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