Skip to content

Commit ca79733

Browse files
anangljhedberg
authored andcommitted
drivers: pinctrl_nrf: Add support for SPIM CSN pin function
Certain SPIM instances in nRF52/53/54L/54H Series provide hardware control of the CSN (chip select) line. Although the standard SPI drivers do not use this feature, it should be possible to configure this line through pinctrl in case some special driver needs this. Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 8e07c77 commit ca79733

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

drivers/pinctrl/pinctrl_nrf.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ static const nrf_gpio_pin_drive_t drive_modes[NRF_DRIVE_COUNT] = {
4646
#define NRF_PSEL_UART(reg, line) ((NRF_UARTE_Type *)reg)->PSEL.line
4747
#endif
4848

49-
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_spi) || defined(CONFIG_NRFX_SPI)
50-
#define NRF_PSEL_SPIM(reg, line) ((NRF_SPI_Type *)reg)->PSEL##line
51-
#elif DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_spim) || defined(CONFIG_NRFX_SPIM)
49+
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_spim) || defined(CONFIG_NRFX_SPIM)
5250
#include <hal/nrf_spim.h>
5351
#define NRF_PSEL_SPIM(reg, line) ((NRF_SPIM_Type *)reg)->PSEL.line
52+
#elif DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_spi) || defined(CONFIG_NRFX_SPI)
53+
#define NRF_PSEL_SPIM(reg, line) ((NRF_SPI_Type *)reg)->PSEL##line
5454
#endif
5555

5656
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_spis) || defined(CONFIG_NRFX_SPIS)
@@ -265,6 +265,14 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt,
265265
dir = NRF_GPIO_PIN_DIR_INPUT;
266266
input = NRF_GPIO_PIN_INPUT_CONNECT;
267267
break;
268+
#if defined(NRF_SPIM_HAS_HW_CSN) && NRF_SPIM_HAS_HW_CSN
269+
case NRF_FUN_SPIM_CSN:
270+
NRF_PSEL_SPIM(reg, CSN) = psel;
271+
write = 1U;
272+
dir = NRF_GPIO_PIN_DIR_OUTPUT;
273+
input = NRF_GPIO_PIN_INPUT_DISCONNECT;
274+
break;
275+
#endif
268276
#endif /* defined(NRF_PSEL_SPIM) */
269277
#if defined(NRF_PSEL_SPIS)
270278
case NRF_FUN_SPIS_SCK:

include/zephyr/dt-bindings/pinctrl/nrf-pinctrl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@
186186
#define NRF_FUN_TDM_SDOUT 76U
187187
/** TDM MCK */
188188
#define NRF_FUN_TDM_MCK 77U
189+
/** SPI master CSN */
190+
#define NRF_FUN_SPIM_CSN 78U
189191

190192
/** @} */
191193

0 commit comments

Comments
 (0)