From 9284cec2fcbd76175ac2337c1f897840cc706488 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Jul 2012 19:25:48 -0700 Subject: [PATCH] snow: Add pmu command to print out pmu registers This command is primarily useful for testing, since it repeatedly hammers the i2c bus. Enable the command on snow for now. BUG=chrome-os-partner:10888 TEST=manual: run 'pmu 100' on snow and see that it displays the correct output. Change-Id: I36c15af195d17f67dff4c05559d1756693a65c19 Signed-off-by: Simon Glass Reviewed-on: https://gerrit.chromium.org/gerrit/26829 Reviewed-by: David Hendricks --- board/snow/board.h | 2 ++ common/pmu_tps65090.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/board/snow/board.h b/board/snow/board.h index 93a88ce420..5a3266fb84 100644 --- a/board/snow/board.h +++ b/board/snow/board.h @@ -55,6 +55,8 @@ #define I2C_PORT_SLAVE 1 #define CONFIG_ARBITRATE_I2C I2C_PORT_HOST +#define CONFIG_CMD_PMU + /* GPIO signal list */ enum gpio_signal { /* Inputs with interrupt handlers are first for efficiency */ diff --git a/common/pmu_tps65090.c b/common/pmu_tps65090.c index e674da9ff4..3198e1eae4 100644 --- a/common/pmu_tps65090.c +++ b/common/pmu_tps65090.c @@ -10,6 +10,7 @@ #include "common.h" #include "i2c.h" #include "pmu_tpschrome.h" +#include "timer.h" #include "util.h" #define CPUTS(outstr) cputs(CC_CHARGER, outstr) @@ -151,3 +152,54 @@ void pmu_init(void) pmu_write(IRQ2MASK, 0xff); } + +#ifdef CONFIG_CMD_PMU +static int print_pmu_info(void) +{ + int reg, ret; + int value; + + for (reg = 0; reg < 0xc; reg++) { + ret = pmu_read(reg, &value); + if (ret) + return ret; + if (!reg) + ccputs("PMU: "); + + ccprintf("%02x ", value); + } + ccputs("\n"); + + return 0; +} + +static int command_pmu(int argc, char **argv) +{ + int repeat = 1; + int rv = 0; + int loop; + char *e; + + if (argc > 1) { + repeat = strtoi(argv[1], &e, 0); + if (*e) { + ccputs("Invalid repeat count\n"); + return EC_ERROR_INVAL; + } + } + + for (loop = 0; loop < repeat; loop++) { + rv = print_pmu_info(); + usleep(1000); + } + + if (rv) + ccprintf("Failed - error %d\n", rv); + + return rv ? EC_ERROR_UNKNOWN : EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(pmu, command_pmu, + "", + "Print PMU info", + NULL); +#endif