Loading...
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (c) 2011-2016 Synaptics Incorporated
4 * Copyright (c) 2011 Unixphere
5 */
6
7#ifndef _RMI_BUS_H
8#define _RMI_BUS_H
9
10#include <linux/rmi.h>
11
12struct rmi_device;
13
14/*
15 * The interrupt source count in the function descriptor can represent up to
16 * 6 interrupt sources in the normal manner.
17 */
18#define RMI_FN_MAX_IRQS 6
19
20/**
21 * struct rmi_function - represents the implementation of an RMI4
22 * function for a particular device (basically, a driver for that RMI4 function)
23 *
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.
27 *
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
31 * interrupt handling.
32 * @irqs: assigned virq numbers (up to num_of_irqs)
33 *
34 * @node: entry in device's list of functions
35 */
36struct rmi_function {
37 struct rmi_function_descriptor fd;
38 struct rmi_device *rmi_dev;
39 struct device dev;
40 struct list_head node;
41
42 unsigned int num_of_irqs;
43 int irq[RMI_FN_MAX_IRQS];
44 unsigned int irq_pos;
45 unsigned long irq_mask[];
46};
47
48#define to_rmi_function(d) container_of(d, struct rmi_function, dev)
49
50bool rmi_is_function_device(struct device *dev);
51
52int __must_check rmi_register_function(struct rmi_function *);
53void rmi_unregister_function(struct rmi_function *);
54
55/**
56 * struct rmi_function_handler - driver routines for a particular RMI function.
57 *
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
67 * sensor.
68 * @suspend: Should perform any required operations to suspend the particular
69 * function.
70 * @resume: Should perform any required operations to resume the particular
71 * function.
72 *
73 * All callbacks are expected to return 0 on success, error code on failure.
74 */
75struct rmi_function_handler {
76 struct device_driver driver;
77
78 u8 func;
79
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);
87};
88
89#define to_rmi_function_handler(d) \
90 container_of(d, struct rmi_function_handler, driver)
91
92int __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)
96
97void rmi_unregister_function_handler(struct rmi_function_handler *);
98
99#define to_rmi_driver(d) \
100 container_of(d, struct rmi_driver, driver)
101
102#define to_rmi_device(d) container_of(d, struct rmi_device, dev)
103
104static inline struct rmi_device_platform_data *
105rmi_get_platform_data(struct rmi_device *d)
106{
107 return &d->xport->pdata;
108}
109
110bool rmi_is_physical_device(struct device *dev);
111
112/**
113 * rmi_reset - reset a RMI4 device
114 * @d: Pointer to an RMI device
115 *
116 * Calls for a reset of each function implemented by a specific device.
117 * Returns 0 on success or a negative error code.
118 */
119static inline int rmi_reset(struct rmi_device *d)
120{
121 return d->driver->reset_handler(d);
122}
123
124/**
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
129 *
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
132 * error code.
133 */
134static inline int rmi_read(struct rmi_device *d, u16 addr, u8 *buf)
135{
136 return d->xport->ops->read_block(d->xport, addr, buf, 1);
137}
138
139/**
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
145 *
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
148 * error code.
149 */
150static inline int rmi_read_block(struct rmi_device *d, u16 addr,
151 void *buf, size_t len)
152{
153 return d->xport->ops->read_block(d->xport, addr, buf, len);
154}
155
156/**
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
161 *
162 * Writes a single byte using the underlying transport protocol. It
163 * returns zero on success or a negative error code.
164 */
165static inline int rmi_write(struct rmi_device *d, u16 addr, u8 data)
166{
167 return d->xport->ops->write_block(d->xport, addr, &data, 1);
168}
169
170/**
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
176 *
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.
179 */
180static inline int rmi_write_block(struct rmi_device *d, u16 addr,
181 const void *buf, size_t len)
182{
183 return d->xport->ops->write_block(d->xport, addr, buf, len);
184}
185
186int rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data));
187
188extern struct bus_type rmi_bus_type;
189
190int rmi_of_property_read_u32(struct device *dev, u32 *result,
191 const char *prop, bool optional);
192
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)
197
198void rmi_dbg(int flags, struct device *dev, const char *fmt, ...);
199#endif
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
15struct 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 */
32struct 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
45bool rmi_is_function_device(struct device *dev);
46
47int __must_check rmi_register_function(struct rmi_function *);
48void 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 */
70struct 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
87int __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
92void 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
99static inline struct rmi_device_platform_data *
100rmi_get_platform_data(struct rmi_device *d)
101{
102 return &d->xport->pdata;
103}
104
105bool rmi_is_physical_device(struct device *dev);
106
107/**
108 * rmi_read - read a single byte
109 * @d: Pointer to an RMI device
110 * @addr: The address to read from
111 * @buf: The read buffer
112 *
113 * Reads a single byte of data using the underlying transport protocol
114 * into memory pointed by @buf. It returns 0 on success or a negative
115 * error code.
116 */
117static inline int rmi_read(struct rmi_device *d, u16 addr, u8 *buf)
118{
119 return d->xport->ops->read_block(d->xport, addr, buf, 1);
120}
121
122/**
123 * rmi_read_block - read a block of bytes
124 * @d: Pointer to an RMI device
125 * @addr: The start address to read from
126 * @buf: The read buffer
127 * @len: Length of the read buffer
128 *
129 * Reads a block of byte data using the underlying transport protocol
130 * into memory pointed by @buf. It returns 0 on success or a negative
131 * error code.
132 */
133static inline int rmi_read_block(struct rmi_device *d, u16 addr,
134 void *buf, size_t len)
135{
136 return d->xport->ops->read_block(d->xport, addr, buf, len);
137}
138
139/**
140 * rmi_write - write a single byte
141 * @d: Pointer to an RMI device
142 * @addr: The address to write to
143 * @data: The data to write
144 *
145 * Writes a single byte using the underlying transport protocol. It
146 * returns zero on success or a negative error code.
147 */
148static inline int rmi_write(struct rmi_device *d, u16 addr, u8 data)
149{
150 return d->xport->ops->write_block(d->xport, addr, &data, 1);
151}
152
153/**
154 * rmi_write_block - write a block of bytes
155 * @d: Pointer to an RMI device
156 * @addr: The start address to write to
157 * @buf: The write buffer
158 * @len: Length of the write buffer
159 *
160 * Writes a block of byte data from buf using the underlaying transport
161 * protocol. It returns the amount of bytes written or a negative error code.
162 */
163static inline int rmi_write_block(struct rmi_device *d, u16 addr,
164 const void *buf, size_t len)
165{
166 return d->xport->ops->write_block(d->xport, addr, buf, len);
167}
168
169int rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data));
170
171extern struct bus_type rmi_bus_type;
172
173int rmi_of_property_read_u32(struct device *dev, u32 *result,
174 const char *prop, bool optional);
175
176#define RMI_DEBUG_CORE BIT(0)
177#define RMI_DEBUG_XPORT BIT(1)
178#define RMI_DEBUG_FN BIT(2)
179#define RMI_DEBUG_2D_SENSOR BIT(3)
180
181void rmi_dbg(int flags, struct device *dev, const char *fmt, ...);
182#endif