blob: 6693b3c6d1e4579c738fbfaefb52987a313c77d7 [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>
Stefan Reinauerd6682e82013-02-21 15:39:35 -080022
23#ifndef __PRE_RAM__
Gabe Black9f96aa62013-06-28 14:24:33 -070024int google_chromeec_i2c_xfer(uint8_t chip, uint8_t addr, int alen,
25 uint8_t *buffer, int len, int is_read);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080026u32 google_chromeec_get_wake_mask(void);
27int google_chromeec_set_sci_mask(u32 mask);
28int google_chromeec_set_smi_mask(u32 mask);
29int google_chromeec_set_wake_mask(u32 mask);
30u8 google_chromeec_get_event(void);
31int google_ec_running_ro(void);
Hung-Te Lin76720d02013-04-15 18:06:32 +080032void google_chromeec_init(void);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080033#endif
34
Duncan Lauriefc0f5172014-09-18 12:54:02 -070035#ifdef __PRE_RAM__
Aaron Durbin9f1a7cf2014-01-09 14:28:05 -060036/* If recovery mode is enabled and EC is not running RO firmware reboot. */
Duncan Laurie7cced0d2013-06-04 10:03:34 -070037void google_chromeec_early_init(void);
Duncan Lauriefc0f5172014-09-18 12:54:02 -070038void google_chromeec_early_pd_init(void);
Aaron Durbin9f1a7cf2014-01-09 14:28:05 -060039/* Reboot if EC firmware is not expected type. */
40void google_chromeec_check_ec_image(int expected_type);
Duncan Lauriefc0f5172014-09-18 12:54:02 -070041void google_chromeec_check_pd_image(int expected_type);
42#endif
43
Hung-Te Lin6bfbb332013-04-15 18:27:24 +080044uint8_t google_chromeec_calc_checksum(const uint8_t *data, int size);
Shawn Nematbakhshd0a6a382013-07-08 14:18:01 -070045u16 google_chromeec_get_board_version(void);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080046u32 google_chromeec_get_events_b(void);
Sheng-Liang Song1d6560f2014-04-30 15:46:45 -070047int google_chromeec_clear_events_b(u32 mask);
Stefan Reinauerd6682e82013-02-21 15:39:35 -080048int google_chromeec_kbbacklight(int percent);
49void google_chromeec_post(u8 postcode);
50void google_chromeec_log_events(u32 mask);
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
Shawn Nematbakhsh5725ea32015-04-01 16:52:37 -070054/* For MEC, access ranges 0x800 thru 0x9ff using EMI interface instead of LPC */
55#define MEC_EMI_RANGE_START EC_HOST_CMD_REGION0
56#define MEC_EMI_RANGE_END (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE)
57
58void mec_io_bytes(int write, u16 offset, unsigned int length,
59 u8 *buf, u8 *csum);
60
Stefan Reinauerd6682e82013-02-21 15:39:35 -080061enum usb_charge_mode {
62 USB_CHARGE_MODE_DISABLED,
63 USB_CHARGE_MODE_CHARGE_AUTO,
64 USB_CHARGE_MODE_CHARGE_BC12,
65 USB_CHARGE_MODE_DOWNSTREAM_500MA,
66 USB_CHARGE_MODE_DOWNSTREAM_1500MA,
67};
68int google_chromeec_set_usb_charge_mode(u8 port_id, enum usb_charge_mode mode);
69
Hung-Te Lina904f9e2013-04-11 15:58:12 +080070/* internal structure to send a command to the EC and wait for response. */
71struct chromeec_command {
Hung-Te Line946f982013-06-22 11:18:39 +080072 uint16_t cmd_code; /* command code in, status out */
Hung-Te Lina904f9e2013-04-11 15:58:12 +080073 uint8_t cmd_version; /* command version */
74 const void* cmd_data_in; /* command data, if any */
75 void* cmd_data_out; /* command response, if any */
76 uint16_t cmd_size_in; /* size of command data */
77 uint16_t cmd_size_out; /* expected size of command response in,
78 * actual received size out */
Duncan Lauriefc0f5172014-09-18 12:54:02 -070079 int cmd_dev_index;/* device index for passthru */
Hung-Te Lina904f9e2013-04-11 15:58:12 +080080};
81
Aaron Durbin82827272014-08-06 14:34:57 -050082/*
83 * There are transport level constraints for sending protov3 packets. Because
84 * of this provide a way for the generic protocol layer to request buffers
85 * so that there is zero copying being done through the layers.
86 *
87 * Request the buffer provided the size. If 'req' is non-zero then the
88 * buffer requested is for EC requests. Otherwise it's for responses. Return
89 * non-NULL on success, NULL on error.
90 */
91void *crosec_get_buffer(size_t size, int req);
92
93/*
94 * The lower level transport works on the buffers handed out to the
95 * upper level. Therefore, only the size of the request and response
96 * are required.
97 */
98typedef int (*crosec_io_t)(size_t req_size, size_t resp_size, void *context);
Hung-Te Lin23fb9972013-06-21 20:11:47 +080099int crosec_command_proto(struct chromeec_command *cec_command,
100 crosec_io_t crosec_io, void *context);
101
Hung-Te Lina904f9e2013-04-11 15:58:12 +0800102int google_chromeec_command(struct chromeec_command *cec_command);
103
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800104#endif /* _EC_GOOGLE_CHROMEEC_EC_H */