Skip to content

Commit 69c75c7

Browse files
ananglioannisg
authored andcommitted
drivers: spi: nrfx: Move MISO lines pull configuration to DT
After switching to nrfx 2.0.0, the Kconfig choice options that allowed enabling of pull-up or pull-down for MISO lines in SPIs and SPIMs are not properly supported, they are simply ignored. This commit restores the possibility of applying pull configuration for MISO lines. In earlier nrfx versions, the MISO pull configuration could be only set globally, in nrfx_config files, for all SPI and SPIM instances together. Since nrfx 2.0.0, this configuration can be applied per instance. This commit takes advantage of this possibility and instead of using a common Kconfig option as a global setting for all instances, allows applying individual instance settings via devicetree. Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 2717b28 commit 69c75c7

File tree

5 files changed

+61
-46
lines changed

5 files changed

+61
-46
lines changed

drivers/spi/Kconfig.nrfx

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -247,52 +247,6 @@ config SPI_NRFX_RAM_BUFFER_SIZE
247247
supplying buffers located in flash to the driver, otherwise such
248248
transfers will fail.
249249

250-
choice
251-
prompt "nRF SPIM MISO pin pull configuration"
252-
default SPI_NRFX_SPIM_MISO_PULL_DOWN
253-
254-
config SPI_NRFX_SPIM_MISO_NO_PULL
255-
bool "no pull"
256-
help
257-
Disable MISO pin pull.
258-
259-
config SPI_NRFX_SPIM_MISO_PULL_DOWN
260-
bool "pull down"
261-
help
262-
Enable MISO pin pull down.
263-
264-
config SPI_NRFX_SPIM_MISO_PULL_UP
265-
bool "pull up"
266-
help
267-
Enable MISO pin pull up.
268-
269-
endchoice
270-
271250
endif # NRFX_SPIM
272251

273-
if NRFX_SPI
274-
275-
choice
276-
prompt "nRF SPI MISO pin pull configuration"
277-
default SPI_NRFX_SPI_MISO_PULL_DOWN
278-
279-
config SPI_NRFX_SPI_MISO_NO_PULL
280-
bool "no pull"
281-
help
282-
Disable MISO pin pull.
283-
284-
config SPI_NRFX_SPI_MISO_PULL_DOWN
285-
bool "pull down"
286-
help
287-
Enable MISO pin pull down.
288-
289-
config SPI_NRFX_SPI_MISO_PULL_UP
290-
bool "pull up"
291-
help
292-
Enable MISO pin pull up.
293-
294-
endchoice
295-
296-
endif # NRFX_SPI
297-
298252
endif # SPI_NRFX

drivers/spi/spi_nrfx_spi.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,26 @@ static int spi_nrfx_pm_control(struct device *dev, u32_t ctrl_command,
321321
}
322322
#endif /* CONFIG_DEVICE_POWER_MANAGEMENT */
323323

324+
#define SPI_NRFX_MISO_PULL_DOWN(idx) \
325+
IS_ENABLED(DT_NORDIC_NRF_SPI_SPI_##idx##_MISO_PULL_DOWN)
326+
327+
#define SPI_NRFX_MISO_PULL_UP(idx) \
328+
IS_ENABLED(DT_NORDIC_NRF_SPI_SPI_##idx##_MISO_PULL_UP)
329+
330+
#define SPI_NRFX_MISO_PULL(idx) \
331+
(SPI_NRFX_MISO_PULL_UP(idx) \
332+
? SPI_NRFX_MISO_PULL_DOWN(idx) \
333+
? -1 /* invalid configuration */\
334+
: NRF_GPIO_PIN_PULLUP \
335+
: SPI_NRFX_MISO_PULL_DOWN(idx) \
336+
? NRF_GPIO_PIN_PULLDOWN \
337+
: NRF_GPIO_PIN_NOPULL)
324338

325339
#define SPI_NRFX_SPI_DEVICE(idx) \
340+
BUILD_ASSERT_MSG( \
341+
!SPI_NRFX_MISO_PULL_UP(idx) || !SPI_NRFX_MISO_PULL_DOWN(idx), \
342+
"SPI"#idx \
343+
": cannot enable both pull-up and pull-down on MISO line"); \
326344
static int spi_##idx##_init(struct device *dev) \
327345
{ \
328346
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_SPI##idx), \
@@ -346,6 +364,7 @@ static int spi_nrfx_pm_control(struct device *dev, u32_t ctrl_command,
346364
.frequency = NRF_SPI_FREQ_4M, \
347365
.mode = NRF_SPI_MODE_0, \
348366
.bit_order = NRF_SPI_BIT_ORDER_MSB_FIRST, \
367+
.miso_pull = SPI_NRFX_MISO_PULL(idx), \
349368
} \
350369
}; \
351370
DEVICE_DEFINE(spi_##idx, DT_NORDIC_NRF_SPI_SPI_##idx##_LABEL, \

drivers/spi/spi_nrfx_spim.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,21 @@ static int spim_nrfx_pm_control(struct device *dev, u32_t ctrl_command,
360360
}
361361
#endif /* CONFIG_DEVICE_POWER_MANAGEMENT */
362362

363+
#define SPIM_NRFX_MISO_PULL_DOWN(idx) \
364+
IS_ENABLED(DT_NORDIC_NRF_SPIM_SPI_##idx##_MISO_PULL_DOWN)
365+
366+
#define SPIM_NRFX_MISO_PULL_UP(idx) \
367+
IS_ENABLED(DT_NORDIC_NRF_SPIM_SPI_##idx##_MISO_PULL_UP)
368+
369+
#define SPIM_NRFX_MISO_PULL(idx) \
370+
(SPIM_NRFX_MISO_PULL_UP(idx) \
371+
? SPIM_NRFX_MISO_PULL_DOWN(idx) \
372+
? -1 /* invalid configuration */\
373+
: NRF_GPIO_PIN_PULLUP \
374+
: SPIM_NRFX_MISO_PULL_DOWN(idx) \
375+
? NRF_GPIO_PIN_PULLDOWN \
376+
: NRF_GPIO_PIN_NOPULL)
377+
363378
#define SPI_NRFX_SPIM_EXTENDED_CONFIG(idx) \
364379
COND_CODE_1(IS_ENABLED(NRFX_SPIM_EXTENDED_ENABLED), \
365380
(.dcx_pin = NRFX_SPIM_PIN_NOT_USED, \
@@ -369,6 +384,10 @@ static int spim_nrfx_pm_control(struct device *dev, u32_t ctrl_command,
369384
())
370385

371386
#define SPI_NRFX_SPIM_DEVICE(idx) \
387+
BUILD_ASSERT_MSG( \
388+
!SPIM_NRFX_MISO_PULL_UP(idx) || !SPIM_NRFX_MISO_PULL_DOWN(idx),\
389+
"SPIM"#idx \
390+
": cannot enable both pull-up and pull-down on MISO line"); \
372391
static int spi_##idx##_init(struct device *dev) \
373392
{ \
374393
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_SPIM##idx), \
@@ -393,6 +412,7 @@ static int spim_nrfx_pm_control(struct device *dev, u32_t ctrl_command,
393412
.frequency = NRF_SPIM_FREQ_4M, \
394413
.mode = NRF_SPIM_MODE_0, \
395414
.bit_order = NRF_SPIM_BIT_ORDER_MSB_FIRST, \
415+
.miso_pull = SPIM_NRFX_MISO_PULL(idx), \
396416
SPI_NRFX_SPIM_EXTENDED_CONFIG(idx) \
397417
} \
398418
}; \

dts/bindings/spi/nordic,nrf-spi.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ description: Nordic nRF family SPI (SPI master)
88
compatible: "nordic,nrf-spi"
99

1010
include: nordic,nrf-spi-common.yaml
11+
12+
properties:
13+
miso-pull-up:
14+
type: boolean
15+
required: false
16+
description: Enable pull-up on MISO line
17+
18+
miso-pull-down:
19+
type: boolean
20+
required: false
21+
description: Enable pull-down on MISO line

dts/bindings/spi/nordic,nrf-spim.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ description: Nordic nRF family SPIM (SPI master with EasyDMA)
88
compatible: "nordic,nrf-spim"
99

1010
include: nordic,nrf-spi-common.yaml
11+
12+
properties:
13+
miso-pull-up:
14+
type: boolean
15+
required: false
16+
description: Enable pull-up on MISO line
17+
18+
miso-pull-down:
19+
type: boolean
20+
required: false
21+
description: Enable pull-down on MISO line

0 commit comments

Comments
 (0)