blob: c5ac03d027dad2c5cefd2da29d95031d1d038695 [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/*
Simon Glass836bb6e2014-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 Tyan88364382013-05-15 18:27:28 +080014 */
15
16#include <common.h>
17#include <command.h>
Simon Glass84d6cbd2014-10-13 23:42:14 -060018#include <dm.h>
Hung-ying Tyan88364382013-05-15 18:27:28 +080019#include <i2c.h>
20#include <cros_ec.h>
21#include <fdtdec.h>
22#include <malloc.h>
23#include <spi.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090024#include <linux/errno.h>
Hung-ying Tyan88364382013-05-15 18:27:28 +080025#include <asm/io.h>
26#include <asm-generic/gpio.h>
Simon Glass84d6cbd2014-10-13 23:42:14 -060027#include <dm/device-internal.h>
Simon Glass2ec9d172017-05-18 20:09:23 -060028#include <dm/of_extra.h>
Simon Glass84d6cbd2014-10-13 23:42:14 -060029#include <dm/uclass-internal.h>
Hung-ying Tyan88364382013-05-15 18:27:28 +080030
31#ifdef DEBUG_TRACE
32#define debug_trace(fmt, b...) debug(fmt, #b)
33#else
34#define debug_trace(fmt, b...)
35#endif
36
37enum {
38 /* Timeout waiting for a flash erase command to complete */
39 CROS_EC_CMD_TIMEOUT_MS = 5000,
40 /* Timeout waiting for a synchronous hash to be recomputed */
41 CROS_EC_CMD_HASH_TIMEOUT_MS = 2000,
42};
43
Hung-ying Tyan88364382013-05-15 18:27:28 +080044void cros_ec_dump_data(const char *name, int cmd, const uint8_t *data, int len)
45{
46#ifdef DEBUG
47 int i;
48
49 printf("%s: ", name);
50 if (cmd != -1)
51 printf("cmd=%#x: ", cmd);
52 for (i = 0; i < len; i++)
53 printf("%02x ", data[i]);
54 printf("\n");
55#endif
56}
57
58/*
59 * Calculate a simple 8-bit checksum of a data block
60 *
61 * @param data Data block to checksum
62 * @param size Size of data block in bytes
63 * @return checksum value (0 to 255)
64 */
65int cros_ec_calc_checksum(const uint8_t *data, int size)
66{
67 int csum, i;
68
69 for (i = csum = 0; i < size; i++)
70 csum += data[i];
71 return csum & 0xff;
72}
73
Simon Glass2d8ede52014-02-27 13:26:09 -070074/**
75 * Create a request packet for protocol version 3.
76 *
77 * The packet is stored in the device's internal output buffer.
78 *
79 * @param dev CROS-EC device
80 * @param cmd Command to send (EC_CMD_...)
81 * @param cmd_version Version of command to send (EC_VER_...)
82 * @param dout Output data (may be NULL If dout_len=0)
83 * @param dout_len Size of output data in bytes
84 * @return packet size in bytes, or <0 if error.
85 */
86static int create_proto3_request(struct cros_ec_dev *dev,
87 int cmd, int cmd_version,
88 const void *dout, int dout_len)
89{
90 struct ec_host_request *rq = (struct ec_host_request *)dev->dout;
91 int out_bytes = dout_len + sizeof(*rq);
92
93 /* Fail if output size is too big */
94 if (out_bytes > (int)sizeof(dev->dout)) {
95 debug("%s: Cannot send %d bytes\n", __func__, dout_len);
96 return -EC_RES_REQUEST_TRUNCATED;
97 }
98
99 /* Fill in request packet */
100 rq->struct_version = EC_HOST_REQUEST_VERSION;
101 rq->checksum = 0;
102 rq->command = cmd;
103 rq->command_version = cmd_version;
104 rq->reserved = 0;
105 rq->data_len = dout_len;
106
107 /* Copy data after header */
108 memcpy(rq + 1, dout, dout_len);
109
110 /* Write checksum field so the entire packet sums to 0 */
111 rq->checksum = (uint8_t)(-cros_ec_calc_checksum(dev->dout, out_bytes));
112
113 cros_ec_dump_data("out", cmd, dev->dout, out_bytes);
114
115 /* Return size of request packet */
116 return out_bytes;
117}
118
119/**
120 * Prepare the device to receive a protocol version 3 response.
121 *
122 * @param dev CROS-EC device
123 * @param din_len Maximum size of response in bytes
124 * @return maximum expected number of bytes in response, or <0 if error.
125 */
126static int prepare_proto3_response_buffer(struct cros_ec_dev *dev, int din_len)
127{
128 int in_bytes = din_len + sizeof(struct ec_host_response);
129
130 /* Fail if input size is too big */
131 if (in_bytes > (int)sizeof(dev->din)) {
132 debug("%s: Cannot receive %d bytes\n", __func__, din_len);
133 return -EC_RES_RESPONSE_TOO_BIG;
134 }
135
136 /* Return expected size of response packet */
137 return in_bytes;
138}
139
140/**
141 * Handle a protocol version 3 response packet.
142 *
143 * The packet must already be stored in the device's internal input buffer.
144 *
145 * @param dev CROS-EC device
146 * @param dinp Returns pointer to response data
147 * @param din_len Maximum size of response in bytes
Simon Glass8bbb38b2015-01-25 08:27:17 -0700148 * @return number of bytes of response data, or <0 if error. Note that error
149 * codes can be from errno.h or -ve EC_RES_INVALID_CHECKSUM values (and they
150 * overlap!)
Simon Glass2d8ede52014-02-27 13:26:09 -0700151 */
152static int handle_proto3_response(struct cros_ec_dev *dev,
153 uint8_t **dinp, int din_len)
154{
155 struct ec_host_response *rs = (struct ec_host_response *)dev->din;
156 int in_bytes;
157 int csum;
158
159 cros_ec_dump_data("in-header", -1, dev->din, sizeof(*rs));
160
161 /* Check input data */
162 if (rs->struct_version != EC_HOST_RESPONSE_VERSION) {
163 debug("%s: EC response version mismatch\n", __func__);
164 return -EC_RES_INVALID_RESPONSE;
165 }
166
167 if (rs->reserved) {
168 debug("%s: EC response reserved != 0\n", __func__);
169 return -EC_RES_INVALID_RESPONSE;
170 }
171
172 if (rs->data_len > din_len) {
173 debug("%s: EC returned too much data\n", __func__);
174 return -EC_RES_RESPONSE_TOO_BIG;
175 }
176
177 cros_ec_dump_data("in-data", -1, dev->din + sizeof(*rs), rs->data_len);
178
179 /* Update in_bytes to actual data size */
180 in_bytes = sizeof(*rs) + rs->data_len;
181
182 /* Verify checksum */
183 csum = cros_ec_calc_checksum(dev->din, in_bytes);
184 if (csum) {
185 debug("%s: EC response checksum invalid: 0x%02x\n", __func__,
186 csum);
187 return -EC_RES_INVALID_CHECKSUM;
188 }
189
190 /* Return error result, if any */
191 if (rs->result)
192 return -(int)rs->result;
193
194 /* If we're still here, set response data pointer and return length */
195 *dinp = (uint8_t *)(rs + 1);
196
197 return rs->data_len;
198}
199
200static int send_command_proto3(struct cros_ec_dev *dev,
201 int cmd, int cmd_version,
202 const void *dout, int dout_len,
203 uint8_t **dinp, int din_len)
204{
Simon Glass84d6cbd2014-10-13 23:42:14 -0600205 struct dm_cros_ec_ops *ops;
Simon Glass2d8ede52014-02-27 13:26:09 -0700206 int out_bytes, in_bytes;
207 int rv;
208
209 /* Create request packet */
210 out_bytes = create_proto3_request(dev, cmd, cmd_version,
211 dout, dout_len);
212 if (out_bytes < 0)
213 return out_bytes;
214
215 /* Prepare response buffer */
216 in_bytes = prepare_proto3_response_buffer(dev, din_len);
217 if (in_bytes < 0)
218 return in_bytes;
219
Simon Glass84d6cbd2014-10-13 23:42:14 -0600220 ops = dm_cros_ec_get_ops(dev->dev);
Simon Glass8bbb38b2015-01-25 08:27:17 -0700221 rv = ops->packet ? ops->packet(dev->dev, out_bytes, in_bytes) : -ENOSYS;
Simon Glass2d8ede52014-02-27 13:26:09 -0700222 if (rv < 0)
223 return rv;
224
225 /* Process the response */
226 return handle_proto3_response(dev, dinp, din_len);
227}
228
Hung-ying Tyan88364382013-05-15 18:27:28 +0800229static int send_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
230 const void *dout, int dout_len,
231 uint8_t **dinp, int din_len)
232{
Simon Glass84d6cbd2014-10-13 23:42:14 -0600233 struct dm_cros_ec_ops *ops;
Simon Glass2d8ede52014-02-27 13:26:09 -0700234 int ret = -1;
235
236 /* Handle protocol version 3 support */
237 if (dev->protocol_version == 3) {
238 return send_command_proto3(dev, cmd, cmd_version,
239 dout, dout_len, dinp, din_len);
240 }
Hung-ying Tyan88364382013-05-15 18:27:28 +0800241
Simon Glass84d6cbd2014-10-13 23:42:14 -0600242 ops = dm_cros_ec_get_ops(dev->dev);
243 ret = ops->command(dev->dev, cmd, cmd_version,
244 (const uint8_t *)dout, dout_len, dinp, din_len);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800245
246 return ret;
247}
248
249/**
250 * Send a command to the CROS-EC device and return the reply.
251 *
252 * The device's internal input/output buffers are used.
253 *
254 * @param dev CROS-EC device
255 * @param cmd Command to send (EC_CMD_...)
256 * @param cmd_version Version of command to send (EC_VER_...)
257 * @param dout Output data (may be NULL If dout_len=0)
258 * @param dout_len Size of output data in bytes
259 * @param dinp Response data (may be NULL If din_len=0).
260 * If not NULL, it will be updated to point to the data
261 * and will always be double word aligned (64-bits)
262 * @param din_len Maximum size of response in bytes
Simon Glass8bbb38b2015-01-25 08:27:17 -0700263 * @return number of bytes in response, or -ve on error
Hung-ying Tyan88364382013-05-15 18:27:28 +0800264 */
265static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd,
Simon Glasse6c5c942018-10-01 12:22:08 -0600266 int cmd_version, const void *dout, int dout_len,
267 uint8_t **dinp, int din_len)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800268{
Simon Glass2ab83f02014-02-27 13:26:11 -0700269 uint8_t *din = NULL;
Hung-ying Tyan88364382013-05-15 18:27:28 +0800270 int len;
271
Hung-ying Tyan88364382013-05-15 18:27:28 +0800272 len = send_command(dev, cmd, cmd_version, dout, dout_len,
273 &din, din_len);
274
275 /* If the command doesn't complete, wait a while */
276 if (len == -EC_RES_IN_PROGRESS) {
Simon Glass2ab83f02014-02-27 13:26:11 -0700277 struct ec_response_get_comms_status *resp = NULL;
Hung-ying Tyan88364382013-05-15 18:27:28 +0800278 ulong start;
279
280 /* Wait for command to complete */
281 start = get_timer(0);
282 do {
283 int ret;
284
285 mdelay(50); /* Insert some reasonable delay */
286 ret = send_command(dev, EC_CMD_GET_COMMS_STATUS, 0,
287 NULL, 0,
288 (uint8_t **)&resp, sizeof(*resp));
289 if (ret < 0)
290 return ret;
291
292 if (get_timer(start) > CROS_EC_CMD_TIMEOUT_MS) {
293 debug("%s: Command %#02x timeout\n",
294 __func__, cmd);
295 return -EC_RES_TIMEOUT;
296 }
297 } while (resp->flags & EC_COMMS_STATUS_PROCESSING);
298
299 /* OK it completed, so read the status response */
300 /* not sure why it was 0 for the last argument */
301 len = send_command(dev, EC_CMD_RESEND_RESPONSE, 0,
302 NULL, 0, &din, din_len);
303 }
304
Simon Glasse907bf22017-05-18 20:09:22 -0600305 debug("%s: len=%d, din=%p\n", __func__, len, din);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800306 if (dinp) {
307 /* If we have any data to return, it must be 64bit-aligned */
308 assert(len <= 0 || !((uintptr_t)din & 7));
309 *dinp = din;
310 }
311
312 return len;
313}
314
315/**
316 * Send a command to the CROS-EC device and return the reply.
317 *
318 * The device's internal input/output buffers are used.
319 *
320 * @param dev CROS-EC device
321 * @param cmd Command to send (EC_CMD_...)
322 * @param cmd_version Version of command to send (EC_VER_...)
323 * @param dout Output data (may be NULL If dout_len=0)
324 * @param dout_len Size of output data in bytes
325 * @param din Response data (may be NULL If din_len=0).
326 * It not NULL, it is a place for ec_command() to copy the
327 * data to.
328 * @param din_len Maximum size of response in bytes
Simon Glass8bbb38b2015-01-25 08:27:17 -0700329 * @return number of bytes in response, or -ve on error
Hung-ying Tyan88364382013-05-15 18:27:28 +0800330 */
331static int ec_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
332 const void *dout, int dout_len,
333 void *din, int din_len)
334{
335 uint8_t *in_buffer;
336 int len;
337
338 assert((din_len == 0) || din);
339 len = ec_command_inptr(dev, cmd, cmd_version, dout, dout_len,
340 &in_buffer, din_len);
341 if (len > 0) {
342 /*
343 * If we were asked to put it somewhere, do so, otherwise just
344 * disregard the result.
345 */
346 if (din && in_buffer) {
347 assert(len <= din_len);
348 memmove(din, in_buffer, len);
349 }
350 }
351 return len;
352}
353
Simon Glass745009c2015-10-18 21:17:14 -0600354int cros_ec_scan_keyboard(struct udevice *dev, struct mbkp_keyscan *scan)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800355{
Simon Glass745009c2015-10-18 21:17:14 -0600356 struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
357
358 if (ec_command(cdev, EC_CMD_MKBP_STATE, 0, NULL, 0, scan,
Simon Glass2ab83f02014-02-27 13:26:11 -0700359 sizeof(scan->data)) != sizeof(scan->data))
Hung-ying Tyan88364382013-05-15 18:27:28 +0800360 return -1;
361
362 return 0;
363}
364
365int cros_ec_read_id(struct cros_ec_dev *dev, char *id, int maxlen)
366{
367 struct ec_response_get_version *r;
368
369 if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
Simon Glass2ab83f02014-02-27 13:26:11 -0700370 (uint8_t **)&r, sizeof(*r)) != sizeof(*r))
Hung-ying Tyan88364382013-05-15 18:27:28 +0800371 return -1;
372
Simon Glass2ab83f02014-02-27 13:26:11 -0700373 if (maxlen > (int)sizeof(r->version_string_ro))
Hung-ying Tyan88364382013-05-15 18:27:28 +0800374 maxlen = sizeof(r->version_string_ro);
375
376 switch (r->current_image) {
377 case EC_IMAGE_RO:
378 memcpy(id, r->version_string_ro, maxlen);
379 break;
380 case EC_IMAGE_RW:
381 memcpy(id, r->version_string_rw, maxlen);
382 break;
383 default:
384 return -1;
385 }
386
387 id[maxlen - 1] = '\0';
388 return 0;
389}
390
391int cros_ec_read_version(struct cros_ec_dev *dev,
392 struct ec_response_get_version **versionp)
393{
394 if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
395 (uint8_t **)versionp, sizeof(**versionp))
Simon Glass2ab83f02014-02-27 13:26:11 -0700396 != sizeof(**versionp))
Hung-ying Tyan88364382013-05-15 18:27:28 +0800397 return -1;
398
399 return 0;
400}
401
402int cros_ec_read_build_info(struct cros_ec_dev *dev, char **strp)
403{
404 if (ec_command_inptr(dev, EC_CMD_GET_BUILD_INFO, 0, NULL, 0,
Simon Glass836bb6e2014-02-27 13:26:07 -0700405 (uint8_t **)strp, EC_PROTO2_MAX_PARAM_SIZE) < 0)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800406 return -1;
407
408 return 0;
409}
410
411int cros_ec_read_current_image(struct cros_ec_dev *dev,
Simon Glasse6c5c942018-10-01 12:22:08 -0600412 enum ec_current_image *image)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800413{
414 struct ec_response_get_version *r;
415
416 if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
Simon Glass2ab83f02014-02-27 13:26:11 -0700417 (uint8_t **)&r, sizeof(*r)) != sizeof(*r))
Hung-ying Tyan88364382013-05-15 18:27:28 +0800418 return -1;
419
420 *image = r->current_image;
421 return 0;
422}
423
424static int cros_ec_wait_on_hash_done(struct cros_ec_dev *dev,
Simon Glasse6c5c942018-10-01 12:22:08 -0600425 struct ec_response_vboot_hash *hash)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800426{
427 struct ec_params_vboot_hash p;
428 ulong start;
429
430 start = get_timer(0);
431 while (hash->status == EC_VBOOT_HASH_STATUS_BUSY) {
432 mdelay(50); /* Insert some reasonable delay */
433
434 p.cmd = EC_VBOOT_HASH_GET;
435 if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
436 hash, sizeof(*hash)) < 0)
437 return -1;
438
439 if (get_timer(start) > CROS_EC_CMD_HASH_TIMEOUT_MS) {
440 debug("%s: EC_VBOOT_HASH_GET timeout\n", __func__);
441 return -EC_RES_TIMEOUT;
442 }
443 }
444 return 0;
445}
446
447
448int cros_ec_read_hash(struct cros_ec_dev *dev,
Simon Glasse6c5c942018-10-01 12:22:08 -0600449 struct ec_response_vboot_hash *hash)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800450{
451 struct ec_params_vboot_hash p;
452 int rv;
453
454 p.cmd = EC_VBOOT_HASH_GET;
455 if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
456 hash, sizeof(*hash)) < 0)
457 return -1;
458
459 /* If the EC is busy calculating the hash, fidget until it's done. */
460 rv = cros_ec_wait_on_hash_done(dev, hash);
461 if (rv)
462 return rv;
463
464 /* If the hash is valid, we're done. Otherwise, we have to kick it off
465 * again and wait for it to complete. Note that we explicitly assume
466 * that hashing zero bytes is always wrong, even though that would
467 * produce a valid hash value. */
468 if (hash->status == EC_VBOOT_HASH_STATUS_DONE && hash->size)
469 return 0;
470
471 debug("%s: No valid hash (status=%d size=%d). Compute one...\n",
472 __func__, hash->status, hash->size);
473
Simon Glass836bb6e2014-02-27 13:26:07 -0700474 p.cmd = EC_VBOOT_HASH_START;
Hung-ying Tyan88364382013-05-15 18:27:28 +0800475 p.hash_type = EC_VBOOT_HASH_TYPE_SHA256;
476 p.nonce_size = 0;
477 p.offset = EC_VBOOT_HASH_OFFSET_RW;
478
479 if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
480 hash, sizeof(*hash)) < 0)
481 return -1;
482
483 rv = cros_ec_wait_on_hash_done(dev, hash);
484 if (rv)
485 return rv;
486
487 debug("%s: hash done\n", __func__);
488
489 return 0;
490}
491
492static int cros_ec_invalidate_hash(struct cros_ec_dev *dev)
493{
494 struct ec_params_vboot_hash p;
495 struct ec_response_vboot_hash *hash;
496
497 /* We don't have an explict command for the EC to discard its current
498 * hash value, so we'll just tell it to calculate one that we know is
499 * wrong (we claim that hashing zero bytes is always invalid).
500 */
501 p.cmd = EC_VBOOT_HASH_RECALC;
502 p.hash_type = EC_VBOOT_HASH_TYPE_SHA256;
503 p.nonce_size = 0;
504 p.offset = 0;
505 p.size = 0;
506
507 debug("%s:\n", __func__);
508
509 if (ec_command_inptr(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
510 (uint8_t **)&hash, sizeof(*hash)) < 0)
511 return -1;
512
513 /* No need to wait for it to finish */
514 return 0;
515}
516
517int cros_ec_reboot(struct cros_ec_dev *dev, enum ec_reboot_cmd cmd,
Simon Glasse6c5c942018-10-01 12:22:08 -0600518 uint8_t flags)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800519{
520 struct ec_params_reboot_ec p;
521
522 p.cmd = cmd;
523 p.flags = flags;
524
525 if (ec_command_inptr(dev, EC_CMD_REBOOT_EC, 0, &p, sizeof(p), NULL, 0)
526 < 0)
527 return -1;
528
529 if (!(flags & EC_REBOOT_FLAG_ON_AP_SHUTDOWN)) {
530 /*
531 * EC reboot will take place immediately so delay to allow it
532 * to complete. Note that some reboot types (EC_REBOOT_COLD)
533 * will reboot the AP as well, in which case we won't actually
534 * get to this point.
535 */
536 /*
537 * TODO(rspangler@chromium.org): Would be nice if we had a
538 * better way to determine when the reboot is complete. Could
539 * we poll a memory-mapped LPC value?
540 */
541 udelay(50000);
542 }
543
544 return 0;
545}
546
Simon Glass745009c2015-10-18 21:17:14 -0600547int cros_ec_interrupt_pending(struct udevice *dev)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800548{
Simon Glass745009c2015-10-18 21:17:14 -0600549 struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
550
Hung-ying Tyan88364382013-05-15 18:27:28 +0800551 /* no interrupt support : always poll */
Simon Glass745009c2015-10-18 21:17:14 -0600552 if (!dm_gpio_is_valid(&cdev->ec_int))
Simon Glass2ab83f02014-02-27 13:26:11 -0700553 return -ENOENT;
Hung-ying Tyan88364382013-05-15 18:27:28 +0800554
Simon Glass745009c2015-10-18 21:17:14 -0600555 return dm_gpio_get_value(&cdev->ec_int);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800556}
557
Simon Glass836bb6e2014-02-27 13:26:07 -0700558int cros_ec_info(struct cros_ec_dev *dev, struct ec_response_mkbp_info *info)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800559{
Simon Glass836bb6e2014-02-27 13:26:07 -0700560 if (ec_command(dev, EC_CMD_MKBP_INFO, 0, NULL, 0, info,
Simon Glass2ab83f02014-02-27 13:26:11 -0700561 sizeof(*info)) != sizeof(*info))
Hung-ying Tyan88364382013-05-15 18:27:28 +0800562 return -1;
563
564 return 0;
565}
566
567int cros_ec_get_host_events(struct cros_ec_dev *dev, uint32_t *events_ptr)
568{
569 struct ec_response_host_event_mask *resp;
570
571 /*
572 * Use the B copy of the event flags, because the main copy is already
573 * used by ACPI/SMI.
574 */
575 if (ec_command_inptr(dev, EC_CMD_HOST_EVENT_GET_B, 0, NULL, 0,
Simon Glass2ab83f02014-02-27 13:26:11 -0700576 (uint8_t **)&resp, sizeof(*resp)) < (int)sizeof(*resp))
Hung-ying Tyan88364382013-05-15 18:27:28 +0800577 return -1;
578
579 if (resp->mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_INVALID))
580 return -1;
581
582 *events_ptr = resp->mask;
583 return 0;
584}
585
586int cros_ec_clear_host_events(struct cros_ec_dev *dev, uint32_t events)
587{
588 struct ec_params_host_event_mask params;
589
590 params.mask = events;
591
592 /*
593 * Use the B copy of the event flags, so it affects the data returned
594 * by cros_ec_get_host_events().
595 */
596 if (ec_command_inptr(dev, EC_CMD_HOST_EVENT_CLEAR_B, 0,
597 &params, sizeof(params), NULL, 0) < 0)
598 return -1;
599
600 return 0;
601}
602
603int cros_ec_flash_protect(struct cros_ec_dev *dev,
Simon Glasse6c5c942018-10-01 12:22:08 -0600604 uint32_t set_mask, uint32_t set_flags,
605 struct ec_response_flash_protect *resp)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800606{
607 struct ec_params_flash_protect params;
608
609 params.mask = set_mask;
610 params.flags = set_flags;
611
612 if (ec_command(dev, EC_CMD_FLASH_PROTECT, EC_VER_FLASH_PROTECT,
613 &params, sizeof(params),
Simon Glass2ab83f02014-02-27 13:26:11 -0700614 resp, sizeof(*resp)) != sizeof(*resp))
Hung-ying Tyan88364382013-05-15 18:27:28 +0800615 return -1;
616
617 return 0;
618}
619
620static int cros_ec_check_version(struct cros_ec_dev *dev)
621{
622 struct ec_params_hello req;
623 struct ec_response_hello *resp;
624
Simon Glass72a38e02015-03-26 09:29:30 -0600625 struct dm_cros_ec_ops *ops;
626 int ret;
627
628 ops = dm_cros_ec_get_ops(dev->dev);
629 if (ops->check_version) {
630 ret = ops->check_version(dev->dev);
631 if (ret)
632 return ret;
633 }
Hung-ying Tyan88364382013-05-15 18:27:28 +0800634
635 /*
636 * TODO(sjg@chromium.org).
637 * There is a strange oddity here with the EC. We could just ignore
638 * the response, i.e. pass the last two parameters as NULL and 0.
639 * In this case we won't read back very many bytes from the EC.
640 * On the I2C bus the EC gets upset about this and will try to send
641 * the bytes anyway. This means that we will have to wait for that
642 * to complete before continuing with a new EC command.
643 *
644 * This problem is probably unique to the I2C bus.
645 *
646 * So for now, just read all the data anyway.
647 */
Randall Spanglere8c12662014-02-27 13:26:08 -0700648
Randall Spanglera6070282014-02-27 13:26:10 -0700649 /* Try sending a version 3 packet */
650 dev->protocol_version = 3;
Simon Glassd11e8fd2014-11-11 18:06:30 -0700651 req.in_data = 0;
Randall Spanglera6070282014-02-27 13:26:10 -0700652 if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
653 (uint8_t **)&resp, sizeof(*resp)) > 0) {
654 return 0;
655 }
656
Randall Spanglere8c12662014-02-27 13:26:08 -0700657 /* Try sending a version 2 packet */
658 dev->protocol_version = 2;
Hung-ying Tyan88364382013-05-15 18:27:28 +0800659 if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
660 (uint8_t **)&resp, sizeof(*resp)) > 0) {
Randall Spanglere8c12662014-02-27 13:26:08 -0700661 return 0;
Hung-ying Tyan88364382013-05-15 18:27:28 +0800662 }
663
Randall Spanglere8c12662014-02-27 13:26:08 -0700664 /*
665 * Fail if we're still here, since the EC doesn't understand any
666 * protcol version we speak. Version 1 interface without command
667 * version is no longer supported, and we don't know about any new
668 * protocol versions.
669 */
670 dev->protocol_version = 0;
671 printf("%s: ERROR: old EC interface not supported\n", __func__);
672 return -1;
Hung-ying Tyan88364382013-05-15 18:27:28 +0800673}
674
675int cros_ec_test(struct cros_ec_dev *dev)
676{
677 struct ec_params_hello req;
678 struct ec_response_hello *resp;
679
680 req.in_data = 0x12345678;
681 if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
682 (uint8_t **)&resp, sizeof(*resp)) < sizeof(*resp)) {
683 printf("ec_command_inptr() returned error\n");
684 return -1;
685 }
686 if (resp->out_data != req.in_data + 0x01020304) {
687 printf("Received invalid handshake %x\n", resp->out_data);
688 return -1;
689 }
690
691 return 0;
692}
693
694int cros_ec_flash_offset(struct cros_ec_dev *dev, enum ec_flash_region region,
695 uint32_t *offset, uint32_t *size)
696{
697 struct ec_params_flash_region_info p;
698 struct ec_response_flash_region_info *r;
699 int ret;
700
701 p.region = region;
702 ret = ec_command_inptr(dev, EC_CMD_FLASH_REGION_INFO,
703 EC_VER_FLASH_REGION_INFO,
704 &p, sizeof(p), (uint8_t **)&r, sizeof(*r));
705 if (ret != sizeof(*r))
706 return -1;
707
708 if (offset)
709 *offset = r->offset;
710 if (size)
711 *size = r->size;
712
713 return 0;
714}
715
716int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset, uint32_t size)
717{
718 struct ec_params_flash_erase p;
719
720 p.offset = offset;
721 p.size = size;
722 return ec_command_inptr(dev, EC_CMD_FLASH_ERASE, 0, &p, sizeof(p),
723 NULL, 0);
724}
725
726/**
727 * Write a single block to the flash
728 *
729 * Write a block of data to the EC flash. The size must not exceed the flash
730 * write block size which you can obtain from cros_ec_flash_write_burst_size().
731 *
732 * The offset starts at 0. You can obtain the region information from
733 * cros_ec_flash_offset() to find out where to write for a particular region.
734 *
735 * Attempting to write to the region where the EC is currently running from
736 * will result in an error.
737 *
738 * @param dev CROS-EC device
739 * @param data Pointer to data buffer to write
740 * @param offset Offset within flash to write to.
741 * @param size Number of bytes to write
742 * @return 0 if ok, -1 on error
743 */
744static int cros_ec_flash_write_block(struct cros_ec_dev *dev,
Simon Glasse6c5c942018-10-01 12:22:08 -0600745 const uint8_t *data, uint32_t offset,
746 uint32_t size)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800747{
Moritz Fischerbae5b972016-09-12 12:57:52 -0700748 struct ec_params_flash_write *p;
749 int ret;
Hung-ying Tyan88364382013-05-15 18:27:28 +0800750
Moritz Fischerbae5b972016-09-12 12:57:52 -0700751 p = malloc(sizeof(*p) + size);
752 if (!p)
753 return -ENOMEM;
Hung-ying Tyan88364382013-05-15 18:27:28 +0800754
Moritz Fischerbae5b972016-09-12 12:57:52 -0700755 p->offset = offset;
756 p->size = size;
757 assert(data && p->size <= EC_FLASH_WRITE_VER0_SIZE);
758 memcpy(p + 1, data, p->size);
759
760 ret = ec_command_inptr(dev, EC_CMD_FLASH_WRITE, 0,
761 p, sizeof(*p) + size, NULL, 0) >= 0 ? 0 : -1;
762
763 free(p);
764
765 return ret;
Hung-ying Tyan88364382013-05-15 18:27:28 +0800766}
767
768/**
769 * Return optimal flash write burst size
770 */
771static int cros_ec_flash_write_burst_size(struct cros_ec_dev *dev)
772{
Simon Glass836bb6e2014-02-27 13:26:07 -0700773 return EC_FLASH_WRITE_VER0_SIZE;
Hung-ying Tyan88364382013-05-15 18:27:28 +0800774}
775
776/**
777 * Check if a block of data is erased (all 0xff)
778 *
779 * This function is useful when dealing with flash, for checking whether a
780 * data block is erased and thus does not need to be programmed.
781 *
782 * @param data Pointer to data to check (must be word-aligned)
783 * @param size Number of bytes to check (must be word-aligned)
784 * @return 0 if erased, non-zero if any word is not erased
785 */
786static int cros_ec_data_is_erased(const uint32_t *data, int size)
787{
788 assert(!(size & 3));
789 size /= sizeof(uint32_t);
790 for (; size > 0; size -= 4, data++)
791 if (*data != -1U)
792 return 0;
793
794 return 1;
795}
796
Moritz Fischer281ca882016-09-13 14:44:48 -0700797/**
798 * Read back flash parameters
799 *
800 * This function reads back parameters of the flash as reported by the EC
801 *
802 * @param dev Pointer to device
803 * @param info Pointer to output flash info struct
804 */
805int cros_ec_read_flashinfo(struct cros_ec_dev *dev,
Simon Glasse6c5c942018-10-01 12:22:08 -0600806 struct ec_response_flash_info *info)
Moritz Fischer281ca882016-09-13 14:44:48 -0700807{
808 int ret;
809
810 ret = ec_command(dev, EC_CMD_FLASH_INFO, 0,
811 NULL, 0, info, sizeof(*info));
812 if (ret < 0)
813 return ret;
814
815 return ret < sizeof(*info) ? -1 : 0;
816}
817
Hung-ying Tyan88364382013-05-15 18:27:28 +0800818int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data,
Simon Glasse6c5c942018-10-01 12:22:08 -0600819 uint32_t offset, uint32_t size)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800820{
821 uint32_t burst = cros_ec_flash_write_burst_size(dev);
822 uint32_t end, off;
823 int ret;
824
825 /*
826 * TODO: round up to the nearest multiple of write size. Can get away
827 * without that on link right now because its write size is 4 bytes.
828 */
829 end = offset + size;
830 for (off = offset; off < end; off += burst, data += burst) {
831 uint32_t todo;
832
833 /* If the data is empty, there is no point in programming it */
834 todo = min(end - off, burst);
835 if (dev->optimise_flash_write &&
Simon Glasse6c5c942018-10-01 12:22:08 -0600836 cros_ec_data_is_erased((uint32_t *)data, todo))
Hung-ying Tyan88364382013-05-15 18:27:28 +0800837 continue;
838
839 ret = cros_ec_flash_write_block(dev, data, off, todo);
840 if (ret)
841 return ret;
842 }
843
844 return 0;
845}
846
847/**
848 * Read a single block from the flash
849 *
850 * Read a block of data from the EC flash. The size must not exceed the flash
851 * write block size which you can obtain from cros_ec_flash_write_burst_size().
852 *
853 * The offset starts at 0. You can obtain the region information from
854 * cros_ec_flash_offset() to find out where to read for a particular region.
855 *
856 * @param dev CROS-EC device
857 * @param data Pointer to data buffer to read into
858 * @param offset Offset within flash to read from
859 * @param size Number of bytes to read
860 * @return 0 if ok, -1 on error
861 */
862static int cros_ec_flash_read_block(struct cros_ec_dev *dev, uint8_t *data,
Simon Glasse6c5c942018-10-01 12:22:08 -0600863 uint32_t offset, uint32_t size)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800864{
865 struct ec_params_flash_read p;
866
867 p.offset = offset;
868 p.size = size;
869
870 return ec_command(dev, EC_CMD_FLASH_READ, 0,
871 &p, sizeof(p), data, size) >= 0 ? 0 : -1;
872}
873
874int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset,
Simon Glasse6c5c942018-10-01 12:22:08 -0600875 uint32_t size)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800876{
877 uint32_t burst = cros_ec_flash_write_burst_size(dev);
878 uint32_t end, off;
879 int ret;
880
881 end = offset + size;
882 for (off = offset; off < end; off += burst, data += burst) {
883 ret = cros_ec_flash_read_block(dev, data, off,
884 min(end - off, burst));
885 if (ret)
886 return ret;
887 }
888
889 return 0;
890}
891
Simon Glasse6c5c942018-10-01 12:22:08 -0600892int cros_ec_flash_update_rw(struct cros_ec_dev *dev, const uint8_t *image,
893 int image_size)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800894{
895 uint32_t rw_offset, rw_size;
896 int ret;
897
898 if (cros_ec_flash_offset(dev, EC_FLASH_REGION_RW, &rw_offset, &rw_size))
899 return -1;
Simon Glass2ab83f02014-02-27 13:26:11 -0700900 if (image_size > (int)rw_size)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800901 return -1;
902
903 /* Invalidate the existing hash, just in case the AP reboots
904 * unexpectedly during the update. If that happened, the EC RW firmware
905 * would be invalid, but the EC would still have the original hash.
906 */
907 ret = cros_ec_invalidate_hash(dev);
908 if (ret)
909 return ret;
910
911 /*
912 * Erase the entire RW section, so that the EC doesn't see any garbage
913 * past the new image if it's smaller than the current image.
914 *
915 * TODO: could optimize this to erase just the current image, since
916 * presumably everything past that is 0xff's. But would still need to
917 * round up to the nearest multiple of erase size.
918 */
919 ret = cros_ec_flash_erase(dev, rw_offset, rw_size);
920 if (ret)
921 return ret;
922
923 /* Write the image */
924 ret = cros_ec_flash_write(dev, image, rw_offset, image_size);
925 if (ret)
926 return ret;
927
928 return 0;
929}
930
931int cros_ec_read_vbnvcontext(struct cros_ec_dev *dev, uint8_t *block)
932{
933 struct ec_params_vbnvcontext p;
934 int len;
935
936 p.op = EC_VBNV_CONTEXT_OP_READ;
937
938 len = ec_command(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT,
939 &p, sizeof(p), block, EC_VBNV_BLOCK_SIZE);
940 if (len < EC_VBNV_BLOCK_SIZE)
941 return -1;
942
943 return 0;
944}
945
946int cros_ec_write_vbnvcontext(struct cros_ec_dev *dev, const uint8_t *block)
947{
948 struct ec_params_vbnvcontext p;
949 int len;
950
951 p.op = EC_VBNV_CONTEXT_OP_WRITE;
952 memcpy(p.block, block, sizeof(p.block));
953
954 len = ec_command_inptr(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT,
955 &p, sizeof(p), NULL, 0);
956 if (len < 0)
957 return -1;
958
959 return 0;
960}
961
Simon Glassf48eaf02015-08-03 08:19:24 -0600962int cros_ec_set_ldo(struct udevice *dev, uint8_t index, uint8_t state)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800963{
Simon Glassf48eaf02015-08-03 08:19:24 -0600964 struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800965 struct ec_params_ldo_set params;
966
967 params.index = index;
968 params.state = state;
969
Simon Glassf48eaf02015-08-03 08:19:24 -0600970 if (ec_command_inptr(cdev, EC_CMD_LDO_SET, 0, &params, sizeof(params),
971 NULL, 0))
Hung-ying Tyan88364382013-05-15 18:27:28 +0800972 return -1;
973
974 return 0;
975}
976
Simon Glassf48eaf02015-08-03 08:19:24 -0600977int cros_ec_get_ldo(struct udevice *dev, uint8_t index, uint8_t *state)
Hung-ying Tyan88364382013-05-15 18:27:28 +0800978{
Simon Glassf48eaf02015-08-03 08:19:24 -0600979 struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
Hung-ying Tyan88364382013-05-15 18:27:28 +0800980 struct ec_params_ldo_get params;
981 struct ec_response_ldo_get *resp;
982
983 params.index = index;
984
Simon Glassf48eaf02015-08-03 08:19:24 -0600985 if (ec_command_inptr(cdev, EC_CMD_LDO_GET, 0, &params, sizeof(params),
986 (uint8_t **)&resp, sizeof(*resp)) !=
987 sizeof(*resp))
Hung-ying Tyan88364382013-05-15 18:27:28 +0800988 return -1;
989
990 *state = resp->state;
991
992 return 0;
993}
994
Simon Glass84d6cbd2014-10-13 23:42:14 -0600995int cros_ec_register(struct udevice *dev)
996{
Simon Glasse564f052015-03-05 12:25:20 -0700997 struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
Simon Glass84d6cbd2014-10-13 23:42:14 -0600998 char id[MSG_BYTES];
999
1000 cdev->dev = dev;
Simon Glass32f8a192015-01-05 20:05:32 -07001001 gpio_request_by_name(dev, "ec-interrupt", 0, &cdev->ec_int,
1002 GPIOD_IS_IN);
Simon Glass2ec9d172017-05-18 20:09:23 -06001003 cdev->optimise_flash_write = dev_read_bool(dev, "optimise-flash-write");
Simon Glass84d6cbd2014-10-13 23:42:14 -06001004
Simon Glass84d6cbd2014-10-13 23:42:14 -06001005 if (cros_ec_check_version(cdev)) {
1006 debug("%s: Could not detect CROS-EC version\n", __func__);
1007 return -CROS_EC_ERR_CHECK_VERSION;
1008 }
1009
1010 if (cros_ec_read_id(cdev, id, sizeof(id))) {
1011 debug("%s: Could not read KBC ID\n", __func__);
1012 return -CROS_EC_ERR_READ_ID;
1013 }
1014
1015 /* Remember this device for use by the cros_ec command */
Simon Glassc4b206d2015-02-17 15:29:36 -07001016 debug("Google Chrome EC v%d CROS-EC driver ready, id '%s'\n",
1017 cdev->protocol_version, id);
Simon Glass84d6cbd2014-10-13 23:42:14 -06001018
1019 return 0;
1020}
Hung-ying Tyan88364382013-05-15 18:27:28 +08001021
Simon Glass2ec9d172017-05-18 20:09:23 -06001022int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config)
Simon Glassd7f25f32014-02-27 13:26:03 -07001023{
Simon Glass2ec9d172017-05-18 20:09:23 -06001024 ofnode flash_node, node;
Simon Glassd7f25f32014-02-27 13:26:03 -07001025
Simon Glass2ec9d172017-05-18 20:09:23 -06001026 flash_node = dev_read_subnode(dev, "flash");
1027 if (!ofnode_valid(flash_node)) {
Simon Glassd7f25f32014-02-27 13:26:03 -07001028 debug("Failed to find flash node\n");
1029 return -1;
1030 }
1031
Simon Glass5e0a7342018-06-11 13:07:17 -06001032 if (ofnode_read_fmap_entry(flash_node, &config->flash)) {
Simon Glass2ec9d172017-05-18 20:09:23 -06001033 debug("Failed to decode flash node in chrome-ec\n");
Simon Glassd7f25f32014-02-27 13:26:03 -07001034 return -1;
1035 }
1036
Simon Glass2ec9d172017-05-18 20:09:23 -06001037 config->flash_erase_value = ofnode_read_s32_default(flash_node,
1038 "erase-value", -1);
Simon Glass3991f422017-08-05 15:45:54 -06001039 ofnode_for_each_subnode(node, flash_node) {
Simon Glass2ec9d172017-05-18 20:09:23 -06001040 const char *name = ofnode_get_name(node);
Simon Glassd7f25f32014-02-27 13:26:03 -07001041 enum ec_flash_region region;
1042
1043 if (0 == strcmp(name, "ro")) {
1044 region = EC_FLASH_REGION_RO;
1045 } else if (0 == strcmp(name, "rw")) {
1046 region = EC_FLASH_REGION_RW;
1047 } else if (0 == strcmp(name, "wp-ro")) {
1048 region = EC_FLASH_REGION_WP_RO;
1049 } else {
1050 debug("Unknown EC flash region name '%s'\n", name);
1051 return -1;
1052 }
1053
Simon Glass5e0a7342018-06-11 13:07:17 -06001054 if (ofnode_read_fmap_entry(node, &config->region[region])) {
Simon Glassd7f25f32014-02-27 13:26:03 -07001055 debug("Failed to decode flash region in chrome-ec'\n");
1056 return -1;
1057 }
1058 }
1059
1060 return 0;
1061}
1062
Moritz Fischer6d1a7182016-09-27 15:42:07 -07001063int cros_ec_i2c_tunnel(struct udevice *dev, int port, struct i2c_msg *in,
1064 int nmsgs)
Simon Glasscc456bd2015-08-03 08:19:23 -06001065{
1066 struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
1067 union {
1068 struct ec_params_i2c_passthru p;
1069 uint8_t outbuf[EC_PROTO2_MAX_PARAM_SIZE];
1070 } params;
1071 union {
1072 struct ec_response_i2c_passthru r;
1073 uint8_t inbuf[EC_PROTO2_MAX_PARAM_SIZE];
1074 } response;
1075 struct ec_params_i2c_passthru *p = &params.p;
1076 struct ec_response_i2c_passthru *r = &response.r;
1077 struct ec_params_i2c_passthru_msg *msg;
1078 uint8_t *pdata, *read_ptr = NULL;
1079 int read_len;
1080 int size;
1081 int rv;
1082 int i;
1083
Moritz Fischer6d1a7182016-09-27 15:42:07 -07001084 p->port = port;
Simon Glasscc456bd2015-08-03 08:19:23 -06001085
1086 p->num_msgs = nmsgs;
1087 size = sizeof(*p) + p->num_msgs * sizeof(*msg);
1088
1089 /* Create a message to write the register address and optional data */
1090 pdata = (uint8_t *)p + size;
1091
1092 read_len = 0;
1093 for (i = 0, msg = p->msg; i < nmsgs; i++, msg++, in++) {
1094 bool is_read = in->flags & I2C_M_RD;
1095
1096 msg->addr_flags = in->addr;
1097 msg->len = in->len;
1098 if (is_read) {
1099 msg->addr_flags |= EC_I2C_FLAG_READ;
1100 read_len += in->len;
1101 read_ptr = in->buf;
1102 if (sizeof(*r) + read_len > sizeof(response)) {
1103 puts("Read length too big for buffer\n");
1104 return -1;
1105 }
1106 } else {
1107 if (pdata - (uint8_t *)p + in->len > sizeof(params)) {
1108 puts("Params too large for buffer\n");
1109 return -1;
1110 }
1111 memcpy(pdata, in->buf, in->len);
1112 pdata += in->len;
1113 }
1114 }
1115
1116 rv = ec_command(cdev, EC_CMD_I2C_PASSTHRU, 0, p, pdata - (uint8_t *)p,
1117 r, sizeof(*r) + read_len);
1118 if (rv < 0)
1119 return rv;
1120
1121 /* Parse response */
1122 if (r->i2c_status & EC_I2C_STATUS_ERROR) {
1123 printf("Transfer failed with status=0x%x\n", r->i2c_status);
1124 return -1;
1125 }
1126
1127 if (rv < sizeof(*r) + read_len) {
1128 puts("Truncated read response\n");
1129 return -1;
1130 }
1131
1132 /* We only support a single read message for each transfer */
1133 if (read_len)
1134 memcpy(read_ptr, r->data, read_len);
1135
1136 return 0;
1137}
1138
Simon Glass84d6cbd2014-10-13 23:42:14 -06001139UCLASS_DRIVER(cros_ec) = {
1140 .id = UCLASS_CROS_EC,
1141 .name = "cros_ec",
1142 .per_device_auto_alloc_size = sizeof(struct cros_ec_dev),
Simon Glass91195482016-07-05 17:10:10 -06001143 .post_bind = dm_scan_fdt_dev,
Simon Glass84d6cbd2014-10-13 23:42:14 -06001144};