xref: /openbmc/u-boot/include/ec_commands.h (revision cf033e04)
1*6f1c0430SSimon Glass /* Copyright (c) 2018 The Chromium OS Authors. All rights reserved.
288364387SHung-ying Tyan  * Use of this source code is governed by a BSD-style license that can be
388364387SHung-ying Tyan  * found in the LICENSE file.
488364387SHung-ying Tyan  */
588364387SHung-ying Tyan 
688364387SHung-ying Tyan /* Host communication command constants for Chrome EC */
788364387SHung-ying Tyan 
888364387SHung-ying Tyan #ifndef __CROS_EC_COMMANDS_H
988364387SHung-ying Tyan #define __CROS_EC_COMMANDS_H
1088364387SHung-ying Tyan 
1188364387SHung-ying Tyan /*
1288364387SHung-ying Tyan  * Protocol overview
1388364387SHung-ying Tyan  *
1488364387SHung-ying Tyan  * request:  CMD [ P0 P1 P2 ... Pn S ]
1588364387SHung-ying Tyan  * response: ERR [ P0 P1 P2 ... Pn S ]
1688364387SHung-ying Tyan  *
1788364387SHung-ying Tyan  * where the bytes are defined as follow :
1888364387SHung-ying Tyan  *      - CMD is the command code. (defined by EC_CMD_ constants)
1988364387SHung-ying Tyan  *      - ERR is the error code. (defined by EC_RES_ constants)
2088364387SHung-ying Tyan  *      - Px is the optional payload.
2188364387SHung-ying Tyan  *        it is not sent if the error code is not success.
2288364387SHung-ying Tyan  *        (defined by ec_params_ and ec_response_ structures)
2388364387SHung-ying Tyan  *      - S is the checksum which is the sum of all payload bytes.
2488364387SHung-ying Tyan  *
2588364387SHung-ying Tyan  * On LPC, CMD and ERR are sent/received at EC_LPC_ADDR_KERNEL|USER_CMD
2688364387SHung-ying Tyan  * and the payloads are sent/received at EC_LPC_ADDR_KERNEL|USER_PARAM.
2788364387SHung-ying Tyan  * On I2C, all bytes are sent serially in the same message.
2888364387SHung-ying Tyan  */
2988364387SHung-ying Tyan 
30*6f1c0430SSimon Glass /*
31*6f1c0430SSimon Glass  * Current version of this protocol
32*6f1c0430SSimon Glass  *
33*6f1c0430SSimon Glass  * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
34*6f1c0430SSimon Glass  * determined in other ways.  Remove this once the kernel code no longer
35*6f1c0430SSimon Glass  * depends on it.
36*6f1c0430SSimon Glass  */
3788364387SHung-ying Tyan #define EC_PROTO_VERSION          0x00000002
3888364387SHung-ying Tyan 
3988364387SHung-ying Tyan /* Command version mask */
4088364387SHung-ying Tyan #define EC_VER_MASK(version) (1UL << (version))
4188364387SHung-ying Tyan 
4288364387SHung-ying Tyan /* I/O addresses for ACPI commands */
4388364387SHung-ying Tyan #define EC_LPC_ADDR_ACPI_DATA  0x62
4488364387SHung-ying Tyan #define EC_LPC_ADDR_ACPI_CMD   0x66
4588364387SHung-ying Tyan 
4688364387SHung-ying Tyan /* I/O addresses for host command */
4788364387SHung-ying Tyan #define EC_LPC_ADDR_HOST_DATA  0x200
4888364387SHung-ying Tyan #define EC_LPC_ADDR_HOST_CMD   0x204
4988364387SHung-ying Tyan 
5088364387SHung-ying Tyan /* I/O addresses for host command args and params */
51836bb6e8SSimon Glass /* Protocol version 2 */
52836bb6e8SSimon Glass #define EC_LPC_ADDR_HOST_ARGS    0x800  /* And 0x801, 0x802, 0x803 */
53836bb6e8SSimon Glass #define EC_LPC_ADDR_HOST_PARAM   0x804  /* For version 2 params; size is
54836bb6e8SSimon Glass 					 * EC_PROTO2_MAX_PARAM_SIZE */
55836bb6e8SSimon Glass /* Protocol version 3 */
56836bb6e8SSimon Glass #define EC_LPC_ADDR_HOST_PACKET  0x800  /* Offset of version 3 packet */
57836bb6e8SSimon Glass #define EC_LPC_HOST_PACKET_SIZE  0x100  /* Max size of version 3 packet */
5888364387SHung-ying Tyan 
59836bb6e8SSimon Glass /* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
60836bb6e8SSimon Glass  * and they tell the kernel that so we have to think of it as two parts. */
61836bb6e8SSimon Glass #define EC_HOST_CMD_REGION0    0x800
62836bb6e8SSimon Glass #define EC_HOST_CMD_REGION1    0x880
63836bb6e8SSimon Glass #define EC_HOST_CMD_REGION_SIZE 0x80
6488364387SHung-ying Tyan 
6588364387SHung-ying Tyan /* EC command register bit functions */
6688364387SHung-ying Tyan #define EC_LPC_CMDR_DATA	(1 << 0)  /* Data ready for host to read */
6788364387SHung-ying Tyan #define EC_LPC_CMDR_PENDING	(1 << 1)  /* Write pending to EC */
6888364387SHung-ying Tyan #define EC_LPC_CMDR_BUSY	(1 << 2)  /* EC is busy processing a command */
6988364387SHung-ying Tyan #define EC_LPC_CMDR_CMD		(1 << 3)  /* Last host write was a command */
7088364387SHung-ying Tyan #define EC_LPC_CMDR_ACPI_BRST	(1 << 4)  /* Burst mode (not used) */
7188364387SHung-ying Tyan #define EC_LPC_CMDR_SCI		(1 << 5)  /* SCI event is pending */
7288364387SHung-ying Tyan #define EC_LPC_CMDR_SMI		(1 << 6)  /* SMI event is pending */
7388364387SHung-ying Tyan 
7488364387SHung-ying Tyan #define EC_LPC_ADDR_MEMMAP       0x900
7588364387SHung-ying Tyan #define EC_MEMMAP_SIZE         255 /* ACPI IO buffer max is 255 bytes */
7688364387SHung-ying Tyan #define EC_MEMMAP_TEXT_MAX     8   /* Size of a string in the memory map */
7788364387SHung-ying Tyan 
7888364387SHung-ying Tyan /* The offset address of each type of data in mapped memory. */
79*6f1c0430SSimon Glass #define EC_MEMMAP_TEMP_SENSOR      0x00 /* Temp sensors 0x00 - 0x0f */
80*6f1c0430SSimon Glass #define EC_MEMMAP_FAN              0x10 /* Fan speeds 0x10 - 0x17 */
81*6f1c0430SSimon Glass #define EC_MEMMAP_TEMP_SENSOR_B    0x18 /* More temp sensors 0x18 - 0x1f */
82*6f1c0430SSimon Glass #define EC_MEMMAP_ID               0x20 /* 0x20 == 'E', 0x21 == 'C' */
8388364387SHung-ying Tyan #define EC_MEMMAP_ID_VERSION       0x22 /* Version of data in 0x20 - 0x2f */
8488364387SHung-ying Tyan #define EC_MEMMAP_THERMAL_VERSION  0x23 /* Version of data in 0x00 - 0x1f */
8588364387SHung-ying Tyan #define EC_MEMMAP_BATTERY_VERSION  0x24 /* Version of data in 0x40 - 0x7f */
8688364387SHung-ying Tyan #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
8788364387SHung-ying Tyan #define EC_MEMMAP_EVENTS_VERSION   0x26 /* Version of data in 0x34 - 0x3f */
88*6f1c0430SSimon Glass #define EC_MEMMAP_HOST_CMD_FLAGS   0x27 /* Host cmd interface flags (8 bits) */
89*6f1c0430SSimon Glass /* Unused 0x28 - 0x2f */
90*6f1c0430SSimon Glass #define EC_MEMMAP_SWITCHES         0x30	/* 8 bits */
91*6f1c0430SSimon Glass /* Unused 0x31 - 0x33 */
92*6f1c0430SSimon Glass #define EC_MEMMAP_HOST_EVENTS      0x34 /* 32 bits */
93*6f1c0430SSimon Glass /* Reserve 0x38 - 0x3f for additional host event-related stuff */
94*6f1c0430SSimon Glass /* Battery values are all 32 bits */
9588364387SHung-ying Tyan #define EC_MEMMAP_BATT_VOLT        0x40 /* Battery Present Voltage */
9688364387SHung-ying Tyan #define EC_MEMMAP_BATT_RATE        0x44 /* Battery Present Rate */
9788364387SHung-ying Tyan #define EC_MEMMAP_BATT_CAP         0x48 /* Battery Remaining Capacity */
9888364387SHung-ying Tyan #define EC_MEMMAP_BATT_FLAG        0x4c /* Battery State, defined below */
9988364387SHung-ying Tyan #define EC_MEMMAP_BATT_DCAP        0x50 /* Battery Design Capacity */
10088364387SHung-ying Tyan #define EC_MEMMAP_BATT_DVLT        0x54 /* Battery Design Voltage */
10188364387SHung-ying Tyan #define EC_MEMMAP_BATT_LFCC        0x58 /* Battery Last Full Charge Capacity */
10288364387SHung-ying Tyan #define EC_MEMMAP_BATT_CCNT        0x5c /* Battery Cycle Count */
103*6f1c0430SSimon Glass /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
10488364387SHung-ying Tyan #define EC_MEMMAP_BATT_MFGR        0x60 /* Battery Manufacturer String */
10588364387SHung-ying Tyan #define EC_MEMMAP_BATT_MODEL       0x68 /* Battery Model Number String */
10688364387SHung-ying Tyan #define EC_MEMMAP_BATT_SERIAL      0x70 /* Battery Serial Number String */
10788364387SHung-ying Tyan #define EC_MEMMAP_BATT_TYPE        0x78 /* Battery Type String */
108*6f1c0430SSimon Glass #define EC_MEMMAP_ALS              0x80 /* ALS readings in lux (2 X 16 bits) */
109*6f1c0430SSimon Glass /* Unused 0x84 - 0x8f */
110*6f1c0430SSimon Glass #define EC_MEMMAP_ACC_STATUS       0x90 /* Accelerometer status (8 bits )*/
111*6f1c0430SSimon Glass /* Unused 0x91 */
112*6f1c0430SSimon Glass #define EC_MEMMAP_ACC_DATA         0x92 /* Accelerometers data 0x92 - 0x9f */
113*6f1c0430SSimon Glass /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
114*6f1c0430SSimon Glass /* 0x94 - 0x99: 1st Accelerometer */
115*6f1c0430SSimon Glass /* 0x9a - 0x9f: 2nd Accelerometer */
116*6f1c0430SSimon Glass #define EC_MEMMAP_GYRO_DATA        0xa0 /* Gyroscope data 0xa0 - 0xa5 */
117*6f1c0430SSimon Glass /* Unused 0xa6 - 0xdf */
118*6f1c0430SSimon Glass 
119*6f1c0430SSimon Glass /*
120*6f1c0430SSimon Glass  * ACPI is unable to access memory mapped data at or above this offset due to
121*6f1c0430SSimon Glass  * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
122*6f1c0430SSimon Glass  * which might be needed by ACPI.
123*6f1c0430SSimon Glass  */
124*6f1c0430SSimon Glass #define EC_MEMMAP_NO_ACPI 0xe0
125*6f1c0430SSimon Glass 
126*6f1c0430SSimon Glass /* Define the format of the accelerometer mapped memory status byte. */
127*6f1c0430SSimon Glass #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK  0x0f
128*6f1c0430SSimon Glass #define EC_MEMMAP_ACC_STATUS_BUSY_BIT        (1 << 4)
129*6f1c0430SSimon Glass #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT    (1 << 7)
13088364387SHung-ying Tyan 
13188364387SHung-ying Tyan /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
13288364387SHung-ying Tyan #define EC_TEMP_SENSOR_ENTRIES     16
13388364387SHung-ying Tyan /*
13488364387SHung-ying Tyan  * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
13588364387SHung-ying Tyan  *
13688364387SHung-ying Tyan  * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
13788364387SHung-ying Tyan  */
13888364387SHung-ying Tyan #define EC_TEMP_SENSOR_B_ENTRIES      8
139*6f1c0430SSimon Glass 
140*6f1c0430SSimon Glass /* Special values for mapped temperature sensors */
14188364387SHung-ying Tyan #define EC_TEMP_SENSOR_NOT_PRESENT    0xff
14288364387SHung-ying Tyan #define EC_TEMP_SENSOR_ERROR          0xfe
14388364387SHung-ying Tyan #define EC_TEMP_SENSOR_NOT_POWERED    0xfd
14488364387SHung-ying Tyan #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
14588364387SHung-ying Tyan /*
14688364387SHung-ying Tyan  * The offset of temperature value stored in mapped memory.  This allows
14788364387SHung-ying Tyan  * reporting a temperature range of 200K to 454K = -73C to 181C.
14888364387SHung-ying Tyan  */
14988364387SHung-ying Tyan #define EC_TEMP_SENSOR_OFFSET      200
15088364387SHung-ying Tyan 
151*6f1c0430SSimon Glass /*
152*6f1c0430SSimon Glass  * Number of ALS readings at EC_MEMMAP_ALS
153*6f1c0430SSimon Glass  */
154*6f1c0430SSimon Glass #define EC_ALS_ENTRIES             2
155*6f1c0430SSimon Glass 
156*6f1c0430SSimon Glass /*
157*6f1c0430SSimon Glass  * The default value a temperature sensor will return when it is present but
158*6f1c0430SSimon Glass  * has not been read this boot.  This is a reasonable number to avoid
159*6f1c0430SSimon Glass  * triggering alarms on the host.
160*6f1c0430SSimon Glass  */
161*6f1c0430SSimon Glass #define EC_TEMP_SENSOR_DEFAULT     (296 - EC_TEMP_SENSOR_OFFSET)
162*6f1c0430SSimon Glass 
16388364387SHung-ying Tyan #define EC_FAN_SPEED_ENTRIES       4       /* Number of fans at EC_MEMMAP_FAN */
16488364387SHung-ying Tyan #define EC_FAN_SPEED_NOT_PRESENT   0xffff  /* Entry not present */
16588364387SHung-ying Tyan #define EC_FAN_SPEED_STALLED       0xfffe  /* Fan stalled */
16688364387SHung-ying Tyan 
16788364387SHung-ying Tyan /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
16888364387SHung-ying Tyan #define EC_BATT_FLAG_AC_PRESENT   0x01
16988364387SHung-ying Tyan #define EC_BATT_FLAG_BATT_PRESENT 0x02
17088364387SHung-ying Tyan #define EC_BATT_FLAG_DISCHARGING  0x04
17188364387SHung-ying Tyan #define EC_BATT_FLAG_CHARGING     0x08
17288364387SHung-ying Tyan #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
17388364387SHung-ying Tyan 
17488364387SHung-ying Tyan /* Switch flags at EC_MEMMAP_SWITCHES */
17588364387SHung-ying Tyan #define EC_SWITCH_LID_OPEN               0x01
17688364387SHung-ying Tyan #define EC_SWITCH_POWER_BUTTON_PRESSED   0x02
17788364387SHung-ying Tyan #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
178836bb6e8SSimon Glass /* Was recovery requested via keyboard; now unused. */
179836bb6e8SSimon Glass #define EC_SWITCH_IGNORE1		 0x08
18088364387SHung-ying Tyan /* Recovery requested via dedicated signal (from servo board) */
18188364387SHung-ying Tyan #define EC_SWITCH_DEDICATED_RECOVERY     0x10
18288364387SHung-ying Tyan /* Was fake developer mode switch; now unused.  Remove in next refactor. */
18388364387SHung-ying Tyan #define EC_SWITCH_IGNORE0                0x20
18488364387SHung-ying Tyan 
18588364387SHung-ying Tyan /* Host command interface flags */
18688364387SHung-ying Tyan /* Host command interface supports LPC args (LPC interface only) */
18788364387SHung-ying Tyan #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED  0x01
188836bb6e8SSimon Glass /* Host command interface supports version 3 protocol */
189836bb6e8SSimon Glass #define EC_HOST_CMD_FLAG_VERSION_3   0x02
19088364387SHung-ying Tyan 
19188364387SHung-ying Tyan /* Wireless switch flags */
192*6f1c0430SSimon Glass #define EC_WIRELESS_SWITCH_ALL       ~0x00  /* All flags */
193*6f1c0430SSimon Glass #define EC_WIRELESS_SWITCH_WLAN       0x01  /* WLAN radio */
194*6f1c0430SSimon Glass #define EC_WIRELESS_SWITCH_BLUETOOTH  0x02  /* Bluetooth radio */
195*6f1c0430SSimon Glass #define EC_WIRELESS_SWITCH_WWAN       0x04  /* WWAN power */
196*6f1c0430SSimon Glass #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08  /* WLAN power */
197*6f1c0430SSimon Glass 
198*6f1c0430SSimon Glass /*****************************************************************************/
199*6f1c0430SSimon Glass /*
200*6f1c0430SSimon Glass  * ACPI commands
201*6f1c0430SSimon Glass  *
202*6f1c0430SSimon Glass  * These are valid ONLY on the ACPI command/data port.
203*6f1c0430SSimon Glass  */
204*6f1c0430SSimon Glass 
205*6f1c0430SSimon Glass /*
206*6f1c0430SSimon Glass  * ACPI Read Embedded Controller
207*6f1c0430SSimon Glass  *
208*6f1c0430SSimon Glass  * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
209*6f1c0430SSimon Glass  *
210*6f1c0430SSimon Glass  * Use the following sequence:
211*6f1c0430SSimon Glass  *
212*6f1c0430SSimon Glass  *    - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
213*6f1c0430SSimon Glass  *    - Wait for EC_LPC_CMDR_PENDING bit to clear
214*6f1c0430SSimon Glass  *    - Write address to EC_LPC_ADDR_ACPI_DATA
215*6f1c0430SSimon Glass  *    - Wait for EC_LPC_CMDR_DATA bit to set
216*6f1c0430SSimon Glass  *    - Read value from EC_LPC_ADDR_ACPI_DATA
217*6f1c0430SSimon Glass  */
218*6f1c0430SSimon Glass #define EC_CMD_ACPI_READ 0x0080
219*6f1c0430SSimon Glass 
220*6f1c0430SSimon Glass /*
221*6f1c0430SSimon Glass  * ACPI Write Embedded Controller
222*6f1c0430SSimon Glass  *
223*6f1c0430SSimon Glass  * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
224*6f1c0430SSimon Glass  *
225*6f1c0430SSimon Glass  * Use the following sequence:
226*6f1c0430SSimon Glass  *
227*6f1c0430SSimon Glass  *    - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
228*6f1c0430SSimon Glass  *    - Wait for EC_LPC_CMDR_PENDING bit to clear
229*6f1c0430SSimon Glass  *    - Write address to EC_LPC_ADDR_ACPI_DATA
230*6f1c0430SSimon Glass  *    - Wait for EC_LPC_CMDR_PENDING bit to clear
231*6f1c0430SSimon Glass  *    - Write value to EC_LPC_ADDR_ACPI_DATA
232*6f1c0430SSimon Glass  */
233*6f1c0430SSimon Glass #define EC_CMD_ACPI_WRITE 0x0081
234*6f1c0430SSimon Glass 
235*6f1c0430SSimon Glass /*
236*6f1c0430SSimon Glass  * ACPI Burst Enable Embedded Controller
237*6f1c0430SSimon Glass  *
238*6f1c0430SSimon Glass  * This enables burst mode on the EC to allow the host to issue several
239*6f1c0430SSimon Glass  * commands back-to-back. While in this mode, writes to mapped multi-byte
240*6f1c0430SSimon Glass  * data are locked out to ensure data consistency.
241*6f1c0430SSimon Glass  */
242*6f1c0430SSimon Glass #define EC_CMD_ACPI_BURST_ENABLE 0x0082
243*6f1c0430SSimon Glass 
244*6f1c0430SSimon Glass /*
245*6f1c0430SSimon Glass  * ACPI Burst Disable Embedded Controller
246*6f1c0430SSimon Glass  *
247*6f1c0430SSimon Glass  * This disables burst mode on the EC and stops preventing EC writes to mapped
248*6f1c0430SSimon Glass  * multi-byte data.
249*6f1c0430SSimon Glass  */
250*6f1c0430SSimon Glass #define EC_CMD_ACPI_BURST_DISABLE 0x0083
251*6f1c0430SSimon Glass 
252*6f1c0430SSimon Glass /*
253*6f1c0430SSimon Glass  * ACPI Query Embedded Controller
254*6f1c0430SSimon Glass  *
255*6f1c0430SSimon Glass  * This clears the lowest-order bit in the currently pending host events, and
256*6f1c0430SSimon Glass  * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
257*6f1c0430SSimon Glass  * event 0x80000000 = 32), or 0 if no event was pending.
258*6f1c0430SSimon Glass  */
259*6f1c0430SSimon Glass #define EC_CMD_ACPI_QUERY_EVENT 0x0084
260*6f1c0430SSimon Glass 
261*6f1c0430SSimon Glass /* Valid addresses in ACPI memory space, for read/write commands */
262*6f1c0430SSimon Glass 
263*6f1c0430SSimon Glass /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
264*6f1c0430SSimon Glass #define EC_ACPI_MEM_VERSION            0x00
265*6f1c0430SSimon Glass /*
266*6f1c0430SSimon Glass  * Test location; writing value here updates test compliment byte to (0xff -
267*6f1c0430SSimon Glass  * value).
268*6f1c0430SSimon Glass  */
269*6f1c0430SSimon Glass #define EC_ACPI_MEM_TEST               0x01
270*6f1c0430SSimon Glass /* Test compliment; writes here are ignored. */
271*6f1c0430SSimon Glass #define EC_ACPI_MEM_TEST_COMPLIMENT    0x02
272*6f1c0430SSimon Glass 
273*6f1c0430SSimon Glass /* Keyboard backlight brightness percent (0 - 100) */
274*6f1c0430SSimon Glass #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
275*6f1c0430SSimon Glass /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
276*6f1c0430SSimon Glass #define EC_ACPI_MEM_FAN_DUTY           0x04
277*6f1c0430SSimon Glass 
278*6f1c0430SSimon Glass /*
279*6f1c0430SSimon Glass  * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
280*6f1c0430SSimon Glass  * independent thresholds attached to them. The current value of the ID
281*6f1c0430SSimon Glass  * register determines which sensor is affected by the THRESHOLD and COMMIT
282*6f1c0430SSimon Glass  * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
283*6f1c0430SSimon Glass  * as the memory-mapped sensors. The COMMIT register applies those settings.
284*6f1c0430SSimon Glass  *
285*6f1c0430SSimon Glass  * The spec does not mandate any way to read back the threshold settings
286*6f1c0430SSimon Glass  * themselves, but when a threshold is crossed the AP needs a way to determine
287*6f1c0430SSimon Glass  * which sensor(s) are responsible. Each reading of the ID register clears and
288*6f1c0430SSimon Glass  * returns one sensor ID that has crossed one of its threshold (in either
289*6f1c0430SSimon Glass  * direction) since the last read. A value of 0xFF means "no new thresholds
290*6f1c0430SSimon Glass  * have tripped". Setting or enabling the thresholds for a sensor will clear
291*6f1c0430SSimon Glass  * the unread event count for that sensor.
292*6f1c0430SSimon Glass  */
293*6f1c0430SSimon Glass #define EC_ACPI_MEM_TEMP_ID            0x05
294*6f1c0430SSimon Glass #define EC_ACPI_MEM_TEMP_THRESHOLD     0x06
295*6f1c0430SSimon Glass #define EC_ACPI_MEM_TEMP_COMMIT        0x07
296*6f1c0430SSimon Glass /*
297*6f1c0430SSimon Glass  * Here are the bits for the COMMIT register:
298*6f1c0430SSimon Glass  *   bit 0 selects the threshold index for the chosen sensor (0/1)
299*6f1c0430SSimon Glass  *   bit 1 enables/disables the selected threshold (0 = off, 1 = on)
300*6f1c0430SSimon Glass  * Each write to the commit register affects one threshold.
301*6f1c0430SSimon Glass  */
302*6f1c0430SSimon Glass #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
303*6f1c0430SSimon Glass #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
304*6f1c0430SSimon Glass /*
305*6f1c0430SSimon Glass  * Example:
306*6f1c0430SSimon Glass  *
307*6f1c0430SSimon Glass  * Set the thresholds for sensor 2 to 50 C and 60 C:
308*6f1c0430SSimon Glass  *   write 2 to [0x05]      --  select temp sensor 2
309*6f1c0430SSimon Glass  *   write 0x7b to [0x06]   --  C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
310*6f1c0430SSimon Glass  *   write 0x2 to [0x07]    --  enable threshold 0 with this value
311*6f1c0430SSimon Glass  *   write 0x85 to [0x06]   --  C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
312*6f1c0430SSimon Glass  *   write 0x3 to [0x07]    --  enable threshold 1 with this value
313*6f1c0430SSimon Glass  *
314*6f1c0430SSimon Glass  * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
315*6f1c0430SSimon Glass  *   write 2 to [0x05]      --  select temp sensor 2
316*6f1c0430SSimon Glass  *   write 0x1 to [0x07]    --  disable threshold 1
317*6f1c0430SSimon Glass  */
318*6f1c0430SSimon Glass 
319*6f1c0430SSimon Glass /* DPTF battery charging current limit */
320*6f1c0430SSimon Glass #define EC_ACPI_MEM_CHARGING_LIMIT     0x08
321*6f1c0430SSimon Glass 
322*6f1c0430SSimon Glass /* Charging limit is specified in 64 mA steps */
323*6f1c0430SSimon Glass #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA   64
324*6f1c0430SSimon Glass /* Value to disable DPTF battery charging limit */
325*6f1c0430SSimon Glass #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED  0xff
326*6f1c0430SSimon Glass 
327*6f1c0430SSimon Glass /*
328*6f1c0430SSimon Glass  * Report device orientation
329*6f1c0430SSimon Glass  *   bit 0 device is tablet mode
330*6f1c0430SSimon Glass  */
331*6f1c0430SSimon Glass #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
332*6f1c0430SSimon Glass #define EC_ACPI_MEM_DEVICE_TABLET_MODE 0x01
333*6f1c0430SSimon Glass 
334*6f1c0430SSimon Glass /*
335*6f1c0430SSimon Glass  * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf.  This data
336*6f1c0430SSimon Glass  * is read-only from the AP.  Added in EC_ACPI_MEM_VERSION 2.
337*6f1c0430SSimon Glass  */
338*6f1c0430SSimon Glass #define EC_ACPI_MEM_MAPPED_BEGIN   0x20
339*6f1c0430SSimon Glass #define EC_ACPI_MEM_MAPPED_SIZE    0xe0
340*6f1c0430SSimon Glass 
341*6f1c0430SSimon Glass /* Current version of ACPI memory address space */
342*6f1c0430SSimon Glass #define EC_ACPI_MEM_VERSION_CURRENT 2
343*6f1c0430SSimon Glass 
34488364387SHung-ying Tyan 
34588364387SHung-ying Tyan /*
34688364387SHung-ying Tyan  * This header file is used in coreboot both in C and ACPI code.  The ACPI code
34788364387SHung-ying Tyan  * is pre-processed to handle constants but the ASL compiler is unable to
34888364387SHung-ying Tyan  * handle actual C code so keep it separate.
34988364387SHung-ying Tyan  */
35088364387SHung-ying Tyan #ifndef __ACPI__
35188364387SHung-ying Tyan 
35288364387SHung-ying Tyan /*
35388364387SHung-ying Tyan  * Define __packed if someone hasn't beat us to it.  Linux kernel style
35488364387SHung-ying Tyan  * checking prefers __packed over __attribute__((packed)).
35588364387SHung-ying Tyan  */
35688364387SHung-ying Tyan #ifndef __packed
35788364387SHung-ying Tyan #define __packed __attribute__((packed))
35888364387SHung-ying Tyan #endif
35988364387SHung-ying Tyan 
360*6f1c0430SSimon Glass #ifndef __aligned
361*6f1c0430SSimon Glass #define __aligned(x) __attribute__((aligned(x)))
362*6f1c0430SSimon Glass #endif
363*6f1c0430SSimon Glass 
364*6f1c0430SSimon Glass /*
365*6f1c0430SSimon Glass  * Attributes for EC request and response packets.  Just defining __packed
366*6f1c0430SSimon Glass  * results in inefficient assembly code on ARM, if the structure is actually
367*6f1c0430SSimon Glass  * 32-bit aligned, as it should be for all buffers.
368*6f1c0430SSimon Glass  *
369*6f1c0430SSimon Glass  * Be very careful when adding these to existing structures.  They will round
370*6f1c0430SSimon Glass  * up the structure size to the specified boundary.
371*6f1c0430SSimon Glass  *
372*6f1c0430SSimon Glass  * Also be very careful to make that if a structure is included in some other
373*6f1c0430SSimon Glass  * parent structure that the alignment will still be true given the packing of
374*6f1c0430SSimon Glass  * the parent structure.  This is particularly important if the sub-structure
375*6f1c0430SSimon Glass  * will be passed as a pointer to another function, since that function will
376*6f1c0430SSimon Glass  * not know about the misaligment caused by the parent structure's packing.
377*6f1c0430SSimon Glass  *
378*6f1c0430SSimon Glass  * Also be very careful using __packed - particularly when nesting non-packed
379*6f1c0430SSimon Glass  * structures inside packed ones.  In fact, DO NOT use __packed directly;
380*6f1c0430SSimon Glass  * always use one of these attributes.
381*6f1c0430SSimon Glass  *
382*6f1c0430SSimon Glass  * Once everything is annotated properly, the following search strings should
383*6f1c0430SSimon Glass  * not return ANY matches in this file other than right here:
384*6f1c0430SSimon Glass  *
385*6f1c0430SSimon Glass  * "__packed" - generates inefficient code; all sub-structs must also be packed
386*6f1c0430SSimon Glass  *
387*6f1c0430SSimon Glass  * "struct [^_]" - all structs should be annotated, except for structs that are
388*6f1c0430SSimon Glass  * members of other structs/unions (and their original declarations should be
389*6f1c0430SSimon Glass  * annotated).
390*6f1c0430SSimon Glass  */
391*6f1c0430SSimon Glass #ifdef CONFIG_HOSTCMD_ALIGNED
392*6f1c0430SSimon Glass 
393*6f1c0430SSimon Glass /*
394*6f1c0430SSimon Glass  * Packed structures where offset and size are always aligned to 1, 2, or 4
395*6f1c0430SSimon Glass  * byte boundary.
396*6f1c0430SSimon Glass  */
397*6f1c0430SSimon Glass #define __ec_align1 __packed
398*6f1c0430SSimon Glass #define __ec_align2 __packed __aligned(2)
399*6f1c0430SSimon Glass #define __ec_align4 __packed __aligned(4)
400*6f1c0430SSimon Glass 
401*6f1c0430SSimon Glass /*
402*6f1c0430SSimon Glass  * Packed structure which must be under-aligned, because its size is not a
403*6f1c0430SSimon Glass  * 4-byte multiple.  This is sub-optimal because it forces byte-wise access
404*6f1c0430SSimon Glass  * of all multi-byte fields in it, even though they are themselves aligned.
405*6f1c0430SSimon Glass  *
406*6f1c0430SSimon Glass  * In theory, we could duplicate the structure with __aligned(4) for accessing
407*6f1c0430SSimon Glass  * its members, but use the __packed version for sizeof().
408*6f1c0430SSimon Glass  */
409*6f1c0430SSimon Glass #define __ec_align_size1 __packed
410*6f1c0430SSimon Glass 
411*6f1c0430SSimon Glass /*
412*6f1c0430SSimon Glass  * Packed structure which must be under-aligned, because its offset inside a
413*6f1c0430SSimon Glass  * parent structure is not a 4-byte multiple.
414*6f1c0430SSimon Glass  */
415*6f1c0430SSimon Glass #define __ec_align_offset1 __packed
416*6f1c0430SSimon Glass #define __ec_align_offset2 __packed __aligned(2)
417*6f1c0430SSimon Glass 
418*6f1c0430SSimon Glass /*
419*6f1c0430SSimon Glass  * Structures which are complicated enough that I'm skipping them on the first
420*6f1c0430SSimon Glass  * pass.  They are effectively unchanged from their previous definitions.
421*6f1c0430SSimon Glass  *
422*6f1c0430SSimon Glass  * TODO(rspangler): Figure out what to do with these.  It's likely necessary
423*6f1c0430SSimon Glass  * to work out the size and offset of each member and add explicit padding to
424*6f1c0430SSimon Glass  * maintain those.
425*6f1c0430SSimon Glass  */
426*6f1c0430SSimon Glass #define __ec_todo_packed __packed
427*6f1c0430SSimon Glass #define __ec_todo_unpacked
428*6f1c0430SSimon Glass 
429*6f1c0430SSimon Glass #else  /* !CONFIG_HOSTCMD_ALIGNED */
430*6f1c0430SSimon Glass 
431*6f1c0430SSimon Glass /*
432*6f1c0430SSimon Glass  * Packed structures make no assumption about alignment, so they do inefficient
433*6f1c0430SSimon Glass  * byte-wise reads.
434*6f1c0430SSimon Glass  */
435*6f1c0430SSimon Glass #define __ec_align1 __packed
436*6f1c0430SSimon Glass #define __ec_align2 __packed
437*6f1c0430SSimon Glass #define __ec_align4 __packed
438*6f1c0430SSimon Glass #define __ec_align_size1 __packed
439*6f1c0430SSimon Glass #define __ec_align_offset1 __packed
440*6f1c0430SSimon Glass #define __ec_align_offset2 __packed
441*6f1c0430SSimon Glass #define __ec_todo_packed __packed
442*6f1c0430SSimon Glass #define __ec_todo_unpacked
443*6f1c0430SSimon Glass 
444*6f1c0430SSimon Glass #endif  /* !CONFIG_HOSTCMD_ALIGNED */
445*6f1c0430SSimon Glass 
44688364387SHung-ying Tyan /* LPC command status byte masks */
44788364387SHung-ying Tyan /* EC has written a byte in the data register and host hasn't read it yet */
44888364387SHung-ying Tyan #define EC_LPC_STATUS_TO_HOST     0x01
44988364387SHung-ying Tyan /* Host has written a command/data byte and the EC hasn't read it yet */
45088364387SHung-ying Tyan #define EC_LPC_STATUS_FROM_HOST   0x02
45188364387SHung-ying Tyan /* EC is processing a command */
45288364387SHung-ying Tyan #define EC_LPC_STATUS_PROCESSING  0x04
45388364387SHung-ying Tyan /* Last write to EC was a command, not data */
45488364387SHung-ying Tyan #define EC_LPC_STATUS_LAST_CMD    0x08
455*6f1c0430SSimon Glass /* EC is in burst mode */
45688364387SHung-ying Tyan #define EC_LPC_STATUS_BURST_MODE  0x10
45788364387SHung-ying Tyan /* SCI event is pending (requesting SCI query) */
45888364387SHung-ying Tyan #define EC_LPC_STATUS_SCI_PENDING 0x20
45988364387SHung-ying Tyan /* SMI event is pending (requesting SMI query) */
46088364387SHung-ying Tyan #define EC_LPC_STATUS_SMI_PENDING 0x40
46188364387SHung-ying Tyan /* (reserved) */
46288364387SHung-ying Tyan #define EC_LPC_STATUS_RESERVED    0x80
46388364387SHung-ying Tyan 
46488364387SHung-ying Tyan /*
46588364387SHung-ying Tyan  * EC is busy.  This covers both the EC processing a command, and the host has
46688364387SHung-ying Tyan  * written a new command but the EC hasn't picked it up yet.
46788364387SHung-ying Tyan  */
46888364387SHung-ying Tyan #define EC_LPC_STATUS_BUSY_MASK \
46988364387SHung-ying Tyan 	(EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
47088364387SHung-ying Tyan 
471*6f1c0430SSimon Glass /* Host command response codes (16-bit).  Note that response codes should be
472*6f1c0430SSimon Glass  * stored in a uint16_t rather than directly in a value of this type.
473*6f1c0430SSimon Glass  */
47488364387SHung-ying Tyan enum ec_status {
47588364387SHung-ying Tyan 	EC_RES_SUCCESS = 0,
47688364387SHung-ying Tyan 	EC_RES_INVALID_COMMAND = 1,
47788364387SHung-ying Tyan 	EC_RES_ERROR = 2,
47888364387SHung-ying Tyan 	EC_RES_INVALID_PARAM = 3,
47988364387SHung-ying Tyan 	EC_RES_ACCESS_DENIED = 4,
48088364387SHung-ying Tyan 	EC_RES_INVALID_RESPONSE = 5,
48188364387SHung-ying Tyan 	EC_RES_INVALID_VERSION = 6,
48288364387SHung-ying Tyan 	EC_RES_INVALID_CHECKSUM = 7,
48388364387SHung-ying Tyan 	EC_RES_IN_PROGRESS = 8,		/* Accepted, command in progress */
48488364387SHung-ying Tyan 	EC_RES_UNAVAILABLE = 9,		/* No response available */
48588364387SHung-ying Tyan 	EC_RES_TIMEOUT = 10,		/* We got a timeout */
48688364387SHung-ying Tyan 	EC_RES_OVERFLOW = 11,		/* Table / data overflow */
487836bb6e8SSimon Glass 	EC_RES_INVALID_HEADER = 12,     /* Header contains invalid data */
488836bb6e8SSimon Glass 	EC_RES_REQUEST_TRUNCATED = 13,  /* Didn't get the entire request */
489*6f1c0430SSimon Glass 	EC_RES_RESPONSE_TOO_BIG = 14,   /* Response was too big to handle */
490*6f1c0430SSimon Glass 	EC_RES_BUS_ERROR = 15,		/* Communications bus error */
491*6f1c0430SSimon Glass 	EC_RES_BUSY = 16		/* Up but too busy.  Should retry */
49288364387SHung-ying Tyan };
49388364387SHung-ying Tyan 
49488364387SHung-ying Tyan /*
49588364387SHung-ying Tyan  * Host event codes.  Note these are 1-based, not 0-based, because ACPI query
49688364387SHung-ying Tyan  * EC command uses code 0 to mean "no event pending".  We explicitly specify
49788364387SHung-ying Tyan  * each value in the enum listing so they won't change if we delete/insert an
49888364387SHung-ying Tyan  * item or rearrange the list (it needs to be stable across platforms, not
49988364387SHung-ying Tyan  * just within a single compiled instance).
50088364387SHung-ying Tyan  */
50188364387SHung-ying Tyan enum host_event_code {
50288364387SHung-ying Tyan 	EC_HOST_EVENT_LID_CLOSED = 1,
50388364387SHung-ying Tyan 	EC_HOST_EVENT_LID_OPEN = 2,
50488364387SHung-ying Tyan 	EC_HOST_EVENT_POWER_BUTTON = 3,
50588364387SHung-ying Tyan 	EC_HOST_EVENT_AC_CONNECTED = 4,
50688364387SHung-ying Tyan 	EC_HOST_EVENT_AC_DISCONNECTED = 5,
50788364387SHung-ying Tyan 	EC_HOST_EVENT_BATTERY_LOW = 6,
50888364387SHung-ying Tyan 	EC_HOST_EVENT_BATTERY_CRITICAL = 7,
50988364387SHung-ying Tyan 	EC_HOST_EVENT_BATTERY = 8,
51088364387SHung-ying Tyan 	EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
511*6f1c0430SSimon Glass 	/* Event generated by a device attached to the EC */
512*6f1c0430SSimon Glass 	EC_HOST_EVENT_DEVICE = 10,
51388364387SHung-ying Tyan 	EC_HOST_EVENT_THERMAL = 11,
51488364387SHung-ying Tyan 	EC_HOST_EVENT_USB_CHARGER = 12,
51588364387SHung-ying Tyan 	EC_HOST_EVENT_KEY_PRESSED = 13,
51688364387SHung-ying Tyan 	/*
51788364387SHung-ying Tyan 	 * EC has finished initializing the host interface.  The host can check
51888364387SHung-ying Tyan 	 * for this event following sending a EC_CMD_REBOOT_EC command to
51988364387SHung-ying Tyan 	 * determine when the EC is ready to accept subsequent commands.
52088364387SHung-ying Tyan 	 */
52188364387SHung-ying Tyan 	EC_HOST_EVENT_INTERFACE_READY = 14,
52288364387SHung-ying Tyan 	/* Keyboard recovery combo has been pressed */
52388364387SHung-ying Tyan 	EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
52488364387SHung-ying Tyan 
52588364387SHung-ying Tyan 	/* Shutdown due to thermal overload */
52688364387SHung-ying Tyan 	EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
52788364387SHung-ying Tyan 	/* Shutdown due to battery level too low */
52888364387SHung-ying Tyan 	EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
52988364387SHung-ying Tyan 
530*6f1c0430SSimon Glass 	/* Suggest that the AP throttle itself */
531*6f1c0430SSimon Glass 	EC_HOST_EVENT_THROTTLE_START = 18,
532*6f1c0430SSimon Glass 	/* Suggest that the AP resume normal speed */
533*6f1c0430SSimon Glass 	EC_HOST_EVENT_THROTTLE_STOP = 19,
534*6f1c0430SSimon Glass 
535*6f1c0430SSimon Glass 	/* Hang detect logic detected a hang and host event timeout expired */
536*6f1c0430SSimon Glass 	EC_HOST_EVENT_HANG_DETECT = 20,
537*6f1c0430SSimon Glass 	/* Hang detect logic detected a hang and warm rebooted the AP */
538*6f1c0430SSimon Glass 	EC_HOST_EVENT_HANG_REBOOT = 21,
539*6f1c0430SSimon Glass 
540*6f1c0430SSimon Glass 	/* PD MCU triggering host event */
541*6f1c0430SSimon Glass 	EC_HOST_EVENT_PD_MCU = 22,
542*6f1c0430SSimon Glass 
543*6f1c0430SSimon Glass 	/* Battery Status flags have changed */
544*6f1c0430SSimon Glass 	EC_HOST_EVENT_BATTERY_STATUS = 23,
545*6f1c0430SSimon Glass 
546*6f1c0430SSimon Glass 	/* EC encountered a panic, triggering a reset */
547*6f1c0430SSimon Glass 	EC_HOST_EVENT_PANIC = 24,
548*6f1c0430SSimon Glass 
549*6f1c0430SSimon Glass 	/* Keyboard fastboot combo has been pressed */
550*6f1c0430SSimon Glass 	EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
551*6f1c0430SSimon Glass 
552*6f1c0430SSimon Glass 	/* EC RTC event occurred */
553*6f1c0430SSimon Glass 	EC_HOST_EVENT_RTC = 26,
554*6f1c0430SSimon Glass 
555*6f1c0430SSimon Glass 	/* Emulate MKBP event */
556*6f1c0430SSimon Glass 	EC_HOST_EVENT_MKBP = 27,
557*6f1c0430SSimon Glass 
558*6f1c0430SSimon Glass 	/* EC desires to change state of host-controlled USB mux */
559*6f1c0430SSimon Glass 	EC_HOST_EVENT_USB_MUX = 28,
560*6f1c0430SSimon Glass 
561*6f1c0430SSimon Glass 	/* TABLET/LAPTOP mode event*/
562*6f1c0430SSimon Glass 	EC_HOST_EVENT_MODE_CHANGE = 29,
563*6f1c0430SSimon Glass 
564*6f1c0430SSimon Glass 	/* Keyboard recovery combo with hardware reinitialization */
565*6f1c0430SSimon Glass 	EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
566*6f1c0430SSimon Glass 
567*6f1c0430SSimon Glass 	/*
568*6f1c0430SSimon Glass 	 * Reserve this last bit to indicate that at least one bit in a
569*6f1c0430SSimon Glass 	 * secondary host event word is set.  See crbug.com/633646.
570*6f1c0430SSimon Glass 	 */
571*6f1c0430SSimon Glass 	EC_HOST_EVENT_EXTENDED = 31,
572*6f1c0430SSimon Glass 
57388364387SHung-ying Tyan 	/*
57488364387SHung-ying Tyan 	 * The high bit of the event mask is not used as a host event code.  If
57588364387SHung-ying Tyan 	 * it reads back as set, then the entire event mask should be
57688364387SHung-ying Tyan 	 * considered invalid by the host.  This can happen when reading the
57788364387SHung-ying Tyan 	 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
57888364387SHung-ying Tyan 	 * not initialized on the EC, or improperly configured on the host.
57988364387SHung-ying Tyan 	 */
58088364387SHung-ying Tyan 	EC_HOST_EVENT_INVALID = 32
58188364387SHung-ying Tyan };
58288364387SHung-ying Tyan /* Host event mask */
583*6f1c0430SSimon Glass #define EC_HOST_EVENT_MASK(event_code) (1ULL << ((event_code) - 1))
58488364387SHung-ying Tyan 
58588364387SHung-ying Tyan /* Arguments at EC_LPC_ADDR_HOST_ARGS */
586*6f1c0430SSimon Glass struct __ec_align4 ec_lpc_host_args {
58788364387SHung-ying Tyan 	uint8_t flags;
58888364387SHung-ying Tyan 	uint8_t command_version;
58988364387SHung-ying Tyan 	uint8_t data_size;
59088364387SHung-ying Tyan 	/*
59188364387SHung-ying Tyan 	 * Checksum; sum of command + flags + command_version + data_size +
59288364387SHung-ying Tyan 	 * all params/response data bytes.
59388364387SHung-ying Tyan 	 */
59488364387SHung-ying Tyan 	uint8_t checksum;
595*6f1c0430SSimon Glass };
59688364387SHung-ying Tyan 
59788364387SHung-ying Tyan /* Flags for ec_lpc_host_args.flags */
59888364387SHung-ying Tyan /*
59988364387SHung-ying Tyan  * Args are from host.  Data area at EC_LPC_ADDR_HOST_PARAM contains command
60088364387SHung-ying Tyan  * params.
60188364387SHung-ying Tyan  *
60288364387SHung-ying Tyan  * If EC gets a command and this flag is not set, this is an old-style command.
60388364387SHung-ying Tyan  * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
60488364387SHung-ying Tyan  * unknown length.  EC must respond with an old-style response (that is,
605*6f1c0430SSimon Glass  * without setting EC_HOST_ARGS_FLAG_TO_HOST).
60688364387SHung-ying Tyan  */
60788364387SHung-ying Tyan #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
60888364387SHung-ying Tyan /*
60988364387SHung-ying Tyan  * Args are from EC.  Data area at EC_LPC_ADDR_HOST_PARAM contains response.
61088364387SHung-ying Tyan  *
61188364387SHung-ying Tyan  * If EC responds to a command and this flag is not set, this is an old-style
61288364387SHung-ying Tyan  * response.  Command version is 0 and response data from EC is at
61388364387SHung-ying Tyan  * EC_LPC_ADDR_OLD_PARAM with unknown length.
61488364387SHung-ying Tyan  */
61588364387SHung-ying Tyan #define EC_HOST_ARGS_FLAG_TO_HOST   0x02
61688364387SHung-ying Tyan 
617836bb6e8SSimon Glass /*****************************************************************************/
618*6f1c0430SSimon Glass /*
619*6f1c0430SSimon Glass  * Byte codes returned by EC over SPI interface.
620*6f1c0430SSimon Glass  *
621*6f1c0430SSimon Glass  * These can be used by the AP to debug the EC interface, and to determine
622*6f1c0430SSimon Glass  * when the EC is not in a state where it will ever get around to responding
623*6f1c0430SSimon Glass  * to the AP.
624*6f1c0430SSimon Glass  *
625*6f1c0430SSimon Glass  * Example of sequence of bytes read from EC for a current good transfer:
626*6f1c0430SSimon Glass  *   1. -                  - AP asserts chip select (CS#)
627*6f1c0430SSimon Glass  *   2. EC_SPI_OLD_READY   - AP sends first byte(s) of request
628*6f1c0430SSimon Glass  *   3. -                  - EC starts handling CS# interrupt
629*6f1c0430SSimon Glass  *   4. EC_SPI_RECEIVING   - AP sends remaining byte(s) of request
630*6f1c0430SSimon Glass  *   5. EC_SPI_PROCESSING  - EC starts processing request; AP is clocking in
631*6f1c0430SSimon Glass  *                           bytes looking for EC_SPI_FRAME_START
632*6f1c0430SSimon Glass  *   6. -                  - EC finishes processing and sets up response
633*6f1c0430SSimon Glass  *   7. EC_SPI_FRAME_START - AP reads frame byte
634*6f1c0430SSimon Glass  *   8. (response packet)  - AP reads response packet
635*6f1c0430SSimon Glass  *   9. EC_SPI_PAST_END    - Any additional bytes read by AP
636*6f1c0430SSimon Glass  *   10 -                  - AP deasserts chip select
637*6f1c0430SSimon Glass  *   11 -                  - EC processes CS# interrupt and sets up DMA for
638*6f1c0430SSimon Glass  *                           next request
639*6f1c0430SSimon Glass  *
640*6f1c0430SSimon Glass  * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
641*6f1c0430SSimon Glass  * the following byte values:
642*6f1c0430SSimon Glass  *   EC_SPI_OLD_READY
643*6f1c0430SSimon Glass  *   EC_SPI_RX_READY
644*6f1c0430SSimon Glass  *   EC_SPI_RECEIVING
645*6f1c0430SSimon Glass  *   EC_SPI_PROCESSING
646*6f1c0430SSimon Glass  *
647*6f1c0430SSimon Glass  * Then the EC found an error in the request, or was not ready for the request
648*6f1c0430SSimon Glass  * and lost data.  The AP should give up waiting for EC_SPI_FRAME_START,
649*6f1c0430SSimon Glass  * because the EC is unable to tell when the AP is done sending its request.
650*6f1c0430SSimon Glass  */
651*6f1c0430SSimon Glass 
652*6f1c0430SSimon Glass /*
653*6f1c0430SSimon Glass  * Framing byte which precedes a response packet from the EC.  After sending a
654*6f1c0430SSimon Glass  * request, the AP will clock in bytes until it sees the framing byte, then
655*6f1c0430SSimon Glass  * clock in the response packet.
656*6f1c0430SSimon Glass  */
657*6f1c0430SSimon Glass #define EC_SPI_FRAME_START    0xec
658*6f1c0430SSimon Glass 
659*6f1c0430SSimon Glass /*
660*6f1c0430SSimon Glass  * Padding bytes which are clocked out after the end of a response packet.
661*6f1c0430SSimon Glass  */
662*6f1c0430SSimon Glass #define EC_SPI_PAST_END       0xed
663*6f1c0430SSimon Glass 
664*6f1c0430SSimon Glass /*
665*6f1c0430SSimon Glass  * EC is ready to receive, and has ignored the byte sent by the AP.  EC expects
666*6f1c0430SSimon Glass  * that the AP will send a valid packet header (starting with
667*6f1c0430SSimon Glass  * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
668*6f1c0430SSimon Glass  */
669*6f1c0430SSimon Glass #define EC_SPI_RX_READY       0xf8
670*6f1c0430SSimon Glass 
671*6f1c0430SSimon Glass /*
672*6f1c0430SSimon Glass  * EC has started receiving the request from the AP, but hasn't started
673*6f1c0430SSimon Glass  * processing it yet.
674*6f1c0430SSimon Glass  */
675*6f1c0430SSimon Glass #define EC_SPI_RECEIVING      0xf9
676*6f1c0430SSimon Glass 
677*6f1c0430SSimon Glass /* EC has received the entire request from the AP and is processing it. */
678*6f1c0430SSimon Glass #define EC_SPI_PROCESSING     0xfa
679*6f1c0430SSimon Glass 
680*6f1c0430SSimon Glass /*
681*6f1c0430SSimon Glass  * EC received bad data from the AP, such as a packet header with an invalid
682*6f1c0430SSimon Glass  * length.  EC will ignore all data until chip select deasserts.
683*6f1c0430SSimon Glass  */
684*6f1c0430SSimon Glass #define EC_SPI_RX_BAD_DATA    0xfb
685*6f1c0430SSimon Glass 
686*6f1c0430SSimon Glass /*
687*6f1c0430SSimon Glass  * EC received data from the AP before it was ready.  That is, the AP asserted
688*6f1c0430SSimon Glass  * chip select and started clocking data before the EC was ready to receive it.
689*6f1c0430SSimon Glass  * EC will ignore all data until chip select deasserts.
690*6f1c0430SSimon Glass  */
691*6f1c0430SSimon Glass #define EC_SPI_NOT_READY      0xfc
692*6f1c0430SSimon Glass 
693*6f1c0430SSimon Glass /*
694*6f1c0430SSimon Glass  * EC was ready to receive a request from the AP.  EC has treated the byte sent
695*6f1c0430SSimon Glass  * by the AP as part of a request packet, or (for old-style ECs) is processing
696*6f1c0430SSimon Glass  * a fully received packet but is not ready to respond yet.
697*6f1c0430SSimon Glass  */
698*6f1c0430SSimon Glass #define EC_SPI_OLD_READY      0xfd
699*6f1c0430SSimon Glass 
700*6f1c0430SSimon Glass /*****************************************************************************/
701836bb6e8SSimon Glass 
702836bb6e8SSimon Glass /*
703836bb6e8SSimon Glass  * Protocol version 2 for I2C and SPI send a request this way:
704836bb6e8SSimon Glass  *
705836bb6e8SSimon Glass  *	0	EC_CMD_VERSION0 + (command version)
706836bb6e8SSimon Glass  *	1	Command number
707836bb6e8SSimon Glass  *	2	Length of params = N
708836bb6e8SSimon Glass  *	3..N+2	Params, if any
709836bb6e8SSimon Glass  *	N+3	8-bit checksum of bytes 0..N+2
710836bb6e8SSimon Glass  *
711836bb6e8SSimon Glass  * The corresponding response is:
712836bb6e8SSimon Glass  *
713836bb6e8SSimon Glass  *	0	Result code (EC_RES_*)
714836bb6e8SSimon Glass  *	1	Length of params = M
715836bb6e8SSimon Glass  *	2..M+1	Params, if any
716836bb6e8SSimon Glass  *	M+2	8-bit checksum of bytes 0..M+1
717836bb6e8SSimon Glass  */
718836bb6e8SSimon Glass #define EC_PROTO2_REQUEST_HEADER_BYTES 3
719836bb6e8SSimon Glass #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
720836bb6e8SSimon Glass #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES +	\
721836bb6e8SSimon Glass 				    EC_PROTO2_REQUEST_TRAILER_BYTES)
722836bb6e8SSimon Glass 
723836bb6e8SSimon Glass #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
724836bb6e8SSimon Glass #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
725836bb6e8SSimon Glass #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES +	\
726836bb6e8SSimon Glass 				     EC_PROTO2_RESPONSE_TRAILER_BYTES)
727836bb6e8SSimon Glass 
728836bb6e8SSimon Glass /* Parameter length was limited by the LPC interface */
729836bb6e8SSimon Glass #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
730836bb6e8SSimon Glass 
731836bb6e8SSimon Glass /* Maximum request and response packet sizes for protocol version 2 */
732836bb6e8SSimon Glass #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD +	\
733836bb6e8SSimon Glass 				    EC_PROTO2_MAX_PARAM_SIZE)
734836bb6e8SSimon Glass #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD +	\
735836bb6e8SSimon Glass 				     EC_PROTO2_MAX_PARAM_SIZE)
736836bb6e8SSimon Glass 
737836bb6e8SSimon Glass /*****************************************************************************/
738836bb6e8SSimon Glass 
739836bb6e8SSimon Glass /*
740836bb6e8SSimon Glass  * Value written to legacy command port / prefix byte to indicate protocol
741836bb6e8SSimon Glass  * 3+ structs are being used.  Usage is bus-dependent.
742836bb6e8SSimon Glass  */
743836bb6e8SSimon Glass #define EC_COMMAND_PROTOCOL_3 0xda
744836bb6e8SSimon Glass 
745836bb6e8SSimon Glass #define EC_HOST_REQUEST_VERSION 3
746836bb6e8SSimon Glass 
747836bb6e8SSimon Glass /* Version 3 request from host */
748*6f1c0430SSimon Glass struct __ec_align4 ec_host_request {
749*6f1c0430SSimon Glass 	/* Structure version (=3)
750836bb6e8SSimon Glass 	 *
751836bb6e8SSimon Glass 	 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
752836bb6e8SSimon Glass 	 * version it doesn't know how to parse.
753836bb6e8SSimon Glass 	 */
754836bb6e8SSimon Glass 	uint8_t struct_version;
755836bb6e8SSimon Glass 
756836bb6e8SSimon Glass 	/*
757836bb6e8SSimon Glass 	 * Checksum of request and data; sum of all bytes including checksum
758836bb6e8SSimon Glass 	 * should total to 0.
759836bb6e8SSimon Glass 	 */
760836bb6e8SSimon Glass 	uint8_t checksum;
761836bb6e8SSimon Glass 
762836bb6e8SSimon Glass 	/* Command code */
763836bb6e8SSimon Glass 	uint16_t command;
764836bb6e8SSimon Glass 
765836bb6e8SSimon Glass 	/* Command version */
766836bb6e8SSimon Glass 	uint8_t command_version;
767836bb6e8SSimon Glass 
768836bb6e8SSimon Glass 	/* Unused byte in current protocol version; set to 0 */
769836bb6e8SSimon Glass 	uint8_t reserved;
770836bb6e8SSimon Glass 
771836bb6e8SSimon Glass 	/* Length of data which follows this header */
772836bb6e8SSimon Glass 	uint16_t data_len;
773*6f1c0430SSimon Glass };
774836bb6e8SSimon Glass 
775836bb6e8SSimon Glass #define EC_HOST_RESPONSE_VERSION 3
776836bb6e8SSimon Glass 
777836bb6e8SSimon Glass /* Version 3 response from EC */
778*6f1c0430SSimon Glass struct __ec_align4 ec_host_response {
779*6f1c0430SSimon Glass 	/* Structure version (=3) */
780836bb6e8SSimon Glass 	uint8_t struct_version;
781836bb6e8SSimon Glass 
782836bb6e8SSimon Glass 	/*
783836bb6e8SSimon Glass 	 * Checksum of response and data; sum of all bytes including checksum
784836bb6e8SSimon Glass 	 * should total to 0.
785836bb6e8SSimon Glass 	 */
786836bb6e8SSimon Glass 	uint8_t checksum;
787836bb6e8SSimon Glass 
788836bb6e8SSimon Glass 	/* Result code (EC_RES_*) */
789836bb6e8SSimon Glass 	uint16_t result;
790836bb6e8SSimon Glass 
791836bb6e8SSimon Glass 	/* Length of data which follows this header */
792836bb6e8SSimon Glass 	uint16_t data_len;
793836bb6e8SSimon Glass 
794836bb6e8SSimon Glass 	/* Unused bytes in current protocol version; set to 0 */
795836bb6e8SSimon Glass 	uint16_t reserved;
796*6f1c0430SSimon Glass };
797836bb6e8SSimon Glass 
798836bb6e8SSimon Glass /*****************************************************************************/
79988364387SHung-ying Tyan /*
80088364387SHung-ying Tyan  * Notes on commands:
80188364387SHung-ying Tyan  *
802*6f1c0430SSimon Glass  * Each command is an 16-bit command value.  Commands which take params or
803*6f1c0430SSimon Glass  * return response data specify structures for that data.  If no structure is
80488364387SHung-ying Tyan  * specified, the command does not input or output data, respectively.
80588364387SHung-ying Tyan  * Parameter/response length is implicit in the structs.  Some underlying
80688364387SHung-ying Tyan  * communication protocols (I2C, SPI) may add length or checksum headers, but
80788364387SHung-ying Tyan  * those are implementation-dependent and not defined here.
808*6f1c0430SSimon Glass  *
809*6f1c0430SSimon Glass  * All commands MUST be #defined to be 4-digit UPPER CASE hex values
810*6f1c0430SSimon Glass  * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
81188364387SHung-ying Tyan  */
81288364387SHung-ying Tyan 
81388364387SHung-ying Tyan /*****************************************************************************/
81488364387SHung-ying Tyan /* General / test commands */
81588364387SHung-ying Tyan 
81688364387SHung-ying Tyan /*
81788364387SHung-ying Tyan  * Get protocol version, used to deal with non-backward compatible protocol
81888364387SHung-ying Tyan  * changes.
81988364387SHung-ying Tyan  */
820*6f1c0430SSimon Glass #define EC_CMD_PROTO_VERSION 0x0000
82188364387SHung-ying Tyan 
822*6f1c0430SSimon Glass struct __ec_align4 ec_response_proto_version {
82388364387SHung-ying Tyan 	uint32_t version;
824*6f1c0430SSimon Glass };
82588364387SHung-ying Tyan 
82688364387SHung-ying Tyan /*
82788364387SHung-ying Tyan  * Hello.  This is a simple command to test the EC is responsive to
82888364387SHung-ying Tyan  * commands.
82988364387SHung-ying Tyan  */
830*6f1c0430SSimon Glass #define EC_CMD_HELLO 0x0001
83188364387SHung-ying Tyan 
832*6f1c0430SSimon Glass struct __ec_align4 ec_params_hello {
83388364387SHung-ying Tyan 	uint32_t in_data;  /* Pass anything here */
834*6f1c0430SSimon Glass };
83588364387SHung-ying Tyan 
836*6f1c0430SSimon Glass struct __ec_align4 ec_response_hello {
83788364387SHung-ying Tyan 	uint32_t out_data;  /* Output will be in_data + 0x01020304 */
838*6f1c0430SSimon Glass };
83988364387SHung-ying Tyan 
84088364387SHung-ying Tyan /* Get version number */
841*6f1c0430SSimon Glass #define EC_CMD_GET_VERSION 0x0002
84288364387SHung-ying Tyan 
84388364387SHung-ying Tyan enum ec_current_image {
84488364387SHung-ying Tyan 	EC_IMAGE_UNKNOWN = 0,
84588364387SHung-ying Tyan 	EC_IMAGE_RO,
84688364387SHung-ying Tyan 	EC_IMAGE_RW
84788364387SHung-ying Tyan };
84888364387SHung-ying Tyan 
849*6f1c0430SSimon Glass struct __ec_align4 ec_response_get_version {
85088364387SHung-ying Tyan 	/* Null-terminated version strings for RO, RW */
85188364387SHung-ying Tyan 	char version_string_ro[32];
85288364387SHung-ying Tyan 	char version_string_rw[32];
85388364387SHung-ying Tyan 	char reserved[32];       /* Was previously RW-B string */
85488364387SHung-ying Tyan 	uint32_t current_image;  /* One of ec_current_image */
855*6f1c0430SSimon Glass };
85688364387SHung-ying Tyan 
85788364387SHung-ying Tyan /* Read test */
858*6f1c0430SSimon Glass #define EC_CMD_READ_TEST 0x0003
85988364387SHung-ying Tyan 
860*6f1c0430SSimon Glass struct __ec_align4 ec_params_read_test {
86188364387SHung-ying Tyan 	uint32_t offset;   /* Starting value for read buffer */
86288364387SHung-ying Tyan 	uint32_t size;     /* Size to read in bytes */
863*6f1c0430SSimon Glass };
86488364387SHung-ying Tyan 
865*6f1c0430SSimon Glass struct __ec_align4 ec_response_read_test {
86688364387SHung-ying Tyan 	uint32_t data[32];
867*6f1c0430SSimon Glass };
86888364387SHung-ying Tyan 
86988364387SHung-ying Tyan /*
87088364387SHung-ying Tyan  * Get build information
87188364387SHung-ying Tyan  *
87288364387SHung-ying Tyan  * Response is null-terminated string.
87388364387SHung-ying Tyan  */
874*6f1c0430SSimon Glass #define EC_CMD_GET_BUILD_INFO 0x0004
87588364387SHung-ying Tyan 
87688364387SHung-ying Tyan /* Get chip info */
877*6f1c0430SSimon Glass #define EC_CMD_GET_CHIP_INFO 0x0005
87888364387SHung-ying Tyan 
879*6f1c0430SSimon Glass struct __ec_align4 ec_response_get_chip_info {
88088364387SHung-ying Tyan 	/* Null-terminated strings */
88188364387SHung-ying Tyan 	char vendor[32];
88288364387SHung-ying Tyan 	char name[32];
88388364387SHung-ying Tyan 	char revision[32];  /* Mask version */
884*6f1c0430SSimon Glass };
88588364387SHung-ying Tyan 
88688364387SHung-ying Tyan /* Get board HW version */
887*6f1c0430SSimon Glass #define EC_CMD_GET_BOARD_VERSION 0x0006
88888364387SHung-ying Tyan 
889*6f1c0430SSimon Glass struct __ec_align2 ec_response_board_version {
89088364387SHung-ying Tyan 	uint16_t board_version;  /* A monotonously incrementing number. */
891*6f1c0430SSimon Glass };
89288364387SHung-ying Tyan 
89388364387SHung-ying Tyan /*
89488364387SHung-ying Tyan  * Read memory-mapped data.
89588364387SHung-ying Tyan  *
89688364387SHung-ying Tyan  * This is an alternate interface to memory-mapped data for bus protocols
89788364387SHung-ying Tyan  * which don't support direct-mapped memory - I2C, SPI, etc.
89888364387SHung-ying Tyan  *
89988364387SHung-ying Tyan  * Response is params.size bytes of data.
90088364387SHung-ying Tyan  */
901*6f1c0430SSimon Glass #define EC_CMD_READ_MEMMAP 0x0007
90288364387SHung-ying Tyan 
903*6f1c0430SSimon Glass struct __ec_align1 ec_params_read_memmap {
90488364387SHung-ying Tyan 	uint8_t offset;   /* Offset in memmap (EC_MEMMAP_*) */
90588364387SHung-ying Tyan 	uint8_t size;     /* Size to read in bytes */
906*6f1c0430SSimon Glass };
90788364387SHung-ying Tyan 
90888364387SHung-ying Tyan /* Read versions supported for a command */
909*6f1c0430SSimon Glass #define EC_CMD_GET_CMD_VERSIONS 0x0008
91088364387SHung-ying Tyan 
911*6f1c0430SSimon Glass struct __ec_align1 ec_params_get_cmd_versions {
91288364387SHung-ying Tyan 	uint8_t cmd;      /* Command to check */
913*6f1c0430SSimon Glass };
91488364387SHung-ying Tyan 
915*6f1c0430SSimon Glass struct __ec_align2 ec_params_get_cmd_versions_v1 {
916*6f1c0430SSimon Glass 	uint16_t cmd;     /* Command to check */
917*6f1c0430SSimon Glass };
918*6f1c0430SSimon Glass 
919*6f1c0430SSimon Glass struct __ec_align4 ec_response_get_cmd_versions {
92088364387SHung-ying Tyan 	/*
92188364387SHung-ying Tyan 	 * Mask of supported versions; use EC_VER_MASK() to compare with a
92288364387SHung-ying Tyan 	 * desired version.
92388364387SHung-ying Tyan 	 */
92488364387SHung-ying Tyan 	uint32_t version_mask;
925*6f1c0430SSimon Glass };
92688364387SHung-ying Tyan 
92788364387SHung-ying Tyan /*
928*6f1c0430SSimon Glass  * Check EC communications status (busy). This is needed on i2c/spi but not
92988364387SHung-ying Tyan  * on lpc since it has its own out-of-band busy indicator.
93088364387SHung-ying Tyan  *
93188364387SHung-ying Tyan  * lpc must read the status from the command register. Attempting this on
93288364387SHung-ying Tyan  * lpc will overwrite the args/parameter space and corrupt its data.
93388364387SHung-ying Tyan  */
934*6f1c0430SSimon Glass #define EC_CMD_GET_COMMS_STATUS		0x0009
93588364387SHung-ying Tyan 
93688364387SHung-ying Tyan /* Avoid using ec_status which is for return values */
93788364387SHung-ying Tyan enum ec_comms_status {
93888364387SHung-ying Tyan 	EC_COMMS_STATUS_PROCESSING	= 1 << 0,	/* Processing cmd */
93988364387SHung-ying Tyan };
94088364387SHung-ying Tyan 
941*6f1c0430SSimon Glass struct __ec_align4 ec_response_get_comms_status {
94288364387SHung-ying Tyan 	uint32_t flags;		/* Mask of enum ec_comms_status */
943*6f1c0430SSimon Glass };
94488364387SHung-ying Tyan 
945*6f1c0430SSimon Glass /* Fake a variety of responses, purely for testing purposes. */
946*6f1c0430SSimon Glass #define EC_CMD_TEST_PROTOCOL		0x000A
947836bb6e8SSimon Glass 
948836bb6e8SSimon Glass /* Tell the EC what to send back to us. */
949*6f1c0430SSimon Glass struct __ec_align4 ec_params_test_protocol {
950836bb6e8SSimon Glass 	uint32_t ec_result;
951836bb6e8SSimon Glass 	uint32_t ret_len;
952836bb6e8SSimon Glass 	uint8_t buf[32];
953*6f1c0430SSimon Glass };
954836bb6e8SSimon Glass 
955836bb6e8SSimon Glass /* Here it comes... */
956*6f1c0430SSimon Glass struct __ec_align4 ec_response_test_protocol {
957836bb6e8SSimon Glass 	uint8_t buf[32];
958*6f1c0430SSimon Glass };
959836bb6e8SSimon Glass 
960*6f1c0430SSimon Glass /* Get protocol information */
961*6f1c0430SSimon Glass #define EC_CMD_GET_PROTOCOL_INFO	0x000B
962836bb6e8SSimon Glass 
963836bb6e8SSimon Glass /* Flags for ec_response_get_protocol_info.flags */
964836bb6e8SSimon Glass /* EC_RES_IN_PROGRESS may be returned if a command is slow */
965836bb6e8SSimon Glass #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
966836bb6e8SSimon Glass 
967*6f1c0430SSimon Glass struct __ec_align4 ec_response_get_protocol_info {
968836bb6e8SSimon Glass 	/* Fields which exist if at least protocol version 3 supported */
969836bb6e8SSimon Glass 
970836bb6e8SSimon Glass 	/* Bitmask of protocol versions supported (1 << n means version n)*/
971836bb6e8SSimon Glass 	uint32_t protocol_versions;
972836bb6e8SSimon Glass 
973836bb6e8SSimon Glass 	/* Maximum request packet size, in bytes */
974836bb6e8SSimon Glass 	uint16_t max_request_packet_size;
975836bb6e8SSimon Glass 
976836bb6e8SSimon Glass 	/* Maximum response packet size, in bytes */
977836bb6e8SSimon Glass 	uint16_t max_response_packet_size;
978836bb6e8SSimon Glass 
979836bb6e8SSimon Glass 	/* Flags; see EC_PROTOCOL_INFO_* */
980836bb6e8SSimon Glass 	uint32_t flags;
981*6f1c0430SSimon Glass };
982*6f1c0430SSimon Glass 
983*6f1c0430SSimon Glass 
984*6f1c0430SSimon Glass /*****************************************************************************/
985*6f1c0430SSimon Glass /* Get/Set miscellaneous values */
986*6f1c0430SSimon Glass 
987*6f1c0430SSimon Glass /* The upper byte of .flags tells what to do (nothing means "get") */
988*6f1c0430SSimon Glass #define EC_GSV_SET        0x80000000
989*6f1c0430SSimon Glass 
990*6f1c0430SSimon Glass /* The lower three bytes of .flags identifies the parameter, if that has
991*6f1c0430SSimon Glass    meaning for an individual command. */
992*6f1c0430SSimon Glass #define EC_GSV_PARAM_MASK 0x00ffffff
993*6f1c0430SSimon Glass 
994*6f1c0430SSimon Glass struct __ec_align4 ec_params_get_set_value {
995*6f1c0430SSimon Glass 	uint32_t flags;
996*6f1c0430SSimon Glass 	uint32_t value;
997*6f1c0430SSimon Glass };
998*6f1c0430SSimon Glass 
999*6f1c0430SSimon Glass struct __ec_align4 ec_response_get_set_value {
1000*6f1c0430SSimon Glass 	uint32_t flags;
1001*6f1c0430SSimon Glass 	uint32_t value;
1002*6f1c0430SSimon Glass };
1003*6f1c0430SSimon Glass 
1004*6f1c0430SSimon Glass /* More than one command can use these structs to get/set parameters. */
1005*6f1c0430SSimon Glass #define EC_CMD_GSV_PAUSE_IN_S5	0x000C
1006*6f1c0430SSimon Glass 
1007*6f1c0430SSimon Glass /*****************************************************************************/
1008*6f1c0430SSimon Glass /* List the features supported by the firmware */
1009*6f1c0430SSimon Glass #define EC_CMD_GET_FEATURES  0x000D
1010*6f1c0430SSimon Glass 
1011*6f1c0430SSimon Glass /* Supported features */
1012*6f1c0430SSimon Glass enum ec_feature_code {
1013*6f1c0430SSimon Glass 	/*
1014*6f1c0430SSimon Glass 	 * This image contains a limited set of features. Another image
1015*6f1c0430SSimon Glass 	 * in RW partition may support more features.
1016*6f1c0430SSimon Glass 	 */
1017*6f1c0430SSimon Glass 	EC_FEATURE_LIMITED = 0,
1018*6f1c0430SSimon Glass 	/*
1019*6f1c0430SSimon Glass 	 * Commands for probing/reading/writing/erasing the flash in the
1020*6f1c0430SSimon Glass 	 * EC are present.
1021*6f1c0430SSimon Glass 	 */
1022*6f1c0430SSimon Glass 	EC_FEATURE_FLASH = 1,
1023*6f1c0430SSimon Glass 	/*
1024*6f1c0430SSimon Glass 	 * Can control the fan speed directly.
1025*6f1c0430SSimon Glass 	 */
1026*6f1c0430SSimon Glass 	EC_FEATURE_PWM_FAN = 2,
1027*6f1c0430SSimon Glass 	/*
1028*6f1c0430SSimon Glass 	 * Can control the intensity of the keyboard backlight.
1029*6f1c0430SSimon Glass 	 */
1030*6f1c0430SSimon Glass 	EC_FEATURE_PWM_KEYB = 3,
1031*6f1c0430SSimon Glass 	/*
1032*6f1c0430SSimon Glass 	 * Support Google lightbar, introduced on Pixel.
1033*6f1c0430SSimon Glass 	 */
1034*6f1c0430SSimon Glass 	EC_FEATURE_LIGHTBAR = 4,
1035*6f1c0430SSimon Glass 	/* Control of LEDs  */
1036*6f1c0430SSimon Glass 	EC_FEATURE_LED = 5,
1037*6f1c0430SSimon Glass 	/* Exposes an interface to control gyro and sensors.
1038*6f1c0430SSimon Glass 	 * The host goes through the EC to access these sensors.
1039*6f1c0430SSimon Glass 	 * In addition, the EC may provide composite sensors, like lid angle.
1040*6f1c0430SSimon Glass 	 */
1041*6f1c0430SSimon Glass 	EC_FEATURE_MOTION_SENSE = 6,
1042*6f1c0430SSimon Glass 	/* The keyboard is controlled by the EC */
1043*6f1c0430SSimon Glass 	EC_FEATURE_KEYB = 7,
1044*6f1c0430SSimon Glass 	/* The AP can use part of the EC flash as persistent storage. */
1045*6f1c0430SSimon Glass 	EC_FEATURE_PSTORE = 8,
1046*6f1c0430SSimon Glass 	/* The EC monitors BIOS port 80h, and can return POST codes. */
1047*6f1c0430SSimon Glass 	EC_FEATURE_PORT80 = 9,
1048*6f1c0430SSimon Glass 	/*
1049*6f1c0430SSimon Glass 	 * Thermal management: include TMP specific commands.
1050*6f1c0430SSimon Glass 	 * Higher level than direct fan control.
1051*6f1c0430SSimon Glass 	 */
1052*6f1c0430SSimon Glass 	EC_FEATURE_THERMAL = 10,
1053*6f1c0430SSimon Glass 	/* Can switch the screen backlight on/off */
1054*6f1c0430SSimon Glass 	EC_FEATURE_BKLIGHT_SWITCH = 11,
1055*6f1c0430SSimon Glass 	/* Can switch the wifi module on/off */
1056*6f1c0430SSimon Glass 	EC_FEATURE_WIFI_SWITCH = 12,
1057*6f1c0430SSimon Glass 	/* Monitor host events, through for example SMI or SCI */
1058*6f1c0430SSimon Glass 	EC_FEATURE_HOST_EVENTS = 13,
1059*6f1c0430SSimon Glass 	/* The EC exposes GPIO commands to control/monitor connected devices. */
1060*6f1c0430SSimon Glass 	EC_FEATURE_GPIO = 14,
1061*6f1c0430SSimon Glass 	/* The EC can send i2c messages to downstream devices. */
1062*6f1c0430SSimon Glass 	EC_FEATURE_I2C = 15,
1063*6f1c0430SSimon Glass 	/* Command to control charger are included */
1064*6f1c0430SSimon Glass 	EC_FEATURE_CHARGER = 16,
1065*6f1c0430SSimon Glass 	/* Simple battery support. */
1066*6f1c0430SSimon Glass 	EC_FEATURE_BATTERY = 17,
1067*6f1c0430SSimon Glass 	/*
1068*6f1c0430SSimon Glass 	 * Support Smart battery protocol
1069*6f1c0430SSimon Glass 	 * (Common Smart Battery System Interface Specification)
1070*6f1c0430SSimon Glass 	 */
1071*6f1c0430SSimon Glass 	EC_FEATURE_SMART_BATTERY = 18,
1072*6f1c0430SSimon Glass 	/* EC can detect when the host hangs. */
1073*6f1c0430SSimon Glass 	EC_FEATURE_HANG_DETECT = 19,
1074*6f1c0430SSimon Glass 	/* Report power information, for pit only */
1075*6f1c0430SSimon Glass 	EC_FEATURE_PMU = 20,
1076*6f1c0430SSimon Glass 	/* Another Cros EC device is present downstream of this one */
1077*6f1c0430SSimon Glass 	EC_FEATURE_SUB_MCU = 21,
1078*6f1c0430SSimon Glass 	/* Support USB Power delivery (PD) commands */
1079*6f1c0430SSimon Glass 	EC_FEATURE_USB_PD = 22,
1080*6f1c0430SSimon Glass 	/* Control USB multiplexer, for audio through USB port for instance. */
1081*6f1c0430SSimon Glass 	EC_FEATURE_USB_MUX = 23,
1082*6f1c0430SSimon Glass 	/* Motion Sensor code has an internal software FIFO */
1083*6f1c0430SSimon Glass 	EC_FEATURE_MOTION_SENSE_FIFO = 24,
1084*6f1c0430SSimon Glass 	/* Support temporary secure vstore */
1085*6f1c0430SSimon Glass 	EC_FEATURE_VSTORE = 25,
1086*6f1c0430SSimon Glass 	/* EC decides on USB-C SS mux state, muxes configured by host */
1087*6f1c0430SSimon Glass 	EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1088*6f1c0430SSimon Glass 	/* EC has RTC feature that can be controlled by host commands */
1089*6f1c0430SSimon Glass 	EC_FEATURE_RTC = 27,
1090*6f1c0430SSimon Glass 	/* The MCU exposes a Fingerprint sensor */
1091*6f1c0430SSimon Glass 	EC_FEATURE_FINGERPRINT = 28,
1092*6f1c0430SSimon Glass 	/* The MCU exposes a Touchpad */
1093*6f1c0430SSimon Glass 	EC_FEATURE_TOUCHPAD = 29,
1094*6f1c0430SSimon Glass 	/* The MCU has RWSIG task enabled */
1095*6f1c0430SSimon Glass 	EC_FEATURE_RWSIG = 30,
1096*6f1c0430SSimon Glass 	/* EC has device events support */
1097*6f1c0430SSimon Glass 	EC_FEATURE_DEVICE_EVENT = 31,
1098*6f1c0430SSimon Glass 	/* EC supports the unified wake masks for LPC/eSPI systems */
1099*6f1c0430SSimon Glass 	EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
1100*6f1c0430SSimon Glass };
1101*6f1c0430SSimon Glass 
1102*6f1c0430SSimon Glass #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
1103*6f1c0430SSimon Glass #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
1104*6f1c0430SSimon Glass struct __ec_align4 ec_response_get_features {
1105*6f1c0430SSimon Glass 	uint32_t flags[2];
1106*6f1c0430SSimon Glass };
1107*6f1c0430SSimon Glass 
1108*6f1c0430SSimon Glass /*****************************************************************************/
1109*6f1c0430SSimon Glass /* Get the board's SKU ID from EC */
1110*6f1c0430SSimon Glass #define EC_CMD_GET_SKU_ID 0x000E
1111*6f1c0430SSimon Glass 
1112*6f1c0430SSimon Glass /* Set SKU ID from AP */
1113*6f1c0430SSimon Glass #define EC_CMD_SET_SKU_ID 0x000F
1114*6f1c0430SSimon Glass 
1115*6f1c0430SSimon Glass struct __ec_align4 ec_sku_id_info {
1116*6f1c0430SSimon Glass 	uint32_t sku_id;
1117*6f1c0430SSimon Glass };
111888364387SHung-ying Tyan 
111988364387SHung-ying Tyan /*****************************************************************************/
112088364387SHung-ying Tyan /* Flash commands */
112188364387SHung-ying Tyan 
112288364387SHung-ying Tyan /* Get flash info */
1123*6f1c0430SSimon Glass #define EC_CMD_FLASH_INFO 0x0010
1124*6f1c0430SSimon Glass #define EC_VER_FLASH_INFO 2
112588364387SHung-ying Tyan 
1126*6f1c0430SSimon Glass /* Version 0 returns these fields */
1127*6f1c0430SSimon Glass struct __ec_align4 ec_response_flash_info {
112888364387SHung-ying Tyan 	/* Usable flash size, in bytes */
112988364387SHung-ying Tyan 	uint32_t flash_size;
113088364387SHung-ying Tyan 	/*
113188364387SHung-ying Tyan 	 * Write block size.  Write offset and size must be a multiple
113288364387SHung-ying Tyan 	 * of this.
113388364387SHung-ying Tyan 	 */
113488364387SHung-ying Tyan 	uint32_t write_block_size;
113588364387SHung-ying Tyan 	/*
113688364387SHung-ying Tyan 	 * Erase block size.  Erase offset and size must be a multiple
113788364387SHung-ying Tyan 	 * of this.
113888364387SHung-ying Tyan 	 */
113988364387SHung-ying Tyan 	uint32_t erase_block_size;
114088364387SHung-ying Tyan 	/*
114188364387SHung-ying Tyan 	 * Protection block size.  Protection offset and size must be a
114288364387SHung-ying Tyan 	 * multiple of this.
114388364387SHung-ying Tyan 	 */
114488364387SHung-ying Tyan 	uint32_t protect_block_size;
1145*6f1c0430SSimon Glass };
1146*6f1c0430SSimon Glass 
1147*6f1c0430SSimon Glass /* Flags for version 1+ flash info command */
1148*6f1c0430SSimon Glass /* EC flash erases bits to 0 instead of 1 */
1149*6f1c0430SSimon Glass #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
1150*6f1c0430SSimon Glass 
1151*6f1c0430SSimon Glass /* Flash must be selected for read/write/erase operations to succeed.  This may
1152*6f1c0430SSimon Glass  * be necessary on a chip where write/erase can be corrupted by other board
1153*6f1c0430SSimon Glass  * activity, or where the chip needs to enable some sort of programming voltage,
1154*6f1c0430SSimon Glass  * or where the read/write/erase operations require cleanly suspending other
1155*6f1c0430SSimon Glass  * chip functionality. */
1156*6f1c0430SSimon Glass #define EC_FLASH_INFO_SELECT_REQUIRED (1 << 1)
1157*6f1c0430SSimon Glass 
1158*6f1c0430SSimon Glass /*
1159*6f1c0430SSimon Glass  * Version 1 returns the same initial fields as version 0, with additional
1160*6f1c0430SSimon Glass  * fields following.
1161*6f1c0430SSimon Glass  *
1162*6f1c0430SSimon Glass  * gcc anonymous structs don't seem to get along with the __packed directive;
1163*6f1c0430SSimon Glass  * if they did we'd define the version 0 structure as a sub-structure of this
1164*6f1c0430SSimon Glass  * one.
1165*6f1c0430SSimon Glass  *
1166*6f1c0430SSimon Glass  * Version 2 supports flash banks of different sizes:
1167*6f1c0430SSimon Glass  * The caller specified the number of banks it has preallocated
1168*6f1c0430SSimon Glass  * (num_banks_desc)
1169*6f1c0430SSimon Glass  * The EC returns the number of banks describing the flash memory.
1170*6f1c0430SSimon Glass  * It adds banks descriptions up to num_banks_desc.
1171*6f1c0430SSimon Glass  */
1172*6f1c0430SSimon Glass struct __ec_align4 ec_response_flash_info_1 {
1173*6f1c0430SSimon Glass 	/* Version 0 fields; see above for description */
1174*6f1c0430SSimon Glass 	uint32_t flash_size;
1175*6f1c0430SSimon Glass 	uint32_t write_block_size;
1176*6f1c0430SSimon Glass 	uint32_t erase_block_size;
1177*6f1c0430SSimon Glass 	uint32_t protect_block_size;
1178*6f1c0430SSimon Glass 
1179*6f1c0430SSimon Glass 	/* Version 1 adds these fields: */
1180*6f1c0430SSimon Glass 	/*
1181*6f1c0430SSimon Glass 	 * Ideal write size in bytes.  Writes will be fastest if size is
1182*6f1c0430SSimon Glass 	 * exactly this and offset is a multiple of this.  For example, an EC
1183*6f1c0430SSimon Glass 	 * may have a write buffer which can do half-page operations if data is
1184*6f1c0430SSimon Glass 	 * aligned, and a slower word-at-a-time write mode.
1185*6f1c0430SSimon Glass 	 */
1186*6f1c0430SSimon Glass 	uint32_t write_ideal_size;
1187*6f1c0430SSimon Glass 
1188*6f1c0430SSimon Glass 	/* Flags; see EC_FLASH_INFO_* */
1189*6f1c0430SSimon Glass 	uint32_t flags;
1190*6f1c0430SSimon Glass };
1191*6f1c0430SSimon Glass 
1192*6f1c0430SSimon Glass struct __ec_align4 ec_params_flash_info_2 {
1193*6f1c0430SSimon Glass 	/* Number of banks to describe */
1194*6f1c0430SSimon Glass 	uint16_t num_banks_desc;
1195*6f1c0430SSimon Glass 	/* Reserved; set 0; ignore on read */
1196*6f1c0430SSimon Glass 	uint8_t reserved[2];
1197*6f1c0430SSimon Glass };
1198*6f1c0430SSimon Glass 
1199*6f1c0430SSimon Glass struct ec_flash_bank {
1200*6f1c0430SSimon Glass 	/* Number of sector is in this bank. */
1201*6f1c0430SSimon Glass 	uint16_t count;
1202*6f1c0430SSimon Glass 	/* Size in power of 2 of each sector (8 --> 256 bytes) */
1203*6f1c0430SSimon Glass 	uint8_t size_exp;
1204*6f1c0430SSimon Glass 	/* Minimal write size for the sectors in this bank */
1205*6f1c0430SSimon Glass 	uint8_t write_size_exp;
1206*6f1c0430SSimon Glass 	/* Erase size for the sectors in this bank */
1207*6f1c0430SSimon Glass 	uint8_t erase_size_exp;
1208*6f1c0430SSimon Glass 	/* Size for write protection, usually identical to erase size. */
1209*6f1c0430SSimon Glass 	uint8_t protect_size_exp;
1210*6f1c0430SSimon Glass 	/* Reserved; set 0; ignore on read */
1211*6f1c0430SSimon Glass 	uint8_t reserved[2];
1212*6f1c0430SSimon Glass };
1213*6f1c0430SSimon Glass 
1214*6f1c0430SSimon Glass struct __ec_align4 ec_response_flash_info_2 {
1215*6f1c0430SSimon Glass 	/* Total flash in the EC. */
1216*6f1c0430SSimon Glass 	uint32_t flash_size;
1217*6f1c0430SSimon Glass 	/* Flags; see EC_FLASH_INFO_* */
1218*6f1c0430SSimon Glass 	uint32_t flags;
1219*6f1c0430SSimon Glass 	/* Maximum size to use to send data to write to the EC. */
1220*6f1c0430SSimon Glass 	uint32_t write_ideal_size;
1221*6f1c0430SSimon Glass 	/* Number of banks present in the EC. */
1222*6f1c0430SSimon Glass 	uint16_t num_banks_total;
1223*6f1c0430SSimon Glass 	/* Number of banks described in banks array. */
1224*6f1c0430SSimon Glass 	uint16_t num_banks_desc;
1225*6f1c0430SSimon Glass 	struct ec_flash_bank banks[0];
1226*6f1c0430SSimon Glass };
122788364387SHung-ying Tyan 
122888364387SHung-ying Tyan /*
122988364387SHung-ying Tyan  * Read flash
123088364387SHung-ying Tyan  *
123188364387SHung-ying Tyan  * Response is params.size bytes of data.
123288364387SHung-ying Tyan  */
1233*6f1c0430SSimon Glass #define EC_CMD_FLASH_READ 0x0011
123488364387SHung-ying Tyan 
1235*6f1c0430SSimon Glass struct __ec_align4 ec_params_flash_read {
123688364387SHung-ying Tyan 	uint32_t offset;   /* Byte offset to read */
123788364387SHung-ying Tyan 	uint32_t size;     /* Size to read in bytes */
1238*6f1c0430SSimon Glass };
123988364387SHung-ying Tyan 
124088364387SHung-ying Tyan /* Write flash */
1241*6f1c0430SSimon Glass #define EC_CMD_FLASH_WRITE 0x0012
1242836bb6e8SSimon Glass #define EC_VER_FLASH_WRITE 1
1243836bb6e8SSimon Glass 
1244836bb6e8SSimon Glass /* Version 0 of the flash command supported only 64 bytes of data */
1245836bb6e8SSimon Glass #define EC_FLASH_WRITE_VER0_SIZE 64
124688364387SHung-ying Tyan 
1247*6f1c0430SSimon Glass struct __ec_align4 ec_params_flash_write {
124888364387SHung-ying Tyan 	uint32_t offset;   /* Byte offset to write */
124988364387SHung-ying Tyan 	uint32_t size;     /* Size to write in bytes */
1250836bb6e8SSimon Glass 	/* Followed by data to write */
1251*6f1c0430SSimon Glass };
125288364387SHung-ying Tyan 
125388364387SHung-ying Tyan /* Erase flash */
1254*6f1c0430SSimon Glass #define EC_CMD_FLASH_ERASE 0x0013
125588364387SHung-ying Tyan 
1256*6f1c0430SSimon Glass /* v0 */
1257*6f1c0430SSimon Glass struct __ec_align4 ec_params_flash_erase {
125888364387SHung-ying Tyan 	uint32_t offset;   /* Byte offset to erase */
125988364387SHung-ying Tyan 	uint32_t size;     /* Size to erase in bytes */
1260*6f1c0430SSimon Glass };
1261*6f1c0430SSimon Glass 
1262*6f1c0430SSimon Glass 
1263*6f1c0430SSimon Glass #define EC_VER_FLASH_WRITE 1
1264*6f1c0430SSimon Glass /* v1 add async erase:
1265*6f1c0430SSimon Glass  * subcommands can returns:
1266*6f1c0430SSimon Glass  * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1267*6f1c0430SSimon Glass  * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1268*6f1c0430SSimon Glass  * EC_RES_ERROR : other errors.
1269*6f1c0430SSimon Glass  * EC_RES_BUSY : an existing erase operation is in progress.
1270*6f1c0430SSimon Glass  * EC_RES_ACCESS_DENIED: Trying to erase running image.
1271*6f1c0430SSimon Glass  *
1272*6f1c0430SSimon Glass  * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1273*6f1c0430SSimon Glass  * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1274*6f1c0430SSimon Glass  * the proper result.
1275*6f1c0430SSimon Glass  * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1276*6f1c0430SSimon Glass  * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1277*6f1c0430SSimon Glass  * ERASE_GET_RESULT command may timeout on EC where flash access is not
1278*6f1c0430SSimon Glass  * permitted while erasing. (For instance, STM32F4).
1279*6f1c0430SSimon Glass  */
1280*6f1c0430SSimon Glass enum ec_flash_erase_cmd {
1281*6f1c0430SSimon Glass 	FLASH_ERASE_SECTOR,     /* Erase and wait for result */
1282*6f1c0430SSimon Glass 	FLASH_ERASE_SECTOR_ASYNC,  /* Erase and return immediately. */
1283*6f1c0430SSimon Glass 	FLASH_ERASE_GET_RESULT,  /* Ask for last erase result */
1284*6f1c0430SSimon Glass };
1285*6f1c0430SSimon Glass 
1286*6f1c0430SSimon Glass struct __ec_align4 ec_params_flash_erase_v1 {
1287*6f1c0430SSimon Glass 	/* One of ec_flash_erase_cmd. */
1288*6f1c0430SSimon Glass 	uint8_t  cmd;
1289*6f1c0430SSimon Glass 	/* Pad byte; currently always contains 0 */
1290*6f1c0430SSimon Glass 	uint8_t  reserved;
1291*6f1c0430SSimon Glass 	/* No flags defined yet; set to 0 */
1292*6f1c0430SSimon Glass 	uint16_t flag;
1293*6f1c0430SSimon Glass 	/* Same as v0 parameters. */
1294*6f1c0430SSimon Glass 	struct ec_params_flash_erase params;
1295*6f1c0430SSimon Glass };
129688364387SHung-ying Tyan 
129788364387SHung-ying Tyan /*
129888364387SHung-ying Tyan  * Get/set flash protection.
129988364387SHung-ying Tyan  *
130088364387SHung-ying Tyan  * If mask!=0, sets/clear the requested bits of flags.  Depending on the
130188364387SHung-ying Tyan  * firmware write protect GPIO, not all flags will take effect immediately;
130288364387SHung-ying Tyan  * some flags require a subsequent hard reset to take effect.  Check the
130388364387SHung-ying Tyan  * returned flags bits to see what actually happened.
130488364387SHung-ying Tyan  *
130588364387SHung-ying Tyan  * If mask=0, simply returns the current flags state.
130688364387SHung-ying Tyan  */
1307*6f1c0430SSimon Glass #define EC_CMD_FLASH_PROTECT 0x0015
130888364387SHung-ying Tyan #define EC_VER_FLASH_PROTECT 1  /* Command version 1 */
130988364387SHung-ying Tyan 
131088364387SHung-ying Tyan /* Flags for flash protection */
131188364387SHung-ying Tyan /* RO flash code protected when the EC boots */
131288364387SHung-ying Tyan #define EC_FLASH_PROTECT_RO_AT_BOOT         (1 << 0)
131388364387SHung-ying Tyan /*
131488364387SHung-ying Tyan  * RO flash code protected now.  If this bit is set, at-boot status cannot
131588364387SHung-ying Tyan  * be changed.
131688364387SHung-ying Tyan  */
131788364387SHung-ying Tyan #define EC_FLASH_PROTECT_RO_NOW             (1 << 1)
131888364387SHung-ying Tyan /* Entire flash code protected now, until reboot. */
131988364387SHung-ying Tyan #define EC_FLASH_PROTECT_ALL_NOW            (1 << 2)
132088364387SHung-ying Tyan /* Flash write protect GPIO is asserted now */
132188364387SHung-ying Tyan #define EC_FLASH_PROTECT_GPIO_ASSERTED      (1 << 3)
132288364387SHung-ying Tyan /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
132388364387SHung-ying Tyan #define EC_FLASH_PROTECT_ERROR_STUCK        (1 << 4)
132488364387SHung-ying Tyan /*
132588364387SHung-ying Tyan  * Error - flash protection is in inconsistent state.  At least one bank of
132688364387SHung-ying Tyan  * flash which should be protected is not protected.  Usually fixed by
132788364387SHung-ying Tyan  * re-requesting the desired flags, or by a hard reset if that fails.
132888364387SHung-ying Tyan  */
132988364387SHung-ying Tyan #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
1330*6f1c0430SSimon Glass /* Entire flash code protected when the EC boots */
133188364387SHung-ying Tyan #define EC_FLASH_PROTECT_ALL_AT_BOOT        (1 << 6)
1332*6f1c0430SSimon Glass /* RW flash code protected when the EC boots */
1333*6f1c0430SSimon Glass #define EC_FLASH_PROTECT_RW_AT_BOOT         (1 << 7)
1334*6f1c0430SSimon Glass /* RW flash code protected now. */
1335*6f1c0430SSimon Glass #define EC_FLASH_PROTECT_RW_NOW             (1 << 8)
1336*6f1c0430SSimon Glass /* Rollback information flash region protected when the EC boots */
1337*6f1c0430SSimon Glass #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT   (1 << 9)
1338*6f1c0430SSimon Glass /* Rollback information flash region protected now */
1339*6f1c0430SSimon Glass #define EC_FLASH_PROTECT_ROLLBACK_NOW       (1 << 10)
134088364387SHung-ying Tyan 
1341*6f1c0430SSimon Glass struct __ec_align4 ec_params_flash_protect {
134288364387SHung-ying Tyan 	uint32_t mask;   /* Bits in flags to apply */
134388364387SHung-ying Tyan 	uint32_t flags;  /* New flags to apply */
1344*6f1c0430SSimon Glass };
134588364387SHung-ying Tyan 
1346*6f1c0430SSimon Glass struct __ec_align4 ec_response_flash_protect {
134788364387SHung-ying Tyan 	/* Current value of flash protect flags */
134888364387SHung-ying Tyan 	uint32_t flags;
134988364387SHung-ying Tyan 	/*
135088364387SHung-ying Tyan 	 * Flags which are valid on this platform.  This allows the caller
135188364387SHung-ying Tyan 	 * to distinguish between flags which aren't set vs. flags which can't
135288364387SHung-ying Tyan 	 * be set on this platform.
135388364387SHung-ying Tyan 	 */
135488364387SHung-ying Tyan 	uint32_t valid_flags;
135588364387SHung-ying Tyan 	/* Flags which can be changed given the current protection state */
135688364387SHung-ying Tyan 	uint32_t writable_flags;
1357*6f1c0430SSimon Glass };
135888364387SHung-ying Tyan 
135988364387SHung-ying Tyan /*
136088364387SHung-ying Tyan  * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
136188364387SHung-ying Tyan  * write protect.  These commands may be reused with version > 0.
136288364387SHung-ying Tyan  */
136388364387SHung-ying Tyan 
136488364387SHung-ying Tyan /* Get the region offset/size */
1365*6f1c0430SSimon Glass #define EC_CMD_FLASH_REGION_INFO 0x0016
136688364387SHung-ying Tyan #define EC_VER_FLASH_REGION_INFO 1
136788364387SHung-ying Tyan 
136888364387SHung-ying Tyan enum ec_flash_region {
136988364387SHung-ying Tyan 	/* Region which holds read-only EC image */
1370cecb19c0SSimon Glass 	EC_FLASH_REGION_RO = 0,
1371*6f1c0430SSimon Glass 	/* Region which holds active rewritable EC image */
1372*6f1c0430SSimon Glass 	EC_FLASH_REGION_ACTIVE,
137388364387SHung-ying Tyan 	/*
137488364387SHung-ying Tyan 	 * Region which should be write-protected in the factory (a superset of
137588364387SHung-ying Tyan 	 * EC_FLASH_REGION_RO)
137688364387SHung-ying Tyan 	 */
137788364387SHung-ying Tyan 	EC_FLASH_REGION_WP_RO,
1378*6f1c0430SSimon Glass 	/* Region which holds updatable image */
1379*6f1c0430SSimon Glass 	EC_FLASH_REGION_UPDATE,
1380cecb19c0SSimon Glass 	/* Number of regions */
1381cecb19c0SSimon Glass 	EC_FLASH_REGION_COUNT,
138288364387SHung-ying Tyan };
138388364387SHung-ying Tyan 
1384*6f1c0430SSimon Glass struct __ec_align4 ec_params_flash_region_info {
138588364387SHung-ying Tyan 	uint32_t region;  /* enum ec_flash_region */
1386*6f1c0430SSimon Glass };
138788364387SHung-ying Tyan 
1388*6f1c0430SSimon Glass struct __ec_align4 ec_response_flash_region_info {
138988364387SHung-ying Tyan 	uint32_t offset;
139088364387SHung-ying Tyan 	uint32_t size;
1391*6f1c0430SSimon Glass };
139288364387SHung-ying Tyan 
139388364387SHung-ying Tyan /* Read/write VbNvContext */
1394*6f1c0430SSimon Glass #define EC_CMD_VBNV_CONTEXT 0x0017
139588364387SHung-ying Tyan #define EC_VER_VBNV_CONTEXT 1
139688364387SHung-ying Tyan #define EC_VBNV_BLOCK_SIZE 16
1397*6f1c0430SSimon Glass #define EC_VBNV_BLOCK_SIZE_V2 64
139888364387SHung-ying Tyan 
139988364387SHung-ying Tyan enum ec_vbnvcontext_op {
140088364387SHung-ying Tyan 	EC_VBNV_CONTEXT_OP_READ,
140188364387SHung-ying Tyan 	EC_VBNV_CONTEXT_OP_WRITE,
140288364387SHung-ying Tyan };
140388364387SHung-ying Tyan 
1404*6f1c0430SSimon Glass struct __ec_align4 ec_params_vbnvcontext {
140588364387SHung-ying Tyan 	uint32_t op;
1406*6f1c0430SSimon Glass 	uint8_t block[EC_VBNV_BLOCK_SIZE_V2];
1407*6f1c0430SSimon Glass };
140888364387SHung-ying Tyan 
1409*6f1c0430SSimon Glass struct __ec_align4 ec_response_vbnvcontext {
1410*6f1c0430SSimon Glass 	uint8_t block[EC_VBNV_BLOCK_SIZE_V2];
1411*6f1c0430SSimon Glass };
1412*6f1c0430SSimon Glass 
1413*6f1c0430SSimon Glass 
1414*6f1c0430SSimon Glass /* Get SPI flash information */
1415*6f1c0430SSimon Glass #define EC_CMD_FLASH_SPI_INFO 0x0018
1416*6f1c0430SSimon Glass 
1417*6f1c0430SSimon Glass struct __ec_align1 ec_response_flash_spi_info {
1418*6f1c0430SSimon Glass 	/* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1419*6f1c0430SSimon Glass 	uint8_t jedec[3];
1420*6f1c0430SSimon Glass 
1421*6f1c0430SSimon Glass 	/* Pad byte; currently always contains 0 */
1422*6f1c0430SSimon Glass 	uint8_t reserved0;
1423*6f1c0430SSimon Glass 
1424*6f1c0430SSimon Glass 	/* Manufacturer / device ID from command 0x90 */
1425*6f1c0430SSimon Glass 	uint8_t mfr_dev_id[2];
1426*6f1c0430SSimon Glass 
1427*6f1c0430SSimon Glass 	/* Status registers from command 0x05 and 0x35 */
1428*6f1c0430SSimon Glass 	uint8_t sr1, sr2;
1429*6f1c0430SSimon Glass };
1430*6f1c0430SSimon Glass 
1431*6f1c0430SSimon Glass 
1432*6f1c0430SSimon Glass /* Select flash during flash operations */
1433*6f1c0430SSimon Glass #define EC_CMD_FLASH_SELECT 0x0019
1434*6f1c0430SSimon Glass 
1435*6f1c0430SSimon Glass struct __ec_align4 ec_params_flash_select {
1436*6f1c0430SSimon Glass 	/* 1 to select flash, 0 to deselect flash */
1437*6f1c0430SSimon Glass 	uint8_t select;
1438*6f1c0430SSimon Glass };
143988364387SHung-ying Tyan 
144088364387SHung-ying Tyan /*****************************************************************************/
144188364387SHung-ying Tyan /* PWM commands */
144288364387SHung-ying Tyan 
144388364387SHung-ying Tyan /* Get fan target RPM */
1444*6f1c0430SSimon Glass #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
144588364387SHung-ying Tyan 
1446*6f1c0430SSimon Glass struct __ec_align4 ec_response_pwm_get_fan_rpm {
144788364387SHung-ying Tyan 	uint32_t rpm;
1448*6f1c0430SSimon Glass };
144988364387SHung-ying Tyan 
145088364387SHung-ying Tyan /* Set target fan RPM */
1451*6f1c0430SSimon Glass #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
145288364387SHung-ying Tyan 
1453*6f1c0430SSimon Glass /* Version 0 of input params */
1454*6f1c0430SSimon Glass struct __ec_align4 ec_params_pwm_set_fan_target_rpm_v0 {
145588364387SHung-ying Tyan 	uint32_t rpm;
1456*6f1c0430SSimon Glass };
1457*6f1c0430SSimon Glass 
1458*6f1c0430SSimon Glass /* Version 1 of input params */
1459*6f1c0430SSimon Glass struct __ec_align_size1 ec_params_pwm_set_fan_target_rpm_v1 {
1460*6f1c0430SSimon Glass 	uint32_t rpm;
1461*6f1c0430SSimon Glass 	uint8_t fan_idx;
1462*6f1c0430SSimon Glass };
146388364387SHung-ying Tyan 
146488364387SHung-ying Tyan /* Get keyboard backlight */
1465*6f1c0430SSimon Glass /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1466*6f1c0430SSimon Glass #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
146788364387SHung-ying Tyan 
1468*6f1c0430SSimon Glass struct __ec_align1 ec_response_pwm_get_keyboard_backlight {
146988364387SHung-ying Tyan 	uint8_t percent;
147088364387SHung-ying Tyan 	uint8_t enabled;
1471*6f1c0430SSimon Glass };
147288364387SHung-ying Tyan 
147388364387SHung-ying Tyan /* Set keyboard backlight */
1474*6f1c0430SSimon Glass /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1475*6f1c0430SSimon Glass #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
147688364387SHung-ying Tyan 
1477*6f1c0430SSimon Glass struct __ec_align1 ec_params_pwm_set_keyboard_backlight {
147888364387SHung-ying Tyan 	uint8_t percent;
1479*6f1c0430SSimon Glass };
148088364387SHung-ying Tyan 
148188364387SHung-ying Tyan /* Set target fan PWM duty cycle */
1482*6f1c0430SSimon Glass #define EC_CMD_PWM_SET_FAN_DUTY 0x0024
148388364387SHung-ying Tyan 
1484*6f1c0430SSimon Glass /* Version 0 of input params */
1485*6f1c0430SSimon Glass struct __ec_align4 ec_params_pwm_set_fan_duty_v0 {
148688364387SHung-ying Tyan 	uint32_t percent;
1487*6f1c0430SSimon Glass };
1488*6f1c0430SSimon Glass 
1489*6f1c0430SSimon Glass /* Version 1 of input params */
1490*6f1c0430SSimon Glass struct __ec_align_size1 ec_params_pwm_set_fan_duty_v1 {
1491*6f1c0430SSimon Glass 	uint32_t percent;
1492*6f1c0430SSimon Glass 	uint8_t fan_idx;
1493*6f1c0430SSimon Glass };
1494*6f1c0430SSimon Glass 
1495*6f1c0430SSimon Glass #define EC_CMD_PWM_SET_DUTY 0x0025
1496*6f1c0430SSimon Glass /* 16 bit duty cycle, 0xffff = 100% */
1497*6f1c0430SSimon Glass #define EC_PWM_MAX_DUTY 0xffff
1498*6f1c0430SSimon Glass 
1499*6f1c0430SSimon Glass enum ec_pwm_type {
1500*6f1c0430SSimon Glass 	/* All types, indexed by board-specific enum pwm_channel */
1501*6f1c0430SSimon Glass 	EC_PWM_TYPE_GENERIC = 0,
1502*6f1c0430SSimon Glass 	/* Keyboard backlight */
1503*6f1c0430SSimon Glass 	EC_PWM_TYPE_KB_LIGHT,
1504*6f1c0430SSimon Glass 	/* Display backlight */
1505*6f1c0430SSimon Glass 	EC_PWM_TYPE_DISPLAY_LIGHT,
1506*6f1c0430SSimon Glass 	EC_PWM_TYPE_COUNT,
1507*6f1c0430SSimon Glass };
1508*6f1c0430SSimon Glass 
1509*6f1c0430SSimon Glass struct __ec_align4 ec_params_pwm_set_duty {
1510*6f1c0430SSimon Glass 	uint16_t duty;     /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1511*6f1c0430SSimon Glass 	uint8_t pwm_type;  /* ec_pwm_type */
1512*6f1c0430SSimon Glass 	uint8_t index;     /* Type-specific index, or 0 if unique */
1513*6f1c0430SSimon Glass };
1514*6f1c0430SSimon Glass 
1515*6f1c0430SSimon Glass #define EC_CMD_PWM_GET_DUTY 0x0026
1516*6f1c0430SSimon Glass 
1517*6f1c0430SSimon Glass struct __ec_align1 ec_params_pwm_get_duty {
1518*6f1c0430SSimon Glass 	uint8_t pwm_type;  /* ec_pwm_type */
1519*6f1c0430SSimon Glass 	uint8_t index;     /* Type-specific index, or 0 if unique */
1520*6f1c0430SSimon Glass };
1521*6f1c0430SSimon Glass 
1522*6f1c0430SSimon Glass struct __ec_align2 ec_response_pwm_get_duty {
1523*6f1c0430SSimon Glass 	uint16_t duty;     /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1524*6f1c0430SSimon Glass };
152588364387SHung-ying Tyan 
152688364387SHung-ying Tyan /*****************************************************************************/
152788364387SHung-ying Tyan /*
152888364387SHung-ying Tyan  * Lightbar commands. This looks worse than it is. Since we only use one HOST
152988364387SHung-ying Tyan  * command to say "talk to the lightbar", we put the "and tell it to do X" part
153088364387SHung-ying Tyan  * into a subcommand. We'll make separate structs for subcommands with
153188364387SHung-ying Tyan  * different input args, so that we know how much to expect.
153288364387SHung-ying Tyan  */
1533*6f1c0430SSimon Glass #define EC_CMD_LIGHTBAR_CMD 0x0028
153488364387SHung-ying Tyan 
1535*6f1c0430SSimon Glass struct __ec_todo_unpacked rgb_s {
153688364387SHung-ying Tyan 	uint8_t r, g, b;
153788364387SHung-ying Tyan };
153888364387SHung-ying Tyan 
153988364387SHung-ying Tyan #define LB_BATTERY_LEVELS 4
154088364387SHung-ying Tyan /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
154188364387SHung-ying Tyan  * host command, but the alignment is the same regardless. Keep it that way.
154288364387SHung-ying Tyan  */
1543*6f1c0430SSimon Glass struct __ec_todo_packed lightbar_params_v0 {
154488364387SHung-ying Tyan 	/* Timing */
1545*6f1c0430SSimon Glass 	int32_t google_ramp_up;
1546*6f1c0430SSimon Glass 	int32_t google_ramp_down;
1547*6f1c0430SSimon Glass 	int32_t s3s0_ramp_up;
1548*6f1c0430SSimon Glass 	int32_t s0_tick_delay[2];		/* AC=0/1 */
1549*6f1c0430SSimon Glass 	int32_t s0a_tick_delay[2];		/* AC=0/1 */
1550*6f1c0430SSimon Glass 	int32_t s0s3_ramp_down;
1551*6f1c0430SSimon Glass 	int32_t s3_sleep_for;
1552*6f1c0430SSimon Glass 	int32_t s3_ramp_up;
1553*6f1c0430SSimon Glass 	int32_t s3_ramp_down;
155488364387SHung-ying Tyan 
155588364387SHung-ying Tyan 	/* Oscillation */
155688364387SHung-ying Tyan 	uint8_t new_s0;
155788364387SHung-ying Tyan 	uint8_t osc_min[2];			/* AC=0/1 */
155888364387SHung-ying Tyan 	uint8_t osc_max[2];			/* AC=0/1 */
155988364387SHung-ying Tyan 	uint8_t w_ofs[2];			/* AC=0/1 */
156088364387SHung-ying Tyan 
156188364387SHung-ying Tyan 	/* Brightness limits based on the backlight and AC. */
156288364387SHung-ying Tyan 	uint8_t bright_bl_off_fixed[2];		/* AC=0/1 */
156388364387SHung-ying Tyan 	uint8_t bright_bl_on_min[2];		/* AC=0/1 */
156488364387SHung-ying Tyan 	uint8_t bright_bl_on_max[2];		/* AC=0/1 */
156588364387SHung-ying Tyan 
156688364387SHung-ying Tyan 	/* Battery level thresholds */
156788364387SHung-ying Tyan 	uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
156888364387SHung-ying Tyan 
156988364387SHung-ying Tyan 	/* Map [AC][battery_level] to color index */
157088364387SHung-ying Tyan 	uint8_t s0_idx[2][LB_BATTERY_LEVELS];	/* AP is running */
157188364387SHung-ying Tyan 	uint8_t s3_idx[2][LB_BATTERY_LEVELS];	/* AP is sleeping */
157288364387SHung-ying Tyan 
157388364387SHung-ying Tyan 	/* Color palette */
157488364387SHung-ying Tyan 	struct rgb_s color[8];			/* 0-3 are Google colors */
1575*6f1c0430SSimon Glass };
157688364387SHung-ying Tyan 
1577*6f1c0430SSimon Glass struct __ec_todo_packed lightbar_params_v1 {
1578*6f1c0430SSimon Glass 	/* Timing */
1579*6f1c0430SSimon Glass 	int32_t google_ramp_up;
1580*6f1c0430SSimon Glass 	int32_t google_ramp_down;
1581*6f1c0430SSimon Glass 	int32_t s3s0_ramp_up;
1582*6f1c0430SSimon Glass 	int32_t s0_tick_delay[2];		/* AC=0/1 */
1583*6f1c0430SSimon Glass 	int32_t s0a_tick_delay[2];		/* AC=0/1 */
1584*6f1c0430SSimon Glass 	int32_t s0s3_ramp_down;
1585*6f1c0430SSimon Glass 	int32_t s3_sleep_for;
1586*6f1c0430SSimon Glass 	int32_t s3_ramp_up;
1587*6f1c0430SSimon Glass 	int32_t s3_ramp_down;
1588*6f1c0430SSimon Glass 	int32_t s5_ramp_up;
1589*6f1c0430SSimon Glass 	int32_t s5_ramp_down;
1590*6f1c0430SSimon Glass 	int32_t tap_tick_delay;
1591*6f1c0430SSimon Glass 	int32_t tap_gate_delay;
1592*6f1c0430SSimon Glass 	int32_t tap_display_time;
1593*6f1c0430SSimon Glass 
1594*6f1c0430SSimon Glass 	/* Tap-for-battery params */
1595*6f1c0430SSimon Glass 	uint8_t tap_pct_red;
1596*6f1c0430SSimon Glass 	uint8_t tap_pct_green;
1597*6f1c0430SSimon Glass 	uint8_t tap_seg_min_on;
1598*6f1c0430SSimon Glass 	uint8_t tap_seg_max_on;
1599*6f1c0430SSimon Glass 	uint8_t tap_seg_osc;
1600*6f1c0430SSimon Glass 	uint8_t tap_idx[3];
1601*6f1c0430SSimon Glass 
1602*6f1c0430SSimon Glass 	/* Oscillation */
1603*6f1c0430SSimon Glass 	uint8_t osc_min[2];			/* AC=0/1 */
1604*6f1c0430SSimon Glass 	uint8_t osc_max[2];			/* AC=0/1 */
1605*6f1c0430SSimon Glass 	uint8_t w_ofs[2];			/* AC=0/1 */
1606*6f1c0430SSimon Glass 
1607*6f1c0430SSimon Glass 	/* Brightness limits based on the backlight and AC. */
1608*6f1c0430SSimon Glass 	uint8_t bright_bl_off_fixed[2];		/* AC=0/1 */
1609*6f1c0430SSimon Glass 	uint8_t bright_bl_on_min[2];		/* AC=0/1 */
1610*6f1c0430SSimon Glass 	uint8_t bright_bl_on_max[2];		/* AC=0/1 */
1611*6f1c0430SSimon Glass 
1612*6f1c0430SSimon Glass 	/* Battery level thresholds */
1613*6f1c0430SSimon Glass 	uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1614*6f1c0430SSimon Glass 
1615*6f1c0430SSimon Glass 	/* Map [AC][battery_level] to color index */
1616*6f1c0430SSimon Glass 	uint8_t s0_idx[2][LB_BATTERY_LEVELS];	/* AP is running */
1617*6f1c0430SSimon Glass 	uint8_t s3_idx[2][LB_BATTERY_LEVELS];	/* AP is sleeping */
1618*6f1c0430SSimon Glass 
1619*6f1c0430SSimon Glass 	/* s5: single color pulse on inhibited power-up */
1620*6f1c0430SSimon Glass 	uint8_t s5_idx;
1621*6f1c0430SSimon Glass 
1622*6f1c0430SSimon Glass 	/* Color palette */
1623*6f1c0430SSimon Glass 	struct rgb_s color[8];			/* 0-3 are Google colors */
1624*6f1c0430SSimon Glass };
1625*6f1c0430SSimon Glass 
1626*6f1c0430SSimon Glass /* Lightbar command params v2
1627*6f1c0430SSimon Glass  * crbug.com/467716
1628*6f1c0430SSimon Glass  *
1629*6f1c0430SSimon Glass  * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1630*6f1c0430SSimon Glass  * logical groups to make it more manageable ( < 120 bytes).
1631*6f1c0430SSimon Glass  *
1632*6f1c0430SSimon Glass  * NOTE: Each of these groups must be less than 120 bytes.
1633*6f1c0430SSimon Glass  */
1634*6f1c0430SSimon Glass 
1635*6f1c0430SSimon Glass struct __ec_todo_packed lightbar_params_v2_timing {
1636*6f1c0430SSimon Glass 	/* Timing */
1637*6f1c0430SSimon Glass 	int32_t google_ramp_up;
1638*6f1c0430SSimon Glass 	int32_t google_ramp_down;
1639*6f1c0430SSimon Glass 	int32_t s3s0_ramp_up;
1640*6f1c0430SSimon Glass 	int32_t s0_tick_delay[2];		/* AC=0/1 */
1641*6f1c0430SSimon Glass 	int32_t s0a_tick_delay[2];		/* AC=0/1 */
1642*6f1c0430SSimon Glass 	int32_t s0s3_ramp_down;
1643*6f1c0430SSimon Glass 	int32_t s3_sleep_for;
1644*6f1c0430SSimon Glass 	int32_t s3_ramp_up;
1645*6f1c0430SSimon Glass 	int32_t s3_ramp_down;
1646*6f1c0430SSimon Glass 	int32_t s5_ramp_up;
1647*6f1c0430SSimon Glass 	int32_t s5_ramp_down;
1648*6f1c0430SSimon Glass 	int32_t tap_tick_delay;
1649*6f1c0430SSimon Glass 	int32_t tap_gate_delay;
1650*6f1c0430SSimon Glass 	int32_t tap_display_time;
1651*6f1c0430SSimon Glass };
1652*6f1c0430SSimon Glass 
1653*6f1c0430SSimon Glass struct __ec_todo_packed lightbar_params_v2_tap {
1654*6f1c0430SSimon Glass 	/* Tap-for-battery params */
1655*6f1c0430SSimon Glass 	uint8_t tap_pct_red;
1656*6f1c0430SSimon Glass 	uint8_t tap_pct_green;
1657*6f1c0430SSimon Glass 	uint8_t tap_seg_min_on;
1658*6f1c0430SSimon Glass 	uint8_t tap_seg_max_on;
1659*6f1c0430SSimon Glass 	uint8_t tap_seg_osc;
1660*6f1c0430SSimon Glass 	uint8_t tap_idx[3];
1661*6f1c0430SSimon Glass };
1662*6f1c0430SSimon Glass 
1663*6f1c0430SSimon Glass struct __ec_todo_packed lightbar_params_v2_oscillation {
1664*6f1c0430SSimon Glass 	/* Oscillation */
1665*6f1c0430SSimon Glass 	uint8_t osc_min[2];			/* AC=0/1 */
1666*6f1c0430SSimon Glass 	uint8_t osc_max[2];			/* AC=0/1 */
1667*6f1c0430SSimon Glass 	uint8_t w_ofs[2];			/* AC=0/1 */
1668*6f1c0430SSimon Glass };
1669*6f1c0430SSimon Glass 
1670*6f1c0430SSimon Glass struct __ec_todo_packed lightbar_params_v2_brightness {
1671*6f1c0430SSimon Glass 	/* Brightness limits based on the backlight and AC. */
1672*6f1c0430SSimon Glass 	uint8_t bright_bl_off_fixed[2];		/* AC=0/1 */
1673*6f1c0430SSimon Glass 	uint8_t bright_bl_on_min[2];		/* AC=0/1 */
1674*6f1c0430SSimon Glass 	uint8_t bright_bl_on_max[2];		/* AC=0/1 */
1675*6f1c0430SSimon Glass };
1676*6f1c0430SSimon Glass 
1677*6f1c0430SSimon Glass struct __ec_todo_packed lightbar_params_v2_thresholds {
1678*6f1c0430SSimon Glass 	/* Battery level thresholds */
1679*6f1c0430SSimon Glass 	uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1680*6f1c0430SSimon Glass };
1681*6f1c0430SSimon Glass 
1682*6f1c0430SSimon Glass struct __ec_todo_packed lightbar_params_v2_colors {
1683*6f1c0430SSimon Glass 	/* Map [AC][battery_level] to color index */
1684*6f1c0430SSimon Glass 	uint8_t s0_idx[2][LB_BATTERY_LEVELS];	/* AP is running */
1685*6f1c0430SSimon Glass 	uint8_t s3_idx[2][LB_BATTERY_LEVELS];	/* AP is sleeping */
1686*6f1c0430SSimon Glass 
1687*6f1c0430SSimon Glass 	/* s5: single color pulse on inhibited power-up */
1688*6f1c0430SSimon Glass 	uint8_t s5_idx;
1689*6f1c0430SSimon Glass 
1690*6f1c0430SSimon Glass 	/* Color palette */
1691*6f1c0430SSimon Glass 	struct rgb_s color[8];			/* 0-3 are Google colors */
1692*6f1c0430SSimon Glass };
1693*6f1c0430SSimon Glass 
1694*6f1c0430SSimon Glass /* Lightbyte program. */
1695*6f1c0430SSimon Glass #define EC_LB_PROG_LEN 192
1696*6f1c0430SSimon Glass struct __ec_todo_unpacked lightbar_program {
1697*6f1c0430SSimon Glass 	uint8_t size;
1698*6f1c0430SSimon Glass 	uint8_t data[EC_LB_PROG_LEN];
1699*6f1c0430SSimon Glass };
1700*6f1c0430SSimon Glass 
1701*6f1c0430SSimon Glass struct __ec_todo_packed ec_params_lightbar {
170288364387SHung-ying Tyan 	uint8_t cmd;		      /* Command (see enum lightbar_command) */
170388364387SHung-ying Tyan 	union {
1704*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
170588364387SHung-ying Tyan 			/* no args */
1706*6f1c0430SSimon Glass 		} dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1707*6f1c0430SSimon Glass 			version, get_brightness, get_demo, suspend, resume,
1708*6f1c0430SSimon Glass 			get_params_v2_timing, get_params_v2_tap,
1709*6f1c0430SSimon Glass 			get_params_v2_osc, get_params_v2_bright,
1710*6f1c0430SSimon Glass 			get_params_v2_thlds, get_params_v2_colors;
171188364387SHung-ying Tyan 
1712*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
171388364387SHung-ying Tyan 			uint8_t num;
1714*6f1c0430SSimon Glass 		} set_brightness, seq, demo;
171588364387SHung-ying Tyan 
1716*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
171788364387SHung-ying Tyan 			uint8_t ctrl, reg, value;
171888364387SHung-ying Tyan 		} reg;
171988364387SHung-ying Tyan 
1720*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
172188364387SHung-ying Tyan 			uint8_t led, red, green, blue;
1722*6f1c0430SSimon Glass 		} set_rgb;
172388364387SHung-ying Tyan 
1724*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
1725*6f1c0430SSimon Glass 			uint8_t led;
1726*6f1c0430SSimon Glass 		} get_rgb;
1727*6f1c0430SSimon Glass 
1728*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
1729*6f1c0430SSimon Glass 			uint8_t enable;
1730*6f1c0430SSimon Glass 		} manual_suspend_ctrl;
1731*6f1c0430SSimon Glass 
1732*6f1c0430SSimon Glass 		struct lightbar_params_v0 set_params_v0;
1733*6f1c0430SSimon Glass 		struct lightbar_params_v1 set_params_v1;
1734*6f1c0430SSimon Glass 
1735*6f1c0430SSimon Glass 		struct lightbar_params_v2_timing set_v2par_timing;
1736*6f1c0430SSimon Glass 		struct lightbar_params_v2_tap set_v2par_tap;
1737*6f1c0430SSimon Glass 		struct lightbar_params_v2_oscillation set_v2par_osc;
1738*6f1c0430SSimon Glass 		struct lightbar_params_v2_brightness set_v2par_bright;
1739*6f1c0430SSimon Glass 		struct lightbar_params_v2_thresholds set_v2par_thlds;
1740*6f1c0430SSimon Glass 		struct lightbar_params_v2_colors set_v2par_colors;
1741*6f1c0430SSimon Glass 
1742*6f1c0430SSimon Glass 		struct lightbar_program set_program;
174388364387SHung-ying Tyan 	};
1744*6f1c0430SSimon Glass };
174588364387SHung-ying Tyan 
1746*6f1c0430SSimon Glass struct __ec_todo_packed ec_response_lightbar {
174788364387SHung-ying Tyan 	union {
1748*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
1749*6f1c0430SSimon Glass 			struct __ec_todo_unpacked {
175088364387SHung-ying Tyan 				uint8_t reg;
175188364387SHung-ying Tyan 				uint8_t ic0;
175288364387SHung-ying Tyan 				uint8_t ic1;
175388364387SHung-ying Tyan 			} vals[23];
175488364387SHung-ying Tyan 		} dump;
175588364387SHung-ying Tyan 
1756*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
175788364387SHung-ying Tyan 			uint8_t num;
1758*6f1c0430SSimon Glass 		} get_seq, get_brightness, get_demo;
175988364387SHung-ying Tyan 
1760*6f1c0430SSimon Glass 		struct lightbar_params_v0 get_params_v0;
1761*6f1c0430SSimon Glass 		struct lightbar_params_v1 get_params_v1;
176288364387SHung-ying Tyan 
1763*6f1c0430SSimon Glass 
1764*6f1c0430SSimon Glass 		struct lightbar_params_v2_timing get_params_v2_timing;
1765*6f1c0430SSimon Glass 		struct lightbar_params_v2_tap get_params_v2_tap;
1766*6f1c0430SSimon Glass 		struct lightbar_params_v2_oscillation get_params_v2_osc;
1767*6f1c0430SSimon Glass 		struct lightbar_params_v2_brightness get_params_v2_bright;
1768*6f1c0430SSimon Glass 		struct lightbar_params_v2_thresholds get_params_v2_thlds;
1769*6f1c0430SSimon Glass 		struct lightbar_params_v2_colors get_params_v2_colors;
1770*6f1c0430SSimon Glass 
1771*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
1772*6f1c0430SSimon Glass 			uint32_t num;
1773*6f1c0430SSimon Glass 			uint32_t flags;
1774*6f1c0430SSimon Glass 		} version;
1775*6f1c0430SSimon Glass 
1776*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
1777*6f1c0430SSimon Glass 			uint8_t red, green, blue;
1778*6f1c0430SSimon Glass 		} get_rgb;
1779*6f1c0430SSimon Glass 
1780*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
178188364387SHung-ying Tyan 			/* no return params */
1782*6f1c0430SSimon Glass 		} off, on, init, set_brightness, seq, reg, set_rgb,
1783*6f1c0430SSimon Glass 			demo, set_params_v0, set_params_v1,
1784*6f1c0430SSimon Glass 			set_program, manual_suspend_ctrl, suspend, resume,
1785*6f1c0430SSimon Glass 			set_v2par_timing, set_v2par_tap,
1786*6f1c0430SSimon Glass 			set_v2par_osc, set_v2par_bright, set_v2par_thlds,
1787*6f1c0430SSimon Glass 			set_v2par_colors;
178888364387SHung-ying Tyan 	};
1789*6f1c0430SSimon Glass };
179088364387SHung-ying Tyan 
179188364387SHung-ying Tyan /* Lightbar commands */
179288364387SHung-ying Tyan enum lightbar_command {
179388364387SHung-ying Tyan 	LIGHTBAR_CMD_DUMP = 0,
179488364387SHung-ying Tyan 	LIGHTBAR_CMD_OFF = 1,
179588364387SHung-ying Tyan 	LIGHTBAR_CMD_ON = 2,
179688364387SHung-ying Tyan 	LIGHTBAR_CMD_INIT = 3,
1797*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
179888364387SHung-ying Tyan 	LIGHTBAR_CMD_SEQ = 5,
179988364387SHung-ying Tyan 	LIGHTBAR_CMD_REG = 6,
1800*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SET_RGB = 7,
180188364387SHung-ying Tyan 	LIGHTBAR_CMD_GET_SEQ = 8,
180288364387SHung-ying Tyan 	LIGHTBAR_CMD_DEMO = 9,
1803*6f1c0430SSimon Glass 	LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1804*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
1805*6f1c0430SSimon Glass 	LIGHTBAR_CMD_VERSION = 12,
1806*6f1c0430SSimon Glass 	LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1807*6f1c0430SSimon Glass 	LIGHTBAR_CMD_GET_RGB = 14,
1808*6f1c0430SSimon Glass 	LIGHTBAR_CMD_GET_DEMO = 15,
1809*6f1c0430SSimon Glass 	LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1810*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
1811*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SET_PROGRAM = 18,
1812*6f1c0430SSimon Glass 	LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1813*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SUSPEND = 20,
1814*6f1c0430SSimon Glass 	LIGHTBAR_CMD_RESUME = 21,
1815*6f1c0430SSimon Glass 	LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
1816*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
1817*6f1c0430SSimon Glass 	LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
1818*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
1819*6f1c0430SSimon Glass 	LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
1820*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
1821*6f1c0430SSimon Glass 	LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
1822*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
1823*6f1c0430SSimon Glass 	LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
1824*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
1825*6f1c0430SSimon Glass 	LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
1826*6f1c0430SSimon Glass 	LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
182788364387SHung-ying Tyan 	LIGHTBAR_NUM_CMDS
182888364387SHung-ying Tyan };
182988364387SHung-ying Tyan 
183088364387SHung-ying Tyan /*****************************************************************************/
1831836bb6e8SSimon Glass /* LED control commands */
1832836bb6e8SSimon Glass 
1833*6f1c0430SSimon Glass #define EC_CMD_LED_CONTROL 0x0029
1834836bb6e8SSimon Glass 
1835836bb6e8SSimon Glass enum ec_led_id {
1836*6f1c0430SSimon Glass 	/* LED to indicate battery state of charge */
1837836bb6e8SSimon Glass 	EC_LED_ID_BATTERY_LED = 0,
1838*6f1c0430SSimon Glass 	/*
1839*6f1c0430SSimon Glass 	 * LED to indicate system power state (on or in suspend).
1840*6f1c0430SSimon Glass 	 * May be on power button or on C-panel.
1841*6f1c0430SSimon Glass 	 */
1842*6f1c0430SSimon Glass 	EC_LED_ID_POWER_LED,
1843*6f1c0430SSimon Glass 	/* LED on power adapter or its plug */
1844836bb6e8SSimon Glass 	EC_LED_ID_ADAPTER_LED,
1845*6f1c0430SSimon Glass 	/* LED to indicate left side */
1846*6f1c0430SSimon Glass 	EC_LED_ID_LEFT_LED,
1847*6f1c0430SSimon Glass 	/* LED to indicate right side */
1848*6f1c0430SSimon Glass 	EC_LED_ID_RIGHT_LED,
1849*6f1c0430SSimon Glass 	/* LED to indicate recovery mode with HW_REINIT */
1850*6f1c0430SSimon Glass 	EC_LED_ID_RECOVERY_HW_REINIT_LED,
1851*6f1c0430SSimon Glass 	/* LED to indicate sysrq debug mode. */
1852*6f1c0430SSimon Glass 	EC_LED_ID_SYSRQ_DEBUG_LED,
1853*6f1c0430SSimon Glass 
1854*6f1c0430SSimon Glass 	EC_LED_ID_COUNT
1855836bb6e8SSimon Glass };
1856836bb6e8SSimon Glass 
1857836bb6e8SSimon Glass /* LED control flags */
1858836bb6e8SSimon Glass #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1859836bb6e8SSimon Glass #define EC_LED_FLAGS_AUTO  (1 << 1) /* Switch LED back to automatic control */
1860836bb6e8SSimon Glass 
1861836bb6e8SSimon Glass enum ec_led_colors {
1862836bb6e8SSimon Glass 	EC_LED_COLOR_RED = 0,
1863836bb6e8SSimon Glass 	EC_LED_COLOR_GREEN,
1864836bb6e8SSimon Glass 	EC_LED_COLOR_BLUE,
1865836bb6e8SSimon Glass 	EC_LED_COLOR_YELLOW,
1866836bb6e8SSimon Glass 	EC_LED_COLOR_WHITE,
1867*6f1c0430SSimon Glass 	EC_LED_COLOR_AMBER,
1868836bb6e8SSimon Glass 
1869836bb6e8SSimon Glass 	EC_LED_COLOR_COUNT
1870836bb6e8SSimon Glass };
1871836bb6e8SSimon Glass 
1872*6f1c0430SSimon Glass struct __ec_align1 ec_params_led_control {
1873836bb6e8SSimon Glass 	uint8_t led_id;     /* Which LED to control */
1874836bb6e8SSimon Glass 	uint8_t flags;      /* Control flags */
1875836bb6e8SSimon Glass 
1876836bb6e8SSimon Glass 	uint8_t brightness[EC_LED_COLOR_COUNT];
1877*6f1c0430SSimon Glass };
1878836bb6e8SSimon Glass 
1879*6f1c0430SSimon Glass struct __ec_align1 ec_response_led_control {
1880836bb6e8SSimon Glass 	/*
1881836bb6e8SSimon Glass 	 * Available brightness value range.
1882836bb6e8SSimon Glass 	 *
1883836bb6e8SSimon Glass 	 * Range 0 means color channel not present.
1884836bb6e8SSimon Glass 	 * Range 1 means on/off control.
1885836bb6e8SSimon Glass 	 * Other values means the LED is control by PWM.
1886836bb6e8SSimon Glass 	 */
1887836bb6e8SSimon Glass 	uint8_t brightness_range[EC_LED_COLOR_COUNT];
1888*6f1c0430SSimon Glass };
1889836bb6e8SSimon Glass 
1890836bb6e8SSimon Glass /*****************************************************************************/
189188364387SHung-ying Tyan /* Verified boot commands */
189288364387SHung-ying Tyan 
189388364387SHung-ying Tyan /*
189488364387SHung-ying Tyan  * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
189588364387SHung-ying Tyan  * reused for other purposes with version > 0.
189688364387SHung-ying Tyan  */
189788364387SHung-ying Tyan 
189888364387SHung-ying Tyan /* Verified boot hash command */
1899*6f1c0430SSimon Glass #define EC_CMD_VBOOT_HASH 0x002A
190088364387SHung-ying Tyan 
1901*6f1c0430SSimon Glass struct __ec_align4 ec_params_vboot_hash {
190288364387SHung-ying Tyan 	uint8_t cmd;             /* enum ec_vboot_hash_cmd */
190388364387SHung-ying Tyan 	uint8_t hash_type;       /* enum ec_vboot_hash_type */
190488364387SHung-ying Tyan 	uint8_t nonce_size;      /* Nonce size; may be 0 */
190588364387SHung-ying Tyan 	uint8_t reserved0;       /* Reserved; set 0 */
190688364387SHung-ying Tyan 	uint32_t offset;         /* Offset in flash to hash */
190788364387SHung-ying Tyan 	uint32_t size;           /* Number of bytes to hash */
190888364387SHung-ying Tyan 	uint8_t nonce_data[64];  /* Nonce data; ignored if nonce_size=0 */
1909*6f1c0430SSimon Glass };
191088364387SHung-ying Tyan 
1911*6f1c0430SSimon Glass struct __ec_align4 ec_response_vboot_hash {
191288364387SHung-ying Tyan 	uint8_t status;          /* enum ec_vboot_hash_status */
191388364387SHung-ying Tyan 	uint8_t hash_type;       /* enum ec_vboot_hash_type */
191488364387SHung-ying Tyan 	uint8_t digest_size;     /* Size of hash digest in bytes */
191588364387SHung-ying Tyan 	uint8_t reserved0;       /* Ignore; will be 0 */
191688364387SHung-ying Tyan 	uint32_t offset;         /* Offset in flash which was hashed */
191788364387SHung-ying Tyan 	uint32_t size;           /* Number of bytes hashed */
191888364387SHung-ying Tyan 	uint8_t hash_digest[64]; /* Hash digest data */
1919*6f1c0430SSimon Glass };
192088364387SHung-ying Tyan 
192188364387SHung-ying Tyan enum ec_vboot_hash_cmd {
192288364387SHung-ying Tyan 	EC_VBOOT_HASH_GET = 0,       /* Get current hash status */
192388364387SHung-ying Tyan 	EC_VBOOT_HASH_ABORT = 1,     /* Abort calculating current hash */
192488364387SHung-ying Tyan 	EC_VBOOT_HASH_START = 2,     /* Start computing a new hash */
192588364387SHung-ying Tyan 	EC_VBOOT_HASH_RECALC = 3,    /* Synchronously compute a new hash */
192688364387SHung-ying Tyan };
192788364387SHung-ying Tyan 
192888364387SHung-ying Tyan enum ec_vboot_hash_type {
192988364387SHung-ying Tyan 	EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
193088364387SHung-ying Tyan };
193188364387SHung-ying Tyan 
193288364387SHung-ying Tyan enum ec_vboot_hash_status {
193388364387SHung-ying Tyan 	EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
193488364387SHung-ying Tyan 	EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
193588364387SHung-ying Tyan 	EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
193688364387SHung-ying Tyan };
193788364387SHung-ying Tyan 
193888364387SHung-ying Tyan /*
193988364387SHung-ying Tyan  * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
194088364387SHung-ying Tyan  * If one of these is specified, the EC will automatically update offset and
194188364387SHung-ying Tyan  * size to the correct values for the specified image (RO or RW).
194288364387SHung-ying Tyan  */
194388364387SHung-ying Tyan #define EC_VBOOT_HASH_OFFSET_RO		0xfffffffe
1944*6f1c0430SSimon Glass #define EC_VBOOT_HASH_OFFSET_ACTIVE	0xfffffffd
1945*6f1c0430SSimon Glass #define EC_VBOOT_HASH_OFFSET_UPDATE	0xfffffffc
1946*6f1c0430SSimon Glass 
1947*6f1c0430SSimon Glass /*****************************************************************************/
1948*6f1c0430SSimon Glass /*
1949*6f1c0430SSimon Glass  * Motion sense commands. We'll make separate structs for sub-commands with
1950*6f1c0430SSimon Glass  * different input args, so that we know how much to expect.
1951*6f1c0430SSimon Glass  */
1952*6f1c0430SSimon Glass #define EC_CMD_MOTION_SENSE_CMD 0x002B
1953*6f1c0430SSimon Glass 
1954*6f1c0430SSimon Glass /* Motion sense commands */
1955*6f1c0430SSimon Glass enum motionsense_command {
1956*6f1c0430SSimon Glass 	/*
1957*6f1c0430SSimon Glass 	 * Dump command returns all motion sensor data including motion sense
1958*6f1c0430SSimon Glass 	 * module flags and individual sensor flags.
1959*6f1c0430SSimon Glass 	 */
1960*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_DUMP = 0,
1961*6f1c0430SSimon Glass 
1962*6f1c0430SSimon Glass 	/*
1963*6f1c0430SSimon Glass 	 * Info command returns data describing the details of a given sensor,
1964*6f1c0430SSimon Glass 	 * including enum motionsensor_type, enum motionsensor_location, and
1965*6f1c0430SSimon Glass 	 * enum motionsensor_chip.
1966*6f1c0430SSimon Glass 	 */
1967*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_INFO = 1,
1968*6f1c0430SSimon Glass 
1969*6f1c0430SSimon Glass 	/*
1970*6f1c0430SSimon Glass 	 * EC Rate command is a setter/getter command for the EC sampling rate
1971*6f1c0430SSimon Glass 	 * in milliseconds.
1972*6f1c0430SSimon Glass 	 * It is per sensor, the EC run sample task  at the minimum of all
1973*6f1c0430SSimon Glass 	 * sensors EC_RATE.
1974*6f1c0430SSimon Glass 	 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
1975*6f1c0430SSimon Glass 	 * to collect all the sensor samples.
1976*6f1c0430SSimon Glass 	 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
1977*6f1c0430SSimon Glass 	 * to process of all motion sensors in milliseconds.
1978*6f1c0430SSimon Glass 	 */
1979*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_EC_RATE = 2,
1980*6f1c0430SSimon Glass 
1981*6f1c0430SSimon Glass 	/*
1982*6f1c0430SSimon Glass 	 * Sensor ODR command is a setter/getter command for the output data
1983*6f1c0430SSimon Glass 	 * rate of a specific motion sensor in millihertz.
1984*6f1c0430SSimon Glass 	 */
1985*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_SENSOR_ODR = 3,
1986*6f1c0430SSimon Glass 
1987*6f1c0430SSimon Glass 	/*
1988*6f1c0430SSimon Glass 	 * Sensor range command is a setter/getter command for the range of
1989*6f1c0430SSimon Glass 	 * a specified motion sensor in +/-G's or +/- deg/s.
1990*6f1c0430SSimon Glass 	 */
1991*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1992*6f1c0430SSimon Glass 
1993*6f1c0430SSimon Glass 	/*
1994*6f1c0430SSimon Glass 	 * Setter/getter command for the keyboard wake angle. When the lid
1995*6f1c0430SSimon Glass 	 * angle is greater than this value, keyboard wake is disabled in S3,
1996*6f1c0430SSimon Glass 	 * and when the lid angle goes less than this value, keyboard wake is
1997*6f1c0430SSimon Glass 	 * enabled. Note, the lid angle measurement is an approximate,
1998*6f1c0430SSimon Glass 	 * un-calibrated value, hence the wake angle isn't exact.
1999*6f1c0430SSimon Glass 	 */
2000*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2001*6f1c0430SSimon Glass 
2002*6f1c0430SSimon Glass 	/*
2003*6f1c0430SSimon Glass 	 * Returns a single sensor data.
2004*6f1c0430SSimon Glass 	 */
2005*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_DATA = 6,
2006*6f1c0430SSimon Glass 
2007*6f1c0430SSimon Glass 	/*
2008*6f1c0430SSimon Glass 	 * Return sensor fifo info.
2009*6f1c0430SSimon Glass 	 */
2010*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_FIFO_INFO = 7,
2011*6f1c0430SSimon Glass 
2012*6f1c0430SSimon Glass 	/*
2013*6f1c0430SSimon Glass 	 * Insert a flush element in the fifo and return sensor fifo info.
2014*6f1c0430SSimon Glass 	 * The host can use that element to synchronize its operation.
2015*6f1c0430SSimon Glass 	 */
2016*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2017*6f1c0430SSimon Glass 
2018*6f1c0430SSimon Glass 	/*
2019*6f1c0430SSimon Glass 	 * Return a portion of the fifo.
2020*6f1c0430SSimon Glass 	 */
2021*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_FIFO_READ = 9,
2022*6f1c0430SSimon Glass 
2023*6f1c0430SSimon Glass 	/*
2024*6f1c0430SSimon Glass 	 * Perform low level calibration.
2025*6f1c0430SSimon Glass 	 * On sensors that support it, ask to do offset calibration.
2026*6f1c0430SSimon Glass 	 */
2027*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2028*6f1c0430SSimon Glass 
2029*6f1c0430SSimon Glass 	/*
2030*6f1c0430SSimon Glass 	 * Sensor Offset command is a setter/getter command for the offset
2031*6f1c0430SSimon Glass 	 * used for calibration.
2032*6f1c0430SSimon Glass 	 * The offsets can be calculated by the host, or via
2033*6f1c0430SSimon Glass 	 * PERFORM_CALIB command.
2034*6f1c0430SSimon Glass 	 */
2035*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2036*6f1c0430SSimon Glass 
2037*6f1c0430SSimon Glass 	/*
2038*6f1c0430SSimon Glass 	 * List available activities for a MOTION sensor.
2039*6f1c0430SSimon Glass 	 * Indicates if they are enabled or disabled.
2040*6f1c0430SSimon Glass 	 */
2041*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2042*6f1c0430SSimon Glass 
2043*6f1c0430SSimon Glass 	/*
2044*6f1c0430SSimon Glass 	 * Activity management
2045*6f1c0430SSimon Glass 	 * Enable/Disable activity recognition.
2046*6f1c0430SSimon Glass 	 */
2047*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2048*6f1c0430SSimon Glass 
2049*6f1c0430SSimon Glass 	/*
2050*6f1c0430SSimon Glass 	 * Lid Angle
2051*6f1c0430SSimon Glass 	 */
2052*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_LID_ANGLE = 14,
2053*6f1c0430SSimon Glass 
2054*6f1c0430SSimon Glass 	/*
2055*6f1c0430SSimon Glass 	 * Allow the FIFO to trigger interrupt via MKBP events.
2056*6f1c0430SSimon Glass 	 * By default the FIFO does not send interrupt to process the FIFO
2057*6f1c0430SSimon Glass 	 * until the AP is ready or it is coming from a wakeup sensor.
2058*6f1c0430SSimon Glass 	 */
2059*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2060*6f1c0430SSimon Glass 
2061*6f1c0430SSimon Glass 	/*
2062*6f1c0430SSimon Glass 	 * Spoof the readings of the sensors.  The spoofed readings can be set
2063*6f1c0430SSimon Glass 	 * to arbitrary values, or will lock to the last read actual values.
2064*6f1c0430SSimon Glass 	 */
2065*6f1c0430SSimon Glass 	MOTIONSENSE_CMD_SPOOF = 16,
2066*6f1c0430SSimon Glass 
2067*6f1c0430SSimon Glass 	/* Number of motionsense sub-commands. */
2068*6f1c0430SSimon Glass 	MOTIONSENSE_NUM_CMDS
2069*6f1c0430SSimon Glass };
2070*6f1c0430SSimon Glass 
2071*6f1c0430SSimon Glass /* List of motion sensor types. */
2072*6f1c0430SSimon Glass enum motionsensor_type {
2073*6f1c0430SSimon Glass 	MOTIONSENSE_TYPE_ACCEL = 0,
2074*6f1c0430SSimon Glass 	MOTIONSENSE_TYPE_GYRO = 1,
2075*6f1c0430SSimon Glass 	MOTIONSENSE_TYPE_MAG = 2,
2076*6f1c0430SSimon Glass 	MOTIONSENSE_TYPE_PROX = 3,
2077*6f1c0430SSimon Glass 	MOTIONSENSE_TYPE_LIGHT = 4,
2078*6f1c0430SSimon Glass 	MOTIONSENSE_TYPE_ACTIVITY = 5,
2079*6f1c0430SSimon Glass 	MOTIONSENSE_TYPE_BARO = 6,
2080*6f1c0430SSimon Glass 	MOTIONSENSE_TYPE_MAX,
2081*6f1c0430SSimon Glass };
2082*6f1c0430SSimon Glass 
2083*6f1c0430SSimon Glass /* List of motion sensor locations. */
2084*6f1c0430SSimon Glass enum motionsensor_location {
2085*6f1c0430SSimon Glass 	MOTIONSENSE_LOC_BASE = 0,
2086*6f1c0430SSimon Glass 	MOTIONSENSE_LOC_LID = 1,
2087*6f1c0430SSimon Glass 	MOTIONSENSE_LOC_MAX,
2088*6f1c0430SSimon Glass };
2089*6f1c0430SSimon Glass 
2090*6f1c0430SSimon Glass /* List of motion sensor chips. */
2091*6f1c0430SSimon Glass enum motionsensor_chip {
2092*6f1c0430SSimon Glass 	MOTIONSENSE_CHIP_KXCJ9 = 0,
2093*6f1c0430SSimon Glass 	MOTIONSENSE_CHIP_LSM6DS0 = 1,
2094*6f1c0430SSimon Glass 	MOTIONSENSE_CHIP_BMI160 = 2,
2095*6f1c0430SSimon Glass 	MOTIONSENSE_CHIP_SI1141 = 3,
2096*6f1c0430SSimon Glass 	MOTIONSENSE_CHIP_SI1142 = 4,
2097*6f1c0430SSimon Glass 	MOTIONSENSE_CHIP_SI1143 = 5,
2098*6f1c0430SSimon Glass 	MOTIONSENSE_CHIP_KX022 = 6,
2099*6f1c0430SSimon Glass 	MOTIONSENSE_CHIP_L3GD20H = 7,
2100*6f1c0430SSimon Glass 	MOTIONSENSE_CHIP_BMA255 = 8,
2101*6f1c0430SSimon Glass 	MOTIONSENSE_CHIP_BMP280 = 9,
2102*6f1c0430SSimon Glass 	MOTIONSENSE_CHIP_OPT3001 = 10,
2103*6f1c0430SSimon Glass };
2104*6f1c0430SSimon Glass 
2105*6f1c0430SSimon Glass struct __ec_todo_packed ec_response_motion_sensor_data {
2106*6f1c0430SSimon Glass 	/* Flags for each sensor. */
2107*6f1c0430SSimon Glass 	uint8_t flags;
2108*6f1c0430SSimon Glass 	/* sensor number the data comes from */
2109*6f1c0430SSimon Glass 	uint8_t sensor_num;
2110*6f1c0430SSimon Glass 	/* Each sensor is up to 3-axis. */
2111*6f1c0430SSimon Glass 	union {
2112*6f1c0430SSimon Glass 		int16_t             data[3];
2113*6f1c0430SSimon Glass 		struct __ec_todo_packed {
2114*6f1c0430SSimon Glass 			uint16_t    reserved;
2115*6f1c0430SSimon Glass 			uint32_t    timestamp;
2116*6f1c0430SSimon Glass 		};
2117*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2118*6f1c0430SSimon Glass 			uint8_t     activity; /* motionsensor_activity */
2119*6f1c0430SSimon Glass 			uint8_t     state;
2120*6f1c0430SSimon Glass 			int16_t     add_info[2];
2121*6f1c0430SSimon Glass 		};
2122*6f1c0430SSimon Glass 	};
2123*6f1c0430SSimon Glass };
2124*6f1c0430SSimon Glass 
2125*6f1c0430SSimon Glass /* Note: used in ec_response_get_next_data */
2126*6f1c0430SSimon Glass struct __ec_todo_packed ec_response_motion_sense_fifo_info {
2127*6f1c0430SSimon Glass 	/* Size of the fifo */
2128*6f1c0430SSimon Glass 	uint16_t size;
2129*6f1c0430SSimon Glass 	/* Amount of space used in the fifo */
2130*6f1c0430SSimon Glass 	uint16_t count;
2131*6f1c0430SSimon Glass 	/* Timestamp recorded in us */
2132*6f1c0430SSimon Glass 	uint32_t timestamp;
2133*6f1c0430SSimon Glass 	/* Total amount of vector lost */
2134*6f1c0430SSimon Glass 	uint16_t total_lost;
2135*6f1c0430SSimon Glass 	/* Lost events since the last fifo_info, per sensors */
2136*6f1c0430SSimon Glass 	uint16_t lost[0];
2137*6f1c0430SSimon Glass };
2138*6f1c0430SSimon Glass 
2139*6f1c0430SSimon Glass struct __ec_todo_packed ec_response_motion_sense_fifo_data {
2140*6f1c0430SSimon Glass 	uint32_t number_data;
2141*6f1c0430SSimon Glass 	struct ec_response_motion_sensor_data data[0];
2142*6f1c0430SSimon Glass };
2143*6f1c0430SSimon Glass 
2144*6f1c0430SSimon Glass /* List supported activity recognition */
2145*6f1c0430SSimon Glass enum motionsensor_activity {
2146*6f1c0430SSimon Glass 	MOTIONSENSE_ACTIVITY_RESERVED = 0,
2147*6f1c0430SSimon Glass 	MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2148*6f1c0430SSimon Glass 	MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
2149*6f1c0430SSimon Glass };
2150*6f1c0430SSimon Glass 
2151*6f1c0430SSimon Glass struct __ec_todo_unpacked ec_motion_sense_activity {
2152*6f1c0430SSimon Glass 	uint8_t sensor_num;
2153*6f1c0430SSimon Glass 	uint8_t activity; /* one of enum motionsensor_activity */
2154*6f1c0430SSimon Glass 	uint8_t enable;   /* 1: enable, 0: disable */
2155*6f1c0430SSimon Glass 	uint8_t reserved;
2156*6f1c0430SSimon Glass 	uint16_t parameters[3]; /* activity dependent parameters */
2157*6f1c0430SSimon Glass };
2158*6f1c0430SSimon Glass 
2159*6f1c0430SSimon Glass /* Module flag masks used for the dump sub-command. */
2160*6f1c0430SSimon Glass #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
2161*6f1c0430SSimon Glass 
2162*6f1c0430SSimon Glass /* Sensor flag masks used for the dump sub-command. */
2163*6f1c0430SSimon Glass #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
2164*6f1c0430SSimon Glass 
2165*6f1c0430SSimon Glass /*
2166*6f1c0430SSimon Glass  * Flush entry for synchronization.
2167*6f1c0430SSimon Glass  * data contains time stamp
2168*6f1c0430SSimon Glass  */
2169*6f1c0430SSimon Glass #define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
2170*6f1c0430SSimon Glass #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
2171*6f1c0430SSimon Glass #define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2)
2172*6f1c0430SSimon Glass #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE (1<<3)
2173*6f1c0430SSimon Glass 
2174*6f1c0430SSimon Glass /*
2175*6f1c0430SSimon Glass  * Send this value for the data element to only perform a read. If you
2176*6f1c0430SSimon Glass  * send any other value, the EC will interpret it as data to set and will
2177*6f1c0430SSimon Glass  * return the actual value set.
2178*6f1c0430SSimon Glass  */
2179*6f1c0430SSimon Glass #define EC_MOTION_SENSE_NO_VALUE -1
2180*6f1c0430SSimon Glass 
2181*6f1c0430SSimon Glass #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2182*6f1c0430SSimon Glass 
2183*6f1c0430SSimon Glass /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2184*6f1c0430SSimon Glass /* Set Calibration information */
2185*6f1c0430SSimon Glass #define MOTION_SENSE_SET_OFFSET 1
2186*6f1c0430SSimon Glass 
2187*6f1c0430SSimon Glass #define LID_ANGLE_UNRELIABLE 500
2188*6f1c0430SSimon Glass 
2189*6f1c0430SSimon Glass enum motionsense_spoof_mode {
2190*6f1c0430SSimon Glass 	/* Disable spoof mode. */
2191*6f1c0430SSimon Glass 	MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2192*6f1c0430SSimon Glass 
2193*6f1c0430SSimon Glass 	/* Enable spoof mode, but use provided component values. */
2194*6f1c0430SSimon Glass 	MOTIONSENSE_SPOOF_MODE_CUSTOM,
2195*6f1c0430SSimon Glass 
2196*6f1c0430SSimon Glass 	/* Enable spoof mode, but use the current sensor values. */
2197*6f1c0430SSimon Glass 	MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2198*6f1c0430SSimon Glass 
2199*6f1c0430SSimon Glass 	/* Query the current spoof mode status for the sensor. */
2200*6f1c0430SSimon Glass 	MOTIONSENSE_SPOOF_MODE_QUERY,
2201*6f1c0430SSimon Glass };
2202*6f1c0430SSimon Glass 
2203*6f1c0430SSimon Glass struct __ec_todo_packed ec_params_motion_sense {
2204*6f1c0430SSimon Glass 	uint8_t cmd;
2205*6f1c0430SSimon Glass 	union {
2206*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_DUMP */
2207*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2208*6f1c0430SSimon Glass 			/*
2209*6f1c0430SSimon Glass 			 * Maximal number of sensor the host is expecting.
2210*6f1c0430SSimon Glass 			 * 0 means the host is only interested in the number
2211*6f1c0430SSimon Glass 			 * of sensors controlled by the EC.
2212*6f1c0430SSimon Glass 			 */
2213*6f1c0430SSimon Glass 			uint8_t max_sensor_count;
2214*6f1c0430SSimon Glass 		} dump;
2215*6f1c0430SSimon Glass 
2216*6f1c0430SSimon Glass 		/*
2217*6f1c0430SSimon Glass 		 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
2218*6f1c0430SSimon Glass 		 */
2219*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2220*6f1c0430SSimon Glass 			/* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2221*6f1c0430SSimon Glass 			 * kb_wake_angle: angle to wakup AP.
2222*6f1c0430SSimon Glass 			 */
2223*6f1c0430SSimon Glass 			int16_t data;
2224*6f1c0430SSimon Glass 		} kb_wake_angle;
2225*6f1c0430SSimon Glass 
2226*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2227*6f1c0430SSimon Glass 		 * and MOTIONSENSE_CMD_PERFORM_CALIB. */
2228*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2229*6f1c0430SSimon Glass 			uint8_t sensor_num;
2230*6f1c0430SSimon Glass 		} info, info_3, data, fifo_flush, perform_calib,
2231*6f1c0430SSimon Glass 				list_activities;
2232*6f1c0430SSimon Glass 
2233*6f1c0430SSimon Glass 		/*
2234*6f1c0430SSimon Glass 		 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2235*6f1c0430SSimon Glass 		 * and MOTIONSENSE_CMD_SENSOR_RANGE.
2236*6f1c0430SSimon Glass 		 */
2237*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2238*6f1c0430SSimon Glass 			uint8_t sensor_num;
2239*6f1c0430SSimon Glass 
2240*6f1c0430SSimon Glass 			/* Rounding flag, true for round-up, false for down. */
2241*6f1c0430SSimon Glass 			uint8_t roundup;
2242*6f1c0430SSimon Glass 
2243*6f1c0430SSimon Glass 			uint16_t reserved;
2244*6f1c0430SSimon Glass 
2245*6f1c0430SSimon Glass 			/* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2246*6f1c0430SSimon Glass 			int32_t data;
2247*6f1c0430SSimon Glass 		} ec_rate, sensor_odr, sensor_range;
2248*6f1c0430SSimon Glass 
2249*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
2250*6f1c0430SSimon Glass 		struct __ec_todo_packed {
2251*6f1c0430SSimon Glass 			uint8_t sensor_num;
2252*6f1c0430SSimon Glass 
2253*6f1c0430SSimon Glass 			/*
2254*6f1c0430SSimon Glass 			 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2255*6f1c0430SSimon Glass 			 * the calibration information in the EC.
2256*6f1c0430SSimon Glass 			 * If unset, just retrieve calibration information.
2257*6f1c0430SSimon Glass 			 */
2258*6f1c0430SSimon Glass 			uint16_t flags;
2259*6f1c0430SSimon Glass 
2260*6f1c0430SSimon Glass 			/*
2261*6f1c0430SSimon Glass 			 * Temperature at calibration, in units of 0.01 C
2262*6f1c0430SSimon Glass 			 * 0x8000: invalid / unknown.
2263*6f1c0430SSimon Glass 			 * 0x0: 0C
2264*6f1c0430SSimon Glass 			 * 0x7fff: +327.67C
2265*6f1c0430SSimon Glass 			 */
2266*6f1c0430SSimon Glass 			int16_t temp;
2267*6f1c0430SSimon Glass 
2268*6f1c0430SSimon Glass 			/*
2269*6f1c0430SSimon Glass 			 * Offset for calibration.
2270*6f1c0430SSimon Glass 			 * Unit:
2271*6f1c0430SSimon Glass 			 * Accelerometer: 1/1024 g
2272*6f1c0430SSimon Glass 			 * Gyro:          1/1024 deg/s
2273*6f1c0430SSimon Glass 			 * Compass:       1/16 uT
2274*6f1c0430SSimon Glass 			 */
2275*6f1c0430SSimon Glass 			int16_t offset[3];
2276*6f1c0430SSimon Glass 		} sensor_offset;
2277*6f1c0430SSimon Glass 
2278*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_FIFO_INFO */
2279*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2280*6f1c0430SSimon Glass 		} fifo_info;
2281*6f1c0430SSimon Glass 
2282*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_FIFO_READ */
2283*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2284*6f1c0430SSimon Glass 			/*
2285*6f1c0430SSimon Glass 			 * Number of expected vector to return.
2286*6f1c0430SSimon Glass 			 * EC may return less or 0 if none available.
2287*6f1c0430SSimon Glass 			 */
2288*6f1c0430SSimon Glass 			uint32_t max_data_vector;
2289*6f1c0430SSimon Glass 		} fifo_read;
2290*6f1c0430SSimon Glass 
2291*6f1c0430SSimon Glass 		struct ec_motion_sense_activity set_activity;
2292*6f1c0430SSimon Glass 
2293*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_LID_ANGLE */
2294*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2295*6f1c0430SSimon Glass 		} lid_angle;
2296*6f1c0430SSimon Glass 
2297*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2298*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2299*6f1c0430SSimon Glass 			/*
2300*6f1c0430SSimon Glass 			 * 1: enable, 0 disable fifo,
2301*6f1c0430SSimon Glass 			 * EC_MOTION_SENSE_NO_VALUE return value.
2302*6f1c0430SSimon Glass 			 */
2303*6f1c0430SSimon Glass 			int8_t enable;
2304*6f1c0430SSimon Glass 		} fifo_int_enable;
2305*6f1c0430SSimon Glass 
2306*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_SPOOF */
2307*6f1c0430SSimon Glass 		struct __ec_todo_packed {
2308*6f1c0430SSimon Glass 			uint8_t sensor_id;
2309*6f1c0430SSimon Glass 
2310*6f1c0430SSimon Glass 			/* See enum motionsense_spoof_mode. */
2311*6f1c0430SSimon Glass 			uint8_t spoof_enable;
2312*6f1c0430SSimon Glass 
2313*6f1c0430SSimon Glass 			/* Ignored, used for alignment. */
2314*6f1c0430SSimon Glass 			uint8_t reserved;
2315*6f1c0430SSimon Glass 
2316*6f1c0430SSimon Glass 			/* Individual component values to spoof. */
2317*6f1c0430SSimon Glass 			int16_t components[3];
2318*6f1c0430SSimon Glass 		} spoof;
2319*6f1c0430SSimon Glass 	};
2320*6f1c0430SSimon Glass };
2321*6f1c0430SSimon Glass 
2322*6f1c0430SSimon Glass struct __ec_todo_packed ec_response_motion_sense {
2323*6f1c0430SSimon Glass 	union {
2324*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_DUMP */
2325*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2326*6f1c0430SSimon Glass 			/* Flags representing the motion sensor module. */
2327*6f1c0430SSimon Glass 			uint8_t module_flags;
2328*6f1c0430SSimon Glass 
2329*6f1c0430SSimon Glass 			/* Number of sensors managed directly by the EC */
2330*6f1c0430SSimon Glass 			uint8_t sensor_count;
2331*6f1c0430SSimon Glass 
2332*6f1c0430SSimon Glass 			/*
2333*6f1c0430SSimon Glass 			 * sensor data is truncated if response_max is too small
2334*6f1c0430SSimon Glass 			 * for holding all the data.
2335*6f1c0430SSimon Glass 			 */
2336*6f1c0430SSimon Glass 			struct ec_response_motion_sensor_data sensor[0];
2337*6f1c0430SSimon Glass 		} dump;
2338*6f1c0430SSimon Glass 
2339*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_INFO. */
2340*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2341*6f1c0430SSimon Glass 			/* Should be element of enum motionsensor_type. */
2342*6f1c0430SSimon Glass 			uint8_t type;
2343*6f1c0430SSimon Glass 
2344*6f1c0430SSimon Glass 			/* Should be element of enum motionsensor_location. */
2345*6f1c0430SSimon Glass 			uint8_t location;
2346*6f1c0430SSimon Glass 
2347*6f1c0430SSimon Glass 			/* Should be element of enum motionsensor_chip. */
2348*6f1c0430SSimon Glass 			uint8_t chip;
2349*6f1c0430SSimon Glass 		} info;
2350*6f1c0430SSimon Glass 
2351*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_INFO version 3 */
2352*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2353*6f1c0430SSimon Glass 			/* Should be element of enum motionsensor_type. */
2354*6f1c0430SSimon Glass 			uint8_t type;
2355*6f1c0430SSimon Glass 
2356*6f1c0430SSimon Glass 			/* Should be element of enum motionsensor_location. */
2357*6f1c0430SSimon Glass 			uint8_t location;
2358*6f1c0430SSimon Glass 
2359*6f1c0430SSimon Glass 			/* Should be element of enum motionsensor_chip. */
2360*6f1c0430SSimon Glass 			uint8_t chip;
2361*6f1c0430SSimon Glass 
2362*6f1c0430SSimon Glass 			/* Minimum sensor sampling frequency */
2363*6f1c0430SSimon Glass 			uint32_t min_frequency;
2364*6f1c0430SSimon Glass 
2365*6f1c0430SSimon Glass 			/* Maximum sensor sampling frequency */
2366*6f1c0430SSimon Glass 			uint32_t max_frequency;
2367*6f1c0430SSimon Glass 
2368*6f1c0430SSimon Glass 			/* Max number of sensor events that could be in fifo */
2369*6f1c0430SSimon Glass 			uint32_t fifo_max_event_count;
2370*6f1c0430SSimon Glass 		} info_3;
2371*6f1c0430SSimon Glass 
2372*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_DATA */
2373*6f1c0430SSimon Glass 		struct ec_response_motion_sensor_data data;
2374*6f1c0430SSimon Glass 
2375*6f1c0430SSimon Glass 		/*
2376*6f1c0430SSimon Glass 		 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
2377*6f1c0430SSimon Glass 		 * MOTIONSENSE_CMD_SENSOR_RANGE,
2378*6f1c0430SSimon Glass 		 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2379*6f1c0430SSimon Glass 		 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2380*6f1c0430SSimon Glass 		 * MOTIONSENSE_CMD_SPOOF.
2381*6f1c0430SSimon Glass 		 */
2382*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2383*6f1c0430SSimon Glass 			/* Current value of the parameter queried. */
2384*6f1c0430SSimon Glass 			int32_t ret;
2385*6f1c0430SSimon Glass 		} ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2386*6f1c0430SSimon Glass 		  fifo_int_enable, spoof;
2387*6f1c0430SSimon Glass 
2388*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
2389*6f1c0430SSimon Glass 		struct __ec_todo_unpacked  {
2390*6f1c0430SSimon Glass 			int16_t temp;
2391*6f1c0430SSimon Glass 			int16_t offset[3];
2392*6f1c0430SSimon Glass 		} sensor_offset, perform_calib;
2393*6f1c0430SSimon Glass 
2394*6f1c0430SSimon Glass 		struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2395*6f1c0430SSimon Glass 
2396*6f1c0430SSimon Glass 		struct ec_response_motion_sense_fifo_data fifo_read;
2397*6f1c0430SSimon Glass 
2398*6f1c0430SSimon Glass 		struct __ec_todo_packed {
2399*6f1c0430SSimon Glass 			uint16_t reserved;
2400*6f1c0430SSimon Glass 			uint32_t enabled;
2401*6f1c0430SSimon Glass 			uint32_t disabled;
2402*6f1c0430SSimon Glass 		} list_activities;
2403*6f1c0430SSimon Glass 
2404*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2405*6f1c0430SSimon Glass 		} set_activity;
2406*6f1c0430SSimon Glass 
2407*6f1c0430SSimon Glass 		/* Used for MOTIONSENSE_CMD_LID_ANGLE */
2408*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2409*6f1c0430SSimon Glass 			/*
2410*6f1c0430SSimon Glass 			 * Angle between 0 and 360 degree if available,
2411*6f1c0430SSimon Glass 			 * LID_ANGLE_UNRELIABLE otherwise.
2412*6f1c0430SSimon Glass 			 */
2413*6f1c0430SSimon Glass 			uint16_t value;
2414*6f1c0430SSimon Glass 		} lid_angle;
2415*6f1c0430SSimon Glass 	};
2416*6f1c0430SSimon Glass };
2417*6f1c0430SSimon Glass 
2418*6f1c0430SSimon Glass /*****************************************************************************/
2419*6f1c0430SSimon Glass /* Force lid open command */
2420*6f1c0430SSimon Glass 
2421*6f1c0430SSimon Glass /* Make lid event always open */
2422*6f1c0430SSimon Glass #define EC_CMD_FORCE_LID_OPEN 0x002C
2423*6f1c0430SSimon Glass 
2424*6f1c0430SSimon Glass struct __ec_align1 ec_params_force_lid_open {
2425*6f1c0430SSimon Glass 	uint8_t enabled;
2426*6f1c0430SSimon Glass };
2427*6f1c0430SSimon Glass 
2428*6f1c0430SSimon Glass /*****************************************************************************/
2429*6f1c0430SSimon Glass /* Configure the behavior of the power button */
2430*6f1c0430SSimon Glass #define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2431*6f1c0430SSimon Glass 
2432*6f1c0430SSimon Glass enum ec_config_power_button_flags {
2433*6f1c0430SSimon Glass 	/* Enable/Disable power button pulses for x86 devices */
2434*6f1c0430SSimon Glass 	EC_POWER_BUTTON_ENABLE_PULSE = (1 << 0),
2435*6f1c0430SSimon Glass };
2436*6f1c0430SSimon Glass 
2437*6f1c0430SSimon Glass struct __ec_align1 ec_params_config_power_button {
2438*6f1c0430SSimon Glass 	/* See enum ec_config_power_button_flags */
2439*6f1c0430SSimon Glass 	uint8_t flags;
2440*6f1c0430SSimon Glass };
244188364387SHung-ying Tyan 
244288364387SHung-ying Tyan /*****************************************************************************/
244388364387SHung-ying Tyan /* USB charging control commands */
244488364387SHung-ying Tyan 
244588364387SHung-ying Tyan /* Set USB port charging mode */
2446*6f1c0430SSimon Glass #define EC_CMD_USB_CHARGE_SET_MODE 0x0030
244788364387SHung-ying Tyan 
2448*6f1c0430SSimon Glass struct __ec_align1 ec_params_usb_charge_set_mode {
244988364387SHung-ying Tyan 	uint8_t usb_port_id;
245088364387SHung-ying Tyan 	uint8_t mode;
2451*6f1c0430SSimon Glass };
245288364387SHung-ying Tyan 
245388364387SHung-ying Tyan /*****************************************************************************/
245488364387SHung-ying Tyan /* Persistent storage for host */
245588364387SHung-ying Tyan 
245688364387SHung-ying Tyan /* Maximum bytes that can be read/written in a single command */
245788364387SHung-ying Tyan #define EC_PSTORE_SIZE_MAX 64
245888364387SHung-ying Tyan 
245988364387SHung-ying Tyan /* Get persistent storage info */
2460*6f1c0430SSimon Glass #define EC_CMD_PSTORE_INFO 0x0040
246188364387SHung-ying Tyan 
2462*6f1c0430SSimon Glass struct __ec_align4 ec_response_pstore_info {
246388364387SHung-ying Tyan 	/* Persistent storage size, in bytes */
246488364387SHung-ying Tyan 	uint32_t pstore_size;
246588364387SHung-ying Tyan 	/* Access size; read/write offset and size must be a multiple of this */
246688364387SHung-ying Tyan 	uint32_t access_size;
2467*6f1c0430SSimon Glass };
246888364387SHung-ying Tyan 
246988364387SHung-ying Tyan /*
247088364387SHung-ying Tyan  * Read persistent storage
247188364387SHung-ying Tyan  *
247288364387SHung-ying Tyan  * Response is params.size bytes of data.
247388364387SHung-ying Tyan  */
2474*6f1c0430SSimon Glass #define EC_CMD_PSTORE_READ 0x0041
247588364387SHung-ying Tyan 
2476*6f1c0430SSimon Glass struct __ec_align4 ec_params_pstore_read {
247788364387SHung-ying Tyan 	uint32_t offset;   /* Byte offset to read */
247888364387SHung-ying Tyan 	uint32_t size;     /* Size to read in bytes */
2479*6f1c0430SSimon Glass };
248088364387SHung-ying Tyan 
248188364387SHung-ying Tyan /* Write persistent storage */
2482*6f1c0430SSimon Glass #define EC_CMD_PSTORE_WRITE 0x0042
248388364387SHung-ying Tyan 
2484*6f1c0430SSimon Glass struct __ec_align4 ec_params_pstore_write {
248588364387SHung-ying Tyan 	uint32_t offset;   /* Byte offset to write */
248688364387SHung-ying Tyan 	uint32_t size;     /* Size to write in bytes */
248788364387SHung-ying Tyan 	uint8_t data[EC_PSTORE_SIZE_MAX];
2488*6f1c0430SSimon Glass };
248988364387SHung-ying Tyan 
249088364387SHung-ying Tyan /*****************************************************************************/
249188364387SHung-ying Tyan /* Real-time clock */
249288364387SHung-ying Tyan 
249388364387SHung-ying Tyan /* RTC params and response structures */
2494*6f1c0430SSimon Glass struct __ec_align4 ec_params_rtc {
249588364387SHung-ying Tyan 	uint32_t time;
2496*6f1c0430SSimon Glass };
249788364387SHung-ying Tyan 
2498*6f1c0430SSimon Glass struct __ec_align4 ec_response_rtc {
249988364387SHung-ying Tyan 	uint32_t time;
2500*6f1c0430SSimon Glass };
250188364387SHung-ying Tyan 
250288364387SHung-ying Tyan /* These use ec_response_rtc */
2503*6f1c0430SSimon Glass #define EC_CMD_RTC_GET_VALUE 0x0044
2504*6f1c0430SSimon Glass #define EC_CMD_RTC_GET_ALARM 0x0045
250588364387SHung-ying Tyan 
250688364387SHung-ying Tyan /* These all use ec_params_rtc */
2507*6f1c0430SSimon Glass #define EC_CMD_RTC_SET_VALUE 0x0046
2508*6f1c0430SSimon Glass #define EC_CMD_RTC_SET_ALARM 0x0047
2509*6f1c0430SSimon Glass 
2510*6f1c0430SSimon Glass /* Pass as time param to SET_ALARM to clear the current alarm */
2511*6f1c0430SSimon Glass #define EC_RTC_ALARM_CLEAR 0
251288364387SHung-ying Tyan 
251388364387SHung-ying Tyan /*****************************************************************************/
251488364387SHung-ying Tyan /* Port80 log access */
251588364387SHung-ying Tyan 
2516*6f1c0430SSimon Glass /* Maximum entries that can be read/written in a single command */
2517*6f1c0430SSimon Glass #define EC_PORT80_SIZE_MAX 32
251888364387SHung-ying Tyan 
2519*6f1c0430SSimon Glass /* Get last port80 code from previous boot */
2520*6f1c0430SSimon Glass #define EC_CMD_PORT80_LAST_BOOT 0x0048
2521*6f1c0430SSimon Glass #define EC_CMD_PORT80_READ 0x0048
2522*6f1c0430SSimon Glass 
2523*6f1c0430SSimon Glass enum ec_port80_subcmd {
2524*6f1c0430SSimon Glass 	EC_PORT80_GET_INFO = 0,
2525*6f1c0430SSimon Glass 	EC_PORT80_READ_BUFFER,
2526*6f1c0430SSimon Glass };
2527*6f1c0430SSimon Glass 
2528*6f1c0430SSimon Glass struct __ec_todo_packed ec_params_port80_read {
2529*6f1c0430SSimon Glass 	uint16_t subcmd;
2530*6f1c0430SSimon Glass 	union {
2531*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2532*6f1c0430SSimon Glass 			uint32_t offset;
2533*6f1c0430SSimon Glass 			uint32_t num_entries;
2534*6f1c0430SSimon Glass 		} read_buffer;
2535*6f1c0430SSimon Glass 	};
2536*6f1c0430SSimon Glass };
2537*6f1c0430SSimon Glass 
2538*6f1c0430SSimon Glass struct __ec_todo_packed ec_response_port80_read {
2539*6f1c0430SSimon Glass 	union {
2540*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2541*6f1c0430SSimon Glass 			uint32_t writes;
2542*6f1c0430SSimon Glass 			uint32_t history_size;
2543*6f1c0430SSimon Glass 			uint32_t last_boot;
2544*6f1c0430SSimon Glass 		} get_info;
2545*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
2546*6f1c0430SSimon Glass 			uint16_t codes[EC_PORT80_SIZE_MAX];
2547*6f1c0430SSimon Glass 		} data;
2548*6f1c0430SSimon Glass 	};
2549*6f1c0430SSimon Glass };
2550*6f1c0430SSimon Glass 
2551*6f1c0430SSimon Glass struct __ec_align2 ec_response_port80_last_boot {
255288364387SHung-ying Tyan 	uint16_t code;
2553*6f1c0430SSimon Glass };
255488364387SHung-ying Tyan 
255588364387SHung-ying Tyan /*****************************************************************************/
2556*6f1c0430SSimon Glass /* Temporary secure storage for host verified boot use */
255788364387SHung-ying Tyan 
2558*6f1c0430SSimon Glass /* Number of bytes in a vstore slot */
2559*6f1c0430SSimon Glass #define EC_VSTORE_SLOT_SIZE 64
256088364387SHung-ying Tyan 
2561*6f1c0430SSimon Glass /* Maximum number of vstore slots */
2562*6f1c0430SSimon Glass #define EC_VSTORE_SLOT_MAX 32
2563*6f1c0430SSimon Glass 
2564*6f1c0430SSimon Glass /* Get persistent storage info */
2565*6f1c0430SSimon Glass #define EC_CMD_VSTORE_INFO 0x0049
2566*6f1c0430SSimon Glass struct __ec_align_size1 ec_response_vstore_info {
2567*6f1c0430SSimon Glass 	/* Indicates which slots are locked */
2568*6f1c0430SSimon Glass 	uint32_t slot_locked;
2569*6f1c0430SSimon Glass 	/* Total number of slots available */
2570*6f1c0430SSimon Glass 	uint8_t slot_count;
2571*6f1c0430SSimon Glass };
2572*6f1c0430SSimon Glass 
2573*6f1c0430SSimon Glass /*
2574*6f1c0430SSimon Glass  * Read temporary secure storage
2575*6f1c0430SSimon Glass  *
2576*6f1c0430SSimon Glass  * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2577*6f1c0430SSimon Glass  */
2578*6f1c0430SSimon Glass #define EC_CMD_VSTORE_READ 0x004A
2579*6f1c0430SSimon Glass 
2580*6f1c0430SSimon Glass struct __ec_align1 ec_params_vstore_read {
2581*6f1c0430SSimon Glass 	uint8_t slot; /* Slot to read from */
2582*6f1c0430SSimon Glass };
2583*6f1c0430SSimon Glass 
2584*6f1c0430SSimon Glass struct __ec_align1 ec_response_vstore_read {
2585*6f1c0430SSimon Glass 	uint8_t data[EC_VSTORE_SLOT_SIZE];
2586*6f1c0430SSimon Glass };
2587*6f1c0430SSimon Glass 
2588*6f1c0430SSimon Glass /*
2589*6f1c0430SSimon Glass  * Write temporary secure storage and lock it.
2590*6f1c0430SSimon Glass  */
2591*6f1c0430SSimon Glass #define EC_CMD_VSTORE_WRITE 0x004B
2592*6f1c0430SSimon Glass 
2593*6f1c0430SSimon Glass struct __ec_align1 ec_params_vstore_write {
2594*6f1c0430SSimon Glass 	uint8_t slot; /* Slot to write to */
2595*6f1c0430SSimon Glass 	uint8_t data[EC_VSTORE_SLOT_SIZE];
2596*6f1c0430SSimon Glass };
2597*6f1c0430SSimon Glass 
2598*6f1c0430SSimon Glass /*****************************************************************************/
2599*6f1c0430SSimon Glass /* Thermal engine commands. Note that there are two implementations. We'll
2600*6f1c0430SSimon Glass  * reuse the command number, but the data and behavior is incompatible.
2601*6f1c0430SSimon Glass  * Version 0 is what originally shipped on Link.
2602*6f1c0430SSimon Glass  * Version 1 separates the CPU thermal limits from the fan control.
2603*6f1c0430SSimon Glass  */
2604*6f1c0430SSimon Glass 
2605*6f1c0430SSimon Glass #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
2606*6f1c0430SSimon Glass #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
2607*6f1c0430SSimon Glass 
2608*6f1c0430SSimon Glass /* The version 0 structs are opaque. You have to know what they are for
2609*6f1c0430SSimon Glass  * the get/set commands to make any sense.
2610*6f1c0430SSimon Glass  */
2611*6f1c0430SSimon Glass 
2612*6f1c0430SSimon Glass /* Version 0 - set */
2613*6f1c0430SSimon Glass struct __ec_align2 ec_params_thermal_set_threshold {
261488364387SHung-ying Tyan 	uint8_t sensor_type;
261588364387SHung-ying Tyan 	uint8_t threshold_id;
261688364387SHung-ying Tyan 	uint16_t value;
2617*6f1c0430SSimon Glass };
261888364387SHung-ying Tyan 
2619*6f1c0430SSimon Glass /* Version 0 - get */
2620*6f1c0430SSimon Glass struct __ec_align1 ec_params_thermal_get_threshold {
262188364387SHung-ying Tyan 	uint8_t sensor_type;
262288364387SHung-ying Tyan 	uint8_t threshold_id;
2623*6f1c0430SSimon Glass };
262488364387SHung-ying Tyan 
2625*6f1c0430SSimon Glass struct __ec_align2 ec_response_thermal_get_threshold {
262688364387SHung-ying Tyan 	uint16_t value;
2627*6f1c0430SSimon Glass };
2628*6f1c0430SSimon Glass 
2629*6f1c0430SSimon Glass 
2630*6f1c0430SSimon Glass /* The version 1 structs are visible. */
2631*6f1c0430SSimon Glass enum ec_temp_thresholds {
2632*6f1c0430SSimon Glass 	EC_TEMP_THRESH_WARN = 0,
2633*6f1c0430SSimon Glass 	EC_TEMP_THRESH_HIGH,
2634*6f1c0430SSimon Glass 	EC_TEMP_THRESH_HALT,
2635*6f1c0430SSimon Glass 
2636*6f1c0430SSimon Glass 	EC_TEMP_THRESH_COUNT
2637*6f1c0430SSimon Glass };
2638*6f1c0430SSimon Glass 
2639*6f1c0430SSimon Glass /*
2640*6f1c0430SSimon Glass  * Thermal configuration for one temperature sensor. Temps are in degrees K.
2641*6f1c0430SSimon Glass  * Zero values will be silently ignored by the thermal task.
2642*6f1c0430SSimon Glass  *
2643*6f1c0430SSimon Glass  * Note that this structure is a sub-structure of
2644*6f1c0430SSimon Glass  * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
2645*6f1c0430SSimon Glass  */
2646*6f1c0430SSimon Glass struct __ec_align4 ec_thermal_config {
2647*6f1c0430SSimon Glass 	uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
2648*6f1c0430SSimon Glass 	uint32_t temp_fan_off;		/* no active cooling needed */
2649*6f1c0430SSimon Glass 	uint32_t temp_fan_max;		/* max active cooling needed */
2650*6f1c0430SSimon Glass };
2651*6f1c0430SSimon Glass 
2652*6f1c0430SSimon Glass /* Version 1 - get config for one sensor. */
2653*6f1c0430SSimon Glass struct __ec_align4 ec_params_thermal_get_threshold_v1 {
2654*6f1c0430SSimon Glass 	uint32_t sensor_num;
2655*6f1c0430SSimon Glass };
2656*6f1c0430SSimon Glass /* This returns a struct ec_thermal_config */
2657*6f1c0430SSimon Glass 
2658*6f1c0430SSimon Glass /* Version 1 - set config for one sensor.
2659*6f1c0430SSimon Glass  * Use read-modify-write for best results! */
2660*6f1c0430SSimon Glass struct __ec_align4 ec_params_thermal_set_threshold_v1 {
2661*6f1c0430SSimon Glass 	uint32_t sensor_num;
2662*6f1c0430SSimon Glass 	struct ec_thermal_config cfg;
2663*6f1c0430SSimon Glass };
2664*6f1c0430SSimon Glass /* This returns no data */
2665*6f1c0430SSimon Glass 
2666*6f1c0430SSimon Glass /****************************************************************************/
266788364387SHung-ying Tyan 
266888364387SHung-ying Tyan /* Toggle automatic fan control */
2669*6f1c0430SSimon Glass #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
267088364387SHung-ying Tyan 
2671*6f1c0430SSimon Glass /* Version 1 of input params */
2672*6f1c0430SSimon Glass struct __ec_align1 ec_params_auto_fan_ctrl_v1 {
2673*6f1c0430SSimon Glass 	uint8_t fan_idx;
2674*6f1c0430SSimon Glass };
267588364387SHung-ying Tyan 
2676*6f1c0430SSimon Glass /* Get/Set TMP006 calibration data */
2677*6f1c0430SSimon Glass #define EC_CMD_TMP006_GET_CALIBRATION 0x0053
2678*6f1c0430SSimon Glass #define EC_CMD_TMP006_SET_CALIBRATION 0x0054
2679*6f1c0430SSimon Glass 
2680*6f1c0430SSimon Glass /*
2681*6f1c0430SSimon Glass  * The original TMP006 calibration only needed four params, but now we need
2682*6f1c0430SSimon Glass  * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
2683*6f1c0430SSimon Glass  * the params opaque. The v1 "get" response will include the algorithm number
2684*6f1c0430SSimon Glass  * and how many params it requires. That way we can change the EC code without
2685*6f1c0430SSimon Glass  * needing to update this file. We can also use a different algorithm on each
2686*6f1c0430SSimon Glass  * sensor.
2687*6f1c0430SSimon Glass  */
2688*6f1c0430SSimon Glass 
2689*6f1c0430SSimon Glass /* This is the same struct for both v0 and v1. */
2690*6f1c0430SSimon Glass struct __ec_align1 ec_params_tmp006_get_calibration {
269188364387SHung-ying Tyan 	uint8_t index;
2692*6f1c0430SSimon Glass };
269388364387SHung-ying Tyan 
2694*6f1c0430SSimon Glass /* Version 0 */
2695*6f1c0430SSimon Glass struct __ec_align4 ec_response_tmp006_get_calibration_v0 {
269688364387SHung-ying Tyan 	float s0;
269788364387SHung-ying Tyan 	float b0;
269888364387SHung-ying Tyan 	float b1;
269988364387SHung-ying Tyan 	float b2;
2700*6f1c0430SSimon Glass };
270188364387SHung-ying Tyan 
2702*6f1c0430SSimon Glass struct __ec_align4 ec_params_tmp006_set_calibration_v0 {
270388364387SHung-ying Tyan 	uint8_t index;
2704*6f1c0430SSimon Glass 	uint8_t reserved[3];
270588364387SHung-ying Tyan 	float s0;
270688364387SHung-ying Tyan 	float b0;
270788364387SHung-ying Tyan 	float b1;
270888364387SHung-ying Tyan 	float b2;
2709*6f1c0430SSimon Glass };
2710*6f1c0430SSimon Glass 
2711*6f1c0430SSimon Glass /* Version 1 */
2712*6f1c0430SSimon Glass struct __ec_align4 ec_response_tmp006_get_calibration_v1 {
2713*6f1c0430SSimon Glass 	uint8_t algorithm;
2714*6f1c0430SSimon Glass 	uint8_t num_params;
2715*6f1c0430SSimon Glass 	uint8_t reserved[2];
2716*6f1c0430SSimon Glass 	float val[0];
2717*6f1c0430SSimon Glass };
2718*6f1c0430SSimon Glass 
2719*6f1c0430SSimon Glass struct __ec_align4 ec_params_tmp006_set_calibration_v1 {
2720*6f1c0430SSimon Glass 	uint8_t index;
2721*6f1c0430SSimon Glass 	uint8_t algorithm;
2722*6f1c0430SSimon Glass 	uint8_t num_params;
2723*6f1c0430SSimon Glass 	uint8_t reserved;
2724*6f1c0430SSimon Glass 	float val[0];
2725*6f1c0430SSimon Glass };
2726*6f1c0430SSimon Glass 
2727*6f1c0430SSimon Glass 
2728*6f1c0430SSimon Glass /* Read raw TMP006 data */
2729*6f1c0430SSimon Glass #define EC_CMD_TMP006_GET_RAW 0x0055
2730*6f1c0430SSimon Glass 
2731*6f1c0430SSimon Glass struct __ec_align1 ec_params_tmp006_get_raw {
2732*6f1c0430SSimon Glass 	uint8_t index;
2733*6f1c0430SSimon Glass };
2734*6f1c0430SSimon Glass 
2735*6f1c0430SSimon Glass struct __ec_align4 ec_response_tmp006_get_raw {
2736*6f1c0430SSimon Glass 	int32_t t;  /* In 1/100 K */
2737*6f1c0430SSimon Glass 	int32_t v;  /* In nV */
2738*6f1c0430SSimon Glass };
273988364387SHung-ying Tyan 
274088364387SHung-ying Tyan /*****************************************************************************/
2741836bb6e8SSimon Glass /* MKBP - Matrix KeyBoard Protocol */
274288364387SHung-ying Tyan 
274388364387SHung-ying Tyan /*
274488364387SHung-ying Tyan  * Read key state
274588364387SHung-ying Tyan  *
2746836bb6e8SSimon Glass  * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
274788364387SHung-ying Tyan  * expected response size.
2748*6f1c0430SSimon Glass  *
2749*6f1c0430SSimon Glass  * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT.  If you wish
2750*6f1c0430SSimon Glass  * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
2751*6f1c0430SSimon Glass  * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
275288364387SHung-ying Tyan  */
2753*6f1c0430SSimon Glass #define EC_CMD_MKBP_STATE 0x0060
275488364387SHung-ying Tyan 
2755*6f1c0430SSimon Glass /*
2756*6f1c0430SSimon Glass  * Provide information about various MKBP things.  See enum ec_mkbp_info_type.
2757*6f1c0430SSimon Glass  */
2758*6f1c0430SSimon Glass #define EC_CMD_MKBP_INFO 0x0061
275988364387SHung-ying Tyan 
2760*6f1c0430SSimon Glass struct __ec_align_size1 ec_response_mkbp_info {
276188364387SHung-ying Tyan 	uint32_t rows;
276288364387SHung-ying Tyan 	uint32_t cols;
2763*6f1c0430SSimon Glass 	/* Formerly "switches", which was 0. */
2764*6f1c0430SSimon Glass 	uint8_t reserved;
2765*6f1c0430SSimon Glass };
2766*6f1c0430SSimon Glass 
2767*6f1c0430SSimon Glass struct __ec_align1 ec_params_mkbp_info {
2768*6f1c0430SSimon Glass 	uint8_t info_type;
2769*6f1c0430SSimon Glass 	uint8_t event_type;
2770*6f1c0430SSimon Glass };
2771*6f1c0430SSimon Glass 
2772*6f1c0430SSimon Glass enum ec_mkbp_info_type {
2773*6f1c0430SSimon Glass 	/*
2774*6f1c0430SSimon Glass 	 * Info about the keyboard matrix: number of rows and columns.
2775*6f1c0430SSimon Glass 	 *
2776*6f1c0430SSimon Glass 	 * Returns struct ec_response_mkbp_info.
2777*6f1c0430SSimon Glass 	 */
2778*6f1c0430SSimon Glass 	EC_MKBP_INFO_KBD = 0,
2779*6f1c0430SSimon Glass 
2780*6f1c0430SSimon Glass 	/*
2781*6f1c0430SSimon Glass 	 * For buttons and switches, info about which specifically are
2782*6f1c0430SSimon Glass 	 * supported.  event_type must be set to one of the values in enum
2783*6f1c0430SSimon Glass 	 * ec_mkbp_event.
2784*6f1c0430SSimon Glass 	 *
2785*6f1c0430SSimon Glass 	 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2786*6f1c0430SSimon Glass 	 * bitmask indicating which buttons or switches are present.  See the
2787*6f1c0430SSimon Glass 	 * bit inidices below.
2788*6f1c0430SSimon Glass 	 */
2789*6f1c0430SSimon Glass 	EC_MKBP_INFO_SUPPORTED = 1,
2790*6f1c0430SSimon Glass 
2791*6f1c0430SSimon Glass 	/*
2792*6f1c0430SSimon Glass 	 * Instantaneous state of buttons and switches.
2793*6f1c0430SSimon Glass 	 *
2794*6f1c0430SSimon Glass 	 * event_type must be set to one of the values in enum ec_mkbp_event.
2795*6f1c0430SSimon Glass 	 *
2796*6f1c0430SSimon Glass 	 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2797*6f1c0430SSimon Glass 	 * indicating the current state of the keyboard matrix.
2798*6f1c0430SSimon Glass 	 *
2799*6f1c0430SSimon Glass 	 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2800*6f1c0430SSimon Glass 	 * event state.
2801*6f1c0430SSimon Glass 	 *
2802*6f1c0430SSimon Glass 	 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2803*6f1c0430SSimon Glass 	 * state of supported buttons.
2804*6f1c0430SSimon Glass 	 *
2805*6f1c0430SSimon Glass 	 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2806*6f1c0430SSimon Glass 	 * state of supported switches.
2807*6f1c0430SSimon Glass 	 */
2808*6f1c0430SSimon Glass 	EC_MKBP_INFO_CURRENT = 2,
2809*6f1c0430SSimon Glass };
281088364387SHung-ying Tyan 
281188364387SHung-ying Tyan /* Simulate key press */
2812*6f1c0430SSimon Glass #define EC_CMD_MKBP_SIMULATE_KEY 0x0062
281388364387SHung-ying Tyan 
2814*6f1c0430SSimon Glass struct __ec_align1 ec_params_mkbp_simulate_key {
281588364387SHung-ying Tyan 	uint8_t col;
281688364387SHung-ying Tyan 	uint8_t row;
281788364387SHung-ying Tyan 	uint8_t pressed;
2818*6f1c0430SSimon Glass };
281988364387SHung-ying Tyan 
282088364387SHung-ying Tyan /* Configure keyboard scanning */
2821*6f1c0430SSimon Glass #define EC_CMD_MKBP_SET_CONFIG 0x0064
2822*6f1c0430SSimon Glass #define EC_CMD_MKBP_GET_CONFIG 0x0065
282388364387SHung-ying Tyan 
282488364387SHung-ying Tyan /* flags */
2825836bb6e8SSimon Glass enum mkbp_config_flags {
2826836bb6e8SSimon Glass 	EC_MKBP_FLAGS_ENABLE = 1,	/* Enable keyboard scanning */
282788364387SHung-ying Tyan };
282888364387SHung-ying Tyan 
2829836bb6e8SSimon Glass enum mkbp_config_valid {
2830836bb6e8SSimon Glass 	EC_MKBP_VALID_SCAN_PERIOD		= 1 << 0,
2831836bb6e8SSimon Glass 	EC_MKBP_VALID_POLL_TIMEOUT		= 1 << 1,
2832836bb6e8SSimon Glass 	EC_MKBP_VALID_MIN_POST_SCAN_DELAY	= 1 << 3,
2833836bb6e8SSimon Glass 	EC_MKBP_VALID_OUTPUT_SETTLE		= 1 << 4,
2834836bb6e8SSimon Glass 	EC_MKBP_VALID_DEBOUNCE_DOWN		= 1 << 5,
2835836bb6e8SSimon Glass 	EC_MKBP_VALID_DEBOUNCE_UP		= 1 << 6,
2836836bb6e8SSimon Glass 	EC_MKBP_VALID_FIFO_MAX_DEPTH		= 1 << 7,
283788364387SHung-ying Tyan };
283888364387SHung-ying Tyan 
2839*6f1c0430SSimon Glass /*
2840*6f1c0430SSimon Glass  * Configuration for our key scanning algorithm.
2841*6f1c0430SSimon Glass  *
2842*6f1c0430SSimon Glass  * Note that this is used as a sub-structure of
2843*6f1c0430SSimon Glass  * ec_{params/response}_mkbp_get_config.
2844*6f1c0430SSimon Glass  */
2845*6f1c0430SSimon Glass struct __ec_align_size1 ec_mkbp_config {
284688364387SHung-ying Tyan 	uint32_t valid_mask;		/* valid fields */
2847836bb6e8SSimon Glass 	uint8_t flags;		/* some flags (enum mkbp_config_flags) */
284888364387SHung-ying Tyan 	uint8_t valid_flags;		/* which flags are valid */
284988364387SHung-ying Tyan 	uint16_t scan_period_us;	/* period between start of scans */
285088364387SHung-ying Tyan 	/* revert to interrupt mode after no activity for this long */
285188364387SHung-ying Tyan 	uint32_t poll_timeout_us;
285288364387SHung-ying Tyan 	/*
285388364387SHung-ying Tyan 	 * minimum post-scan relax time. Once we finish a scan we check
285488364387SHung-ying Tyan 	 * the time until we are due to start the next one. If this time is
285588364387SHung-ying Tyan 	 * shorter this field, we use this instead.
285688364387SHung-ying Tyan 	 */
285788364387SHung-ying Tyan 	uint16_t min_post_scan_delay_us;
285888364387SHung-ying Tyan 	/* delay between setting up output and waiting for it to settle */
285988364387SHung-ying Tyan 	uint16_t output_settle_us;
286088364387SHung-ying Tyan 	uint16_t debounce_down_us;	/* time for debounce on key down */
286188364387SHung-ying Tyan 	uint16_t debounce_up_us;	/* time for debounce on key up */
286288364387SHung-ying Tyan 	/* maximum depth to allow for fifo (0 = no keyscan output) */
286388364387SHung-ying Tyan 	uint8_t fifo_max_depth;
2864*6f1c0430SSimon Glass };
286588364387SHung-ying Tyan 
2866*6f1c0430SSimon Glass struct __ec_align_size1 ec_params_mkbp_set_config {
2867836bb6e8SSimon Glass 	struct ec_mkbp_config config;
2868*6f1c0430SSimon Glass };
286988364387SHung-ying Tyan 
2870*6f1c0430SSimon Glass struct __ec_align_size1 ec_response_mkbp_get_config {
2871836bb6e8SSimon Glass 	struct ec_mkbp_config config;
2872*6f1c0430SSimon Glass };
287388364387SHung-ying Tyan 
287488364387SHung-ying Tyan /* Run the key scan emulation */
2875*6f1c0430SSimon Glass #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
287688364387SHung-ying Tyan 
287788364387SHung-ying Tyan enum ec_keyscan_seq_cmd {
287888364387SHung-ying Tyan 	EC_KEYSCAN_SEQ_STATUS = 0,	/* Get status information */
287988364387SHung-ying Tyan 	EC_KEYSCAN_SEQ_CLEAR = 1,	/* Clear sequence */
288088364387SHung-ying Tyan 	EC_KEYSCAN_SEQ_ADD = 2,		/* Add item to sequence */
288188364387SHung-ying Tyan 	EC_KEYSCAN_SEQ_START = 3,	/* Start running sequence */
288288364387SHung-ying Tyan 	EC_KEYSCAN_SEQ_COLLECT = 4,	/* Collect sequence summary data */
288388364387SHung-ying Tyan };
288488364387SHung-ying Tyan 
288588364387SHung-ying Tyan enum ec_collect_flags {
288688364387SHung-ying Tyan 	/*
288788364387SHung-ying Tyan 	 * Indicates this scan was processed by the EC. Due to timing, some
288888364387SHung-ying Tyan 	 * scans may be skipped.
288988364387SHung-ying Tyan 	 */
289088364387SHung-ying Tyan 	EC_KEYSCAN_SEQ_FLAG_DONE	= 1 << 0,
289188364387SHung-ying Tyan };
289288364387SHung-ying Tyan 
2893*6f1c0430SSimon Glass struct __ec_align1 ec_collect_item {
289488364387SHung-ying Tyan 	uint8_t flags;		/* some flags (enum ec_collect_flags) */
289588364387SHung-ying Tyan };
289688364387SHung-ying Tyan 
2897*6f1c0430SSimon Glass struct __ec_todo_packed ec_params_keyscan_seq_ctrl {
289888364387SHung-ying Tyan 	uint8_t cmd;	/* Command to send (enum ec_keyscan_seq_cmd) */
289988364387SHung-ying Tyan 	union {
2900*6f1c0430SSimon Glass 		struct __ec_align1 {
290188364387SHung-ying Tyan 			uint8_t active;		/* still active */
290288364387SHung-ying Tyan 			uint8_t num_items;	/* number of items */
290388364387SHung-ying Tyan 			/* Current item being presented */
290488364387SHung-ying Tyan 			uint8_t cur_item;
290588364387SHung-ying Tyan 		} status;
2906*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
290788364387SHung-ying Tyan 			/*
290888364387SHung-ying Tyan 			 * Absolute time for this scan, measured from the
290988364387SHung-ying Tyan 			 * start of the sequence.
291088364387SHung-ying Tyan 			 */
291188364387SHung-ying Tyan 			uint32_t time_us;
291288364387SHung-ying Tyan 			uint8_t scan[0];	/* keyscan data */
291388364387SHung-ying Tyan 		} add;
2914*6f1c0430SSimon Glass 		struct __ec_align1 {
291588364387SHung-ying Tyan 			uint8_t start_item;	/* First item to return */
291688364387SHung-ying Tyan 			uint8_t num_items;	/* Number of items to return */
291788364387SHung-ying Tyan 		} collect;
291888364387SHung-ying Tyan 	};
2919*6f1c0430SSimon Glass };
292088364387SHung-ying Tyan 
2921*6f1c0430SSimon Glass struct __ec_todo_packed ec_result_keyscan_seq_ctrl {
292288364387SHung-ying Tyan 	union {
2923*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
292488364387SHung-ying Tyan 			uint8_t num_items;	/* Number of items */
292588364387SHung-ying Tyan 			/* Data for each item */
292688364387SHung-ying Tyan 			struct ec_collect_item item[0];
292788364387SHung-ying Tyan 		} collect;
292888364387SHung-ying Tyan 	};
2929*6f1c0430SSimon Glass };
2930*6f1c0430SSimon Glass 
2931*6f1c0430SSimon Glass /*
2932*6f1c0430SSimon Glass  * Get the next pending MKBP event.
2933*6f1c0430SSimon Glass  *
2934*6f1c0430SSimon Glass  * Returns EC_RES_UNAVAILABLE if there is no event pending.
2935*6f1c0430SSimon Glass  */
2936*6f1c0430SSimon Glass #define EC_CMD_GET_NEXT_EVENT 0x0067
2937*6f1c0430SSimon Glass 
2938*6f1c0430SSimon Glass enum ec_mkbp_event {
2939*6f1c0430SSimon Glass 	/* Keyboard matrix changed. The event data is the new matrix state. */
2940*6f1c0430SSimon Glass 	EC_MKBP_EVENT_KEY_MATRIX = 0,
2941*6f1c0430SSimon Glass 
2942*6f1c0430SSimon Glass 	/* New host event. The event data is 4 bytes of host event flags. */
2943*6f1c0430SSimon Glass 	EC_MKBP_EVENT_HOST_EVENT = 1,
2944*6f1c0430SSimon Glass 
2945*6f1c0430SSimon Glass 	/* New Sensor FIFO data. The event data is fifo_info structure. */
2946*6f1c0430SSimon Glass 	EC_MKBP_EVENT_SENSOR_FIFO = 2,
2947*6f1c0430SSimon Glass 
2948*6f1c0430SSimon Glass 	/* The state of the non-matrixed buttons have changed. */
2949*6f1c0430SSimon Glass 	EC_MKBP_EVENT_BUTTON = 3,
2950*6f1c0430SSimon Glass 
2951*6f1c0430SSimon Glass 	/* The state of the switches have changed. */
2952*6f1c0430SSimon Glass 	EC_MKBP_EVENT_SWITCH = 4,
2953*6f1c0430SSimon Glass 
2954*6f1c0430SSimon Glass 	/* New Fingerprint sensor event, the event data is fp_events bitmap. */
2955*6f1c0430SSimon Glass 	EC_MKBP_EVENT_FINGERPRINT = 5,
2956*6f1c0430SSimon Glass 
2957*6f1c0430SSimon Glass 	/*
2958*6f1c0430SSimon Glass 	 * Sysrq event: send emulated sysrq. The event data is sysrq,
2959*6f1c0430SSimon Glass 	 * corresponding to the key to be pressed.
2960*6f1c0430SSimon Glass 	 */
2961*6f1c0430SSimon Glass 	EC_MKBP_EVENT_SYSRQ = 6,
2962*6f1c0430SSimon Glass 
2963*6f1c0430SSimon Glass 	/* Number of MKBP events */
2964*6f1c0430SSimon Glass 	EC_MKBP_EVENT_COUNT,
2965*6f1c0430SSimon Glass };
2966*6f1c0430SSimon Glass 
2967*6f1c0430SSimon Glass union __ec_align_offset1 ec_response_get_next_data {
2968*6f1c0430SSimon Glass 	uint8_t key_matrix[13];
2969*6f1c0430SSimon Glass 
2970*6f1c0430SSimon Glass 	/* Unaligned */
2971*6f1c0430SSimon Glass 	uint32_t host_event;
2972*6f1c0430SSimon Glass 
2973*6f1c0430SSimon Glass 	struct __ec_todo_unpacked {
2974*6f1c0430SSimon Glass 		/* For aligning the fifo_info */
2975*6f1c0430SSimon Glass 		uint8_t reserved[3];
2976*6f1c0430SSimon Glass 		struct ec_response_motion_sense_fifo_info info;
2977*6f1c0430SSimon Glass 	} sensor_fifo;
2978*6f1c0430SSimon Glass 
2979*6f1c0430SSimon Glass 	uint32_t buttons;
2980*6f1c0430SSimon Glass 
2981*6f1c0430SSimon Glass 	uint32_t switches;
2982*6f1c0430SSimon Glass 
2983*6f1c0430SSimon Glass 	uint32_t fp_events;
2984*6f1c0430SSimon Glass 
2985*6f1c0430SSimon Glass 	uint32_t sysrq;
2986*6f1c0430SSimon Glass };
2987*6f1c0430SSimon Glass 
2988*6f1c0430SSimon Glass struct __ec_align1 ec_response_get_next_event {
2989*6f1c0430SSimon Glass 	uint8_t event_type;
2990*6f1c0430SSimon Glass 	/* Followed by event data if any */
2991*6f1c0430SSimon Glass 	union ec_response_get_next_data data;
2992*6f1c0430SSimon Glass };
2993*6f1c0430SSimon Glass 
2994*6f1c0430SSimon Glass /* Bit indices for buttons and switches.*/
2995*6f1c0430SSimon Glass /* Buttons */
2996*6f1c0430SSimon Glass #define EC_MKBP_POWER_BUTTON	0
2997*6f1c0430SSimon Glass #define EC_MKBP_VOL_UP		1
2998*6f1c0430SSimon Glass #define EC_MKBP_VOL_DOWN	2
2999*6f1c0430SSimon Glass #define EC_MKBP_RECOVERY	3
3000*6f1c0430SSimon Glass 
3001*6f1c0430SSimon Glass /* Switches */
3002*6f1c0430SSimon Glass #define EC_MKBP_LID_OPEN	0
3003*6f1c0430SSimon Glass #define EC_MKBP_TABLET_MODE	1
3004*6f1c0430SSimon Glass 
3005*6f1c0430SSimon Glass /* Run keyboard factory test scanning */
3006*6f1c0430SSimon Glass #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
3007*6f1c0430SSimon Glass 
3008*6f1c0430SSimon Glass struct __ec_align2 ec_response_keyboard_factory_test {
3009*6f1c0430SSimon Glass 	uint16_t shorted;	/* Keyboard pins are shorted */
3010*6f1c0430SSimon Glass };
3011*6f1c0430SSimon Glass 
3012*6f1c0430SSimon Glass /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3013*6f1c0430SSimon Glass #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
3014*6f1c0430SSimon Glass #define EC_MKBP_FP_FINGER_DOWN          (1 << 29)
3015*6f1c0430SSimon Glass #define EC_MKBP_FP_FINGER_UP            (1 << 30)
3016*6f1c0430SSimon Glass #define EC_MKBP_FP_IMAGE_READY          (1 << 31)
301788364387SHung-ying Tyan 
301888364387SHung-ying Tyan /*****************************************************************************/
301988364387SHung-ying Tyan /* Temperature sensor commands */
302088364387SHung-ying Tyan 
302188364387SHung-ying Tyan /* Read temperature sensor info */
3022*6f1c0430SSimon Glass #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
302388364387SHung-ying Tyan 
3024*6f1c0430SSimon Glass struct __ec_align1 ec_params_temp_sensor_get_info {
302588364387SHung-ying Tyan 	uint8_t id;
3026*6f1c0430SSimon Glass };
302788364387SHung-ying Tyan 
3028*6f1c0430SSimon Glass struct __ec_align1 ec_response_temp_sensor_get_info {
302988364387SHung-ying Tyan 	char sensor_name[32];
303088364387SHung-ying Tyan 	uint8_t sensor_type;
3031*6f1c0430SSimon Glass };
303288364387SHung-ying Tyan 
303388364387SHung-ying Tyan /*****************************************************************************/
303488364387SHung-ying Tyan 
303588364387SHung-ying Tyan /*
303688364387SHung-ying Tyan  * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
303788364387SHung-ying Tyan  * commands accidentally sent to the wrong interface.  See the ACPI section
303888364387SHung-ying Tyan  * below.
303988364387SHung-ying Tyan  */
304088364387SHung-ying Tyan 
304188364387SHung-ying Tyan /*****************************************************************************/
304288364387SHung-ying Tyan /* Host event commands */
304388364387SHung-ying Tyan 
3044*6f1c0430SSimon Glass 
3045*6f1c0430SSimon Glass /* Obsolete. New implementation should use EC_CMD_PROGRAM_HOST_EVENT instead */
304688364387SHung-ying Tyan /*
304788364387SHung-ying Tyan  * Host event mask params and response structures, shared by all of the host
304888364387SHung-ying Tyan  * event commands below.
304988364387SHung-ying Tyan  */
3050*6f1c0430SSimon Glass struct __ec_align4 ec_params_host_event_mask {
305188364387SHung-ying Tyan 	uint32_t mask;
3052*6f1c0430SSimon Glass };
305388364387SHung-ying Tyan 
3054*6f1c0430SSimon Glass struct __ec_align4 ec_response_host_event_mask {
305588364387SHung-ying Tyan 	uint32_t mask;
3056*6f1c0430SSimon Glass };
305788364387SHung-ying Tyan 
305888364387SHung-ying Tyan /* These all use ec_response_host_event_mask */
3059*6f1c0430SSimon Glass #define EC_CMD_HOST_EVENT_GET_B         0x0087
3060*6f1c0430SSimon Glass #define EC_CMD_HOST_EVENT_GET_SMI_MASK  0x0088
3061*6f1c0430SSimon Glass #define EC_CMD_HOST_EVENT_GET_SCI_MASK  0x0089
3062*6f1c0430SSimon Glass #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
306388364387SHung-ying Tyan 
306488364387SHung-ying Tyan /* These all use ec_params_host_event_mask */
3065*6f1c0430SSimon Glass #define EC_CMD_HOST_EVENT_SET_SMI_MASK  0x008A
3066*6f1c0430SSimon Glass #define EC_CMD_HOST_EVENT_SET_SCI_MASK  0x008B
3067*6f1c0430SSimon Glass #define EC_CMD_HOST_EVENT_CLEAR         0x008C
3068*6f1c0430SSimon Glass #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3069*6f1c0430SSimon Glass #define EC_CMD_HOST_EVENT_CLEAR_B       0x008F
3070*6f1c0430SSimon Glass 
3071*6f1c0430SSimon Glass /*
3072*6f1c0430SSimon Glass  * Unified host event programming interface - Should be used by newer versions
3073*6f1c0430SSimon Glass  * of BIOS/OS to program host events and masks
3074*6f1c0430SSimon Glass  */
3075*6f1c0430SSimon Glass 
3076*6f1c0430SSimon Glass struct __ec_align4 ec_params_host_event {
3077*6f1c0430SSimon Glass 
3078*6f1c0430SSimon Glass 	/* Action requested by host - one of enum ec_host_event_action. */
3079*6f1c0430SSimon Glass 	uint8_t action;
3080*6f1c0430SSimon Glass 
3081*6f1c0430SSimon Glass 	/*
3082*6f1c0430SSimon Glass 	 * Mask type that the host requested the action on - one of
3083*6f1c0430SSimon Glass 	 * enum ec_host_event_mask_type.
3084*6f1c0430SSimon Glass 	 */
3085*6f1c0430SSimon Glass 	uint8_t mask_type;
3086*6f1c0430SSimon Glass 
3087*6f1c0430SSimon Glass 	/* Set to 0, ignore on read */
3088*6f1c0430SSimon Glass 	uint16_t reserved;
3089*6f1c0430SSimon Glass 
3090*6f1c0430SSimon Glass 	/* Value to be used in case of set operations. */
3091*6f1c0430SSimon Glass 	uint64_t value;
3092*6f1c0430SSimon Glass };
3093*6f1c0430SSimon Glass 
3094*6f1c0430SSimon Glass /*
3095*6f1c0430SSimon Glass  * Response structure returned by EC_CMD_HOST_EVENT.
3096*6f1c0430SSimon Glass  * Update the value on a GET request. Set to 0 on GET/CLEAR
3097*6f1c0430SSimon Glass  */
3098*6f1c0430SSimon Glass 
3099*6f1c0430SSimon Glass struct __ec_align4 ec_response_host_event {
3100*6f1c0430SSimon Glass 
3101*6f1c0430SSimon Glass 	/* Mask value in case of get operation */
3102*6f1c0430SSimon Glass 	uint64_t value;
3103*6f1c0430SSimon Glass };
3104*6f1c0430SSimon Glass 
3105*6f1c0430SSimon Glass enum ec_host_event_action {
3106*6f1c0430SSimon Glass 	/*
3107*6f1c0430SSimon Glass 	 * params.value is ignored. Value of mask_type populated
3108*6f1c0430SSimon Glass 	 * in response.value
3109*6f1c0430SSimon Glass 	 */
3110*6f1c0430SSimon Glass 	EC_HOST_EVENT_GET,
3111*6f1c0430SSimon Glass 
3112*6f1c0430SSimon Glass 	/* Bits in params.value are set */
3113*6f1c0430SSimon Glass 	EC_HOST_EVENT_SET,
3114*6f1c0430SSimon Glass 
3115*6f1c0430SSimon Glass 	/* Bits in params.value are cleared */
3116*6f1c0430SSimon Glass 	EC_HOST_EVENT_CLEAR,
3117*6f1c0430SSimon Glass };
3118*6f1c0430SSimon Glass 
3119*6f1c0430SSimon Glass enum ec_host_event_mask_type {
3120*6f1c0430SSimon Glass 
3121*6f1c0430SSimon Glass 	/* Main host event copy */
3122*6f1c0430SSimon Glass 	EC_HOST_EVENT_MAIN,
3123*6f1c0430SSimon Glass 
3124*6f1c0430SSimon Glass 	/* Copy B of host events */
3125*6f1c0430SSimon Glass 	EC_HOST_EVENT_B,
3126*6f1c0430SSimon Glass 
3127*6f1c0430SSimon Glass 	/* SCI Mask */
3128*6f1c0430SSimon Glass 	EC_HOST_EVENT_SCI_MASK,
3129*6f1c0430SSimon Glass 
3130*6f1c0430SSimon Glass 	/* SMI Mask */
3131*6f1c0430SSimon Glass 	EC_HOST_EVENT_SMI_MASK,
3132*6f1c0430SSimon Glass 
3133*6f1c0430SSimon Glass 	/* Mask of events that should be always reported in hostevents */
3134*6f1c0430SSimon Glass 	EC_HOST_EVENT_ALWAYS_REPORT_MASK,
3135*6f1c0430SSimon Glass 
3136*6f1c0430SSimon Glass 	/* Active wake mask */
3137*6f1c0430SSimon Glass 	EC_HOST_EVENT_ACTIVE_WAKE_MASK,
3138*6f1c0430SSimon Glass 
3139*6f1c0430SSimon Glass 	/* Lazy wake mask for S0ix */
3140*6f1c0430SSimon Glass 	EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
3141*6f1c0430SSimon Glass 
3142*6f1c0430SSimon Glass 	/* Lazy wake mask for S3 */
3143*6f1c0430SSimon Glass 	EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
3144*6f1c0430SSimon Glass 
3145*6f1c0430SSimon Glass 	/* Lazy wake mask for S5 */
3146*6f1c0430SSimon Glass 	EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
3147*6f1c0430SSimon Glass };
3148*6f1c0430SSimon Glass 
3149*6f1c0430SSimon Glass #define EC_CMD_HOST_EVENT       0x00A4
315088364387SHung-ying Tyan 
315188364387SHung-ying Tyan /*****************************************************************************/
315288364387SHung-ying Tyan /* Switch commands */
315388364387SHung-ying Tyan 
315488364387SHung-ying Tyan /* Enable/disable LCD backlight */
3155*6f1c0430SSimon Glass #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
315688364387SHung-ying Tyan 
3157*6f1c0430SSimon Glass struct __ec_align1 ec_params_switch_enable_backlight {
315888364387SHung-ying Tyan 	uint8_t enabled;
3159*6f1c0430SSimon Glass };
316088364387SHung-ying Tyan 
316188364387SHung-ying Tyan /* Enable/disable WLAN/Bluetooth */
3162*6f1c0430SSimon Glass #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
3163*6f1c0430SSimon Glass #define EC_VER_SWITCH_ENABLE_WIRELESS 1
316488364387SHung-ying Tyan 
3165*6f1c0430SSimon Glass /* Version 0 params; no response */
3166*6f1c0430SSimon Glass struct __ec_align1 ec_params_switch_enable_wireless_v0 {
316788364387SHung-ying Tyan 	uint8_t enabled;
3168*6f1c0430SSimon Glass };
3169*6f1c0430SSimon Glass 
3170*6f1c0430SSimon Glass /* Version 1 params */
3171*6f1c0430SSimon Glass struct __ec_align1 ec_params_switch_enable_wireless_v1 {
3172*6f1c0430SSimon Glass 	/* Flags to enable now */
3173*6f1c0430SSimon Glass 	uint8_t now_flags;
3174*6f1c0430SSimon Glass 
3175*6f1c0430SSimon Glass 	/* Which flags to copy from now_flags */
3176*6f1c0430SSimon Glass 	uint8_t now_mask;
3177*6f1c0430SSimon Glass 
3178*6f1c0430SSimon Glass 	/*
3179*6f1c0430SSimon Glass 	 * Flags to leave enabled in S3, if they're on at the S0->S3
3180*6f1c0430SSimon Glass 	 * transition.  (Other flags will be disabled by the S0->S3
3181*6f1c0430SSimon Glass 	 * transition.)
3182*6f1c0430SSimon Glass 	 */
3183*6f1c0430SSimon Glass 	uint8_t suspend_flags;
3184*6f1c0430SSimon Glass 
3185*6f1c0430SSimon Glass 	/* Which flags to copy from suspend_flags */
3186*6f1c0430SSimon Glass 	uint8_t suspend_mask;
3187*6f1c0430SSimon Glass };
3188*6f1c0430SSimon Glass 
3189*6f1c0430SSimon Glass /* Version 1 response */
3190*6f1c0430SSimon Glass struct __ec_align1 ec_response_switch_enable_wireless_v1 {
3191*6f1c0430SSimon Glass 	/* Flags to enable now */
3192*6f1c0430SSimon Glass 	uint8_t now_flags;
3193*6f1c0430SSimon Glass 
3194*6f1c0430SSimon Glass 	/* Flags to leave enabled in S3 */
3195*6f1c0430SSimon Glass 	uint8_t suspend_flags;
3196*6f1c0430SSimon Glass };
319788364387SHung-ying Tyan 
319888364387SHung-ying Tyan /*****************************************************************************/
319988364387SHung-ying Tyan /* GPIO commands. Only available on EC if write protect has been disabled. */
320088364387SHung-ying Tyan 
320188364387SHung-ying Tyan /* Set GPIO output value */
3202*6f1c0430SSimon Glass #define EC_CMD_GPIO_SET 0x0092
320388364387SHung-ying Tyan 
3204*6f1c0430SSimon Glass struct __ec_align1 ec_params_gpio_set {
320588364387SHung-ying Tyan 	char name[32];
320688364387SHung-ying Tyan 	uint8_t val;
3207*6f1c0430SSimon Glass };
320888364387SHung-ying Tyan 
320988364387SHung-ying Tyan /* Get GPIO value */
3210*6f1c0430SSimon Glass #define EC_CMD_GPIO_GET 0x0093
321188364387SHung-ying Tyan 
3212*6f1c0430SSimon Glass /* Version 0 of input params and response */
3213*6f1c0430SSimon Glass struct __ec_align1 ec_params_gpio_get {
321488364387SHung-ying Tyan 	char name[32];
3215*6f1c0430SSimon Glass };
3216*6f1c0430SSimon Glass 
3217*6f1c0430SSimon Glass struct __ec_align1 ec_response_gpio_get {
321888364387SHung-ying Tyan 	uint8_t val;
3219*6f1c0430SSimon Glass };
3220*6f1c0430SSimon Glass 
3221*6f1c0430SSimon Glass /* Version 1 of input params and response */
3222*6f1c0430SSimon Glass struct __ec_align1 ec_params_gpio_get_v1 {
3223*6f1c0430SSimon Glass 	uint8_t subcmd;
3224*6f1c0430SSimon Glass 	union {
3225*6f1c0430SSimon Glass 		struct __ec_align1 {
3226*6f1c0430SSimon Glass 			char name[32];
3227*6f1c0430SSimon Glass 		} get_value_by_name;
3228*6f1c0430SSimon Glass 		struct __ec_align1 {
3229*6f1c0430SSimon Glass 			uint8_t index;
3230*6f1c0430SSimon Glass 		} get_info;
3231*6f1c0430SSimon Glass 	};
3232*6f1c0430SSimon Glass };
3233*6f1c0430SSimon Glass 
3234*6f1c0430SSimon Glass struct __ec_todo_packed ec_response_gpio_get_v1 {
3235*6f1c0430SSimon Glass 	union {
3236*6f1c0430SSimon Glass 		struct __ec_align1 {
3237*6f1c0430SSimon Glass 			uint8_t val;
3238*6f1c0430SSimon Glass 		} get_value_by_name, get_count;
3239*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
3240*6f1c0430SSimon Glass 			uint8_t val;
3241*6f1c0430SSimon Glass 			char name[32];
3242*6f1c0430SSimon Glass 			uint32_t flags;
3243*6f1c0430SSimon Glass 		} get_info;
3244*6f1c0430SSimon Glass 	};
3245*6f1c0430SSimon Glass };
3246*6f1c0430SSimon Glass 
3247*6f1c0430SSimon Glass enum gpio_get_subcmd {
3248*6f1c0430SSimon Glass 	EC_GPIO_GET_BY_NAME = 0,
3249*6f1c0430SSimon Glass 	EC_GPIO_GET_COUNT = 1,
3250*6f1c0430SSimon Glass 	EC_GPIO_GET_INFO = 2,
3251*6f1c0430SSimon Glass };
325288364387SHung-ying Tyan 
325388364387SHung-ying Tyan /*****************************************************************************/
325488364387SHung-ying Tyan /* I2C commands. Only available when flash write protect is unlocked. */
325588364387SHung-ying Tyan 
3256*6f1c0430SSimon Glass /*
3257*6f1c0430SSimon Glass  * CAUTION: These commands are deprecated, and are not supported anymore in EC
3258*6f1c0430SSimon Glass  * builds >= 8398.0.0 (see crosbug.com/p/23570).
3259*6f1c0430SSimon Glass  *
3260*6f1c0430SSimon Glass  * Use EC_CMD_I2C_PASSTHRU instead.
3261*6f1c0430SSimon Glass  */
326288364387SHung-ying Tyan 
3263*6f1c0430SSimon Glass /* Read I2C bus */
3264*6f1c0430SSimon Glass #define EC_CMD_I2C_READ 0x0094
3265*6f1c0430SSimon Glass 
3266*6f1c0430SSimon Glass struct __ec_align_size1 ec_params_i2c_read {
3267836bb6e8SSimon Glass 	uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
326888364387SHung-ying Tyan 	uint8_t read_size; /* Either 8 or 16. */
326988364387SHung-ying Tyan 	uint8_t port;
327088364387SHung-ying Tyan 	uint8_t offset;
3271*6f1c0430SSimon Glass };
3272*6f1c0430SSimon Glass 
3273*6f1c0430SSimon Glass struct __ec_align2 ec_response_i2c_read {
327488364387SHung-ying Tyan 	uint16_t data;
3275*6f1c0430SSimon Glass };
327688364387SHung-ying Tyan 
327788364387SHung-ying Tyan /* Write I2C bus */
3278*6f1c0430SSimon Glass #define EC_CMD_I2C_WRITE 0x0095
327988364387SHung-ying Tyan 
3280*6f1c0430SSimon Glass struct __ec_align_size1 ec_params_i2c_write {
328188364387SHung-ying Tyan 	uint16_t data;
3282836bb6e8SSimon Glass 	uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
328388364387SHung-ying Tyan 	uint8_t write_size; /* Either 8 or 16. */
328488364387SHung-ying Tyan 	uint8_t port;
328588364387SHung-ying Tyan 	uint8_t offset;
3286*6f1c0430SSimon Glass };
328788364387SHung-ying Tyan 
328888364387SHung-ying Tyan /*****************************************************************************/
328988364387SHung-ying Tyan /* Charge state commands. Only available when flash write protect unlocked. */
329088364387SHung-ying Tyan 
3291*6f1c0430SSimon Glass /* Force charge state machine to stop charging the battery or force it to
3292*6f1c0430SSimon Glass  * discharge the battery.
3293*6f1c0430SSimon Glass  */
3294*6f1c0430SSimon Glass #define EC_CMD_CHARGE_CONTROL 0x0096
3295*6f1c0430SSimon Glass #define EC_VER_CHARGE_CONTROL 1
329688364387SHung-ying Tyan 
3297*6f1c0430SSimon Glass enum ec_charge_control_mode {
3298*6f1c0430SSimon Glass 	CHARGE_CONTROL_NORMAL = 0,
3299*6f1c0430SSimon Glass 	CHARGE_CONTROL_IDLE,
3300*6f1c0430SSimon Glass 	CHARGE_CONTROL_DISCHARGE,
3301*6f1c0430SSimon Glass };
3302*6f1c0430SSimon Glass 
3303*6f1c0430SSimon Glass struct __ec_align4 ec_params_charge_control {
3304*6f1c0430SSimon Glass 	uint32_t mode;  /* enum charge_control_mode */
3305*6f1c0430SSimon Glass };
330688364387SHung-ying Tyan 
330788364387SHung-ying Tyan /*****************************************************************************/
330888364387SHung-ying Tyan /* Console commands. Only available when flash write protect is unlocked. */
330988364387SHung-ying Tyan 
331088364387SHung-ying Tyan /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
3311*6f1c0430SSimon Glass #define EC_CMD_CONSOLE_SNAPSHOT 0x0097
331288364387SHung-ying Tyan 
331388364387SHung-ying Tyan /*
3314*6f1c0430SSimon Glass  * Read data from the saved snapshot. If the subcmd parameter is
3315*6f1c0430SSimon Glass  * CONSOLE_READ_NEXT, this will return data starting from the beginning of
3316*6f1c0430SSimon Glass  * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
3317*6f1c0430SSimon Glass  * end of the previous snapshot.
3318*6f1c0430SSimon Glass  *
3319*6f1c0430SSimon Glass  * The params are only looked at in version >= 1 of this command. Prior
3320*6f1c0430SSimon Glass  * versions will just default to CONSOLE_READ_NEXT behavior.
332188364387SHung-ying Tyan  *
332288364387SHung-ying Tyan  * Response is null-terminated string.  Empty string, if there is no more
332388364387SHung-ying Tyan  * remaining output.
332488364387SHung-ying Tyan  */
3325*6f1c0430SSimon Glass #define EC_CMD_CONSOLE_READ 0x0098
3326*6f1c0430SSimon Glass 
3327*6f1c0430SSimon Glass enum ec_console_read_subcmd {
3328*6f1c0430SSimon Glass 	CONSOLE_READ_NEXT = 0,
3329*6f1c0430SSimon Glass 	CONSOLE_READ_RECENT
3330*6f1c0430SSimon Glass };
3331*6f1c0430SSimon Glass 
3332*6f1c0430SSimon Glass struct __ec_align1 ec_params_console_read_v1 {
3333*6f1c0430SSimon Glass 	uint8_t subcmd; /* enum ec_console_read_subcmd */
3334*6f1c0430SSimon Glass };
333588364387SHung-ying Tyan 
333688364387SHung-ying Tyan /*****************************************************************************/
333788364387SHung-ying Tyan 
333888364387SHung-ying Tyan /*
3339*6f1c0430SSimon Glass  * Cut off battery power immediately or after the host has shut down.
334088364387SHung-ying Tyan  *
3341*6f1c0430SSimon Glass  * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
3342*6f1c0430SSimon Glass  *	  EC_RES_SUCCESS if the command was successful.
3343*6f1c0430SSimon Glass  *	  EC_RES_ERROR if the cut off command failed.
334488364387SHung-ying Tyan  */
3345*6f1c0430SSimon Glass #define EC_CMD_BATTERY_CUT_OFF 0x0099
3346*6f1c0430SSimon Glass 
3347*6f1c0430SSimon Glass #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN	(1 << 0)
3348*6f1c0430SSimon Glass 
3349*6f1c0430SSimon Glass struct __ec_align1 ec_params_battery_cutoff {
3350*6f1c0430SSimon Glass 	uint8_t flags;
3351*6f1c0430SSimon Glass };
335288364387SHung-ying Tyan 
335388364387SHung-ying Tyan /*****************************************************************************/
335488364387SHung-ying Tyan /* USB port mux control. */
335588364387SHung-ying Tyan 
335688364387SHung-ying Tyan /*
335788364387SHung-ying Tyan  * Switch USB mux or return to automatic switching.
335888364387SHung-ying Tyan  */
3359*6f1c0430SSimon Glass #define EC_CMD_USB_MUX 0x009A
336088364387SHung-ying Tyan 
3361*6f1c0430SSimon Glass struct __ec_align1 ec_params_usb_mux {
336288364387SHung-ying Tyan 	uint8_t mux;
3363*6f1c0430SSimon Glass };
336488364387SHung-ying Tyan 
336588364387SHung-ying Tyan /*****************************************************************************/
336688364387SHung-ying Tyan /* LDOs / FETs control. */
336788364387SHung-ying Tyan 
336888364387SHung-ying Tyan enum ec_ldo_state {
336988364387SHung-ying Tyan 	EC_LDO_STATE_OFF = 0,	/* the LDO / FET is shut down */
337088364387SHung-ying Tyan 	EC_LDO_STATE_ON = 1,	/* the LDO / FET is ON / providing power */
337188364387SHung-ying Tyan };
337288364387SHung-ying Tyan 
337388364387SHung-ying Tyan /*
337488364387SHung-ying Tyan  * Switch on/off a LDO.
337588364387SHung-ying Tyan  */
3376*6f1c0430SSimon Glass #define EC_CMD_LDO_SET 0x009B
337788364387SHung-ying Tyan 
3378*6f1c0430SSimon Glass struct __ec_align1 ec_params_ldo_set {
337988364387SHung-ying Tyan 	uint8_t index;
338088364387SHung-ying Tyan 	uint8_t state;
3381*6f1c0430SSimon Glass };
338288364387SHung-ying Tyan 
338388364387SHung-ying Tyan /*
338488364387SHung-ying Tyan  * Get LDO state.
338588364387SHung-ying Tyan  */
3386*6f1c0430SSimon Glass #define EC_CMD_LDO_GET 0x009C
338788364387SHung-ying Tyan 
3388*6f1c0430SSimon Glass struct __ec_align1 ec_params_ldo_get {
338988364387SHung-ying Tyan 	uint8_t index;
3390*6f1c0430SSimon Glass };
339188364387SHung-ying Tyan 
3392*6f1c0430SSimon Glass struct __ec_align1 ec_response_ldo_get {
339388364387SHung-ying Tyan 	uint8_t state;
3394*6f1c0430SSimon Glass };
339588364387SHung-ying Tyan 
339688364387SHung-ying Tyan /*****************************************************************************/
3397836bb6e8SSimon Glass /* Power info. */
3398836bb6e8SSimon Glass 
3399836bb6e8SSimon Glass /*
3400836bb6e8SSimon Glass  * Get power info.
3401836bb6e8SSimon Glass  */
3402*6f1c0430SSimon Glass #define EC_CMD_POWER_INFO 0x009D
3403836bb6e8SSimon Glass 
3404*6f1c0430SSimon Glass struct __ec_align4 ec_response_power_info {
3405836bb6e8SSimon Glass 	uint32_t usb_dev_type;
3406836bb6e8SSimon Glass 	uint16_t voltage_ac;
3407836bb6e8SSimon Glass 	uint16_t voltage_system;
3408836bb6e8SSimon Glass 	uint16_t current_system;
3409836bb6e8SSimon Glass 	uint16_t usb_current_limit;
3410*6f1c0430SSimon Glass };
3411836bb6e8SSimon Glass 
3412836bb6e8SSimon Glass /*****************************************************************************/
3413836bb6e8SSimon Glass /* I2C passthru command */
3414836bb6e8SSimon Glass 
3415*6f1c0430SSimon Glass #define EC_CMD_I2C_PASSTHRU 0x009E
3416836bb6e8SSimon Glass 
3417836bb6e8SSimon Glass /* Read data; if not present, message is a write */
3418836bb6e8SSimon Glass #define EC_I2C_FLAG_READ	(1 << 15)
3419836bb6e8SSimon Glass 
3420836bb6e8SSimon Glass /* Mask for address */
3421836bb6e8SSimon Glass #define EC_I2C_ADDR_MASK	0x3ff
3422836bb6e8SSimon Glass 
3423836bb6e8SSimon Glass #define EC_I2C_STATUS_NAK	(1 << 0) /* Transfer was not acknowledged */
3424836bb6e8SSimon Glass #define EC_I2C_STATUS_TIMEOUT	(1 << 1) /* Timeout during transfer */
3425836bb6e8SSimon Glass 
3426836bb6e8SSimon Glass /* Any error */
3427836bb6e8SSimon Glass #define EC_I2C_STATUS_ERROR	(EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
3428836bb6e8SSimon Glass 
3429*6f1c0430SSimon Glass struct __ec_align2 ec_params_i2c_passthru_msg {
3430836bb6e8SSimon Glass 	uint16_t addr_flags;	/* I2C slave address (7 or 10 bits) and flags */
3431836bb6e8SSimon Glass 	uint16_t len;		/* Number of bytes to read or write */
3432*6f1c0430SSimon Glass };
3433836bb6e8SSimon Glass 
3434*6f1c0430SSimon Glass struct __ec_align2 ec_params_i2c_passthru {
3435836bb6e8SSimon Glass 	uint8_t port;		/* I2C port number */
3436836bb6e8SSimon Glass 	uint8_t num_msgs;	/* Number of messages */
3437836bb6e8SSimon Glass 	struct ec_params_i2c_passthru_msg msg[];
3438836bb6e8SSimon Glass 	/* Data to write for all messages is concatenated here */
3439*6f1c0430SSimon Glass };
3440836bb6e8SSimon Glass 
3441*6f1c0430SSimon Glass struct __ec_align1 ec_response_i2c_passthru {
3442836bb6e8SSimon Glass 	uint8_t i2c_status;	/* Status flags (EC_I2C_STATUS_...) */
3443836bb6e8SSimon Glass 	uint8_t num_msgs;	/* Number of messages processed */
3444836bb6e8SSimon Glass 	uint8_t data[];		/* Data read by messages concatenated here */
3445*6f1c0430SSimon Glass };
3446836bb6e8SSimon Glass 
3447836bb6e8SSimon Glass /*****************************************************************************/
3448*6f1c0430SSimon Glass /* Power button hang detect */
3449*6f1c0430SSimon Glass 
3450*6f1c0430SSimon Glass #define EC_CMD_HANG_DETECT 0x009F
3451*6f1c0430SSimon Glass 
3452*6f1c0430SSimon Glass /* Reasons to start hang detection timer */
3453*6f1c0430SSimon Glass /* Power button pressed */
3454*6f1c0430SSimon Glass #define EC_HANG_START_ON_POWER_PRESS  (1 << 0)
3455*6f1c0430SSimon Glass 
3456*6f1c0430SSimon Glass /* Lid closed */
3457*6f1c0430SSimon Glass #define EC_HANG_START_ON_LID_CLOSE    (1 << 1)
3458*6f1c0430SSimon Glass 
3459*6f1c0430SSimon Glass  /* Lid opened */
3460*6f1c0430SSimon Glass #define EC_HANG_START_ON_LID_OPEN     (1 << 2)
3461*6f1c0430SSimon Glass 
3462*6f1c0430SSimon Glass /* Start of AP S3->S0 transition (booting or resuming from suspend) */
3463*6f1c0430SSimon Glass #define EC_HANG_START_ON_RESUME       (1 << 3)
3464*6f1c0430SSimon Glass 
3465*6f1c0430SSimon Glass /* Reasons to cancel hang detection */
3466*6f1c0430SSimon Glass 
3467*6f1c0430SSimon Glass /* Power button released */
3468*6f1c0430SSimon Glass #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
3469*6f1c0430SSimon Glass 
3470*6f1c0430SSimon Glass /* Any host command from AP received */
3471*6f1c0430SSimon Glass #define EC_HANG_STOP_ON_HOST_COMMAND  (1 << 9)
3472*6f1c0430SSimon Glass 
3473*6f1c0430SSimon Glass /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
3474*6f1c0430SSimon Glass #define EC_HANG_STOP_ON_SUSPEND       (1 << 10)
347588364387SHung-ying Tyan 
347688364387SHung-ying Tyan /*
3477*6f1c0430SSimon Glass  * If this flag is set, all the other fields are ignored, and the hang detect
3478*6f1c0430SSimon Glass  * timer is started.  This provides the AP a way to start the hang timer
3479*6f1c0430SSimon Glass  * without reconfiguring any of the other hang detect settings.  Note that
3480*6f1c0430SSimon Glass  * you must previously have configured the timeouts.
348188364387SHung-ying Tyan  */
3482*6f1c0430SSimon Glass #define EC_HANG_START_NOW             (1 << 30)
3483*6f1c0430SSimon Glass 
3484*6f1c0430SSimon Glass /*
3485*6f1c0430SSimon Glass  * If this flag is set, all the other fields are ignored (including
3486*6f1c0430SSimon Glass  * EC_HANG_START_NOW).  This provides the AP a way to stop the hang timer
3487*6f1c0430SSimon Glass  * without reconfiguring any of the other hang detect settings.
3488*6f1c0430SSimon Glass  */
3489*6f1c0430SSimon Glass #define EC_HANG_STOP_NOW              (1 << 31)
3490*6f1c0430SSimon Glass 
3491*6f1c0430SSimon Glass struct __ec_align4 ec_params_hang_detect {
3492*6f1c0430SSimon Glass 	/* Flags; see EC_HANG_* */
3493*6f1c0430SSimon Glass 	uint32_t flags;
3494*6f1c0430SSimon Glass 
3495*6f1c0430SSimon Glass 	/* Timeout in msec before generating host event, if enabled */
3496*6f1c0430SSimon Glass 	uint16_t host_event_timeout_msec;
3497*6f1c0430SSimon Glass 
3498*6f1c0430SSimon Glass 	/* Timeout in msec before generating warm reboot, if enabled */
3499*6f1c0430SSimon Glass 	uint16_t warm_reboot_timeout_msec;
3500*6f1c0430SSimon Glass };
3501*6f1c0430SSimon Glass 
3502*6f1c0430SSimon Glass /*****************************************************************************/
3503*6f1c0430SSimon Glass /* Commands for battery charging */
3504*6f1c0430SSimon Glass 
3505*6f1c0430SSimon Glass /*
3506*6f1c0430SSimon Glass  * This is the single catch-all host command to exchange data regarding the
3507*6f1c0430SSimon Glass  * charge state machine (v2 and up).
3508*6f1c0430SSimon Glass  */
3509*6f1c0430SSimon Glass #define EC_CMD_CHARGE_STATE 0x00A0
3510*6f1c0430SSimon Glass 
3511*6f1c0430SSimon Glass /* Subcommands for this host command */
3512*6f1c0430SSimon Glass enum charge_state_command {
3513*6f1c0430SSimon Glass 	CHARGE_STATE_CMD_GET_STATE,
3514*6f1c0430SSimon Glass 	CHARGE_STATE_CMD_GET_PARAM,
3515*6f1c0430SSimon Glass 	CHARGE_STATE_CMD_SET_PARAM,
3516*6f1c0430SSimon Glass 	CHARGE_STATE_NUM_CMDS
3517*6f1c0430SSimon Glass };
3518*6f1c0430SSimon Glass 
3519*6f1c0430SSimon Glass /*
3520*6f1c0430SSimon Glass  * Known param numbers are defined here. Ranges are reserved for board-specific
3521*6f1c0430SSimon Glass  * params, which are handled by the particular implementations.
3522*6f1c0430SSimon Glass  */
3523*6f1c0430SSimon Glass enum charge_state_params {
3524*6f1c0430SSimon Glass 	CS_PARAM_CHG_VOLTAGE,	      /* charger voltage limit */
3525*6f1c0430SSimon Glass 	CS_PARAM_CHG_CURRENT,	      /* charger current limit */
3526*6f1c0430SSimon Glass 	CS_PARAM_CHG_INPUT_CURRENT,   /* charger input current limit */
3527*6f1c0430SSimon Glass 	CS_PARAM_CHG_STATUS,	      /* charger-specific status */
3528*6f1c0430SSimon Glass 	CS_PARAM_CHG_OPTION,	      /* charger-specific options */
3529*6f1c0430SSimon Glass 	CS_PARAM_LIMIT_POWER,	      /*
3530*6f1c0430SSimon Glass 				       * Check if power is limited due to
3531*6f1c0430SSimon Glass 				       * low battery and / or a weak external
3532*6f1c0430SSimon Glass 				       * charger. READ ONLY.
3533*6f1c0430SSimon Glass 				       */
3534*6f1c0430SSimon Glass 	/* How many so far? */
3535*6f1c0430SSimon Glass 	CS_NUM_BASE_PARAMS,
3536*6f1c0430SSimon Glass 
3537*6f1c0430SSimon Glass 	/* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
3538*6f1c0430SSimon Glass 	CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
3539*6f1c0430SSimon Glass 	CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
3540*6f1c0430SSimon Glass 
3541*6f1c0430SSimon Glass 	/* Other custom param ranges go here... */
3542*6f1c0430SSimon Glass };
3543*6f1c0430SSimon Glass 
3544*6f1c0430SSimon Glass struct __ec_todo_packed ec_params_charge_state {
3545*6f1c0430SSimon Glass 	uint8_t cmd;				/* enum charge_state_command */
3546*6f1c0430SSimon Glass 	union {
3547*6f1c0430SSimon Glass 		struct __ec_align1 {
3548*6f1c0430SSimon Glass 			/* no args */
3549*6f1c0430SSimon Glass 		} get_state;
3550*6f1c0430SSimon Glass 
3551*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
3552*6f1c0430SSimon Glass 			uint32_t param;		/* enum charge_state_param */
3553*6f1c0430SSimon Glass 		} get_param;
3554*6f1c0430SSimon Glass 
3555*6f1c0430SSimon Glass 		struct __ec_todo_unpacked {
3556*6f1c0430SSimon Glass 			uint32_t param;		/* param to set */
3557*6f1c0430SSimon Glass 			uint32_t value;		/* value to set */
3558*6f1c0430SSimon Glass 		} set_param;
3559*6f1c0430SSimon Glass 	};
3560*6f1c0430SSimon Glass };
3561*6f1c0430SSimon Glass 
3562*6f1c0430SSimon Glass struct __ec_align4 ec_response_charge_state {
3563*6f1c0430SSimon Glass 	union {
3564*6f1c0430SSimon Glass 		struct __ec_align4 {
3565*6f1c0430SSimon Glass 			int ac;
3566*6f1c0430SSimon Glass 			int chg_voltage;
3567*6f1c0430SSimon Glass 			int chg_current;
3568*6f1c0430SSimon Glass 			int chg_input_current;
3569*6f1c0430SSimon Glass 			int batt_state_of_charge;
3570*6f1c0430SSimon Glass 		} get_state;
3571*6f1c0430SSimon Glass 
3572*6f1c0430SSimon Glass 		struct __ec_align4 {
3573*6f1c0430SSimon Glass 			uint32_t value;
3574*6f1c0430SSimon Glass 		} get_param;
3575*6f1c0430SSimon Glass 		struct __ec_align4 {
3576*6f1c0430SSimon Glass 			/* no return values */
3577*6f1c0430SSimon Glass 		} set_param;
3578*6f1c0430SSimon Glass 	};
3579*6f1c0430SSimon Glass };
3580*6f1c0430SSimon Glass 
358188364387SHung-ying Tyan 
358288364387SHung-ying Tyan /*
358388364387SHung-ying Tyan  * Set maximum battery charging current.
358488364387SHung-ying Tyan  */
3585*6f1c0430SSimon Glass #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
358688364387SHung-ying Tyan 
3587*6f1c0430SSimon Glass struct __ec_align4 ec_params_current_limit {
3588836bb6e8SSimon Glass 	uint32_t limit; /* in mA */
3589*6f1c0430SSimon Glass };
3590836bb6e8SSimon Glass 
3591836bb6e8SSimon Glass /*
3592*6f1c0430SSimon Glass  * Set maximum external voltage / current.
3593836bb6e8SSimon Glass  */
3594*6f1c0430SSimon Glass #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
3595836bb6e8SSimon Glass 
3596*6f1c0430SSimon Glass /* Command v0 is used only on Spring and is obsolete + unsupported */
3597*6f1c0430SSimon Glass struct __ec_align2 ec_params_external_power_limit_v1 {
3598*6f1c0430SSimon Glass 	uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
3599*6f1c0430SSimon Glass 	uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
3600*6f1c0430SSimon Glass };
3601*6f1c0430SSimon Glass 
3602*6f1c0430SSimon Glass #define EC_POWER_LIMIT_NONE 0xffff
3603*6f1c0430SSimon Glass 
3604*6f1c0430SSimon Glass /*
3605*6f1c0430SSimon Glass  * Set maximum voltage & current of a dedicated charge port
3606*6f1c0430SSimon Glass  */
3607*6f1c0430SSimon Glass #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
3608*6f1c0430SSimon Glass 
3609*6f1c0430SSimon Glass struct __ec_align2 ec_params_dedicated_charger_limit {
3610*6f1c0430SSimon Glass 	uint16_t current_lim; /* in mA */
3611*6f1c0430SSimon Glass 	uint16_t voltage_lim; /* in mV */
3612*6f1c0430SSimon Glass };
3613*6f1c0430SSimon Glass 
3614*6f1c0430SSimon Glass /*****************************************************************************/
3615*6f1c0430SSimon Glass /* Hibernate/Deep Sleep Commands */
3616*6f1c0430SSimon Glass 
3617*6f1c0430SSimon Glass /* Set the delay before going into hibernation. */
3618*6f1c0430SSimon Glass #define EC_CMD_HIBERNATION_DELAY 0x00A8
3619*6f1c0430SSimon Glass 
3620*6f1c0430SSimon Glass struct __ec_align4 ec_params_hibernation_delay {
3621*6f1c0430SSimon Glass 	/*
3622*6f1c0430SSimon Glass 	 * Seconds to wait in G3 before hibernate.  Pass in 0 to read the
3623*6f1c0430SSimon Glass 	 * current settings without changing them.
3624*6f1c0430SSimon Glass 	 */
3625*6f1c0430SSimon Glass 	uint32_t seconds;
3626*6f1c0430SSimon Glass };
3627*6f1c0430SSimon Glass 
3628*6f1c0430SSimon Glass struct __ec_align4 ec_response_hibernation_delay {
3629*6f1c0430SSimon Glass 	/*
3630*6f1c0430SSimon Glass 	 * The current time in seconds in which the system has been in the G3
3631*6f1c0430SSimon Glass 	 * state.  This value is reset if the EC transitions out of G3.
3632*6f1c0430SSimon Glass 	 */
3633*6f1c0430SSimon Glass 	uint32_t time_g3;
3634*6f1c0430SSimon Glass 
3635*6f1c0430SSimon Glass 	/*
3636*6f1c0430SSimon Glass 	 * The current time remaining in seconds until the EC should hibernate.
3637*6f1c0430SSimon Glass 	 * This value is also reset if the EC transitions out of G3.
3638*6f1c0430SSimon Glass 	 */
3639*6f1c0430SSimon Glass 	uint32_t time_remaining;
3640*6f1c0430SSimon Glass 
3641*6f1c0430SSimon Glass 	/*
3642*6f1c0430SSimon Glass 	 * The current time in seconds that the EC should wait in G3 before
3643*6f1c0430SSimon Glass 	 * hibernating.
3644*6f1c0430SSimon Glass 	 */
3645*6f1c0430SSimon Glass 	uint32_t hibernate_delay;
3646*6f1c0430SSimon Glass };
3647*6f1c0430SSimon Glass 
3648*6f1c0430SSimon Glass /* Inform the EC when entering a sleep state */
3649*6f1c0430SSimon Glass #define EC_CMD_HOST_SLEEP_EVENT 0x00A9
3650*6f1c0430SSimon Glass 
3651*6f1c0430SSimon Glass enum host_sleep_event {
3652*6f1c0430SSimon Glass 	HOST_SLEEP_EVENT_S3_SUSPEND   = 1,
3653*6f1c0430SSimon Glass 	HOST_SLEEP_EVENT_S3_RESUME    = 2,
3654*6f1c0430SSimon Glass 	HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
3655*6f1c0430SSimon Glass 	HOST_SLEEP_EVENT_S0IX_RESUME  = 4
3656*6f1c0430SSimon Glass };
3657*6f1c0430SSimon Glass 
3658*6f1c0430SSimon Glass struct __ec_align1 ec_params_host_sleep_event {
3659*6f1c0430SSimon Glass 	uint8_t sleep_event;
3660*6f1c0430SSimon Glass };
3661*6f1c0430SSimon Glass 
3662*6f1c0430SSimon Glass /*****************************************************************************/
3663*6f1c0430SSimon Glass /* Device events */
3664*6f1c0430SSimon Glass #define EC_CMD_DEVICE_EVENT 0x00AA
3665*6f1c0430SSimon Glass 
3666*6f1c0430SSimon Glass enum ec_device_event {
3667*6f1c0430SSimon Glass 	EC_DEVICE_EVENT_TRACKPAD,
3668*6f1c0430SSimon Glass 	EC_DEVICE_EVENT_DSP,
3669*6f1c0430SSimon Glass 	EC_DEVICE_EVENT_WIFI,
3670*6f1c0430SSimon Glass };
3671*6f1c0430SSimon Glass 
3672*6f1c0430SSimon Glass enum ec_device_event_param {
3673*6f1c0430SSimon Glass 	/* Get and clear pending device events */
3674*6f1c0430SSimon Glass 	EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
3675*6f1c0430SSimon Glass 	/* Get device event mask */
3676*6f1c0430SSimon Glass 	EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
3677*6f1c0430SSimon Glass 	/* Set device event mask */
3678*6f1c0430SSimon Glass 	EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
3679*6f1c0430SSimon Glass };
3680*6f1c0430SSimon Glass 
3681*6f1c0430SSimon Glass #define EC_DEVICE_EVENT_MASK(event_code) (1UL << (event_code % 32))
3682*6f1c0430SSimon Glass 
3683*6f1c0430SSimon Glass struct __ec_align_size1 ec_params_device_event {
3684*6f1c0430SSimon Glass 	uint32_t event_mask;
3685*6f1c0430SSimon Glass 	uint8_t param;
3686*6f1c0430SSimon Glass };
3687*6f1c0430SSimon Glass 
3688*6f1c0430SSimon Glass struct __ec_align4 ec_response_device_event {
3689*6f1c0430SSimon Glass 	uint32_t event_mask;
3690*6f1c0430SSimon Glass };
369188364387SHung-ying Tyan 
369288364387SHung-ying Tyan /*****************************************************************************/
369388364387SHung-ying Tyan /* Smart battery pass-through */
369488364387SHung-ying Tyan 
369588364387SHung-ying Tyan /* Get / Set 16-bit smart battery registers */
3696*6f1c0430SSimon Glass #define EC_CMD_SB_READ_WORD   0x00B0
3697*6f1c0430SSimon Glass #define EC_CMD_SB_WRITE_WORD  0x00B1
369888364387SHung-ying Tyan 
369988364387SHung-ying Tyan /* Get / Set string smart battery parameters
370088364387SHung-ying Tyan  * formatted as SMBUS "block".
370188364387SHung-ying Tyan  */
3702*6f1c0430SSimon Glass #define EC_CMD_SB_READ_BLOCK  0x00B2
3703*6f1c0430SSimon Glass #define EC_CMD_SB_WRITE_BLOCK 0x00B3
370488364387SHung-ying Tyan 
3705*6f1c0430SSimon Glass struct __ec_align1 ec_params_sb_rd {
370688364387SHung-ying Tyan 	uint8_t reg;
3707*6f1c0430SSimon Glass };
370888364387SHung-ying Tyan 
3709*6f1c0430SSimon Glass struct __ec_align2 ec_response_sb_rd_word {
371088364387SHung-ying Tyan 	uint16_t value;
3711*6f1c0430SSimon Glass };
371288364387SHung-ying Tyan 
3713*6f1c0430SSimon Glass struct __ec_align1 ec_params_sb_wr_word {
371488364387SHung-ying Tyan 	uint8_t reg;
371588364387SHung-ying Tyan 	uint16_t value;
3716*6f1c0430SSimon Glass };
371788364387SHung-ying Tyan 
3718*6f1c0430SSimon Glass struct __ec_align1 ec_response_sb_rd_block {
371988364387SHung-ying Tyan 	uint8_t data[32];
3720*6f1c0430SSimon Glass };
372188364387SHung-ying Tyan 
3722*6f1c0430SSimon Glass struct __ec_align1 ec_params_sb_wr_block {
372388364387SHung-ying Tyan 	uint8_t reg;
372488364387SHung-ying Tyan 	uint16_t data[32];
3725*6f1c0430SSimon Glass };
3726*6f1c0430SSimon Glass 
3727*6f1c0430SSimon Glass /*****************************************************************************/
3728*6f1c0430SSimon Glass /* Battery vendor parameters
3729*6f1c0430SSimon Glass  *
3730*6f1c0430SSimon Glass  * Get or set vendor-specific parameters in the battery. Implementations may
3731*6f1c0430SSimon Glass  * differ between boards or batteries. On a set operation, the response
3732*6f1c0430SSimon Glass  * contains the actual value set, which may be rounded or clipped from the
3733*6f1c0430SSimon Glass  * requested value.
3734*6f1c0430SSimon Glass  */
3735*6f1c0430SSimon Glass 
3736*6f1c0430SSimon Glass #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
3737*6f1c0430SSimon Glass 
3738*6f1c0430SSimon Glass enum ec_battery_vendor_param_mode {
3739*6f1c0430SSimon Glass 	BATTERY_VENDOR_PARAM_MODE_GET = 0,
3740*6f1c0430SSimon Glass 	BATTERY_VENDOR_PARAM_MODE_SET,
3741*6f1c0430SSimon Glass };
3742*6f1c0430SSimon Glass 
3743*6f1c0430SSimon Glass struct __ec_align_size1 ec_params_battery_vendor_param {
3744*6f1c0430SSimon Glass 	uint32_t param;
3745*6f1c0430SSimon Glass 	uint32_t value;
3746*6f1c0430SSimon Glass 	uint8_t mode;
3747*6f1c0430SSimon Glass };
3748*6f1c0430SSimon Glass 
3749*6f1c0430SSimon Glass struct __ec_align4 ec_response_battery_vendor_param {
3750*6f1c0430SSimon Glass 	uint32_t value;
3751*6f1c0430SSimon Glass };
3752*6f1c0430SSimon Glass 
3753*6f1c0430SSimon Glass /*****************************************************************************/
3754*6f1c0430SSimon Glass /*
3755*6f1c0430SSimon Glass  * Smart Battery Firmware Update Commands
3756*6f1c0430SSimon Glass  */
3757*6f1c0430SSimon Glass #define EC_CMD_SB_FW_UPDATE 0x00B5
3758*6f1c0430SSimon Glass 
3759*6f1c0430SSimon Glass enum ec_sb_fw_update_subcmd {
3760*6f1c0430SSimon Glass 	EC_SB_FW_UPDATE_PREPARE  = 0x0,
3761*6f1c0430SSimon Glass 	EC_SB_FW_UPDATE_INFO     = 0x1, /*query sb info */
3762*6f1c0430SSimon Glass 	EC_SB_FW_UPDATE_BEGIN    = 0x2, /*check if protected */
3763*6f1c0430SSimon Glass 	EC_SB_FW_UPDATE_WRITE    = 0x3, /*check if protected */
3764*6f1c0430SSimon Glass 	EC_SB_FW_UPDATE_END      = 0x4,
3765*6f1c0430SSimon Glass 	EC_SB_FW_UPDATE_STATUS   = 0x5,
3766*6f1c0430SSimon Glass 	EC_SB_FW_UPDATE_PROTECT  = 0x6,
3767*6f1c0430SSimon Glass 	EC_SB_FW_UPDATE_MAX      = 0x7,
3768*6f1c0430SSimon Glass };
3769*6f1c0430SSimon Glass 
3770*6f1c0430SSimon Glass #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
3771*6f1c0430SSimon Glass #define SB_FW_UPDATE_CMD_STATUS_SIZE 2
3772*6f1c0430SSimon Glass #define SB_FW_UPDATE_CMD_INFO_SIZE 8
3773*6f1c0430SSimon Glass 
3774*6f1c0430SSimon Glass struct __ec_align4 ec_sb_fw_update_header {
3775*6f1c0430SSimon Glass 	uint16_t subcmd;  /* enum ec_sb_fw_update_subcmd */
3776*6f1c0430SSimon Glass 	uint16_t fw_id;   /* firmware id */
3777*6f1c0430SSimon Glass };
3778*6f1c0430SSimon Glass 
3779*6f1c0430SSimon Glass struct __ec_align4 ec_params_sb_fw_update {
3780*6f1c0430SSimon Glass 	struct ec_sb_fw_update_header hdr;
3781*6f1c0430SSimon Glass 	union {
3782*6f1c0430SSimon Glass 		/* EC_SB_FW_UPDATE_PREPARE  = 0x0 */
3783*6f1c0430SSimon Glass 		/* EC_SB_FW_UPDATE_INFO     = 0x1 */
3784*6f1c0430SSimon Glass 		/* EC_SB_FW_UPDATE_BEGIN    = 0x2 */
3785*6f1c0430SSimon Glass 		/* EC_SB_FW_UPDATE_END      = 0x4 */
3786*6f1c0430SSimon Glass 		/* EC_SB_FW_UPDATE_STATUS   = 0x5 */
3787*6f1c0430SSimon Glass 		/* EC_SB_FW_UPDATE_PROTECT  = 0x6 */
3788*6f1c0430SSimon Glass 		struct __ec_align4 {
3789*6f1c0430SSimon Glass 			/* no args */
3790*6f1c0430SSimon Glass 		} dummy;
3791*6f1c0430SSimon Glass 
3792*6f1c0430SSimon Glass 		/* EC_SB_FW_UPDATE_WRITE    = 0x3 */
3793*6f1c0430SSimon Glass 		struct __ec_align4 {
3794*6f1c0430SSimon Glass 			uint8_t  data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
3795*6f1c0430SSimon Glass 		} write;
3796*6f1c0430SSimon Glass 	};
3797*6f1c0430SSimon Glass };
3798*6f1c0430SSimon Glass 
3799*6f1c0430SSimon Glass struct __ec_align1 ec_response_sb_fw_update {
3800*6f1c0430SSimon Glass 	union {
3801*6f1c0430SSimon Glass 		/* EC_SB_FW_UPDATE_INFO     = 0x1 */
3802*6f1c0430SSimon Glass 		struct __ec_align1 {
3803*6f1c0430SSimon Glass 			uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
3804*6f1c0430SSimon Glass 		} info;
3805*6f1c0430SSimon Glass 
3806*6f1c0430SSimon Glass 		/* EC_SB_FW_UPDATE_STATUS   = 0x5 */
3807*6f1c0430SSimon Glass 		struct __ec_align1 {
3808*6f1c0430SSimon Glass 			uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
3809*6f1c0430SSimon Glass 		} status;
3810*6f1c0430SSimon Glass 	};
3811*6f1c0430SSimon Glass };
381288364387SHung-ying Tyan 
3813b5279249SSimon Glass /*
3814b5279249SSimon Glass  * Entering Verified Boot Mode Command
3815b5279249SSimon Glass  * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
3816b5279249SSimon Glass  * Valid Modes are: normal, developer, and recovery.
3817b5279249SSimon Glass  */
3818*6f1c0430SSimon Glass #define EC_CMD_ENTERING_MODE 0x00B6
3819b5279249SSimon Glass 
3820*6f1c0430SSimon Glass struct __ec_align4 ec_params_entering_mode {
3821b5279249SSimon Glass 	int vboot_mode;
3822*6f1c0430SSimon Glass };
3823b5279249SSimon Glass 
3824b5279249SSimon Glass #define VBOOT_MODE_NORMAL    0
3825b5279249SSimon Glass #define VBOOT_MODE_DEVELOPER 1
3826b5279249SSimon Glass #define VBOOT_MODE_RECOVERY  2
3827b5279249SSimon Glass 
382888364387SHung-ying Tyan /*****************************************************************************/
3829*6f1c0430SSimon Glass /*
3830*6f1c0430SSimon Glass  * I2C passthru protection command: Protects I2C tunnels against access on
3831*6f1c0430SSimon Glass  * certain addresses (board-specific).
3832*6f1c0430SSimon Glass  */
3833*6f1c0430SSimon Glass #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
3834*6f1c0430SSimon Glass 
3835*6f1c0430SSimon Glass enum ec_i2c_passthru_protect_subcmd {
3836*6f1c0430SSimon Glass 	EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
3837*6f1c0430SSimon Glass 	EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
3838*6f1c0430SSimon Glass };
3839*6f1c0430SSimon Glass 
3840*6f1c0430SSimon Glass struct __ec_align1 ec_params_i2c_passthru_protect {
3841*6f1c0430SSimon Glass 	uint8_t subcmd;
3842*6f1c0430SSimon Glass 	uint8_t port;		/* I2C port number */
3843*6f1c0430SSimon Glass };
3844*6f1c0430SSimon Glass 
3845*6f1c0430SSimon Glass struct __ec_align1 ec_response_i2c_passthru_protect {
3846*6f1c0430SSimon Glass 	uint8_t status;		/* Status flags (0: unlocked, 1: locked) */
3847*6f1c0430SSimon Glass };
3848*6f1c0430SSimon Glass 
3849*6f1c0430SSimon Glass /*****************************************************************************/
385088364387SHung-ying Tyan /* System commands */
385188364387SHung-ying Tyan 
385288364387SHung-ying Tyan /*
3853*6f1c0430SSimon Glass  * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
3854*6f1c0430SSimon Glass  * necessarily reboot the EC.  Rename to "image" or something similar?
385588364387SHung-ying Tyan  */
3856*6f1c0430SSimon Glass #define EC_CMD_REBOOT_EC 0x00D2
385788364387SHung-ying Tyan 
385888364387SHung-ying Tyan /* Command */
385988364387SHung-ying Tyan enum ec_reboot_cmd {
386088364387SHung-ying Tyan 	EC_REBOOT_CANCEL = 0,        /* Cancel a pending reboot */
386188364387SHung-ying Tyan 	EC_REBOOT_JUMP_RO = 1,       /* Jump to RO without rebooting */
386288364387SHung-ying Tyan 	EC_REBOOT_JUMP_RW = 2,       /* Jump to RW without rebooting */
386388364387SHung-ying Tyan 	/* (command 3 was jump to RW-B) */
386488364387SHung-ying Tyan 	EC_REBOOT_COLD = 4,          /* Cold-reboot */
386588364387SHung-ying Tyan 	EC_REBOOT_DISABLE_JUMP = 5,  /* Disable jump until next reboot */
3866*6f1c0430SSimon Glass 	EC_REBOOT_HIBERNATE = 6,     /* Hibernate EC */
3867*6f1c0430SSimon Glass 	EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
386888364387SHung-ying Tyan };
386988364387SHung-ying Tyan 
387088364387SHung-ying Tyan /* Flags for ec_params_reboot_ec.reboot_flags */
387188364387SHung-ying Tyan #define EC_REBOOT_FLAG_RESERVED0      (1 << 0)  /* Was recovery request */
387288364387SHung-ying Tyan #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1)  /* Reboot after AP shutdown */
3873*6f1c0430SSimon Glass #define EC_REBOOT_FLAG_SWITCH_RW_SLOT (1 << 2)  /* Switch RW slot */
387488364387SHung-ying Tyan 
3875*6f1c0430SSimon Glass struct __ec_align1 ec_params_reboot_ec {
387688364387SHung-ying Tyan 	uint8_t cmd;           /* enum ec_reboot_cmd */
387788364387SHung-ying Tyan 	uint8_t flags;         /* See EC_REBOOT_FLAG_* */
3878*6f1c0430SSimon Glass };
387988364387SHung-ying Tyan 
388088364387SHung-ying Tyan /*
388188364387SHung-ying Tyan  * Get information on last EC panic.
388288364387SHung-ying Tyan  *
388388364387SHung-ying Tyan  * Returns variable-length platform-dependent panic information.  See panic.h
388488364387SHung-ying Tyan  * for details.
388588364387SHung-ying Tyan  */
3886*6f1c0430SSimon Glass #define EC_CMD_GET_PANIC_INFO 0x00D3
388788364387SHung-ying Tyan 
388888364387SHung-ying Tyan /*****************************************************************************/
388988364387SHung-ying Tyan /*
389088364387SHung-ying Tyan  * Special commands
389188364387SHung-ying Tyan  *
389288364387SHung-ying Tyan  * These do not follow the normal rules for commands.  See each command for
389388364387SHung-ying Tyan  * details.
389488364387SHung-ying Tyan  */
389588364387SHung-ying Tyan 
389688364387SHung-ying Tyan /*
389788364387SHung-ying Tyan  * Reboot NOW
389888364387SHung-ying Tyan  *
389988364387SHung-ying Tyan  * This command will work even when the EC LPC interface is busy, because the
390088364387SHung-ying Tyan  * reboot command is processed at interrupt level.  Note that when the EC
390188364387SHung-ying Tyan  * reboots, the host will reboot too, so there is no response to this command.
390288364387SHung-ying Tyan  *
390388364387SHung-ying Tyan  * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
390488364387SHung-ying Tyan  */
3905*6f1c0430SSimon Glass #define EC_CMD_REBOOT 0x00D1  /* Think "die" */
390688364387SHung-ying Tyan 
390788364387SHung-ying Tyan /*
390888364387SHung-ying Tyan  * Resend last response (not supported on LPC).
390988364387SHung-ying Tyan  *
391088364387SHung-ying Tyan  * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
391188364387SHung-ying Tyan  * there was no previous command, or the previous command's response was too
391288364387SHung-ying Tyan  * big to save.
391388364387SHung-ying Tyan  */
3914*6f1c0430SSimon Glass #define EC_CMD_RESEND_RESPONSE 0x00DB
391588364387SHung-ying Tyan 
391688364387SHung-ying Tyan /*
391788364387SHung-ying Tyan  * This header byte on a command indicate version 0. Any header byte less
391888364387SHung-ying Tyan  * than this means that we are talking to an old EC which doesn't support
391988364387SHung-ying Tyan  * versioning. In that case, we assume version 0.
392088364387SHung-ying Tyan  *
392188364387SHung-ying Tyan  * Header bytes greater than this indicate a later version. For example,
392288364387SHung-ying Tyan  * EC_CMD_VERSION0 + 1 means we are using version 1.
392388364387SHung-ying Tyan  *
3924*6f1c0430SSimon Glass  * The old EC interface must not use commands 0xdc or higher.
392588364387SHung-ying Tyan  */
3926*6f1c0430SSimon Glass #define EC_CMD_VERSION0 0x00DC
392788364387SHung-ying Tyan 
3928*6f1c0430SSimon Glass /*****************************************************************************/
3929*6f1c0430SSimon Glass /*
3930*6f1c0430SSimon Glass  * PD commands
3931*6f1c0430SSimon Glass  *
3932*6f1c0430SSimon Glass  * These commands are for PD MCU communication.
3933*6f1c0430SSimon Glass  */
3934*6f1c0430SSimon Glass 
3935*6f1c0430SSimon Glass /* EC to PD MCU exchange status command */
3936*6f1c0430SSimon Glass #define EC_CMD_PD_EXCHANGE_STATUS 0x0100
3937*6f1c0430SSimon Glass #define EC_VER_PD_EXCHANGE_STATUS 2
3938*6f1c0430SSimon Glass 
3939*6f1c0430SSimon Glass enum pd_charge_state {
3940*6f1c0430SSimon Glass 	PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
3941*6f1c0430SSimon Glass 	PD_CHARGE_NONE,          /* No charging allowed */
3942*6f1c0430SSimon Glass 	PD_CHARGE_5V,            /* 5V charging only */
3943*6f1c0430SSimon Glass 	PD_CHARGE_MAX            /* Charge at max voltage */
3944*6f1c0430SSimon Glass };
3945*6f1c0430SSimon Glass 
3946*6f1c0430SSimon Glass /* Status of EC being sent to PD */
3947*6f1c0430SSimon Glass #define EC_STATUS_HIBERNATING	(1 << 0)
3948*6f1c0430SSimon Glass 
3949*6f1c0430SSimon Glass struct __ec_align1 ec_params_pd_status {
3950*6f1c0430SSimon Glass 	uint8_t status;       /* EC status */
3951*6f1c0430SSimon Glass 	int8_t batt_soc;      /* battery state of charge */
3952*6f1c0430SSimon Glass 	uint8_t charge_state; /* charging state (from enum pd_charge_state) */
3953*6f1c0430SSimon Glass };
3954*6f1c0430SSimon Glass 
3955*6f1c0430SSimon Glass /* Status of PD being sent back to EC */
3956*6f1c0430SSimon Glass #define PD_STATUS_HOST_EVENT      (1 << 0) /* Forward host event to AP */
3957*6f1c0430SSimon Glass #define PD_STATUS_IN_RW           (1 << 1) /* Running RW image */
3958*6f1c0430SSimon Glass #define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
3959*6f1c0430SSimon Glass #define PD_STATUS_TCPC_ALERT_0    (1 << 3) /* Alert active in port 0 TCPC */
3960*6f1c0430SSimon Glass #define PD_STATUS_TCPC_ALERT_1    (1 << 4) /* Alert active in port 1 TCPC */
3961*6f1c0430SSimon Glass #define PD_STATUS_TCPC_ALERT_2    (1 << 5) /* Alert active in port 2 TCPC */
3962*6f1c0430SSimon Glass #define PD_STATUS_TCPC_ALERT_3    (1 << 6) /* Alert active in port 3 TCPC */
3963*6f1c0430SSimon Glass #define PD_STATUS_EC_INT_ACTIVE  (PD_STATUS_TCPC_ALERT_0 | \
3964*6f1c0430SSimon Glass 				      PD_STATUS_TCPC_ALERT_1 | \
3965*6f1c0430SSimon Glass 				      PD_STATUS_HOST_EVENT)
3966*6f1c0430SSimon Glass struct __ec_align_size1 ec_response_pd_status {
3967*6f1c0430SSimon Glass 	uint32_t curr_lim_ma;       /* input current limit */
3968*6f1c0430SSimon Glass 	uint16_t status;            /* PD MCU status */
3969*6f1c0430SSimon Glass 	int8_t active_charge_port;  /* active charging port */
3970*6f1c0430SSimon Glass };
3971*6f1c0430SSimon Glass 
3972*6f1c0430SSimon Glass /* AP to PD MCU host event status command, cleared on read */
3973*6f1c0430SSimon Glass #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
3974*6f1c0430SSimon Glass 
3975*6f1c0430SSimon Glass /* PD MCU host event status bits */
3976*6f1c0430SSimon Glass #define PD_EVENT_UPDATE_DEVICE     (1 << 0)
3977*6f1c0430SSimon Glass #define PD_EVENT_POWER_CHANGE      (1 << 1)
3978*6f1c0430SSimon Glass #define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
3979*6f1c0430SSimon Glass #define PD_EVENT_DATA_SWAP         (1 << 3)
3980*6f1c0430SSimon Glass struct __ec_align4 ec_response_host_event_status {
3981*6f1c0430SSimon Glass 	uint32_t status;      /* PD MCU host event status */
3982*6f1c0430SSimon Glass };
3983*6f1c0430SSimon Glass 
3984*6f1c0430SSimon Glass /* Set USB type-C port role and muxes */
3985*6f1c0430SSimon Glass #define EC_CMD_USB_PD_CONTROL 0x0101
3986*6f1c0430SSimon Glass 
3987*6f1c0430SSimon Glass enum usb_pd_control_role {
3988*6f1c0430SSimon Glass 	USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3989*6f1c0430SSimon Glass 	USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3990*6f1c0430SSimon Glass 	USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3991*6f1c0430SSimon Glass 	USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3992*6f1c0430SSimon Glass 	USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
3993*6f1c0430SSimon Glass 	USB_PD_CTRL_ROLE_COUNT
3994*6f1c0430SSimon Glass };
3995*6f1c0430SSimon Glass 
3996*6f1c0430SSimon Glass enum usb_pd_control_mux {
3997*6f1c0430SSimon Glass 	USB_PD_CTRL_MUX_NO_CHANGE = 0,
3998*6f1c0430SSimon Glass 	USB_PD_CTRL_MUX_NONE = 1,
3999*6f1c0430SSimon Glass 	USB_PD_CTRL_MUX_USB = 2,
4000*6f1c0430SSimon Glass 	USB_PD_CTRL_MUX_DP = 3,
4001*6f1c0430SSimon Glass 	USB_PD_CTRL_MUX_DOCK = 4,
4002*6f1c0430SSimon Glass 	USB_PD_CTRL_MUX_AUTO = 5,
4003*6f1c0430SSimon Glass 	USB_PD_CTRL_MUX_COUNT
4004*6f1c0430SSimon Glass };
4005*6f1c0430SSimon Glass 
4006*6f1c0430SSimon Glass enum usb_pd_control_swap {
4007*6f1c0430SSimon Glass 	USB_PD_CTRL_SWAP_NONE = 0,
4008*6f1c0430SSimon Glass 	USB_PD_CTRL_SWAP_DATA = 1,
4009*6f1c0430SSimon Glass 	USB_PD_CTRL_SWAP_POWER = 2,
4010*6f1c0430SSimon Glass 	USB_PD_CTRL_SWAP_VCONN = 3,
4011*6f1c0430SSimon Glass 	USB_PD_CTRL_SWAP_COUNT
4012*6f1c0430SSimon Glass };
4013*6f1c0430SSimon Glass 
4014*6f1c0430SSimon Glass struct __ec_align1 ec_params_usb_pd_control {
4015*6f1c0430SSimon Glass 	uint8_t port;
4016*6f1c0430SSimon Glass 	uint8_t role;
4017*6f1c0430SSimon Glass 	uint8_t mux;
4018*6f1c0430SSimon Glass 	uint8_t swap;
4019*6f1c0430SSimon Glass };
4020*6f1c0430SSimon Glass 
4021*6f1c0430SSimon Glass #define PD_CTRL_RESP_ENABLED_COMMS      (1 << 0) /* Communication enabled */
4022*6f1c0430SSimon Glass #define PD_CTRL_RESP_ENABLED_CONNECTED  (1 << 1) /* Device connected */
4023*6f1c0430SSimon Glass #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
4024*6f1c0430SSimon Glass 
4025*6f1c0430SSimon Glass #define PD_CTRL_RESP_ROLE_POWER         (1 << 0) /* 0=SNK/1=SRC */
4026*6f1c0430SSimon Glass #define PD_CTRL_RESP_ROLE_DATA          (1 << 1) /* 0=UFP/1=DFP */
4027*6f1c0430SSimon Glass #define PD_CTRL_RESP_ROLE_VCONN         (1 << 2) /* Vconn status */
4028*6f1c0430SSimon Glass #define PD_CTRL_RESP_ROLE_DR_POWER      (1 << 3) /* Partner is dualrole power */
4029*6f1c0430SSimon Glass #define PD_CTRL_RESP_ROLE_DR_DATA       (1 << 4) /* Partner is dualrole data */
4030*6f1c0430SSimon Glass #define PD_CTRL_RESP_ROLE_USB_COMM      (1 << 5) /* Partner USB comm capable */
4031*6f1c0430SSimon Glass #define PD_CTRL_RESP_ROLE_EXT_POWERED   (1 << 6) /* Partner externally powerd */
4032*6f1c0430SSimon Glass 
4033*6f1c0430SSimon Glass struct __ec_align1 ec_response_usb_pd_control {
4034*6f1c0430SSimon Glass 	uint8_t enabled;
4035*6f1c0430SSimon Glass 	uint8_t role;
4036*6f1c0430SSimon Glass 	uint8_t polarity;
4037*6f1c0430SSimon Glass 	uint8_t state;
4038*6f1c0430SSimon Glass };
4039*6f1c0430SSimon Glass 
4040*6f1c0430SSimon Glass struct __ec_align1 ec_response_usb_pd_control_v1 {
4041*6f1c0430SSimon Glass 	uint8_t enabled;
4042*6f1c0430SSimon Glass 	uint8_t role;
4043*6f1c0430SSimon Glass 	uint8_t polarity;
4044*6f1c0430SSimon Glass 	char state[32];
4045*6f1c0430SSimon Glass };
4046*6f1c0430SSimon Glass 
4047*6f1c0430SSimon Glass #define EC_CMD_USB_PD_PORTS 0x0102
4048*6f1c0430SSimon Glass 
4049*6f1c0430SSimon Glass /* Maximum number of PD ports on a device, num_ports will be <= this */
4050*6f1c0430SSimon Glass #define EC_USB_PD_MAX_PORTS 8
4051*6f1c0430SSimon Glass 
4052*6f1c0430SSimon Glass struct __ec_align1 ec_response_usb_pd_ports {
4053*6f1c0430SSimon Glass 	uint8_t num_ports;
4054*6f1c0430SSimon Glass };
4055*6f1c0430SSimon Glass 
4056*6f1c0430SSimon Glass #define EC_CMD_USB_PD_POWER_INFO 0x0103
4057*6f1c0430SSimon Glass 
4058*6f1c0430SSimon Glass #define PD_POWER_CHARGING_PORT 0xff
4059*6f1c0430SSimon Glass struct __ec_align1 ec_params_usb_pd_power_info {
4060*6f1c0430SSimon Glass 	uint8_t port;
4061*6f1c0430SSimon Glass };
4062*6f1c0430SSimon Glass 
4063*6f1c0430SSimon Glass enum usb_chg_type {
4064*6f1c0430SSimon Glass 	USB_CHG_TYPE_NONE,
4065*6f1c0430SSimon Glass 	USB_CHG_TYPE_PD,
4066*6f1c0430SSimon Glass 	USB_CHG_TYPE_C,
4067*6f1c0430SSimon Glass 	USB_CHG_TYPE_PROPRIETARY,
4068*6f1c0430SSimon Glass 	USB_CHG_TYPE_BC12_DCP,
4069*6f1c0430SSimon Glass 	USB_CHG_TYPE_BC12_CDP,
4070*6f1c0430SSimon Glass 	USB_CHG_TYPE_BC12_SDP,
4071*6f1c0430SSimon Glass 	USB_CHG_TYPE_OTHER,
4072*6f1c0430SSimon Glass 	USB_CHG_TYPE_VBUS,
4073*6f1c0430SSimon Glass 	USB_CHG_TYPE_UNKNOWN,
4074*6f1c0430SSimon Glass };
4075*6f1c0430SSimon Glass enum usb_power_roles {
4076*6f1c0430SSimon Glass 	USB_PD_PORT_POWER_DISCONNECTED,
4077*6f1c0430SSimon Glass 	USB_PD_PORT_POWER_SOURCE,
4078*6f1c0430SSimon Glass 	USB_PD_PORT_POWER_SINK,
4079*6f1c0430SSimon Glass 	USB_PD_PORT_POWER_SINK_NOT_CHARGING,
4080*6f1c0430SSimon Glass };
4081*6f1c0430SSimon Glass 
4082*6f1c0430SSimon Glass struct __ec_align2 usb_chg_measures {
4083*6f1c0430SSimon Glass 	uint16_t voltage_max;
4084*6f1c0430SSimon Glass 	uint16_t voltage_now;
4085*6f1c0430SSimon Glass 	uint16_t current_max;
4086*6f1c0430SSimon Glass 	uint16_t current_lim;
4087*6f1c0430SSimon Glass };
4088*6f1c0430SSimon Glass 
4089*6f1c0430SSimon Glass struct __ec_align4 ec_response_usb_pd_power_info {
4090*6f1c0430SSimon Glass 	uint8_t role;
4091*6f1c0430SSimon Glass 	uint8_t type;
4092*6f1c0430SSimon Glass 	uint8_t dualrole;
4093*6f1c0430SSimon Glass 	uint8_t reserved1;
4094*6f1c0430SSimon Glass 	struct usb_chg_measures meas;
4095*6f1c0430SSimon Glass 	uint32_t max_power;
4096*6f1c0430SSimon Glass };
4097*6f1c0430SSimon Glass 
4098*6f1c0430SSimon Glass /* Write USB-PD device FW */
4099*6f1c0430SSimon Glass #define EC_CMD_USB_PD_FW_UPDATE 0x0110
4100*6f1c0430SSimon Glass 
4101*6f1c0430SSimon Glass enum usb_pd_fw_update_cmds {
4102*6f1c0430SSimon Glass 	USB_PD_FW_REBOOT,
4103*6f1c0430SSimon Glass 	USB_PD_FW_FLASH_ERASE,
4104*6f1c0430SSimon Glass 	USB_PD_FW_FLASH_WRITE,
4105*6f1c0430SSimon Glass 	USB_PD_FW_ERASE_SIG,
4106*6f1c0430SSimon Glass };
4107*6f1c0430SSimon Glass 
4108*6f1c0430SSimon Glass struct __ec_align4 ec_params_usb_pd_fw_update {
4109*6f1c0430SSimon Glass 	uint16_t dev_id;
4110*6f1c0430SSimon Glass 	uint8_t cmd;
4111*6f1c0430SSimon Glass 	uint8_t port;
4112*6f1c0430SSimon Glass 	uint32_t size;     /* Size to write in bytes */
4113*6f1c0430SSimon Glass 	/* Followed by data to write */
4114*6f1c0430SSimon Glass };
4115*6f1c0430SSimon Glass 
4116*6f1c0430SSimon Glass /* Write USB-PD Accessory RW_HASH table entry */
4117*6f1c0430SSimon Glass #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
4118*6f1c0430SSimon Glass /* RW hash is first 20 bytes of SHA-256 of RW section */
4119*6f1c0430SSimon Glass #define PD_RW_HASH_SIZE 20
4120*6f1c0430SSimon Glass struct __ec_align1 ec_params_usb_pd_rw_hash_entry {
4121*6f1c0430SSimon Glass 	uint16_t dev_id;
4122*6f1c0430SSimon Glass 	uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
4123*6f1c0430SSimon Glass 	uint8_t reserved;        /* For alignment of current_image
4124*6f1c0430SSimon Glass 				  * TODO(rspangler) but it's not aligned!
4125*6f1c0430SSimon Glass 				  * Should have been reserved[2]. */
4126*6f1c0430SSimon Glass 	uint32_t current_image;  /* One of ec_current_image */
4127*6f1c0430SSimon Glass };
4128*6f1c0430SSimon Glass 
4129*6f1c0430SSimon Glass /* Read USB-PD Accessory info */
4130*6f1c0430SSimon Glass #define EC_CMD_USB_PD_DEV_INFO 0x0112
4131*6f1c0430SSimon Glass 
4132*6f1c0430SSimon Glass struct __ec_align1 ec_params_usb_pd_info_request {
4133*6f1c0430SSimon Glass 	uint8_t port;
4134*6f1c0430SSimon Glass };
4135*6f1c0430SSimon Glass 
4136*6f1c0430SSimon Glass /* Read USB-PD Device discovery info */
4137*6f1c0430SSimon Glass #define EC_CMD_USB_PD_DISCOVERY 0x0113
4138*6f1c0430SSimon Glass struct __ec_align_size1 ec_params_usb_pd_discovery_entry {
4139*6f1c0430SSimon Glass 	uint16_t vid;  /* USB-IF VID */
4140*6f1c0430SSimon Glass 	uint16_t pid;  /* USB-IF PID */
4141*6f1c0430SSimon Glass 	uint8_t ptype; /* product type (hub,periph,cable,ama) */
4142*6f1c0430SSimon Glass };
4143*6f1c0430SSimon Glass 
4144*6f1c0430SSimon Glass /* Override default charge behavior */
4145*6f1c0430SSimon Glass #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
4146*6f1c0430SSimon Glass 
4147*6f1c0430SSimon Glass /* Negative port parameters have special meaning */
4148*6f1c0430SSimon Glass enum usb_pd_override_ports {
4149*6f1c0430SSimon Glass 	OVERRIDE_DONT_CHARGE = -2,
4150*6f1c0430SSimon Glass 	OVERRIDE_OFF = -1,
4151*6f1c0430SSimon Glass 	/* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
4152*6f1c0430SSimon Glass };
4153*6f1c0430SSimon Glass 
4154*6f1c0430SSimon Glass struct __ec_align2 ec_params_charge_port_override {
4155*6f1c0430SSimon Glass 	int16_t override_port; /* Override port# */
4156*6f1c0430SSimon Glass };
4157*6f1c0430SSimon Glass 
4158*6f1c0430SSimon Glass /* Read (and delete) one entry of PD event log */
4159*6f1c0430SSimon Glass #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
4160*6f1c0430SSimon Glass 
4161*6f1c0430SSimon Glass struct __ec_align4 ec_response_pd_log {
4162*6f1c0430SSimon Glass 	uint32_t timestamp; /* relative timestamp in milliseconds */
4163*6f1c0430SSimon Glass 	uint8_t type;       /* event type : see PD_EVENT_xx below */
4164*6f1c0430SSimon Glass 	uint8_t size_port;  /* [7:5] port number [4:0] payload size in bytes */
4165*6f1c0430SSimon Glass 	uint16_t data;      /* type-defined data payload */
4166*6f1c0430SSimon Glass 	uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
4167*6f1c0430SSimon Glass };
4168*6f1c0430SSimon Glass 
4169*6f1c0430SSimon Glass 
4170*6f1c0430SSimon Glass /* The timestamp is the microsecond counter shifted to get about a ms. */
4171*6f1c0430SSimon Glass #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
4172*6f1c0430SSimon Glass 
4173*6f1c0430SSimon Glass #define PD_LOG_SIZE_MASK  0x1f
4174*6f1c0430SSimon Glass #define PD_LOG_PORT_MASK  0xe0
4175*6f1c0430SSimon Glass #define PD_LOG_PORT_SHIFT    5
4176*6f1c0430SSimon Glass #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
4177*6f1c0430SSimon Glass 				      ((size) & PD_LOG_SIZE_MASK))
4178*6f1c0430SSimon Glass #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
4179*6f1c0430SSimon Glass #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
4180*6f1c0430SSimon Glass 
4181*6f1c0430SSimon Glass /* PD event log : entry types */
4182*6f1c0430SSimon Glass /* PD MCU events */
4183*6f1c0430SSimon Glass #define PD_EVENT_MCU_BASE       0x00
4184*6f1c0430SSimon Glass #define PD_EVENT_MCU_CHARGE             (PD_EVENT_MCU_BASE+0)
4185*6f1c0430SSimon Glass #define PD_EVENT_MCU_CONNECT            (PD_EVENT_MCU_BASE+1)
4186*6f1c0430SSimon Glass /* Reserved for custom board event */
4187*6f1c0430SSimon Glass #define PD_EVENT_MCU_BOARD_CUSTOM       (PD_EVENT_MCU_BASE+2)
4188*6f1c0430SSimon Glass /* PD generic accessory events */
4189*6f1c0430SSimon Glass #define PD_EVENT_ACC_BASE       0x20
4190*6f1c0430SSimon Glass #define PD_EVENT_ACC_RW_FAIL   (PD_EVENT_ACC_BASE+0)
4191*6f1c0430SSimon Glass #define PD_EVENT_ACC_RW_ERASE  (PD_EVENT_ACC_BASE+1)
4192*6f1c0430SSimon Glass /* PD power supply events */
4193*6f1c0430SSimon Glass #define PD_EVENT_PS_BASE        0x40
4194*6f1c0430SSimon Glass #define PD_EVENT_PS_FAULT      (PD_EVENT_PS_BASE+0)
4195*6f1c0430SSimon Glass /* PD video dongles events */
4196*6f1c0430SSimon Glass #define PD_EVENT_VIDEO_BASE     0x60
4197*6f1c0430SSimon Glass #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
4198*6f1c0430SSimon Glass #define PD_EVENT_VIDEO_CODEC   (PD_EVENT_VIDEO_BASE+1)
4199*6f1c0430SSimon Glass /* Returned in the "type" field, when there is no entry available */
4200*6f1c0430SSimon Glass #define PD_EVENT_NO_ENTRY       0xff
4201*6f1c0430SSimon Glass 
4202*6f1c0430SSimon Glass /*
4203*6f1c0430SSimon Glass  * PD_EVENT_MCU_CHARGE event definition :
4204*6f1c0430SSimon Glass  * the payload is "struct usb_chg_measures"
4205*6f1c0430SSimon Glass  * the data field contains the port state flags as defined below :
4206*6f1c0430SSimon Glass  */
4207*6f1c0430SSimon Glass /* Port partner is a dual role device */
4208*6f1c0430SSimon Glass #define CHARGE_FLAGS_DUAL_ROLE         (1 << 15)
4209*6f1c0430SSimon Glass /* Port is the pending override port */
4210*6f1c0430SSimon Glass #define CHARGE_FLAGS_DELAYED_OVERRIDE  (1 << 14)
4211*6f1c0430SSimon Glass /* Port is the override port */
4212*6f1c0430SSimon Glass #define CHARGE_FLAGS_OVERRIDE          (1 << 13)
4213*6f1c0430SSimon Glass /* Charger type */
4214*6f1c0430SSimon Glass #define CHARGE_FLAGS_TYPE_SHIFT               3
4215*6f1c0430SSimon Glass #define CHARGE_FLAGS_TYPE_MASK       (0xf << CHARGE_FLAGS_TYPE_SHIFT)
4216*6f1c0430SSimon Glass /* Power delivery role */
4217*6f1c0430SSimon Glass #define CHARGE_FLAGS_ROLE_MASK         (7 <<  0)
4218*6f1c0430SSimon Glass 
4219*6f1c0430SSimon Glass /*
4220*6f1c0430SSimon Glass  * PD_EVENT_PS_FAULT data field flags definition :
4221*6f1c0430SSimon Glass  */
4222*6f1c0430SSimon Glass #define PS_FAULT_OCP                          1
4223*6f1c0430SSimon Glass #define PS_FAULT_FAST_OCP                     2
4224*6f1c0430SSimon Glass #define PS_FAULT_OVP                          3
4225*6f1c0430SSimon Glass #define PS_FAULT_DISCH                        4
4226*6f1c0430SSimon Glass 
4227*6f1c0430SSimon Glass /*
4228*6f1c0430SSimon Glass  * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
4229*6f1c0430SSimon Glass  */
4230*6f1c0430SSimon Glass struct __ec_align4 mcdp_version {
4231*6f1c0430SSimon Glass 	uint8_t major;
4232*6f1c0430SSimon Glass 	uint8_t minor;
4233*6f1c0430SSimon Glass 	uint16_t build;
4234*6f1c0430SSimon Glass };
4235*6f1c0430SSimon Glass 
4236*6f1c0430SSimon Glass struct __ec_align4 mcdp_info {
4237*6f1c0430SSimon Glass 	uint8_t family[2];
4238*6f1c0430SSimon Glass 	uint8_t chipid[2];
4239*6f1c0430SSimon Glass 	struct mcdp_version irom;
4240*6f1c0430SSimon Glass 	struct mcdp_version fw;
4241*6f1c0430SSimon Glass };
4242*6f1c0430SSimon Glass 
4243*6f1c0430SSimon Glass /* struct mcdp_info field decoding */
4244*6f1c0430SSimon Glass #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
4245*6f1c0430SSimon Glass #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
4246*6f1c0430SSimon Glass 
4247*6f1c0430SSimon Glass /* Get/Set USB-PD Alternate mode info */
4248*6f1c0430SSimon Glass #define EC_CMD_USB_PD_GET_AMODE 0x0116
4249*6f1c0430SSimon Glass struct __ec_align_size1 ec_params_usb_pd_get_mode_request {
4250*6f1c0430SSimon Glass 	uint16_t svid_idx; /* SVID index to get */
4251*6f1c0430SSimon Glass 	uint8_t port;      /* port */
4252*6f1c0430SSimon Glass };
4253*6f1c0430SSimon Glass 
4254*6f1c0430SSimon Glass struct __ec_align4 ec_params_usb_pd_get_mode_response {
4255*6f1c0430SSimon Glass 	uint16_t svid;   /* SVID */
4256*6f1c0430SSimon Glass 	uint16_t opos;    /* Object Position */
4257*6f1c0430SSimon Glass 	uint32_t vdo[6]; /* Mode VDOs */
4258*6f1c0430SSimon Glass };
4259*6f1c0430SSimon Glass 
4260*6f1c0430SSimon Glass #define EC_CMD_USB_PD_SET_AMODE 0x0117
4261*6f1c0430SSimon Glass 
4262*6f1c0430SSimon Glass enum pd_mode_cmd {
4263*6f1c0430SSimon Glass 	PD_EXIT_MODE = 0,
4264*6f1c0430SSimon Glass 	PD_ENTER_MODE = 1,
4265*6f1c0430SSimon Glass 	/* Not a command.  Do NOT remove. */
4266*6f1c0430SSimon Glass 	PD_MODE_CMD_COUNT,
4267*6f1c0430SSimon Glass };
4268*6f1c0430SSimon Glass 
4269*6f1c0430SSimon Glass struct __ec_align4 ec_params_usb_pd_set_mode_request {
4270*6f1c0430SSimon Glass 	uint32_t cmd;  /* enum pd_mode_cmd */
4271*6f1c0430SSimon Glass 	uint16_t svid; /* SVID to set */
4272*6f1c0430SSimon Glass 	uint8_t opos;  /* Object Position */
4273*6f1c0430SSimon Glass 	uint8_t port;  /* port */
4274*6f1c0430SSimon Glass };
4275*6f1c0430SSimon Glass 
4276*6f1c0430SSimon Glass /* Ask the PD MCU to record a log of a requested type */
4277*6f1c0430SSimon Glass #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
4278*6f1c0430SSimon Glass 
4279*6f1c0430SSimon Glass struct __ec_align1 ec_params_pd_write_log_entry {
4280*6f1c0430SSimon Glass 	uint8_t type; /* event type : see PD_EVENT_xx above */
4281*6f1c0430SSimon Glass 	uint8_t port; /* port#, or 0 for events unrelated to a given port */
4282*6f1c0430SSimon Glass };
4283*6f1c0430SSimon Glass 
4284*6f1c0430SSimon Glass 
4285*6f1c0430SSimon Glass /* Control USB-PD chip */
4286*6f1c0430SSimon Glass #define EC_CMD_PD_CONTROL 0x0119
4287*6f1c0430SSimon Glass 
4288*6f1c0430SSimon Glass enum ec_pd_control_cmd {
4289*6f1c0430SSimon Glass 	PD_SUSPEND = 0,      /* Suspend the PD chip (EC: stop talking to PD) */
4290*6f1c0430SSimon Glass 	PD_RESUME,           /* Resume the PD chip (EC: start talking to PD) */
4291*6f1c0430SSimon Glass 	PD_RESET,            /* Force reset the PD chip */
4292*6f1c0430SSimon Glass 	PD_CONTROL_DISABLE   /* Disable further calls to this command */
4293*6f1c0430SSimon Glass };
4294*6f1c0430SSimon Glass 
4295*6f1c0430SSimon Glass struct __ec_align1 ec_params_pd_control {
4296*6f1c0430SSimon Glass 	uint8_t chip;         /* chip id (should be 0) */
4297*6f1c0430SSimon Glass 	uint8_t subcmd;
4298*6f1c0430SSimon Glass };
4299*6f1c0430SSimon Glass 
4300*6f1c0430SSimon Glass /* Get info about USB-C SS muxes */
4301*6f1c0430SSimon Glass #define EC_CMD_USB_PD_MUX_INFO 0x011A
4302*6f1c0430SSimon Glass 
4303*6f1c0430SSimon Glass struct __ec_align1 ec_params_usb_pd_mux_info {
4304*6f1c0430SSimon Glass 	uint8_t port; /* USB-C port number */
4305*6f1c0430SSimon Glass };
4306*6f1c0430SSimon Glass 
4307*6f1c0430SSimon Glass /* Flags representing mux state */
4308*6f1c0430SSimon Glass #define USB_PD_MUX_USB_ENABLED       (1 << 0)
4309*6f1c0430SSimon Glass #define USB_PD_MUX_DP_ENABLED        (1 << 1)
4310*6f1c0430SSimon Glass #define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
4311*6f1c0430SSimon Glass #define USB_PD_MUX_HPD_IRQ           (1 << 3)
4312*6f1c0430SSimon Glass 
4313*6f1c0430SSimon Glass struct __ec_align1 ec_response_usb_pd_mux_info {
4314*6f1c0430SSimon Glass 	uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
4315*6f1c0430SSimon Glass };
4316*6f1c0430SSimon Glass 
4317*6f1c0430SSimon Glass #define EC_CMD_PD_CHIP_INFO		0x011B
4318*6f1c0430SSimon Glass 
4319*6f1c0430SSimon Glass struct __ec_align1 ec_params_pd_chip_info {
4320*6f1c0430SSimon Glass 	uint8_t port;	/* USB-C port number */
4321*6f1c0430SSimon Glass 	uint8_t renew;	/* Force renewal */
4322*6f1c0430SSimon Glass };
4323*6f1c0430SSimon Glass 
4324*6f1c0430SSimon Glass struct __ec_align2 ec_response_pd_chip_info {
4325*6f1c0430SSimon Glass 	uint16_t vendor_id;
4326*6f1c0430SSimon Glass 	uint16_t product_id;
4327*6f1c0430SSimon Glass 	uint16_t device_id;
4328*6f1c0430SSimon Glass 	union {
4329*6f1c0430SSimon Glass 		uint8_t fw_version_string[8];
4330*6f1c0430SSimon Glass 		uint64_t fw_version_number;
4331*6f1c0430SSimon Glass 	};
4332*6f1c0430SSimon Glass };
4333*6f1c0430SSimon Glass 
4334*6f1c0430SSimon Glass /* Run RW signature verification and get status */
4335*6f1c0430SSimon Glass #define EC_CMD_RWSIG_CHECK_STATUS	0x011C
4336*6f1c0430SSimon Glass 
4337*6f1c0430SSimon Glass struct __ec_align4 ec_response_rwsig_check_status {
4338*6f1c0430SSimon Glass 	uint32_t status;
4339*6f1c0430SSimon Glass };
4340*6f1c0430SSimon Glass 
4341*6f1c0430SSimon Glass /* For controlling RWSIG task */
4342*6f1c0430SSimon Glass #define EC_CMD_RWSIG_ACTION	0x011D
4343*6f1c0430SSimon Glass 
4344*6f1c0430SSimon Glass enum rwsig_action {
4345*6f1c0430SSimon Glass 	RWSIG_ACTION_ABORT = 0,		/* Abort RWSIG and prevent jumping */
4346*6f1c0430SSimon Glass 	RWSIG_ACTION_CONTINUE = 1,	/* Jump to RW immediately */
4347*6f1c0430SSimon Glass };
4348*6f1c0430SSimon Glass 
4349*6f1c0430SSimon Glass struct __ec_align4 ec_params_rwsig_action {
4350*6f1c0430SSimon Glass 	uint32_t action;
4351*6f1c0430SSimon Glass };
4352*6f1c0430SSimon Glass 
4353*6f1c0430SSimon Glass /* Run verification on a slot */
4354*6f1c0430SSimon Glass #define EC_CMD_EFS_VERIFY	0x011E
4355*6f1c0430SSimon Glass 
4356*6f1c0430SSimon Glass struct __ec_align1 ec_params_efs_verify {
4357*6f1c0430SSimon Glass 	uint8_t region;		/* enum ec_flash_region */
4358*6f1c0430SSimon Glass };
4359*6f1c0430SSimon Glass 
4360*6f1c0430SSimon Glass /*
4361*6f1c0430SSimon Glass  * Retrieve info from Cros Board Info store. Response is based on the data
4362*6f1c0430SSimon Glass  * type. Integers return a uint32. Strings return a string, using the response
4363*6f1c0430SSimon Glass  * size to determine how big it is.
4364*6f1c0430SSimon Glass  */
4365*6f1c0430SSimon Glass #define EC_CMD_GET_CROS_BOARD_INFO	0x011F
4366*6f1c0430SSimon Glass /*
4367*6f1c0430SSimon Glass  * Write info into Cros Board Info on EEPROM. Write fails if the board has
4368*6f1c0430SSimon Glass  * hardware write-protect enabled.
4369*6f1c0430SSimon Glass  */
4370*6f1c0430SSimon Glass #define EC_CMD_SET_CROS_BOARD_INFO	0x0120
4371*6f1c0430SSimon Glass 
4372*6f1c0430SSimon Glass enum cbi_data_tag {
4373*6f1c0430SSimon Glass 	CBI_TAG_BOARD_VERSION = 0, /* uint16_t or uint8_t[] = {minor,major} */
4374*6f1c0430SSimon Glass 	CBI_TAG_OEM_ID = 1,        /* uint8_t */
4375*6f1c0430SSimon Glass 	CBI_TAG_SKU_ID = 2,        /* uint8_t */
4376*6f1c0430SSimon Glass 	CBI_TAG_COUNT,
4377*6f1c0430SSimon Glass };
4378*6f1c0430SSimon Glass 
4379*6f1c0430SSimon Glass /*
4380*6f1c0430SSimon Glass  * Flags to control read operation
4381*6f1c0430SSimon Glass  *
4382*6f1c0430SSimon Glass  * RELOAD:  Invalidate cache and read data from EEPROM. Useful to verify
4383*6f1c0430SSimon Glass  *          write was successful without reboot.
4384*6f1c0430SSimon Glass  */
4385*6f1c0430SSimon Glass #define CBI_GET_RELOAD		(1 << 0)
4386*6f1c0430SSimon Glass 
4387*6f1c0430SSimon Glass struct __ec_align4 ec_params_get_cbi {
4388*6f1c0430SSimon Glass 	uint32_t type;		/* enum cbi_data_tag */
4389*6f1c0430SSimon Glass 	uint32_t flag;		/* CBI_GET_* */
4390*6f1c0430SSimon Glass };
4391*6f1c0430SSimon Glass 
4392*6f1c0430SSimon Glass /*
4393*6f1c0430SSimon Glass  * Flags to control write behavior.
4394*6f1c0430SSimon Glass  *
4395*6f1c0430SSimon Glass  * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
4396*6f1c0430SSimon Glass  *          useful when writing multiple fields in a row.
4397*6f1c0430SSimon Glass  * INIT:    Needs to be set when creating a new CBI from scratch. All fields
4398*6f1c0430SSimon Glass  *          will be initialized to zero first.
4399*6f1c0430SSimon Glass  */
4400*6f1c0430SSimon Glass #define CBI_SET_NO_SYNC		(1 << 0)
4401*6f1c0430SSimon Glass #define CBI_SET_INIT		(1 << 1)
4402*6f1c0430SSimon Glass 
4403*6f1c0430SSimon Glass struct __ec_align1 ec_params_set_cbi {
4404*6f1c0430SSimon Glass 	uint32_t tag;		/* enum cbi_data_tag */
4405*6f1c0430SSimon Glass 	uint32_t flag;		/* CBI_SET_* */
4406*6f1c0430SSimon Glass 	uint32_t size;		/* Data size */
4407*6f1c0430SSimon Glass 	uint8_t data[];		/* For string and raw data */
4408*6f1c0430SSimon Glass };
4409*6f1c0430SSimon Glass 
4410*6f1c0430SSimon Glass /*****************************************************************************/
4411*6f1c0430SSimon Glass /* The command range 0x200-0x2FF is reserved for Rotor. */
4412*6f1c0430SSimon Glass 
4413*6f1c0430SSimon Glass /*****************************************************************************/
4414*6f1c0430SSimon Glass /*
4415*6f1c0430SSimon Glass  * Reserve a range of host commands for the CR51 firmware.
4416*6f1c0430SSimon Glass  */
4417*6f1c0430SSimon Glass #define EC_CMD_CR51_BASE 0x0300
4418*6f1c0430SSimon Glass #define EC_CMD_CR51_LAST 0x03FF
4419*6f1c0430SSimon Glass 
4420*6f1c0430SSimon Glass /*****************************************************************************/
4421*6f1c0430SSimon Glass /* Fingerprint MCU commands: range 0x0400-0x040x */
4422*6f1c0430SSimon Glass 
4423*6f1c0430SSimon Glass /* Fingerprint SPI sensor passthru command: prototyping ONLY */
4424*6f1c0430SSimon Glass #define EC_CMD_FP_PASSTHRU 0x0400
4425*6f1c0430SSimon Glass 
4426*6f1c0430SSimon Glass #define EC_FP_FLAG_NOT_COMPLETE 0x1
4427*6f1c0430SSimon Glass 
4428*6f1c0430SSimon Glass struct __ec_align2 ec_params_fp_passthru {
4429*6f1c0430SSimon Glass 	uint16_t len;		/* Number of bytes to write then read */
4430*6f1c0430SSimon Glass 	uint16_t flags;		/* EC_FP_FLAG_xxx */
4431*6f1c0430SSimon Glass 	uint8_t data[];		/* Data to send */
4432*6f1c0430SSimon Glass };
4433*6f1c0430SSimon Glass 
4434*6f1c0430SSimon Glass /* Fingerprint sensor configuration command: prototyping ONLY */
4435*6f1c0430SSimon Glass #define EC_CMD_FP_SENSOR_CONFIG 0x0401
4436*6f1c0430SSimon Glass 
4437*6f1c0430SSimon Glass #define EC_FP_SENSOR_CONFIG_MAX_REGS 16
4438*6f1c0430SSimon Glass 
4439*6f1c0430SSimon Glass struct __ec_align2 ec_params_fp_sensor_config {
4440*6f1c0430SSimon Glass 	uint8_t count;		/* Number of setup registers */
4441*6f1c0430SSimon Glass 	/*
4442*6f1c0430SSimon Glass 	 * the value to send to each of the 'count' setup registers
4443*6f1c0430SSimon Glass 	 * is stored in the 'data' array for 'len' bytes just after
4444*6f1c0430SSimon Glass 	 * the previous one.
4445*6f1c0430SSimon Glass 	 */
4446*6f1c0430SSimon Glass 	uint8_t len[EC_FP_SENSOR_CONFIG_MAX_REGS];
4447*6f1c0430SSimon Glass 	uint8_t data[];
4448*6f1c0430SSimon Glass };
4449*6f1c0430SSimon Glass 
4450*6f1c0430SSimon Glass /* Configure the Fingerprint MCU behavior */
4451*6f1c0430SSimon Glass #define EC_CMD_FP_MODE 0x0402
4452*6f1c0430SSimon Glass 
4453*6f1c0430SSimon Glass /* Put the sensor in its lowest power mode */
4454*6f1c0430SSimon Glass #define FP_MODE_DEEPSLEEP     (1<<0)
4455*6f1c0430SSimon Glass /* Wait to see a finger on the sensor */
4456*6f1c0430SSimon Glass #define FP_MODE_FINGER_DOWN   (1<<1)
4457*6f1c0430SSimon Glass /* Poll until the finger has left the sensor */
4458*6f1c0430SSimon Glass #define FP_MODE_FINGER_UP     (1<<2)
4459*6f1c0430SSimon Glass /* Capture the current finger image */
4460*6f1c0430SSimon Glass #define FP_MODE_CAPTURE       (1<<3)
4461*6f1c0430SSimon Glass /* special value: don't change anything just read back current mode */
4462*6f1c0430SSimon Glass #define FP_MODE_DONT_CHANGE   (1<<31)
4463*6f1c0430SSimon Glass 
4464*6f1c0430SSimon Glass struct __ec_align4 ec_params_fp_mode {
4465*6f1c0430SSimon Glass 	uint32_t mode; /* as defined by FP_MODE_ constants */
4466*6f1c0430SSimon Glass 	/* TBD */
4467*6f1c0430SSimon Glass };
4468*6f1c0430SSimon Glass 
4469*6f1c0430SSimon Glass struct __ec_align4 ec_response_fp_mode {
4470*6f1c0430SSimon Glass 	uint32_t mode; /* as defined by FP_MODE_ constants */
4471*6f1c0430SSimon Glass 	/* TBD */
4472*6f1c0430SSimon Glass };
4473*6f1c0430SSimon Glass 
4474*6f1c0430SSimon Glass /* Retrieve Fingerprint sensor information */
4475*6f1c0430SSimon Glass #define EC_CMD_FP_INFO 0x0403
4476*6f1c0430SSimon Glass 
4477*6f1c0430SSimon Glass struct __ec_align2 ec_response_fp_info {
4478*6f1c0430SSimon Glass 	/* Sensor identification */
4479*6f1c0430SSimon Glass 	uint32_t vendor_id;
4480*6f1c0430SSimon Glass 	uint32_t product_id;
4481*6f1c0430SSimon Glass 	uint32_t model_id;
4482*6f1c0430SSimon Glass 	uint32_t version;
4483*6f1c0430SSimon Glass 	/* Image frame characteristics */
4484*6f1c0430SSimon Glass 	uint32_t frame_size;
4485*6f1c0430SSimon Glass 	uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
4486*6f1c0430SSimon Glass 	uint16_t width;
4487*6f1c0430SSimon Glass 	uint16_t height;
4488*6f1c0430SSimon Glass 	uint16_t bpp;
4489*6f1c0430SSimon Glass };
4490*6f1c0430SSimon Glass 
4491*6f1c0430SSimon Glass /* Get the last captured finger frame: TODO: will be AES-encrypted */
4492*6f1c0430SSimon Glass #define EC_CMD_FP_FRAME 0x0404
4493*6f1c0430SSimon Glass 
4494*6f1c0430SSimon Glass struct __ec_align4 ec_params_fp_frame {
4495*6f1c0430SSimon Glass 	uint32_t offset;
4496*6f1c0430SSimon Glass 	uint32_t size;
4497*6f1c0430SSimon Glass };
4498*6f1c0430SSimon Glass 
4499*6f1c0430SSimon Glass /*****************************************************************************/
4500*6f1c0430SSimon Glass /* Touchpad MCU commands: range 0x0500-0x05FF */
4501*6f1c0430SSimon Glass 
4502*6f1c0430SSimon Glass /* Perform touchpad self test */
4503*6f1c0430SSimon Glass #define EC_CMD_TP_SELF_TEST 0x0500
4504*6f1c0430SSimon Glass 
4505*6f1c0430SSimon Glass /* Get number of frame types, and the size of each type */
4506*6f1c0430SSimon Glass #define EC_CMD_TP_FRAME_INFO 0x0501
4507*6f1c0430SSimon Glass 
4508*6f1c0430SSimon Glass struct __ec_align4 ec_response_tp_frame_info {
4509*6f1c0430SSimon Glass 	uint32_t n_frames;
4510*6f1c0430SSimon Glass 	uint32_t frame_sizes[0];
4511*6f1c0430SSimon Glass };
4512*6f1c0430SSimon Glass 
4513*6f1c0430SSimon Glass /* Create a snapshot of current frame readings */
4514*6f1c0430SSimon Glass #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
4515*6f1c0430SSimon Glass 
4516*6f1c0430SSimon Glass /* Read the frame */
4517*6f1c0430SSimon Glass #define EC_CMD_TP_FRAME_GET 0x0503
4518*6f1c0430SSimon Glass 
4519*6f1c0430SSimon Glass struct __ec_align4 ec_params_tp_frame_get {
4520*6f1c0430SSimon Glass 	uint32_t frame_index;
4521*6f1c0430SSimon Glass 	uint32_t offset;
4522*6f1c0430SSimon Glass 	uint32_t size;
4523*6f1c0430SSimon Glass };
4524*6f1c0430SSimon Glass 
4525*6f1c0430SSimon Glass /*****************************************************************************/
4526*6f1c0430SSimon Glass /*
4527*6f1c0430SSimon Glass  * Reserve a range of host commands for board-specific, experimental, or
4528*6f1c0430SSimon Glass  * special purpose features. These can be (re)used without updating this file.
4529*6f1c0430SSimon Glass  *
4530*6f1c0430SSimon Glass  * CAUTION: Don't go nuts with this. Shipping products should document ALL
4531*6f1c0430SSimon Glass  * their EC commands for easier development, testing, debugging, and support.
4532*6f1c0430SSimon Glass  *
4533*6f1c0430SSimon Glass  * All commands MUST be #defined to be 4-digit UPPER CASE hex values
4534*6f1c0430SSimon Glass  * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
4535*6f1c0430SSimon Glass  *
4536*6f1c0430SSimon Glass  * In your experimental code, you may want to do something like this:
4537*6f1c0430SSimon Glass  *
4538*6f1c0430SSimon Glass  *   #define EC_CMD_MAGIC_FOO 0x0000
4539*6f1c0430SSimon Glass  *   #define EC_CMD_MAGIC_BAR 0x0001
4540*6f1c0430SSimon Glass  *   #define EC_CMD_MAGIC_HEY 0x0002
4541*6f1c0430SSimon Glass  *
4542*6f1c0430SSimon Glass  *   DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
4543*6f1c0430SSimon Glass  *      EC_VER_MASK(0);
4544*6f1c0430SSimon Glass  *
4545*6f1c0430SSimon Glass  *   DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
4546*6f1c0430SSimon Glass  *      EC_VER_MASK(0);
4547*6f1c0430SSimon Glass  *
4548*6f1c0430SSimon Glass  *   DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
4549*6f1c0430SSimon Glass  *      EC_VER_MASK(0);
4550*6f1c0430SSimon Glass  */
4551*6f1c0430SSimon Glass #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
4552*6f1c0430SSimon Glass #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
4553*6f1c0430SSimon Glass 
4554*6f1c0430SSimon Glass /*
4555*6f1c0430SSimon Glass  * Given the private host command offset, calculate the true private host
4556*6f1c0430SSimon Glass  * command value.
4557*6f1c0430SSimon Glass  */
4558*6f1c0430SSimon Glass #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
4559*6f1c0430SSimon Glass 	(EC_CMD_BOARD_SPECIFIC_BASE + (command))
4560*6f1c0430SSimon Glass 
4561*6f1c0430SSimon Glass /*****************************************************************************/
4562*6f1c0430SSimon Glass /*
4563*6f1c0430SSimon Glass  * Passthru commands
4564*6f1c0430SSimon Glass  *
4565*6f1c0430SSimon Glass  * Some platforms have sub-processors chained to each other.  For example.
4566*6f1c0430SSimon Glass  *
4567*6f1c0430SSimon Glass  *     AP <--> EC <--> PD MCU
4568*6f1c0430SSimon Glass  *
4569*6f1c0430SSimon Glass  * The top 2 bits of the command number are used to indicate which device the
4570*6f1c0430SSimon Glass  * command is intended for.  Device 0 is always the device receiving the
4571*6f1c0430SSimon Glass  * command; other device mapping is board-specific.
4572*6f1c0430SSimon Glass  *
4573*6f1c0430SSimon Glass  * When a device receives a command to be passed to a sub-processor, it passes
4574*6f1c0430SSimon Glass  * it on with the device number set back to 0.  This allows the sub-processor
4575*6f1c0430SSimon Glass  * to remain blissfully unaware of whether the command originated on the next
4576*6f1c0430SSimon Glass  * device up the chain, or was passed through from the AP.
4577*6f1c0430SSimon Glass  *
4578*6f1c0430SSimon Glass  * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
4579*6f1c0430SSimon Glass  *     AP sends command 0x4002 to the EC
4580*6f1c0430SSimon Glass  *     EC sends command 0x0002 to the PD MCU
4581*6f1c0430SSimon Glass  *     EC forwards PD MCU response back to the AP
4582*6f1c0430SSimon Glass  */
4583*6f1c0430SSimon Glass 
4584*6f1c0430SSimon Glass /* Offset and max command number for sub-device n */
4585*6f1c0430SSimon Glass #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
4586*6f1c0430SSimon Glass #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
4587*6f1c0430SSimon Glass 
4588*6f1c0430SSimon Glass /*****************************************************************************/
4589*6f1c0430SSimon Glass /*
4590*6f1c0430SSimon Glass  * Deprecated constants. These constants have been renamed for clarity. The
4591*6f1c0430SSimon Glass  * meaning and size has not changed. Programs that use the old names should
4592*6f1c0430SSimon Glass  * switch to the new names soon, as the old names may not be carried forward
4593*6f1c0430SSimon Glass  * forever.
4594*6f1c0430SSimon Glass  */
4595*6f1c0430SSimon Glass #define EC_HOST_PARAM_SIZE      EC_PROTO2_MAX_PARAM_SIZE
4596*6f1c0430SSimon Glass #define EC_LPC_ADDR_OLD_PARAM   EC_HOST_CMD_REGION1
4597*6f1c0430SSimon Glass #define EC_OLD_PARAM_SIZE       EC_HOST_CMD_REGION_SIZE
4598*6f1c0430SSimon Glass 
4599*6f1c0430SSimon Glass #endif  /* !__ACPI__ && !__KERNEL__ */
460088364387SHung-ying Tyan 
460188364387SHung-ying Tyan #endif  /* __CROS_EC_COMMANDS_H */
4602