2020#include <linux/device.h>
2121#include <linux/interrupt.h>
2222#include <linux/irq.h>
23+ #include <linux/irqdomain.h>
2324#include <linux/gpio.h>
2425#include <linux/mfd/tps65910.h>
2526
26- static inline int irq_to_tps65910_irq (struct tps65910 * tps65910 ,
27- int irq )
28- {
29- return (irq - tps65910 -> irq_base );
30- }
31-
3227/*
3328 * This is a threaded IRQ handler so can access I2C/SPI. Since all
3429 * interrupts are clear on read the IRQ line will be reasserted and
@@ -76,7 +71,7 @@ static irqreturn_t tps65910_irq(int irq, void *irq_data)
7671 if (!(irq_sts & (1 << i )))
7772 continue ;
7873
79- handle_nested_irq (tps65910 -> irq_base + i );
74+ handle_nested_irq (irq_find_mapping ( tps65910 -> domain , i ) );
8075 }
8176
8277 /* Write the STS register back to clear IRQs we handled */
@@ -135,14 +130,14 @@ static void tps65910_irq_enable(struct irq_data *data)
135130{
136131 struct tps65910 * tps65910 = irq_data_get_irq_chip_data (data );
137132
138- tps65910 -> irq_mask &= ~( 1 << irq_to_tps65910_irq ( tps65910 , data -> irq ) );
133+ tps65910 -> irq_mask &= ~(1 << data -> hwirq );
139134}
140135
141136static void tps65910_irq_disable (struct irq_data * data )
142137{
143138 struct tps65910 * tps65910 = irq_data_get_irq_chip_data (data );
144139
145- tps65910 -> irq_mask |= ( 1 << irq_to_tps65910_irq ( tps65910 , data -> irq ) );
140+ tps65910 -> irq_mask |= (1 << data -> hwirq );
146141}
147142
148143#ifdef CONFIG_PM_SLEEP
@@ -164,28 +159,47 @@ static struct irq_chip tps65910_irq_chip = {
164159 .irq_set_wake = tps65910_irq_set_wake ,
165160};
166161
162+ static int tps65910_irq_map (struct irq_domain * h , unsigned int virq ,
163+ irq_hw_number_t hw )
164+ {
165+ struct tps65910 * tps65910 = h -> host_data ;
166+
167+ irq_set_chip_data (virq , tps65910 );
168+ irq_set_chip_and_handler (virq , & tps65910_irq_chip , handle_edge_irq );
169+ irq_set_nested_thread (virq , 1 );
170+
171+ /* ARM needs us to explicitly flag the IRQ as valid
172+ * and will set them noprobe when we do so. */
173+ #ifdef CONFIG_ARM
174+ set_irq_flags (virq , IRQF_VALID );
175+ #else
176+ irq_set_noprobe (virq );
177+ #endif
178+
179+ return 0 ;
180+ }
181+
182+ static struct irq_domain_ops tps65910_domain_ops = {
183+ .map = tps65910_irq_map ,
184+ .xlate = irq_domain_xlate_twocell ,
185+ };
186+
167187int tps65910_irq_init (struct tps65910 * tps65910 , int irq ,
168188 struct tps65910_platform_data * pdata )
169189{
170- int ret , cur_irq ;
190+ int ret ;
171191 int flags = IRQF_ONESHOT ;
172192
173193 if (!irq ) {
174194 dev_warn (tps65910 -> dev , "No interrupt support, no core IRQ\n" );
175195 return - EINVAL ;
176196 }
177197
178- if (!pdata || ! pdata -> irq_base ) {
179- dev_warn (tps65910 -> dev , "No interrupt support, no IRQ base \n" );
198+ if (!pdata ) {
199+ dev_warn (tps65910 -> dev , "No interrupt support, no pdata \n" );
180200 return - EINVAL ;
181201 }
182202
183- tps65910 -> irq_mask = 0xFFFFFF ;
184-
185- mutex_init (& tps65910 -> irq_lock );
186- tps65910 -> chip_irq = irq ;
187- tps65910 -> irq_base = pdata -> irq_base ;
188-
189203 switch (tps65910_chip_id (tps65910 )) {
190204 case TPS65910 :
191205 tps65910 -> irq_num = TPS65910_NUM_IRQ ;
@@ -195,22 +209,36 @@ int tps65910_irq_init(struct tps65910 *tps65910, int irq,
195209 break ;
196210 }
197211
198- /* Register with genirq */
199- for (cur_irq = tps65910 -> irq_base ;
200- cur_irq < tps65910 -> irq_num + tps65910 -> irq_base ;
201- cur_irq ++ ) {
202- irq_set_chip_data (cur_irq , tps65910 );
203- irq_set_chip_and_handler (cur_irq , & tps65910_irq_chip ,
204- handle_edge_irq );
205- irq_set_nested_thread (cur_irq , 1 );
206-
207- /* ARM needs us to explicitly flag the IRQ as valid
208- * and will set them noprobe when we do so. */
209- #ifdef CONFIG_ARM
210- set_irq_flags (cur_irq , IRQF_VALID );
211- #else
212- irq_set_noprobe (cur_irq );
213- #endif
212+ if (pdata -> irq_base > 0 ) {
213+ pdata -> irq_base = irq_alloc_descs (pdata -> irq_base , 0 ,
214+ tps65910 -> irq_num , -1 );
215+ if (pdata -> irq_base < 0 ) {
216+ dev_warn (tps65910 -> dev , "Failed to alloc IRQs: %d\n" ,
217+ pdata -> irq_base );
218+ return pdata -> irq_base ;
219+ }
220+ }
221+
222+ tps65910 -> irq_mask = 0xFFFFFF ;
223+
224+ mutex_init (& tps65910 -> irq_lock );
225+ tps65910 -> chip_irq = irq ;
226+ tps65910 -> irq_base = pdata -> irq_base ;
227+
228+ if (pdata -> irq_base > 0 )
229+ tps65910 -> domain = irq_domain_add_legacy (tps65910 -> dev -> of_node ,
230+ tps65910 -> irq_num ,
231+ pdata -> irq_base ,
232+ 0 ,
233+ & tps65910_domain_ops , tps65910 );
234+ else
235+ tps65910 -> domain = irq_domain_add_linear (tps65910 -> dev -> of_node ,
236+ tps65910 -> irq_num ,
237+ & tps65910_domain_ops , tps65910 );
238+
239+ if (!tps65910 -> domain ) {
240+ dev_err (tps65910 -> dev , "Failed to create IRQ domain\n" );
241+ return - ENOMEM ;
214242 }
215243
216244 ret = request_threaded_irq (irq , NULL , tps65910_irq , flags ,
0 commit comments