From dc1c2742b677cbfde6ba6e7d20685e25c53a7c29 Mon Sep 17 00:00:00 2001 From: Mieszko Mierunski Date: Mon, 28 May 2018 15:43:25 +0200 Subject: [PATCH] boards: nrf: Moved SDA and SCL pin configuration to DTS for nRF boards SDA and SCL pins can now be configured through DTS. Pins on development kits have been assigned according to arduino headers. Signed-off-by: Mieszko Mierunski --- arch/arm/soc/nordic_nrf/nrf51/dts.fixup | 4 +++ arch/arm/soc/nordic_nrf/nrf52/dts.fixup | 4 +++ boards/arm/bbc_microbit/Kconfig.defconfig | 6 ---- boards/arm/bbc_microbit/bbc_microbit.dts | 2 ++ boards/arm/nrf51_pca10028/nrf51_pca10028.dts | 4 +++ boards/arm/nrf51_vbluno51/Kconfig.defconfig | 6 ---- boards/arm/nrf51_vbluno51/nrf51_vbluno51.dts | 2 ++ boards/arm/nrf52840_pca10056/Kconfig.board | 1 + .../nrf52840_pca10056/nrf52840_pca10056.dts | 4 +++ boards/arm/nrf52_blenano2/Kconfig.defconfig | 6 ---- boards/arm/nrf52_blenano2/nrf52_blenano2.dts | 5 ++++ boards/arm/nrf52_pca10040/nrf52_pca10040.dts | 5 ++++ boards/arm/nrf52_pca20020/Kconfig.defconfig | 15 ---------- boards/arm/nrf52_pca20020/nrf52_pca20020.dts | 4 +++ boards/arm/nrf52_vbluno52/Kconfig.defconfig | 6 ---- boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts | 2 ++ drivers/i2c/Kconfig.nrfx | 28 ------------------- drivers/i2c/i2c_nrfx_twi.c | 4 +-- drivers/i2c/i2c_nrfx_twim.c | 4 +-- dts/bindings/i2c/nordic,nrf5-i2c.yaml | 11 ++++++++ 20 files changed, 52 insertions(+), 71 deletions(-) diff --git a/arch/arm/soc/nordic_nrf/nrf51/dts.fixup b/arch/arm/soc/nordic_nrf/nrf51/dts.fixup index 529cfffeffa..87cb8061d81 100644 --- a/arch/arm/soc/nordic_nrf/nrf51/dts.fixup +++ b/arch/arm/soc/nordic_nrf/nrf51/dts.fixup @@ -12,12 +12,16 @@ #define CONFIG_I2C_0_BITRATE NORDIC_NRF5_I2C_40003000_CLOCK_FREQUENCY #define CONFIG_I2C_0_IRQ_PRI NORDIC_NRF5_I2C_40003000_IRQ_0_PRIORITY #define CONFIG_I2C_0_IRQ NORDIC_NRF5_I2C_40003000_IRQ_0 +#define CONFIG_I2C_0_SDA_PIN NORDIC_NRF5_I2C_40003000_SDA_PIN +#define CONFIG_I2C_0_SCL_PIN NORDIC_NRF5_I2C_40003000_SCL_PIN #define CONFIG_I2C_1_BASE_ADDR NORDIC_NRF5_I2C_40004000_BASE_ADDRESS #define CONFIG_I2C_1_NAME NORDIC_NRF5_I2C_40004000_LABEL #define CONFIG_I2C_1_BITRATE NORDIC_NRF5_I2C_40004000_CLOCK_FREQUENCY #define CONFIG_I2C_1_IRQ_PRI NORDIC_NRF5_I2C_40004000_IRQ_0_PRIORITY #define CONFIG_I2C_1_IRQ NORDIC_NRF5_I2C_40004000_IRQ_0 +#define CONFIG_I2C_1_SDA_PIN NORDIC_NRF5_I2C_40004000_SDA_PIN +#define CONFIG_I2C_1_SCL_PIN NORDIC_NRF5_I2C_40004000_SCL_PIN #define CONFIG_WDT_0_NAME NORDIC_NRF_WATCHDOG_40010000_LABEL #define CONFIG_WDT_NRF_IRQ NORDIC_NRF_WATCHDOG_40010000_IRQ_WDT diff --git a/arch/arm/soc/nordic_nrf/nrf52/dts.fixup b/arch/arm/soc/nordic_nrf/nrf52/dts.fixup index b05b86d6ebf..b44ce998116 100644 --- a/arch/arm/soc/nordic_nrf/nrf52/dts.fixup +++ b/arch/arm/soc/nordic_nrf/nrf52/dts.fixup @@ -17,12 +17,16 @@ #define CONFIG_I2C_0_BITRATE NORDIC_NRF5_I2C_40003000_CLOCK_FREQUENCY #define CONFIG_I2C_0_IRQ_PRI NORDIC_NRF5_I2C_40003000_IRQ_0_PRIORITY #define CONFIG_I2C_0_IRQ NORDIC_NRF5_I2C_40003000_IRQ_0 +#define CONFIG_I2C_0_SDA_PIN NORDIC_NRF5_I2C_40003000_SDA_PIN +#define CONFIG_I2C_0_SCL_PIN NORDIC_NRF5_I2C_40003000_SCL_PIN #define CONFIG_I2C_1_BASE_ADDR NORDIC_NRF5_I2C_40004000_BASE_ADDRESS #define CONFIG_I2C_1_NAME NORDIC_NRF5_I2C_40004000_LABEL #define CONFIG_I2C_1_BITRATE NORDIC_NRF5_I2C_40004000_CLOCK_FREQUENCY #define CONFIG_I2C_1_IRQ_PRI NORDIC_NRF5_I2C_40004000_IRQ_0_PRIORITY #define CONFIG_I2C_1_IRQ NORDIC_NRF5_I2C_40004000_IRQ_0 +#define CONFIG_I2C_1_SDA_PIN NORDIC_NRF5_I2C_40004000_SDA_PIN +#define CONFIG_I2C_1_SCL_PIN NORDIC_NRF5_I2C_40004000_SCL_PIN #define CONFIG_USBD_NRF5_IRQ NORDIC_NRF_USBD_40027000_IRQ_USBD #define CONFIG_USBD_NRF5_IRQ_PRI NORDIC_NRF_USBD_40027000_IRQ_USBD_PRIORITY diff --git a/boards/arm/bbc_microbit/Kconfig.defconfig b/boards/arm/bbc_microbit/Kconfig.defconfig index 23e4ca64ef0..52611199f1f 100644 --- a/boards/arm/bbc_microbit/Kconfig.defconfig +++ b/boards/arm/bbc_microbit/Kconfig.defconfig @@ -45,12 +45,6 @@ choice I2C_0_NRF_TYPE endchoice -config I2C_0_NRF_SDA_PIN - default 30 - -config I2C_0_NRF_SCL_PIN - default 0 - endif # I2C_0 endif # I2C diff --git a/boards/arm/bbc_microbit/bbc_microbit.dts b/boards/arm/bbc_microbit/bbc_microbit.dts index cdc8d1d84dd..184007cc130 100644 --- a/boards/arm/bbc_microbit/bbc_microbit.dts +++ b/boards/arm/bbc_microbit/bbc_microbit.dts @@ -21,6 +21,8 @@ &uart0 { status = "ok"; current-speed = <115200>; + sda-pin = <30>; + scl-pin = <0>; }; &i2c0 { diff --git a/boards/arm/nrf51_pca10028/nrf51_pca10028.dts b/boards/arm/nrf51_pca10028/nrf51_pca10028.dts index f8d399912d8..eed30b6c93b 100644 --- a/boards/arm/nrf51_pca10028/nrf51_pca10028.dts +++ b/boards/arm/nrf51_pca10028/nrf51_pca10028.dts @@ -29,10 +29,14 @@ &i2c0 { status = "ok"; + sda-pin = <30>; + scl-pin = <7>; }; &i2c1 { status = "ok"; + sda-pin = <5>; + scl-pin = <6>; }; &flash0 { diff --git a/boards/arm/nrf51_vbluno51/Kconfig.defconfig b/boards/arm/nrf51_vbluno51/Kconfig.defconfig index 29b6b85ee9a..6a70e115bd3 100644 --- a/boards/arm/nrf51_vbluno51/Kconfig.defconfig +++ b/boards/arm/nrf51_vbluno51/Kconfig.defconfig @@ -51,12 +51,6 @@ choice I2C_0_NRF_TYPE endchoice -config I2C_0_NRF_SDA_PIN - default 29 - -config I2C_0_NRF_SCL_PIN - default 30 - endif # I2C_0 endif # I2C diff --git a/boards/arm/nrf51_vbluno51/nrf51_vbluno51.dts b/boards/arm/nrf51_vbluno51/nrf51_vbluno51.dts index 75aaf5e50ca..335bb116b18 100644 --- a/boards/arm/nrf51_vbluno51/nrf51_vbluno51.dts +++ b/boards/arm/nrf51_vbluno51/nrf51_vbluno51.dts @@ -27,4 +27,6 @@ &i2c0 { status = "ok"; clock-frequency = ; + sda-pin = <29>; + scl-pin = <30>; }; diff --git a/boards/arm/nrf52840_pca10056/Kconfig.board b/boards/arm/nrf52840_pca10056/Kconfig.board index c7eebe18362..3ee0ed3b957 100644 --- a/boards/arm/nrf52840_pca10056/Kconfig.board +++ b/boards/arm/nrf52840_pca10056/Kconfig.board @@ -7,4 +7,5 @@ config BOARD_NRF52840_PCA10056 bool "NRF52840 PCA10056" select HAS_DTS_GPIO + select HAS_DTS_I2C depends on SOC_NRF52840_QIAA diff --git a/boards/arm/nrf52840_pca10056/nrf52840_pca10056.dts b/boards/arm/nrf52840_pca10056/nrf52840_pca10056.dts index ef82ef56d9c..c581d97a8ff 100644 --- a/boards/arm/nrf52840_pca10056/nrf52840_pca10056.dts +++ b/boards/arm/nrf52840_pca10056/nrf52840_pca10056.dts @@ -42,10 +42,14 @@ &i2c0 { status = "ok"; + sda-pin = <26>; + scl-pin = <27>; }; &i2c1 { status = "ok"; + sda-pin = <30>; + scl-pin = <31>; }; &flash0 { diff --git a/boards/arm/nrf52_blenano2/Kconfig.defconfig b/boards/arm/nrf52_blenano2/Kconfig.defconfig index eeb7866669b..d5137afa67b 100644 --- a/boards/arm/nrf52_blenano2/Kconfig.defconfig +++ b/boards/arm/nrf52_blenano2/Kconfig.defconfig @@ -51,12 +51,6 @@ choice I2C_0_NRF_TYPE endchoice -config I2C_0_NRF_SDA_PIN - default 28 - -config I2C_0_NRF_SCL_PIN - default 2 - endif # I2C_0 endif # I2C diff --git a/boards/arm/nrf52_blenano2/nrf52_blenano2.dts b/boards/arm/nrf52_blenano2/nrf52_blenano2.dts index d8cd90eb625..32f7fe98b6d 100644 --- a/boards/arm/nrf52_blenano2/nrf52_blenano2.dts +++ b/boards/arm/nrf52_blenano2/nrf52_blenano2.dts @@ -33,6 +33,11 @@ status = "ok"; }; +&i2c0 { + sda-pin = <28>; + scl-pin = <2>; +}; + &flash0 { /* * For more information, see: diff --git a/boards/arm/nrf52_pca10040/nrf52_pca10040.dts b/boards/arm/nrf52_pca10040/nrf52_pca10040.dts index 78b5ccf3d67..4c98a868363 100644 --- a/boards/arm/nrf52_pca10040/nrf52_pca10040.dts +++ b/boards/arm/nrf52_pca10040/nrf52_pca10040.dts @@ -36,12 +36,17 @@ compatible = "nordic,nrf-uart"; current-speed = <115200>; }; + &i2c0 { status = "ok"; + sda-pin = <26>; + scl-pin = <27>; }; &i2c1 { status = "ok"; + sda-pin = <30>; + scl-pin = <31>; }; &flash0 { diff --git a/boards/arm/nrf52_pca20020/Kconfig.defconfig b/boards/arm/nrf52_pca20020/Kconfig.defconfig index 74c57f217c0..ad846a14908 100644 --- a/boards/arm/nrf52_pca20020/Kconfig.defconfig +++ b/boards/arm/nrf52_pca20020/Kconfig.defconfig @@ -51,12 +51,6 @@ choice I2C_0_NRF_TYPE endchoice -config I2C_0_NRF_SDA_PIN - default 7 - -config I2C_0_NRF_SCL_PIN - default 8 - endif # I2C_0 if I2C_1 @@ -66,15 +60,6 @@ choice I2C_1_NRF_TYPE endchoice -config I2C_1_NRF_TWIM - def_bool y - -config I2C_1_NRF_SDA_PIN - default 14 - -config I2C_1_NRF_SCL_PIN - default 15 - config GPIO_SX1509B def_bool y diff --git a/boards/arm/nrf52_pca20020/nrf52_pca20020.dts b/boards/arm/nrf52_pca20020/nrf52_pca20020.dts index 750f9e17803..41143a85c85 100644 --- a/boards/arm/nrf52_pca20020/nrf52_pca20020.dts +++ b/boards/arm/nrf52_pca20020/nrf52_pca20020.dts @@ -38,6 +38,8 @@ &i2c0 { status = "ok"; clock-frequency = ; + sda-pin = <7>; + scl-pin = <8>; sx1509b: sx1509b@3e { compatible = "semtech,sx1509b"; @@ -67,6 +69,8 @@ &i2c1 { status = "ok"; clock-frequency = ; + sda-pin = <14>; + scl-pin = <15>; }; &flash0 { diff --git a/boards/arm/nrf52_vbluno52/Kconfig.defconfig b/boards/arm/nrf52_vbluno52/Kconfig.defconfig index 3474741c174..1c8bea4e1ee 100644 --- a/boards/arm/nrf52_vbluno52/Kconfig.defconfig +++ b/boards/arm/nrf52_vbluno52/Kconfig.defconfig @@ -51,12 +51,6 @@ choice I2C_0_NRF_TYPE endchoice -config I2C_0_NRF_SDA_PIN - default 26 - -config I2C_0_NRF_SCL_PIN - default 27 - endif # I2C_0 endif # I2C diff --git a/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts b/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts index 3890667f664..56541db58d8 100644 --- a/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts +++ b/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts @@ -36,4 +36,6 @@ &i2c0 { status = "ok"; clock-frequency = ; + sda-pin = <26>; + scl-pin = <27>; }; diff --git a/drivers/i2c/Kconfig.nrfx b/drivers/i2c/Kconfig.nrfx index 941766f738e..048c994951c 100644 --- a/drivers/i2c/Kconfig.nrfx +++ b/drivers/i2c/Kconfig.nrfx @@ -39,20 +39,6 @@ config I2C_0_NRF_TWIM endchoice -config I2C_0_NRF_SDA_PIN - int "SDA pin number" - range 0 47 if SOC_NRF52840_QIAA - range 0 31 - help - GPIO pin number to use for SDA. - -config I2C_0_NRF_SCL_PIN - int "SCL pin number" - range 0 47 if SOC_NRF52840_QIAA - range 0 31 - help - GPIO pin number to use for SCL. - endif # I2C_0 && !SPI_0 # Nordic TWIx1 and SPIx1 instances can not be used at the same time. @@ -79,20 +65,6 @@ config I2C_1_NRF_TWIM endchoice -config I2C_1_NRF_SDA_PIN - int "SDA pin number" - range 0 47 if SOC_NRF52840_QIAA - range 0 31 - help - GPIO pin number to use for SDA. - -config I2C_1_NRF_SCL_PIN - int "SCL pin number" - range 0 47 if SOC_NRF52840_QIAA - range 0 31 - help - GPIO pin number to use for SCL. - endif # I2C_1 && !SPI_1 endif #I2C_NRFX diff --git a/drivers/i2c/i2c_nrfx_twi.c b/drivers/i2c/i2c_nrfx_twi.c index 8479163defb..adc2a0aad34 100644 --- a/drivers/i2c/i2c_nrfx_twi.c +++ b/drivers/i2c/i2c_nrfx_twi.c @@ -135,8 +135,8 @@ static int init_twi(struct device *dev, const nrfx_twi_config_t *config) CONFIG_I2C_##idx##_IRQ_PRI, \ nrfx_isr, nrfx_twi_##idx##_irq_handler, 0); \ const nrfx_twi_config_t config = { \ - .scl = CONFIG_I2C_##idx##_NRF_SCL_PIN, \ - .sda = CONFIG_I2C_##idx##_NRF_SDA_PIN, \ + .scl = CONFIG_I2C_##idx##_SCL_PIN, \ + .sda = CONFIG_I2C_##idx##_SDA_PIN, \ .frequency = NRF_TWI_FREQ_100K, \ }; \ return init_twi(dev, &config); \ diff --git a/drivers/i2c/i2c_nrfx_twim.c b/drivers/i2c/i2c_nrfx_twim.c index 3c8a12d2a41..f7ee5439ee7 100644 --- a/drivers/i2c/i2c_nrfx_twim.c +++ b/drivers/i2c/i2c_nrfx_twim.c @@ -135,8 +135,8 @@ static int init_twim(struct device *dev, const nrfx_twim_config_t *config) CONFIG_I2C_##idx##_IRQ_PRI, \ nrfx_isr, nrfx_twim_##idx##_irq_handler, 0);\ const nrfx_twim_config_t config = { \ - .scl = CONFIG_I2C_##idx##_NRF_SCL_PIN, \ - .sda = CONFIG_I2C_##idx##_NRF_SDA_PIN, \ + .scl = CONFIG_I2C_##idx##_SCL_PIN, \ + .sda = CONFIG_I2C_##idx##_SDA_PIN, \ .frequency = NRF_TWIM_FREQ_100K, \ }; \ return init_twim(dev, &config); \ diff --git a/dts/bindings/i2c/nordic,nrf5-i2c.yaml b/dts/bindings/i2c/nordic,nrf5-i2c.yaml index 682e8bb3d1b..5b1f3b6445d 100644 --- a/dts/bindings/i2c/nordic,nrf5-i2c.yaml +++ b/dts/bindings/i2c/nordic,nrf5-i2c.yaml @@ -33,4 +33,15 @@ properties: description: required interrupts generation: define + sda-pin: + type: int + description: SDA pin + generation: define + category: required + + scl-pin: + type: int + description: SCL pin + generation: define + category: required ...