2727#include <linux/types.h>
2828#include <linux/irqchip.h>
2929#include <linux/irqchip/chained_irq.h>
30+ #include <linux/syscore_ops.h>
3031
3132#define IRQS_PER_WORD 32
3233#define REG_BYTES_PER_IRQ_WORD (sizeof(u32) * 4)
@@ -39,6 +40,11 @@ struct bcm7038_l1_chip {
3940 unsigned int n_words ;
4041 struct irq_domain * domain ;
4142 struct bcm7038_l1_cpu * cpus [NR_CPUS ];
43+ #ifdef CONFIG_PM_SLEEP
44+ struct list_head list ;
45+ u32 wake_mask [MAX_WORDS ];
46+ #endif
47+ u32 irq_fwd_mask [MAX_WORDS ];
4248 u8 affinity [MAX_WORDS * IRQS_PER_WORD ];
4349};
4450
@@ -249,6 +255,7 @@ static int __init bcm7038_l1_init_one(struct device_node *dn,
249255 resource_size_t sz ;
250256 struct bcm7038_l1_cpu * cpu ;
251257 unsigned int i , n_words , parent_irq ;
258+ int ret ;
252259
253260 if (of_address_to_resource (dn , idx , & res ))
254261 return - EINVAL ;
@@ -262,6 +269,14 @@ static int __init bcm7038_l1_init_one(struct device_node *dn,
262269 else if (intc -> n_words != n_words )
263270 return - EINVAL ;
264271
272+ ret = of_property_read_u32_array (dn , "brcm,int-fwd-mask" ,
273+ intc -> irq_fwd_mask , n_words );
274+ if (ret != 0 && ret != - EINVAL ) {
275+ /* property exists but has the wrong number of words */
276+ pr_err ("invalid brcm,int-fwd-mask property\n" );
277+ return - EINVAL ;
278+ }
279+
265280 cpu = intc -> cpus [idx ] = kzalloc (sizeof (* cpu ) + n_words * sizeof (u32 ),
266281 GFP_KERNEL );
267282 if (!cpu )
@@ -272,21 +287,101 @@ static int __init bcm7038_l1_init_one(struct device_node *dn,
272287 return - ENOMEM ;
273288
274289 for (i = 0 ; i < n_words ; i ++ ) {
275- l1_writel (0xffffffff , cpu -> map_base + reg_mask_set (intc , i ));
276- cpu -> mask_cache [i ] = 0xffffffff ;
290+ l1_writel (~intc -> irq_fwd_mask [i ],
291+ cpu -> map_base + reg_mask_set (intc , i ));
292+ l1_writel (intc -> irq_fwd_mask [i ],
293+ cpu -> map_base + reg_mask_clr (intc , i ));
294+ cpu -> mask_cache [i ] = ~intc -> irq_fwd_mask [i ];
277295 }
278296
279297 parent_irq = irq_of_parse_and_map (dn , idx );
280298 if (!parent_irq ) {
281299 pr_err ("failed to map parent interrupt %d\n" , parent_irq );
282300 return - EINVAL ;
283301 }
302+
303+ if (of_property_read_bool (dn , "brcm,irq-can-wake" ))
304+ enable_irq_wake (parent_irq );
305+
284306 irq_set_chained_handler_and_data (parent_irq , bcm7038_l1_irq_handle ,
285307 intc );
286308
287309 return 0 ;
288310}
289311
312+ #ifdef CONFIG_PM_SLEEP
313+ /*
314+ * We keep a list of bcm7038_l1_chip used for suspend/resume. This hack is
315+ * used because the struct chip_type suspend/resume hooks are not called
316+ * unless chip_type is hooked onto a generic_chip. Since this driver does
317+ * not use generic_chip, we need to manually hook our resume/suspend to
318+ * syscore_ops.
319+ */
320+ static LIST_HEAD (bcm7038_l1_intcs_list );
321+ static DEFINE_RAW_SPINLOCK (bcm7038_l1_intcs_lock );
322+
323+ static int bcm7038_l1_suspend (void )
324+ {
325+ struct bcm7038_l1_chip * intc ;
326+ int boot_cpu , word ;
327+ u32 val ;
328+
329+ /* Wakeup interrupt should only come from the boot cpu */
330+ boot_cpu = cpu_logical_map (0 );
331+
332+ list_for_each_entry (intc , & bcm7038_l1_intcs_list , list ) {
333+ for (word = 0 ; word < intc -> n_words ; word ++ ) {
334+ val = intc -> wake_mask [word ] | intc -> irq_fwd_mask [word ];
335+ l1_writel (~val ,
336+ intc -> cpus [boot_cpu ]-> map_base + reg_mask_set (intc , word ));
337+ l1_writel (val ,
338+ intc -> cpus [boot_cpu ]-> map_base + reg_mask_clr (intc , word ));
339+ }
340+ }
341+
342+ return 0 ;
343+ }
344+
345+ static void bcm7038_l1_resume (void )
346+ {
347+ struct bcm7038_l1_chip * intc ;
348+ int boot_cpu , word ;
349+
350+ boot_cpu = cpu_logical_map (0 );
351+
352+ list_for_each_entry (intc , & bcm7038_l1_intcs_list , list ) {
353+ for (word = 0 ; word < intc -> n_words ; word ++ ) {
354+ l1_writel (intc -> cpus [boot_cpu ]-> mask_cache [word ],
355+ intc -> cpus [boot_cpu ]-> map_base + reg_mask_set (intc , word ));
356+ l1_writel (~intc -> cpus [boot_cpu ]-> mask_cache [word ],
357+ intc -> cpus [boot_cpu ]-> map_base + reg_mask_clr (intc , word ));
358+ }
359+ }
360+ }
361+
362+ static struct syscore_ops bcm7038_l1_syscore_ops = {
363+ .suspend = bcm7038_l1_suspend ,
364+ .resume = bcm7038_l1_resume ,
365+ };
366+
367+ static int bcm7038_l1_set_wake (struct irq_data * d , unsigned int on )
368+ {
369+ struct bcm7038_l1_chip * intc = irq_data_get_irq_chip_data (d );
370+ unsigned long flags ;
371+ u32 word = d -> hwirq / IRQS_PER_WORD ;
372+ u32 mask = BIT (d -> hwirq % IRQS_PER_WORD );
373+
374+ raw_spin_lock_irqsave (& intc -> lock , flags );
375+ if (on )
376+ intc -> wake_mask [word ] |= mask ;
377+ else
378+ intc -> wake_mask [word ] &= ~mask ;
379+ raw_spin_unlock_irqrestore (& intc -> lock , flags );
380+
381+ return 0 ;
382+ }
383+ #endif
384+
290385static struct irq_chip bcm7038_l1_irq_chip = {
291386 .name = "bcm7038-l1" ,
292387 .irq_mask = bcm7038_l1_mask ,
@@ -295,11 +390,21 @@ static struct irq_chip bcm7038_l1_irq_chip = {
295390#ifdef CONFIG_SMP
296391 .irq_cpu_offline = bcm7038_l1_cpu_offline ,
297392#endif
393+ #ifdef CONFIG_PM_SLEEP
394+ .irq_set_wake = bcm7038_l1_set_wake ,
395+ #endif
298396};
299397
300398static int bcm7038_l1_map (struct irq_domain * d , unsigned int virq ,
301399 irq_hw_number_t hw_irq )
302400{
401+ struct bcm7038_l1_chip * intc = d -> host_data ;
402+ u32 mask = BIT (hw_irq % IRQS_PER_WORD );
403+ u32 word = hw_irq / IRQS_PER_WORD ;
404+
405+ if (intc -> irq_fwd_mask [word ] & mask )
406+ return - EPERM ;
407+
303408 irq_set_chip_and_handler (virq , & bcm7038_l1_irq_chip , handle_level_irq );
304409 irq_set_chip_data (virq , d -> host_data );
305410 irqd_set_single_target (irq_desc_get_irq_data (irq_to_desc (virq )));
@@ -340,6 +445,16 @@ int __init bcm7038_l1_of_init(struct device_node *dn,
340445 goto out_unmap ;
341446 }
342447
448+ #ifdef CONFIG_PM_SLEEP
449+ /* Add bcm7038_l1_chip into a list */
450+ raw_spin_lock (& bcm7038_l1_intcs_lock );
451+ list_add_tail (& intc -> list , & bcm7038_l1_intcs_list );
452+ raw_spin_unlock (& bcm7038_l1_intcs_lock );
453+
454+ if (list_is_singular (& bcm7038_l1_intcs_list ))
455+ register_syscore_ops (& bcm7038_l1_syscore_ops );
456+ #endif
457+
343458 pr_info ("registered BCM7038 L1 intc (%pOF, IRQs: %d)\n" ,
344459 dn , IRQS_PER_WORD * intc -> n_words );
345460
0 commit comments