Skip to content

Commit 24d28e4

Browse files
ndyerdtor
authored andcommitted
Input: synaptics-rmi4 - convert irq distribution to irq_domain
Convert the RMI driver to use the standard mechanism for distributing IRQs to the various functions. Tested on: * S7300 (F11, F34, F54) * S7817 (F12, F34, F54) Signed-off-by: Nick Dyer <[email protected]> Acked-by: Christopher Heiny <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 8f6a652 commit 24d28e4

File tree

12 files changed

+119
-85
lines changed

12 files changed

+119
-85
lines changed

drivers/input/rmi4/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44
config RMI4_CORE
55
tristate "Synaptics RMI4 bus support"
6+
select IRQ_DOMAIN
67
help
78
Say Y here if you want to support the Synaptics RMI4 bus. This is
89
required for all RMI4 device support.

drivers/input/rmi4/rmi_bus.c

+49-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <linux/kernel.h>
1111
#include <linux/device.h>
12+
#include <linux/irq.h>
13+
#include <linux/irqdomain.h>
1214
#include <linux/list.h>
1315
#include <linux/pm.h>
1416
#include <linux/rmi.h>
@@ -167,6 +169,39 @@ static inline void rmi_function_of_probe(struct rmi_function *fn)
167169
{}
168170
#endif
169171

172+
static struct irq_chip rmi_irq_chip = {
173+
.name = "rmi4",
174+
};
175+
176+
static int rmi_create_function_irq(struct rmi_function *fn,
177+
struct rmi_function_handler *handler)
178+
{
179+
struct rmi_driver_data *drvdata = dev_get_drvdata(&fn->rmi_dev->dev);
180+
int i, error;
181+
182+
for (i = 0; i < fn->num_of_irqs; i++) {
183+
set_bit(fn->irq_pos + i, fn->irq_mask);
184+
185+
fn->irq[i] = irq_create_mapping(drvdata->irqdomain,
186+
fn->irq_pos + i);
187+
188+
irq_set_chip_data(fn->irq[i], fn);
189+
irq_set_chip_and_handler(fn->irq[i], &rmi_irq_chip,
190+
handle_simple_irq);
191+
irq_set_nested_thread(fn->irq[i], 1);
192+
193+
error = devm_request_threaded_irq(&fn->dev, fn->irq[i], NULL,
194+
handler->attention, IRQF_ONESHOT,
195+
dev_name(&fn->dev), fn);
196+
if (error) {
197+
dev_err(&fn->dev, "Error %d registering IRQ\n", error);
198+
return error;
199+
}
200+
}
201+
202+
return 0;
203+
}
204+
170205
static int rmi_function_probe(struct device *dev)
171206
{
172207
struct rmi_function *fn = to_rmi_function(dev);
@@ -178,7 +213,14 @@ static int rmi_function_probe(struct device *dev)
178213

179214
if (handler->probe) {
180215
error = handler->probe(fn);
181-
return error;
216+
if (error)
217+
return error;
218+
}
219+
220+
if (fn->num_of_irqs && handler->attention) {
221+
error = rmi_create_function_irq(fn, handler);
222+
if (error)
223+
return error;
182224
}
183225

184226
return 0;
@@ -230,12 +272,18 @@ int rmi_register_function(struct rmi_function *fn)
230272

231273
void rmi_unregister_function(struct rmi_function *fn)
232274
{
275+
int i;
276+
233277
rmi_dbg(RMI_DEBUG_CORE, &fn->dev, "Unregistering F%02X.\n",
234278
fn->fd.function_number);
235279

236280
device_del(&fn->dev);
237281
of_node_put(fn->dev.of_node);
238282
put_device(&fn->dev);
283+
284+
for (i = 0; i < fn->num_of_irqs; i++)
285+
irq_dispose_mapping(fn->irq[i]);
286+
239287
}
240288

241289
/**

drivers/input/rmi4/rmi_bus.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
struct rmi_device;
1616

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+
1723
/**
1824
* struct rmi_function - represents the implementation of an RMI4
1925
* function for a particular device (basically, a driver for that RMI4 function)
@@ -26,6 +32,7 @@ struct rmi_device;
2632
* @irq_pos: The position in the irq bitfield this function holds
2733
* @irq_mask: For convenience, can be used to mask IRQ bits off during ATTN
2834
* interrupt handling.
35+
* @irqs: assigned virq numbers (up to num_of_irqs)
2936
*
3037
* @node: entry in device's list of functions
3138
*/
@@ -36,6 +43,7 @@ struct rmi_function {
3643
struct list_head node;
3744

3845
unsigned int num_of_irqs;
46+
int irq[RMI_FN_MAX_IRQS];
3947
unsigned int irq_pos;
4048
unsigned long irq_mask[];
4149
};
@@ -76,7 +84,7 @@ struct rmi_function_handler {
7684
void (*remove)(struct rmi_function *fn);
7785
int (*config)(struct rmi_function *fn);
7886
int (*reset)(struct rmi_function *fn);
79-
int (*attention)(struct rmi_function *fn, unsigned long *irq_bits);
87+
irqreturn_t (*attention)(int irq, void *ctx);
8088
int (*suspend)(struct rmi_function *fn);
8189
int (*resume)(struct rmi_function *fn);
8290
};

drivers/input/rmi4/rmi_driver.c

+20-32
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/pm.h>
2222
#include <linux/slab.h>
2323
#include <linux/of.h>
24+
#include <linux/irqdomain.h>
2425
#include <uapi/linux/input.h>
2526
#include <linux/rmi.h>
2627
#include "rmi_bus.h"
@@ -127,28 +128,11 @@ static int rmi_driver_process_config_requests(struct rmi_device *rmi_dev)
127128
return 0;
128129
}
129130

130-
static void process_one_interrupt(struct rmi_driver_data *data,
131-
struct rmi_function *fn)
132-
{
133-
struct rmi_function_handler *fh;
134-
135-
if (!fn || !fn->dev.driver)
136-
return;
137-
138-
fh = to_rmi_function_handler(fn->dev.driver);
139-
if (fh->attention) {
140-
bitmap_and(data->fn_irq_bits, data->irq_status, fn->irq_mask,
141-
data->irq_count);
142-
if (!bitmap_empty(data->fn_irq_bits, data->irq_count))
143-
fh->attention(fn, data->fn_irq_bits);
144-
}
145-
}
146-
147131
static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
148132
{
149133
struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
150134
struct device *dev = &rmi_dev->dev;
151-
struct rmi_function *entry;
135+
int i;
152136
int error;
153137

154138
if (!data)
@@ -173,16 +157,8 @@ static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
173157
*/
174158
mutex_unlock(&data->irq_mutex);
175159

176-
/*
177-
* It would be nice to be able to use irq_chip to handle these
178-
* nested IRQs. Unfortunately, most of the current customers for
179-
* this driver are using older kernels (3.0.x) that don't support
180-
* the features required for that. Once they've shifted to more
181-
* recent kernels (say, 3.3 and higher), this should be switched to
182-
* use irq_chip.
183-
*/
184-
list_for_each_entry(entry, &data->function_list, node)
185-
process_one_interrupt(data, entry);
160+
for_each_set_bit(i, data->irq_status, data->irq_count)
161+
handle_nested_irq(irq_find_mapping(data->irqdomain, i));
186162

187163
if (data->input)
188164
input_sync(data->input);
@@ -1000,9 +976,13 @@ EXPORT_SYMBOL_GPL(rmi_driver_resume);
1000976
static int rmi_driver_remove(struct device *dev)
1001977
{
1002978
struct rmi_device *rmi_dev = to_rmi_device(dev);
979+
struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
1003980

1004981
rmi_disable_irq(rmi_dev, false);
1005982

983+
irq_domain_remove(data->irqdomain);
984+
data->irqdomain = NULL;
985+
1006986
rmi_f34_remove_sysfs(rmi_dev);
1007987
rmi_free_function_list(rmi_dev);
1008988

@@ -1034,7 +1014,8 @@ int rmi_probe_interrupts(struct rmi_driver_data *data)
10341014
{
10351015
struct rmi_device *rmi_dev = data->rmi_dev;
10361016
struct device *dev = &rmi_dev->dev;
1037-
int irq_count;
1017+
struct fwnode_handle *fwnode = rmi_dev->xport->dev->fwnode;
1018+
int irq_count = 0;
10381019
size_t size;
10391020
int retval;
10401021

@@ -1045,7 +1026,6 @@ int rmi_probe_interrupts(struct rmi_driver_data *data)
10451026
* being accessed.
10461027
*/
10471028
rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Counting IRQs.\n", __func__);
1048-
irq_count = 0;
10491029
data->bootloader_mode = false;
10501030

10511031
retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_count_irqs);
@@ -1057,6 +1037,15 @@ int rmi_probe_interrupts(struct rmi_driver_data *data)
10571037
if (data->bootloader_mode)
10581038
dev_warn(dev, "Device in bootloader mode.\n");
10591039

1040+
/* Allocate and register a linear revmap irq_domain */
1041+
data->irqdomain = irq_domain_create_linear(fwnode, irq_count,
1042+
&irq_domain_simple_ops,
1043+
data);
1044+
if (!data->irqdomain) {
1045+
dev_err(&rmi_dev->dev, "Failed to create IRQ domain\n");
1046+
return PTR_ERR(data->irqdomain);
1047+
}
1048+
10601049
data->irq_count = irq_count;
10611050
data->num_of_irq_regs = (data->irq_count + 7) / 8;
10621051

@@ -1079,10 +1068,9 @@ int rmi_init_functions(struct rmi_driver_data *data)
10791068
{
10801069
struct rmi_device *rmi_dev = data->rmi_dev;
10811070
struct device *dev = &rmi_dev->dev;
1082-
int irq_count;
1071+
int irq_count = 0;
10831072
int retval;
10841073

1085-
irq_count = 0;
10861074
rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Creating functions.\n", __func__);
10871075
retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_create_function);
10881076
if (retval < 0) {

drivers/input/rmi4/rmi_f01.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,9 @@ static int rmi_f01_resume(struct rmi_function *fn)
681681
return 0;
682682
}
683683

684-
static int rmi_f01_attention(struct rmi_function *fn,
685-
unsigned long *irq_bits)
684+
static irqreturn_t rmi_f01_attention(int irq, void *ctx)
686685
{
686+
struct rmi_function *fn = ctx;
687687
struct rmi_device *rmi_dev = fn->rmi_dev;
688688
int error;
689689
u8 device_status;
@@ -692,7 +692,7 @@ static int rmi_f01_attention(struct rmi_function *fn,
692692
if (error) {
693693
dev_err(&fn->dev,
694694
"Failed to read device status: %d.\n", error);
695-
return error;
695+
return IRQ_RETVAL(error);
696696
}
697697

698698
if (RMI_F01_STATUS_BOOTLOADER(device_status))
@@ -704,11 +704,11 @@ static int rmi_f01_attention(struct rmi_function *fn,
704704
error = rmi_dev->driver->reset_handler(rmi_dev);
705705
if (error) {
706706
dev_err(&fn->dev, "Device reset failed: %d\n", error);
707-
return error;
707+
return IRQ_RETVAL(error);
708708
}
709709
}
710710

711-
return 0;
711+
return IRQ_HANDLED;
712712
}
713713

714714
struct rmi_function_handler rmi_f01_handler = {

drivers/input/rmi4/rmi_f03.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ static int rmi_f03_config(struct rmi_function *fn)
244244
return 0;
245245
}
246246

247-
static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
247+
static irqreturn_t rmi_f03_attention(int irq, void *ctx)
248248
{
249+
struct rmi_function *fn = ctx;
249250
struct rmi_device *rmi_dev = fn->rmi_dev;
250251
struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
251252
struct f03_data *f03 = dev_get_drvdata(&fn->dev);
@@ -262,7 +263,7 @@ static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
262263
/* First grab the data passed by the transport device */
263264
if (drvdata->attn_data.size < ob_len) {
264265
dev_warn(&fn->dev, "F03 interrupted, but data is missing!\n");
265-
return 0;
266+
return IRQ_HANDLED;
266267
}
267268

268269
memcpy(obs, drvdata->attn_data.data, ob_len);
@@ -277,7 +278,7 @@ static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
277278
"%s: Failed to read F03 output buffers: %d\n",
278279
__func__, error);
279280
serio_interrupt(f03->serio, 0, SERIO_TIMEOUT);
280-
return error;
281+
return IRQ_RETVAL(error);
281282
}
282283
}
283284

@@ -303,7 +304,7 @@ static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
303304
serio_interrupt(f03->serio, ob_data, serio_flags);
304305
}
305306

306-
return 0;
307+
return IRQ_HANDLED;
307308
}
308309

309310
static void rmi_f03_remove(struct rmi_function *fn)

0 commit comments

Comments
 (0)