omap-wakeupgen.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OMAP WakeupGen Source file
  4. *
  5. * OMAP WakeupGen is the interrupt controller extension used along
  6. * with ARM GIC to wake the CPU out from low power states on
  7. * external interrupts. It is responsible for generating wakeup
  8. * event from the incoming interrupts and enable bits. It is
  9. * implemented in MPU always ON power domain. During normal operation,
  10. * WakeupGen delivers external interrupts directly to the GIC.
  11. *
  12. * Copyright (C) 2011 Texas Instruments, Inc.
  13. * Santosh Shilimkar <[email protected]>
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <linux/irq.h>
  19. #include <linux/irqchip.h>
  20. #include <linux/irqdomain.h>
  21. #include <linux/of_address.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/cpu.h>
  24. #include <linux/notifier.h>
  25. #include <linux/cpu_pm.h>
  26. #include "omap-wakeupgen.h"
  27. #include "omap-secure.h"
  28. #include "soc.h"
  29. #include "omap4-sar-layout.h"
  30. #include "common.h"
  31. #include "pm.h"
  32. #define AM43XX_NR_REG_BANKS 7
  33. #define AM43XX_IRQS 224
  34. #define MAX_NR_REG_BANKS AM43XX_NR_REG_BANKS
  35. #define MAX_IRQS AM43XX_IRQS
  36. #define DEFAULT_NR_REG_BANKS 5
  37. #define DEFAULT_IRQS 160
  38. #define WKG_MASK_ALL 0x00000000
  39. #define WKG_UNMASK_ALL 0xffffffff
  40. #define CPU_ENA_OFFSET 0x400
  41. #define CPU0_ID 0x0
  42. #define CPU1_ID 0x1
  43. #define OMAP4_NR_BANKS 4
  44. #define OMAP4_NR_IRQS 128
  45. #define SYS_NIRQ1_EXT_SYS_IRQ_1 7
  46. #define SYS_NIRQ2_EXT_SYS_IRQ_2 119
  47. static void __iomem *wakeupgen_base;
  48. static void __iomem *sar_base;
  49. static DEFINE_RAW_SPINLOCK(wakeupgen_lock);
  50. static unsigned int irq_target_cpu[MAX_IRQS];
  51. static unsigned int irq_banks = DEFAULT_NR_REG_BANKS;
  52. static unsigned int max_irqs = DEFAULT_IRQS;
  53. static unsigned int omap_secure_apis;
  54. #ifdef CONFIG_CPU_PM
  55. static unsigned int wakeupgen_context[MAX_NR_REG_BANKS];
  56. #endif
  57. struct omap_wakeupgen_ops {
  58. void (*save_context)(void);
  59. void (*restore_context)(void);
  60. };
  61. static struct omap_wakeupgen_ops *wakeupgen_ops;
  62. /*
  63. * Static helper functions.
  64. */
  65. static inline u32 wakeupgen_readl(u8 idx, u32 cpu)
  66. {
  67. return readl_relaxed(wakeupgen_base + OMAP_WKG_ENB_A_0 +
  68. (cpu * CPU_ENA_OFFSET) + (idx * 4));
  69. }
  70. static inline void wakeupgen_writel(u32 val, u8 idx, u32 cpu)
  71. {
  72. writel_relaxed(val, wakeupgen_base + OMAP_WKG_ENB_A_0 +
  73. (cpu * CPU_ENA_OFFSET) + (idx * 4));
  74. }
  75. static inline void sar_writel(u32 val, u32 offset, u8 idx)
  76. {
  77. writel_relaxed(val, sar_base + offset + (idx * 4));
  78. }
  79. static inline int _wakeupgen_get_irq_info(u32 irq, u32 *bit_posn, u8 *reg_index)
  80. {
  81. /*
  82. * Each WakeupGen register controls 32 interrupt.
  83. * i.e. 1 bit per SPI IRQ
  84. */
  85. *reg_index = irq >> 5;
  86. *bit_posn = irq %= 32;
  87. return 0;
  88. }
  89. static void _wakeupgen_clear(unsigned int irq, unsigned int cpu)
  90. {
  91. u32 val, bit_number;
  92. u8 i;
  93. if (_wakeupgen_get_irq_info(irq, &bit_number, &i))
  94. return;
  95. val = wakeupgen_readl(i, cpu);
  96. val &= ~BIT(bit_number);
  97. wakeupgen_writel(val, i, cpu);
  98. }
  99. static void _wakeupgen_set(unsigned int irq, unsigned int cpu)
  100. {
  101. u32 val, bit_number;
  102. u8 i;
  103. if (_wakeupgen_get_irq_info(irq, &bit_number, &i))
  104. return;
  105. val = wakeupgen_readl(i, cpu);
  106. val |= BIT(bit_number);
  107. wakeupgen_writel(val, i, cpu);
  108. }
  109. /*
  110. * Architecture specific Mask extension
  111. */
  112. static void wakeupgen_mask(struct irq_data *d)
  113. {
  114. unsigned long flags;
  115. raw_spin_lock_irqsave(&wakeupgen_lock, flags);
  116. _wakeupgen_clear(d->hwirq, irq_target_cpu[d->hwirq]);
  117. raw_spin_unlock_irqrestore(&wakeupgen_lock, flags);
  118. irq_chip_mask_parent(d);
  119. }
  120. /*
  121. * Architecture specific Unmask extension
  122. */
  123. static void wakeupgen_unmask(struct irq_data *d)
  124. {
  125. unsigned long flags;
  126. raw_spin_lock_irqsave(&wakeupgen_lock, flags);
  127. _wakeupgen_set(d->hwirq, irq_target_cpu[d->hwirq]);
  128. raw_spin_unlock_irqrestore(&wakeupgen_lock, flags);
  129. irq_chip_unmask_parent(d);
  130. }
  131. /*
  132. * The sys_nirq pins bypass peripheral modules and are wired directly
  133. * to MPUSS wakeupgen. They get automatically inverted for GIC.
  134. */
  135. static int wakeupgen_irq_set_type(struct irq_data *d, unsigned int type)
  136. {
  137. bool inverted = false;
  138. switch (type) {
  139. case IRQ_TYPE_LEVEL_LOW:
  140. type &= ~IRQ_TYPE_LEVEL_MASK;
  141. type |= IRQ_TYPE_LEVEL_HIGH;
  142. inverted = true;
  143. break;
  144. case IRQ_TYPE_EDGE_FALLING:
  145. type &= ~IRQ_TYPE_EDGE_BOTH;
  146. type |= IRQ_TYPE_EDGE_RISING;
  147. inverted = true;
  148. break;
  149. default:
  150. break;
  151. }
  152. if (inverted && d->hwirq != SYS_NIRQ1_EXT_SYS_IRQ_1 &&
  153. d->hwirq != SYS_NIRQ2_EXT_SYS_IRQ_2)
  154. pr_warn("wakeupgen: irq%li polarity inverted in dts\n",
  155. d->hwirq);
  156. return irq_chip_set_type_parent(d, type);
  157. }
  158. #ifdef CONFIG_HOTPLUG_CPU
  159. static DEFINE_PER_CPU(u32 [MAX_NR_REG_BANKS], irqmasks);
  160. static void _wakeupgen_save_masks(unsigned int cpu)
  161. {
  162. u8 i;
  163. for (i = 0; i < irq_banks; i++)
  164. per_cpu(irqmasks, cpu)[i] = wakeupgen_readl(i, cpu);
  165. }
  166. static void _wakeupgen_restore_masks(unsigned int cpu)
  167. {
  168. u8 i;
  169. for (i = 0; i < irq_banks; i++)
  170. wakeupgen_writel(per_cpu(irqmasks, cpu)[i], i, cpu);
  171. }
  172. static void _wakeupgen_set_all(unsigned int cpu, unsigned int reg)
  173. {
  174. u8 i;
  175. for (i = 0; i < irq_banks; i++)
  176. wakeupgen_writel(reg, i, cpu);
  177. }
  178. /*
  179. * Mask or unmask all interrupts on given CPU.
  180. * 0 = Mask all interrupts on the 'cpu'
  181. * 1 = Unmask all interrupts on the 'cpu'
  182. * Ensure that the initial mask is maintained. This is faster than
  183. * iterating through GIC registers to arrive at the correct masks.
  184. */
  185. static void wakeupgen_irqmask_all(unsigned int cpu, unsigned int set)
  186. {
  187. unsigned long flags;
  188. raw_spin_lock_irqsave(&wakeupgen_lock, flags);
  189. if (set) {
  190. _wakeupgen_save_masks(cpu);
  191. _wakeupgen_set_all(cpu, WKG_MASK_ALL);
  192. } else {
  193. _wakeupgen_set_all(cpu, WKG_UNMASK_ALL);
  194. _wakeupgen_restore_masks(cpu);
  195. }
  196. raw_spin_unlock_irqrestore(&wakeupgen_lock, flags);
  197. }
  198. #endif
  199. #ifdef CONFIG_CPU_PM
  200. static inline void omap4_irq_save_context(void)
  201. {
  202. u32 i, val;
  203. if (omap_rev() == OMAP4430_REV_ES1_0)
  204. return;
  205. for (i = 0; i < irq_banks; i++) {
  206. /* Save the CPUx interrupt mask for IRQ 0 to 127 */
  207. val = wakeupgen_readl(i, 0);
  208. sar_writel(val, WAKEUPGENENB_OFFSET_CPU0, i);
  209. val = wakeupgen_readl(i, 1);
  210. sar_writel(val, WAKEUPGENENB_OFFSET_CPU1, i);
  211. /*
  212. * Disable the secure interrupts for CPUx. The restore
  213. * code blindly restores secure and non-secure interrupt
  214. * masks from SAR RAM. Secure interrupts are not suppose
  215. * to be enabled from HLOS. So overwrite the SAR location
  216. * so that the secure interrupt remains disabled.
  217. */
  218. sar_writel(0x0, WAKEUPGENENB_SECURE_OFFSET_CPU0, i);
  219. sar_writel(0x0, WAKEUPGENENB_SECURE_OFFSET_CPU1, i);
  220. }
  221. /* Save AuxBoot* registers */
  222. val = readl_relaxed(wakeupgen_base + OMAP_AUX_CORE_BOOT_0);
  223. writel_relaxed(val, sar_base + AUXCOREBOOT0_OFFSET);
  224. val = readl_relaxed(wakeupgen_base + OMAP_AUX_CORE_BOOT_1);
  225. writel_relaxed(val, sar_base + AUXCOREBOOT1_OFFSET);
  226. /* Save SyncReq generation logic */
  227. 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);
  231. /* Set the Backup Bit Mask status */
  232. val = readl_relaxed(sar_base + SAR_BACKUP_STATUS_OFFSET);
  233. val |= SAR_BACKUP_STATUS_WAKEUPGEN;
  234. writel_relaxed(val, sar_base + SAR_BACKUP_STATUS_OFFSET);
  235. }
  236. static inline void omap5_irq_save_context(void)
  237. {
  238. u32 i, val;
  239. for (i = 0; i < irq_banks; i++) {
  240. /* Save the CPUx interrupt mask for IRQ 0 to 159 */
  241. val = wakeupgen_readl(i, 0);
  242. sar_writel(val, OMAP5_WAKEUPGENENB_OFFSET_CPU0, i);
  243. val = wakeupgen_readl(i, 1);
  244. sar_writel(val, OMAP5_WAKEUPGENENB_OFFSET_CPU1, i);
  245. sar_writel(0x0, OMAP5_WAKEUPGENENB_SECURE_OFFSET_CPU0, i);
  246. sar_writel(0x0, OMAP5_WAKEUPGENENB_SECURE_OFFSET_CPU1, i);
  247. }
  248. /* Save AuxBoot* registers */
  249. val = readl_relaxed(wakeupgen_base + OMAP_AUX_CORE_BOOT_0);
  250. writel_relaxed(val, sar_base + OMAP5_AUXCOREBOOT0_OFFSET);
  251. val = readl_relaxed(wakeupgen_base + OMAP_AUX_CORE_BOOT_0);
  252. writel_relaxed(val, sar_base + OMAP5_AUXCOREBOOT1_OFFSET);
  253. /* Set the Backup Bit Mask status */
  254. val = readl_relaxed(sar_base + OMAP5_SAR_BACKUP_STATUS_OFFSET);
  255. val |= SAR_BACKUP_STATUS_WAKEUPGEN;
  256. writel_relaxed(val, sar_base + OMAP5_SAR_BACKUP_STATUS_OFFSET);
  257. }
  258. static inline void am43xx_irq_save_context(void)
  259. {
  260. u32 i;
  261. for (i = 0; i < irq_banks; i++) {
  262. wakeupgen_context[i] = wakeupgen_readl(i, 0);
  263. wakeupgen_writel(0, i, CPU0_ID);
  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. */
  274. static void irq_save_context(void)
  275. {
  276. /* DRA7 has no SAR to save */
  277. if (soc_is_dra7xx())
  278. return;
  279. if (wakeupgen_ops && wakeupgen_ops->save_context)
  280. wakeupgen_ops->save_context();
  281. }
  282. /*
  283. * Clear WakeupGen SAR backup status.
  284. */
  285. static void irq_sar_clear(void)
  286. {
  287. u32 val;
  288. u32 offset = SAR_BACKUP_STATUS_OFFSET;
  289. /* DRA7 has no SAR to save */
  290. if (soc_is_dra7xx())
  291. return;
  292. if (soc_is_omap54xx())
  293. offset = OMAP5_SAR_BACKUP_STATUS_OFFSET;
  294. val = readl_relaxed(sar_base + offset);
  295. val &= ~SAR_BACKUP_STATUS_WAKEUPGEN;
  296. writel_relaxed(val, sar_base + offset);
  297. }
  298. static void am43xx_irq_restore_context(void)
  299. {
  300. u32 i;
  301. for (i = 0; i < irq_banks; i++)
  302. wakeupgen_writel(wakeupgen_context[i], i, CPU0_ID);
  303. }
  304. static void irq_restore_context(void)
  305. {
  306. if (wakeupgen_ops && wakeupgen_ops->restore_context)
  307. wakeupgen_ops->restore_context();
  308. }
  309. /*
  310. * Save GIC and Wakeupgen interrupt context using secure API
  311. * for HS/EMU devices.
  312. */
  313. static void irq_save_secure_context(void)
  314. {
  315. u32 ret;
  316. ret = omap_secure_dispatcher(OMAP4_HAL_SAVEGIC_INDEX,
  317. FLAG_START_CRITICAL,
  318. 0, 0, 0, 0, 0);
  319. if (ret != API_HAL_RET_VALUE_OK)
  320. pr_err("GIC and Wakeupgen context save failed\n");
  321. }
  322. /* Define ops for context save and restore for each SoC */
  323. static struct omap_wakeupgen_ops omap4_wakeupgen_ops = {
  324. .save_context = omap4_irq_save_context,
  325. .restore_context = irq_sar_clear,
  326. };
  327. static struct omap_wakeupgen_ops omap5_wakeupgen_ops = {
  328. .save_context = omap5_irq_save_context,
  329. .restore_context = irq_sar_clear,
  330. };
  331. static struct omap_wakeupgen_ops am43xx_wakeupgen_ops = {
  332. .save_context = am43xx_irq_save_context,
  333. .restore_context = am43xx_irq_restore_context,
  334. };
  335. #else
  336. static struct omap_wakeupgen_ops omap4_wakeupgen_ops = {};
  337. static struct omap_wakeupgen_ops omap5_wakeupgen_ops = {};
  338. static struct omap_wakeupgen_ops am43xx_wakeupgen_ops = {};
  339. #endif
  340. #ifdef CONFIG_HOTPLUG_CPU
  341. static int omap_wakeupgen_cpu_online(unsigned int cpu)
  342. {
  343. wakeupgen_irqmask_all(cpu, 0);
  344. return 0;
  345. }
  346. static int omap_wakeupgen_cpu_dead(unsigned int cpu)
  347. {
  348. wakeupgen_irqmask_all(cpu, 1);
  349. return 0;
  350. }
  351. static void __init irq_hotplug_init(void)
  352. {
  353. cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "arm/omap-wake:online",
  354. omap_wakeupgen_cpu_online, NULL);
  355. cpuhp_setup_state_nocalls(CPUHP_ARM_OMAP_WAKE_DEAD,
  356. "arm/omap-wake:dead", NULL,
  357. omap_wakeupgen_cpu_dead);
  358. }
  359. #else
  360. static void __init irq_hotplug_init(void)
  361. {}
  362. #endif
  363. #ifdef CONFIG_CPU_PM
  364. static int irq_notifier(struct notifier_block *self, unsigned long cmd, void *v)
  365. {
  366. switch (cmd) {
  367. case CPU_CLUSTER_PM_ENTER:
  368. if (omap_type() == OMAP2_DEVICE_TYPE_GP || soc_is_am43xx())
  369. irq_save_context();
  370. else
  371. irq_save_secure_context();
  372. break;
  373. case CPU_CLUSTER_PM_EXIT:
  374. if (omap_type() == OMAP2_DEVICE_TYPE_GP || soc_is_am43xx())
  375. irq_restore_context();
  376. break;
  377. }
  378. return NOTIFY_OK;
  379. }
  380. static struct notifier_block irq_notifier_block = {
  381. .notifier_call = irq_notifier,
  382. };
  383. static void __init irq_pm_init(void)
  384. {
  385. /* FIXME: Remove this when MPU OSWR support is added */
  386. if (!IS_PM44XX_ERRATUM(PM_OMAP4_CPU_OSWR_DISABLE))
  387. cpu_pm_register_notifier(&irq_notifier_block);
  388. }
  389. #else
  390. static void __init irq_pm_init(void)
  391. {}
  392. #endif
  393. void __iomem *omap_get_wakeupgen_base(void)
  394. {
  395. return wakeupgen_base;
  396. }
  397. int omap_secure_apis_support(void)
  398. {
  399. return omap_secure_apis;
  400. }
  401. static struct irq_chip wakeupgen_chip = {
  402. .name = "WUGEN",
  403. .irq_eoi = irq_chip_eoi_parent,
  404. .irq_mask = wakeupgen_mask,
  405. .irq_unmask = wakeupgen_unmask,
  406. .irq_retrigger = irq_chip_retrigger_hierarchy,
  407. .irq_set_type = wakeupgen_irq_set_type,
  408. .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND,
  409. #ifdef CONFIG_SMP
  410. .irq_set_affinity = irq_chip_set_affinity_parent,
  411. #endif
  412. };
  413. static int wakeupgen_domain_translate(struct irq_domain *d,
  414. struct irq_fwspec *fwspec,
  415. unsigned long *hwirq,
  416. unsigned int *type)
  417. {
  418. if (is_of_node(fwspec->fwnode)) {
  419. if (fwspec->param_count != 3)
  420. return -EINVAL;
  421. /* No PPI should point to this domain */
  422. if (fwspec->param[0] != 0)
  423. return -EINVAL;
  424. *hwirq = fwspec->param[1];
  425. *type = fwspec->param[2];
  426. return 0;
  427. }
  428. return -EINVAL;
  429. }
  430. static int wakeupgen_domain_alloc(struct irq_domain *domain,
  431. unsigned int virq,
  432. unsigned int nr_irqs, void *data)
  433. {
  434. struct irq_fwspec *fwspec = data;
  435. struct irq_fwspec parent_fwspec;
  436. irq_hw_number_t hwirq;
  437. int i;
  438. if (fwspec->param_count != 3)
  439. return -EINVAL; /* Not GIC compliant */
  440. if (fwspec->param[0] != 0)
  441. return -EINVAL; /* No PPI should point to this domain */
  442. hwirq = fwspec->param[1];
  443. if (hwirq >= MAX_IRQS)
  444. return -EINVAL; /* Can't deal with this */
  445. for (i = 0; i < nr_irqs; i++)
  446. irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
  447. &wakeupgen_chip, NULL);
  448. parent_fwspec = *fwspec;
  449. parent_fwspec.fwnode = domain->parent->fwnode;
  450. return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs,
  451. &parent_fwspec);
  452. }
  453. static const struct irq_domain_ops wakeupgen_domain_ops = {
  454. .translate = wakeupgen_domain_translate,
  455. .alloc = wakeupgen_domain_alloc,
  456. .free = irq_domain_free_irqs_common,
  457. };
  458. /*
  459. * Initialise the wakeupgen module.
  460. */
  461. static int __init wakeupgen_init(struct device_node *node,
  462. struct device_node *parent)
  463. {
  464. struct irq_domain *parent_domain, *domain;
  465. int i;
  466. unsigned int boot_cpu = smp_processor_id();
  467. u32 val;
  468. if (!parent) {
  469. pr_err("%pOF: no parent, giving up\n", node);
  470. return -ENODEV;
  471. }
  472. parent_domain = irq_find_host(parent);
  473. if (!parent_domain) {
  474. pr_err("%pOF: unable to obtain parent domain\n", node);
  475. return -ENXIO;
  476. }
  477. /* Not supported on OMAP4 ES1.0 silicon */
  478. if (omap_rev() == OMAP4430_REV_ES1_0) {
  479. WARN(1, "WakeupGen: Not supported on OMAP4430 ES1.0\n");
  480. return -EPERM;
  481. }
  482. /* Static mapping, never released */
  483. wakeupgen_base = of_iomap(node, 0);
  484. if (WARN_ON(!wakeupgen_base))
  485. return -ENOMEM;
  486. if (cpu_is_omap44xx()) {
  487. irq_banks = OMAP4_NR_BANKS;
  488. max_irqs = OMAP4_NR_IRQS;
  489. omap_secure_apis = 1;
  490. wakeupgen_ops = &omap4_wakeupgen_ops;
  491. } else if (soc_is_omap54xx()) {
  492. wakeupgen_ops = &omap5_wakeupgen_ops;
  493. } else if (soc_is_am43xx()) {
  494. irq_banks = AM43XX_NR_REG_BANKS;
  495. max_irqs = AM43XX_IRQS;
  496. wakeupgen_ops = &am43xx_wakeupgen_ops;
  497. }
  498. domain = irq_domain_add_hierarchy(parent_domain, 0, max_irqs,
  499. node, &wakeupgen_domain_ops,
  500. NULL);
  501. if (!domain) {
  502. iounmap(wakeupgen_base);
  503. return -ENOMEM;
  504. }
  505. /* Clear all IRQ bitmasks at wakeupGen level */
  506. for (i = 0; i < irq_banks; i++) {
  507. wakeupgen_writel(0, i, CPU0_ID);
  508. if (!soc_is_am43xx())
  509. wakeupgen_writel(0, i, CPU1_ID);
  510. }
  511. /*
  512. * FIXME: Add support to set_smp_affinity() once the core
  513. * GIC code has necessary hooks in place.
  514. */
  515. /* Associate all the IRQs to boot CPU like GIC init does. */
  516. for (i = 0; i < max_irqs; i++)
  517. irq_target_cpu[i] = boot_cpu;
  518. /*
  519. * Enables OMAP5 ES2 PM Mode using ES2_PM_MODE in AMBA_IF_MODE
  520. * 0x0: ES1 behavior, CPU cores would enter and exit OFF mode together.
  521. * 0x1: ES2 behavior, CPU cores are allowed to enter/exit OFF mode
  522. * independently.
  523. * This needs to be set one time thanks to always ON domain.
  524. *
  525. * We do not support ES1 behavior anymore. OMAP5 is assumed to be
  526. * ES2.0, and the same is applicable for DRA7.
  527. */
  528. if (soc_is_omap54xx() || soc_is_dra7xx()) {
  529. val = __raw_readl(wakeupgen_base + OMAP_AMBA_IF_MODE);
  530. val |= BIT(5);
  531. omap_smc1(OMAP5_MON_AMBA_IF_INDEX, val);
  532. }
  533. irq_hotplug_init();
  534. irq_pm_init();
  535. sar_base = omap4_get_sar_ram_base();
  536. return 0;
  537. }
  538. IRQCHIP_DECLARE(ti_wakeupgen, "ti,omap4-wugen-mpu", wakeupgen_init);