1414#include <zephyr/mem_mgmt/mem_attr.h>
1515#include <soc.h>
1616#include <dmm.h>
17- #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
18- #include <nrfx_ppi.h>
19- #endif
2017#ifdef CONFIG_SOC_NRF5340_CPUAPP
2118#include <hal/nrf_clock.h>
2219#endif
@@ -31,12 +28,6 @@ LOG_MODULE_REGISTER(spi_nrfx_spim, CONFIG_SPI_LOG_LEVEL);
3128#include "spi_context.h"
3229#include "spi_nrfx_common.h"
3330
34- #if defined(CONFIG_SOC_NRF52832 ) && !defined(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 )
35- #error This driver is not available by default for nRF52832 because of Product Anomaly 58 \
36- (SPIM: An additional byte is clocked out when RXD.MAXCNT == 1 and TXD.MAXCNT <= 1). \
37- Use CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58=y to override this limitation.
38- #endif
39-
4031#if (CONFIG_SPI_NRFX_RAM_BUFFER_SIZE > 0 )
4132#define SPI_BUFFER_IN_RAM 1
4233#endif
@@ -112,11 +103,6 @@ struct spi_nrfx_data {
112103 uint8_t * tx_buffer ;
113104 uint8_t * rx_buffer ;
114105#endif
115- #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
116- bool anomaly_58_workaround_active ;
117- uint8_t ppi_ch ;
118- uint8_t gpiote_ch ;
119- #endif
120106#ifdef SPIM_ANY_FAST
121107 bool clock_requested ;
122108#endif
@@ -129,9 +115,6 @@ struct spi_nrfx_config {
129115 void (* irq_connect )(void );
130116 uint16_t max_chunk_len ;
131117 const struct pinctrl_dev_config * pcfg ;
132- #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
133- bool anomaly_58_workaround ;
134- #endif
135118 uint32_t wake_pin ;
136119 nrfx_gpiote_t wake_gpiote ;
137120#ifdef SPIM_ANY_FAST
@@ -384,89 +367,6 @@ static int configure(const struct device *dev,
384367 return 0 ;
385368}
386369
387- #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
388- static const nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE (0 );
389-
390- /*
391- * Brief Workaround for transmitting 1 byte with SPIM.
392- *
393- * Derived from the setup_workaround_for_ftpan_58() function from
394- * the nRF52832 Rev 1 Errata v1.6 document anomaly 58 workaround.
395- *
396- * Warning Must not be used when transmitting multiple bytes.
397- *
398- * Warning After this workaround is used, the user must reset the PPI
399- * channel and the GPIOTE channel before attempting to transmit multiple
400- * bytes.
401- */
402- static void anomaly_58_workaround_setup (const struct device * dev )
403- {
404- struct spi_nrfx_data * dev_data = dev -> data ;
405- const struct spi_nrfx_config * dev_config = dev -> config ;
406- NRF_SPIM_Type * spim = dev_config -> spim .p_reg ;
407- uint32_t ppi_ch = dev_data -> ppi_ch ;
408- uint32_t gpiote_ch = dev_data -> gpiote_ch ;
409- uint32_t eep = (uint32_t )& gpiote .p_reg -> EVENTS_IN [gpiote_ch ];
410- uint32_t tep = (uint32_t )& spim -> TASKS_STOP ;
411-
412- dev_data -> anomaly_58_workaround_active = true;
413-
414- /* Create an event when SCK toggles */
415- nrf_gpiote_event_configure (gpiote .p_reg , gpiote_ch , spim -> PSEL .SCK ,
416- GPIOTE_CONFIG_POLARITY_Toggle );
417- nrf_gpiote_event_enable (gpiote .p_reg , gpiote_ch );
418-
419- /* Stop the spim instance when SCK toggles */
420- nrf_ppi_channel_endpoint_setup (NRF_PPI , ppi_ch , eep , tep );
421- nrf_ppi_channel_enable (NRF_PPI , ppi_ch );
422-
423- /* The spim instance cannot be stopped mid-byte, so it will finish
424- * transmitting the first byte and then stop. Effectively ensuring
425- * that only 1 byte is transmitted.
426- */
427- }
428-
429- static void anomaly_58_workaround_clear (struct spi_nrfx_data * dev_data )
430- {
431- uint32_t ppi_ch = dev_data -> ppi_ch ;
432- uint32_t gpiote_ch = dev_data -> gpiote_ch ;
433-
434- if (dev_data -> anomaly_58_workaround_active ) {
435- nrf_ppi_channel_disable (NRF_PPI , ppi_ch );
436- nrf_gpiote_task_disable (gpiote .p_reg , gpiote_ch );
437-
438- dev_data -> anomaly_58_workaround_active = false;
439- }
440- }
441-
442- static int anomaly_58_workaround_init (const struct device * dev )
443- {
444- struct spi_nrfx_data * dev_data = dev -> data ;
445- const struct spi_nrfx_config * dev_config = dev -> config ;
446- nrfx_err_t err_code ;
447-
448- dev_data -> anomaly_58_workaround_active = false;
449-
450- if (dev_config -> anomaly_58_workaround ) {
451- err_code = nrfx_ppi_channel_alloc (& dev_data -> ppi_ch );
452- if (err_code != NRFX_SUCCESS ) {
453- LOG_ERR ("Failed to allocate PPI channel" );
454- return - ENODEV ;
455- }
456-
457- err_code = nrfx_gpiote_channel_alloc (& gpiote , & dev_data -> gpiote_ch );
458- if (err_code != NRFX_SUCCESS ) {
459- LOG_ERR ("Failed to allocate GPIOTE channel" );
460- return - ENODEV ;
461- }
462- LOG_DBG ("PAN 58 workaround enabled for %s: ppi %u, gpiote %u" ,
463- dev -> name , dev_data -> ppi_ch , dev_data -> gpiote_ch );
464- }
465-
466- return 0 ;
467- }
468- #endif
469-
470370static void finish_transaction (const struct device * dev , int error )
471371{
472372 struct spi_nrfx_data * dev_data = dev -> data ;
@@ -544,26 +444,9 @@ static void transfer_next_chunk(const struct device *dev)
544444 goto in_alloc_failed ;
545445 }
546446
547- #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
548- if (xfer .rx_length == 1 && xfer .tx_length <= 1 ) {
549- if (dev_config -> anomaly_58_workaround ) {
550- anomaly_58_workaround_setup (dev );
551- } else {
552- LOG_WRN ("Transaction aborted since it would trigger "
553- "nRF52832 PAN 58" );
554- error = - EIO ;
555- }
556- }
557- #endif
558- if (error == 0 ) {
559- result = nrfx_spim_xfer (& dev_config -> spim , & xfer , 0 );
560- if (result == NRFX_SUCCESS ) {
561- return ;
562- }
563- error = - EIO ;
564- #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
565- anomaly_58_workaround_clear (dev_data );
566- #endif
447+ result = nrfx_spim_xfer (& dev_config -> spim , & xfer , 0 );
448+ if (result == NRFX_SUCCESS ) {
449+ return ;
567450 }
568451
569452 /* On nrfx_spim_xfer() error */
@@ -592,10 +475,6 @@ static void event_handler(const nrfx_spim_evt_t *p_event, void *p_context)
592475 return ;
593476 }
594477
595- #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
596- anomaly_58_workaround_clear (dev_data );
597- #endif
598-
599478 if (spi_context_tx_buf_on (& dev_data -> ctx )) {
600479 dmm_buffer_out_release (dev_config -> mem_reg ,
601480 (void * * )p_event -> xfer_desc .p_tx_buffer );
@@ -693,9 +572,6 @@ static int transceive(const struct device *dev,
693572#else
694573 dev_data -> ctx .ready = 0 ;
695574#endif /* CONFIG_MULTITHREADING */
696- #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
697- anomaly_58_workaround_clear (dev_data );
698- #endif
699575 } else if (error ) {
700576 finalize_spi_transaction (dev , true);
701577 }
@@ -867,12 +743,6 @@ static int spi_nrfx_init(const struct device *dev)
867743
868744 spi_context_unlock_unconditionally (& dev_data -> ctx );
869745
870- #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
871- err = anomaly_58_workaround_init (dev );
872- if (err < 0 ) {
873- return err ;
874- }
875- #endif
876746 return pm_device_driver_init (dev , spim_nrfx_pm_action );
877747}
878748
@@ -957,10 +827,6 @@ static int spi_nrfx_deinit(const struct device *dev)
957827 .irq_connect = irq_connect##idx, \
958828 .pcfg = PINCTRL_DT_DEV_CONFIG_GET(SPIM(idx)), \
959829 .max_chunk_len = BIT_MASK(SPIM_PROP(idx, easydma_maxcnt_bits)),\
960- COND_CODE_1(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58, \
961- (.anomaly_58_workaround = \
962- SPIM_PROP(idx, anomaly_58_workaround),), \
963- ()) \
964830 .wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(SPIM(idx), wake_gpios, \
965831 WAKE_PIN_NOT_USED), \
966832 .wake_gpiote = WAKE_GPIOTE_INSTANCE(SPIM(idx)), \
0 commit comments