Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: cros_ec: rev cros_ec_commands.h

Update cros_ec_commands.h to the latest version in the EC
firmware sources and add power domain and passthru commands.

Also, update lightbar to use new command names.

Signed-off-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Acked-by: Lee Jones <lee.jones@linaro.org>
Acked-by: Olof Johansson <olof@lixom.net>
Signed-off-by: Lee Jones <lee.jones@linaro.org>

authored by

Stephen Barber and committed by
Lee Jones
256ab950 a8411784

+262 -29
+7 -7
drivers/platform/chrome/cros_ec_lightbar.c
··· 197 197 return -ENOMEM; 198 198 199 199 param = (struct ec_params_lightbar *)msg->data; 200 - param->cmd = LIGHTBAR_CMD_BRIGHTNESS; 201 - param->brightness.num = val; 200 + param->cmd = LIGHTBAR_CMD_SET_BRIGHTNESS; 201 + param->set_brightness.num = val; 202 202 ret = lb_throttle(); 203 203 if (ret) 204 204 goto exit; ··· 253 253 254 254 if (i == 4) { 255 255 param = (struct ec_params_lightbar *)msg->data; 256 - param->cmd = LIGHTBAR_CMD_RGB; 257 - param->rgb.led = val[0]; 258 - param->rgb.red = val[1]; 259 - param->rgb.green = val[2]; 260 - param->rgb.blue = val[3]; 256 + param->cmd = LIGHTBAR_CMD_SET_RGB; 257 + param->set_rgb.led = val[0]; 258 + param->set_rgb.red = val[1]; 259 + param->set_rgb.green = val[2]; 260 + param->set_rgb.blue = val[3]; 261 261 /* 262 262 * Throttle only the first of every four transactions, 263 263 * so that the user can update all four LEDs at once.
+255 -22
include/linux/mfd/cros_ec_commands.h
··· 515 515 /* 516 516 * Notes on commands: 517 517 * 518 - * Each command is an 8-byte command value. Commands which take params or 518 + * Each command is an 16-bit command value. Commands which take params or 519 519 * return response data specify structs for that data. If no struct is 520 520 * specified, the command does not input or output data, respectively. 521 521 * Parameter/response length is implicit in the structs. Some underlying ··· 966 966 /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a 967 967 * host command, but the alignment is the same regardless. Keep it that way. 968 968 */ 969 - struct lightbar_params { 969 + struct lightbar_params_v0 { 970 970 /* Timing */ 971 971 int32_t google_ramp_up; 972 972 int32_t google_ramp_down; ··· 1000 1000 struct rgb_s color[8]; /* 0-3 are Google colors */ 1001 1001 } __packed; 1002 1002 1003 + struct lightbar_params_v1 { 1004 + /* Timing */ 1005 + int32_t google_ramp_up; 1006 + int32_t google_ramp_down; 1007 + int32_t s3s0_ramp_up; 1008 + int32_t s0_tick_delay[2]; /* AC=0/1 */ 1009 + int32_t s0a_tick_delay[2]; /* AC=0/1 */ 1010 + int32_t s0s3_ramp_down; 1011 + int32_t s3_sleep_for; 1012 + int32_t s3_ramp_up; 1013 + int32_t s3_ramp_down; 1014 + int32_t tap_tick_delay; 1015 + int32_t tap_display_time; 1016 + 1017 + /* Tap-for-battery params */ 1018 + uint8_t tap_pct_red; 1019 + uint8_t tap_pct_green; 1020 + uint8_t tap_seg_min_on; 1021 + uint8_t tap_seg_max_on; 1022 + uint8_t tap_seg_osc; 1023 + uint8_t tap_idx[3]; 1024 + 1025 + /* Oscillation */ 1026 + uint8_t osc_min[2]; /* AC=0/1 */ 1027 + uint8_t osc_max[2]; /* AC=0/1 */ 1028 + uint8_t w_ofs[2]; /* AC=0/1 */ 1029 + 1030 + /* Brightness limits based on the backlight and AC. */ 1031 + uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ 1032 + uint8_t bright_bl_on_min[2]; /* AC=0/1 */ 1033 + uint8_t bright_bl_on_max[2]; /* AC=0/1 */ 1034 + 1035 + /* Battery level thresholds */ 1036 + uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; 1037 + 1038 + /* Map [AC][battery_level] to color index */ 1039 + uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ 1040 + uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ 1041 + 1042 + /* Color palette */ 1043 + struct rgb_s color[8]; /* 0-3 are Google colors */ 1044 + } __packed; 1045 + 1003 1046 struct ec_params_lightbar { 1004 1047 uint8_t cmd; /* Command (see enum lightbar_command) */ 1005 1048 union { 1006 1049 struct { 1007 1050 /* no args */ 1008 - } dump, off, on, init, get_seq, get_params, version; 1051 + } dump, off, on, init, get_seq, get_params_v0, get_params_v1, 1052 + version, get_brightness, get_demo; 1009 1053 1010 - struct num { 1054 + struct { 1011 1055 uint8_t num; 1012 - } brightness, seq, demo; 1056 + } set_brightness, seq, demo; 1013 1057 1014 - struct reg { 1058 + struct { 1015 1059 uint8_t ctrl, reg, value; 1016 1060 } reg; 1017 1061 1018 - struct rgb { 1062 + struct { 1019 1063 uint8_t led, red, green, blue; 1020 - } rgb; 1064 + } set_rgb; 1021 1065 1022 - struct lightbar_params set_params; 1066 + struct { 1067 + uint8_t led; 1068 + } get_rgb; 1069 + 1070 + struct lightbar_params_v0 set_params_v0; 1071 + struct lightbar_params_v1 set_params_v1; 1023 1072 }; 1024 1073 } __packed; 1025 1074 1026 1075 struct ec_response_lightbar { 1027 1076 union { 1028 - struct dump { 1077 + struct { 1029 1078 struct { 1030 1079 uint8_t reg; 1031 1080 uint8_t ic0; ··· 1082 1033 } vals[23]; 1083 1034 } dump; 1084 1035 1085 - struct get_seq { 1036 + struct { 1086 1037 uint8_t num; 1087 - } get_seq; 1038 + } get_seq, get_brightness, get_demo; 1088 1039 1089 - struct lightbar_params get_params; 1040 + struct lightbar_params_v0 get_params_v0; 1041 + struct lightbar_params_v1 get_params_v1; 1090 1042 1091 - struct version { 1043 + struct { 1092 1044 uint32_t num; 1093 1045 uint32_t flags; 1094 1046 } version; 1095 1047 1096 1048 struct { 1049 + uint8_t red, green, blue; 1050 + } get_rgb; 1051 + 1052 + struct { 1097 1053 /* no return params */ 1098 - } off, on, init, brightness, seq, reg, rgb, demo, set_params; 1054 + } off, on, init, set_brightness, seq, reg, set_rgb, 1055 + demo, set_params_v0, set_params_v1; 1099 1056 }; 1100 1057 } __packed; 1101 1058 ··· 1111 1056 LIGHTBAR_CMD_OFF = 1, 1112 1057 LIGHTBAR_CMD_ON = 2, 1113 1058 LIGHTBAR_CMD_INIT = 3, 1114 - LIGHTBAR_CMD_BRIGHTNESS = 4, 1059 + LIGHTBAR_CMD_SET_BRIGHTNESS = 4, 1115 1060 LIGHTBAR_CMD_SEQ = 5, 1116 1061 LIGHTBAR_CMD_REG = 6, 1117 - LIGHTBAR_CMD_RGB = 7, 1062 + LIGHTBAR_CMD_SET_RGB = 7, 1118 1063 LIGHTBAR_CMD_GET_SEQ = 8, 1119 1064 LIGHTBAR_CMD_DEMO = 9, 1120 - LIGHTBAR_CMD_GET_PARAMS = 10, 1121 - LIGHTBAR_CMD_SET_PARAMS = 11, 1065 + LIGHTBAR_CMD_GET_PARAMS_V0 = 10, 1066 + LIGHTBAR_CMD_SET_PARAMS_V0 = 11, 1122 1067 LIGHTBAR_CMD_VERSION = 12, 1068 + LIGHTBAR_CMD_GET_BRIGHTNESS = 13, 1069 + LIGHTBAR_CMD_GET_RGB = 14, 1070 + LIGHTBAR_CMD_GET_DEMO = 15, 1071 + LIGHTBAR_CMD_GET_PARAMS_V1 = 16, 1072 + LIGHTBAR_CMD_SET_PARAMS_V1 = 17, 1123 1073 LIGHTBAR_NUM_CMDS 1124 1074 }; 1125 1075 ··· 1481 1421 /*****************************************************************************/ 1482 1422 /* Port80 log access */ 1483 1423 1424 + /* Maximum entries that can be read/written in a single command */ 1425 + #define EC_PORT80_SIZE_MAX 32 1426 + 1484 1427 /* Get last port80 code from previous boot */ 1485 1428 #define EC_CMD_PORT80_LAST_BOOT 0x48 1429 + #define EC_CMD_PORT80_READ 0x48 1430 + 1431 + enum ec_port80_subcmd { 1432 + EC_PORT80_GET_INFO = 0, 1433 + EC_PORT80_READ_BUFFER, 1434 + }; 1435 + 1436 + struct ec_params_port80_read { 1437 + uint16_t subcmd; 1438 + union { 1439 + struct { 1440 + uint32_t offset; 1441 + uint32_t num_entries; 1442 + } read_buffer; 1443 + }; 1444 + } __packed; 1445 + 1446 + struct ec_response_port80_read { 1447 + union { 1448 + struct { 1449 + uint32_t writes; 1450 + uint32_t history_size; 1451 + uint32_t last_boot; 1452 + } get_info; 1453 + struct { 1454 + uint16_t codes[EC_PORT80_SIZE_MAX]; 1455 + } data; 1456 + }; 1457 + } __packed; 1486 1458 1487 1459 struct ec_response_port80_last_boot { 1488 1460 uint16_t code; ··· 1874 1782 /* Get GPIO value */ 1875 1783 #define EC_CMD_GPIO_GET 0x93 1876 1784 1785 + /* Version 0 of input params and response */ 1877 1786 struct ec_params_gpio_get { 1878 1787 char name[32]; 1879 1788 } __packed; 1880 1789 struct ec_response_gpio_get { 1881 1790 uint8_t val; 1882 1791 } __packed; 1792 + 1793 + /* Version 1 of input params and response */ 1794 + struct ec_params_gpio_get_v1 { 1795 + uint8_t subcmd; 1796 + union { 1797 + struct { 1798 + char name[32]; 1799 + } get_value_by_name; 1800 + struct { 1801 + uint8_t index; 1802 + } get_info; 1803 + }; 1804 + } __packed; 1805 + 1806 + struct ec_response_gpio_get_v1 { 1807 + union { 1808 + struct { 1809 + uint8_t val; 1810 + } get_value_by_name, get_count; 1811 + struct { 1812 + uint8_t val; 1813 + char name[32]; 1814 + uint32_t flags; 1815 + } get_info; 1816 + }; 1817 + } __packed; 1818 + 1819 + enum gpio_get_subcmd { 1820 + EC_GPIO_GET_BY_NAME = 0, 1821 + EC_GPIO_GET_COUNT = 1, 1822 + EC_GPIO_GET_INFO = 2, 1823 + }; 1883 1824 1884 1825 /*****************************************************************************/ 1885 1826 /* I2C commands. Only available when flash write protect is unlocked. */ ··· 1982 1857 /*****************************************************************************/ 1983 1858 1984 1859 /* 1985 - * Cut off battery power output if the battery supports. 1860 + * Cut off battery power immediately or after the host has shut down. 1986 1861 * 1987 - * For unsupported battery, just don't implement this command and lets EC 1988 - * return EC_RES_INVALID_COMMAND. 1862 + * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. 1863 + * EC_RES_SUCCESS if the command was successful. 1864 + * EC_RES_ERROR if the cut off command failed. 1989 1865 */ 1866 + 1990 1867 #define EC_CMD_BATTERY_CUT_OFF 0x99 1868 + 1869 + #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0) 1870 + 1871 + struct ec_params_battery_cutoff { 1872 + uint8_t flags; 1873 + } __packed; 1991 1874 1992 1875 /*****************************************************************************/ 1993 1876 /* USB port mux control. */ ··· 2275 2142 } __packed; 2276 2143 2277 2144 /*****************************************************************************/ 2145 + /* Battery vendor parameters 2146 + * 2147 + * Get or set vendor-specific parameters in the battery. Implementations may 2148 + * differ between boards or batteries. On a set operation, the response 2149 + * contains the actual value set, which may be rounded or clipped from the 2150 + * requested value. 2151 + */ 2152 + 2153 + #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4 2154 + 2155 + enum ec_battery_vendor_param_mode { 2156 + BATTERY_VENDOR_PARAM_MODE_GET = 0, 2157 + BATTERY_VENDOR_PARAM_MODE_SET, 2158 + }; 2159 + 2160 + struct ec_params_battery_vendor_param { 2161 + uint32_t param; 2162 + uint32_t value; 2163 + uint8_t mode; 2164 + } __packed; 2165 + 2166 + struct ec_response_battery_vendor_param { 2167 + uint32_t value; 2168 + } __packed; 2169 + 2170 + /*****************************************************************************/ 2278 2171 /* System commands */ 2279 2172 2280 2173 /* ··· 2494 2335 #define EC_CMD_VERSION0 0xdc 2495 2336 2496 2337 #endif /* !__ACPI__ */ 2338 + 2339 + /*****************************************************************************/ 2340 + /* 2341 + * PD commands 2342 + * 2343 + * These commands are for PD MCU communication. 2344 + */ 2345 + 2346 + /* EC to PD MCU exchange status command */ 2347 + #define EC_CMD_PD_EXCHANGE_STATUS 0x100 2348 + 2349 + /* Status of EC being sent to PD */ 2350 + struct ec_params_pd_status { 2351 + int8_t batt_soc; /* battery state of charge */ 2352 + } __packed; 2353 + 2354 + /* Status of PD being sent back to EC */ 2355 + struct ec_response_pd_status { 2356 + int8_t status; /* PD MCU status */ 2357 + uint32_t curr_lim_ma; /* input current limit */ 2358 + } __packed; 2359 + 2360 + /* Set USB type-C port role and muxes */ 2361 + #define EC_CMD_USB_PD_CONTROL 0x101 2362 + 2363 + enum usb_pd_control_role { 2364 + USB_PD_CTRL_ROLE_NO_CHANGE = 0, 2365 + USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ 2366 + USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, 2367 + USB_PD_CTRL_ROLE_FORCE_SINK = 3, 2368 + USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, 2369 + }; 2370 + 2371 + enum usb_pd_control_mux { 2372 + USB_PD_CTRL_MUX_NO_CHANGE = 0, 2373 + USB_PD_CTRL_MUX_NONE = 1, 2374 + USB_PD_CTRL_MUX_USB = 2, 2375 + USB_PD_CTRL_MUX_DP = 3, 2376 + USB_PD_CTRL_MUX_DOCK = 4, 2377 + USB_PD_CTRL_MUX_AUTO = 5, 2378 + }; 2379 + 2380 + struct ec_params_usb_pd_control { 2381 + uint8_t port; 2382 + uint8_t role; 2383 + uint8_t mux; 2384 + } __packed; 2385 + 2386 + /*****************************************************************************/ 2387 + /* 2388 + * Passthru commands 2389 + * 2390 + * Some platforms have sub-processors chained to each other. For example. 2391 + * 2392 + * AP <--> EC <--> PD MCU 2393 + * 2394 + * The top 2 bits of the command number are used to indicate which device the 2395 + * command is intended for. Device 0 is always the device receiving the 2396 + * command; other device mapping is board-specific. 2397 + * 2398 + * When a device receives a command to be passed to a sub-processor, it passes 2399 + * it on with the device number set back to 0. This allows the sub-processor 2400 + * to remain blissfully unaware of whether the command originated on the next 2401 + * device up the chain, or was passed through from the AP. 2402 + * 2403 + * In the above example, if the AP wants to send command 0x0002 to the PD MCU, 2404 + * AP sends command 0x4002 to the EC 2405 + * EC sends command 0x0002 to the PD MCU 2406 + * EC forwards PD MCU response back to the AP 2407 + */ 2408 + 2409 + /* Offset and max command number for sub-device n */ 2410 + #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) 2411 + #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) 2497 2412 2498 2413 /*****************************************************************************/ 2499 2414 /*