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 | * |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
David Hendricks | b907de3 | 2014-08-11 16:47:09 -0700 | [diff] [blame] | 18 | #ifndef __CROS_EC_H_ |
| 19 | #define __CROS_EC_H_ |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 20 | |
| 21 | /* 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] | 22 | * instead of including cros_ec_ec_commands.h */ |
David Hendricks | a5c5cf8 | 2014-08-11 16:40:17 -0700 | [diff] [blame] | 23 | #include "cros_ec_commands.h" |
Puthikorn Voravootivat | c0993cf | 2014-08-28 16:04:58 -0700 | [diff] [blame] | 24 | #include "programmer.h" |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 25 | |
David Hendricks | b907de3 | 2014-08-11 16:47:09 -0700 | [diff] [blame] | 26 | struct cros_ec_priv { |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 27 | int detected; |
Simon Glass | 01c1167 | 2013-07-01 18:03:33 +0900 | [diff] [blame] | 28 | enum ec_current_image current_image; |
Simon Glass | c453a64 | 2013-07-01 18:08:53 +0900 | [diff] [blame] | 29 | struct ec_response_flash_region_info *region; |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 30 | int (*ec_command)(int command, int ver, const void *indata, int insize, |
| 31 | void *outdata, int outsize); |
David Hendricks | 14935fe | 2014-08-14 17:38:24 -0700 | [diff] [blame] | 32 | |
| 33 | /* |
Gwendal Grignou | 94e87d6 | 2014-11-25 15:34:15 -0800 | [diff] [blame] | 34 | * 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 Hendricks | 14935fe | 2014-08-14 17:38:24 -0700 | [diff] [blame] | 40 | */ |
Gwendal Grignou | 94e87d6 | 2014-11-25 15:34:15 -0800 | [diff] [blame] | 41 | const char* dev; |
David Hendricks | fbd5e6d | 2014-08-21 15:01:43 -0700 | [diff] [blame] | 42 | |
| 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 Laurie | 8432872 | 2014-09-10 23:25:01 -0700 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Allow block size to be overwritten in case the EC is incorrect. |
| 51 | */ |
| 52 | unsigned int erase_block_size; |
Sam McNally | 6ac63c1 | 2020-10-27 10:12:19 +1100 | [diff] [blame^] | 53 | |
| 54 | /* |
| 55 | * Allow max response size to be overwritten in case the EC is incorrect. |
| 56 | */ |
| 57 | unsigned int max_response_size; |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Souvik Ghosh | 586968a | 2016-08-11 17:56:24 -0700 | [diff] [blame] | 60 | extern struct cros_ec_priv *cros_ec_priv; |
| 61 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 62 | int cros_ec_probe_size(struct flashctx *flash); |
| 63 | int cros_ec_block_erase(struct flashctx *flash, |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 64 | unsigned int blockaddr, unsigned int len); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 65 | int cros_ec_read(struct flashctx *flash, uint8_t *readarr, |
David Hendricks | a915131 | 2013-07-01 12:21:01 -0700 | [diff] [blame] | 66 | unsigned int blockaddr, unsigned int readcnt); |
Patrick Georgi | ab8353e | 2017-02-03 18:32:01 +0100 | [diff] [blame] | 67 | int cros_ec_write(struct flashctx *flash, const 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_ */ |