blob: eddc23d48f888f7ebab2d7b4beefc758472dd195 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Hung-ying Tyan88364382013-05-15 18:27:28 +08002/*
3 * Chromium OS cros_ec driver
4 *
5 * Copyright (c) 2012 The Chromium OS Authors.
Hung-ying Tyan88364382013-05-15 18:27:28 +08006 */
7
8#ifndef _CROS_EC_H
9#define _CROS_EC_H
10
11#include <linux/compiler.h>
12#include <ec_commands.h>
Hung-ying Tyan88364382013-05-15 18:27:28 +080013#include <cros_ec_message.h>
Simon Glass32f8a192015-01-05 20:05:32 -070014#include <asm/gpio.h>
Simon Glassb7e0d732017-05-18 20:09:02 -060015#include <dm/of_extra.h>
Hung-ying Tyan88364382013-05-15 18:27:28 +080016
Hung-ying Tyan88364382013-05-15 18:27:28 +080017/* Our configuration information */
18struct cros_ec_dev {
Simon Glass84d6cbd2014-10-13 23:42:14 -060019 struct udevice *dev; /* Transport device */
Simon Glass32f8a192015-01-05 20:05:32 -070020 struct gpio_desc ec_int; /* GPIO used as EC interrupt line */
Randall Spanglere8c12662014-02-27 13:26:08 -070021 int protocol_version; /* Protocol version to use */
Hung-ying Tyan88364382013-05-15 18:27:28 +080022 int optimise_flash_write; /* Don't write erased flash blocks */
23
24 /*
25 * These two buffers will always be dword-aligned and include enough
26 * space for up to 7 word-alignment bytes also, so we can ensure that
27 * the body of the message is always dword-aligned (64-bit).
28 *
29 * We use this alignment to keep ARM and x86 happy. Probably word
30 * alignment would be OK, there might be a small performance advantage
31 * to using dword.
32 */
33 uint8_t din[ALIGN(MSG_BYTES + sizeof(int64_t), sizeof(int64_t))]
34 __aligned(sizeof(int64_t));
35 uint8_t dout[ALIGN(MSG_BYTES + sizeof(int64_t), sizeof(int64_t))]
36 __aligned(sizeof(int64_t));
37};
38
39/*
40 * Hard-code the number of columns we happen to know we have right now. It
41 * would be more correct to call cros_ec_info() at startup and determine the
42 * actual number of keyboard cols from there.
43 */
44#define CROS_EC_KEYSCAN_COLS 13
45
46/* Information returned by a key scan */
47struct mbkp_keyscan {
48 uint8_t data[CROS_EC_KEYSCAN_COLS];
49};
50
Simon Glassd7f25f32014-02-27 13:26:03 -070051/* Holds information about the Chrome EC */
52struct fdt_cros_ec {
53 struct fmap_entry flash; /* Address and size of EC flash */
54 /*
55 * Byte value of erased flash, or -1 if not known. It is normally
56 * 0xff but some flash devices use 0 (e.g. STM32Lxxx)
57 */
58 int flash_erase_value;
59 struct fmap_entry region[EC_FLASH_REGION_COUNT];
60};
61
Hung-ying Tyan88364382013-05-15 18:27:28 +080062/**
63 * Read the ID of the CROS-EC device
64 *
65 * The ID is a string identifying the CROS-EC device.
66 *
67 * @param dev CROS-EC device
68 * @param id Place to put the ID
69 * @param maxlen Maximum length of the ID field
70 * @return 0 if ok, -1 on error
71 */
Simon Glass6322a7b2018-10-01 12:22:22 -060072int cros_ec_read_id(struct udevice *dev, char *id, int maxlen);
Hung-ying Tyan88364382013-05-15 18:27:28 +080073
74/**
75 * Read a keyboard scan from the CROS-EC device
76 *
77 * Send a message requesting a keyboard scan and return the result
78 *
79 * @param dev CROS-EC device
80 * @param scan Place to put the scan results
81 * @return 0 if ok, -1 on error
82 */
Simon Glass745009c2015-10-18 21:17:14 -060083int cros_ec_scan_keyboard(struct udevice *dev, struct mbkp_keyscan *scan);
Hung-ying Tyan88364382013-05-15 18:27:28 +080084
85/**
Alper Nebi Yasak69007972020-10-30 20:25:20 +030086 * Get the next pending MKBP event from the ChromeOS EC device.
87 *
88 * Send a message requesting the next event and return the result.
89 *
90 * @param event Place to put the event.
91 * @return 0 if ok, <0 on error.
92 */
93int cros_ec_get_next_event(struct udevice *dev,
94 struct ec_response_get_next_event *event);
95
96/**
Hung-ying Tyan88364382013-05-15 18:27:28 +080097 * Read which image is currently running on the CROS-EC device.
98 *
99 * @param dev CROS-EC device
100 * @param image Destination for image identifier
101 * @return 0 if ok, <0 on error
102 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600103int cros_ec_read_current_image(struct udevice *dev,
104 enum ec_current_image *image);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800105
106/**
107 * Read the hash of the CROS-EC device firmware.
108 *
109 * @param dev CROS-EC device
Simon Glassa12ef7e2018-10-01 12:22:38 -0600110 * @param hash_offset Offset in flash to read from
Hung-ying Tyan88364382013-05-15 18:27:28 +0800111 * @param hash Destination for hash information
112 * @return 0 if ok, <0 on error
113 */
Simon Glassa12ef7e2018-10-01 12:22:38 -0600114int cros_ec_read_hash(struct udevice *dev, uint hash_offset,
115 struct ec_response_vboot_hash *hash);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800116
117/**
118 * Send a reboot command to the CROS-EC device.
119 *
120 * Note that some reboot commands (such as EC_REBOOT_COLD) also reboot the AP.
121 *
122 * @param dev CROS-EC device
123 * @param cmd Reboot command
124 * @param flags Flags for reboot command (EC_REBOOT_FLAG_*)
125 * @return 0 if ok, <0 on error
126 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600127int cros_ec_reboot(struct udevice *dev, enum ec_reboot_cmd cmd, uint8_t flags);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800128
129/**
130 * Check if the CROS-EC device has an interrupt pending.
131 *
132 * Read the status of the external interrupt connected to the CROS-EC device.
133 * If no external interrupt is configured, this always returns 1.
134 *
135 * @param dev CROS-EC device
136 * @return 0 if no interrupt is pending
137 */
Simon Glass745009c2015-10-18 21:17:14 -0600138int cros_ec_interrupt_pending(struct udevice *dev);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800139
140enum {
141 CROS_EC_OK,
142 CROS_EC_ERR = 1,
143 CROS_EC_ERR_FDT_DECODE,
144 CROS_EC_ERR_CHECK_VERSION,
145 CROS_EC_ERR_READ_ID,
146 CROS_EC_ERR_DEV_INIT,
147};
148
149/**
Simon Glass836bb6e2014-02-27 13:26:07 -0700150 * Initialise the Chromium OS EC driver
Hung-ying Tyan88364382013-05-15 18:27:28 +0800151 *
152 * @param blob Device tree blob containing setup information
153 * @param cros_ecp Returns pointer to the cros_ec device, or NULL if none
154 * @return 0 if we got an cros_ec device and all is well (or no cros_ec is
155 * expected), -ve if we should have an cros_ec device but failed to find
156 * one, or init failed (-CROS_EC_ERR_...).
157 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600158int cros_ec_init(const void *blob, struct udevice**cros_ecp);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800159
160/**
161 * Read information about the keyboard matrix
162 *
163 * @param dev CROS-EC device
164 * @param info Place to put the info structure
165 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600166int cros_ec_info(struct udevice *dev, struct ec_response_mkbp_info *info);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800167
168/**
169 * Read the host event flags
170 *
171 * @param dev CROS-EC device
172 * @param events_ptr Destination for event flags. Not changed on error.
173 * @return 0 if ok, <0 on error
174 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600175int cros_ec_get_host_events(struct udevice *dev, uint32_t *events_ptr);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800176
177/**
178 * Clear the specified host event flags
179 *
180 * @param dev CROS-EC device
181 * @param events Event flags to clear
182 * @return 0 if ok, <0 on error
183 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600184int cros_ec_clear_host_events(struct udevice *dev, uint32_t events);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800185
186/**
187 * Get/set flash protection
188 *
189 * @param dev CROS-EC device
190 * @param set_mask Mask of flags to set; if 0, just retrieves existing
191 * protection state without changing it.
192 * @param set_flags New flag values; only bits in set_mask are applied;
193 * ignored if set_mask=0.
194 * @param prot Destination for updated protection state from EC.
195 * @return 0 if ok, <0 on error
196 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600197int cros_ec_flash_protect(struct udevice *dev, uint32_t set_mask,
198 uint32_t set_flags,
199 struct ec_response_flash_protect *resp);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800200
Simon Glass72ef8bf2018-11-06 15:21:22 -0700201/**
202 * Notify EC of current boot mode
203 *
204 * @param dev CROS-EC device
205 * @param vboot_mode Verified boot mode
206 * @return 0 if ok, <0 on error
207 */
208int cros_ec_entering_mode(struct udevice *dev, int mode);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800209
210/**
211 * Run internal tests on the cros_ec interface.
212 *
213 * @param dev CROS-EC device
214 * @return 0 if ok, <0 if the test failed
215 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600216int cros_ec_test(struct udevice *dev);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800217
218/**
219 * Update the EC RW copy.
220 *
221 * @param dev CROS-EC device
222 * @param image the content to write
223 * @param imafge_size content length
224 * @return 0 if ok, <0 if the test failed
225 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600226int cros_ec_flash_update_rw(struct udevice *dev, const uint8_t *image,
227 int image_size);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800228
229/**
230 * Return a pointer to the board's CROS-EC device
231 *
Hung-ying Tyan88364382013-05-15 18:27:28 +0800232 * @return pointer to CROS-EC device, or NULL if none is available
233 */
Simon Glass42116f62018-10-01 12:22:23 -0600234struct udevice *board_get_cros_ec_dev(void);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800235
Simon Glass84d6cbd2014-10-13 23:42:14 -0600236struct dm_cros_ec_ops {
Simon Glass2b4b6532021-01-16 14:52:27 -0700237 /**
238 * check_version() - Check the protocol version being used (optional)
239 *
240 * If provided, this function should check that the EC can be supported
241 * by the driver. If not provided, HELLO messages will be sent to try
242 * to determine the protocol version.
243 *
244 * @dev: Device to check
245 * @return 0 if the protocol is valid, -ve if not supported
246 */
Simon Glass84d6cbd2014-10-13 23:42:14 -0600247 int (*check_version)(struct udevice *dev);
Simon Glass2b4b6532021-01-16 14:52:27 -0700248
249 /**
250 * command() - Old-style command interface
251 *
252 * This sends a command and receives a response (deprecated, use
253 * packet())
254 *
255 * @dev: Device to use
256 * @cmd: Command to send (only supports 0-0xff)
257 * @cmd_version: Version of command to send (often 0)
258 * @dout: Output data (may be NULL If dout_len=0)
259 * @dout_len: Length of output data excluding 4-byte header
260 * @dinp: On input, set to point to input data, often struct
261 * cros_ec_dev->din - typically this is left alone but may be
262 * updated by the driver
263 * @din_len: Maximum length of response
264 * @return number of bytes in response, or -ve on error
265 */
Simon Glass84d6cbd2014-10-13 23:42:14 -0600266 int (*command)(struct udevice *dev, uint8_t cmd, int cmd_version,
267 const uint8_t *dout, int dout_len,
268 uint8_t **dinp, int din_len);
Simon Glass2b4b6532021-01-16 14:52:27 -0700269
270 /**
271 * packet() - New-style command interface
272 *
273 * This interface is preferred over command(), since it is typically
274 * easier to implement.
275 *
276 * @dev: Device to use
277 * @out_bytes: Number of bytes to send (from struct cros_ec_dev->dout)
278 * @in_bytes: Maximum number of bytes to expect in response
279 * @return number of bytes in response, or -ve on error
280 */
Simon Glass84d6cbd2014-10-13 23:42:14 -0600281 int (*packet)(struct udevice *dev, int out_bytes, int in_bytes);
Simon Glass3a6c9942021-01-16 14:52:28 -0700282
283 /**
284 * get_switches() - Get value of EC switches
285 *
286 * This is currently supported on the LPC EC.
287 *
288 * @dev: Device to use
289 * @return current switches value, or -ENOSYS if not supported
290 */
291 int (*get_switches)(struct udevice *dev);
Simon Glass84d6cbd2014-10-13 23:42:14 -0600292};
293
294#define dm_cros_ec_get_ops(dev) \
295 ((struct dm_cros_ec_ops *)(dev)->driver->ops)
296
297int cros_ec_register(struct udevice *dev);
298
Randall Spanglera6070282014-02-27 13:26:10 -0700299/**
Hung-ying Tyan88364382013-05-15 18:27:28 +0800300 * Dump a block of data for a command.
301 *
302 * @param name Name for data (e.g. 'in', 'out')
303 * @param cmd Command number associated with data, or -1 for none
304 * @param data Data block to dump
305 * @param len Length of data block to dump
306 */
307void cros_ec_dump_data(const char *name, int cmd, const uint8_t *data, int len);
308
309/**
310 * Calculate a simple 8-bit checksum of a data block
311 *
312 * @param data Data block to checksum
313 * @param size Size of data block in bytes
314 * @return checksum value (0 to 255)
315 */
316int cros_ec_calc_checksum(const uint8_t *data, int size);
317
Simon Glass6322a7b2018-10-01 12:22:22 -0600318int cros_ec_flash_erase(struct udevice *dev, uint32_t offset, uint32_t size);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800319
320/**
321 * Read data from the flash
322 *
323 * Read an arbitrary amount of data from the EC flash, by repeatedly reading
324 * small blocks.
325 *
326 * The offset starts at 0. You can obtain the region information from
327 * cros_ec_flash_offset() to find out where to read for a particular region.
328 *
329 * @param dev CROS-EC device
330 * @param data Pointer to data buffer to read into
331 * @param offset Offset within flash to read from
332 * @param size Number of bytes to read
333 * @return 0 if ok, -1 on error
334 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600335int cros_ec_flash_read(struct udevice *dev, uint8_t *data, uint32_t offset,
336 uint32_t size);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800337
338/**
Moritz Fischerbfeba012016-10-04 17:08:08 -0700339 * Read back flash parameters
340 *
341 * This function reads back parameters of the flash as reported by the EC
342 *
343 * @param dev Pointer to device
344 * @param info Pointer to output flash info struct
345 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600346int cros_ec_read_flashinfo(struct udevice *dev,
347 struct ec_response_flash_info *info);
Moritz Fischerbfeba012016-10-04 17:08:08 -0700348
349/**
Hung-ying Tyan88364382013-05-15 18:27:28 +0800350 * Write data to the flash
351 *
352 * Write an arbitrary amount of data to the EC flash, by repeatedly writing
353 * small blocks.
354 *
355 * The offset starts at 0. You can obtain the region information from
356 * cros_ec_flash_offset() to find out where to write for a particular region.
357 *
358 * Attempting to write to the region where the EC is currently running from
359 * will result in an error.
360 *
361 * @param dev CROS-EC device
362 * @param data Pointer to data buffer to write
363 * @param offset Offset within flash to write to.
364 * @param size Number of bytes to write
365 * @return 0 if ok, -1 on error
366 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600367int cros_ec_flash_write(struct udevice *dev, const uint8_t *data,
368 uint32_t offset, uint32_t size);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800369
370/**
371 * Obtain position and size of a flash region
372 *
373 * @param dev CROS-EC device
374 * @param region Flash region to query
375 * @param offset Returns offset of flash region in EC flash
376 * @param size Returns size of flash region
377 * @return 0 if ok, -1 on error
378 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600379int cros_ec_flash_offset(struct udevice *dev, enum ec_flash_region region,
380 uint32_t *offset, uint32_t *size);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800381
382/**
Simon Glass7791df52021-01-16 14:52:25 -0700383 * cros_ec_get_sku_id() - Read the SKU ID
384 *
385 * @dev: CROS-EC device
386 * return SKU ID, or -ve on error
387 */
388int cros_ec_get_sku_id(struct udevice *dev);
389
390/**
Simon Glass6322a7b2018-10-01 12:22:22 -0600391 * Read/write non-volatile data from/to a CROS-EC device.
Hung-ying Tyan88364382013-05-15 18:27:28 +0800392 *
393 * @param dev CROS-EC device
394 * @param block Buffer of VbNvContext to be read/write
395 * @return 0 if ok, -1 on error
396 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600397int cros_ec_read_nvdata(struct udevice *dev, uint8_t *block, int size);
398int cros_ec_write_nvdata(struct udevice *dev, const uint8_t *block, int size);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800399
400/**
401 * Read the version information for the EC images
402 *
403 * @param dev CROS-EC device
404 * @param versionp This is set to point to the version information
405 * @return 0 if ok, -1 on error
406 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600407int cros_ec_read_version(struct udevice *dev,
408 struct ec_response_get_version **versionp);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800409
410/**
411 * Read the build information for the EC
412 *
413 * @param dev CROS-EC device
414 * @param versionp This is set to point to the build string
415 * @return 0 if ok, -1 on error
416 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600417int cros_ec_read_build_info(struct udevice *dev, char **strp);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800418
419/**
420 * Switch on/off a LDO / FET.
421 *
422 * @param dev CROS-EC device
423 * @param index index of the LDO/FET to switch
424 * @param state new state of the LDO/FET : EC_LDO_STATE_ON|OFF
425 * @return 0 if ok, -1 on error
426 */
Simon Glassf48eaf02015-08-03 08:19:24 -0600427int cros_ec_set_ldo(struct udevice *dev, uint8_t index, uint8_t state);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800428
429/**
430 * Read back a LDO / FET current state.
431 *
432 * @param dev CROS-EC device
433 * @param index index of the LDO/FET to switch
434 * @param state current state of the LDO/FET : EC_LDO_STATE_ON|OFF
435 * @return 0 if ok, -1 on error
436 */
Simon Glassf48eaf02015-08-03 08:19:24 -0600437int cros_ec_get_ldo(struct udevice *dev, uint8_t index, uint8_t *state);
Vadim Bendebury41364f02014-02-27 13:26:02 -0700438
439/**
Vadim Bendebury41364f02014-02-27 13:26:02 -0700440 * Get access to the error reported when cros_ec_board_init() was called
441 *
442 * This permits delayed reporting of the EC error if it failed during
443 * early init.
444 *
445 * @return error (0 if there was no error, -ve if there was an error)
446 */
447int cros_ec_get_error(void);
448
Simon Glassd7f25f32014-02-27 13:26:03 -0700449/**
450 * Returns information from the FDT about the Chrome EC flash
451 *
Simon Glass2ec9d172017-05-18 20:09:23 -0600452 * @param dev Device to read from
Simon Glassd7f25f32014-02-27 13:26:03 -0700453 * @param config Structure to use to return information
454 */
Simon Glass2ec9d172017-05-18 20:09:23 -0600455int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config);
Simon Glassd7f25f32014-02-27 13:26:03 -0700456
Simon Glassdf93d902014-02-27 13:26:12 -0700457/**
458 * Check the current keyboard state, in case recovery mode is requested.
459 * This function is for sandbox only.
460 *
461 * @param ec CROS-EC device
462 */
Simon Glass6322a7b2018-10-01 12:22:22 -0600463void cros_ec_check_keyboard(struct udevice *dev);
Simon Glassdf93d902014-02-27 13:26:12 -0700464
Simon Glasscc456bd2015-08-03 08:19:23 -0600465struct i2c_msg;
466/*
467 * Tunnel an I2C transfer to the EC
468 *
469 * @param dev CROS-EC device
Moritz Fischer6d1a7182016-09-27 15:42:07 -0700470 * @param port The remote port on EC to use
Simon Glasscc456bd2015-08-03 08:19:23 -0600471 * @param msg List of messages to transfer
472 * @param nmsgs Number of messages to transfer
473 */
Moritz Fischer6d1a7182016-09-27 15:42:07 -0700474int cros_ec_i2c_tunnel(struct udevice *dev, int port, struct i2c_msg *msg,
475 int nmsgs);
Simon Glasscc456bd2015-08-03 08:19:23 -0600476
Simon Glass72ef8bf2018-11-06 15:21:22 -0700477/**
478 * cros_ec_get_events_b() - Get event mask B
479 *
480 * @return value of event mask, default value of 0 if it could not be read
481 */
482uint64_t cros_ec_get_events_b(struct udevice *dev);
483
484/**
485 * cros_ec_clear_events_b() - Clear even mask B
486 *
487 * Any pending events in the B range are cleared
488 *
489 * @return 0 if OK, -ve on error
490 */
491int cros_ec_clear_events_b(struct udevice *dev, uint64_t mask);
492
493/**
494 * cros_ec_efs_verify() - tell the EC to verify one of its images
495 *
496 * @param dev CROS-EC device
497 * @param region Flash region to query
498 * @return 0 if OK, -ve on error
499 */
500int cros_ec_efs_verify(struct udevice *dev, enum ec_flash_region region);
501
502/**
503 * cros_ec_battery_cutoff() - Request that the battery be cut off
504 *
505 * This tells the battery to stop supplying power. This is used before shipping
506 * a device to ensure that the battery remains charged while the device is
507 * shipped or sitting on the shelf waiting to be purchased.
508 *
509 * @param dev CROS-EC device
510 * @param flags Flags to use (EC_BATTERY_CUTOFF_FLAG_...)
511 * @return 0 if OK, -ve on error
512 */
513int cros_ec_battery_cutoff(struct udevice *dev, uint8_t flags);
514
515/**
516 * cros_ec_read_limit_power() - Check if power is limited by batter/charger
517 *
518 * Sometimes the battery is low and / or the device is connected to a charger
519 * that cannot supply much power.
520 *
521 * @param dev CROS-EC device
522 * @param limit_powerp Returns whether power is limited (0 or 1)
523 * @return 0 if OK, -ENOSYS if the EC does not support this comment, -EINVAL
524 * if the EC returned an invalid response
525 */
526int cros_ec_read_limit_power(struct udevice *dev, int *limit_powerp);
527
528/**
529 * cros_ec_config_powerbtn() - Configure the behaviour of the power button
530 *
531 * @param dev CROS-EC device
532 * @param flags Flags to use (EC_POWER_BUTTON_...)
533 * @return 0 if OK, -ve on error
534 */
535int cros_ec_config_powerbtn(struct udevice *dev, uint32_t flags);
536
537/**
538 * cros_ec_get_lid_shutdown_mask() - Set the lid shutdown mask
539 *
540 * Determines whether a lid close event is reported
541 *
542 * @param dev CROS-EC device
543 * @return shufdown mas if OK, -ve on error
544 */
545int cros_ec_get_lid_shutdown_mask(struct udevice *dev);
546
547/**
548 * cros_ec_set_lid_shutdown_mask() - Set the lid shutdown mask
549 *
550 * Set whether a lid close event is reported
551 *
552 * @param dev CROS-EC device
553 * @param enable true to enable reporting, false to disable
554 * @return shufdown mas if OK, -ve on error
555 */
556int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable);
557
Simon Glassd8e9a932021-01-16 14:52:22 -0700558/**
559 * cros_ec_hello() - Send a hello message
560 *
561 * Sends a message with a fixed input value and checks that the expected output
562 * value is received
563 *
564 * @dev: CROS-EC device
565 * @handshakep: If non-NULL, returns received handshake value on error
566 * @return 0 if OK, -ve on error
567 */
568int cros_ec_hello(struct udevice *dev, uint *handshakep);
Simon Glass8aec32f2021-01-16 14:52:26 -0700569
570/**
571 * cros_ec_get_features() - Get the set of features provided by the EC
572 *
573 * See enum ec_feature_code for the list of available features
574 *
575 * @dev: CROS-EC device
576 * @featuresp: Returns a bitmask of supported features
577 * @return 0 if OK, -ve on error
578 */
579int cros_ec_get_features(struct udevice *dev, u64 *featuresp);
580
581/**
582 * cros_ec_check_feature() - Check if a feature is supported
583 *
584 * @dev: CROS-EC device
585 * @feature: Feature number to check (enum ec_feature_code)
586 * @return true if supported, false if not, -ve on error
587 */
588int cros_ec_check_feature(struct udevice *dev, uint feature);
589
Simon Glass3a6c9942021-01-16 14:52:28 -0700590/**
591 * cros_ec_get_switches() - Get switches value
592 *
593 * @dev: CROS-EC device
594 * @return switches value, or -ENOSYS if not supported, or other -ve value on
595 * other error
596 */
597int cros_ec_get_switches(struct udevice *dev);
598
Simon Glass10f74652021-01-16 14:52:31 -0700599/**
600 * cros_ec_vstore_supported() - Check if vstore is supported
601 *
602 * @dev: CROS-EC device
603 * @return false if not supported, true if supported, -ve on error
604 */
605int cros_ec_vstore_supported(struct udevice *dev);
606
607/**
608 * cros_ec_vstore_info() - Get vstore information
609 *
610 * @dev: CROS-EC device
611 * @lockedp: mask of locked slots
612 * @return number of vstore slots supported by the EC,, -ve on error
613 */
614int cros_ec_vstore_info(struct udevice *dev, u32 *lockedp);
615
616/**
617 * cros_ec_vstore_read() - Read data from EC vstore slot
618 *
619 * @dev: CROS-EC device
620 * @slot: vstore slot to read from
621 * @data: buffer to store read data, must be EC_VSTORE_SLOT_SIZE bytes
622 * @return 0 if OK, -ve on error
623 */
624int cros_ec_vstore_read(struct udevice *dev, int slot, uint8_t *data);
625
626/**
627 * cros_ec_vstore_write() - Save data into EC vstore slot
628 *
629 * The maximum size of data is EC_VSTORE_SLOT_SIZE. It is the caller's
630 * responsibility to check the number of implemented slots by querying the
631 * vstore info.
632 *
633 * @dev: CROS-EC device
634 * @slot: vstore slot to write into
635 * @data: data to write
636 * @size: size of data in bytes
637 * @return 0 if OK, -ve on error
638 */
639int cros_ec_vstore_write(struct udevice *dev, int slot, const uint8_t *data,
640 size_t size);
641
Hung-ying Tyan88364382013-05-15 18:27:28 +0800642#endif