@@ -21,6 +21,7 @@ LOG_MODULE_REGISTER(qspi_nor, CONFIG_FLASH_LOG_LEVEL);
2121#include "flash_priv.h"
2222#include <nrfx_qspi.h>
2323#include <hal/nrf_clock.h>
24+ #include <hal/nrf_gpio.h>
2425
2526struct qspi_nor_data {
2627#ifdef CONFIG_MULTITHREADING
@@ -30,10 +31,8 @@ struct qspi_nor_data {
3031 struct k_sem sem ;
3132 /* The semaphore to indicate that transfer has completed. */
3233 struct k_sem sync ;
33- #if NRF52_ERRATA_122_PRESENT
3434 /* The semaphore to control driver init/uninit. */
3535 struct k_sem count ;
36- #endif
3736#else /* CONFIG_MULTITHREADING */
3837 /* A flag that signals completed transfer when threads are
3938 * not enabled.
@@ -176,19 +175,10 @@ BUILD_ASSERT(DT_INST_PROP(0, address_size_32),
176175 "After entering 4 byte addressing mode, 4 byte addressing is expected" );
177176#endif
178177
178+ static bool qspi_initialized ;
179179
180-
181- #if NRF52_ERRATA_122_PRESENT
182- #include <hal/nrf_gpio.h>
183- static int anomaly_122_init (const struct device * dev );
184- static void anomaly_122_uninit (const struct device * dev );
185-
186- #define ANOMALY_122_INIT (dev ) anomaly_122_init(dev)
187- #define ANOMALY_122_UNINIT (dev ) anomaly_122_uninit(dev)
188- #else
189- #define ANOMALY_122_INIT (dev ) 0
190- #define ANOMALY_122_UNINIT (dev )
191- #endif
180+ static int qspi_device_init (const struct device * dev );
181+ static void qspi_device_uninit (const struct device * dev );
192182
193183#define WORD_SIZE 4
194184
@@ -361,23 +351,16 @@ static void qspi_handler(nrfx_qspi_evt_t event, void *p_context)
361351 }
362352}
363353
364- #if NRF52_ERRATA_122_PRESENT
365- static bool qspi_initialized ;
366-
367- static int anomaly_122_init (const struct device * dev )
354+ static int qspi_device_init (const struct device * dev )
368355{
369356 struct qspi_nor_data * dev_data = dev -> data ;
370357 nrfx_err_t res ;
371358 int ret = 0 ;
372359
373- if (!nrf52_errata_122 ()) {
374- return 0 ;
375- }
376-
377360 qspi_lock (dev );
378361
379- /* In multithreading, driver can call anomaly_122_init more than once
380- * before calling anomaly_122_uninit . Keepping count, so QSPI is
362+ /* In multithreading, driver can call qspi_device_init more than once
363+ * before calling qspi_device_uninit . Keepping count, so QSPI is
381364 * uninitialized only at the last call (count == 0).
382365 */
383366#ifdef CONFIG_MULTITHREADING
@@ -399,14 +382,10 @@ static int anomaly_122_init(const struct device *dev)
399382 return ret ;
400383}
401384
402- static void anomaly_122_uninit (const struct device * dev )
385+ static void qspi_device_uninit (const struct device * dev )
403386{
404387 bool last = true;
405388
406- if (!nrf52_errata_122 ()) {
407- return ;
408- }
409-
410389 qspi_lock (dev );
411390
412391#ifdef CONFIG_MULTITHREADING
@@ -438,8 +417,6 @@ static void anomaly_122_uninit(const struct device *dev)
438417
439418 qspi_unlock (dev );
440419}
441- #endif /* NRF52_ERRATA_122_PRESENT */
442-
443420
444421/* QSPI send custom command.
445422 *
@@ -629,7 +606,7 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size)
629606 int rv = 0 ;
630607 const struct qspi_nor_config * params = dev -> config ;
631608
632- rv = ANOMALY_122_INIT (dev );
609+ rv = qspi_device_init (dev );
633610 if (rv != 0 ) {
634611 goto out ;
635612 }
@@ -685,7 +662,7 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size)
685662 qspi_trans_unlock (dev );
686663
687664out :
688- ANOMALY_122_UNINIT (dev );
665+ qspi_device_uninit (dev );
689666 return rv ;
690667}
691668
@@ -807,12 +784,12 @@ static int qspi_read_jedec_id(const struct device *dev,
807784 .rx_buf = & rx_buf ,
808785 };
809786
810- int ret = ANOMALY_122_INIT (dev );
787+ int ret = qspi_device_init (dev );
811788
812789 if (ret == 0 ) {
813790 ret = qspi_send_cmd (dev , & cmd , false);
814791 }
815- ANOMALY_122_UNINIT (dev );
792+ qspi_device_uninit (dev );
816793
817794 return ret ;
818795}
@@ -837,12 +814,12 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset,
837814 .io3_level = true,
838815 };
839816
840- int ret = ANOMALY_122_INIT (dev );
817+ int ret = qspi_device_init (dev );
841818 nrfx_err_t res = NRFX_SUCCESS ;
842819
843820 if (ret != 0 ) {
844- LOG_DBG ("ANOMALY_122_INIT : %d" , ret );
845- ANOMALY_122_UNINIT (dev );
821+ LOG_DBG ("qspi_device_init : %d" , ret );
822+ qspi_device_uninit (dev );
846823 return ret ;
847824 }
848825
@@ -867,7 +844,7 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset,
867844
868845out :
869846 qspi_unlock (dev );
870- ANOMALY_122_UNINIT (dev );
847+ qspi_device_uninit (dev );
871848 return qspi_get_zephyr_ret_code (res );
872849}
873850
@@ -994,7 +971,7 @@ static int qspi_nor_read(const struct device *dev, off_t addr, void *dest,
994971 return - EINVAL ;
995972 }
996973
997- int rc = ANOMALY_122_INIT (dev );
974+ int rc = qspi_device_init (dev );
998975
999976 if (rc != 0 ) {
1000977 goto out ;
@@ -1009,7 +986,7 @@ static int qspi_nor_read(const struct device *dev, off_t addr, void *dest,
1009986 rc = qspi_get_zephyr_ret_code (res );
1010987
1011988out :
1012- ANOMALY_122_UNINIT (dev );
989+ qspi_device_uninit (dev );
1013990 return rc ;
1014991}
1015992
@@ -1102,7 +1079,7 @@ static int qspi_nor_write(const struct device *dev, off_t addr,
11021079
11031080 nrfx_err_t res = NRFX_SUCCESS ;
11041081
1105- int rc = ANOMALY_122_INIT (dev );
1082+ int rc = qspi_device_init (dev );
11061083
11071084 if (rc != 0 ) {
11081085 goto out ;
@@ -1132,7 +1109,7 @@ static int qspi_nor_write(const struct device *dev, off_t addr,
11321109
11331110 rc = qspi_get_zephyr_ret_code (res );
11341111out :
1135- ANOMALY_122_UNINIT (dev );
1112+ qspi_device_uninit (dev );
11361113 return rc ;
11371114}
11381115
@@ -1184,7 +1161,7 @@ static int qspi_nor_configure(const struct device *dev)
11841161 return ret ;
11851162 }
11861163
1187- ANOMALY_122_UNINIT (dev );
1164+ qspi_device_uninit (dev );
11881165
11891166 /* now the spi bus is configured, we can verify the flash id */
11901167 if (qspi_nor_read_id (dev ) != 0 ) {
@@ -1335,7 +1312,7 @@ static int qspi_nor_pm_action(const struct device *dev,
13351312
13361313 switch (action ) {
13371314 case PM_DEVICE_ACTION_SUSPEND :
1338- ret = ANOMALY_122_INIT (dev );
1315+ ret = qspi_device_init (dev );
13391316 if (ret < 0 ) {
13401317 return ret ;
13411318 }
@@ -1379,7 +1356,7 @@ static int qspi_nor_pm_action(const struct device *dev,
13791356 return ret ;
13801357 }
13811358
1382- ANOMALY_122_UNINIT (dev );
1359+ qspi_device_uninit (dev );
13831360 break ;
13841361
13851362 default :
@@ -1429,9 +1406,7 @@ static struct qspi_nor_data qspi_nor_dev_data = {
14291406 .trans = Z_SEM_INITIALIZER (qspi_nor_dev_data .trans , 1 , 1 ),
14301407 .sem = Z_SEM_INITIALIZER (qspi_nor_dev_data .sem , 1 , 1 ),
14311408 .sync = Z_SEM_INITIALIZER (qspi_nor_dev_data .sync , 0 , 1 ),
1432- #if NRF52_ERRATA_122_PRESENT
14331409 .count = Z_SEM_INITIALIZER (qspi_nor_dev_data .count , 0 , K_SEM_MAX_LIMIT ),
1434- #endif
14351410#endif /* CONFIG_MULTITHREADING */
14361411};
14371412
0 commit comments