hw/misc: Add LED device
Subsystems (3)
v5 cover hw/misc: Add LED device
Hello,
These patches are part of the GSoC unselected 'QEMU visualizer' project.
This series introduce a LED device that can be easily connected to a GPIO output.
Since v4:
- Fixed typos (Luc)
- Removed TYPE_TOSA_MISC_GPIO qdev conversion patch (Peter)
Since v3:
- Rebased (TYPE_TOSA_MISC_GPIO)
- Rebased (Meson)
- Addressed Richard's review comments
- Improved doc/comments
Since v2:
- Rebased on PCA9552
- Model intensity to be ready for PWM use (Dave)
- Remove QMP events until we get a UI visualizer (Peter)
- Remove microbit patch (Peter)
Since v1: addressed Eric Blake review comments
- Added QMP rate limit
Next steps planned:
- PoC visualizer...
- look at using a dbus backend (elmarco)
- look at LED array/matrix such 7segments.
Regards,
Phil.
Philippe Mathieu-Daudé (7):
hw/misc/led: Add a LED device
hw/misc/led: Allow connecting from GPIO output hw/misc/led: Emit a trace event when LED intensity has changed hw/arm/aspeed: Add the 3 front LEDs drived by the PCA9552 #1 hw/misc/mps2-fpgaio: Use the LED device hw/misc/mps2-scc: Use the LED device
hw/arm/tosa: Replace fprintf() calls by LED devices
include/hw/misc/led.h | 92 +++++++++++++++++++ include/hw/misc/mps2-fpgaio.h | 2 + include/hw/misc/mps2-scc.h | 2 + include/hw/qdev-core.h | 8 ++ hw/arm/aspeed.c | 20 +++++ hw/arm/tosa.c | 40 ++++----- hw/misc/led.c | 161 ++++++++++++++++++++++++++++++++++ hw/misc/mps2-fpgaio.c | 19 ++-- hw/misc/mps2-scc.c | 25 +++--- MAINTAINERS | 6 ++ hw/arm/Kconfig | 2 + hw/misc/Kconfig | 5 ++ hw/misc/meson.build | 1 + hw/misc/trace-events | 6 +- 14 files changed, 346 insertions(+), 43 deletions(-) create mode 100644 include/hw/misc/led.h create mode 100644 hw/misc/led.c
Signature · 1 line
2.26.2
PATCH v5 1/7 hw/misc/led: Add a LED device
Add a LED device which can be connected to a GPIO output. They can also be dimmed with PWM devices. For now we do not implement the dimmed mode, but in preparation of a future implementation, we start using the LED intensity.
LEDs are limited to a fixed set of colors.
--- include/hw/misc/led.h | 84 +++++++++++++++++++++++++ hw/misc/led.c | 142 ++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 6 ++ hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/trace-events | 3 + 6 files changed, 239 insertions(+) create mode 100644 include/hw/misc/led.h create mode 100644 hw/misc/led.c
include/hw/misc/led.h new file +84 -0
@@ -0,0 +1,84 @@ +/* +* QEMU single LED device +* +* Copyright (C) 2020 Philippe Mathieu-Daudé <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#ifndef HW_MISC_LED_H +#define HW_MISC_LED_H + +#include "hw/qdev-core.h" + +#define TYPE_LED "led" +#define LED (obj) OBJECT_CHECK(LEDState, (obj), TYPE_LED) + +/** +* LEDColor: Color of a LED +* +* This set is restricted to physically available LED colors. +* +* LED colors from 'Table 1. Product performance of LUXEON Rebel Color +* Line' of the 'DS68 LUXEON Rebel Color Line' datasheet available at: +* https://www.lumileds.com/products/color-leds/luxeon-rebel-color/ +*/ +typedef enum {/* Coarse wavelength range */ +LED_COLOR_VIOLET ,/* 425 nm */ +LED_COLOR_BLUE ,/* 475 nm */ +LED_COLOR_CYAN ,/* 500 nm */ +LED_COLOR_GREEN ,/* 535 nm */ +LED_COLOR_AMBER ,/* 590 nm */ +LED_COLOR_ORANGE ,/* 615 nm */ +LED_COLOR_RED ,/* 630 nm */ +}LEDColor ; + +typedef struct LEDState { +/* Private */ +DeviceState parent_obj; +/* Public */ + +uint8_t intensity_percent; + +/* Properties */ +char *description; +char *color; +}LEDState ; + +/** +* led_set_intensity: Set the intensity of a LED device +* @s: the LED object +* @intensity_percent: intensity as percentage in range 0 to 100. +*/ +void led_set_intensity (LEDState *s,unsigned intensity_percent); + +/** +* led_get_intensity: +* @s: the LED object +* +* Returns: The LED intensity as percentage in range 0 to 100. +*/ +unsigned led_get_intensity (LEDState *s); + +/** +* led_set_state: Set the state of a LED device +* @s: the LED object +* @is_emitting: boolean indicating whether the LED is emitting +* +* This utility is meant for LED connected to GPIO. +*/ +void led_set_state (LEDState *s,bool is_emitting); + +/** +* led_create_simple: Create and realize a LED device +* @parentobj: the parent object +* @color: color of the LED +* @description: description of the LED (optional) +* +* Create the device state structure, initialize it, and +* drop the reference to it (the device is realized). +*/ +LEDState *led_create_simple (Object *parentobj, +LEDColor color, +const char *description); + +#endif /* HW_MISC_LED_H */
hw/misc/led.c new file +142 -0
142 lines not on this page · raw message
MAINTAINERS +6 -0
@@ -1951,6 +1951,12 @@ F: docs/specs/vmgenid.txt F: tests/qtest/vmgenid-test.c F: stubs/vmgenid.c +LED +M: Philippe Mathieu-Daudé <[email protected]> +S: Maintained +F: include/hw/misc/led.h +F: hw/misc/led.c + Unimplemented device M: Peter Maydell <[email protected]> R: Philippe Mathieu-Daudé <[email protected]>
hw/misc/Kconfig +3 -0
@@ -126,6 +126,9 @@ config AUX config UNIMP bool +config LED + bool + config MAC_VIA bool select MOS6522
hw/misc/meson.build +1 -0
@@ -11,6 +11,7 @@ softmmu_ss.add(when: 'CONFIG_TMP105', if_true: files('tmp105.c')) softmmu_ss.add(when: 'CONFIG_TMP421', if_true: files('tmp421.c')) softmmu_ss.add(when: 'CONFIG_UNIMP', if_true: files('unimp.c')) softmmu_ss.add(when: 'CONFIG_EMPTY_SLOT', if_true: files('empty_slot.c')) +softmmu_ss.add(when: 'CONFIG_LED', if_true: files('led.c')) # ARM devices softmmu_ss.add(when: 'CONFIG_PL310', if_true: files('arm_l2x0.c'))
hw/misc/trace-events +3 -0
@@ -214,6 +214,9 @@ via1_adb_poll(uint8_t data, const char *vadbint, int status, int index, int size grlib_ahb_pnp_read(uint64_t addr, uint32_t value) "AHB PnP read addr:0x%03"PRIx64" data:0x%08x" grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx64" data:0x%08x" +# led.c +led_set_intensity(const char *color, const char *desc, uint8_t intensity_percent) "LED desc:'%s' color:%s intensity: %u%%" + # pca9552.c pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]" pca955x_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u"
Signature · 1 line
2.26.2
Re: [PATCH v5 1/7] hw/misc/led: Add a LED device
Quoted 8 lines · Philippe Mathieu-Daudé
Add a LED device which can be connected to a GPIO output. They can also be dimmed with PWM devices. For now we do not implement the dimmed mode, but in preparation of a future implementation, we start using the LED intensity.
LEDs are limited to a fixed set of colors.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 307 lines
--- include/hw/misc/led.h | 84 +++++++++++++++++++++++++ hw/misc/led.c | 142 ++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 6 ++ hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/trace-events | 3 + 6 files changed, 239 insertions(+)create mode 100644
include/hw/misc/led.h
create mode 100644hw/misc/led.cinclude/hw/misc/led.h new file +84
-0@@ -0,0 +1,84 @@ +/* +* QEMU single LED device +* +* Copyright (C) 2020 Philippe Mathieu-Daudé <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#ifndef HW_MISC_LED_H +#define HW_MISC_LED_H + +#include "hw/qdev-core.h" + +#define TYPE_LED "led" +#define LED (obj) OBJECT_CHECK(LEDState, (obj), TYPE_LED) + +/** +* LEDColor: Color of a LED +* +* This set is restricted to physically available LED colors. +* +* LED colors from 'Table 1. Product performance of LUXEON Rebel Color +* Line' of the 'DS68 LUXEON Rebel Color Line' datasheet available at: +* https://www.lumileds.com/products/color-leds/luxeon-rebel-color/ +*/ +typedef enum {/* Coarse wavelength range */ +LED_COLOR_VIOLET ,/* 425 nm */ +LED_COLOR_BLUE ,/* 475 nm */ +LED_COLOR_CYAN ,/* 500 nm */ +LED_COLOR_GREEN ,/* 535 nm */ +LED_COLOR_AMBER ,/* 590 nm */ +LED_COLOR_ORANGE ,/* 615 nm */ +LED_COLOR_RED ,/* 630 nm */ +}LEDColor ; + +typedef struct LEDState { +/* Private */ +DeviceState parent_obj; +/* Public */ + +uint8_t intensity_percent; + +/* Properties */ +char *description; +char *color; +}LEDState ; + +/** +* led_set_intensity: Set the intensity of a LED device +* @s: the LED object +* @intensity_percent: intensity as percentage in range 0 to 100. +*/ +void led_set_intensity (LEDState *s,unsigned intensity_percent); + +/** +* led_get_intensity: +* @s: the LED object +* +* Returns: The LED intensity as percentage in range 0 to 100. +*/ +unsigned led_get_intensity (LEDState *s); + +/** +* led_set_state: Set the state of a LED device +* @s: the LED object +* @is_emitting: boolean indicating whether the LED is emitting +* +* This utility is meant for LED connected to GPIO. +*/ +void led_set_state (LEDState *s,bool is_emitting); + +/** +* led_create_simple: Create and realize a LED device +* @parentobj: the parent object +* @color: color of the LED +* @description: description of the LED (optional) +* +* Create the device state structure, initialize it, and +* drop the reference to it (the device is realized). +*/ +LEDState *led_create_simple (Object *parentobj, +LEDColor color, +const char *description); + +#endif /* HW_MISC_LED_H */ hw/misc/led.c new file +142
-0@@ -0,0 +1,142 @@ +/* +* QEMU single LED device +* +* Copyright (C) 2020 Philippe Mathieu-Daudé <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "migration/vmstate.h" +#include "hw/qdev-properties.h" +#include "hw/misc/led.h" +#include "trace.h" + +#define LED_INTENSITY_PERCENT_MAX 100 + +static const char *led_color_name[] = { + [LED_COLOR_VIOLET ] ="violet" , + [LED_COLOR_BLUE ] ="blue" , + [LED_COLOR_CYAN ] ="cyan" , + [LED_COLOR_GREEN ] ="green" , + [LED_COLOR_AMBER ] ="amber" , + [LED_COLOR_ORANGE ] ="orange" , + [LED_COLOR_RED ] ="red" , +}; + +static bool led_color_name_is_valid (const char *color_name) +{ +for (size_t i =0 ; i <ARRAY_SIZE (led_color_name); i++) { +if (strcmp (color_name, led_color_name[i]) ==0 ) { +return true; + } + } +return false; +} + +void led_set_intensity (LEDState *s,unsigned intensity_percent) +{ +if (intensity_percent >LED_INTENSITY_PERCENT_MAX ) { + intensity_percent =LED_INTENSITY_PERCENT_MAX ; + } +trace_led_set_intensity (s->description, s->color, intensity_percent); + s->intensity_percent = intensity_percent; +} + +unsigned led_get_intensity (LEDState *s) +{ +return s->intensity_percent; +} + +void led_set_state (LEDState *s,bool is_emitting) +{ +led_set_intensity (s, is_emitting ?LED_INTENSITY_PERCENT_MAX :0 ); +} + +static void led_reset (DeviceState *dev) +{ +LEDState *s =LED (dev); + +led_set_state (s, false); +} + +static const VMStateDescription vmstate_led = { + .name =TYPE_LED , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT8 (intensity_percent, LEDState), +VMSTATE_END_OF_LIST () + } +}; + +static void led_realize (DeviceState *dev,Error **errp) +{ +LEDState *s =LED (dev); + +if (s->color ==NULL ) { +error_setg (errp,"property 'color' not specified" ); +return ; + }else if (!led_color_name_is_valid (s->color)) { +error_setg (errp,"property 'color' invalid or not supported" ); +return ; + } +if (s->description ==NULL ) { + s->description =g_strdup ("n/a" ); + } +} + +static Property led_properties[] = { +DEFINE_PROP_STRING ("color" , LEDState, color), +DEFINE_PROP_STRING ("description" , LEDState, description), +DEFINE_PROP_END_OF_LIST (), +}; + +static void led_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc ="LED" ; + dc->vmsd = &vmstate_led; + dc->reset = led_reset; + dc->realize = led_realize; +set_bit (DEVICE_CATEGORY_DISPLAY , dc->categories); +device_class_set_props (dc, led_properties); +} + +static const TypeInfo led_info = { + .name =TYPE_LED , + .parent =TYPE_DEVICE , + .instance_size =sizeof (LEDState), + .class_init = led_class_init +}; + +static void led_register_types (void ) +{ +type_register_static (&led_info); +} + +type_init (led_register_types) + +LEDState *led_create_simple(Object *parentobj, +LEDColor color, +const char *description) +{ + g_autofree char *name = NULL; +DeviceState *dev; + + dev =qdev_new (TYPE_LED ); +qdev_prop_set_string (dev,"color" , led_color_name[color]); +if (!description) { +static unsigned undescribed_led_id; + name =g_strdup_printf ("undescribed-led-#%u" , undescribed_led_id++); + }else { +qdev_prop_set_string (dev,"description" , description); + name =g_ascii_strdown (description,-1 ); + name =g_strdelimit (name," #" ,'-' ); + } +object_property_add_child (parentobj, name,OBJECT (dev)); +qdev_realize_and_unref (dev,NULL , &error_fatal); + +return LED (dev); +}MAINTAINERS +6
-0@@ -1951,6 +1951,12 @@ F: docs/specs/vmgenid.txt F: tests/qtest/vmgenid-test.c F: stubs/vmgenid.c +LED +M: Philippe Mathieu-Daudé <[email protected]> +S: Maintained +F: include/hw/misc/led.h +F: hw/misc/led.c + Unimplemented device M: Peter Maydell <[email protected]> R: Philippe Mathieu-Daudé <[email protected]>hw/misc/Kconfig +3
-0@@ -126,6 +126,9 @@ config AUX config UNIMP bool +config LED + bool + config MAC_VIA bool select MOS6522hw/misc/meson.build +1
-0@@ -11,6 +11,7 @@ softmmu_ss.add(when: 'CONFIG_TMP105', if_true: files('tmp105.c')) softmmu_ss.add(when: 'CONFIG_TMP421', if_true: files('tmp421.c')) softmmu_ss.add(when: 'CONFIG_UNIMP', if_true: files('unimp.c')) softmmu_ss.add(when: 'CONFIG_EMPTY_SLOT', if_true: files('empty_slot.c')) +softmmu_ss.add(when: 'CONFIG_LED', if_true: files('led.c')) # ARM devices softmmu_ss.add(when: 'CONFIG_PL310', if_true: files('arm_l2x0.c'))hw/misc/trace-events +3
-0@@ -214,6 +214,9 @@ via1_adb_poll(uint8_t data, const char *vadbint, int status, int index, int size grlib_ahb_pnp_read(uint64_t addr, uint32_t value) "AHB PnP read addr:0x%03"PRIx64" data:0x%08x" grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx64" data:0x%08x" +# led.c +led_set_intensity(const char *color, const char *desc, uint8_t intensity_percent) "LED desc:'%s' color:%s intensity: %u%%" + # pca9552.c pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]" pca955x_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u"
Re: [PATCH v5 1/7] hw/misc/led: Add a LED device
In reply to Philippe Mathieu-DaudéQuoted 1 line · Philippe Mathieu-Daudé
+static const char *led_color_name[] = {
const char * const
Otherwise,
r~
PATCH v5 2/7 hw/misc/led: Allow connecting from GPIO output
In reply to Philippe Mathieu-Daudé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.
--- include/hw/misc/led.h | 8 ++++++++ include/hw/qdev-core.h | 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-)
include/hw/misc/led.h +8 -0
@@ -38,10 +38,16 @@ typedef struct LEDState {/* Public */ uint8_t intensity_percent; +qemu_irq irq;/* Properties */ char *description;char *color; +/* +* When used with GPIO, the intensity at reset is related +* to the GPIO polarity. +*/ +bool inverted_polarity; } LEDState;/**
@@ -71,6 +77,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) *
@@ -78,6 +85,7 @@ void led_set_state(LEDState *s, bool is_emitting);* drop the reference to it (the device is realized). */ LEDState *led_create_simple (Object *parentobj, +GpioPolarity gpio_polarity,LEDColor color,const char *description);
include/hw/qdev-core.h +8 -0
@@ -424,6 +424,14 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,void qdev_machine_creation_done (void );bool qdev_machine_modified (void ); +/** +* GpioPolarity: Polarity of a GPIO line +*/ +typedef enum { +GPIO_POLARITY_ACTIVE_LOW , +GPIO_POLARITY_ACTIVE_HIGH +}GpioPolarity ; +/** * qdev_get_gpio_in: Get one of a device's anonymous input GPIO lines * @dev: Device whose GPIO we want
hw/misc/led.c +16 -1
@@ -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" #define LED_INTENSITY_PERCENT_MAX 100
@@ -53,11 +54,19 @@ void led_set_state(LEDState *s, bool is_emitting)led_set_intensity (s, is_emitting ?LED_INTENSITY_PERCENT_MAX :0 ); } +static void led_set_state_gpio_handler (void *opaque,int line,int new_state) +{ +LEDState *s =LED (opaque); + +assert (line ==0 ); +led_set_state (s, !!new_state != s->inverted_polarity); +} +static void led_reset (DeviceState *dev) {LEDState *s =LED (dev); -led_set_state (s, false); +led_set_state (s, s->inverted_polarity); }static const VMStateDescription vmstate_led = {
@@ -84,11 +93,14 @@ static void led_realize(DeviceState *dev, Error **errp)if (s->description ==NULL ) { s->description =g_strdup ("n/a" ); } + +qdev_init_gpio_in (DEVICE (s), led_set_state_gpio_handler,1 ); }static Property led_properties[] = {DEFINE_PROP_STRING ("color" , LEDState, color),DEFINE_PROP_STRING ("description" , LEDState, description), +DEFINE_PROP_BOOL ("polarity-inverted" , LEDState, inverted_polarity, false),DEFINE_PROP_END_OF_LIST (), };
@@ -119,6 +131,7 @@ static void led_register_types(void)type_init (led_register_types) LEDState *led_create_simple(Object *parentobj, +GpioPolarity gpio_polarity,LEDColor color,const char *description) {
@@ -126,6 +139,8 @@ LEDState *led_create_simple(Object *parentobj,DeviceState *dev; dev =qdev_new (TYPE_LED ); +qdev_prop_set_bit (dev,"polarity-inverted" , + gpio_polarity ==GPIO_POLARITY_ACTIVE_LOW );qdev_prop_set_string (dev,"color" , led_color_name[color]);if (!description) {static unsigned undescribed_led_id;
Signature · 1 line
2.26.2
Re: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output
Hi Phil,
Quoted 108 lines · Philippe Mathieu-Daudé
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é <[email protected]>--- include/hw/misc/led.h | 8 ++++++++ include/hw/qdev-core.h | 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-)include/hw/misc/led.h +8
-0@@ -38,10 +38,16 @@ typedef struct LEDState {/* Public */ uint8_t intensity_percent; +qemu_irq irq;/* Properties */ char *description;char *color; +/* +* When used with GPIO, the intensity at reset is related +* to the GPIO polarity. +*/ +bool inverted_polarity; } LEDState;/** @@ -71,6 +77,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) * @@ -78,6 +85,7 @@ void led_set_state(LEDState *s, bool is_emitting);* drop the reference to it (the device is realized). */ LEDState *led_create_simple (Object *parentobj, +GpioPolarity gpio_polarity,LEDColor color,const char *description);include/hw/qdev-core.h +8
-0@@ -424,6 +424,14 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,void qdev_machine_creation_done (void );bool qdev_machine_modified (void ); +/** +* GpioPolarity: Polarity of a GPIO line +*/ +typedef enum { +GPIO_POLARITY_ACTIVE_LOW , +GPIO_POLARITY_ACTIVE_HIGH +}GpioPolarity ; +/** * qdev_get_gpio_in: Get one of a device's anonymous input GPIO lines * @dev: Device whose GPIO we want hw/misc/led.c +10
-1@@ -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" #define LED_INTENSITY_PERCENT_MAX 100@@ -53,11 +54,19 @@ void led_set_state(LEDState *s, bool is_emitting)led_set_intensity (s, is_emitting ?LED_INTENSITY_PERCENT_MAX :0 ); } +static void led_set_state_gpio_handler (void *opaque,int line,int new_state) +{ +LEDState *s =LED (opaque); + +assert (line ==0 ); +led_set_state (s, !!new_state != s->inverted_polarity); +} +static void led_reset (DeviceState *dev) {LEDState *s =LED (dev); -led_set_state (s, false); +led_set_state (s, s->inverted_polarity); }static const VMStateDescription vmstate_led = {@@ -84,11 +93,14 @@ static void led_realize(DeviceState *dev, Error **errp)if (s->description ==NULL ) {
hw/misc/led.c static void led_realize(DeviceState *dev, Error **errp) · line 103
Quoted 10 lines
hw/misc/led.c +3
-0s->description =g_strdup ("n/a" ); } + +qdev_init_gpio_in (DEVICE (s), led_set_state_gpio_handler,1 ); }static Property led_properties[] = {DEFINE_PROP_STRING ("color" , LEDState, color),DEFINE_PROP_STRING ("description" , LEDState, description), +DEFINE_PROP_BOOL ("polarity-inverted" , LEDState, inverted_polarity, false),
I was wondering, since the GpioPolarity type you introduce is not used in the GPIO API, and since you use a boolean property here. Wouldn't it be clearer is you name this property "active-low"? Because "polarity-inverted" doesn't tell what the polarity is in the first place. Moreover since this property only affects the LED GPIO, and not the LED API (led_set_state), I think you can even name it "gpio-active-low" to make this clear.
hw/misc/led.c static void led_register_types(void) · line 134
Quoted 8 lines
hw/misc/led.c +1
-0DEFINE_PROP_END_OF_LIST(), };@@ -119,6 +131,7 @@ static void led_register_types(void)type_init (led_register_types) LEDState *led_create_simple(Object *parentobj, + GpioPolarity gpio_polarity,
You could go with a boolean here also and name the parameter gpio_active_low, but I don't have a strong opinion on this.
So with or without those modifications:
Quoted 13 lines
hw/misc/led.c +2
-0LEDColor color, const char *description) {@@ -126,6 +139,8 @@ LEDState *led_create_simple(Object *parentobj,DeviceState *dev; dev =qdev_new (TYPE_LED ); +qdev_prop_set_bit (dev,"polarity-inverted" , + gpio_polarity ==GPIO_POLARITY_ACTIVE_LOW );qdev_prop_set_string (dev,"color" , led_color_name[color]);if (!description) {static unsigned undescribed_led_id;
Re: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output
Quoted 109 lines · Luc Michel
Hi Phil,
Quoted 106 lines · Philippe Mathieu-Daudé
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é <[email protected]>---
include/hw/misc/led.h | 8 ++++++++include/hw/qdev-core.h| 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++-3 files changed, 32 insertions(+), 1 deletion(-)include/hw/misc/led.h +8
-0@@ -38,10 +38,16 @@ typedef struct LEDState { /* Public */ uint8_t intensity_percent; + qemu_irq irq; /* Properties */ char *description; char *color; + /* + * When used with GPIO, the intensity at reset is related + * to the GPIO polarity. + */ + bool inverted_polarity; } LEDState; /**@@ -71,6 +77,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) * @@ -78,6 +85,7 @@ void led_set_state(LEDState *s, bool is_emitting);* drop the reference to it (the device is realized). */ LEDState *led_create_simple(Object *parentobj, + GpioPolarity gpio_polarity, LEDColor color, const char *description);diff --git
a/include/hw/qdev-core.hb/include/hw/qdev-core.hindexea3f73a282d..846354736a5100644include/hw/qdev-core.h +0
-0@@ -424,6 +424,14 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, void qdev_machine_creation_done(void); bool qdev_machine_modified(void);+/**
+ * GpioPolarity: Polarity of a GPIO line
+ */include/hw/qdev-core.h +5
-0+typedef enum { + GPIO_POLARITY_ACTIVE_LOW, + GPIO_POLARITY_ACTIVE_HIGH +}GpioPolarity ; +/**
*qdev_get_gpio_in: Get one of a device's anonymous input GPIO lines
* @dev: Device whose GPIO we wanthw/misc/led.c +1
-0@@ -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" #define LED_INTENSITY_PERCENT_MAX 100@@ -53,11 +54,19 @@ void led_set_state(LEDState *s, bool is_emitting) led_set_intensity(s, is_emitting ? LED_INTENSITY_PERCENT_MAX : 0); }+static void
led_set_state_gpio_handler(void *opaque, int line, int new_state)hw/misc/led.c +7
-0+{ + LEDState *s = LED(opaque); + + assert(line == 0); + led_set_state(s, !!new_state != s->inverted_polarity); +} +static void
led_reset(DeviceState *dev)
{
LEDState *s = LED(dev);
-led_set_state(s, false);
+led_set_state(s, s->inverted_polarity); }
static const VMStateDescriptionvmstate_led= {hw/misc/led.c +2
-0@@ -84,11 +93,14 @@ static void led_realize(DeviceState *dev, Error **errp) if (s->description == NULL) { s->description = g_strdup("n/a"); } + + qdev_init_gpio_in(DEVICE(s), led_set_state_gpio_handler, 1);
Quoted 8 lines
hw/misc/led.c static void led_realize(DeviceState *dev, Error **errp)
Quoted 6 lines
hw/misc/led.c +1
-0} static Property led_properties[] = { DEFINE_PROP_STRING("color", LEDState, color), DEFINE_PROP_STRING("description", LEDState, description), + DEFINE_PROP_BOOL("polarity-inverted", LEDState, inverted_polarity, false),I was wondering, since the GpioPolarity type you introduce is not used in the GPIO API, and since you use a boolean property here.
"GpioPolarity not used in GPIO API": For now, but I expect it to be used there too. Maybe not soon, but some places could use it and become clearer.
Quoted 6 lines
Wouldn't it
be clearer is you name this property "active-low"? Because "polarity-inverted" doesn't tell what the polarity is in the first place. Moreover since this property only affects the LED GPIO, and not the LED API (led_set_state), I think you can even name it "gpio-active-low" to make this clear.
Very good point, thanks for your suggestion!
Quoted 9 lines
Quoted 7 lines
hw/misc/led.c +0
-0DEFINE_PROP_END_OF_LIST(), };@@ -119,6 +131,7 @@ static void
led_register_types(void)type_init(led_register_types)
LEDState *led_create_simple(Object *parentobj, + GpioPolaritygpio_polarity,You could go with a boolean here also and name the parameter
gpio_active_low, but I don't have a strong opinion on this.
I'll try, as this might postpone the need for the GpioPolarity enum (including its migration and the qapi enum visitors...).
Quoted 17 lines
So with or without those modifications:
Reviewed-by Luc Michel <[email protected]>Quoted 12 lines
LEDColor color, const char *description) {
hw/misc/led.c +2
-0@@ -126,6 +139,8 @@ LEDState *led_create_simple(Object *parentobj, DeviceState *dev; dev = qdev_new(TYPE_LED); + qdev_prop_set_bit(dev, "polarity-inverted", + gpio_polarity == GPIO_POLARITY_ACTIVE_LOW); qdev_prop_set_string(dev, "color", led_color_name[color]); if (!description) { static unsigned undescribed_led_id;
Re: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output
Quoted 139 lines · Philippe Mathieu-Daudé
Quoted 109 lines · Luc Michel
Hi Phil,
Quoted 106 lines · Philippe Mathieu-Daudé
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é <[email protected]>---
include/hw/misc/led.h | 8 ++++++++include/hw/qdev-core.h| 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++-3 files changed, 32 insertions(+), 1 deletion(-)include/hw/misc/led.h +8
-0@@ -38,10 +38,16 @@ typedef struct LEDState { /* Public */ uint8_t intensity_percent; + qemu_irq irq; /* Properties */ char *description; char *color; + /* + * When used with GPIO, the intensity at reset is related + * to the GPIO polarity. + */ + bool inverted_polarity; } LEDState; /**@@ -71,6 +77,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) * @@ -78,6 +85,7 @@ void led_set_state(LEDState *s, bool is_emitting);* drop the reference to it (the device is realized). */ LEDState *led_create_simple(Object *parentobj, + GpioPolarity gpio_polarity, LEDColor color, const char *description);diff --git
a/include/hw/qdev-core.hb/include/hw/qdev-core.hindexea3f73a282d..846354736a5100644include/hw/qdev-core.h +0
-0@@ -424,6 +424,14 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, void qdev_machine_creation_done(void); bool qdev_machine_modified(void);+/**
+ * GpioPolarity: Polarity of a GPIO line
+ */include/hw/qdev-core.h +5
-0+typedef enum { + GPIO_POLARITY_ACTIVE_LOW, + GPIO_POLARITY_ACTIVE_HIGH +}GpioPolarity ; +/**
*qdev_get_gpio_in: Get one of a device's anonymous input GPIO lines
* @dev: Device whose GPIO we wanthw/misc/led.c +1
-0@@ -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" #define LED_INTENSITY_PERCENT_MAX 100@@ -53,11 +54,19 @@ void led_set_state(LEDState *s, bool is_emitting) led_set_intensity(s, is_emitting ? LED_INTENSITY_PERCENT_MAX : 0); }+static void
led_set_state_gpio_handler(void *opaque, int line, int new_state)hw/misc/led.c +7
-0+{ + LEDState *s = LED(opaque); + + assert(line == 0); + led_set_state(s, !!new_state != s->inverted_polarity); +} +static void
led_reset(DeviceState *dev)
{
LEDState *s = LED(dev);
-led_set_state(s, false);
+led_set_state(s, s->inverted_polarity); }
static const VMStateDescriptionvmstate_led= {hw/misc/led.c +2
-0@@ -84,11 +93,14 @@ static void led_realize(DeviceState *dev, Error **errp) if (s->description == NULL) { s->description = g_strdup("n/a"); } + + qdev_init_gpio_in(DEVICE(s), led_set_state_gpio_handler, 1);Quoted 8 lines
hw/misc/led.c static void led_realize(DeviceState *dev, Error **errp)
Quoted 6 lines
hw/misc/led.c +1
-0} static Property led_properties[] = { DEFINE_PROP_STRING("color", LEDState, color), DEFINE_PROP_STRING("description", LEDState, description), + DEFINE_PROP_BOOL("polarity-inverted", LEDState, inverted_polarity, false),I was wondering, since the GpioPolarity type you introduce is not used in the GPIO API, and since you use a boolean property here.
"GpioPolarity not used in GPIO API": For now, but I expect it to be used there too. Maybe not soon, but some places could use it and become clearer.
Quoted 6 lines
Wouldn't it
be clearer is you name this property "active-low"? Because "polarity-inverted" doesn't tell what the polarity is in the first place. Moreover since this property only affects the LED GPIO, and not the LED API (led_set_state), I think you can even name it "gpio-active-low" to make this clear.Very good point, thanks for your suggestion!
Quoted 7 lines
Quoted 7 lines
hw/misc/led.c +0
-0DEFINE_PROP_END_OF_LIST(), };@@ -119,6 +131,7 @@ static void
led_register_types(void)type_init(led_register_types)
LEDState *led_create_simple(Object *parentobj, + GpioPolaritygpio_polarity,
Quoted 5 lines
Quoted 2 lines
You could go with a boolean here also and name the parameter
gpio_active_low, but I don't have a strong opinion on this.I'll try, as this might postpone the need for the GpioPolarity enum (including its migration and the qapi enum visitors...).
After testing using a simple boolean, I think I'll keep the enum as it makes the caller code easier to review:
s->led = led_create_simple(OBJECT(dev),
GPIO_POLARITY_ACTIVE_HIGH,
LED_COLOR_GREEN, name);vs
s->led = led_create_simple(OBJECT(dev), true,
LED_COLOR_GREEN, name);Quoted 19 lines
Quoted 18 lines
So with or without those modifications:
Reviewed-by Luc Michel <[email protected]>Quoted 12 lines
LEDColor color, const char *description) {
hw/misc/led.c +2
-0@@ -126,6 +139,8 @@ LEDState *led_create_simple(Object *parentobj, DeviceState *dev; dev = qdev_new(TYPE_LED); + qdev_prop_set_bit(dev, "polarity-inverted", + gpio_polarity == GPIO_POLARITY_ACTIVE_LOW); qdev_prop_set_string(dev, "color", led_color_name[color]); if (!description) { static unsigned undescribed_led_id;
Re: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output
In reply to Philippe Mathieu-DaudéQuoted 25 lines · Philippe Mathieu-Daudé
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é <[email protected]>--- include/hw/misc/led.h | 8 ++++++++ include/hw/qdev-core.h | 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-)include/hw/misc/led.h +0
-0@@ -38,10 +38,16 @@ typedef struct LEDState {/* Public */ uint8_t intensity_percent;
include/hw/misc/led.h typedef struct LEDState { · line 50
Quoted 10 lines
include/hw/misc/led.h +6
-0+qemu_irq irq;/* Properties */ char *description;char *color; +/* +* When used with GPIO, the intensity at reset is related +* to the GPIO polarity. +*/ +bool inverted_polarity;
Why are you not using the GpioPolarity enum that you added?
r~
Re: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output
Eduardo is already in Cc, adding Markus.
Quoted 28 lines · Richard Henderson
Quoted 27 lines · Philippe Mathieu-Daudé
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é <[email protected]>--- include/hw/misc/led.h | 8 ++++++++ include/hw/qdev-core.h | 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-)include/hw/misc/led.h +1
-0@@ -38,10 +38,16 @@ typedef struct LEDState {/* Public */ uint8_t intensity_percent; +qemu_irq irq;
Quoted 10 lines
include/hw/misc/led.h typedef struct LEDState { · line 50
Quoted 8 lines
include/hw/misc/led.h +5
-0/* Properties */ char *description;char *color; +/* +* When used with GPIO, the intensity at reset is related +* to the GPIO polarity. +*/ +bool inverted_polarity;Why are you not using the GpioPolarity enum that you added?
Because it is migrated...
Using DEFINE_PROP_BOOL() is simpler that adding hardware specific enum visitor in hw/core/qdev-properties.c (which is included in user-mode builds because pulled by the CPU type).
A sane cleanup would be to make get_enum(), set_enum() and set_default_value_enum() public (prefixed with 'qdev_') in include/hw/qdev-properties.h.
Out of the scope of this series, but might be worth it.
Eduardo, Markus, what do you think?
Thanks Richard for reviewing this series!
Phil.
Re: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output
Quoted 42 lines · Philippe Mathieu-Daudé
Eduardo is already in Cc, adding Markus.
Quoted 28 lines · Richard Henderson
Quoted 27 lines · Philippe Mathieu-Daudé
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é <[email protected]>--- include/hw/misc/led.h | 8 ++++++++ include/hw/qdev-core.h | 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-)include/hw/misc/led.h +1
-0@@ -38,10 +38,16 @@ typedef struct LEDState {/* Public */ uint8_t intensity_percent; +qemu_irq irq;Quoted 10 lines
include/hw/misc/led.h typedef struct LEDState { · line 50
Quoted 8 lines
include/hw/misc/led.h +5
-0/* Properties */ char *description;char *color; +/* +* When used with GPIO, the intensity at reset is related +* to the GPIO polarity. +*/ +bool inverted_polarity;Why are you not using the GpioPolarity enum that you added?
Quoted 1 line
Because it is migrated...
Luc made me realize we don't need to keep the enum in the device state, a 'is_gpio_polarity_high' boolean is enough, so I don't need to worry about migrating the enum.
https://www.mail-archive.com/[email protected]/msg739790.html
Quoted 5 lines
Using
DEFINE_PROP_BOOL()is simpler that adding hardware specific enum visitor inhw/core/qdev-properties.c(which is included in user-mode builds because pulled by the CPU type).
Quoted 7 lines
A sane cleanup would be to make
get_enum(),set_enum()andset_default_value_enum()public (prefixed with 'qdev_') ininclude/hw/qdev-properties.h.Out of the scope of this series, but might be worth it.
Eduardo, Markus, what do you think?
This question still stands however :)
Quoted 5 lines
Thanks Richard for reviewing this series!
Phil.
Re: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output
In reply to Philippe Mathieu-DaudéQuoted 42 lines · Philippe Mathieu-Daudé
Eduardo is already in Cc, adding Markus.
Quoted 28 lines · Richard Henderson
Quoted 27 lines · Philippe Mathieu-Daudé
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é <[email protected]>--- include/hw/misc/led.h | 8 ++++++++ include/hw/qdev-core.h | 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-)include/hw/misc/led.h +1
-0@@ -38,10 +38,16 @@ typedef struct LEDState {/* Public */ uint8_t intensity_percent; +qemu_irq irq;Quoted 10 lines
include/hw/misc/led.h typedef struct LEDState { · line 50
Quoted 8 lines
include/hw/misc/led.h +5
-0/* Properties */ char *description;char *color; +/* +* When used with GPIO, the intensity at reset is related +* to the GPIO polarity. +*/ +bool inverted_polarity;Why are you not using the GpioPolarity enum that you added?
Quoted 5 lines
Because it is migrated...
Using
DEFINE_PROP_BOOL()is simpler that adding hardware specific enum visitor inhw/core/qdev-properties.c(which is included in user-mode builds because pulled by the CPU type).
Yes.
You could also use DEFINE_PROP_UINT8(), and use it with your enumeration constants.
I'd be tempted to ditch the enum entirely. Matter of taste, no big deal either way.
Quoted 3 lines
A sane cleanup would be to make
get_enum(),set_enum()andset_default_value_enum()public (prefixed with 'qdev_') ininclude/hw/qdev-properties.h.
Purpose? To be able to define enum properties outside qdev-properties.c?
Quoted 7 lines
Out of the scope of this series, but might be worth it.
Eduardo, Markus, what do you think?
Thanks Richard for reviewing this series!
Phil.
Re: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output
Quoted 50 lines · Markus Armbruster
Quoted 42 lines · Philippe Mathieu-Daudé
Eduardo is already in Cc, adding Markus.
Quoted 28 lines · Richard Henderson
Quoted 27 lines · Philippe Mathieu-Daudé
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é <[email protected]>--- include/hw/misc/led.h | 8 ++++++++ include/hw/qdev-core.h | 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-)include/hw/misc/led.h +1
-0@@ -38,10 +38,16 @@ typedef struct LEDState {/* Public */ uint8_t intensity_percent; +qemu_irq irq;Quoted 10 lines
include/hw/misc/led.h typedef struct LEDState { · line 50
Quoted 8 lines
include/hw/misc/led.h +5
-0/* Properties */ char *description;char *color; +/* +* When used with GPIO, the intensity at reset is related +* to the GPIO polarity. +*/ +bool inverted_polarity;Why are you not using the GpioPolarity enum that you added?
Quoted 5 lines
Because it is migrated...
Using
DEFINE_PROP_BOOL()is simpler that adding hardware specific enum visitor inhw/core/qdev-properties.c(which is included in user-mode builds because pulled by the CPU type).
Quoted 7 lines
Yes.
You could also use
DEFINE_PROP_UINT8(), and use it with your enumeration constants.I'd be tempted to ditch the enum entirely. Matter of taste, no big deal either way.
Done in v6!
Quoted 7 lines
Quoted 4 lines
A sane cleanup would be to make
get_enum(),set_enum()andset_default_value_enum()public (prefixed with 'qdev_') ininclude/hw/qdev-properties.h.Purpose? To be able to define enum properties outside
qdev-properties.c?
Yes, to avoid pulling in PCI and MAC address properties into qemu-storage-daemon and linux-user binaries...
Re: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output
Quoted 53 lines · Philippe Mathieu-Daudé
Quoted 52 lines · Markus Armbruster
Quoted 42 lines · Philippe Mathieu-Daudé
Eduardo is already in Cc, adding Markus.
Quoted 28 lines · Richard Henderson
Quoted 27 lines · Philippe Mathieu-Daudé
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é <[email protected]>--- include/hw/misc/led.h | 8 ++++++++ include/hw/qdev-core.h | 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-)include/hw/misc/led.h +1
-0@@ -38,10 +38,16 @@ typedef struct LEDState {/* Public */ uint8_t intensity_percent; +qemu_irq irq;Quoted 10 lines
include/hw/misc/led.h typedef struct LEDState { · line 50
Quoted 8 lines
include/hw/misc/led.h +5
-0/* Properties */ char *description;char *color; +/* +* When used with GPIO, the intensity at reset is related +* to the GPIO polarity. +*/ +bool inverted_polarity;Why are you not using the GpioPolarity enum that you added?
Quoted 5 lines
Because it is migrated...
Using
DEFINE_PROP_BOOL()is simpler that adding hardware specific enum visitor inhw/core/qdev-properties.c(which is included in user-mode builds because pulled by the CPU type).Yes.
Quoted 13 lines
Quoted 5 lines
You could also use
DEFINE_PROP_UINT8(), and use it with your enumeration constants.I'd be tempted to ditch the enum entirely. Matter of taste, no big deal either way.
Done in v6!
Quoted 5 lines
Quoted 4 lines
A sane cleanup would be to make
get_enum(),set_enum()andset_default_value_enum()public (prefixed with 'qdev_') ininclude/hw/qdev-properties.h.
Where and how exactly do you expect those functions to be used? Having additional PropertyInfo structs defined manually would not be desirable (especially if they are outside qdev*.c). Having a DEFINE_PROP_ENUM macro that does the enum magic behind the scenes would be nice.
Quoted 5 lines
Quoted 2 lines
Purpose? To be able to define enum properties outside
qdev-properties.c?Yes, to avoid pulling in PCI and MAC address properties into qemu-storage-daemon and linux-user binaries...
I don't understand what enum functions have to do with PCI and MAC address properties.
Signature · 1 line
Eduardo
Re: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output
Quoted 74 lines · Eduardo Habkost
Quoted 53 lines · Philippe Mathieu-Daudé
Quoted 52 lines · Markus Armbruster
Quoted 42 lines · Philippe Mathieu-Daudé
Eduardo is already in Cc, adding Markus.
Quoted 28 lines · Richard Henderson
Quoted 27 lines · Philippe Mathieu-Daudé
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é <[email protected]>--- include/hw/misc/led.h | 8 ++++++++ include/hw/qdev-core.h | 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-)include/hw/misc/led.h +1
-0@@ -38,10 +38,16 @@ typedef struct LEDState {/* Public */ uint8_t intensity_percent; +qemu_irq irq;Quoted 10 lines
include/hw/misc/led.h typedef struct LEDState { · line 50
Quoted 8 lines
include/hw/misc/led.h +5
-0/* Properties */ char *description;char *color; +/* +* When used with GPIO, the intensity at reset is related +* to the GPIO polarity. +*/ +bool inverted_polarity;Why are you not using the GpioPolarity enum that you added?
Quoted 5 lines
Because it is migrated...
Using
DEFINE_PROP_BOOL()is simpler that adding hardware specific enum visitor inhw/core/qdev-properties.c(which is included in user-mode builds because pulled by the CPU type).Yes.
Quoted 13 lines
Quoted 5 lines
You could also use
DEFINE_PROP_UINT8(), and use it with your enumeration constants.I'd be tempted to ditch the enum entirely. Matter of taste, no big deal either way.
Done in v6!
Quoted 5 lines
Quoted 4 lines
A sane cleanup would be to make
get_enum(),set_enum()andset_default_value_enum()public (prefixed with 'qdev_') ininclude/hw/qdev-properties.h.Where and how exactly do you expect those functions to be used? Having additional PropertyInfo structs defined manually would not be desirable (especially if they are outside qdev*.c). Having a
DEFINE_PROP_ENUMmacro that does the enum magic behind the scenes would be nice.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Purpose? To be able to define enum properties outside
qdev-properties.c?Yes, to avoid pulling in PCI and MAC address properties into qemu-storage-daemon and linux-user binaries...
I don't understand what enum functions have to do with PCI and MAC address properties.
My guess is that as get_enum()/set_enum()/set_default_value_enum() are static, enum properties using it ended in this core file:
const PropertyInfo qdev_prop_bios_chs_trans = {
.name = "BiosAtaTranslation",
.description = "Logical CHS translation algorithm, "
"auto/none/lba/large/rechs",
.enum_table = &BiosAtaTranslation_lookup, .get = get_enum,
.set = set_enum,
.set_default_value = set_default_value_enum,
};
const PropertyInfo qdev_prop_fdc_drive_type = {
.name = "FdcDriveType",
.description = "FDC drive type, "
"144/288/120/none/auto",
.enum_table = &FloppyDriveType_lookup,
.get = get_enum,
.set = set_enum,
.set_default_value = set_default_value_enum,
};
const PropertyInfo qdev_prop_pcie_link_speed = {
.name = "PCIELinkSpeed",
.description = "2_5/5/8/16",
.enum_table = &PCIELinkSpeed_lookup,
.get = get_prop_pcielinkspeed,
.set = set_prop_pcielinkspeed,
.set_default_value = set_default_value_enum,
};
Looking at qdev_prop_macaddr[] and qdev_prop_set_macaddr() maybe I was remembering incorrectly, it seems this one can be extracted easily.
Regards,
Phil.
Re: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output
Quoted 116 lines · Philippe Mathieu-Daudé
Quoted 74 lines · Eduardo Habkost
Quoted 53 lines · Philippe Mathieu-Daudé
Quoted 52 lines · Markus Armbruster
Quoted 42 lines · Philippe Mathieu-Daudé
Eduardo is already in Cc, adding Markus.
Quoted 28 lines · Richard Henderson
Quoted 27 lines · Philippe Mathieu-Daudé
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é <[email protected]>--- include/hw/misc/led.h | 8 ++++++++ include/hw/qdev-core.h | 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-)include/hw/misc/led.h +1
-0@@ -38,10 +38,16 @@ typedef struct LEDState {/* Public */ uint8_t intensity_percent; +qemu_irq irq;Quoted 10 lines
include/hw/misc/led.h typedef struct LEDState { · line 50
Quoted 8 lines
include/hw/misc/led.h +5
-0/* Properties */ char *description;char *color; +/* +* When used with GPIO, the intensity at reset is related +* to the GPIO polarity. +*/ +bool inverted_polarity;Why are you not using the GpioPolarity enum that you added?
Quoted 5 lines
Because it is migrated...
Using
DEFINE_PROP_BOOL()is simpler that adding hardware specific enum visitor inhw/core/qdev-properties.c(which is included in user-mode builds because pulled by the CPU type).Yes.
Quoted 13 lines
Quoted 5 lines
You could also use
DEFINE_PROP_UINT8(), and use it with your enumeration constants.I'd be tempted to ditch the enum entirely. Matter of taste, no big deal either way.
Done in v6!
Quoted 5 lines
Quoted 4 lines
A sane cleanup would be to make
get_enum(),set_enum()andset_default_value_enum()public (prefixed with 'qdev_') ininclude/hw/qdev-properties.h.Where and how exactly do you expect those functions to be used? Having additional PropertyInfo structs defined manually would not be desirable (especially if they are outside qdev*.c). Having a
DEFINE_PROP_ENUMmacro that does the enum magic behind the scenes would be nice.Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Purpose? To be able to define enum properties outside
qdev-properties.c?Yes, to avoid pulling in PCI and MAC address properties into qemu-storage-daemon and linux-user binaries...
I don't understand what enum functions have to do with PCI and MAC address properties.
My guess is that as get_enum()/set_enum()/set_default_value_enum() are static, enum properties using it ended in this core file:
const PropertyInfo
qdev_prop_bios_chs_trans= {
.name = "BiosAtaTranslation",
.description = "Logical CHS translation algorithm, "
"auto/none/lba/large/rechs",
.enum_table =&BiosAtaTranslation_lookup, .get =get_enum,
.set =set_enum,
.set_default_value =set_default_value_enum,
};const PropertyInfo
qdev_prop_fdc_drive_type= {
.name = "FdcDriveType",
.description = "FDC drive type, "
"144/288/120/none/auto",
.enum_table =&FloppyDriveType_lookup,
.get =get_enum,
.set =set_enum,
.set_default_value =set_default_value_enum,
};const PropertyInfo
qdev_prop_pcie_link_speed= {
.name = "PCIELinkSpeed",
.description = "2_5/5/8/16",
.enum_table =&PCIELinkSpeed_lookup,
.get =get_prop_pcielinkspeed,
.set =set_prop_pcielinkspeed,
.set_default_value =set_default_value_enum,
};
Quoted 3 lines
Looking at qdev_prop_macaddr[] and
qdev_prop_set_macaddr()maybe I was remembering incorrectly, it seems this one can be extracted easily.
Already done in "user-mode: Prune build dependencies (part 3)" actually :)
https://www.mail-archive.com/[email protected]/msg688867.html
PATCH v5 3/7 hw/misc/led: Emit a trace event when LED intensity has changed
In reply to Philippe Mathieu-DaudéTrack the LED intensity, and emit a trace event when it changes.
--- hw/misc/led.c | 4 ++++ hw/misc/trace-events | 1 + 2 files changed, 5 insertions(+)
hw/misc/led.c +4 -0
@@ -41,6 +41,10 @@ void led_set_intensity(LEDState *s, unsigned intensity_percent) intensity_percent =LED_INTENSITY_PERCENT_MAX ; }trace_led_set_intensity (s->description, s->color, intensity_percent); +if (intensity_percent != s->intensity_percent) { +trace_led_change_intensity (s->description, s->color, + s->intensity_percent, intensity_percent); + } s->intensity_percent = intensity_percent; }
hw/misc/trace-events +1 -0
@@ -216,6 +216,7 @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6 # led.c led_set_intensity(const char *color, const char *desc, uint8_t intensity_percent) "LED desc:'%s' color:%s intensity: %u%%" +led_change_intensity(const char *color, const char *desc, uint8_t old_intensity_percent, uint8_t new_intensity_percent) "LED desc:'%s' color:%s intensity %u%% -> %u%%" # pca9552.c pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]"
Signature · 1 line
2.26.2
Re: [PATCH v5 3/7] hw/misc/led: Emit a trace event when LED intensity has changed
Quoted 4 lines · Philippe Mathieu-Daudé
Track the LED intensity, and emit a trace event when it changes.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 33 lines
--- hw/misc/led.c | 4 ++++ hw/misc/trace-events | 1 + 2 files changed, 5 insertions(+)hw/misc/led.c +4
-0@@ -41,6 +41,10 @@ void led_set_intensity(LEDState *s, unsigned intensity_percent) intensity_percent =LED_INTENSITY_PERCENT_MAX ; }trace_led_set_intensity (s->description, s->color, intensity_percent); +if (intensity_percent != s->intensity_percent) { +trace_led_change_intensity (s->description, s->color, + s->intensity_percent, intensity_percent); + } s->intensity_percent = intensity_percent; }hw/misc/trace-events +1
-0@@ -216,6 +216,7 @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6 # led.c led_set_intensity(const char *color, const char *desc, uint8_t intensity_percent) "LED desc:'%s' color:%s intensity: %u%%" +led_change_intensity(const char *color, const char *desc, uint8_t old_intensity_percent, uint8_t new_intensity_percent) "LED desc:'%s' color:%s intensity %u%% -> %u%%" # pca9552.c pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]"
PATCH v5 4/7 hw/arm/aspeed: Add the 3 front LEDs drived by the PCA9552 #1
In reply to Philippe Mathieu-DaudéThe Witherspoon has 3 LEDs connected to a PCA9552. Add them. The names and reset values are taken from:
https://github.com/open-power/witherspoon-xml/blob/master/witherspoon.xml
Example booting obmc-phosphor-image:
$ qemu-system-arm -M witherspoon-bmc -trace led_change_intensity 1592693373.997015:led_change_intensity LED desc:'front-fault-4' color:green intensity 0% -> 100% 1592693373.997632:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100% 1592693373.998239:led_change_intensity LED desc:'front-id-5' color:green intensity 0% -> 100% 1592693500.291805:led_change_intensity LED desc:'front-power-3' color:green intensity 100% -> 0% 1592693500.312041:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100% 1592693500.821254:led_change_intensity LED desc:'front-power-3' color:green intensity 100% -> 0% 1592693501.331517:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100% 1592693501.841367:led_change_intensity LED desc:'front-power-3' color:green intensity 100% -> 0% 1592693502.350839:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100% 1592693502.861134:led_change_intensity LED desc:'front-power-3' color:green intensity 100% -> 0% 1592693503.371090:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100%
We notice the front-power LED starts to blink at a ~2Hz rate.
--- hw/arm/aspeed.c | 20 ++++++++++++++++++++ hw/arm/Kconfig | 1 + 2 files changed, 21 insertions(+)
hw/arm/aspeed.c +20 -0
@@ -20,6 +20,7 @@#include "hw/i2c/smbus_eeprom.h" #include "hw/misc/pca9552.h" #include "hw/misc/tmp105.h" +#include "hw/misc/led.h" #include "hw/qdev-properties.h" #include "qemu/log.h" #include "sysemu/block-backend.h"
@@ -521,9 +522,20 @@ static void sonorapass_bmc_i2c_init(AspeedMachineState *bmc)static void witherspoon_bmc_i2c_init (AspeedMachineState *bmc) { +static const struct { +unsigned gpio_id; +LEDColor color; +const char *description; +bool gpio_polarity; + } pca1_leds[] = { + {13 ,LED_COLOR_GREEN ,"front-fault-4" ,GPIO_POLARITY_ACTIVE_LOW }, + {14 ,LED_COLOR_GREEN ,"front-power-3" ,GPIO_POLARITY_ACTIVE_LOW }, + {15 ,LED_COLOR_GREEN ,"front-id-5" ,GPIO_POLARITY_ACTIVE_LOW }, + };AspeedSoCState *soc = &bmc->soc;uint8_t *eeprom_buf =g_malloc0 (8 *1024 );DeviceState *dev; +LEDState *led;/* Bus 3: TODO bmp280@77 */ /* Bus 3: TODO max31785@52 */
@@ -534,6 +546,14 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc)aspeed_i2c_get_bus (&soc->i2c,3 ), &error_fatal); +for (size_t i =0 ; i <ARRAY_SIZE (pca1_leds); i++) { + led =led_create_simple (OBJECT (bmc), + pca1_leds[i].gpio_polarity, + pca1_leds[i].color, + pca1_leds[i].description); +qdev_connect_gpio_out (dev, pca1_leds[i].gpio_id, +qdev_get_gpio_in (DEVICE (led),0 )); + }i2c_slave_create_simple (aspeed_i2c_get_bus (&soc->i2c,4 ),"tmp423" ,0x4c );i2c_slave_create_simple (aspeed_i2c_get_bus (&soc->i2c,5 ),"tmp423" ,0x4c );
hw/arm/Kconfig +1 -0
@@ -394,6 +394,7 @@ config ASPEED_SOC select TMP105 select TMP421 select UNIMP + select LED config MPS2 bool
Signature · 1 line
2.26.2
Re: [PATCH v5 4/7] hw/arm/aspeed: Add the 3 front LEDs drived by the PCA9552 #1
Quoted 19 lines · Philippe Mathieu-Daudé
The Witherspoon has 3 LEDs connected to a PCA9552. Add them. The names and reset values are taken from:
https://github.com/open-power/witherspoon-xml/blob/master/witherspoon.xmlExample booting obmc-phosphor-image:
$ qemu-system-arm -M witherspoon-bmc -trace led_change_intensity 1592693373.997015:led_change_intensity LED desc:'front-fault-4' color:green intensity 0% -> 100% 1592693373.997632:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100% 1592693373.998239:led_change_intensity LED desc:'front-id-5' color:green intensity 0% -> 100% 1592693500.291805:led_change_intensity LED desc:'front-power-3' color:green intensity 100% -> 0% 1592693500.312041:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100% 1592693500.821254:led_change_intensity LED desc:'front-power-3' color:green intensity 100% -> 0% 1592693501.331517:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100% 1592693501.841367:led_change_intensity LED desc:'front-power-3' color:green intensity 100% -> 0% 1592693502.350839:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100% 1592693502.861134:led_change_intensity LED desc:'front-power-3' color:green intensity 100% -> 0% 1592693503.371090:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100%
Quoted 4 lines
We notice the front-power LED starts to blink at a ~2Hz rate.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 66 lines
--- hw/arm/aspeed.c | 20 ++++++++++++++++++++ hw/arm/Kconfig | 1 + 2 files changed, 21 insertions(+)hw/arm/aspeed.c +20
-0@@ -20,6 +20,7 @@#include "hw/i2c/smbus_eeprom.h" #include "hw/misc/pca9552.h" #include "hw/misc/tmp105.h" +#include "hw/misc/led.h" #include "hw/qdev-properties.h" #include "qemu/log.h" #include "sysemu/block-backend.h" @@ -521,9 +522,20 @@ static void sonorapass_bmc_i2c_init(AspeedMachineState *bmc)static void witherspoon_bmc_i2c_init (AspeedMachineState *bmc) { +static const struct { +unsigned gpio_id; +LEDColor color; +const char *description; +bool gpio_polarity; + } pca1_leds[] = { + {13 ,LED_COLOR_GREEN ,"front-fault-4" ,GPIO_POLARITY_ACTIVE_LOW }, + {14 ,LED_COLOR_GREEN ,"front-power-3" ,GPIO_POLARITY_ACTIVE_LOW }, + {15 ,LED_COLOR_GREEN ,"front-id-5" ,GPIO_POLARITY_ACTIVE_LOW }, + };AspeedSoCState *soc = &bmc->soc;uint8_t *eeprom_buf =g_malloc0 (8 *1024 );DeviceState *dev; +LEDState *led;/* Bus 3: TODO bmp280@77 */ /* Bus 3: TODO max31785@52 */ @@ -534,6 +546,14 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc)aspeed_i2c_get_bus (&soc->i2c,3 ), &error_fatal); +for (size_t i =0 ; i <ARRAY_SIZE (pca1_leds); i++) { + led =led_create_simple (OBJECT (bmc), + pca1_leds[i].gpio_polarity, + pca1_leds[i].color, + pca1_leds[i].description); +qdev_connect_gpio_out (dev, pca1_leds[i].gpio_id, +qdev_get_gpio_in (DEVICE (led),0 )); + }i2c_slave_create_simple (aspeed_i2c_get_bus (&soc->i2c,4 ),"tmp423" ,0x4c );i2c_slave_create_simple (aspeed_i2c_get_bus (&soc->i2c,5 ),"tmp423" ,0x4c );hw/arm/Kconfig +1
-0@@ -394,6 +394,7 @@ config ASPEED_SOC select TMP105 select TMP421 select UNIMP + select LED config MPS2 bool
PATCH v5 5/7 hw/misc/mps2-fpgaio: Use the LED device
In reply to Philippe Mathieu-DaudéPer the 'ARM MPS2 and MPS2+ FPGA Prototyping Boards Technical Reference Manual' (100112_0200_07_en):
2.1 Overview of the MPS2 and MPS2+ hardware
The MPS2 and MPS2+ FPGA Prototyping Boards contain the following components and interfaces:
* User switches and user LEDs:
- Two green LEDs and two push buttons that connect to the FPGA.
- Eight green LEDs and one 8-way dip switch that connect to the MCC.
Add the 2 LEDs connected to the FPGA.
This remplaces the 'mps2_fpgaio_leds' trace events by the generic 'led_set_intensity' event.
--- include/hw/misc/mps2-fpgaio.h | 2 ++ hw/misc/mps2-fpgaio.c | 19 ++++++++++++++----- hw/misc/Kconfig | 1 + hw/misc/trace-events | 1 - 4 files changed, 17 insertions(+), 6 deletions(-)
include/hw/misc/mps2-fpgaio.h +2 -0
@@ -22,6 +22,7 @@#define MPS2_FPGAIO_H #include "hw/sysbus.h" +#include "hw/misc/led.h" #define TYPE_MPS2_FPGAIO "mps2-fpgaio"#define MPS2_FPGAIO (obj) OBJECT_CHECK(MPS2FPGAIO, (obj), TYPE_MPS2_FPGAIO)
@@ -32,6 +33,7 @@ typedef struct {/*< public >*/ MemoryRegion iomem; +LEDState *led[2 ];uint32_t led0;uint32_t prescale;
hw/misc/mps2-fpgaio.c +14 -5
@@ -24,6 +24,7 @@#include "migration/vmstate.h" #include "hw/registerfields.h" #include "hw/misc/mps2-fpgaio.h" +#include "hw/misc/led.h" #include "hw/qdev-properties.h" #include "qemu/timer.h"
@@ -176,12 +177,9 @@ static void mps2_fpgaio_write(void *opaque, hwaddr offset, uint64_t value,switch (offset) {case A_LED0 : -/* LED bits [1:0] control board LEDs. We don't currently have -* a mechanism for displaying this graphically, so use a trace event. -*/ -trace_mps2_fpgaio_leds (value &0x02 ?'*' :'.' , - value &0x01 ?'*' :'.' ); s->led0 = value &0x3 ; +led_set_state (s->led[0 ], value &0x01 ); +led_set_state (s->led[1 ], value &0x02 );break ;case A_PRESCALE :resync_counter (s);
@@ -251,6 +249,16 @@ static void mps2_fpgaio_init(Object *obj)sysbus_init_mmio (sbd, &s->iomem); } +static void mps2_fpgaio_realize (DeviceState *dev,Error **errp) +{ +MPS2FPGAIO *s =MPS2_FPGAIO (dev); + + s->led[0 ] =led_create_simple (OBJECT (dev),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_GREEN ,"USERLED0" ); + s->led[1 ] =led_create_simple (OBJECT (dev),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_GREEN ,"USERLED1" ); +} +static bool mps2_fpgaio_counters_needed (void *opaque) {/* Currently vmstate.c insists all subsections have a 'needed' function */
@@ -299,6 +307,7 @@ static void mps2_fpgaio_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass); dc->vmsd = &mps2_fpgaio_vmstate; + dc->realize = mps2_fpgaio_realize; dc->reset = mps2_fpgaio_reset;device_class_set_props (dc, mps2_fpgaio_properties); }
hw/misc/Kconfig +1 -0
@@ -93,6 +93,7 @@ config MIPS_ITU config MPS2_FPGAIO bool + select LED config MPS2_SCC bool
hw/misc/trace-events +0 -1
@@ -93,7 +93,6 @@ mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC mps2_fpgaio_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_fpgaio_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_fpgaio_reset(void) "MPS2 FPGAIO: reset" -mps2_fpgaio_leds(char led1, char led0) "MPS2 FPGAIO LEDs: %c%c" # msf2-sysreg.c msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysreg write: addr 0x%08" PRIx64 " data 0x%" PRIx32 " prev 0x%" PRIx32
Signature · 1 line
2.26.2
Re: [PATCH v5 5/7] hw/misc/mps2-fpgaio: Use the LED device
Hi Phil,
Quoted 10 lines · Philippe Mathieu-Daudé
Per the 'ARM MPS2 and MPS2+ FPGA Prototyping Boards Technical Reference Manual' (100112_0200_07_en):
2.1 Overview of the MPS2 and MPS2+ hardware
The MPS2 and MPS2+ FPGA Prototyping Boards contain the following components and interfaces:
* User switches and user LEDs:
Quoted 8 lines
- Two green LEDs and two push buttons that connect to the FPGA.
- Eight green LEDs and one 8-way dip switch that connect to the MCC.Add the 2 LEDs connected to the FPGA.
This remplaces the '
mps2_fpgaio_leds' trace events by the generic
replaces
Quoted 1 line
'
led_set_intensity' event.
If I'm not mistaken the LED device being a DEVICE and not a SYS_BUS_DEVICE, it needs to be manually reset. So you probably need to reset it in mps2_fpgaio_reset so it doesn't get out of sync on system reset.
Signature · 1 line
Luc
Quoted 106 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/misc/mps2-fpgaio.h | 2 ++ hw/misc/mps2-fpgaio.c | 19 ++++++++++++++----- hw/misc/Kconfig | 1 + hw/misc/trace-events | 1 - 4 files changed, 17 insertions(+), 6 deletions(-)include/hw/misc/mps2-fpgaio.h +2
-0@@ -22,6 +22,7 @@#define MPS2_FPGAIO_H #include "hw/sysbus.h" +#include "hw/misc/led.h" #define TYPE_MPS2_FPGAIO "mps2-fpgaio"#define MPS2_FPGAIO (obj) OBJECT_CHECK(MPS2FPGAIO, (obj), TYPE_MPS2_FPGAIO)@@ -32,6 +33,7 @@ typedef struct {/*< public >*/ MemoryRegion iomem; +LEDState *led[2 ];uint32_t led0;uint32_t prescale;hw/misc/mps2-fpgaio.c +14
-5@@ -24,6 +24,7 @@#include "migration/vmstate.h" #include "hw/registerfields.h" #include "hw/misc/mps2-fpgaio.h" +#include "hw/misc/led.h" #include "hw/qdev-properties.h" #include "qemu/timer.h" @@ -176,12 +177,9 @@ static void mps2_fpgaio_write(void *opaque, hwaddr offset, uint64_t value,switch (offset) {case A_LED0 : -/* LED bits [1:0] control board LEDs. We don't currently have -* a mechanism for displaying this graphically, so use a trace event. -*/ -trace_mps2_fpgaio_leds (value &0x02 ?'*' :'.' , - value &0x01 ?'*' :'.' ); s->led0 = value &0x3 ; +led_set_state (s->led[0 ], value &0x01 ); +led_set_state (s->led[1 ], value &0x02 );break ;case A_PRESCALE :resync_counter (s);@@ -251,6 +249,16 @@ static void mps2_fpgaio_init(Object *obj)sysbus_init_mmio (sbd, &s->iomem); } +static void mps2_fpgaio_realize (DeviceState *dev,Error **errp) +{ +MPS2FPGAIO *s =MPS2_FPGAIO (dev); + + s->led[0 ] =led_create_simple (OBJECT (dev),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_GREEN ,"USERLED0" ); + s->led[1 ] =led_create_simple (OBJECT (dev),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_GREEN ,"USERLED1" ); +} +static bool mps2_fpgaio_counters_needed (void *opaque) {/* Currently vmstate.c insists all subsections have a 'needed' function */ @@ -299,6 +307,7 @@ static void mps2_fpgaio_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass); dc->vmsd = &mps2_fpgaio_vmstate; + dc->realize = mps2_fpgaio_realize; dc->reset = mps2_fpgaio_reset;device_class_set_props (dc, mps2_fpgaio_properties); }hw/misc/Kconfig +1
-0@@ -93,6 +93,7 @@ config MIPS_ITU config MPS2_FPGAIO bool + select LED config MPS2_SCC boolhw/misc/trace-events +0
-1@@ -93,7 +93,6 @@ mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC mps2_fpgaio_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_fpgaio_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_fpgaio_reset(void) "MPS2 FPGAIO: reset" -mps2_fpgaio_leds(char led1, char led0) "MPS2 FPGAIO LEDs: %c%c" # msf2-sysreg.c msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysreg write: addr 0x%08" PRIx64 " data 0x%" PRIx32 " prev 0x%" PRIx32
Re: [PATCH v5 5/7] hw/misc/mps2-fpgaio: Use the LED device
Quoted 20 lines · Luc Michel
Hi Phil,
Quoted 17 lines · Philippe Mathieu-Daudé
Per the 'ARM MPS2 and MPS2+ FPGA Prototyping Boards Technical Reference Manual' (100112_0200_07_en):
2.1 Overview of the MPS2 and MPS2+ hardware
The MPS2 and MPS2+ FPGA Prototyping Boards contain the following components and interfaces:
* User switches and user LEDs:
- Two green LEDs and two push buttons that connect to the FPGA.
- Eight green LEDs and one 8-way dip switch that connect to the MCC.Add the 2 LEDs connected to the FPGA.
Quoted 8 lines
Quoted 1 line
This remplaces the '
mps2_fpgaio_leds' trace events by the genericreplaces
Quoted 1 line
'
led_set_intensity' event.If I'm not mistaken the LED device being a DEVICE and not a
SYS_BUS_DEVICE, it needs to be manually reset. So you probably need to reset it inmps2_fpgaio_resetso it doesn't get out of sync on system reset.
Correct...
Alternatively we could see a LED as a SysBusDevice exposing a MMIO region of 1 writable bit =) But it is unlikely to be mapped on the main system bus.
I'll add the reset, thanks for reviewing!
Phil.
Re: [PATCH v5 5/7] hw/misc/mps2-fpgaio: Use the LED device
In reply to Philippe Mathieu-DaudéQuoted 15 lines · Philippe Mathieu-Daudé
Per the 'ARM MPS2 and MPS2+ FPGA Prototyping Boards Technical Reference Manual' (100112_0200_07_en):
2.1 Overview of the MPS2 and MPS2+ hardware
The MPS2 and MPS2+ FPGA Prototyping Boards contain the following components and interfaces:
* User switches and user LEDs:
- Two green LEDs and two push buttons that connect to the FPGA.
- Eight green LEDs and one 8-way dip switch that connect to the MCC.
Quoted 7 lines
Add the 2 LEDs connected to the FPGA.
This remplaces the '
mps2_fpgaio_leds' trace events by the generic 'led_set_intensity' event.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
r~
PATCH v5 6/7 hw/misc/mps2-scc: Use the LED device
In reply to Philippe Mathieu-DaudéPer the 'ARM MPS2 and MPS2+ FPGA Prototyping Boards Technical Reference Manual' (100112_0200_07_en):
2.1 Overview of the MPS2 and MPS2+ hardware
The MPS2 and MPS2+ FPGA Prototyping Boards contain the following components and interfaces:
* User switches and user LEDs:
- Two green LEDs and two push buttons that connect to the FPGA.
- Eight green LEDs and one 8-way dip switch that connect to the MCC.
Add the 8 LEDs connected to the MCC.
This remplaces the 'mps2_scc_leds' trace events by the generic 'led_set_intensity' event.
---
https://youtu.be/l9kD70uPchk?t=288
--- include/hw/misc/mps2-scc.h | 2 ++ hw/misc/mps2-scc.c | 25 ++++++++++++++----------- hw/misc/Kconfig | 1 + hw/misc/trace-events | 1 - 4 files changed, 17 insertions(+), 12 deletions(-)
include/hw/misc/mps2-scc.h +2 -0
@@ -13,6 +13,7 @@#define MPS2_SCC_H #include "hw/sysbus.h" +#include "hw/misc/led.h" #define TYPE_MPS2_SCC "mps2-scc"#define MPS2_SCC (obj) OBJECT_CHECK(MPS2SCC, (obj), TYPE_MPS2_SCC)
@@ -25,6 +26,7 @@ typedef struct {/*< public >*/ MemoryRegion iomem; +LEDState *led[8 ];uint32_t cfg0;uint32_t cfg1;
hw/misc/mps2-scc.c +14 -11
@@ -20,11 +20,13 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/module.h" +#include "qemu/bitops.h" #include "trace.h" #include "hw/sysbus.h" #include "migration/vmstate.h" #include "hw/registerfields.h" #include "hw/misc/mps2-scc.h" +#include "hw/misc/led.h" #include "hw/qdev-properties.h" REG32 (CFG0 ,0 )
@@ -152,18 +154,10 @@ static void mps2_scc_write(void *opaque, hwaddr offset, uint64_t value, s->cfg0 = value;break ;case A_CFG1 : -/* CFG1 bits [7:0] control the board LEDs. We don't currently have -* a mechanism for displaying this graphically, so use a trace event. -*/ -trace_mps2_scc_leds (value &0x80 ?'*' :'.' , - value &0x40 ?'*' :'.' , - value &0x20 ?'*' :'.' , - value &0x10 ?'*' :'.' , - value &0x08 ?'*' :'.' , - value &0x04 ?'*' :'.' , - value &0x02 ?'*' :'.' , - value &0x01 ?'*' :'.' ); s->cfg1 = value; +for (size_t i =0 ; i <ARRAY_SIZE (s->led); i++) { +led_set_state (s->led[i],extract32 (value, i,1 )); + }break ;case A_CFGDATA_OUT : s->cfgdata_out = value;
@@ -245,10 +239,19 @@ static void mps2_scc_init(Object *obj)memory_region_init_io (&s->iomem, obj, &mps2_scc_ops, s,"mps2-scc" ,0x1000 );sysbus_init_mmio (sbd, &s->iomem); + }static void mps2_scc_realize (DeviceState *dev,Error **errp) { +MPS2SCC *s =MPS2_SCC (dev); + +for (size_t i =0 ; i <ARRAY_SIZE (s->led); i++) { +char *name =g_strdup_printf ("SCC LED%zu" , i); + s->led[i] =led_create_simple (OBJECT (dev),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_GREEN , name); +g_free (name); + } }static const VMStateDescription mps2_scc_vmstate = {
hw/misc/Kconfig +1 -0
@@ -97,6 +97,7 @@ config MPS2_FPGAIO config MPS2_SCC bool + select LED config TZ_MPC bool
hw/misc/trace-events +0 -1
@@ -85,7 +85,6 @@ aspeed_scu_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 mps2_scc_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 SCC read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_scc_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 SCC write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_scc_reset(void) "MPS2 SCC: reset" -mps2_scc_leds(char led7, char led6, char led5, char led4, char led3, char led2, char led1, char led0) "MPS2 SCC LEDs: %c%c%c%c%c%c%c%c" mps2_scc_cfg_write(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config write: function %d device %d data 0x%" PRIx32 mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config read: function %d device %d data 0x%" PRIx32
Signature · 1 line
2.26.2
Re: [PATCH v5 6/7] hw/misc/mps2-scc: Use the LED device
Quoted 10 lines · Philippe Mathieu-Daudé
Per the 'ARM MPS2 and MPS2+ FPGA Prototyping Boards Technical Reference Manual' (100112_0200_07_en):
2.1 Overview of the MPS2 and MPS2+ hardware
The MPS2 and MPS2+ FPGA Prototyping Boards contain the following components and interfaces:
* User switches and user LEDs:
Quoted 8 lines
- Two green LEDs and two push buttons that connect to the FPGA.
- Eight green LEDs and one 8-way dip switch that connect to the MCC.Add the 8 LEDs connected to the MCC.
This remplaces the '
mps2_scc_leds' trace events by the generic
replaces
Quoted 1 line
'
led_set_intensity' event.
Same as patch 5, I think you need to reset your LEDs in mps2_scc_reset.
Also, see below for a superfluous new line.
Quoted 72 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
https://youtu.be/l9kD70uPchk?t=288--- include/hw/misc/mps2-scc.h | 2 ++ hw/misc/mps2-scc.c | 25 ++++++++++++++----------- hw/misc/Kconfig | 1 + hw/misc/trace-events | 1 - 4 files changed, 17 insertions(+), 12 deletions(-)include/hw/misc/mps2-scc.h +2
-0@@ -13,6 +13,7 @@#define MPS2_SCC_H #include "hw/sysbus.h" +#include "hw/misc/led.h" #define TYPE_MPS2_SCC "mps2-scc"#define MPS2_SCC (obj) OBJECT_CHECK(MPS2SCC, (obj), TYPE_MPS2_SCC)@@ -25,6 +26,7 @@ typedef struct {/*< public >*/ MemoryRegion iomem; +LEDState *led[8 ];uint32_t cfg0;uint32_t cfg1;hw/misc/mps2-scc.c +5
-11@@ -20,11 +20,13 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/module.h" +#include "qemu/bitops.h" #include "trace.h" #include "hw/sysbus.h" #include "migration/vmstate.h" #include "hw/registerfields.h" #include "hw/misc/mps2-scc.h" +#include "hw/misc/led.h" #include "hw/qdev-properties.h" REG32 (CFG0 ,0 )@@ -152,18 +154,10 @@ static void mps2_scc_write(void *opaque, hwaddr offset, uint64_t value, s->cfg0 = value;break ;case A_CFG1 : -/* CFG1 bits [7:0] control the board LEDs. We don't currently have -* a mechanism for displaying this graphically, so use a trace event. -*/ -trace_mps2_scc_leds (value &0x80 ?'*' :'.' , - value &0x40 ?'*' :'.' , - value &0x20 ?'*' :'.' , - value &0x10 ?'*' :'.' , - value &0x08 ?'*' :'.' , - value &0x04 ?'*' :'.' , - value &0x02 ?'*' :'.' , - value &0x01 ?'*' :'.' ); s->cfg1 = value; +for (size_t i =0 ; i <ARRAY_SIZE (s->led); i++) { +led_set_state (s->led[i],extract32 (value, i,1 )); + }break ;case A_CFGDATA_OUT : s->cfgdata_out = value;
hw/misc/mps2-scc.c static void mps2_scc_init(Object *obj) · line 242
Quoted 4 lines
hw/misc/mps2-scc.c +1
-0@@ -245,10 +239,19 @@ static void mps2_scc_init(Object *obj)memory_region_init_io (&s->iomem, obj, &mps2_scc_ops, s,"mps2-scc" ,0x1000 );sysbus_init_mmio (sbd, &s->iomem); +
Superfluous new line.
Signature · 1 line
Luc
Quoted 40 lines
hw/misc/mps2-scc.c +8
-0}static void mps2_scc_realize (DeviceState *dev,Error **errp) { +MPS2SCC *s =MPS2_SCC (dev); + +for (size_t i =0 ; i <ARRAY_SIZE (s->led); i++) { +char *name =g_strdup_printf ("SCC LED%zu" , i); + s->led[i] =led_create_simple (OBJECT (dev),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_GREEN , name); +g_free (name); + } }static const VMStateDescription mps2_scc_vmstate = {hw/misc/Kconfig +1
-0@@ -97,6 +97,7 @@ config MPS2_FPGAIO config MPS2_SCC bool + select LED config TZ_MPC boolhw/misc/trace-events +0
-1@@ -85,7 +85,6 @@ aspeed_scu_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 mps2_scc_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 SCC read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_scc_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 SCC write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_scc_reset(void) "MPS2 SCC: reset" -mps2_scc_leds(char led7, char led6, char led5, char led4, char led3, char led2, char led1, char led0) "MPS2 SCC LEDs: %c%c%c%c%c%c%c%c" mps2_scc_cfg_write(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config write: function %d device %d data 0x%" PRIx32 mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config read: function %d device %d data 0x%" PRIx32
Re: [PATCH v5 6/7] hw/misc/mps2-scc: Use the LED device
In reply to Philippe Mathieu-DaudéQuoted 15 lines · Philippe Mathieu-Daudé
Per the 'ARM MPS2 and MPS2+ FPGA Prototyping Boards Technical Reference Manual' (100112_0200_07_en):
2.1 Overview of the MPS2 and MPS2+ hardware
The MPS2 and MPS2+ FPGA Prototyping Boards contain the following components and interfaces:
* User switches and user LEDs:
- Two green LEDs and two push buttons that connect to the FPGA.
- Eight green LEDs and one 8-way dip switch that connect to the MCC.
Quoted 7 lines
Add the 8 LEDs connected to the MCC.
This remplaces the '
mps2_scc_leds' trace events by the generic 'led_set_intensity' event.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
r~
PATCH v5 7/7 hw/arm/tosa: Replace fprintf() calls by LED devices
In reply to Philippe Mathieu-DaudéThe recently added LED device reports LED status changes with the 'led_set_intensity' trace event. It is less invasive than the fprintf() calls. We need however to have a binary built with tracing support.
--- hw/arm/tosa.c | 40 +++++++++++++++------------------------- hw/arm/Kconfig | 1 + 2 files changed, 16 insertions(+), 25 deletions(-)
hw/arm/tosa.c +15 -25
@@ -24,6 +24,7 @@#include "hw/irq.h" #include "hw/ssi/ssi.h" #include "hw/sysbus.h" +#include "hw/misc/led.h" #include "exec/address-spaces.h" #define TOSA_RAM 0x04000000
@@ -81,26 +82,6 @@ typedef struct TosaMiscGPIOState {SysBusDevice parent_obj; } TosaMiscGPIOState; -static void tosa_gpio_leds (void *opaque,int line,int level) -{ -switch (line) { -case 0 : -fprintf (stderr,"blue LED %s.\n" , level ?"on" :"off" ); -break ; -case 1 : -fprintf (stderr,"green LED %s.\n" , level ?"on" :"off" ); -break ; -case 2 : -fprintf (stderr,"amber LED %s.\n" , level ?"on" :"off" ); -break ; -case 3 : -fprintf (stderr,"wlan LED %s.\n" , level ?"on" :"off" ); -break ; -default : -g_assert_not_reached (); - } -} -static void tosa_reset (void *opaque,int line,int level) {if (level) {
@@ -112,7 +93,6 @@ static void tosa_misc_gpio_init(Object *obj) {DeviceState *dev =DEVICE (obj); -qdev_init_gpio_in_named (dev, tosa_gpio_leds,"leds" ,4 );qdev_init_gpio_in_named (dev, tosa_reset,"reset" ,1 ); }
@@ -122,6 +102,7 @@ static void tosa_gpio_setup(PXA2xxState *cpu, TC6393xbState *tmio) {DeviceState *misc_gpio; +LEDState *led[4 ]; misc_gpio =sysbus_create_simple (TYPE_TOSA_MISC_GPIO ,-1 ,NULL );
@@ -143,14 +124,23 @@ static void tosa_gpio_setup(PXA2xxState *cpu,qdev_get_gpio_in (cpu->gpio,TOSA_GPIO_JC_CF_IRQ ), NULL); + led[0 ] =led_create_simple (OBJECT (misc_gpio),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_BLUE ,"bluetooth" ); + led[1 ] =led_create_simple (OBJECT (misc_gpio),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_GREEN ,"note" ); + led[2 ] =led_create_simple (OBJECT (misc_gpio),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_AMBER ,"charger-error" ); + led[3 ] =led_create_simple (OBJECT (misc_gpio),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_GREEN ,"wlan" ); +qdev_connect_gpio_out (scp1,TOSA_GPIO_BT_LED , -qdev_get_gpio_in_named (misc_gpio,"leds" ,0 )); +qdev_get_gpio_in (DEVICE (led[0 ]),0 ));qdev_connect_gpio_out (scp1,TOSA_GPIO_NOTE_LED , -qdev_get_gpio_in_named (misc_gpio,"leds" ,1 )); +qdev_get_gpio_in (DEVICE (led[1 ]),0 ));qdev_connect_gpio_out (scp1,TOSA_GPIO_CHRG_ERR_LED , -qdev_get_gpio_in_named (misc_gpio,"leds" ,2 )); +qdev_get_gpio_in (DEVICE (led[2 ]),0 ));qdev_connect_gpio_out (scp1,TOSA_GPIO_WLAN_LED , -qdev_get_gpio_in_named (misc_gpio,"leds" ,3 )); +qdev_get_gpio_in (DEVICE (led[3 ]),0 ));qdev_connect_gpio_out (scp1,TOSA_GPIO_TC6393XB_L3V_ON ,tc6393xb_l3v_get (tmio));
hw/arm/Kconfig +1 -0
@@ -150,6 +150,7 @@ config TOSA select ZAURUS # scoop select MICRODRIVE select PXA2XX + select LED config SPITZ bool
Signature · 1 line
2.26.2
Re: [PATCH v5 7/7] hw/arm/tosa: Replace fprintf() calls by LED devices
Quoted 6 lines · Philippe Mathieu-Daudé
The recently added LED device reports LED status changes with the '
led_set_intensity' trace event. It is less invasive than thefprintf()calls. We need however to have a binary built with tracing support.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 101 lines
--- hw/arm/tosa.c | 40 +++++++++++++++------------------------- hw/arm/Kconfig | 1 + 2 files changed, 16 insertions(+), 25 deletions(-)hw/arm/tosa.c +15
-25@@ -24,6 +24,7 @@#include "hw/irq.h" #include "hw/ssi/ssi.h" #include "hw/sysbus.h" +#include "hw/misc/led.h" #include "exec/address-spaces.h" #define TOSA_RAM 0x04000000@@ -81,26 +82,6 @@ typedef struct TosaMiscGPIOState {SysBusDevice parent_obj; } TosaMiscGPIOState; -static void tosa_gpio_leds (void *opaque,int line,int level) -{ -switch (line) { -case 0 : -fprintf (stderr,"blue LED %s.\n" , level ?"on" :"off" ); -break ; -case 1 : -fprintf (stderr,"green LED %s.\n" , level ?"on" :"off" ); -break ; -case 2 : -fprintf (stderr,"amber LED %s.\n" , level ?"on" :"off" ); -break ; -case 3 : -fprintf (stderr,"wlan LED %s.\n" , level ?"on" :"off" ); -break ; -default : -g_assert_not_reached (); - } -} -static void tosa_reset (void *opaque,int line,int level) {if (level) {@@ -112,7 +93,6 @@ static void tosa_misc_gpio_init(Object *obj) {DeviceState *dev =DEVICE (obj); -qdev_init_gpio_in_named (dev, tosa_gpio_leds,"leds" ,4 );qdev_init_gpio_in_named (dev, tosa_reset,"reset" ,1 ); }@@ -122,6 +102,7 @@ static void tosa_gpio_setup(PXA2xxState *cpu, TC6393xbState *tmio) {DeviceState *misc_gpio; +LEDState *led[4 ]; misc_gpio =sysbus_create_simple (TYPE_TOSA_MISC_GPIO ,-1 ,NULL );@@ -143,14 +124,23 @@ static void tosa_gpio_setup(PXA2xxState *cpu,qdev_get_gpio_in (cpu->gpio,TOSA_GPIO_JC_CF_IRQ ), NULL); + led[0 ] =led_create_simple (OBJECT (misc_gpio),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_BLUE ,"bluetooth" ); + led[1 ] =led_create_simple (OBJECT (misc_gpio),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_GREEN ,"note" ); + led[2 ] =led_create_simple (OBJECT (misc_gpio),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_AMBER ,"charger-error" ); + led[3 ] =led_create_simple (OBJECT (misc_gpio),GPIO_POLARITY_ACTIVE_HIGH , +LED_COLOR_GREEN ,"wlan" ); +qdev_connect_gpio_out (scp1,TOSA_GPIO_BT_LED , -qdev_get_gpio_in_named (misc_gpio,"leds" ,0 )); +qdev_get_gpio_in (DEVICE (led[0 ]),0 ));qdev_connect_gpio_out (scp1,TOSA_GPIO_NOTE_LED , -qdev_get_gpio_in_named (misc_gpio,"leds" ,1 )); +qdev_get_gpio_in (DEVICE (led[1 ]),0 ));qdev_connect_gpio_out (scp1,TOSA_GPIO_CHRG_ERR_LED , -qdev_get_gpio_in_named (misc_gpio,"leds" ,2 )); +qdev_get_gpio_in (DEVICE (led[2 ]),0 ));qdev_connect_gpio_out (scp1,TOSA_GPIO_WLAN_LED , -qdev_get_gpio_in_named (misc_gpio,"leds" ,3 )); +qdev_get_gpio_in (DEVICE (led[3 ]),0 ));qdev_connect_gpio_out (scp1,TOSA_GPIO_TC6393XB_L3V_ON ,tc6393xb_l3v_get (tmio));hw/arm/Kconfig +1
-0@@ -150,6 +150,7 @@ config TOSA select ZAURUS # scoop select MICRODRIVE select PXA2XX + select LED config SPITZ bool
Re: [PATCH v5 7/7] hw/arm/tosa: Replace fprintf() calls by LED devices
In reply to Philippe Mathieu-DaudéQuoted 10 lines · Philippe Mathieu-Daudé
The recently added LED device reports LED status changes with the '
led_set_intensity' trace event. It is less invasive than thefprintf()calls. We need however to have a binary built with tracing support.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/arm/tosa.c | 40 +++++++++++++++------------------------- hw/arm/Kconfig | 1 + 2 files changed, 16 insertions(+), 25 deletions(-)
r~