@@ -238,32 +238,6 @@ static int exit_dpd(const struct device *const dev);
238238#define QSPI_IS_SECTOR_ALIGNED (_ofs ) (((_ofs) & (QSPI_SECTOR_SIZE - 1U)) == 0)
239239#define QSPI_IS_BLOCK_ALIGNED (_ofs ) (((_ofs) & (QSPI_BLOCK_SIZE - 1U)) == 0)
240240
241- /**
242- * @brief Converts NRFX return codes to the zephyr ones
243- */
244- static inline int qspi_get_zephyr_ret_code (nrfx_err_t res )
245- {
246- switch (res ) {
247- case NRFX_SUCCESS :
248- return 0 ;
249- case NRFX_ERROR_INVALID_PARAM :
250- case NRFX_ERROR_INVALID_ADDR :
251- return - EINVAL ;
252- case NRFX_ERROR_INVALID_STATE :
253- return - ECANCELED ;
254- #if NRF_ERRATA_STATIC_CHECK (53 , 159 )
255- case NRFX_ERROR_FORBIDDEN :
256- LOG_ERR ("nRF5340 anomaly 159 conditions detected" );
257- LOG_ERR ("Set the CPU clock to 64 MHz before starting QSPI operation" );
258- return - ECANCELED ;
259- #endif
260- case NRFX_ERROR_BUSY :
261- case NRFX_ERROR_TIMEOUT :
262- default :
263- return - EBUSY ;
264- }
265- }
266-
267241static inline void qspi_lock (const struct device * dev )
268242{
269243#ifdef CONFIG_MULTITHREADING
@@ -375,12 +349,11 @@ static void qspi_release(const struct device *dev)
375349 }
376350}
377351
378- static inline void qspi_wait_for_completion (const struct device * dev ,
379- nrfx_err_t res )
352+ static inline void qspi_wait_for_completion (const struct device * dev , int res )
380353{
381354 struct qspi_nor_data * dev_data = dev -> data ;
382355
383- if (res == NRFX_SUCCESS ) {
356+ if (res == 0 ) {
384357#ifdef CONFIG_MULTITHREADING
385358 k_sem_take (& dev_data -> sync , K_FOREVER );
386359#else /* CONFIG_MULTITHREADING */
@@ -476,9 +449,7 @@ static int qspi_send_cmd(const struct device *dev, const struct qspi_cmd *cmd,
476449 .wren = wren ,
477450 };
478451
479- int res = nrfx_qspi_cinstr_xfer (& cinstr_cfg , tx_buf , rx_buf );
480-
481- return qspi_get_zephyr_ret_code (res );
452+ return nrfx_qspi_cinstr_xfer (& cinstr_cfg , tx_buf , rx_buf );
482453}
483454
484455#if !IS_EQUAL (INST_0_QER , JESD216_DW15_QER_VAL_NONE )
@@ -606,7 +577,7 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size)
606577 return rc ;
607578 }
608579 while (size > 0 ) {
609- nrfx_err_t res = ! NRFX_SUCCESS ;
580+ int res = -1 ;
610581 uint32_t adj = 0 ;
611582
612583 if (size == params -> size ) {
@@ -626,11 +597,11 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size)
626597 } else {
627598 /* minimal erase size is at least a sector size */
628599 LOG_ERR ("unsupported at 0x%lx size %zu" , (long )addr , size );
629- res = NRFX_ERROR_INVALID_PARAM ;
600+ res = - EINVAL ;
630601 }
631602
632603 qspi_wait_for_completion (dev , res );
633- if (res == NRFX_SUCCESS ) {
604+ if (res == 0 ) {
634605 addr += adj ;
635606 size -= adj ;
636607
@@ -645,7 +616,7 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size)
645616 }
646617 } else {
647618 LOG_ERR ("erase error at 0x%lx size %zu" , (long )addr , size );
648- rc = qspi_get_zephyr_ret_code ( res ) ;
619+ rc = res ;
649620 break ;
650621 }
651622 }
@@ -780,39 +751,39 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset,
780751 .io2_level = true,
781752 .io3_level = true,
782753 };
783- nrfx_err_t res ;
754+ int res ;
784755
785756 qspi_acquire (dev );
786757
787758 res = nrfx_qspi_lfm_start (& cinstr_cfg );
788- if (res != NRFX_SUCCESS ) {
759+ if (res != 0 ) {
789760 LOG_DBG ("lfm_start: %x" , res );
790761 goto out ;
791762 }
792763
793764 res = nrfx_qspi_lfm_xfer (addr_buf , NULL , sizeof (addr_buf ), false);
794- if (res != NRFX_SUCCESS ) {
765+ if (res != 0 ) {
795766 LOG_DBG ("lfm_xfer addr: %x" , res );
796767 goto out ;
797768 }
798769
799770 res = nrfx_qspi_lfm_xfer (NULL , data , len , true);
800- if (res != NRFX_SUCCESS ) {
771+ if (res != 0 ) {
801772 LOG_DBG ("lfm_xfer read: %x" , res );
802773 goto out ;
803774 }
804775
805776out :
806777 qspi_release (dev );
807778
808- return qspi_get_zephyr_ret_code ( res ) ;
779+ return res ;
809780}
810781
811782#endif /* CONFIG_FLASH_JESD216_API */
812783
813- static inline nrfx_err_t read_non_aligned (const struct device * dev ,
814- off_t addr ,
815- void * dest , size_t size )
784+ static inline int read_non_aligned (const struct device * dev ,
785+ off_t addr ,
786+ void * dest , size_t size )
816787{
817788 uint8_t __aligned (WORD_SIZE ) buf [WORD_SIZE * 2 ];
818789 uint8_t * dptr = dest ;
@@ -839,14 +810,14 @@ static inline nrfx_err_t read_non_aligned(const struct device *dev,
839810 flash_suffix = size - flash_prefix - flash_middle ;
840811 }
841812
842- nrfx_err_t res = NRFX_SUCCESS ;
813+ int res = 0 ;
843814
844815 /* read from aligned flash to aligned memory */
845816 if (flash_middle != 0 ) {
846817 res = nrfx_qspi_read (dptr + dest_prefix , flash_middle ,
847818 addr + flash_prefix );
848819 qspi_wait_for_completion (dev , res );
849- if (res != NRFX_SUCCESS ) {
820+ if (res != 0 ) {
850821 return res ;
851822 }
852823
@@ -861,7 +832,7 @@ static inline nrfx_err_t read_non_aligned(const struct device *dev,
861832 res = nrfx_qspi_read (buf , WORD_SIZE , addr -
862833 (WORD_SIZE - flash_prefix ));
863834 qspi_wait_for_completion (dev , res );
864- if (res != NRFX_SUCCESS ) {
835+ if (res != 0 ) {
865836 return res ;
866837 }
867838 memcpy (dptr , buf + WORD_SIZE - flash_prefix , flash_prefix );
@@ -872,7 +843,7 @@ static inline nrfx_err_t read_non_aligned(const struct device *dev,
872843 res = nrfx_qspi_read (buf , WORD_SIZE * 2 ,
873844 addr + flash_prefix + flash_middle );
874845 qspi_wait_for_completion (dev , res );
875- if (res != NRFX_SUCCESS ) {
846+ if (res != 0 ) {
876847 return res ;
877848 }
878849 memcpy (dptr + flash_prefix + flash_middle , buf , flash_suffix );
@@ -885,7 +856,7 @@ static int qspi_nor_read(const struct device *dev, off_t addr, void *dest,
885856 size_t size )
886857{
887858 const struct qspi_nor_config * params = dev -> config ;
888- nrfx_err_t res ;
859+ int res ;
889860
890861 if (!dest ) {
891862 return - EINVAL ;
@@ -911,23 +882,23 @@ static int qspi_nor_read(const struct device *dev, off_t addr, void *dest,
911882
912883 qspi_release (dev );
913884
914- return qspi_get_zephyr_ret_code ( res ) ;
885+ return res ;
915886}
916887
917888/* addr aligned, sptr not null, slen less than 4 */
918- static inline nrfx_err_t write_sub_word (const struct device * dev , off_t addr ,
919- const void * sptr , size_t slen )
889+ static inline int write_sub_word (const struct device * dev , off_t addr ,
890+ const void * sptr , size_t slen )
920891{
921892 uint8_t __aligned (4 ) buf [4 ];
922- nrfx_err_t res ;
893+ int res ;
923894
924895 /* read out the whole word so that unchanged data can be
925896 * written back
926897 */
927898 res = nrfx_qspi_read (buf , sizeof (buf ), addr );
928899 qspi_wait_for_completion (dev , res );
929900
930- if (res == NRFX_SUCCESS ) {
901+ if (res == 0 ) {
931902 memcpy (buf , sptr , slen );
932903 res = nrfx_qspi_write (buf , sizeof (buf ), addr );
933904 qspi_wait_for_completion (dev , res );
@@ -944,30 +915,30 @@ BUILD_ASSERT((CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE % 4) == 0,
944915 *
945916 * If not enabled return the error the peripheral would have produced.
946917 */
947- static nrfx_err_t write_through_buffer (const struct device * dev , off_t addr ,
918+ static int write_through_buffer (const struct device * dev , off_t addr ,
948919 const void * sptr , size_t slen )
949920{
950- nrfx_err_t res = NRFX_SUCCESS ;
921+ int res = 0 ;
951922
952923 if (CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE > 0 ) {
953924 uint8_t __aligned (4 ) buf [CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE ];
954925 const uint8_t * sp = sptr ;
955926
956- while ((slen > 0 ) && (res == NRFX_SUCCESS )) {
927+ while ((slen > 0 ) && (res == 0 )) {
957928 size_t len = MIN (slen , sizeof (buf ));
958929
959930 memcpy (buf , sp , len );
960931 res = nrfx_qspi_write (buf , len , addr );
961932 qspi_wait_for_completion (dev , res );
962933
963- if (res == NRFX_SUCCESS ) {
934+ if (res == 0 ) {
964935 slen -= len ;
965936 sp += len ;
966937 addr += len ;
967938 }
968939 }
969940 } else {
970- res = NRFX_ERROR_INVALID_ADDR ;
941+ res = - EACCES ;
971942 }
972943 return res ;
973944}
@@ -1006,19 +977,15 @@ static int qspi_nor_write(const struct device *dev, off_t addr,
1006977
1007978 rc = qspi_nor_write_protection_set (dev , false);
1008979 if (rc == 0 ) {
1009- nrfx_err_t res ;
1010-
1011980 if (size < 4U ) {
1012- res = write_sub_word (dev , addr , src , size );
981+ rc = write_sub_word (dev , addr , src , size );
1013982 } else if (!nrfx_is_in_ram (src ) ||
1014983 !nrfx_is_word_aligned (src )) {
1015- res = write_through_buffer (dev , addr , src , size );
984+ rc = write_through_buffer (dev , addr , src , size );
1016985 } else {
1017- res = nrfx_qspi_write (src , size , addr );
1018- qspi_wait_for_completion (dev , res );
986+ rc = nrfx_qspi_write (src , size , addr );
987+ qspi_wait_for_completion (dev , rc );
1019988 }
1020-
1021- rc = qspi_get_zephyr_ret_code (res );
1022989 }
1023990
1024991 rc2 = qspi_nor_write_protection_set (dev , true);
@@ -1080,11 +1047,9 @@ static int qspi_init(const struct device *dev)
10801047{
10811048 const struct qspi_nor_config * dev_config = dev -> config ;
10821049 uint8_t id [SPI_NOR_MAX_ID_LEN ];
1083- nrfx_err_t res ;
10841050 int rc ;
10851051
1086- res = nrfx_qspi_init (& dev_config -> nrfx_cfg , qspi_handler , dev -> data );
1087- rc = qspi_get_zephyr_ret_code (res );
1052+ rc = nrfx_qspi_init (& dev_config -> nrfx_cfg , qspi_handler , dev -> data );
10881053 if (rc < 0 ) {
10891054 return rc ;
10901055 }
@@ -1269,15 +1234,14 @@ static int exit_dpd(const struct device *const dev)
12691234 .op_code = SPI_NOR_CMD_RDPD ,
12701235 };
12711236 uint32_t t_exit_dpd = DT_INST_PROP_OR (0 , t_exit_dpd , 0 );
1272- nrfx_err_t res ;
12731237 int rc ;
12741238
12751239 nrf_qspi_pins_get (NRF_QSPI , & pins );
12761240 nrf_qspi_pins_set (NRF_QSPI , & disconnected_pins );
1277- res = nrfx_qspi_activate (true);
1241+ rc = nrfx_qspi_activate (true);
12781242 nrf_qspi_pins_set (NRF_QSPI , & pins );
12791243
1280- if (res != NRFX_SUCCESS ) {
1244+ if (rc != 0 ) {
12811245 return - EIO ;
12821246 }
12831247
@@ -1301,11 +1265,10 @@ static int exit_dpd(const struct device *const dev)
13011265static int qspi_suspend (const struct device * dev )
13021266{
13031267 const struct qspi_nor_config * dev_config = dev -> config ;
1304- nrfx_err_t res ;
13051268 int rc ;
13061269
1307- res = nrfx_qspi_mem_busy_check ();
1308- if (res != NRFX_SUCCESS ) {
1270+ rc = nrfx_qspi_mem_busy_check ();
1271+ if (rc != - ) {
13091272 return - EBUSY ;
13101273 }
13111274
@@ -1322,17 +1285,16 @@ static int qspi_suspend(const struct device *dev)
13221285static int qspi_resume (const struct device * dev )
13231286{
13241287 const struct qspi_nor_config * dev_config = dev -> config ;
1325- nrfx_err_t res ;
13261288 int rc ;
13271289
13281290 rc = pinctrl_apply_state (dev_config -> pcfg , PINCTRL_STATE_DEFAULT );
13291291 if (rc < 0 ) {
13301292 return rc ;
13311293 }
13321294
1333- res = nrfx_qspi_init (& dev_config -> nrfx_cfg , qspi_handler , dev -> data );
1334- if (res != NRFX_SUCCESS ) {
1335- return - EIO ;
1295+ rc = nrfx_qspi_init (& dev_config -> nrfx_cfg , qspi_handler , dev -> data );
1296+ if (rc < 0 ) {
1297+ return rc ;
13361298 }
13371299
13381300 return exit_dpd (dev );
0 commit comments