Skip to contentSkip to conversation

hw/misc/pca9552: Trace LED On/Off events

PATCH Superseded Philippe Mathieu-Daudé 2 participants 4 messages Jun 17, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/misc/pca9552: Trace LED On/Off events

Example booting obmc-phosphor-image:

  $ qemu-system-arm -M witherspoon-bmc -trace pca\*
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ .......*]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ......**]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ .....***]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [..*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [.**..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [*.*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [*.*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
---
 hw/misc/pca9552.c    | 18 ++++++++++++++++++
 hw/misc/trace-events |  3 +++
 2 files changed, 21 insertions(+)
hw/misc/pca9552.c +18 -0
index cac729e35a..693f6c3b24 100644
@@ -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:
hw/misc/trace-events +3 -0
index 5561746866..21e52f192d 100644
@@ -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]"
Signature · 1 line
2.21.3
#1 lore raw
Quoted 18 lines · Philippe Mathieu-Daudé

Example booting obmc-phosphor-image:

  $ qemu-system-arm -M witherspoon-bmc -trace pca\*
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ .......*]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ......**]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ .....***]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [..*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [.**..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [*.*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [*.*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]

It looks better but the ordering is wrong.

Quoted 31 lines
---
 hw/misc/pca9552.c    | 18 ++++++++++++++++++
 hw/misc/trace-events |  3 +++
 2 files changed, 21 insertions(+)
hw/misc/pca9552.c +9 -0
index cac729e35a..693f6c3b24 100644
@@ -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 ? '*' : '.',

hw/misc/pca9552.c static void pca9552_write(PCA9552State *s, uint8_t reg, uint8_t data) · line 116

Quoted 10 lines
hw/misc/pca9552.c +9 -0
+                        val & 0x20 ? '*' : '.',
+                        val & 0x10 ? '*' : '.',
+                        val & 0x08 ? '*' : '.',
+                        val & 0x04 ? '*' : '.',
+                        val & 0x02 ? '*' : '.',
+                        val & 0x01 ? '*' : '.');
+            }
+            trace_pca9552_led_state(s, buf[1], buf[0]);
+        }
         break;

or something like this :

static void pca9552_update_pin_input(PCA9552State *s)

 {
     int i;

+ char state[s->nr_leds + 1];

     for (i = 0; i < s->nr_leds; i++) {
         uint8_t input_reg = PCA9552_INPUT0 + (i / 8);
@@ -45,9 +47,11 @@ static void pca9552_update_pin_input(PCA
         switch (config) {
         case PCA9552_LED_ON:
             s->regs[input_reg] |= 1 << input_shift;
+            state[i] = '*';
             break;
         case PCA9552_LED_OFF:
             s->regs[input_reg] &= ~(1 << input_shift);
+            state[i] = '.';
             break;
         case PCA9552_LED_PWM0:
         case PCA9552_LED_PWM1:
@@ -56,6 +60,9 @@ static void pca9552_update_pin_input(PCA
             break;
         }
     }

+ state[i] = 0;
+
+ trace_pca9552_led_state(s, state);
}

The pin usage is described in the witherspoon DTS :

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts?id=b1f9be9392f0#n78

The front-power led is blinking. I suppose it means the BMC is on but not the host.

Cheers,

C.

Quoted 14 lines
hw/misc/pca9552.c +0 -0
     case PCA9552_INPUT0:
hw/misc/trace-events +3 -0
index 5561746866..21e52f192d 100644
@@ -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]"
#2 lore raw
Quoted 20 lines · Cédric Le Goater
Quoted 18 lines · Philippe Mathieu-Daudé

Example booting obmc-phosphor-image:

  $ qemu-system-arm -M witherspoon-bmc -trace pca\*
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ .......*]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ......**]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ .....***]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [..*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [.**..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [*.*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [*.*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
Quoted 1 line

It looks better but the ordering is wrong.

The order is [15, 14, ..., 3, 2, 1, 0].

This one is blinking?

    front-power {
        retain-state-shutdown;
        default-state = "keep";
        gpios = <&pca0 14 GPIO_ACTIVE_LOW>;
    };
Quoted 102 lines
Quoted 32 lines
---
 hw/misc/pca9552.c    | 18 ++++++++++++++++++
 hw/misc/trace-events |  3 +++
 2 files changed, 21 insertions(+)
hw/misc/pca9552.c +9 -0
index cac729e35a..693f6c3b24 100644
@@ -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 ? '*' : '.',

hw/misc/pca9552.c static void pca9552_write(PCA9552State *s, uint8_t reg, uint8_t data) · line 116

Quoted 10 lines
hw/misc/pca9552.c +9 -0
+                        val & 0x20 ? '*' : '.',
+                        val & 0x10 ? '*' : '.',
+                        val & 0x08 ? '*' : '.',
+                        val & 0x04 ? '*' : '.',
+                        val & 0x02 ? '*' : '.',
+                        val & 0x01 ? '*' : '.');
+            }
+            trace_pca9552_led_state(s, buf[1], buf[0]);
+        }
         break;

or something like this :

static void pca9552_update_pin_input(PCA9552State *s)

 {
     int i;
(quoted diff) +6 -0
+    char state[s->nr_leds + 1];
 
     for (i = 0; i < s->nr_leds; i++) {
         uint8_t input_reg = PCA9552_INPUT0 + (i / 8);
@@ -45,9 +47,11 @@ static void pca9552_update_pin_input(PCA
         switch (config) {
         case PCA9552_LED_ON:
             s->regs[input_reg] |= 1 << input_shift;
+            state[i] = '*';
             break;
         case PCA9552_LED_OFF:
             s->regs[input_reg] &= ~(1 << input_shift);
+            state[i] = '.';
             break;
         case PCA9552_LED_PWM0:
         case PCA9552_LED_PWM1:
@@ -56,6 +60,9 @@ static void pca9552_update_pin_input(PCA
             break;
         }
     }
+    state[i] = 0;
+
+    trace_pca9552_led_state(s, state);
 }
 
 

The pin usage is described in the witherspoon DTS :

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts?id=b1f9be9392f0#n78

The front-power led is blinking. I suppose it means the BMC is on but not the host.

Cheers,

C.

Quoted 14 lines
hw/misc/pca9552.c +0 -0
     case PCA9552_INPUT0:
hw/misc/trace-events +3 -0
index 5561746866..21e52f192d 100644
@@ -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]"
Reviewed-by
#3 lore raw
Quoted 21 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Cédric Le Goater
Quoted 18 lines · Philippe Mathieu-Daudé

Example booting obmc-phosphor-image:

  $ qemu-system-arm -M witherspoon-bmc -trace pca\*
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ........]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ .......*]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ......**]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ .....***]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [........ ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [..*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [.**..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [*.*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [*.*..... ....****]
  [email protected]:pca9552_led_state 0x5594a9f57560 LEDs [***..... ....****]
Quoted 3 lines
Quoted 1 line

It looks better but the ordering is wrong.

The order is [15, 14, ..., 3, 2, 1, 0].

I am contaminated by PowerPC specs.

Quoted 7 lines

This one is blinking?

    front-power {
        retain-state-shutdown;
        default-state = "keep";
        gpios = <&pca0 14 GPIO_ACTIVE_LOW>;
    };

yes.

Let it be then,

Thanks,

C.

Quoted 102 lines
Quoted 102 lines
Quoted 32 lines
---
 hw/misc/pca9552.c    | 18 ++++++++++++++++++
 hw/misc/trace-events |  3 +++
 2 files changed, 21 insertions(+)
hw/misc/pca9552.c +9 -0
index cac729e35a..693f6c3b24 100644
@@ -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 ? '*' : '.',

hw/misc/pca9552.c static void pca9552_write(PCA9552State *s, uint8_t reg, uint8_t data) · line 116

Quoted 10 lines
hw/misc/pca9552.c +9 -0
+                        val & 0x20 ? '*' : '.',
+                        val & 0x10 ? '*' : '.',
+                        val & 0x08 ? '*' : '.',
+                        val & 0x04 ? '*' : '.',
+                        val & 0x02 ? '*' : '.',
+                        val & 0x01 ? '*' : '.');
+            }
+            trace_pca9552_led_state(s, buf[1], buf[0]);
+        }
         break;

or something like this :

static void pca9552_update_pin_input(PCA9552State *s)

 {
     int i;
(quoted diff) +6 -0
+    char state[s->nr_leds + 1];
 
     for (i = 0; i < s->nr_leds; i++) {
         uint8_t input_reg = PCA9552_INPUT0 + (i / 8);
@@ -45,9 +47,11 @@ static void pca9552_update_pin_input(PCA
         switch (config) {
         case PCA9552_LED_ON:
             s->regs[input_reg] |= 1 << input_shift;
+            state[i] = '*';
             break;
         case PCA9552_LED_OFF:
             s->regs[input_reg] &= ~(1 << input_shift);
+            state[i] = '.';
             break;
         case PCA9552_LED_PWM0:
         case PCA9552_LED_PWM1:
@@ -56,6 +60,9 @@ static void pca9552_update_pin_input(PCA
             break;
         }
     }
+    state[i] = 0;
+
+    trace_pca9552_led_state(s, state);
 }
 
 

The pin usage is described in the witherspoon DTS :

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts?id=b1f9be9392f0#n78

The front-power led is blinking. I suppose it means the BMC is on but not the host.

Cheers,

C.

Quoted 14 lines
hw/misc/pca9552.c +0 -0
     case PCA9552_INPUT0:
hw/misc/trace-events +3 -0
index 5561746866..21e52f192d 100644
@@ -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]"