hw/misc/pca9552: Trace GPIO change events
v6 cover hw/misc/pca9552: Trace GPIO change events
This series add trace events to better display GPIO changes. We'll continue in the following series by connecting LEDs to these GPIOs.
This helps me to work on a generic LED device, see:
https://www.mail-archive.com/[email protected]/msg711917.html
Since v5, addressed Cédric review comment:
- Move pin_count check from realize() to instance_init()
Since v4: Addressed Cédric review comments
- Extract PCA955xClass
- Add/use pca955x_pins_get_status() method instead of keeping cached value in PCA955xState
Example when booting an obmc-phosphor-image, we can see the LED #14 (front-power LED) starting to blink.
- ASCII LED bar view:
$ qemu-system-arm -M witherspoon-bmc -trace pca955x_gpio_status 1592689902.327837:pca955x_gpio_status pca-unspecified GPIOs 0-15 [*...............] 1592689902.329934:pca955x_gpio_status pca-unspecified GPIOs 0-15 [**..............] 1592689902.330717:pca955x_gpio_status pca-unspecified GPIOs 0-15 [***.............] 1592689902.331431:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****............] 1592689902.332163:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*..] 1592689902.332888:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........**.] 1592689902.333629:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........***] 1592690032.793289:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*.*] 1592690033.303163:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........***] 1592690033.812962:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*.*] 1592690034.323234:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........***] 1592690034.832922:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*.*]
- Only display GPIOs which status changes:
$ qemu-system-arm -M witherspoon-bmc -trace pca955x_gpio_change 1592690552.687372:pca955x_gpio_change pca1 GPIO id:0 status: 0 -> 1 1592690552.690169:pca955x_gpio_change pca1 GPIO id:1 status: 0 -> 1 1592690552.691673:pca955x_gpio_change pca1 GPIO id:2 status: 0 -> 1 1592690552.696886:pca955x_gpio_change pca1 GPIO id:3 status: 0 -> 1 1592690552.698614:pca955x_gpio_change pca1 GPIO id:13 status: 0 -> 1 1592690552.699833:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1 1592690552.700842:pca955x_gpio_change pca1 GPIO id:15 status: 0 -> 1 1592690683.841921:pca955x_gpio_change pca1 GPIO id:14 status: 1 -> 0 1592690683.861660:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1 1592690684.371460:pca955x_gpio_change pca1 GPIO id:14 status: 1 -> 0 1592690684.882115:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1 1592690685.391411:pca955x_gpio_change pca1 GPIO id:14 status: 1 -> 0 1592690685.901391:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1
For information about how to test the obmc-phosphor-image, see:
https://www.mail-archive.com/[email protected]/msg712911.html
$ git backport-diff -u v5 Key: [----] : patches are identical [####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively
001/9:[----] [--] 'hw/i2c/core: Add i2c_try_create_slave() and i2c_realize_and_unref()' 002/9:[----] [--] 'hw/misc/pca9552: Rename 'nr_leds' as 'pin_count'' 003/9:[----] [--] 'hw/misc/pca9552: Rename generic code as pca955x' 004/9:[0010] [FC] 'hw/misc/pca9552: Add generic PCA955xClass, parent of TYPE_PCA9552' 005/9:[0007] [FC] 'hw/misc/pca9552: Add a 'description' property for debugging purpose' 006/9:[----] [--] 'hw/misc/pca9552: Trace GPIO High/Low events' 007/9:[----] [-C] 'hw/arm/aspeed: Describe each PCA9552 device' 008/9:[----] [--] 'hw/misc/pca9552: Trace GPIO change events' 009/9:[0003] [FC] 'hw/misc/pca9552: Model qdev output GPIOs'
Based-on: <[email protected]>
Philippe Mathieu-Daudé (9):
hw/i2c/core: Add i2c_try_create_slave() and i2c_realize_and_unref() hw/misc/pca9552: Rename 'nr_leds' as 'pin_count' hw/misc/pca9552: Rename generic code as pca955x hw/misc/pca9552: Add generic PCA955xClass, parent of TYPE_PCA9552 hw/misc/pca9552: Add a 'description' property for debugging purpose hw/misc/pca9552: Trace GPIO High/Low events hw/arm/aspeed: Describe each PCA9552 device hw/misc/pca9552: Trace GPIO change events hw/misc/pca9552: Model qdev output GPIOs
include/hw/i2c/i2c.h | 2 + include/hw/misc/pca9552.h | 16 +-- hw/arm/aspeed.c | 13 ++- hw/i2c/core.c | 18 +++- hw/misc/pca9552.c | 216 ++++++++++++++++++++++++++++---------- hw/misc/trace-events | 4 + 6 files changed, 202 insertions(+), 67 deletions(-)
Signature · 1 line
2.21.3
PATCH v6 1/9 hw/i2c/core: Add i2c_try_create_slave() and i2c_realize_and_unref()
Extract i2c_try_create_slave() and i2c_realize_and_unref() from i2c_create_slave().
We can now set properties on a I2CSlave before it is realized.
This is in line with the recent qdev/QOM changes merged in commit 6675a653d2e.
---
Cc: Markus Armbruster <[email protected]>
--- include/hw/i2c/i2c.h | 2 ++ hw/i2c/core.c | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-)
include/hw/i2c/i2c.h +2 -0
@@ -80,6 +80,8 @@ int i2c_send(I2CBus *bus, uint8_t data);uint8_t i2c_recv (I2CBus *bus);DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr); +DeviceState *i2c_try_create_slave (const char *name,uint8_t addr); +bool i2c_realize_and_unref (DeviceState *dev,I2CBus *bus,Error **errp);/* lm832x.c */ void lm832x_key_event (DeviceState *dev,int key,int state);
hw/i2c/core.c +16 -2
@@ -267,13 +267,27 @@ const VMStateDescription vmstate_i2c_slave = { } }; -DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr) +DeviceState *i2c_try_create_slave (const char *name,uint8_t addr) {DeviceState *dev; dev =qdev_new (name);qdev_prop_set_uint8 (dev,"address" , addr); -qdev_realize_and_unref (dev, &bus->qbus, &error_fatal); +return dev; +} + +bool i2c_realize_and_unref (DeviceState *dev,I2CBus *bus,Error **errp) +{ +return qdev_realize_and_unref (dev, &bus->qbus, errp); +} + +DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr) +{ +DeviceState *dev; + + dev =i2c_try_create_slave (name, addr); +i2c_realize_and_unref (dev, bus, &error_fatal); +return dev; }
Signature · 1 line
2.21.3
Re: [PATCH v6 1/9] hw/i2c/core: Add i2c_try_create_slave() and i2c_realize_and_unref()
Quoted 9 lines · Philippe Mathieu-Daudé
Extract
i2c_try_create_slave()andi2c_realize_and_unref()fromi2c_create_slave().
We can now set properties on a I2CSlave before it is realized.This is in line with the recent qdev/QOM changes merged in commit
6675a653d2e.Reviewed-by Corey Minyard <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>
Collecting Markus review on v5:
https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg07060.html
Quoted 56 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Cc: Markus Armbruster <[email protected]>--- include/hw/i2c/i2c.h | 2 ++ hw/i2c/core.c | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-)include/hw/i2c/i2c.h +2
-0@@ -80,6 +80,8 @@ int i2c_send(I2CBus *bus, uint8_t data);uint8_t i2c_recv (I2CBus *bus);DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr); +DeviceState *i2c_try_create_slave (const char *name,uint8_t addr); +bool i2c_realize_and_unref (DeviceState *dev,I2CBus *bus,Error **errp);/* lm832x.c */ void lm832x_key_event (DeviceState *dev,int key,int state);hw/i2c/core.c +16
-2@@ -267,13 +267,27 @@ const VMStateDescription vmstate_i2c_slave = { } }; -DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr) +DeviceState *i2c_try_create_slave (const char *name,uint8_t addr) {DeviceState *dev; dev =qdev_new (name);qdev_prop_set_uint8 (dev,"address" , addr); -qdev_realize_and_unref (dev, &bus->qbus, &error_fatal); +return dev; +} + +bool i2c_realize_and_unref (DeviceState *dev,I2CBus *bus,Error **errp) +{ +return qdev_realize_and_unref (dev, &bus->qbus, errp); +} + +DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr) +{ +DeviceState *dev; + + dev =i2c_try_create_slave (name, addr); +i2c_realize_and_unref (dev, bus, &error_fatal); +return dev; }
Re: [PATCH v6 1/9] hw/i2c/core: Add i2c_try_create_slave() and i2c_realize_and_unref()
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
Extract
i2c_try_create_slave()andi2c_realize_and_unref()fromi2c_create_slave().
We can now set properties on a I2CSlave before it is realized.This is in line with the recent qdev/QOM changes merged in commit
6675a653d2e.Reviewed-by Corey Minyard <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Couple of things I belatedly noticed on this patch, which I don't think are important enough for me to drop it from my pullreq, but which I think it would be nice to address in a followup:
include/hw/i2c/i2c.h int i2c_send(I2CBus *bus, uint8_t data); · line 84
Quoted 10 lines
include/hw/i2c/i2c.h +2
-0@@ -80,6 +80,8 @@ int i2c_send(I2CBus *bus, uint8_t data);uint8_t i2c_recv (I2CBus *bus);DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr); +DeviceState *i2c_try_create_slave (const char *name,uint8_t addr); +bool i2c_realize_and_unref (DeviceState *dev,I2CBus *bus,Error **errp);
Can we have doc-comments for new global-scope functions, please ?
Quoted 19 lines
hw/i2c/core.c +6
-2@@ -267,13 +267,27 @@ const VMStateDescription vmstate_i2c_slave = { } }; -DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr) +DeviceState *i2c_try_create_slave (const char *name,uint8_t addr) {DeviceState *dev; dev =qdev_new (name);qdev_prop_set_uint8 (dev,"address" , addr); -qdev_realize_and_unref (dev, &bus->qbus, &error_fatal); +return dev; +} + +bool i2c_realize_and_unref (DeviceState *dev,I2CBus *bus,Error **errp) +{
hw/i2c/core.c const VMStateDescription vmstate_i2c_slave = { · line 290
Quoted 10 lines
hw/i2c/core.c +10
-0+return qdev_realize_and_unref (dev, &bus->qbus, errp); +} + +DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr) +{ +DeviceState *dev; + + dev =i2c_try_create_slave (name, addr); +i2c_realize_and_unref (dev, bus, &error_fatal); +
We now have a _try_ function which isn't "same behaviour as the non-try function, but give me back an error status rather than just killing QEMU". That seems confusing -- is there a better name we can use ?
thanks
-- PMM
Re: [PATCH v6 1/9] hw/i2c/core: Add i2c_try_create_slave() and i2c_realize_and_unref()
Quoted 23 lines · Peter Maydell
Quoted 10 lines · Philippe Mathieu-Daudé
Extract
i2c_try_create_slave()andi2c_realize_and_unref()fromi2c_create_slave().
We can now set properties on a I2CSlave before it is realized.This is in line with the recent qdev/QOM changes merged in commit
6675a653d2e.Reviewed-by Corey Minyard <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Couple of things I belatedly noticed on this patch, which I don't think are important enough for me to drop it from my pullreq, but which I think it would be nice to address in a followup:
Quoted 7 lines
include/hw/i2c/i2c.h +0
-0@@ -80,6 +80,8 @@ int i2c_send(I2CBus *bus, uint8_t data);uint8_t i2c_recv (I2CBus *bus);
Quoted 5 lines
include/hw/i2c/i2c.h int i2c_send(I2CBus *bus, uint8_t data); · line 84
Quoted 3 lines
include/hw/i2c/i2c.h +2
-0DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr); +DeviceState *i2c_try_create_slave (const char *name,uint8_t addr); +bool i2c_realize_and_unref (DeviceState *dev,I2CBus *bus,Error **errp);Can we have doc-comments for new global-scope functions, please ?
Sure.
Quoted 27 lines
Quoted 27 lines
hw/i2c/core.c +13
-2@@ -267,13 +267,27 @@ const VMStateDescription vmstate_i2c_slave = { } }; -DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr) +DeviceState *i2c_try_create_slave (const char *name,uint8_t addr) {DeviceState *dev; dev =qdev_new (name);qdev_prop_set_uint8 (dev,"address" , addr); -qdev_realize_and_unref (dev, &bus->qbus, &error_fatal); +return dev; +} + +bool i2c_realize_and_unref (DeviceState *dev,I2CBus *bus,Error **errp) +{ +return qdev_realize_and_unref (dev, &bus->qbus, errp); +} + +DeviceState *i2c_create_slave (I2CBus *bus,const char *name,uint8_t addr) +{ +DeviceState *dev; +
Quoted 8 lines
hw/i2c/core.c const VMStateDescription vmstate_i2c_slave = { · line 290
Quoted 3 lines
hw/i2c/core.c +3
-0+ dev =i2c_try_create_slave (name, addr); +i2c_realize_and_unref (dev, bus, &error_fatal); +We now have a _try_ function which isn't "same behaviour as the non-try function, but give me back an error status rather than just killing QEMU". That seems confusing -- is there a better name we can use ?
Yes, Markus asked me to change that, but as it could be done on top, he didn't block the series.
I'll address that next week.
Quoted 2 lines
thanks
-- PMM
PATCH v6 2/9 hw/misc/pca9552: Rename 'nr_leds' as 'pin_count'
In reply to Philippe Mathieu-DaudéThe PCA9552 device does not expose LEDs, but simple pins to connnect LEDs to. To be clearer with the device model, rename 'nr_leds' as 'pin_count'.
--- include/hw/misc/pca9552.h | 2 +- hw/misc/pca9552.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
include/hw/misc/pca9552.h +1 -1
@@ -26,7 +26,7 @@ typedef struct PCA9552State {uint8_t regs[PCA9552_NR_REGS ];uint8_t max_reg; - uint8_t nr_leds; + uint8_t pin_count; } PCA9552State;#endif
hw/misc/pca9552.c +5 -5
@@ -37,7 +37,7 @@ static void pca9552_update_pin_input(PCA9552State *s) {int i; -for (i =0 ; i < s->nr_leds; i++) { +for (i =0 ; i < s->pin_count; i++) {uint8_t input_reg =PCA9552_INPUT0 + (i /8 );uint8_t input_shift = (i %8 );uint8_t config =pca9552_pin_get_config (s, i);
@@ -185,7 +185,7 @@ static void pca9552_get_led(Object *obj, Visitor *v, const char *name,error_setg (errp,"%s: error reading %s" , __func__, name);return ; } -if (led <0 || led > s->nr_leds) { +if (led <0 || led > s->pin_count) {error_setg (errp,"%s invalid led %s" , __func__, name);return ; }
@@ -228,7 +228,7 @@ static void pca9552_set_led(Object *obj, Visitor *v, const char *name,error_setg (errp,"%s: error reading %s" , __func__, name);return ; } -if (led <0 || led > s->nr_leds) { +if (led <0 || led > s->pin_count) {error_setg (errp,"%s invalid led %s" , __func__, name);return ; }
@@ -291,9 +291,9 @@ static void pca9552_initfn(Object *obj)* PCA955X device */ s->max_reg =PCA9552_LS3 ; - s->nr_leds =16 ; + s->pin_count =16 ; -for (led =0 ; led < s->nr_leds; led++) { +for (led =0 ; led < s->pin_count; led++) {char *name; name =g_strdup_printf ("led%d" , led);
Signature · 1 line
2.21.3
PATCH v6 3/9 hw/misc/pca9552: Rename generic code as pca955x
In reply to Philippe Mathieu-DaudéVarious code from the PCA9552 device model is generic to the PCA955X family. We'll split the generic code in a base class in the next commit. To ease review, first do a dumb renaming.
--- include/hw/misc/pca9552.h | 10 ++--- hw/misc/pca9552.c | 80 +++++++++++++++++++-------------------- 2 files changed, 45 insertions(+), 45 deletions(-)
include/hw/misc/pca9552.h +5 -5
@@ -12,11 +12,11 @@#include "hw/i2c/i2c.h" #define TYPE_PCA9552 "pca9552" -#define PCA9552 (obj) OBJECT_CHECK(PCA9552State, (obj), TYPE_PCA9552) +#define PCA955X (obj) OBJECT_CHECK(PCA955xState, (obj), TYPE_PCA9552) -#define PCA9552_NR_REGS 10 +#define PCA955X_NR_REGS 10 -typedef struct PCA9552State { +typedef struct PCA955xState { /*< private >*/ I2CSlave i2c; /*< public >*/
@@ -24,9 +24,9 @@ typedef struct PCA9552State {uint8_t len;uint8_t pointer; -uint8_t regs[PCA9552_NR_REGS ]; +uint8_t regs[PCA955X_NR_REGS ];uint8_t max_reg; uint8_t pin_count; -} PCA9552State; +} PCA955xState;#endif
hw/misc/pca9552.c +40 -40
229 lines not on this page · raw message
Signature · 1 line
2.21.3
PATCH v6 4/9 hw/misc/pca9552: Add generic PCA955xClass, parent of TYPE_PCA9552
In reply to Philippe Mathieu-DaudéExtract the code common to the PCA955x family in PCA955xClass, keeping the PCA9552 specific parts into pca9552_class_init(). Remove the 'TODO' comment added in commit 5141d4158cf.
--- include/hw/misc/pca9552.h | 6 ++-- hw/misc/pca9552.c | 66 ++++++++++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 21 deletions(-)
include/hw/misc/pca9552.h +3 -3
@@ -12,9 +12,11 @@#include "hw/i2c/i2c.h" #define TYPE_PCA9552 "pca9552" -#define PCA955X (obj) OBJECT_CHECK(PCA955xState, (obj), TYPE_PCA9552) +#define TYPE_PCA955X "pca955x" +#define PCA955X (obj) OBJECT_CHECK(PCA955xState, (obj), TYPE_PCA955X)#define PCA955X_NR_REGS 10 +#define PCA955X_PIN_COUNT_MAX 16 typedef struct PCA955xState { /*< private >*/
@@ -25,8 +27,6 @@ typedef struct PCA955xState {uint8_t pointer; uint8_t regs[PCA955X_NR_REGS]; -uint8_t max_reg; - uint8_t pin_count; } PCA955xState;#endif
hw/misc/pca9552.c +48 -18
150 lines not on this page · raw message
Signature · 1 line
2.21.3
PATCH v6 5/9 hw/misc/pca9552: Add a 'description' property for debugging purpose
In reply to Philippe Mathieu-DaudéAdd a description field to distinguish between multiple devices.
--- include/hw/misc/pca9552.h | 1 + hw/misc/pca9552.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+)
include/hw/misc/pca9552.h +1 -0
@@ -27,6 +27,7 @@ typedef struct PCA955xState {uint8_t pointer;uint8_t regs[PCA955X_NR_REGS ]; + char *description; /* For debugging purpose only */ } PCA955xState;#endif
hw/misc/pca9552.c +18 -0
@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/module.h" +#include "hw/qdev-properties.h" #include "hw/misc/pca9552.h" #include "hw/misc/pca9552_regs.h" #include "migration/vmstate.h"
@@ -317,13 +318,30 @@ static void pca955x_initfn(Object *obj) } } +static void pca955x_realize (DeviceState *dev,Error **errp) +{ +PCA955xState *s =PCA955X (dev); + +if (!s->description) { + s->description =g_strdup ("pca-unspecified" ); + } +} + +static Property pca955x_properties[] = { +DEFINE_PROP_STRING ("description" , PCA955xState, description), +DEFINE_PROP_END_OF_LIST (), +}; +static void pca955x_class_init (ObjectClass *klass,void *data) { +DeviceClass *dc =DEVICE_CLASS (klass);I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); k->event = pca955x_event; k->recv = pca955x_recv; k->send = pca955x_send; + dc->realize = pca955x_realize; +device_class_set_props (dc, pca955x_properties); }static const TypeInfo pca955x_info = {
Signature · 1 line
2.21.3
PATCH v6 6/9 hw/misc/pca9552: Trace GPIO High/Low events
In reply to Philippe Mathieu-DaudéAdd a trivial representation of the PCA9552 GPIOs.
Example booting obmc-phosphor-image:
$ qemu-system-arm -M witherspoon-bmc -trace pca955x_gpio_status 1592689902.327837:pca955x_gpio_status pca-unspecified GPIOs 0-15 [*...............] 1592689902.329934:pca955x_gpio_status pca-unspecified GPIOs 0-15 [**..............] 1592689902.330717:pca955x_gpio_status pca-unspecified GPIOs 0-15 [***.............] 1592689902.331431:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****............] 1592689902.332163:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*..] 1592689902.332888:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........**.] 1592689902.333629:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........***] 1592690032.793289:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*.*] 1592690033.303163:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........***] 1592690033.812962:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*.*] 1592690034.323234:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........***] 1592690034.832922:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*.*]
We notice the GPIO #14 (front-power LED) starts to blink.
This LED is described in the witherspoon device-tree [*]:
front-power {
retain-state-shutdown;
default-state = "keep";
gpios = <&pca0 14 GPIO_ACTIVE_LOW>;
};--- hw/misc/pca9552.c | 39 +++++++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 3 +++ 2 files changed, 42 insertions(+)
hw/misc/pca9552.c +39 -0
@@ -13,12 +13,14 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/module.h" +#include "qemu/bitops.h" #include "hw/qdev-properties.h" #include "hw/misc/pca9552.h" #include "hw/misc/pca9552_regs.h" #include "migration/vmstate.h" #include "qapi/error.h" #include "qapi/visitor.h" +#include "trace.h" typedef struct PCA955xClass { /*< private >*/
@@ -49,6 +51,39 @@ static uint8_t pca955x_pin_get_config(PCA955xState *s, int pin)return extract32 (s->regs[reg], shift,2 ); } +/* Return INPUT status (bit #N belongs to GPIO #N) */ +static uint16_t pca955x_pins_get_status (PCA955xState *s) +{ +return (s->regs[PCA9552_INPUT1 ] <<8 ) | s->regs[PCA9552_INPUT0 ]; +} + +static void pca955x_display_pins_status (PCA955xState *s, +uint16_t previous_pins_status) +{ +PCA955xClass *k =PCA955X_GET_CLASS (s); +uint16_t pins_status, pins_changed; +int i; + + pins_status =pca955x_pins_get_status (s); + pins_changed = previous_pins_status ^ pins_status; +if (!pins_changed) { +return ; + } +if (trace_event_get_state_backends (TRACE_PCA955X_GPIO_STATUS )) { +char *buf =g_newa (char, k->pin_count +1 ); + +for (i =0 ; i < k->pin_count; i++) { +if (extract32 (pins_status, i,1 )) { + buf[i] ='*' ; + }else { + buf[i] ='.' ; + } + } + buf[i] ='\0' ; +trace_pca955x_gpio_status (s->description, buf); + } +} +static void pca955x_update_pin_input (PCA955xState *s) {PCA955xClass *k =PCA955X_GET_CLASS (s);
@@ -98,6 +133,8 @@ static uint8_t pca955x_read(PCA955xState *s, uint8_t reg)static void pca955x_write (PCA955xState *s,uint8_t reg,uint8_t data) { +uint16_t pins_status; +switch (reg) {case PCA9552_PSC0 :case PCA9552_PWM0 :
@@ -110,8 +147,10 @@ static void pca955x_write(PCA955xState *s, uint8_t reg, uint8_t data)case PCA9552_LS1 :case PCA9552_LS2 :case PCA9552_LS3 : + pins_status =pca955x_pins_get_status (s); s->regs[reg] = data;pca955x_update_pin_input (s); +pca955x_display_pins_status (s, pins_status);break ;case PCA9552_INPUT0 :
hw/misc/trace-events +3 -0
@@ -206,3 +206,6 @@ via1_rtc_cmd_pram_sect_write(int sector, int offset, int addr, int value) "secto # grlib_ahb_apb_pnp.c 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" + +# pca9552.c +pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]"
Signature · 1 line
2.21.3
PATCH v6 7/9 hw/arm/aspeed: Describe each PCA9552 device
In reply to Philippe Mathieu-DaudéWe have 2 distinct PCA9552 devices. Set their description to distinguish them when looking at the trace events.
Description name taken from:
https://github.com/open-power/witherspoon-xml/blob/master/witherspoon.xml
---
Cc: Markus Armbruster <[email protected]>
Cc: Corey Minyard <[email protected]>
--- hw/arm/aspeed.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
hw/arm/aspeed.c +9 -4
@@ -508,12 +508,15 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc) {AspeedSoCState *soc = &bmc->soc;uint8_t *eeprom_buf =g_malloc0 (8 *1024 ); +DeviceState *dev;/* Bus 3: TODO bmp280@77 */ /* Bus 3: TODO max31785@52 */ /* Bus 3: TODO dps310@76 */ -i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),3 ),TYPE_PCA9552 , -0x60 ); + dev =i2c_try_create_slave (TYPE_PCA9552 ,0x60 ); +qdev_prop_set_string (dev,"description" ,"pca1" ); +i2c_realize_and_unref (dev,aspeed_i2c_get_bus (DEVICE (&soc->i2c),3 ), + &error_fatal);i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),4 ),"tmp423" ,0x4c );i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),5 ),"tmp423" ,0x4c );
@@ -528,8 +531,10 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc)smbus_eeprom_init_one (aspeed_i2c_get_bus (DEVICE (&soc->i2c),11 ),0x51 , eeprom_buf); -i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),11 ),TYPE_PCA9552 , -0x60 ); + dev =i2c_try_create_slave (TYPE_PCA9552 ,0x60 ); +qdev_prop_set_string (dev,"description" ,"pca0" ); +i2c_realize_and_unref (dev,aspeed_i2c_get_bus (DEVICE (&soc->i2c),11 ), + &error_fatal);/* Bus 11: TODO ucd90160@64 */ }
Signature · 1 line
2.21.3
Re: [PATCH v6 7/9] hw/arm/aspeed: Describe each PCA9552 device
Quoted 8 lines · Philippe Mathieu-Daudé
We have 2 distinct PCA9552 devices. Set their description to distinguish them when looking at the trace events.
Description name taken from:
https://github.com/open-power/witherspoon-xml/blob/master/witherspoon.xmlReviewed-by Cédric Le Goater <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Collecting Markus review on v5:
https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg07078.html
Quoted 43 lines
---
Cc: Markus Armbruster <[email protected]>
Cc: Corey Minyard <[email protected]>--- hw/arm/aspeed.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)hw/arm/aspeed.c +9
-4@@ -508,12 +508,15 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc) {AspeedSoCState *soc = &bmc->soc;uint8_t *eeprom_buf =g_malloc0 (8 *1024 ); +DeviceState *dev;/* Bus 3: TODO bmp280@77 */ /* Bus 3: TODO max31785@52 */ /* Bus 3: TODO dps310@76 */ -i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),3 ),TYPE_PCA9552 , -0x60 ); + dev =i2c_try_create_slave (TYPE_PCA9552 ,0x60 ); +qdev_prop_set_string (dev,"description" ,"pca1" ); +i2c_realize_and_unref (dev,aspeed_i2c_get_bus (DEVICE (&soc->i2c),3 ), + &error_fatal);i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),4 ),"tmp423" ,0x4c );i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),5 ),"tmp423" ,0x4c );@@ -528,8 +531,10 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc)smbus_eeprom_init_one (aspeed_i2c_get_bus (DEVICE (&soc->i2c),11 ),0x51 , eeprom_buf); -i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),11 ),TYPE_PCA9552 , -0x60 ); + dev =i2c_try_create_slave (TYPE_PCA9552 ,0x60 ); +qdev_prop_set_string (dev,"description" ,"pca0" ); +i2c_realize_and_unref (dev,aspeed_i2c_get_bus (DEVICE (&soc->i2c),11 ), + &error_fatal);/* Bus 11: TODO ucd90160@64 */ }
Re: [PATCH v6 7/9] hw/arm/aspeed: Describe each PCA9552 device
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
We have 2 distinct PCA9552 devices. Set their description to distinguish them when looking at the trace events.
Description name taken from:
https://github.com/open-power/witherspoon-xml/blob/master/witherspoon.xml
I forgot to respond to this earlier.
Quoted 48 lines
Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Cc: Markus Armbruster <[email protected]>
Cc: Corey Minyard <[email protected]>--- hw/arm/aspeed.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)hw/arm/aspeed.c +9
-4@@ -508,12 +508,15 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc) {AspeedSoCState *soc = &bmc->soc;uint8_t *eeprom_buf =g_malloc0 (8 *1024 ); +DeviceState *dev;/* Bus 3: TODO bmp280@77 */ /* Bus 3: TODO max31785@52 */ /* Bus 3: TODO dps310@76 */ -i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),3 ),TYPE_PCA9552 , -0x60 ); + dev =i2c_try_create_slave (TYPE_PCA9552 ,0x60 ); +qdev_prop_set_string (dev,"description" ,"pca1" ); +i2c_realize_and_unref (dev,aspeed_i2c_get_bus (DEVICE (&soc->i2c),3 ), + &error_fatal);i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),4 ),"tmp423" ,0x4c );i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),5 ),"tmp423" ,0x4c );@@ -528,8 +531,10 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc)smbus_eeprom_init_one (aspeed_i2c_get_bus (DEVICE (&soc->i2c),11 ),0x51 , eeprom_buf); -i2c_create_slave (aspeed_i2c_get_bus (DEVICE (&soc->i2c),11 ),TYPE_PCA9552 , -0x60 ); + dev =i2c_try_create_slave (TYPE_PCA9552 ,0x60 ); +qdev_prop_set_string (dev,"description" ,"pca0" ); +i2c_realize_and_unref (dev,aspeed_i2c_get_bus (DEVICE (&soc->i2c),11 ), + &error_fatal);/* Bus 11: TODO ucd90160@64 */ }Signature · 1 line
2.21.3
PATCH v6 8/9 hw/misc/pca9552: Trace GPIO change events
In reply to Philippe Mathieu-DaudéEmit a trace event when a GPIO change its state.
Example booting obmc-phosphor-image:
$ qemu-system-arm -M witherspoon-bmc -trace pca955x_gpio_change 1592690552.687372:pca955x_gpio_change pca1 GPIO id:0 status: 0 -> 1 1592690552.690169:pca955x_gpio_change pca1 GPIO id:1 status: 0 -> 1 1592690552.691673:pca955x_gpio_change pca1 GPIO id:2 status: 0 -> 1 1592690552.696886:pca955x_gpio_change pca1 GPIO id:3 status: 0 -> 1 1592690552.698614:pca955x_gpio_change pca1 GPIO id:13 status: 0 -> 1 1592690552.699833:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1 1592690552.700842:pca955x_gpio_change pca1 GPIO id:15 status: 0 -> 1 1592690683.841921:pca955x_gpio_change pca1 GPIO id:14 status: 1 -> 0 1592690683.861660:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1 1592690684.371460:pca955x_gpio_change pca1 GPIO id:14 status: 1 -> 0 1592690684.882115:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1 1592690685.391411:pca955x_gpio_change pca1 GPIO id:14 status: 1 -> 0 1592690685.901391:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1 1592690686.411678:pca955x_gpio_change pca1 GPIO id:14 status: 1 -> 0 1592690686.921279:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1
We notice the GPIO #14 (front-power LED) starts to blink.
This LED is described in the witherspoon device-tree [*]:
front-power {
retain-state-shutdown;
default-state = "keep";
gpios = <&pca0 14 GPIO_ACTIVE_LOW>;
};--- hw/misc/pca9552.c | 15 +++++++++++++++ hw/misc/trace-events | 1 + 2 files changed, 16 insertions(+)
hw/misc/pca9552.c +15 -0
@@ -82,6 +82,21 @@ static void pca955x_display_pins_status(PCA955xState *s, buf[i] ='\0' ;trace_pca955x_gpio_status (s->description, buf); } +if (trace_event_get_state_backends (TRACE_PCA955X_GPIO_CHANGE )) { +for (i =0 ; i < k->pin_count; i++) { +if (extract32 (pins_changed, i,1 )) { +unsigned new_state =extract32 (pins_status, i,1 ); + +/* +* We display the state using the PCA logic ("active-high"). +* This is not the state of the LED, which signal might be +* wired "active-low" on the board. +*/ +trace_pca955x_gpio_change (s->description, i, + !new_state, new_state); + } + } + } }static void pca955x_update_pin_input (PCA955xState *s)
hw/misc/trace-events +1 -0
@@ -209,3 +209,4 @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6 # 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.21.3
PATCH v6 9/9 hw/misc/pca9552: Model qdev output GPIOs
In reply to Philippe Mathieu-DaudéThe PCA9552 has 16 GPIOs which can be used as input, output or PWM mode. QEMU models the output GPIO with the qemu_irq type. Let the device expose the 16 GPIOs to allow us to later connect LEDs to these outputs.
--- include/hw/misc/pca9552.h | 1 + hw/misc/pca9552.c | 6 ++++++ 2 files changed, 7 insertions(+)
include/hw/misc/pca9552.h +1 -0
@@ -27,6 +27,7 @@ typedef struct PCA955xState {uint8_t pointer;uint8_t regs[PCA955X_NR_REGS ]; +qemu_irq gpio[PCA955X_PIN_COUNT_MAX ];char *description;/* For debugging purpose only */ } PCA955xState;
hw/misc/pca9552.c +6 -0
@@ -17,6 +17,7 @@#include "hw/qdev-properties.h" #include "hw/misc/pca9552.h" #include "hw/misc/pca9552_regs.h" +#include "hw/irq.h" #include "migration/vmstate.h" #include "qapi/error.h" #include "qapi/visitor.h"
@@ -111,9 +112,11 @@ static void pca955x_update_pin_input(PCA955xState *s)switch (config) {case PCA9552_LED_ON : +qemu_set_irq (s->gpio[i],1 ); s->regs[input_reg] |=1 << input_shift;break ;case PCA9552_LED_OFF : +qemu_set_irq (s->gpio[i],0 ); s->regs[input_reg] &= ~(1 << input_shift);break ;case PCA9552_LED_PWM0 :
@@ -374,11 +377,14 @@ static void pca955x_initfn(Object *obj)static void pca955x_realize (DeviceState *dev,Error **errp) { +PCA955xClass *k =PCA955X_GET_CLASS (dev);PCA955xState *s =PCA955X (dev);if (!s->description) { s->description =g_strdup ("pca-unspecified" ); } + +qdev_init_gpio_out (dev, s->gpio, k->pin_count); }static Property pca955x_properties[] = {
Signature · 1 line
2.21.3
Quoted 6 lines · Philippe Mathieu-Daudé
This series add trace events to better display GPIO changes. We'll continue in the following series by connecting LEDs to these GPIOs.
This helps me to work on a generic LED device, see:
https://www.mail-archive.com/[email protected]/msg711917.html
Thanks,
C.
Quoted 86 lines
Since v5, addressed Cédric review comment:
- Movepin_countcheck fromrealize()toinstance_init()Since v4: Addressed Cédric review comments
- Extract PCA955xClass
- Add/usepca955x_pins_get_status()method instead of keeping cached value in PCA955xStateExample when booting an obmc-phosphor-image, we can see the LED #14 (front-power LED) starting to blink.
- ASCII LED bar view:
$ qemu-system-arm -M witherspoon-bmc -trace pca955x_gpio_status 1592689902.327837:pca955x_gpio_status pca-unspecified GPIOs 0-15 [*...............] 1592689902.329934:pca955x_gpio_status pca-unspecified GPIOs 0-15 [**..............] 1592689902.330717:pca955x_gpio_status pca-unspecified GPIOs 0-15 [***.............] 1592689902.331431:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****............] 1592689902.332163:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*..] 1592689902.332888:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........**.] 1592689902.333629:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........***] 1592690032.793289:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*.*] 1592690033.303163:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........***] 1592690033.812962:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*.*] 1592690034.323234:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........***] 1592690034.832922:pca955x_gpio_status pca-unspecified GPIOs 0-15 [****.........*.*]- Only display GPIOs which status changes:
$ qemu-system-arm -M witherspoon-bmc -trace pca955x_gpio_change 1592690552.687372:pca955x_gpio_change pca1 GPIO id:0 status: 0 -> 1 1592690552.690169:pca955x_gpio_change pca1 GPIO id:1 status: 0 -> 1 1592690552.691673:pca955x_gpio_change pca1 GPIO id:2 status: 0 -> 1 1592690552.696886:pca955x_gpio_change pca1 GPIO id:3 status: 0 -> 1 1592690552.698614:pca955x_gpio_change pca1 GPIO id:13 status: 0 -> 1 1592690552.699833:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1 1592690552.700842:pca955x_gpio_change pca1 GPIO id:15 status: 0 -> 1 1592690683.841921:pca955x_gpio_change pca1 GPIO id:14 status: 1 -> 0 1592690683.861660:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1 1592690684.371460:pca955x_gpio_change pca1 GPIO id:14 status: 1 -> 0 1592690684.882115:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1 1592690685.391411:pca955x_gpio_change pca1 GPIO id:14 status: 1 -> 0 1592690685.901391:pca955x_gpio_change pca1 GPIO id:14 status: 0 -> 1For information about how to test the obmc-phosphor-image, see:
https://www.mail-archive.com/[email protected]/msg712911.html$ git backport-diff -u v5 Key: [----] : patches are identical [####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively001/9:[----] [--] 'hw/i2c/core: Add
i2c_try_create_slave()andi2c_realize_and_unref()' 002/9:[----] [--] 'hw/misc/pca9552: Rename 'nr_leds' as 'pin_count'' 003/9:[----] [--] 'hw/misc/pca9552: Rename generic code as pca955x' 004/9:[0010] [FC] 'hw/misc/pca9552: Add generic PCA955xClass, parent ofTYPE_PCA9552' 005/9:[0007] [FC] 'hw/misc/pca9552: Add a 'description' property for debugging purpose' 006/9:[----] [--] 'hw/misc/pca9552: Trace GPIO High/Low events' 007/9:[----] [-C] 'hw/arm/aspeed: Describe each PCA9552 device' 008/9:[----] [--] 'hw/misc/pca9552: Trace GPIO change events' 009/9:[0003] [FC] 'hw/misc/pca9552: Model qdev output GPIOs'Based-on: <[email protected]>
Philippe Mathieu-Daudé (9):
hw/i2c/core: Addi2c_try_create_slave()andi2c_realize_and_unref()hw/misc/pca9552: Rename 'nr_leds' as 'pin_count' hw/misc/pca9552: Rename generic code as pca955x hw/misc/pca9552: Add generic PCA955xClass, parent ofTYPE_PCA9552hw/misc/pca9552: Add a 'description' property for debugging purpose hw/misc/pca9552: Trace GPIO High/Low events hw/arm/aspeed: Describe each PCA9552 device hw/misc/pca9552: Trace GPIO change events hw/misc/pca9552: Model qdev output GPIOsinclude/hw/i2c/i2c.h | 2 + include/hw/misc/pca9552.h | 16 +-- hw/arm/aspeed.c | 13 ++- hw/i2c/core.c | 18 +++- hw/misc/pca9552.c | 216 ++++++++++++++++++++++++++++---------- hw/misc/trace-events | 4 + 6 files changed, 202 insertions(+), 67 deletions(-)
Quoted 10 lines · Cédric Le Goater
Quoted 6 lines · Philippe Mathieu-Daudé
This series add trace events to better display GPIO changes. We'll continue in the following series by connecting LEDs to these GPIOs.
This helps me to work on a generic LED device, see:
https://www.mail-archive.com/[email protected]/msg711917.htmlTested-by Cédric Le Goater <[email protected]>
Thanks :)
Note to the maintainer, this series is now fully reviewed/tested.
Quoted 21 lines
Quoted 21 lines
Based-on: <[email protected]>
Philippe Mathieu-Daudé (9):
hw/i2c/core: Addi2c_try_create_slave()andi2c_realize_and_unref()hw/misc/pca9552: Rename 'nr_leds' as 'pin_count' hw/misc/pca9552: Rename generic code as pca955x hw/misc/pca9552: Add generic PCA955xClass, parent ofTYPE_PCA9552hw/misc/pca9552: Add a 'description' property for debugging purpose hw/misc/pca9552: Trace GPIO High/Low events hw/arm/aspeed: Describe each PCA9552 device hw/misc/pca9552: Trace GPIO change events hw/misc/pca9552: Model qdev output GPIOsinclude/hw/i2c/i2c.h | 2 + include/hw/misc/pca9552.h | 16 +-- hw/arm/aspeed.c | 13 ++- hw/i2c/core.c | 18 +++- hw/misc/pca9552.c | 216 ++++++++++++++++++++++++++++---------- hw/misc/trace-events | 4 + 6 files changed, 202 insertions(+), 67 deletions(-)
Peter Maydell
AppliedQuoted 11 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Cédric Le Goater
Quoted 6 lines · Philippe Mathieu-Daudé
This series add trace events to better display GPIO changes. We'll continue in the following series by connecting LEDs to these GPIOs.
This helps me to work on a generic LED device, see:
https://www.mail-archive.com/[email protected]/msg711917.html
Quoted 5 lines
Quoted 1 line
Tested-by Cédric Le Goater <[email protected]>Thanks :)
Note to the maintainer, this series is now fully reviewed/tested.
Applied to target-arm.next, thanks.
-- PMM