diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2015-04-01 10:05:57 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-05-07 22:25:25 +0000 |
commit | 17487510e3e2f91f44692e7d30db8c7d8fcde2bd (patch) | |
tree | caa942810c3558d127123d50a7f2fd9bbf469417 | |
parent | 6d80aeed939a35859c87517236e88c847604499d (diff) | |
download | chrome-ec-17487510e3e2f91f44692e7d30db8c7d8fcde2bd.tar.gz |
ec: Add Inventory command
Add command that list supported features by the firmware.
Also let the firmware indicates if more features are expected in the RW
version.
This will help the cros_ec framework load the right driver(s) for
exposing information via sysfs.
BUG=chromium:428364
BRANCH=none
TEST=Test on samus on both ec and pd:
localhost ~ # ectool inventory
EC supported features:
1 : Flash support
2 : Direct Fan power management support
3 : Keyboard backlight support
4 : Lightbar support
6 : Motion Sensors support
7 : Keyboard support
9 : BIOS Port 80h access support
10 : Thermal management support
11 : Switch backlight on/off support
12 : Switch wifi on/off support
13 : Host event support
14 : GPIO support
15 : I2C master support
16 : Charger support
17 : Simple Battery support
18 : Smart Battery support
21 : Control downstream MCU support
localhost ~ # ectool --name cros_pd inventory
EC supported features:
1 : Flash support
14 : GPIO support
15 : I2C master support
22 : USB Cros Power Delievery support
Change-Id: Ib6eaac91fda86835e754c5316ecf81fbc27786e5
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/263463
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
-rw-r--r-- | common/host_command.c | 92 | ||||
-rw-r--r-- | include/config.h | 3 | ||||
-rw-r--r-- | include/ec_commands.h | 84 | ||||
-rw-r--r-- | util/ectool.c | 55 |
4 files changed, 233 insertions, 1 deletions
diff --git a/common/host_command.c b/common/host_command.c index 0a6226b59e..451bff74f3 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -678,6 +678,98 @@ DECLARE_HOST_COMMAND(EC_CMD_TEST_PROTOCOL, host_command_test_protocol, EC_VER_MASK(0)); +/* Returns supported features. */ +static int host_command_get_features(struct host_cmd_handler_args *args) +{ + struct ec_response_get_features *r = args->response; + args->response_size = sizeof(*r); + + memset(r, 0, sizeof(*r)); + r->flags[0] = 0 +#ifdef CONFIG_FW_LIMITED_IMAGE + | EC_FEATURE_MASK_0(EC_FEATURE_LIMITED) +#endif +#ifdef CONFIG_FLASH + | EC_FEATURE_MASK_0(EC_FEATURE_FLASH) +#endif +#ifdef CONFIG_FANS + | EC_FEATURE_MASK_0(EC_FEATURE_PWM_FAN) +#endif +#ifdef CONFIG_PWM_KBLIGHT + | EC_FEATURE_MASK_0(EC_FEATURE_PWM_KEYB) +#endif +#ifdef HAS_TASK_LIGHTBAR + | EC_FEATURE_MASK_0(EC_FEATURE_LIGHTBAR) +#endif +#ifdef CONFIG_LED_COMMON + | EC_FEATURE_MASK_0(EC_FEATURE_LED) +#endif +#ifdef HAS_TASK_MOTIONSENSE + | EC_FEATURE_MASK_0(EC_FEATURE_MOTION_SENSE) +#endif +#ifdef HAS_TASK_KEYSCAN + | EC_FEATURE_MASK_0(EC_FEATURE_KEYB) +#endif +#ifdef CONFIG_PSTORE + | EC_FEATURE_MASK_0(EC_FEATURE_PSTORE) +#endif +#ifdef CONFIG_LPC + | EC_FEATURE_MASK_0(EC_FEATURE_PORT80) +#endif +#ifdef CONFIG_TEMP_SENSOR + | EC_FEATURE_MASK_0(EC_FEATURE_THERMAL) +#endif +/* Hack to uniquely identify Samus and Falco ec */ +#if (defined CONFIG_BACKLIGHT_LID) || \ + (defined CONFIG_BATTERY_SAMUS) || \ + (defined CONFIG_EXTPOWER_FALCO) + | EC_FEATURE_MASK_0(EC_FEATURE_BKLIGHT_SWITCH) +#endif +#ifdef CONFIG_WIRELESS + | EC_FEATURE_MASK_0(EC_FEATURE_WIFI_SWITCH) +#endif +#ifdef CONFIG_HOSTCMD_EVENTS + | EC_FEATURE_MASK_0(EC_FEATURE_HOST_EVENTS) +#endif +#ifdef CONFIG_COMMON_GPIO + | EC_FEATURE_MASK_0(EC_FEATURE_GPIO) +#endif +#ifdef CONFIG_I2C + | EC_FEATURE_MASK_0(EC_FEATURE_I2C) +#endif +#ifdef CONFIG_CHARGER + | EC_FEATURE_MASK_0(EC_FEATURE_CHARGER) +#endif +#if (defined CONFIG_BATTERY) || (defined CONFIG_BATTERY_SMART) + | EC_FEATURE_MASK_0(EC_FEATURE_BATTERY) +#endif +#ifdef CONFIG_BATTERY_SMART + | EC_FEATURE_MASK_0(EC_FEATURE_SMART_BATTERY) +#endif +#ifdef CONFIG_AP_HANG_DETECT + | EC_FEATURE_MASK_0(EC_FEATURE_HANG_DETECT) +#endif +#ifdef CONFIG_PMU_POWERINFO + | EC_FEATURE_MASK_0(EC_FEATURE_PMU) +#endif +#ifdef HAS_TASK_PDCMD + | EC_FEATURE_MASK_0(EC_FEATURE_SUB_MCU) +#endif +#ifdef CONFIG_CHARGE_MANAGER + | EC_FEATURE_MASK_0(EC_FEATURE_USB_PD) +#endif +/* should be more generic */ +#ifdef CONFIG_USB_SWITCH_TSU6721 + | EC_FEATURE_MASK_0(EC_FEATURE_USB_MUX) +#endif + ; + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_GET_FEATURES, + host_command_get_features, + EC_VER_MASK(0)); + + /*****************************************************************************/ /* Console commands */ diff --git a/include/config.h b/include/config.h index 307edb4722..47370d8aac 100644 --- a/include/config.h +++ b/include/config.h @@ -656,6 +656,9 @@ */ #define CONFIG_FW_INCLUDE_RO +/* If defined, another image (RW) exists with more features */ +#undef CONFIG_FW_LIMITED_IMAGE + /*****************************************************************************/ /* Motion sensor based gesture recognition information */ /* These all require HAS_TASK_MOTIONSENSE to work */ diff --git a/include/ec_commands.h b/include/ec_commands.h index ef7836d40c..cb064b9588 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -859,6 +859,88 @@ struct ec_response_get_set_value { /* More than one command can use these structs to get/set paramters. */ #define EC_CMD_GSV_PAUSE_IN_S5 0x0c +/*****************************************************************************/ +/* List the features supported by the firmware */ +#define EC_CMD_GET_FEATURES 0x0d + +/* Supported features */ +enum ec_feature_code { + /* + * This image contains a limited set of features. Another image + * in RW partition may support more features. + */ + EC_FEATURE_LIMITED = 0, + /* + * Commands for probing/reading/writing/erasing the flash in the + * EC are present. + */ + EC_FEATURE_FLASH = 1, + /* + * Can control the fan speed directly. + */ + EC_FEATURE_PWM_FAN = 2, + /* + * Can control the intensity of the keyboard backlight. + */ + EC_FEATURE_PWM_KEYB = 3, + /* + * Support Google lightbar, introduced on Pixel. + */ + EC_FEATURE_LIGHTBAR = 4, + /* Control of LEDs */ + EC_FEATURE_LED = 5, + /* Exposes an interface to control gyro and sensors. + * The host goes through the EC to access these sensors. + * In addition, the EC may provide composite sensors, like lid angle. + */ + EC_FEATURE_MOTION_SENSE = 6, + /* The keyboard is controlled by the EC */ + EC_FEATURE_KEYB = 7, + /* The AP can use part of the EC flash as persistent storage. */ + EC_FEATURE_PSTORE = 8, + /* The EC monitors BIOS port 80h, and can return POST codes. */ + EC_FEATURE_PORT80 = 9, + /* + * Thermal management: include TMP specific commands. + * Higher level than direct fan control. + */ + EC_FEATURE_THERMAL = 10, + /* Can switch the screen backlight on/off */ + EC_FEATURE_BKLIGHT_SWITCH = 11, + /* Can switch the wifi module on/off */ + EC_FEATURE_WIFI_SWITCH = 12, + /* Monitor host events, through for example SMI or SCI */ + EC_FEATURE_HOST_EVENTS = 13, + /* The EC exposes GPIO commands to control/monitor connected devices. */ + EC_FEATURE_GPIO = 14, + /* The EC can send i2c messages to downstream devices. */ + EC_FEATURE_I2C = 15, + /* Command to control charger are included */ + EC_FEATURE_CHARGER = 16, + /* Simple battery support. */ + EC_FEATURE_BATTERY = 17, + /* + * Support Smart battery protocol + * (Common Smart Battery System Interface Specification) + */ + EC_FEATURE_SMART_BATTERY = 18, + /* EC can dectect when the host hangs. */ + EC_FEATURE_HANG_DETECT = 19, + /* Report power information, for pit only */ + EC_FEATURE_PMU = 20, + /* Another Cros EC device is present downstream of this one */ + EC_FEATURE_SUB_MCU = 21, + /* Support USB Power delivery (PD) commands */ + EC_FEATURE_USB_PD = 22, + /* Control USB multiplexer, for audio through USB port for instance. */ + EC_FEATURE_USB_MUX = 23 +}; + +#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32)) +#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32)) +struct ec_response_get_features { + uint32_t flags[2]; +} __packed; /*****************************************************************************/ /* Flash commands */ @@ -2272,7 +2354,7 @@ enum gpio_get_subcmd { /* * TODO(crosbug.com/p/23570): These commands are deprecated, and will be - * removed soon. Use EC_CMD_I2C_XFER instead. + * removed soon. Use EC_CMD_I2C_PASSTHRU instead. */ /* Read I2C bus */ diff --git a/util/ectool.c b/util/ectool.c index c809464d92..9470600029 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -127,6 +127,8 @@ const char help_str[] = " Perform I2C transfer on EC's I2C bus\n" " infopddev <port>\n" " Get info about USB type-C accessory attached to port\n" + " inventory\n" + " Return the list of supported features\n" " keyscan <beat_us> <filename>\n" " Test low-level key scanning\n" " led <name> <query | auto | off | <color> | <color>=<value>...>\n" @@ -392,6 +394,58 @@ int cmd_s5(int argc, char *argv[]) return rv < 0; } +static const char * const ec_feature_names[] = { + [EC_FEATURE_LIMITED] = "Limited image, load RW for more", + [EC_FEATURE_FLASH] = "Flash", + [EC_FEATURE_PWM_FAN] = "Direct Fan power management", + [EC_FEATURE_PWM_KEYB] = "Keyboard backlight", + [EC_FEATURE_LIGHTBAR] = "Lightbar", + [EC_FEATURE_LED] = "LED", + [EC_FEATURE_MOTION_SENSE] = "Motion Sensors", + [EC_FEATURE_KEYB] = "Keyboard", + [EC_FEATURE_PSTORE] = "Host Permanent Storage", + [EC_FEATURE_PORT80] = "BIOS Port 80h access", + [EC_FEATURE_THERMAL] = "Thermal management", + [EC_FEATURE_BKLIGHT_SWITCH] = "Switch backlight on/off", + [EC_FEATURE_WIFI_SWITCH] = "Switch wifi on/off", + [EC_FEATURE_HOST_EVENTS] = "Host event", + [EC_FEATURE_GPIO] = "GPIO", + [EC_FEATURE_I2C] = "I2C master", + [EC_FEATURE_CHARGER] = "Charger", + [EC_FEATURE_BATTERY] = "Simple Battery", + [EC_FEATURE_SMART_BATTERY] = "Smart Battery", + [EC_FEATURE_HANG_DETECT] = "Host hang detection", + [EC_FEATURE_PMU] = "Power Management", + [EC_FEATURE_SUB_MCU] = "Control downstream MCU", + [EC_FEATURE_USB_PD] = "USB Cros Power Delievery", + [EC_FEATURE_USB_MUX] = "USB Multiplexer", +}; + +int cmd_inventory(int argc, char *argv[]) +{ + struct ec_response_get_features r; + int rv, i, j, idx; + + rv = ec_command(EC_CMD_GET_FEATURES, 0, NULL, 0, &r, sizeof(r)); + if (rv < 0) + return rv; + + printf("EC supported features:\n"); + for (i = 0, idx = 0; i < 2; i++) { + for (j = 0; j < 32; j++, idx++) { + if (r.flags[i] & (1 << j)) { + if (idx >= ARRAY_SIZE(ec_feature_names) || + strlen(ec_feature_names[idx]) == 0) + printf("%-4d: Unknown feature\n", idx); + else + printf("%-4d: %s support\n", + idx, ec_feature_names[idx]); + } + } + } + return 0; +} + int cmd_cmdversions(int argc, char *argv[]) { @@ -6155,6 +6209,7 @@ const struct command commands[] = { {"i2cwrite", cmd_i2c_write}, {"i2cxfer", cmd_i2c_xfer}, {"infopddev", cmd_pd_device_info}, + {"inventory", cmd_inventory}, {"led", cmd_led}, {"lightbar", cmd_lightbar}, {"keyconfig", cmd_keyconfig}, |