1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2011-2016 Synaptics Incorporated
4 * Copyright (c) 2011 Unixphere
10 #include <linux/rmi.h>
15 * The interrupt source count in the function descriptor can represent up to
16 * 6 interrupt sources in the normal manner.
18 #define RMI_FN_MAX_IRQS 6
21 * struct rmi_function - represents the implementation of an RMI4
22 * function for a particular device (basically, a driver for that RMI4 function)
24 * @fd: The function descriptor of the RMI function
25 * @rmi_dev: Pointer to the RMI device associated with this function container
26 * @dev: The device associated with this particular function.
28 * @num_of_irqs: The number of irqs needed by this function
29 * @irq_pos: The position in the irq bitfield this function holds
30 * @irq_mask: For convenience, can be used to mask IRQ bits off during ATTN
32 * @irqs: assigned virq numbers (up to num_of_irqs)
34 * @node: entry in device's list of functions
37 struct rmi_function_descriptor fd
;
38 struct rmi_device
*rmi_dev
;
40 struct list_head node
;
42 unsigned int num_of_irqs
;
43 int irq
[RMI_FN_MAX_IRQS
];
45 unsigned long irq_mask
[];
48 #define to_rmi_function(d) container_of(d, struct rmi_function, dev)
50 bool rmi_is_function_device(struct device
*dev
);
52 int __must_check
rmi_register_function(struct rmi_function
*);
53 void rmi_unregister_function(struct rmi_function
*);
56 * struct rmi_function_handler - driver routines for a particular RMI function.
58 * @func: The RMI function number
59 * @reset: Called when a reset of the touch sensor is detected. The routine
60 * should perform any out-of-the-ordinary reset handling that might be
61 * necessary. Restoring of touch sensor configuration registers should be
62 * handled in the config() callback, below.
63 * @config: Called when the function container is first initialized, and
64 * after a reset is detected. This routine should write any necessary
65 * configuration settings to the device.
66 * @attention: Called when the IRQ(s) for the function are set by the touch
68 * @suspend: Should perform any required operations to suspend the particular
70 * @resume: Should perform any required operations to resume the particular
73 * All callbacks are expected to return 0 on success, error code on failure.
75 struct rmi_function_handler
{
76 struct device_driver driver
;
80 int (*probe
)(struct rmi_function
*fn
);
81 void (*remove
)(struct rmi_function
*fn
);
82 int (*config
)(struct rmi_function
*fn
);
83 int (*reset
)(struct rmi_function
*fn
);
84 irqreturn_t (*attention
)(int irq
, void *ctx
);
85 int (*suspend
)(struct rmi_function
*fn
);
86 int (*resume
)(struct rmi_function
*fn
);
89 #define to_rmi_function_handler(d) \
90 container_of(d, struct rmi_function_handler, driver)
92 int __must_check
__rmi_register_function_handler(struct rmi_function_handler
*,
93 struct module
*, const char *);
94 #define rmi_register_function_handler(handler) \
95 __rmi_register_function_handler(handler, THIS_MODULE, KBUILD_MODNAME)
97 void rmi_unregister_function_handler(struct rmi_function_handler
*);
99 #define to_rmi_driver(d) \
100 container_of(d, struct rmi_driver, driver)
102 #define to_rmi_device(d) container_of(d, struct rmi_device, dev)
104 static inline struct rmi_device_platform_data
*
105 rmi_get_platform_data(struct rmi_device
*d
)
107 return &d
->xport
->pdata
;
110 bool rmi_is_physical_device(struct device
*dev
);
113 * rmi_reset - reset a RMI4 device
114 * @d: Pointer to an RMI device
116 * Calls for a reset of each function implemented by a specific device.
117 * Returns 0 on success or a negative error code.
119 static inline int rmi_reset(struct rmi_device
*d
)
121 return d
->driver
->reset_handler(d
);
125 * rmi_read - read a single byte
126 * @d: Pointer to an RMI device
127 * @addr: The address to read from
128 * @buf: The read buffer
130 * Reads a single byte of data using the underlying transport protocol
131 * into memory pointed by @buf. It returns 0 on success or a negative
134 static inline int rmi_read(struct rmi_device
*d
, u16 addr
, u8
*buf
)
136 return d
->xport
->ops
->read_block(d
->xport
, addr
, buf
, 1);
140 * rmi_read_block - read a block of bytes
141 * @d: Pointer to an RMI device
142 * @addr: The start address to read from
143 * @buf: The read buffer
144 * @len: Length of the read buffer
146 * Reads a block of byte data using the underlying transport protocol
147 * into memory pointed by @buf. It returns 0 on success or a negative
150 static inline int rmi_read_block(struct rmi_device
*d
, u16 addr
,
151 void *buf
, size_t len
)
153 return d
->xport
->ops
->read_block(d
->xport
, addr
, buf
, len
);
157 * rmi_write - write a single byte
158 * @d: Pointer to an RMI device
159 * @addr: The address to write to
160 * @data: The data to write
162 * Writes a single byte using the underlying transport protocol. It
163 * returns zero on success or a negative error code.
165 static inline int rmi_write(struct rmi_device
*d
, u16 addr
, u8 data
)
167 return d
->xport
->ops
->write_block(d
->xport
, addr
, &data
, 1);
171 * rmi_write_block - write a block of bytes
172 * @d: Pointer to an RMI device
173 * @addr: The start address to write to
174 * @buf: The write buffer
175 * @len: Length of the write buffer
177 * Writes a block of byte data from buf using the underlaying transport
178 * protocol. It returns the amount of bytes written or a negative error code.
180 static inline int rmi_write_block(struct rmi_device
*d
, u16 addr
,
181 const void *buf
, size_t len
)
183 return d
->xport
->ops
->write_block(d
->xport
, addr
, buf
, len
);
186 int rmi_for_each_dev(void *data
, int (*func
)(struct device
*dev
, void *data
));
188 extern struct bus_type rmi_bus_type
;
190 int rmi_of_property_read_u32(struct device
*dev
, u32
*result
,
191 const char *prop
, bool optional
);
193 #define RMI_DEBUG_CORE BIT(0)
194 #define RMI_DEBUG_XPORT BIT(1)
195 #define RMI_DEBUG_FN BIT(2)
196 #define RMI_DEBUG_2D_SENSOR BIT(3)
198 void rmi_dbg(int flags
, struct device
*dev
, const char *fmt
, ...);