irq-mmp.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /*
  2. * linux/arch/arm/mach-mmp/irq.c
  3. *
  4. * Generic IRQ handling, GPIO IRQ demultiplexing, etc.
  5. * Copyright (C) 2008 - 2012 Marvell Technology Group Ltd.
  6. *
  7. * Author: Bin Yang <bin.yang@marvell.com>
  8. * Haojian Zhuang <haojian.zhuang@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/irq.h>
  17. #include <linux/irqchip.h>
  18. #include <linux/irqdomain.h>
  19. #include <linux/io.h>
  20. #include <linux/ioport.h>
  21. #include <linux/of_address.h>
  22. #include <linux/of_irq.h>
  23. #include <asm/exception.h>
  24. #include <asm/hardirq.h>
  25. #define MAX_ICU_NR 16
  26. #define PJ1_INT_SEL 0x10c
  27. #define PJ4_INT_SEL 0x104
  28. /* bit fields in PJ1_INT_SEL and PJ4_INT_SEL */
  29. #define SEL_INT_PENDING (1 << 6)
  30. #define SEL_INT_NUM_MASK 0x3f
  31. struct icu_chip_data {
  32. int nr_irqs;
  33. unsigned int virq_base;
  34. unsigned int cascade_irq;
  35. void __iomem *reg_status;
  36. void __iomem *reg_mask;
  37. unsigned int conf_enable;
  38. unsigned int conf_disable;
  39. unsigned int conf_mask;
  40. unsigned int clr_mfp_irq_base;
  41. unsigned int clr_mfp_hwirq;
  42. struct irq_domain *domain;
  43. };
  44. struct mmp_intc_conf {
  45. unsigned int conf_enable;
  46. unsigned int conf_disable;
  47. unsigned int conf_mask;
  48. };
  49. static void __iomem *mmp_icu_base;
  50. static struct icu_chip_data icu_data[MAX_ICU_NR];
  51. static int max_icu_nr;
  52. extern void mmp2_clear_pmic_int(void);
  53. static void icu_mask_ack_irq(struct irq_data *d)
  54. {
  55. struct irq_domain *domain = d->domain;
  56. struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
  57. int hwirq;
  58. u32 r;
  59. hwirq = d->irq - data->virq_base;
  60. if (data == &icu_data[0]) {
  61. r = readl_relaxed(mmp_icu_base + (hwirq << 2));
  62. r &= ~data->conf_mask;
  63. r |= data->conf_disable;
  64. writel_relaxed(r, mmp_icu_base + (hwirq << 2));
  65. } else {
  66. #ifdef CONFIG_CPU_MMP2
  67. if ((data->virq_base == data->clr_mfp_irq_base)
  68. && (hwirq == data->clr_mfp_hwirq))
  69. mmp2_clear_pmic_int();
  70. #endif
  71. r = readl_relaxed(data->reg_mask) | (1 << hwirq);
  72. writel_relaxed(r, data->reg_mask);
  73. }
  74. }
  75. static void icu_mask_irq(struct irq_data *d)
  76. {
  77. struct irq_domain *domain = d->domain;
  78. struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
  79. int hwirq;
  80. u32 r;
  81. hwirq = d->irq - data->virq_base;
  82. if (data == &icu_data[0]) {
  83. r = readl_relaxed(mmp_icu_base + (hwirq << 2));
  84. r &= ~data->conf_mask;
  85. r |= data->conf_disable;
  86. writel_relaxed(r, mmp_icu_base + (hwirq << 2));
  87. } else {
  88. r = readl_relaxed(data->reg_mask) | (1 << hwirq);
  89. writel_relaxed(r, data->reg_mask);
  90. }
  91. }
  92. static void icu_unmask_irq(struct irq_data *d)
  93. {
  94. struct irq_domain *domain = d->domain;
  95. struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
  96. int hwirq;
  97. u32 r;
  98. hwirq = d->irq - data->virq_base;
  99. if (data == &icu_data[0]) {
  100. r = readl_relaxed(mmp_icu_base + (hwirq << 2));
  101. r &= ~data->conf_mask;
  102. r |= data->conf_enable;
  103. writel_relaxed(r, mmp_icu_base + (hwirq << 2));
  104. } else {
  105. r = readl_relaxed(data->reg_mask) & ~(1 << hwirq);
  106. writel_relaxed(r, data->reg_mask);
  107. }
  108. }
  109. struct irq_chip icu_irq_chip = {
  110. .name = "icu_irq",
  111. .irq_mask = icu_mask_irq,
  112. .irq_mask_ack = icu_mask_ack_irq,
  113. .irq_unmask = icu_unmask_irq,
  114. };
  115. static void icu_mux_irq_demux(struct irq_desc *desc)
  116. {
  117. unsigned int irq = irq_desc_get_irq(desc);
  118. struct irq_domain *domain;
  119. struct icu_chip_data *data;
  120. int i;
  121. unsigned long mask, status, n;
  122. for (i = 1; i < max_icu_nr; i++) {
  123. if (irq == icu_data[i].cascade_irq) {
  124. domain = icu_data[i].domain;
  125. data = (struct icu_chip_data *)domain->host_data;
  126. break;
  127. }
  128. }
  129. if (i >= max_icu_nr) {
  130. pr_err("Spurious irq %d in MMP INTC\n", irq);
  131. return;
  132. }
  133. mask = readl_relaxed(data->reg_mask);
  134. while (1) {
  135. status = readl_relaxed(data->reg_status) & ~mask;
  136. if (status == 0)
  137. break;
  138. for_each_set_bit(n, &status, BITS_PER_LONG) {
  139. generic_handle_irq(icu_data[i].virq_base + n);
  140. }
  141. }
  142. }
  143. static int mmp_irq_domain_map(struct irq_domain *d, unsigned int irq,
  144. irq_hw_number_t hw)
  145. {
  146. irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq);
  147. return 0;
  148. }
  149. static int mmp_irq_domain_xlate(struct irq_domain *d, struct device_node *node,
  150. const u32 *intspec, unsigned int intsize,
  151. unsigned long *out_hwirq,
  152. unsigned int *out_type)
  153. {
  154. *out_hwirq = intspec[0];
  155. return 0;
  156. }
  157. const struct irq_domain_ops mmp_irq_domain_ops = {
  158. .map = mmp_irq_domain_map,
  159. .xlate = mmp_irq_domain_xlate,
  160. };
  161. static struct mmp_intc_conf mmp_conf = {
  162. .conf_enable = 0x51,
  163. .conf_disable = 0x0,
  164. .conf_mask = 0x7f,
  165. };
  166. static struct mmp_intc_conf mmp2_conf = {
  167. .conf_enable = 0x20,
  168. .conf_disable = 0x0,
  169. .conf_mask = 0x7f,
  170. };
  171. static void __exception_irq_entry mmp_handle_irq(struct pt_regs *regs)
  172. {
  173. int hwirq;
  174. hwirq = readl_relaxed(mmp_icu_base + PJ1_INT_SEL);
  175. if (!(hwirq & SEL_INT_PENDING))
  176. return;
  177. hwirq &= SEL_INT_NUM_MASK;
  178. handle_domain_irq(icu_data[0].domain, hwirq, regs);
  179. }
  180. static void __exception_irq_entry mmp2_handle_irq(struct pt_regs *regs)
  181. {
  182. int hwirq;
  183. hwirq = readl_relaxed(mmp_icu_base + PJ4_INT_SEL);
  184. if (!(hwirq & SEL_INT_PENDING))
  185. return;
  186. hwirq &= SEL_INT_NUM_MASK;
  187. handle_domain_irq(icu_data[0].domain, hwirq, regs);
  188. }
  189. /* MMP (ARMv5) */
  190. void __init icu_init_irq(void)
  191. {
  192. int irq;
  193. max_icu_nr = 1;
  194. mmp_icu_base = ioremap(0xd4282000, 0x1000);
  195. icu_data[0].conf_enable = mmp_conf.conf_enable;
  196. icu_data[0].conf_disable = mmp_conf.conf_disable;
  197. icu_data[0].conf_mask = mmp_conf.conf_mask;
  198. icu_data[0].nr_irqs = 64;
  199. icu_data[0].virq_base = 0;
  200. icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0,
  201. &irq_domain_simple_ops,
  202. &icu_data[0]);
  203. for (irq = 0; irq < 64; irq++) {
  204. icu_mask_irq(irq_get_irq_data(irq));
  205. irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq);
  206. }
  207. irq_set_default_host(icu_data[0].domain);
  208. set_handle_irq(mmp_handle_irq);
  209. }
  210. /* MMP2 (ARMv7) */
  211. void __init mmp2_init_icu(void)
  212. {
  213. int irq, end;
  214. max_icu_nr = 8;
  215. mmp_icu_base = ioremap(0xd4282000, 0x1000);
  216. icu_data[0].conf_enable = mmp2_conf.conf_enable;
  217. icu_data[0].conf_disable = mmp2_conf.conf_disable;
  218. icu_data[0].conf_mask = mmp2_conf.conf_mask;
  219. icu_data[0].nr_irqs = 64;
  220. icu_data[0].virq_base = 0;
  221. icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0,
  222. &irq_domain_simple_ops,
  223. &icu_data[0]);
  224. icu_data[1].reg_status = mmp_icu_base + 0x150;
  225. icu_data[1].reg_mask = mmp_icu_base + 0x168;
  226. icu_data[1].clr_mfp_irq_base = icu_data[0].virq_base +
  227. icu_data[0].nr_irqs;
  228. icu_data[1].clr_mfp_hwirq = 1; /* offset to IRQ_MMP2_PMIC_BASE */
  229. icu_data[1].nr_irqs = 2;
  230. icu_data[1].cascade_irq = 4;
  231. icu_data[1].virq_base = icu_data[0].virq_base + icu_data[0].nr_irqs;
  232. icu_data[1].domain = irq_domain_add_legacy(NULL, icu_data[1].nr_irqs,
  233. icu_data[1].virq_base, 0,
  234. &irq_domain_simple_ops,
  235. &icu_data[1]);
  236. icu_data[2].reg_status = mmp_icu_base + 0x154;
  237. icu_data[2].reg_mask = mmp_icu_base + 0x16c;
  238. icu_data[2].nr_irqs = 2;
  239. icu_data[2].cascade_irq = 5;
  240. icu_data[2].virq_base = icu_data[1].virq_base + icu_data[1].nr_irqs;
  241. icu_data[2].domain = irq_domain_add_legacy(NULL, icu_data[2].nr_irqs,
  242. icu_data[2].virq_base, 0,
  243. &irq_domain_simple_ops,
  244. &icu_data[2]);
  245. icu_data[3].reg_status = mmp_icu_base + 0x180;
  246. icu_data[3].reg_mask = mmp_icu_base + 0x17c;
  247. icu_data[3].nr_irqs = 3;
  248. icu_data[3].cascade_irq = 9;
  249. icu_data[3].virq_base = icu_data[2].virq_base + icu_data[2].nr_irqs;
  250. icu_data[3].domain = irq_domain_add_legacy(NULL, icu_data[3].nr_irqs,
  251. icu_data[3].virq_base, 0,
  252. &irq_domain_simple_ops,
  253. &icu_data[3]);
  254. icu_data[4].reg_status = mmp_icu_base + 0x158;
  255. icu_data[4].reg_mask = mmp_icu_base + 0x170;
  256. icu_data[4].nr_irqs = 5;
  257. icu_data[4].cascade_irq = 17;
  258. icu_data[4].virq_base = icu_data[3].virq_base + icu_data[3].nr_irqs;
  259. icu_data[4].domain = irq_domain_add_legacy(NULL, icu_data[4].nr_irqs,
  260. icu_data[4].virq_base, 0,
  261. &irq_domain_simple_ops,
  262. &icu_data[4]);
  263. icu_data[5].reg_status = mmp_icu_base + 0x15c;
  264. icu_data[5].reg_mask = mmp_icu_base + 0x174;
  265. icu_data[5].nr_irqs = 15;
  266. icu_data[5].cascade_irq = 35;
  267. icu_data[5].virq_base = icu_data[4].virq_base + icu_data[4].nr_irqs;
  268. icu_data[5].domain = irq_domain_add_legacy(NULL, icu_data[5].nr_irqs,
  269. icu_data[5].virq_base, 0,
  270. &irq_domain_simple_ops,
  271. &icu_data[5]);
  272. icu_data[6].reg_status = mmp_icu_base + 0x160;
  273. icu_data[6].reg_mask = mmp_icu_base + 0x178;
  274. icu_data[6].nr_irqs = 2;
  275. icu_data[6].cascade_irq = 51;
  276. icu_data[6].virq_base = icu_data[5].virq_base + icu_data[5].nr_irqs;
  277. icu_data[6].domain = irq_domain_add_legacy(NULL, icu_data[6].nr_irqs,
  278. icu_data[6].virq_base, 0,
  279. &irq_domain_simple_ops,
  280. &icu_data[6]);
  281. icu_data[7].reg_status = mmp_icu_base + 0x188;
  282. icu_data[7].reg_mask = mmp_icu_base + 0x184;
  283. icu_data[7].nr_irqs = 2;
  284. icu_data[7].cascade_irq = 55;
  285. icu_data[7].virq_base = icu_data[6].virq_base + icu_data[6].nr_irqs;
  286. icu_data[7].domain = irq_domain_add_legacy(NULL, icu_data[7].nr_irqs,
  287. icu_data[7].virq_base, 0,
  288. &irq_domain_simple_ops,
  289. &icu_data[7]);
  290. end = icu_data[7].virq_base + icu_data[7].nr_irqs;
  291. for (irq = 0; irq < end; irq++) {
  292. icu_mask_irq(irq_get_irq_data(irq));
  293. if (irq == icu_data[1].cascade_irq ||
  294. irq == icu_data[2].cascade_irq ||
  295. irq == icu_data[3].cascade_irq ||
  296. irq == icu_data[4].cascade_irq ||
  297. irq == icu_data[5].cascade_irq ||
  298. irq == icu_data[6].cascade_irq ||
  299. irq == icu_data[7].cascade_irq) {
  300. irq_set_chip(irq, &icu_irq_chip);
  301. irq_set_chained_handler(irq, icu_mux_irq_demux);
  302. } else {
  303. irq_set_chip_and_handler(irq, &icu_irq_chip,
  304. handle_level_irq);
  305. }
  306. }
  307. irq_set_default_host(icu_data[0].domain);
  308. set_handle_irq(mmp2_handle_irq);
  309. }
  310. #ifdef CONFIG_OF
  311. static int __init mmp_init_bases(struct device_node *node)
  312. {
  313. int ret, nr_irqs, irq, i = 0;
  314. ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", &nr_irqs);
  315. if (ret) {
  316. pr_err("Not found mrvl,intc-nr-irqs property\n");
  317. return ret;
  318. }
  319. mmp_icu_base = of_iomap(node, 0);
  320. if (!mmp_icu_base) {
  321. pr_err("Failed to get interrupt controller register\n");
  322. return -ENOMEM;
  323. }
  324. icu_data[0].virq_base = 0;
  325. icu_data[0].domain = irq_domain_add_linear(node, nr_irqs,
  326. &mmp_irq_domain_ops,
  327. &icu_data[0]);
  328. for (irq = 0; irq < nr_irqs; irq++) {
  329. ret = irq_create_mapping(icu_data[0].domain, irq);
  330. if (!ret) {
  331. pr_err("Failed to mapping hwirq\n");
  332. goto err;
  333. }
  334. if (!irq)
  335. icu_data[0].virq_base = ret;
  336. }
  337. icu_data[0].nr_irqs = nr_irqs;
  338. return 0;
  339. err:
  340. if (icu_data[0].virq_base) {
  341. for (i = 0; i < irq; i++)
  342. irq_dispose_mapping(icu_data[0].virq_base + i);
  343. }
  344. irq_domain_remove(icu_data[0].domain);
  345. iounmap(mmp_icu_base);
  346. return -EINVAL;
  347. }
  348. static int __init mmp_of_init(struct device_node *node,
  349. struct device_node *parent)
  350. {
  351. int ret;
  352. ret = mmp_init_bases(node);
  353. if (ret < 0)
  354. return ret;
  355. icu_data[0].conf_enable = mmp_conf.conf_enable;
  356. icu_data[0].conf_disable = mmp_conf.conf_disable;
  357. icu_data[0].conf_mask = mmp_conf.conf_mask;
  358. irq_set_default_host(icu_data[0].domain);
  359. set_handle_irq(mmp_handle_irq);
  360. max_icu_nr = 1;
  361. return 0;
  362. }
  363. IRQCHIP_DECLARE(mmp_intc, "mrvl,mmp-intc", mmp_of_init);
  364. static int __init mmp2_of_init(struct device_node *node,
  365. struct device_node *parent)
  366. {
  367. int ret;
  368. ret = mmp_init_bases(node);
  369. if (ret < 0)
  370. return ret;
  371. icu_data[0].conf_enable = mmp2_conf.conf_enable;
  372. icu_data[0].conf_disable = mmp2_conf.conf_disable;
  373. icu_data[0].conf_mask = mmp2_conf.conf_mask;
  374. irq_set_default_host(icu_data[0].domain);
  375. set_handle_irq(mmp2_handle_irq);
  376. max_icu_nr = 1;
  377. return 0;
  378. }
  379. IRQCHIP_DECLARE(mmp2_intc, "mrvl,mmp2-intc", mmp2_of_init);
  380. static int __init mmp2_mux_of_init(struct device_node *node,
  381. struct device_node *parent)
  382. {
  383. struct resource res;
  384. int i, ret, irq, j = 0;
  385. u32 nr_irqs, mfp_irq;
  386. if (!parent)
  387. return -ENODEV;
  388. i = max_icu_nr;
  389. ret = of_property_read_u32(node, "mrvl,intc-nr-irqs",
  390. &nr_irqs);
  391. if (ret) {
  392. pr_err("Not found mrvl,intc-nr-irqs property\n");
  393. return -EINVAL;
  394. }
  395. ret = of_address_to_resource(node, 0, &res);
  396. if (ret < 0) {
  397. pr_err("Not found reg property\n");
  398. return -EINVAL;
  399. }
  400. icu_data[i].reg_status = mmp_icu_base + res.start;
  401. ret = of_address_to_resource(node, 1, &res);
  402. if (ret < 0) {
  403. pr_err("Not found reg property\n");
  404. return -EINVAL;
  405. }
  406. icu_data[i].reg_mask = mmp_icu_base + res.start;
  407. icu_data[i].cascade_irq = irq_of_parse_and_map(node, 0);
  408. if (!icu_data[i].cascade_irq)
  409. return -EINVAL;
  410. icu_data[i].virq_base = 0;
  411. icu_data[i].domain = irq_domain_add_linear(node, nr_irqs,
  412. &mmp_irq_domain_ops,
  413. &icu_data[i]);
  414. for (irq = 0; irq < nr_irqs; irq++) {
  415. ret = irq_create_mapping(icu_data[i].domain, irq);
  416. if (!ret) {
  417. pr_err("Failed to mapping hwirq\n");
  418. goto err;
  419. }
  420. if (!irq)
  421. icu_data[i].virq_base = ret;
  422. }
  423. icu_data[i].nr_irqs = nr_irqs;
  424. if (!of_property_read_u32(node, "mrvl,clr-mfp-irq",
  425. &mfp_irq)) {
  426. icu_data[i].clr_mfp_irq_base = icu_data[i].virq_base;
  427. icu_data[i].clr_mfp_hwirq = mfp_irq;
  428. }
  429. irq_set_chained_handler(icu_data[i].cascade_irq,
  430. icu_mux_irq_demux);
  431. max_icu_nr++;
  432. return 0;
  433. err:
  434. if (icu_data[i].virq_base) {
  435. for (j = 0; j < irq; j++)
  436. irq_dispose_mapping(icu_data[i].virq_base + j);
  437. }
  438. irq_domain_remove(icu_data[i].domain);
  439. return -EINVAL;
  440. }
  441. IRQCHIP_DECLARE(mmp2_mux_intc, "mrvl,mmp2-mux-intc", mmp2_mux_of_init);
  442. #endif