blob: 9daf2fd406ce85ce9f7093e6cc38aff0078c058d [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 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
David Hendricksb907de32014-08-11 16:47:09 -070021#ifndef __CROS_EC_H_
22#define __CROS_EC_H_
David Hendricksa9151312013-07-01 12:21:01 -070023
24/* FIXME: We should be able to forward declare enum ec_current_image here
David Hendricksb907de32014-08-11 16:47:09 -070025 * instead of including cros_ec_ec_commands.h */
David Hendricksa5c5cf82014-08-11 16:40:17 -070026#include "cros_ec_commands.h"
Puthikorn Voravootivatc0993cf2014-08-28 16:04:58 -070027#include "programmer.h"
David Hendricksa9151312013-07-01 12:21:01 -070028
David Hendricksb907de32014-08-11 16:47:09 -070029struct cros_ec_priv {
David Hendricksa9151312013-07-01 12:21:01 -070030 int detected;
Simon Glass01c11672013-07-01 18:03:33 +090031 enum ec_current_image current_image;
Simon Glassc453a642013-07-01 18:08:53 +090032 struct ec_response_flash_region_info *region;
David Hendricksa9151312013-07-01 12:21:01 -070033 int (*ec_command)(int command, int ver, const void *indata, int insize,
34 void *outdata, int outsize);
David Hendricks14935fe2014-08-14 17:38:24 -070035
36 /*
37 * Starting in version 3.0, the EC can act as a bridge to pass along
38 * messages from the host to up to 3 attached devices (device 0 is the
39 * EC itself) which also use the CrOS EC protocol. The devices can be
40 * attached to any bus on the EC and the EC will abstract bus details.
41 * Bits 14 and 15 in the command word indicate the device index.
42 */
43 unsigned int dev_index;
David Hendricksfbd5e6d2014-08-21 15:01:43 -070044
45 /*
46 * Some CrOS ECs support page write mode for their flash memory. This
47 * represents the ideal size of a data payload to write to flash.
48 */
49 unsigned int ideal_write_size;
David Hendricksa9151312013-07-01 12:21:01 -070050};
51
David Hendricksb907de32014-08-11 16:47:09 -070052int cros_ec_test(struct cros_ec_priv *priv);
Puthikorn Voravootivatc0993cf2014-08-28 16:04:58 -070053void cros_ec_set_max_size(struct cros_ec_priv *priv,
54 struct opaque_programmer *op);
David Hendricks14935fe2014-08-14 17:38:24 -070055int cros_ec_parse_param(struct cros_ec_priv *priv);
David Hendricksb907de32014-08-11 16:47:09 -070056int cros_ec_probe_size(struct flashchip *flash);
57int cros_ec_block_erase(struct flashchip *flash,
David Hendricksa9151312013-07-01 12:21:01 -070058 unsigned int blockaddr, unsigned int len);
David Hendricksb907de32014-08-11 16:47:09 -070059int cros_ec_read(struct flashchip *flash, uint8_t *readarr,
David Hendricksa9151312013-07-01 12:21:01 -070060 unsigned int blockaddr, unsigned int readcnt);
David Hendricksb907de32014-08-11 16:47:09 -070061int cros_ec_write(struct flashchip *flash, uint8_t *buf, unsigned int addr,
David Hendricksa9151312013-07-01 12:21:01 -070062 unsigned int nbytes);
63
David Hendricksb907de32014-08-11 16:47:09 -070064#endif /* __CROS_EC_H_ */