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