summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-02-28 13:44:03 -0800
committerRandall Spangler <rspangler@chromium.org>2012-02-28 13:58:34 -0800
commit4c89ccd89eea60092118e49ca6b68a04d21d8870 (patch)
tree19cbd88927df9b8839bd11a6d760ebae20241476 /common
parente632029ed045e2b4922e3131898b0137d3a79972 (diff)
downloadchrome-ec-4c89ccd89eea60092118e49ca6b68a04d21d8870.tar.gz
Register host commands the same clever way we do console commands
BUG=none TEST=run assorted ectool commands Change-Id: I830d3cbf2d1557b3ab455ec8736d3de5e5d3e697
Diffstat (limited to 'common')
-rw-r--r--common/flash_commands.c24
-rw-r--r--common/host_command.c106
-rw-r--r--common/main.c2
-rw-r--r--common/pstore_commands.c6
-rw-r--r--common/pwm_commands.c13
-rw-r--r--common/usb_charge_commands.c8
6 files changed, 62 insertions, 97 deletions
diff --git a/common/flash_commands.c b/common/flash_commands.c
index 6da536b40c..04e4b89b6e 100644
--- a/common/flash_commands.c
+++ b/common/flash_commands.c
@@ -1,14 +1,13 @@
-/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-/* Flash memory module for Chrome EC */
+/* Flash memory commands for Chrome EC */
#include "console.h"
#include "flash.h"
-#include "flash_commands.h"
-#include "lpc_commands.h"
+#include "host_command.h"
#include "registers.h" /* TODO: remove; only for temp debugging */
#include "shared_mem.h"
#include "uart.h"
@@ -203,6 +202,7 @@ enum lpc_status flash_command_get_info(uint8_t *data)
r->protect_block_size = FLASH_PROTECT_BYTES;
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_INFO, flash_command_get_info);
#ifdef SUPPORT_CHECKSUM
@@ -228,6 +228,7 @@ enum lpc_status flash_command_checksum(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_CHECKSUM, flash_command_checksum);
#endif
@@ -246,6 +247,7 @@ enum lpc_status flash_command_read(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_READ, flash_command_read);
enum lpc_status flash_command_write(uint8_t *data)
@@ -261,6 +263,7 @@ enum lpc_status flash_command_write(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WRITE, flash_command_write);
enum lpc_status flash_command_erase(uint8_t *data)
@@ -273,6 +276,8 @@ enum lpc_status flash_command_erase(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_ERASE, flash_command_erase);
+
/* TODO: use shadow range in EEPROM */
static int shadow_wp_offset;
@@ -296,6 +301,9 @@ enum lpc_status flash_command_wp_enable(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WP_ENABLE,
+ flash_command_wp_enable);
+
enum lpc_status flash_command_wp_get_state(uint8_t *data)
{
@@ -309,6 +317,9 @@ enum lpc_status flash_command_wp_get_state(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WP_GET_STATE,
+ flash_command_wp_get_state);
+
enum lpc_status flash_command_wp_set_range(uint8_t *data)
{
@@ -320,6 +331,9 @@ enum lpc_status flash_command_wp_set_range(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WP_SET_RANGE,
+ flash_command_wp_set_range);
+
enum lpc_status flash_command_wp_get_range(uint8_t *data)
{
@@ -331,3 +345,5 @@ enum lpc_status flash_command_wp_get_range(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WP_GET_RANGE,
+ flash_command_wp_get_range);
diff --git a/common/host_command.c b/common/host_command.c
index f52c6095ad..faf29bfa63 100644
--- a/common/host_command.c
+++ b/common/host_command.c
@@ -5,24 +5,22 @@
/* Host command module for Chrome EC */
-#include "board.h"
-#include "config.h"
#include "console.h"
-#include "flash_commands.h"
#include "host_command.h"
#include "lpc.h"
#include "lpc_commands.h"
-#include "pstore_commands.h"
-#include "pwm_commands.h"
#include "system.h"
#include "task.h"
#include "timer.h"
#include "uart.h"
-#include "usb_charge_commands.h"
#include "util.h"
static int host_command[2];
+/* Host commands are described in a special section */
+extern const struct host_command __hcmds[];
+extern const struct host_command __hcmds_end[];
+
/*****************************************************************************/
/* Host commands */
@@ -71,6 +69,7 @@ static enum lpc_status host_command_hello(uint8_t *data)
r->out_data = d + 0x01020304;
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_HELLO, host_command_hello);
static enum lpc_status host_command_get_version(uint8_t *data)
@@ -104,6 +103,7 @@ static enum lpc_status host_command_get_version(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_GET_VERSION, host_command_get_version);
static enum lpc_status host_command_read_test(uint8_t *data)
@@ -124,89 +124,37 @@ static enum lpc_status host_command_read_test(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_READ_TEST, host_command_read_test);
+
+
+/* Finds a command by command number. Returns the command structure, or NULL if
+ * no match found. */
+static const struct host_command *find_host_command(int command)
+{
+ const struct host_command *cmd;
+
+ for (cmd = __hcmds; cmd < __hcmds_end; cmd++) {
+ if (command == cmd->command)
+ return cmd;
+ }
+
+ return NULL;
+}
-/* handle a LPC command */
+/* Handle a LPC command */
static void command_process(int slot)
{
int command = host_command[slot];
uint8_t *data = lpc_get_host_range(slot);
+ const struct host_command *cmd = find_host_command(command);
uart_printf("[hostcmd%d 0x%02x]\n", slot, command);
- /* TODO: might be smaller to make this a table, once we get a bunch
- * of commands. */
- switch (command) {
- case EC_LPC_COMMAND_HELLO:
- lpc_send_host_response(slot, host_command_hello(data));
- return;
- case EC_LPC_COMMAND_GET_VERSION:
- lpc_send_host_response(slot, host_command_get_version(data));
- return;
- case EC_LPC_COMMAND_READ_TEST:
- lpc_send_host_response(slot, host_command_read_test(data));
- return;
- case EC_LPC_COMMAND_FLASH_INFO:
- lpc_send_host_response(slot, flash_command_get_info(data));
- return;
- case EC_LPC_COMMAND_FLASH_READ:
- lpc_send_host_response(slot, flash_command_read(data));
- return;
- case EC_LPC_COMMAND_FLASH_WRITE:
- lpc_send_host_response(slot, flash_command_write(data));
- return;
- case EC_LPC_COMMAND_FLASH_ERASE:
- lpc_send_host_response(slot, flash_command_erase(data));
- return;
- case EC_LPC_COMMAND_FLASH_WP_ENABLE:
- lpc_send_host_response(slot, flash_command_wp_enable(data));
- return;
- case EC_LPC_COMMAND_FLASH_WP_GET_STATE:
- lpc_send_host_response(slot, flash_command_wp_get_state(data));
- return;
- case EC_LPC_COMMAND_FLASH_WP_SET_RANGE:
- lpc_send_host_response(slot, flash_command_wp_set_range(data));
- return;
- case EC_LPC_COMMAND_FLASH_WP_GET_RANGE:
- lpc_send_host_response(slot, flash_command_wp_get_range(data));
- return;
-#ifdef SUPPORT_CHECKSUM
- case EC_LPC_COMMAND_FLASH_CHECKSUM:
- lpc_send_host_response(slot, flash_command_checksum(data));
- return;
-#endif
- case EC_LPC_COMMAND_PWM_GET_FAN_RPM:
- lpc_send_host_response(slot, pwm_command_get_fan_rpm(data));
- return;
- case EC_LPC_COMMAND_PWM_SET_FAN_TARGET_RPM:
- lpc_send_host_response(slot,
- pwm_command_set_fan_target_rpm(data));
- return;
- case EC_LPC_COMMAND_PWM_GET_KEYBOARD_BACKLIGHT:
- lpc_send_host_response(slot,
- pwm_command_get_keyboard_backlight(data));
- return;
- case EC_LPC_COMMAND_PWM_SET_KEYBOARD_BACKLIGHT:
- lpc_send_host_response(slot,
- pwm_command_set_keyboard_backlight(data));
- return;
- case EC_LPC_COMMAND_USB_CHARGE_SET_MODE:
- lpc_send_host_response(slot, usb_charge_command_set_mode(data));
- return;
-#ifdef CONFIG_PSTORE
- case EC_LPC_COMMAND_PSTORE_INFO:
- lpc_send_host_response(slot, pstore_command_get_info(data));
- return;
- case EC_LPC_COMMAND_PSTORE_READ:
- lpc_send_host_response(slot, pstore_command_read(data));
- return;
- case EC_LPC_COMMAND_PSTORE_WRITE:
- lpc_send_host_response(slot, pstore_command_write(data));
- return;
-#endif
- default:
+ if (cmd)
+ lpc_send_host_response(slot, cmd->handler(data));
+ else
lpc_send_host_response(slot, EC_LPC_STATUS_INVALID_COMMAND);
- }
}
/*****************************************************************************/
diff --git a/common/main.c b/common/main.c
index f342bad9a0..628227d627 100644
--- a/common/main.c
+++ b/common/main.c
@@ -13,7 +13,6 @@
#include "console.h"
#include "eeprom.h"
#include "flash.h"
-#include "flash_commands.h"
#include "gpio.h"
#include "i2c.h"
#include "jtag.h"
@@ -26,7 +25,6 @@
#include "power_button.h"
#include "powerdemo.h"
#include "pwm.h"
-#include "pwm_commands.h"
#include "system.h"
#include "task.h"
#include "temp_sensor.h"
diff --git a/common/pstore_commands.c b/common/pstore_commands.c
index 24ce7c7878..67c35d1bab 100644
--- a/common/pstore_commands.c
+++ b/common/pstore_commands.c
@@ -7,8 +7,7 @@
#include "board.h"
#include "eeprom.h"
-#include "lpc_commands.h"
-#include "pstore_commands.h"
+#include "host_command.h"
#include "uart.h"
#include "util.h"
@@ -34,6 +33,7 @@ enum lpc_status pstore_command_get_info(uint8_t *data)
r->access_size = sizeof(uint32_t);
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PSTORE_INFO, pstore_command_get_info);
enum lpc_status pstore_command_read(uint8_t *data)
@@ -71,6 +71,7 @@ enum lpc_status pstore_command_read(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PSTORE_READ, pstore_command_read);
enum lpc_status pstore_command_write(uint8_t *data)
@@ -107,3 +108,4 @@ enum lpc_status pstore_command_write(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PSTORE_WRITE, pstore_command_write);
diff --git a/common/pwm_commands.c b/common/pwm_commands.c
index e186436d79..3e6a9ee52b 100644
--- a/common/pwm_commands.c
+++ b/common/pwm_commands.c
@@ -5,14 +5,10 @@
/* PWM host commands for Chrome EC */
+#include "host_command.h"
#include "pwm.h"
-#include "pwm_commands.h"
-#include "lpc_commands.h"
-/*****************************************************************************/
-/* Host commands */
-
enum lpc_status pwm_command_get_fan_rpm(uint8_t *data)
{
struct lpc_response_pwm_get_fan_rpm *r =
@@ -21,6 +17,7 @@ enum lpc_status pwm_command_get_fan_rpm(uint8_t *data)
r->rpm = pwm_get_fan_target_rpm();
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PWM_GET_FAN_RPM, pwm_command_get_fan_rpm);
enum lpc_status pwm_command_set_fan_target_rpm(uint8_t *data)
@@ -31,6 +28,8 @@ enum lpc_status pwm_command_set_fan_target_rpm(uint8_t *data)
pwm_set_fan_target_rpm(p->rpm);
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PWM_SET_FAN_TARGET_RPM,
+ pwm_command_set_fan_target_rpm);
enum lpc_status pwm_command_get_keyboard_backlight(uint8_t *data)
@@ -41,6 +40,8 @@ enum lpc_status pwm_command_get_keyboard_backlight(uint8_t *data)
r->percent = pwm_get_keyboard_backlight();
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PWM_GET_KEYBOARD_BACKLIGHT,
+ pwm_command_get_keyboard_backlight);
enum lpc_status pwm_command_set_keyboard_backlight(uint8_t *data)
@@ -51,3 +52,5 @@ enum lpc_status pwm_command_set_keyboard_backlight(uint8_t *data)
pwm_set_keyboard_backlight(p->percent);
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PWM_SET_KEYBOARD_BACKLIGHT,
+ pwm_command_set_keyboard_backlight);
diff --git a/common/usb_charge_commands.c b/common/usb_charge_commands.c
index 6d72f48742..22fdb3374d 100644
--- a/common/usb_charge_commands.c
+++ b/common/usb_charge_commands.c
@@ -7,15 +7,11 @@
#include "console.h"
#include "usb_charge.h"
-#include "usb_charge_commands.h"
-#include "lpc_commands.h"
+#include "host_command.h"
#include "uart.h"
#include "util.h"
-/*****************************************************************************/
-/* Host commands */
-
enum lpc_status usb_charge_command_set_mode(uint8_t *data)
{
struct lpc_params_usb_charge_set_mode *p =
@@ -31,3 +27,5 @@ enum lpc_status usb_charge_command_set_mode(uint8_t *data)
return EC_LPC_STATUS_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_USB_CHARGE_SET_MODE,
+ usb_charge_command_set_mode);