@@ -29,13 +29,23 @@ struct stm32_exti_bank {
29
29
30
30
#define UNDEF_REG ~0
31
31
32
+ struct stm32_exti_drv_data {
33
+ const struct stm32_exti_bank * * exti_banks ;
34
+ u32 bank_nr ;
35
+ };
36
+
32
37
struct stm32_exti_chip_data {
38
+ struct stm32_exti_host_data * host_data ;
33
39
const struct stm32_exti_bank * reg_bank ;
34
40
u32 rtsr_cache ;
35
41
u32 ftsr_cache ;
36
42
};
37
43
38
- static struct stm32_exti_chip_data * stm32_exti_data ;
44
+ struct stm32_exti_host_data {
45
+ void __iomem * base ;
46
+ struct stm32_exti_chip_data * chips_data ;
47
+ const struct stm32_exti_drv_data * drv_data ;
48
+ };
39
49
40
50
static const struct stm32_exti_bank stm32f4xx_exti_b1 = {
41
51
.imr_ofst = 0x00 ,
@@ -51,6 +61,11 @@ static const struct stm32_exti_bank *stm32f4xx_exti_banks[] = {
51
61
& stm32f4xx_exti_b1 ,
52
62
};
53
63
64
+ static const struct stm32_exti_drv_data stm32f4xx_drv_data = {
65
+ .exti_banks = stm32f4xx_exti_banks ,
66
+ .bank_nr = ARRAY_SIZE (stm32f4xx_exti_banks ),
67
+ };
68
+
54
69
static const struct stm32_exti_bank stm32h7xx_exti_b1 = {
55
70
.imr_ofst = 0x80 ,
56
71
.emr_ofst = 0x84 ,
@@ -87,6 +102,11 @@ static const struct stm32_exti_bank *stm32h7xx_exti_banks[] = {
87
102
& stm32h7xx_exti_b3 ,
88
103
};
89
104
105
+ static const struct stm32_exti_drv_data stm32h7xx_drv_data = {
106
+ .exti_banks = stm32h7xx_exti_banks ,
107
+ .bank_nr = ARRAY_SIZE (stm32h7xx_exti_banks ),
108
+ };
109
+
90
110
static unsigned long stm32_exti_pending (struct irq_chip_generic * gc )
91
111
{
92
112
struct stm32_exti_chip_data * chip_data = gc -> private ;
@@ -237,29 +257,85 @@ static void stm32_irq_ack(struct irq_data *d)
237
257
238
258
irq_gc_unlock (gc );
239
259
}
260
+ static struct
261
+ stm32_exti_host_data * stm32_exti_host_init (const struct stm32_exti_drv_data * dd ,
262
+ struct device_node * node )
263
+ {
264
+ struct stm32_exti_host_data * host_data ;
265
+
266
+ host_data = kzalloc (sizeof (* host_data ), GFP_KERNEL );
267
+ if (!host_data )
268
+ return NULL ;
269
+
270
+ host_data -> drv_data = dd ;
271
+ host_data -> chips_data = kcalloc (dd -> bank_nr ,
272
+ sizeof (struct stm32_exti_chip_data ),
273
+ GFP_KERNEL );
274
+ if (!host_data -> chips_data )
275
+ return NULL ;
276
+
277
+ host_data -> base = of_iomap (node , 0 );
278
+ if (!host_data -> base ) {
279
+ pr_err ("%pOF: Unable to map registers\n" , node );
280
+ return NULL ;
281
+ }
240
282
241
- static int
242
- __init stm32_exti_init (const struct stm32_exti_bank * * stm32_exti_banks ,
243
- int bank_nr , struct device_node * node )
283
+ return host_data ;
284
+ }
285
+
286
+ static struct
287
+ stm32_exti_chip_data * stm32_exti_chip_init (struct stm32_exti_host_data * h_data ,
288
+ u32 bank_idx ,
289
+ struct device_node * node )
290
+ {
291
+ const struct stm32_exti_bank * stm32_bank ;
292
+ struct stm32_exti_chip_data * chip_data ;
293
+ void __iomem * base = h_data -> base ;
294
+ u32 irqs_mask ;
295
+
296
+ stm32_bank = h_data -> drv_data -> exti_banks [bank_idx ];
297
+ chip_data = & h_data -> chips_data [bank_idx ];
298
+ chip_data -> host_data = h_data ;
299
+ chip_data -> reg_bank = stm32_bank ;
300
+
301
+ /* Determine number of irqs supported */
302
+ writel_relaxed (~0UL , base + stm32_bank -> rtsr_ofst );
303
+ irqs_mask = readl_relaxed (base + stm32_bank -> rtsr_ofst );
304
+
305
+ /*
306
+ * This IP has no reset, so after hot reboot we should
307
+ * clear registers to avoid residue
308
+ */
309
+ writel_relaxed (0 , base + stm32_bank -> imr_ofst );
310
+ writel_relaxed (0 , base + stm32_bank -> emr_ofst );
311
+ writel_relaxed (0 , base + stm32_bank -> rtsr_ofst );
312
+ writel_relaxed (0 , base + stm32_bank -> ftsr_ofst );
313
+ writel_relaxed (~0UL , base + stm32_bank -> rpr_ofst );
314
+ if (stm32_bank -> fpr_ofst != UNDEF_REG )
315
+ writel_relaxed (~0UL , base + stm32_bank -> fpr_ofst );
316
+
317
+ pr_info ("%s: bank%d, External IRQs available:%#x\n" ,
318
+ node -> full_name , bank_idx , irqs_mask );
319
+
320
+ return chip_data ;
321
+ }
322
+
323
+ static int __init stm32_exti_init (const struct stm32_exti_drv_data * drv_data ,
324
+ struct device_node * node )
244
325
{
326
+ struct stm32_exti_host_data * host_data ;
245
327
unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN ;
246
- int nr_irqs , nr_exti , ret , i ;
328
+ int nr_irqs , ret , i ;
247
329
struct irq_chip_generic * gc ;
248
330
struct irq_domain * domain ;
249
- void * base ;
250
331
251
- base = of_iomap ( node , 0 );
252
- if (!base ) {
253
- pr_err ( "%pOF: Unable to map registers\n" , node ) ;
254
- return - ENOMEM ;
332
+ host_data = stm32_exti_host_init ( drv_data , node );
333
+ if (!host_data ) {
334
+ ret = - ENOMEM ;
335
+ goto out_free_mem ;
255
336
}
256
337
257
- stm32_exti_data = kcalloc (bank_nr , sizeof (* stm32_exti_data ),
258
- GFP_KERNEL );
259
- if (!stm32_exti_data )
260
- return - ENOMEM ;
261
-
262
- domain = irq_domain_add_linear (node , bank_nr * IRQS_PER_BANK ,
338
+ domain = irq_domain_add_linear (node , drv_data -> bank_nr * IRQS_PER_BANK ,
263
339
& irq_exti_domain_ops , NULL );
264
340
if (!domain ) {
265
341
pr_err ("%s: Could not register interrupt domain.\n" ,
@@ -276,16 +352,16 @@ __init stm32_exti_init(const struct stm32_exti_bank **stm32_exti_banks,
276
352
goto out_free_domain ;
277
353
}
278
354
279
- for (i = 0 ; i < bank_nr ; i ++ ) {
280
- const struct stm32_exti_bank * stm32_bank = stm32_exti_banks [i ];
281
- struct stm32_exti_chip_data * chip_data = & stm32_exti_data [i ];
282
- u32 irqs_mask ;
355
+ for (i = 0 ; i < drv_data -> bank_nr ; i ++ ) {
356
+ const struct stm32_exti_bank * stm32_bank ;
357
+ struct stm32_exti_chip_data * chip_data ;
283
358
284
- chip_data -> reg_bank = stm32_bank ;
359
+ stm32_bank = drv_data -> exti_banks [i ];
360
+ chip_data = stm32_exti_chip_init (host_data , i , node );
285
361
286
362
gc = irq_get_domain_generic_chip (domain , i * IRQS_PER_BANK );
287
363
288
- gc -> reg_base = base ;
364
+ gc -> reg_base = host_data -> base ;
289
365
gc -> chip_types -> type = IRQ_TYPE_EDGE_BOTH ;
290
366
gc -> chip_types -> chip .irq_ack = stm32_irq_ack ;
291
367
gc -> chip_types -> chip .irq_mask = irq_gc_mask_clr_bit ;
@@ -298,26 +374,6 @@ __init stm32_exti_init(const struct stm32_exti_bank **stm32_exti_banks,
298
374
299
375
gc -> chip_types -> regs .mask = stm32_bank -> imr_ofst ;
300
376
gc -> private = (void * )chip_data ;
301
-
302
- /* Determine number of irqs supported */
303
- writel_relaxed (~0UL , base + stm32_bank -> rtsr_ofst );
304
- irqs_mask = readl_relaxed (base + stm32_bank -> rtsr_ofst );
305
- nr_exti = fls (readl_relaxed (base + stm32_bank -> rtsr_ofst ));
306
-
307
- /*
308
- * This IP has no reset, so after hot reboot we should
309
- * clear registers to avoid residue
310
- */
311
- writel_relaxed (0 , base + stm32_bank -> imr_ofst );
312
- writel_relaxed (0 , base + stm32_bank -> emr_ofst );
313
- writel_relaxed (0 , base + stm32_bank -> rtsr_ofst );
314
- writel_relaxed (0 , base + stm32_bank -> ftsr_ofst );
315
- writel_relaxed (~0UL , base + stm32_bank -> rpr_ofst );
316
- if (stm32_bank -> fpr_ofst != UNDEF_REG )
317
- writel_relaxed (~0UL , base + stm32_bank -> fpr_ofst );
318
-
319
- pr_info ("%s: bank%d, External IRQs available:%#x\n" ,
320
- node -> full_name , i , irqs_mask );
321
377
}
322
378
323
379
nr_irqs = of_irq_count (node );
@@ -333,25 +389,25 @@ __init stm32_exti_init(const struct stm32_exti_bank **stm32_exti_banks,
333
389
out_free_domain :
334
390
irq_domain_remove (domain );
335
391
out_unmap :
336
- iounmap (base );
337
- kfree (stm32_exti_data );
392
+ iounmap (host_data -> base );
393
+ out_free_mem :
394
+ kfree (host_data -> chips_data );
395
+ kfree (host_data );
338
396
return ret ;
339
397
}
340
398
341
399
static int __init stm32f4_exti_of_init (struct device_node * np ,
342
400
struct device_node * parent )
343
401
{
344
- return stm32_exti_init (stm32f4xx_exti_banks ,
345
- ARRAY_SIZE (stm32f4xx_exti_banks ), np );
402
+ return stm32_exti_init (& stm32f4xx_drv_data , np );
346
403
}
347
404
348
405
IRQCHIP_DECLARE (stm32f4_exti , "st,stm32-exti" , stm32f4_exti_of_init );
349
406
350
407
static int __init stm32h7_exti_of_init (struct device_node * np ,
351
408
struct device_node * parent )
352
409
{
353
- return stm32_exti_init (stm32h7xx_exti_banks ,
354
- ARRAY_SIZE (stm32h7xx_exti_banks ), np );
410
+ return stm32_exti_init (& stm32h7xx_drv_data , np );
355
411
}
356
412
357
413
IRQCHIP_DECLARE (stm32h7_exti , "st,stm32h7-exti" , stm32h7_exti_of_init );
0 commit comments