hw/misc/led: Allow connecting from GPIO output

Some devices expose GPIO lines.

Add a GPIO qdev input to our LED device, so we can
connect a GPIO output using qdev_connect_gpio_out().

When used with GPIOs, the intensity can only be either
minium or maximum. This depends of the polarity of the
GPIO (which can be inverted).
Declare the GpioPolarity type to model the polarity.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
Message-Id: <20200912134041.946260-3-f4bug@amsat.org>
This commit is contained in:
Philippe Mathieu-Daudé 2020-06-16 06:23:50 +02:00
parent c1b2982627
commit ddb67f6402
3 changed files with 42 additions and 1 deletions

View file

@ -9,6 +9,7 @@
#define HW_MISC_LED_H
#include "qom/object.h"
#include "hw/qdev-core.h"
#define TYPE_LED "led"
@ -37,10 +38,17 @@ struct LEDState {
/* Public */
uint8_t intensity_percent;
qemu_irq irq;
/* Properties */
char *description;
char *color;
/*
* Determines whether a GPIO is using a positive (active-high)
* logic (when used with GPIO, the intensity at reset is related
* to the GPIO polarity).
*/
bool gpio_active_high;
};
typedef struct LEDState LEDState;
DECLARE_INSTANCE_CHECKER(LEDState, LED, TYPE_LED)
@ -72,6 +80,7 @@ void led_set_state(LEDState *s, bool is_emitting);
/**
* led_create_simple: Create and realize a LED device
* @parentobj: the parent object
* @gpio_polarity: GPIO polarity
* @color: color of the LED
* @description: description of the LED (optional)
*
@ -81,6 +90,7 @@ void led_set_state(LEDState *s, bool is_emitting);
* Returns: The newly allocated and instantiated LED object.
*/
LEDState *led_create_simple(Object *parentobj,
GpioPolarity gpio_polarity,
LEDColor color,
const char *description);