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

4  * SPDX-License-Identifier: Apache-2.0
27 #define ANDES_ACCESS_ADDRESSED BIT(0)
29 /* Indicates that an access command is performing a write. If not
30 * provided access is a read.
35 flash_andes_qspi_access(dev, opcode, 0, 0, dest, length)
40 flash_andes_qspi_access(dev, opcode, ANDES_ACCESS_WRITE, 0, NULL, 0)
93 const struct flash_andes_qspi_data *dev_data = dev->data; in dev_erase_types()
95 return dev_data->erase_types; in dev_erase_types()
102 const struct flash_andes_qspi_data *dev_data = dev->data; in dev_flash_size()
104 return dev_data->flash_size; in dev_flash_size()
106 const struct flash_andes_qspi_config *config = dev->config; in dev_flash_size()
108 return config->flash_size; in dev_flash_size()
115 const struct flash_andes_qspi_data *dev_data = dev->data; in dev_page_size()
117 return dev_data->page_size; in dev_page_size()
129 * @return 0 on success
135 struct flash_andes_qspi_data *dev_data = dev->data; in flash_andes_qspi_access()
136 const struct flash_andes_qspi_config *config = dev->config; in flash_andes_qspi_access()
137 uint32_t base = config->base; in flash_andes_qspi_access()
139 bool is_addressed = (access & ANDES_ACCESS_ADDRESSED) != 0U; in flash_andes_qspi_access()
140 bool is_write = (access & ANDES_ACCESS_WRITE) != 0U; in flash_andes_qspi_access()
141 int ret = 0; in flash_andes_qspi_access()
150 (0x2 << TFMAT_ADDR_LEN_OFFSET)), QSPI_TFMAT(base)); in flash_andes_qspi_access()
156 if (length == 0) { in flash_andes_qspi_access()
164 dev_data->tx_ptr = 0; in flash_andes_qspi_access()
165 dev_data->tx_buf = (uint8_t *)data; in flash_andes_qspi_access()
166 dev_data->tx_len = length; in flash_andes_qspi_access()
169 ((length - 1) << TCTRL_WR_TCNT_OFFSET)); in flash_andes_qspi_access()
172 dev_data->rx_ptr = 0; in flash_andes_qspi_access()
173 dev_data->rx_buf = (uint8_t *)data; in flash_andes_qspi_access()
176 ((length - 1) << TCTRL_RD_TCNT_OFFSET)); in flash_andes_qspi_access()
210 k_sem_take(&dev_data->device_sync_sem, K_FOREVER); in flash_andes_qspi_access()
218 struct flash_andes_qspi_data *dev_data = dev->data; in acquire_device()
220 k_sem_take(&dev_data->sem, K_FOREVER); in acquire_device()
226 struct flash_andes_qspi_data *dev_data = dev->data; in release_device()
228 k_sem_give(&dev_data->sem); in release_device()
235 * @return 0 on success, negative errno code otherwise
262 * @return 0 on success, negative errno code otherwise
267 /* READ_SFDP requires a 24-bit address followed by a single in read_sfdp()
268 * byte for a wait state. This is effected by using 32-bit in read_sfdp()
269 * address by shifting the 24-bit address up 8 bits. in read_sfdp()
286 * @return 0 on success or a negative error code.
293 if (ret == 0) { in flash_andes_qspi_wrsr()
295 ANDES_ACCESS_WRITE, 0, &sr, in flash_andes_qspi_wrsr()
309 /* should be between 0 and flash size */ in flash_andes_qspi_read()
310 if ((addr < 0 || addr >= flash_size || ((flash_size - addr) < size))) { in flash_andes_qspi_read()
311 return -EINVAL; in flash_andes_qspi_read()
314 if (size == 0) { in flash_andes_qspi_read()
315 return 0; in flash_andes_qspi_read()
333 int ret = 0; in flash_andes_qspi_write()
335 /* should be between 0 and flash size */ in flash_andes_qspi_write()
336 if ((addr < 0 || addr >= flash_size || ((flash_size - addr) < size))) { in flash_andes_qspi_write()
337 return -EINVAL; in flash_andes_qspi_write()
340 if (size == 0) { in flash_andes_qspi_write()
341 return 0; in flash_andes_qspi_write()
348 if (ret != 0) { in flash_andes_qspi_write()
354 to_write = MIN(page_size - (addr % page_size), size); in flash_andes_qspi_write()
359 if (ret != 0) { in flash_andes_qspi_write()
363 size -= to_write; in flash_andes_qspi_write()
368 } while (size > 0); in flash_andes_qspi_write()
386 int ret = 0; in flash_andes_qspi_erase()
389 if ((addr < 0 || addr >= flash_size || ((flash_size - addr) < size))) { in flash_andes_qspi_erase()
390 return -EINVAL; in flash_andes_qspi_erase()
393 if (size == 0) { in flash_andes_qspi_erase()
394 return 0; in flash_andes_qspi_erase()
397 /* address must be sector-aligned */ in flash_andes_qspi_erase()
399 return -EINVAL; in flash_andes_qspi_erase()
402 /* size must be a multiple of sectors */ in flash_andes_qspi_erase()
403 if ((size % SPI_NOR_SECTOR_SIZE) != 0) { in flash_andes_qspi_erase()
404 return -EINVAL; in flash_andes_qspi_erase()
411 if (ret != 0) { in flash_andes_qspi_erase()
418 size -= flash_size; in flash_andes_qspi_erase()
422 while (size > 0) { in flash_andes_qspi_erase()
427 for (uint8_t ei = 0; ei < JESD216_NUM_ERASE_TYPES; ++ei) { in flash_andes_qspi_erase()
431 if ((etp->exp != 0) && in flash_andes_qspi_erase()
432 SPI_NOR_IS_ALIGNED(addr, etp->exp) && in flash_andes_qspi_erase()
433 SPI_NOR_IS_ALIGNED(size, etp->exp) && in flash_andes_qspi_erase()
434 ((bet == NULL) || (etp->exp > bet->exp))) { in flash_andes_qspi_erase()
440 flash_andes_qspi_cmd_addr_write(dev, bet->cmd, in flash_andes_qspi_erase()
441 addr, NULL, 0); in flash_andes_qspi_erase()
442 addr += BIT(bet->exp); in flash_andes_qspi_erase()
443 size -= BIT(bet->exp); in flash_andes_qspi_erase()
445 LOG_DBG("Can't erase %zu at 0x%lx", in flash_andes_qspi_erase()
447 ret = -EINVAL; in flash_andes_qspi_erase()
493 return -EINVAL; in flash_andes_qspi_read_jedec_id()
509 struct flash_andes_qspi_data *dev_data = dev->data; in spi_nor_process_bfp()
510 struct jesd216_erase_type *etp = dev_data->erase_types; in spi_nor_process_bfp()
513 LOG_DBG("%s: %u MiBy flash", dev->name, (uint32_t)(flash_size >> 20)); in spi_nor_process_bfp()
516 * Sector Map Parameter table references them by index.) in spi_nor_process_bfp()
518 memset(dev_data->erase_types, 0, sizeof(dev_data->erase_types)); in spi_nor_process_bfp()
519 for (uint8_t ti = 1; ti <= ARRAY_SIZE(dev_data->erase_types); ++ti) { in spi_nor_process_bfp()
520 if (jesd216_bfp_erase(bfp, ti, etp) == 0) { in spi_nor_process_bfp()
522 (uint32_t)BIT(etp->exp), etp->cmd); in spi_nor_process_bfp()
527 dev_data->page_size = jesd216_bfp_page_size(php, bfp); in spi_nor_process_bfp()
529 dev_data->flash_size = flash_size; in spi_nor_process_bfp()
533 return -EINVAL; in spi_nor_process_bfp()
537 return 0; in spi_nor_process_bfp()
554 ret = read_sfdp(dev, 0, u_header.raw, sizeof(u_header.raw)); in spi_nor_process_sfdp()
555 if (ret != 0) { in spi_nor_process_sfdp()
564 return -EINVAL; in spi_nor_process_sfdp()
567 LOG_DBG("%s: SFDP v %u.%u AP %x with %u PH", dev->name, in spi_nor_process_sfdp()
568 hp->rev_major, hp->rev_minor, hp->access, 1 + hp->nph); in spi_nor_process_sfdp()
570 const struct jesd216_param_header *php = hp->phdr; in spi_nor_process_sfdp()
572 php + MIN(decl_nph, 1 + hp->nph); in spi_nor_process_sfdp()
578 (php - hp->phdr), id, php->rev_major, php->rev_minor, in spi_nor_process_sfdp()
579 php->len_dw, jesd216_param_addr(php)); in spi_nor_process_sfdp()
583 uint32_t dw[MIN(php->len_dw, 20)]; in spi_nor_process_sfdp()
591 if (ret != 0) { in spi_nor_process_sfdp()
597 if (ret != 0) { in spi_nor_process_sfdp()
604 /* For devicetree we need to synthesize a parameter header and in spi_nor_process_sfdp()
607 const struct flash_andes_qspi_config *config = dev->config; in spi_nor_process_sfdp()
609 .len_dw = config->bfp_len, in spi_nor_process_sfdp()
612 ret = spi_nor_process_bfp(dev, &bfp_hdr, config->bfp); in spi_nor_process_sfdp()
622 int ret = 0; in setup_pages_layout()
626 struct flash_andes_qspi_data *dev_data = dev->data; in setup_pages_layout()
630 uint8_t exponent = 0; in setup_pages_layout()
633 for (size_t i = 0; i < ARRAY_SIZE(dev_data->erase_types); ++i) { in setup_pages_layout()
635 &dev_data->erase_types[i]; in setup_pages_layout()
637 if ((etp->cmd != 0) && in setup_pages_layout()
638 ((exponent == 0) || (etp->exp < exponent))) { in setup_pages_layout()
639 exponent = etp->exp; in setup_pages_layout()
643 if (exponent == 0) { in setup_pages_layout()
644 return -ENOTSUP; in setup_pages_layout()
649 /* Error if layout page size is not a multiple of smallest in setup_pages_layout()
652 if ((layout_page_size % erase_size) != 0) { in setup_pages_layout()
655 return -EINVAL; in setup_pages_layout()
661 if ((flash_size % layout_page_size) != 0) { in setup_pages_layout()
666 dev_data->layout.pages_size = layout_page_size; in setup_pages_layout()
667 dev_data->layout.pages_count = flash_size / layout_page_size; in setup_pages_layout()
668 LOG_DBG("layout %zu x %zu By pages", dev_data->layout.pages_count, in setup_pages_layout()
669 dev_data->layout.pages_size); in setup_pages_layout()
672 const struct flash_andes_qspi_config *config = dev->config; in setup_pages_layout()
673 const struct flash_pages_layout *layout = &config->layout; in setup_pages_layout()
675 size_t layout_size = layout->pages_size * layout->pages_count; in setup_pages_layout()
677 if (!SPI_NOR_IS_SECTOR_ALIGNED(layout->pages_size)) { in setup_pages_layout()
680 return -EINVAL; in setup_pages_layout()
684 LOG_ERR("device size %zu mismatch %zu * %zu By pages", in setup_pages_layout()
685 flash_size, layout->pages_count, layout->pages_size); in setup_pages_layout()
686 return -EINVAL; in setup_pages_layout()
697 const struct flash_andes_qspi_config *config = dev->config; in qspi_andes_configure()
698 uint32_t base = config->base; in qspi_andes_configure()
700 /* Setting the divisor value to 0xff indicates the SCLK in qspi_andes_configure()
722 return 0; in qspi_andes_configure()
727 struct flash_andes_qspi_data *data = dev->data; in qspi_andes_irq_handler()
728 const struct flash_andes_qspi_config *config = dev->config; in qspi_andes_irq_handler()
729 uint32_t base = config->base; in qspi_andes_irq_handler()
733 uint32_t tx_num = 0, tx_data = 0; in qspi_andes_irq_handler()
743 tx_num = data->tx_fifo_size - cur_tx_fifo_num; in qspi_andes_irq_handler()
745 if (tx_num > data->tx_len) { in qspi_andes_irq_handler()
746 tx_num = data->tx_len; in qspi_andes_irq_handler()
749 for (i = tx_num; i > 0; i--) { in qspi_andes_irq_handler()
750 tx_data = data->tx_buf[data->tx_ptr]; in qspi_andes_irq_handler()
752 data->tx_ptr++; in qspi_andes_irq_handler()
753 if (data->tx_ptr == data->tx_len) { in qspi_andes_irq_handler()
764 for (i = cur_rx_fifo_num; i > 0; i--) { in qspi_andes_irq_handler()
766 data->rx_buf[data->rx_ptr] = rx_data; in qspi_andes_irq_handler()
767 data->rx_ptr++; in qspi_andes_irq_handler()
768 if (data->rx_ptr == data->rx_len) { in qspi_andes_irq_handler()
782 sys_write32(0, QSPI_INTEN(base)); in qspi_andes_irq_handler()
784 k_sem_give(&data->device_sync_sem); in qspi_andes_irq_handler()
792 * @return 0 on success, negative errno code otherwise
796 const struct flash_andes_qspi_config *config = dev->config; in flash_andes_qspi_init()
797 struct flash_andes_qspi_data *dev_data = dev->data; in flash_andes_qspi_init()
798 uint32_t base = config->base; in flash_andes_qspi_init()
800 uint8_t ret, reg = (0x1UL << 6); in flash_andes_qspi_init()
804 if (config->xip) { in flash_andes_qspi_init()
805 return -EINVAL; in flash_andes_qspi_init()
808 k_sem_init(&dev_data->sem, 1, 1); in flash_andes_qspi_init()
809 k_sem_init(&dev_data->device_sync_sem, 0, 1); in flash_andes_qspi_init()
812 dev_data->tx_fifo_size = TX_FIFO_SIZE(base); in flash_andes_qspi_init()
813 dev_data->rx_fifo_size = RX_FIFO_SIZE(base); in flash_andes_qspi_init()
815 config->cfg_func(); in flash_andes_qspi_init()
816 irq_enable(config->irq_num); in flash_andes_qspi_init()
821 if (ret != 0) { in flash_andes_qspi_init()
823 return -ENODEV; in flash_andes_qspi_init()
828 if (memcmp(jedec_id, config->jedec_id, sizeof(jedec_id)) != 0) { in flash_andes_qspi_init()
830 "%02x %02x %02x", jedec_id[0], jedec_id[1], jedec_id[2], in flash_andes_qspi_init()
831 config->jedec_id[0], config->jedec_id[1], config->jedec_id[2]); in flash_andes_qspi_init()
832 return -EINVAL; in flash_andes_qspi_init()
837 if (ret != 0) { in flash_andes_qspi_init()
839 return -ENODEV; in flash_andes_qspi_init()
844 if (ret != 0) { in flash_andes_qspi_init()
846 return -ENODEV; in flash_andes_qspi_init()
853 return 0; in flash_andes_qspi_init()
862 const struct flash_andes_qspi_data *dev_data = dev->data; in flash_andes_qspi_pages_layout()
864 *layout = &dev_data->layout; in flash_andes_qspi_pages_layout()
866 const struct flash_andes_qspi_config *config = dev->config; in flash_andes_qspi_pages_layout()
868 *layout = &config->layout; in flash_andes_qspi_pages_layout()
878 const struct flash_andes_qspi_config *config = dev->config; in flash_andes_qspi_get_parameters()
880 return &config->parameters; in flash_andes_qspi_get_parameters()
941 .erase_value = 0xff \
962 0); \