blob: b70f949fcbb343f5fa25869f3c6edcf53e9b092c [file] [log] [blame]
Angel Pons210a0082020-04-02 23:48:24 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Laurieb0bf2802018-10-15 02:18:03 +00002
3#ifndef EC_GOOGLE_WILCO_COMMANDS_H
4#define EC_GOOGLE_WILCO_COMMANDS_H
5
Duncan Laurie2f954922018-10-15 02:28:54 +00006#include <types.h>
Duncan Laurieb0bf2802018-10-15 02:18:03 +00007
8enum {
Duncan Laurie2f954922018-10-15 02:28:54 +00009 /* 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 Roth0949e732021-10-01 14:28:22 -060013 /* Inform the EC about the reason host is turning off */
Duncan Laurie2f954922018-10-15 02:28:54 +000014 KB_POWER_OFF = 0x08,
Duncan Laurie57f22f62018-11-17 12:17:04 -070015 /* Control wireless radios */
16 KB_RADIO_CONTROL = 0x2b,
Duncan Laurie3fbe1942018-10-15 13:39:35 -070017 /* Save PS/2 data before S3 suspend */
18 KB_SAVE = 0x2f,
19 /* Restore PS/2 data after S3 resume */
20 KB_RESTORE = 0x30,
Duncan Laurie221ebdc2018-11-29 17:59:04 -080021 /* Manage the EC control of camera power */
22 KB_CAMERA = 0x33,
Duncan Laurieb0bf2802018-10-15 02:18:03 +000023 /* Retrieve information about the EC */
24 KB_EC_INFO = 0x38,
25 /* Set ACPI mode on or off */
26 KB_ACPI = 0x3a,
Duncan Laurieb34de932019-04-10 18:43:56 -070027 /* Board ID */
28 KB_BOARD_ID = 0x3d,
Lijian Zhaoa31872c2019-01-10 19:31:15 -080029 /* Change ACPI wake up source */
30 KB_ACPI_WAKEUP_CHANGE = 0x4a,
Duncan Laurieb0bf2802018-10-15 02:18:03 +000031 /* Manage the EC power button passthru to the host */
32 KB_POWER_BUTTON_TO_HOST = 0x3e,
Duncan Laurie29f2b252018-10-19 17:01:31 -070033 /* Manage the EC control of speaker mute */
34 KB_HW_MUTE_CONTROL = 0x60,
Duncan Laurie2f954922018-10-15 02:28:54 +000035 /* Inform the EC that the host is about to enter S3 */
36 KB_SLP_EN = 0x64,
Duncan Laurie421a9622018-10-15 02:46:45 +000037 /* Inform the EC about BIOS boot progress */
38 KB_BIOS_PROGRESS = 0xc2,
Keith Short8ef67322019-05-10 11:49:24 -060039 /* Inform the EC that a fatal error occurred */
40 KB_ERR_CODE = 0x7b,
Eric Laif74b6e32020-01-23 14:43:08 +080041 /* Set CPU ID */
42 KB_CPU_ID = 0xbf,
Duncan Laurieb0bf2802018-10-15 02:18:03 +000043};
44
Duncan Laurie90a96c72019-03-13 17:35:22 -070045enum ec_ram_addr {
Duncan Laurie32346f02019-03-20 12:51:07 -070046 /* Indicate if EC uses signed firmware */
47 EC_RAM_SIGNED_FW = 0x5c,
Duncan Laurie90a96c72019-03-13 17:35:22 -070048 /* Indicate support for S0ix */
49 EC_RAM_S0IX_SUPPORT = 0xb8,
50};
51
Duncan Laurieb0bf2802018-10-15 02:18:03 +000052enum set_acpi_mode_cmd {
53 ACPI_OFF = 0,
54 ACPI_ON
55};
56
Duncan Laurie421a9622018-10-15 02:46:45 +000057enum bios_progress_code {
Duncan Laurie31354672019-03-27 19:28:17 -070058 BIOS_PROGRESS_BEFORE_MEMORY = 0x00,
Duncan Laurie421a9622018-10-15 02:46:45 +000059 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 Laurie29f2b252018-10-19 17:01:31 -070065enum ec_audio_mute {
66 AUDIO_MUTE = 0, /* Mute speakers immediately */
67 AUDIO_UNMUTE_125MS, /* Unmute in 125ms */
68};
69
Duncan Laurie57f22f62018-11-17 12:17:04 -070070enum ec_radio {
Duncan Laurie35f95072019-05-23 14:48:29 -070071 RADIO_WIFI = 0,
72 RADIO_WWAN,
73 RADIO_BT,
74};
75
76enum ec_radio_action {
77 RADIO_READ = 1,
78 RADIO_WRITE,
79 RADIO_TOGGLE,
Duncan Laurie57f22f62018-11-17 12:17:04 -070080};
81
Duncan Laurie221ebdc2018-11-29 17:59:04 -080082enum ec_camera {
83 CAMERA_ON = 0,
84 CAMERA_OFF
85};
86
Keith Short8ef67322019-05-10 11:49:24 -060087enum ec_err_code {
88 DLED_MEMORY = 0x03,
89 DLED_PANEL = 0x10,
90 DLED_ROM = 0x19,
91};
92
Duncan Laurie57f22f62018-11-17 12:17:04 -070093/**
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 */
99int wilco_ec_radio_control(enum ec_radio radio, uint8_t state);
100
Duncan Laurieb0bf2802018-10-15 02:18:03 +0000101/*
102 * EC Information
103 */
104
105enum 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
113struct 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 */
129int 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 */
141void wilco_ec_print_all_info(void);
142
Duncan Laurie2f954922018-10-15 02:28:54 +0000143/*
144 * EC Power State
145 */
146
147enum 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*/
183void 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 */
190void wilco_ec_slp_en(void);
191
192enum 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
203enum 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
210enum 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
217enum 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
225enum ec_pm5_state {
226 EC_PM5_INT_HD_SATA = BIT(7), /* Internal SATA HDD */
227};
228
229enum 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
236enum 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
242enum ec_pm2_event {
243 EC_EV2_ACPI_MONSWITCH = BIT(0), /* Monitor switch status */
244};
245
246struct 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 */
264int 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 */
274int wilco_ec_get_lid_state(void);
275
Duncan Laurieb34de932019-04-10 18:43:56 -0700276/**
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 */
285int wilco_ec_get_board_id(uint8_t *id);
286
Lijian Zhaoa31872c2019-01-10 19:31:15 -0800287enum 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 */
300int wilco_ec_change_wake(uint8_t source, enum ec_wake_change change);
301
302enum 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 Laurie32346f02019-03-20 12:51:07 -0700308/**
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 */
315int wilco_ec_signed_fw(void);
316
Keith Short8ef67322019-05-10 11:49:24 -0600317/**
Keith Shortf41afde2019-05-10 11:52:55 -0600318 * wilco_ec_save_post_code
Keith Short8ef67322019-05-10 11:49:24 -0600319 *
Keith Shortf41afde2019-05-10 11:52:55 -0600320 * 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 Short8ef67322019-05-10 11:49:24 -0600323 *
Keith Shortf41afde2019-05-10 11:52:55 -0600324 * @post_code: Post code to save
Keith Short8ef67322019-05-10 11:49:24 -0600325 */
Keith Shortf41afde2019-05-10 11:52:55 -0600326void wilco_ec_save_post_code(uint8_t post_code);
Keith Short8ef67322019-05-10 11:49:24 -0600327
Eric Laif74b6e32020-01-23 14:43:08 +0800328/**
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 */
340int wilco_ec_set_cpuid(uint32_t cpuid, uint8_t cpu_cores, uint8_t gpu_cores);
341
Duncan Laurieb0bf2802018-10-15 02:18:03 +0000342#endif /* EC_GOOGLE_WILCO_COMMANDS_H */