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-
147131static 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);
1000976static 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 ) {
0 commit comments