Allwinner A10 GPIO support
Subsystems (2)
cover Allwinner A10 GPIO support
This patch series introduces GPIO support for Allwinner A10 and Cubieboard.
The support is focused on input/output and interrupt functionality. The qtest suite is also updated with tests for implemented functionality.
---
Strahinja Jankovic (3):
hw/gpio: Allwinner A10 GPIO emulation
hw/arm: Add GPIO to Allwinner A10 model
tests/qtest: Allwinner GPIO tests
MAINTAINERS | 3 + docs/system/arm/cubieboard.rst | 1 + hw/arm/Kconfig | 1 + hw/arm/allwinner-a10.c | 8 + hw/gpio/Kconfig | 3 + hw/gpio/allwinner-gpio.c | 465 +++++++++++++++++++++++++++++++++ hw/gpio/meson.build | 1 + hw/gpio/trace-events | 6 + include/hw/arm/allwinner-a10.h | 2 + include/hw/gpio/allwinner-gpio-regs.h | 228 ++++++++++++++++ include/hw/gpio/allwinner-gpio.h | 41 +++ tests/qtest/allwinner-gpio-test.c | 474 ++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 13 files changed, 1235 insertions(+), 1 deletion(-)
---
base-commit: fa19879df1658f96ac07365fca8835b7decd6995
change-id: 20260818-allwinner-gpio-6ea84117df94
Best regards,
Signature · 1 line
Strahinja Jankovic <[email protected]>
PATCH 1/3 hw/gpio: Allwinner A10 GPIO emulation
This patch implements Allwinner A10 GPIO peripheral emulation.
The emulation focuses on input/output and interrupt functionality, whereas the drive and pull up/down functionality is not emulated.
--- MAINTAINERS | 2 + hw/gpio/Kconfig | 3 + hw/gpio/allwinner-gpio.c | 465 ++++++++++++++++++++++++++++++++++ hw/gpio/meson.build | 1 + hw/gpio/trace-events | 6 + include/hw/gpio/allwinner-gpio-regs.h | 228 +++++++++++++++++ include/hw/gpio/allwinner-gpio.h | 41 +++ 7 files changed, 746 insertions(+)
MAINTAINERS +2 -0
@@ -743,6 +743,8 @@ F: include/hw/*/allwinner* F: hw/arm/cubieboard.c F: docs/system/arm/cubieboard.rst F: hw/misc/axp2xx.c +F: hw/gpio/allwinner-gpio.c +F: include/hw/gpio/allwinner-gpio* F: tests/functional/arm/test_cubieboard.py Allwinner-h3
hw/gpio/Kconfig +3 -0
@@ -33,3 +33,6 @@ config ZAURUS_SCOOP config CADENCE_GPIO bool + +config ALLWINNER_GPIO + bool
hw/gpio/allwinner-gpio.c new file +465 -0
465 lines not on this page · raw message
hw/gpio/meson.build +1 -0
@@ -20,3 +20,4 @@ system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_sgpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c')) system_ss.add(when: 'CONFIG_CADENCE_GPIO', if_true: files('cadence_gpio.c')) +system_ss.add(when: 'CONFIG_ALLWINNER_GPIO', if_true: files('allwinner-gpio.c'))
hw/gpio/trace-events +6 -0
@@ -51,3 +51,9 @@ stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high) "GPIO%s di cdns_gpio_read(const char *path, uint64_t offset, uint32_t value) "%s:reg[0x%04" PRIx64 "] -> 0x%" PRIx32 cdns_gpio_write(const char *path, uint64_t offset, uint64_t value) "%s:reg[0x%04" PRIx64 "] <- 0x%04" PRIx64 cdns_gpio_set(const char *path, int line, int level) "%s:[%d] <- %d" + +# allwinner_gpio.c +allwinner_gpio_set(const char *port, int line, int level) "[%s:%d] <- %d" +allwinner_gpio_read(const char *reg, uint32_t value) "[%s] -> 0x%" PRIx32 +allwinner_gpio_write(const char *reg, uint32_t value) "[%s] <- 0x%" PRIx32 +allwinner_gpio_out_pin(const char *reg, uint32_t pin, uint32_t value) "[%s.%d] <- 0x%" PRIx32
include/hw/gpio/allwinner-gpio-regs.h new file +228 -0
228 lines not on this page · raw message
include/hw/gpio/allwinner-gpio.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH 1/3] hw/gpio: Allwinner A10 GPIO emulation
Hi,jankovic,I read datasheet of Allwinner and confirm basic address and most function do well. But there are still some place needing improvement.
Quoted 14 lines
hw/gpio/allwinner-gpio.c new file +14
-0+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 ); +} + +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 );
hw/gpio/allwinner-gpio.c line 246
Quoted 10 lines
hw/gpio/allwinner-gpio.c new file +10
-0+} + +static inline int int_ctl_cfg (AWGPIOState *s,int irq_line) +{ +unsigned int_cfg_n = s->regs[REG_INDEX (GPIO_INT_CFG0 ) + irq_line /8 ]; +return extract32 (int_cfg_n, + (irq_line %INT_CFG_IRQ_PER_REG ) *INT_CFG_IRQ_STRIDE , +INT_CFG_IRQ_STRIDE -1 ); +} +
there you use 'INT_CFG_IRQ_STRIDE - 1’ as stride for both two function。For int_ctl_cfg the stride is supposed to be 4 https://linux-sunxi.org/images/1/1e/Allwinner_A10_User_manual_V1.5.pdf in page 333 you can find it, now all qtest pass because double edge do not be designed in qtest(better add this test). But for input and output function it is right due to byte 3 is reserved.
Jack Wang
Re: [PATCH 1/3] hw/gpio: Allwinner A10 GPIO emulation
Hi Jack,
Thanks for reviewing the changes.
Quoted 28 lines · Jack Wang
Hi,jankovic,I read datasheet of Allwinner and confirm basic address and most function do well. But there are still some place needing improvement.
hw/gpio/allwinner-gpio.c
Quoted 5 lines
hw/gpio/allwinner-gpio.c new file +5
-0+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)==
hw/gpio/allwinner-gpio.c
Quoted 8 lines
hw/gpio/allwinner-gpio.c new file +8
-0+ CFG_OUTPUT_MASK); +} + +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)==
hw/gpio/allwinner-gpio.c
Quoted 6 lines
hw/gpio/allwinner-gpio.c new file +6
-0+ CFG_INPUT_MASK); +} + +static inline int int_ctl_cfg (AWGPIOState *s,int irq_line) +{ + unsigned int_cfg_n = s->regs[REG_INDEX(GPIO_INT_CFG0) + irq_line /8];
Review
Quoted 2 lines
(quoted diff) +2
-0+ return extract32(int_cfg_n, + (irq_line % INT_CFG_IRQ_PER_REG) *
INT_CFG_IRQ_STRIDE,
Quoted 10 lines
hw/gpio/allwinner-gpio.c line 246
Quoted 3 lines
hw/gpio/allwinner-gpio.c new file +3
-0+ INT_CFG_IRQ_STRIDE - 1); +} +there you use '
INT_CFG_IRQ_STRIDE- 1’ as stride for both two function。Forint_ctl_cfgthe stride is supposed to be 4
https://linux-sunxi.org/images/1/1e/Allwinner_A10_User_manual_V1.5.pdf in page 333 you can find it, now all qtest pass because double edge do not be designed in qtest(better add this test). But for input and output function it is right due to byte 3 is reserved.
The stride is set to 4 bits, but I am using only 3 bits when extracting the value for specific interrupt pin configuration, since the maximum non-reserved value that can be configured is 4 (for double edge). I will add the double edge test as well in the v2 patches.
Best regards,
Strahinja Jankovic
Quoted 3 lines
Jack Wang
PATCH 2/3 hw/arm: Add GPIO to Allwinner A10 model
In reply to Strahinja JankovicThe Allwinner A10 GPIO is added to the Allwinner A10 description, so it is available when Cubieboard is emulated.
Update the documentation for Cubieboard to indicate GPIO availability.
--- docs/system/arm/cubieboard.rst | 1 + hw/arm/Kconfig | 1 + hw/arm/allwinner-a10.c | 8 ++++++++ include/hw/arm/allwinner-a10.h | 2 ++ 4 files changed, 12 insertions(+)
docs/system/arm/cubieboard.rst +1 -0
@@ -12,6 +12,7 @@ Emulated devices: - RTC - EMAC - SDHCI +- GPIO - USB controller - SATA controller - TWI (I2C) controller
hw/arm/Kconfig +1 -0
@@ -311,6 +311,7 @@ config ALLWINNER_A10 select ALLWINNER_EMAC select ALLWINNER_I2C select ALLWINNER_A10_SPI + select ALLWINNER_GPIO select AXP2XX_PMU select SERIAL_MM select UNIMP
hw/arm/allwinner-a10.c +8 -0
@@ -41,6 +41,7 @@#define AW_A10_EHCI_BASE 0x01c14000#define AW_A10_OHCI_BASE 0x01c14400#define AW_A10_SATA_BASE 0x01c18000 +#define AW_A10_GPIO_BASE 0x01c20800#define AW_A10_WDT_BASE 0x01c20c90#define AW_A10_RTC_BASE 0x01c20d00#define AW_A10_I2C0_BASE 0x01c2ac00
@@ -83,6 +84,8 @@ static void aw_a10_init(Object *obj)object_initialize_child (obj,"spi0" , &s->spi0,TYPE_AW_A10_SPI ); +object_initialize_child (obj,"gpio" , &s->gpio,TYPE_AW_GPIO ); +for (size_t i =0 ; i <AW_A10_NUM_USB ; i++) {object_initialize_child (obj,"ehci[*]" , &s->ehci[i],TYPE_PLATFORM_EHCI );
@@ -203,6 +206,11 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->spi0),0 ,AW_A10_SPI0_BASE );sysbus_connect_irq (SYS_BUS_DEVICE (&s->spi0),0 ,qdev_get_gpio_in (dev,10 )); +/* GPIO */ +sysbus_realize (SYS_BUS_DEVICE (&s->gpio), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gpio),0 ,AW_A10_GPIO_BASE ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gpio),0 ,qdev_get_gpio_in (dev,28 )); +/* WDT */ sysbus_realize (SYS_BUS_DEVICE (&s->wdt), &error_fatal);sysbus_mmio_map_overlap (SYS_BUS_DEVICE (&s->wdt),0 ,AW_A10_WDT_BASE ,1 );
include/hw/arm/allwinner-a10.h +2 -0
@@ -13,6 +13,7 @@#include "hw/misc/allwinner-a10-dramc.h" #include "hw/i2c/allwinner-i2c.h" #include "hw/ssi/allwinner-a10-spi.h" +#include "hw/gpio/allwinner-gpio.h" #include "hw/watchdog/allwinner-wdt.h" #include "system/block-backend.h"
@@ -42,6 +43,7 @@ struct AwA10State {AwSdHostState mmc0;AWI2CState i2c0;AWA10SPIState spi0; +AWGPIOState gpio;AwRtcState rtc;AwWdtState wdt;MemoryRegion sram_a;
Signature · 1 line
2.55.0
PATCH 3/3 tests/qtest: Allwinner GPIO tests
In reply to Strahinja JankovicAdd Allwinner GPIO set of qtests to validate functionality. Tests cover input and output port setting, as well as interrupt functionality.
--- MAINTAINERS | 1 + tests/qtest/allwinner-gpio-test.c | 474 ++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 3 files changed, 477 insertions(+), 1 deletion(-)
MAINTAINERS +1 -0
@@ -746,6 +746,7 @@ F: hw/misc/axp2xx.c F: hw/gpio/allwinner-gpio.c F: include/hw/gpio/allwinner-gpio* F: tests/functional/arm/test_cubieboard.py +F: tests/qtest/allwinner-gpio-test.c Allwinner-h3 M: Niek Linnenbank <[email protected]>
tests/qtest/allwinner-gpio-test.c new file +474 -0
474 lines not on this page · raw message
tests/qtest/meson.build +2 -1
@@ -257,7 +257,8 @@ qtests_arm = \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ ['arm-cpu-features', - 'boot-serial-test'] + 'boot-serial-test'] + \ + (config_all_devices.has_key('CONFIG_ALLWINNER_A10')? ['allwinner-gpio-test'] : []) # TODO: once aarch64 TCG is fixed on ARM 32 bit host, make bios-tables-test unconditional qtests_aarch64 = \
Signature · 1 line
2.55.0