2 * Copyright (c) 2011-2016 Synaptics Incorporated
3 * Copyright (c) 2011 Unixphere
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.
13 #include <linux/rmi.h>
18 * The interrupt source count in the function descriptor can represent up to
19 * 6 interrupt sources in the normal manner.
21 #define RMI_FN_MAX_IRQS 6
24 * struct rmi_function - represents the implementation of an RMI4
25 * function for a particular device (basically, a driver for that RMI4 function)
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.
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
35 * @irqs: assigned virq numbers (up to num_of_irqs)
37 * @node: entry in device's list of functions
40 struct rmi_function_descriptor fd
;
41 struct rmi_device
*rmi_dev
;
43 struct list_head node
;
45 unsigned int num_of_irqs
;
46 int irq
[RMI_FN_MAX_IRQS
];
48 unsigned long irq_mask
[];
51 #define to_rmi_function(d) container_of(d, struct rmi_function, dev)
53 bool rmi_is_function_device(struct device
*dev
);
55 int __must_check
rmi_register_function(struct rmi_function
*);
56 void rmi_unregister_function(struct rmi_function
*);
59 * struct rmi_function_handler - driver routines for a particular RMI function.
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
71 * @suspend: Should perform any required operations to suspend the particular
73 * @resume: Should perform any required operations to resume the particular
76 * All callbacks are expected to return 0 on success, error code on failure.
78 struct rmi_function_handler
{
79 struct device_driver driver
;
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
);
92 #define to_rmi_function_handler(d) \
93 container_of(d, struct rmi_function_handler, driver)
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)
100 void rmi_unregister_function_handler(struct rmi_function_handler
*);
102 #define to_rmi_driver(d) \
103 container_of(d, struct rmi_driver, driver)
105 #define to_rmi_device(d) container_of(d, struct rmi_device, dev)
107 static inline struct rmi_device_platform_data
*
108 rmi_get_platform_data(struct rmi_device
*d
)
110 return &d
->xport
->pdata
;
113 bool rmi_is_physical_device(struct device
*dev
);
116 * rmi_reset - reset a RMI4 device
117 * @d: Pointer to an RMI device
119 * Calls for a reset of each function implemented by a specific device.
120 * Returns 0 on success or a negative error code.
122 static inline int rmi_reset(struct rmi_device
*d
)
124 return d
->driver
->reset_handler(d
);
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
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
137 static inline int rmi_read(struct rmi_device
*d
, u16 addr
, u8
*buf
)
139 return d
->xport
->ops
->read_block(d
->xport
, addr
, buf
, 1);
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
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
153 static inline int rmi_read_block(struct rmi_device
*d
, u16 addr
,
154 void *buf
, size_t len
)
156 return d
->xport
->ops
->read_block(d
->xport
, addr
, buf
, len
);
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
165 * Writes a single byte using the underlying transport protocol. It
166 * returns zero on success or a negative error code.
168 static inline int rmi_write(struct rmi_device
*d
, u16 addr
, u8 data
)
170 return d
->xport
->ops
->write_block(d
->xport
, addr
, &data
, 1);
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
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.
183 static inline int rmi_write_block(struct rmi_device
*d
, u16 addr
,
184 const void *buf
, size_t len
)
186 return d
->xport
->ops
->write_block(d
->xport
, addr
, buf
, len
);
189 int rmi_for_each_dev(void *data
, int (*func
)(struct device
*dev
, void *data
));
191 extern struct bus_type rmi_bus_type
;
193 int rmi_of_property_read_u32(struct device
*dev
, u32
*result
,
194 const char *prop
, bool optional
);
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)
201 void rmi_dbg(int flags
, struct device
*dev
, const char *fmt
, ...);