cros_ec.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifndef __CROS_EC_H_
  21. #define __CROS_EC_H_
  22. /* FIXME: We should be able to forward declare enum ec_current_image here
  23. * instead of including cros_ec_ec_commands.h */
  24. #include "cros_ec_commands.h"
  25. #include "programmer.h"
  26. struct cros_ec_priv {
  27. int detected;
  28. enum ec_current_image current_image;
  29. struct ec_response_flash_region_info *region;
  30. int (*ec_command)(int command, int ver, const void *indata, int insize,
  31. void *outdata, int outsize);
  32. /*
  33. * Latest kernel supports handling of several ECs in the system.
  34. * To use that feature, the proper device file should be used:
  35. * The format is /dev/cros_XX, where XX is the type of device:
  36. * - ec: the main EC
  37. * - pd: the Power Delivery EC
  38. * - sh: the Sensor Hub EC.
  39. */
  40. const char* dev;
  41. /*
  42. * Some CrOS ECs support page write mode for their flash memory. This
  43. * represents the ideal size of a data payload to write to flash.
  44. */
  45. unsigned int ideal_write_size;
  46. /*
  47. * Allow block size to be overwritten in case the EC is incorrect.
  48. */
  49. unsigned int erase_block_size;
  50. };
  51. extern struct cros_ec_priv *cros_ec_priv;
  52. int cros_ec_test(struct cros_ec_priv *priv);
  53. void cros_ec_set_max_size(struct cros_ec_priv *priv,
  54. struct opaque_programmer *op);
  55. int cros_ec_parse_param(struct cros_ec_priv *priv);
  56. int cros_ec_probe_size(struct flashctx *flash);
  57. int cros_ec_block_erase(struct flashctx *flash,
  58. unsigned int blockaddr, unsigned int len);
  59. int cros_ec_read(struct flashctx *flash, uint8_t *readarr,
  60. unsigned int blockaddr, unsigned int readcnt);
  61. int cros_ec_write(struct flashctx *flash, uint8_t *buf, unsigned int addr,
  62. unsigned int nbytes);
  63. #endif /* __CROS_EC_H_ */