drivers/flash: Move write_block_size into flash_parameters
With addition of flash_parameters structure, and supporting API call to retrieve it, it is no longer needed to store write_block_size as a part of flash_driver_api and it should be part of flash_parameters. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
parent
076282a117
commit
609b645ac7
15 changed files with 35 additions and 35 deletions
|
@ -26,6 +26,7 @@ struct flash_gecko_data {
|
|||
|
||||
|
||||
static const struct flash_parameters flash_gecko_parameters = {
|
||||
.write_block_size = DT_PROP(SOC_NV_FLASH_NODE, write_block_size),
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
||||
|
@ -216,7 +217,6 @@ static const struct flash_driver_api flash_gecko_driver_api = {
|
|||
#ifdef CONFIG_FLASH_PAGE_LAYOUT
|
||||
.page_layout = flash_gecko_page_layout,
|
||||
#endif
|
||||
.write_block_size = DT_PROP(SOC_NV_FLASH_NODE, write_block_size),
|
||||
};
|
||||
|
||||
static struct flash_gecko_data flash_gecko_0_data;
|
||||
|
|
|
@ -47,6 +47,7 @@ struct flash_sam_dev_data {
|
|||
};
|
||||
|
||||
static const struct flash_parameters flash_sam_parameters = {
|
||||
.write_block_size = FLASH_WRITE_BLK_SZ,
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
||||
|
@ -360,7 +361,6 @@ static const struct flash_driver_api flash_sam_api = {
|
|||
#ifdef CONFIG_FLASH_PAGE_LAYOUT
|
||||
.page_layout = flash_sam_page_layout,
|
||||
#endif
|
||||
.write_block_size = FLASH_WRITE_BLK_SZ,
|
||||
};
|
||||
|
||||
static const struct flash_sam_dev_cfg flash_sam_cfg = {
|
||||
|
|
|
@ -62,6 +62,11 @@ static const struct flash_pages_layout flash_sam0_pages_layout = {
|
|||
#endif
|
||||
|
||||
static const struct flash_parameters flash_sam0_parameters = {
|
||||
#if CONFIG_SOC_FLASH_SAM0_EMULATE_BYTE_PAGES
|
||||
.write_block_size = 1,
|
||||
#else
|
||||
.write_block_size = FLASH_PAGE_SIZE,
|
||||
#endif
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
||||
|
@ -430,11 +435,6 @@ static const struct flash_driver_api flash_sam0_api = {
|
|||
#ifdef CONFIG_FLASH_PAGE_LAYOUT
|
||||
.page_layout = flash_sam0_page_layout,
|
||||
#endif
|
||||
#if CONFIG_SOC_FLASH_SAM0_EMULATE_BYTE_PAGES
|
||||
.write_block_size = 1,
|
||||
#else
|
||||
.write_block_size = FLASH_PAGE_SIZE,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct flash_sam0_data flash_sam0_data_0;
|
||||
|
|
|
@ -142,6 +142,7 @@ static bool write_protection;
|
|||
static const struct flash_driver_api flash_sim_api;
|
||||
|
||||
static const struct flash_parameters flash_sim_parameters = {
|
||||
.write_block_size = FLASH_SIMULATOR_PROG_UNIT,
|
||||
.erase_value = FLASH_SIMULATOR_ERASE_VALUE
|
||||
};
|
||||
|
||||
|
@ -362,7 +363,6 @@ static const struct flash_driver_api flash_sim_api = {
|
|||
.write = flash_sim_write,
|
||||
.erase = flash_sim_erase,
|
||||
.write_protection = flash_wp_set,
|
||||
.write_block_size = FLASH_SIMULATOR_PROG_UNIT,
|
||||
.get_parameters = flash_sim_get_parameters,
|
||||
#ifdef CONFIG_FLASH_PAGE_LAYOUT
|
||||
.page_layout = flash_sim_page_layout,
|
||||
|
|
|
@ -58,6 +58,13 @@ LOG_MODULE_REGISTER(flash_stm32, CONFIG_FLASH_LOG_LEVEL);
|
|||
#define CFG_HW_FLASH_SEMID 2
|
||||
|
||||
static const struct flash_parameters flash_stm32_parameters = {
|
||||
#if DT_PROP(DT_INST(0, soc_nv_flash), write_block_size)
|
||||
.write_block_size = DT_PROP(DT_INST(0, soc_nv_flash), write_block_size),
|
||||
#else
|
||||
#error Flash write block size not available
|
||||
/* Flash Write block size is extracted from device tree */
|
||||
/* as flash node property 'write-block-size' */
|
||||
#endif
|
||||
/* WARNING: This value may be not valid for L0/L1 chips */
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
@ -316,13 +323,6 @@ static const struct flash_driver_api flash_stm32_api = {
|
|||
#ifdef CONFIG_FLASH_PAGE_LAYOUT
|
||||
.page_layout = flash_stm32_page_layout,
|
||||
#endif
|
||||
#if DT_PROP(DT_INST(0, soc_nv_flash), write_block_size)
|
||||
.write_block_size = DT_PROP(DT_INST(0, soc_nv_flash), write_block_size),
|
||||
#else
|
||||
#error Flash write block size not available
|
||||
/* Flash Write block size is extracted from device tree */
|
||||
/* as flash node property 'write-block-size' */
|
||||
#endif
|
||||
};
|
||||
|
||||
static int stm32_flash_init(struct device *dev)
|
||||
|
@ -362,7 +362,7 @@ static int stm32_flash_init(struct device *dev)
|
|||
flash_stm32_sem_init(dev);
|
||||
|
||||
LOG_DBG("Flash initialized. BS: %zu",
|
||||
flash_stm32_api.write_block_size);
|
||||
flash_stm32_parameters.write_block_size);
|
||||
|
||||
#if ((CONFIG_FLASH_LOG_LEVEL >= LOG_LEVEL_DBG) && CONFIG_FLASH_PAGE_LAYOUT)
|
||||
const struct flash_pages_layout *layout;
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
LOG_MODULE_REGISTER(qspi_nor, CONFIG_FLASH_LOG_LEVEL);
|
||||
|
||||
static const struct flash_parameters qspi_flash_parameters = {
|
||||
.write_block_size = 1,
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
||||
|
@ -787,7 +788,6 @@ static const struct flash_driver_api qspi_nor_api = {
|
|||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
.page_layout = qspi_nor_pages_layout,
|
||||
#endif
|
||||
.write_block_size = 1,
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -44,6 +44,11 @@ struct flash_priv {
|
|||
};
|
||||
|
||||
static const struct flash_parameters flash_mcux_parameters = {
|
||||
#if DT_NODE_HAS_PROP(SOC_NV_FLASH_NODE, write_block_size)
|
||||
.write_block_size = DT_PROP(SOC_NV_FLASH_NODE, write_block_size),
|
||||
#else
|
||||
.write_block_size = FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE,
|
||||
#endif
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
||||
|
@ -168,11 +173,6 @@ static const struct flash_driver_api flash_mcux_api = {
|
|||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
.page_layout = flash_mcux_pages_layout,
|
||||
#endif
|
||||
#if DT_NODE_HAS_PROP(SOC_NV_FLASH_NODE, write_block_size)
|
||||
.write_block_size = DT_PROP(SOC_NV_FLASH_NODE, write_block_size),
|
||||
#else
|
||||
.write_block_size = FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE,
|
||||
#endif
|
||||
};
|
||||
|
||||
static int flash_mcux_init(struct device *dev)
|
||||
|
|
|
@ -62,6 +62,7 @@ struct flash_nios2_qspi_config {
|
|||
};
|
||||
|
||||
static const struct flash_parameters flash_nios2_qspi_parameters = {
|
||||
.write_block_size = NIOS2_WRITE_BLOCK_SIZE,
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
||||
|
@ -471,7 +472,6 @@ static const struct flash_driver_api flash_nios2_qspi_api = {
|
|||
.page_layout = (flash_api_pages_layout)
|
||||
flash_page_layout_not_implemented,
|
||||
#endif
|
||||
.write_block_size = NIOS2_WRITE_BLOCK_SIZE,
|
||||
};
|
||||
|
||||
static int flash_nios2_qspi_init(struct device *dev)
|
||||
|
|
|
@ -106,6 +106,11 @@ static int erase_in_timeslice(uint32_t addr, uint32_t size);
|
|||
#endif /* CONFIG_SOC_FLASH_NRF_RADIO_SYNC */
|
||||
|
||||
static const struct flash_parameters flash_nrf_parameters = {
|
||||
#if IS_ENABLED(CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS)
|
||||
.write_block_size = 1,
|
||||
#else
|
||||
.write_block_size = 4,
|
||||
#endif
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
||||
|
@ -299,11 +304,6 @@ static const struct flash_driver_api flash_nrf_api = {
|
|||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
.page_layout = flash_nrf_pages_layout,
|
||||
#endif
|
||||
#if IS_ENABLED(CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS)
|
||||
.write_block_size = 1,
|
||||
#else
|
||||
.write_block_size = 4,
|
||||
#endif
|
||||
};
|
||||
|
||||
static int nrf_flash_init(struct device *dev)
|
||||
|
|
|
@ -29,6 +29,7 @@ struct flash_priv {
|
|||
};
|
||||
|
||||
static const struct flash_parameters flash_mcux_parameters = {
|
||||
.write_block_size = FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE,
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
||||
|
@ -154,7 +155,6 @@ static const struct flash_driver_api flash_mcux_api = {
|
|||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
.page_layout = flash_mcux_pages_layout,
|
||||
#endif
|
||||
.write_block_size = FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE,
|
||||
};
|
||||
|
||||
static int flash_mcux_init(struct device *dev)
|
||||
|
|
|
@ -77,6 +77,7 @@ struct spi_flash_at45_config {
|
|||
};
|
||||
|
||||
static const struct flash_parameters flash_at45_parameters = {
|
||||
.write_block_size = 1,
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
||||
|
@ -645,7 +646,6 @@ static const struct flash_driver_api spi_flash_at45_api = {
|
|||
#if IS_ENABLED(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
.page_layout = spi_flash_at45_pages_layout,
|
||||
#endif
|
||||
.write_block_size = 1,
|
||||
};
|
||||
|
||||
#define DT_DRV_COMPAT atmel_at45
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#endif
|
||||
|
||||
static const struct flash_parameters flash_wb_parameters = {
|
||||
.write_block_size = 1,
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
||||
|
@ -409,7 +410,6 @@ static const struct flash_driver_api spi_flash_api = {
|
|||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
.page_layout = flash_wb_pages_layout,
|
||||
#endif
|
||||
.write_block_size = 1,
|
||||
};
|
||||
|
||||
static int spi_flash_wb_configure(struct device *dev)
|
||||
|
|
|
@ -85,6 +85,7 @@ struct spi_nor_data {
|
|||
};
|
||||
|
||||
static const struct flash_parameters flash_nor_parameters = {
|
||||
.write_block_size = 1,
|
||||
.erase_value = 0xff,
|
||||
};
|
||||
|
||||
|
@ -589,7 +590,6 @@ static const struct flash_driver_api spi_nor_api = {
|
|||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
.page_layout = spi_nor_pages_layout,
|
||||
#endif
|
||||
.write_block_size = 1,
|
||||
};
|
||||
|
||||
static const struct spi_nor_config flash_id = {
|
||||
|
|
|
@ -42,6 +42,7 @@ struct flash_pages_layout {
|
|||
* through a runtime.
|
||||
*/
|
||||
struct flash_parameters {
|
||||
const size_t write_block_size;
|
||||
uint8_t erase_value; /* Byte value of erased flash */
|
||||
};
|
||||
|
||||
|
@ -89,7 +90,6 @@ __subsystem struct flash_driver_api {
|
|||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
flash_api_pages_layout page_layout;
|
||||
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
|
||||
const size_t write_block_size;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -304,7 +304,7 @@ static inline size_t z_impl_flash_get_write_block_size(struct device *dev)
|
|||
const struct flash_driver_api *api =
|
||||
(const struct flash_driver_api *)dev->driver_api;
|
||||
|
||||
return api->write_block_size;
|
||||
return api->get_parameters(dev)->write_block_size;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -215,7 +215,7 @@ int stream_flash_init(struct stream_flash_ctx *ctx, struct device *fdev,
|
|||
}
|
||||
|
||||
if ((offset + size) > total_size ||
|
||||
offset % api->write_block_size) {
|
||||
offset % flash_get_write_block_size(fdev)) {
|
||||
LOG_ERR("Incorrect parameter");
|
||||
return -EFAULT;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue