Skip to contentSkip to conversation

Allwinner A10 GPIO support

PATCH Applied Strahinja Jankovic 2 participants 5 messages Sep 15 – Sep 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 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.

---
Changes in v4:
- removed unused allwinner_gpio_update_all_output_lines function that
was flagged by clang
- Link to v3: https://lore.kernel.org/qemu-devel/[email protected]

Changes in v3:
- replaced forward declarations of gpio_is_input and int_ctl_cfg with
definitions
- updated use of extract32 for int_cfg_n to use full stride INT_CFG_IRQ_STRIDE
- replaced custom bit manipulation with deposit32
- updated output GPIO line handling to have same behavior when lines are
configured as input as when they are assigned to special function
- removed update of outbound gpio lines in the reset function
- improved test organization with common add_test function, as suggested
- removed leftover comments
- minor style fixes
- Link to v2: https://lore.kernel.org/qemu-devel/[email protected]

Changes in v2:
- allwinner-gpio-test: Added test for interrupt triggered on both rising
and falling edge
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]

---
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              | 441 ++++++++++++++++++++++++++++
 hw/gpio/meson.build                   |   1 +
 hw/gpio/trace-events                  |   6 +
 include/hw/arm/allwinner-a10.h        |   2 +
 include/hw/gpio/allwinner-gpio-regs.h | 227 +++++++++++++++
 include/hw/gpio/allwinner-gpio.h      |  41 +++
 tests/qtest/allwinner-gpio-test.c     | 535 ++++++++++++++++++++++++++++++++++
 tests/qtest/meson.build               |   3 +-
 13 files changed, 1271 insertions(+), 1 deletion(-)

---
base-commit: 302c2f2df4d8b2eec81c38ee5d5b04e8e6e40d31
change-id: 20260818-allwinner-gpio-6ea84117df94

Best regards,

Signature · 1 line
Strahinja Jankovic <[email protected]>
#1 lore raw

PATCH v4 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              | 441 ++++++++++++++++++++++++++++++++++
 hw/gpio/meson.build                   |   1 +
 hw/gpio/trace-events                  |   6 +
 include/hw/gpio/allwinner-gpio-regs.h | 227 +++++++++++++++++
 include/hw/gpio/allwinner-gpio.h      |  41 ++++
 7 files changed, 721 insertions(+)
MAINTAINERS +2 -0
index 5bf895732c..b453edc820 100644
@@ -746,6 +746,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
index fcc7c70bd5..ea0fb72b40 100644
@@ -33,3 +33,6 @@ config ZAURUS_SCOOP
 
 config CADENCE_GPIO
     bool
+
+config ALLWINNER_GPIO
+    bool
hw/gpio/allwinner-gpio.c new file +441 -0

441 lines not on this page · raw message

hw/gpio/meson.build +1 -0
index 0555f44b6a..8ede5e88ae 100644
@@ -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
index 80ca783a03..5ef3e0b8fd 100644
@@ -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 +227 -0

227 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
#2 lore raw

PATCH v4 2/3 hw/arm: Add GPIO to Allwinner A10 model

In reply to Strahinja Jankovic

The 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
index 90d24c73a1..ee9f489ead 100644
@@ -12,6 +12,7 @@ Emulated devices:
 - RTC
 - EMAC
 - SDHCI
+- GPIO
 - USB controller
 - SATA controller
 - TWI (I2C) controller
hw/arm/Kconfig +1 -0
index eae06369b0..4445f16f45 100644
@@ -295,6 +295,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
index 66f30757dd..66fe484ae0 100644
@@ -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
index 445ba1be21..8b7736c7bd 100644
@@ -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
#3 lore raw

PATCH v4 3/3 tests/qtest: Allwinner GPIO tests

In reply to Strahinja Jankovic

Add 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 | 535 ++++++++++++++++++++++++++++++++++++++
 tests/qtest/meson.build           |   3 +-
 3 files changed, 538 insertions(+), 1 deletion(-)
MAINTAINERS +1 -0
index b453edc820..da6b588eca 100644
@@ -749,6 +749,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 +535 -0

535 lines not on this page · raw message

tests/qtest/meson.build +2 -1
index c3593f7530..6c5db1a0a3 100644
@@ -268,7 +268,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