-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce gpio-keys wake-up sources using pinctrl #64538
Changes from all commits
8607cf6
8f914d8
598947f
9d8833f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,33 @@ | ||
/* | ||
* Copyright (c) 2022, Gerson Fernando Budke <[email protected]> | ||
* Copyright (c) 2022-2023, Gerson Fernando Budke <[email protected]> | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <dt-bindings/pinctrl/sam4sXc-pinctrl.h> | ||
|
||
&pinctrl { | ||
spi0_default: spi0_default { | ||
adc0_default: adc0_default { | ||
group1 { | ||
pinmux = <PA12A_SPI_MISO>, | ||
<PA13A_SPI_MOSI>, | ||
<PA14A_SPI_SPCK>, | ||
<PA31A_SPI_NPCS1>, | ||
<PA30B_SPI_NPCS2>; | ||
pinmux = <PB0X_ADC_AD4>, | ||
<PB1X_ADC_AD5>; | ||
}; | ||
}; | ||
|
||
twi0_default: twi0_default { | ||
gpio_keys_default: gpio_keys_default { | ||
group1 { | ||
pinmux = <PA4A_TWI0_TWCK>, | ||
<PA3A_TWI0_TWD>; | ||
pinmux = <PA5X_SUPC_WKUP4>; | ||
bias-pull-up; | ||
}; | ||
}; | ||
|
||
uart0_default: uart0_default { | ||
group1 { | ||
pinmux = <PA9A_UART0_RXD>, | ||
<PA10A_UART0_TXD>; | ||
}; | ||
}; | ||
uart1_default: uart1_default { | ||
group1 { | ||
pinmux = <PB2A_UART1_RXD>, | ||
<PB3A_UART1_TXD>; | ||
}; | ||
}; | ||
usart1_default: usart1_default { | ||
group1 { | ||
pinmux = <PA21A_USART1_RXD>, | ||
<PA22A_USART1_TXD>; | ||
}; | ||
}; | ||
pwm0_default: pwm0_default { | ||
group1 { | ||
pinmux = <PA12B_PWM_PWMH1>, | ||
<PA13B_PWM_PWMH2>, | ||
<PA14B_PWM_PWMH3>; | ||
}; | ||
}; | ||
adc0_default: adc0_default { | ||
group1 { | ||
pinmux = <PB0X_ADC_AD4>, | ||
<PB1X_ADC_AD5>; | ||
}; | ||
}; | ||
|
||
smc_default: smc_default { | ||
group1 { | ||
pinmux = <PC18A_EBI_A0>, | ||
|
@@ -89,4 +63,40 @@ | |
<PC8A_EBI_NWE>; | ||
}; | ||
}; | ||
|
||
spi0_default: spi0_default { | ||
group1 { | ||
pinmux = <PA12A_SPI_MISO>, | ||
<PA13A_SPI_MOSI>, | ||
<PA14A_SPI_SPCK>, | ||
<PA31A_SPI_NPCS1>, | ||
<PA30B_SPI_NPCS2>; | ||
}; | ||
}; | ||
|
||
twi0_default: twi0_default { | ||
group1 { | ||
pinmux = <PA4A_TWI0_TWCK>, | ||
<PA3A_TWI0_TWD>; | ||
}; | ||
}; | ||
|
||
uart0_default: uart0_default { | ||
group1 { | ||
pinmux = <PA9A_UART0_RXD>, | ||
<PA10A_UART0_TXD>; | ||
}; | ||
}; | ||
uart1_default: uart1_default { | ||
group1 { | ||
pinmux = <PB2A_UART1_RXD>, | ||
<PB3A_UART1_TXD>; | ||
}; | ||
}; | ||
usart1_default: usart1_default { | ||
group1 { | ||
pinmux = <PA21A_USART1_RXD>, | ||
<PA22A_USART1_TXD>; | ||
}; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* Copyright (c) 2017 Piotr Mienkowski | ||
* Copyright (c) 2017 Justin Watson | ||
* Copyright (c) 2020 Stephanos Ioannidis <[email protected]> | ||
* Copyright (c) 2020 Gerson Fernando Budke <[email protected]> | ||
* Copyright (c) 2020-2023 Gerson Fernando Budke <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
@@ -39,6 +39,9 @@ | |
gpio_keys { | ||
compatible = "gpio-keys"; | ||
|
||
pinctrl-0 = <&gpio_keys_default>; | ||
pinctrl-names = "default"; | ||
|
||
/* The switch is labeled SW300 in the schematic, and labeled | ||
* SW0 on the board, and labeld SW1 User Button on docs | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2022, Gerson Fernando Budke <[email protected]> | ||
* Copyright (c) 2022-2023, Gerson Fernando Budke <[email protected]> | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
|
@@ -13,7 +13,6 @@ | |
<PA17X_AFE0_AD6>; | ||
}; | ||
}; | ||
|
||
afec1_default: afec1_default { /* ADCH - J504 */ | ||
group1 { | ||
pinmux = <PC31X_AFE1_AD6>; | ||
|
@@ -40,6 +39,13 @@ | |
}; | ||
}; | ||
|
||
gpio_keys_default: gpio_keys_default { | ||
group1 { | ||
pinmux = <PA11X_SUPC_WKUP7>; | ||
bias-pull-up; | ||
}; | ||
}; | ||
|
||
mdio_default: mdio_default { | ||
group1 { | ||
pinmux = <PD8A_GMAC_GMDC>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* Copyright (c) 2017 Piotr Mienkowski | ||
* Copyright (c) 2017 Justin Watson | ||
* Copyright (c) 2020 Stephanos Ioannidis <[email protected]> | ||
* Copyright (c) 2019-2022 Gerson Fernando Budke <[email protected]> | ||
* Copyright (c) 2019-2023 Gerson Fernando Budke <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
@@ -54,6 +54,9 @@ | |
gpio_keys { | ||
compatible = "gpio-keys"; | ||
|
||
pinctrl-0 = <&gpio_keys_default>; | ||
pinctrl-names = "default"; | ||
|
||
/* The switch is labeled SW300/301 in the schematic, and | ||
* labeled SW0 on the board, and labeled ERASE User Button | ||
* on docs | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
* Copyright (c) 2022 Google LLC | ||
* Copyright (c) 2023 Gerson Fernando Budke <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
@@ -8,6 +9,9 @@ | |
|
||
#include <zephyr/device.h> | ||
#include <zephyr/drivers/gpio.h> | ||
#ifdef CONFIG_PINCTRL | ||
#include <zephyr/drivers/pinctrl.h> | ||
#endif | ||
#include <zephyr/input/input.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/logging/log.h> | ||
|
@@ -31,6 +35,9 @@ struct gpio_keys_config { | |
uint32_t debounce_interval_ms; | ||
const int num_keys; | ||
const struct gpio_keys_pin_config *pin_cfg; | ||
#ifdef CONFIG_PINCTRL | ||
const struct pinctrl_dev_config *pinctrl_cfg; | ||
#endif | ||
}; | ||
|
||
struct gpio_keys_pin_data { | ||
|
@@ -123,6 +130,13 @@ static int gpio_keys_init(const struct device *dev) | |
const struct gpio_keys_config *cfg = dev->config; | ||
int ret; | ||
|
||
#ifdef CONFIG_PINCTRL | ||
ret = pinctrl_apply_state(cfg->pinctrl_cfg, PINCTRL_STATE_DEFAULT); | ||
if (ret < 0) { | ||
return ret; | ||
} | ||
Comment on lines
+135
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will make the driver useless to any platform that has CONFIG_PINCTRL=y and no pinctrl entries for each gpio-keys subnode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is your suggestion about how to handle it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see my comment above |
||
#endif | ||
|
||
for (int i = 0; i < cfg->num_keys; i++) { | ||
const struct gpio_dt_spec *gpio = &cfg->pin_cfg[i].spec; | ||
|
||
|
@@ -163,13 +177,15 @@ static int gpio_keys_init(const struct device *dev) | |
} | ||
|
||
#define GPIO_KEYS_INIT(i) \ | ||
IF_ENABLED(CONFIG_PINCTRL, (PINCTRL_DT_INST_DEFINE(i);)) \ | ||
DT_INST_FOREACH_CHILD_STATUS_OKAY(i, GPIO_KEYS_CFG_CHECK); \ | ||
static const struct gpio_keys_pin_config gpio_keys_pin_config_##i[] = { \ | ||
DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(i, GPIO_KEYS_CFG_DEF, (,))}; \ | ||
static const struct gpio_keys_config gpio_keys_config_##i = { \ | ||
.debounce_interval_ms = DT_INST_PROP(i, debounce_interval_ms), \ | ||
.num_keys = ARRAY_SIZE(gpio_keys_pin_config_##i), \ | ||
.pin_cfg = gpio_keys_pin_config_##i, \ | ||
IF_ENABLED(CONFIG_PINCTRL, (.pinctrl_cfg = PINCTRL_DT_INST_DEV_CONFIG_GET(i),)) \ | ||
}; \ | ||
static struct gpio_keys_pin_data \ | ||
gpio_keys_pin_data_##i[ARRAY_SIZE(gpio_keys_pin_config_##i)]; \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2022-2023, Gerson Fernando Budke <[email protected]> | ||
* Copyright (c) 2022-2023 Gerson Fernando Budke <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
@@ -71,6 +71,10 @@ static void pinctrl_configure_pin(pinctrl_soc_pin_t pin) | |
if (port_func == SAM_PINMUX_FUNC_periph) { | ||
soc_pin.flags |= (SAM_PINMUX_PERIPH_GET(pin) | ||
<< SOC_GPIO_FUNC_POS); | ||
} else if (port_func == SAM_PINMUX_FUNC_wakeup) { | ||
soc_pin.flags |= (SAM_PINMUX_PERIPH_GET(pin) | ||
<< SOC_GPIO_FUNC_POS) | ||
| SAM_PINCTRL_WAKEUP; | ||
} | ||
|
||
soc_gpio_configure(&soc_pin); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you look at Linux, the way
gpio-keys
are configured as wake-up sources is via thewakeup-source
property (in each subnode). So, I guess the proper way to handle this is to make the input driver handle such property and forward it to the GPIO/pinctrl(?) driver when configuring the pin.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref https://www.kernel.org/doc/Documentation/devicetree/bindings/input/gpio-keys.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR seems to be the most far I can go with what is implemented in tree. IMHO the use of
wakeup-source
can be addressed in another moment because it seems to require a dedicated API which, for the moment, is out of scope for this PR. To propose an API change or new API require in deep knowledge from other architectures which I don't have.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine adding these pinctrl entries (thanks for the https://github.com/torvalds/linux/blob/750b95887e567848ac2c851dae47922cac6db946/arch/arm/boot/dts/microchip/at91-sama5d2_xplained.dts#L708-L720 example). However, these entries should be of course optional, and the driver needs to be prepared to handle the case when they're not present, that is, handle the
-ENOENT
error case gracefully. Also, thewakeup-source
can be used as a toggle to apply such configuration, I guess.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thank you. Can I get your approval on #64213 since it a dependency?
Perfect! I'll do it.
This is what I want add later on another PR but that is the final idea.