From 3966a33c5c40add7677393378746aeb7bb1683e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 1 Mar 2022 17:02:16 +0100 Subject: [PATCH] drivers: i2s_nrfx: Add support for pinctrl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for the new pinctrl API to the nRF I2S driver. Update code of the driver and the related devicetree binding. Signed-off-by: Andrzej Głąbek --- drivers/i2s/i2s_nrfx.c | 28 ++++++++++++---- dts/bindings/i2s/nordic,nrf-i2s.yaml | 50 +++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/drivers/i2s/i2s_nrfx.c b/drivers/i2s/i2s_nrfx.c index 4a4374a1cd2..c7d481dfd38 100644 --- a/drivers/i2s/i2s_nrfx.c +++ b/drivers/i2s/i2s_nrfx.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -38,6 +40,9 @@ struct i2s_nrfx_drv_data { struct i2s_nrfx_drv_cfg { nrfx_i2s_data_handler_t data_handler; nrfx_i2s_config_t nrfx_def_cfg; +#ifdef CONFIG_PINCTRL + const struct pinctrl_dev_config *pcfg; +#endif enum clock_source { PCLK32M, PCLK32M_HFXO, @@ -873,14 +878,12 @@ static const struct i2s_driver_api i2s_nrf_drv_api = { }; #define I2S(idx) DT_NODELABEL(i2s##idx) - -#define I2S_PIN(idx, name) \ - COND_CODE_1(DT_NODE_HAS_PROP(I2S(idx), name##_pin), \ - (DT_PROP(I2S(idx), name##_pin)), \ - (NRFX_I2S_PIN_NOT_USED)) -#define I2S_CLK_SRC(idx) DT_STRING_TOKEN(I2S(idx), clock_source) +#define I2S_PIN(idx, name) DT_PROP_OR(I2S(idx), name##_pin, \ + NRFX_I2S_PIN_NOT_USED) +#define I2S_CLK_SRC(idx) DT_STRING_TOKEN(I2S(idx), clock_source) #define I2S_NRFX_DEVICE(idx) \ + NRF_DT_ENSURE_PINS_ASSIGNED(I2S(idx), sck_pin); \ static void *tx_msgs##idx[CONFIG_I2S_NRFX_TX_BLOCK_COUNT]; \ static void *rx_msgs##idx[CONFIG_I2S_NRFX_RX_BLOCK_COUNT]; \ static struct i2s_nrfx_drv_data i2s_nrfx_data##idx = { \ @@ -890,6 +893,14 @@ static const struct i2s_driver_api i2s_nrf_drv_api = { { \ IRQ_CONNECT(DT_IRQN(I2S(idx)), DT_IRQ(I2S(idx), priority), \ nrfx_isr, nrfx_i2s_irq_handler, 0); \ + IF_ENABLED(CONFIG_PINCTRL, ( \ + const struct i2s_nrfx_drv_cfg *drv_cfg = dev->config;\ + int err = pinctrl_apply_state(drv_cfg->pcfg, \ + PINCTRL_STATE_DEFAULT);\ + if (err < 0) { \ + return err; \ + } \ + )) \ k_msgq_init(&i2s_nrfx_data##idx.tx_queue, \ (char *)tx_msgs##idx, sizeof(void *), \ ARRAY_SIZE(tx_msgs##idx)); \ @@ -904,6 +915,7 @@ static const struct i2s_driver_api i2s_nrf_drv_api = { { \ data_handler(DEVICE_DT_GET(I2S(idx)), p_released, status); \ } \ + IF_ENABLED(CONFIG_PINCTRL, (PINCTRL_DT_DEFINE(I2S(idx)))); \ static const struct i2s_nrfx_drv_cfg i2s_nrfx_cfg##idx = { \ .data_handler = data_handler##idx, \ .nrfx_def_cfg = NRFX_I2S_DEFAULT_CONFIG(I2S_PIN(idx, sck), \ @@ -911,6 +923,10 @@ static const struct i2s_driver_api i2s_nrf_drv_api = { I2S_PIN(idx, mck), \ I2S_PIN(idx, sdout), \ I2S_PIN(idx, sdin)), \ + IF_ENABLED(CONFIG_PINCTRL, \ + (.nrfx_def_cfg.skip_gpio_cfg = true, \ + .nrfx_def_cfg.skip_psel_cfg = true, \ + .pcfg = PINCTRL_DT_DEV_CONFIG_GET(I2S(idx)),)) \ .clk_src = I2S_CLK_SRC(idx), \ }; \ BUILD_ASSERT(I2S_CLK_SRC(idx) != ACLK || NRF_I2S_HAS_CLKCONFIG, \ diff --git a/dts/bindings/i2s/nordic,nrf-i2s.yaml b/dts/bindings/i2s/nordic,nrf-i2s.yaml index f3e866d3fdb..aa4c36a48e5 100644 --- a/dts/bindings/i2s/nordic,nrf-i2s.yaml +++ b/dts/bindings/i2s/nordic,nrf-i2s.yaml @@ -5,7 +5,7 @@ description: Nordic I2S (Inter-IC sound interface) compatible: "nordic,nrf-i2s" -include: i2s-controller.yaml +include: [i2s-controller.yaml, pinctrl-device.yaml] properties: reg: @@ -16,28 +16,62 @@ properties: sck-pin: type: int - required: true - description: SCK pin + required: false + description: | + IMPORTANT: This option will only be used if the new pin control driver + is not enabled. It will be deprecated in the future. + + The SCK pin to use. + + For pins P0.0 through P0.31, use the pin number. For example, + to use P0.16 for SCK, set: + + sck-pin = <16>; + + For pins P1.0 through P1.31, add 32 to the pin number. For + example, to use P1.2 for SCK, set: + + sck-pin = <34>; /* 32 + 2 */ lrck-pin: type: int - required: true - description: LRCK pin + required: false + description: | + IMPORTANT: This option will only be used if the new pin control driver + is not enabled. It will be deprecated in the future. + + The LRCK pin to use. The pin numbering scheme is the same as + the sck-pin property's. sdout-pin: type: int required: false - description: SDOUT pin + description: | + IMPORTANT: This option will only be used if the new pin control driver + is not enabled. It will be deprecated in the future. + + The SDOUT pin to use. The pin numbering scheme is the same as + the sck-pin property's. sdin-pin: type: int required: false - description: SDIN pin + description: | + IMPORTANT: This option will only be used if the new pin control driver + is not enabled. It will be deprecated in the future. + + The SDIN pin to use. The pin numbering scheme is the same as + the sck-pin property's. mck-pin: type: int required: false - description: MCK pin + description: | + IMPORTANT: This option will only be used if the new pin control driver + is not enabled. It will be deprecated in the future. + + The MCK pin to use. The pin numbering scheme is the same as + the sck-pin property's. clock-source: type: string