rmi_bus.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (c) 2011-2016 Synaptics Incorporated
  3. * Copyright (c) 2011 Unixphere
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. */
  9. #ifndef _RMI_BUS_H
  10. #define _RMI_BUS_H
  11. #include <linux/rmi.h>
  12. struct rmi_device;
  13. /*
  14. * The interrupt source count in the function descriptor can represent up to
  15. * 6 interrupt sources in the normal manner.
  16. */
  17. #define RMI_FN_MAX_IRQS 6
  18. /**
  19. * struct rmi_function - represents the implementation of an RMI4
  20. * function for a particular device (basically, a driver for that RMI4 function)
  21. *
  22. * @fd: The function descriptor of the RMI function
  23. * @rmi_dev: Pointer to the RMI device associated with this function container
  24. * @dev: The device associated with this particular function.
  25. *
  26. * @num_of_irqs: The number of irqs needed by this function
  27. * @irq_pos: The position in the irq bitfield this function holds
  28. * @irq_mask: For convenience, can be used to mask IRQ bits off during ATTN
  29. * interrupt handling.
  30. * @irqs: assigned virq numbers (up to num_of_irqs)
  31. *
  32. * @node: entry in device's list of functions
  33. */
  34. struct rmi_function {
  35. struct rmi_function_descriptor fd;
  36. struct rmi_device *rmi_dev;
  37. struct device dev;
  38. struct list_head node;
  39. unsigned int num_of_irqs;
  40. int irq[RMI_FN_MAX_IRQS];
  41. unsigned int irq_pos;
  42. unsigned long irq_mask[];
  43. };
  44. #define to_rmi_function(d) container_of(d, struct rmi_function, dev)
  45. bool rmi_is_function_device(struct device *dev);
  46. int __must_check rmi_register_function(struct rmi_function *);
  47. void rmi_unregister_function(struct rmi_function *);
  48. /**
  49. * struct rmi_function_handler - driver routines for a particular RMI function.
  50. *
  51. * @func: The RMI function number
  52. * @reset: Called when a reset of the touch sensor is detected. The routine
  53. * should perform any out-of-the-ordinary reset handling that might be
  54. * necessary. Restoring of touch sensor configuration registers should be
  55. * handled in the config() callback, below.
  56. * @config: Called when the function container is first initialized, and
  57. * after a reset is detected. This routine should write any necessary
  58. * configuration settings to the device.
  59. * @attention: Called when the IRQ(s) for the function are set by the touch
  60. * sensor.
  61. * @suspend: Should perform any required operations to suspend the particular
  62. * function.
  63. * @resume: Should perform any required operations to resume the particular
  64. * function.
  65. *
  66. * All callbacks are expected to return 0 on success, error code on failure.
  67. */
  68. struct rmi_function_handler {
  69. struct device_driver driver;
  70. u8 func;
  71. int (*probe)(struct rmi_function *fn);
  72. void (*remove)(struct rmi_function *fn);
  73. int (*config)(struct rmi_function *fn);
  74. int (*reset)(struct rmi_function *fn);
  75. irqreturn_t (*attention)(int irq, void *ctx);
  76. int (*suspend)(struct rmi_function *fn);
  77. int (*resume)(struct rmi_function *fn);
  78. };
  79. #define to_rmi_function_handler(d) \
  80. container_of(d, struct rmi_function_handler, driver)
  81. int __must_check __rmi_register_function_handler(struct rmi_function_handler *,
  82. struct module *, const char *);
  83. #define rmi_register_function_handler(handler) \
  84. __rmi_register_function_handler(handler, THIS_MODULE, KBUILD_MODNAME)
  85. void rmi_unregister_function_handler(struct rmi_function_handler *);
  86. #define to_rmi_driver(d) \
  87. container_of(d, struct rmi_driver, driver)
  88. #define to_rmi_device(d) container_of(d, struct rmi_device, dev)
  89. static inline struct rmi_device_platform_data *
  90. rmi_get_platform_data(struct rmi_device *d)
  91. {
  92. return &d->xport->pdata;
  93. }
  94. bool rmi_is_physical_device(struct device *dev);
  95. /**
  96. * rmi_reset - reset a RMI4 device
  97. * @d: Pointer to an RMI device
  98. *
  99. * Calls for a reset of each function implemented by a specific device.
  100. * Returns 0 on success or a negative error code.
  101. */
  102. static inline int rmi_reset(struct rmi_device *d)
  103. {
  104. return d->driver->reset_handler(d);
  105. }
  106. /**
  107. * rmi_read - read a single byte
  108. * @d: Pointer to an RMI device
  109. * @addr: The address to read from
  110. * @buf: The read buffer
  111. *
  112. * Reads a single byte of data using the underlying transport protocol
  113. * into memory pointed by @buf. It returns 0 on success or a negative
  114. * error code.
  115. */
  116. static inline int rmi_read(struct rmi_device *d, u16 addr, u8 *buf)
  117. {
  118. return d->xport->ops->read_block(d->xport, addr, buf, 1);
  119. }
  120. /**
  121. * rmi_read_block - read a block of bytes
  122. * @d: Pointer to an RMI device
  123. * @addr: The start address to read from
  124. * @buf: The read buffer
  125. * @len: Length of the read buffer
  126. *
  127. * Reads a block of byte data using the underlying transport protocol
  128. * into memory pointed by @buf. It returns 0 on success or a negative
  129. * error code.
  130. */
  131. static inline int rmi_read_block(struct rmi_device *d, u16 addr,
  132. void *buf, size_t len)
  133. {
  134. return d->xport->ops->read_block(d->xport, addr, buf, len);
  135. }
  136. /**
  137. * rmi_write - write a single byte
  138. * @d: Pointer to an RMI device
  139. * @addr: The address to write to
  140. * @data: The data to write
  141. *
  142. * Writes a single byte using the underlying transport protocol. It
  143. * returns zero on success or a negative error code.
  144. */
  145. static inline int rmi_write(struct rmi_device *d, u16 addr, u8 data)
  146. {
  147. return d->xport->ops->write_block(d->xport, addr, &data, 1);
  148. }
  149. /**
  150. * rmi_write_block - write a block of bytes
  151. * @d: Pointer to an RMI device
  152. * @addr: The start address to write to
  153. * @buf: The write buffer
  154. * @len: Length of the write buffer
  155. *
  156. * Writes a block of byte data from buf using the underlaying transport
  157. * protocol. It returns the amount of bytes written or a negative error code.
  158. */
  159. static inline int rmi_write_block(struct rmi_device *d, u16 addr,
  160. const void *buf, size_t len)
  161. {
  162. return d->xport->ops->write_block(d->xport, addr, buf, len);
  163. }
  164. int rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data));
  165. extern struct bus_type rmi_bus_type;
  166. int rmi_of_property_read_u32(struct device *dev, u32 *result,
  167. const char *prop, bool optional);
  168. #define RMI_DEBUG_CORE BIT(0)
  169. #define RMI_DEBUG_XPORT BIT(1)
  170. #define RMI_DEBUG_FN BIT(2)
  171. #define RMI_DEBUG_2D_SENSOR BIT(3)
  172. void rmi_dbg(int flags, struct device *dev, const char *fmt, ...);
  173. #endif