David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 1 | /* |
| 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 Hendricks | b907de3 | 2014-08-11 16:47:09 -0700 | [diff] [blame] | 21 | #ifndef __CROS_EC_H_ |
| 22 | #define __CROS_EC_H_ |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 23 | |
| 24 | /* FIXME: We should be able to forward declare enum ec_current_image here |
David Hendricks | b907de3 | 2014-08-11 16:47:09 -0700 | [diff] [blame] | 25 | * instead of including cros_ec_ec_commands.h */ |
David Hendricks | a5c5cf8 | 2014-08-11 16:40:17 -0700 | [diff] [blame] | 26 | #include "cros_ec_commands.h" |
Puthikorn Voravootivat | c0993cf | 2014-08-28 16:04:58 -0700 | [diff] [blame] | 27 | #include "programmer.h" |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 28 | |
David Hendricks | b907de3 | 2014-08-11 16:47:09 -0700 | [diff] [blame] | 29 | struct cros_ec_priv { |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 30 | int detected; |
Simon Glass | 01c1167 | 2013-07-01 18:03:33 +0900 | [diff] [blame] | 31 | enum ec_current_image current_image; |
Simon Glass | c453a64 | 2013-07-01 18:08:53 +0900 | [diff] [blame] | 32 | struct ec_response_flash_region_info *region; |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 33 | int (*ec_command)(int command, int ver, const void *indata, int insize, |
| 34 | void *outdata, int outsize); |
David Hendricks | 14935fe | 2014-08-14 17:38:24 -0700 | [diff] [blame] | 35 | |
| 36 | /* |
Gwendal Grignou | 94e87d6 | 2014-11-25 15:34:15 -0800 | [diff] [blame^] | 37 | * Latest kernel supports handling of several ECs in the system. |
| 38 | * To use that feature, the proper device file should be used: |
| 39 | * The format is /dev/cros_XX, where XX is the type of device: |
| 40 | * - ec: the main EC |
| 41 | * - pd: the Power Delivery EC |
| 42 | * - sh: the Sensor Hub EC. |
David Hendricks | 14935fe | 2014-08-14 17:38:24 -0700 | [diff] [blame] | 43 | */ |
Gwendal Grignou | 94e87d6 | 2014-11-25 15:34:15 -0800 | [diff] [blame^] | 44 | const char* dev; |
David Hendricks | fbd5e6d | 2014-08-21 15:01:43 -0700 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * Some CrOS ECs support page write mode for their flash memory. This |
| 48 | * represents the ideal size of a data payload to write to flash. |
| 49 | */ |
| 50 | unsigned int ideal_write_size; |
Duncan Laurie | 8432872 | 2014-09-10 23:25:01 -0700 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Allow block size to be overwritten in case the EC is incorrect. |
| 54 | */ |
| 55 | unsigned int erase_block_size; |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
David Hendricks | b907de3 | 2014-08-11 16:47:09 -0700 | [diff] [blame] | 58 | int cros_ec_test(struct cros_ec_priv *priv); |
Puthikorn Voravootivat | c0993cf | 2014-08-28 16:04:58 -0700 | [diff] [blame] | 59 | void cros_ec_set_max_size(struct cros_ec_priv *priv, |
| 60 | struct opaque_programmer *op); |
David Hendricks | 14935fe | 2014-08-14 17:38:24 -0700 | [diff] [blame] | 61 | int cros_ec_parse_param(struct cros_ec_priv *priv); |
David Hendricks | b907de3 | 2014-08-11 16:47:09 -0700 | [diff] [blame] | 62 | int cros_ec_probe_size(struct flashchip *flash); |
| 63 | int cros_ec_block_erase(struct flashchip *flash, |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 64 | unsigned int blockaddr, unsigned int len); |
David Hendricks | b907de3 | 2014-08-11 16:47:09 -0700 | [diff] [blame] | 65 | int cros_ec_read(struct flashchip *flash, uint8_t *readarr, |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 66 | unsigned int blockaddr, unsigned int readcnt); |
David Hendricks | b907de3 | 2014-08-11 16:47:09 -0700 | [diff] [blame] | 67 | int cros_ec_write(struct flashchip *flash, uint8_t *buf, unsigned int addr, |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 68 | unsigned int nbytes); |
| 69 | |
David Hendricks | b907de3 | 2014-08-11 16:47:09 -0700 | [diff] [blame] | 70 | #endif /* __CROS_EC_H_ */ |