summaryrefslogtreecommitdiff
path: root/zephyr/drivers/cros_flash/cros_flash_npcx.c
diff options
context:
space:
mode:
authorDawid Niedzwiecki <dn@semihalf.com>2021-12-03 08:22:24 +0100
committerCommit Bot <commit-bot@chromium.org>2022-01-18 19:04:08 +0000
commit1550d516f34d0be2e10488517d7023c1a236082d (patch)
tree2ad4997f4f53af28bb6305235cd575842370279a /zephyr/drivers/cros_flash/cros_flash_npcx.c
parent3fe7264eedf033ff984c56a9f58074bae4cf8208 (diff)
downloadchrome-ec-1550d516f34d0be2e10488517d7023c1a236082d.tar.gz
zephyr: flash: clean up the shim layer
Investigate if there is a possibility to call Zephyr flash drivers directly in the shim layer, not via CrosEC drivers. Unfortunately, it is possible only for the read operation. Other operations require additional actions depending on the chip type e.g. splitting into smaller parts or refreshing watchdog. Also, move locking of physical flash operations to the CrosEC drivers from the shim layer. BUG=b:205175314 TEST=zmake testall && make sure SoftwareSync works to verify flash operations BRANCH=main Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I9c947d46244a255573ebde9a5cd7432a3ee9389c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3389268 Tested-by: Dawid Niedźwiecki <dn@semihalf.com> Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'zephyr/drivers/cros_flash/cros_flash_npcx.c')
-rw-r--r--zephyr/drivers/cros_flash/cros_flash_npcx.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/zephyr/drivers/cros_flash/cros_flash_npcx.c b/zephyr/drivers/cros_flash/cros_flash_npcx.c
index 4c6a6e5e3c..d6ecd950e1 100644
--- a/zephyr/drivers/cros_flash/cros_flash_npcx.c
+++ b/zephyr/drivers/cros_flash/cros_flash_npcx.c
@@ -34,7 +34,7 @@ struct cros_flash_npcx_data {
static struct spi_config spi_cfg;
-#define FLASH_DEV DT_NODELABEL(int_flash)
+#define FLASH_DEV DT_CHOSEN(zephyr_flash_controller)
#define SPI_CONTROLLER_DEV DT_NODELABEL(spi_fiu0)
#define DRV_DATA(dev) ((struct cros_flash_npcx_data *)(dev)->data)
@@ -435,15 +435,6 @@ static int cros_flash_npcx_init(const struct device *dev)
return 0;
}
-/* TODO(b/205175314): Migrate cros-flash driver to Zephyr flash driver) */
-static int cros_flash_npcx_read(const struct device *dev, int offset, int size,
- char *dst_data)
-{
- struct cros_flash_npcx_data *data = DRV_DATA(dev);
-
- return flash_read(data->flash_dev, offset, dst_data, size);
-}
-
static int cros_flash_npcx_write(const struct device *dev, int offset, int size,
const char *src_data)
{
@@ -463,8 +454,14 @@ static int cros_flash_npcx_write(const struct device *dev, int offset, int size,
return -EINVAL;
}
+ /* Lock physical flash operations */
+ crec_flash_lock_mapped_storage(1);
+
ret = flash_write(data->flash_dev, offset, src_data, size);
+ /* Unlock physical flash operations */
+ crec_flash_lock_mapped_storage(0);
+
return ret;
}
@@ -491,8 +488,14 @@ static int cros_flash_npcx_erase(const struct device *dev, int offset, int size)
return -EINVAL;
}
+ /* Lock physical flash operations */
+ crec_flash_lock_mapped_storage(1);
+
ret = flash_erase(data->flash_dev, offset, size);
+ /* Unlock physical flash operations */
+ crec_flash_lock_mapped_storage(0);
+
return ret;
}
@@ -609,7 +612,6 @@ static int cros_flash_npcx_get_status(const struct device *dev, uint8_t *sr1,
/* cros ec flash driver registration */
static const struct cros_flash_driver_api cros_flash_npcx_driver_api = {
.init = cros_flash_npcx_init,
- .physical_read = cros_flash_npcx_read,
.physical_write = cros_flash_npcx_write,
.physical_erase = cros_flash_npcx_erase,
.physical_get_protect = cros_flash_npcx_get_protect,