Home | History | Annotate | Download | only in updater
      1 /* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
      2  * Use of this source code is governed by a BSD-style license that can be
      3  * found in the LICENSE file.
      4  */
      5 
      6 /* Host communication command constants for Chrome EC */
      7 
      8 #ifndef __CROS_EC_COMMANDS_H
      9 #define __CROS_EC_COMMANDS_H
     10 
     11 /*
     12  * Current version of this protocol
     13  *
     14  * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
     15  * determined in other ways.  Remove this once the kernel code no longer
     16  * depends on it.
     17  */
     18 #define EC_PROTO_VERSION          0x00000002
     19 
     20 /* Command version mask */
     21 #define EC_VER_MASK(version) (1UL << (version))
     22 
     23 /* I/O addresses for ACPI commands */
     24 #define EC_LPC_ADDR_ACPI_DATA  0x62
     25 #define EC_LPC_ADDR_ACPI_CMD   0x66
     26 
     27 /* I/O addresses for host command */
     28 #define EC_LPC_ADDR_HOST_DATA  0x200
     29 #define EC_LPC_ADDR_HOST_CMD   0x204
     30 
     31 /* I/O addresses for host command args and params */
     32 /* Protocol version 2 */
     33 #define EC_LPC_ADDR_HOST_ARGS    0x800  /* And 0x801, 0x802, 0x803 */
     34 #define EC_LPC_ADDR_HOST_PARAM   0x804  /* For version 2 params; size is
     35 					 * EC_PROTO2_MAX_PARAM_SIZE */
     36 /* Protocol version 3 */
     37 #define EC_LPC_ADDR_HOST_PACKET  0x800  /* Offset of version 3 packet */
     38 #define EC_LPC_HOST_PACKET_SIZE  0x100  /* Max size of version 3 packet */
     39 
     40 /* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
     41  * and they tell the kernel that so we have to think of it as two parts. */
     42 #define EC_HOST_CMD_REGION0    0x800
     43 #define EC_HOST_CMD_REGION1    0x880
     44 #define EC_HOST_CMD_REGION_SIZE 0x80
     45 
     46 /* EC command register bit functions */
     47 #define EC_LPC_CMDR_DATA	(1 << 0)  /* Data ready for host to read */
     48 #define EC_LPC_CMDR_PENDING	(1 << 1)  /* Write pending to EC */
     49 #define EC_LPC_CMDR_BUSY	(1 << 2)  /* EC is busy processing a command */
     50 #define EC_LPC_CMDR_CMD		(1 << 3)  /* Last host write was a command */
     51 #define EC_LPC_CMDR_ACPI_BRST	(1 << 4)  /* Burst mode (not used) */
     52 #define EC_LPC_CMDR_SCI		(1 << 5)  /* SCI event is pending */
     53 #define EC_LPC_CMDR_SMI		(1 << 6)  /* SMI event is pending */
     54 
     55 #define EC_LPC_ADDR_MEMMAP       0x900
     56 #define EC_MEMMAP_SIZE         255 /* ACPI IO buffer max is 255 bytes */
     57 #define EC_MEMMAP_TEXT_MAX     8   /* Size of a string in the memory map */
     58 
     59 /* The offset address of each type of data in mapped memory. */
     60 #define EC_MEMMAP_TEMP_SENSOR      0x00 /* Temp sensors 0x00 - 0x0f */
     61 #define EC_MEMMAP_FAN              0x10 /* Fan speeds 0x10 - 0x17 */
     62 #define EC_MEMMAP_TEMP_SENSOR_B    0x18 /* More temp sensors 0x18 - 0x1f */
     63 #define EC_MEMMAP_ID               0x20 /* 0x20 == 'E', 0x21 == 'C' */
     64 #define EC_MEMMAP_ID_VERSION       0x22 /* Version of data in 0x20 - 0x2f */
     65 #define EC_MEMMAP_THERMAL_VERSION  0x23 /* Version of data in 0x00 - 0x1f */
     66 #define EC_MEMMAP_BATTERY_VERSION  0x24 /* Version of data in 0x40 - 0x7f */
     67 #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
     68 #define EC_MEMMAP_EVENTS_VERSION   0x26 /* Version of data in 0x34 - 0x3f */
     69 #define EC_MEMMAP_HOST_CMD_FLAGS   0x27 /* Host cmd interface flags (8 bits) */
     70 /* Unused 0x28 - 0x2f */
     71 #define EC_MEMMAP_SWITCHES         0x30	/* 8 bits */
     72 /* Unused 0x31 - 0x33 */
     73 #define EC_MEMMAP_HOST_EVENTS      0x34 /* 32 bits */
     74 /* Reserve 0x38 - 0x3f for additional host event-related stuff */
     75 /* Battery values are all 32 bits */
     76 #define EC_MEMMAP_BATT_VOLT        0x40 /* Battery Present Voltage */
     77 #define EC_MEMMAP_BATT_RATE        0x44 /* Battery Present Rate */
     78 #define EC_MEMMAP_BATT_CAP         0x48 /* Battery Remaining Capacity */
     79 #define EC_MEMMAP_BATT_FLAG        0x4c /* Battery State, defined below */
     80 #define EC_MEMMAP_BATT_DCAP        0x50 /* Battery Design Capacity */
     81 #define EC_MEMMAP_BATT_DVLT        0x54 /* Battery Design Voltage */
     82 #define EC_MEMMAP_BATT_LFCC        0x58 /* Battery Last Full Charge Capacity */
     83 #define EC_MEMMAP_BATT_CCNT        0x5c /* Battery Cycle Count */
     84 /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
     85 #define EC_MEMMAP_BATT_MFGR        0x60 /* Battery Manufacturer String */
     86 #define EC_MEMMAP_BATT_MODEL       0x68 /* Battery Model Number String */
     87 #define EC_MEMMAP_BATT_SERIAL      0x70 /* Battery Serial Number String */
     88 #define EC_MEMMAP_BATT_TYPE        0x78 /* Battery Type String */
     89 #define EC_MEMMAP_ALS              0x80 /* ALS readings in lux (2 X 16 bits) */
     90 /* Unused 0x84 - 0x8f */
     91 #define EC_MEMMAP_ACC_STATUS       0x90 /* Accelerometer status (8 bits )*/
     92 /* Unused 0x91 */
     93 #define EC_MEMMAP_ACC_DATA         0x92 /* Accelerometers data 0x92 - 0x9f */
     94 /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
     95 /* 0x94 - 0x99: 1st Accelerometer */
     96 /* 0x9a - 0x9f: 2nd Accelerometer */
     97 #define EC_MEMMAP_GYRO_DATA        0xa0 /* Gyroscope data 0xa0 - 0xa5 */
     98 /* Unused 0xa6 - 0xdf */
     99 
    100 /*
    101  * ACPI is unable to access memory mapped data at or above this offset due to
    102  * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
    103  * which might be needed by ACPI.
    104  */
    105 #define EC_MEMMAP_NO_ACPI 0xe0
    106 
    107 /* Define the format of the accelerometer mapped memory status byte. */
    108 #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK  0x0f
    109 #define EC_MEMMAP_ACC_STATUS_BUSY_BIT        (1 << 4)
    110 #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT    (1 << 7)
    111 
    112 /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
    113 #define EC_TEMP_SENSOR_ENTRIES     16
    114 /*
    115  * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
    116  *
    117  * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
    118  */
    119 #define EC_TEMP_SENSOR_B_ENTRIES      8
    120 
    121 /* Special values for mapped temperature sensors */
    122 #define EC_TEMP_SENSOR_NOT_PRESENT    0xff
    123 #define EC_TEMP_SENSOR_ERROR          0xfe
    124 #define EC_TEMP_SENSOR_NOT_POWERED    0xfd
    125 #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
    126 /*
    127  * The offset of temperature value stored in mapped memory.  This allows
    128  * reporting a temperature range of 200K to 454K = -73C to 181C.
    129  */
    130 #define EC_TEMP_SENSOR_OFFSET      200
    131 
    132 /*
    133  * Number of ALS readings at EC_MEMMAP_ALS
    134  */
    135 #define EC_ALS_ENTRIES             2
    136 
    137 /*
    138  * The default value a temperature sensor will return when it is present but
    139  * has not been read this boot.  This is a reasonable number to avoid
    140  * triggering alarms on the host.
    141  */
    142 #define EC_TEMP_SENSOR_DEFAULT     (296 - EC_TEMP_SENSOR_OFFSET)
    143 
    144 #define EC_FAN_SPEED_ENTRIES       4       /* Number of fans at EC_MEMMAP_FAN */
    145 #define EC_FAN_SPEED_NOT_PRESENT   0xffff  /* Entry not present */
    146 #define EC_FAN_SPEED_STALLED       0xfffe  /* Fan stalled */
    147 
    148 /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
    149 #define EC_BATT_FLAG_AC_PRESENT   0x01
    150 #define EC_BATT_FLAG_BATT_PRESENT 0x02
    151 #define EC_BATT_FLAG_DISCHARGING  0x04
    152 #define EC_BATT_FLAG_CHARGING     0x08
    153 #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
    154 
    155 /* Switch flags at EC_MEMMAP_SWITCHES */
    156 #define EC_SWITCH_LID_OPEN               0x01
    157 #define EC_SWITCH_POWER_BUTTON_PRESSED   0x02
    158 #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
    159 /* Was recovery requested via keyboard; now unused. */
    160 #define EC_SWITCH_IGNORE1		 0x08
    161 /* Recovery requested via dedicated signal (from servo board) */
    162 #define EC_SWITCH_DEDICATED_RECOVERY     0x10
    163 /* Was fake developer mode switch; now unused.  Remove in next refactor. */
    164 #define EC_SWITCH_IGNORE0                0x20
    165 
    166 /* Host command interface flags */
    167 /* Host command interface supports LPC args (LPC interface only) */
    168 #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED  0x01
    169 /* Host command interface supports version 3 protocol */
    170 #define EC_HOST_CMD_FLAG_VERSION_3   0x02
    171 
    172 /* Wireless switch flags */
    173 #define EC_WIRELESS_SWITCH_ALL       ~0x00  /* All flags */
    174 #define EC_WIRELESS_SWITCH_WLAN       0x01  /* WLAN radio */
    175 #define EC_WIRELESS_SWITCH_BLUETOOTH  0x02  /* Bluetooth radio */
    176 #define EC_WIRELESS_SWITCH_WWAN       0x04  /* WWAN power */
    177 #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08  /* WLAN power */
    178 
    179 /*****************************************************************************/
    180 /*
    181  * ACPI commands
    182  *
    183  * These are valid ONLY on the ACPI command/data port.
    184  */
    185 
    186 /*
    187  * ACPI Read Embedded Controller
    188  *
    189  * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
    190  *
    191  * Use the following sequence:
    192  *
    193  *    - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
    194  *    - Wait for EC_LPC_CMDR_PENDING bit to clear
    195  *    - Write address to EC_LPC_ADDR_ACPI_DATA
    196  *    - Wait for EC_LPC_CMDR_DATA bit to set
    197  *    - Read value from EC_LPC_ADDR_ACPI_DATA
    198  */
    199 #define EC_CMD_ACPI_READ 0x80
    200 
    201 /*
    202  * ACPI Write Embedded Controller
    203  *
    204  * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
    205  *
    206  * Use the following sequence:
    207  *
    208  *    - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
    209  *    - Wait for EC_LPC_CMDR_PENDING bit to clear
    210  *    - Write address to EC_LPC_ADDR_ACPI_DATA
    211  *    - Wait for EC_LPC_CMDR_PENDING bit to clear
    212  *    - Write value to EC_LPC_ADDR_ACPI_DATA
    213  */
    214 #define EC_CMD_ACPI_WRITE 0x81
    215 
    216 /*
    217  * ACPI Burst Enable Embedded Controller
    218  *
    219  * This enables burst mode on the EC to allow the host to issue several
    220  * commands back-to-back. While in this mode, writes to mapped multi-byte
    221  * data are locked out to ensure data consistency.
    222  */
    223 #define EC_CMD_ACPI_BURST_ENABLE 0x82
    224 
    225 /*
    226  * ACPI Burst Disable Embedded Controller
    227  *
    228  * This disables burst mode on the EC and stops preventing EC writes to mapped
    229  * multi-byte data.
    230  */
    231 #define EC_CMD_ACPI_BURST_DISABLE 0x83
    232 
    233 /*
    234  * ACPI Query Embedded Controller
    235  *
    236  * This clears the lowest-order bit in the currently pending host events, and
    237  * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
    238  * event 0x80000000 = 32), or 0 if no event was pending.
    239  */
    240 #define EC_CMD_ACPI_QUERY_EVENT 0x84
    241 
    242 /* Valid addresses in ACPI memory space, for read/write commands */
    243 
    244 /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
    245 #define EC_ACPI_MEM_VERSION            0x00
    246 /*
    247  * Test location; writing value here updates test compliment byte to (0xff -
    248  * value).
    249  */
    250 #define EC_ACPI_MEM_TEST               0x01
    251 /* Test compliment; writes here are ignored. */
    252 #define EC_ACPI_MEM_TEST_COMPLIMENT    0x02
    253 
    254 /* Keyboard backlight brightness percent (0 - 100) */
    255 #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
    256 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
    257 #define EC_ACPI_MEM_FAN_DUTY           0x04
    258 
    259 /*
    260  * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
    261  * independent thresholds attached to them. The current value of the ID
    262  * register determines which sensor is affected by the THRESHOLD and COMMIT
    263  * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
    264  * as the memory-mapped sensors. The COMMIT register applies those settings.
    265  *
    266  * The spec does not mandate any way to read back the threshold settings
    267  * themselves, but when a threshold is crossed the AP needs a way to determine
    268  * which sensor(s) are responsible. Each reading of the ID register clears and
    269  * returns one sensor ID that has crossed one of its threshold (in either
    270  * direction) since the last read. A value of 0xFF means "no new thresholds
    271  * have tripped". Setting or enabling the thresholds for a sensor will clear
    272  * the unread event count for that sensor.
    273  */
    274 #define EC_ACPI_MEM_TEMP_ID            0x05
    275 #define EC_ACPI_MEM_TEMP_THRESHOLD     0x06
    276 #define EC_ACPI_MEM_TEMP_COMMIT        0x07
    277 /*
    278  * Here are the bits for the COMMIT register:
    279  *   bit 0 selects the threshold index for the chosen sensor (0/1)
    280  *   bit 1 enables/disables the selected threshold (0 = off, 1 = on)
    281  * Each write to the commit register affects one threshold.
    282  */
    283 #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
    284 #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
    285 /*
    286  * Example:
    287  *
    288  * Set the thresholds for sensor 2 to 50 C and 60 C:
    289  *   write 2 to [0x05]      --  select temp sensor 2
    290  *   write 0x7b to [0x06]   --  C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
    291  *   write 0x2 to [0x07]    --  enable threshold 0 with this value
    292  *   write 0x85 to [0x06]   --  C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
    293  *   write 0x3 to [0x07]    --  enable threshold 1 with this value
    294  *
    295  * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
    296  *   write 2 to [0x05]      --  select temp sensor 2
    297  *   write 0x1 to [0x07]    --  disable threshold 1
    298  */
    299 
    300 /* DPTF battery charging current limit */
    301 #define EC_ACPI_MEM_CHARGING_LIMIT     0x08
    302 
    303 /* Charging limit is specified in 64 mA steps */
    304 #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA   64
    305 /* Value to disable DPTF battery charging limit */
    306 #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED  0xff
    307 
    308 /*
    309  * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf.  This data
    310  * is read-only from the AP.  Added in EC_ACPI_MEM_VERSION 2.
    311  */
    312 #define EC_ACPI_MEM_MAPPED_BEGIN   0x20
    313 #define EC_ACPI_MEM_MAPPED_SIZE    0xe0
    314 
    315 /* Current version of ACPI memory address space */
    316 #define EC_ACPI_MEM_VERSION_CURRENT 2
    317 
    318 
    319 /*
    320  * This header file is used in coreboot both in C and ACPI code.  The ACPI code
    321  * is pre-processed to handle constants but the ASL compiler is unable to
    322  * handle actual C code so keep it separate.
    323  */
    324 #ifndef __ACPI__
    325 
    326 /*
    327  * Define __packed if someone hasn't beat us to it.  Linux kernel style
    328  * checking prefers __packed over __attribute__((packed)).
    329  */
    330 #ifndef __packed
    331 #define __packed __attribute__((packed))
    332 #endif
    333 
    334 /* LPC command status byte masks */
    335 /* EC has written a byte in the data register and host hasn't read it yet */
    336 #define EC_LPC_STATUS_TO_HOST     0x01
    337 /* Host has written a command/data byte and the EC hasn't read it yet */
    338 #define EC_LPC_STATUS_FROM_HOST   0x02
    339 /* EC is processing a command */
    340 #define EC_LPC_STATUS_PROCESSING  0x04
    341 /* Last write to EC was a command, not data */
    342 #define EC_LPC_STATUS_LAST_CMD    0x08
    343 /* EC is in burst mode */
    344 #define EC_LPC_STATUS_BURST_MODE  0x10
    345 /* SCI event is pending (requesting SCI query) */
    346 #define EC_LPC_STATUS_SCI_PENDING 0x20
    347 /* SMI event is pending (requesting SMI query) */
    348 #define EC_LPC_STATUS_SMI_PENDING 0x40
    349 /* (reserved) */
    350 #define EC_LPC_STATUS_RESERVED    0x80
    351 
    352 /*
    353  * EC is busy.  This covers both the EC processing a command, and the host has
    354  * written a new command but the EC hasn't picked it up yet.
    355  */
    356 #define EC_LPC_STATUS_BUSY_MASK \
    357 	(EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
    358 
    359 /* Host command response codes */
    360 enum ec_status {
    361 	EC_RES_SUCCESS = 0,
    362 	EC_RES_INVALID_COMMAND = 1,
    363 	EC_RES_ERROR = 2,
    364 	EC_RES_INVALID_PARAM = 3,
    365 	EC_RES_ACCESS_DENIED = 4,
    366 	EC_RES_INVALID_RESPONSE = 5,
    367 	EC_RES_INVALID_VERSION = 6,
    368 	EC_RES_INVALID_CHECKSUM = 7,
    369 	EC_RES_IN_PROGRESS = 8,		/* Accepted, command in progress */
    370 	EC_RES_UNAVAILABLE = 9,		/* No response available */
    371 	EC_RES_TIMEOUT = 10,		/* We got a timeout */
    372 	EC_RES_OVERFLOW = 11,		/* Table / data overflow */
    373 	EC_RES_INVALID_HEADER = 12,     /* Header contains invalid data */
    374 	EC_RES_REQUEST_TRUNCATED = 13,  /* Didn't get the entire request */
    375 	EC_RES_RESPONSE_TOO_BIG = 14,   /* Response was too big to handle */
    376 	EC_RES_BUS_ERROR = 15,          /* Communications bus error */
    377 	EC_RES_BUSY = 16                /* Up but too busy.  Should retry */
    378 };
    379 
    380 /*
    381  * Host event codes.  Note these are 1-based, not 0-based, because ACPI query
    382  * EC command uses code 0 to mean "no event pending".  We explicitly specify
    383  * each value in the enum listing so they won't change if we delete/insert an
    384  * item or rearrange the list (it needs to be stable across platforms, not
    385  * just within a single compiled instance).
    386  */
    387 enum host_event_code {
    388 	EC_HOST_EVENT_LID_CLOSED = 1,
    389 	EC_HOST_EVENT_LID_OPEN = 2,
    390 	EC_HOST_EVENT_POWER_BUTTON = 3,
    391 	EC_HOST_EVENT_AC_CONNECTED = 4,
    392 	EC_HOST_EVENT_AC_DISCONNECTED = 5,
    393 	EC_HOST_EVENT_BATTERY_LOW = 6,
    394 	EC_HOST_EVENT_BATTERY_CRITICAL = 7,
    395 	EC_HOST_EVENT_BATTERY = 8,
    396 	EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
    397 	EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
    398 	EC_HOST_EVENT_THERMAL = 11,
    399 	EC_HOST_EVENT_USB_CHARGER = 12,
    400 	EC_HOST_EVENT_KEY_PRESSED = 13,
    401 	/*
    402 	 * EC has finished initializing the host interface.  The host can check
    403 	 * for this event following sending a EC_CMD_REBOOT_EC command to
    404 	 * determine when the EC is ready to accept subsequent commands.
    405 	 */
    406 	EC_HOST_EVENT_INTERFACE_READY = 14,
    407 	/* Keyboard recovery combo has been pressed */
    408 	EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
    409 
    410 	/* Shutdown due to thermal overload */
    411 	EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
    412 	/* Shutdown due to battery level too low */
    413 	EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
    414 
    415 	/* Suggest that the AP throttle itself */
    416 	EC_HOST_EVENT_THROTTLE_START = 18,
    417 	/* Suggest that the AP resume normal speed */
    418 	EC_HOST_EVENT_THROTTLE_STOP = 19,
    419 
    420 	/* Hang detect logic detected a hang and host event timeout expired */
    421 	EC_HOST_EVENT_HANG_DETECT = 20,
    422 	/* Hang detect logic detected a hang and warm rebooted the AP */
    423 	EC_HOST_EVENT_HANG_REBOOT = 21,
    424 
    425 	/* PD MCU triggering host event */
    426 	EC_HOST_EVENT_PD_MCU = 22,
    427 
    428 	/* Battery Status flags have changed */
    429 	EC_HOST_EVENT_BATTERY_STATUS = 23,
    430 
    431 	/* EC encountered a panic, triggering a reset */
    432 	EC_HOST_EVENT_PANIC = 24,
    433 
    434 	/* Keyboard fastboot combo has been pressed */
    435 	EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
    436 
    437 	/*
    438 	 * The high bit of the event mask is not used as a host event code.  If
    439 	 * it reads back as set, then the entire event mask should be
    440 	 * considered invalid by the host.  This can happen when reading the
    441 	 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
    442 	 * not initialized on the EC, or improperly configured on the host.
    443 	 */
    444 	EC_HOST_EVENT_INVALID = 32
    445 };
    446 /* Host event mask */
    447 #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
    448 
    449 /* Arguments at EC_LPC_ADDR_HOST_ARGS */
    450 struct ec_lpc_host_args {
    451 	uint8_t flags;
    452 	uint8_t command_version;
    453 	uint8_t data_size;
    454 	/*
    455 	 * Checksum; sum of command + flags + command_version + data_size +
    456 	 * all params/response data bytes.
    457 	 */
    458 	uint8_t checksum;
    459 } __packed;
    460 
    461 /* Flags for ec_lpc_host_args.flags */
    462 /*
    463  * Args are from host.  Data area at EC_LPC_ADDR_HOST_PARAM contains command
    464  * params.
    465  *
    466  * If EC gets a command and this flag is not set, this is an old-style command.
    467  * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
    468  * unknown length.  EC must respond with an old-style response (that is,
    469  * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
    470  */
    471 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
    472 /*
    473  * Args are from EC.  Data area at EC_LPC_ADDR_HOST_PARAM contains response.
    474  *
    475  * If EC responds to a command and this flag is not set, this is an old-style
    476  * response.  Command version is 0 and response data from EC is at
    477  * EC_LPC_ADDR_OLD_PARAM with unknown length.
    478  */
    479 #define EC_HOST_ARGS_FLAG_TO_HOST   0x02
    480 
    481 /*****************************************************************************/
    482 /*
    483  * Byte codes returned by EC over SPI interface.
    484  *
    485  * These can be used by the AP to debug the EC interface, and to determine
    486  * when the EC is not in a state where it will ever get around to responding
    487  * to the AP.
    488  *
    489  * Example of sequence of bytes read from EC for a current good transfer:
    490  *   1. -                  - AP asserts chip select (CS#)
    491  *   2. EC_SPI_OLD_READY   - AP sends first byte(s) of request
    492  *   3. -                  - EC starts handling CS# interrupt
    493  *   4. EC_SPI_RECEIVING   - AP sends remaining byte(s) of request
    494  *   5. EC_SPI_PROCESSING  - EC starts processing request; AP is clocking in
    495  *                           bytes looking for EC_SPI_FRAME_START
    496  *   6. -                  - EC finishes processing and sets up response
    497  *   7. EC_SPI_FRAME_START - AP reads frame byte
    498  *   8. (response packet)  - AP reads response packet
    499  *   9. EC_SPI_PAST_END    - Any additional bytes read by AP
    500  *   10 -                  - AP deasserts chip select
    501  *   11 -                  - EC processes CS# interrupt and sets up DMA for
    502  *                           next request
    503  *
    504  * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
    505  * the following byte values:
    506  *   EC_SPI_OLD_READY
    507  *   EC_SPI_RX_READY
    508  *   EC_SPI_RECEIVING
    509  *   EC_SPI_PROCESSING
    510  *
    511  * Then the EC found an error in the request, or was not ready for the request
    512  * and lost data.  The AP should give up waiting for EC_SPI_FRAME_START,
    513  * because the EC is unable to tell when the AP is done sending its request.
    514  */
    515 
    516 /*
    517  * Framing byte which precedes a response packet from the EC.  After sending a
    518  * request, the AP will clock in bytes until it sees the framing byte, then
    519  * clock in the response packet.
    520  */
    521 #define EC_SPI_FRAME_START    0xec
    522 
    523 /*
    524  * Padding bytes which are clocked out after the end of a response packet.
    525  */
    526 #define EC_SPI_PAST_END       0xed
    527 
    528 /*
    529  * EC is ready to receive, and has ignored the byte sent by the AP.  EC expects
    530  * that the AP will send a valid packet header (starting with
    531  * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
    532  */
    533 #define EC_SPI_RX_READY       0xf8
    534 
    535 /*
    536  * EC has started receiving the request from the AP, but hasn't started
    537  * processing it yet.
    538  */
    539 #define EC_SPI_RECEIVING      0xf9
    540 
    541 /* EC has received the entire request from the AP and is processing it. */
    542 #define EC_SPI_PROCESSING     0xfa
    543 
    544 /*
    545  * EC received bad data from the AP, such as a packet header with an invalid
    546  * length.  EC will ignore all data until chip select deasserts.
    547  */
    548 #define EC_SPI_RX_BAD_DATA    0xfb
    549 
    550 /*
    551  * EC received data from the AP before it was ready.  That is, the AP asserted
    552  * chip select and started clocking data before the EC was ready to receive it.
    553  * EC will ignore all data until chip select deasserts.
    554  */
    555 #define EC_SPI_NOT_READY      0xfc
    556 
    557 /*
    558  * EC was ready to receive a request from the AP.  EC has treated the byte sent
    559  * by the AP as part of a request packet, or (for old-style ECs) is processing
    560  * a fully received packet but is not ready to respond yet.
    561  */
    562 #define EC_SPI_OLD_READY      0xfd
    563 
    564 /*****************************************************************************/
    565 
    566 /*
    567  * Protocol version 2 for I2C and SPI send a request this way:
    568  *
    569  *	0	EC_CMD_VERSION0 + (command version)
    570  *	1	Command number
    571  *	2	Length of params = N
    572  *	3..N+2	Params, if any
    573  *	N+3	8-bit checksum of bytes 0..N+2
    574  *
    575  * The corresponding response is:
    576  *
    577  *	0	Result code (EC_RES_*)
    578  *	1	Length of params = M
    579  *	2..M+1	Params, if any
    580  *	M+2	8-bit checksum of bytes 0..M+1
    581  */
    582 #define EC_PROTO2_REQUEST_HEADER_BYTES 3
    583 #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
    584 #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES +	\
    585 				    EC_PROTO2_REQUEST_TRAILER_BYTES)
    586 
    587 #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
    588 #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
    589 #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES +	\
    590 				     EC_PROTO2_RESPONSE_TRAILER_BYTES)
    591 
    592 /* Parameter length was limited by the LPC interface */
    593 #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
    594 
    595 /* Maximum request and response packet sizes for protocol version 2 */
    596 #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD +	\
    597 				    EC_PROTO2_MAX_PARAM_SIZE)
    598 #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD +	\
    599 				     EC_PROTO2_MAX_PARAM_SIZE)
    600 
    601 /*****************************************************************************/
    602 
    603 /*
    604  * Value written to legacy command port / prefix byte to indicate protocol
    605  * 3+ structs are being used.  Usage is bus-dependent.
    606  */
    607 #define EC_COMMAND_PROTOCOL_3 0xda
    608 
    609 #define EC_HOST_REQUEST_VERSION 3
    610 
    611 /* Version 3 request from host */
    612 struct ec_host_request {
    613 	/* Struct version (=3)
    614 	 *
    615 	 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
    616 	 * version it doesn't know how to parse.
    617 	 */
    618 	uint8_t struct_version;
    619 
    620 	/*
    621 	 * Checksum of request and data; sum of all bytes including checksum
    622 	 * should total to 0.
    623 	 */
    624 	uint8_t checksum;
    625 
    626 	/* Command code */
    627 	uint16_t command;
    628 
    629 	/* Command version */
    630 	uint8_t command_version;
    631 
    632 	/* Unused byte in current protocol version; set to 0 */
    633 	uint8_t reserved;
    634 
    635 	/* Length of data which follows this header */
    636 	uint16_t data_len;
    637 } __packed;
    638 
    639 #define EC_HOST_RESPONSE_VERSION 3
    640 
    641 /* Version 3 response from EC */
    642 struct ec_host_response {
    643 	/* Struct version (=3) */
    644 	uint8_t struct_version;
    645 
    646 	/*
    647 	 * Checksum of response and data; sum of all bytes including checksum
    648 	 * should total to 0.
    649 	 */
    650 	uint8_t checksum;
    651 
    652 	/* Result code (EC_RES_*) */
    653 	uint16_t result;
    654 
    655 	/* Length of data which follows this header */
    656 	uint16_t data_len;
    657 
    658 	/* Unused bytes in current protocol version; set to 0 */
    659 	uint16_t reserved;
    660 } __packed;
    661 
    662 /*****************************************************************************/
    663 /*
    664  * Notes on commands:
    665  *
    666  * Each command is an 16-bit command value.  Commands which take params or
    667  * return response data specify structs for that data.  If no struct is
    668  * specified, the command does not input or output data, respectively.
    669  * Parameter/response length is implicit in the structs.  Some underlying
    670  * communication protocols (I2C, SPI) may add length or checksum headers, but
    671  * those are implementation-dependent and not defined here.
    672  */
    673 
    674 /*****************************************************************************/
    675 /* General / test commands */
    676 
    677 /*
    678  * Get protocol version, used to deal with non-backward compatible protocol
    679  * changes.
    680  */
    681 #define EC_CMD_PROTO_VERSION 0x00
    682 
    683 struct ec_response_proto_version {
    684 	uint32_t version;
    685 } __packed;
    686 
    687 /*
    688  * Hello.  This is a simple command to test the EC is responsive to
    689  * commands.
    690  */
    691 #define EC_CMD_HELLO 0x01
    692 
    693 struct ec_params_hello {
    694 	uint32_t in_data;  /* Pass anything here */
    695 } __packed;
    696 
    697 struct ec_response_hello {
    698 	uint32_t out_data;  /* Output will be in_data + 0x01020304 */
    699 } __packed;
    700 
    701 /* Get version number */
    702 #define EC_CMD_GET_VERSION 0x02
    703 
    704 enum ec_current_image {
    705 	EC_IMAGE_UNKNOWN = 0,
    706 	EC_IMAGE_RO,
    707 	EC_IMAGE_RW
    708 };
    709 
    710 struct ec_response_get_version {
    711 	/* Null-terminated version strings for RO, RW */
    712 	char version_string_ro[32];
    713 	char version_string_rw[32];
    714 	char reserved[32];       /* Was previously RW-B string */
    715 	uint32_t current_image;  /* One of ec_current_image */
    716 } __packed;
    717 
    718 /* Read test */
    719 #define EC_CMD_READ_TEST 0x03
    720 
    721 struct ec_params_read_test {
    722 	uint32_t offset;   /* Starting value for read buffer */
    723 	uint32_t size;     /* Size to read in bytes */
    724 } __packed;
    725 
    726 struct ec_response_read_test {
    727 	uint32_t data[32];
    728 } __packed;
    729 
    730 /*
    731  * Get build information
    732  *
    733  * Response is null-terminated string.
    734  */
    735 #define EC_CMD_GET_BUILD_INFO 0x04
    736 
    737 /* Get chip info */
    738 #define EC_CMD_GET_CHIP_INFO 0x05
    739 
    740 struct ec_response_get_chip_info {
    741 	/* Null-terminated strings */
    742 	char vendor[32];
    743 	char name[32];
    744 	char revision[32];  /* Mask version */
    745 } __packed;
    746 
    747 /* Get board HW version */
    748 #define EC_CMD_GET_BOARD_VERSION 0x06
    749 
    750 struct ec_response_board_version {
    751 	uint16_t board_version;  /* A monotonously incrementing number. */
    752 } __packed;
    753 
    754 /*
    755  * Read memory-mapped data.
    756  *
    757  * This is an alternate interface to memory-mapped data for bus protocols
    758  * which don't support direct-mapped memory - I2C, SPI, etc.
    759  *
    760  * Response is params.size bytes of data.
    761  */
    762 #define EC_CMD_READ_MEMMAP 0x07
    763 
    764 struct ec_params_read_memmap {
    765 	uint8_t offset;   /* Offset in memmap (EC_MEMMAP_*) */
    766 	uint8_t size;     /* Size to read in bytes */
    767 } __packed;
    768 
    769 /* Read versions supported for a command */
    770 #define EC_CMD_GET_CMD_VERSIONS 0x08
    771 
    772 struct ec_params_get_cmd_versions {
    773 	uint8_t cmd;      /* Command to check */
    774 } __packed;
    775 
    776 struct ec_params_get_cmd_versions_v1 {
    777 	uint16_t cmd;     /* Command to check */
    778 } __packed;
    779 
    780 struct ec_response_get_cmd_versions {
    781 	/*
    782 	 * Mask of supported versions; use EC_VER_MASK() to compare with a
    783 	 * desired version.
    784 	 */
    785 	uint32_t version_mask;
    786 } __packed;
    787 
    788 /*
    789  * Check EC communcations status (busy). This is needed on i2c/spi but not
    790  * on lpc since it has its own out-of-band busy indicator.
    791  *
    792  * lpc must read the status from the command register. Attempting this on
    793  * lpc will overwrite the args/parameter space and corrupt its data.
    794  */
    795 #define EC_CMD_GET_COMMS_STATUS		0x09
    796 
    797 /* Avoid using ec_status which is for return values */
    798 enum ec_comms_status {
    799 	EC_COMMS_STATUS_PROCESSING	= 1 << 0,	/* Processing cmd */
    800 };
    801 
    802 struct ec_response_get_comms_status {
    803 	uint32_t flags;		/* Mask of enum ec_comms_status */
    804 } __packed;
    805 
    806 /* Fake a variety of responses, purely for testing purposes. */
    807 #define EC_CMD_TEST_PROTOCOL		0x0a
    808 
    809 /* Tell the EC what to send back to us. */
    810 struct ec_params_test_protocol {
    811 	uint32_t ec_result;
    812 	uint32_t ret_len;
    813 	uint8_t buf[32];
    814 } __packed;
    815 
    816 /* Here it comes... */
    817 struct ec_response_test_protocol {
    818 	uint8_t buf[32];
    819 } __packed;
    820 
    821 /* Get prococol information */
    822 #define EC_CMD_GET_PROTOCOL_INFO	0x0b
    823 
    824 /* Flags for ec_response_get_protocol_info.flags */
    825 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
    826 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
    827 
    828 struct ec_response_get_protocol_info {
    829 	/* Fields which exist if at least protocol version 3 supported */
    830 
    831 	/* Bitmask of protocol versions supported (1 << n means version n)*/
    832 	uint32_t protocol_versions;
    833 
    834 	/* Maximum request packet size, in bytes */
    835 	uint16_t max_request_packet_size;
    836 
    837 	/* Maximum response packet size, in bytes */
    838 	uint16_t max_response_packet_size;
    839 
    840 	/* Flags; see EC_PROTOCOL_INFO_* */
    841 	uint32_t flags;
    842 } __packed;
    843 
    844 
    845 /*****************************************************************************/
    846 /* Get/Set miscellaneous values */
    847 
    848 /* The upper byte of .flags tells what to do (nothing means "get") */
    849 #define EC_GSV_SET        0x80000000
    850 
    851 /* The lower three bytes of .flags identifies the parameter, if that has
    852    meaning for an individual command. */
    853 #define EC_GSV_PARAM_MASK 0x00ffffff
    854 
    855 struct ec_params_get_set_value {
    856 	uint32_t flags;
    857 	uint32_t value;
    858 } __packed;
    859 
    860 struct ec_response_get_set_value {
    861 	uint32_t flags;
    862 	uint32_t value;
    863 } __packed;
    864 
    865 /* More than one command can use these structs to get/set paramters. */
    866 #define EC_CMD_GSV_PAUSE_IN_S5	0x0c
    867 /*      EC_CMD_GSV_BOOT_ON_AC   0xa3 (defined below) */
    868 
    869 /*****************************************************************************/
    870 /* List the features supported by the firmware */
    871 #define EC_CMD_GET_FEATURES  0x0d
    872 
    873 /* Supported features */
    874 enum ec_feature_code {
    875 	/*
    876 	 * This image contains a limited set of features. Another image
    877 	 * in RW partition may support more features.
    878 	 */
    879 	EC_FEATURE_LIMITED = 0,
    880 	/*
    881 	 * Commands for probing/reading/writing/erasing the flash in the
    882 	 * EC are present.
    883 	 */
    884 	EC_FEATURE_FLASH = 1,
    885 	/*
    886 	 * Can control the fan speed directly.
    887 	 */
    888 	EC_FEATURE_PWM_FAN = 2,
    889 	/*
    890 	 * Can control the intensity of the keyboard backlight.
    891 	 */
    892 	EC_FEATURE_PWM_KEYB = 3,
    893 	/*
    894 	 * Support Google lightbar, introduced on Pixel.
    895 	 */
    896 	EC_FEATURE_LIGHTBAR = 4,
    897 	/* Control of LEDs  */
    898 	EC_FEATURE_LED = 5,
    899 	/* Exposes an interface to control gyro and sensors.
    900 	 * The host goes through the EC to access these sensors.
    901 	 * In addition, the EC may provide composite sensors, like lid angle.
    902 	 */
    903 	EC_FEATURE_MOTION_SENSE = 6,
    904 	/* The keyboard is controlled by the EC */
    905 	EC_FEATURE_KEYB = 7,
    906 	/* The AP can use part of the EC flash as persistent storage. */
    907 	EC_FEATURE_PSTORE = 8,
    908 	/* The EC monitors BIOS port 80h, and can return POST codes. */
    909 	EC_FEATURE_PORT80 = 9,
    910 	/*
    911 	 * Thermal management: include TMP specific commands.
    912 	 * Higher level than direct fan control.
    913 	 */
    914 	EC_FEATURE_THERMAL = 10,
    915 	/* Can switch the screen backlight on/off */
    916 	EC_FEATURE_BKLIGHT_SWITCH = 11,
    917 	/* Can switch the wifi module on/off */
    918 	EC_FEATURE_WIFI_SWITCH = 12,
    919 	/* Monitor host events, through for example SMI or SCI */
    920 	EC_FEATURE_HOST_EVENTS = 13,
    921 	/* The EC exposes GPIO commands to control/monitor connected devices. */
    922 	EC_FEATURE_GPIO = 14,
    923 	/* The EC can send i2c messages to downstream devices. */
    924 	EC_FEATURE_I2C = 15,
    925 	/* Command to control charger are included */
    926 	EC_FEATURE_CHARGER = 16,
    927 	/* Simple battery support. */
    928 	EC_FEATURE_BATTERY = 17,
    929 	/*
    930 	 * Support Smart battery protocol
    931 	 * (Common Smart Battery System Interface Specification)
    932 	 */
    933 	EC_FEATURE_SMART_BATTERY = 18,
    934 	/* EC can dectect when the host hangs. */
    935 	EC_FEATURE_HANG_DETECT = 19,
    936 	/* Report power information, for pit only */
    937 	EC_FEATURE_PMU = 20,
    938 	/* Another Cros EC device is present downstream of this one */
    939 	EC_FEATURE_SUB_MCU = 21,
    940 	/* Support USB Power delivery (PD) commands */
    941 	EC_FEATURE_USB_PD = 22,
    942 	/* Control USB multiplexer, for audio through USB port for instance. */
    943 	EC_FEATURE_USB_MUX = 23,
    944 	/* Motion Sensor code has an internal software FIFO */
    945 	EC_FEATURE_MOTION_SENSE_FIFO = 24,
    946 	/* Support enabling/disabling booting the system on AC plug event */
    947 	EC_FEATURE_BOOT_ON_AC = 25,
    948 };
    949 
    950 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
    951 #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
    952 struct ec_response_get_features {
    953 	uint32_t flags[2];
    954 } __packed;
    955 
    956 /*****************************************************************************/
    957 /* Flash commands */
    958 
    959 /* Get flash info */
    960 #define EC_CMD_FLASH_INFO 0x10
    961 
    962 /* Version 0 returns these fields */
    963 struct ec_response_flash_info {
    964 	/* Usable flash size, in bytes */
    965 	uint32_t flash_size;
    966 	/*
    967 	 * Write block size.  Write offset and size must be a multiple
    968 	 * of this.
    969 	 */
    970 	uint32_t write_block_size;
    971 	/*
    972 	 * Erase block size.  Erase offset and size must be a multiple
    973 	 * of this.
    974 	 */
    975 	uint32_t erase_block_size;
    976 	/*
    977 	 * Protection block size.  Protection offset and size must be a
    978 	 * multiple of this.
    979 	 */
    980 	uint32_t protect_block_size;
    981 } __packed;
    982 
    983 /* Flags for version 1+ flash info command */
    984 /* EC flash erases bits to 0 instead of 1 */
    985 #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
    986 
    987 /*
    988  * Version 1 returns the same initial fields as version 0, with additional
    989  * fields following.
    990  *
    991  * gcc anonymous structs don't seem to get along with the __packed directive;
    992  * if they did we'd define the version 0 struct as a sub-struct of this one.
    993  */
    994 struct ec_response_flash_info_1 {
    995 	/* Version 0 fields; see above for description */
    996 	uint32_t flash_size;
    997 	uint32_t write_block_size;
    998 	uint32_t erase_block_size;
    999 	uint32_t protect_block_size;
   1000 
   1001 	/* Version 1 adds these fields: */
   1002 	/*
   1003 	 * Ideal write size in bytes.  Writes will be fastest if size is
   1004 	 * exactly this and offset is a multiple of this.  For example, an EC
   1005 	 * may have a write buffer which can do half-page operations if data is
   1006 	 * aligned, and a slower word-at-a-time write mode.
   1007 	 */
   1008 	uint32_t write_ideal_size;
   1009 
   1010 	/* Flags; see EC_FLASH_INFO_* */
   1011 	uint32_t flags;
   1012 } __packed;
   1013 
   1014 /*
   1015  * Read flash
   1016  *
   1017  * Response is params.size bytes of data.
   1018  */
   1019 #define EC_CMD_FLASH_READ 0x11
   1020 
   1021 struct ec_params_flash_read {
   1022 	uint32_t offset;   /* Byte offset to read */
   1023 	uint32_t size;     /* Size to read in bytes */
   1024 } __packed;
   1025 
   1026 /* Write flash */
   1027 #define EC_CMD_FLASH_WRITE 0x12
   1028 #define EC_VER_FLASH_WRITE 1
   1029 
   1030 /* Version 0 of the flash command supported only 64 bytes of data */
   1031 #define EC_FLASH_WRITE_VER0_SIZE 64
   1032 
   1033 struct ec_params_flash_write {
   1034 	uint32_t offset;   /* Byte offset to write */
   1035 	uint32_t size;     /* Size to write in bytes */
   1036 	/* Followed by data to write */
   1037 } __packed;
   1038 
   1039 /* Erase flash */
   1040 #define EC_CMD_FLASH_ERASE 0x13
   1041 
   1042 struct ec_params_flash_erase {
   1043 	uint32_t offset;   /* Byte offset to erase */
   1044 	uint32_t size;     /* Size to erase in bytes */
   1045 } __packed;
   1046 
   1047 /*
   1048  * Get/set flash protection.
   1049  *
   1050  * If mask!=0, sets/clear the requested bits of flags.  Depending on the
   1051  * firmware write protect GPIO, not all flags will take effect immediately;
   1052  * some flags require a subsequent hard reset to take effect.  Check the
   1053  * returned flags bits to see what actually happened.
   1054  *
   1055  * If mask=0, simply returns the current flags state.
   1056  */
   1057 #define EC_CMD_FLASH_PROTECT 0x15
   1058 #define EC_VER_FLASH_PROTECT 1  /* Command version 1 */
   1059 
   1060 /* Flags for flash protection */
   1061 /* RO flash code protected when the EC boots */
   1062 #define EC_FLASH_PROTECT_RO_AT_BOOT         (1 << 0)
   1063 /*
   1064  * RO flash code protected now.  If this bit is set, at-boot status cannot
   1065  * be changed.
   1066  */
   1067 #define EC_FLASH_PROTECT_RO_NOW             (1 << 1)
   1068 /* Entire flash code protected now, until reboot. */
   1069 #define EC_FLASH_PROTECT_ALL_NOW            (1 << 2)
   1070 /* Flash write protect GPIO is asserted now */
   1071 #define EC_FLASH_PROTECT_GPIO_ASSERTED      (1 << 3)
   1072 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
   1073 #define EC_FLASH_PROTECT_ERROR_STUCK        (1 << 4)
   1074 /*
   1075  * Error - flash protection is in inconsistent state.  At least one bank of
   1076  * flash which should be protected is not protected.  Usually fixed by
   1077  * re-requesting the desired flags, or by a hard reset if that fails.
   1078  */
   1079 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
   1080 /* Entire flash code protected when the EC boots */
   1081 #define EC_FLASH_PROTECT_ALL_AT_BOOT        (1 << 6)
   1082 
   1083 struct ec_params_flash_protect {
   1084 	uint32_t mask;   /* Bits in flags to apply */
   1085 	uint32_t flags;  /* New flags to apply */
   1086 } __packed;
   1087 
   1088 struct ec_response_flash_protect {
   1089 	/* Current value of flash protect flags */
   1090 	uint32_t flags;
   1091 	/*
   1092 	 * Flags which are valid on this platform.  This allows the caller
   1093 	 * to distinguish between flags which aren't set vs. flags which can't
   1094 	 * be set on this platform.
   1095 	 */
   1096 	uint32_t valid_flags;
   1097 	/* Flags which can be changed given the current protection state */
   1098 	uint32_t writable_flags;
   1099 } __packed;
   1100 
   1101 /*
   1102  * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
   1103  * write protect.  These commands may be reused with version > 0.
   1104  */
   1105 
   1106 /* Get the region offset/size */
   1107 #define EC_CMD_FLASH_REGION_INFO 0x16
   1108 #define EC_VER_FLASH_REGION_INFO 1
   1109 
   1110 enum ec_flash_region {
   1111 	/* Region which holds read-only EC image */
   1112 	EC_FLASH_REGION_RO = 0,
   1113 	/* Region which holds rewritable EC image */
   1114 	EC_FLASH_REGION_RW,
   1115 	/*
   1116 	 * Region which should be write-protected in the factory (a superset of
   1117 	 * EC_FLASH_REGION_RO)
   1118 	 */
   1119 	EC_FLASH_REGION_WP_RO,
   1120 	/* Number of regions */
   1121 	EC_FLASH_REGION_COUNT,
   1122 };
   1123 
   1124 struct ec_params_flash_region_info {
   1125 	uint32_t region;  /* enum ec_flash_region */
   1126 } __packed;
   1127 
   1128 struct ec_response_flash_region_info {
   1129 	uint32_t offset;
   1130 	uint32_t size;
   1131 } __packed;
   1132 
   1133 /* Read/write VbNvContext */
   1134 #define EC_CMD_VBNV_CONTEXT 0x17
   1135 #define EC_VER_VBNV_CONTEXT 1
   1136 #define EC_VBNV_BLOCK_SIZE 16
   1137 
   1138 enum ec_vbnvcontext_op {
   1139 	EC_VBNV_CONTEXT_OP_READ,
   1140 	EC_VBNV_CONTEXT_OP_WRITE,
   1141 };
   1142 
   1143 struct ec_params_vbnvcontext {
   1144 	uint32_t op;
   1145 	uint8_t block[EC_VBNV_BLOCK_SIZE];
   1146 } __packed;
   1147 
   1148 struct ec_response_vbnvcontext {
   1149 	uint8_t block[EC_VBNV_BLOCK_SIZE];
   1150 } __packed;
   1151 
   1152 /*****************************************************************************/
   1153 /* PWM commands */
   1154 
   1155 /* Get fan target RPM */
   1156 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
   1157 
   1158 struct ec_response_pwm_get_fan_rpm {
   1159 	uint32_t rpm;
   1160 } __packed;
   1161 
   1162 /* Set target fan RPM */
   1163 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
   1164 
   1165 /* Version 0 of input params */
   1166 struct ec_params_pwm_set_fan_target_rpm_v0 {
   1167 	uint32_t rpm;
   1168 } __packed;
   1169 
   1170 /* Version 1 of input params */
   1171 struct ec_params_pwm_set_fan_target_rpm_v1 {
   1172 	uint32_t rpm;
   1173 	uint8_t fan_idx;
   1174 } __packed;
   1175 
   1176 /* Get keyboard backlight */
   1177 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
   1178 
   1179 struct ec_response_pwm_get_keyboard_backlight {
   1180 	uint8_t percent;
   1181 	uint8_t enabled;
   1182 } __packed;
   1183 
   1184 /* Set keyboard backlight */
   1185 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
   1186 
   1187 struct ec_params_pwm_set_keyboard_backlight {
   1188 	uint8_t percent;
   1189 } __packed;
   1190 
   1191 /* Set target fan PWM duty cycle */
   1192 #define EC_CMD_PWM_SET_FAN_DUTY 0x24
   1193 
   1194 /* Version 0 of input params */
   1195 struct ec_params_pwm_set_fan_duty_v0 {
   1196 	uint32_t percent;
   1197 } __packed;
   1198 
   1199 /* Version 1 of input params */
   1200 struct ec_params_pwm_set_fan_duty_v1 {
   1201 	uint32_t percent;
   1202 	uint8_t fan_idx;
   1203 } __packed;
   1204 
   1205 /*****************************************************************************/
   1206 /*
   1207  * Lightbar commands. This looks worse than it is. Since we only use one HOST
   1208  * command to say "talk to the lightbar", we put the "and tell it to do X" part
   1209  * into a subcommand. We'll make separate structs for subcommands with
   1210  * different input args, so that we know how much to expect.
   1211  */
   1212 #define EC_CMD_LIGHTBAR_CMD 0x28
   1213 
   1214 struct rgb_s {
   1215 	uint8_t r, g, b;
   1216 };
   1217 
   1218 #define LB_BATTERY_LEVELS 4
   1219 /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
   1220  * host command, but the alignment is the same regardless. Keep it that way.
   1221  */
   1222 struct lightbar_params_v0 {
   1223 	/* Timing */
   1224 	int32_t google_ramp_up;
   1225 	int32_t google_ramp_down;
   1226 	int32_t s3s0_ramp_up;
   1227 	int32_t s0_tick_delay[2];		/* AC=0/1 */
   1228 	int32_t s0a_tick_delay[2];		/* AC=0/1 */
   1229 	int32_t s0s3_ramp_down;
   1230 	int32_t s3_sleep_for;
   1231 	int32_t s3_ramp_up;
   1232 	int32_t s3_ramp_down;
   1233 
   1234 	/* Oscillation */
   1235 	uint8_t new_s0;
   1236 	uint8_t osc_min[2];			/* AC=0/1 */
   1237 	uint8_t osc_max[2];			/* AC=0/1 */
   1238 	uint8_t w_ofs[2];			/* AC=0/1 */
   1239 
   1240 	/* Brightness limits based on the backlight and AC. */
   1241 	uint8_t bright_bl_off_fixed[2];		/* AC=0/1 */
   1242 	uint8_t bright_bl_on_min[2];		/* AC=0/1 */
   1243 	uint8_t bright_bl_on_max[2];		/* AC=0/1 */
   1244 
   1245 	/* Battery level thresholds */
   1246 	uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
   1247 
   1248 	/* Map [AC][battery_level] to color index */
   1249 	uint8_t s0_idx[2][LB_BATTERY_LEVELS];	/* AP is running */
   1250 	uint8_t s3_idx[2][LB_BATTERY_LEVELS];	/* AP is sleeping */
   1251 
   1252 	/* Color palette */
   1253 	struct rgb_s color[8];			/* 0-3 are Google colors */
   1254 } __packed;
   1255 
   1256 struct lightbar_params_v1 {
   1257 	/* Timing */
   1258 	int32_t google_ramp_up;
   1259 	int32_t google_ramp_down;
   1260 	int32_t s3s0_ramp_up;
   1261 	int32_t s0_tick_delay[2];		/* AC=0/1 */
   1262 	int32_t s0a_tick_delay[2];		/* AC=0/1 */
   1263 	int32_t s0s3_ramp_down;
   1264 	int32_t s3_sleep_for;
   1265 	int32_t s3_ramp_up;
   1266 	int32_t s3_ramp_down;
   1267 	int32_t s5_ramp_up;
   1268 	int32_t s5_ramp_down;
   1269 	int32_t tap_tick_delay;
   1270 	int32_t tap_gate_delay;
   1271 	int32_t tap_display_time;
   1272 
   1273 	/* Tap-for-battery params */
   1274 	uint8_t tap_pct_red;
   1275 	uint8_t tap_pct_green;
   1276 	uint8_t tap_seg_min_on;
   1277 	uint8_t tap_seg_max_on;
   1278 	uint8_t tap_seg_osc;
   1279 	uint8_t tap_idx[3];
   1280 
   1281 	/* Oscillation */
   1282 	uint8_t osc_min[2];			/* AC=0/1 */
   1283 	uint8_t osc_max[2];			/* AC=0/1 */
   1284 	uint8_t w_ofs[2];			/* AC=0/1 */
   1285 
   1286 	/* Brightness limits based on the backlight and AC. */
   1287 	uint8_t bright_bl_off_fixed[2];		/* AC=0/1 */
   1288 	uint8_t bright_bl_on_min[2];		/* AC=0/1 */
   1289 	uint8_t bright_bl_on_max[2];		/* AC=0/1 */
   1290 
   1291 	/* Battery level thresholds */
   1292 	uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
   1293 
   1294 	/* Map [AC][battery_level] to color index */
   1295 	uint8_t s0_idx[2][LB_BATTERY_LEVELS];	/* AP is running */
   1296 	uint8_t s3_idx[2][LB_BATTERY_LEVELS];	/* AP is sleeping */
   1297 
   1298 	/* s5: single color pulse on inhibited power-up */
   1299 	uint8_t s5_idx;
   1300 
   1301 	/* Color palette */
   1302 	struct rgb_s color[8];			/* 0-3 are Google colors */
   1303 } __packed;
   1304 
   1305 /* Lightbar command params v2
   1306  * crbug.com/467716
   1307  *
   1308  * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
   1309  * logical groups to make it more manageable ( < 120 bytes).
   1310  *
   1311  * NOTE: Each of these groups must be less than 120 bytes.
   1312  */
   1313 
   1314 struct lightbar_params_v2_timing {
   1315 	/* Timing */
   1316 	int32_t google_ramp_up;
   1317 	int32_t google_ramp_down;
   1318 	int32_t s3s0_ramp_up;
   1319 	int32_t s0_tick_delay[2];		/* AC=0/1 */
   1320 	int32_t s0a_tick_delay[2];		/* AC=0/1 */
   1321 	int32_t s0s3_ramp_down;
   1322 	int32_t s3_sleep_for;
   1323 	int32_t s3_ramp_up;
   1324 	int32_t s3_ramp_down;
   1325 	int32_t s5_ramp_up;
   1326 	int32_t s5_ramp_down;
   1327 	int32_t tap_tick_delay;
   1328 	int32_t tap_gate_delay;
   1329 	int32_t tap_display_time;
   1330 } __packed;
   1331 
   1332 struct lightbar_params_v2_tap {
   1333 	/* Tap-for-battery params */
   1334 	uint8_t tap_pct_red;
   1335 	uint8_t tap_pct_green;
   1336 	uint8_t tap_seg_min_on;
   1337 	uint8_t tap_seg_max_on;
   1338 	uint8_t tap_seg_osc;
   1339 	uint8_t tap_idx[3];
   1340 } __packed;
   1341 
   1342 struct lightbar_params_v2_oscillation {
   1343 	/* Oscillation */
   1344 	uint8_t osc_min[2];			/* AC=0/1 */
   1345 	uint8_t osc_max[2];			/* AC=0/1 */
   1346 	uint8_t w_ofs[2];			/* AC=0/1 */
   1347 } __packed;
   1348 
   1349 struct lightbar_params_v2_brightness {
   1350 	/* Brightness limits based on the backlight and AC. */
   1351 	uint8_t bright_bl_off_fixed[2];		/* AC=0/1 */
   1352 	uint8_t bright_bl_on_min[2];		/* AC=0/1 */
   1353 	uint8_t bright_bl_on_max[2];		/* AC=0/1 */
   1354 } __packed;
   1355 
   1356 struct lightbar_params_v2_thresholds {
   1357 	/* Battery level thresholds */
   1358 	uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
   1359 } __packed;
   1360 
   1361 struct lightbar_params_v2_colors {
   1362 	/* Map [AC][battery_level] to color index */
   1363 	uint8_t s0_idx[2][LB_BATTERY_LEVELS];	/* AP is running */
   1364 	uint8_t s3_idx[2][LB_BATTERY_LEVELS];	/* AP is sleeping */
   1365 
   1366 	/* s5: single color pulse on inhibited power-up */
   1367 	uint8_t s5_idx;
   1368 
   1369 	/* Color palette */
   1370 	struct rgb_s color[8];			/* 0-3 are Google colors */
   1371 } __packed;
   1372 
   1373 /* Lightbyte program. */
   1374 #define EC_LB_PROG_LEN 192
   1375 struct lightbar_program {
   1376 	uint8_t size;
   1377 	uint8_t data[EC_LB_PROG_LEN];
   1378 };
   1379 
   1380 struct ec_params_lightbar {
   1381 	uint8_t cmd;		      /* Command (see enum lightbar_command) */
   1382 	union {
   1383 		struct {
   1384 			/* no args */
   1385 		} dump, off, on, init, get_seq, get_params_v0, get_params_v1,
   1386 			version, get_brightness, get_demo, suspend, resume,
   1387 			get_params_v2_timing, get_params_v2_tap,
   1388 			get_params_v2_osc, get_params_v2_bright,
   1389 			get_params_v2_thlds, get_params_v2_colors;
   1390 
   1391 		struct {
   1392 			uint8_t num;
   1393 		} set_brightness, seq, demo;
   1394 
   1395 		struct {
   1396 			uint8_t ctrl, reg, value;
   1397 		} reg;
   1398 
   1399 		struct {
   1400 			uint8_t led, red, green, blue;
   1401 		} set_rgb;
   1402 
   1403 		struct {
   1404 			uint8_t led;
   1405 		} get_rgb;
   1406 
   1407 		struct {
   1408 			uint8_t enable;
   1409 		} manual_suspend_ctrl;
   1410 
   1411 		struct lightbar_params_v0 set_params_v0;
   1412 		struct lightbar_params_v1 set_params_v1;
   1413 
   1414 		struct lightbar_params_v2_timing set_v2par_timing;
   1415 		struct lightbar_params_v2_tap set_v2par_tap;
   1416 		struct lightbar_params_v2_oscillation set_v2par_osc;
   1417 		struct lightbar_params_v2_brightness set_v2par_bright;
   1418 		struct lightbar_params_v2_thresholds set_v2par_thlds;
   1419 		struct lightbar_params_v2_colors set_v2par_colors;
   1420 
   1421 		struct lightbar_program set_program;
   1422 	};
   1423 } __packed;
   1424 
   1425 struct ec_response_lightbar {
   1426 	union {
   1427 		struct {
   1428 			struct {
   1429 				uint8_t reg;
   1430 				uint8_t ic0;
   1431 				uint8_t ic1;
   1432 			} vals[23];
   1433 		} dump;
   1434 
   1435 		struct  {
   1436 			uint8_t num;
   1437 		} get_seq, get_brightness, get_demo;
   1438 
   1439 		struct lightbar_params_v0 get_params_v0;
   1440 		struct lightbar_params_v1 get_params_v1;
   1441 
   1442 
   1443 		struct lightbar_params_v2_timing get_params_v2_timing;
   1444 		struct lightbar_params_v2_tap get_params_v2_tap;
   1445 		struct lightbar_params_v2_oscillation get_params_v2_osc;
   1446 		struct lightbar_params_v2_brightness get_params_v2_bright;
   1447 		struct lightbar_params_v2_thresholds get_params_v2_thlds;
   1448 		struct lightbar_params_v2_colors get_params_v2_colors;
   1449 
   1450 		struct {
   1451 			uint32_t num;
   1452 			uint32_t flags;
   1453 		} version;
   1454 
   1455 		struct {
   1456 			uint8_t red, green, blue;
   1457 		} get_rgb;
   1458 
   1459 		struct {
   1460 			/* no return params */
   1461 		} off, on, init, set_brightness, seq, reg, set_rgb,
   1462 			demo, set_params_v0, set_params_v1,
   1463 			set_program, manual_suspend_ctrl, suspend, resume,
   1464 			set_v2par_timing, set_v2par_tap,
   1465 			set_v2par_osc, set_v2par_bright, set_v2par_thlds,
   1466 			set_v2par_colors;
   1467 	};
   1468 } __packed;
   1469 
   1470 /* Lightbar commands */
   1471 enum lightbar_command {
   1472 	LIGHTBAR_CMD_DUMP = 0,
   1473 	LIGHTBAR_CMD_OFF = 1,
   1474 	LIGHTBAR_CMD_ON = 2,
   1475 	LIGHTBAR_CMD_INIT = 3,
   1476 	LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
   1477 	LIGHTBAR_CMD_SEQ = 5,
   1478 	LIGHTBAR_CMD_REG = 6,
   1479 	LIGHTBAR_CMD_SET_RGB = 7,
   1480 	LIGHTBAR_CMD_GET_SEQ = 8,
   1481 	LIGHTBAR_CMD_DEMO = 9,
   1482 	LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
   1483 	LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
   1484 	LIGHTBAR_CMD_VERSION = 12,
   1485 	LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
   1486 	LIGHTBAR_CMD_GET_RGB = 14,
   1487 	LIGHTBAR_CMD_GET_DEMO = 15,
   1488 	LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
   1489 	LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
   1490 	LIGHTBAR_CMD_SET_PROGRAM = 18,
   1491 	LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
   1492 	LIGHTBAR_CMD_SUSPEND = 20,
   1493 	LIGHTBAR_CMD_RESUME = 21,
   1494 	LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
   1495 	LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
   1496 	LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
   1497 	LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
   1498 	LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
   1499 	LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
   1500 	LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
   1501 	LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
   1502 	LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
   1503 	LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
   1504 	LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
   1505 	LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
   1506 	LIGHTBAR_NUM_CMDS
   1507 };
   1508 
   1509 /*****************************************************************************/
   1510 /* LED control commands */
   1511 
   1512 #define EC_CMD_LED_CONTROL 0x29
   1513 
   1514 enum ec_led_id {
   1515 	/* LED to indicate battery state of charge */
   1516 	EC_LED_ID_BATTERY_LED = 0,
   1517 	/*
   1518 	 * LED to indicate system power state (on or in suspend).
   1519 	 * May be on power button or on C-panel.
   1520 	 */
   1521 	EC_LED_ID_POWER_LED,
   1522 	/* LED on power adapter or its plug */
   1523 	EC_LED_ID_ADAPTER_LED,
   1524 
   1525 	EC_LED_ID_COUNT
   1526 };
   1527 
   1528 /* LED control flags */
   1529 #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
   1530 #define EC_LED_FLAGS_AUTO  (1 << 1) /* Switch LED back to automatic control */
   1531 
   1532 enum ec_led_colors {
   1533 	EC_LED_COLOR_RED = 0,
   1534 	EC_LED_COLOR_GREEN,
   1535 	EC_LED_COLOR_BLUE,
   1536 	EC_LED_COLOR_YELLOW,
   1537 	EC_LED_COLOR_WHITE,
   1538 
   1539 	EC_LED_COLOR_COUNT
   1540 };
   1541 
   1542 struct ec_params_led_control {
   1543 	uint8_t led_id;     /* Which LED to control */
   1544 	uint8_t flags;      /* Control flags */
   1545 
   1546 	uint8_t brightness[EC_LED_COLOR_COUNT];
   1547 } __packed;
   1548 
   1549 struct ec_response_led_control {
   1550 	/*
   1551 	 * Available brightness value range.
   1552 	 *
   1553 	 * Range 0 means color channel not present.
   1554 	 * Range 1 means on/off control.
   1555 	 * Other values means the LED is control by PWM.
   1556 	 */
   1557 	uint8_t brightness_range[EC_LED_COLOR_COUNT];
   1558 } __packed;
   1559 
   1560 /*****************************************************************************/
   1561 /* Verified boot commands */
   1562 
   1563 /*
   1564  * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
   1565  * reused for other purposes with version > 0.
   1566  */
   1567 
   1568 /* Verified boot hash command */
   1569 #define EC_CMD_VBOOT_HASH 0x2a
   1570 
   1571 struct ec_params_vboot_hash {
   1572 	uint8_t cmd;             /* enum ec_vboot_hash_cmd */
   1573 	uint8_t hash_type;       /* enum ec_vboot_hash_type */
   1574 	uint8_t nonce_size;      /* Nonce size; may be 0 */
   1575 	uint8_t reserved0;       /* Reserved; set 0 */
   1576 	uint32_t offset;         /* Offset in flash to hash */
   1577 	uint32_t size;           /* Number of bytes to hash */
   1578 	uint8_t nonce_data[64];  /* Nonce data; ignored if nonce_size=0 */
   1579 } __packed;
   1580 
   1581 struct ec_response_vboot_hash {
   1582 	uint8_t status;          /* enum ec_vboot_hash_status */
   1583 	uint8_t hash_type;       /* enum ec_vboot_hash_type */
   1584 	uint8_t digest_size;     /* Size of hash digest in bytes */
   1585 	uint8_t reserved0;       /* Ignore; will be 0 */
   1586 	uint32_t offset;         /* Offset in flash which was hashed */
   1587 	uint32_t size;           /* Number of bytes hashed */
   1588 	uint8_t hash_digest[64]; /* Hash digest data */
   1589 } __packed;
   1590 
   1591 enum ec_vboot_hash_cmd {
   1592 	EC_VBOOT_HASH_GET = 0,       /* Get current hash status */
   1593 	EC_VBOOT_HASH_ABORT = 1,     /* Abort calculating current hash */
   1594 	EC_VBOOT_HASH_START = 2,     /* Start computing a new hash */
   1595 	EC_VBOOT_HASH_RECALC = 3,    /* Synchronously compute a new hash */
   1596 };
   1597 
   1598 enum ec_vboot_hash_type {
   1599 	EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
   1600 };
   1601 
   1602 enum ec_vboot_hash_status {
   1603 	EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
   1604 	EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
   1605 	EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
   1606 };
   1607 
   1608 /*
   1609  * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
   1610  * If one of these is specified, the EC will automatically update offset and
   1611  * size to the correct values for the specified image (RO or RW).
   1612  */
   1613 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
   1614 #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
   1615 
   1616 /*****************************************************************************/
   1617 /*
   1618  * Motion sense commands. We'll make separate structs for sub-commands with
   1619  * different input args, so that we know how much to expect.
   1620  */
   1621 #define EC_CMD_MOTION_SENSE_CMD 0x2b
   1622 
   1623 /* Motion sense commands */
   1624 enum motionsense_command {
   1625 	/*
   1626 	 * Dump command returns all motion sensor data including motion sense
   1627 	 * module flags and individual sensor flags.
   1628 	 */
   1629 	MOTIONSENSE_CMD_DUMP = 0,
   1630 
   1631 	/*
   1632 	 * Info command returns data describing the details of a given sensor,
   1633 	 * including enum motionsensor_type, enum motionsensor_location, and
   1634 	 * enum motionsensor_chip.
   1635 	 */
   1636 	MOTIONSENSE_CMD_INFO = 1,
   1637 
   1638 	/*
   1639 	 * EC Rate command is a setter/getter command for the EC sampling rate
   1640 	 * in milliseconds.
   1641 	 * It is per sensor, the EC run sample task  at the minimum of all
   1642 	 * sensors EC_RATE.
   1643 	 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
   1644 	 * to collect all the sensor samples.
   1645 	 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
   1646 	 * to process of all motion sensors in milliseconds.
   1647 	 */
   1648 	MOTIONSENSE_CMD_EC_RATE = 2,
   1649 
   1650 	/*
   1651 	 * Sensor ODR command is a setter/getter command for the output data
   1652 	 * rate of a specific motion sensor in millihertz.
   1653 	 */
   1654 	MOTIONSENSE_CMD_SENSOR_ODR = 3,
   1655 
   1656 	/*
   1657 	 * Sensor range command is a setter/getter command for the range of
   1658 	 * a specified motion sensor in +/-G's or +/- deg/s.
   1659 	 */
   1660 	MOTIONSENSE_CMD_SENSOR_RANGE = 4,
   1661 
   1662 	/*
   1663 	 * Setter/getter command for the keyboard wake angle. When the lid
   1664 	 * angle is greater than this value, keyboard wake is disabled in S3,
   1665 	 * and when the lid angle goes less than this value, keyboard wake is
   1666 	 * enabled. Note, the lid angle measurement is an approximate,
   1667 	 * un-calibrated value, hence the wake angle isn't exact.
   1668 	 */
   1669 	MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
   1670 
   1671 	/*
   1672 	 * Returns a single sensor data.
   1673 	 */
   1674 	MOTIONSENSE_CMD_DATA = 6,
   1675 
   1676 	/*
   1677 	 * Return sensor fifo info.
   1678 	 */
   1679 	MOTIONSENSE_CMD_FIFO_INFO = 7,
   1680 
   1681 	/*
   1682 	 * Insert a flush element in the fifo and return sensor fifo info.
   1683 	 * The host can use that element to synchronize its operation.
   1684 	 */
   1685 	MOTIONSENSE_CMD_FIFO_FLUSH = 8,
   1686 
   1687 	/*
   1688 	 * Return a portion of the fifo.
   1689 	 */
   1690 	MOTIONSENSE_CMD_FIFO_READ = 9,
   1691 
   1692 	/*
   1693 	 * Perform low level calibration.
   1694 	 * On sensors that support it, ask to do offset calibration.
   1695 	 */
   1696 	MOTIONSENSE_CMD_PERFORM_CALIB = 10,
   1697 
   1698 	/*
   1699 	 * Sensor Offset command is a setter/getter command for the offset
   1700 	 * used for calibration.
   1701 	 * The offsets can be calculated by the host, or via
   1702 	 * PERFORM_CALIB command.
   1703 	 */
   1704 	MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
   1705 
   1706 	/* Number of motionsense sub-commands. */
   1707 	MOTIONSENSE_NUM_CMDS
   1708 };
   1709 
   1710 /* List of motion sensor types. */
   1711 enum motionsensor_type {
   1712 	MOTIONSENSE_TYPE_ACCEL = 0,
   1713 	MOTIONSENSE_TYPE_GYRO = 1,
   1714 	MOTIONSENSE_TYPE_MAG = 2,
   1715 	MOTIONSENSE_TYPE_PROX = 3,
   1716 	MOTIONSENSE_TYPE_LIGHT = 4,
   1717 	MOTIONSENSE_TYPE_MAX,
   1718 };
   1719 
   1720 /* List of motion sensor locations. */
   1721 enum motionsensor_location {
   1722 	MOTIONSENSE_LOC_BASE = 0,
   1723 	MOTIONSENSE_LOC_LID = 1,
   1724 	MOTIONSENSE_LOC_MAX,
   1725 };
   1726 
   1727 /* List of motion sensor chips. */
   1728 enum motionsensor_chip {
   1729 	MOTIONSENSE_CHIP_KXCJ9 = 0,
   1730 	MOTIONSENSE_CHIP_LSM6DS0 = 1,
   1731 	MOTIONSENSE_CHIP_BMI160 = 2,
   1732 	MOTIONSENSE_CHIP_SI1141 = 3,
   1733 	MOTIONSENSE_CHIP_SI1142 = 4,
   1734 	MOTIONSENSE_CHIP_SI1143 = 5,
   1735 };
   1736 
   1737 struct ec_response_motion_sensor_data {
   1738 	/* Flags for each sensor. */
   1739 	uint8_t flags;
   1740 	/* sensor number the data comes from */
   1741 	uint8_t sensor_num;
   1742 	/* Each sensor is up to 3-axis. */
   1743 	union {
   1744 		int16_t             data[3];
   1745 		struct {
   1746 			uint16_t    rsvd;
   1747 			uint32_t    timestamp;
   1748 		} __packed;
   1749 	};
   1750 } __packed;
   1751 
   1752 struct ec_response_motion_sense_fifo_info {
   1753 	/* Size of the fifo */
   1754 	uint16_t size;
   1755 	/* Amount of space used in the fifo */
   1756 	uint16_t count;
   1757 	/* TImestamp recorded in us */
   1758 	uint32_t timestamp;
   1759 	/* Total amount of vector lost */
   1760 	uint16_t total_lost;
   1761 	/* Lost events since the last fifo_info, per sensors */
   1762 	uint16_t lost[0];
   1763 } __packed;
   1764 
   1765 struct ec_response_motion_sense_fifo_data {
   1766 	uint32_t number_data;
   1767 	struct ec_response_motion_sensor_data data[0];
   1768 } __packed;
   1769 /* Module flag masks used for the dump sub-command. */
   1770 #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
   1771 
   1772 /* Sensor flag masks used for the dump sub-command. */
   1773 #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
   1774 
   1775 /*
   1776  * Flush entry for synchronisation.
   1777  * data contains time stamp
   1778  */
   1779 #define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
   1780 #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
   1781 
   1782 /*
   1783  * Send this value for the data element to only perform a read. If you
   1784  * send any other value, the EC will interpret it as data to set and will
   1785  * return the actual value set.
   1786  */
   1787 #define EC_MOTION_SENSE_NO_VALUE -1
   1788 
   1789 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
   1790 
   1791 /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
   1792 /* Set Calibration information */
   1793 #define MOTION_SENSE_SET_OFFSET 1
   1794 
   1795 struct ec_params_motion_sense {
   1796 	uint8_t cmd;
   1797 	union {
   1798 		/* Used for MOTIONSENSE_CMD_DUMP */
   1799 		struct {
   1800 			/*
   1801 			 * Maximal number of sensor the host is expecting.
   1802 			 * 0 means the host is only interested in the number
   1803 			 * of sensors controlled by the EC.
   1804 			 */
   1805 			uint8_t max_sensor_count;
   1806 		} dump;
   1807 
   1808 		/*
   1809 		 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
   1810 		 */
   1811 		struct {
   1812 			/* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
   1813 			 * kb_wake_angle: angle to wakup AP.
   1814 			 */
   1815 			int16_t data;
   1816 		} kb_wake_angle;
   1817 
   1818 		/* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
   1819 		 * and MOTIONSENSE_CMD_PERFORM_CALIB. */
   1820 		struct {
   1821 			uint8_t sensor_num;
   1822 		} info, data, fifo_flush, perform_calib;
   1823 
   1824 		/*
   1825 		 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
   1826 		 * and MOTIONSENSE_CMD_SENSOR_RANGE.
   1827 		 */
   1828 		struct {
   1829 			uint8_t sensor_num;
   1830 
   1831 			/* Rounding flag, true for round-up, false for down. */
   1832 			uint8_t roundup;
   1833 
   1834 			uint16_t reserved;
   1835 
   1836 			/* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
   1837 			int32_t data;
   1838 		} ec_rate, sensor_odr, sensor_range;
   1839 
   1840 		/* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
   1841 		struct {
   1842 			uint8_t sensor_num;
   1843 
   1844 			/*
   1845 			 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
   1846 			 * the calibration information in the EC.
   1847 			 * If unset, just retrieve calibration information.
   1848 			 */
   1849 			uint16_t flags;
   1850 
   1851 			/*
   1852 			 * Temperature at calibration, in units of 0.01 C
   1853 			 * 0x8000: invalid / unknown.
   1854 			 * 0x0: 0C
   1855 			 * 0x7fff: +327.67C
   1856 			 */
   1857 			int16_t temp;
   1858 
   1859 			/*
   1860 			 * Offset for calibration.
   1861 			 * Unit:
   1862 			 * Accelerometer: 1/1024 g
   1863 			 * Gyro:          1/1024 deg/s
   1864 			 * Compass:       1/16 uT
   1865 			 */
   1866 			int16_t offset[3];
   1867 		} __packed sensor_offset;
   1868 
   1869 		/* Used for MOTIONSENSE_CMD_FIFO_INFO */
   1870 		struct {
   1871 		} fifo_info;
   1872 
   1873 		/* Used for MOTIONSENSE_CMD_FIFO_READ */
   1874 		struct {
   1875 			/*
   1876 			 * Number of expected vector to return.
   1877 			 * EC may return less or 0 if none available.
   1878 			 */
   1879 			uint32_t max_data_vector;
   1880 		} fifo_read;
   1881 	};
   1882 } __packed;
   1883 
   1884 struct ec_response_motion_sense {
   1885 	union {
   1886 		/* Used for MOTIONSENSE_CMD_DUMP */
   1887 		struct {
   1888 			/* Flags representing the motion sensor module. */
   1889 			uint8_t module_flags;
   1890 
   1891 			/* Number of sensors managed directly by the EC */
   1892 			uint8_t sensor_count;
   1893 
   1894 			/*
   1895 			 * sensor data is truncated if response_max is too small
   1896 			 * for holding all the data.
   1897 			 */
   1898 			struct ec_response_motion_sensor_data sensor[0];
   1899 		} dump;
   1900 
   1901 		/* Used for MOTIONSENSE_CMD_INFO. */
   1902 		struct {
   1903 			/* Should be element of enum motionsensor_type. */
   1904 			uint8_t type;
   1905 
   1906 			/* Should be element of enum motionsensor_location. */
   1907 			uint8_t location;
   1908 
   1909 			/* Should be element of enum motionsensor_chip. */
   1910 			uint8_t chip;
   1911 		} info;
   1912 
   1913 		/* Used for MOTIONSENSE_CMD_DATA */
   1914 		struct ec_response_motion_sensor_data data;
   1915 
   1916 		/*
   1917 		 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
   1918 		 * MOTIONSENSE_CMD_SENSOR_RANGE, and
   1919 		 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
   1920 		 */
   1921 		struct {
   1922 			/* Current value of the parameter queried. */
   1923 			int32_t ret;
   1924 		} ec_rate, sensor_odr, sensor_range, kb_wake_angle;
   1925 
   1926 		/* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
   1927 		struct {
   1928 			int16_t temp;
   1929 			int16_t offset[3];
   1930 		} sensor_offset, perform_calib;
   1931 
   1932 		struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
   1933 
   1934 		struct ec_response_motion_sense_fifo_data fifo_read;
   1935 	};
   1936 } __packed;
   1937 
   1938 /*****************************************************************************/
   1939 /* Force lid open command */
   1940 
   1941 /* Make lid event always open */
   1942 #define EC_CMD_FORCE_LID_OPEN 0x2c
   1943 
   1944 struct ec_params_force_lid_open {
   1945 	uint8_t enabled;
   1946 } __packed;
   1947 
   1948 /*****************************************************************************/
   1949 /* USB charging control commands */
   1950 
   1951 /* Set USB port charging mode */
   1952 #define EC_CMD_USB_CHARGE_SET_MODE 0x30
   1953 
   1954 struct ec_params_usb_charge_set_mode {
   1955 	uint8_t usb_port_id;
   1956 	uint8_t mode;
   1957 } __packed;
   1958 
   1959 /*****************************************************************************/
   1960 /* Persistent storage for host */
   1961 
   1962 /* Maximum bytes that can be read/written in a single command */
   1963 #define EC_PSTORE_SIZE_MAX 64
   1964 
   1965 /* Get persistent storage info */
   1966 #define EC_CMD_PSTORE_INFO 0x40
   1967 
   1968 struct ec_response_pstore_info {
   1969 	/* Persistent storage size, in bytes */
   1970 	uint32_t pstore_size;
   1971 	/* Access size; read/write offset and size must be a multiple of this */
   1972 	uint32_t access_size;
   1973 } __packed;
   1974 
   1975 /*
   1976  * Read persistent storage
   1977  *
   1978  * Response is params.size bytes of data.
   1979  */
   1980 #define EC_CMD_PSTORE_READ 0x41
   1981 
   1982 struct ec_params_pstore_read {
   1983 	uint32_t offset;   /* Byte offset to read */
   1984 	uint32_t size;     /* Size to read in bytes */
   1985 } __packed;
   1986 
   1987 /* Write persistent storage */
   1988 #define EC_CMD_PSTORE_WRITE 0x42
   1989 
   1990 struct ec_params_pstore_write {
   1991 	uint32_t offset;   /* Byte offset to write */
   1992 	uint32_t size;     /* Size to write in bytes */
   1993 	uint8_t data[EC_PSTORE_SIZE_MAX];
   1994 } __packed;
   1995 
   1996 /*****************************************************************************/
   1997 /* Real-time clock */
   1998 
   1999 /* RTC params and response structures */
   2000 struct ec_params_rtc {
   2001 	uint32_t time;
   2002 } __packed;
   2003 
   2004 struct ec_response_rtc {
   2005 	uint32_t time;
   2006 } __packed;
   2007 
   2008 /* These use ec_response_rtc */
   2009 #define EC_CMD_RTC_GET_VALUE 0x44
   2010 #define EC_CMD_RTC_GET_ALARM 0x45
   2011 
   2012 /* These all use ec_params_rtc */
   2013 #define EC_CMD_RTC_SET_VALUE 0x46
   2014 #define EC_CMD_RTC_SET_ALARM 0x47
   2015 
   2016 /*****************************************************************************/
   2017 /* Port80 log access */
   2018 
   2019 /* Maximum entries that can be read/written in a single command */
   2020 #define EC_PORT80_SIZE_MAX 32
   2021 
   2022 /* Get last port80 code from previous boot */
   2023 #define EC_CMD_PORT80_LAST_BOOT 0x48
   2024 #define EC_CMD_PORT80_READ 0x48
   2025 
   2026 enum ec_port80_subcmd {
   2027 	EC_PORT80_GET_INFO = 0,
   2028 	EC_PORT80_READ_BUFFER,
   2029 };
   2030 
   2031 struct ec_params_port80_read {
   2032 	uint16_t subcmd;
   2033 	union {
   2034 		struct {
   2035 			uint32_t offset;
   2036 			uint32_t num_entries;
   2037 		} read_buffer;
   2038 	};
   2039 } __packed;
   2040 
   2041 struct ec_response_port80_read {
   2042 	union {
   2043 		struct {
   2044 			uint32_t writes;
   2045 			uint32_t history_size;
   2046 			uint32_t last_boot;
   2047 		} get_info;
   2048 		struct {
   2049 			uint16_t codes[EC_PORT80_SIZE_MAX];
   2050 		} data;
   2051 	};
   2052 } __packed;
   2053 
   2054 struct ec_response_port80_last_boot {
   2055 	uint16_t code;
   2056 } __packed;
   2057 
   2058 /*****************************************************************************/
   2059 /* Thermal engine commands. Note that there are two implementations. We'll
   2060  * reuse the command number, but the data and behavior is incompatible.
   2061  * Version 0 is what originally shipped on Link.
   2062  * Version 1 separates the CPU thermal limits from the fan control.
   2063  */
   2064 
   2065 #define EC_CMD_THERMAL_SET_THRESHOLD 0x50
   2066 #define EC_CMD_THERMAL_GET_THRESHOLD 0x51
   2067 
   2068 /* The version 0 structs are opaque. You have to know what they are for
   2069  * the get/set commands to make any sense.
   2070  */
   2071 
   2072 /* Version 0 - set */
   2073 struct ec_params_thermal_set_threshold {
   2074 	uint8_t sensor_type;
   2075 	uint8_t threshold_id;
   2076 	uint16_t value;
   2077 } __packed;
   2078 
   2079 /* Version 0 - get */
   2080 struct ec_params_thermal_get_threshold {
   2081 	uint8_t sensor_type;
   2082 	uint8_t threshold_id;
   2083 } __packed;
   2084 
   2085 struct ec_response_thermal_get_threshold {
   2086 	uint16_t value;
   2087 } __packed;
   2088 
   2089 
   2090 /* The version 1 structs are visible. */
   2091 enum ec_temp_thresholds {
   2092 	EC_TEMP_THRESH_WARN = 0,
   2093 	EC_TEMP_THRESH_HIGH,
   2094 	EC_TEMP_THRESH_HALT,
   2095 
   2096 	EC_TEMP_THRESH_COUNT
   2097 };
   2098 
   2099 /* Thermal configuration for one temperature sensor. Temps are in degrees K.
   2100  * Zero values will be silently ignored by the thermal task.
   2101  */
   2102 struct ec_thermal_config {
   2103 	uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
   2104 	uint32_t temp_fan_off;		/* no active cooling needed */
   2105 	uint32_t temp_fan_max;		/* max active cooling needed */
   2106 } __packed;
   2107 
   2108 /* Version 1 - get config for one sensor. */
   2109 struct ec_params_thermal_get_threshold_v1 {
   2110 	uint32_t sensor_num;
   2111 } __packed;
   2112 /* This returns a struct ec_thermal_config */
   2113 
   2114 /* Version 1 - set config for one sensor.
   2115  * Use read-modify-write for best results! */
   2116 struct ec_params_thermal_set_threshold_v1 {
   2117 	uint32_t sensor_num;
   2118 	struct ec_thermal_config cfg;
   2119 } __packed;
   2120 /* This returns no data */
   2121 
   2122 /****************************************************************************/
   2123 
   2124 /* Toggle automatic fan control */
   2125 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
   2126 
   2127 /* Version 1 of input params */
   2128 struct ec_params_auto_fan_ctrl_v1 {
   2129 	uint8_t fan_idx;
   2130 } __packed;
   2131 
   2132 /* Get/Set TMP006 calibration data */
   2133 #define EC_CMD_TMP006_GET_CALIBRATION 0x53
   2134 #define EC_CMD_TMP006_SET_CALIBRATION 0x54
   2135 
   2136 /*
   2137  * The original TMP006 calibration only needed four params, but now we need
   2138  * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
   2139  * the params opaque. The v1 "get" response will include the algorithm number
   2140  * and how many params it requires. That way we can change the EC code without
   2141  * needing to update this file. We can also use a different algorithm on each
   2142  * sensor.
   2143  */
   2144 
   2145 /* This is the same struct for both v0 and v1. */
   2146 struct ec_params_tmp006_get_calibration {
   2147 	uint8_t index;
   2148 } __packed;
   2149 
   2150 /* Version 0 */
   2151 struct ec_response_tmp006_get_calibration_v0 {
   2152 	float s0;
   2153 	float b0;
   2154 	float b1;
   2155 	float b2;
   2156 } __packed;
   2157 
   2158 struct ec_params_tmp006_set_calibration_v0 {
   2159 	uint8_t index;
   2160 	uint8_t reserved[3];
   2161 	float s0;
   2162 	float b0;
   2163 	float b1;
   2164 	float b2;
   2165 } __packed;
   2166 
   2167 /* Version 1 */
   2168 struct ec_response_tmp006_get_calibration_v1 {
   2169 	uint8_t algorithm;
   2170 	uint8_t num_params;
   2171 	uint8_t reserved[2];
   2172 	float val[0];
   2173 } __packed;
   2174 
   2175 struct ec_params_tmp006_set_calibration_v1 {
   2176 	uint8_t index;
   2177 	uint8_t algorithm;
   2178 	uint8_t num_params;
   2179 	uint8_t reserved;
   2180 	float val[0];
   2181 } __packed;
   2182 
   2183 
   2184 /* Read raw TMP006 data */
   2185 #define EC_CMD_TMP006_GET_RAW 0x55
   2186 
   2187 struct ec_params_tmp006_get_raw {
   2188 	uint8_t index;
   2189 } __packed;
   2190 
   2191 struct ec_response_tmp006_get_raw {
   2192 	int32_t t;  /* In 1/100 K */
   2193 	int32_t v;  /* In nV */
   2194 };
   2195 
   2196 /*****************************************************************************/
   2197 /* MKBP - Matrix KeyBoard Protocol */
   2198 
   2199 /*
   2200  * Read key state
   2201  *
   2202  * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
   2203  * expected response size.
   2204  */
   2205 #define EC_CMD_MKBP_STATE 0x60
   2206 
   2207 /* Provide information about the matrix : number of rows and columns */
   2208 #define EC_CMD_MKBP_INFO 0x61
   2209 
   2210 struct ec_response_mkbp_info {
   2211 	uint32_t rows;
   2212 	uint32_t cols;
   2213 	uint8_t switches;
   2214 } __packed;
   2215 
   2216 /* Simulate key press */
   2217 #define EC_CMD_MKBP_SIMULATE_KEY 0x62
   2218 
   2219 struct ec_params_mkbp_simulate_key {
   2220 	uint8_t col;
   2221 	uint8_t row;
   2222 	uint8_t pressed;
   2223 } __packed;
   2224 
   2225 /* Configure keyboard scanning */
   2226 #define EC_CMD_MKBP_SET_CONFIG 0x64
   2227 #define EC_CMD_MKBP_GET_CONFIG 0x65
   2228 
   2229 /* flags */
   2230 enum mkbp_config_flags {
   2231 	EC_MKBP_FLAGS_ENABLE = 1,	/* Enable keyboard scanning */
   2232 };
   2233 
   2234 enum mkbp_config_valid {
   2235 	EC_MKBP_VALID_SCAN_PERIOD		= 1 << 0,
   2236 	EC_MKBP_VALID_POLL_TIMEOUT		= 1 << 1,
   2237 	EC_MKBP_VALID_MIN_POST_SCAN_DELAY	= 1 << 3,
   2238 	EC_MKBP_VALID_OUTPUT_SETTLE		= 1 << 4,
   2239 	EC_MKBP_VALID_DEBOUNCE_DOWN		= 1 << 5,
   2240 	EC_MKBP_VALID_DEBOUNCE_UP		= 1 << 6,
   2241 	EC_MKBP_VALID_FIFO_MAX_DEPTH		= 1 << 7,
   2242 };
   2243 
   2244 /* Configuration for our key scanning algorithm */
   2245 struct ec_mkbp_config {
   2246 	uint32_t valid_mask;		/* valid fields */
   2247 	uint8_t flags;		/* some flags (enum mkbp_config_flags) */
   2248 	uint8_t valid_flags;		/* which flags are valid */
   2249 	uint16_t scan_period_us;	/* period between start of scans */
   2250 	/* revert to interrupt mode after no activity for this long */
   2251 	uint32_t poll_timeout_us;
   2252 	/*
   2253 	 * minimum post-scan relax time. Once we finish a scan we check
   2254 	 * the time until we are due to start the next one. If this time is
   2255 	 * shorter this field, we use this instead.
   2256 	 */
   2257 	uint16_t min_post_scan_delay_us;
   2258 	/* delay between setting up output and waiting for it to settle */
   2259 	uint16_t output_settle_us;
   2260 	uint16_t debounce_down_us;	/* time for debounce on key down */
   2261 	uint16_t debounce_up_us;	/* time for debounce on key up */
   2262 	/* maximum depth to allow for fifo (0 = no keyscan output) */
   2263 	uint8_t fifo_max_depth;
   2264 } __packed;
   2265 
   2266 struct ec_params_mkbp_set_config {
   2267 	struct ec_mkbp_config config;
   2268 } __packed;
   2269 
   2270 struct ec_response_mkbp_get_config {
   2271 	struct ec_mkbp_config config;
   2272 } __packed;
   2273 
   2274 /* Run the key scan emulation */
   2275 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
   2276 
   2277 enum ec_keyscan_seq_cmd {
   2278 	EC_KEYSCAN_SEQ_STATUS = 0,	/* Get status information */
   2279 	EC_KEYSCAN_SEQ_CLEAR = 1,	/* Clear sequence */
   2280 	EC_KEYSCAN_SEQ_ADD = 2,		/* Add item to sequence */
   2281 	EC_KEYSCAN_SEQ_START = 3,	/* Start running sequence */
   2282 	EC_KEYSCAN_SEQ_COLLECT = 4,	/* Collect sequence summary data */
   2283 };
   2284 
   2285 enum ec_collect_flags {
   2286 	/*
   2287 	 * Indicates this scan was processed by the EC. Due to timing, some
   2288 	 * scans may be skipped.
   2289 	 */
   2290 	EC_KEYSCAN_SEQ_FLAG_DONE	= 1 << 0,
   2291 };
   2292 
   2293 struct ec_collect_item {
   2294 	uint8_t flags;		/* some flags (enum ec_collect_flags) */
   2295 };
   2296 
   2297 struct ec_params_keyscan_seq_ctrl {
   2298 	uint8_t cmd;	/* Command to send (enum ec_keyscan_seq_cmd) */
   2299 	union {
   2300 		struct {
   2301 			uint8_t active;		/* still active */
   2302 			uint8_t num_items;	/* number of items */
   2303 			/* Current item being presented */
   2304 			uint8_t cur_item;
   2305 		} status;
   2306 		struct {
   2307 			/*
   2308 			 * Absolute time for this scan, measured from the
   2309 			 * start of the sequence.
   2310 			 */
   2311 			uint32_t time_us;
   2312 			uint8_t scan[0];	/* keyscan data */
   2313 		} add;
   2314 		struct {
   2315 			uint8_t start_item;	/* First item to return */
   2316 			uint8_t num_items;	/* Number of items to return */
   2317 		} collect;
   2318 	};
   2319 } __packed;
   2320 
   2321 struct ec_result_keyscan_seq_ctrl {
   2322 	union {
   2323 		struct {
   2324 			uint8_t num_items;	/* Number of items */
   2325 			/* Data for each item */
   2326 			struct ec_collect_item item[0];
   2327 		} collect;
   2328 	};
   2329 } __packed;
   2330 
   2331 /*
   2332  * Get the next pending MKBP event.
   2333  *
   2334  * Returns EC_RES_UNAVAILABLE if there is no event pending.
   2335  */
   2336 #define EC_CMD_GET_NEXT_EVENT 0x67
   2337 
   2338 enum ec_mkbp_event {
   2339 	/* Keyboard matrix changed. The event data is the new matrix state. */
   2340 	EC_MKBP_EVENT_KEY_MATRIX = 0,
   2341 
   2342 	/* New host event. The event data is 4 bytes of host event flags. */
   2343 	EC_MKBP_EVENT_HOST_EVENT = 1,
   2344 
   2345 	/* New Sensor FIFO data. The event data is fifo_info structure. */
   2346 	EC_MKBP_EVENT_SENSOR_FIFO = 2,
   2347 
   2348 	/* Number of MKBP events */
   2349 	EC_MKBP_EVENT_COUNT,
   2350 };
   2351 
   2352 union ec_response_get_next_data {
   2353 	uint8_t   key_matrix[13];
   2354 
   2355 	/* Unaligned */
   2356 	uint32_t  host_event;
   2357 
   2358 	struct {
   2359 		/* For aligning the fifo_info */
   2360 		uint8_t rsvd[3];
   2361 		struct ec_response_motion_sense_fifo_info info;
   2362 	}        sensor_fifo;
   2363 } __packed;
   2364 
   2365 struct ec_response_get_next_event {
   2366 	uint8_t event_type;
   2367 	/* Followed by event data if any */
   2368 	union ec_response_get_next_data data;
   2369 } __packed;
   2370 
   2371 /*****************************************************************************/
   2372 /* Temperature sensor commands */
   2373 
   2374 /* Read temperature sensor info */
   2375 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
   2376 
   2377 struct ec_params_temp_sensor_get_info {
   2378 	uint8_t id;
   2379 } __packed;
   2380 
   2381 struct ec_response_temp_sensor_get_info {
   2382 	char sensor_name[32];
   2383 	uint8_t sensor_type;
   2384 } __packed;
   2385 
   2386 /*****************************************************************************/
   2387 
   2388 /*
   2389  * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
   2390  * commands accidentally sent to the wrong interface.  See the ACPI section
   2391  * below.
   2392  */
   2393 
   2394 /*****************************************************************************/
   2395 /* Host event commands */
   2396 
   2397 /*
   2398  * Host event mask params and response structures, shared by all of the host
   2399  * event commands below.
   2400  */
   2401 struct ec_params_host_event_mask {
   2402 	uint32_t mask;
   2403 } __packed;
   2404 
   2405 struct ec_response_host_event_mask {
   2406 	uint32_t mask;
   2407 } __packed;
   2408 
   2409 /* These all use ec_response_host_event_mask */
   2410 #define EC_CMD_HOST_EVENT_GET_B         0x87
   2411 #define EC_CMD_HOST_EVENT_GET_SMI_MASK  0x88
   2412 #define EC_CMD_HOST_EVENT_GET_SCI_MASK  0x89
   2413 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
   2414 
   2415 /* These all use ec_params_host_event_mask */
   2416 #define EC_CMD_HOST_EVENT_SET_SMI_MASK  0x8a
   2417 #define EC_CMD_HOST_EVENT_SET_SCI_MASK  0x8b
   2418 #define EC_CMD_HOST_EVENT_CLEAR         0x8c
   2419 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
   2420 #define EC_CMD_HOST_EVENT_CLEAR_B       0x8f
   2421 
   2422 /*****************************************************************************/
   2423 /* Switch commands */
   2424 
   2425 /* Enable/disable LCD backlight */
   2426 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
   2427 
   2428 struct ec_params_switch_enable_backlight {
   2429 	uint8_t enabled;
   2430 } __packed;
   2431 
   2432 /* Enable/disable WLAN/Bluetooth */
   2433 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
   2434 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
   2435 
   2436 /* Version 0 params; no response */
   2437 struct ec_params_switch_enable_wireless_v0 {
   2438 	uint8_t enabled;
   2439 } __packed;
   2440 
   2441 /* Version 1 params */
   2442 struct ec_params_switch_enable_wireless_v1 {
   2443 	/* Flags to enable now */
   2444 	uint8_t now_flags;
   2445 
   2446 	/* Which flags to copy from now_flags */
   2447 	uint8_t now_mask;
   2448 
   2449 	/*
   2450 	 * Flags to leave enabled in S3, if they're on at the S0->S3
   2451 	 * transition.  (Other flags will be disabled by the S0->S3
   2452 	 * transition.)
   2453 	 */
   2454 	uint8_t suspend_flags;
   2455 
   2456 	/* Which flags to copy from suspend_flags */
   2457 	uint8_t suspend_mask;
   2458 } __packed;
   2459 
   2460 /* Version 1 response */
   2461 struct ec_response_switch_enable_wireless_v1 {
   2462 	/* Flags to enable now */
   2463 	uint8_t now_flags;
   2464 
   2465 	/* Flags to leave enabled in S3 */
   2466 	uint8_t suspend_flags;
   2467 } __packed;
   2468 
   2469 /*****************************************************************************/
   2470 /* GPIO commands. Only available on EC if write protect has been disabled. */
   2471 
   2472 /* Set GPIO output value */
   2473 #define EC_CMD_GPIO_SET 0x92
   2474 
   2475 struct ec_params_gpio_set {
   2476 	char name[32];
   2477 	uint8_t val;
   2478 } __packed;
   2479 
   2480 /* Get GPIO value */
   2481 #define EC_CMD_GPIO_GET 0x93
   2482 
   2483 /* Version 0 of input params and response */
   2484 struct ec_params_gpio_get {
   2485 	char name[32];
   2486 } __packed;
   2487 struct ec_response_gpio_get {
   2488 	uint8_t val;
   2489 } __packed;
   2490 
   2491 /* Version 1 of input params and response */
   2492 struct ec_params_gpio_get_v1 {
   2493 	uint8_t subcmd;
   2494 	union {
   2495 		struct {
   2496 			char name[32];
   2497 		} get_value_by_name;
   2498 		struct {
   2499 			uint8_t index;
   2500 		} get_info;
   2501 	};
   2502 } __packed;
   2503 
   2504 struct ec_response_gpio_get_v1 {
   2505 	union {
   2506 		struct {
   2507 			uint8_t val;
   2508 		} get_value_by_name, get_count;
   2509 		struct {
   2510 			uint8_t val;
   2511 			char name[32];
   2512 			uint32_t flags;
   2513 		} get_info;
   2514 	};
   2515 } __packed;
   2516 
   2517 enum gpio_get_subcmd {
   2518 	EC_GPIO_GET_BY_NAME = 0,
   2519 	EC_GPIO_GET_COUNT = 1,
   2520 	EC_GPIO_GET_INFO = 2,
   2521 };
   2522 
   2523 /*****************************************************************************/
   2524 /* I2C commands. Only available when flash write protect is unlocked. */
   2525 
   2526 /*
   2527  * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
   2528  * removed soon.  Use EC_CMD_I2C_PASSTHRU instead.
   2529  */
   2530 
   2531 /* Read I2C bus */
   2532 #define EC_CMD_I2C_READ 0x94
   2533 
   2534 struct ec_params_i2c_read {
   2535 	uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
   2536 	uint8_t read_size; /* Either 8 or 16. */
   2537 	uint8_t port;
   2538 	uint8_t offset;
   2539 } __packed;
   2540 struct ec_response_i2c_read {
   2541 	uint16_t data;
   2542 } __packed;
   2543 
   2544 /* Write I2C bus */
   2545 #define EC_CMD_I2C_WRITE 0x95
   2546 
   2547 struct ec_params_i2c_write {
   2548 	uint16_t data;
   2549 	uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
   2550 	uint8_t write_size; /* Either 8 or 16. */
   2551 	uint8_t port;
   2552 	uint8_t offset;
   2553 } __packed;
   2554 
   2555 /*****************************************************************************/
   2556 /* Charge state commands. Only available when flash write protect unlocked. */
   2557 
   2558 /* Force charge state machine to stop charging the battery or force it to
   2559  * discharge the battery.
   2560  */
   2561 #define EC_CMD_CHARGE_CONTROL 0x96
   2562 #define EC_VER_CHARGE_CONTROL 1
   2563 
   2564 enum ec_charge_control_mode {
   2565 	CHARGE_CONTROL_NORMAL = 0,
   2566 	CHARGE_CONTROL_IDLE,
   2567 	CHARGE_CONTROL_DISCHARGE,
   2568 };
   2569 
   2570 struct ec_params_charge_control {
   2571 	uint32_t mode;  /* enum charge_control_mode */
   2572 } __packed;
   2573 
   2574 /*****************************************************************************/
   2575 /* Console commands. Only available when flash write protect is unlocked. */
   2576 
   2577 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
   2578 #define EC_CMD_CONSOLE_SNAPSHOT 0x97
   2579 
   2580 /*
   2581  * Read data from the saved snapshot. If the subcmd parameter is
   2582  * CONSOLE_READ_NEXT, this will return data starting from the beginning of
   2583  * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
   2584  * end of the previous snapshot.
   2585  *
   2586  * The params are only looked at in version >= 1 of this command. Prior
   2587  * versions will just default to CONSOLE_READ_NEXT behavior.
   2588  *
   2589  * Response is null-terminated string.  Empty string, if there is no more
   2590  * remaining output.
   2591  */
   2592 #define EC_CMD_CONSOLE_READ 0x98
   2593 
   2594 enum ec_console_read_subcmd {
   2595 	CONSOLE_READ_NEXT = 0,
   2596 	CONSOLE_READ_RECENT
   2597 };
   2598 
   2599 struct ec_params_console_read_v1 {
   2600 	uint8_t subcmd; /* enum ec_console_read_subcmd */
   2601 } __packed;
   2602 
   2603 /*****************************************************************************/
   2604 
   2605 /*
   2606  * Cut off battery power immediately or after the host has shut down.
   2607  *
   2608  * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
   2609  *	  EC_RES_SUCCESS if the command was successful.
   2610  *	  EC_RES_ERROR if the cut off command failed.
   2611  */
   2612 #define EC_CMD_BATTERY_CUT_OFF 0x99
   2613 
   2614 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN	(1 << 0)
   2615 
   2616 struct ec_params_battery_cutoff {
   2617 	uint8_t flags;
   2618 } __packed;
   2619 
   2620 /*****************************************************************************/
   2621 /* USB port mux control. */
   2622 
   2623 /*
   2624  * Switch USB mux or return to automatic switching.
   2625  */
   2626 #define EC_CMD_USB_MUX 0x9a
   2627 
   2628 struct ec_params_usb_mux {
   2629 	uint8_t mux;
   2630 } __packed;
   2631 
   2632 /*****************************************************************************/
   2633 /* LDOs / FETs control. */
   2634 
   2635 enum ec_ldo_state {
   2636 	EC_LDO_STATE_OFF = 0,	/* the LDO / FET is shut down */
   2637 	EC_LDO_STATE_ON = 1,	/* the LDO / FET is ON / providing power */
   2638 };
   2639 
   2640 /*
   2641  * Switch on/off a LDO.
   2642  */
   2643 #define EC_CMD_LDO_SET 0x9b
   2644 
   2645 struct ec_params_ldo_set {
   2646 	uint8_t index;
   2647 	uint8_t state;
   2648 } __packed;
   2649 
   2650 /*
   2651  * Get LDO state.
   2652  */
   2653 #define EC_CMD_LDO_GET 0x9c
   2654 
   2655 struct ec_params_ldo_get {
   2656 	uint8_t index;
   2657 } __packed;
   2658 
   2659 struct ec_response_ldo_get {
   2660 	uint8_t state;
   2661 } __packed;
   2662 
   2663 /*****************************************************************************/
   2664 /* Power info. */
   2665 
   2666 /*
   2667  * Get power info.
   2668  */
   2669 #define EC_CMD_POWER_INFO 0x9d
   2670 
   2671 struct ec_response_power_info {
   2672 	uint32_t usb_dev_type;
   2673 	uint16_t voltage_ac;
   2674 	uint16_t voltage_system;
   2675 	uint16_t current_system;
   2676 	uint16_t usb_current_limit;
   2677 } __packed;
   2678 
   2679 /*****************************************************************************/
   2680 /* I2C passthru command */
   2681 
   2682 #define EC_CMD_I2C_PASSTHRU 0x9e
   2683 
   2684 /* Read data; if not present, message is a write */
   2685 #define EC_I2C_FLAG_READ	(1 << 15)
   2686 
   2687 /* Mask for address */
   2688 #define EC_I2C_ADDR_MASK	0x3ff
   2689 
   2690 #define EC_I2C_STATUS_NAK	(1 << 0) /* Transfer was not acknowledged */
   2691 #define EC_I2C_STATUS_TIMEOUT	(1 << 1) /* Timeout during transfer */
   2692 
   2693 /* Any error */
   2694 #define EC_I2C_STATUS_ERROR	(EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
   2695 
   2696 struct ec_params_i2c_passthru_msg {
   2697 	uint16_t addr_flags;	/* I2C slave address (7 or 10 bits) and flags */
   2698 	uint16_t len;		/* Number of bytes to read or write */
   2699 } __packed;
   2700 
   2701 struct ec_params_i2c_passthru {
   2702 	uint8_t port;		/* I2C port number */
   2703 	uint8_t num_msgs;	/* Number of messages */
   2704 	struct ec_params_i2c_passthru_msg msg[];
   2705 	/* Data to write for all messages is concatenated here */
   2706 } __packed;
   2707 
   2708 struct ec_response_i2c_passthru {
   2709 	uint8_t i2c_status;	/* Status flags (EC_I2C_STATUS_...) */
   2710 	uint8_t num_msgs;	/* Number of messages processed */
   2711 	uint8_t data[];		/* Data read by messages concatenated here */
   2712 } __packed;
   2713 
   2714 /*****************************************************************************/
   2715 /* Power button hang detect */
   2716 
   2717 #define EC_CMD_HANG_DETECT 0x9f
   2718 
   2719 /* Reasons to start hang detection timer */
   2720 /* Power button pressed */
   2721 #define EC_HANG_START_ON_POWER_PRESS  (1 << 0)
   2722 
   2723 /* Lid closed */
   2724 #define EC_HANG_START_ON_LID_CLOSE    (1 << 1)
   2725 
   2726  /* Lid opened */
   2727 #define EC_HANG_START_ON_LID_OPEN     (1 << 2)
   2728 
   2729 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
   2730 #define EC_HANG_START_ON_RESUME       (1 << 3)
   2731 
   2732 /* Reasons to cancel hang detection */
   2733 
   2734 /* Power button released */
   2735 #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
   2736 
   2737 /* Any host command from AP received */
   2738 #define EC_HANG_STOP_ON_HOST_COMMAND  (1 << 9)
   2739 
   2740 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
   2741 #define EC_HANG_STOP_ON_SUSPEND       (1 << 10)
   2742 
   2743 /*
   2744  * If this flag is set, all the other fields are ignored, and the hang detect
   2745  * timer is started.  This provides the AP a way to start the hang timer
   2746  * without reconfiguring any of the other hang detect settings.  Note that
   2747  * you must previously have configured the timeouts.
   2748  */
   2749 #define EC_HANG_START_NOW             (1 << 30)
   2750 
   2751 /*
   2752  * If this flag is set, all the other fields are ignored (including
   2753  * EC_HANG_START_NOW).  This provides the AP a way to stop the hang timer
   2754  * without reconfiguring any of the other hang detect settings.
   2755  */
   2756 #define EC_HANG_STOP_NOW              (1 << 31)
   2757 
   2758 struct ec_params_hang_detect {
   2759 	/* Flags; see EC_HANG_* */
   2760 	uint32_t flags;
   2761 
   2762 	/* Timeout in msec before generating host event, if enabled */
   2763 	uint16_t host_event_timeout_msec;
   2764 
   2765 	/* Timeout in msec before generating warm reboot, if enabled */
   2766 	uint16_t warm_reboot_timeout_msec;
   2767 } __packed;
   2768 
   2769 /*****************************************************************************/
   2770 /* Commands for battery charging */
   2771 
   2772 /*
   2773  * This is the single catch-all host command to exchange data regarding the
   2774  * charge state machine (v2 and up).
   2775  */
   2776 #define EC_CMD_CHARGE_STATE 0xa0
   2777 
   2778 /* Subcommands for this host command */
   2779 enum charge_state_command {
   2780 	CHARGE_STATE_CMD_GET_STATE,
   2781 	CHARGE_STATE_CMD_GET_PARAM,
   2782 	CHARGE_STATE_CMD_SET_PARAM,
   2783 	CHARGE_STATE_NUM_CMDS
   2784 };
   2785 
   2786 /*
   2787  * Known param numbers are defined here. Ranges are reserved for board-specific
   2788  * params, which are handled by the particular implementations.
   2789  */
   2790 enum charge_state_params {
   2791 	CS_PARAM_CHG_VOLTAGE,	      /* charger voltage limit */
   2792 	CS_PARAM_CHG_CURRENT,	      /* charger current limit */
   2793 	CS_PARAM_CHG_INPUT_CURRENT,   /* charger input current limit */
   2794 	CS_PARAM_CHG_STATUS,	      /* charger-specific status */
   2795 	CS_PARAM_CHG_OPTION,	      /* charger-specific options */
   2796 	/* How many so far? */
   2797 	CS_NUM_BASE_PARAMS,
   2798 
   2799 	/* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
   2800 	CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
   2801 	CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
   2802 
   2803 	/* Other custom param ranges go here... */
   2804 };
   2805 
   2806 struct ec_params_charge_state {
   2807 	uint8_t cmd;				/* enum charge_state_command */
   2808 	union {
   2809 		struct {
   2810 			/* no args */
   2811 		} get_state;
   2812 
   2813 		struct {
   2814 			uint32_t param;		/* enum charge_state_param */
   2815 		} get_param;
   2816 
   2817 		struct {
   2818 			uint32_t param;		/* param to set */
   2819 			uint32_t value;		/* value to set */
   2820 		} set_param;
   2821 	};
   2822 } __packed;
   2823 
   2824 struct ec_response_charge_state {
   2825 	union {
   2826 		struct {
   2827 			int ac;
   2828 			int chg_voltage;
   2829 			int chg_current;
   2830 			int chg_input_current;
   2831 			int batt_state_of_charge;
   2832 		} get_state;
   2833 
   2834 		struct {
   2835 			uint32_t value;
   2836 		} get_param;
   2837 		struct {
   2838 			/* no return values */
   2839 		} set_param;
   2840 	};
   2841 } __packed;
   2842 
   2843 
   2844 /*
   2845  * Set maximum battery charging current.
   2846  */
   2847 #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
   2848 
   2849 struct ec_params_current_limit {
   2850 	uint32_t limit; /* in mA */
   2851 } __packed;
   2852 
   2853 /*
   2854  * Set maximum external voltage / current.
   2855  */
   2856 #define EC_CMD_EXTERNAL_POWER_LIMIT 0xa2
   2857 
   2858 /* Command v0 is used only on Spring and is obsolete + unsupported */
   2859 struct ec_params_external_power_limit_v1 {
   2860 	uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
   2861 	uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
   2862 } __packed;
   2863 
   2864 #define EC_POWER_LIMIT_NONE 0xffff
   2865 
   2866 /*****************************************************************************/
   2867 
   2868 /*
   2869  * Get/Set the option to boot the AP when the AC power is plugged
   2870  *
   2871  * Use ec_params_get_set_value/ec_response_get_set_value structs and EC_GSV_SET
   2872  * please see "Get/Set miscellaneous values" section above.
   2873  */
   2874 #define EC_CMD_GSV_BOOT_ON_AC	0xa3
   2875 
   2876 /*****************************************************************************/
   2877 /* Smart battery pass-through */
   2878 
   2879 /* Get / Set 16-bit smart battery registers */
   2880 #define EC_CMD_SB_READ_WORD   0xb0
   2881 #define EC_CMD_SB_WRITE_WORD  0xb1
   2882 
   2883 /* Get / Set string smart battery parameters
   2884  * formatted as SMBUS "block".
   2885  */
   2886 #define EC_CMD_SB_READ_BLOCK  0xb2
   2887 #define EC_CMD_SB_WRITE_BLOCK 0xb3
   2888 
   2889 struct ec_params_sb_rd {
   2890 	uint8_t reg;
   2891 } __packed;
   2892 
   2893 struct ec_response_sb_rd_word {
   2894 	uint16_t value;
   2895 } __packed;
   2896 
   2897 struct ec_params_sb_wr_word {
   2898 	uint8_t reg;
   2899 	uint16_t value;
   2900 } __packed;
   2901 
   2902 struct ec_response_sb_rd_block {
   2903 	uint8_t data[32];
   2904 } __packed;
   2905 
   2906 struct ec_params_sb_wr_block {
   2907 	uint8_t reg;
   2908 	uint16_t data[32];
   2909 } __packed;
   2910 
   2911 
   2912 /*****************************************************************************/
   2913 /* Battery vendor parameters
   2914  *
   2915  * Get or set vendor-specific parameters in the battery. Implementations may
   2916  * differ between boards or batteries. On a set operation, the response
   2917  * contains the actual value set, which may be rounded or clipped from the
   2918  * requested value.
   2919  */
   2920 
   2921 #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
   2922 
   2923 enum ec_battery_vendor_param_mode {
   2924 	BATTERY_VENDOR_PARAM_MODE_GET = 0,
   2925 	BATTERY_VENDOR_PARAM_MODE_SET,
   2926 };
   2927 
   2928 struct ec_params_battery_vendor_param {
   2929 	uint32_t param;
   2930 	uint32_t value;
   2931 	uint8_t mode;
   2932 } __packed;
   2933 
   2934 struct ec_response_battery_vendor_param {
   2935 	uint32_t value;
   2936 } __packed;
   2937 
   2938 /*****************************************************************************/
   2939 /*
   2940  * Smart Battery Firmware Update Commands
   2941  */
   2942 #define EC_CMD_SB_FW_UPDATE 0xb5
   2943 
   2944 enum ec_sb_fw_update_subcmd {
   2945 	EC_SB_FW_UPDATE_PREPARE  = 0x0,
   2946 	EC_SB_FW_UPDATE_INFO     = 0x1, /*query sb info */
   2947 	EC_SB_FW_UPDATE_BEGIN    = 0x2, /*check if protected */
   2948 	EC_SB_FW_UPDATE_WRITE    = 0x3, /*check if protected */
   2949 	EC_SB_FW_UPDATE_END      = 0x4,
   2950 	EC_SB_FW_UPDATE_STATUS   = 0x5,
   2951 	EC_SB_FW_UPDATE_PROTECT  = 0x6,
   2952 	EC_SB_FW_UPDATE_MAX      = 0x7,
   2953 };
   2954 
   2955 #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
   2956 #define SB_FW_UPDATE_CMD_STATUS_SIZE 2
   2957 #define SB_FW_UPDATE_CMD_INFO_SIZE 8
   2958 
   2959 struct ec_sb_fw_update_header {
   2960 	uint16_t subcmd;  /* enum ec_sb_fw_update_subcmd */
   2961 	uint16_t fw_id;   /* firmware id */
   2962 } __packed;
   2963 
   2964 struct ec_params_sb_fw_update {
   2965 	struct ec_sb_fw_update_header hdr;
   2966 	union {
   2967 		/* EC_SB_FW_UPDATE_PREPARE  = 0x0 */
   2968 		/* EC_SB_FW_UPDATE_INFO     = 0x1 */
   2969 		/* EC_SB_FW_UPDATE_BEGIN    = 0x2 */
   2970 		/* EC_SB_FW_UPDATE_END      = 0x4 */
   2971 		/* EC_SB_FW_UPDATE_STATUS   = 0x5 */
   2972 		/* EC_SB_FW_UPDATE_PROTECT  = 0x6 */
   2973 		struct {
   2974 			/* no args */
   2975 		} dummy;
   2976 
   2977 		/* EC_SB_FW_UPDATE_WRITE    = 0x3 */
   2978 		struct {
   2979 			uint8_t  data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
   2980 		} write;
   2981 	};
   2982 } __packed;
   2983 
   2984 struct ec_response_sb_fw_update {
   2985 	union {
   2986 		/* EC_SB_FW_UPDATE_INFO     = 0x1 */
   2987 		struct {
   2988 			uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
   2989 		} info;
   2990 
   2991 		/* EC_SB_FW_UPDATE_STATUS   = 0x5 */
   2992 		struct {
   2993 			uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
   2994 		} status;
   2995 	};
   2996 } __packed;
   2997 
   2998 /*
   2999  * Entering Verified Boot Mode Command
   3000  * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
   3001  * Valid Modes are: normal, developer, and recovery.
   3002  */
   3003 #define EC_CMD_ENTERING_MODE 0xb6
   3004 
   3005 struct ec_params_entering_mode {
   3006 	int vboot_mode;
   3007 } __packed;
   3008 
   3009 #define VBOOT_MODE_NORMAL    0
   3010 #define VBOOT_MODE_DEVELOPER 1
   3011 #define VBOOT_MODE_RECOVERY  2
   3012 
   3013 /*****************************************************************************/
   3014 /* System commands */
   3015 
   3016 /*
   3017  * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
   3018  * necessarily reboot the EC.  Rename to "image" or something similar?
   3019  */
   3020 #define EC_CMD_REBOOT_EC 0xd2
   3021 
   3022 /* Command */
   3023 enum ec_reboot_cmd {
   3024 	EC_REBOOT_CANCEL = 0,        /* Cancel a pending reboot */
   3025 	EC_REBOOT_JUMP_RO = 1,       /* Jump to RO without rebooting */
   3026 	EC_REBOOT_JUMP_RW = 2,       /* Jump to RW without rebooting */
   3027 	/* (command 3 was jump to RW-B) */
   3028 	EC_REBOOT_COLD = 4,          /* Cold-reboot */
   3029 	EC_REBOOT_DISABLE_JUMP = 5,  /* Disable jump until next reboot */
   3030 	EC_REBOOT_HIBERNATE = 6      /* Hibernate EC */
   3031 };
   3032 
   3033 /* Flags for ec_params_reboot_ec.reboot_flags */
   3034 #define EC_REBOOT_FLAG_RESERVED0      (1 << 0)  /* Was recovery request */
   3035 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1)  /* Reboot after AP shutdown */
   3036 
   3037 struct ec_params_reboot_ec {
   3038 	uint8_t cmd;           /* enum ec_reboot_cmd */
   3039 	uint8_t flags;         /* See EC_REBOOT_FLAG_* */
   3040 } __packed;
   3041 
   3042 /*
   3043  * Get information on last EC panic.
   3044  *
   3045  * Returns variable-length platform-dependent panic information.  See panic.h
   3046  * for details.
   3047  */
   3048 #define EC_CMD_GET_PANIC_INFO 0xd3
   3049 
   3050 /*****************************************************************************/
   3051 /*
   3052  * Special commands
   3053  *
   3054  * These do not follow the normal rules for commands.  See each command for
   3055  * details.
   3056  */
   3057 
   3058 /*
   3059  * Reboot NOW
   3060  *
   3061  * This command will work even when the EC LPC interface is busy, because the
   3062  * reboot command is processed at interrupt level.  Note that when the EC
   3063  * reboots, the host will reboot too, so there is no response to this command.
   3064  *
   3065  * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
   3066  */
   3067 #define EC_CMD_REBOOT 0xd1  /* Think "die" */
   3068 
   3069 /*
   3070  * Resend last response (not supported on LPC).
   3071  *
   3072  * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
   3073  * there was no previous command, or the previous command's response was too
   3074  * big to save.
   3075  */
   3076 #define EC_CMD_RESEND_RESPONSE 0xdb
   3077 
   3078 /*
   3079  * This header byte on a command indicate version 0. Any header byte less
   3080  * than this means that we are talking to an old EC which doesn't support
   3081  * versioning. In that case, we assume version 0.
   3082  *
   3083  * Header bytes greater than this indicate a later version. For example,
   3084  * EC_CMD_VERSION0 + 1 means we are using version 1.
   3085  *
   3086  * The old EC interface must not use commands 0xdc or higher.
   3087  */
   3088 #define EC_CMD_VERSION0 0xdc
   3089 
   3090 /*****************************************************************************/
   3091 /*
   3092  * PD commands
   3093  *
   3094  * These commands are for PD MCU communication.
   3095  */
   3096 
   3097 /* EC to PD MCU exchange status command */
   3098 #define EC_CMD_PD_EXCHANGE_STATUS 0x100
   3099 
   3100 enum pd_charge_state {
   3101 	PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
   3102 	PD_CHARGE_NONE,          /* No charging allowed */
   3103 	PD_CHARGE_5V,            /* 5V charging only */
   3104 	PD_CHARGE_MAX            /* Charge at max voltage */
   3105 };
   3106 
   3107 /* Status of EC being sent to PD */
   3108 struct ec_params_pd_status {
   3109 	int8_t batt_soc;      /* battery state of charge */
   3110 	uint8_t charge_state; /* charging state (from enum pd_charge_state) */
   3111 } __packed;
   3112 
   3113 /* Status of PD being sent back to EC */
   3114 #define PD_STATUS_HOST_EVENT      (1 << 0) /* Forward host event to AP */
   3115 #define PD_STATUS_IN_RW           (1 << 1) /* Running RW image */
   3116 #define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
   3117 #define PD_STATUS_TCPC_ALERT_0    (1 << 3) /* Alert active in port 0 TCPC */
   3118 #define PD_STATUS_TCPC_ALERT_1    (1 << 4) /* Alert active in port 1 TCPC */
   3119 #define PD_STATUS_EC_INT_ACTIVE  (PD_STATUS_TCPC_ALERT_0 | \
   3120 				      PD_STATUS_TCPC_ALERT_1 | \
   3121 				      PD_STATUS_HOST_EVENT)
   3122 struct ec_response_pd_status {
   3123 	uint32_t status;      /* PD MCU status */
   3124 	uint32_t curr_lim_ma; /* input current limit */
   3125 	int32_t active_charge_port; /* active charging port */
   3126 } __packed;
   3127 
   3128 /* AP to PD MCU host event status command, cleared on read */
   3129 #define EC_CMD_PD_HOST_EVENT_STATUS 0x104
   3130 
   3131 /* PD MCU host event status bits */
   3132 #define PD_EVENT_UPDATE_DEVICE     (1 << 0)
   3133 #define PD_EVENT_POWER_CHANGE      (1 << 1)
   3134 #define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
   3135 #define PD_EVENT_DATA_SWAP         (1 << 3)
   3136 struct ec_response_host_event_status {
   3137 	uint32_t status;      /* PD MCU host event status */
   3138 } __packed;
   3139 
   3140 /* Set USB type-C port role and muxes */
   3141 #define EC_CMD_USB_PD_CONTROL 0x101
   3142 
   3143 enum usb_pd_control_role {
   3144 	USB_PD_CTRL_ROLE_NO_CHANGE = 0,
   3145 	USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
   3146 	USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
   3147 	USB_PD_CTRL_ROLE_FORCE_SINK = 3,
   3148 	USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
   3149 	USB_PD_CTRL_ROLE_COUNT
   3150 };
   3151 
   3152 enum usb_pd_control_mux {
   3153 	USB_PD_CTRL_MUX_NO_CHANGE = 0,
   3154 	USB_PD_CTRL_MUX_NONE = 1,
   3155 	USB_PD_CTRL_MUX_USB = 2,
   3156 	USB_PD_CTRL_MUX_DP = 3,
   3157 	USB_PD_CTRL_MUX_DOCK = 4,
   3158 	USB_PD_CTRL_MUX_AUTO = 5,
   3159 	USB_PD_CTRL_MUX_COUNT
   3160 };
   3161 
   3162 enum usb_pd_control_swap {
   3163 	USB_PD_CTRL_SWAP_NONE = 0,
   3164 	USB_PD_CTRL_SWAP_DATA = 1,
   3165 	USB_PD_CTRL_SWAP_POWER = 2,
   3166 	USB_PD_CTRL_SWAP_VCONN = 3,
   3167 	USB_PD_CTRL_SWAP_COUNT
   3168 };
   3169 
   3170 struct ec_params_usb_pd_control {
   3171 	uint8_t port;
   3172 	uint8_t role;
   3173 	uint8_t mux;
   3174 	uint8_t swap;
   3175 } __packed;
   3176 
   3177 struct ec_response_usb_pd_control {
   3178 	uint8_t enabled;
   3179 	uint8_t role;
   3180 	uint8_t polarity;
   3181 	uint8_t state;
   3182 } __packed;
   3183 
   3184 struct ec_response_usb_pd_control_v1 {
   3185 	uint8_t enabled; /* [0] comm enabled [1] connected */
   3186 	uint8_t role; /* [0] power: 0=SNK/1=SRC [1] data: 0=UFP/1=DFP
   3187 			 [2] vconn 0=off/1=on */
   3188 	uint8_t polarity;
   3189 	char state[32];
   3190 } __packed;
   3191 
   3192 #define EC_CMD_USB_PD_PORTS 0x102
   3193 
   3194 struct ec_response_usb_pd_ports {
   3195 	uint8_t num_ports;
   3196 } __packed;
   3197 
   3198 #define EC_CMD_USB_PD_POWER_INFO 0x103
   3199 
   3200 #define PD_POWER_CHARGING_PORT 0xff
   3201 struct ec_params_usb_pd_power_info {
   3202 	uint8_t port;
   3203 } __packed;
   3204 
   3205 enum usb_chg_type {
   3206 	USB_CHG_TYPE_NONE,
   3207 	USB_CHG_TYPE_PD,
   3208 	USB_CHG_TYPE_C,
   3209 	USB_CHG_TYPE_PROPRIETARY,
   3210 	USB_CHG_TYPE_BC12_DCP,
   3211 	USB_CHG_TYPE_BC12_CDP,
   3212 	USB_CHG_TYPE_BC12_SDP,
   3213 	USB_CHG_TYPE_OTHER,
   3214 	USB_CHG_TYPE_VBUS,
   3215 	USB_CHG_TYPE_UNKNOWN,
   3216 };
   3217 enum usb_power_roles {
   3218 	USB_PD_PORT_POWER_DISCONNECTED,
   3219 	USB_PD_PORT_POWER_SOURCE,
   3220 	USB_PD_PORT_POWER_SINK,
   3221 	USB_PD_PORT_POWER_SINK_NOT_CHARGING,
   3222 };
   3223 
   3224 struct usb_chg_measures {
   3225 	uint16_t voltage_max;
   3226 	uint16_t voltage_now;
   3227 	uint16_t current_max;
   3228 	uint16_t current_lim;
   3229 } __packed;
   3230 
   3231 struct ec_response_usb_pd_power_info {
   3232 	uint8_t role;
   3233 	uint8_t type;
   3234 	uint8_t dualrole;
   3235 	uint8_t reserved1;
   3236 	struct usb_chg_measures meas;
   3237 	uint32_t max_power;
   3238 } __packed;
   3239 
   3240 /* Write USB-PD device FW */
   3241 #define EC_CMD_USB_PD_FW_UPDATE 0x110
   3242 
   3243 enum usb_pd_fw_update_cmds {
   3244 	USB_PD_FW_REBOOT,
   3245 	USB_PD_FW_FLASH_ERASE,
   3246 	USB_PD_FW_FLASH_WRITE,
   3247 	USB_PD_FW_ERASE_SIG,
   3248 };
   3249 
   3250 struct ec_params_usb_pd_fw_update {
   3251 	uint16_t dev_id;
   3252 	uint8_t cmd;
   3253 	uint8_t port;
   3254 	uint32_t size;     /* Size to write in bytes */
   3255 	/* Followed by data to write */
   3256 } __packed;
   3257 
   3258 /* Write USB-PD Accessory RW_HASH table entry */
   3259 #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x111
   3260 /* RW hash is first 20 bytes of SHA-256 of RW section */
   3261 #define PD_RW_HASH_SIZE 20
   3262 struct ec_params_usb_pd_rw_hash_entry {
   3263 	uint16_t dev_id;
   3264 	uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
   3265 	uint8_t reserved;        /* For alignment of current_image */
   3266 	uint32_t current_image;  /* One of ec_current_image */
   3267 } __packed;
   3268 
   3269 /* Read USB-PD Accessory info */
   3270 #define EC_CMD_USB_PD_DEV_INFO 0x112
   3271 
   3272 struct ec_params_usb_pd_info_request {
   3273 	uint8_t port;
   3274 } __packed;
   3275 
   3276 /* Read USB-PD Device discovery info */
   3277 #define EC_CMD_USB_PD_DISCOVERY 0x113
   3278 struct ec_params_usb_pd_discovery_entry {
   3279 	uint16_t vid;  /* USB-IF VID */
   3280 	uint16_t pid;  /* USB-IF PID */
   3281 	uint8_t ptype; /* product type (hub,periph,cable,ama) */
   3282 } __packed;
   3283 
   3284 /* Override default charge behavior */
   3285 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x114
   3286 
   3287 /* Negative port parameters have special meaning */
   3288 enum usb_pd_override_ports {
   3289 	OVERRIDE_DONT_CHARGE = -2,
   3290 	OVERRIDE_OFF = -1,
   3291 	/* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
   3292 };
   3293 
   3294 struct ec_params_charge_port_override {
   3295 	int16_t override_port; /* Override port# */
   3296 } __packed;
   3297 
   3298 /* Read (and delete) one entry of PD event log */
   3299 #define EC_CMD_PD_GET_LOG_ENTRY 0x115
   3300 
   3301 struct ec_response_pd_log {
   3302 	uint32_t timestamp; /* relative timestamp in milliseconds */
   3303 	uint8_t type;       /* event type : see PD_EVENT_xx below */
   3304 	uint8_t size_port;  /* [7:5] port number [4:0] payload size in bytes */
   3305 	uint16_t data;      /* type-defined data payload */
   3306 	uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
   3307 } __packed;
   3308 
   3309 
   3310 /* The timestamp is the microsecond counter shifted to get about a ms. */
   3311 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
   3312 
   3313 #define PD_LOG_SIZE_MASK  0x1f
   3314 #define PD_LOG_PORT_MASK  0xe0
   3315 #define PD_LOG_PORT_SHIFT    5
   3316 #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
   3317 				      ((size) & PD_LOG_SIZE_MASK))
   3318 #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
   3319 #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
   3320 
   3321 /* PD event log : entry types */
   3322 /* PD MCU events */
   3323 #define PD_EVENT_MCU_BASE       0x00
   3324 #define PD_EVENT_MCU_CHARGE             (PD_EVENT_MCU_BASE+0)
   3325 #define PD_EVENT_MCU_CONNECT            (PD_EVENT_MCU_BASE+1)
   3326 /* Reserved for custom board event */
   3327 #define PD_EVENT_MCU_BOARD_CUSTOM       (PD_EVENT_MCU_BASE+2)
   3328 /* PD generic accessory events */
   3329 #define PD_EVENT_ACC_BASE       0x20
   3330 #define PD_EVENT_ACC_RW_FAIL   (PD_EVENT_ACC_BASE+0)
   3331 #define PD_EVENT_ACC_RW_ERASE  (PD_EVENT_ACC_BASE+1)
   3332 /* PD power supply events */
   3333 #define PD_EVENT_PS_BASE        0x40
   3334 #define PD_EVENT_PS_FAULT      (PD_EVENT_PS_BASE+0)
   3335 /* PD video dongles events */
   3336 #define PD_EVENT_VIDEO_BASE     0x60
   3337 #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
   3338 #define PD_EVENT_VIDEO_CODEC   (PD_EVENT_VIDEO_BASE+1)
   3339 /* Returned in the "type" field, when there is no entry available */
   3340 #define PD_EVENT_NO_ENTRY       0xff
   3341 
   3342 /*
   3343  * PD_EVENT_MCU_CHARGE event definition :
   3344  * the payload is "struct usb_chg_measures"
   3345  * the data field contains the port state flags as defined below :
   3346  */
   3347 /* Port partner is a dual role device */
   3348 #define CHARGE_FLAGS_DUAL_ROLE         (1 << 15)
   3349 /* Port is the pending override port */
   3350 #define CHARGE_FLAGS_DELAYED_OVERRIDE  (1 << 14)
   3351 /* Port is the override port */
   3352 #define CHARGE_FLAGS_OVERRIDE          (1 << 13)
   3353 /* Charger type */
   3354 #define CHARGE_FLAGS_TYPE_SHIFT               3
   3355 #define CHARGE_FLAGS_TYPE_MASK       (0xf << CHARGE_FLAGS_TYPE_SHIFT)
   3356 /* Power delivery role */
   3357 #define CHARGE_FLAGS_ROLE_MASK         (7 <<  0)
   3358 
   3359 /*
   3360  * PD_EVENT_PS_FAULT data field flags definition :
   3361  */
   3362 #define PS_FAULT_OCP                          1
   3363 #define PS_FAULT_FAST_OCP                     2
   3364 #define PS_FAULT_OVP                          3
   3365 #define PS_FAULT_DISCH                        4
   3366 
   3367 /*
   3368  * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
   3369  */
   3370 struct mcdp_version {
   3371 	uint8_t major;
   3372 	uint8_t minor;
   3373 	uint16_t build;
   3374 } __packed;
   3375 
   3376 struct mcdp_info {
   3377 	uint8_t family[2];
   3378 	uint8_t chipid[2];
   3379 	struct mcdp_version irom;
   3380 	struct mcdp_version fw;
   3381 } __packed;
   3382 
   3383 /* struct mcdp_info field decoding */
   3384 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
   3385 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
   3386 
   3387 /* Get/Set USB-PD Alternate mode info */
   3388 #define EC_CMD_USB_PD_GET_AMODE 0x116
   3389 struct ec_params_usb_pd_get_mode_request {
   3390 	uint16_t svid_idx; /* SVID index to get */
   3391 	uint8_t port;      /* port */
   3392 } __packed;
   3393 
   3394 struct ec_params_usb_pd_get_mode_response {
   3395 	uint16_t svid;   /* SVID */
   3396 	uint16_t opos;    /* Object Position */
   3397 	uint32_t vdo[6]; /* Mode VDOs */
   3398 } __packed;
   3399 
   3400 #define EC_CMD_USB_PD_SET_AMODE 0x117
   3401 
   3402 enum pd_mode_cmd {
   3403 	PD_EXIT_MODE = 0,
   3404 	PD_ENTER_MODE = 1,
   3405 	/* Not a command.  Do NOT remove. */
   3406 	PD_MODE_CMD_COUNT,
   3407 };
   3408 
   3409 struct ec_params_usb_pd_set_mode_request {
   3410 	uint32_t cmd;  /* enum pd_mode_cmd */
   3411 	uint16_t svid; /* SVID to set */
   3412 	uint8_t opos;  /* Object Position */
   3413 	uint8_t port;  /* port */
   3414 } __packed;
   3415 
   3416 /* Ask the PD MCU to record a log of a requested type */
   3417 #define EC_CMD_PD_WRITE_LOG_ENTRY 0x118
   3418 
   3419 struct ec_params_pd_write_log_entry {
   3420 	uint8_t type; /* event type : see PD_EVENT_xx above */
   3421 	uint8_t port; /* port#, or 0 for events unrelated to a given port */
   3422 } __packed;
   3423 
   3424 #endif  /* !__ACPI__ */
   3425 
   3426 /*****************************************************************************/
   3427 /*
   3428  * Passthru commands
   3429  *
   3430  * Some platforms have sub-processors chained to each other.  For example.
   3431  *
   3432  *     AP <--> EC <--> PD MCU
   3433  *
   3434  * The top 2 bits of the command number are used to indicate which device the
   3435  * command is intended for.  Device 0 is always the device receiving the
   3436  * command; other device mapping is board-specific.
   3437  *
   3438  * When a device receives a command to be passed to a sub-processor, it passes
   3439  * it on with the device number set back to 0.  This allows the sub-processor
   3440  * to remain blissfully unaware of whether the command originated on the next
   3441  * device up the chain, or was passed through from the AP.
   3442  *
   3443  * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
   3444  *     AP sends command 0x4002 to the EC
   3445  *     EC sends command 0x0002 to the PD MCU
   3446  *     EC forwards PD MCU response back to the AP
   3447  */
   3448 
   3449 /* Offset and max command number for sub-device n */
   3450 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
   3451 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
   3452 
   3453 /*****************************************************************************/
   3454 /*
   3455  * Deprecated constants. These constants have been renamed for clarity. The
   3456  * meaning and size has not changed. Programs that use the old names should
   3457  * switch to the new names soon, as the old names may not be carried forward
   3458  * forever.
   3459  */
   3460 #define EC_HOST_PARAM_SIZE      EC_PROTO2_MAX_PARAM_SIZE
   3461 #define EC_LPC_ADDR_OLD_PARAM   EC_HOST_CMD_REGION1
   3462 #define EC_OLD_PARAM_SIZE       EC_HOST_CMD_REGION_SIZE
   3463 
   3464 #endif  /* __CROS_EC_COMMANDS_H */
   3465