cros_ec_lpc_mec.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * cros_ec_lpc_mec - LPC variant I/O for Microchip EC
  3. *
  4. * Copyright (C) 2016 Google, Inc
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * This driver uses the Chrome OS EC byte-level message-based protocol for
  16. * communicating the keyboard state (which keys are pressed) from a keyboard EC
  17. * to the AP over some bus (such as i2c, lpc, spi). The EC does debouncing,
  18. * but everything else (including deghosting) is done here. The main
  19. * motivation for this is to keep the EC firmware as simple as possible, since
  20. * it cannot be easily upgraded and EC flash/IRAM space is relatively
  21. * expensive.
  22. */
  23. #ifndef __CROS_EC_LPC_MEC_H
  24. #define __CROS_EC_LPC_MEC_H
  25. #include <linux/mfd/cros_ec_commands.h>
  26. enum cros_ec_lpc_mec_emi_access_mode {
  27. /* 8-bit access */
  28. ACCESS_TYPE_BYTE = 0x0,
  29. /* 16-bit access */
  30. ACCESS_TYPE_WORD = 0x1,
  31. /* 32-bit access */
  32. ACCESS_TYPE_LONG = 0x2,
  33. /*
  34. * 32-bit access, read or write of MEC_EMI_EC_DATA_B3 causes the
  35. * EC data register to be incremented.
  36. */
  37. ACCESS_TYPE_LONG_AUTO_INCREMENT = 0x3,
  38. };
  39. enum cros_ec_lpc_mec_io_type {
  40. MEC_IO_READ,
  41. MEC_IO_WRITE,
  42. };
  43. /* Access IO ranges 0x800 thru 0x9ff using EMI interface instead of LPC */
  44. #define MEC_EMI_RANGE_START EC_HOST_CMD_REGION0
  45. #define MEC_EMI_RANGE_END (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE)
  46. /* EMI registers are relative to base */
  47. #define MEC_EMI_BASE 0x800
  48. #define MEC_EMI_HOST_TO_EC (MEC_EMI_BASE + 0)
  49. #define MEC_EMI_EC_TO_HOST (MEC_EMI_BASE + 1)
  50. #define MEC_EMI_EC_ADDRESS_B0 (MEC_EMI_BASE + 2)
  51. #define MEC_EMI_EC_ADDRESS_B1 (MEC_EMI_BASE + 3)
  52. #define MEC_EMI_EC_DATA_B0 (MEC_EMI_BASE + 4)
  53. #define MEC_EMI_EC_DATA_B1 (MEC_EMI_BASE + 5)
  54. #define MEC_EMI_EC_DATA_B2 (MEC_EMI_BASE + 6)
  55. #define MEC_EMI_EC_DATA_B3 (MEC_EMI_BASE + 7)
  56. /*
  57. * cros_ec_lpc_mec_init
  58. *
  59. * Initialize MEC I/O.
  60. */
  61. void cros_ec_lpc_mec_init(void);
  62. /*
  63. * cros_ec_lpc_mec_destroy
  64. *
  65. * Cleanup MEC I/O.
  66. */
  67. void cros_ec_lpc_mec_destroy(void);
  68. /**
  69. * cros_ec_lpc_io_bytes_mec - Read / write bytes to MEC EMI port
  70. *
  71. * @io_type: MEC_IO_READ or MEC_IO_WRITE, depending on request
  72. * @offset: Base read / write address
  73. * @length: Number of bytes to read / write
  74. * @buf: Destination / source buffer
  75. *
  76. * @return 8-bit checksum of all bytes read / written
  77. */
  78. u8 cros_ec_lpc_io_bytes_mec(enum cros_ec_lpc_mec_io_type io_type,
  79. unsigned int offset, unsigned int length, u8 *buf);
  80. #endif /* __CROS_EC_LPC_MEC_H */