drivers: i2c_gecko: use DT_<COMPAT>_<INSTANCE>_<PROP> defines
Use the new DT_<COMPAT>_<INSTANCE>_<PROP> 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 <piotr.mienkowski@gmail.com>
This commit is contained in:
parent
47fb24fea3
commit
bca692ee8c
16 changed files with 148 additions and 100 deletions
|
@ -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
|
||||
|
|
|
@ -68,7 +68,8 @@
|
|||
};
|
||||
|
||||
&i2c0 {
|
||||
location = <15>;
|
||||
location-sda = <GECKO_LOCATION(15) GECKO_PORT_C GECKO_PIN(10)>;
|
||||
location-scl = <GECKO_LOCATION(15) GECKO_PORT_C GECKO_PIN(11)>;
|
||||
status = "ok";
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -67,12 +67,14 @@
|
|||
};
|
||||
|
||||
&i2c0 {
|
||||
location = <15>;
|
||||
location-sda = <GECKO_LOCATION(15) GECKO_PORT_C GECKO_PIN(10)>;
|
||||
location-scl = <GECKO_LOCATION(15) GECKO_PORT_C GECKO_PIN(11)>;
|
||||
status = "ok";
|
||||
};
|
||||
|
||||
&i2c1 {
|
||||
location = <17>;
|
||||
location-sda = <GECKO_LOCATION(17) GECKO_PORT_C GECKO_PIN(4)>;
|
||||
location-scl = <GECKO_LOCATION(17) GECKO_PORT_C GECKO_PIN(5)>;
|
||||
status = "ok";
|
||||
};
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <arm/armv6-m.dtsi>
|
||||
#include <dt-bindings/gpio/gpio.h>
|
||||
#include <dt-bindings/i2c/i2c.h>
|
||||
#include "gpio_gecko.h"
|
||||
|
||||
/ {
|
||||
|
@ -61,6 +62,17 @@
|
|||
label = "LEUART_0";
|
||||
};
|
||||
|
||||
i2c0: i2c@4000a000 {
|
||||
compatible = "silabs,gecko-i2c";
|
||||
clock-frequency = <I2C_BITRATE_STANDARD>;
|
||||
#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>;
|
||||
|
|
|
@ -25,11 +25,6 @@
|
|||
compatible = "mmio-sram";
|
||||
};
|
||||
|
||||
aliases {
|
||||
i2c-0 = &i2c0;
|
||||
i2c-1 = &i2c1;
|
||||
};
|
||||
|
||||
soc {
|
||||
flash-controller@400e0000 {
|
||||
compatible = "silabs,gecko-flash-controller";
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <arm/armv7-m.dtsi>
|
||||
#include <dt-bindings/gpio/gpio.h>
|
||||
#include <dt-bindings/i2c/i2c.h>
|
||||
#include "gpio_gecko.h"
|
||||
|
||||
/ {
|
||||
|
@ -96,6 +97,28 @@
|
|||
label = "LEUART_1";
|
||||
};
|
||||
|
||||
i2c0: i2c@4000a000 {
|
||||
compatible = "silabs,gecko-i2c";
|
||||
clock-frequency = <I2C_BITRATE_STANDARD>;
|
||||
#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 = <I2C_BITRATE_STANDARD>;
|
||||
#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>;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <arm/armv7-m.dtsi>
|
||||
#include <dt-bindings/gpio/gpio.h>
|
||||
#include <dt-bindings/i2c/i2c.h>
|
||||
#include "gpio_gecko.h"
|
||||
|
||||
/ {
|
||||
|
@ -61,6 +62,17 @@
|
|||
label = "LEUART_0";
|
||||
};
|
||||
|
||||
i2c0: i2c@4000c000 {
|
||||
compatible = "silabs,gecko-i2c";
|
||||
clock-frequency = <I2C_BITRATE_STANDARD>;
|
||||
#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>;
|
||||
|
|
|
@ -19,11 +19,6 @@
|
|||
compatible = "mmio-sram";
|
||||
};
|
||||
|
||||
aliases {
|
||||
i2c-0 = &i2c0;
|
||||
i2c-1 = &i2c1;
|
||||
};
|
||||
|
||||
soc {
|
||||
flash-controller@400e0000 {
|
||||
compatible = "silabs,gecko-flash-controller";
|
||||
|
|
|
@ -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 <location port pin>
|
||||
generation: define
|
||||
|
||||
location-scl:
|
||||
type: array
|
||||
category: required
|
||||
description: SCL pin configuration defined as <location port pin>
|
||||
generation: define
|
||||
...
|
||||
|
|
|
@ -22,6 +22,13 @@ config UART_GECKO
|
|||
|
||||
endif # SERIAL
|
||||
|
||||
if I2C
|
||||
|
||||
config I2C_GECKO
|
||||
default y
|
||||
|
||||
endif # I2C
|
||||
|
||||
if FLASH
|
||||
|
||||
config SOC_FLASH_GECKO
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -22,6 +22,13 @@ config UART_GECKO
|
|||
|
||||
endif # SERIAL
|
||||
|
||||
if I2C
|
||||
|
||||
config I2C_GECKO
|
||||
default y
|
||||
|
||||
endif # I2C
|
||||
|
||||
if FLASH
|
||||
|
||||
config SOC_FLASH_GECKO
|
||||
|
|
|
@ -22,6 +22,13 @@ config UART_GECKO
|
|||
|
||||
endif # SERIAL
|
||||
|
||||
if I2C
|
||||
|
||||
config I2C_GECKO
|
||||
default y
|
||||
|
||||
endif # I2C
|
||||
|
||||
if FLASH
|
||||
|
||||
config SOC_FLASH_GECKO
|
||||
|
|
|
@ -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_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue