Emit a trace event when a GPIO change its state.
Example booting obmc-phosphor-image:
$ qemu-system-arm -M witherspoon-bmc -trace pca9552_gpio_change
1592690552.687372:pca9552_gpio_change pca1 GPIO id:0 status: 0 -> 1
1592690552.690169:pca9552_gpio_change pca1 GPIO id:1 status: 0 -> 1
1592690552.691673:pca9552_gpio_change pca1 GPIO id:2 status: 0 -> 1
1592690552.696886:pca9552_gpio_change pca1 GPIO id:3 status: 0 -> 1
1592690552.698614:pca9552_gpio_change pca1 GPIO id:13 status: 0 -> 1
1592690552.699833:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
1592690552.700842:pca9552_gpio_change pca1 GPIO id:15 status: 0 -> 1
1592690683.841921:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
1592690683.861660:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
1592690684.371460:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
1592690684.882115:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
1592690685.391411:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
1592690685.901391:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
1592690686.411678:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
1592690686.921279:pca9552_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>;
};
[*] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts?id=b1f9be9392f0#n140
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/misc/pca9552.c | 15 +++++++++++++++
hw/misc/trace-events | 1 +
2 files changed, 16 insertions(+)
diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c
index f0d435e310..85557b78d9 100644
--- a/hw/misc/pca9552.c
+++ b/hw/misc/pca9552.c
@@ -60,6 +60,21 @@ static void pca9552_display_pins_status(PCA9552State *s)
buf[i] = '\0';
trace_pca9552_gpio_status(s->description, buf);
}
+ if (trace_event_get_state_backends(TRACE_PCA9552_GPIO_CHANGE)) {
+ for (i = 0; i < s->nr_leds; 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_pca9552_gpio_change(s->description, i,
+ !new_state, new_state);
+ }
+ }
+ }
}
static void pca9552_update_pin_input(PCA9552State *s)
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
index 7630e59652..805d2110e0 100644
--- a/hw/misc/trace-events
+++ b/hw/misc/trace-events
@@ -209,3 +209,4 @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6
# pca9552.c
pca9552_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]"
+pca9552_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u"
--
2.21.3
On 6/21/20 12:58 AM, Philippe Mathieu-Daudé wrote:
> Emit a trace event when a GPIO change its state.
I understand now why you need 'pin_status'.
We could compute 'pin_status' and 'pin_changed' in routine
pca9552_update_pin_input() when updating the PCA9552_INPUT0/1
register values and pass them to pca9552_display_pins_status()
or something like that.
Maybe add two different display routines also.
>
> Example booting obmc-phosphor-image:
>
> $ qemu-system-arm -M witherspoon-bmc -trace pca9552_gpio_change
> 1592690552.687372:pca9552_gpio_change pca1 GPIO id:0 status: 0 -> 1
> 1592690552.690169:pca9552_gpio_change pca1 GPIO id:1 status: 0 -> 1
> 1592690552.691673:pca9552_gpio_change pca1 GPIO id:2 status: 0 -> 1
> 1592690552.696886:pca9552_gpio_change pca1 GPIO id:3 status: 0 -> 1
> 1592690552.698614:pca9552_gpio_change pca1 GPIO id:13 status: 0 -> 1
> 1592690552.699833:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
> 1592690552.700842:pca9552_gpio_change pca1 GPIO id:15 status: 0 -> 1
> 1592690683.841921:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
> 1592690683.861660:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
> 1592690684.371460:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
> 1592690684.882115:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
> 1592690685.391411:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
> 1592690685.901391:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
> 1592690686.411678:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
> 1592690686.921279:pca9552_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>;
> };
>
> [*] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts?id=b1f9be9392f0#n140
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> hw/misc/pca9552.c | 15 +++++++++++++++
> hw/misc/trace-events | 1 +
> 2 files changed, 16 insertions(+)
>
> diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c
> index f0d435e310..85557b78d9 100644
> --- a/hw/misc/pca9552.c
> +++ b/hw/misc/pca9552.c
> @@ -60,6 +60,21 @@ static void pca9552_display_pins_status(PCA9552State *s)
> buf[i] = '\0';
> trace_pca9552_gpio_status(s->description, buf);
> }
> + if (trace_event_get_state_backends(TRACE_PCA9552_GPIO_CHANGE)) {
> + for (i = 0; i < s->nr_leds; 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_pca9552_gpio_change(s->description, i,
> + !new_state, new_state);
> + }
> + }
> + }
> }
>
> static void pca9552_update_pin_input(PCA9552State *s)
> diff --git a/hw/misc/trace-events b/hw/misc/trace-events
> index 7630e59652..805d2110e0 100644
> --- a/hw/misc/trace-events
> +++ b/hw/misc/trace-events
> @@ -209,3 +209,4 @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6
>
> # pca9552.c
> pca9552_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]"
> +pca9552_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u"
>
On 6/22/20 9:01 AM, Cédric Le Goater wrote:
> On 6/21/20 12:58 AM, Philippe Mathieu-Daudé wrote:
>> Emit a trace event when a GPIO change its state.
>
> I understand now why you need 'pin_status'.
>
> We could compute 'pin_status' and 'pin_changed' in routine
> pca9552_update_pin_input() when updating the PCA9552_INPUT0/1
> register values and pass them to pca9552_display_pins_status()
> or something like that.
Good idea, thanks!
>
> Maybe add two different display routines also.
>
>>
>> Example booting obmc-phosphor-image:
>>
>> $ qemu-system-arm -M witherspoon-bmc -trace pca9552_gpio_change
>> 1592690552.687372:pca9552_gpio_change pca1 GPIO id:0 status: 0 -> 1
>> 1592690552.690169:pca9552_gpio_change pca1 GPIO id:1 status: 0 -> 1
>> 1592690552.691673:pca9552_gpio_change pca1 GPIO id:2 status: 0 -> 1
>> 1592690552.696886:pca9552_gpio_change pca1 GPIO id:3 status: 0 -> 1
>> 1592690552.698614:pca9552_gpio_change pca1 GPIO id:13 status: 0 -> 1
>> 1592690552.699833:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
>> 1592690552.700842:pca9552_gpio_change pca1 GPIO id:15 status: 0 -> 1
>> 1592690683.841921:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
>> 1592690683.861660:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
>> 1592690684.371460:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
>> 1592690684.882115:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
>> 1592690685.391411:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
>> 1592690685.901391:pca9552_gpio_change pca1 GPIO id:14 status: 0 -> 1
>> 1592690686.411678:pca9552_gpio_change pca1 GPIO id:14 status: 1 -> 0
>> 1592690686.921279:pca9552_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>;
>> };
>>
>> [*] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts?id=b1f9be9392f0#n140
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> hw/misc/pca9552.c | 15 +++++++++++++++
>> hw/misc/trace-events | 1 +
>> 2 files changed, 16 insertions(+)
>>
>> diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c
>> index f0d435e310..85557b78d9 100644
>> --- a/hw/misc/pca9552.c
>> +++ b/hw/misc/pca9552.c
>> @@ -60,6 +60,21 @@ static void pca9552_display_pins_status(PCA9552State *s)
>> buf[i] = '\0';
>> trace_pca9552_gpio_status(s->description, buf);
>> }
>> + if (trace_event_get_state_backends(TRACE_PCA9552_GPIO_CHANGE)) {
>> + for (i = 0; i < s->nr_leds; 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_pca9552_gpio_change(s->description, i,
>> + !new_state, new_state);
>> + }
>> + }
>> + }
>> }
>>
>> static void pca9552_update_pin_input(PCA9552State *s)
>> diff --git a/hw/misc/trace-events b/hw/misc/trace-events
>> index 7630e59652..805d2110e0 100644
>> --- a/hw/misc/trace-events
>> +++ b/hw/misc/trace-events
>> @@ -209,3 +209,4 @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6
>>
>> # pca9552.c
>> pca9552_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]"
>> +pca9552_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u"
>>
>
>
© 2016 - 2026 Red Hat, Inc.