Angel Pons | 210a008 | 2020-04-02 23:48:24 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | b0bf280 | 2018-10-15 02:18:03 +0000 | [diff] [blame] | 2 | |
| 3 | #ifndef EC_GOOGLE_WILCO_COMMANDS_H |
| 4 | #define EC_GOOGLE_WILCO_COMMANDS_H |
| 5 | |
Duncan Laurie | 2f95492 | 2018-10-15 02:28:54 +0000 | [diff] [blame] | 6 | #include <types.h> |
Duncan Laurie | b0bf280 | 2018-10-15 02:18:03 +0000 | [diff] [blame] | 7 | |
| 8 | enum { |
Duncan Laurie | 2f95492 | 2018-10-15 02:28:54 +0000 | [diff] [blame] | 9 | /* Read and clear power state information */ |
| 10 | KB_POWER_SMI = 0x04, |
| 11 | /* Read but do not clear power state information */ |
| 12 | KB_POWER_STATUS = 0x05, |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 13 | /* Inform the EC about the reason host is turning off */ |
Duncan Laurie | 2f95492 | 2018-10-15 02:28:54 +0000 | [diff] [blame] | 14 | KB_POWER_OFF = 0x08, |
Duncan Laurie | 57f22f6 | 2018-11-17 12:17:04 -0700 | [diff] [blame] | 15 | /* Control wireless radios */ |
| 16 | KB_RADIO_CONTROL = 0x2b, |
Duncan Laurie | 3fbe194 | 2018-10-15 13:39:35 -0700 | [diff] [blame] | 17 | /* Save PS/2 data before S3 suspend */ |
| 18 | KB_SAVE = 0x2f, |
| 19 | /* Restore PS/2 data after S3 resume */ |
| 20 | KB_RESTORE = 0x30, |
Duncan Laurie | 221ebdc | 2018-11-29 17:59:04 -0800 | [diff] [blame] | 21 | /* Manage the EC control of camera power */ |
| 22 | KB_CAMERA = 0x33, |
Duncan Laurie | b0bf280 | 2018-10-15 02:18:03 +0000 | [diff] [blame] | 23 | /* Retrieve information about the EC */ |
| 24 | KB_EC_INFO = 0x38, |
| 25 | /* Set ACPI mode on or off */ |
| 26 | KB_ACPI = 0x3a, |
Duncan Laurie | b34de93 | 2019-04-10 18:43:56 -0700 | [diff] [blame] | 27 | /* Board ID */ |
| 28 | KB_BOARD_ID = 0x3d, |
Lijian Zhao | a31872c | 2019-01-10 19:31:15 -0800 | [diff] [blame] | 29 | /* Change ACPI wake up source */ |
| 30 | KB_ACPI_WAKEUP_CHANGE = 0x4a, |
Duncan Laurie | b0bf280 | 2018-10-15 02:18:03 +0000 | [diff] [blame] | 31 | /* Manage the EC power button passthru to the host */ |
| 32 | KB_POWER_BUTTON_TO_HOST = 0x3e, |
Duncan Laurie | 29f2b25 | 2018-10-19 17:01:31 -0700 | [diff] [blame] | 33 | /* Manage the EC control of speaker mute */ |
| 34 | KB_HW_MUTE_CONTROL = 0x60, |
Duncan Laurie | 2f95492 | 2018-10-15 02:28:54 +0000 | [diff] [blame] | 35 | /* Inform the EC that the host is about to enter S3 */ |
| 36 | KB_SLP_EN = 0x64, |
Duncan Laurie | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 37 | /* Inform the EC about BIOS boot progress */ |
| 38 | KB_BIOS_PROGRESS = 0xc2, |
Keith Short | 8ef6732 | 2019-05-10 11:49:24 -0600 | [diff] [blame] | 39 | /* Inform the EC that a fatal error occurred */ |
| 40 | KB_ERR_CODE = 0x7b, |
Eric Lai | f74b6e3 | 2020-01-23 14:43:08 +0800 | [diff] [blame] | 41 | /* Set CPU ID */ |
| 42 | KB_CPU_ID = 0xbf, |
Duncan Laurie | b0bf280 | 2018-10-15 02:18:03 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
Duncan Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 45 | enum ec_ram_addr { |
Duncan Laurie | 32346f0 | 2019-03-20 12:51:07 -0700 | [diff] [blame] | 46 | /* Indicate if EC uses signed firmware */ |
| 47 | EC_RAM_SIGNED_FW = 0x5c, |
Duncan Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 48 | /* Indicate support for S0ix */ |
| 49 | EC_RAM_S0IX_SUPPORT = 0xb8, |
| 50 | }; |
| 51 | |
Duncan Laurie | b0bf280 | 2018-10-15 02:18:03 +0000 | [diff] [blame] | 52 | enum set_acpi_mode_cmd { |
| 53 | ACPI_OFF = 0, |
| 54 | ACPI_ON |
| 55 | }; |
| 56 | |
Duncan Laurie | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 57 | enum bios_progress_code { |
Duncan Laurie | 3135467 | 2019-03-27 19:28:17 -0700 | [diff] [blame] | 58 | BIOS_PROGRESS_BEFORE_MEMORY = 0x00, |
Duncan Laurie | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 59 | BIOS_PROGRESS_MEMORY_INIT = 0x01, |
| 60 | BIOS_PROGRESS_VIDEO_INIT = 0x02, |
| 61 | BIOS_PROGRESS_LOGO_DISPLAYED = 0x03, |
| 62 | BIOS_PROGRESS_POST_COMPLETE = 0x04, |
| 63 | }; |
| 64 | |
Duncan Laurie | 29f2b25 | 2018-10-19 17:01:31 -0700 | [diff] [blame] | 65 | enum ec_audio_mute { |
| 66 | AUDIO_MUTE = 0, /* Mute speakers immediately */ |
| 67 | AUDIO_UNMUTE_125MS, /* Unmute in 125ms */ |
| 68 | }; |
| 69 | |
Duncan Laurie | 57f22f6 | 2018-11-17 12:17:04 -0700 | [diff] [blame] | 70 | enum ec_radio { |
Duncan Laurie | 35f9507 | 2019-05-23 14:48:29 -0700 | [diff] [blame] | 71 | RADIO_WIFI = 0, |
| 72 | RADIO_WWAN, |
| 73 | RADIO_BT, |
| 74 | }; |
| 75 | |
| 76 | enum ec_radio_action { |
| 77 | RADIO_READ = 1, |
| 78 | RADIO_WRITE, |
| 79 | RADIO_TOGGLE, |
Duncan Laurie | 57f22f6 | 2018-11-17 12:17:04 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Duncan Laurie | 221ebdc | 2018-11-29 17:59:04 -0800 | [diff] [blame] | 82 | enum ec_camera { |
| 83 | CAMERA_ON = 0, |
| 84 | CAMERA_OFF |
| 85 | }; |
| 86 | |
Keith Short | 8ef6732 | 2019-05-10 11:49:24 -0600 | [diff] [blame] | 87 | enum ec_err_code { |
| 88 | DLED_MEMORY = 0x03, |
| 89 | DLED_PANEL = 0x10, |
| 90 | DLED_ROM = 0x19, |
| 91 | }; |
| 92 | |
Duncan Laurie | 57f22f6 | 2018-11-17 12:17:04 -0700 | [diff] [blame] | 93 | /** |
| 94 | * wilco_ec_radio_control() - Control wireless radios. |
| 95 | * @ec_radio: Wireless radio type. |
| 96 | * @state: Turn radio on or off. |
| 97 | * Return: 0 if successful or negative error code on failure. |
| 98 | */ |
| 99 | int wilco_ec_radio_control(enum ec_radio radio, uint8_t state); |
| 100 | |
Duncan Laurie | b0bf280 | 2018-10-15 02:18:03 +0000 | [diff] [blame] | 101 | /* |
| 102 | * EC Information |
| 103 | */ |
| 104 | |
| 105 | enum get_ec_info_cmd { |
| 106 | GET_EC_LABEL = 0, |
| 107 | GET_EC_SVN_REV, |
| 108 | GET_EC_MODEL_NO, |
| 109 | GET_EC_BUILD_DATE |
| 110 | }; |
| 111 | |
| 112 | #define EC_INFO_MAX_SIZE 9 |
| 113 | struct ec_response_get_ec_info { |
| 114 | char data[EC_INFO_MAX_SIZE]; /* ASCII NUL terminated string */ |
| 115 | }; |
| 116 | |
| 117 | /** |
| 118 | * wilco_ec_get_info |
| 119 | * |
| 120 | * Read a specific information string from the EC and return it in |
| 121 | * the caller-provided buffer of at least EC_INFO_MAX_SIZE bytes. |
| 122 | * |
| 123 | * @cmd: Information to retrieve |
| 124 | * @info: Character array of EC_INFO_MAX_SIZE bytes |
| 125 | * |
| 126 | * Returns 0 if successful and resulting string is in 'info' |
| 127 | * Returns -1 if the EC command fails |
| 128 | */ |
| 129 | int wilco_ec_get_info(enum get_ec_info_cmd cmd, char *info); |
| 130 | |
| 131 | /** |
| 132 | * wilco_ec_print_all_info |
| 133 | * |
| 134 | * Retrieve and print all the information strings from the EC: |
| 135 | * |
| 136 | * GET_EC_LABEL |
| 137 | * GET_EC_SVN_REV |
| 138 | * GET_EC_MODEL_NO |
| 139 | * GET_EC_BUILD_DATE |
| 140 | */ |
| 141 | void wilco_ec_print_all_info(void); |
| 142 | |
Duncan Laurie | 2f95492 | 2018-10-15 02:28:54 +0000 | [diff] [blame] | 143 | /* |
| 144 | * EC Power State |
| 145 | */ |
| 146 | |
| 147 | enum ec_power_off_reason { |
| 148 | EC_PWROFF_FLASH = 0x11, |
| 149 | EC_PWROFF_AC_REMOVED = 0x12, |
| 150 | EC_PWROFF_BAT_REMOVED = 0x13, |
| 151 | EC_PWROFF_LOBAT = 0x15, |
| 152 | EC_PWROFF_PWRB_IN_POST = 0x16, |
| 153 | EC_PWROFF_FORCE_IMMEDIATE = 0x18, |
| 154 | EC_PWROFF_WDT = 0x1b, |
| 155 | EC_PWROFF_FORCE_THERMAL = 0x22, |
| 156 | EC_PWROFF_ERR_CODE = 0x23, |
| 157 | EC_PWROFF_PAID_PWRGD = 0x27, |
| 158 | EC_PWROFF_PAID_CPU = 0x28, |
| 159 | EC_PWROFF_PAID_GFX = 0x29, |
| 160 | EC_PWROFF_PAID_CLK = 0x2a, |
| 161 | EC_PWROFF_PAID_NOMEMORY = 0x2b, |
| 162 | EC_PWROFF_PAID_MEMORY_ERR = 0x2c, |
| 163 | EC_PWROFF_PAID_MEMORY_SPD = 0x2d, |
| 164 | EC_SWOFF_ACPI = 0x31, |
| 165 | EC_SWOFF_BOOT_PASSWORD = 0x33, |
| 166 | EC_SWOFF_DISK_PASSWORD = 0x34, |
| 167 | EC_SWOFF_POWER_CYCLE = 0x37, |
| 168 | EC_SWOFF_HARD_RESET = 0x3b, |
| 169 | EC_SWOFF_FSMI = 0x3f, |
| 170 | EC_PWRLOG_THERMTRIP = 0x41, |
| 171 | EC_PWRLOG_NO_S5 = 0x42, |
| 172 | EC_PWROFF_4S_PWRB = 0x44, |
| 173 | EC_PWROFF_ASF2_FORCEOFF = 0x45, |
| 174 | EC_PWROFF_PWRB_THERMAL = 0x48, |
| 175 | EC_PWROFF_AOAC_TIMER = 0x4b, |
| 176 | }; |
| 177 | |
| 178 | /** |
| 179 | * wilco_ec_power_off |
| 180 | * |
| 181 | * Tell the EC why the host is about to power off. |
| 182 | */ |
| 183 | void wilco_ec_power_off(enum ec_power_off_reason reason); |
| 184 | |
| 185 | /** |
| 186 | * wilco_ec_slp_en |
| 187 | * |
| 188 | * Tell the EC that the host is entering a sleep state. |
| 189 | */ |
| 190 | void wilco_ec_slp_en(void); |
| 191 | |
| 192 | enum ec_pm1_state { |
| 193 | EC_PM1_AC_AVAIL = BIT(0), /* AC available */ |
| 194 | EC_PM1_BAT_AVAIL = BIT(1), /* Battery available */ |
| 195 | EC_PM1_LO_BAT1 = BIT(2), /* Battery 1 low */ |
| 196 | EC_PM1_LO_BAT2 = BIT(3), /* Battery 2 low */ |
| 197 | EC_PM1_LID_OPEN = BIT(4), /* Lid is open */ |
| 198 | EC_PM1_LCD_POWER = BIT(5), /* LCD is powered */ |
| 199 | EC_PM1_OVER_TEMP = BIT(6), /* CPU is over temperature */ |
| 200 | EC_PM1_DOCKED = BIT(7), /* System is docked */ |
| 201 | }; |
| 202 | |
| 203 | enum ec_pm2_state { |
| 204 | EC_PM2_SYS_MB_PCIE = BIT(0), /* MB has PCIe */ |
| 205 | EC_PM2_SYS_MB_SATA = BIT(1), /* MB has SATA */ |
| 206 | EC_PM2_PWRB_PRESSED = BIT(2), /* Power button is pressed */ |
| 207 | EC_PM2_TURBO_MODE = BIT(3), /* Turbo mode */ |
| 208 | }; |
| 209 | |
| 210 | enum ec_pm3_state { |
| 211 | EC_PM3_BAT1_PRES = BIT(2), /* Battery 1 is present */ |
| 212 | EC_PM3_BAT2_PRES = BIT(3), /* Battery 2 is present */ |
| 213 | EC_PM3_LOWER_PSTATE = BIT(6), /* EC requests lower P-state */ |
| 214 | EC_PM3_CPU_THROTTLE = BIT(7), /* EC requests CPU throttle */ |
| 215 | }; |
| 216 | |
| 217 | enum ec_pm4_state { |
| 218 | EC_PM4_BAT1_CHG = BIT(0), /* Battery 1 is being charged */ |
| 219 | EC_PM4_BAT2_CHG = BIT(1), /* Battery 2 is being charged */ |
| 220 | EC_PM4_BAT1_PWR = BIT(2), /* Battery 1 is powering the system */ |
| 221 | EC_PM4_BAT2_PWR = BIT(3), /* Battery 2 is powering the system */ |
| 222 | EC_PM4_PANEL_STATE = BIT(5), /* Panel power state */ |
| 223 | }; |
| 224 | |
| 225 | enum ec_pm5_state { |
| 226 | EC_PM5_INT_HD_SATA = BIT(7), /* Internal SATA HDD */ |
| 227 | }; |
| 228 | |
| 229 | enum ec_pm6_state { |
| 230 | EC_PM6_WLAN_SWITCH = BIT(0), /* Wireless switch */ |
| 231 | EC_PM6_SYS_MB_MODEM = BIT(1), /* MB has modem */ |
| 232 | EC_PM6_ETH_STATE = BIT(2), /* Ethernet cable state */ |
| 233 | EC_PM6_AC_UPDATE = BIT(3), /* Update AC information */ |
| 234 | }; |
| 235 | |
| 236 | enum ec_pm1_event { |
| 237 | EC_EV1_PWRB_PRESSED = BIT(0), /* Power button was pressed */ |
| 238 | EC_EV1_HOTKEY_PRESSED = BIT(1), /* Hotkey was pressed */ |
| 239 | EC_EV1_STATE_CHANGED = BIT(2), /* PMx state changed */ |
| 240 | }; |
| 241 | |
| 242 | enum ec_pm2_event { |
| 243 | EC_EV2_ACPI_MONSWITCH = BIT(0), /* Monitor switch status */ |
| 244 | }; |
| 245 | |
| 246 | struct ec_pm_event_state { |
| 247 | uint8_t event[2]; /* ec_pm{1,2}_event */ |
| 248 | uint8_t state[6]; /* ec_pm{1,2,3,4,5,6}_state */ |
| 249 | uint8_t hotkey; /* Hotkey, if pressed */ |
| 250 | uint16_t ac_type; /* AC adapter information */ |
| 251 | }; |
| 252 | |
| 253 | /** |
| 254 | * wilco_ec_get_pm |
| 255 | * |
| 256 | * Retrieve power and event information from the EC. |
| 257 | * |
| 258 | * @pm: Power event state structure to fill out |
| 259 | * @clear: Clear EC event state after reading |
| 260 | * |
| 261 | * Returns 0 if EC command was successful |
| 262 | * Returns -1 if EC command failed |
| 263 | */ |
| 264 | int wilco_ec_get_pm(struct ec_pm_event_state *pm, bool clear); |
| 265 | |
| 266 | /** |
| 267 | * wilco_ec_get_lid_state |
| 268 | * |
| 269 | * Retrieve the lid state without clearing it in the EC. |
| 270 | * |
| 271 | * Returns 1 if the lid is open, 0 if it is closed |
| 272 | * Returns -1 if the EC command failed |
| 273 | */ |
| 274 | int wilco_ec_get_lid_state(void); |
| 275 | |
Duncan Laurie | b34de93 | 2019-04-10 18:43:56 -0700 | [diff] [blame] | 276 | /** |
| 277 | * wilco_ec_get_board_id |
| 278 | * |
| 279 | * Retrieve the board ID value from the EC. |
| 280 | * @id: Pointer to variable to store the ID read from the EC. |
| 281 | * |
| 282 | * Returns number of bytes transferred from the EC |
| 283 | * Returns -1 if the EC command failed |
| 284 | */ |
| 285 | int wilco_ec_get_board_id(uint8_t *id); |
| 286 | |
Lijian Zhao | a31872c | 2019-01-10 19:31:15 -0800 | [diff] [blame] | 287 | enum ec_wake_change { |
| 288 | WAKE_OFF = 0, |
| 289 | WAKE_ON |
| 290 | }; |
| 291 | /** |
| 292 | * wilco_ec_change_wake_source |
| 293 | * |
| 294 | * Change acpi wake up source. |
| 295 | * @source: Wake up source that can be enabled/disabled. |
| 296 | * @ec_wake_change: On/off switch. |
| 297 | * |
| 298 | * Returns -1 if the EC command failed |
| 299 | */ |
| 300 | int wilco_ec_change_wake(uint8_t source, enum ec_wake_change change); |
| 301 | |
| 302 | enum ec_acpi_wake_events { |
| 303 | EC_ACPI_WAKE_PWRB = BIT(0), /* Wake up by power button */ |
| 304 | EC_ACPI_WAKE_LID = BIT(1), /* Wake up by lid switch */ |
| 305 | EC_ACPI_WAKE_RTC = BIT(5), /* Wake up by RTC */ |
| 306 | }; |
| 307 | |
Duncan Laurie | 32346f0 | 2019-03-20 12:51:07 -0700 | [diff] [blame] | 308 | /** |
| 309 | * wilco_ec_signed_fw |
| 310 | * |
| 311 | * Indicate if the EC uses signed firmware. |
| 312 | * |
| 313 | * Returns 1 if EC uses signed firmware, otherwise returns 0 |
| 314 | */ |
| 315 | int wilco_ec_signed_fw(void); |
| 316 | |
Keith Short | 8ef6732 | 2019-05-10 11:49:24 -0600 | [diff] [blame] | 317 | /** |
Keith Short | f41afde | 2019-05-10 11:52:55 -0600 | [diff] [blame] | 318 | * wilco_ec_save_post_code |
Keith Short | 8ef6732 | 2019-05-10 11:49:24 -0600 | [diff] [blame] | 319 | * |
Keith Short | f41afde | 2019-05-10 11:52:55 -0600 | [diff] [blame] | 320 | * Save this post code as the most recent progress step. If the boot fails |
| 321 | * and calls die_notify() this post code will be used to send an error code |
| 322 | * to the EC indicating the failure. |
Keith Short | 8ef6732 | 2019-05-10 11:49:24 -0600 | [diff] [blame] | 323 | * |
Keith Short | f41afde | 2019-05-10 11:52:55 -0600 | [diff] [blame] | 324 | * @post_code: Post code to save |
Keith Short | 8ef6732 | 2019-05-10 11:49:24 -0600 | [diff] [blame] | 325 | */ |
Keith Short | f41afde | 2019-05-10 11:52:55 -0600 | [diff] [blame] | 326 | void wilco_ec_save_post_code(uint8_t post_code); |
Keith Short | 8ef6732 | 2019-05-10 11:49:24 -0600 | [diff] [blame] | 327 | |
Eric Lai | f74b6e3 | 2020-01-23 14:43:08 +0800 | [diff] [blame] | 328 | /** |
| 329 | * wilco_ec_set_cpuid |
| 330 | * |
| 331 | * Set CPU ID to EC. |
| 332 | * |
| 333 | * @cpuid: read CPU ID from cpu_eax(1) |
| 334 | * @cpu_cores: cores of CPU |
| 335 | * @gpu_cores: cores of GPU |
| 336 | * |
| 337 | * Returns 0 if EC command was successful |
| 338 | * Returns -1 if EC command failed |
| 339 | */ |
| 340 | int wilco_ec_set_cpuid(uint32_t cpuid, uint8_t cpu_cores, uint8_t gpu_cores); |
| 341 | |
Duncan Laurie | b0bf280 | 2018-10-15 02:18:03 +0000 | [diff] [blame] | 342 | #endif /* EC_GOOGLE_WILCO_COMMANDS_H */ |