From deba60892149ed0ff574efece93222b6525b92ef Mon Sep 17 00:00:00 2001 From: Steven Lemaire Date: Tue, 14 Jul 2020 11:22:27 +0200 Subject: [PATCH] driver: gpio: gecko: Add support for Gecko Series 2 SoC Use the GPIO API from emlib instead of accessing the register directly: The emlib API is doing the checks and uses the proper registers depending on the SoC used. Signed-off-by: Steven Lemaire --- drivers/gpio/gpio_gecko.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/drivers/gpio/gpio_gecko.c b/drivers/gpio/gpio_gecko.c index ed9829839f2..dd997b11491 100644 --- a/drivers/gpio/gpio_gecko.c +++ b/drivers/gpio/gpio_gecko.c @@ -52,7 +52,6 @@ struct gpio_gecko_common_data { struct gpio_gecko_config { /* gpio_driver_config needs to be first */ struct gpio_driver_config common; - GPIO_P_TypeDef *gpio_base; GPIO_Port_TypeDef gpio_index; }; @@ -128,9 +127,9 @@ static int gpio_gecko_configure(struct device *dev, static int gpio_gecko_port_get_raw(struct device *dev, uint32_t *value) { const struct gpio_gecko_config *config = dev->config_info; - GPIO_P_TypeDef *gpio_base = config->gpio_base; + GPIO_Port_TypeDef gpio_index = config->gpio_index; - *value = gpio_base->DIN; + *value = GPIO_PortInGet(gpio_index); return 0; } @@ -139,9 +138,9 @@ static int gpio_gecko_port_set_masked_raw(struct device *dev, uint32_t mask, uint32_t value) { const struct gpio_gecko_config *config = dev->config_info; - GPIO_P_TypeDef *gpio_base = config->gpio_base; + GPIO_Port_TypeDef gpio_index = config->gpio_index; - gpio_base->DOUT = (gpio_base->DOUT & ~mask) | (mask & value); + GPIO_PortOutSetVal(gpio_index, value, mask); return 0; } @@ -149,13 +148,9 @@ static int gpio_gecko_port_set_masked_raw(struct device *dev, uint32_t mask, static int gpio_gecko_port_set_bits_raw(struct device *dev, uint32_t mask) { const struct gpio_gecko_config *config = dev->config_info; - GPIO_P_TypeDef *gpio_base = config->gpio_base; + GPIO_Port_TypeDef gpio_index = config->gpio_index; -#if defined(_GPIO_P_DOUTSET_MASK) - gpio_base->DOUTSET = mask; -#else - BUS_RegMaskedSet(&gpio_base->DOUT, mask); -#endif + GPIO_PortOutSet(gpio_index, mask); return 0; } @@ -163,13 +158,9 @@ static int gpio_gecko_port_set_bits_raw(struct device *dev, uint32_t mask) static int gpio_gecko_port_clear_bits_raw(struct device *dev, uint32_t mask) { const struct gpio_gecko_config *config = dev->config_info; - GPIO_P_TypeDef *gpio_base = config->gpio_base; + GPIO_Port_TypeDef gpio_index = config->gpio_index; -#if defined(_GPIO_P_DOUTCLR_MASK) - gpio_base->DOUTCLR = mask; -#else - BUS_RegMaskedClear(&gpio_base->DOUT, mask); -#endif + GPIO_PortOutClear(gpio_index, mask); return 0; } @@ -177,9 +168,9 @@ static int gpio_gecko_port_clear_bits_raw(struct device *dev, uint32_t mask) static int gpio_gecko_port_toggle_bits(struct device *dev, uint32_t mask) { const struct gpio_gecko_config *config = dev->config_info; - GPIO_P_TypeDef *gpio_base = config->gpio_base; + GPIO_Port_TypeDef gpio_index = config->gpio_index; - gpio_base->DOUTTGL = mask; + GPIO_PortOutToggle(gpio_index, mask); return 0; } @@ -254,7 +245,11 @@ static void gpio_gecko_common_isr(void *arg) enabled_int = int_status & port_data->int_enabled_mask; if (enabled_int != 0) { int_status &= ~enabled_int; +#if defined(_SILICON_LABS_32B_SERIES_2) + GPIO->IF_CLR = enabled_int; +#else GPIO->IFC = enabled_int; +#endif gpio_fire_callbacks(&port_data->callbacks, port_dev, enabled_int); } @@ -313,7 +308,6 @@ static const struct gpio_gecko_config gpio_gecko_port##idx##_config = { \ .common = { \ .port_pin_mask = (gpio_port_pins_t)(-1), \ }, \ - .gpio_base = (GPIO_P_TypeDef *)DT_INST_REG_ADDR(idx), \ .gpio_index = DT_INST_PROP(idx, peripheral_id), \ }; \ \