blob: 7310ade09dadfd598f900eaf466c11f612967d5f [file] [log] [blame]
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 The Chromium OS Authors. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
Stefan Reinauerd6682e82013-02-21 15:39:35 -080015 * Mailbox EC communication interface for Google Chrome Embedded Controller.
16 */
17
18#ifndef _EC_GOOGLE_CHROMEEC_EC_H
19#define _EC_GOOGLE_CHROMEEC_EC_H
Hung-Te Lin23fb9972013-06-21 20:11:47 +080020#include <stddef.h>
21#include <stdint.h>
Duncan Lauriee2cea4f2015-12-01 19:14:09 -080022#include "ec_commands.h"
Stefan Reinauerd6682e82013-02-21 15:39:35 -080023
Aaron Durbinfbb3e6c2016-05-10 17:00:06 -050024/* Fill in base and size of the IO port resources used. */
25void google_chromeec_ioport_range(uint16_t *base, size_t *size);
26
Gabe Black9f96aa62013-06-28 14:24:33 -070027int google_chromeec_i2c_xfer(uint8_t chip, uint8_t addr, int alen,
28 uint8_t *buffer, int len, int is_read);
Furquan Shaikh8788fd62017-11-20 20:28:18 -080029uint64_t google_chromeec_get_wake_mask(void);
30int google_chromeec_set_sci_mask(uint64_t mask);
31int google_chromeec_set_smi_mask(uint64_t mask);
32int google_chromeec_set_wake_mask(uint64_t mask);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080033u8 google_chromeec_get_event(void);
Jenny TC1dfc2c32017-12-14 14:24:39 +053034
35/* Check if EC supports feature EC_FEATURE_UNIFIED_WAKE_MASKS */
36bool google_chromeec_is_uhepi_supported(void);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080037int google_ec_running_ro(void);
Hung-Te Lin76720d02013-04-15 18:06:32 +080038void google_chromeec_init(void);
Daisuke Nojiri476c2c52018-01-26 17:36:44 -080039int google_chromeec_pd_get_amode(uint16_t svid);
Daisuke Nojirid182b632018-02-16 17:50:06 -080040int google_chromeec_wait_for_displayport(long timeout);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080041
Duncan Laurie7378a172017-06-29 23:52:17 -070042/* Device events */
Furquan Shaikh8788fd62017-11-20 20:28:18 -080043uint64_t google_chromeec_get_device_enabled_events(void);
44int google_chromeec_set_device_enabled_events(uint64_t mask);
45uint64_t google_chromeec_get_device_current_events(void);
Duncan Laurie7378a172017-06-29 23:52:17 -070046
Duncan Lauriee2cea4f2015-12-01 19:14:09 -080047int google_chromeec_check_feature(int feature);
Hung-Te Lin6bfbb332013-04-15 18:27:24 +080048uint8_t google_chromeec_calc_checksum(const uint8_t *data, int size);
Shawn Nematbakhshd0a6a382013-07-08 14:18:01 -070049u16 google_chromeec_get_board_version(void);
Patrick Georgi69206d92017-07-31 14:20:07 +020050u32 google_chromeec_get_sku_id(void);
Kevin Chiue2bb0592017-09-12 09:13:41 +080051int google_chromeec_set_sku_id(u32 skuid);
Furquan Shaikh8788fd62017-11-20 20:28:18 -080052uint64_t google_chromeec_get_events_b(void);
53int google_chromeec_clear_events_b(uint64_t mask);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080054int google_chromeec_kbbacklight(int percent);
55void google_chromeec_post(u8 postcode);
Stefan Reinaueraaaf6892013-08-29 15:57:11 -070056int google_chromeec_vbnv_context(int is_read, uint8_t *data, int len);
Duncan Laurie699c7882015-08-13 12:52:08 -070057uint8_t google_chromeec_get_switches(void);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080058
Duncan Lauriee2cea4f2015-12-01 19:14:09 -080059/* Temporary secure storage commands */
60int google_chromeec_vstore_supported(void);
61int google_chromeec_vstore_info(uint32_t *locked);
62int google_chromeec_vstore_read(int slot, uint8_t *data);
63int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size);
64
Aaron Durbine68d22f2017-05-04 12:32:52 -050065/* Issue reboot command to EC with specified type and flags. Returns 0 on
66 success, < 0 otherwise. */
67int google_chromeec_reboot(int dev_idx, enum ec_reboot_cmd type, uint8_t flags);
68
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -080069/**
70 * Get OEM (or SKU) ID from Cros Board Info
71 *
72 * @param id [OUT] oem/sku id
73 * @return 0 on success or negative integer for errors.
74 */
75int google_chromeec_cbi_get_oem_id(uint32_t *id);
76int google_chromeec_cbi_get_sku_id(uint32_t *id);
77
Alexandru Gagniuc851ef962016-03-30 14:38:44 -070078/* MEC uses 0x800/0x804 as register/index pair, thus an 8-byte resource. */
79#define MEC_EMI_BASE 0x800
80#define MEC_EMI_SIZE 8
81
Shawn Nematbakhsh5725ea32015-04-01 16:52:37 -070082/* For MEC, access ranges 0x800 thru 0x9ff using EMI interface instead of LPC */
83#define MEC_EMI_RANGE_START EC_HOST_CMD_REGION0
84#define MEC_EMI_RANGE_END (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE)
85
86void mec_io_bytes(int write, u16 offset, unsigned int length,
87 u8 *buf, u8 *csum);
88
Stefan Reinauerd6682e82013-02-21 15:39:35 -080089enum usb_charge_mode {
90 USB_CHARGE_MODE_DISABLED,
91 USB_CHARGE_MODE_CHARGE_AUTO,
92 USB_CHARGE_MODE_CHARGE_BC12,
93 USB_CHARGE_MODE_DOWNSTREAM_500MA,
94 USB_CHARGE_MODE_DOWNSTREAM_1500MA,
95};
96int google_chromeec_set_usb_charge_mode(u8 port_id, enum usb_charge_mode mode);
Julius Wernerea79d2b2016-11-21 20:14:07 -080097int google_chromeec_set_usb_pd_role(u8 port, enum usb_pd_control_role role);
Shelley Chenebd53302017-09-29 14:15:11 -070098/*
99 * Retrieve the charger type and max wattage.
100 *
101 * @param type charger type
102 * @param max_watts charger max wattage
103 * @return non-zero for error, otherwise 0.
104 */
105int google_chromeec_get_usb_pd_power_info(enum usb_chg_type *type,
106 u32 *max_watts);
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800107
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -0800108/*
109 * Set max current and voltage of a dedicated charger.
110 *
111 * @param current_lim Max current in mA
112 * @param voltage_lim Max voltage in mV
113 * @return non-zero for error, otherwise 0.
114 */
115int google_chromeec_override_dedicated_charger_limit(u16 current_lim,
116 u16 voltage_lim);
117
Hung-Te Lina904f9e2013-04-11 15:58:12 +0800118/* internal structure to send a command to the EC and wait for response. */
119struct chromeec_command {
Hung-Te Line946f982013-06-22 11:18:39 +0800120 uint16_t cmd_code; /* command code in, status out */
Hung-Te Lina904f9e2013-04-11 15:58:12 +0800121 uint8_t cmd_version; /* command version */
122 const void* cmd_data_in; /* command data, if any */
123 void* cmd_data_out; /* command response, if any */
124 uint16_t cmd_size_in; /* size of command data */
125 uint16_t cmd_size_out; /* expected size of command response in,
126 * actual received size out */
Duncan Lauriefc0f5172014-09-18 12:54:02 -0700127 int cmd_dev_index;/* device index for passthru */
Hung-Te Lina904f9e2013-04-11 15:58:12 +0800128};
129
Aaron Durbin82827272014-08-06 14:34:57 -0500130/*
131 * There are transport level constraints for sending protov3 packets. Because
132 * of this provide a way for the generic protocol layer to request buffers
133 * so that there is zero copying being done through the layers.
134 *
135 * Request the buffer provided the size. If 'req' is non-zero then the
136 * buffer requested is for EC requests. Otherwise it's for responses. Return
137 * non-NULL on success, NULL on error.
138 */
139void *crosec_get_buffer(size_t size, int req);
140
141/*
142 * The lower level transport works on the buffers handed out to the
143 * upper level. Therefore, only the size of the request and response
144 * are required.
145 */
146typedef int (*crosec_io_t)(size_t req_size, size_t resp_size, void *context);
Hung-Te Lin23fb9972013-06-21 20:11:47 +0800147int crosec_command_proto(struct chromeec_command *cec_command,
148 crosec_io_t crosec_io, void *context);
149
Hung-Te Lina904f9e2013-04-11 15:58:12 +0800150int google_chromeec_command(struct chromeec_command *cec_command);
151
Furquan Shaikh2749c522017-10-04 14:01:41 -0700152struct google_chromeec_event_info {
Furquan Shaikh8788fd62017-11-20 20:28:18 -0800153 uint64_t log_events;
154 uint64_t sci_events;
Furquan Shaikh1a5b7c62018-05-30 11:51:23 -0700155 uint64_t smi_events;
Furquan Shaikh8788fd62017-11-20 20:28:18 -0800156 uint64_t s3_wake_events;
157 uint64_t s3_device_events;
158 uint64_t s5_wake_events;
Jenny TC1dfc2c32017-12-14 14:24:39 +0530159 uint64_t s0ix_wake_events;
Furquan Shaikh2749c522017-10-04 14:01:41 -0700160};
161void google_chromeec_events_init(const struct google_chromeec_event_info *info,
162 bool is_s3_wakeup);
163
Furquan Shaikhe01bf642017-10-13 10:59:51 -0700164/*
165 * Get next available MKBP event in ec_response_get_next_event. Returns 0 on
166 * success, < 0 otherwise.
167 */
168int google_chromeec_get_mkbp_event(struct ec_response_get_next_event *event);
169
Furquan Shaikh70b257f2017-10-16 23:00:27 -0700170/* Log host events to eventlog based on the mask provided. */
Furquan Shaikh8788fd62017-11-20 20:28:18 -0800171void google_chromeec_log_events(uint64_t mask);
Furquan Shaikh70b257f2017-10-16 23:00:27 -0700172
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800173#endif /* _EC_GOOGLE_CHROMEEC_EC_H */