[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/8] hw/gpio/avr_gpio: Add 'id' field in AVRGPIOState
From: |
Heecheol Yang |
Subject: |
[PATCH 3/8] hw/gpio/avr_gpio: Add 'id' field in AVRGPIOState |
Date: |
Mon, 12 Sep 2022 20:21:01 +0900 |
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
AVR MCU have various GPIO ports. Add an 'id' property to distinct
all instances.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20210313165445.2113938-6-f4bug@amsat.org>
Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
Signed-off-by: Heecheol Yang <heecheol.yang@outlook.com>
---
hw/avr/atmega.c | 1 +
hw/gpio/avr_gpio.c | 14 ++++++++++++--
include/hw/gpio/avr_gpio.h | 1 +
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/hw/avr/atmega.c b/hw/avr/atmega.c
index f5fb3a5225..d3a966ae94 100644
--- a/hw/avr/atmega.c
+++ b/hw/avr/atmega.c
@@ -284,6 +284,7 @@ static void atmega_realize(DeviceState *dev, Error **errp)
devname = g_strdup_printf("atmega-gpio-%c", 'a' + (char)i);
object_initialize_child(OBJECT(dev), devname, &s->gpio[i],
TYPE_AVR_GPIO);
+ qdev_prop_set_uint8(DEVICE(&s->gpio[i]), "id", i);
sysbus_realize(SYS_BUS_DEVICE(&s->gpio[i]), &error_abort);
sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio[i]), 0,
OFFSET_DATA + mc->dev[idx].addr);
diff --git a/hw/gpio/avr_gpio.c b/hw/gpio/avr_gpio.c
index da34009dae..3db55bfa77 100644
--- a/hw/gpio/avr_gpio.c
+++ b/hw/gpio/avr_gpio.c
@@ -113,6 +113,11 @@ static const VMStateDescription avr_gpio_vmstate = {
},
};
+static Property avr_gpio_properties[] = {
+ DEFINE_PROP_UINT8("id", AVRGPIOState, id, UINT8_MAX),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
static void avr_gpio_init(Object *obj)
{
AVRGPIOState *s = AVR_GPIO(obj);
@@ -123,9 +128,13 @@ static void avr_gpio_init(Object *obj)
}
static void avr_gpio_realize(DeviceState *dev, Error **errp)
{
- /* Do nothing currently */
-}
+ AVRGPIOState *s = AVR_GPIO(dev);
+ if (s->id == UINT8_MAX) {
+ error_setg(errp, "property 'id' not set");
+ return;
+ }
+}
static void avr_gpio_class_init(ObjectClass *klass, void *data)
{
@@ -134,6 +143,7 @@ static void avr_gpio_class_init(ObjectClass *klass, void
*data)
dc->reset = avr_gpio_reset;
dc->realize = avr_gpio_realize;
dc->vmsd = &avr_gpio_vmstate;
+ device_class_set_props(dc, avr_gpio_properties);
}
static const TypeInfo avr_gpio_info = {
diff --git a/include/hw/gpio/avr_gpio.h b/include/hw/gpio/avr_gpio.h
index 498a7275f0..e982f627ea 100644
--- a/include/hw/gpio/avr_gpio.h
+++ b/include/hw/gpio/avr_gpio.h
@@ -48,6 +48,7 @@ struct AVRGPIOState {
/* PORTx data changed IRQs */
qemu_irq out[8u];
+ uint8_t id;
};
#endif /* AVR_GPIO_H */
--
2.34.1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH 3/8] hw/gpio/avr_gpio: Add 'id' field in AVRGPIOState,
Heecheol Yang <=