![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* 0003 * ChromeOS Wilco Embedded Controller 0004 * 0005 * Copyright 2018 Google LLC 0006 */ 0007 0008 #ifndef WILCO_EC_H 0009 #define WILCO_EC_H 0010 0011 #include <linux/mutex.h> 0012 #include <linux/types.h> 0013 0014 /* Message flags for using the mailbox() interface */ 0015 #define WILCO_EC_FLAG_NO_RESPONSE BIT(0) /* EC does not respond */ 0016 0017 /* Normal commands have a maximum 32 bytes of data */ 0018 #define EC_MAILBOX_DATA_SIZE 32 0019 0020 struct device; 0021 struct resource; 0022 struct platform_device; 0023 0024 /** 0025 * struct wilco_ec_device - Wilco Embedded Controller handle. 0026 * @dev: Device handle. 0027 * @mailbox_lock: Mutex to ensure one mailbox command at a time. 0028 * @io_command: I/O port for mailbox command. Provided by ACPI. 0029 * @io_data: I/O port for mailbox data. Provided by ACPI. 0030 * @io_packet: I/O port for mailbox packet data. Provided by ACPI. 0031 * @data_buffer: Buffer used for EC communication. The same buffer 0032 * is used to hold the request and the response. 0033 * @data_size: Size of the data buffer used for EC communication. 0034 * @debugfs_pdev: The child platform_device used by the debugfs sub-driver. 0035 * @rtc_pdev: The child platform_device used by the RTC sub-driver. 0036 * @charger_pdev: Child platform_device used by the charger config sub-driver. 0037 * @telem_pdev: The child platform_device used by the telemetry sub-driver. 0038 */ 0039 struct wilco_ec_device { 0040 struct device *dev; 0041 struct mutex mailbox_lock; 0042 struct resource *io_command; 0043 struct resource *io_data; 0044 struct resource *io_packet; 0045 void *data_buffer; 0046 size_t data_size; 0047 struct platform_device *debugfs_pdev; 0048 struct platform_device *rtc_pdev; 0049 struct platform_device *charger_pdev; 0050 struct platform_device *telem_pdev; 0051 }; 0052 0053 /** 0054 * struct wilco_ec_request - Mailbox request message format. 0055 * @struct_version: Should be %EC_MAILBOX_PROTO_VERSION 0056 * @checksum: Sum of all bytes must be 0. 0057 * @mailbox_id: Mailbox identifier, specifies the command set. 0058 * @mailbox_version: Mailbox interface version %EC_MAILBOX_VERSION 0059 * @reserved: Set to zero. 0060 * @data_size: Length of following data. 0061 */ 0062 struct wilco_ec_request { 0063 u8 struct_version; 0064 u8 checksum; 0065 u16 mailbox_id; 0066 u8 mailbox_version; 0067 u8 reserved; 0068 u16 data_size; 0069 } __packed; 0070 0071 /** 0072 * struct wilco_ec_response - Mailbox response message format. 0073 * @struct_version: Should be %EC_MAILBOX_PROTO_VERSION 0074 * @checksum: Sum of all bytes must be 0. 0075 * @result: Result code from the EC. Non-zero indicates an error. 0076 * @data_size: Length of the response data buffer. 0077 * @reserved: Set to zero. 0078 * @data: Response data buffer. Max size is %EC_MAILBOX_DATA_SIZE_EXTENDED. 0079 */ 0080 struct wilco_ec_response { 0081 u8 struct_version; 0082 u8 checksum; 0083 u16 result; 0084 u16 data_size; 0085 u8 reserved[2]; 0086 u8 data[]; 0087 } __packed; 0088 0089 /** 0090 * enum wilco_ec_msg_type - Message type to select a set of command codes. 0091 * @WILCO_EC_MSG_LEGACY: Legacy EC messages for standard EC behavior. 0092 * @WILCO_EC_MSG_PROPERTY: Get/Set/Sync EC controlled NVRAM property. 0093 * @WILCO_EC_MSG_TELEMETRY: Request telemetry data from the EC. 0094 */ 0095 enum wilco_ec_msg_type { 0096 WILCO_EC_MSG_LEGACY = 0x00f0, 0097 WILCO_EC_MSG_PROPERTY = 0x00f2, 0098 WILCO_EC_MSG_TELEMETRY = 0x00f5, 0099 }; 0100 0101 /** 0102 * struct wilco_ec_message - Request and response message. 0103 * @type: Mailbox message type. 0104 * @flags: Message flags, e.g. %WILCO_EC_FLAG_NO_RESPONSE. 0105 * @request_size: Number of bytes to send to the EC. 0106 * @request_data: Buffer containing the request data. 0107 * @response_size: Number of bytes to read from EC. 0108 * @response_data: Buffer containing the response data, should be 0109 * response_size bytes and allocated by caller. 0110 */ 0111 struct wilco_ec_message { 0112 enum wilco_ec_msg_type type; 0113 u8 flags; 0114 size_t request_size; 0115 void *request_data; 0116 size_t response_size; 0117 void *response_data; 0118 }; 0119 0120 /** 0121 * wilco_ec_mailbox() - Send request to the EC and receive the response. 0122 * @ec: Wilco EC device. 0123 * @msg: Wilco EC message. 0124 * 0125 * Return: Number of bytes received or negative error code on failure. 0126 */ 0127 int wilco_ec_mailbox(struct wilco_ec_device *ec, struct wilco_ec_message *msg); 0128 0129 /** 0130 * wilco_keyboard_leds_init() - Set up the keyboard backlight LEDs. 0131 * @ec: EC device to query. 0132 * 0133 * After this call, the keyboard backlight will be exposed through a an LED 0134 * device at /sys/class/leds. 0135 * 0136 * This may sleep because it uses wilco_ec_mailbox(). 0137 * 0138 * Return: 0 on success, negative error code on failure. 0139 */ 0140 int wilco_keyboard_leds_init(struct wilco_ec_device *ec); 0141 0142 /* 0143 * A Property is typically a data item that is stored to NVRAM 0144 * by the EC. Each of these data items has an index associated 0145 * with it, known as the Property ID (PID). Properties may have 0146 * variable lengths, up to a max of WILCO_EC_PROPERTY_MAX_SIZE 0147 * bytes. Properties can be simple integers, or they may be more 0148 * complex binary data. 0149 */ 0150 0151 #define WILCO_EC_PROPERTY_MAX_SIZE 4 0152 0153 /** 0154 * struct ec_property_set_msg - Message to get or set a property. 0155 * @property_id: Which property to get or set. 0156 * @length: Number of bytes of |data| that are used. 0157 * @data: Actual property data. 0158 */ 0159 struct wilco_ec_property_msg { 0160 u32 property_id; 0161 int length; 0162 u8 data[WILCO_EC_PROPERTY_MAX_SIZE]; 0163 }; 0164 0165 /** 0166 * wilco_ec_get_property() - Retrieve a property from the EC. 0167 * @ec: Embedded Controller device. 0168 * @prop_msg: Message for request and response. 0169 * 0170 * The property_id field of |prop_msg| should be filled before calling this 0171 * function. The result will be stored in the data and length fields. 0172 * 0173 * Return: 0 on success, negative error code on failure. 0174 */ 0175 int wilco_ec_get_property(struct wilco_ec_device *ec, 0176 struct wilco_ec_property_msg *prop_msg); 0177 0178 /** 0179 * wilco_ec_set_property() - Store a property on the EC. 0180 * @ec: Embedded Controller device. 0181 * @prop_msg: Message for request and response. 0182 * 0183 * The property_id, length, and data fields of |prop_msg| should be 0184 * filled before calling this function. 0185 * 0186 * Return: 0 on success, negative error code on failure. 0187 */ 0188 int wilco_ec_set_property(struct wilco_ec_device *ec, 0189 struct wilco_ec_property_msg *prop_msg); 0190 0191 /** 0192 * wilco_ec_get_byte_property() - Retrieve a byte-size property from the EC. 0193 * @ec: Embedded Controller device. 0194 * @property_id: Which property to retrieve. 0195 * @val: The result value, will be filled by this function. 0196 * 0197 * Return: 0 on success, negative error code on failure. 0198 */ 0199 int wilco_ec_get_byte_property(struct wilco_ec_device *ec, u32 property_id, 0200 u8 *val); 0201 0202 /** 0203 * wilco_ec_get_byte_property() - Store a byte-size property on the EC. 0204 * @ec: Embedded Controller device. 0205 * @property_id: Which property to store. 0206 * @val: Value to store. 0207 * 0208 * Return: 0 on success, negative error code on failure. 0209 */ 0210 int wilco_ec_set_byte_property(struct wilco_ec_device *ec, u32 property_id, 0211 u8 val); 0212 0213 /** 0214 * wilco_ec_add_sysfs() - Create sysfs entries 0215 * @ec: Wilco EC device 0216 * 0217 * wilco_ec_remove_sysfs() needs to be called afterwards 0218 * to perform the necessary cleanup. 0219 * 0220 * Return: 0 on success or negative error code on failure. 0221 */ 0222 int wilco_ec_add_sysfs(struct wilco_ec_device *ec); 0223 void wilco_ec_remove_sysfs(struct wilco_ec_device *ec); 0224 0225 #endif /* WILCO_EC_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |