blob: e1d2e991d17a31fc15f1c44616c9b4b7f9de3a84 [file] [log] [blame]
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +05301/*
2 * OMAP WakeupGen Source file
3 *
4 * OMAP WakeupGen is the interrupt controller extension used along
5 * with ARM GIC to wake the CPU out from low power states on
6 * external interrupts. It is responsible for generating wakeup
7 * event from the incoming interrupts and enable bits. It is
8 * implemented in MPU always ON power domain. During normal operation,
9 * WakeupGen delivers external interrupts directly to the GIC.
10 *
11 * Copyright (C) 2011 Texas Instruments, Inc.
12 * Santosh Shilimkar <santosh.shilimkar@ti.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/io.h>
22#include <linux/irq.h>
Marc Zyngier7136d452015-03-11 15:43:49 +000023#include <linux/irqdomain.h>
24#include <linux/of_address.h>
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053025#include <linux/platform_device.h>
26#include <linux/cpu.h>
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +053027#include <linux/notifier.h>
28#include <linux/cpu_pm.h>
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053029
Tony Lindgren732231a2012-09-20 11:41:16 -070030#include "omap-wakeupgen.h"
Tony Lindgrenc1db9d72012-09-20 11:41:14 -070031#include "omap-secure.h"
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +053032
Tony Lindgrendbc04162012-08-31 10:59:07 -070033#include "soc.h"
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +053034#include "omap4-sar-layout.h"
35#include "common.h"
Rajendra Nayak6099dd32013-05-27 15:46:44 +053036#include "pm.h"
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053037
Afzal Mohammed6246cd02013-10-09 12:42:33 +053038#define AM43XX_NR_REG_BANKS 7
39#define AM43XX_IRQS 224
40#define MAX_NR_REG_BANKS AM43XX_NR_REG_BANKS
41#define MAX_IRQS AM43XX_IRQS
42#define DEFAULT_NR_REG_BANKS 5
43#define DEFAULT_IRQS 160
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053044#define WKG_MASK_ALL 0x00000000
45#define WKG_UNMASK_ALL 0xffffffff
46#define CPU_ENA_OFFSET 0x400
47#define CPU0_ID 0x0
48#define CPU1_ID 0x1
Santosh Shilimkar247c4452012-05-09 20:38:35 +053049#define OMAP4_NR_BANKS 4
50#define OMAP4_NR_IRQS 128
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053051
52static void __iomem *wakeupgen_base;
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +053053static void __iomem *sar_base;
Thomas Gleixneraecb9e12012-12-07 16:49:47 +020054static DEFINE_RAW_SPINLOCK(wakeupgen_lock);
Tony Lindgrene534e872012-09-04 17:22:45 -070055static unsigned int irq_target_cpu[MAX_IRQS];
Afzal Mohammed6246cd02013-10-09 12:42:33 +053056static unsigned int irq_banks = DEFAULT_NR_REG_BANKS;
57static unsigned int max_irqs = DEFAULT_IRQS;
Santosh Shilimkar247c4452012-05-09 20:38:35 +053058static unsigned int omap_secure_apis;
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053059
60/*
61 * Static helper functions.
62 */
63static inline u32 wakeupgen_readl(u8 idx, u32 cpu)
64{
Victor Kamenskyedfaf052014-04-15 20:37:46 +030065 return readl_relaxed(wakeupgen_base + OMAP_WKG_ENB_A_0 +
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053066 (cpu * CPU_ENA_OFFSET) + (idx * 4));
67}
68
69static inline void wakeupgen_writel(u32 val, u8 idx, u32 cpu)
70{
Victor Kamenskyedfaf052014-04-15 20:37:46 +030071 writel_relaxed(val, wakeupgen_base + OMAP_WKG_ENB_A_0 +
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053072 (cpu * CPU_ENA_OFFSET) + (idx * 4));
73}
74
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +053075static inline void sar_writel(u32 val, u32 offset, u8 idx)
76{
Victor Kamenskyedfaf052014-04-15 20:37:46 +030077 writel_relaxed(val, sar_base + offset + (idx * 4));
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +053078}
79
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053080static inline int _wakeupgen_get_irq_info(u32 irq, u32 *bit_posn, u8 *reg_index)
81{
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053082 /*
83 * Each WakeupGen register controls 32 interrupt.
84 * i.e. 1 bit per SPI IRQ
85 */
Marc Zyngier7136d452015-03-11 15:43:49 +000086 *reg_index = irq >> 5;
87 *bit_posn = irq %= 32;
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +053088
89 return 0;
90}
91
92static void _wakeupgen_clear(unsigned int irq, unsigned int cpu)
93{
94 u32 val, bit_number;
95 u8 i;
96
97 if (_wakeupgen_get_irq_info(irq, &bit_number, &i))
98 return;
99
100 val = wakeupgen_readl(i, cpu);
101 val &= ~BIT(bit_number);
102 wakeupgen_writel(val, i, cpu);
103}
104
105static void _wakeupgen_set(unsigned int irq, unsigned int cpu)
106{
107 u32 val, bit_number;
108 u8 i;
109
110 if (_wakeupgen_get_irq_info(irq, &bit_number, &i))
111 return;
112
113 val = wakeupgen_readl(i, cpu);
114 val |= BIT(bit_number);
115 wakeupgen_writel(val, i, cpu);
116}
117
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530118/*
119 * Architecture specific Mask extension
120 */
121static void wakeupgen_mask(struct irq_data *d)
122{
123 unsigned long flags;
124
Thomas Gleixneraecb9e12012-12-07 16:49:47 +0200125 raw_spin_lock_irqsave(&wakeupgen_lock, flags);
Sricharan R1cc4b1a92013-12-03 15:57:24 +0530126 _wakeupgen_clear(d->hwirq, irq_target_cpu[d->hwirq]);
Thomas Gleixneraecb9e12012-12-07 16:49:47 +0200127 raw_spin_unlock_irqrestore(&wakeupgen_lock, flags);
Marc Zyngier7136d452015-03-11 15:43:49 +0000128 irq_chip_mask_parent(d);
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530129}
130
131/*
132 * Architecture specific Unmask extension
133 */
134static void wakeupgen_unmask(struct irq_data *d)
135{
136 unsigned long flags;
137
Thomas Gleixneraecb9e12012-12-07 16:49:47 +0200138 raw_spin_lock_irqsave(&wakeupgen_lock, flags);
Sricharan R1cc4b1a92013-12-03 15:57:24 +0530139 _wakeupgen_set(d->hwirq, irq_target_cpu[d->hwirq]);
Thomas Gleixneraecb9e12012-12-07 16:49:47 +0200140 raw_spin_unlock_irqrestore(&wakeupgen_lock, flags);
Marc Zyngier7136d452015-03-11 15:43:49 +0000141 irq_chip_unmask_parent(d);
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530142}
143
Kevin Hilmanbb1dbe72012-03-06 12:00:25 -0800144#ifdef CONFIG_HOTPLUG_CPU
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530145static DEFINE_PER_CPU(u32 [MAX_NR_REG_BANKS], irqmasks);
Kevin Hilmanbb1dbe72012-03-06 12:00:25 -0800146
147static void _wakeupgen_save_masks(unsigned int cpu)
148{
149 u8 i;
150
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530151 for (i = 0; i < irq_banks; i++)
Kevin Hilmanbb1dbe72012-03-06 12:00:25 -0800152 per_cpu(irqmasks, cpu)[i] = wakeupgen_readl(i, cpu);
153}
154
155static void _wakeupgen_restore_masks(unsigned int cpu)
156{
157 u8 i;
158
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530159 for (i = 0; i < irq_banks; i++)
Kevin Hilmanbb1dbe72012-03-06 12:00:25 -0800160 wakeupgen_writel(per_cpu(irqmasks, cpu)[i], i, cpu);
161}
162
163static void _wakeupgen_set_all(unsigned int cpu, unsigned int reg)
164{
165 u8 i;
166
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530167 for (i = 0; i < irq_banks; i++)
Kevin Hilmanbb1dbe72012-03-06 12:00:25 -0800168 wakeupgen_writel(reg, i, cpu);
169}
170
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530171/*
172 * Mask or unmask all interrupts on given CPU.
173 * 0 = Mask all interrupts on the 'cpu'
174 * 1 = Unmask all interrupts on the 'cpu'
175 * Ensure that the initial mask is maintained. This is faster than
176 * iterating through GIC registers to arrive at the correct masks.
177 */
178static void wakeupgen_irqmask_all(unsigned int cpu, unsigned int set)
179{
180 unsigned long flags;
181
Thomas Gleixneraecb9e12012-12-07 16:49:47 +0200182 raw_spin_lock_irqsave(&wakeupgen_lock, flags);
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530183 if (set) {
184 _wakeupgen_save_masks(cpu);
185 _wakeupgen_set_all(cpu, WKG_MASK_ALL);
186 } else {
187 _wakeupgen_set_all(cpu, WKG_UNMASK_ALL);
188 _wakeupgen_restore_masks(cpu);
189 }
Thomas Gleixneraecb9e12012-12-07 16:49:47 +0200190 raw_spin_unlock_irqrestore(&wakeupgen_lock, flags);
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530191}
Kevin Hilmanbb1dbe72012-03-06 12:00:25 -0800192#endif
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530193
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530194#ifdef CONFIG_CPU_PM
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530195static inline void omap4_irq_save_context(void)
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530196{
197 u32 i, val;
198
199 if (omap_rev() == OMAP4430_REV_ES1_0)
200 return;
201
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530202 for (i = 0; i < irq_banks; i++) {
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530203 /* Save the CPUx interrupt mask for IRQ 0 to 127 */
204 val = wakeupgen_readl(i, 0);
205 sar_writel(val, WAKEUPGENENB_OFFSET_CPU0, i);
206 val = wakeupgen_readl(i, 1);
207 sar_writel(val, WAKEUPGENENB_OFFSET_CPU1, i);
208
209 /*
210 * Disable the secure interrupts for CPUx. The restore
211 * code blindly restores secure and non-secure interrupt
212 * masks from SAR RAM. Secure interrupts are not suppose
213 * to be enabled from HLOS. So overwrite the SAR location
214 * so that the secure interrupt remains disabled.
215 */
216 sar_writel(0x0, WAKEUPGENENB_SECURE_OFFSET_CPU0, i);
217 sar_writel(0x0, WAKEUPGENENB_SECURE_OFFSET_CPU1, i);
218 }
219
220 /* Save AuxBoot* registers */
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300221 val = readl_relaxed(wakeupgen_base + OMAP_AUX_CORE_BOOT_0);
222 writel_relaxed(val, sar_base + AUXCOREBOOT0_OFFSET);
223 val = readl_relaxed(wakeupgen_base + OMAP_AUX_CORE_BOOT_1);
224 writel_relaxed(val, sar_base + AUXCOREBOOT1_OFFSET);
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530225
226 /* Save SyncReq generation logic */
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300227 val = readl_relaxed(wakeupgen_base + OMAP_PTMSYNCREQ_MASK);
228 writel_relaxed(val, sar_base + PTMSYNCREQ_MASK_OFFSET);
229 val = readl_relaxed(wakeupgen_base + OMAP_PTMSYNCREQ_EN);
230 writel_relaxed(val, sar_base + PTMSYNCREQ_EN_OFFSET);
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530231
232 /* Set the Backup Bit Mask status */
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300233 val = readl_relaxed(sar_base + SAR_BACKUP_STATUS_OFFSET);
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530234 val |= SAR_BACKUP_STATUS_WAKEUPGEN;
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300235 writel_relaxed(val, sar_base + SAR_BACKUP_STATUS_OFFSET);
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530236
237}
238
239static inline void omap5_irq_save_context(void)
240{
241 u32 i, val;
242
243 for (i = 0; i < irq_banks; i++) {
244 /* Save the CPUx interrupt mask for IRQ 0 to 159 */
245 val = wakeupgen_readl(i, 0);
246 sar_writel(val, OMAP5_WAKEUPGENENB_OFFSET_CPU0, i);
247 val = wakeupgen_readl(i, 1);
248 sar_writel(val, OMAP5_WAKEUPGENENB_OFFSET_CPU1, i);
249 sar_writel(0x0, OMAP5_WAKEUPGENENB_SECURE_OFFSET_CPU0, i);
250 sar_writel(0x0, OMAP5_WAKEUPGENENB_SECURE_OFFSET_CPU1, i);
251 }
252
253 /* Save AuxBoot* registers */
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300254 val = readl_relaxed(wakeupgen_base + OMAP_AUX_CORE_BOOT_0);
255 writel_relaxed(val, sar_base + OMAP5_AUXCOREBOOT0_OFFSET);
256 val = readl_relaxed(wakeupgen_base + OMAP_AUX_CORE_BOOT_0);
257 writel_relaxed(val, sar_base + OMAP5_AUXCOREBOOT1_OFFSET);
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530258
259 /* Set the Backup Bit Mask status */
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300260 val = readl_relaxed(sar_base + OMAP5_SAR_BACKUP_STATUS_OFFSET);
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530261 val |= SAR_BACKUP_STATUS_WAKEUPGEN;
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300262 writel_relaxed(val, sar_base + OMAP5_SAR_BACKUP_STATUS_OFFSET);
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530263
264}
265
266/*
267 * Save WakeupGen interrupt context in SAR BANK3. Restore is done by
268 * ROM code. WakeupGen IP is integrated along with GIC to manage the
269 * interrupt wakeups from CPU low power states. It manages
270 * masking/unmasking of Shared peripheral interrupts(SPI). So the
271 * interrupt enable/disable control should be in sync and consistent
272 * at WakeupGen and GIC so that interrupts are not lost.
273 */
274static void irq_save_context(void)
275{
276 if (!sar_base)
277 sar_base = omap4_get_sar_ram_base();
278
279 if (soc_is_omap54xx())
280 omap5_irq_save_context();
281 else
282 omap4_irq_save_context();
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530283}
284
285/*
286 * Clear WakeupGen SAR backup status.
287 */
Paul Walmsley8c3d4532012-04-13 06:34:26 -0600288static void irq_sar_clear(void)
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530289{
290 u32 val;
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530291 u32 offset = SAR_BACKUP_STATUS_OFFSET;
292
293 if (soc_is_omap54xx())
294 offset = OMAP5_SAR_BACKUP_STATUS_OFFSET;
295
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300296 val = readl_relaxed(sar_base + offset);
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530297 val &= ~SAR_BACKUP_STATUS_WAKEUPGEN;
Victor Kamenskyedfaf052014-04-15 20:37:46 +0300298 writel_relaxed(val, sar_base + offset);
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530299}
300
301/*
302 * Save GIC and Wakeupgen interrupt context using secure API
303 * for HS/EMU devices.
304 */
305static void irq_save_secure_context(void)
306{
307 u32 ret;
308 ret = omap_secure_dispatcher(OMAP4_HAL_SAVEGIC_INDEX,
309 FLAG_START_CRITICAL,
310 0, 0, 0, 0, 0);
311 if (ret != API_HAL_RET_VALUE_OK)
312 pr_err("GIC and Wakeupgen context save failed\n");
313}
314#endif
315
Santosh Shilimkarb5b4f282010-06-16 22:19:48 +0530316#ifdef CONFIG_HOTPLUG_CPU
Paul Gortmaker8bd26e32013-06-17 15:43:14 -0400317static int irq_cpu_hotplug_notify(struct notifier_block *self,
318 unsigned long action, void *hcpu)
Santosh Shilimkarb5b4f282010-06-16 22:19:48 +0530319{
320 unsigned int cpu = (unsigned int)hcpu;
321
322 switch (action) {
323 case CPU_ONLINE:
324 wakeupgen_irqmask_all(cpu, 0);
325 break;
326 case CPU_DEAD:
327 wakeupgen_irqmask_all(cpu, 1);
328 break;
329 }
330 return NOTIFY_OK;
331}
332
333static struct notifier_block __refdata irq_hotplug_notifier = {
334 .notifier_call = irq_cpu_hotplug_notify,
335};
336
337static void __init irq_hotplug_init(void)
338{
339 register_hotcpu_notifier(&irq_hotplug_notifier);
340}
341#else
342static void __init irq_hotplug_init(void)
343{}
344#endif
345
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530346#ifdef CONFIG_CPU_PM
347static int irq_notifier(struct notifier_block *self, unsigned long cmd, void *v)
348{
349 switch (cmd) {
350 case CPU_CLUSTER_PM_ENTER:
351 if (omap_type() == OMAP2_DEVICE_TYPE_GP)
352 irq_save_context();
353 else
354 irq_save_secure_context();
355 break;
356 case CPU_CLUSTER_PM_EXIT:
357 if (omap_type() == OMAP2_DEVICE_TYPE_GP)
358 irq_sar_clear();
359 break;
360 }
361 return NOTIFY_OK;
362}
363
364static struct notifier_block irq_notifier_block = {
365 .notifier_call = irq_notifier,
366};
367
368static void __init irq_pm_init(void)
369{
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530370 /* FIXME: Remove this when MPU OSWR support is added */
Rajendra Nayak6099dd32013-05-27 15:46:44 +0530371 if (!IS_PM44XX_ERRATUM(PM_OMAP4_CPU_OSWR_DISABLE))
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530372 cpu_pm_register_notifier(&irq_notifier_block);
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530373}
374#else
375static void __init irq_pm_init(void)
376{}
377#endif
378
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530379void __iomem *omap_get_wakeupgen_base(void)
380{
381 return wakeupgen_base;
382}
383
384int omap_secure_apis_support(void)
385{
386 return omap_secure_apis;
387}
388
Marc Zyngier7136d452015-03-11 15:43:49 +0000389static struct irq_chip wakeupgen_chip = {
390 .name = "WUGEN",
391 .irq_eoi = irq_chip_eoi_parent,
392 .irq_mask = wakeupgen_mask,
393 .irq_unmask = wakeupgen_unmask,
394 .irq_retrigger = irq_chip_retrigger_hierarchy,
Grygorii Strashko63059a22015-08-14 15:20:28 +0300395 .irq_set_type = irq_chip_set_type_parent,
Marc Zyngier7136d452015-03-11 15:43:49 +0000396 .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND,
397#ifdef CONFIG_SMP
398 .irq_set_affinity = irq_chip_set_affinity_parent,
399#endif
400};
401
402static int wakeupgen_domain_xlate(struct irq_domain *domain,
403 struct device_node *controller,
404 const u32 *intspec,
405 unsigned int intsize,
406 unsigned long *out_hwirq,
407 unsigned int *out_type)
408{
409 if (domain->of_node != controller)
410 return -EINVAL; /* Shouldn't happen, really... */
411 if (intsize != 3)
412 return -EINVAL; /* Not GIC compliant */
413 if (intspec[0] != 0)
414 return -EINVAL; /* No PPI should point to this domain */
415
416 *out_hwirq = intspec[1];
417 *out_type = intspec[2];
418 return 0;
419}
420
421static int wakeupgen_domain_alloc(struct irq_domain *domain,
422 unsigned int virq,
423 unsigned int nr_irqs, void *data)
424{
425 struct of_phandle_args *args = data;
426 struct of_phandle_args parent_args;
427 irq_hw_number_t hwirq;
428 int i;
429
430 if (args->args_count != 3)
431 return -EINVAL; /* Not GIC compliant */
432 if (args->args[0] != 0)
433 return -EINVAL; /* No PPI should point to this domain */
434
435 hwirq = args->args[1];
436 if (hwirq >= MAX_IRQS)
437 return -EINVAL; /* Can't deal with this */
438
439 for (i = 0; i < nr_irqs; i++)
440 irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
441 &wakeupgen_chip, NULL);
442
443 parent_args = *args;
444 parent_args.np = domain->parent->of_node;
445 return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &parent_args);
446}
447
Krzysztof Kozlowski82979552015-04-27 21:49:44 +0900448static const struct irq_domain_ops wakeupgen_domain_ops = {
Marc Zyngier7136d452015-03-11 15:43:49 +0000449 .xlate = wakeupgen_domain_xlate,
450 .alloc = wakeupgen_domain_alloc,
451 .free = irq_domain_free_irqs_common,
452};
453
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530454/*
455 * Initialise the wakeupgen module.
456 */
Marc Zyngier7136d452015-03-11 15:43:49 +0000457static int __init wakeupgen_init(struct device_node *node,
458 struct device_node *parent)
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530459{
Marc Zyngier7136d452015-03-11 15:43:49 +0000460 struct irq_domain *parent_domain, *domain;
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530461 int i;
462 unsigned int boot_cpu = smp_processor_id();
Santosh Shilimkar4664d4d2013-02-08 17:07:31 +0530463 u32 val;
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530464
Marc Zyngier7136d452015-03-11 15:43:49 +0000465 if (!parent) {
466 pr_err("%s: no parent, giving up\n", node->full_name);
467 return -ENODEV;
468 }
469
470 parent_domain = irq_find_host(parent);
471 if (!parent_domain) {
472 pr_err("%s: unable to obtain parent domain\n", node->full_name);
473 return -ENXIO;
474 }
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530475 /* Not supported on OMAP4 ES1.0 silicon */
476 if (omap_rev() == OMAP4430_REV_ES1_0) {
477 WARN(1, "WakeupGen: Not supported on OMAP4430 ES1.0\n");
478 return -EPERM;
479 }
480
481 /* Static mapping, never released */
Marc Zyngier7136d452015-03-11 15:43:49 +0000482 wakeupgen_base = of_iomap(node, 0);
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530483 if (WARN_ON(!wakeupgen_base))
484 return -ENOMEM;
485
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530486 if (cpu_is_omap44xx()) {
487 irq_banks = OMAP4_NR_BANKS;
488 max_irqs = OMAP4_NR_IRQS;
489 omap_secure_apis = 1;
Afzal Mohammed6246cd02013-10-09 12:42:33 +0530490 } else if (soc_is_am43xx()) {
491 irq_banks = AM43XX_NR_REG_BANKS;
492 max_irqs = AM43XX_IRQS;
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530493 }
494
Marc Zyngier7136d452015-03-11 15:43:49 +0000495 domain = irq_domain_add_hierarchy(parent_domain, 0, max_irqs,
496 node, &wakeupgen_domain_ops,
497 NULL);
498 if (!domain) {
499 iounmap(wakeupgen_base);
500 return -ENOMEM;
501 }
502
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530503 /* Clear all IRQ bitmasks at wakeupGen level */
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530504 for (i = 0; i < irq_banks; i++) {
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530505 wakeupgen_writel(0, i, CPU0_ID);
Afzal Mohammed6246cd02013-10-09 12:42:33 +0530506 if (!soc_is_am43xx())
507 wakeupgen_writel(0, i, CPU1_ID);
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530508 }
509
510 /*
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530511 * FIXME: Add support to set_smp_affinity() once the core
512 * GIC code has necessary hooks in place.
513 */
514
515 /* Associate all the IRQs to boot CPU like GIC init does. */
Santosh Shilimkar247c4452012-05-09 20:38:35 +0530516 for (i = 0; i < max_irqs; i++)
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530517 irq_target_cpu[i] = boot_cpu;
518
Santosh Shilimkar4664d4d2013-02-08 17:07:31 +0530519 /*
520 * Enables OMAP5 ES2 PM Mode using ES2_PM_MODE in AMBA_IF_MODE
521 * 0x0: ES1 behavior, CPU cores would enter and exit OFF mode together.
522 * 0x1: ES2 behavior, CPU cores are allowed to enter/exit OFF mode
523 * independently.
524 * This needs to be set one time thanks to always ON domain.
525 *
526 * We do not support ES1 behavior anymore. OMAP5 is assumed to be
527 * ES2.0, and the same is applicable for DRA7.
528 */
529 if (soc_is_omap54xx() || soc_is_dra7xx()) {
530 val = __raw_readl(wakeupgen_base + OMAP_AMBA_IF_MODE);
531 val |= BIT(5);
532 omap_smc1(OMAP5_MON_AMBA_IF_INDEX, val);
533 }
534
Santosh Shilimkarb5b4f282010-06-16 22:19:48 +0530535 irq_hotplug_init();
Santosh Shilimkar0f3cf2e2010-06-16 23:29:31 +0530536 irq_pm_init();
Santosh Shilimkarb5b4f282010-06-16 22:19:48 +0530537
Santosh Shilimkarfcf6efa2010-06-16 22:19:47 +0530538 return 0;
539}
Marc Zyngier7136d452015-03-11 15:43:49 +0000540
541/*
542 * We cannot use the IRQCHIP_DECLARE macro that lives in
543 * drivers/irqchip, so we're forced to roll our own. Not very nice.
544 */
545OF_DECLARE_2(irqchip, ti_wakeupgen, "ti,omap4-wugen-mpu", wakeupgen_init);