blob: 013c67e04648fa60a1959baadb1a309d2a561003 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08002/*
3 * Chromium OS cros_ec driver
4 *
5 * Copyright (c) 2012 The Chromium OS Authors.
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08006 */
7
8/*
Simon Glassece28862014-02-27 13:26:07 -07009 * This is the interface to the Chrome OS EC. It provides keyboard functions,
10 * power control and battery management. Quite a few other functions are
11 * provided to enable the EC software to be updated, talk to the EC's I2C bus
12 * and store a small amount of data in a memory which persists while the EC
13 * is not reset.
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +080014 */
15
Simon Glassa77024d2018-11-06 15:21:19 -070016#define LOG_CATEGORY UCLASS_CROS_EC
17
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +080018#include <common.h>
19#include <command.h>
Simon Glass44569b52014-10-13 23:42:14 -060020#include <dm.h>
Simon Glass8e201882020-05-10 11:39:54 -060021#include <flash.h>
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +080022#include <i2c.h>
23#include <cros_ec.h>
24#include <fdtdec.h>
Simon Glass0f2af882020-05-10 11:40:05 -060025#include <log.h>
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +080026#include <malloc.h>
27#include <spi.h>
Simon Glassdbd79542020-05-10 11:40:11 -060028#include <linux/delay.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090029#include <linux/errno.h>
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +080030#include <asm/io.h>
31#include <asm-generic/gpio.h>
Simon Glass44569b52014-10-13 23:42:14 -060032#include <dm/device-internal.h>
Simon Glassb35e6d62017-05-18 20:09:23 -060033#include <dm/of_extra.h>
Simon Glass44569b52014-10-13 23:42:14 -060034#include <dm/uclass-internal.h>
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +080035
36#ifdef DEBUG_TRACE
37#define debug_trace(fmt, b...) debug(fmt, #b)
38#else
39#define debug_trace(fmt, b...)
40#endif
41
42enum {
43 /* Timeout waiting for a flash erase command to complete */
44 CROS_EC_CMD_TIMEOUT_MS = 5000,
45 /* Timeout waiting for a synchronous hash to be recomputed */
46 CROS_EC_CMD_HASH_TIMEOUT_MS = 2000,
47};
48
Simon Glass153f2522018-11-06 15:21:22 -070049#define INVALID_HCMD 0xFF
50
51/*
52 * Map UHEPI masks to non UHEPI commands in order to support old EC FW
53 * which does not support UHEPI command.
54 */
55static const struct {
56 u8 set_cmd;
57 u8 clear_cmd;
58 u8 get_cmd;
59} event_map[] = {
60 [EC_HOST_EVENT_MAIN] = {
61 INVALID_HCMD, EC_CMD_HOST_EVENT_CLEAR,
62 INVALID_HCMD,
63 },
64 [EC_HOST_EVENT_B] = {
65 INVALID_HCMD, EC_CMD_HOST_EVENT_CLEAR_B,
66 EC_CMD_HOST_EVENT_GET_B,
67 },
68 [EC_HOST_EVENT_SCI_MASK] = {
69 EC_CMD_HOST_EVENT_SET_SCI_MASK, INVALID_HCMD,
70 EC_CMD_HOST_EVENT_GET_SCI_MASK,
71 },
72 [EC_HOST_EVENT_SMI_MASK] = {
73 EC_CMD_HOST_EVENT_SET_SMI_MASK, INVALID_HCMD,
74 EC_CMD_HOST_EVENT_GET_SMI_MASK,
75 },
76 [EC_HOST_EVENT_ALWAYS_REPORT_MASK] = {
77 INVALID_HCMD, INVALID_HCMD, INVALID_HCMD,
78 },
79 [EC_HOST_EVENT_ACTIVE_WAKE_MASK] = {
80 EC_CMD_HOST_EVENT_SET_WAKE_MASK, INVALID_HCMD,
81 EC_CMD_HOST_EVENT_GET_WAKE_MASK,
82 },
83 [EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX] = {
84 EC_CMD_HOST_EVENT_SET_WAKE_MASK, INVALID_HCMD,
85 EC_CMD_HOST_EVENT_GET_WAKE_MASK,
86 },
87 [EC_HOST_EVENT_LAZY_WAKE_MASK_S3] = {
88 EC_CMD_HOST_EVENT_SET_WAKE_MASK, INVALID_HCMD,
89 EC_CMD_HOST_EVENT_GET_WAKE_MASK,
90 },
91 [EC_HOST_EVENT_LAZY_WAKE_MASK_S5] = {
92 EC_CMD_HOST_EVENT_SET_WAKE_MASK, INVALID_HCMD,
93 EC_CMD_HOST_EVENT_GET_WAKE_MASK,
94 },
95};
96
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +080097void cros_ec_dump_data(const char *name, int cmd, const uint8_t *data, int len)
98{
99#ifdef DEBUG
100 int i;
101
102 printf("%s: ", name);
103 if (cmd != -1)
104 printf("cmd=%#x: ", cmd);
105 for (i = 0; i < len; i++)
106 printf("%02x ", data[i]);
107 printf("\n");
108#endif
109}
110
111/*
112 * Calculate a simple 8-bit checksum of a data block
113 *
114 * @param data Data block to checksum
115 * @param size Size of data block in bytes
116 * @return checksum value (0 to 255)
117 */
118int cros_ec_calc_checksum(const uint8_t *data, int size)
119{
120 int csum, i;
121
122 for (i = csum = 0; i < size; i++)
123 csum += data[i];
124 return csum & 0xff;
125}
126
Simon Glass13c7c5b2014-02-27 13:26:09 -0700127/**
128 * Create a request packet for protocol version 3.
129 *
130 * The packet is stored in the device's internal output buffer.
131 *
132 * @param dev CROS-EC device
133 * @param cmd Command to send (EC_CMD_...)
134 * @param cmd_version Version of command to send (EC_VER_...)
135 * @param dout Output data (may be NULL If dout_len=0)
136 * @param dout_len Size of output data in bytes
137 * @return packet size in bytes, or <0 if error.
138 */
Simon Glassbed43522018-10-01 12:22:22 -0600139static int create_proto3_request(struct cros_ec_dev *cdev,
Simon Glass13c7c5b2014-02-27 13:26:09 -0700140 int cmd, int cmd_version,
141 const void *dout, int dout_len)
142{
Simon Glassbed43522018-10-01 12:22:22 -0600143 struct ec_host_request *rq = (struct ec_host_request *)cdev->dout;
Simon Glass13c7c5b2014-02-27 13:26:09 -0700144 int out_bytes = dout_len + sizeof(*rq);
145
146 /* Fail if output size is too big */
Simon Glassbed43522018-10-01 12:22:22 -0600147 if (out_bytes > (int)sizeof(cdev->dout)) {
Simon Glass13c7c5b2014-02-27 13:26:09 -0700148 debug("%s: Cannot send %d bytes\n", __func__, dout_len);
149 return -EC_RES_REQUEST_TRUNCATED;
150 }
151
152 /* Fill in request packet */
153 rq->struct_version = EC_HOST_REQUEST_VERSION;
154 rq->checksum = 0;
155 rq->command = cmd;
156 rq->command_version = cmd_version;
157 rq->reserved = 0;
158 rq->data_len = dout_len;
159
160 /* Copy data after header */
161 memcpy(rq + 1, dout, dout_len);
162
163 /* Write checksum field so the entire packet sums to 0 */
Simon Glassbed43522018-10-01 12:22:22 -0600164 rq->checksum = (uint8_t)(-cros_ec_calc_checksum(cdev->dout, out_bytes));
Simon Glass13c7c5b2014-02-27 13:26:09 -0700165
Simon Glassbed43522018-10-01 12:22:22 -0600166 cros_ec_dump_data("out", cmd, cdev->dout, out_bytes);
Simon Glass13c7c5b2014-02-27 13:26:09 -0700167
168 /* Return size of request packet */
169 return out_bytes;
170}
171
172/**
173 * Prepare the device to receive a protocol version 3 response.
174 *
175 * @param dev CROS-EC device
176 * @param din_len Maximum size of response in bytes
177 * @return maximum expected number of bytes in response, or <0 if error.
178 */
Simon Glassbed43522018-10-01 12:22:22 -0600179static int prepare_proto3_response_buffer(struct cros_ec_dev *cdev, int din_len)
Simon Glass13c7c5b2014-02-27 13:26:09 -0700180{
181 int in_bytes = din_len + sizeof(struct ec_host_response);
182
183 /* Fail if input size is too big */
Simon Glassbed43522018-10-01 12:22:22 -0600184 if (in_bytes > (int)sizeof(cdev->din)) {
Simon Glass13c7c5b2014-02-27 13:26:09 -0700185 debug("%s: Cannot receive %d bytes\n", __func__, din_len);
186 return -EC_RES_RESPONSE_TOO_BIG;
187 }
188
189 /* Return expected size of response packet */
190 return in_bytes;
191}
192
193/**
194 * Handle a protocol version 3 response packet.
195 *
196 * The packet must already be stored in the device's internal input buffer.
197 *
198 * @param dev CROS-EC device
199 * @param dinp Returns pointer to response data
200 * @param din_len Maximum size of response in bytes
Simon Glassd3d9c062015-01-25 08:27:17 -0700201 * @return number of bytes of response data, or <0 if error. Note that error
202 * codes can be from errno.h or -ve EC_RES_INVALID_CHECKSUM values (and they
203 * overlap!)
Simon Glass13c7c5b2014-02-27 13:26:09 -0700204 */
205static int handle_proto3_response(struct cros_ec_dev *dev,
206 uint8_t **dinp, int din_len)
207{
208 struct ec_host_response *rs = (struct ec_host_response *)dev->din;
209 int in_bytes;
210 int csum;
211
212 cros_ec_dump_data("in-header", -1, dev->din, sizeof(*rs));
213
214 /* Check input data */
215 if (rs->struct_version != EC_HOST_RESPONSE_VERSION) {
216 debug("%s: EC response version mismatch\n", __func__);
217 return -EC_RES_INVALID_RESPONSE;
218 }
219
220 if (rs->reserved) {
221 debug("%s: EC response reserved != 0\n", __func__);
222 return -EC_RES_INVALID_RESPONSE;
223 }
224
225 if (rs->data_len > din_len) {
226 debug("%s: EC returned too much data\n", __func__);
227 return -EC_RES_RESPONSE_TOO_BIG;
228 }
229
230 cros_ec_dump_data("in-data", -1, dev->din + sizeof(*rs), rs->data_len);
231
232 /* Update in_bytes to actual data size */
233 in_bytes = sizeof(*rs) + rs->data_len;
234
235 /* Verify checksum */
236 csum = cros_ec_calc_checksum(dev->din, in_bytes);
237 if (csum) {
238 debug("%s: EC response checksum invalid: 0x%02x\n", __func__,
239 csum);
240 return -EC_RES_INVALID_CHECKSUM;
241 }
242
243 /* Return error result, if any */
244 if (rs->result)
245 return -(int)rs->result;
246
247 /* If we're still here, set response data pointer and return length */
248 *dinp = (uint8_t *)(rs + 1);
249
250 return rs->data_len;
251}
252
Simon Glassbed43522018-10-01 12:22:22 -0600253static int send_command_proto3(struct cros_ec_dev *cdev,
Simon Glass13c7c5b2014-02-27 13:26:09 -0700254 int cmd, int cmd_version,
255 const void *dout, int dout_len,
256 uint8_t **dinp, int din_len)
257{
Simon Glass44569b52014-10-13 23:42:14 -0600258 struct dm_cros_ec_ops *ops;
Simon Glass13c7c5b2014-02-27 13:26:09 -0700259 int out_bytes, in_bytes;
260 int rv;
261
262 /* Create request packet */
Simon Glassbed43522018-10-01 12:22:22 -0600263 out_bytes = create_proto3_request(cdev, cmd, cmd_version,
Simon Glass13c7c5b2014-02-27 13:26:09 -0700264 dout, dout_len);
265 if (out_bytes < 0)
266 return out_bytes;
267
268 /* Prepare response buffer */
Simon Glassbed43522018-10-01 12:22:22 -0600269 in_bytes = prepare_proto3_response_buffer(cdev, din_len);
Simon Glass13c7c5b2014-02-27 13:26:09 -0700270 if (in_bytes < 0)
271 return in_bytes;
272
Simon Glassbed43522018-10-01 12:22:22 -0600273 ops = dm_cros_ec_get_ops(cdev->dev);
274 rv = ops->packet ? ops->packet(cdev->dev, out_bytes, in_bytes) :
275 -ENOSYS;
Simon Glass13c7c5b2014-02-27 13:26:09 -0700276 if (rv < 0)
277 return rv;
278
279 /* Process the response */
Simon Glassbed43522018-10-01 12:22:22 -0600280 return handle_proto3_response(cdev, dinp, din_len);
Simon Glass13c7c5b2014-02-27 13:26:09 -0700281}
282
Simon Glass3a239512018-11-06 15:21:18 -0700283static int send_command(struct cros_ec_dev *dev, uint cmd, int cmd_version,
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800284 const void *dout, int dout_len,
285 uint8_t **dinp, int din_len)
286{
Simon Glass44569b52014-10-13 23:42:14 -0600287 struct dm_cros_ec_ops *ops;
Simon Glass13c7c5b2014-02-27 13:26:09 -0700288 int ret = -1;
289
290 /* Handle protocol version 3 support */
291 if (dev->protocol_version == 3) {
292 return send_command_proto3(dev, cmd, cmd_version,
293 dout, dout_len, dinp, din_len);
294 }
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800295
Simon Glass44569b52014-10-13 23:42:14 -0600296 ops = dm_cros_ec_get_ops(dev->dev);
297 ret = ops->command(dev->dev, cmd, cmd_version,
298 (const uint8_t *)dout, dout_len, dinp, din_len);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800299
300 return ret;
301}
302
303/**
304 * Send a command to the CROS-EC device and return the reply.
305 *
306 * The device's internal input/output buffers are used.
307 *
308 * @param dev CROS-EC device
309 * @param cmd Command to send (EC_CMD_...)
310 * @param cmd_version Version of command to send (EC_VER_...)
311 * @param dout Output data (may be NULL If dout_len=0)
312 * @param dout_len Size of output data in bytes
313 * @param dinp Response data (may be NULL If din_len=0).
314 * If not NULL, it will be updated to point to the data
315 * and will always be double word aligned (64-bits)
316 * @param din_len Maximum size of response in bytes
Simon Glassd3d9c062015-01-25 08:27:17 -0700317 * @return number of bytes in response, or -ve on error
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800318 */
Michael Auchter4eaae8e2019-12-09 20:27:31 +0000319static int ec_command_inptr(struct udevice *dev, uint cmd,
Simon Glass699c9ca2018-10-01 12:22:08 -0600320 int cmd_version, const void *dout, int dout_len,
321 uint8_t **dinp, int din_len)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800322{
Simon Glassbed43522018-10-01 12:22:22 -0600323 struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
Simon Glass19cc2952014-02-27 13:26:11 -0700324 uint8_t *din = NULL;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800325 int len;
326
Simon Glassbed43522018-10-01 12:22:22 -0600327 len = send_command(cdev, cmd, cmd_version, dout, dout_len, &din,
328 din_len);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800329
330 /* If the command doesn't complete, wait a while */
331 if (len == -EC_RES_IN_PROGRESS) {
Simon Glass19cc2952014-02-27 13:26:11 -0700332 struct ec_response_get_comms_status *resp = NULL;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800333 ulong start;
334
335 /* Wait for command to complete */
336 start = get_timer(0);
337 do {
338 int ret;
339
340 mdelay(50); /* Insert some reasonable delay */
Simon Glassbed43522018-10-01 12:22:22 -0600341 ret = send_command(cdev, EC_CMD_GET_COMMS_STATUS, 0,
342 NULL, 0,
343 (uint8_t **)&resp, sizeof(*resp));
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800344 if (ret < 0)
345 return ret;
346
347 if (get_timer(start) > CROS_EC_CMD_TIMEOUT_MS) {
348 debug("%s: Command %#02x timeout\n",
349 __func__, cmd);
350 return -EC_RES_TIMEOUT;
351 }
352 } while (resp->flags & EC_COMMS_STATUS_PROCESSING);
353
354 /* OK it completed, so read the status response */
355 /* not sure why it was 0 for the last argument */
Simon Glassbed43522018-10-01 12:22:22 -0600356 len = send_command(cdev, EC_CMD_RESEND_RESPONSE, 0, NULL, 0,
357 &din, din_len);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800358 }
359
Simon Glass0b8e8ce2017-05-18 20:09:22 -0600360 debug("%s: len=%d, din=%p\n", __func__, len, din);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800361 if (dinp) {
362 /* If we have any data to return, it must be 64bit-aligned */
363 assert(len <= 0 || !((uintptr_t)din & 7));
364 *dinp = din;
365 }
366
367 return len;
368}
369
370/**
371 * Send a command to the CROS-EC device and return the reply.
372 *
373 * The device's internal input/output buffers are used.
374 *
375 * @param dev CROS-EC device
376 * @param cmd Command to send (EC_CMD_...)
377 * @param cmd_version Version of command to send (EC_VER_...)
378 * @param dout Output data (may be NULL If dout_len=0)
379 * @param dout_len Size of output data in bytes
380 * @param din Response data (may be NULL If din_len=0).
381 * It not NULL, it is a place for ec_command() to copy the
382 * data to.
383 * @param din_len Maximum size of response in bytes
Simon Glassd3d9c062015-01-25 08:27:17 -0700384 * @return number of bytes in response, or -ve on error
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800385 */
Simon Glass3a239512018-11-06 15:21:18 -0700386static int ec_command(struct udevice *dev, uint cmd, int cmd_version,
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800387 const void *dout, int dout_len,
388 void *din, int din_len)
389{
390 uint8_t *in_buffer;
391 int len;
392
393 assert((din_len == 0) || din);
394 len = ec_command_inptr(dev, cmd, cmd_version, dout, dout_len,
Simon Glassbed43522018-10-01 12:22:22 -0600395 &in_buffer, din_len);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800396 if (len > 0) {
397 /*
398 * If we were asked to put it somewhere, do so, otherwise just
399 * disregard the result.
400 */
401 if (din && in_buffer) {
402 assert(len <= din_len);
403 memmove(din, in_buffer, len);
404 }
405 }
406 return len;
407}
408
Simon Glassfb726402015-10-18 21:17:14 -0600409int cros_ec_scan_keyboard(struct udevice *dev, struct mbkp_keyscan *scan)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800410{
Simon Glassbed43522018-10-01 12:22:22 -0600411 if (ec_command(dev, EC_CMD_MKBP_STATE, 0, NULL, 0, scan,
Simon Glass19cc2952014-02-27 13:26:11 -0700412 sizeof(scan->data)) != sizeof(scan->data))
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800413 return -1;
414
415 return 0;
416}
417
Alper Nebi Yasak1ce07292020-10-30 20:25:20 +0300418int cros_ec_get_next_event(struct udevice *dev,
419 struct ec_response_get_next_event *event)
420{
421 int ret;
422
423 ret = ec_command(dev, EC_CMD_GET_NEXT_EVENT, 0, NULL, 0,
424 event, sizeof(*event));
425 if (ret < 0)
426 return ret;
427 else if (ret != sizeof(*event))
428 return -EC_RES_INVALID_RESPONSE;
429
430 return 0;
431}
432
Simon Glassbed43522018-10-01 12:22:22 -0600433int cros_ec_read_id(struct udevice *dev, char *id, int maxlen)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800434{
435 struct ec_response_get_version *r;
Simon Glassa77024d2018-11-06 15:21:19 -0700436 int ret;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800437
Simon Glassa77024d2018-11-06 15:21:19 -0700438 ret = ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
439 (uint8_t **)&r, sizeof(*r));
440 if (ret != sizeof(*r)) {
Simon Glass48d268f2018-11-23 21:29:36 -0700441 log_err("Got rc %d, expected %u\n", ret, (uint)sizeof(*r));
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800442 return -1;
Simon Glassa77024d2018-11-06 15:21:19 -0700443 }
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800444
Simon Glass19cc2952014-02-27 13:26:11 -0700445 if (maxlen > (int)sizeof(r->version_string_ro))
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800446 maxlen = sizeof(r->version_string_ro);
447
448 switch (r->current_image) {
449 case EC_IMAGE_RO:
450 memcpy(id, r->version_string_ro, maxlen);
451 break;
452 case EC_IMAGE_RW:
453 memcpy(id, r->version_string_rw, maxlen);
454 break;
455 default:
Simon Glassa77024d2018-11-06 15:21:19 -0700456 log_err("Invalid EC image %d\n", r->current_image);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800457 return -1;
458 }
459
460 id[maxlen - 1] = '\0';
461 return 0;
462}
463
Simon Glassbed43522018-10-01 12:22:22 -0600464int cros_ec_read_version(struct udevice *dev,
465 struct ec_response_get_version **versionp)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800466{
467 if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
468 (uint8_t **)versionp, sizeof(**versionp))
Simon Glass19cc2952014-02-27 13:26:11 -0700469 != sizeof(**versionp))
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800470 return -1;
471
472 return 0;
473}
474
Simon Glassbed43522018-10-01 12:22:22 -0600475int cros_ec_read_build_info(struct udevice *dev, char **strp)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800476{
477 if (ec_command_inptr(dev, EC_CMD_GET_BUILD_INFO, 0, NULL, 0,
Simon Glassece28862014-02-27 13:26:07 -0700478 (uint8_t **)strp, EC_PROTO2_MAX_PARAM_SIZE) < 0)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800479 return -1;
480
481 return 0;
482}
483
Simon Glassbed43522018-10-01 12:22:22 -0600484int cros_ec_read_current_image(struct udevice *dev,
Simon Glass699c9ca2018-10-01 12:22:08 -0600485 enum ec_current_image *image)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800486{
487 struct ec_response_get_version *r;
488
489 if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
Simon Glass19cc2952014-02-27 13:26:11 -0700490 (uint8_t **)&r, sizeof(*r)) != sizeof(*r))
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800491 return -1;
492
493 *image = r->current_image;
494 return 0;
495}
496
Simon Glassbed43522018-10-01 12:22:22 -0600497static int cros_ec_wait_on_hash_done(struct udevice *dev,
Simon Glass97208d92020-11-09 07:14:43 -0700498 struct ec_params_vboot_hash *p,
Simon Glass699c9ca2018-10-01 12:22:08 -0600499 struct ec_response_vboot_hash *hash)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800500{
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800501 ulong start;
502
503 start = get_timer(0);
504 while (hash->status == EC_VBOOT_HASH_STATUS_BUSY) {
505 mdelay(50); /* Insert some reasonable delay */
506
Simon Glass97208d92020-11-09 07:14:43 -0700507 p->cmd = EC_VBOOT_HASH_GET;
508 if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, p, sizeof(*p), hash,
509 sizeof(*hash)) < 0)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800510 return -1;
511
512 if (get_timer(start) > CROS_EC_CMD_HASH_TIMEOUT_MS) {
513 debug("%s: EC_VBOOT_HASH_GET timeout\n", __func__);
514 return -EC_RES_TIMEOUT;
515 }
516 }
517 return 0;
518}
519
Simon Glass94564902018-10-01 12:22:38 -0600520int cros_ec_read_hash(struct udevice *dev, uint hash_offset,
521 struct ec_response_vboot_hash *hash)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800522{
523 struct ec_params_vboot_hash p;
524 int rv;
525
526 p.cmd = EC_VBOOT_HASH_GET;
Simon Glass94564902018-10-01 12:22:38 -0600527 p.offset = hash_offset;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800528 if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
529 hash, sizeof(*hash)) < 0)
530 return -1;
531
532 /* If the EC is busy calculating the hash, fidget until it's done. */
Simon Glass97208d92020-11-09 07:14:43 -0700533 rv = cros_ec_wait_on_hash_done(dev, &p, hash);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800534 if (rv)
535 return rv;
536
537 /* If the hash is valid, we're done. Otherwise, we have to kick it off
538 * again and wait for it to complete. Note that we explicitly assume
539 * that hashing zero bytes is always wrong, even though that would
540 * produce a valid hash value. */
541 if (hash->status == EC_VBOOT_HASH_STATUS_DONE && hash->size)
542 return 0;
543
544 debug("%s: No valid hash (status=%d size=%d). Compute one...\n",
545 __func__, hash->status, hash->size);
546
Simon Glassece28862014-02-27 13:26:07 -0700547 p.cmd = EC_VBOOT_HASH_START;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800548 p.hash_type = EC_VBOOT_HASH_TYPE_SHA256;
549 p.nonce_size = 0;
Simon Glass94564902018-10-01 12:22:38 -0600550 p.offset = hash_offset;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800551
552 if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
553 hash, sizeof(*hash)) < 0)
554 return -1;
555
Simon Glass97208d92020-11-09 07:14:43 -0700556 rv = cros_ec_wait_on_hash_done(dev, &p, hash);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800557 if (rv)
558 return rv;
Simon Glass97208d92020-11-09 07:14:43 -0700559 if (hash->status != EC_VBOOT_HASH_STATUS_DONE) {
560 log_err("Hash did not complete, status=%d\n", hash->status);
561 return -EIO;
562 }
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800563
564 debug("%s: hash done\n", __func__);
565
566 return 0;
567}
568
Simon Glassbed43522018-10-01 12:22:22 -0600569static int cros_ec_invalidate_hash(struct udevice *dev)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800570{
571 struct ec_params_vboot_hash p;
572 struct ec_response_vboot_hash *hash;
573
574 /* We don't have an explict command for the EC to discard its current
575 * hash value, so we'll just tell it to calculate one that we know is
576 * wrong (we claim that hashing zero bytes is always invalid).
577 */
578 p.cmd = EC_VBOOT_HASH_RECALC;
579 p.hash_type = EC_VBOOT_HASH_TYPE_SHA256;
580 p.nonce_size = 0;
581 p.offset = 0;
582 p.size = 0;
583
584 debug("%s:\n", __func__);
585
586 if (ec_command_inptr(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
587 (uint8_t **)&hash, sizeof(*hash)) < 0)
588 return -1;
589
590 /* No need to wait for it to finish */
591 return 0;
592}
593
Simon Glass9b306e52021-01-16 14:52:22 -0700594int cros_ec_hello(struct udevice *dev, uint *handshakep)
595{
596 struct ec_params_hello req;
597 struct ec_response_hello *resp;
598
599 req.in_data = 0x12345678;
600 if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
601 (uint8_t **)&resp, sizeof(*resp)) < 0)
602 return -EIO;
603 if (resp->out_data != req.in_data + 0x01020304) {
604 printf("Received invalid handshake %x\n", resp->out_data);
605 if (handshakep)
606 *handshakep = req.in_data;
607 return -ENOTSYNC;
608 }
609
610 return 0;
611}
612
Simon Glassbed43522018-10-01 12:22:22 -0600613int cros_ec_reboot(struct udevice *dev, enum ec_reboot_cmd cmd, uint8_t flags)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800614{
615 struct ec_params_reboot_ec p;
616
617 p.cmd = cmd;
618 p.flags = flags;
619
620 if (ec_command_inptr(dev, EC_CMD_REBOOT_EC, 0, &p, sizeof(p), NULL, 0)
621 < 0)
622 return -1;
623
624 if (!(flags & EC_REBOOT_FLAG_ON_AP_SHUTDOWN)) {
625 /*
626 * EC reboot will take place immediately so delay to allow it
627 * to complete. Note that some reboot types (EC_REBOOT_COLD)
628 * will reboot the AP as well, in which case we won't actually
629 * get to this point.
630 */
631 /*
632 * TODO(rspangler@chromium.org): Would be nice if we had a
633 * better way to determine when the reboot is complete. Could
634 * we poll a memory-mapped LPC value?
635 */
636 udelay(50000);
637 }
638
639 return 0;
640}
641
Simon Glassfb726402015-10-18 21:17:14 -0600642int cros_ec_interrupt_pending(struct udevice *dev)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800643{
Simon Glassfb726402015-10-18 21:17:14 -0600644 struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
645
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800646 /* no interrupt support : always poll */
Simon Glassfb726402015-10-18 21:17:14 -0600647 if (!dm_gpio_is_valid(&cdev->ec_int))
Simon Glass19cc2952014-02-27 13:26:11 -0700648 return -ENOENT;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800649
Simon Glassfb726402015-10-18 21:17:14 -0600650 return dm_gpio_get_value(&cdev->ec_int);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800651}
652
Simon Glassbed43522018-10-01 12:22:22 -0600653int cros_ec_info(struct udevice *dev, struct ec_response_mkbp_info *info)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800654{
Simon Glassece28862014-02-27 13:26:07 -0700655 if (ec_command(dev, EC_CMD_MKBP_INFO, 0, NULL, 0, info,
Simon Glass19cc2952014-02-27 13:26:11 -0700656 sizeof(*info)) != sizeof(*info))
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800657 return -1;
658
659 return 0;
660}
661
Simon Glass153f2522018-11-06 15:21:22 -0700662int cros_ec_get_event_mask(struct udevice *dev, uint type, uint32_t *mask)
663{
664 struct ec_response_host_event_mask rsp;
665 int ret;
666
667 ret = ec_command(dev, type, 0, NULL, 0, &rsp, sizeof(rsp));
668 if (ret < 0)
669 return ret;
670 else if (ret != sizeof(rsp))
671 return -EINVAL;
672
673 *mask = rsp.mask;
674
675 return 0;
676}
677
678int cros_ec_set_event_mask(struct udevice *dev, uint type, uint32_t mask)
679{
680 struct ec_params_host_event_mask req;
681 int ret;
682
683 req.mask = mask;
684
685 ret = ec_command(dev, type, 0, &req, sizeof(req), NULL, 0);
686 if (ret < 0)
687 return ret;
688
689 return 0;
690}
691
Simon Glassbed43522018-10-01 12:22:22 -0600692int cros_ec_get_host_events(struct udevice *dev, uint32_t *events_ptr)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800693{
694 struct ec_response_host_event_mask *resp;
695
696 /*
697 * Use the B copy of the event flags, because the main copy is already
698 * used by ACPI/SMI.
699 */
700 if (ec_command_inptr(dev, EC_CMD_HOST_EVENT_GET_B, 0, NULL, 0,
Simon Glass19cc2952014-02-27 13:26:11 -0700701 (uint8_t **)&resp, sizeof(*resp)) < (int)sizeof(*resp))
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800702 return -1;
703
704 if (resp->mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_INVALID))
705 return -1;
706
707 *events_ptr = resp->mask;
708 return 0;
709}
710
Simon Glassbed43522018-10-01 12:22:22 -0600711int cros_ec_clear_host_events(struct udevice *dev, uint32_t events)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800712{
713 struct ec_params_host_event_mask params;
714
715 params.mask = events;
716
717 /*
718 * Use the B copy of the event flags, so it affects the data returned
719 * by cros_ec_get_host_events().
720 */
721 if (ec_command_inptr(dev, EC_CMD_HOST_EVENT_CLEAR_B, 0,
722 &params, sizeof(params), NULL, 0) < 0)
723 return -1;
724
725 return 0;
726}
727
Simon Glassbed43522018-10-01 12:22:22 -0600728int cros_ec_flash_protect(struct udevice *dev, uint32_t set_mask,
729 uint32_t set_flags,
Simon Glass699c9ca2018-10-01 12:22:08 -0600730 struct ec_response_flash_protect *resp)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800731{
732 struct ec_params_flash_protect params;
733
734 params.mask = set_mask;
735 params.flags = set_flags;
736
737 if (ec_command(dev, EC_CMD_FLASH_PROTECT, EC_VER_FLASH_PROTECT,
738 &params, sizeof(params),
Simon Glass19cc2952014-02-27 13:26:11 -0700739 resp, sizeof(*resp)) != sizeof(*resp))
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800740 return -1;
741
742 return 0;
743}
744
Simon Glass153f2522018-11-06 15:21:22 -0700745int cros_ec_entering_mode(struct udevice *dev, int mode)
746{
747 int rc;
748
749 rc = ec_command(dev, EC_CMD_ENTERING_MODE, 0, &mode, sizeof(mode),
750 NULL, 0);
751 if (rc)
752 return -1;
753 return 0;
754}
755
Simon Glassbed43522018-10-01 12:22:22 -0600756static int cros_ec_check_version(struct udevice *dev)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800757{
Simon Glassbed43522018-10-01 12:22:22 -0600758 struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800759 struct ec_params_hello req;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800760
Simon Glass23fb1562015-03-26 09:29:30 -0600761 struct dm_cros_ec_ops *ops;
762 int ret;
763
Simon Glassbed43522018-10-01 12:22:22 -0600764 ops = dm_cros_ec_get_ops(dev);
Simon Glass23fb1562015-03-26 09:29:30 -0600765 if (ops->check_version) {
Simon Glassbed43522018-10-01 12:22:22 -0600766 ret = ops->check_version(dev);
Simon Glass23fb1562015-03-26 09:29:30 -0600767 if (ret)
768 return ret;
769 }
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800770
771 /*
772 * TODO(sjg@chromium.org).
773 * There is a strange oddity here with the EC. We could just ignore
774 * the response, i.e. pass the last two parameters as NULL and 0.
775 * In this case we won't read back very many bytes from the EC.
776 * On the I2C bus the EC gets upset about this and will try to send
777 * the bytes anyway. This means that we will have to wait for that
778 * to complete before continuing with a new EC command.
779 *
780 * This problem is probably unique to the I2C bus.
781 *
782 * So for now, just read all the data anyway.
783 */
Randall Spanglerf03e9702014-02-27 13:26:08 -0700784
Randall Spanglerce3ebb92014-02-27 13:26:10 -0700785 /* Try sending a version 3 packet */
Simon Glassbed43522018-10-01 12:22:22 -0600786 cdev->protocol_version = 3;
Simon Glass73c1ecf2014-11-11 18:06:30 -0700787 req.in_data = 0;
Simon Glass9b306e52021-01-16 14:52:22 -0700788 ret = cros_ec_hello(dev, NULL);
789 if (!ret || ret == -ENOTSYNC)
Randall Spanglerce3ebb92014-02-27 13:26:10 -0700790 return 0;
Randall Spanglerce3ebb92014-02-27 13:26:10 -0700791
Randall Spanglerf03e9702014-02-27 13:26:08 -0700792 /* Try sending a version 2 packet */
Simon Glassbed43522018-10-01 12:22:22 -0600793 cdev->protocol_version = 2;
Simon Glass9b306e52021-01-16 14:52:22 -0700794 ret = cros_ec_hello(dev, NULL);
795 if (!ret || ret == -ENOTSYNC)
Randall Spanglerf03e9702014-02-27 13:26:08 -0700796 return 0;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800797
Randall Spanglerf03e9702014-02-27 13:26:08 -0700798 /*
799 * Fail if we're still here, since the EC doesn't understand any
800 * protcol version we speak. Version 1 interface without command
801 * version is no longer supported, and we don't know about any new
802 * protocol versions.
803 */
Simon Glassbed43522018-10-01 12:22:22 -0600804 cdev->protocol_version = 0;
Randall Spanglerf03e9702014-02-27 13:26:08 -0700805 printf("%s: ERROR: old EC interface not supported\n", __func__);
806 return -1;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800807}
808
Simon Glassbed43522018-10-01 12:22:22 -0600809int cros_ec_test(struct udevice *dev)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800810{
Simon Glass9b306e52021-01-16 14:52:22 -0700811 uint out_data;
812 int ret;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800813
Simon Glass9b306e52021-01-16 14:52:22 -0700814 ret = cros_ec_hello(dev, &out_data);
815 if (ret == -ENOTSYNC) {
816 printf("Received invalid handshake %x\n", out_data);
817 return ret;
818 } else if (ret) {
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800819 printf("ec_command_inptr() returned error\n");
Simon Glass9b306e52021-01-16 14:52:22 -0700820 return ret;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800821 }
822
823 return 0;
824}
825
Simon Glassbed43522018-10-01 12:22:22 -0600826int cros_ec_flash_offset(struct udevice *dev, enum ec_flash_region region,
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800827 uint32_t *offset, uint32_t *size)
828{
829 struct ec_params_flash_region_info p;
830 struct ec_response_flash_region_info *r;
831 int ret;
832
833 p.region = region;
834 ret = ec_command_inptr(dev, EC_CMD_FLASH_REGION_INFO,
835 EC_VER_FLASH_REGION_INFO,
836 &p, sizeof(p), (uint8_t **)&r, sizeof(*r));
837 if (ret != sizeof(*r))
838 return -1;
839
840 if (offset)
841 *offset = r->offset;
842 if (size)
843 *size = r->size;
844
845 return 0;
846}
847
Simon Glassbed43522018-10-01 12:22:22 -0600848int cros_ec_flash_erase(struct udevice *dev, uint32_t offset, uint32_t size)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800849{
850 struct ec_params_flash_erase p;
851
852 p.offset = offset;
853 p.size = size;
854 return ec_command_inptr(dev, EC_CMD_FLASH_ERASE, 0, &p, sizeof(p),
855 NULL, 0);
856}
857
858/**
859 * Write a single block to the flash
860 *
861 * Write a block of data to the EC flash. The size must not exceed the flash
862 * write block size which you can obtain from cros_ec_flash_write_burst_size().
863 *
864 * The offset starts at 0. You can obtain the region information from
865 * cros_ec_flash_offset() to find out where to write for a particular region.
866 *
867 * Attempting to write to the region where the EC is currently running from
868 * will result in an error.
869 *
870 * @param dev CROS-EC device
871 * @param data Pointer to data buffer to write
872 * @param offset Offset within flash to write to.
873 * @param size Number of bytes to write
874 * @return 0 if ok, -1 on error
875 */
Simon Glassbed43522018-10-01 12:22:22 -0600876static int cros_ec_flash_write_block(struct udevice *dev, const uint8_t *data,
877 uint32_t offset, uint32_t size)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800878{
Moritz Fischere597bc72016-09-12 12:57:52 -0700879 struct ec_params_flash_write *p;
880 int ret;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800881
Moritz Fischere597bc72016-09-12 12:57:52 -0700882 p = malloc(sizeof(*p) + size);
883 if (!p)
884 return -ENOMEM;
885
886 p->offset = offset;
887 p->size = size;
888 assert(data && p->size <= EC_FLASH_WRITE_VER0_SIZE);
889 memcpy(p + 1, data, p->size);
890
891 ret = ec_command_inptr(dev, EC_CMD_FLASH_WRITE, 0,
892 p, sizeof(*p) + size, NULL, 0) >= 0 ? 0 : -1;
893
894 free(p);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800895
Moritz Fischere597bc72016-09-12 12:57:52 -0700896 return ret;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800897}
898
899/**
900 * Return optimal flash write burst size
901 */
Simon Glassbed43522018-10-01 12:22:22 -0600902static int cros_ec_flash_write_burst_size(struct udevice *dev)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800903{
Simon Glassece28862014-02-27 13:26:07 -0700904 return EC_FLASH_WRITE_VER0_SIZE;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800905}
906
907/**
908 * Check if a block of data is erased (all 0xff)
909 *
910 * This function is useful when dealing with flash, for checking whether a
911 * data block is erased and thus does not need to be programmed.
912 *
913 * @param data Pointer to data to check (must be word-aligned)
914 * @param size Number of bytes to check (must be word-aligned)
915 * @return 0 if erased, non-zero if any word is not erased
916 */
917static int cros_ec_data_is_erased(const uint32_t *data, int size)
918{
919 assert(!(size & 3));
920 size /= sizeof(uint32_t);
921 for (; size > 0; size -= 4, data++)
922 if (*data != -1U)
923 return 0;
924
925 return 1;
926}
927
Moritz Fischerde5bc892016-09-13 14:44:48 -0700928/**
929 * Read back flash parameters
930 *
931 * This function reads back parameters of the flash as reported by the EC
932 *
933 * @param dev Pointer to device
934 * @param info Pointer to output flash info struct
935 */
Simon Glassbed43522018-10-01 12:22:22 -0600936int cros_ec_read_flashinfo(struct udevice *dev,
Simon Glass699c9ca2018-10-01 12:22:08 -0600937 struct ec_response_flash_info *info)
Moritz Fischerde5bc892016-09-13 14:44:48 -0700938{
939 int ret;
940
941 ret = ec_command(dev, EC_CMD_FLASH_INFO, 0,
942 NULL, 0, info, sizeof(*info));
943 if (ret < 0)
944 return ret;
945
946 return ret < sizeof(*info) ? -1 : 0;
947}
948
Simon Glassbed43522018-10-01 12:22:22 -0600949int cros_ec_flash_write(struct udevice *dev, const uint8_t *data,
Simon Glass699c9ca2018-10-01 12:22:08 -0600950 uint32_t offset, uint32_t size)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800951{
Simon Glassbed43522018-10-01 12:22:22 -0600952 struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800953 uint32_t burst = cros_ec_flash_write_burst_size(dev);
954 uint32_t end, off;
955 int ret;
956
Simon Glass411661d2018-11-06 15:21:20 -0700957 if (!burst)
958 return -EINVAL;
959
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800960 /*
961 * TODO: round up to the nearest multiple of write size. Can get away
962 * without that on link right now because its write size is 4 bytes.
963 */
964 end = offset + size;
965 for (off = offset; off < end; off += burst, data += burst) {
966 uint32_t todo;
967
968 /* If the data is empty, there is no point in programming it */
969 todo = min(end - off, burst);
Simon Glassbed43522018-10-01 12:22:22 -0600970 if (cdev->optimise_flash_write &&
Simon Glass699c9ca2018-10-01 12:22:08 -0600971 cros_ec_data_is_erased((uint32_t *)data, todo))
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +0800972 continue;
973
974 ret = cros_ec_flash_write_block(dev, data, off, todo);
975 if (ret)
976 return ret;
977 }
978
979 return 0;
980}
981
982/**
Simon Glass153f2522018-11-06 15:21:22 -0700983 * Run verification on a slot
984 *
985 * @param me CrosEc instance
986 * @param region Region to run verification on
987 * @return 0 if success or not applicable. Non-zero if verification failed.
988 */
989int cros_ec_efs_verify(struct udevice *dev, enum ec_flash_region region)
990{
991 struct ec_params_efs_verify p;
992 int rv;
993
994 log_info("EFS: EC is verifying updated image...\n");
995 p.region = region;
996
997 rv = ec_command(dev, EC_CMD_EFS_VERIFY, 0, &p, sizeof(p), NULL, 0);
998 if (rv >= 0) {
999 log_info("EFS: Verification success\n");
1000 return 0;
1001 }
1002 if (rv == -EC_RES_INVALID_COMMAND) {
1003 log_info("EFS: EC doesn't support EFS_VERIFY command\n");
1004 return 0;
1005 }
1006 log_info("EFS: Verification failed\n");
1007
1008 return rv;
1009}
1010
1011/**
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001012 * Read a single block from the flash
1013 *
1014 * Read a block of data from the EC flash. The size must not exceed the flash
1015 * write block size which you can obtain from cros_ec_flash_write_burst_size().
1016 *
1017 * The offset starts at 0. You can obtain the region information from
1018 * cros_ec_flash_offset() to find out where to read for a particular region.
1019 *
1020 * @param dev CROS-EC device
1021 * @param data Pointer to data buffer to read into
1022 * @param offset Offset within flash to read from
1023 * @param size Number of bytes to read
1024 * @return 0 if ok, -1 on error
1025 */
Simon Glassbed43522018-10-01 12:22:22 -06001026static int cros_ec_flash_read_block(struct udevice *dev, uint8_t *data,
Simon Glass699c9ca2018-10-01 12:22:08 -06001027 uint32_t offset, uint32_t size)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001028{
1029 struct ec_params_flash_read p;
1030
1031 p.offset = offset;
1032 p.size = size;
1033
1034 return ec_command(dev, EC_CMD_FLASH_READ, 0,
1035 &p, sizeof(p), data, size) >= 0 ? 0 : -1;
1036}
1037
Simon Glassbed43522018-10-01 12:22:22 -06001038int cros_ec_flash_read(struct udevice *dev, uint8_t *data, uint32_t offset,
Simon Glass699c9ca2018-10-01 12:22:08 -06001039 uint32_t size)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001040{
1041 uint32_t burst = cros_ec_flash_write_burst_size(dev);
1042 uint32_t end, off;
1043 int ret;
1044
1045 end = offset + size;
1046 for (off = offset; off < end; off += burst, data += burst) {
1047 ret = cros_ec_flash_read_block(dev, data, off,
1048 min(end - off, burst));
1049 if (ret)
1050 return ret;
1051 }
1052
1053 return 0;
1054}
1055
Simon Glassbed43522018-10-01 12:22:22 -06001056int cros_ec_flash_update_rw(struct udevice *dev, const uint8_t *image,
Simon Glass699c9ca2018-10-01 12:22:08 -06001057 int image_size)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001058{
1059 uint32_t rw_offset, rw_size;
1060 int ret;
1061
Simon Glass2c1e5502018-10-01 12:22:36 -06001062 if (cros_ec_flash_offset(dev, EC_FLASH_REGION_ACTIVE, &rw_offset,
1063 &rw_size))
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001064 return -1;
Simon Glass19cc2952014-02-27 13:26:11 -07001065 if (image_size > (int)rw_size)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001066 return -1;
1067
1068 /* Invalidate the existing hash, just in case the AP reboots
1069 * unexpectedly during the update. If that happened, the EC RW firmware
1070 * would be invalid, but the EC would still have the original hash.
1071 */
1072 ret = cros_ec_invalidate_hash(dev);
1073 if (ret)
1074 return ret;
1075
1076 /*
1077 * Erase the entire RW section, so that the EC doesn't see any garbage
1078 * past the new image if it's smaller than the current image.
1079 *
1080 * TODO: could optimize this to erase just the current image, since
1081 * presumably everything past that is 0xff's. But would still need to
1082 * round up to the nearest multiple of erase size.
1083 */
1084 ret = cros_ec_flash_erase(dev, rw_offset, rw_size);
1085 if (ret)
1086 return ret;
1087
1088 /* Write the image */
1089 ret = cros_ec_flash_write(dev, image, rw_offset, image_size);
1090 if (ret)
1091 return ret;
1092
1093 return 0;
1094}
1095
Simon Glassbed43522018-10-01 12:22:22 -06001096int cros_ec_read_nvdata(struct udevice *dev, uint8_t *block, int size)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001097{
1098 struct ec_params_vbnvcontext p;
1099 int len;
1100
Simon Glass153f2522018-11-06 15:21:22 -07001101 if (size != EC_VBNV_BLOCK_SIZE && size != EC_VBNV_BLOCK_SIZE_V2)
Simon Glassbed43522018-10-01 12:22:22 -06001102 return -EINVAL;
1103
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001104 p.op = EC_VBNV_CONTEXT_OP_READ;
1105
1106 len = ec_command(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT,
Simon Glass153f2522018-11-06 15:21:22 -07001107 &p, sizeof(uint32_t) + size, block, size);
1108 if (len != size) {
1109 log_err("Expected %d bytes, got %d\n", size, len);
Simon Glassbed43522018-10-01 12:22:22 -06001110 return -EIO;
Simon Glass153f2522018-11-06 15:21:22 -07001111 }
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001112
1113 return 0;
1114}
1115
Simon Glassbed43522018-10-01 12:22:22 -06001116int cros_ec_write_nvdata(struct udevice *dev, const uint8_t *block, int size)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001117{
1118 struct ec_params_vbnvcontext p;
1119 int len;
1120
Simon Glass153f2522018-11-06 15:21:22 -07001121 if (size != EC_VBNV_BLOCK_SIZE && size != EC_VBNV_BLOCK_SIZE_V2)
Simon Glassbed43522018-10-01 12:22:22 -06001122 return -EINVAL;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001123 p.op = EC_VBNV_CONTEXT_OP_WRITE;
Simon Glass153f2522018-11-06 15:21:22 -07001124 memcpy(p.block, block, size);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001125
1126 len = ec_command_inptr(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT,
Simon Glass153f2522018-11-06 15:21:22 -07001127 &p, sizeof(uint32_t) + size, NULL, 0);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001128 if (len < 0)
1129 return -1;
1130
Simon Glass153f2522018-11-06 15:21:22 -07001131 return 0;
1132}
1133
1134int cros_ec_battery_cutoff(struct udevice *dev, uint8_t flags)
1135{
1136 struct ec_params_battery_cutoff p;
1137 int len;
1138
1139 p.flags = flags;
1140 len = ec_command(dev, EC_CMD_BATTERY_CUT_OFF, 1, &p, sizeof(p),
1141 NULL, 0);
1142
1143 if (len < 0)
1144 return -1;
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001145 return 0;
1146}
1147
Simon Glasseb2cc512015-08-03 08:19:24 -06001148int cros_ec_set_ldo(struct udevice *dev, uint8_t index, uint8_t state)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001149{
1150 struct ec_params_ldo_set params;
1151
1152 params.index = index;
1153 params.state = state;
1154
Simon Glassbed43522018-10-01 12:22:22 -06001155 if (ec_command_inptr(dev, EC_CMD_LDO_SET, 0, &params, sizeof(params),
Simon Glasseb2cc512015-08-03 08:19:24 -06001156 NULL, 0))
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001157 return -1;
1158
1159 return 0;
1160}
1161
Simon Glasseb2cc512015-08-03 08:19:24 -06001162int cros_ec_get_ldo(struct udevice *dev, uint8_t index, uint8_t *state)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001163{
1164 struct ec_params_ldo_get params;
1165 struct ec_response_ldo_get *resp;
1166
1167 params.index = index;
1168
Simon Glassbed43522018-10-01 12:22:22 -06001169 if (ec_command_inptr(dev, EC_CMD_LDO_GET, 0, &params, sizeof(params),
Simon Glasseb2cc512015-08-03 08:19:24 -06001170 (uint8_t **)&resp, sizeof(*resp)) !=
1171 sizeof(*resp))
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001172 return -1;
1173
1174 *state = resp->state;
1175
1176 return 0;
1177}
1178
Simon Glass44569b52014-10-13 23:42:14 -06001179int cros_ec_register(struct udevice *dev)
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001180{
Simon Glassde0977b2015-03-05 12:25:20 -07001181 struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001182 char id[MSG_BYTES];
Simon Glass44569b52014-10-13 23:42:14 -06001183
1184 cdev->dev = dev;
Simon Glass0d7cc472015-01-05 20:05:32 -07001185 gpio_request_by_name(dev, "ec-interrupt", 0, &cdev->ec_int,
1186 GPIOD_IS_IN);
Simon Glassb35e6d62017-05-18 20:09:23 -06001187 cdev->optimise_flash_write = dev_read_bool(dev, "optimise-flash-write");
Simon Glass44569b52014-10-13 23:42:14 -06001188
Simon Glassbed43522018-10-01 12:22:22 -06001189 if (cros_ec_check_version(dev)) {
Simon Glass44569b52014-10-13 23:42:14 -06001190 debug("%s: Could not detect CROS-EC version\n", __func__);
1191 return -CROS_EC_ERR_CHECK_VERSION;
1192 }
1193
Simon Glassbed43522018-10-01 12:22:22 -06001194 if (cros_ec_read_id(dev, id, sizeof(id))) {
Simon Glass44569b52014-10-13 23:42:14 -06001195 debug("%s: Could not read KBC ID\n", __func__);
1196 return -CROS_EC_ERR_READ_ID;
1197 }
1198
1199 /* Remember this device for use by the cros_ec command */
Simon Glass46e17332015-02-17 15:29:36 -07001200 debug("Google Chrome EC v%d CROS-EC driver ready, id '%s'\n",
1201 cdev->protocol_version, id);
Simon Glass44569b52014-10-13 23:42:14 -06001202
1203 return 0;
1204}
Hung-ying Tyanc48ca88f2013-05-15 18:27:28 +08001205
Simon Glassb35e6d62017-05-18 20:09:23 -06001206int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config)
Simon Glass3c59abc2014-02-27 13:26:03 -07001207{
Simon Glassb35e6d62017-05-18 20:09:23 -06001208 ofnode flash_node, node;
Simon Glass3c59abc2014-02-27 13:26:03 -07001209
Simon Glassb35e6d62017-05-18 20:09:23 -06001210 flash_node = dev_read_subnode(dev, "flash");
1211 if (!ofnode_valid(flash_node)) {
Simon Glass3c59abc2014-02-27 13:26:03 -07001212 debug("Failed to find flash node\n");
1213 return -1;
1214 }
1215
Simon Glass4b580932018-06-11 13:07:17 -06001216 if (ofnode_read_fmap_entry(flash_node, &config->flash)) {
Simon Glassb35e6d62017-05-18 20:09:23 -06001217 debug("Failed to decode flash node in chrome-ec\n");
Simon Glass3c59abc2014-02-27 13:26:03 -07001218 return -1;
1219 }
1220
Simon Glassb35e6d62017-05-18 20:09:23 -06001221 config->flash_erase_value = ofnode_read_s32_default(flash_node,
1222 "erase-value", -1);
Simon Glass28529762017-08-05 15:45:54 -06001223 ofnode_for_each_subnode(node, flash_node) {
Simon Glassb35e6d62017-05-18 20:09:23 -06001224 const char *name = ofnode_get_name(node);
Simon Glass3c59abc2014-02-27 13:26:03 -07001225 enum ec_flash_region region;
1226
1227 if (0 == strcmp(name, "ro")) {
1228 region = EC_FLASH_REGION_RO;
1229 } else if (0 == strcmp(name, "rw")) {
Simon Glass2c1e5502018-10-01 12:22:36 -06001230 region = EC_FLASH_REGION_ACTIVE;
Simon Glass3c59abc2014-02-27 13:26:03 -07001231 } else if (0 == strcmp(name, "wp-ro")) {
1232 region = EC_FLASH_REGION_WP_RO;
1233 } else {
1234 debug("Unknown EC flash region name '%s'\n", name);
1235 return -1;
1236 }
1237
Simon Glass4b580932018-06-11 13:07:17 -06001238 if (ofnode_read_fmap_entry(node, &config->region[region])) {
Simon Glass3c59abc2014-02-27 13:26:03 -07001239 debug("Failed to decode flash region in chrome-ec'\n");
1240 return -1;
1241 }
1242 }
1243
1244 return 0;
1245}
1246
Moritz Fischer6cddc602016-09-27 15:42:07 -07001247int cros_ec_i2c_tunnel(struct udevice *dev, int port, struct i2c_msg *in,
1248 int nmsgs)
Simon Glass9ad07af2015-08-03 08:19:23 -06001249{
Simon Glass9ad07af2015-08-03 08:19:23 -06001250 union {
1251 struct ec_params_i2c_passthru p;
1252 uint8_t outbuf[EC_PROTO2_MAX_PARAM_SIZE];
1253 } params;
1254 union {
1255 struct ec_response_i2c_passthru r;
1256 uint8_t inbuf[EC_PROTO2_MAX_PARAM_SIZE];
1257 } response;
1258 struct ec_params_i2c_passthru *p = &params.p;
1259 struct ec_response_i2c_passthru *r = &response.r;
1260 struct ec_params_i2c_passthru_msg *msg;
1261 uint8_t *pdata, *read_ptr = NULL;
1262 int read_len;
1263 int size;
1264 int rv;
1265 int i;
1266
Moritz Fischer6cddc602016-09-27 15:42:07 -07001267 p->port = port;
Simon Glass9ad07af2015-08-03 08:19:23 -06001268
1269 p->num_msgs = nmsgs;
1270 size = sizeof(*p) + p->num_msgs * sizeof(*msg);
1271
1272 /* Create a message to write the register address and optional data */
1273 pdata = (uint8_t *)p + size;
1274
1275 read_len = 0;
1276 for (i = 0, msg = p->msg; i < nmsgs; i++, msg++, in++) {
1277 bool is_read = in->flags & I2C_M_RD;
1278
1279 msg->addr_flags = in->addr;
1280 msg->len = in->len;
1281 if (is_read) {
1282 msg->addr_flags |= EC_I2C_FLAG_READ;
1283 read_len += in->len;
1284 read_ptr = in->buf;
1285 if (sizeof(*r) + read_len > sizeof(response)) {
1286 puts("Read length too big for buffer\n");
1287 return -1;
1288 }
1289 } else {
1290 if (pdata - (uint8_t *)p + in->len > sizeof(params)) {
1291 puts("Params too large for buffer\n");
1292 return -1;
1293 }
1294 memcpy(pdata, in->buf, in->len);
1295 pdata += in->len;
1296 }
1297 }
1298
Simon Glassbed43522018-10-01 12:22:22 -06001299 rv = ec_command(dev, EC_CMD_I2C_PASSTHRU, 0, p, pdata - (uint8_t *)p,
Simon Glass9ad07af2015-08-03 08:19:23 -06001300 r, sizeof(*r) + read_len);
1301 if (rv < 0)
1302 return rv;
1303
1304 /* Parse response */
1305 if (r->i2c_status & EC_I2C_STATUS_ERROR) {
1306 printf("Transfer failed with status=0x%x\n", r->i2c_status);
1307 return -1;
1308 }
1309
1310 if (rv < sizeof(*r) + read_len) {
1311 puts("Truncated read response\n");
1312 return -1;
1313 }
1314
1315 /* We only support a single read message for each transfer */
1316 if (read_len)
1317 memcpy(read_ptr, r->data, read_len);
1318
Simon Glass153f2522018-11-06 15:21:22 -07001319 return 0;
1320}
1321
1322int cros_ec_check_feature(struct udevice *dev, int feature)
1323{
1324 struct ec_response_get_features r;
1325 int rv;
1326
1327 rv = ec_command(dev, EC_CMD_GET_FEATURES, 0, &r, sizeof(r), NULL, 0);
1328 if (rv)
1329 return rv;
1330
1331 if (feature >= 8 * sizeof(r.flags))
1332 return -1;
1333
1334 return r.flags[feature / 32] & EC_FEATURE_MASK_0(feature);
1335}
1336
1337/*
1338 * Query the EC for specified mask indicating enabled events.
1339 * The EC maintains separate event masks for SMI, SCI and WAKE.
1340 */
1341static int cros_ec_uhepi_cmd(struct udevice *dev, uint mask, uint action,
1342 uint64_t *value)
1343{
1344 int ret;
1345 struct ec_params_host_event req;
1346 struct ec_response_host_event rsp;
1347
1348 req.action = action;
1349 req.mask_type = mask;
1350 if (action != EC_HOST_EVENT_GET)
1351 req.value = *value;
1352 else
1353 *value = 0;
1354 ret = ec_command(dev, EC_CMD_HOST_EVENT, 0, &req, sizeof(req), &rsp,
1355 sizeof(rsp));
1356
1357 if (action != EC_HOST_EVENT_GET)
1358 return ret;
1359 if (ret == 0)
1360 *value = rsp.value;
1361
1362 return ret;
1363}
1364
1365static int cros_ec_handle_non_uhepi_cmd(struct udevice *dev, uint hcmd,
1366 uint action, uint64_t *value)
1367{
1368 int ret = -1;
1369 struct ec_params_host_event_mask req;
1370 struct ec_response_host_event_mask rsp;
1371
1372 if (hcmd == INVALID_HCMD)
1373 return ret;
1374
1375 if (action != EC_HOST_EVENT_GET)
1376 req.mask = (uint32_t)*value;
1377 else
1378 *value = 0;
1379
1380 ret = ec_command(dev, hcmd, 0, &req, sizeof(req), &rsp, sizeof(rsp));
1381 if (action != EC_HOST_EVENT_GET)
1382 return ret;
1383 if (ret == 0)
1384 *value = rsp.mask;
1385
1386 return ret;
1387}
1388
1389bool cros_ec_is_uhepi_supported(struct udevice *dev)
1390{
1391#define UHEPI_SUPPORTED 1
1392#define UHEPI_NOT_SUPPORTED 2
1393 static int uhepi_support;
1394
1395 if (!uhepi_support) {
1396 uhepi_support = cros_ec_check_feature(dev,
1397 EC_FEATURE_UNIFIED_WAKE_MASKS) > 0 ? UHEPI_SUPPORTED :
1398 UHEPI_NOT_SUPPORTED;
1399 log_debug("Chrome EC: UHEPI %s\n",
1400 uhepi_support == UHEPI_SUPPORTED ? "supported" :
1401 "not supported");
1402 }
1403 return uhepi_support == UHEPI_SUPPORTED;
1404}
1405
1406static int cros_ec_get_mask(struct udevice *dev, uint type)
1407{
1408 u64 value = 0;
1409
1410 if (cros_ec_is_uhepi_supported(dev)) {
1411 cros_ec_uhepi_cmd(dev, type, EC_HOST_EVENT_GET, &value);
1412 } else {
1413 assert(type < ARRAY_SIZE(event_map));
1414 cros_ec_handle_non_uhepi_cmd(dev, event_map[type].get_cmd,
1415 EC_HOST_EVENT_GET, &value);
1416 }
1417 return value;
1418}
1419
1420static int cros_ec_clear_mask(struct udevice *dev, uint type, u64 mask)
1421{
1422 if (cros_ec_is_uhepi_supported(dev))
1423 return cros_ec_uhepi_cmd(dev, type, EC_HOST_EVENT_CLEAR, &mask);
1424
1425 assert(type < ARRAY_SIZE(event_map));
1426
1427 return cros_ec_handle_non_uhepi_cmd(dev, event_map[type].clear_cmd,
1428 EC_HOST_EVENT_CLEAR, &mask);
1429}
1430
1431uint64_t cros_ec_get_events_b(struct udevice *dev)
1432{
1433 return cros_ec_get_mask(dev, EC_HOST_EVENT_B);
1434}
1435
1436int cros_ec_clear_events_b(struct udevice *dev, uint64_t mask)
1437{
1438 log_debug("Chrome EC: clear events_b mask to 0x%016llx\n", mask);
1439
1440 return cros_ec_clear_mask(dev, EC_HOST_EVENT_B, mask);
1441}
1442
1443int cros_ec_read_limit_power(struct udevice *dev, int *limit_powerp)
1444{
1445 struct ec_params_charge_state p;
1446 struct ec_response_charge_state r;
1447 int ret;
1448
1449 p.cmd = CHARGE_STATE_CMD_GET_PARAM;
1450 p.get_param.param = CS_PARAM_LIMIT_POWER;
1451 ret = ec_command(dev, EC_CMD_CHARGE_STATE, 0, &p, sizeof(p),
1452 &r, sizeof(r));
1453
1454 /*
1455 * If our EC doesn't support the LIMIT_POWER parameter, assume that
1456 * LIMIT_POWER is not requested.
1457 */
1458 if (ret == -EC_RES_INVALID_PARAM || ret == -EC_RES_INVALID_COMMAND) {
1459 log_warning("PARAM_LIMIT_POWER not supported by EC\n");
1460 return -ENOSYS;
1461 }
1462
1463 if (ret != sizeof(r.get_param))
1464 return -EINVAL;
1465
1466 *limit_powerp = r.get_param.value;
1467 return 0;
1468}
1469
1470int cros_ec_config_powerbtn(struct udevice *dev, uint32_t flags)
1471{
1472 struct ec_params_config_power_button params;
1473 int ret;
1474
1475 params.flags = flags;
1476 ret = ec_command(dev, EC_CMD_CONFIG_POWER_BUTTON, 0,
1477 &params, sizeof(params), NULL, 0);
1478 if (ret < 0)
1479 return ret;
1480
1481 return 0;
1482}
1483
1484int cros_ec_get_lid_shutdown_mask(struct udevice *dev)
1485{
1486 u32 mask;
1487 int ret;
1488
1489 ret = cros_ec_get_event_mask(dev, EC_CMD_HOST_EVENT_GET_SMI_MASK,
1490 &mask);
1491 if (ret < 0)
1492 return ret;
1493
1494 return !!(mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_CLOSED));
1495}
1496
1497int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable)
1498{
1499 u32 mask;
1500 int ret;
1501
1502 ret = cros_ec_get_event_mask(dev, EC_CMD_HOST_EVENT_GET_SMI_MASK,
1503 &mask);
1504 if (ret < 0)
1505 return ret;
1506
Simon Glass48d268f2018-11-23 21:29:36 -07001507 /* Set lid close event state in the EC SMI event mask */
Simon Glass153f2522018-11-06 15:21:22 -07001508 if (enable)
1509 mask |= EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_CLOSED);
1510 else
1511 mask &= ~EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_CLOSED);
1512
1513 ret = cros_ec_set_event_mask(dev, EC_CMD_HOST_EVENT_SET_SMI_MASK, mask);
1514 if (ret < 0)
1515 return ret;
1516
1517 printf("EC: %sabled lid close event\n", enable ? "en" : "dis");
Simon Glass9ad07af2015-08-03 08:19:23 -06001518 return 0;
1519}
1520
Simon Glass44569b52014-10-13 23:42:14 -06001521UCLASS_DRIVER(cros_ec) = {
1522 .id = UCLASS_CROS_EC,
Simon Glassf18ca782019-05-02 10:52:11 -06001523 .name = "cros-ec",
Simon Glass8a2b47f2020-12-03 16:55:17 -07001524 .per_device_auto = sizeof(struct cros_ec_dev),
Simon Glass18230342016-07-05 17:10:10 -06001525 .post_bind = dm_scan_fdt_dev,
Simon Glass134022a2018-11-06 15:21:21 -07001526 .flags = DM_UC_FLAG_ALLOC_PRIV_DMA,
Simon Glass44569b52014-10-13 23:42:14 -06001527};