coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ec.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 /*
4  * Mailbox EC communication interface for Google Chrome Embedded Controller.
5  */
6 
7 #ifndef _EC_GOOGLE_CHROMEEC_EC_H
8 #define _EC_GOOGLE_CHROMEEC_EC_H
9 #include <types.h>
10 #include <device/device.h>
11 #include "ec_commands.h"
12 #include <device/usbc_mux.h>
13 
14 /* Fill in base and size of the IO port resources used. */
15 void google_chromeec_ioport_range(uint16_t *base, size_t *size);
16 
18  uint8_t *buffer, int len, int is_read);
24 
25 /* Check if EC supports feature EC_FEATURE_UNIFIED_WAKE_MASKS */
27 int google_ec_running_ro(void);
29 void google_chromeec_init(void);
30 /* Check for the current mux state in EC
31  * in: int port physical port number of the type-c port
32  * out: uint8_t flags representing the status of the mux such as
33  * usb capability, dp capability, cable type, etc
34  */
36 /* Poll (up to `timeout_ms` ms) for DisplayPort to be ready
37  * Return: -1: Error. 0: Timeout.
38  * >=1: Bitmask of the ports that DP device is connected
39  */
40 int google_chromeec_wait_for_displayport(long timeout_ms);
41 /* Poll (up to `timeout_ms` ms) for a Hot-Plug Detect (HPD)
42  * event on the specified port.
43  * Return: 0 on HPD ready, -1 on timeout */
44 int google_chromeec_wait_for_dp_hpd(int port, long timeout_ms);
45 /* Send command to EC to request to enter DisplayPort ALT mode on the
46  * specified port.
47  * Return: 0 on success, -1 on error */
49 /*
50  * Obtain any USB-C mux data needed for the specified port
51  * in: int port physical port number of the type-c port
52  * out: struct usbc_mux_info mux_info stores USB-C mux data
53  * Return: 0 on success, -1 on error
54  */
55 int google_chromeec_get_usbc_mux_info(int port, struct usbc_mux_info *mux_info);
56 
57 /* Device events */
61 
62 int google_chromeec_check_feature(int feature);
63 uint8_t google_chromeec_calc_checksum(const uint8_t *data, int size);
64 
65 /**
66  * google_chromeec_get_board_version() - Get the board version
67  * @version: Out parameter to retrieve the board Version
68  *
69  * Return: 0 on success or -1 on failure/error.
70  *
71  * This function is used to get the board version information from EC.
72  */
78 int google_chromeec_kbbacklight(int percent);
79 void google_chromeec_post(uint8_t postcode);
80 int google_chromeec_vbnv_context(int is_read, uint8_t *data, int len);
83 
84 /* Temporary secure storage commands */
87 int google_chromeec_vstore_read(int slot, uint8_t *data);
88 int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size);
89 
90 /* Issue reboot command to EC with specified type and flags. Returns 0 on
91  success, < 0 otherwise. */
92 int google_chromeec_reboot(int dev_idx, enum ec_reboot_cmd type, uint8_t flags);
93 
94 /**
95  * Get data from Cros Board Info
96  *
97  * @param id/fw_config/buf [OUT] value from CBI.
98  * @return 0 on success or negative integer for errors.
99  */
103 int google_chromeec_cbi_get_dram_part_num(char *buf, size_t bufsize);
104 int google_chromeec_cbi_get_oem_name(char *buf, size_t bufsize);
105 /* version may be stored in CBI as a smaller integer width, but the EC code
106  handles it correctly. */
109 
110 #define CROS_SKU_UNKNOWN 0xFFFFFFFF
111 #define CROS_SKU_UNPROVISIONED 0x7FFFFFFF
112 /* Returns CROS_SKU_UNKNOWN on failure. */
114 const char *google_chromeec_smbios_system_sku(void);
115 
116 /* MEC uses 0x800/0x804 as register/index pair, thus an 8-byte resource. */
117 #define MEC_EMI_BASE 0x800
118 #define MEC_EMI_SIZE 8
119 
120 /* For MEC, access ranges 0x800 thru 0x9ff using EMI interface instead of LPC */
121 #define MEC_EMI_RANGE_START EC_HOST_CMD_REGION0
122 #define MEC_EMI_RANGE_END (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE)
123 
126 /*
127  * Retrieve the charger type and max wattage.
128  *
129  * @param type charger type
130  * @param current_max charger max current
131  * @param voltage_max charger max voltage
132  * @return non-zero for error, otherwise 0.
133  */
135  uint16_t *current_max, uint16_t *voltage_max);
136 
137 /*
138  * Set max current and voltage of a dedicated charger.
139  *
140  * @param current_lim Max current in mA
141  * @param voltage_lim Max voltage in mV
142  * @return non-zero for error, otherwise 0.
143  */
145  uint16_t voltage_lim);
146 
147 /* internal structure to send a command to the EC and wait for response. */
149  uint16_t cmd_code; /* command code in, status out */
150  uint8_t cmd_version; /* command version */
151  const void* cmd_data_in; /* command data, if any */
152  void* cmd_data_out; /* command response, if any */
153  uint16_t cmd_size_in; /* size of command data */
154  uint16_t cmd_size_out; /* expected size of command response in,
155  * actual received size out */
156  int cmd_dev_index;/* device index for passthru */
157 };
158 
159 /*
160  * There are transport level constraints for sending protov3 packets. Because
161  * of this provide a way for the generic protocol layer to request buffers
162  * so that there is zero copying being done through the layers.
163  *
164  * Request the buffer provided the size. If 'req' is non-zero then the
165  * buffer requested is for EC requests. Otherwise it's for responses. Return
166  * non-NULL on success, NULL on error.
167  */
168 void *crosec_get_buffer(size_t size, int req);
169 
170 /*
171  * The lower level transport works on the buffers handed out to the
172  * upper level. Therefore, only the size of the request and response
173  * are required.
174  */
175 typedef int (*crosec_io_t)(size_t req_size, size_t resp_size, void *context);
177  crosec_io_t crosec_io, void *context);
178 
179 /**
180  * Performs light verification of the EC<->AP communication channel.
181  *
182  * @return 0 on success, -1 on error
183  */
184 int google_chromeec_hello(void);
185 
186 /**
187  * Send a command to a CrOS EC
188  *
189  * @param cec_command: CrOS EC command to send
190  * @return 0 for success. Non-zero for error.
191  */
193 
202 };
204  bool is_s3_wakeup);
205 
206 /*
207  * Get next available MKBP event in ec_response_get_next_event. Returns 0 on
208  * success, < 0 otherwise.
209  */
211 
212 /* Log host events to eventlog based on the mask provided. */
214 
215 /**
216  * Protect/un-protect EC flash regions.
217  *
218  * @param mask Set/clear the requested bits in 'flags'
219  * @param flags Flash protection flags
220  * @param resp Pointer to response structure
221  * @return 0 on success, -1 on error
222  */
224  struct ec_response_flash_protect *resp);
225 /**
226  * Calculate image hash for vboot.
227  *
228  * @param hash_type The hash types supported by the EC for vboot
229  * @param offset The offset to start hashing in flash
230  * @param resp Pointer to response structure
231  * @return 0 on success, -1 on error
232  */
235  struct ec_response_vboot_hash *resp);
236 /**
237  * Return the EC's vboot image hash.
238  *
239  * @param offset Get hash for flash region beginning here
240  * @param resp Pointer to response structure
241  * @return 0 on success, -1 on error
242  *
243  */
245  struct ec_response_vboot_hash *resp);
246 
247 /**
248  * Get offset and size of the specified EC flash region.
249  *
250  * @param region Which region of EC flash
251  * @param offset Gets filled with region's offset
252  * @param size Gets filled with region's size
253  * @return 0 on success, -1 on error
254  */
256  uint32_t *offset, uint32_t *size);
257 /**
258  * Erase a region of EC flash.
259  *
260  * @param offset Where to begin erasing
261  * @param size Size of area to erase
262  * @return 0 on success, -1 on error
263  */
265 
266 /**
267  * Return information about the entire flash.
268  *
269  * @param info Pointer to response structure
270  * @return 0 on success, -1 on error
271  */
273 
274 /**
275  * Write a block into EC flash.
276  *
277  * @param data Pointer to data to write to flash, prefixed by a
278  * struct ec_params_flash_write
279  * @param offset Offset to begin writing data
280  * @param size Number of bytes to be written to flash from data
281  * @return 0 on success, -1 on error
282  */
283 int google_chromeec_flash_write_block(const uint8_t *data, uint32_t size);
284 
285 /**
286  * Verify flash using EFS if available.
287  *
288  * @param region Which flash region to verify
289  * @return 0 on success, -1 on error
290  */
292 
293 /**
294  * Command EC to perform battery cutoff.
295  *
296  * @param flags Flags to pass to the EC
297  * @return 0 on success, -1 on error
298  */
300 
301 /**
302  * Check if the EC is requesting the system to limit input power.
303  *
304  * @param limit_power If successful, limit_power is 1 if EC is requesting
305  * input power limits, otherwise 0.
306  * @return 0 on success, -1 on error
307  */
308 int google_chromeec_read_limit_power_request(int *limit_power);
309 
310 /**
311  * Get information about the protocol that the EC speaks.
312  *
313  * @param resp Filled with host command protocol information.
314  * @return 0 on success, -1 on error
315  */
317  struct ec_response_get_protocol_info *resp);
318 
319 /**
320  * Get available versions of the specified command.
321  *
322  * @param command Command ID
323  * @param pmask Pointer to version mask
324  * @return 0 on success, -1 on error
325  */
326 int google_chromeec_get_cmd_versions(int command, uint32_t *pmask);
327 
328 /**
329  * Get number of PD-capable USB ports from EC.
330  *
331  * @param *num_ports If successful, num_ports is the number
332  * of PD-capable USB ports according to the EC.
333  * @return 0 on success, -1 on error
334  */
335 int google_chromeec_get_num_pd_ports(unsigned int *num_ports);
336 
337 /* Structure representing the capabilities of a USB-PD port */
343 };
344 
345 /**
346  * Get role-based capabilities for a USB-PD port
347  *
348  * @param port Which port to get information about
349  * @param *power_role_cap The power-role capability of the port
350  * @param *try_power_role_cap The Try-power-role capability of the port
351  * @param *data_role_cap The data role capability of the port
352  * @param *port_location Location of the port on the device
353  * @return 0 on success, -1 on error
354  */
356  struct usb_pd_port_caps *port_caps);
357 
358 /**
359  * Get the keyboard configuration / layout information from EC
360  *
361  * @param *keybd If successful, this is filled with EC filled parameters
362  * @return 0 on success, -1 on error
363  */
365 
366 /**
367  * Send EC command to perform AP reset
368  *
369  * @return 0 on success, -1 on error
370  */
371 int google_chromeec_ap_reset(void);
372 
373 /**
374  * Configure the regulator as enabled / disabled.
375  *
376  * @param index Regulator ID
377  * @param enable Set to enable / disable the regulator
378  * @return 0 on success, -1 on error
379  */
381 
382 /**
383  * Query if the regulator is enabled.
384  *
385  * @param index Regulator ID
386  * @param *enabled If successful, enabled indicates enable/disable status.
387  * @return 0 on success, -1 on error
388  */
390 
391 /**
392  * Set voltage for the voltage regulator within the range specified.
393  *
394  * @param index Regulator ID
395  * @param min_mv Minimum voltage
396  * @param max_mv Maximum voltage
397  * @return 0 on success, -1 on error
398  */
400  uint32_t max_mv);
401 
402 /**
403  * Get the currently configured voltage for the voltage regulator.
404  *
405  * @param index Regulator ID
406  * @param *voltage_mv If successful, voltage_mv is filled with current voltage
407  * @return 0 on success, -1 on error
408  */
410 
411 #if CONFIG(HAVE_ACPI_TABLES)
412 /**
413  * Writes USB Type-C PD related information to the SSDT
414  *
415  * @param dev EC device
416  */
417 void google_chromeec_fill_ssdt_generator(const struct device *dev);
418 
419 /**
420  * Returns the ACPI name for the EC device.
421  *
422  * @param dev EC device
423  */
424 const char *google_chromeec_acpi_name(const struct device *dev);
425 
426 #endif /* HAVE_ACPI_TABLES */
427 
428 #endif /* _EC_GOOGLE_CHROMEEC_EC_H */
static u32 addr
Definition: cirrus.c:14
static struct smmstore_params_info info
Definition: ramstage.c:12
int google_chromeec_command(struct chromeec_command *cec_command)
Send a command to a CrOS EC.
Definition: ec_i2c.c:176
int google_chromeec_get_pd_port_caps(int port, struct usb_pd_port_caps *port_caps)
Get role-based capabilities for a USB-PD port.
Definition: ec.c:1440
int google_chromeec_set_device_enabled_events(uint64_t mask)
Definition: ec.c:323
int google_chromeec_cbi_get_fw_config(uint64_t *fw_config)
Definition: ec.c:844
int google_chromeec_get_vboot_hash(uint32_t offset, struct ec_response_vboot_hash *resp)
Return the EC's vboot image hash.
Definition: ec.c:487
int google_chromeec_clear_events_b(uint64_t mask)
Definition: ec.c:277
uint8_t google_chromeec_calc_checksum(const uint8_t *data, int size)
Definition: ec.c:66
int google_chromeec_wait_for_displayport(long timeout_ms)
Wait for DisplayPort to be ready.
Definition: ec.c:1668
int google_chromeec_get_protocol_info(struct ec_response_get_protocol_info *resp)
Get information about the protocol that the EC speaks.
Definition: ec.c:734
int google_chromeec_get_cmd_versions(int command, uint32_t *pmask)
Get available versions of the specified command.
Definition: ec.c:464
int google_chromeec_typec_control_enter_dp_mode(int port)
Definition: ec.c:1512
int google_chromeec_cbi_get_board_version(uint32_t *version)
Definition: ec.c:870
int google_chromeec_set_wake_mask(uint64_t mask)
Definition: ec.c:1131
int google_chromeec_flash_info(struct ec_response_flash_info *info)
Return information about the entire flash.
Definition: ec.c:609
int google_chromeec_vstore_supported(void)
Definition: vstore.c:11
int google_chromeec_regulator_is_enabled(uint32_t index, uint8_t *enabled)
Query if the regulator is enabled.
Definition: ec.c:1776
int google_chromeec_hello(void)
Performs light verification of the EC<->AP communication channel.
Definition: ec.c:1236
int google_chromeec_get_board_version(uint32_t *version)
google_chromeec_get_board_version() - Get the board version
Definition: ec.c:915
void google_chromeec_post(uint8_t postcode)
Definition: ec.c:97
void google_chromeec_ioport_range(uint16_t *base, size_t *size)
Definition: ec_lpc.c:364
int google_chromeec_flash_region_info(enum ec_flash_region region, uint32_t *offset, uint32_t *size)
Get offset and size of the specified EC flash region.
Definition: ec.c:559
int google_chromeec_flash_erase(uint32_t region_offset, uint32_t region_size)
Erase a region of EC flash.
Definition: ec.c:587
const char * google_chromeec_smbios_system_sku(void)
Definition: ec_smbios.c:9
bool google_chromeec_get_ap_watchdog_flag(void)
Definition: ec.c:1008
uint32_t google_chromeec_get_sku_id(void)
Definition: ec.c:934
int google_chromeec_reboot(int dev_idx, enum ec_reboot_cmd type, uint8_t flags)
Definition: ec.c:794
uint64_t google_chromeec_get_events_b(void)
Definition: ec.c:272
int google_chromeec_read_limit_power_request(int *limit_power)
Check if the EC is requesting the system to limit input power.
Definition: ec.c:700
int google_chromeec_check_feature(int feature)
Definition: ec.c:443
int google_chromeec_flash_protect(uint32_t mask, uint32_t flags, struct ec_response_flash_protect *resp)
Protect/un-protect EC flash regions.
Definition: ec.c:536
enum host_event_code google_chromeec_get_event(void)
Definition: ec_i2c.c:242
int google_chromeec_cbi_get_dram_part_num(char *buf, size_t bufsize)
Definition: ec.c:905
int google_ec_running_ro(void)
Definition: ec.c:1475
uint64_t google_chromeec_get_device_current_events(void)
Definition: ec.c:344
int google_chromeec_regulator_set_voltage(uint32_t index, uint32_t min_mv, uint32_t max_mv)
Set voltage for the voltage regulator within the range specified.
Definition: ec.c:1800
void google_chromeec_log_events(uint64_t mask)
Definition: ec.c:386
int crosec_command_proto(struct chromeec_command *cec_command, crosec_io_t crosec_io, void *context)
Definition: crosec_proto.c:240
int google_chromeec_set_sku_id(uint32_t skuid)
Definition: ec.c:753
int google_chromeec_cbi_get_oem_id(uint32_t *id)
Get data from Cros Board Info.
Definition: ec.c:865
int google_chromeec_flash_write_block(const uint8_t *data, uint32_t size)
Write a block into EC flash.
Definition: ec.c:632
int google_chromeec_usb_get_pd_mux_info(int port, uint8_t *flags)
Check for the current mux state in EC.
Definition: ec.c:1543
int google_chromeec_get_num_pd_ports(unsigned int *num_ports)
Get number of PD-capable USB ports from EC.
Definition: ec.c:1419
uint64_t google_chromeec_get_wake_mask(void)
Definition: ec.c:1138
int google_chromeec_get_keybd_config(struct ec_response_keybd_config *keybd)
Get the keyboard configuration / layout information from EC.
Definition: ec.c:1718
int google_chromeec_wait_for_dp_hpd(int port, long timeout_ms)
Definition: ec.c:1699
int google_chromeec_start_vboot_hash(enum ec_vboot_hash_type hash_type, uint32_t offset, struct ec_response_vboot_hash *resp)
Calculate image hash for vboot.
Definition: ec.c:510
enum ec_image google_chromeec_get_current_image(void)
Definition: ec.c:1384
int google_chromeec_i2c_xfer(uint8_t chip, uint8_t addr, int alen, uint8_t *buffer, int len, int is_read)
Definition: ec.c:1030
int google_chromeec_vstore_info(uint32_t *locked)
Definition: vstore.c:22
int google_chromeec_get_usb_pd_power_info(enum usb_chg_type *type, uint16_t *current_max, uint16_t *voltage_max)
Definition: ec.c:1163
int google_chromeec_get_usbc_mux_info(int port, struct usbc_mux_info *mux_info)
Definition: ec.c:1575
uint8_t google_chromeec_get_switches(void)
Definition: ec_lpc.c:359
int google_chromeec_get_mkbp_event(struct ec_response_get_next_event *event)
Definition: ec.c:284
int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size)
Definition: vstore.c:75
int google_chromeec_vstore_read(int slot, uint8_t *data)
Definition: vstore.c:45
int(* crosec_io_t)(size_t req_size, size_t resp_size, void *context)
Definition: ec.h:175
int google_chromeec_set_smi_mask(uint64_t mask)
Definition: ec.c:1125
int google_chromeec_set_usb_pd_role(uint8_t port, enum usb_pd_control_role role)
Definition: ec.c:1214
int google_chromeec_kbbacklight(int percent)
Definition: ec.c:75
void google_chromeec_events_init(const struct google_chromeec_event_info *info, bool is_s3_wakeup)
Definition: ec.c:410
int google_chromeec_cbi_get_ssfc(uint32_t *ssfc)
Definition: ec.c:875
uint64_t google_chromeec_get_device_enabled_events(void)
Definition: ec.c:300
int google_chromeec_override_dedicated_charger_limit(uint16_t current_lim, uint16_t voltage_lim)
Definition: ec.c:1194
bool google_chromeec_is_uhepi_supported(void)
Definition: ec.c:177
uint32_t google_chromeec_get_board_sku(void)
Definition: ec_skuid.c:6
int google_chromeec_cbi_get_sku_id(uint32_t *id)
Definition: ec.c:839
int google_chromeec_vbnv_context(int is_read, uint8_t *data, int len)
Definition: ec.c:952
void * crosec_get_buffer(size_t size, int req)
Definition: crosec_proto.c:12
int google_chromeec_battery_cutoff(uint8_t flags)
Command EC to perform battery cutoff.
Definition: ec.c:679
int google_chromeec_ap_reset(void)
Send EC command to perform AP reset.
Definition: ec.c:1736
int google_chromeec_regulator_enable(uint32_t index, uint8_t enable)
Configure the regulator as enabled / disabled.
Definition: ec.c:1754
int google_chromeec_set_usb_charge_mode(uint8_t port_id, enum usb_charge_mode mode)
Definition: ec.c:1143
int google_chromeec_efs_verify(enum ec_flash_region region)
Verify flash using EFS if available.
Definition: ec.c:653
void google_chromeec_init(void)
Definition: ec.c:1470
int google_chromeec_regulator_get_voltage(uint32_t index, uint32_t *voltage_mv)
Get the currently configured voltage for the voltage regulator.
Definition: ec.c:1824
int google_chromeec_cbi_get_oem_name(char *buf, size_t bufsize)
Definition: ec.c:910
int google_chromeec_set_sci_mask(uint64_t mask)
Definition: ec.c:1119
void google_chromeec_fill_ssdt_generator(const struct device *dev)
Definition: ec_acpi.c:265
const char * google_chromeec_acpi_name(const struct device *dev)
Definition: ec_acpi.c:21
static struct usb_pd_port_caps port_caps
Definition: ec_acpi.c:121
ec_pd_power_role_caps
Definition: ec_commands.h:6294
ec_flash_region
Definition: ec_commands.h:1812
host_event_code
Definition: ec_commands.h:653
usb_pd_control_role
Definition: ec_commands.h:5504
ec_reboot_cmd
Definition: ec_commands.h:5367
usb_charge_mode
Definition: ec_commands.h:3238
cec_command
Definition: ec_commands.h:5071
ec_image
Definition: ec_commands.h:1141
usb_chg_type
Definition: ec_commands.h:5618
ec_pd_try_power_role_caps
Definition: ec_commands.h:6300
ec_vboot_hash_type
Definition: ec_commands.h:2495
ec_pd_data_role_caps
Definition: ec_commands.h:6306
ec_pd_port_location
Definition: ec_commands.h:6313
static size_t offset
Definition: flashconsole.c:16
static struct tpm_chip chip
Definition: tis.c:17
port
Definition: i915.h:29
unsigned int type
Definition: edid.c:57
unsigned int version[2]
Definition: edid.c:55
static uint8_t * buf
Definition: uart.c:7
u8 buffer[C2P_BUFFER_MAXSIZE]
Definition: psp_smm.c:18
static size_t region_offset(const struct region *r)
Definition: region.h:105
uintptr_t base
Definition: uart.c:17
static const int mask[4]
Definition: gpio.c:308
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
unsigned long long uint64_t
Definition: stdint.h:17
unsigned char uint8_t
Definition: stdint.h:8
uint8_t cmd_version
Definition: ec.h:150
uint16_t cmd_size_in
Definition: ec.h:153
int cmd_dev_index
Definition: ec.h:156
void * cmd_data_out
Definition: ec.h:152
const void * cmd_data_in
Definition: ec.h:151
uint16_t cmd_size_out
Definition: ec.h:154
uint16_t cmd_code
Definition: ec.h:149
Definition: device.h:107
struct ec_response_flash_info - Response to the flash info command.
Definition: ec_commands.h:1547
struct ec_response_flash_protect - Response to the flash protect command.
Definition: ec_commands.h:1797
struct ec_response_get_protocol_info - Response to the get protocol info.
Definition: ec_commands.h:1341
struct fw_config - Firmware configuration field and option.
Definition: fw_config.h:20
uint64_t smi_events
Definition: ec.h:197
uint64_t log_events
Definition: ec.h:195
uint64_t s5_wake_events
Definition: ec.h:200
uint64_t sci_events
Definition: ec.h:196
uint64_t s3_wake_events
Definition: ec.h:198
uint64_t s3_device_events
Definition: ec.h:199
uint64_t s0ix_wake_events
Definition: ec.h:201
Definition: region.h:76
enum ec_pd_power_role_caps power_role_cap
Definition: ec.h:339
enum ec_pd_try_power_role_caps try_power_role_cap
Definition: ec.h:340
enum ec_pd_port_location port_location
Definition: ec.h:342
enum ec_pd_data_role_caps data_role_cap
Definition: ec.h:341