From bca692ee8c5c985a71d56d8740405f3af6df065e Mon Sep 17 00:00:00 2001 From: Piotr Mienkowski Date: Fri, 1 Feb 2019 15:43:19 +0100 Subject: [PATCH] drivers: i2c_gecko: use DT___ defines Use the new DT___ defines to instantiate devices. This commit adds also ability to define individual pin locations on SoC series that support the feature. Definitions of GPIO pins assigned to a given location have been moved from soc_pinmap.h file to board DTS file. Signed-off-by: Piotr Mienkowski --- boards/arm/efm32pg_stk3402a/Kconfig.defconfig | 7 -- .../arm/efm32pg_stk3402a/efm32pg_stk3402a.dts | 3 +- boards/arm/efr32mg_sltb004a/Kconfig.defconfig | 10 --- .../arm/efr32mg_sltb004a/efr32mg_sltb004a.dts | 6 +- drivers/i2c/i2c_gecko.c | 85 +++++++++++++------ dts/arm/silabs/efm32hg.dtsi | 12 +++ dts/arm/silabs/efm32pg12b.dtsi | 5 -- dts/arm/silabs/efm32wg.dtsi | 23 +++++ dts/arm/silabs/efr32fg1p.dtsi | 12 +++ dts/arm/silabs/efr32mg.dtsi | 5 -- dts/bindings/i2c/silabs,gecko-i2c.yaml | 19 +++-- .../efm32hg/Kconfig.defconfig.efm32hg | 7 ++ soc/arm/silabs_exx32/efm32pg12b/soc_pinmap.h | 20 ----- .../efm32wg/Kconfig.defconfig.efm32wg | 7 ++ .../efr32fg1p/Kconfig.defconfig.efr32fg1p | 7 ++ soc/arm/silabs_exx32/efr32mg12p/soc_pinmap.h | 20 ----- 16 files changed, 148 insertions(+), 100 deletions(-) diff --git a/boards/arm/efm32pg_stk3402a/Kconfig.defconfig b/boards/arm/efm32pg_stk3402a/Kconfig.defconfig index 1a8bd748961..9cec15c2230 100644 --- a/boards/arm/efm32pg_stk3402a/Kconfig.defconfig +++ b/boards/arm/efm32pg_stk3402a/Kconfig.defconfig @@ -38,11 +38,4 @@ config GPIO_GECKO_PORTF endif # GPIO_GECKO -if I2C_GECKO - -config I2C_0 - default y - -endif # I2C_GECKO - endif # BOARD_EFM32PG_STK3402A diff --git a/boards/arm/efm32pg_stk3402a/efm32pg_stk3402a.dts b/boards/arm/efm32pg_stk3402a/efm32pg_stk3402a.dts index dd6d6fdde7e..2b6cab5a3a0 100644 --- a/boards/arm/efm32pg_stk3402a/efm32pg_stk3402a.dts +++ b/boards/arm/efm32pg_stk3402a/efm32pg_stk3402a.dts @@ -68,7 +68,8 @@ }; &i2c0 { - location = <15>; + location-sda = ; + location-scl = ; status = "ok"; }; diff --git a/boards/arm/efr32mg_sltb004a/Kconfig.defconfig b/boards/arm/efr32mg_sltb004a/Kconfig.defconfig index 611acca4a00..3963d767707 100644 --- a/boards/arm/efr32mg_sltb004a/Kconfig.defconfig +++ b/boards/arm/efr32mg_sltb004a/Kconfig.defconfig @@ -29,14 +29,4 @@ config GPIO_GECKO_PORTF endif # GPIO_GECKO -if I2C_GECKO - -config I2C_0 - default y - -config I2C_1 - default y - -endif # I2C_GECKO - endif # BOARD_EFR32MG_SLTB004A diff --git a/boards/arm/efr32mg_sltb004a/efr32mg_sltb004a.dts b/boards/arm/efr32mg_sltb004a/efr32mg_sltb004a.dts index 054a2b6f2e6..23a6ba57560 100644 --- a/boards/arm/efr32mg_sltb004a/efr32mg_sltb004a.dts +++ b/boards/arm/efr32mg_sltb004a/efr32mg_sltb004a.dts @@ -67,12 +67,14 @@ }; &i2c0 { - location = <15>; + location-sda = ; + location-scl = ; status = "ok"; }; &i2c1 { - location = <17>; + location-sda = ; + location-scl = ; status = "ok"; }; diff --git a/drivers/i2c/i2c_gecko.c b/drivers/i2c/i2c_gecko.c index 20765d7d310..ee1cbd77a30 100644 --- a/drivers/i2c/i2c_gecko.c +++ b/drivers/i2c/i2c_gecko.c @@ -29,10 +29,15 @@ struct i2c_gecko_config { I2C_TypeDef *base; CMU_Clock_TypeDef clock; I2C_Init_TypeDef i2cInit; + u32_t bitrate; struct soc_gpio_pin pin_sda; struct soc_gpio_pin pin_scl; - unsigned int loc; - u32_t bitrate; +#ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION + u8_t loc_sda; + u8_t loc_scl; +#else + u8_t loc; +#endif }; struct i2c_gecko_data { @@ -42,19 +47,20 @@ struct i2c_gecko_data { void i2c_gecko_config_pins(struct device *dev, const struct soc_gpio_pin *pin_sda, - const struct soc_gpio_pin *pin_scl, u8_t loc) + const struct soc_gpio_pin *pin_scl) { I2C_TypeDef *base = DEV_BASE(dev); + struct i2c_gecko_config *config = DEV_CFG(dev); soc_gpio_configure(pin_scl); soc_gpio_configure(pin_sda); -#ifdef _I2C_ROUTEPEN_MASK +#ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION base->ROUTEPEN = I2C_ROUTEPEN_SDAPEN | I2C_ROUTEPEN_SCLPEN; - base->ROUTELOC0 = (loc << _I2C_ROUTELOC0_SDALOC_SHIFT) - | (loc << _I2C_ROUTELOC0_SCLLOC_SHIFT); + base->ROUTELOC0 = (config->loc_sda << _I2C_ROUTELOC0_SDALOC_SHIFT) | + (config->loc_scl << _I2C_ROUTELOC0_SCLLOC_SHIFT); #else - base->ROUTE = I2C_ROUTE_SDAPEN | I2C_ROUTE_SCLPEN | (loc << 8); + base->ROUTE = I2C_ROUTE_SDAPEN | I2C_ROUTE_SCLPEN | (config->loc << 8); #endif } @@ -160,8 +166,7 @@ static int i2c_gecko_init(struct device *dev) CMU_ClockEnable(config->clock, true); - i2c_gecko_config_pins(dev, &config->pin_sda, - &config->pin_scl, config->loc); + i2c_gecko_config_pins(dev, &config->pin_sda, &config->pin_scl); bitrate_cfg = _i2c_map_dt_bitrate(config->bitrate); @@ -178,40 +183,70 @@ static const struct i2c_driver_api i2c_gecko_driver_api = { .transfer = i2c_gecko_transfer, }; -#ifdef CONFIG_I2C_0 +#ifdef DT_SILABS_GECKO_I2C_0 + +#define PIN_I2C_0_SDA {DT_SILABS_GECKO_I2C_0_LOCATION_SDA_1, \ + DT_SILABS_GECKO_I2C_0_LOCATION_SDA_2, gpioModeWiredAnd, 1} +#define PIN_I2C_0_SCL {DT_SILABS_GECKO_I2C_0_LOCATION_SCL_1, \ + DT_SILABS_GECKO_I2C_0_LOCATION_SCL_2, gpioModeWiredAnd, 1} + static struct i2c_gecko_config i2c_gecko_config_0 = { - .base = (I2C_TypeDef *)DT_SILABS_GECKO_I2C_I2C_0_BASE_ADDRESS, + .base = (I2C_TypeDef *)DT_SILABS_GECKO_I2C_0_BASE_ADDRESS, .clock = cmuClock_I2C0, .i2cInit = I2C_INIT_DEFAULT, - .pin_sda = PIN_I2C0_SDA, - .pin_scl = PIN_I2C0_SCL, - .loc = DT_SILABS_GECKO_I2C_I2C_0_LOCATION, - .bitrate = DT_SILABS_GECKO_I2C_I2C_0_CLOCK_FREQUENCY, + .pin_sda = PIN_I2C_0_SDA, + .pin_scl = PIN_I2C_0_SCL, +#ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION + .loc_sda = DT_SILABS_GECKO_I2C_0_LOCATION_SDA_0, + .loc_scl = DT_SILABS_GECKO_I2C_0_LOCATION_SCL_0, +#else +#if DT_SILABS_GECKO_I2C_0_LOCATION_SDA_0 \ + != DT_SILABS_GECKO_I2C_0_LOCATION_SCL_0 +#error I2C_0 DTS location-* properties must have identical value +#endif + .loc = DT_SILABS_GECKO_I2C_0_LOCATION_SCL_0, +#endif + .bitrate = DT_SILABS_GECKO_I2C_0_CLOCK_FREQUENCY, }; static struct i2c_gecko_data i2c_gecko_data_0; -DEVICE_AND_API_INIT(i2c_gecko_0, DT_SILABS_GECKO_I2C_I2C_0_LABEL, +DEVICE_AND_API_INIT(i2c_gecko_0, DT_SILABS_GECKO_I2C_0_LABEL, &i2c_gecko_init, &i2c_gecko_data_0, &i2c_gecko_config_0, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &i2c_gecko_driver_api); -#endif /* CONFIG_I2C_0 */ +#endif /* DT_SILABS_GECKO_I2C_0 */ + +#ifdef DT_SILABS_GECKO_I2C_1 + +#define PIN_I2C_1_SDA {DT_SILABS_GECKO_I2C_1_LOCATION_SDA_1, \ + DT_SILABS_GECKO_I2C_1_LOCATION_SDA_2, gpioModeWiredAnd, 1} +#define PIN_I2C_1_SCL {DT_SILABS_GECKO_I2C_1_LOCATION_SCL_1, \ + DT_SILABS_GECKO_I2C_1_LOCATION_SCL_2, gpioModeWiredAnd, 1} -#ifdef CONFIG_I2C_1 static struct i2c_gecko_config i2c_gecko_config_1 = { - .base = (I2C_TypeDef *)DT_SILABS_GECKO_I2C_I2C_1_BASE_ADDRESS, + .base = (I2C_TypeDef *)DT_SILABS_GECKO_I2C_1_BASE_ADDRESS, .clock = cmuClock_I2C1, .i2cInit = I2C_INIT_DEFAULT, - .pin_sda = PIN_I2C1_SDA, - .pin_scl = PIN_I2C1_SCL, - .loc = DT_SILABS_GECKO_I2C_I2C_1_LOCATION, - .bitrate = DT_SILABS_GECKO_I2C_I2C_1_CLOCK_FREQUENCY, + .pin_sda = PIN_I2C_1_SDA, + .pin_scl = PIN_I2C_1_SCL, +#ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION + .loc_sda = DT_SILABS_GECKO_I2C_1_LOCATION_SDA_0, + .loc_scl = DT_SILABS_GECKO_I2C_1_LOCATION_SCL_0, +#else +#if DT_SILABS_GECKO_I2C_1_LOCATION_SDA_0 \ + != DT_SILABS_GECKO_I2C_1_LOCATION_SCL_0 +#error I2C_1 DTS location-* properties must have identical value +#endif + .loc = DT_SILABS_GECKO_I2C_1_LOCATION_SCL_0, +#endif + .bitrate = DT_SILABS_GECKO_I2C_1_CLOCK_FREQUENCY, }; static struct i2c_gecko_data i2c_gecko_data_1; -DEVICE_AND_API_INIT(i2c_gecko_1, DT_SILABS_GECKO_I2C_I2C_1_LABEL, +DEVICE_AND_API_INIT(i2c_gecko_1, DT_SILABS_GECKO_I2C_1_LABEL, &i2c_gecko_init, &i2c_gecko_data_1, &i2c_gecko_config_1, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &i2c_gecko_driver_api); -#endif /* CONFIG_I2C_1 */ +#endif /* DT_SILABS_GECKO_I2C_1 */ diff --git a/dts/arm/silabs/efm32hg.dtsi b/dts/arm/silabs/efm32hg.dtsi index 0c556301ab5..8cbfbf318f1 100644 --- a/dts/arm/silabs/efm32hg.dtsi +++ b/dts/arm/silabs/efm32hg.dtsi @@ -1,5 +1,6 @@ #include #include +#include #include "gpio_gecko.h" / { @@ -61,6 +62,17 @@ label = "LEUART_0"; }; + i2c0: i2c@4000a000 { + compatible = "silabs,gecko-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x4000a000 0x400>; + interrupts = <5 0>; + label = "I2C_0"; + status = "disabled"; + }; + gpio@40006100 { compatible = "silabs,efm32-gpio"; reg = <0x40006100 0xf00>; diff --git a/dts/arm/silabs/efm32pg12b.dtsi b/dts/arm/silabs/efm32pg12b.dtsi index fa99a813744..abc7afafb28 100644 --- a/dts/arm/silabs/efm32pg12b.dtsi +++ b/dts/arm/silabs/efm32pg12b.dtsi @@ -25,11 +25,6 @@ compatible = "mmio-sram"; }; - aliases { - i2c-0 = &i2c0; - i2c-1 = &i2c1; - }; - soc { flash-controller@400e0000 { compatible = "silabs,gecko-flash-controller"; diff --git a/dts/arm/silabs/efm32wg.dtsi b/dts/arm/silabs/efm32wg.dtsi index 6cf43eee37e..3a915d76a92 100644 --- a/dts/arm/silabs/efm32wg.dtsi +++ b/dts/arm/silabs/efm32wg.dtsi @@ -1,5 +1,6 @@ #include #include +#include #include "gpio_gecko.h" / { @@ -96,6 +97,28 @@ label = "LEUART_1"; }; + i2c0: i2c@4000a000 { + compatible = "silabs,gecko-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x4000a000 0x400>; + interrupts = <9 0>; + label = "I2C_0"; + status = "disabled"; + }; + + i2c1: i2c@4000a400 { + compatible = "silabs,gecko-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x4000a400 0x400>; + interrupts = <10 0>; + label = "I2C_1"; + status = "disabled"; + }; + gpio@40006100 { compatible = "silabs,efm32-gpio"; reg = <0x40006100 0xf00>; diff --git a/dts/arm/silabs/efr32fg1p.dtsi b/dts/arm/silabs/efr32fg1p.dtsi index e6e3c63ccc4..90a5dba5efe 100644 --- a/dts/arm/silabs/efr32fg1p.dtsi +++ b/dts/arm/silabs/efr32fg1p.dtsi @@ -1,5 +1,6 @@ #include #include +#include #include "gpio_gecko.h" / { @@ -61,6 +62,17 @@ label = "LEUART_0"; }; + i2c0: i2c@4000c000 { + compatible = "silabs,gecko-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x4000c000 0x400>; + interrupts = <16 0>; + label = "I2C_0"; + status = "disabled"; + }; + gpio: gpio@4000a400 { compatible = "silabs,efr32xg1-gpio"; reg = <0x4000a400 0xc00>; diff --git a/dts/arm/silabs/efr32mg.dtsi b/dts/arm/silabs/efr32mg.dtsi index 34465267358..722e7062fe2 100644 --- a/dts/arm/silabs/efr32mg.dtsi +++ b/dts/arm/silabs/efr32mg.dtsi @@ -19,11 +19,6 @@ compatible = "mmio-sram"; }; - aliases { - i2c-0 = &i2c0; - i2c-1 = &i2c1; - }; - soc { flash-controller@400e0000 { compatible = "silabs,gecko-flash-controller"; diff --git a/dts/bindings/i2c/silabs,gecko-i2c.yaml b/dts/bindings/i2c/silabs,gecko-i2c.yaml index 48a2e69e75e..73698953637 100644 --- a/dts/bindings/i2c/silabs,gecko-i2c.yaml +++ b/dts/bindings/i2c/silabs,gecko-i2c.yaml @@ -32,9 +32,18 @@ properties: description: required interrupts generation: define - location: - type: int - category: required - description: PIN location - generation: define + # Note: Not all SoC series support setting individual pin location. If this + # is a case all location-* properties need to have identical value. + + location-sda: + type: array + category: required + description: SDA pin configuration defined as + generation: define + + location-scl: + type: array + category: required + description: SCL pin configuration defined as + generation: define ... diff --git a/soc/arm/silabs_exx32/efm32hg/Kconfig.defconfig.efm32hg b/soc/arm/silabs_exx32/efm32hg/Kconfig.defconfig.efm32hg index 06298f6f452..7df85d6b73a 100644 --- a/soc/arm/silabs_exx32/efm32hg/Kconfig.defconfig.efm32hg +++ b/soc/arm/silabs_exx32/efm32hg/Kconfig.defconfig.efm32hg @@ -22,6 +22,13 @@ config UART_GECKO endif # SERIAL +if I2C + +config I2C_GECKO + default y + +endif # I2C + if FLASH config SOC_FLASH_GECKO diff --git a/soc/arm/silabs_exx32/efm32pg12b/soc_pinmap.h b/soc/arm/silabs_exx32/efm32pg12b/soc_pinmap.h index 448d4a63841..b38a4a740d2 100644 --- a/soc/arm/silabs_exx32/efm32pg12b/soc_pinmap.h +++ b/soc/arm/silabs_exx32/efm32pg12b/soc_pinmap.h @@ -31,24 +31,4 @@ #endif #endif /* CONFIG_GPIO_GECKO */ -#ifdef CONFIG_I2C_GECKO -#ifdef CONFIG_I2C_0 -#if (DT_SILABS_GECKO_I2C_I2C_0_LOCATION == 15) -#define PIN_I2C0_SDA {gpioPortC, 10, gpioModeWiredAnd, 1} -#define PIN_I2C0_SCL {gpioPortC, 11, gpioModeWiredAnd, 1} -#else -#error ("I2C Driver for Gecko MCUs not implemented for this location index") -#endif -#endif /* CONFIG_I2C_0 */ - -#ifdef CONFIG_I2C_1 -#if (DT_SILABS_GECKO_I2C_I2C_1_LOCATION == 6) -#define PIN_I2C1_SDA {gpioPortB, 6, gpioModeWiredAnd, 1} -#define PIN_I2C1_SCL {gpioPortB, 7, gpioModeWiredAnd, 1} -#else -#error ("I2C Driver for Gecko MCUs not implemented for this location index") -#endif -#endif /* CONFIG_I2C_1 */ -#endif /* CONFIG_I2C_GECKO */ - #endif /* _SILABS_EFM32PG12B_SOC_PINMAP_H_ */ diff --git a/soc/arm/silabs_exx32/efm32wg/Kconfig.defconfig.efm32wg b/soc/arm/silabs_exx32/efm32wg/Kconfig.defconfig.efm32wg index d3460584ba8..d74d085de6a 100644 --- a/soc/arm/silabs_exx32/efm32wg/Kconfig.defconfig.efm32wg +++ b/soc/arm/silabs_exx32/efm32wg/Kconfig.defconfig.efm32wg @@ -22,6 +22,13 @@ config UART_GECKO endif # SERIAL +if I2C + +config I2C_GECKO + default y + +endif # I2C + if FLASH config SOC_FLASH_GECKO diff --git a/soc/arm/silabs_exx32/efr32fg1p/Kconfig.defconfig.efr32fg1p b/soc/arm/silabs_exx32/efr32fg1p/Kconfig.defconfig.efr32fg1p index 657c4be789a..43980d972c4 100644 --- a/soc/arm/silabs_exx32/efr32fg1p/Kconfig.defconfig.efr32fg1p +++ b/soc/arm/silabs_exx32/efr32fg1p/Kconfig.defconfig.efr32fg1p @@ -22,6 +22,13 @@ config UART_GECKO endif # SERIAL +if I2C + +config I2C_GECKO + default y + +endif # I2C + if FLASH config SOC_FLASH_GECKO diff --git a/soc/arm/silabs_exx32/efr32mg12p/soc_pinmap.h b/soc/arm/silabs_exx32/efr32mg12p/soc_pinmap.h index 148b6235e76..19353ad5338 100644 --- a/soc/arm/silabs_exx32/efr32mg12p/soc_pinmap.h +++ b/soc/arm/silabs_exx32/efr32mg12p/soc_pinmap.h @@ -30,24 +30,4 @@ #endif #endif /* CONFIG_GPIO_GECKO */ -#ifdef CONFIG_I2C_GECKO -#ifdef CONFIG_I2C_0 -#if (DT_SILABS_GECKO_I2C_I2C_0_LOCATION == 15) -#define PIN_I2C0_SDA {gpioPortC, 10, gpioModeWiredAnd, 1} -#define PIN_I2C0_SCL {gpioPortC, 11, gpioModeWiredAnd, 1} -#else -#error ("I2C Driver for Gecko MCUs not implemented for this location index") -#endif -#endif /* CONFIG_I2C_0 */ - -#ifdef CONFIG_I2C_1 -#if (DT_SILABS_GECKO_I2C_I2C_1_LOCATION == 17) -#define PIN_I2C1_SDA {gpioPortC, 4, gpioModeWiredAnd, 1} -#define PIN_I2C1_SCL {gpioPortC, 5, gpioModeWiredAnd, 1} -#else -#error ("I2C Driver for Gecko MCUs not implemented for this location index") -#endif -#endif /* CONFIG_I2C_1 */ -#endif /* CONFIG_I2C_GECKO */ - #endif /* _SOC_PINMAP_H_ */