ipic.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. /*
  2. * arch/powerpc/sysdev/ipic.c
  3. *
  4. * IPIC routines implementations.
  5. *
  6. * Copyright 2005 Freescale Semiconductor, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/errno.h>
  16. #include <linux/reboot.h>
  17. #include <linux/slab.h>
  18. #include <linux/stddef.h>
  19. #include <linux/sched.h>
  20. #include <linux/signal.h>
  21. #include <linux/syscore_ops.h>
  22. #include <linux/device.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/fsl_devices.h>
  25. #include <asm/irq.h>
  26. #include <asm/io.h>
  27. #include <asm/prom.h>
  28. #include <asm/ipic.h>
  29. #include "ipic.h"
  30. static struct ipic * primary_ipic;
  31. static struct irq_chip ipic_level_irq_chip, ipic_edge_irq_chip;
  32. static DEFINE_RAW_SPINLOCK(ipic_lock);
  33. static struct ipic_info ipic_info[] = {
  34. [1] = {
  35. .mask = IPIC_SIMSR_H,
  36. .prio = IPIC_SIPRR_C,
  37. .force = IPIC_SIFCR_H,
  38. .bit = 16,
  39. .prio_mask = 0,
  40. },
  41. [2] = {
  42. .mask = IPIC_SIMSR_H,
  43. .prio = IPIC_SIPRR_C,
  44. .force = IPIC_SIFCR_H,
  45. .bit = 17,
  46. .prio_mask = 1,
  47. },
  48. [3] = {
  49. .mask = IPIC_SIMSR_H,
  50. .prio = IPIC_SIPRR_C,
  51. .force = IPIC_SIFCR_H,
  52. .bit = 18,
  53. .prio_mask = 2,
  54. },
  55. [4] = {
  56. .mask = IPIC_SIMSR_H,
  57. .prio = IPIC_SIPRR_C,
  58. .force = IPIC_SIFCR_H,
  59. .bit = 19,
  60. .prio_mask = 3,
  61. },
  62. [5] = {
  63. .mask = IPIC_SIMSR_H,
  64. .prio = IPIC_SIPRR_C,
  65. .force = IPIC_SIFCR_H,
  66. .bit = 20,
  67. .prio_mask = 4,
  68. },
  69. [6] = {
  70. .mask = IPIC_SIMSR_H,
  71. .prio = IPIC_SIPRR_C,
  72. .force = IPIC_SIFCR_H,
  73. .bit = 21,
  74. .prio_mask = 5,
  75. },
  76. [7] = {
  77. .mask = IPIC_SIMSR_H,
  78. .prio = IPIC_SIPRR_C,
  79. .force = IPIC_SIFCR_H,
  80. .bit = 22,
  81. .prio_mask = 6,
  82. },
  83. [8] = {
  84. .mask = IPIC_SIMSR_H,
  85. .prio = IPIC_SIPRR_C,
  86. .force = IPIC_SIFCR_H,
  87. .bit = 23,
  88. .prio_mask = 7,
  89. },
  90. [9] = {
  91. .mask = IPIC_SIMSR_H,
  92. .prio = IPIC_SIPRR_D,
  93. .force = IPIC_SIFCR_H,
  94. .bit = 24,
  95. .prio_mask = 0,
  96. },
  97. [10] = {
  98. .mask = IPIC_SIMSR_H,
  99. .prio = IPIC_SIPRR_D,
  100. .force = IPIC_SIFCR_H,
  101. .bit = 25,
  102. .prio_mask = 1,
  103. },
  104. [11] = {
  105. .mask = IPIC_SIMSR_H,
  106. .prio = IPIC_SIPRR_D,
  107. .force = IPIC_SIFCR_H,
  108. .bit = 26,
  109. .prio_mask = 2,
  110. },
  111. [12] = {
  112. .mask = IPIC_SIMSR_H,
  113. .prio = IPIC_SIPRR_D,
  114. .force = IPIC_SIFCR_H,
  115. .bit = 27,
  116. .prio_mask = 3,
  117. },
  118. [13] = {
  119. .mask = IPIC_SIMSR_H,
  120. .prio = IPIC_SIPRR_D,
  121. .force = IPIC_SIFCR_H,
  122. .bit = 28,
  123. .prio_mask = 4,
  124. },
  125. [14] = {
  126. .mask = IPIC_SIMSR_H,
  127. .prio = IPIC_SIPRR_D,
  128. .force = IPIC_SIFCR_H,
  129. .bit = 29,
  130. .prio_mask = 5,
  131. },
  132. [15] = {
  133. .mask = IPIC_SIMSR_H,
  134. .prio = IPIC_SIPRR_D,
  135. .force = IPIC_SIFCR_H,
  136. .bit = 30,
  137. .prio_mask = 6,
  138. },
  139. [16] = {
  140. .mask = IPIC_SIMSR_H,
  141. .prio = IPIC_SIPRR_D,
  142. .force = IPIC_SIFCR_H,
  143. .bit = 31,
  144. .prio_mask = 7,
  145. },
  146. [17] = {
  147. .ack = IPIC_SEPNR,
  148. .mask = IPIC_SEMSR,
  149. .prio = IPIC_SMPRR_A,
  150. .force = IPIC_SEFCR,
  151. .bit = 1,
  152. .prio_mask = 5,
  153. },
  154. [18] = {
  155. .ack = IPIC_SEPNR,
  156. .mask = IPIC_SEMSR,
  157. .prio = IPIC_SMPRR_A,
  158. .force = IPIC_SEFCR,
  159. .bit = 2,
  160. .prio_mask = 6,
  161. },
  162. [19] = {
  163. .ack = IPIC_SEPNR,
  164. .mask = IPIC_SEMSR,
  165. .prio = IPIC_SMPRR_A,
  166. .force = IPIC_SEFCR,
  167. .bit = 3,
  168. .prio_mask = 7,
  169. },
  170. [20] = {
  171. .ack = IPIC_SEPNR,
  172. .mask = IPIC_SEMSR,
  173. .prio = IPIC_SMPRR_B,
  174. .force = IPIC_SEFCR,
  175. .bit = 4,
  176. .prio_mask = 4,
  177. },
  178. [21] = {
  179. .ack = IPIC_SEPNR,
  180. .mask = IPIC_SEMSR,
  181. .prio = IPIC_SMPRR_B,
  182. .force = IPIC_SEFCR,
  183. .bit = 5,
  184. .prio_mask = 5,
  185. },
  186. [22] = {
  187. .ack = IPIC_SEPNR,
  188. .mask = IPIC_SEMSR,
  189. .prio = IPIC_SMPRR_B,
  190. .force = IPIC_SEFCR,
  191. .bit = 6,
  192. .prio_mask = 6,
  193. },
  194. [23] = {
  195. .ack = IPIC_SEPNR,
  196. .mask = IPIC_SEMSR,
  197. .prio = IPIC_SMPRR_B,
  198. .force = IPIC_SEFCR,
  199. .bit = 7,
  200. .prio_mask = 7,
  201. },
  202. [32] = {
  203. .mask = IPIC_SIMSR_H,
  204. .prio = IPIC_SIPRR_A,
  205. .force = IPIC_SIFCR_H,
  206. .bit = 0,
  207. .prio_mask = 0,
  208. },
  209. [33] = {
  210. .mask = IPIC_SIMSR_H,
  211. .prio = IPIC_SIPRR_A,
  212. .force = IPIC_SIFCR_H,
  213. .bit = 1,
  214. .prio_mask = 1,
  215. },
  216. [34] = {
  217. .mask = IPIC_SIMSR_H,
  218. .prio = IPIC_SIPRR_A,
  219. .force = IPIC_SIFCR_H,
  220. .bit = 2,
  221. .prio_mask = 2,
  222. },
  223. [35] = {
  224. .mask = IPIC_SIMSR_H,
  225. .prio = IPIC_SIPRR_A,
  226. .force = IPIC_SIFCR_H,
  227. .bit = 3,
  228. .prio_mask = 3,
  229. },
  230. [36] = {
  231. .mask = IPIC_SIMSR_H,
  232. .prio = IPIC_SIPRR_A,
  233. .force = IPIC_SIFCR_H,
  234. .bit = 4,
  235. .prio_mask = 4,
  236. },
  237. [37] = {
  238. .mask = IPIC_SIMSR_H,
  239. .prio = IPIC_SIPRR_A,
  240. .force = IPIC_SIFCR_H,
  241. .bit = 5,
  242. .prio_mask = 5,
  243. },
  244. [38] = {
  245. .mask = IPIC_SIMSR_H,
  246. .prio = IPIC_SIPRR_A,
  247. .force = IPIC_SIFCR_H,
  248. .bit = 6,
  249. .prio_mask = 6,
  250. },
  251. [39] = {
  252. .mask = IPIC_SIMSR_H,
  253. .prio = IPIC_SIPRR_A,
  254. .force = IPIC_SIFCR_H,
  255. .bit = 7,
  256. .prio_mask = 7,
  257. },
  258. [40] = {
  259. .mask = IPIC_SIMSR_H,
  260. .prio = IPIC_SIPRR_B,
  261. .force = IPIC_SIFCR_H,
  262. .bit = 8,
  263. .prio_mask = 0,
  264. },
  265. [41] = {
  266. .mask = IPIC_SIMSR_H,
  267. .prio = IPIC_SIPRR_B,
  268. .force = IPIC_SIFCR_H,
  269. .bit = 9,
  270. .prio_mask = 1,
  271. },
  272. [42] = {
  273. .mask = IPIC_SIMSR_H,
  274. .prio = IPIC_SIPRR_B,
  275. .force = IPIC_SIFCR_H,
  276. .bit = 10,
  277. .prio_mask = 2,
  278. },
  279. [43] = {
  280. .mask = IPIC_SIMSR_H,
  281. .prio = IPIC_SIPRR_B,
  282. .force = IPIC_SIFCR_H,
  283. .bit = 11,
  284. .prio_mask = 3,
  285. },
  286. [44] = {
  287. .mask = IPIC_SIMSR_H,
  288. .prio = IPIC_SIPRR_B,
  289. .force = IPIC_SIFCR_H,
  290. .bit = 12,
  291. .prio_mask = 4,
  292. },
  293. [45] = {
  294. .mask = IPIC_SIMSR_H,
  295. .prio = IPIC_SIPRR_B,
  296. .force = IPIC_SIFCR_H,
  297. .bit = 13,
  298. .prio_mask = 5,
  299. },
  300. [46] = {
  301. .mask = IPIC_SIMSR_H,
  302. .prio = IPIC_SIPRR_B,
  303. .force = IPIC_SIFCR_H,
  304. .bit = 14,
  305. .prio_mask = 6,
  306. },
  307. [47] = {
  308. .mask = IPIC_SIMSR_H,
  309. .prio = IPIC_SIPRR_B,
  310. .force = IPIC_SIFCR_H,
  311. .bit = 15,
  312. .prio_mask = 7,
  313. },
  314. [48] = {
  315. .mask = IPIC_SEMSR,
  316. .prio = IPIC_SMPRR_A,
  317. .force = IPIC_SEFCR,
  318. .bit = 0,
  319. .prio_mask = 4,
  320. },
  321. [64] = {
  322. .mask = IPIC_SIMSR_L,
  323. .prio = IPIC_SMPRR_A,
  324. .force = IPIC_SIFCR_L,
  325. .bit = 0,
  326. .prio_mask = 0,
  327. },
  328. [65] = {
  329. .mask = IPIC_SIMSR_L,
  330. .prio = IPIC_SMPRR_A,
  331. .force = IPIC_SIFCR_L,
  332. .bit = 1,
  333. .prio_mask = 1,
  334. },
  335. [66] = {
  336. .mask = IPIC_SIMSR_L,
  337. .prio = IPIC_SMPRR_A,
  338. .force = IPIC_SIFCR_L,
  339. .bit = 2,
  340. .prio_mask = 2,
  341. },
  342. [67] = {
  343. .mask = IPIC_SIMSR_L,
  344. .prio = IPIC_SMPRR_A,
  345. .force = IPIC_SIFCR_L,
  346. .bit = 3,
  347. .prio_mask = 3,
  348. },
  349. [68] = {
  350. .mask = IPIC_SIMSR_L,
  351. .prio = IPIC_SMPRR_B,
  352. .force = IPIC_SIFCR_L,
  353. .bit = 4,
  354. .prio_mask = 0,
  355. },
  356. [69] = {
  357. .mask = IPIC_SIMSR_L,
  358. .prio = IPIC_SMPRR_B,
  359. .force = IPIC_SIFCR_L,
  360. .bit = 5,
  361. .prio_mask = 1,
  362. },
  363. [70] = {
  364. .mask = IPIC_SIMSR_L,
  365. .prio = IPIC_SMPRR_B,
  366. .force = IPIC_SIFCR_L,
  367. .bit = 6,
  368. .prio_mask = 2,
  369. },
  370. [71] = {
  371. .mask = IPIC_SIMSR_L,
  372. .prio = IPIC_SMPRR_B,
  373. .force = IPIC_SIFCR_L,
  374. .bit = 7,
  375. .prio_mask = 3,
  376. },
  377. [72] = {
  378. .mask = IPIC_SIMSR_L,
  379. .prio = 0,
  380. .force = IPIC_SIFCR_L,
  381. .bit = 8,
  382. },
  383. [73] = {
  384. .mask = IPIC_SIMSR_L,
  385. .prio = 0,
  386. .force = IPIC_SIFCR_L,
  387. .bit = 9,
  388. },
  389. [74] = {
  390. .mask = IPIC_SIMSR_L,
  391. .prio = 0,
  392. .force = IPIC_SIFCR_L,
  393. .bit = 10,
  394. },
  395. [75] = {
  396. .mask = IPIC_SIMSR_L,
  397. .prio = 0,
  398. .force = IPIC_SIFCR_L,
  399. .bit = 11,
  400. },
  401. [76] = {
  402. .mask = IPIC_SIMSR_L,
  403. .prio = 0,
  404. .force = IPIC_SIFCR_L,
  405. .bit = 12,
  406. },
  407. [77] = {
  408. .mask = IPIC_SIMSR_L,
  409. .prio = 0,
  410. .force = IPIC_SIFCR_L,
  411. .bit = 13,
  412. },
  413. [78] = {
  414. .mask = IPIC_SIMSR_L,
  415. .prio = 0,
  416. .force = IPIC_SIFCR_L,
  417. .bit = 14,
  418. },
  419. [79] = {
  420. .mask = IPIC_SIMSR_L,
  421. .prio = 0,
  422. .force = IPIC_SIFCR_L,
  423. .bit = 15,
  424. },
  425. [80] = {
  426. .mask = IPIC_SIMSR_L,
  427. .prio = 0,
  428. .force = IPIC_SIFCR_L,
  429. .bit = 16,
  430. },
  431. [81] = {
  432. .mask = IPIC_SIMSR_L,
  433. .prio = 0,
  434. .force = IPIC_SIFCR_L,
  435. .bit = 17,
  436. },
  437. [82] = {
  438. .mask = IPIC_SIMSR_L,
  439. .prio = 0,
  440. .force = IPIC_SIFCR_L,
  441. .bit = 18,
  442. },
  443. [83] = {
  444. .mask = IPIC_SIMSR_L,
  445. .prio = 0,
  446. .force = IPIC_SIFCR_L,
  447. .bit = 19,
  448. },
  449. [84] = {
  450. .mask = IPIC_SIMSR_L,
  451. .prio = 0,
  452. .force = IPIC_SIFCR_L,
  453. .bit = 20,
  454. },
  455. [85] = {
  456. .mask = IPIC_SIMSR_L,
  457. .prio = 0,
  458. .force = IPIC_SIFCR_L,
  459. .bit = 21,
  460. },
  461. [86] = {
  462. .mask = IPIC_SIMSR_L,
  463. .prio = 0,
  464. .force = IPIC_SIFCR_L,
  465. .bit = 22,
  466. },
  467. [87] = {
  468. .mask = IPIC_SIMSR_L,
  469. .prio = 0,
  470. .force = IPIC_SIFCR_L,
  471. .bit = 23,
  472. },
  473. [88] = {
  474. .mask = IPIC_SIMSR_L,
  475. .prio = 0,
  476. .force = IPIC_SIFCR_L,
  477. .bit = 24,
  478. },
  479. [89] = {
  480. .mask = IPIC_SIMSR_L,
  481. .prio = 0,
  482. .force = IPIC_SIFCR_L,
  483. .bit = 25,
  484. },
  485. [90] = {
  486. .mask = IPIC_SIMSR_L,
  487. .prio = 0,
  488. .force = IPIC_SIFCR_L,
  489. .bit = 26,
  490. },
  491. [91] = {
  492. .mask = IPIC_SIMSR_L,
  493. .prio = 0,
  494. .force = IPIC_SIFCR_L,
  495. .bit = 27,
  496. },
  497. [94] = {
  498. .mask = IPIC_SIMSR_L,
  499. .prio = 0,
  500. .force = IPIC_SIFCR_L,
  501. .bit = 30,
  502. },
  503. };
  504. static inline u32 ipic_read(volatile u32 __iomem *base, unsigned int reg)
  505. {
  506. return in_be32(base + (reg >> 2));
  507. }
  508. static inline void ipic_write(volatile u32 __iomem *base, unsigned int reg, u32 value)
  509. {
  510. out_be32(base + (reg >> 2), value);
  511. }
  512. static inline struct ipic * ipic_from_irq(unsigned int virq)
  513. {
  514. return primary_ipic;
  515. }
  516. static void ipic_unmask_irq(struct irq_data *d)
  517. {
  518. struct ipic *ipic = ipic_from_irq(d->irq);
  519. unsigned int src = irqd_to_hwirq(d);
  520. unsigned long flags;
  521. u32 temp;
  522. raw_spin_lock_irqsave(&ipic_lock, flags);
  523. temp = ipic_read(ipic->regs, ipic_info[src].mask);
  524. temp |= (1 << (31 - ipic_info[src].bit));
  525. ipic_write(ipic->regs, ipic_info[src].mask, temp);
  526. raw_spin_unlock_irqrestore(&ipic_lock, flags);
  527. }
  528. static void ipic_mask_irq(struct irq_data *d)
  529. {
  530. struct ipic *ipic = ipic_from_irq(d->irq);
  531. unsigned int src = irqd_to_hwirq(d);
  532. unsigned long flags;
  533. u32 temp;
  534. raw_spin_lock_irqsave(&ipic_lock, flags);
  535. temp = ipic_read(ipic->regs, ipic_info[src].mask);
  536. temp &= ~(1 << (31 - ipic_info[src].bit));
  537. ipic_write(ipic->regs, ipic_info[src].mask, temp);
  538. /* mb() can't guarantee that masking is finished. But it does finish
  539. * for nearly all cases. */
  540. mb();
  541. raw_spin_unlock_irqrestore(&ipic_lock, flags);
  542. }
  543. static void ipic_ack_irq(struct irq_data *d)
  544. {
  545. struct ipic *ipic = ipic_from_irq(d->irq);
  546. unsigned int src = irqd_to_hwirq(d);
  547. unsigned long flags;
  548. u32 temp;
  549. raw_spin_lock_irqsave(&ipic_lock, flags);
  550. temp = 1 << (31 - ipic_info[src].bit);
  551. ipic_write(ipic->regs, ipic_info[src].ack, temp);
  552. /* mb() can't guarantee that ack is finished. But it does finish
  553. * for nearly all cases. */
  554. mb();
  555. raw_spin_unlock_irqrestore(&ipic_lock, flags);
  556. }
  557. static void ipic_mask_irq_and_ack(struct irq_data *d)
  558. {
  559. struct ipic *ipic = ipic_from_irq(d->irq);
  560. unsigned int src = irqd_to_hwirq(d);
  561. unsigned long flags;
  562. u32 temp;
  563. raw_spin_lock_irqsave(&ipic_lock, flags);
  564. temp = ipic_read(ipic->regs, ipic_info[src].mask);
  565. temp &= ~(1 << (31 - ipic_info[src].bit));
  566. ipic_write(ipic->regs, ipic_info[src].mask, temp);
  567. temp = 1 << (31 - ipic_info[src].bit);
  568. ipic_write(ipic->regs, ipic_info[src].ack, temp);
  569. /* mb() can't guarantee that ack is finished. But it does finish
  570. * for nearly all cases. */
  571. mb();
  572. raw_spin_unlock_irqrestore(&ipic_lock, flags);
  573. }
  574. static int ipic_set_irq_type(struct irq_data *d, unsigned int flow_type)
  575. {
  576. struct ipic *ipic = ipic_from_irq(d->irq);
  577. unsigned int src = irqd_to_hwirq(d);
  578. unsigned int vold, vnew, edibit;
  579. if (flow_type == IRQ_TYPE_NONE)
  580. flow_type = IRQ_TYPE_LEVEL_LOW;
  581. /* ipic supports only low assertion and high-to-low change senses
  582. */
  583. if (!(flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING))) {
  584. printk(KERN_ERR "ipic: sense type 0x%x not supported\n",
  585. flow_type);
  586. return -EINVAL;
  587. }
  588. /* ipic supports only edge mode on external interrupts */
  589. if ((flow_type & IRQ_TYPE_EDGE_FALLING) && !ipic_info[src].ack) {
  590. printk(KERN_ERR "ipic: edge sense not supported on internal "
  591. "interrupts\n");
  592. return -EINVAL;
  593. }
  594. irqd_set_trigger_type(d, flow_type);
  595. if (flow_type & IRQ_TYPE_LEVEL_LOW) {
  596. irq_set_handler_locked(d, handle_level_irq);
  597. d->chip = &ipic_level_irq_chip;
  598. } else {
  599. irq_set_handler_locked(d, handle_edge_irq);
  600. d->chip = &ipic_edge_irq_chip;
  601. }
  602. /* only EXT IRQ senses are programmable on ipic
  603. * internal IRQ senses are LEVEL_LOW
  604. */
  605. if (src == IPIC_IRQ_EXT0)
  606. edibit = 15;
  607. else
  608. if (src >= IPIC_IRQ_EXT1 && src <= IPIC_IRQ_EXT7)
  609. edibit = (14 - (src - IPIC_IRQ_EXT1));
  610. else
  611. return (flow_type & IRQ_TYPE_LEVEL_LOW) ? 0 : -EINVAL;
  612. vold = ipic_read(ipic->regs, IPIC_SECNR);
  613. if ((flow_type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_FALLING) {
  614. vnew = vold | (1 << edibit);
  615. } else {
  616. vnew = vold & ~(1 << edibit);
  617. }
  618. if (vold != vnew)
  619. ipic_write(ipic->regs, IPIC_SECNR, vnew);
  620. return IRQ_SET_MASK_OK_NOCOPY;
  621. }
  622. /* level interrupts and edge interrupts have different ack operations */
  623. static struct irq_chip ipic_level_irq_chip = {
  624. .name = "IPIC",
  625. .irq_unmask = ipic_unmask_irq,
  626. .irq_mask = ipic_mask_irq,
  627. .irq_mask_ack = ipic_mask_irq,
  628. .irq_set_type = ipic_set_irq_type,
  629. };
  630. static struct irq_chip ipic_edge_irq_chip = {
  631. .name = "IPIC",
  632. .irq_unmask = ipic_unmask_irq,
  633. .irq_mask = ipic_mask_irq,
  634. .irq_mask_ack = ipic_mask_irq_and_ack,
  635. .irq_ack = ipic_ack_irq,
  636. .irq_set_type = ipic_set_irq_type,
  637. };
  638. static int ipic_host_match(struct irq_domain *h, struct device_node *node,
  639. enum irq_domain_bus_token bus_token)
  640. {
  641. /* Exact match, unless ipic node is NULL */
  642. struct device_node *of_node = irq_domain_get_of_node(h);
  643. return of_node == NULL || of_node == node;
  644. }
  645. static int ipic_host_map(struct irq_domain *h, unsigned int virq,
  646. irq_hw_number_t hw)
  647. {
  648. struct ipic *ipic = h->host_data;
  649. irq_set_chip_data(virq, ipic);
  650. irq_set_chip_and_handler(virq, &ipic_level_irq_chip, handle_level_irq);
  651. /* Set default irq type */
  652. irq_set_irq_type(virq, IRQ_TYPE_NONE);
  653. return 0;
  654. }
  655. static const struct irq_domain_ops ipic_host_ops = {
  656. .match = ipic_host_match,
  657. .map = ipic_host_map,
  658. .xlate = irq_domain_xlate_onetwocell,
  659. };
  660. struct ipic * __init ipic_init(struct device_node *node, unsigned int flags)
  661. {
  662. struct ipic *ipic;
  663. struct resource res;
  664. u32 temp = 0, ret;
  665. ret = of_address_to_resource(node, 0, &res);
  666. if (ret)
  667. return NULL;
  668. ipic = kzalloc(sizeof(*ipic), GFP_KERNEL);
  669. if (ipic == NULL)
  670. return NULL;
  671. ipic->irqhost = irq_domain_add_linear(node, NR_IPIC_INTS,
  672. &ipic_host_ops, ipic);
  673. if (ipic->irqhost == NULL) {
  674. kfree(ipic);
  675. return NULL;
  676. }
  677. ipic->regs = ioremap(res.start, resource_size(&res));
  678. /* init hw */
  679. ipic_write(ipic->regs, IPIC_SICNR, 0x0);
  680. /* default priority scheme is grouped. If spread mode is required
  681. * configure SICFR accordingly */
  682. if (flags & IPIC_SPREADMODE_GRP_A)
  683. temp |= SICFR_IPSA;
  684. if (flags & IPIC_SPREADMODE_GRP_B)
  685. temp |= SICFR_IPSB;
  686. if (flags & IPIC_SPREADMODE_GRP_C)
  687. temp |= SICFR_IPSC;
  688. if (flags & IPIC_SPREADMODE_GRP_D)
  689. temp |= SICFR_IPSD;
  690. if (flags & IPIC_SPREADMODE_MIX_A)
  691. temp |= SICFR_MPSA;
  692. if (flags & IPIC_SPREADMODE_MIX_B)
  693. temp |= SICFR_MPSB;
  694. ipic_write(ipic->regs, IPIC_SICFR, temp);
  695. /* handle MCP route */
  696. temp = 0;
  697. if (flags & IPIC_DISABLE_MCP_OUT)
  698. temp = SERCR_MCPR;
  699. ipic_write(ipic->regs, IPIC_SERCR, temp);
  700. /* handle routing of IRQ0 to MCP */
  701. temp = ipic_read(ipic->regs, IPIC_SEMSR);
  702. if (flags & IPIC_IRQ0_MCP)
  703. temp |= SEMSR_SIRQ0;
  704. else
  705. temp &= ~SEMSR_SIRQ0;
  706. ipic_write(ipic->regs, IPIC_SEMSR, temp);
  707. primary_ipic = ipic;
  708. irq_set_default_host(primary_ipic->irqhost);
  709. ipic_write(ipic->regs, IPIC_SIMSR_H, 0);
  710. ipic_write(ipic->regs, IPIC_SIMSR_L, 0);
  711. printk ("IPIC (%d IRQ sources) at %p\n", NR_IPIC_INTS,
  712. primary_ipic->regs);
  713. return ipic;
  714. }
  715. int ipic_set_priority(unsigned int virq, unsigned int priority)
  716. {
  717. struct ipic *ipic = ipic_from_irq(virq);
  718. unsigned int src = virq_to_hw(virq);
  719. u32 temp;
  720. if (priority > 7)
  721. return -EINVAL;
  722. if (src > 127)
  723. return -EINVAL;
  724. if (ipic_info[src].prio == 0)
  725. return -EINVAL;
  726. temp = ipic_read(ipic->regs, ipic_info[src].prio);
  727. if (priority < 4) {
  728. temp &= ~(0x7 << (20 + (3 - priority) * 3));
  729. temp |= ipic_info[src].prio_mask << (20 + (3 - priority) * 3);
  730. } else {
  731. temp &= ~(0x7 << (4 + (7 - priority) * 3));
  732. temp |= ipic_info[src].prio_mask << (4 + (7 - priority) * 3);
  733. }
  734. ipic_write(ipic->regs, ipic_info[src].prio, temp);
  735. return 0;
  736. }
  737. void ipic_set_highest_priority(unsigned int virq)
  738. {
  739. struct ipic *ipic = ipic_from_irq(virq);
  740. unsigned int src = virq_to_hw(virq);
  741. u32 temp;
  742. temp = ipic_read(ipic->regs, IPIC_SICFR);
  743. /* clear and set HPI */
  744. temp &= 0x7f000000;
  745. temp |= (src & 0x7f) << 24;
  746. ipic_write(ipic->regs, IPIC_SICFR, temp);
  747. }
  748. void ipic_set_default_priority(void)
  749. {
  750. ipic_write(primary_ipic->regs, IPIC_SIPRR_A, IPIC_PRIORITY_DEFAULT);
  751. ipic_write(primary_ipic->regs, IPIC_SIPRR_B, IPIC_PRIORITY_DEFAULT);
  752. ipic_write(primary_ipic->regs, IPIC_SIPRR_C, IPIC_PRIORITY_DEFAULT);
  753. ipic_write(primary_ipic->regs, IPIC_SIPRR_D, IPIC_PRIORITY_DEFAULT);
  754. ipic_write(primary_ipic->regs, IPIC_SMPRR_A, IPIC_PRIORITY_DEFAULT);
  755. ipic_write(primary_ipic->regs, IPIC_SMPRR_B, IPIC_PRIORITY_DEFAULT);
  756. }
  757. void ipic_enable_mcp(enum ipic_mcp_irq mcp_irq)
  758. {
  759. struct ipic *ipic = primary_ipic;
  760. u32 temp;
  761. temp = ipic_read(ipic->regs, IPIC_SERMR);
  762. temp |= (1 << (31 - mcp_irq));
  763. ipic_write(ipic->regs, IPIC_SERMR, temp);
  764. }
  765. void ipic_disable_mcp(enum ipic_mcp_irq mcp_irq)
  766. {
  767. struct ipic *ipic = primary_ipic;
  768. u32 temp;
  769. temp = ipic_read(ipic->regs, IPIC_SERMR);
  770. temp &= (1 << (31 - mcp_irq));
  771. ipic_write(ipic->regs, IPIC_SERMR, temp);
  772. }
  773. u32 ipic_get_mcp_status(void)
  774. {
  775. return ipic_read(primary_ipic->regs, IPIC_SERSR);
  776. }
  777. void ipic_clear_mcp_status(u32 mask)
  778. {
  779. ipic_write(primary_ipic->regs, IPIC_SERSR, mask);
  780. }
  781. /* Return an interrupt vector or NO_IRQ if no interrupt is pending. */
  782. unsigned int ipic_get_irq(void)
  783. {
  784. int irq;
  785. BUG_ON(primary_ipic == NULL);
  786. #define IPIC_SIVCR_VECTOR_MASK 0x7f
  787. irq = ipic_read(primary_ipic->regs, IPIC_SIVCR) & IPIC_SIVCR_VECTOR_MASK;
  788. if (irq == 0) /* 0 --> no irq is pending */
  789. return NO_IRQ;
  790. return irq_linear_revmap(primary_ipic->irqhost, irq);
  791. }
  792. #ifdef CONFIG_SUSPEND
  793. static struct {
  794. u32 sicfr;
  795. u32 siprr[2];
  796. u32 simsr[2];
  797. u32 sicnr;
  798. u32 smprr[2];
  799. u32 semsr;
  800. u32 secnr;
  801. u32 sermr;
  802. u32 sercr;
  803. } ipic_saved_state;
  804. static int ipic_suspend(void)
  805. {
  806. struct ipic *ipic = primary_ipic;
  807. ipic_saved_state.sicfr = ipic_read(ipic->regs, IPIC_SICFR);
  808. ipic_saved_state.siprr[0] = ipic_read(ipic->regs, IPIC_SIPRR_A);
  809. ipic_saved_state.siprr[1] = ipic_read(ipic->regs, IPIC_SIPRR_D);
  810. ipic_saved_state.simsr[0] = ipic_read(ipic->regs, IPIC_SIMSR_H);
  811. ipic_saved_state.simsr[1] = ipic_read(ipic->regs, IPIC_SIMSR_L);
  812. ipic_saved_state.sicnr = ipic_read(ipic->regs, IPIC_SICNR);
  813. ipic_saved_state.smprr[0] = ipic_read(ipic->regs, IPIC_SMPRR_A);
  814. ipic_saved_state.smprr[1] = ipic_read(ipic->regs, IPIC_SMPRR_B);
  815. ipic_saved_state.semsr = ipic_read(ipic->regs, IPIC_SEMSR);
  816. ipic_saved_state.secnr = ipic_read(ipic->regs, IPIC_SECNR);
  817. ipic_saved_state.sermr = ipic_read(ipic->regs, IPIC_SERMR);
  818. ipic_saved_state.sercr = ipic_read(ipic->regs, IPIC_SERCR);
  819. if (fsl_deep_sleep()) {
  820. /* In deep sleep, make sure there can be no
  821. * pending interrupts, as this can cause
  822. * problems on 831x.
  823. */
  824. ipic_write(ipic->regs, IPIC_SIMSR_H, 0);
  825. ipic_write(ipic->regs, IPIC_SIMSR_L, 0);
  826. ipic_write(ipic->regs, IPIC_SEMSR, 0);
  827. ipic_write(ipic->regs, IPIC_SERMR, 0);
  828. }
  829. return 0;
  830. }
  831. static void ipic_resume(void)
  832. {
  833. struct ipic *ipic = primary_ipic;
  834. ipic_write(ipic->regs, IPIC_SICFR, ipic_saved_state.sicfr);
  835. ipic_write(ipic->regs, IPIC_SIPRR_A, ipic_saved_state.siprr[0]);
  836. ipic_write(ipic->regs, IPIC_SIPRR_D, ipic_saved_state.siprr[1]);
  837. ipic_write(ipic->regs, IPIC_SIMSR_H, ipic_saved_state.simsr[0]);
  838. ipic_write(ipic->regs, IPIC_SIMSR_L, ipic_saved_state.simsr[1]);
  839. ipic_write(ipic->regs, IPIC_SICNR, ipic_saved_state.sicnr);
  840. ipic_write(ipic->regs, IPIC_SMPRR_A, ipic_saved_state.smprr[0]);
  841. ipic_write(ipic->regs, IPIC_SMPRR_B, ipic_saved_state.smprr[1]);
  842. ipic_write(ipic->regs, IPIC_SEMSR, ipic_saved_state.semsr);
  843. ipic_write(ipic->regs, IPIC_SECNR, ipic_saved_state.secnr);
  844. ipic_write(ipic->regs, IPIC_SERMR, ipic_saved_state.sermr);
  845. ipic_write(ipic->regs, IPIC_SERCR, ipic_saved_state.sercr);
  846. }
  847. #else
  848. #define ipic_suspend NULL
  849. #define ipic_resume NULL
  850. #endif
  851. static struct syscore_ops ipic_syscore_ops = {
  852. .suspend = ipic_suspend,
  853. .resume = ipic_resume,
  854. };
  855. static int __init init_ipic_syscore(void)
  856. {
  857. if (!primary_ipic || !primary_ipic->regs)
  858. return -ENODEV;
  859. printk(KERN_DEBUG "Registering ipic system core operations\n");
  860. register_syscore_ops(&ipic_syscore_ops);
  861. return 0;
  862. }
  863. subsys_initcall(init_ipic_syscore);