From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Andrew Jeffery" <andrew@aj.id.au>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-arm@nongnu.org, "Joel Stanley" <joel@jms.id.au>,
"Cédric Le Goater" <clg@kaod.org>
Subject: [PATCH v3 2/7] hw/misc/led: Add helper to connect LED to GPIO output
Date: Sun, 21 Jun 2020 01:07:14 +0200 [thread overview]
Message-ID: <20200620230719.32139-3-f4bug@amsat.org> (raw)
In-Reply-To: <20200620230719.32139-1-f4bug@amsat.org>
Some devices expose GPIO lines. Add the create_led_by_gpio_id()
helper to connect a LED to such GPIO.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
Adding support for named GPIO is trivial. We don't need it yet.
---
include/hw/misc/led.h | 20 ++++++++++++++++++++
hw/misc/led.c | 25 +++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/include/hw/misc/led.h b/include/hw/misc/led.h
index 821ee1247d..883006bb8f 100644
--- a/include/hw/misc/led.h
+++ b/include/hw/misc/led.h
@@ -35,6 +35,8 @@ typedef struct LEDState {
DeviceState parent_obj;
/* Public */
+ qemu_irq irq;
+
/* Properties */
char *description;
char *color;
@@ -76,4 +78,22 @@ DeviceState *create_led(Object *parentobj,
const char *description,
uint16_t reset_intensity);
+/**
+ * create_led_by_gpio_id: create and LED device and connect it to a GPIO output
+ * @parent: the parent object
+ * @gpio_dev: device exporting GPIOs
+ * @gpio_id: GPIO ID of this LED
+ * @color: color of the LED
+ * @description: description of the LED (optional)
+ * @reset_intensity: LED intensity at reset
+ *
+ * This utility function creates a LED and connects it to a
+ * GPIO exported by another device.
+ */
+DeviceState *create_led_by_gpio_id(Object *parentobj,
+ DeviceState *gpio_dev, unsigned gpio_id,
+ LEDColor color,
+ const char *description,
+ uint16_t reset_intensity);
+
#endif /* HW_MISC_LED_H */
diff --git a/hw/misc/led.c b/hw/misc/led.c
index e55ed7dbc4..8503dde777 100644
--- a/hw/misc/led.c
+++ b/hw/misc/led.c
@@ -10,6 +10,7 @@
#include "migration/vmstate.h"
#include "hw/qdev-properties.h"
#include "hw/misc/led.h"
+#include "hw/irq.h"
#include "trace.h"
static const char *led_color(LEDColor color)
@@ -39,6 +40,14 @@ void led_set_state(LEDState *s, bool is_on)
led_set_intensity(s, is_on ? UINT16_MAX : 0);
}
+static void gpio_led_set(void *opaque, int line, int new_state)
+{
+ LEDState *s = LED(opaque);
+
+ assert(line == 0);
+ led_set_state(s, !!new_state);
+}
+
static void led_reset(DeviceState *dev)
{
LEDState *s = LED(dev);
@@ -63,6 +72,8 @@ static void led_realize(DeviceState *dev, Error **errp)
error_setg(errp, "property 'color' not specified");
return;
}
+
+ qdev_init_gpio_in(DEVICE(s), gpio_led_set, 1);
}
static Property led_properties[] = {
@@ -119,3 +130,17 @@ DeviceState *create_led(Object *parentobj,
return dev;
}
+
+DeviceState *create_led_by_gpio_id(Object *parentobj,
+ DeviceState *gpio_dev, unsigned gpio_id,
+ LEDColor color,
+ const char *description,
+ uint16_t reset_intensity)
+{
+ DeviceState *dev;
+
+ dev = create_led(parentobj, color, description, reset_intensity);
+ qdev_connect_gpio_out(gpio_dev, gpio_id, qdev_get_gpio_in(dev, 0));
+
+ return dev;
+}
--
2.21.3
next prev parent reply other threads:[~2020-06-20 23:09 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-20 23:07 [PATCH v3 0/7] hw/misc: Add LED device Philippe Mathieu-Daudé
2020-06-20 23:07 ` [PATCH v3 1/7] hw/misc: Add a " Philippe Mathieu-Daudé
2020-06-21 2:00 ` Richard Henderson
2020-06-21 20:35 ` Philippe Mathieu-Daudé
2020-06-21 20:50 ` Richard Henderson
2020-06-20 23:07 ` Philippe Mathieu-Daudé [this message]
2020-06-21 19:09 ` [PATCH v3 2/7] hw/misc/led: Add helper to connect LED to GPIO output Richard Henderson
2020-06-20 23:07 ` [PATCH v3 3/7] hw/misc/led: Emit a trace event when LED intensity has changed Philippe Mathieu-Daudé
2020-06-21 19:23 ` Richard Henderson
2020-06-21 22:25 ` Philippe Mathieu-Daudé
2020-06-22 16:48 ` Richard Henderson
2020-06-23 7:45 ` Philippe Mathieu-Daudé
2020-06-20 23:07 ` [PATCH v3 4/7] hw/arm/aspeed: Add the 3 front LEDs drived by the PCA9552 #1 Philippe Mathieu-Daudé
2020-06-21 20:51 ` Richard Henderson
2020-06-20 23:07 ` [PATCH v3 5/7] hw/misc/mps2-fpgaio: Use the LED device Philippe Mathieu-Daudé
2020-06-21 21:00 ` Richard Henderson
2020-06-21 21:09 ` Philippe Mathieu-Daudé
2020-06-20 23:07 ` [PATCH v3 6/7] hw/misc/mps2-scc: " Philippe Mathieu-Daudé
2020-06-21 17:31 ` Philippe Mathieu-Daudé
2020-06-21 21:05 ` Richard Henderson
2020-06-20 23:07 ` [PATCH v3 7/7] hw/arm/tosa: Replace fprintf() calls by LED devices Philippe Mathieu-Daudé
2020-06-21 16:52 ` Philippe Mathieu-Daudé
2020-06-20 23:58 ` [PATCH v3 0/7] hw/misc: Add LED device 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=20200620230719.32139-3-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=andrew@aj.id.au \
--cc=clg@kaod.org \
--cc=joel@jms.id.au \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--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).