summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerrit <chrome-bot@google.com>2012-05-21 11:16:06 -0700
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>2012-05-21 11:16:06 -0700
commitb5ce7f5a203937c652dd543bcd4d9d76944ecd6b (patch)
treea27987b1a8b57aa6ec25964d8413428ce91f03f5
parentf618a74f7f72a89d764e727556778c8ad411761a (diff)
parenteac46a9194a211b97e4fb5a77ed8320f17dd7a8c (diff)
downloadchrome-ec-b5ce7f5a203937c652dd543bcd4d9d76944ecd6b.tar.gz
Merge "More debug command cleanup to save space"
-rw-r--r--chip/lm4/i2c.c20
-rw-r--r--chip/lm4/power_button.c5
-rw-r--r--chip/lm4/pwm.c71
-rw-r--r--common/charger_bq24725.c61
-rw-r--r--common/console.c4
-rw-r--r--common/gpio_commands.c44
-rw-r--r--common/memory_commands.c17
-rw-r--r--common/system_common.c75
8 files changed, 111 insertions, 186 deletions
diff --git a/chip/lm4/i2c.c b/chip/lm4/i2c.c
index 1ebab481e8..0d3f2ecf2b 100644
--- a/chip/lm4/i2c.c
+++ b/chip/lm4/i2c.c
@@ -349,27 +349,20 @@ static int command_i2cread(int argc, char **argv)
for (i = 0; i < I2C_PORTS_USED && port != i2c_ports[i].port; i++)
;
- if (i >= I2C_PORTS_USED) {
- ccputs("Unsupported port\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (i >= I2C_PORTS_USED)
+ return EC_ERROR_INVAL;
addr = strtoi(argv[2], &e, 0);
- if (*e || (addr & 0x01)) {
- ccputs("Invalid addr; try 'i2cscan' command\n");
+ if (*e || (addr & 0x01))
return EC_ERROR_INVAL;
- }
if (argc > 3) {
count = strtoi(argv[3], &e, 0);
- if (*e) {
- ccputs("Invalid count\n");
+ if (*e)
return EC_ERROR_INVAL;
- }
}
- ccprintf("Reading %d bytes from I2C device %d:0x%02x...\n",
- count, port, addr);
+ ccprintf("Reading %d bytes from %d:0x%02x:", count, port, addr);
mutex_lock(port_mutex + port);
LM4_I2C_MSA(port) = addr | 0x01;
for (i = 0; i < count; i++) {
@@ -383,7 +376,7 @@ static int command_i2cread(int argc, char **argv)
return rv;
}
d = LM4_I2C_MDR(port) & 0xff;
- ccprintf("0x%02x ", d);
+ ccprintf(" 0x%02x", d);
}
mutex_unlock(port_mutex + port);
ccputs("\n");
@@ -398,7 +391,6 @@ static int command_scan(int argc, char **argv)
for (i = 0; i < I2C_PORTS_USED; i++)
scan_bus(i2c_ports[i].port, i2c_ports[i].name);
- ccputs("done.\n");
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(i2cscan, command_scan);
diff --git a/chip/lm4/power_button.c b/chip/lm4/power_button.c
index e74899070d..45ef06cde9 100644
--- a/chip/lm4/power_button.c
+++ b/chip/lm4/power_button.c
@@ -551,11 +551,8 @@ static int command_powerbtn(int argc, char **argv)
if (argc > 1) {
ms = strtoi(argv[1], &e, 0);
- if (*e) {
- ccputs("Invalid duration.\n"
- "Usage: powerbtn [duration_ms]\n");
+ if (*e)
return EC_ERROR_INVAL;
- }
}
ccprintf("Simulating %d ms power button press.\n", ms);
diff --git a/chip/lm4/pwm.c b/chip/lm4/pwm.c
index c0da3a2da8..1c1f5fcb59 100644
--- a/chip/lm4/pwm.c
+++ b/chip/lm4/pwm.c
@@ -154,16 +154,16 @@ void pwm_task(void)
static int command_fan_info(int argc, char **argv)
{
- ccprintf("Fan actual speed: %4d rpm\n", pwm_get_fan_rpm());
- ccprintf(" target speed: %4d rpm\n",
+ ccprintf("Actual: %4d rpm\n", pwm_get_fan_rpm());
+ ccprintf("Target: %4d rpm\n",
(LM4_FAN_FANCMD(FAN_CH_CPU) & MAX_RPM) * CPU_FAN_SCALE);
- ccprintf(" duty cycle: %d%%\n",
+ ccprintf("Duty: %d%%\n",
((LM4_FAN_FANCMD(FAN_CH_CPU) >> 16)) * 100 / MAX_PWM);
- ccprintf(" status: %d\n",
+ ccprintf("Status: %d\n",
(LM4_FAN_FANSTS >> (2 * FAN_CH_CPU)) & 0x03);
- ccprintf(" enabled: %s\n",
+ ccprintf("Enable: %s\n",
LM4_FAN_FANCTL & (1 << FAN_CH_CPU) ? "yes" : "no");
- ccprintf(" powered: %s\n",
+ ccprintf("Power: %s\n",
gpio_get_level(GPIO_PGOOD_5VALW) ? "yes" : "no");
return EC_SUCCESS;
@@ -175,20 +175,13 @@ static int command_fan_set(int argc, char **argv)
{
int rpm = 0;
char *e;
- int rv;
- if (argc < 2) {
- ccputs("Usage: fanset <rpm>\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (argc < 2)
+ return EC_ERROR_INVAL;
rpm = strtoi(argv[1], &e, 0);
- if (*e) {
- ccputs("Invalid speed\n");
- return EC_ERROR_UNKNOWN;
- }
-
- ccprintf("Setting fan speed to %d rpm...\n", rpm);
+ if (*e)
+ return EC_ERROR_INVAL;
/* Move the fan to automatic control */
if (LM4_FAN_FANCH(FAN_CH_CPU) & 0x0001) {
@@ -203,30 +196,24 @@ static int command_fan_set(int argc, char **argv)
thermal_toggle_auto_fan_ctrl(0);
#endif
- rv = pwm_set_fan_target_rpm(rpm);
- if (rv == EC_SUCCESS)
- ccprintf("Done.\n");
-
- return rv;
+ return pwm_set_fan_target_rpm(rpm);
}
DECLARE_CONSOLE_COMMAND(fanset, command_fan_set);
+#ifdef CONSOLE_COMMAND_FANDUTY
/* TODO: this is a temporary command for debugging tach issues */
static int command_fan_duty(int argc, char **argv)
{
int d = 0, pwm;
char *e;
- if (argc < 2) {
- ccputs("Usage: fanduty <percent>\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (argc < 2)
+ return EC_ERROR_INVAL;
d = strtoi(argv[1], &e, 0);
if (*e) {
- ccputs("Invalid duty cycle\n");
- return EC_ERROR_UNKNOWN;
+ return EC_ERROR_INVAL;
}
pwm = (MAX_PWM * d) / 100;
@@ -251,30 +238,22 @@ static int command_fan_duty(int argc, char **argv)
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(fanduty, command_fan_duty);
+#endif
static int command_kblight(int argc, char **argv)
{
- char *e;
- int rv;
- int i;
-
- if (argc < 2) {
- ccprintf("Keyboard backlight is at %d%%\n",
- pwm_get_keyboard_backlight());
- return EC_SUCCESS;
- }
-
- i = strtoi(argv[1], &e, 0);
- if (*e) {
- ccputs("Invalid percent\n");
- return EC_ERROR_UNKNOWN;
+ int rv = EC_SUCCESS;
+
+ if (argc >= 2) {
+ char *e;
+ int i = strtoi(argv[1], &e, 0);
+ if (*e)
+ return EC_ERROR_INVAL;
+ rv = pwm_set_keyboard_backlight(i);
}
- ccprintf("Setting keyboard backlight to %d%%...\n", i);
- rv = pwm_set_keyboard_backlight(i);
- if (rv == EC_SUCCESS)
- ccprintf("Done.\n");
+ ccprintf("Keyboard backlight: %d%%\n", pwm_get_keyboard_backlight());
return rv;
}
DECLARE_CONSOLE_COMMAND(kblight, command_kblight);
diff --git a/common/charger_bq24725.c b/common/charger_bq24725.c
index c479de6380..6693a1bebe 100644
--- a/common/charger_bq24725.c
+++ b/common/charger_bq24725.c
@@ -173,111 +173,90 @@ int charger_post_init(void)
return charger_set_input_current(CONFIG_CHARGER_INPUT_CURRENT);
}
-
+/*****************************************************************************/
/* Console commands */
-static void print_usage(void)
-{
- ccputs("Usage: charger [set_command value]\n");
- ccputs(" charger input input_current_in_mA\n");
- ccputs(" charger voltage voltage_limit_in_mV\n");
- ccputs(" charger current current_limit_in_mA\n\n");
-}
-
static int print_info(void)
{
int rv;
int d;
const struct charger_info *info;
- ccputs("Charger properties : now (max, min, step)\n");
-
/* info */
info = charger_get_info();
- ccprintf(" name : %s\n", info->name);
+ ccprintf("Name : %s\n", info->name);
/* option */
rv = charger_get_option(&d);
if (rv)
return rv;
- ccprintf(" option : %016b (0x%04x)\n", d, d);
+ ccprintf("Option: %016b (0x%04x)\n", d, d);
/* manufacturer id */
rv = charger_manufacturer_id(&d);
if (rv)
return rv;
- ccprintf(" manufacturer id: 0x%04x\n", d);
+ ccprintf("Man id: 0x%04x\n", d);
/* device id */
rv = charger_device_id(&d);
if (rv)
return rv;
- ccprintf(" device id : 0x%04x\n", d);
+ ccprintf("Dev id: 0x%04x\n", d);
/* charge voltage limit */
rv = charger_get_voltage(&d);
if (rv)
return rv;
- ccprintf(" voltage : %5d (%5d, %4d, %3d)\n", d,
- info->voltage_max, info->voltage_min, info->voltage_step);
+ ccprintf("V_batt: %5d (%4d - %5d, %3d)\n", d,
+ info->voltage_min, info->voltage_max, info->voltage_step);
/* charge current limit */
rv = charger_get_current(&d);
if (rv)
return rv;
- ccprintf(" current : %5d (%5d, %4d, %3d)\n", d,
- info->current_max, info->current_min, info->current_step);
+ ccprintf("I_batt: %5d (%4d - %5d, %3d)\n", d,
+ info->current_min, info->current_max, info->current_step);
/* input current limit */
rv = charger_get_input_current(&d);
if (rv)
return rv;
- ccprintf(" input current : %5d (%5d, %4d, %3d)\n", d,
- info->input_current_max, info->input_current_min,
+ ccprintf("I_in : %5d (%4d - %5d, %3d)\n", d,
+ info->input_current_min, info->input_current_max,
info->input_current_step);
return EC_SUCCESS;
}
+
static int command_charger(int argc, char **argv)
{
int d;
char *endptr;
- if (argc != 3) {
- if (argc != 1)
- print_usage();
+ if (argc != 3)
return print_info();
- }
if (strcasecmp(argv[1], "input") == 0) {
d = strtoi(argv[2], &endptr, 0);
- if (*endptr) {
- print_usage();
- return EC_ERROR_UNKNOWN;
- }
+ if (*endptr)
+ return EC_ERROR_INVAL;
return charger_set_input_current(d);
} else if (strcasecmp(argv[1], "current") == 0) {
d = strtoi(argv[2], &endptr, 0);
- if (*endptr) {
- print_usage();
- return EC_ERROR_UNKNOWN;
- }
+ if (*endptr)
+ return EC_ERROR_INVAL;
return charger_set_current(d);
} else if (strcasecmp(argv[1], "voltage") == 0) {
d = strtoi(argv[2], &endptr, 0);
if (*endptr) {
- print_usage();
- return EC_ERROR_UNKNOWN;
+ return EC_ERROR_INVAL;
}
return charger_set_voltage(d);
- } else {
- print_usage();
- return print_info();
- }
-
- return EC_SUCCESS;
+ } else
+ return EC_ERROR_INVAL;
}
DECLARE_CONSOLE_COMMAND(charger, command_charger);
diff --git a/common/console.c b/common/console.c
index 8f21418f43..16a17fade7 100644
--- a/common/console.c
+++ b/common/console.c
@@ -194,7 +194,9 @@ static void console_process(void)
uart_gets(input_buf, sizeof(input_buf));
rv = handle_command(input_buf);
- if (rv != EC_SUCCESS)
+ if (rv == EC_ERROR_INVAL)
+ ccputs("Command usage/param invalid.\n");
+ else if (rv != EC_SUCCESS)
ccprintf("Command returned error %d\n", rv);
ccputs(PROMPT);
}
diff --git a/common/gpio_commands.c b/common/gpio_commands.c
index 1f32cc2e5e..ca8487533d 100644
--- a/common/gpio_commands.c
+++ b/common/gpio_commands.c
@@ -11,6 +11,9 @@
#include "util.h"
+static uint8_t last_val[(GPIO_COUNT + 7) / 8];
+
+
/* Find a GPIO signal by name. Returns the signal index, or GPIO_COUNT if
* no match. */
static enum gpio_signal find_signal_by_name(const char *name)
@@ -30,8 +33,6 @@ static enum gpio_signal find_signal_by_name(const char *name)
}
-static uint8_t last_val[(GPIO_COUNT + 7) / 8];
-
/* If v is different from the last value for index i, updates the last value
* and returns 1; else returns 0. */
static int last_val_changed(int i, int v)
@@ -47,6 +48,7 @@ static int last_val_changed(int i, int v)
}
}
+
static int command_gpio_get(int argc, char **argv)
{
const struct gpio_info *g = gpio_list;
@@ -55,10 +57,8 @@ static int command_gpio_get(int argc, char **argv)
/* If a signal is specified, print only that one */
if (argc == 2) {
i = find_signal_by_name(argv[1]);
- if (i == GPIO_COUNT) {
- ccputs("Unknown signal name.\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (i == GPIO_COUNT)
+ return EC_ERROR_INVAL;
g = gpio_list + i;
v = gpio_get_level(i);
changed = last_val_changed(i, v);
@@ -68,7 +68,6 @@ static int command_gpio_get(int argc, char **argv)
}
/* Otherwise print them all */
- ccputs("Current GPIO levels:\n");
for (i = 0; i < GPIO_COUNT; i++, g++) {
if (!g->mask)
continue; /* Skip unsupported signals */
@@ -92,32 +91,23 @@ static int command_gpio_set(int argc, char **argv)
char *e;
int v, i;
- if (argc < 3) {
- ccputs("Usage: gpioset <signal_name> <0|1>\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (argc < 3)
+ return EC_ERROR_INVAL;
i = find_signal_by_name(argv[1]);
- if (i == GPIO_COUNT) {
- ccputs("Unknown signal name.\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (i == GPIO_COUNT)
+ return EC_ERROR_INVAL;
g = gpio_list + i;
- if (!g->mask) {
- ccputs("Signal is not implemented.\n");
- return EC_ERROR_UNKNOWN;
- }
- if (!(g->flags & GPIO_OUTPUT)) {
- ccputs("Signal is not an output.\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (!g->mask)
+ return EC_ERROR_INVAL;
+
+ if (!(g->flags & GPIO_OUTPUT))
+ return EC_ERROR_INVAL;
v = strtoi(argv[2], &e, 0);
- if (*e) {
- ccputs("Invalid signal value.\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (*e)
+ return EC_ERROR_INVAL;
return gpio_set_level(i, v);
}
diff --git a/common/memory_commands.c b/common/memory_commands.c
index e8bff757cd..a313379e86 100644
--- a/common/memory_commands.c
+++ b/common/memory_commands.c
@@ -14,14 +14,12 @@ static int command_write_word(int argc, char **argv)
volatile uint32_t *address;
uint32_t value;
- if (argc != 3) {
- ccputs("Usage: ww <address> <value>\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (argc != 3)
+ return EC_ERROR_INVAL;
address = (uint32_t*)strtoi(argv[1], NULL, 0);
value = strtoi(argv[2], NULL, 0);
- ccprintf("write word 0x%p = 0x%08x\n", address, value);
+ ccprintf("write 0x%p = 0x%08x\n", address, value);
cflush(); /* Flush before writing in case this crashes */
*address = value;
@@ -37,14 +35,13 @@ static int command_read_word(int argc, char **argv)
volatile uint32_t *address;
uint32_t value;
- if (argc != 2) {
- ccputs("Usage: rw <address>\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (argc != 2)
+ return EC_ERROR_INVAL;
+
address = (uint32_t*)strtoi(argv[1], NULL, 0);
value = *address;
- ccprintf("read word 0x%p = 0x%08x\n", address, value);
+ ccprintf("read 0x%p = 0x%08x\n", address, value);
return EC_SUCCESS;
}
diff --git a/common/system_common.c b/common/system_common.c
index 018181870e..2cdbf0e626 100644
--- a/common/system_common.c
+++ b/common/system_common.c
@@ -413,13 +413,11 @@ int system_common_pre_init(void)
static int command_sysinfo(int argc, char **argv)
{
- ccprintf("Reset cause: %d (%s)\n",
+ ccprintf("Last reset: %d (%s)\n",
system_get_reset_cause(),
system_get_reset_cause_string());
- ccprintf("Scratchpad: 0x%08x\n", system_get_scratchpad());
- ccprintf("Firmware copy: %s\n", system_get_image_copy_string());
- ccprintf("Jumped to this copy: %s\n",
- system_jumped_to_this_image() ? "yes" : "no");
+ ccprintf("Copy: %s\n", system_get_image_copy_string());
+ ccprintf("Jump: %s\n", system_jumped_to_this_image() ? "yes" : "no");
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(sysinfo, command_sysinfo);
@@ -427,33 +425,32 @@ DECLARE_CONSOLE_COMMAND(sysinfo, command_sysinfo);
static int command_chipinfo(int argc, char **argv)
{
- ccprintf("Chip vendor: %s\n", system_get_chip_vendor());
- ccprintf("Chip name: %s\n", system_get_chip_name());
- ccprintf("Chip revision: %s\n", system_get_chip_revision());
+ ccprintf("Vendor: %s\n", system_get_chip_vendor());
+ ccprintf("Name: %s\n", system_get_chip_name());
+ ccprintf("Revision: %s\n", system_get_chip_revision());
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(chipinfo, command_chipinfo);
-static int command_set_scratchpad(int argc, char **argv)
+#ifdef CONSOLE_COMMAND_SCRATCHPAD
+static int command_scratchpad(int argc, char **argv)
{
- int s;
- char *e;
-
- if (argc < 2) {
- ccputs("Usage: scratchpad <value>\n");
- return EC_ERROR_UNKNOWN;
+ int rv = EC_SUCCESS;
+
+ if (argc == 2) {
+ char *e;
+ int s = strtoi(argv[1], &e, 0);
+ if (*e)
+ return EC_ERROR_INVAL;
+ rv = system_set_scratchpad(s);
}
- s = strtoi(argv[1], &e, 0);
- if (*e) {
- ccputs("Invalid scratchpad value\n");
- return EC_ERROR_UNKNOWN;
- }
- ccprintf("Setting scratchpad to 0x%08x\n", s);
- return system_set_scratchpad(s);
+ ccprintf("Scratchpad: 0x%08x\n", system_get_scratchpad());
+ return rv;
}
-DECLARE_CONSOLE_COMMAND(setscratchpad, command_set_scratchpad);
+DECLARE_CONSOLE_COMMAND(scratchpad, command_scratchpad);
+#endif
static int command_hibernate(int argc, char **argv)
@@ -461,15 +458,13 @@ static int command_hibernate(int argc, char **argv)
int seconds;
int microseconds = 0;
- if (argc < 2) {
- ccputs("Usage: hibernate <seconds> [<microseconds>]\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (argc < 2)
+ return EC_ERROR_INVAL;
seconds = strtoi(argv[1], NULL, 0);
if (argc >= 3)
microseconds = strtoi(argv[2], NULL, 0);
- ccprintf("Hibernating for %d.%06d s ...\n", seconds, microseconds);
+ ccprintf("Hibernating for %d.%06d s\n", seconds, microseconds);
cflush();
system_hibernate(seconds, microseconds);
@@ -481,14 +476,11 @@ DECLARE_CONSOLE_COMMAND(hibernate, command_hibernate);
static int command_version(int argc, char **argv)
{
- ccprintf("Board version: %d\n", system_get_board_version());
- ccprintf("RO version: %s\n",
- system_get_version(SYSTEM_IMAGE_RO));
- ccprintf("RW-A version: %s\n",
- system_get_version(SYSTEM_IMAGE_RW_A));
- ccprintf("RW-B version: %s\n",
- system_get_version(SYSTEM_IMAGE_RW_B));
- ccprintf("Current build: %s\n", system_get_build_info());
+ ccprintf("Board: %d\n", system_get_board_version());
+ ccprintf("RO: %s\n", system_get_version(SYSTEM_IMAGE_RO));
+ ccprintf("RW-A: %s\n", system_get_version(SYSTEM_IMAGE_RW_A));
+ ccprintf("RW-B: %s\n", system_get_version(SYSTEM_IMAGE_RW_B));
+ ccprintf("Build: %s\n", system_get_build_info());
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(version, command_version);
@@ -502,10 +494,8 @@ static int command_sysjump(int argc, char **argv)
/* TODO: (crosbug.com/p/7468) For this command to be allowed, WP must
* be disabled. */
- if (argc < 2) {
- ccputs("Usage: sysjump <RO | A | B | addr>\n");
+ if (argc < 2)
return EC_ERROR_INVAL;
- }
ccputs("Processing sysjump command\n");
@@ -520,11 +510,10 @@ static int command_sysjump(int argc, char **argv)
/* Check for arbitrary address */
addr = strtoi(argv[1], &e, 0);
- if (e && *e) {
- ccputs("Invalid image address\n");
+ if (*e)
return EC_ERROR_INVAL;
- }
- ccprintf("Jumping directly to 0x%08x...\n", addr);
+
+ ccprintf("Jumping to 0x%08x\n", addr);
cflush();
jump_to_image(addr, 0);
return EC_SUCCESS;