19 #include <linux/kernel.h>
37 #define MAX_NR_REG_BANKS 5
39 #define WKG_MASK_ALL 0x00000000
40 #define WKG_UNMASK_ALL 0xffffffff
41 #define CPU_ENA_OFFSET 0x400
44 #define OMAP4_NR_BANKS 4
45 #define OMAP4_NR_IRQS 128
47 static void __iomem *wakeupgen_base;
50 static unsigned int irq_target_cpu[
MAX_IRQS];
52 static unsigned int max_irqs =
MAX_IRQS;
53 static unsigned int omap_secure_apis;
64 static inline void wakeupgen_writel(
u32 val,
u8 idx,
u32 cpu)
75 static inline int _wakeupgen_get_irq_info(
u32 irq,
u32 *bit_posn,
u8 *reg_index)
90 pr_err(
"omap wakeupGen: Invalid IRQ%d\n", irq);
98 *reg_index = spi_irq >> 5;
99 *bit_posn = spi_irq %= 32;
104 static void _wakeupgen_clear(
unsigned int irq,
unsigned int cpu)
109 if (_wakeupgen_get_irq_info(irq, &bit_number, &i))
112 val = wakeupgen_readl(i, cpu);
113 val &= ~
BIT(bit_number);
114 wakeupgen_writel(val, i, cpu);
117 static void _wakeupgen_set(
unsigned int irq,
unsigned int cpu)
122 if (_wakeupgen_get_irq_info(irq, &bit_number, &i))
125 val = wakeupgen_readl(i, cpu);
126 val |=
BIT(bit_number);
127 wakeupgen_writel(val, i, cpu);
133 static void wakeupgen_mask(
struct irq_data *
d)
138 _wakeupgen_clear(d->
irq, irq_target_cpu[d->
irq]);
139 spin_unlock_irqrestore(&wakeupgen_lock, flags);
145 static void wakeupgen_unmask(
struct irq_data *
d)
150 _wakeupgen_set(d->
irq, irq_target_cpu[d->
irq]);
151 spin_unlock_irqrestore(&wakeupgen_lock, flags);
154 #ifdef CONFIG_HOTPLUG_CPU
157 static void _wakeupgen_save_masks(
unsigned int cpu)
161 for (i = 0; i < irq_banks; i++)
162 per_cpu(irqmasks, cpu)[
i] = wakeupgen_readl(i, cpu);
165 static void _wakeupgen_restore_masks(
unsigned int cpu)
169 for (i = 0; i < irq_banks; i++)
170 wakeupgen_writel(
per_cpu(irqmasks, cpu)[i], i, cpu);
173 static void _wakeupgen_set_all(
unsigned int cpu,
unsigned int reg)
177 for (i = 0; i < irq_banks; i++)
178 wakeupgen_writel(reg, i, cpu);
188 static void wakeupgen_irqmask_all(
unsigned int cpu,
unsigned int set)
194 _wakeupgen_save_masks(cpu);
198 _wakeupgen_restore_masks(cpu);
200 spin_unlock_irqrestore(&wakeupgen_lock, flags);
205 static inline void omap4_irq_save_context(
void)
212 for (i = 0; i < irq_banks; i++) {
214 val = wakeupgen_readl(i, 0);
216 val = wakeupgen_readl(i, 1);
249 static inline void omap5_irq_save_context(
void)
253 for (i = 0; i < irq_banks; i++) {
255 val = wakeupgen_readl(i, 0);
257 val = wakeupgen_readl(i, 1);
284 static void irq_save_context(
void)
290 omap5_irq_save_context();
292 omap4_irq_save_context();
298 static void irq_sar_clear(
void)
315 static void irq_save_secure_context(
void)
322 pr_err(
"GIC and Wakeupgen context save failed\n");
326 #ifdef CONFIG_HOTPLUG_CPU
328 unsigned long action,
void *hcpu)
330 unsigned int cpu = (
unsigned int)hcpu;
334 wakeupgen_irqmask_all(cpu, 0);
337 wakeupgen_irqmask_all(cpu, 1);
344 .notifier_call = irq_cpu_hotplug_notify,
347 static void __init irq_hotplug_init(
void)
352 static void __init irq_hotplug_init(
void)
364 irq_save_secure_context();
378 static void __init irq_pm_init(
void)
385 static void __init irq_pm_init(
void)
391 return wakeupgen_base;
396 return omap_secure_apis;
409 WARN(1,
"WakeupGen: Not supported on OMAP4430 ES1.0\n");
421 omap_secure_apis = 1;
425 for (i = 0; i < irq_banks; i++) {
426 wakeupgen_writel(0, i,
CPU0_ID);
427 wakeupgen_writel(0, i,
CPU1_ID);
444 for (i = 0; i < max_irqs; i++)
445 irq_target_cpu[i] = boot_cpu;