blob: 0b6f880909c5e3358a15c13471b1fe9317cecbb6 [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);
34int google_ec_running_ro(void);
Hung-Te Lin76720d02013-04-15 18:06:32 +080035void google_chromeec_init(void);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080036
Duncan Laurie7378a172017-06-29 23:52:17 -070037/* Device events */
Furquan Shaikh8788fd62017-11-20 20:28:18 -080038uint64_t google_chromeec_get_device_enabled_events(void);
39int google_chromeec_set_device_enabled_events(uint64_t mask);
40uint64_t google_chromeec_get_device_current_events(void);
Duncan Laurie7378a172017-06-29 23:52:17 -070041
Duncan Lauriee2cea4f2015-12-01 19:14:09 -080042int google_chromeec_check_feature(int feature);
Hung-Te Lin6bfbb332013-04-15 18:27:24 +080043uint8_t google_chromeec_calc_checksum(const uint8_t *data, int size);
Shawn Nematbakhshd0a6a382013-07-08 14:18:01 -070044u16 google_chromeec_get_board_version(void);
Patrick Georgi69206d92017-07-31 14:20:07 +020045u32 google_chromeec_get_sku_id(void);
Kevin Chiue2bb0592017-09-12 09:13:41 +080046int google_chromeec_set_sku_id(u32 skuid);
Furquan Shaikh8788fd62017-11-20 20:28:18 -080047uint64_t google_chromeec_get_events_b(void);
48int google_chromeec_clear_events_b(uint64_t mask);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080049int google_chromeec_kbbacklight(int percent);
50void google_chromeec_post(u8 postcode);
Stefan Reinaueraaaf6892013-08-29 15:57:11 -070051int google_chromeec_vbnv_context(int is_read, uint8_t *data, int len);
Duncan Laurie699c7882015-08-13 12:52:08 -070052uint8_t google_chromeec_get_switches(void);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080053
Duncan Lauriee2cea4f2015-12-01 19:14:09 -080054/* Temporary secure storage commands */
55int google_chromeec_vstore_supported(void);
56int google_chromeec_vstore_info(uint32_t *locked);
57int google_chromeec_vstore_read(int slot, uint8_t *data);
58int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size);
59
Aaron Durbine68d22f2017-05-04 12:32:52 -050060/* Issue reboot command to EC with specified type and flags. Returns 0 on
61 success, < 0 otherwise. */
62int google_chromeec_reboot(int dev_idx, enum ec_reboot_cmd type, uint8_t flags);
63
Alexandru Gagniuc851ef962016-03-30 14:38:44 -070064/* MEC uses 0x800/0x804 as register/index pair, thus an 8-byte resource. */
65#define MEC_EMI_BASE 0x800
66#define MEC_EMI_SIZE 8
67
Shawn Nematbakhsh5725ea32015-04-01 16:52:37 -070068/* For MEC, access ranges 0x800 thru 0x9ff using EMI interface instead of LPC */
69#define MEC_EMI_RANGE_START EC_HOST_CMD_REGION0
70#define MEC_EMI_RANGE_END (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE)
71
72void mec_io_bytes(int write, u16 offset, unsigned int length,
73 u8 *buf, u8 *csum);
74
Stefan Reinauerd6682e82013-02-21 15:39:35 -080075enum usb_charge_mode {
76 USB_CHARGE_MODE_DISABLED,
77 USB_CHARGE_MODE_CHARGE_AUTO,
78 USB_CHARGE_MODE_CHARGE_BC12,
79 USB_CHARGE_MODE_DOWNSTREAM_500MA,
80 USB_CHARGE_MODE_DOWNSTREAM_1500MA,
81};
82int google_chromeec_set_usb_charge_mode(u8 port_id, enum usb_charge_mode mode);
Julius Wernerea79d2b2016-11-21 20:14:07 -080083int google_chromeec_set_usb_pd_role(u8 port, enum usb_pd_control_role role);
Shelley Chenebd53302017-09-29 14:15:11 -070084/*
85 * Retrieve the charger type and max wattage.
86 *
87 * @param type charger type
88 * @param max_watts charger max wattage
89 * @return non-zero for error, otherwise 0.
90 */
91int google_chromeec_get_usb_pd_power_info(enum usb_chg_type *type,
92 u32 *max_watts);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080093
Hung-Te Lina904f9e2013-04-11 15:58:12 +080094/* internal structure to send a command to the EC and wait for response. */
95struct chromeec_command {
Hung-Te Line946f982013-06-22 11:18:39 +080096 uint16_t cmd_code; /* command code in, status out */
Hung-Te Lina904f9e2013-04-11 15:58:12 +080097 uint8_t cmd_version; /* command version */
98 const void* cmd_data_in; /* command data, if any */
99 void* cmd_data_out; /* command response, if any */
100 uint16_t cmd_size_in; /* size of command data */
101 uint16_t cmd_size_out; /* expected size of command response in,
102 * actual received size out */
Duncan Lauriefc0f5172014-09-18 12:54:02 -0700103 int cmd_dev_index;/* device index for passthru */
Hung-Te Lina904f9e2013-04-11 15:58:12 +0800104};
105
Aaron Durbin82827272014-08-06 14:34:57 -0500106/*
107 * There are transport level constraints for sending protov3 packets. Because
108 * of this provide a way for the generic protocol layer to request buffers
109 * so that there is zero copying being done through the layers.
110 *
111 * Request the buffer provided the size. If 'req' is non-zero then the
112 * buffer requested is for EC requests. Otherwise it's for responses. Return
113 * non-NULL on success, NULL on error.
114 */
115void *crosec_get_buffer(size_t size, int req);
116
117/*
118 * The lower level transport works on the buffers handed out to the
119 * upper level. Therefore, only the size of the request and response
120 * are required.
121 */
122typedef int (*crosec_io_t)(size_t req_size, size_t resp_size, void *context);
Hung-Te Lin23fb9972013-06-21 20:11:47 +0800123int crosec_command_proto(struct chromeec_command *cec_command,
124 crosec_io_t crosec_io, void *context);
125
Hung-Te Lina904f9e2013-04-11 15:58:12 +0800126int google_chromeec_command(struct chromeec_command *cec_command);
127
Furquan Shaikh2749c522017-10-04 14:01:41 -0700128struct google_chromeec_event_info {
Furquan Shaikh8788fd62017-11-20 20:28:18 -0800129 uint64_t log_events;
130 uint64_t sci_events;
131 uint64_t s3_wake_events;
132 uint64_t s3_device_events;
133 uint64_t s5_wake_events;
Furquan Shaikh2749c522017-10-04 14:01:41 -0700134};
135void google_chromeec_events_init(const struct google_chromeec_event_info *info,
136 bool is_s3_wakeup);
137
Furquan Shaikhe01bf642017-10-13 10:59:51 -0700138/*
139 * Get next available MKBP event in ec_response_get_next_event. Returns 0 on
140 * success, < 0 otherwise.
141 */
142int google_chromeec_get_mkbp_event(struct ec_response_get_next_event *event);
143
Furquan Shaikh70b257f2017-10-16 23:00:27 -0700144/* Log host events to eventlog based on the mask provided. */
Furquan Shaikh8788fd62017-11-20 20:28:18 -0800145void google_chromeec_log_events(uint64_t mask);
Furquan Shaikh70b257f2017-10-16 23:00:27 -0700146
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800147#endif /* _EC_GOOGLE_CHROMEEC_EC_H */