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> |
Duncan Laurie | e2cea4f | 2015-12-01 19:14:09 -0800 | [diff] [blame] | 22 | #include "ec_commands.h" |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 23 | |
Aaron Durbin | fbb3e6c | 2016-05-10 17:00:06 -0500 | [diff] [blame] | 24 | /* Fill in base and size of the IO port resources used. */ |
| 25 | void google_chromeec_ioport_range(uint16_t *base, size_t *size); |
| 26 | |
Gabe Black | 9f96aa6 | 2013-06-28 14:24:33 -0700 | [diff] [blame] | 27 | int google_chromeec_i2c_xfer(uint8_t chip, uint8_t addr, int alen, |
| 28 | uint8_t *buffer, int len, int is_read); |
Furquan Shaikh | 8788fd6 | 2017-11-20 20:28:18 -0800 | [diff] [blame] | 29 | uint64_t google_chromeec_get_wake_mask(void); |
| 30 | int google_chromeec_set_sci_mask(uint64_t mask); |
| 31 | int google_chromeec_set_smi_mask(uint64_t mask); |
| 32 | int google_chromeec_set_wake_mask(uint64_t mask); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 33 | u8 google_chromeec_get_event(void); |
| 34 | int google_ec_running_ro(void); |
Hung-Te Lin | 76720d0 | 2013-04-15 18:06:32 +0800 | [diff] [blame] | 35 | void google_chromeec_init(void); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 36 | |
Duncan Laurie | 7378a17 | 2017-06-29 23:52:17 -0700 | [diff] [blame] | 37 | /* Device events */ |
Furquan Shaikh | 8788fd6 | 2017-11-20 20:28:18 -0800 | [diff] [blame] | 38 | uint64_t google_chromeec_get_device_enabled_events(void); |
| 39 | int google_chromeec_set_device_enabled_events(uint64_t mask); |
| 40 | uint64_t google_chromeec_get_device_current_events(void); |
Duncan Laurie | 7378a17 | 2017-06-29 23:52:17 -0700 | [diff] [blame] | 41 | |
Duncan Laurie | e2cea4f | 2015-12-01 19:14:09 -0800 | [diff] [blame] | 42 | int google_chromeec_check_feature(int feature); |
Hung-Te Lin | 6bfbb33 | 2013-04-15 18:27:24 +0800 | [diff] [blame] | 43 | uint8_t google_chromeec_calc_checksum(const uint8_t *data, int size); |
Shawn Nematbakhsh | d0a6a38 | 2013-07-08 14:18:01 -0700 | [diff] [blame] | 44 | u16 google_chromeec_get_board_version(void); |
Patrick Georgi | 69206d9 | 2017-07-31 14:20:07 +0200 | [diff] [blame] | 45 | u32 google_chromeec_get_sku_id(void); |
Kevin Chiu | e2bb059 | 2017-09-12 09:13:41 +0800 | [diff] [blame] | 46 | int google_chromeec_set_sku_id(u32 skuid); |
Furquan Shaikh | 8788fd6 | 2017-11-20 20:28:18 -0800 | [diff] [blame] | 47 | uint64_t google_chromeec_get_events_b(void); |
| 48 | int google_chromeec_clear_events_b(uint64_t mask); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 49 | int google_chromeec_kbbacklight(int percent); |
| 50 | void google_chromeec_post(u8 postcode); |
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 | |
Duncan Laurie | e2cea4f | 2015-12-01 19:14:09 -0800 | [diff] [blame] | 54 | /* Temporary secure storage commands */ |
| 55 | int google_chromeec_vstore_supported(void); |
| 56 | int google_chromeec_vstore_info(uint32_t *locked); |
| 57 | int google_chromeec_vstore_read(int slot, uint8_t *data); |
| 58 | int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size); |
| 59 | |
Aaron Durbin | e68d22f | 2017-05-04 12:32:52 -0500 | [diff] [blame] | 60 | /* Issue reboot command to EC with specified type and flags. Returns 0 on |
| 61 | success, < 0 otherwise. */ |
| 62 | int google_chromeec_reboot(int dev_idx, enum ec_reboot_cmd type, uint8_t flags); |
| 63 | |
Alexandru Gagniuc | 851ef96 | 2016-03-30 14:38:44 -0700 | [diff] [blame] | 64 | /* 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 Nematbakhsh | 5725ea3 | 2015-04-01 16:52:37 -0700 | [diff] [blame] | 68 | /* 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 | |
| 72 | void mec_io_bytes(int write, u16 offset, unsigned int length, |
| 73 | u8 *buf, u8 *csum); |
| 74 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 75 | enum 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 | }; |
| 82 | int google_chromeec_set_usb_charge_mode(u8 port_id, enum usb_charge_mode mode); |
Julius Werner | ea79d2b | 2016-11-21 20:14:07 -0800 | [diff] [blame] | 83 | int google_chromeec_set_usb_pd_role(u8 port, enum usb_pd_control_role role); |
Shelley Chen | ebd5330 | 2017-09-29 14:15:11 -0700 | [diff] [blame] | 84 | /* |
| 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 | */ |
| 91 | int google_chromeec_get_usb_pd_power_info(enum usb_chg_type *type, |
| 92 | u32 *max_watts); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 93 | |
Hung-Te Lin | a904f9e | 2013-04-11 15:58:12 +0800 | [diff] [blame] | 94 | /* internal structure to send a command to the EC and wait for response. */ |
| 95 | struct chromeec_command { |
Hung-Te Lin | e946f98 | 2013-06-22 11:18:39 +0800 | [diff] [blame] | 96 | uint16_t cmd_code; /* command code in, status out */ |
Hung-Te Lin | a904f9e | 2013-04-11 15:58:12 +0800 | [diff] [blame] | 97 | 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 Laurie | fc0f517 | 2014-09-18 12:54:02 -0700 | [diff] [blame] | 103 | int cmd_dev_index;/* device index for passthru */ |
Hung-Te Lin | a904f9e | 2013-04-11 15:58:12 +0800 | [diff] [blame] | 104 | }; |
| 105 | |
Aaron Durbin | 8282727 | 2014-08-06 14:34:57 -0500 | [diff] [blame] | 106 | /* |
| 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 | */ |
| 115 | void *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 | */ |
| 122 | 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] | 123 | int crosec_command_proto(struct chromeec_command *cec_command, |
| 124 | crosec_io_t crosec_io, void *context); |
| 125 | |
Hung-Te Lin | a904f9e | 2013-04-11 15:58:12 +0800 | [diff] [blame] | 126 | int google_chromeec_command(struct chromeec_command *cec_command); |
| 127 | |
Furquan Shaikh | 2749c52 | 2017-10-04 14:01:41 -0700 | [diff] [blame] | 128 | struct google_chromeec_event_info { |
Furquan Shaikh | 8788fd6 | 2017-11-20 20:28:18 -0800 | [diff] [blame] | 129 | 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 Shaikh | 2749c52 | 2017-10-04 14:01:41 -0700 | [diff] [blame] | 134 | }; |
| 135 | void google_chromeec_events_init(const struct google_chromeec_event_info *info, |
| 136 | bool is_s3_wakeup); |
| 137 | |
Furquan Shaikh | e01bf64 | 2017-10-13 10:59:51 -0700 | [diff] [blame] | 138 | /* |
| 139 | * Get next available MKBP event in ec_response_get_next_event. Returns 0 on |
| 140 | * success, < 0 otherwise. |
| 141 | */ |
| 142 | int google_chromeec_get_mkbp_event(struct ec_response_get_next_event *event); |
| 143 | |
Furquan Shaikh | 70b257f | 2017-10-16 23:00:27 -0700 | [diff] [blame] | 144 | /* Log host events to eventlog based on the mask provided. */ |
Furquan Shaikh | 8788fd6 | 2017-11-20 20:28:18 -0800 | [diff] [blame] | 145 | void google_chromeec_log_events(uint64_t mask); |
Furquan Shaikh | 70b257f | 2017-10-16 23:00:27 -0700 | [diff] [blame] | 146 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 147 | #endif /* _EC_GOOGLE_CHROMEEC_EC_H */ |