gpc.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * Copyright 2011-2013 Freescale Semiconductor, Inc.
  3. * Copyright 2011 Linaro Ltd.
  4. *
  5. * The code contained herein is licensed under the GNU General Public
  6. * License. You may obtain a copy of the GNU General Public License
  7. * Version 2 or later at the following locations:
  8. *
  9. * http://www.opensource.org/licenses/gpl-license.html
  10. * http://www.gnu.org/copyleft/gpl.html
  11. */
  12. #include <linux/io.h>
  13. #include <linux/irq.h>
  14. #include <linux/irqchip.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_irq.h>
  18. #include <linux/irqchip/arm-gic.h>
  19. #include "common.h"
  20. #include "hardware.h"
  21. #define GPC_CNTR 0x0
  22. #define GPC_IMR1 0x008
  23. #define GPC_PGC_CPU_PDN 0x2a0
  24. #define GPC_PGC_CPU_PUPSCR 0x2a4
  25. #define GPC_PGC_CPU_PDNSCR 0x2a8
  26. #define GPC_PGC_SW2ISO_SHIFT 0x8
  27. #define GPC_PGC_SW_SHIFT 0x0
  28. #define GPC_CNTR_L2_PGE_SHIFT 22
  29. #define IMR_NUM 4
  30. #define GPC_MAX_IRQS (IMR_NUM * 32)
  31. static void __iomem *gpc_base;
  32. static u32 gpc_wake_irqs[IMR_NUM];
  33. static u32 gpc_saved_imrs[IMR_NUM];
  34. void imx_gpc_set_arm_power_up_timing(u32 sw2iso, u32 sw)
  35. {
  36. writel_relaxed((sw2iso << GPC_PGC_SW2ISO_SHIFT) |
  37. (sw << GPC_PGC_SW_SHIFT), gpc_base + GPC_PGC_CPU_PUPSCR);
  38. }
  39. void imx_gpc_set_arm_power_down_timing(u32 sw2iso, u32 sw)
  40. {
  41. writel_relaxed((sw2iso << GPC_PGC_SW2ISO_SHIFT) |
  42. (sw << GPC_PGC_SW_SHIFT), gpc_base + GPC_PGC_CPU_PDNSCR);
  43. }
  44. void imx_gpc_set_arm_power_in_lpm(bool power_off)
  45. {
  46. writel_relaxed(power_off, gpc_base + GPC_PGC_CPU_PDN);
  47. }
  48. void imx_gpc_set_l2_mem_power_in_lpm(bool power_off)
  49. {
  50. u32 val;
  51. val = readl_relaxed(gpc_base + GPC_CNTR);
  52. val &= ~(1 << GPC_CNTR_L2_PGE_SHIFT);
  53. if (power_off)
  54. val |= 1 << GPC_CNTR_L2_PGE_SHIFT;
  55. writel_relaxed(val, gpc_base + GPC_CNTR);
  56. }
  57. void imx_gpc_pre_suspend(bool arm_power_off)
  58. {
  59. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  60. int i;
  61. /* Tell GPC to power off ARM core when suspend */
  62. if (arm_power_off)
  63. imx_gpc_set_arm_power_in_lpm(arm_power_off);
  64. for (i = 0; i < IMR_NUM; i++) {
  65. gpc_saved_imrs[i] = readl_relaxed(reg_imr1 + i * 4);
  66. writel_relaxed(~gpc_wake_irqs[i], reg_imr1 + i * 4);
  67. }
  68. }
  69. void imx_gpc_post_resume(void)
  70. {
  71. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  72. int i;
  73. /* Keep ARM core powered on for other low-power modes */
  74. imx_gpc_set_arm_power_in_lpm(false);
  75. for (i = 0; i < IMR_NUM; i++)
  76. writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4);
  77. }
  78. static int imx_gpc_irq_set_wake(struct irq_data *d, unsigned int on)
  79. {
  80. unsigned int idx = d->hwirq / 32;
  81. u32 mask;
  82. mask = 1 << d->hwirq % 32;
  83. gpc_wake_irqs[idx] = on ? gpc_wake_irqs[idx] | mask :
  84. gpc_wake_irqs[idx] & ~mask;
  85. /*
  86. * Do *not* call into the parent, as the GIC doesn't have any
  87. * wake-up facility...
  88. */
  89. return 0;
  90. }
  91. void imx_gpc_mask_all(void)
  92. {
  93. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  94. int i;
  95. for (i = 0; i < IMR_NUM; i++) {
  96. gpc_saved_imrs[i] = readl_relaxed(reg_imr1 + i * 4);
  97. writel_relaxed(~0, reg_imr1 + i * 4);
  98. }
  99. }
  100. void imx_gpc_restore_all(void)
  101. {
  102. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  103. int i;
  104. for (i = 0; i < IMR_NUM; i++)
  105. writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4);
  106. }
  107. void imx_gpc_hwirq_unmask(unsigned int hwirq)
  108. {
  109. void __iomem *reg;
  110. u32 val;
  111. reg = gpc_base + GPC_IMR1 + hwirq / 32 * 4;
  112. val = readl_relaxed(reg);
  113. val &= ~(1 << hwirq % 32);
  114. writel_relaxed(val, reg);
  115. }
  116. void imx_gpc_hwirq_mask(unsigned int hwirq)
  117. {
  118. void __iomem *reg;
  119. u32 val;
  120. reg = gpc_base + GPC_IMR1 + hwirq / 32 * 4;
  121. val = readl_relaxed(reg);
  122. val |= 1 << (hwirq % 32);
  123. writel_relaxed(val, reg);
  124. }
  125. static void imx_gpc_irq_unmask(struct irq_data *d)
  126. {
  127. imx_gpc_hwirq_unmask(d->hwirq);
  128. irq_chip_unmask_parent(d);
  129. }
  130. static void imx_gpc_irq_mask(struct irq_data *d)
  131. {
  132. imx_gpc_hwirq_mask(d->hwirq);
  133. irq_chip_mask_parent(d);
  134. }
  135. static struct irq_chip imx_gpc_chip = {
  136. .name = "GPC",
  137. .irq_eoi = irq_chip_eoi_parent,
  138. .irq_mask = imx_gpc_irq_mask,
  139. .irq_unmask = imx_gpc_irq_unmask,
  140. .irq_retrigger = irq_chip_retrigger_hierarchy,
  141. .irq_set_wake = imx_gpc_irq_set_wake,
  142. .irq_set_type = irq_chip_set_type_parent,
  143. #ifdef CONFIG_SMP
  144. .irq_set_affinity = irq_chip_set_affinity_parent,
  145. #endif
  146. };
  147. static int imx_gpc_domain_translate(struct irq_domain *d,
  148. struct irq_fwspec *fwspec,
  149. unsigned long *hwirq,
  150. unsigned int *type)
  151. {
  152. if (is_of_node(fwspec->fwnode)) {
  153. if (fwspec->param_count != 3)
  154. return -EINVAL;
  155. /* No PPI should point to this domain */
  156. if (fwspec->param[0] != 0)
  157. return -EINVAL;
  158. *hwirq = fwspec->param[1];
  159. *type = fwspec->param[2];
  160. return 0;
  161. }
  162. return -EINVAL;
  163. }
  164. static int imx_gpc_domain_alloc(struct irq_domain *domain,
  165. unsigned int irq,
  166. unsigned int nr_irqs, void *data)
  167. {
  168. struct irq_fwspec *fwspec = data;
  169. struct irq_fwspec parent_fwspec;
  170. irq_hw_number_t hwirq;
  171. int i;
  172. if (fwspec->param_count != 3)
  173. return -EINVAL; /* Not GIC compliant */
  174. if (fwspec->param[0] != 0)
  175. return -EINVAL; /* No PPI should point to this domain */
  176. hwirq = fwspec->param[1];
  177. if (hwirq >= GPC_MAX_IRQS)
  178. return -EINVAL; /* Can't deal with this */
  179. for (i = 0; i < nr_irqs; i++)
  180. irq_domain_set_hwirq_and_chip(domain, irq + i, hwirq + i,
  181. &imx_gpc_chip, NULL);
  182. parent_fwspec = *fwspec;
  183. parent_fwspec.fwnode = domain->parent->fwnode;
  184. return irq_domain_alloc_irqs_parent(domain, irq, nr_irqs,
  185. &parent_fwspec);
  186. }
  187. static const struct irq_domain_ops imx_gpc_domain_ops = {
  188. .translate = imx_gpc_domain_translate,
  189. .alloc = imx_gpc_domain_alloc,
  190. .free = irq_domain_free_irqs_common,
  191. };
  192. static int __init imx_gpc_init(struct device_node *node,
  193. struct device_node *parent)
  194. {
  195. struct irq_domain *parent_domain, *domain;
  196. int i;
  197. if (!parent) {
  198. pr_err("%pOF: no parent, giving up\n", node);
  199. return -ENODEV;
  200. }
  201. parent_domain = irq_find_host(parent);
  202. if (!parent_domain) {
  203. pr_err("%pOF: unable to obtain parent domain\n", node);
  204. return -ENXIO;
  205. }
  206. gpc_base = of_iomap(node, 0);
  207. if (WARN_ON(!gpc_base))
  208. return -ENOMEM;
  209. domain = irq_domain_add_hierarchy(parent_domain, 0, GPC_MAX_IRQS,
  210. node, &imx_gpc_domain_ops,
  211. NULL);
  212. if (!domain) {
  213. iounmap(gpc_base);
  214. return -ENOMEM;
  215. }
  216. /* Initially mask all interrupts */
  217. for (i = 0; i < IMR_NUM; i++)
  218. writel_relaxed(~0, gpc_base + GPC_IMR1 + i * 4);
  219. /*
  220. * Clear the OF_POPULATED flag set in of_irq_init so that
  221. * later the GPC power domain driver will not be skipped.
  222. */
  223. of_node_clear_flag(node, OF_POPULATED);
  224. return 0;
  225. }
  226. IRQCHIP_DECLARE(imx_gpc, "fsl,imx6q-gpc", imx_gpc_init);
  227. void __init imx_gpc_check_dt(void)
  228. {
  229. struct device_node *np;
  230. np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpc");
  231. if (WARN_ON(!np))
  232. return;
  233. if (WARN_ON(!of_find_property(np, "interrupt-controller", NULL))) {
  234. pr_warn("Outdated DT detected, suspend/resume will NOT work\n");
  235. /* map GPC, so that at least CPUidle and WARs keep working */
  236. gpc_base = of_iomap(np, 0);
  237. }
  238. }