rmi_bus.h 5.6 KB

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