cros_ec.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * ChromeOS EC multi-function device
  3. *
  4. * Copyright (C) 2012 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. #ifndef __LINUX_MFD_CROS_EC_H
  16. #define __LINUX_MFD_CROS_EC_H
  17. #include <linux/mfd/cros_ec_commands.h>
  18. /*
  19. * Command interface between EC and AP, for LPC, I2C and SPI interfaces.
  20. */
  21. enum {
  22. EC_MSG_TX_HEADER_BYTES = 3,
  23. EC_MSG_TX_TRAILER_BYTES = 1,
  24. EC_MSG_TX_PROTO_BYTES = EC_MSG_TX_HEADER_BYTES +
  25. EC_MSG_TX_TRAILER_BYTES,
  26. EC_MSG_RX_PROTO_BYTES = 3,
  27. /* Max length of messages */
  28. EC_MSG_BYTES = EC_HOST_PARAM_SIZE + EC_MSG_TX_PROTO_BYTES,
  29. };
  30. /**
  31. * struct cros_ec_msg - A message sent to the EC, and its reply
  32. *
  33. * @version: Command version number (often 0)
  34. * @cmd: Command to send (EC_CMD_...)
  35. * @out_buf: Outgoing payload (to EC)
  36. * @outlen: Outgoing length
  37. * @in_buf: Incoming payload (from EC)
  38. * @in_len: Incoming length
  39. */
  40. struct cros_ec_msg {
  41. u8 version;
  42. u8 cmd;
  43. uint8_t *out_buf;
  44. int out_len;
  45. uint8_t *in_buf;
  46. int in_len;
  47. };
  48. /**
  49. * struct cros_ec_device - Information about a ChromeOS EC device
  50. *
  51. * @name: Name of this EC interface
  52. * @priv: Private data
  53. * @irq: Interrupt to use
  54. * @din: input buffer (from EC)
  55. * @dout: output buffer (to EC)
  56. * \note
  57. * These two buffers will always be dword-aligned and include enough
  58. * space for up to 7 word-alignment bytes also, so we can ensure that
  59. * the body of the message is always dword-aligned (64-bit).
  60. *
  61. * We use this alignment to keep ARM and x86 happy. Probably word
  62. * alignment would be OK, there might be a small performance advantage
  63. * to using dword.
  64. * @din_size: size of din buffer
  65. * @dout_size: size of dout buffer
  66. * @command_send: send a command
  67. * @command_recv: receive a command
  68. * @ec_name: name of EC device (e.g. 'chromeos-ec')
  69. * @phys_name: name of physical comms layer (e.g. 'i2c-4')
  70. * @parent: pointer to parent device (e.g. i2c or spi device)
  71. * @dev: Device pointer
  72. * dev_lock: Lock to prevent concurrent access
  73. * @wake_enabled: true if this device can wake the system from sleep
  74. * @was_wake_device: true if this device was set to wake the system from
  75. * sleep at the last suspend
  76. * @event_notifier: interrupt event notifier for transport devices
  77. */
  78. struct cros_ec_device {
  79. const char *name;
  80. void *priv;
  81. int irq;
  82. uint8_t *din;
  83. uint8_t *dout;
  84. int din_size;
  85. int dout_size;
  86. int (*command_send)(struct cros_ec_device *ec,
  87. uint16_t cmd, void *out_buf, int out_len);
  88. int (*command_recv)(struct cros_ec_device *ec,
  89. uint16_t cmd, void *in_buf, int in_len);
  90. int (*command_sendrecv)(struct cros_ec_device *ec,
  91. uint16_t cmd, void *out_buf, int out_len,
  92. void *in_buf, int in_len);
  93. int (*command_xfer)(struct cros_ec_device *ec,
  94. struct cros_ec_msg *msg);
  95. const char *ec_name;
  96. const char *phys_name;
  97. struct device *parent;
  98. /* These are --private-- fields - do not assign */
  99. struct device *dev;
  100. struct mutex dev_lock;
  101. bool wake_enabled;
  102. bool was_wake_device;
  103. struct blocking_notifier_head event_notifier;
  104. };
  105. /**
  106. * cros_ec_suspend - Handle a suspend operation for the ChromeOS EC device
  107. *
  108. * This can be called by drivers to handle a suspend event.
  109. *
  110. * ec_dev: Device to suspend
  111. * @return 0 if ok, -ve on error
  112. */
  113. int cros_ec_suspend(struct cros_ec_device *ec_dev);
  114. /**
  115. * cros_ec_resume - Handle a resume operation for the ChromeOS EC device
  116. *
  117. * This can be called by drivers to handle a resume event.
  118. *
  119. * @ec_dev: Device to resume
  120. * @return 0 if ok, -ve on error
  121. */
  122. int cros_ec_resume(struct cros_ec_device *ec_dev);
  123. /**
  124. * cros_ec_prepare_tx - Prepare an outgoing message in the output buffer
  125. *
  126. * This is intended to be used by all ChromeOS EC drivers, but at present
  127. * only SPI uses it. Once LPC uses the same protocol it can start using it.
  128. * I2C could use it now, with a refactor of the existing code.
  129. *
  130. * @ec_dev: Device to register
  131. * @msg: Message to write
  132. */
  133. int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
  134. struct cros_ec_msg *msg);
  135. /**
  136. * cros_ec_remove - Remove a ChromeOS EC
  137. *
  138. * Call this to deregister a ChromeOS EC. After this you should call
  139. * cros_ec_free().
  140. *
  141. * @ec_dev: Device to register
  142. * @return 0 if ok, -ve on error
  143. */
  144. int cros_ec_remove(struct cros_ec_device *ec_dev);
  145. /**
  146. * cros_ec_register - Register a new ChromeOS EC, using the provided info
  147. *
  148. * Before calling this, allocate a pointer to a new device and then fill
  149. * in all the fields up to the --private-- marker.
  150. *
  151. * @ec_dev: Device to register
  152. * @return 0 if ok, -ve on error
  153. */
  154. int cros_ec_register(struct cros_ec_device *ec_dev);
  155. #endif /* __LINUX_MFD_CROS_EC_H */