diff mbox series

[v2] hw/misc/pca9552: Trace LED On/Off events

Message ID 20200617064734.26956-1-f4bug@amsat.org
State New
Headers show
Series [v2] hw/misc/pca9552: Trace LED On/Off events | expand

Commit Message

Philippe Mathieu-Daudé June 17, 2020, 6:47 a.m. UTC
Example booting obmc-phosphor-image:

  $ qemu-system-arm -M witherspoon-bmc -trace pca\*
  26033@1592376001.873828:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  26033@1592376001.874169:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  26033@1592376001.874348:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  26033@1592376001.874514:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  26033@1592376001.879601:pca9552_led_state 0x5594a9f57560 LEDs [........ .......*]
  26033@1592376001.880507:pca9552_led_state 0x5594a9f57560 LEDs [........ ......**]
  26033@1592376001.880885:pca9552_led_state 0x5594a9f57560 LEDs [........ .....***]
  26033@1592376001.881228:pca9552_led_state 0x5594a9f57560 LEDs [........ ....****]
  26033@1592376001.881601:pca9552_led_state 0x5594a9f57560 LEDs [..*..... ....****]
  26033@1592376001.881952:pca9552_led_state 0x5594a9f57560 LEDs [.**..... ....****]
  26033@1592376001.882299:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
  26033@1592376065.090910:pca9552_led_state 0x5594a9f57560 LEDs [*.*..... ....****]
  26033@1592376065.600649:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
  26033@1592376066.110565:pca9552_led_state 0x5594a9f57560 LEDs [*.*..... ....****]
  26033@1592376066.620390:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]

Suggested-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/misc/pca9552.c    | 18 ++++++++++++++++++
 hw/misc/trace-events |  3 +++
 2 files changed, 21 insertions(+)
diff mbox series

Patch

diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c
index cac729e35a..693f6c3b24 100644
--- a/hw/misc/pca9552.c
+++ b/hw/misc/pca9552.c
@@ -17,6 +17,7 @@ 
 #include "migration/vmstate.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
+#include "trace.h"
 
 #define PCA9552_LED_ON   0x0
 #define PCA9552_LED_OFF  0x1
@@ -95,6 +96,23 @@  static void pca9552_write(PCA9552State *s, uint8_t reg, uint8_t data)
     case PCA9552_LS3:
         s->regs[reg] = data;
         pca9552_update_pin_input(s);
+        if (trace_event_get_state_backends(TRACE_PCA9552_LED_STATE)) {
+            char buf[2][9];
+
+            for (int i = 0; i < 2; i++) {
+                uint8_t val = s->regs[PCA9552_INPUT0 + i];
+                sprintf(buf[i], "%c%c%c%c%c%c%c%c",
+                        val & 0x80 ? '*' : '.',
+                        val & 0x40 ? '*' : '.',
+                        val & 0x20 ? '*' : '.',
+                        val & 0x10 ? '*' : '.',
+                        val & 0x08 ? '*' : '.',
+                        val & 0x04 ? '*' : '.',
+                        val & 0x02 ? '*' : '.',
+                        val & 0x01 ? '*' : '.');
+            }
+            trace_pca9552_led_state(s, buf[1], buf[0]);
+        }
         break;
 
     case PCA9552_INPUT0:
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
index 5561746866..21e52f192d 100644
--- a/hw/misc/trace-events
+++ b/hw/misc/trace-events
@@ -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
+pca9552_led_state(void *object, const char *bufhi, const char *buflo) "%p LEDs [%s %s]"