Lines Matching +full:dev +full:- +full:size

4  * SPDX-License-Identifier: Apache-2.0
44 static bool flash_si32_valid_range(off_t offset, uint32_t size, bool write) in flash_si32_valid_range() argument
50 if ((offset > SOC_NV_FLASH_SIZE) || ((offset + size) > SOC_NV_FLASH_SIZE)) { in flash_si32_valid_range()
56 return -EINVAL; in flash_si32_valid_range()
59 if ((size % SOC_NV_FLASH_WRITE_BLOCK_SIZE) != 0) { in flash_si32_valid_range()
60 return -EINVAL; in flash_si32_valid_range()
67 static int flash_si32_read(const struct device *dev, off_t offset, void *data, size_t size) in flash_si32_read() argument
69 if (!flash_si32_valid_range(offset, size, false)) { in flash_si32_read()
70 return -EINVAL; in flash_si32_read()
73 if (!size) { in flash_si32_read()
77 memcpy(data, (uint8_t *)CONFIG_FLASH_BASE_ADDRESS + offset, size); in flash_si32_read()
82 static int flash_si32_write(const struct device *dev, off_t offset, const void *data_, size_t size) in flash_si32_write() argument
85 struct flash_si32_data *const dev_data = dev->data; in flash_si32_write()
86 const struct flash_si32_config *const config = dev->config; in flash_si32_write()
88 if (!flash_si32_valid_range(offset, size, true)) { in flash_si32_write()
89 return -EINVAL; in flash_si32_write()
92 if (!size) { in flash_si32_write()
96 k_sem_take(&dev_data->mutex, K_FOREVER); in flash_si32_write()
98 SI32_FLASHCTRL_A_write_wraddr(config->controller, offset); in flash_si32_write()
99 SI32_FLASHCTRL_A_enter_multi_byte_write_mode(config->controller); in flash_si32_write()
100 SI32_FLASHCTRL_A_write_flash_key(config->controller, 0xA5); in flash_si32_write()
101 SI32_FLASHCTRL_A_write_flash_key(config->controller, 0xF2); in flash_si32_write()
103 for (size_t i = 0; i < size; i += SOC_NV_FLASH_WRITE_BLOCK_SIZE) { in flash_si32_write()
106 SI32_FLASHCTRL_A_write_wrdata(config->controller, (uint32_t)halfword); in flash_si32_write()
108 while (SI32_FLASHCTRL_A_is_flash_busy(config->controller)) { in flash_si32_write()
112 while (SI32_FLASHCTRL_A_is_buffer_full(config->controller)) { in flash_si32_write()
115 SI32_FLASHCTRL_A_write_flash_key(config->controller, 0x5A); in flash_si32_write()
117 k_sem_give(&dev_data->mutex); in flash_si32_write()
122 static int flash_si32_erase(const struct device *dev, off_t offset, size_t size) in flash_si32_erase() argument
124 struct flash_si32_data *const dev_data = dev->data; in flash_si32_erase()
125 const struct flash_si32_config *const config = dev->config; in flash_si32_erase()
127 if (!flash_si32_valid_range(offset, size, false)) { in flash_si32_erase()
128 return -EINVAL; in flash_si32_erase()
133 return -EINVAL; in flash_si32_erase()
136 if ((size % SOC_NV_FLASH_ERASE_BLOCK_SIZE) != 0) { in flash_si32_erase()
137 LOG_ERR("size %zu: not multiple of a page size", size); in flash_si32_erase()
138 return -EINVAL; in flash_si32_erase()
141 if (!size) { in flash_si32_erase()
145 k_sem_take(&dev_data->mutex, K_FOREVER); in flash_si32_erase()
147 SI32_FLASHCTRL_A_enter_flash_erase_mode(config->controller); in flash_si32_erase()
148 SI32_FLASHCTRL_A_write_flash_key(config->controller, 0xA5); in flash_si32_erase()
149 SI32_FLASHCTRL_A_write_flash_key(config->controller, 0xF2); in flash_si32_erase()
151 for (size_t i = 0; i < size; i += SOC_NV_FLASH_ERASE_BLOCK_SIZE) { in flash_si32_erase()
152 SI32_FLASHCTRL_A_write_wraddr(config->controller, offset + i); in flash_si32_erase()
153 SI32_FLASHCTRL_A_write_wrdata(config->controller, 0); in flash_si32_erase()
155 while (SI32_FLASHCTRL_A_is_buffer_full(config->controller)) { in flash_si32_erase()
159 SI32_FLASHCTRL_A_write_flash_key(config->controller, 0x5A); in flash_si32_erase()
160 SI32_FLASHCTRL_A_exit_flash_erase_mode(config->controller); in flash_si32_erase()
162 k_sem_give(&dev_data->mutex); in flash_si32_erase()
173 void flash_si32_page_layout(const struct device *dev, const struct flash_pages_layout **layout, in flash_si32_page_layout() argument
181 static const struct flash_parameters *flash_si32_get_parameters(const struct device *dev) in flash_si32_get_parameters() argument
183 ARG_UNUSED(dev); in flash_si32_get_parameters()
188 static int flash_si32_init(const struct device *dev) in flash_si32_init() argument
190 struct flash_si32_data *const dev_data = dev->data; in flash_si32_init()
191 const struct flash_si32_config *const config = dev->config; in flash_si32_init()
193 k_sem_init(&dev_data->mutex, 1, 1); in flash_si32_init()
195 SI32_FLASHCTRL_A_exit_read_store_mode(config->controller); in flash_si32_init()