Skip to content

Commit d4023b3

Browse files
henrikbrixandersennashif
authored andcommitted
drivers: gpio: move non-standard dts flags to be soc specific
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 <[email protected]>
1 parent a87c811 commit d4023b3

34 files changed

+417
-212
lines changed

drivers/gpio/gpio_andes_atcgpio100.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <device.h>
1515
#include <soc.h>
1616
#include <drivers/gpio.h>
17+
#include <dt-bindings/gpio/andestech-atcgpio100.h>
1718
#include <sys/util.h>
1819
#include <sys/sys_io.h>
1920

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

142143
/* Set de-bounce */
143-
if (flags & GPIO_INT_DEBOUNCE) {
144+
if (flags & ATCGPIO100_GPIO_DEBOUNCE) {
144145
/* Default settings: Filter out pulses which are
145146
* less than 4 de-bounce clock period
146147
*/

drivers/gpio/gpio_b91.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,6 @@ static int gpio_b91_pin_configure(const struct device *dev,
324324
return -ENOTSUP;
325325
}
326326

327-
/* Strengths not implemented */
328-
if ((flags & GPIO_DS_ALT) != 0) {
329-
return -ENOTSUP;
330-
}
331-
332327
/* Set GPIO init state if defined to avoid glitches */
333328
if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0) {
334329
gpio->output |= BIT(pin);

drivers/gpio/gpio_cc13xx_cc26xx.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <device.h>
1212
#include <errno.h>
1313
#include <drivers/gpio.h>
14+
#include <dt-bindings/gpio/ti-cc13xx-cc26xx-gpio.h>
1415

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

7374
config |= IOC_SLEW_DISABLE | IOC_NO_WAKE_UP;
7475

75-
config |= (flags & GPIO_INT_DEBOUNCE) ? IOC_HYST_ENABLE :
76-
IOC_HYST_DISABLE;
77-
78-
/*
79-
* The GPIO_DS_ALT_HIGH and GPIO_DS_ALT_LOW flags are for setting
80-
* the highest drive strength for a GPIO in the output HIGH and
81-
* output LOW states, respectively. Since only 1 drive strength
82-
* setting is available for a GPIO (irrespective of output state),
83-
* require both flags to be set for highest drive strength, default
84-
* to low/auto drive strength.
85-
* Not all GPIO support 8ma, but setting that bit will use the highest
86-
* supported drive strength.
87-
*/
88-
switch (flags & (GPIO_DS_ALT_HIGH | GPIO_DS_ALT_LOW)) {
89-
case 0:
76+
config |= (flags & CC13XX_CC26XX_GPIO_DEBOUNCE) ?
77+
IOC_HYST_ENABLE : IOC_HYST_DISABLE;
78+
79+
switch (flags & CC13XX_CC26XX_GPIO_DS_MASK) {
80+
case CC13XX_CC26XX_GPIO_DS_DFLT:
9081
config |= IOC_CURRENT_2MA | IOC_STRENGTH_AUTO;
9182
break;
92-
case (GPIO_DS_ALT_HIGH | GPIO_DS_ALT_LOW):
83+
case CC13XX_CC26XX_GPIO_DS_ALT:
84+
/*
85+
* Not all GPIO support 8ma, but setting that bit will use the
86+
* highest supported drive strength.
87+
*/
9388
config |= IOC_CURRENT_8MA | IOC_STRENGTH_MAX;
9489
break;
95-
case GPIO_DS_ALT_HIGH:
96-
case GPIO_DS_ALT_LOW:
90+
default:
9791
return -ENOTSUP;
9892
}
9993

drivers/gpio/gpio_cy8c95xx.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ static int cy8c95xx_config(const struct device *dev,
105105
return -EWOULDBLOCK;
106106
}
107107

108-
/* Strengths not implemented */
109-
if ((flags & GPIO_DS_ALT) != 0) {
110-
return -ENOTSUP;
111-
}
112-
113108
/* Open-drain not implemented */
114109
if ((flags & GPIO_SINGLE_ENDED) != 0U) {
115110
return -ENOTSUP;

drivers/gpio/gpio_dw.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <kernel.h>
1212
#include <drivers/gpio.h>
13+
#include <dt-bindings/gpio/snps-designware-gpio.h>
1314
#include "gpio_dw.h"
1415
#include "gpio_utils.h"
1516

@@ -301,7 +302,7 @@ static inline void dw_pin_config(const struct device *port,
301302
* interrupts according to datasheet.
302303
*/
303304
if (dw_interrupt_support(config) && (dir_port == SWPORTA_DDR)) {
304-
need_debounce = (flags & GPIO_INT_DEBOUNCE);
305+
need_debounce = (flags & DW_GPIO_DEBOUNCE);
305306
dw_set_bit(base_addr, PORTA_DEBOUNCE, pin, need_debounce);
306307
}
307308
}

drivers/gpio/gpio_esp32.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <errno.h>
2020
#include <device.h>
2121
#include <drivers/gpio.h>
22+
#include <dt-bindings/gpio/espressif-esp32-gpio.h>
2223
#ifdef CONFIG_SOC_ESP32C3
2324
#include <drivers/interrupt_controller/intc_esp32c3.h>
2425
#else
@@ -151,8 +152,8 @@ static int gpio_esp32_config(const struct device *dev,
151152
* to either low or high states. Alternative drive strength is weak-only,
152153
* while any other intermediary combination is considered invalid.
153154
*/
154-
switch (flags & GPIO_DS_MASK) {
155-
case GPIO_DS_DFLT:
155+
switch (flags & ESP32_GPIO_DS_MASK) {
156+
case ESP32_GPIO_DS_DFLT:
156157
if (!rtc_gpio_is_valid_gpio(io_pin) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) {
157158
gpio_ll_set_drive_capability(cfg->gpio_base,
158159
io_pin,
@@ -164,7 +165,7 @@ static int gpio_esp32_config(const struct device *dev,
164165
#endif
165166
}
166167
break;
167-
case GPIO_DS_ALT:
168+
case ESP32_GPIO_DS_ALT:
168169
if (!rtc_gpio_is_valid_gpio(io_pin) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) {
169170
gpio_ll_set_drive_capability(cfg->gpio_base,
170171
io_pin,

drivers/gpio/gpio_fxl6408.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ LOG_MODULE_REGISTER(fxl6408, CONFIG_FXL6408_LOG_LEVEL);
2626

2727
#define SUPPORTED_FLAGS (GPIO_INPUT | GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW |\
2828
GPIO_OUTPUT_INIT_HIGH | GPIO_PULL_DOWN | GPIO_PULL_UP |\
29-
GPIO_ACTIVE_HIGH | GPIO_ACTIVE_LOW | GPIO_INT_DEBOUNCE)
29+
GPIO_ACTIVE_HIGH | GPIO_ACTIVE_LOW)
3030

3131
/** Configuration data*/
3232
struct gpio_fxl6408_config {

drivers/gpio/gpio_ite_it8xxx2.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <errno.h>
88
#include <device.h>
99
#include <drivers/gpio.h>
10+
#include <dt-bindings/gpio/ite-it8xxx2-gpio.h>
1011
#include <dt-bindings/interrupt-controller/ite-intc.h>
1112
#include <zephyr/types.h>
1213
#include <sys/util.h>
@@ -379,14 +380,14 @@ static int gpio_ite_configure(const struct device *dev,
379380
gpio_1p8v[gpio_config->index][pin].offset);
380381
mask_1p8v = gpio_1p8v[gpio_config->index][pin].mask_1p8v;
381382
if (reg_1p8v != &IT8XXX2_GPIO_GCRX(0)) {
382-
gpio_flags_t volt = flags & GPIO_VOLTAGE_MASK;
383+
gpio_flags_t volt = flags & IT8XXX2_GPIO_VOLTAGE_MASK;
383384

384-
if (volt == GPIO_VOLTAGE_1P8) {
385+
if (volt == IT8XXX2_GPIO_VOLTAGE_1P8) {
385386
__ASSERT(!(flags & GPIO_PULL_UP),
386387
"Don't enable internal pullup if 1.8V voltage is used");
387388
*reg_1p8v |= mask_1p8v;
388-
} else if (volt == GPIO_VOLTAGE_3P3 ||
389-
volt == GPIO_VOLTAGE_DEFAULT) {
389+
} else if (volt == IT8XXX2_GPIO_VOLTAGE_3P3 ||
390+
volt == IT8XXX2_GPIO_VOLTAGE_DEFAULT) {
390391
*reg_1p8v &= ~mask_1p8v;
391392
} else {
392393
return -EINVAL;

drivers/gpio/gpio_mcux.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <errno.h>
1111
#include <device.h>
1212
#include <drivers/gpio.h>
13+
#include <dt-bindings/gpio/nxp-kinetis-gpio.h>
1314
#include <soc.h>
1415
#include <fsl_common.h>
1516
#include <fsl_port.h>
@@ -98,12 +99,12 @@ static int gpio_mcux_configure(const struct device *dev,
9899

99100
#if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
100101
/* Determine the drive strength */
101-
switch (flags & GPIO_DS_MASK) {
102-
case GPIO_DS_DFLT:
102+
switch (flags & KINETIS_GPIO_DS_MASK) {
103+
case KINETIS_GPIO_DS_DFLT:
103104
/* Default is low drive strength */
104105
mask |= PORT_PCR_DSE_MASK;
105106
break;
106-
case GPIO_DS_ALT:
107+
case KINETIS_GPIO_DS_ALT:
107108
/* Alternate is high drive strength */
108109
pcr |= PORT_PCR_DSE_MASK;
109110
break;

drivers/gpio/gpio_nrfx.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <nrfx_gpiote.h>
99
#include <string.h>
1010
#include <drivers/gpio.h>
11+
#include <dt-bindings/gpio/nordic-nrf-gpio.h>
1112
#include "gpio_utils.h"
1213

1314
struct gpio_nrfx_data {
@@ -38,32 +39,32 @@ static int get_drive(gpio_flags_t flags, nrf_gpio_pin_drive_t *drive)
3839
{
3940
int err = 0;
4041

41-
switch (flags & (GPIO_DS_LOW_MASK | GPIO_DS_HIGH_MASK |
42+
switch (flags & (NRF_GPIO_DS_LOW_MASK | NRF_GPIO_DS_HIGH_MASK |
4243
GPIO_OPEN_DRAIN)) {
43-
case GPIO_DS_DFLT:
44+
case NRF_GPIO_DS_DFLT:
4445
*drive = NRF_GPIO_PIN_S0S1;
4546
break;
46-
case GPIO_DS_DFLT_LOW | GPIO_DS_ALT_HIGH:
47+
case NRF_GPIO_DS_DFLT_LOW | NRF_GPIO_DS_ALT_HIGH:
4748
*drive = NRF_GPIO_PIN_S0H1;
4849
break;
49-
case GPIO_DS_DFLT_LOW | GPIO_OPEN_DRAIN:
50+
case NRF_GPIO_DS_DFLT_LOW | GPIO_OPEN_DRAIN:
5051
*drive = NRF_GPIO_PIN_S0D1;
5152
break;
5253

53-
case GPIO_DS_ALT_LOW | GPIO_DS_DFLT_HIGH:
54+
case NRF_GPIO_DS_ALT_LOW | NRF_GPIO_DS_DFLT_HIGH:
5455
*drive = NRF_GPIO_PIN_H0S1;
5556
break;
56-
case GPIO_DS_ALT:
57+
case NRF_GPIO_DS_ALT:
5758
*drive = NRF_GPIO_PIN_H0H1;
5859
break;
59-
case GPIO_DS_ALT_LOW | GPIO_OPEN_DRAIN:
60+
case NRF_GPIO_DS_ALT_LOW | GPIO_OPEN_DRAIN:
6061
*drive = NRF_GPIO_PIN_H0D1;
6162
break;
6263

63-
case GPIO_DS_DFLT_HIGH | GPIO_OPEN_SOURCE:
64+
case NRF_GPIO_DS_DFLT_HIGH | GPIO_OPEN_SOURCE:
6465
*drive = NRF_GPIO_PIN_D0S1;
6566
break;
66-
case GPIO_DS_ALT_HIGH | GPIO_OPEN_SOURCE:
67+
case NRF_GPIO_DS_ALT_HIGH | GPIO_OPEN_SOURCE:
6768
*drive = NRF_GPIO_PIN_D0H1;
6869
break;
6970

0 commit comments

Comments
 (0)