Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <nick@shmanahar.org>
Acked-by: Christopher Heiny <cheiny@synaptics.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Nick Dyer and committed by
Dmitry Torokhov
24d28e4f 8f6a652a

+119 -85
+1
drivers/input/rmi4/Kconfig
··· 3 3 # 4 4 config RMI4_CORE 5 5 tristate "Synaptics RMI4 bus support" 6 + select IRQ_DOMAIN 6 7 help 7 8 Say Y here if you want to support the Synaptics RMI4 bus. This is 8 9 required for all RMI4 device support.
+49 -1
drivers/input/rmi4/rmi_bus.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/device.h> 12 + #include <linux/irq.h> 13 + #include <linux/irqdomain.h> 12 14 #include <linux/list.h> 13 15 #include <linux/pm.h> 14 16 #include <linux/rmi.h> ··· 169 167 {} 170 168 #endif 171 169 170 + static struct irq_chip rmi_irq_chip = { 171 + .name = "rmi4", 172 + }; 173 + 174 + static int rmi_create_function_irq(struct rmi_function *fn, 175 + struct rmi_function_handler *handler) 176 + { 177 + struct rmi_driver_data *drvdata = dev_get_drvdata(&fn->rmi_dev->dev); 178 + int i, error; 179 + 180 + for (i = 0; i < fn->num_of_irqs; i++) { 181 + set_bit(fn->irq_pos + i, fn->irq_mask); 182 + 183 + fn->irq[i] = irq_create_mapping(drvdata->irqdomain, 184 + fn->irq_pos + i); 185 + 186 + irq_set_chip_data(fn->irq[i], fn); 187 + irq_set_chip_and_handler(fn->irq[i], &rmi_irq_chip, 188 + handle_simple_irq); 189 + irq_set_nested_thread(fn->irq[i], 1); 190 + 191 + error = devm_request_threaded_irq(&fn->dev, fn->irq[i], NULL, 192 + handler->attention, IRQF_ONESHOT, 193 + dev_name(&fn->dev), fn); 194 + if (error) { 195 + dev_err(&fn->dev, "Error %d registering IRQ\n", error); 196 + return error; 197 + } 198 + } 199 + 200 + return 0; 201 + } 202 + 172 203 static int rmi_function_probe(struct device *dev) 173 204 { 174 205 struct rmi_function *fn = to_rmi_function(dev); ··· 213 178 214 179 if (handler->probe) { 215 180 error = handler->probe(fn); 216 - return error; 181 + if (error) 182 + return error; 183 + } 184 + 185 + if (fn->num_of_irqs && handler->attention) { 186 + error = rmi_create_function_irq(fn, handler); 187 + if (error) 188 + return error; 217 189 } 218 190 219 191 return 0; ··· 272 230 273 231 void rmi_unregister_function(struct rmi_function *fn) 274 232 { 233 + int i; 234 + 275 235 rmi_dbg(RMI_DEBUG_CORE, &fn->dev, "Unregistering F%02X.\n", 276 236 fn->fd.function_number); 277 237 278 238 device_del(&fn->dev); 279 239 of_node_put(fn->dev.of_node); 280 240 put_device(&fn->dev); 241 + 242 + for (i = 0; i < fn->num_of_irqs; i++) 243 + irq_dispose_mapping(fn->irq[i]); 244 + 281 245 } 282 246 283 247 /**
+9 -1
drivers/input/rmi4/rmi_bus.h
··· 14 14 15 15 struct rmi_device; 16 16 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 + 17 23 /** 18 24 * struct rmi_function - represents the implementation of an RMI4 19 25 * function for a particular device (basically, a driver for that RMI4 function) ··· 32 26 * @irq_pos: The position in the irq bitfield this function holds 33 27 * @irq_mask: For convenience, can be used to mask IRQ bits off during ATTN 34 28 * interrupt handling. 29 + * @irqs: assigned virq numbers (up to num_of_irqs) 35 30 * 36 31 * @node: entry in device's list of functions 37 32 */ ··· 43 36 struct list_head node; 44 37 45 38 unsigned int num_of_irqs; 39 + int irq[RMI_FN_MAX_IRQS]; 46 40 unsigned int irq_pos; 47 41 unsigned long irq_mask[]; 48 42 }; ··· 84 76 void (*remove)(struct rmi_function *fn); 85 77 int (*config)(struct rmi_function *fn); 86 78 int (*reset)(struct rmi_function *fn); 87 - int (*attention)(struct rmi_function *fn, unsigned long *irq_bits); 79 + irqreturn_t (*attention)(int irq, void *ctx); 88 80 int (*suspend)(struct rmi_function *fn); 89 81 int (*resume)(struct rmi_function *fn); 90 82 };
+20 -32
drivers/input/rmi4/rmi_driver.c
··· 21 21 #include <linux/pm.h> 22 22 #include <linux/slab.h> 23 23 #include <linux/of.h> 24 + #include <linux/irqdomain.h> 24 25 #include <uapi/linux/input.h> 25 26 #include <linux/rmi.h> 26 27 #include "rmi_bus.h" ··· 128 127 return 0; 129 128 } 130 129 131 - static void process_one_interrupt(struct rmi_driver_data *data, 132 - struct rmi_function *fn) 133 - { 134 - struct rmi_function_handler *fh; 135 - 136 - if (!fn || !fn->dev.driver) 137 - return; 138 - 139 - fh = to_rmi_function_handler(fn->dev.driver); 140 - if (fh->attention) { 141 - bitmap_and(data->fn_irq_bits, data->irq_status, fn->irq_mask, 142 - data->irq_count); 143 - if (!bitmap_empty(data->fn_irq_bits, data->irq_count)) 144 - fh->attention(fn, data->fn_irq_bits); 145 - } 146 - } 147 - 148 130 static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev) 149 131 { 150 132 struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev); 151 133 struct device *dev = &rmi_dev->dev; 152 - struct rmi_function *entry; 134 + int i; 153 135 int error; 154 136 155 137 if (!data) ··· 157 173 */ 158 174 mutex_unlock(&data->irq_mutex); 159 175 160 - /* 161 - * It would be nice to be able to use irq_chip to handle these 162 - * nested IRQs. Unfortunately, most of the current customers for 163 - * this driver are using older kernels (3.0.x) that don't support 164 - * the features required for that. Once they've shifted to more 165 - * recent kernels (say, 3.3 and higher), this should be switched to 166 - * use irq_chip. 167 - */ 168 - list_for_each_entry(entry, &data->function_list, node) 169 - process_one_interrupt(data, entry); 176 + for_each_set_bit(i, data->irq_status, data->irq_count) 177 + handle_nested_irq(irq_find_mapping(data->irqdomain, i)); 170 178 171 179 if (data->input) 172 180 input_sync(data->input); ··· 976 1000 static int rmi_driver_remove(struct device *dev) 977 1001 { 978 1002 struct rmi_device *rmi_dev = to_rmi_device(dev); 1003 + struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev); 979 1004 980 1005 rmi_disable_irq(rmi_dev, false); 1006 + 1007 + irq_domain_remove(data->irqdomain); 1008 + data->irqdomain = NULL; 981 1009 982 1010 rmi_f34_remove_sysfs(rmi_dev); 983 1011 rmi_free_function_list(rmi_dev); ··· 1014 1034 { 1015 1035 struct rmi_device *rmi_dev = data->rmi_dev; 1016 1036 struct device *dev = &rmi_dev->dev; 1017 - int irq_count; 1037 + struct fwnode_handle *fwnode = rmi_dev->xport->dev->fwnode; 1038 + int irq_count = 0; 1018 1039 size_t size; 1019 1040 int retval; 1020 1041 ··· 1026 1045 * being accessed. 1027 1046 */ 1028 1047 rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Counting IRQs.\n", __func__); 1029 - irq_count = 0; 1030 1048 data->bootloader_mode = false; 1031 1049 1032 1050 retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_count_irqs); ··· 1036 1056 1037 1057 if (data->bootloader_mode) 1038 1058 dev_warn(dev, "Device in bootloader mode.\n"); 1059 + 1060 + /* Allocate and register a linear revmap irq_domain */ 1061 + data->irqdomain = irq_domain_create_linear(fwnode, irq_count, 1062 + &irq_domain_simple_ops, 1063 + data); 1064 + if (!data->irqdomain) { 1065 + dev_err(&rmi_dev->dev, "Failed to create IRQ domain\n"); 1066 + return PTR_ERR(data->irqdomain); 1067 + } 1039 1068 1040 1069 data->irq_count = irq_count; 1041 1070 data->num_of_irq_regs = (data->irq_count + 7) / 8; ··· 1068 1079 { 1069 1080 struct rmi_device *rmi_dev = data->rmi_dev; 1070 1081 struct device *dev = &rmi_dev->dev; 1071 - int irq_count; 1082 + int irq_count = 0; 1072 1083 int retval; 1073 1084 1074 - irq_count = 0; 1075 1085 rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Creating functions.\n", __func__); 1076 1086 retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_create_function); 1077 1087 if (retval < 0) {
+5 -5
drivers/input/rmi4/rmi_f01.c
··· 681 681 return 0; 682 682 } 683 683 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) 686 685 { 686 + struct rmi_function *fn = ctx; 687 687 struct rmi_device *rmi_dev = fn->rmi_dev; 688 688 int error; 689 689 u8 device_status; ··· 692 692 if (error) { 693 693 dev_err(&fn->dev, 694 694 "Failed to read device status: %d.\n", error); 695 - return error; 695 + return IRQ_RETVAL(error); 696 696 } 697 697 698 698 if (RMI_F01_STATUS_BOOTLOADER(device_status)) ··· 704 704 error = rmi_dev->driver->reset_handler(rmi_dev); 705 705 if (error) { 706 706 dev_err(&fn->dev, "Device reset failed: %d\n", error); 707 - return error; 707 + return IRQ_RETVAL(error); 708 708 } 709 709 } 710 710 711 - return 0; 711 + return IRQ_HANDLED; 712 712 } 713 713 714 714 struct rmi_function_handler rmi_f01_handler = {
+5 -4
drivers/input/rmi4/rmi_f03.c
··· 244 244 return 0; 245 245 } 246 246 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) 248 248 { 249 + struct rmi_function *fn = ctx; 249 250 struct rmi_device *rmi_dev = fn->rmi_dev; 250 251 struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev); 251 252 struct f03_data *f03 = dev_get_drvdata(&fn->dev); ··· 263 262 /* First grab the data passed by the transport device */ 264 263 if (drvdata->attn_data.size < ob_len) { 265 264 dev_warn(&fn->dev, "F03 interrupted, but data is missing!\n"); 266 - return 0; 265 + return IRQ_HANDLED; 267 266 } 268 267 269 268 memcpy(obs, drvdata->attn_data.data, ob_len); ··· 278 277 "%s: Failed to read F03 output buffers: %d\n", 279 278 __func__, error); 280 279 serio_interrupt(f03->serio, 0, SERIO_TIMEOUT); 281 - return error; 280 + return IRQ_RETVAL(error); 282 281 } 283 282 } 284 283 ··· 304 303 serio_interrupt(f03->serio, ob_data, serio_flags); 305 304 } 306 305 307 - return 0; 306 + return IRQ_HANDLED; 308 307 } 309 308 310 309 static void rmi_f03_remove(struct rmi_function *fn)
+16 -26
drivers/input/rmi4/rmi_f11.c
··· 570 570 } 571 571 572 572 static void rmi_f11_finger_handler(struct f11_data *f11, 573 - struct rmi_2d_sensor *sensor, 574 - unsigned long *irq_bits, int num_irq_regs, 575 - int size) 573 + struct rmi_2d_sensor *sensor, int size) 576 574 { 577 575 const u8 *f_state = f11->data.f_state; 578 576 u8 finger_state; ··· 579 581 int rel_fingers; 580 582 int abs_size = sensor->nbr_fingers * RMI_F11_ABS_BYTES; 581 583 582 - int abs_bits = bitmap_and(f11->result_bits, irq_bits, f11->abs_mask, 583 - num_irq_regs * 8); 584 - int rel_bits = bitmap_and(f11->result_bits, irq_bits, f11->rel_mask, 585 - num_irq_regs * 8); 586 - 587 - if (abs_bits) { 584 + if (sensor->report_abs) { 588 585 if (abs_size > size) 589 586 abs_fingers = size / RMI_F11_ABS_BYTES; 590 587 else ··· 597 604 rmi_f11_abs_pos_process(f11, sensor, &sensor->objs[i], 598 605 finger_state, i); 599 606 } 600 - } 601 607 602 - if (rel_bits) { 603 - if ((abs_size + sensor->nbr_fingers * RMI_F11_REL_BYTES) > size) 604 - rel_fingers = (size - abs_size) / RMI_F11_REL_BYTES; 605 - else 606 - rel_fingers = sensor->nbr_fingers; 607 - 608 - for (i = 0; i < rel_fingers; i++) 609 - rmi_f11_rel_pos_report(f11, i); 610 - } 611 - 612 - if (abs_bits) { 613 608 /* 614 609 * the absolute part is made in 2 parts to allow the kernel 615 610 * tracking to take place. ··· 619 638 } 620 639 621 640 input_mt_sync_frame(sensor->input); 641 + } else if (sensor->report_rel) { 642 + if ((abs_size + sensor->nbr_fingers * RMI_F11_REL_BYTES) > size) 643 + rel_fingers = (size - abs_size) / RMI_F11_REL_BYTES; 644 + else 645 + rel_fingers = sensor->nbr_fingers; 646 + 647 + for (i = 0; i < rel_fingers; i++) 648 + rmi_f11_rel_pos_report(f11, i); 622 649 } 650 + 623 651 } 624 652 625 653 static int f11_2d_construct_data(struct f11_data *f11) ··· 1265 1275 return 0; 1266 1276 } 1267 1277 1268 - static int rmi_f11_attention(struct rmi_function *fn, unsigned long *irq_bits) 1278 + static irqreturn_t rmi_f11_attention(int irq, void *ctx) 1269 1279 { 1280 + struct rmi_function *fn = ctx; 1270 1281 struct rmi_device *rmi_dev = fn->rmi_dev; 1271 1282 struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev); 1272 1283 struct f11_data *f11 = dev_get_drvdata(&fn->dev); ··· 1293 1302 data_base_addr, f11->sensor.data_pkt, 1294 1303 f11->sensor.pkt_size); 1295 1304 if (error < 0) 1296 - return error; 1305 + return IRQ_RETVAL(error); 1297 1306 } 1298 1307 1299 - rmi_f11_finger_handler(f11, &f11->sensor, irq_bits, 1300 - drvdata->num_of_irq_regs, valid_bytes); 1308 + rmi_f11_finger_handler(f11, &f11->sensor, valid_bytes); 1301 1309 1302 - return 0; 1310 + return IRQ_HANDLED; 1303 1311 } 1304 1312 1305 1313 static int rmi_f11_resume(struct rmi_function *fn)
+4 -4
drivers/input/rmi4/rmi_f12.c
··· 197 197 rmi_2d_sensor_abs_report(sensor, &sensor->objs[i], i); 198 198 } 199 199 200 - static int rmi_f12_attention(struct rmi_function *fn, 201 - unsigned long *irq_nr_regs) 200 + static irqreturn_t rmi_f12_attention(int irq, void *ctx) 202 201 { 203 202 int retval; 203 + struct rmi_function *fn = ctx; 204 204 struct rmi_device *rmi_dev = fn->rmi_dev; 205 205 struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev); 206 206 struct f12_data *f12 = dev_get_drvdata(&fn->dev); ··· 222 222 if (retval < 0) { 223 223 dev_err(&fn->dev, "Failed to read object data. Code: %d.\n", 224 224 retval); 225 - return retval; 225 + return IRQ_RETVAL(retval); 226 226 } 227 227 } 228 228 ··· 232 232 233 233 input_mt_sync_frame(sensor->input); 234 234 235 - return 0; 235 + return IRQ_HANDLED; 236 236 } 237 237 238 238 static int rmi_f12_write_control_regs(struct rmi_function *fn)
+5 -4
drivers/input/rmi4/rmi_f30.c
··· 122 122 } 123 123 } 124 124 125 - static int rmi_f30_attention(struct rmi_function *fn, unsigned long *irq_bits) 125 + static irqreturn_t rmi_f30_attention(int irq, void *ctx) 126 126 { 127 + struct rmi_function *fn = ctx; 127 128 struct f30_data *f30 = dev_get_drvdata(&fn->dev); 128 129 struct rmi_driver_data *drvdata = dev_get_drvdata(&fn->rmi_dev->dev); 129 130 int error; ··· 135 134 if (drvdata->attn_data.size < f30->register_count) { 136 135 dev_warn(&fn->dev, 137 136 "F30 interrupted, but data is missing\n"); 138 - return 0; 137 + return IRQ_HANDLED; 139 138 } 140 139 memcpy(f30->data_regs, drvdata->attn_data.data, 141 140 f30->register_count); ··· 148 147 dev_err(&fn->dev, 149 148 "%s: Failed to read F30 data registers: %d\n", 150 149 __func__, error); 151 - return error; 150 + return IRQ_RETVAL(error); 152 151 } 153 152 } 154 153 ··· 160 159 rmi_f03_commit_buttons(f30->f03); 161 160 } 162 161 163 - return 0; 162 + return IRQ_HANDLED; 164 163 } 165 164 166 165 static int rmi_f30_config(struct rmi_function *fn)
+3 -2
drivers/input/rmi4/rmi_f34.c
··· 100 100 return 0; 101 101 } 102 102 103 - static int rmi_f34_attention(struct rmi_function *fn, unsigned long *irq_bits) 103 + static irqreturn_t rmi_f34_attention(int irq, void *ctx) 104 104 { 105 + struct rmi_function *fn = ctx; 105 106 struct f34_data *f34 = dev_get_drvdata(&fn->dev); 106 107 int ret; 107 108 u8 status; ··· 127 126 complete(&f34->v7.cmd_done); 128 127 } 129 128 130 - return 0; 129 + return IRQ_HANDLED; 131 130 } 132 131 133 132 static int rmi_f34_write_blocks(struct f34_data *f34, const void *data,
-6
drivers/input/rmi4/rmi_f54.c
··· 610 610 mutex_unlock(&f54->data_mutex); 611 611 } 612 612 613 - static int rmi_f54_attention(struct rmi_function *fn, unsigned long *irqbits) 614 - { 615 - return 0; 616 - } 617 - 618 613 static int rmi_f54_config(struct rmi_function *fn) 619 614 { 620 615 struct rmi_driver *drv = fn->rmi_dev->driver; ··· 751 756 .func = 0x54, 752 757 .probe = rmi_f54_probe, 753 758 .config = rmi_f54_config, 754 - .attention = rmi_f54_attention, 755 759 .remove = rmi_f54_remove, 756 760 };
+2
include/linux/rmi.h
··· 354 354 struct mutex irq_mutex; 355 355 struct input_dev *input; 356 356 357 + struct irq_domain *irqdomain; 358 + 357 359 u8 pdt_props; 358 360 359 361 u8 num_rx_electrodes;