Skip to content

Commit

Permalink
drivers: gpio: move non-standard dts flags to be soc specific
Browse files Browse the repository at this point in the history
Reserve the upper 8 bits of gpio_dt_flags_t for SoC specific flags and
move the non-standard, hardware-specific GPIO devicetree flags (IO
voltage level, drive strength, debounce filter) from the generic
dt-bindings/gpio/gpio.h header to SoC specific dt-bindings headers.

Some of the SoC specific dt-bindings flags take up more bits than
necessary in order to retain backwards compatibility with the deprecated
GPIO flags. The width of these fields can be reduced/optimized once the
deprecated flags are removed.

Remove hardcoded use of GPIO_INT_DEBOUNCE in GPIO client drivers. This
flag can now be set in the devicetree for boards/SoCs with debounce
filter support. The SoC specific debounce flags have had the _INT part
of their name removed since these flag must be passed to
gpio_pin_configure(), not gpio_pin_interrupt_configure().

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
  • Loading branch information
henrikbrixandersen authored and nashif committed Mar 10, 2022
1 parent a87c811 commit d4023b3
Show file tree
Hide file tree
Showing 34 changed files with 417 additions and 212 deletions.
3 changes: 2 additions & 1 deletion drivers/gpio/gpio_andes_atcgpio100.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <device.h>
#include <soc.h>
#include <drivers/gpio.h>
#include <dt-bindings/gpio/andestech-atcgpio100.h>
#include <sys/util.h>
#include <sys/sys_io.h>

Expand Down Expand Up @@ -140,7 +141,7 @@ static int gpio_atcgpio100_config(const struct device *port,
key = k_spin_lock(&data->lock);

/* Set de-bounce */
if (flags & GPIO_INT_DEBOUNCE) {
if (flags & ATCGPIO100_GPIO_DEBOUNCE) {
/* Default settings: Filter out pulses which are
* less than 4 de-bounce clock period
*/
Expand Down
5 changes: 0 additions & 5 deletions drivers/gpio/gpio_b91.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,6 @@ static int gpio_b91_pin_configure(const struct device *dev,
return -ENOTSUP;
}

/* Strengths not implemented */
if ((flags & GPIO_DS_ALT) != 0) {
return -ENOTSUP;
}

/* Set GPIO init state if defined to avoid glitches */
if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0) {
gpio->output |= BIT(pin);
Expand Down
30 changes: 12 additions & 18 deletions drivers/gpio/gpio_cc13xx_cc26xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <device.h>
#include <errno.h>
#include <drivers/gpio.h>
#include <dt-bindings/gpio/ti-cc13xx-cc26xx-gpio.h>

#include <driverlib/gpio.h>
#include <driverlib/interrupt.h>
Expand Down Expand Up @@ -72,28 +73,21 @@ static int gpio_cc13xx_cc26xx_config(const struct device *port,

config |= IOC_SLEW_DISABLE | IOC_NO_WAKE_UP;

config |= (flags & GPIO_INT_DEBOUNCE) ? IOC_HYST_ENABLE :
IOC_HYST_DISABLE;

/*
* The GPIO_DS_ALT_HIGH and GPIO_DS_ALT_LOW flags are for setting
* the highest drive strength for a GPIO in the output HIGH and
* output LOW states, respectively. Since only 1 drive strength
* setting is available for a GPIO (irrespective of output state),
* require both flags to be set for highest drive strength, default
* to low/auto drive strength.
* Not all GPIO support 8ma, but setting that bit will use the highest
* supported drive strength.
*/
switch (flags & (GPIO_DS_ALT_HIGH | GPIO_DS_ALT_LOW)) {
case 0:
config |= (flags & CC13XX_CC26XX_GPIO_DEBOUNCE) ?
IOC_HYST_ENABLE : IOC_HYST_DISABLE;

switch (flags & CC13XX_CC26XX_GPIO_DS_MASK) {
case CC13XX_CC26XX_GPIO_DS_DFLT:
config |= IOC_CURRENT_2MA | IOC_STRENGTH_AUTO;
break;
case (GPIO_DS_ALT_HIGH | GPIO_DS_ALT_LOW):
case CC13XX_CC26XX_GPIO_DS_ALT:
/*
* Not all GPIO support 8ma, but setting that bit will use the
* highest supported drive strength.
*/
config |= IOC_CURRENT_8MA | IOC_STRENGTH_MAX;
break;
case GPIO_DS_ALT_HIGH:
case GPIO_DS_ALT_LOW:
default:
return -ENOTSUP;
}

Expand Down
5 changes: 0 additions & 5 deletions drivers/gpio/gpio_cy8c95xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ static int cy8c95xx_config(const struct device *dev,
return -EWOULDBLOCK;
}

/* Strengths not implemented */
if ((flags & GPIO_DS_ALT) != 0) {
return -ENOTSUP;
}

/* Open-drain not implemented */
if ((flags & GPIO_SINGLE_ENDED) != 0U) {
return -ENOTSUP;
Expand Down
3 changes: 2 additions & 1 deletion drivers/gpio/gpio_dw.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <kernel.h>
#include <drivers/gpio.h>
#include <dt-bindings/gpio/snps-designware-gpio.h>
#include "gpio_dw.h"
#include "gpio_utils.h"

Expand Down Expand Up @@ -301,7 +302,7 @@ static inline void dw_pin_config(const struct device *port,
* interrupts according to datasheet.
*/
if (dw_interrupt_support(config) && (dir_port == SWPORTA_DDR)) {
need_debounce = (flags & GPIO_INT_DEBOUNCE);
need_debounce = (flags & DW_GPIO_DEBOUNCE);
dw_set_bit(base_addr, PORTA_DEBOUNCE, pin, need_debounce);
}
}
Expand Down
7 changes: 4 additions & 3 deletions drivers/gpio/gpio_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <errno.h>
#include <device.h>
#include <drivers/gpio.h>
#include <dt-bindings/gpio/espressif-esp32-gpio.h>
#ifdef CONFIG_SOC_ESP32C3
#include <drivers/interrupt_controller/intc_esp32c3.h>
#else
Expand Down Expand Up @@ -151,8 +152,8 @@ static int gpio_esp32_config(const struct device *dev,
* to either low or high states. Alternative drive strength is weak-only,
* while any other intermediary combination is considered invalid.
*/
switch (flags & GPIO_DS_MASK) {
case GPIO_DS_DFLT:
switch (flags & ESP32_GPIO_DS_MASK) {
case ESP32_GPIO_DS_DFLT:
if (!rtc_gpio_is_valid_gpio(io_pin) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) {
gpio_ll_set_drive_capability(cfg->gpio_base,
io_pin,
Expand All @@ -164,7 +165,7 @@ static int gpio_esp32_config(const struct device *dev,
#endif
}
break;
case GPIO_DS_ALT:
case ESP32_GPIO_DS_ALT:
if (!rtc_gpio_is_valid_gpio(io_pin) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) {
gpio_ll_set_drive_capability(cfg->gpio_base,
io_pin,
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio_fxl6408.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LOG_MODULE_REGISTER(fxl6408, CONFIG_FXL6408_LOG_LEVEL);

#define SUPPORTED_FLAGS (GPIO_INPUT | GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW |\
GPIO_OUTPUT_INIT_HIGH | GPIO_PULL_DOWN | GPIO_PULL_UP |\
GPIO_ACTIVE_HIGH | GPIO_ACTIVE_LOW | GPIO_INT_DEBOUNCE)
GPIO_ACTIVE_HIGH | GPIO_ACTIVE_LOW)

/** Configuration data*/
struct gpio_fxl6408_config {
Expand Down
9 changes: 5 additions & 4 deletions drivers/gpio/gpio_ite_it8xxx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <errno.h>
#include <device.h>
#include <drivers/gpio.h>
#include <dt-bindings/gpio/ite-it8xxx2-gpio.h>
#include <dt-bindings/interrupt-controller/ite-intc.h>
#include <zephyr/types.h>
#include <sys/util.h>
Expand Down Expand Up @@ -379,14 +380,14 @@ static int gpio_ite_configure(const struct device *dev,
gpio_1p8v[gpio_config->index][pin].offset);
mask_1p8v = gpio_1p8v[gpio_config->index][pin].mask_1p8v;
if (reg_1p8v != &IT8XXX2_GPIO_GCRX(0)) {
gpio_flags_t volt = flags & GPIO_VOLTAGE_MASK;
gpio_flags_t volt = flags & IT8XXX2_GPIO_VOLTAGE_MASK;

if (volt == GPIO_VOLTAGE_1P8) {
if (volt == IT8XXX2_GPIO_VOLTAGE_1P8) {
__ASSERT(!(flags & GPIO_PULL_UP),
"Don't enable internal pullup if 1.8V voltage is used");
*reg_1p8v |= mask_1p8v;
} else if (volt == GPIO_VOLTAGE_3P3 ||
volt == GPIO_VOLTAGE_DEFAULT) {
} else if (volt == IT8XXX2_GPIO_VOLTAGE_3P3 ||
volt == IT8XXX2_GPIO_VOLTAGE_DEFAULT) {
*reg_1p8v &= ~mask_1p8v;
} else {
return -EINVAL;
Expand Down
7 changes: 4 additions & 3 deletions drivers/gpio/gpio_mcux.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <errno.h>
#include <device.h>
#include <drivers/gpio.h>
#include <dt-bindings/gpio/nxp-kinetis-gpio.h>
#include <soc.h>
#include <fsl_common.h>
#include <fsl_port.h>
Expand Down Expand Up @@ -98,12 +99,12 @@ static int gpio_mcux_configure(const struct device *dev,

#if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
/* Determine the drive strength */
switch (flags & GPIO_DS_MASK) {
case GPIO_DS_DFLT:
switch (flags & KINETIS_GPIO_DS_MASK) {
case KINETIS_GPIO_DS_DFLT:
/* Default is low drive strength */
mask |= PORT_PCR_DSE_MASK;
break;
case GPIO_DS_ALT:
case KINETIS_GPIO_DS_ALT:
/* Alternate is high drive strength */
pcr |= PORT_PCR_DSE_MASK;
break;
Expand Down
19 changes: 10 additions & 9 deletions drivers/gpio/gpio_nrfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <nrfx_gpiote.h>
#include <string.h>
#include <drivers/gpio.h>
#include <dt-bindings/gpio/nordic-nrf-gpio.h>
#include "gpio_utils.h"

struct gpio_nrfx_data {
Expand Down Expand Up @@ -38,32 +39,32 @@ static int get_drive(gpio_flags_t flags, nrf_gpio_pin_drive_t *drive)
{
int err = 0;

switch (flags & (GPIO_DS_LOW_MASK | GPIO_DS_HIGH_MASK |
switch (flags & (NRF_GPIO_DS_LOW_MASK | NRF_GPIO_DS_HIGH_MASK |
GPIO_OPEN_DRAIN)) {
case GPIO_DS_DFLT:
case NRF_GPIO_DS_DFLT:
*drive = NRF_GPIO_PIN_S0S1;
break;
case GPIO_DS_DFLT_LOW | GPIO_DS_ALT_HIGH:
case NRF_GPIO_DS_DFLT_LOW | NRF_GPIO_DS_ALT_HIGH:
*drive = NRF_GPIO_PIN_S0H1;
break;
case GPIO_DS_DFLT_LOW | GPIO_OPEN_DRAIN:
case NRF_GPIO_DS_DFLT_LOW | GPIO_OPEN_DRAIN:
*drive = NRF_GPIO_PIN_S0D1;
break;

case GPIO_DS_ALT_LOW | GPIO_DS_DFLT_HIGH:
case NRF_GPIO_DS_ALT_LOW | NRF_GPIO_DS_DFLT_HIGH:
*drive = NRF_GPIO_PIN_H0S1;
break;
case GPIO_DS_ALT:
case NRF_GPIO_DS_ALT:
*drive = NRF_GPIO_PIN_H0H1;
break;
case GPIO_DS_ALT_LOW | GPIO_OPEN_DRAIN:
case NRF_GPIO_DS_ALT_LOW | GPIO_OPEN_DRAIN:
*drive = NRF_GPIO_PIN_H0D1;
break;

case GPIO_DS_DFLT_HIGH | GPIO_OPEN_SOURCE:
case NRF_GPIO_DS_DFLT_HIGH | GPIO_OPEN_SOURCE:
*drive = NRF_GPIO_PIN_D0S1;
break;
case GPIO_DS_ALT_HIGH | GPIO_OPEN_SOURCE:
case NRF_GPIO_DS_ALT_HIGH | GPIO_OPEN_SOURCE:
*drive = NRF_GPIO_PIN_D0H1;
break;

Expand Down
15 changes: 0 additions & 15 deletions drivers/gpio/gpio_pca953x.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,6 @@ static int gpio_pca953x_config(const struct device *dev, gpio_pin_t pin,
return -EWOULDBLOCK;
}

/* Zephyr currently defines drive strength support based on
* the behavior and capabilities of the Nordic GPIO
* peripheral: strength defaults to low but can be set high,
* and is controlled independently for output levels.
*
* The PCA953X supports only high strength, and does not
* support different strengths for different levels.
*
* Until something more general is available reject any
* attempt to set a non-default drive strength.
*/
if ((flags & GPIO_DS_ALT) != 0) {
return -ENOTSUP;
}

/* Single Ended lines (Open drain and open source) not supported */
if ((flags & GPIO_SINGLE_ENDED) != 0) {
return -ENOTSUP;
Expand Down
7 changes: 0 additions & 7 deletions drivers/gpio/gpio_pcal6408a.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ static int pcal6408a_pin_configure(const struct device *dev,
return -ENOTSUP;
}

/* Drive strength configuration in this device is incompatible with
* the currently available GPIO API flags, hence it is not supported.
*/
if ((flags & GPIO_DS_ALT) != 0) {
return -ENOTSUP;
}

if (k_is_in_isr()) {
return -EWOULDBLOCK;
}
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpio/gpio_sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <init.h>
#include <soc.h>
#include <drivers/gpio.h>
#include <dt-bindings/gpio/atmel-sam-gpio.h>

#include "gpio_utils.h"

Expand Down Expand Up @@ -116,7 +117,7 @@ static int gpio_sam_port_configure(const struct device *dev, uint32_t mask,

#if defined(CONFIG_SOC_SERIES_SAM3X)
/* Setup debounce. */
if (flags & GPIO_INT_DEBOUNCE) {
if (flags & SAM_GPIO_DEBOUNCE) {
pio->PIO_DIFSR = mask;
} else {
pio->PIO_SCIFSR = mask;
Expand All @@ -127,7 +128,7 @@ static int gpio_sam_port_configure(const struct device *dev, uint32_t mask,
defined(CONFIG_SOC_SERIES_SAMV71)

/* Setup debounce. */
if (flags & GPIO_INT_DEBOUNCE) {
if (flags & SAM_GPIO_DEBOUNCE) {
pio->PIO_IFSCER = mask;
} else {
pio->PIO_IFSCDR = mask;
Expand Down
3 changes: 2 additions & 1 deletion drivers/gpio/gpio_sam0.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <errno.h>
#include <device.h>
#include <drivers/gpio.h>
#include <dt-bindings/gpio/atmel-sam0-gpio.h>
#include <soc.h>
#include <drivers/interrupt_controller/sam0_eic.h>

Expand Down Expand Up @@ -94,7 +95,7 @@ static int gpio_sam0_config(const struct device *dev, gpio_pin_t pin,

/* Preserve debounce flag for interrupt configuration. */
WRITE_BIT(data->debounce, pin,
((flags & GPIO_INT_DEBOUNCE) != 0)
((flags & SAM0_GPIO_DEBOUNCE) != 0)
&& (pincfg.bit.INEN != 0));

/* Write the now-built pin configuration */
Expand Down
18 changes: 2 additions & 16 deletions drivers/gpio/gpio_sx1509b.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <init.h>
#include <drivers/gpio.h>
#include <drivers/gpio/gpio_sx1509b.h>
#include <dt-bindings/gpio/semtech-sx1509b.h>
#include <drivers/i2c.h>
#include <sys/byteorder.h>
#include <sys/util.h>
Expand Down Expand Up @@ -289,21 +290,6 @@ static int sx1509b_config(const struct device *dev,
return -EWOULDBLOCK;
}

/* Zephyr currently defines drive strength support based on
* the behavior and capabilities of the Nordic GPIO
* peripheral: strength defaults to low but can be set high,
* and is controlled independently for output levels.
*
* SX150x defaults to high strength, and does not support
* different strengths for different levels.
*
* Until something more general is available reject any
* attempt to set a non-default drive strength.
*/
if ((flags & GPIO_DS_ALT) != 0) {
return -ENOTSUP;
}

k_sem_take(&drv_data->lock, K_FOREVER);

if (drv_data->led_drv_enable & BIT(pin)) {
Expand Down Expand Up @@ -359,7 +345,7 @@ static int sx1509b_config(const struct device *dev,
pins->dir |= BIT(pin);
}

if ((flags & GPIO_INT_DEBOUNCE) != 0) {
if ((flags & SX1509B_GPIO_DEBOUNCE) != 0) {
debounce->debounce_enable |= BIT(pin);
} else {
debounce->debounce_enable &= ~BIT(pin);
Expand Down
3 changes: 1 addition & 2 deletions drivers/lora/sx126x_standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ int sx126x_variant_init(const struct device *dev)

if (gpio_pin_configure_dt(&sx126x_gpio_reset, GPIO_OUTPUT_ACTIVE) ||
gpio_pin_configure_dt(&sx126x_gpio_busy, GPIO_INPUT) ||
gpio_pin_configure_dt(&sx126x_gpio_dio1,
GPIO_INPUT | GPIO_INT_DEBOUNCE)) {
gpio_pin_configure_dt(&sx126x_gpio_dio1, GPIO_INPUT)) {
LOG_ERR("GPIO configuration failed.");
return -EIO;
}
Expand Down
3 changes: 1 addition & 2 deletions drivers/lora/sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ void SX127xIoIrqInit(DioIrqHandler **irqHandlers)

k_work_init(&dev_data.dio_work[i], sx127x_dio_work_handle);

gpio_pin_configure_dt(&sx127x_dios[i],
GPIO_INPUT | GPIO_INT_DEBOUNCE);
gpio_pin_configure_dt(&sx127x_dios[i], GPIO_INPUT);

gpio_init_callback(&callbacks[i],
sx127x_irq_callback,
Expand Down
Loading

0 comments on commit d4023b3

Please sign in to comment.