Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1 | /* |
| 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 Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 15 | * 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 Lin | 23fb997 | 2013-06-21 20:11:47 +0800 | [diff] [blame] | 20 | #include <stddef.h> |
| 21 | #include <stdint.h> |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 22 | |
| 23 | #ifndef __PRE_RAM__ |
Gabe Black | 9f96aa6 | 2013-06-28 14:24:33 -0700 | [diff] [blame] | 24 | int google_chromeec_i2c_xfer(uint8_t chip, uint8_t addr, int alen, |
| 25 | uint8_t *buffer, int len, int is_read); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 26 | u32 google_chromeec_get_wake_mask(void); |
| 27 | int google_chromeec_set_sci_mask(u32 mask); |
| 28 | int google_chromeec_set_smi_mask(u32 mask); |
| 29 | int google_chromeec_set_wake_mask(u32 mask); |
| 30 | u8 google_chromeec_get_event(void); |
| 31 | int google_ec_running_ro(void); |
Hung-Te Lin | 76720d0 | 2013-04-15 18:06:32 +0800 | [diff] [blame] | 32 | void google_chromeec_init(void); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 33 | #endif |
| 34 | |
Duncan Laurie | fc0f517 | 2014-09-18 12:54:02 -0700 | [diff] [blame] | 35 | #ifdef __PRE_RAM__ |
Aaron Durbin | 9f1a7cf | 2014-01-09 14:28:05 -0600 | [diff] [blame] | 36 | /* If recovery mode is enabled and EC is not running RO firmware reboot. */ |
Duncan Laurie | 7cced0d | 2013-06-04 10:03:34 -0700 | [diff] [blame] | 37 | void google_chromeec_early_init(void); |
Duncan Laurie | fc0f517 | 2014-09-18 12:54:02 -0700 | [diff] [blame] | 38 | void google_chromeec_early_pd_init(void); |
Aaron Durbin | 9f1a7cf | 2014-01-09 14:28:05 -0600 | [diff] [blame] | 39 | /* Reboot if EC firmware is not expected type. */ |
| 40 | void google_chromeec_check_ec_image(int expected_type); |
Duncan Laurie | fc0f517 | 2014-09-18 12:54:02 -0700 | [diff] [blame] | 41 | void google_chromeec_check_pd_image(int expected_type); |
| 42 | #endif |
| 43 | |
Hung-Te Lin | 6bfbb33 | 2013-04-15 18:27:24 +0800 | [diff] [blame] | 44 | uint8_t google_chromeec_calc_checksum(const uint8_t *data, int size); |
Shawn Nematbakhsh | d0a6a38 | 2013-07-08 14:18:01 -0700 | [diff] [blame] | 45 | u16 google_chromeec_get_board_version(void); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 46 | u32 google_chromeec_get_events_b(void); |
Sheng-Liang Song | 1d6560f | 2014-04-30 15:46:45 -0700 | [diff] [blame] | 47 | int google_chromeec_clear_events_b(u32 mask); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 48 | int google_chromeec_kbbacklight(int percent); |
| 49 | void google_chromeec_post(u8 postcode); |
| 50 | void google_chromeec_log_events(u32 mask); |
Stefan Reinauer | aaaf689 | 2013-08-29 15:57:11 -0700 | [diff] [blame] | 51 | int google_chromeec_vbnv_context(int is_read, uint8_t *data, int len); |
Duncan Laurie | 699c788 | 2015-08-13 12:52:08 -0700 | [diff] [blame] | 52 | uint8_t google_chromeec_get_switches(void); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 53 | |
Shawn Nematbakhsh | 5725ea3 | 2015-04-01 16:52:37 -0700 | [diff] [blame] | 54 | /* 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 | |
| 58 | void mec_io_bytes(int write, u16 offset, unsigned int length, |
| 59 | u8 *buf, u8 *csum); |
| 60 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 61 | enum 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 | }; |
| 68 | int google_chromeec_set_usb_charge_mode(u8 port_id, enum usb_charge_mode mode); |
| 69 | |
Hung-Te Lin | a904f9e | 2013-04-11 15:58:12 +0800 | [diff] [blame] | 70 | /* internal structure to send a command to the EC and wait for response. */ |
| 71 | struct chromeec_command { |
Hung-Te Lin | e946f98 | 2013-06-22 11:18:39 +0800 | [diff] [blame] | 72 | uint16_t cmd_code; /* command code in, status out */ |
Hung-Te Lin | a904f9e | 2013-04-11 15:58:12 +0800 | [diff] [blame] | 73 | 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 Laurie | fc0f517 | 2014-09-18 12:54:02 -0700 | [diff] [blame] | 79 | int cmd_dev_index;/* device index for passthru */ |
Hung-Te Lin | a904f9e | 2013-04-11 15:58:12 +0800 | [diff] [blame] | 80 | }; |
| 81 | |
Aaron Durbin | 8282727 | 2014-08-06 14:34:57 -0500 | [diff] [blame] | 82 | /* |
| 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 | */ |
| 91 | void *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 | */ |
| 98 | typedef int (*crosec_io_t)(size_t req_size, size_t resp_size, void *context); |
Hung-Te Lin | 23fb997 | 2013-06-21 20:11:47 +0800 | [diff] [blame] | 99 | int crosec_command_proto(struct chromeec_command *cec_command, |
| 100 | crosec_io_t crosec_io, void *context); |
| 101 | |
Hung-Te Lin | a904f9e | 2013-04-11 15:58:12 +0800 | [diff] [blame] | 102 | int google_chromeec_command(struct chromeec_command *cec_command); |
| 103 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 104 | #endif /* _EC_GOOGLE_CHROMEEC_EC_H */ |