@@ -588,6 +588,69 @@ static int qspi_nrfx_configure(const struct device *dev)
588588 return ret ;
589589}
590590
591+ static int qspi_read_jedec_id (const struct device * dev ,
592+ uint8_t * id )
593+ {
594+ const struct qspi_buf rx_buf = {
595+ .buf = id ,
596+ .len = 3
597+ };
598+ const struct qspi_cmd cmd = {
599+ .op_code = SPI_NOR_CMD_RDID ,
600+ .rx_buf = & rx_buf ,
601+ };
602+
603+ return qspi_send_cmd (dev , & cmd , false);
604+ }
605+
606+ #if defined(CONFIG_FLASH_JESD216_API )
607+
608+ static int qspi_sfdp_read (const struct device * dev , off_t offset ,
609+ void * data , size_t len )
610+ {
611+ __ASSERT (data != NULL , "null destination" );
612+
613+ uint8_t addr_buf [] = {
614+ offset >> 16 ,
615+ offset >> 8 ,
616+ offset ,
617+ 0 , /* wait state */
618+ };
619+ nrf_qspi_cinstr_conf_t cinstr_cfg = {
620+ .opcode = JESD216_CMD_READ_SFDP ,
621+ .length = NRF_QSPI_CINSTR_LEN_1B ,
622+ .io2_level = true,
623+ .io3_level = true,
624+ };
625+
626+ qspi_lock (dev );
627+
628+ int res = nrfx_qspi_lfm_start (& cinstr_cfg );
629+
630+ if (res != NRFX_SUCCESS ) {
631+ LOG_DBG ("lfm_start: %x" , res );
632+ goto out ;
633+ }
634+
635+ res = nrfx_qspi_lfm_xfer (addr_buf , NULL , sizeof (addr_buf ), false);
636+ if (res != NRFX_SUCCESS ) {
637+ LOG_DBG ("lfm_xfer addr: %x" , res );
638+ goto out ;
639+ }
640+
641+ res = nrfx_qspi_lfm_xfer (NULL , data , len , true);
642+ if (res != NRFX_SUCCESS ) {
643+ LOG_DBG ("lfm_xfer read: %x" , res );
644+ goto out ;
645+ }
646+
647+ out :
648+ qspi_unlock (dev );
649+ return qspi_get_zephyr_ret_code (res );
650+ }
651+
652+ #endif /* CONFIG_FLASH_JESD216_API */
653+
591654/**
592655 * @brief Retrieve the Flash JEDEC ID and compare it with the one expected
593656 *
@@ -599,25 +662,17 @@ static int qspi_nrfx_configure(const struct device *dev)
599662static inline int qspi_nor_read_id (const struct device * dev ,
600663 const struct qspi_nor_config * const flash_id )
601664{
602- uint8_t rx_b [SPI_NOR_MAX_ID_LEN ];
603- const struct qspi_buf q_rx_buf = {
604- .buf = rx_b ,
605- .len = sizeof (rx_b ),
606- };
607- const struct qspi_cmd cmd = {
608- .op_code = SPI_NOR_CMD_RDID ,
609- .rx_buf = & q_rx_buf ,
610- .tx_buf = NULL
611- };
665+ uint8_t id [SPI_NOR_MAX_ID_LEN ];
666+ int ret = qspi_read_jedec_id (dev , id );
612667
613- if (qspi_send_cmd ( dev , & cmd , false) != 0 ) {
668+ if (ret != 0 ) {
614669 return - EIO ;
615670 }
616671
617- if (memcmp (flash_id -> id , rx_b , SPI_NOR_MAX_ID_LEN ) != 0 ) {
618- LOG_ERR ("flash id error. Extected: [%d %d %d], got: [%d %d %d ]" ,
619- flash_id -> id [0 ], flash_id -> id [1 ], flash_id -> id [2 ],
620- rx_b [0 ], rx_b [1 ], rx_b [2 ]);
672+ if (memcmp (flash_id -> id , id , SPI_NOR_MAX_ID_LEN ) != 0 ) {
673+ LOG_ERR ("JEDEC id [%02x %02x %02x] expect [%02x %02x %02x ]" ,
674+ id [0 ], id [1 ], id [2 ],
675+ flash_id -> id [0 ], flash_id -> id [1 ], flash_id -> id [2 ]);
621676 return - ENODEV ;
622677 }
623678
@@ -972,6 +1027,10 @@ static const struct flash_driver_api qspi_nor_api = {
9721027#if defined(CONFIG_FLASH_PAGE_LAYOUT )
9731028 .page_layout = qspi_nor_pages_layout ,
9741029#endif
1030+ #if defined(CONFIG_FLASH_JESD216_API )
1031+ .sfdp_read = qspi_sfdp_read ,
1032+ .read_jedec_id = qspi_read_jedec_id ,
1033+ #endif /* CONFIG_FLASH_JESD216_API */
9751034};
9761035
9771036
0 commit comments