From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Peter Maydell <peter.maydell@linaro.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Alexander Graf <graf@amazon.com>,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bartekgola@gmail.com>,
Magnus Damm <magnus.damm@gmail.com>
Cc: linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org,
qemu-arm@nongnu.org, qemu-devel@nongnu.org,
Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH QEMU v2 4/5] ARM: PL061: Add gpiodev support
Date: Thu, 23 Apr 2020 11:01:17 +0200 [thread overview]
Message-ID: <20200423090118.11199-5-geert+renesas@glider.be> (raw)
In-Reply-To: <20200423090118.11199-1-geert+renesas@glider.be>
Make the PL061 GPIO controller user-creatable, and allow the user to tie
a newly created instance to a gpiochip on the host.
To create a new GPIO controller, the QEMU command line must be augmented
with:
-device pl061,host=<gpiochip>
with <gpiochip> the name or label of the gpiochip on the host.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
- New.
---
hw/gpio/pl061.c | 35 +++++++++++++++++++++++++++++++++++
qemu-options.hx | 9 +++++++++
2 files changed, 44 insertions(+)
diff --git a/hw/gpio/pl061.c b/hw/gpio/pl061.c
index 74ba733a8a5e8ca5..98204f9a586ae8c8 100644
--- a/hw/gpio/pl061.c
+++ b/hw/gpio/pl061.c
@@ -12,11 +12,14 @@
#include "hw/arm/fdt.h"
#include "hw/gpio/pl061.h"
#include "hw/irq.h"
+#include "hw/qdev-properties.h"
#include "hw/sysbus.h"
#include "migration/vmstate.h"
+#include "qapi/error.h"
#include "qemu/log.h"
#include "qemu/module.h"
#include "sysemu/device_tree.h"
+#include "sysemu/gpiodev.h"
//#define DEBUG_PL061 1
@@ -41,6 +44,9 @@ static const uint8_t pl061_id_luminary[12] =
typedef struct PL061State {
SysBusDevice parent_obj;
+#ifdef CONFIG_GPIODEV
+ char *host;
+#endif
MemoryRegion iomem;
uint32_t locked;
uint32_t data;
@@ -370,10 +376,39 @@ static void pl061_init(Object *obj)
qdev_init_gpio_out(dev, s->out, 8);
}
+#ifdef CONFIG_GPIODEV
+static Property pl061_properties[] = {
+ DEFINE_PROP_STRING("host", PL061State, host),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void pl061_realize(DeviceState *dev, Error **errp)
+{
+ PL061State *s = PL061(dev);
+
+ if (!dev->opts) {
+ /* Not created by user */
+ return;
+ }
+
+ if (!s->host) {
+ error_setg(errp, "'host' property is required");
+ return;
+ }
+
+ qemu_gpiodev_add(dev, s->host, 8, errp);
+}
+#endif /* CONFIG_GPIODEV */
+
static void pl061_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+#ifdef CONFIG_GPIODEV
+ device_class_set_props(dc, pl061_properties);
+ dc->realize = pl061_realize;
+ dc->user_creatable = true;
+#endif
dc->vmsd = &vmstate_pl061;
dc->reset = &pl061_reset;
}
diff --git a/qemu-options.hx b/qemu-options.hx
index 292d4e7c0cef6097..182de7fb63923b38 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -875,6 +875,15 @@ SRST
``-device isa-ipmi-bt,bmc=id[,ioport=val][,irq=val]``
Like the KCS interface, but defines a BT interface. The default port
is 0xe4 and the default interrupt is 5.
+
+#ifdef CONFIG_GPIODEV
+``-device pl061,host=gpiochip``
+ Add a PL061 GPIO controller, and map its virtual GPIO lines to a GPIO
+ controller on the host.
+
+ ``host=gpiochip``
+ The name or label of the GPIO controller on the host.
+#endif
ERST
DEF("name", HAS_ARG, QEMU_OPTION_name,
--
2.17.1
next prev parent reply other threads:[~2020-04-23 9:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-23 9:01 [PATCH QEMU v2 0/5] Add a GPIO backend Geert Uytterhoeven
2020-04-23 9:01 ` [PATCH QEMU v2 1/5] ARM: PL061: Move TYPE_PL061 to hw/gpio/pl061.h Geert Uytterhoeven
2020-04-23 9:22 ` Philippe Mathieu-Daudé
2020-04-23 9:01 ` [PATCH QEMU v2 2/5] ARM: PL061: Extract pl061_create_fdt() Geert Uytterhoeven
2020-04-23 9:23 ` Philippe Mathieu-Daudé
2020-04-23 9:01 ` [PATCH QEMU v2 3/5] Add a GPIO backend using libgpiod Geert Uytterhoeven
2020-04-23 9:28 ` Philippe Mathieu-Daudé
2020-04-23 9:41 ` Geert Uytterhoeven
2020-04-23 10:06 ` Philippe Mathieu-Daudé
2020-04-23 9:01 ` Geert Uytterhoeven [this message]
2020-04-23 9:33 ` [PATCH QEMU v2 4/5] ARM: PL061: Add gpiodev support Philippe Mathieu-Daudé
2020-04-23 10:08 ` Philippe Mathieu-Daudé
2020-07-16 14:10 ` Geert Uytterhoeven
2020-04-23 9:01 ` [PATCH QEMU v2 5/5] hw/arm/virt: Add dynamic PL061 GPIO support Geert Uytterhoeven
2020-04-23 9:13 ` [PATCH QEMU v2 0/5] Add a GPIO backend no-reply
2020-04-23 9:34 ` no-reply
2020-04-23 9:40 ` no-reply
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=20200423090118.11199-5-geert+renesas@glider.be \
--to=geert+renesas@glider.be \
--cc=bartekgola@gmail.com \
--cc=graf@amazon.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).