gpc.c 6.4 KB

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