From ffcf7cad6a906b3286917b02a07303b600f24754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Fri, 6 Mar 2020 15:56:30 -0800 Subject: [PATCH] drivers: spi: convert spi_nrfx_spim.c to new DT API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to start using DT_NODELABEL() to access SPIMs that way, instead of via an alias. Signed-off-by: Martí Bolívar --- drivers/spi/spi_nrfx_spim.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index 1a2e1dbf497..7182a295359 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -366,11 +366,17 @@ static int spim_nrfx_pm_control(struct device *dev, u32_t ctrl_command, } #endif /* CONFIG_DEVICE_POWER_MANAGEMENT */ -#define SPIM_NRFX_MISO_PULL_DOWN(idx) \ - IS_ENABLED(DT_NORDIC_NRF_SPIM_SPI_##idx##_MISO_PULL_DOWN) +/* + * We use NODELABEL here because the nrfx API requires us to call + * functions which are named according to SoC peripheral instance + * being operated on. Since DT_INST() makes no guarantees about that, + * it won't work. + */ +#define SPIM(idx) DT_NODELABEL(spi##idx) +#define SPIM_PROP(idx, prop) DT_PROP(SPIM(idx), prop) -#define SPIM_NRFX_MISO_PULL_UP(idx) \ - IS_ENABLED(DT_NORDIC_NRF_SPIM_SPI_##idx##_MISO_PULL_UP) +#define SPIM_NRFX_MISO_PULL_DOWN(idx) DT_PROP(SPIM(idx), miso_pull_down) +#define SPIM_NRFX_MISO_PULL_UP(idx) DT_PROP(SPIM(idx), miso_pull_up) #define SPIM_NRFX_MISO_PULL(idx) \ (SPIM_NRFX_MISO_PULL_UP(idx) \ @@ -396,7 +402,7 @@ static int spim_nrfx_pm_control(struct device *dev, u32_t ctrl_command, static int spi_##idx##_init(struct device *dev) \ { \ IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_SPIM##idx), \ - DT_NORDIC_NRF_SPIM_SPI_##idx##_IRQ_0_PRIORITY, \ + DT_IRQ(SPIM(idx), priority), \ nrfx_isr, nrfx_spim_##idx##_irq_handler, 0); \ return init_spim(dev); \ } \ @@ -409,9 +415,9 @@ static int spim_nrfx_pm_control(struct device *dev, u32_t ctrl_command, .spim = NRFX_SPIM_INSTANCE(idx), \ .max_chunk_len = (1 << SPIM##idx##_EASYDMA_MAXCNT_SIZE) - 1, \ .config = { \ - .sck_pin = DT_NORDIC_NRF_SPIM_SPI_##idx##_SCK_PIN, \ - .mosi_pin = DT_NORDIC_NRF_SPIM_SPI_##idx##_MOSI_PIN, \ - .miso_pin = DT_NORDIC_NRF_SPIM_SPI_##idx##_MISO_PIN, \ + .sck_pin = SPIM_PROP(idx, sck_pin), \ + .mosi_pin = SPIM_PROP(idx, mosi_pin), \ + .miso_pin = SPIM_PROP(idx, miso_pin), \ .ss_pin = NRFX_SPIM_PIN_NOT_USED, \ .orc = CONFIG_SPI_##idx##_NRF_ORC, \ .frequency = NRF_SPIM_FREQ_4M, \ @@ -422,7 +428,7 @@ static int spim_nrfx_pm_control(struct device *dev, u32_t ctrl_command, } \ }; \ DEVICE_DEFINE(spi_##idx, \ - DT_NORDIC_NRF_SPIM_SPI_##idx##_LABEL, \ + SPIM_PROP(idx, label), \ spi_##idx##_init, \ spim_nrfx_pm_control, \ &spi_##idx##_data, \