fix: Allwinner GPIO interrupt handling
cover fix: Allwinner GPIO interrupt handling
The original patches assumed that pin had to be configured as input in order to be able to receive interrupt. However, after additional testing with libgpiod and gpiomon, the pin is actually supposed to be configured as EINT (0x06). In the following example with PH1
root@cubieboard-ng:~# gpioget -c 0 224 allwinner_gpio_read [PH:CFG0] -> 0x1061061 allwinner_gpio_write [PH:CFG0] <- 0x1061060 allwinner_gpio_read [PH:DAT] -> 0x49 "224"=active root@cubieboard-ng:~# gpiomon -c 0 224 allwinner_gpio_read [PH:CFG0] -> 0x1061060 allwinner_gpio_write [PH:CFG0] <- 0x1061066 ...
The CFG0 value on the lowest nibble changes from 0 to 6.
This patch set fixes that behavior to expect that pin is configured as EINT in order to allow interrupt-related functionality.
Tests are also updated to reflect this change, and a new test for pins configured as input is added.
---
Strahinja Jankovic (2):
hw/gpio: Add EINT CFG to Allwinner GPIO, fix interrupt handling tests/qtest: Update Allwinner GPIO test
hw/gpio/allwinner-gpio.c | 19 +++++++++--- include/hw/gpio/allwinner-gpio-regs.h | 5 +-- tests/qtest/allwinner-gpio-test.c | 57 ++++++++++++++++++++++++++--------- 3 files changed, 57 insertions(+), 24 deletions(-)
---
base-commit: 602e4f2da10ef642581cfcd5caf5d1534808caa2
change-id: 20261009-allwinner-gpio-eint-1818f24ae7d5
Best regards,
Signature · 1 line
Strahinja Jankovic <[email protected]>
PATCH 1/2 hw/gpio: Add EINT CFG to Allwinner GPIO, fix interrupt handling
The original Allwinner GPIO implementation assumed pin had to be configured as input (CFG 0x0) in order to be able to handle interrupts on interrupt-capable pins.
However, libgpiod configures those pins in EINT mode (CFG 0x06) when gpiomon is used, so this patch fixes interrupt path to expect pin configuration to be set to EINT.
--- hw/gpio/allwinner-gpio.c | 19 ++++++++++++++----- include/hw/gpio/allwinner-gpio-regs.h | 5 +---- 2 files changed, 15 insertions(+), 9 deletions(-)
hw/gpio/allwinner-gpio.c +14 -5
@@ -114,7 +114,7 @@ static inline bool gpio_is_output(AWPortMap *port, uint32_t pin)uint32_t cfg_n = pin /CFG_PINS_PER_REG ;uint32_t pin_shift = (pin %CFG_PINS_PER_REG ) *CFG_PIN_STRIDE ;return (extract32 (port->cfg[cfg_n], pin_shift,CFG_PIN_STRIDE -1 ) == -CFG_OUTPUT_MASK ); +AW_GPIO_CFG_OUT ); }static inline bool gpio_is_input (AWPortMap *port,uint32_t pin)
@@ -122,7 +122,15 @@ static inline bool gpio_is_input(AWPortMap *port, uint32_t pin)uint32_t cfg_n = pin /CFG_PINS_PER_REG ;uint32_t pin_shift = (pin %CFG_PINS_PER_REG ) *CFG_PIN_STRIDE ;return (extract32 (port->cfg[cfg_n], pin_shift,CFG_PIN_STRIDE -1 ) == -CFG_INPUT_MASK ); +AW_GPIO_CFG_IN ); +} + +static inline bool gpio_is_eint (AWPortMap *port,uint32_t pin) +{ +uint32_t cfg_n = pin /CFG_PINS_PER_REG ; +uint32_t pin_shift = (pin %CFG_PINS_PER_REG ) *CFG_PIN_STRIDE ; +return (extract32 (port->cfg[cfg_n], pin_shift,CFG_PIN_STRIDE -1 ) == +AW_GPIO_CFG_EINT ); }static inline int int_ctl_cfg (AWGPIOState *s,int irq_line)
@@ -155,8 +163,8 @@ static void allwinner_gpio_set_int_line(AWGPIOState *s, int port,return ; } -/* if this signal isn't configured as an input signal, nothing to do */ -if (!gpio_is_input (&o->ports[port], line)) { +/* if this signal isn't configured as an EINT, nothing to do */ +if (!gpio_is_eint (&o->ports[port], line)) {return ; }
@@ -225,7 +233,8 @@ static void allwinner_gpio_set(void *opaque, int port, int line, int level)AWPortsOverlay *o = (AWPortsOverlay *)s->regs;AWGPIOLevel aw_level = level ?AW_GPIO_LEVEL_HIGH :AW_GPIO_LEVEL_LOW ; -if (gpio_is_input (&o->ports[port], line)) { +if (gpio_is_input (&o->ports[port], line) || +gpio_is_eint (&o->ports[port], line)) {trace_allwinner_gpio_set (portname (port), line, aw_level);
include/hw/gpio/allwinner-gpio-regs.h +1 -4
@@ -73,9 +73,6 @@ static const AWPortResetVals aw_gpio_port_reset[] = {#define DEFAULT_DRV_MASK 0xffffffff#define DEFAULT_PUL_MASK 0xffffffff -#define CFG_INPUT_MASK 0x0 -#define CFG_OUTPUT_MASK 0x1 -#define CFG_IO_MASK 0x1#define CFG_PIN_STRIDE 4#define CFG_PINS_PER_REG (AW_GPIO_PIN_COUNT / CFG_PIN_STRIDE)
@@ -172,7 +169,7 @@ typedef enum AWGPIOLevel {typedef enum AWGPIOCfg {AW_GPIO_CFG_IN =0 ,AW_GPIO_CFG_OUT =1 , -AW_GPIO_CFG_FUN =2 , +AW_GPIO_CFG_EINT =6 , }AWGPIOCfg ; typedef enum AWGPIOIrqCfg {
Signature · 1 line
2.56.0
PATCH 2/2 tests/qtest: Update Allwinner GPIO test
In reply to Strahinja JankovicFix tests to configure pin to EINT mode instead of input for interrupt testing.
Also add test the configures pin to input mode and validates that manipulating input pin changed value in DAT register.
--- tests/qtest/allwinner-gpio-test.c | 57 ++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 15 deletions(-)
tests/qtest/allwinner-gpio-test.c +42 -15
@@ -238,6 +238,32 @@ static void test_set_input_pins(const void *data)qtest_quit (s); } +/* +* Set pin to input, check that the value is written to DAT register +*/ +static void test_get_input_pins (const void *data) +{ +PortPinTestParam *param = (PortPinTestParam *)data; + g_autofree char *in_name = portname_in(param->port); + +QTestState *s =qtest_init ("-machine cubieboard" ); + +/* Configure pin as input */ +update_cfg_reg (s, param->port, param->pin,AW_GPIO_CFG_IN ); +qtest_set_irq_in (s, +"/machine/soc/gpio" , in_name, param->pin, +AW_GPIO_LEVEL_LOW ); +assert_data_reg (s, param->port, param->pin,AW_GPIO_LEVEL_LOW ); + +/* Change input value */ +qtest_set_irq_in (s, +"/machine/soc/gpio" , in_name, param->pin, +AW_GPIO_LEVEL_HIGH ); +assert_data_reg (s, param->port, param->pin,AW_GPIO_LEVEL_HIGH ); + +qtest_quit (s); +} +/* Test rising edge interrupt */ static void test_irq_pin_rising (const void *data) {
@@ -251,9 +277,9 @@ static void test_irq_pin_rising(const void *data)qtest_irq_intercept_in (s,"/machine/soc" ); -/* Configure as input and set pin low */ -update_cfg_reg (s, gpio_port, port_pin,AW_GPIO_CFG_IN ); -assert_cfg_regval (s, gpio_port, port_pin,AW_GPIO_CFG_IN ); +/* Configure as EINT and set pin low */ +update_cfg_reg (s, gpio_port, port_pin,AW_GPIO_CFG_EINT ); +assert_cfg_regval (s, gpio_port, port_pin,AW_GPIO_CFG_EINT );qtest_set_irq_in (s,"/machine/soc/gpio" , in_name, port_pin,AW_GPIO_LEVEL_LOW );
@@ -296,9 +322,9 @@ static void test_irq_pin_falling(const void *data)qtest_irq_intercept_in (s,"/machine/soc" ); -/* Configure as input and set pin high */ -update_cfg_reg (s, gpio_port, port_pin,AW_GPIO_CFG_IN ); -assert_cfg_regval (s, gpio_port, port_pin,AW_GPIO_CFG_IN ); +/* Configure as EINT and set pin high */ +update_cfg_reg (s, gpio_port, port_pin,AW_GPIO_CFG_EINT ); +assert_cfg_regval (s, gpio_port, port_pin,AW_GPIO_CFG_EINT );qtest_set_irq_in (s,"/machine/soc/gpio" , in_name, port_pin,AW_GPIO_LEVEL_HIGH );
@@ -341,9 +367,9 @@ static void test_irq_pin_high_level(const void *data)qtest_irq_intercept_in (s,"/machine/soc" ); -/* Configure as input and set pin low */ -update_cfg_reg (s, gpio_port, port_pin,AW_GPIO_CFG_IN ); -assert_cfg_regval (s, gpio_port, port_pin,AW_GPIO_CFG_IN ); +/* Configure as EINT and set pin low */ +update_cfg_reg (s, gpio_port, port_pin,AW_GPIO_CFG_EINT ); +assert_cfg_regval (s, gpio_port, port_pin,AW_GPIO_CFG_EINT );qtest_set_irq_in (s,"/machine/soc/gpio" , in_name, port_pin,AW_GPIO_LEVEL_LOW );
@@ -394,9 +420,9 @@ static void test_irq_pin_low_level(const void *data)qtest_irq_intercept_in (s,"/machine/soc" ); -/* Configure as input and set pin high */ -update_cfg_reg (s, gpio_port, port_pin,AW_GPIO_CFG_IN ); -assert_cfg_regval (s, gpio_port, port_pin,AW_GPIO_CFG_IN ); +/* Configure as EINT and set pin high */ +update_cfg_reg (s, gpio_port, port_pin,AW_GPIO_CFG_EINT ); +assert_cfg_regval (s, gpio_port, port_pin,AW_GPIO_CFG_EINT );qtest_set_irq_in (s,"/machine/soc/gpio" , in_name, port_pin,AW_GPIO_LEVEL_HIGH );
@@ -447,9 +473,9 @@ static void test_irq_pin_both_edge(const void *data)qtest_irq_intercept_in (s,"/machine/soc" ); -/* Configure as input and set pin low */ -update_cfg_reg (s, gpio_port, port_pin,AW_GPIO_CFG_IN ); -assert_cfg_regval (s, gpio_port, port_pin,AW_GPIO_CFG_IN ); +/* Configure as EINT and set pin low */ +update_cfg_reg (s, gpio_port, port_pin,AW_GPIO_CFG_EINT ); +assert_cfg_regval (s, gpio_port, port_pin,AW_GPIO_CFG_EINT );qtest_set_irq_in (s,"/machine/soc/gpio" , in_name, port_pin,AW_GPIO_LEVEL_LOW );
@@ -518,6 +544,7 @@ int main(int argc, char **argv)const PortPinTestParam *p = &in_out_test_parameters[i];add_test ("set_output_pins" , p, test_set_output_pins);add_test ("set_input_pins" , p, test_set_input_pins); +add_test ("get_input_pins" , p, test_get_input_pins); }qtest_add_func ("/allwinner-cubieboard/gpio/reset_values" , test_reset_values);
Signature · 1 line
2.56.0
Quoted 21 lines · Strahinja Jankovic
The original patches assumed that pin had to be configured as input in order to be able to receive interrupt. However, after additional testing with libgpiod and gpiomon, the pin is actually supposed to be configured as EINT (
0x06). In the following example with PH1root@cubieboard-ng:~# gpioget -c 0 224 allwinner_gpio_read [PH:CFG0] -> 0x1061061 allwinner_gpio_write [PH:CFG0] <- 0x1061060 allwinner_gpio_read [PH:DAT] -> 0x49 "224"=active root@cubieboard-ng:~# gpiomon -c 0 224 allwinner_gpio_read [PH:CFG0] -> 0x1061060 allwinner_gpio_write [PH:CFG0] <- 0x1061066 ...The CFG0 value on the lowest nibble changes from 0 to 6.
This patch set fixes that behavior to expect that pin is configured as EINT in order to allow interrupt-related functionality.
Quoted 8 lines
Tests are also updated to reflect this change, and a new test for pins configured as input is added.
Signed-off-by Strahinja Jankovic <[email protected]>---
Strahinja Jankovic (2):
hw/gpio: Add EINT CFG to Allwinner GPIO, fix interrupt handling tests/qtest: Update Allwinner GPIO test
This series fails "make check" when patch 1 is applied but not 2. We need to retain "builds and passes tests" at every point in a multiple-commit series, so that "git bisect" works.
I would suggest moving the minimal changes to update the test to match the new behaviour into patch 1, and adding the new get_input_pins patch in patch 2.
thanks
-- PMM
Hi Peter,
Thanks for checking this and for detailed explanation. I will send new patches with the fixes.
Best regards,
Strahinja
Quoted 43 lines · Peter Maydell
Quoted 21 lines · Strahinja Jankovic
The original patches assumed that pin had to be configured as input in order to be able to receive interrupt. However, after additional testing with libgpiod and gpiomon, the pin is actually supposed to be configured as EINT (
0x06). In the following example with PH1root@cubieboard-ng:~# gpioget -c 0 224 allwinner_gpio_read [PH:CFG0] -> 0x1061061 allwinner_gpio_write [PH:CFG0] <- 0x1061060 allwinner_gpio_read [PH:DAT] -> 0x49 "224"=active root@cubieboard-ng:~# gpiomon -c 0 224 allwinner_gpio_read [PH:CFG0] -> 0x1061060 allwinner_gpio_write [PH:CFG0] <- 0x1061066 ...The CFG0 value on the lowest nibble changes from 0 to 6.
This patch set fixes that behavior to expect that pin is configured as EINT in order to allow interrupt-related functionality.
Quoted 8 lines
Tests are also updated to reflect this change, and a new test for pins configured as input is added.
Signed-off-by Strahinja Jankovic <[email protected]>---
Strahinja Jankovic (2):
hw/gpio: Add EINT CFG to Allwinner GPIO, fix interrupt handling tests/qtest: Update Allwinner GPIO testThis series fails "make check" when patch 1 is applied but not 2. We need to retain "builds and passes tests" at every point in a multiple-commit series, so that "git bisect" works.
I would suggest moving the minimal changes to update the test to match the new behaviour into patch 1, and adding the new
get_input_pinspatch in patch 2.thanks
-- PMM