rmi_bus.h 6.0 KB

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