fix: Allwinner GPIO interrupt handling
v2 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.
---
Changes in v2:
- Moved changes to the interrupt handling tests to the first commit, so
tests still pass once the commit is applied.
- Kept new GPIO input test as a separate commit.
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]
---
Strahinja Jankovic (2):
hw/gpio: Add EINT CFG to Allwinner GPIO, fix interrupt handling tests/qtest: Add Allwinner GPIO input 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: a19f59a72d96056d9a8f48cf6c77f5787491e414
change-id: 20261009-allwinner-gpio-eint-1818f24ae7d5
Best regards,
Signature · 1 line
Strahinja Jankovic <[email protected]>
PATCH v2 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.
Also update interrupt handling tests for the correct functionality.
--- hw/gpio/allwinner-gpio.c | 19 ++++++++++++++----- include/hw/gpio/allwinner-gpio-regs.h | 5 +---- tests/qtest/allwinner-gpio-test.c | 30 +++++++++++++++--------------- 3 files changed, 30 insertions(+), 24 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 {
tests/qtest/allwinner-gpio-test.c +15 -15
@@ -251,9 +251,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 +296,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 +341,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 +394,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 +447,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 );
Signature · 1 line
2.56.0
PATCH v2 2/2 tests/qtest: Add Allwinner GPIO input test
In reply to Strahinja JankovicAdd test that configures pin to input mode and validates that manipulating input pin changed value in DAT register.
This was previously tested in the interrupt handling tests, but now is moved into a separate test.
--- tests/qtest/allwinner-gpio-test.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
tests/qtest/allwinner-gpio-test.c +27 -0
@@ -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) {
@@ -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
Peter Maydell
AppliedQuoted 24 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.
Tests are also updated to reflect this change, and a new test for pins configured as input is added.
Quoted 8 lines
Signed-off-by Strahinja Jankovic <[email protected]>---
Changes in v2:
- Moved changes to the interrupt handling tests to the first commit, so
tests still pass once the commit is applied.
- Kept new GPIO input test as a separate commit.
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]
Applied to target-arm.next, thanks.
-- PMM