Merge "Even more debug command cleanup to save space"

This commit is contained in:
Gerrit
2012-05-21 15:24:32 -07:00
committed by Gerrit Code Review
10 changed files with 182 additions and 317 deletions

View File

@@ -140,17 +140,14 @@ static int command_eoption_get(int argc, char **argv)
/* If a signal is specified, print only that one */
if (argc == 2) {
i = find_option_by_name(argv[1], bool_opts);
if (i == -1) {
ccputs("Unknown option.\n");
if (i == -1)
return EC_ERROR_INVAL;
}
d = bool_opts + i;
ccprintf(" %d %s\n", eoption_get_bool(i), d->name);
return EC_SUCCESS;
}
/* Otherwise print them all */
ccputs("Boolean options:\n");
for (i = 0, d = bool_opts; d->name; i++, d++) {
ccprintf(" %d %s\n", eoption_get_bool(i), d->name);
@@ -168,23 +165,17 @@ static int command_eoption_set(int argc, char **argv)
char *e;
int v, i;
if (argc < 3) {
ccputs("Usage: optset <option> <value>\n");
if (argc < 3)
return EC_ERROR_INVAL;
}
v = strtoi(argv[2], &e, 0);
if (*e) {
ccputs("Invalid value.\n");
if (*e)
return EC_ERROR_INVAL;
}
i = find_option_by_name(argv[1], bool_opts);
if (i != -1) {
return eoption_set_bool(i, v);
} else {
ccputs("Unknown option.\n");
if (i == -1)
return EC_ERROR_INVAL;
}
return eoption_set_bool(i, v);
}
DECLARE_CONSOLE_COMMAND(optset, command_eoption_set);

View File

@@ -45,6 +45,7 @@ void host_command_received(int slot, int command)
task_set_event(TASK_ID_HOSTCMD, TASK_EVENT_SLOT(slot), 0);
}
static int host_command_proto_version(uint8_t *data, int *resp_size)
{
struct ec_response_proto_version *r =
@@ -55,8 +56,8 @@ static int host_command_proto_version(uint8_t *data, int *resp_size)
*resp_size = sizeof(struct ec_response_proto_version);
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_PROTO_VERSION,
host_command_proto_version);
DECLARE_HOST_COMMAND(EC_CMD_PROTO_VERSION, host_command_proto_version);
static int host_command_hello(uint8_t *data, int *resp_size)
{
@@ -64,19 +65,6 @@ static int host_command_hello(uint8_t *data, int *resp_size)
struct ec_response_hello *r = (struct ec_response_hello *)data;
uint32_t d = p->in_data;
CPRINTF("[LPC Hello 0x%08x]\n", d);
#ifdef DELAY_HELLO_RESPONSE
/* Pretend command takes a long time, so we can see the busy
* bit set on the host side. */
/* TODO: remove in production. Or maybe hello should take a
* param with how long the delay should be; that'd be more
* useful. */
usleep(1000000);
#endif
CPUTS("[LPC sending hello back]\n");
r->out_data = d + 0x01020304;
*resp_size = sizeof(struct ec_response_hello);
return EC_RES_SUCCESS;
@@ -125,8 +113,7 @@ static int host_command_acpi_query_event(uint8_t *data, int *resp_size)
/* No events pending */
return 0;
}
DECLARE_HOST_COMMAND(EC_CMD_ACPI_QUERY_EVENT,
host_command_acpi_query_event);
DECLARE_HOST_COMMAND(EC_CMD_ACPI_QUERY_EVENT, host_command_acpi_query_event);
#endif

View File

@@ -19,39 +19,30 @@ static int command_host_event(int argc, char **argv)
if (argc == 3) {
char *e;
int i = strtoi(argv[2], &e, 0);
if (*e) {
ccputs("Invalid event mask\n");
if (*e)
return EC_ERROR_INVAL;
}
if (!strcasecmp(argv[1], "set")) {
ccprintf("Setting host event mask 0x%08x\n", i);
if (!strcasecmp(argv[1], "set"))
lpc_set_host_events(i);
} else if (!strcasecmp(argv[1], "clear")) {
ccprintf("Clearing host event mask 0x%08x\n", i);
else if (!strcasecmp(argv[1], "clear"))
lpc_clear_host_events(i);
} else if (!strcasecmp(argv[1], "smi")) {
ccprintf("Setting SMI mask to 0x%08x\n", i);
else if (!strcasecmp(argv[1], "smi"))
lpc_set_host_event_mask(LPC_HOST_EVENT_SMI, i);
} else if (!strcasecmp(argv[1], "sci")) {
ccprintf("Setting SCI mask to 0x%08x\n", i);
else if (!strcasecmp(argv[1], "sci"))
lpc_set_host_event_mask(LPC_HOST_EVENT_SCI, i);
} else if (!strcasecmp(argv[1], "wake")) {
ccprintf("Setting wake mask to 0x%08x\n", i);
else if (!strcasecmp(argv[1], "wake"))
lpc_set_host_event_mask(LPC_HOST_EVENT_WAKE, i);
} else {
ccputs("Unknown sub-command\n");
else
return EC_ERROR_INVAL;
}
}
/* Print current SMI/SCI status */
ccprintf("Raw host events: 0x%08x\n", lpc_get_host_events());
ccprintf("SMI mask: 0x%08x\n",
ccprintf("Events: 0x%08x\n", lpc_get_host_events());
ccprintf("SMI mask: 0x%08x\n",
lpc_get_host_event_mask(LPC_HOST_EVENT_SMI));
ccprintf("SCI mask: 0x%08x\n",
ccprintf("SCI mask: 0x%08x\n",
lpc_get_host_event_mask(LPC_HOST_EVENT_SCI));
ccprintf("Wake mask: 0x%08x\n",
ccprintf("Wake mask: 0x%08x\n",
lpc_get_host_event_mask(LPC_HOST_EVENT_WAKE));
return EC_SUCCESS;
}

View File

@@ -22,7 +22,6 @@
#include "util.h"
#include "x86_power.h"
#define KEYBOARD_DEBUG 1
/* Console output macros */
@@ -42,6 +41,14 @@
#define CPRINTF5(format, args...)
#endif
enum scancode_set_list {
SCANCODE_GET_SET = 0,
SCANCODE_SET_1,
SCANCODE_SET_2,
SCANCODE_SET_3,
SCANCODE_MAX = SCANCODE_SET_3,
};
/*
* i8042 global settings.
@@ -194,49 +201,49 @@ static enum ec_error_list matrix_callback(int8_t row, int8_t col,
break;
default:
CPRINTF("[Not supported scan code set: %d]\n", code_set);
CPRINTF("[Scancode set %d unsupported]\n", code_set);
return EC_ERROR_UNIMPLEMENTED;
}
if (!make_code) {
CPRINTF("[No scancode for (row:col)=(%d:%d)]\n", row, col);
CPRINTF("[Scancode %d:%d missing]\n", row, col);
return EC_ERROR_UNIMPLEMENTED;
}
/* Output the make code (from table) */
if (make_code >= 0x0100) {
*len += 2;
scan_code[0] = make_code >> 8;
scan_code[1] = make_code & 0xff;
} else {
*len += 1;
scan_code[0] = make_code & 0xff;
}
/* Output the make code (from table) */
if (make_code >= 0x0100) {
*len += 2;
scan_code[0] = make_code >> 8;
scan_code[1] = make_code & 0xff;
} else {
*len += 1;
scan_code[0] = make_code & 0xff;
}
switch (code_set) {
case SCANCODE_SET_1:
/* OR 0x80 for the last byte. */
if (!pressed) {
ASSERT(*len >= 1);
scan_code[*len - 1] |= 0x80;
}
break;
switch (code_set) {
case SCANCODE_SET_1:
/* OR 0x80 for the last byte. */
if (!pressed) {
ASSERT(*len >= 1);
scan_code[*len - 1] |= 0x80;
}
break;
case SCANCODE_SET_2:
/* insert the break byte, move back the last byte and insert a 0xf0 byte
* before that. */
if (!pressed) {
ASSERT(*len >= 1);
scan_code[*len] = scan_code[*len - 1];
scan_code[*len - 1] = 0xF0;
*len += 1;
}
break;
default:
break;
}
case SCANCODE_SET_2:
/* insert the break byte, move back the last byte and insert a
* 0xf0 byte before that. */
if (!pressed) {
ASSERT(*len >= 1);
scan_code[*len] = scan_code[*len - 1];
scan_code[*len - 1] = 0xF0;
*len += 1;
}
break;
default:
break;
}
return EC_SUCCESS;
return EC_SUCCESS;
}
@@ -702,36 +709,22 @@ void keyboard_typematic_task(void)
static int command_typematic(int argc, char **argv)
{
if (argc == 1) {
int i;
int i;
ccprintf("Value set from host: 0x%02x\n",
typematic_value_from_host);
ccprintf("Refill first delay : %d (ms)\n",
refill_first_delay);
ccprintf(" inter delay : %d (ms)\n",
refill_inter_delay);
ccprintf("Current delay : %d (us)\n",
typematic_delay);
ccputs("Repeat scan code : ");
for (i = 0; i < typematic_len; ++i) {
ccprintf("0x%02x ", typematic_scan_code[i]);
}
ccputs("\n");
} else if (argc == 3) {
if (argc == 3) {
refill_first_delay = strtoi(argv[1], NULL, 0);
refill_inter_delay = strtoi(argv[2], NULL, 0);
ccputs("New typematic delays:\n");
ccprintf(" Refill first delay : %d (ms)\n",
refill_first_delay);
ccprintf(" Refill inter delay : %d (ms)\n",
refill_inter_delay);
} else {
ccputs("Usage: typematic [<first> <inter>]\n");
return EC_ERROR_UNKNOWN;
}
ccprintf("From host: 0x%02x\n", typematic_value_from_host);
ccprintf("First delay: %d ms\n", refill_first_delay);
ccprintf("Inter delay: %d ms\n", refill_inter_delay);
ccprintf("Current: %d ms\n", typematic_delay / 1000);
ccputs("Repeat scan code:");
for (i = 0; i < typematic_len; ++i)
ccprintf(" 0x%02x", typematic_scan_code[i]);
ccputs("\n");
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(typematic, command_typematic);
@@ -739,31 +732,20 @@ DECLARE_CONSOLE_COMMAND(typematic, command_typematic);
static int command_codeset(int argc, char **argv)
{
int set;
if (argc == 1) {
ccprintf("Current scancode set: %d\n", scancode_set);
ccprintf("I8042_XLATE: %d\n",
controller_ram[0] & I8042_XLATE ? 1 : 0);
} else if (argc == 2) {
set = strtoi(argv[1], NULL, 0);
if (argc == 2) {
int set = strtoi(argv[1], NULL, 0);
switch (set) {
case SCANCODE_SET_1: /* fall-thru */
case SCANCODE_SET_2: /* fall-thru */
scancode_set = set;
ccprintf("Set scancode set to %d\n", scancode_set);
break;
default:
ccprintf("Scancode %d is NOT supported.\n", set);
return EC_ERROR_UNKNOWN;
break;
return EC_ERROR_INVAL;
}
} else {
ccputs("Usage: codeset [<set>]\n");
return EC_ERROR_UNKNOWN;
}
ccprintf("Set: %d\n", scancode_set);
ccprintf("I8042_XLATE: %d\n", controller_ram[0] & I8042_XLATE ? 1 : 0);
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(codeset, command_codeset);
@@ -773,28 +755,17 @@ static int command_controller_ram(int argc, char **argv)
{
int index;
if (argc >= 2) {
index = strtoi(argv[1], NULL, 0);
ccprintf("Controller RAM index = %d\n", index);
if (index >= 0x20) {
ccprintf("Index is out of range (0x00-0x1f).\n");
return EC_ERROR_UNKNOWN;
}
if (argc < 2)
return EC_ERROR_INVAL;
if (argc >= 3) {
update_ctl_ram(index, strtoi(argv[2], NULL, 0));
ccprintf("Write ctlram[%d] as 0x%02x.\n",
index, controller_ram[index]);
} else {
ccprintf("ctlram[%d] is 0x%02x.\n",
index, controller_ram[index]);
}
} else {
ccputs("Usage: ctrlram <index> [<write_value>]\n");
ccputs("\nGet/set controller RAM.\n\n");
return EC_ERROR_UNKNOWN;
}
index = strtoi(argv[1], NULL, 0);
if (index >= 0x20)
return EC_ERROR_INVAL;
if (argc >= 3)
update_ctl_ram(index, strtoi(argv[2], NULL, 0));
ccprintf("%d = 0x%02x\n", index, controller_ram[index]);
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(ctrlram, command_controller_ram);
@@ -802,10 +773,9 @@ DECLARE_CONSOLE_COMMAND(ctrlram, command_controller_ram);
static int command_keyboard_press(int argc, char **argv)
{
int i, j;
int r, c, p;
char *e;
if (argc == 1) {
int i, j;
ccputs("Simulated key:\n");
for (i = 0; i < CROS_COL_NUM; ++i) {
if (simulated_key[i] == 0)
@@ -814,24 +784,22 @@ static int command_keyboard_press(int argc, char **argv)
if (simulated_key[i] & (1 << j))
ccprintf("\t%d %d\n", i, j);
}
} else if (argc == 4) {
int r, c, p;
char *e;
c = strtoi(argv[1], &e, 0);
if ((e && *e) || c < 0 || c >= CROS_COL_NUM) {
ccputs("Bad column.\n");
return EC_ERROR_UNKNOWN;
}
if (*e || c < 0 || c >= CROS_COL_NUM)
return EC_ERROR_INVAL;
r = strtoi(argv[2], &e, 0);
if ((e && *e) || r < 0 || r >= CROS_ROW_NUM) {
ccputs("Bad row.\n");
return EC_ERROR_UNKNOWN;
}
if (*e || r < 0 || r >= CROS_ROW_NUM)
return EC_ERROR_INVAL;
p = strtoi(argv[3], &e, 0);
if ((e && *e) || p < 0 || p > 1) {
ccputs("Bad pressed flag.\n");
return EC_ERROR_UNKNOWN;
}
if (*e || p < 0 || p > 1)
return EC_ERROR_INVAL;
if ((simulated_key[c] & (1 << r)) == (p << r))
return EC_SUCCESS;
@@ -839,9 +807,6 @@ static int command_keyboard_press(int argc, char **argv)
simulated_key[c] = (simulated_key[c] & ~(1 << r)) | (p << r);
keyboard_state_changed(r, c, p);
} else {
ccputs("Usage: kbpress [<col> <row> <pressed>]\n");
return EC_ERROR_UNKNOWN;
}
return EC_SUCCESS;
@@ -872,12 +837,11 @@ static int command_keyboard_log(int argc, char **argv)
}
} else if (argc == 2 && !strcasecmp("off", argv[1])) {
kblog_len = 0;
shared_mem_release(kblog);
if (kblog)
shared_mem_release(kblog);
kblog = NULL;
} else {
ccputs("Usage: kblog [on/off]\n");
return EC_ERROR_UNKNOWN;
}
} else
return EC_ERROR_INVAL;
return EC_SUCCESS;
}

View File

@@ -119,7 +119,7 @@ static inline uint8_t scale(int val, int max)
static void lightbar_init_vals(void)
{
CPRINTF("[%s()]\n", __func__);
CPRINTF("[%T LB init_vals]\n");
set_from_array(init_vals, ARRAY_SIZE(init_vals));
memset(current, 0, sizeof(current));
}
@@ -146,7 +146,7 @@ static void setrgb(int led, int red, int green, int blue)
static void lightbar_off(void)
{
CPRINTF("[%s()]\n", __func__);
CPRINTF("[%T LB off]\n");
/* Just go into standby mode. No register values should change. */
controller_write(0, 0x01, 0x00);
controller_write(1, 0x01, 0x00);
@@ -154,7 +154,7 @@ static void lightbar_off(void)
static void lightbar_on(void)
{
CPRINTF("[%s()]\n", __func__);
CPRINTF("[%T LB on]\n");
/* Come out of standby mode. */
controller_write(0, 0x01, 0x20);
controller_write(1, 0x01, 0x20);
@@ -176,7 +176,7 @@ static void lightbar_setrgb(int led, int red, int green, int blue)
static inline void lightbar_brightness(int newval)
{
int i;
CPRINTF("%s[(%d)]\n", __func__, newval);
CPRINTF("[%T LB bright %d]\n", newval);
brightness = newval;
for (i = 0; i < NUM_LEDS; i++)
lightbar_setrgb(i, current[i][0],
@@ -214,7 +214,6 @@ static const struct {
static uint32_t sequence_S5(void)
{
int i;
CPRINTF("[%s()]\n", __func__);
/* Do something short to indicate S5. We might see it. */
lightbar_on();
@@ -234,7 +233,6 @@ static uint32_t sequence_S5S3(void)
{
int i;
CPRINTF("[%s()]\n", __func__);
/* The controllers need 100us after power is applied before they'll
* respond. */
usleep(100);
@@ -256,7 +254,6 @@ static uint32_t sequence_S0(void)
int l = 0;
int n = 0;
CPRINTF("[%s()]\n", __func__);
lightbar_on();
while (1) {
@@ -278,7 +275,6 @@ static uint32_t sequence_S0(void)
/* CPU is going to sleep */
static uint32_t sequence_S0S3(void)
{
CPRINTF("[%s()]\n", __func__);
lightbar_on();
lightbar_setrgb(0, 0, 0, 255);
lightbar_setrgb(1, 255, 0, 0);
@@ -299,7 +295,6 @@ static uint32_t sequence_S0S3(void)
static uint32_t sequence_S3(void)
{
int i = 0;
CPRINTF("[%s()]\n", __func__);
lightbar_off();
lightbar_init_vals();
lightbar_setrgb(0, 0, 0, 0);
@@ -324,7 +319,6 @@ static uint32_t sequence_S3(void)
/* CPU is waking from sleep */
static uint32_t sequence_S3S0(void)
{
CPRINTF("[%s()]\n", __func__);
lightbar_init_vals();
lightbar_on();
lightbar_setrgb(0, 0, 0, 255);
@@ -343,8 +337,6 @@ static uint32_t sequence_S3S5(void)
{
int i;
CPRINTF("[%s()]\n", __func__);
/* For now, do something to indicate this transition.
* We might see it. */
lightbar_on();
@@ -362,8 +354,6 @@ static uint32_t sequence_TEST(void)
int kmax = 254;
int kstep = 8;
CPRINTF("[%s()]\n", __func__);
lightbar_init_vals();
lightbar_on();
for (i = 0; i < ARRAY_SIZE(testy); i++) {
@@ -411,8 +401,6 @@ static uint32_t sequence_PULSE(void)
{0x1a, g},
};
CPRINTF("[%s()]\n", __func__);
lightbar_init_vals();
lightbar_on();
@@ -435,15 +423,13 @@ static uint32_t sequence_STOP(void)
{
uint32_t msg;
CPRINTF("[%s()]\n", __func__);
do {
msg = TASK_EVENT_CUSTOM(task_wait_event(-1));
CPRINTF("[%s - got msg %x]\n", __func__, msg);
CPRINTF("[%T LB stop got msg %x]\n", msg);
} while (msg != LIGHTBAR_RUN);
/* FIXME: What should we do if the host shuts down? */
CPRINTF("[%s() - leaving]\n", __func__);
CPRINTF("[%T LB restarting]\n");
return 0;
}
@@ -451,15 +437,12 @@ static uint32_t sequence_STOP(void)
/* Telling us to run when we're already running should do nothing. */
static uint32_t sequence_RUN(void)
{
CPRINTF("[%s()]\n", __func__);
return 0;
}
/* We shouldn't come here, but if we do it shouldn't hurt anything */
static uint32_t sequence_ERROR(void)
{
CPRINTF("[%s()]\n", __func__);
lightbar_init_vals();
lightbar_on();
@@ -555,7 +538,6 @@ static uint32_t sequence_KONAMI(void)
int i;
int tmp;
CPRINTF("[%s()]\n", __func__);
lightbar_init_vals();
lightbar_on();
@@ -616,8 +598,10 @@ void lightbar_task(void)
previous_state = LIGHTBAR_S5;
while (1) {
CPRINTF("[%T LB task %d = %s]\n",
current_state, lightbar_cmds[current_state]);
msg = lightbar_cmds[current_state].sequence();
CPRINTF("[%s(%d)]\n", __func__, msg);
CPRINTF("[%T LB msg %d]\n", msg);
msg = TASK_EVENT_CUSTOM(msg);
if (msg && msg < LIGHTBAR_NUM_SEQUENCES) {
previous_state = current_state;
@@ -652,7 +636,7 @@ void lightbar_task(void)
/* Function to request a preset sequence from the lightbar task. */
void lightbar_sequence(enum lightbar_sequence num)
{
CPRINTF("[%s(%d)]\n", __func__, num);
CPRINTF("[%T LB seq %d]\n", num);
if (num && num < LIGHTBAR_NUM_SEQUENCES)
task_set_event(TASK_ID_LIGHTBAR,
TASK_EVENT_WAKE | TASK_EVENT_CUSTOM(num), 0);
@@ -759,7 +743,7 @@ static int lpc_cmd_lightbar(uint8_t *data, int *resp_size)
*resp_size = sizeof(struct ec_params_lightbar_cmd);
break;
default:
CPRINTF("[invalid lightbar cmd 0x%x]\n", ptr->in.cmd);
CPRINTF("[%T LB bad cmd 0x%x]\n", ptr->in.cmd);
return EC_RES_INVALID_PARAM;
}
@@ -773,6 +757,7 @@ DECLARE_HOST_COMMAND(EC_CMD_LIGHTBAR_CMD, lpc_cmd_lightbar);
/* EC console commands */
/****************************************************************************/
#ifdef CONSOLE_COMMAND_LIGHTBAR_HELP
static int help(const char *cmd)
{
ccprintf("Usage:\n");
@@ -788,6 +773,7 @@ static int help(const char *cmd)
" (LED=4 for all)\n", cmd);
return EC_SUCCESS;
}
#endif
static uint8_t find_msg_by_name(const char *str)
{
@@ -802,7 +788,7 @@ static uint8_t find_msg_by_name(const char *str)
static void show_msg_names(void)
{
int i;
ccprintf("sequence names:");
ccprintf("Sequences:");
for (i = 0; i < LIGHTBAR_NUM_SEQUENCES; i++)
ccprintf(" %s", lightbar_cmds[i].string);
ccprintf("\nCurrent = 0x%x %s\n", current_state,
@@ -885,6 +871,10 @@ static int command_lightbar(int argc, char **argv)
return EC_SUCCESS;
}
return help(argv[0]);
#ifdef CONSOLE_COMMAND_LIGHTBAR_HELP
help(argv[0]);
#endif
return EC_ERROR_INVAL;
}
DECLARE_CONSOLE_COMMAND(lightbar, command_lightbar);

View File

@@ -43,18 +43,16 @@ static int command_port80(int argc, char **argv)
* (scrolling) or CR (non-scrolling). */
if (argc > 1 && !strcasecmp(argv[1], "scroll")) {
scroll = !scroll;
ccprintf("port80 scrolling %sabled\n",
scroll ? "en" : "dis");
ccprintf("scroll %sabled\n", scroll ? "en" : "dis");
return EC_SUCCESS;
}
/* Technically, if a port 80 write comes in while we're
* printing this, we could print an incorrect history.
* Probably not worth the complexity to work around that. */
ccputs("Last port 80 writes:");
/* Technically, if a port 80 write comes in while we're printing this,
* we could print an incorrect history. Probably not worth the
* complexity to work around that. */
for (i = 0; i < HISTORY_LEN; i++)
ccprintf(" %02x", history[(h + i) & (HISTORY_LEN - 1)]);
ccputs(" <--newest\n");
ccputs(" <--new\n");
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(port80, command_port80);

View File

@@ -76,24 +76,13 @@ int powerled_set(enum powerled_color color)
static int command_powerled(int argc, char **argv)
{
int i = POWERLED_COLOR_COUNT;
int i;
/* Pick a color, any color... */
if (argc >= 1) {
for (i = 0; i < POWERLED_COLOR_COUNT; i++) {
if (!strcasecmp(argv[1], color_names[i]))
break;
}
for (i = 0; i < POWERLED_COLOR_COUNT; i++) {
if (!strcasecmp(argv[1], color_names[i]))
return powerled_set(i);
}
if (i >= POWERLED_COLOR_COUNT) {
ccputs("Please specify a color:");
for (i = 0; i < POWERLED_COLOR_COUNT; i++)
ccprintf(" %s", color_names[i]);
ccputs("\n");
return EC_ERROR_INVAL;
}
ccprintf("Setting power LED to %s...\n", color_names[i]);
return powerled_set(i);
return EC_ERROR_INVAL;
}
DECLARE_CONSOLE_COMMAND(powerled, command_powerled);

View File

@@ -116,40 +116,39 @@ static int command_battery(int argc, char **argv)
char text[32];
const char *unit;
ccputs("Reading battery...\n");
rv = battery_temperature(&d);
if (rv)
return rv;
ccprintf(" Temperature: 0x%04x = %d x 0.1K (%d C)\n",
ccprintf(" Temp: 0x%04x = %d x 0.1K (%d C)\n",
d, d, (d-2731)/10);
ccprintf(" Manufacturer: %s\n",
ccprintf(" Manuf: %s\n",
battery_manufacturer_name(text, sizeof(text)) == EC_SUCCESS ?
text : "(error)");
ccprintf(" Device: %s\n",
ccprintf(" Device: %s\n",
battery_device_name(text, sizeof(text)) == EC_SUCCESS ?
text : "(error)");
ccprintf(" Chemistry: %s\n",
ccprintf(" Chem: %s\n",
battery_device_chemistry(text, sizeof(text)) == EC_SUCCESS ?
text : "(error)");
battery_serial_number(&d);
ccprintf(" Serial number: 0x%04x\n", d);
ccprintf(" Serial: 0x%04x\n", d);
battery_voltage(&d);
ccprintf(" Voltage: 0x%04x = %d mV\n", d, d);
ccprintf(" V: 0x%04x = %d mV\n", d, d);
battery_desired_voltage(&d);
ccprintf(" Desired voltage 0x%04x = %d mV\n", d, d);
ccprintf(" V-desired: 0x%04x = %d mV\n", d, d);
battery_design_voltage(&d);
ccprintf(" Design output voltage 0x%04x = %d mV\n", d, d);
ccprintf(" V-design: 0x%04x = %d mV\n", d, d);
battery_current(&d);
ccprintf(" Current: 0x%04x = %d mA",
ccprintf(" I: 0x%04x = %d mA",
d & 0xffff, d);
if (d > 0)
ccputs("(CHG)");
@@ -159,36 +158,26 @@ static int command_battery(int argc, char **argv)
battery_desired_current(&d);
ccprintf(" Desired current 0x%04x = %d mA\n", d, d);
ccprintf(" I-desired: 0x%04x = %d mA\n", d, d);
battery_get_battery_mode(&d);
ccprintf(" Battery mode: 0x%04x\n", d);
ccprintf(" Mode: 0x%04x\n", d);
unit = (d & MODE_CAPACITY) ? "0 mW" : " mAh";
battery_state_of_charge(&d);
ccprintf(" %% of charge: %d %%\n", d);
ccprintf(" Charge: %d %%\n", d);
battery_state_of_charge_abs(&d);
ccprintf(" Abs %% of charge: %d %%\n", d);
ccprintf(" Abs: %d %%\n", d);
battery_remaining_capacity(&d);
ccprintf(" Remaining capacity: %d%s\n", d, unit);
ccprintf(" Remaining: %d%s\n", d, unit);
battery_full_charge_capacity(&d);
ccprintf(" Full charge capacity: %d%s\n", d, unit);
ccprintf(" Cap-full: %d%s\n", d, unit);
battery_design_capacity(&d);
ccprintf(" Design capacity: %d%s\n", d, unit);
battery_time_to_empty(&d);
if (d == 65535) {
hour = 0;
minute = 0;
} else {
hour = d / 60;
minute = d % 60;
}
ccprintf(" Time to empty: %dh:%d\n", hour, minute);
ccprintf(" Design: %d%s\n", d, unit);
battery_time_to_full(&d);
if (d == 65535) {
@@ -198,13 +187,29 @@ static int command_battery(int argc, char **argv)
hour = d / 60;
minute = d % 60;
}
ccprintf(" Time to full: %dh:%d\n", hour, minute);
ccprintf(" Time-full: %dh:%d\n", hour, minute);
battery_time_to_empty(&d);
if (d == 65535) {
hour = 0;
minute = 0;
} else {
hour = d / 60;
minute = d % 60;
}
ccprintf(" Empty: %dh:%d\n", hour, minute);
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(battery, command_battery);
/* Usage:sb <r/w> cmd [uint16_t w_word]
* sb r 0x14 // desired charging current
* sb r 0x15 // desired charging voltage
* sb r 0x3 // battery mode
* sb w 0x3 0xe001 // set battery mode
*/
static int command_sb(int argc, char **argv)
{
int rv;
@@ -212,44 +217,34 @@ static int command_sb(int argc, char **argv)
char *e;
if (argc < 3)
goto usage;
return EC_ERROR_INVAL;
cmd = strtoi(argv[2], &e, 0);
if (*e) {
ccputs("Invalid cmd.\n");
goto usage;
}
if (*e)
return EC_ERROR_INVAL;
if (argv[1][0] == 'r') {
rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, &d);
if (rv) {
ccputs("I2C read failed.\n");
if (rv)
return rv;
}
ccprintf("R SBCMD[%04x] 0x%04x (%d)\n", cmd, d, d);
return EC_SUCCESS;
} else if (argc >= 4 && argv[1][0] == 'w') {
d = strtoi(argv[3], &e, 0);
if (*e) {
ccputs("Invalid w_word.\n");
goto usage;
}
if (*e)
return EC_ERROR_INVAL;
ccprintf("W SBCMD[%04x] 0x%04x (%d)\n", cmd, d, d);
rv = i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, d);
if (rv) {
ccputs("I2C write failed.\n");
if (rv)
return rv;
}
return EC_SUCCESS;
}
usage:
ccputs("Usage:sb <r/w> cmd [uint16_t w_word]\n");
ccputs(" sb r 0x14 // desired charging current\n");
ccputs(" sb r 0x15 // desired charging voltage\n");
ccputs(" sb r 0x3 // battery mode\n");
ccputs(" sb w 0x3 0xe001 // set battery mode\n");
return EC_SUCCESS;
return EC_ERROR_INVAL;
}
DECLARE_CONSOLE_COMMAND(sb, command_sb);

View File

@@ -104,25 +104,19 @@ void temp_sensor_task(void)
static int command_temps(int argc, char **argv)
{
int i;
int rv = 0;
int rv = EC_SUCCESS;
int t;
ccputs("Reading temperature sensors...\n");
for (i = 0; i < TEMP_SENSOR_COUNT; ++i) {
ccprintf(" %-20s: ", temp_sensors[i].name);
t = temp_sensor_read(i);
if (t < 0) {
ccprintf("Error\n");
rv = -1;
}
else
rv = EC_ERROR_UNKNOWN;
} else
ccprintf("%d K = %d C\n", t, t - 273);
}
if (rv == -1)
return EC_ERROR_UNKNOWN;
return EC_SUCCESS;
return rv;
}
DECLARE_CONSOLE_COMMAND(temps, command_temps);

View File

@@ -18,15 +18,6 @@
#define MAX_KBLOG 512
enum scancode_set_list {
SCANCODE_GET_SET = 0,
SCANCODE_SET_1,
SCANCODE_SET_2,
SCANCODE_SET_3,
SCANCODE_MAX = SCANCODE_SET_3,
};
/* Called by keyboard scan code once any key state change (after de-bounce),
*
* This function will look up matrix table and convert scancode host.
@@ -56,37 +47,12 @@ void keyboard_set_power_button(int pressed);
/* Log the keyboard-related information */
void kblog_put(char type, uint8_t byte);
/* Register the board-specific keyboard matrix translation function.
* The callback function accepts col/row and returns the scan code.
*
* Note that *scan_code must be at least 4 bytes long to store maximum
* possible sequence.
*/
typedef enum ec_error_list (*keyboard_matrix_callback)(
int8_t row, int8_t col, int8_t pressed,
enum scancode_set_list code_set, uint8_t *scan_code, int32_t* len);
enum ec_error_list keyboard_matrix_register_callback(
int8_t row_num, int8_t col_num,
keyboard_matrix_callback callback);
/***************************************************************************/
/* Below is the interface with the underlying chip-dependent code.
*/
#define MAX_KEYBOARD_MATRIX_ROWS 8
#define MAX_KEYBOARD_MATRIX_COLS 16
typedef void (*keyboard_callback)(int row, int col, int is_pressed);
/* Registers a callback function to underlayer EC lib. So that any key state
* change would notify the upper EC main code.
*
* Note that passing NULL removes any previously registered callback.
*/
enum ec_error_list keyboard_register_callback(keyboard_callback cb);
/* Asks the underlayer EC lib what keys are pressed right now.
*
* Sets bit_array to a debounced array of which keys are currently pressed,