Lines Matching +full:dev +full:- +full:size
4 * SPDX-License-Identifier: Apache-2.0
33 static bool write_range_is_valid(off_t offset, uint32_t size);
34 static bool read_range_is_valid(off_t offset, uint32_t size);
35 static int erase_flash_block(off_t offset, size_t size);
38 static int flash_gecko_read(const struct device *dev, off_t offset, in flash_gecko_read() argument
40 size_t size) in flash_gecko_read() argument
42 if (!read_range_is_valid(offset, size)) { in flash_gecko_read()
43 return -EINVAL; in flash_gecko_read()
46 if (!size) { in flash_gecko_read()
50 memcpy(data, (uint8_t *)CONFIG_FLASH_BASE_ADDRESS + offset, size); in flash_gecko_read()
55 static int flash_gecko_write(const struct device *dev, off_t offset, in flash_gecko_write() argument
56 const void *data, size_t size) in flash_gecko_write() argument
58 struct flash_gecko_data *const dev_data = dev->data; in flash_gecko_write()
63 if (!write_range_is_valid(offset, size)) { in flash_gecko_write()
64 return -EINVAL; in flash_gecko_write()
67 if (!size) { in flash_gecko_write()
71 k_sem_take(&dev_data->mutex, K_FOREVER); in flash_gecko_write()
75 msc_ret = MSC_WriteWord(address, data, size); in flash_gecko_write()
77 ret = -EIO; in flash_gecko_write()
81 k_sem_give(&dev_data->mutex); in flash_gecko_write()
86 static int flash_gecko_erase(const struct device *dev, off_t offset, in flash_gecko_erase() argument
87 size_t size) in flash_gecko_erase() argument
89 struct flash_gecko_data *const dev_data = dev->data; in flash_gecko_erase()
92 if (!read_range_is_valid(offset, size)) { in flash_gecko_erase()
93 return -EINVAL; in flash_gecko_erase()
98 return -EINVAL; in flash_gecko_erase()
101 if ((size % FLASH_PAGE_SIZE) != 0) { in flash_gecko_erase()
102 LOG_ERR("size %zu: not multiple of a page size", size); in flash_gecko_erase()
103 return -EINVAL; in flash_gecko_erase()
106 if (!size) { in flash_gecko_erase()
110 k_sem_take(&dev_data->mutex, K_FOREVER); in flash_gecko_erase()
113 ret = erase_flash_block(offset, size); in flash_gecko_erase()
116 k_sem_give(&dev_data->mutex); in flash_gecko_erase()
125 MSC->LOCK = 0; in flash_gecko_write_protection()
129 MSC->LOCK = MSC_LOCK_LOCKKEY_UNLOCK; in flash_gecko_write_protection()
131 MSC->LOCK = MSC_UNLOCK_CODE; in flash_gecko_write_protection()
137 * - A flash address to write to must be aligned to words.
138 * - Number of bytes to write must be divisible by 4.
140 static bool write_range_is_valid(off_t offset, uint32_t size) in write_range_is_valid() argument
142 return read_range_is_valid(offset, size) in write_range_is_valid()
144 && (size % 4 == 0U); in write_range_is_valid()
147 static bool read_range_is_valid(off_t offset, uint32_t size) in read_range_is_valid() argument
149 return (offset + size) <= (CONFIG_FLASH_SIZE * 1024); in read_range_is_valid()
152 static int erase_flash_block(off_t offset, size_t size) in erase_flash_block() argument
158 for (off_t tmp = offset; tmp < offset + size; tmp += FLASH_PAGE_SIZE) { in erase_flash_block()
162 ret = -EIO; in erase_flash_block()
177 void flash_gecko_page_layout(const struct device *dev, in flash_gecko_page_layout() argument
187 flash_gecko_get_parameters(const struct device *dev) in flash_gecko_get_parameters() argument
189 ARG_UNUSED(dev); in flash_gecko_get_parameters()
194 static int flash_gecko_get_size(const struct device *dev, uint64_t *size) in flash_gecko_get_size() argument
196 ARG_UNUSED(dev); in flash_gecko_get_size()
198 *size = (uint64_t)DT_REG_SIZE(SOC_NV_FLASH_NODE); in flash_gecko_get_size()
203 static int flash_gecko_init(const struct device *dev) in flash_gecko_init() argument
205 struct flash_gecko_data *const dev_data = dev->data; in flash_gecko_init()
207 k_sem_init(&dev_data->mutex, 1, 1); in flash_gecko_init()
212 MSC->LOCK = 0; in flash_gecko_init()
214 LOG_INF("Device %s initialized", dev->name); in flash_gecko_init()