From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Andrew Jeffery" <andrew@aj.id.au>,
"Joaquin de Andres" <me@xcancerberox.com.ar>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Esteban Bosse" <estebanbosse@gmail.com>,
qemu-arm@nongnu.org, "Cédric Le Goater" <clg@kaod.org>,
"Joel Stanley" <joel@jms.id.au>
Subject: [PATCH v3 3/4] hw/misc/pca9552: Trace LED On/Off events
Date: Fri, 19 Jun 2020 16:51:00 +0200 [thread overview]
Message-ID: <20200619145101.1637-4-f4bug@amsat.org> (raw)
In-Reply-To: <20200619145101.1637-1-f4bug@amsat.org>
Add a trivial representation of the PCA9552 LEDs.
Example booting obmc-phosphor-image:
$ qemu-system-arm -M witherspoon-bmc -trace pca9552_leds_status
19286@1592574170.202791:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [*...............]
19286@1592574170.203609:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [**..............]
19286@1592574170.204102:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [***.............]
19286@1592574170.204415:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****............]
19286@1592574170.204758:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........*..]
19286@1592574170.205070:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........**.]
19286@1592574170.205380:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........***]
19286@1592574235.384845:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........*.*]
19286@1592574235.894049:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........***]
19286@1592574236.404277:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........*.*]
19286@1592574236.914644:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........***]
19286@1592574237.424558:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........*.*]
19286@1592574237.934580:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........***]
19286@1592574238.444688:pca9552_leds_status 0x55dde47807c0 LEDs 0-15 [****.........*.*]
We notice the LED #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
Suggested-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/misc/pca9552.h | 1 +
hw/misc/pca9552.c | 29 +++++++++++++++++++++++++++++
hw/misc/trace-events | 3 +++
3 files changed, 33 insertions(+)
diff --git a/include/hw/misc/pca9552.h b/include/hw/misc/pca9552.h
index b2b9a5d9d4..4e171d88c6 100644
--- a/include/hw/misc/pca9552.h
+++ b/include/hw/misc/pca9552.h
@@ -26,6 +26,7 @@ typedef struct PCA9552State {
uint8_t pointer;
uint8_t regs[PCA9552_NR_REGS];
+ uint16_t leds_status; /* Holds latest INPUT0 & INPUT1 status */
uint8_t max_reg;
uint8_t nr_leds;
} PCA9552State;
diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c
index 00fa91b7f4..50c149077d 100644
--- a/hw/misc/pca9552.c
+++ b/hw/misc/pca9552.c
@@ -12,11 +12,13 @@
#include "qemu/osdep.h"
#include "qemu/log.h"
#include "qemu/module.h"
+#include "qemu/bitops.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"
#define PCA955X_LED_MAX 16
@@ -60,6 +62,32 @@ static void pca9552_update_pin_input(PCA9552State *s)
}
}
+static void pca9552_display_leds(PCA9552State *s)
+{
+ uint16_t leds_status, led_changed;
+ int i;
+
+ leds_status = (s->regs[PCA9552_INPUT1] << 8) | s->regs[PCA9552_INPUT0];
+ led_changed = s->leds_status ^ leds_status;
+ if (!led_changed) {
+ return;
+ }
+ s->leds_status = leds_status;
+ if (trace_event_get_state_backends(TRACE_PCA9552_LEDS_STATUS)) {
+ char buf[PCA9552_LED_COUNT + 1];
+
+ for (i = 0; i < s->nr_leds; i++) {
+ if (extract32(leds_status, i, 1)) {
+ buf[i] = '*';
+ } else {
+ buf[i] = '.';
+ }
+ }
+ buf[i] = '\0';
+ trace_pca9552_leds_status(s, buf);
+ }
+}
+
static uint8_t pca9552_read(PCA9552State *s, uint8_t reg)
{
switch (reg) {
@@ -97,6 +125,7 @@ static void pca9552_write(PCA9552State *s, uint8_t reg, uint8_t data)
case PCA9552_LS3:
s->regs[reg] = data;
pca9552_update_pin_input(s);
+ pca9552_display_leds(s);
break;
case PCA9552_INPUT0:
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
index 5561746866..5d9505ad0f 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_leds_status(void *object, const char *buf) "%p LEDs 0-15 [%s]"
--
2.21.3
next prev parent reply other threads:[~2020-06-19 14:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-19 14:50 [PATCH v3 0/4] hw/misc/pca9552: Trace LED On/Off events Philippe Mathieu-Daudé
2020-06-19 14:50 ` [PATCH v3 1/4] hw/misc/pca9552: Replace magic value by PCA9552_LED_COUNT definition Philippe Mathieu-Daudé
2020-06-19 14:50 ` [PATCH v3 2/4] hw/misc/pca9552: Add a PCA955X_LED_MAX definition Philippe Mathieu-Daudé
2020-06-19 14:51 ` Philippe Mathieu-Daudé [this message]
2020-06-19 14:51 ` [PATCH v3 4/4] hw/misc/pca9552: Trace LED change events Philippe Mathieu-Daudé
2020-06-20 11:49 ` [PATCH v3 0/4] hw/misc/pca9552: Trace LED On/Off events Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200619145101.1637-4-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=andrew@aj.id.au \
--cc=clg@kaod.org \
--cc=estebanbosse@gmail.com \
--cc=joel@jms.id.au \
--cc=me@xcancerberox.com.ar \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).