Lines Matching +full:sector +full:- +full:0 +full:a +full:- +full:pages

5  * SPDX-License-Identifier: Apache-2.0
9 * This driver defines a page as the erase_block_size.
10 * This driver defines a write page as defined by the flash controller
11 * This driver defines a section as a contiguous array of bytes
57 if (offset < 0) { in sam_flash_validate_offset_len()
70 return (value & (alignment - 1)) == 0; in sam_flash_aligned()
80 Efc *regs = config->regs; in sam_flash_mask_ready_interrupt()
82 regs->EEFC_FMR &= ~EEFC_FMR_FRDY; in sam_flash_mask_ready_interrupt()
87 Efc *regs = config->regs; in sam_flash_unmask_ready_interrupt()
89 regs->EEFC_FMR |= EEFC_FMR_FRDY; in sam_flash_unmask_ready_interrupt()
94 struct sam_flash_data *data = dev->data; in sam_flash_isr()
95 const struct sam_flash_config *config = dev->config; in sam_flash_isr()
98 k_sem_give(&data->ready_sem); in sam_flash_isr()
103 struct sam_flash_data *data = dev->data; in sam_flash_section_wait_until_ready()
104 const struct sam_flash_config *config = dev->config; in sam_flash_section_wait_until_ready()
105 Efc *regs = config->regs; in sam_flash_section_wait_until_ready()
108 k_sem_reset(&data->ready_sem); in sam_flash_section_wait_until_ready()
111 if (k_sem_take(&data->ready_sem, K_MSEC(500)) < 0) { in sam_flash_section_wait_until_ready()
113 return -EFAULT; in sam_flash_section_wait_until_ready()
117 eefc_fsr = regs->EEFC_FSR; in sam_flash_section_wait_until_ready()
121 return -EPERM; in sam_flash_section_wait_until_ready()
126 return -EPERM; in sam_flash_section_wait_until_ready()
131 return -EPERM; in sam_flash_section_wait_until_ready()
134 return 0; in sam_flash_section_wait_until_ready()
139 const struct sam_flash_config *config = dev->config; in sam_flash_section_is_within_area()
145 if ((offset >= 0) && ((offset + len) <= config->area_size)) { in sam_flash_section_is_within_area()
149 LOG_WRN("Section from 0x%x to 0x%x is not within flash area (0x0 to %x)", in sam_flash_section_is_within_area()
150 (size_t)offset, (size_t)(offset + len), (size_t)config->area_size); in sam_flash_section_is_within_area()
158 const struct sam_flash_config *config = dev->config; in sam_flash_section_is_aligned_with_write_block_size()
160 if (sam_flash_aligned(offset, config->parameters.write_block_size) && in sam_flash_section_is_aligned_with_write_block_size()
161 sam_flash_aligned(len, config->parameters.write_block_size)) { in sam_flash_section_is_aligned_with_write_block_size()
165 LOG_WRN("Section from 0x%x to 0x%x is not aligned with write block size (%u)", in sam_flash_section_is_aligned_with_write_block_size()
166 (size_t)offset, (size_t)(offset + len), config->parameters.write_block_size); in sam_flash_section_is_aligned_with_write_block_size()
174 const struct sam_flash_config *config = dev->config; in sam_flash_section_is_aligned_with_pages()
178 if (flash_get_page_info_by_offs(dev, offset, &pages_info) < 0) { in sam_flash_section_is_aligned_with_pages()
188 if ((offset + len) == (config->area_size)) { in sam_flash_section_is_aligned_with_pages()
193 if (flash_get_page_info_by_offs(dev, offset + len, &pages_info) < 0) { in sam_flash_section_is_aligned_with_pages()
207 struct sam_flash_data *sam_data = dev->data; in sam_flash_read()
208 const struct sam_flash_config *sam_config = dev->config; in sam_flash_read()
211 if (len == 0) { in sam_flash_read()
212 return 0; in sam_flash_read()
216 return -EINVAL; in sam_flash_read()
220 return -EINVAL; in sam_flash_read()
223 key = k_spin_lock(&sam_data->lock); in sam_flash_read()
224 memcpy(data, (uint8_t *)(sam_config->area_address + offset), len); in sam_flash_read()
225 k_spin_unlock(&sam_data->lock, key); in sam_flash_read()
226 return 0; in sam_flash_read()
231 const struct sam_flash_config *sam_config = dev->config; in sam_flash_write_latch_buffer_to_page()
232 Efc *regs = sam_config->regs; in sam_flash_write_latch_buffer_to_page()
235 regs->EEFC_FCR = EEFC_FCR_FCMD_WP | EEFC_FCR_FARG(page) | EEFC_FCR_FKEY_PASSWD; in sam_flash_write_latch_buffer_to_page()
237 return 0; in sam_flash_write_latch_buffer_to_page()
242 return sam_flash_write_latch_buffer_to_page(dev, offset - SAM_FLASH_WRITE_PAGE_SIZE); in sam_flash_write_latch_buffer_to_previous_page()
254 for (size_t i = 0; i < size; i++) { in sam_flash_write_dwords_to_flash()
266 return 0; in sam_flash_write_dwords_to_flash()
271 struct sam_flash_data *sam_data = dev->data; in sam_flash_write()
274 if (len == 0) { in sam_flash_write()
275 return 0; in sam_flash_write()
279 return -EINVAL; in sam_flash_write()
283 return -EINVAL; in sam_flash_write()
286 LOG_DBG("Writing sector from 0x%x to 0x%x", (size_t)offset, (size_t)(offset + len)); in sam_flash_write()
288 key = k_spin_lock(&sam_data->lock); in sam_flash_write()
289 if (sam_flash_write_dwords_to_flash(dev, offset, data, len / sizeof(uint32_t)) < 0) { in sam_flash_write()
290 k_spin_unlock(&sam_data->lock, key); in sam_flash_write()
291 return -EAGAIN; in sam_flash_write()
294 k_spin_unlock(&sam_data->lock, key); in sam_flash_write()
295 return 0; in sam_flash_write()
300 const struct sam_flash_config *sam_config = dev->config; in sam_flash_unlock_write_page()
301 Efc *regs = sam_config->regs; in sam_flash_unlock_write_page()
304 regs->EEFC_FCR = EEFC_FCR_FCMD_CLB in sam_flash_unlock_write_page()
318 page_index_start = info->start_offset / SAM_FLASH_WRITE_PAGE_SIZE; in sam_flash_unlock_page()
319 page_index_end = page_index_start + (info->size / SAM_FLASH_WRITE_PAGE_SIZE); in sam_flash_unlock_page()
323 if (ret < 0) { in sam_flash_unlock_page()
328 return 0; in sam_flash_unlock_page()
333 const struct sam_flash_config *sam_config = dev->config; in sam_flash_erase_page()
334 Efc *regs = sam_config->regs; in sam_flash_erase_page()
339 page_index = info->start_offset / SAM_FLASH_WRITE_PAGE_SIZE; in sam_flash_erase_page()
341 LOG_DBG("Erasing page at 0x%x of size 0x%x", (size_t)info->start_offset, info->size); in sam_flash_erase_page()
344 switch (info->size) { in sam_flash_erase_page()
345 case 0x800: in sam_flash_erase_page()
346 regs->EEFC_FCR = EEFC_FCR_FCMD_EPA in sam_flash_erase_page()
351 case 0x1000: in sam_flash_erase_page()
352 regs->EEFC_FCR = EEFC_FCR_FCMD_EPA in sam_flash_erase_page()
357 case 0x2000: in sam_flash_erase_page()
358 regs->EEFC_FCR = EEFC_FCR_FCMD_EPA in sam_flash_erase_page()
363 case 0x4000: in sam_flash_erase_page()
364 regs->EEFC_FCR = EEFC_FCR_FCMD_EPA in sam_flash_erase_page()
370 return -EINVAL; in sam_flash_erase_page()
374 if (ret == 0) { in sam_flash_erase_page()
378 LOG_ERR("Failed to erase page at 0x%x of size 0x%x", (size_t)info->start_offset, in sam_flash_erase_page()
379 info->size); in sam_flash_erase_page()
387 const struct device *dev = sam_data->dev; in sam_flash_erase_foreach_page()
388 struct sam_flash_erase_data *erase_data = &sam_data->erase_data; in sam_flash_erase_foreach_page()
391 if (info->start_offset < erase_data->section_start) { in sam_flash_erase_foreach_page()
396 /* Check if we've reached the end of pages to erase */ in sam_flash_erase_foreach_page()
397 if (info->start_offset >= erase_data->section_end) { in sam_flash_erase_foreach_page()
399 erase_data->succeeded = true; in sam_flash_erase_foreach_page()
403 if (sam_flash_unlock_page(dev, info) < 0) { in sam_flash_erase_foreach_page()
408 if (sam_flash_erase_page(dev, info) < 0) { in sam_flash_erase_foreach_page()
419 struct sam_flash_data *sam_data = dev->data; in sam_flash_erase()
422 if (size == 0) { in sam_flash_erase()
423 return 0; in sam_flash_erase()
427 return -EINVAL; in sam_flash_erase()
431 return -EINVAL; in sam_flash_erase()
434 LOG_DBG("Erasing sector from 0x%x to 0x%x", (size_t)offset, (size_t)(offset + size)); in sam_flash_erase()
436 key = k_spin_lock(&sam_data->lock); in sam_flash_erase()
437 sam_data->erase_data.section_start = offset; in sam_flash_erase()
438 sam_data->erase_data.section_end = offset + size; in sam_flash_erase()
439 sam_data->erase_data.succeeded = false; in sam_flash_erase()
441 if (!sam_data->erase_data.succeeded) { in sam_flash_erase()
442 k_spin_unlock(&sam_data->lock, key); in sam_flash_erase()
443 return -EFAULT; in sam_flash_erase()
446 k_spin_unlock(&sam_data->lock, key); in sam_flash_erase()
447 return 0; in sam_flash_erase()
452 const struct sam_flash_config *config = dev->config; in sam_flash_get_parameters()
454 return &config->parameters; in sam_flash_get_parameters()
461 const struct sam_flash_config *config = dev->config; in sam_flash_api_pages_layout()
463 *layout = config->pages_layouts; in sam_flash_api_pages_layout()
464 *layout_size = config->pages_layouts_size; in sam_flash_api_pages_layout()
477 struct sam_flash_data *sam_data = dev->data; in sam_flash_init()
478 const struct sam_flash_config *sam_config = dev->config; in sam_flash_init()
480 sam_data->dev = dev; in sam_flash_init()
481 k_sem_init(&sam_data->ready_sem, 0, 1); in sam_flash_init()
483 sam_config->irq_init(); in sam_flash_init()
484 return 0; in sam_flash_init()
487 #define SAM_FLASH_DEVICE DT_INST(0, atmel_sam_flash)
506 sam_flash_isr, DEVICE_DT_INST_GET(inst), 0); \
518 .erase_value = 0xFF, \
530 SAM_FLASH_CONTROLLER(0)