All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Thomas Huth" <huth@tuxfamily.org>,
	"Sarah Harris" <S.E.Harris@kent.ac.uk>,
	"Michael Rolnik" <mrolnik@gmail.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [PATCH 05/11] hw/gpio/avr_gpio: Add 'id' field in AVRGPIOState
Date: Sat, 13 Mar 2021 17:54:39 +0100	[thread overview]
Message-ID: <20210313165445.2113938-6-f4bug@amsat.org> (raw)
In-Reply-To: <20210313165445.2113938-1-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>
---
 include/hw/gpio/avr_gpio.h |  1 +
 hw/avr/atmega.c            |  1 +
 hw/gpio/avr_gpio.c         | 14 ++++++++++++--
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/hw/gpio/avr_gpio.h b/include/hw/gpio/avr_gpio.h
index 498a7275f05..e982f627ea3 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 */
diff --git a/hw/avr/atmega.c b/hw/avr/atmega.c
index 19c3122189f..a19e3035022 100644
--- a/hw/avr/atmega.c
+++ b/hw/avr/atmega.c
@@ -285,6 +285,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 da34009daea..3db55bfa77f 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 = {
-- 
2.26.2



  parent reply	other threads:[~2021-03-13 17:10 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-13 16:54 [PATCH 00/11] AVR patch queue for QEMU 6.0 Philippe Mathieu-Daudé
2021-03-13 16:54 ` [PATCH 01/11] hw/misc/led: Add yellow LED Philippe Mathieu-Daudé
2021-03-13 19:51   ` Richard Henderson
2021-03-13 16:54 ` [PATCH 02/11] hw/avr/arduino: List board schematic links Philippe Mathieu-Daudé
2021-03-13 19:51   ` Richard Henderson
2021-03-13 16:54 ` [PATCH 03/11] hw/avr: Add limited support for avr gpio registers Philippe Mathieu-Daudé
2021-03-13 19:55   ` Richard Henderson
2021-03-14 10:26   ` Mark Cave-Ayland
2021-03-14 23:41     ` Philippe Mathieu-Daudé
2021-03-15 13:15   ` Sarah Harris
2021-03-13 16:54 ` [PATCH 04/11] hw/gpio/avr_gpio: Add migration VMstate Philippe Mathieu-Daudé
2021-03-13 19:57   ` Richard Henderson
2021-03-13 16:54 ` Philippe Mathieu-Daudé [this message]
2021-03-13 19:58   ` [PATCH 05/11] hw/gpio/avr_gpio: Add 'id' field in AVRGPIOState Richard Henderson
2021-03-13 16:54 ` [PATCH 06/11] hw/gpio/avr_gpio: Simplify avr_gpio_write_port using extract32() Philippe Mathieu-Daudé
2021-03-13 19:59   ` Richard Henderson
2021-03-13 16:54 ` [PATCH 07/11] hw/gpio/avr_gpio: Add tracing for reads and writes Philippe Mathieu-Daudé
2021-03-13 17:21   ` Niteesh G. S.
2021-03-23  2:42     ` Niteesh G. S.
2021-03-23  8:39       ` Philippe Mathieu-Daudé
2021-03-13 16:54 ` [PATCH 08/11] hw/avr/arduino: Add D13 LED Philippe Mathieu-Daudé
2021-03-13 17:02   ` Niteesh G. S.
2021-03-13 17:21     ` Niteesh G. S.
2021-03-13 16:54 ` [PATCH 09/11] hw/avr/arduino: Replace magic number by gpio_port_index() call Philippe Mathieu-Daudé
2021-03-13 20:02   ` Richard Henderson
2021-03-13 22:20     ` Philippe Mathieu-Daudé
2021-03-13 16:54 ` [PATCH 10/11] target/avr: Fix some comment spelling errors Philippe Mathieu-Daudé
2021-03-13 16:54 ` [PATCH 11/11] target/avr: Fix interrupt execution Philippe Mathieu-Daudé
2021-03-13 22:16 ` [PATCH 00/11] AVR patch queue for QEMU 6.0 Michael Rolnik
2021-03-14 23:42 ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210313165445.2113938-6-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=S.E.Harris@kent.ac.uk \
    --cc=huth@tuxfamily.org \
    --cc=mrolnik@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.