Add gpios in/out init for aspeed gpio to add the ability to connect to other gpio devices.
Based the qdev-core.h comments, If you want to connect a GPIO to other devices, you need to call qdev_init_gpio_in() or qdev_init_gpio_out(). ``` For input gpios: * * Outbound GPIO lines can be connected to any qemu_irq, but the common * case is connecting them to another device's inbound GPIO line, using * the qemu_irq returned by qdev_get_gpio_in() or qdev_get_gpio_in_named(). For output gpios: * This function is intended to be used by board code or SoC "container" * device models to wire up the GPIO lines; usually the return value * will be passed to qdev_connect_gpio_out() or a similar function to * connect another device's output GPIO line to this input. ``` Signed-off-by: Jian Zhang <zhangjian.3...@bytedance.com> --- hw/gpio/aspeed_gpio.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/gpio/aspeed_gpio.c b/hw/gpio/aspeed_gpio.c index e99c4c6329..616ec8db52 100644 --- a/hw/gpio/aspeed_gpio.c +++ b/hw/gpio/aspeed_gpio.c @@ -1018,6 +1018,17 @@ static void aspeed_gpio_reset(DeviceState *dev) memset(s->sets, 0, sizeof(s->sets)); } +static void aspeed_gpio_set(void *opaque, int line, int new_state) +{ + AspeedGPIOState *s = ASPEED_GPIO(opaque); + uint32_t set_idx, pin; + + set_idx = line / ASPEED_GPIOS_PER_SET; + pin = line % ASPEED_GPIOS_PER_SET; + + aspeed_gpio_set_pin_level(s, set_idx, pin, new_state); +} + static void aspeed_gpio_realize(DeviceState *dev, Error **errp) { AspeedGPIOState *s = ASPEED_GPIO(dev); @@ -1042,6 +1053,12 @@ static void aspeed_gpio_realize(DeviceState *dev, Error **errp) memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_gpio_ops, s, TYPE_ASPEED_GPIO, 0x800); + /* TODO: Maybe could in named, not anonymous is better */ + qdev_init_gpio_out(dev, &s->gpios[0][0], + ASPEED_GPIO_MAX_NR_SETS * ASPEED_GPIOS_PER_SET); + qdev_init_gpio_in(dev, aspeed_gpio_set, + ASPEED_GPIO_MAX_NR_SETS * ASPEED_GPIOS_PER_SET); + sysbus_init_mmio(sbd, &s->iomem); } -- 2.25.1