summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-05-31 14:19:23 -0700
committerGerrit <chrome-bot@google.com>2012-05-31 15:03:17 -0700
commit26b4a9e1a0b104a16154eb03f9d3ea4fab134252 (patch)
treef44b3502e759c4b0326fa9b286fac29969cbe2d0
parent11ab34a721aa40d8e891b6e1bab8e5633bfe8168 (diff)
downloadchrome-ec-26b4a9e1a0b104a16154eb03f9d3ea4fab134252.tar.gz
Assorted keyboard module cleanup
Const- and static-ifying data and pointers. Signed-off-by: Randall Spangler <rspangler@chromium.org> BUG=none TEST=kblog on, then boot system, then kblog; should print log Change-Id: I2e1da8e3d614b66dad8749b18c43bd77dc75928d Reviewed-on: https://gerrit.chromium.org/gerrit/24233 Commit-Ready: Randall Spangler <rspangler@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--common/i8042.c4
-rw-r--r--common/keyboard.c23
-rw-r--r--include/i8042.h2
3 files changed, 17 insertions, 12 deletions
diff --git a/common/i8042.c b/common/i8042.c
index 54eb668f3c..9a07388686 100644
--- a/common/i8042.c
+++ b/common/i8042.c
@@ -80,7 +80,7 @@ void i8042_receives_command(int cmd)
/* Called by EC common code to send bytes to host via port 0x60. */
-static void enq_to_host(int len, uint8_t *to_host)
+static void enq_to_host(int len, const uint8_t *to_host)
{
int from, to;
@@ -151,7 +151,7 @@ void i8042_command_task(void)
}
-enum ec_error_list i8042_send_to_host(int len, uint8_t *to_host)
+enum ec_error_list i8042_send_to_host(int len, const uint8_t *to_host)
{
int i;
diff --git a/common/keyboard.c b/common/keyboard.c
index d0ac87e00b..3fd09682e9 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -108,7 +108,7 @@ struct kb_state {
/* The standard Chrome OS keyboard matrix table. */
#define CROS_ROW_NUM 8 /* TODO: +1 for power button. */
#define CROS_COL_NUM 13
-static uint16_t scancode_set1[CROS_ROW_NUM][CROS_COL_NUM] = {
+static const uint16_t scancode_set1[CROS_ROW_NUM][CROS_COL_NUM] = {
{0x0000, 0xe05b, 0x003b, 0x0030, 0x0044, 0x0073, 0x0031, 0x0000, 0x000d,
0x0000, 0xe038, 0x0000, 0x0000},
{0x0000, 0x0001, 0x003e, 0x0022, 0x0041, 0x0000, 0x0023, 0x0000, 0x0028,
@@ -127,7 +127,7 @@ static uint16_t scancode_set1[CROS_ROW_NUM][CROS_COL_NUM] = {
0x0018, 0x0000, 0xe048, 0xe04b},
};
-static uint16_t scancode_set2[CROS_ROW_NUM][CROS_COL_NUM] = {
+static const uint16_t scancode_set2[CROS_ROW_NUM][CROS_COL_NUM] = {
{0x0000, 0xe01f, 0x0005, 0x0032, 0x0009, 0x0051, 0x0031, 0x0000, 0x0055,
0x0000, 0xe011, 0x0000, 0x0000},
{0x0000, 0x0076, 0x000c, 0x0034, 0x0083, 0x0000, 0x0033, 0x0000, 0x0052,
@@ -322,7 +322,7 @@ void keyboard_enable(int enable)
uint8_t read_ctl_ram(uint8_t addr)
{
- if (addr < 0x20) /* Controller RAM is only 32 bytes. */
+ if (addr < ARRAY_SIZE(controller_ram))
return controller_ram[addr];
else
return 0;
@@ -335,7 +335,7 @@ void update_ctl_ram(uint8_t addr, uint8_t data)
{
uint8_t orig;
- if (addr >= 0x20) /* Controller RAM is only 32 bytes. */
+ if (addr >= ARRAY_SIZE(controller_ram))
return;
orig = controller_ram[addr];
@@ -359,7 +359,7 @@ void update_ctl_ram(uint8_t addr, uint8_t data)
}
-enum {
+static enum {
STATE_NORMAL = 0,
STATE_SCANCODE,
STATE_SETLEDS,
@@ -766,7 +766,7 @@ static int command_controller_ram(int argc, char **argv)
return EC_ERROR_PARAM_COUNT;
index = strtoi(argv[1], NULL, 0);
- if (index >= 0x20)
+ if (index >= ARRAY_SIZE(controller_ram))
return EC_ERROR_PARAM1;
if (argc >= 3)
@@ -843,10 +843,12 @@ static int command_keyboard_log(int argc, char **argv)
ccputs("\n");
} else if (argc == 2 && !strcasecmp("on", argv[1])) {
if (!kblog) {
- ASSERT(EC_SUCCESS ==
- shared_mem_acquire(sizeof(*kblog) * MAX_KBLOG,
- 1, (char **)&kblog));
+ int rv = shared_mem_acquire(sizeof(*kblog) * MAX_KBLOG,
+ 1, (char **)&kblog);
+ if (rv != EC_SUCCESS)
+ kblog = NULL;
kblog_len = 0;
+ return rv;
}
} else if (argc == 2 && !strcasecmp("off", argv[1])) {
kblog_len = 0;
@@ -869,6 +871,9 @@ static int mkbp_command_simulate_key(uint8_t *data, int *resp_size)
struct ec_params_mkbp_simulate_key *p =
(struct ec_params_mkbp_simulate_key *)data;
+ if (p->col >= ARRAY_SIZE(simulated_key))
+ return EC_RES_INVALID_PARAM;
+
simulated_key[p->col] = (simulated_key[p->col] & ~(1 << p->row)) |
(p->pressed << p->row);
diff --git a/include/i8042.h b/include/i8042.h
index d88e3acb1f..6635e75aae 100644
--- a/include/i8042.h
+++ b/include/i8042.h
@@ -119,7 +119,7 @@ void i8042_disable_keyboard_irq(void);
* Return:
* EC_ERROR_BUFFER_FULL -- the queue to host is full. Try again?
*/
-enum ec_error_list i8042_send_to_host(int len, uint8_t *to_host);
+enum ec_error_list i8042_send_to_host(int len, const uint8_t *to_host);
#endif /* __INTERFACE_I8042_H */