blob: d9f68e95c53103bbe1e6625eea20894b280fc497 [file] [log] [blame]
David Hendricksa9151312013-07-01 12:21:01 -07001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright 2013 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
David Hendricksa9151312013-07-01 12:21:01 -070016 */
17
David Hendricksb907de32014-08-11 16:47:09 -070018#ifndef __CROS_EC_H_
19#define __CROS_EC_H_
David Hendricksa9151312013-07-01 12:21:01 -070020
21/* FIXME: We should be able to forward declare enum ec_current_image here
David Hendricksb907de32014-08-11 16:47:09 -070022 * instead of including cros_ec_ec_commands.h */
David Hendricksa5c5cf82014-08-11 16:40:17 -070023#include "cros_ec_commands.h"
Puthikorn Voravootivatc0993cf2014-08-28 16:04:58 -070024#include "programmer.h"
David Hendricksa9151312013-07-01 12:21:01 -070025
David Hendricksb907de32014-08-11 16:47:09 -070026struct cros_ec_priv {
David Hendricksa9151312013-07-01 12:21:01 -070027 int detected;
Simon Glass01c11672013-07-01 18:03:33 +090028 enum ec_current_image current_image;
Simon Glassc453a642013-07-01 18:08:53 +090029 struct ec_response_flash_region_info *region;
David Hendricksa9151312013-07-01 12:21:01 -070030 int (*ec_command)(int command, int ver, const void *indata, int insize,
31 void *outdata, int outsize);
David Hendricks14935fe2014-08-14 17:38:24 -070032
33 /*
Gwendal Grignou94e87d62014-11-25 15:34:15 -080034 * Latest kernel supports handling of several ECs in the system.
35 * To use that feature, the proper device file should be used:
36 * The format is /dev/cros_XX, where XX is the type of device:
37 * - ec: the main EC
38 * - pd: the Power Delivery EC
39 * - sh: the Sensor Hub EC.
David Hendricks14935fe2014-08-14 17:38:24 -070040 */
Gwendal Grignou94e87d62014-11-25 15:34:15 -080041 const char* dev;
David Hendricksfbd5e6d2014-08-21 15:01:43 -070042
43 /*
44 * Some CrOS ECs support page write mode for their flash memory. This
45 * represents the ideal size of a data payload to write to flash.
46 */
47 unsigned int ideal_write_size;
Duncan Laurie84328722014-09-10 23:25:01 -070048
49 /*
50 * Allow block size to be overwritten in case the EC is incorrect.
51 */
52 unsigned int erase_block_size;
Sam McNally6ac63c12020-10-27 10:12:19 +110053
54 /*
55 * Allow max response size to be overwritten in case the EC is incorrect.
56 */
57 unsigned int max_response_size;
David Hendricksa9151312013-07-01 12:21:01 -070058};
59
Souvik Ghosh586968a2016-08-11 17:56:24 -070060extern struct cros_ec_priv *cros_ec_priv;
61
Souvik Ghoshd75cd672016-06-17 14:21:39 -070062int cros_ec_probe_size(struct flashctx *flash);
63int cros_ec_block_erase(struct flashctx *flash,
David Hendricksa9151312013-07-01 12:21:01 -070064 unsigned int blockaddr, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -070065int cros_ec_read(struct flashctx *flash, uint8_t *readarr,
David Hendricksa9151312013-07-01 12:21:01 -070066 unsigned int blockaddr, unsigned int readcnt);
Patrick Georgiab8353e2017-02-03 18:32:01 +010067int cros_ec_write(struct flashctx *flash, const uint8_t *buf, unsigned int addr,
David Hendricksa9151312013-07-01 12:21:01 -070068 unsigned int nbytes);
69
David Hendricksb907de32014-08-11 16:47:09 -070070#endif /* __CROS_EC_H_ */