Lines Matching +full:raw +full:- +full:x +full:- +full:min

4  * SPDX-License-Identifier: Apache-2.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()
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()
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()
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()
310 if ((addr < 0 || addr >= flash_size || ((flash_size - addr) < size))) { in flash_andes_qspi_read()
311 return -EINVAL; in flash_andes_qspi_read()
336 if ((addr < 0 || addr >= flash_size || ((flash_size - addr) < size))) { in flash_andes_qspi_write()
337 return -EINVAL; in flash_andes_qspi_write()
354 to_write = MIN(page_size - (addr % page_size), size); in flash_andes_qspi_write()
363 size -= to_write; in flash_andes_qspi_write()
389 if ((addr < 0 || addr >= flash_size || ((flash_size - addr) < size))) { in flash_andes_qspi_erase()
390 return -EINVAL; in flash_andes_qspi_erase()
397 /* address must be sector-aligned */ in flash_andes_qspi_erase()
399 return -EINVAL; in flash_andes_qspi_erase()
404 return -EINVAL; in flash_andes_qspi_erase()
418 size -= flash_size; 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()
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()
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()
521 LOG_DBG("Erase %u with %02x", 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()
549 uint8_t raw[JESD216_SFDP_SIZE(decl_nph)]; in spi_nor_process_sfdp() member
554 ret = read_sfdp(dev, 0, u_header.raw, sizeof(u_header.raw)); in spi_nor_process_sfdp()
563 LOG_ERR("SFDP magic %08x invalid", magic); 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()
577 LOG_DBG("PH%zu: %04x rev %u.%u: %u DW @ %x", 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()
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()
626 struct flash_andes_qspi_data *dev_data = dev->data; 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()
644 return -ENOTSUP; in setup_pages_layout()
655 return -EINVAL; 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()
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()
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()
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()
784 k_sem_give(&data->device_sync_sem); in qspi_andes_irq_handler()
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()
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()
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()
829 LOG_ERR("Device id %02x %02x %02x does not match config" 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()
839 return -ENODEV; in flash_andes_qspi_init()
846 return -ENODEV; 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()