icu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /*
  2. * icu.c, Interrupt Control Unit routines for the NEC VR4100 series.
  3. *
  4. * Copyright (C) 2001-2002 MontaVista Software Inc.
  5. * Author: Yoichi Yuasa <source@mvista.com>
  6. * Copyright (C) 2003-2006 Yoichi Yuasa <yuasa@linux-mips.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. /*
  23. * Changes:
  24. * MontaVista Software Inc. <source@mvista.com>
  25. * - New creation, NEC VR4122 and VR4131 are supported.
  26. * - Added support for NEC VR4111 and VR4121.
  27. *
  28. * Yoichi Yuasa <yuasa@linux-mips.org>
  29. * - Coped with INTASSIGN of NEC VR4133.
  30. */
  31. #include <linux/errno.h>
  32. #include <linux/init.h>
  33. #include <linux/ioport.h>
  34. #include <linux/irq.h>
  35. #include <linux/module.h>
  36. #include <linux/smp.h>
  37. #include <linux/types.h>
  38. #include <asm/cpu.h>
  39. #include <asm/io.h>
  40. #include <asm/vr41xx/irq.h>
  41. #include <asm/vr41xx/vr41xx.h>
  42. static void __iomem *icu1_base;
  43. static void __iomem *icu2_base;
  44. static unsigned char sysint1_assign[16] = {
  45. 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  46. static unsigned char sysint2_assign[16] = {
  47. 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  48. #define ICU1_TYPE1_BASE 0x0b000080UL
  49. #define ICU2_TYPE1_BASE 0x0b000200UL
  50. #define ICU1_TYPE2_BASE 0x0f000080UL
  51. #define ICU2_TYPE2_BASE 0x0f0000a0UL
  52. #define ICU1_SIZE 0x20
  53. #define ICU2_SIZE 0x1c
  54. #define SYSINT1REG 0x00
  55. #define PIUINTREG 0x02
  56. #define INTASSIGN0 0x04
  57. #define INTASSIGN1 0x06
  58. #define GIUINTLREG 0x08
  59. #define DSIUINTREG 0x0a
  60. #define MSYSINT1REG 0x0c
  61. #define MPIUINTREG 0x0e
  62. #define MAIUINTREG 0x10
  63. #define MKIUINTREG 0x12
  64. #define MMACINTREG 0x12
  65. #define MGIUINTLREG 0x14
  66. #define MDSIUINTREG 0x16
  67. #define NMIREG 0x18
  68. #define SOFTREG 0x1a
  69. #define INTASSIGN2 0x1c
  70. #define INTASSIGN3 0x1e
  71. #define SYSINT2REG 0x00
  72. #define GIUINTHREG 0x02
  73. #define FIRINTREG 0x04
  74. #define MSYSINT2REG 0x06
  75. #define MGIUINTHREG 0x08
  76. #define MFIRINTREG 0x0a
  77. #define PCIINTREG 0x0c
  78. #define PCIINT0 0x0001
  79. #define SCUINTREG 0x0e
  80. #define SCUINT0 0x0001
  81. #define CSIINTREG 0x10
  82. #define MPCIINTREG 0x12
  83. #define MSCUINTREG 0x14
  84. #define MCSIINTREG 0x16
  85. #define BCUINTREG 0x18
  86. #define BCUINTR 0x0001
  87. #define MBCUINTREG 0x1a
  88. #define SYSINT1_IRQ_TO_PIN(x) ((x) - SYSINT1_IRQ_BASE) /* Pin 0-15 */
  89. #define SYSINT2_IRQ_TO_PIN(x) ((x) - SYSINT2_IRQ_BASE) /* Pin 0-15 */
  90. #define INT_TO_IRQ(x) ((x) + 2) /* Int0-4 -> IRQ2-6 */
  91. #define icu1_read(offset) readw(icu1_base + (offset))
  92. #define icu1_write(offset, value) writew((value), icu1_base + (offset))
  93. #define icu2_read(offset) readw(icu2_base + (offset))
  94. #define icu2_write(offset, value) writew((value), icu2_base + (offset))
  95. #define INTASSIGN_MAX 4
  96. #define INTASSIGN_MASK 0x0007
  97. static inline uint16_t icu1_set(uint8_t offset, uint16_t set)
  98. {
  99. uint16_t data;
  100. data = icu1_read(offset);
  101. data |= set;
  102. icu1_write(offset, data);
  103. return data;
  104. }
  105. static inline uint16_t icu1_clear(uint8_t offset, uint16_t clear)
  106. {
  107. uint16_t data;
  108. data = icu1_read(offset);
  109. data &= ~clear;
  110. icu1_write(offset, data);
  111. return data;
  112. }
  113. static inline uint16_t icu2_set(uint8_t offset, uint16_t set)
  114. {
  115. uint16_t data;
  116. data = icu2_read(offset);
  117. data |= set;
  118. icu2_write(offset, data);
  119. return data;
  120. }
  121. static inline uint16_t icu2_clear(uint8_t offset, uint16_t clear)
  122. {
  123. uint16_t data;
  124. data = icu2_read(offset);
  125. data &= ~clear;
  126. icu2_write(offset, data);
  127. return data;
  128. }
  129. void vr41xx_enable_piuint(uint16_t mask)
  130. {
  131. struct irq_desc *desc = irq_to_desc(PIU_IRQ);
  132. unsigned long flags;
  133. if (current_cpu_type() == CPU_VR4111 ||
  134. current_cpu_type() == CPU_VR4121) {
  135. raw_spin_lock_irqsave(&desc->lock, flags);
  136. icu1_set(MPIUINTREG, mask);
  137. raw_spin_unlock_irqrestore(&desc->lock, flags);
  138. }
  139. }
  140. EXPORT_SYMBOL(vr41xx_enable_piuint);
  141. void vr41xx_disable_piuint(uint16_t mask)
  142. {
  143. struct irq_desc *desc = irq_to_desc(PIU_IRQ);
  144. unsigned long flags;
  145. if (current_cpu_type() == CPU_VR4111 ||
  146. current_cpu_type() == CPU_VR4121) {
  147. raw_spin_lock_irqsave(&desc->lock, flags);
  148. icu1_clear(MPIUINTREG, mask);
  149. raw_spin_unlock_irqrestore(&desc->lock, flags);
  150. }
  151. }
  152. EXPORT_SYMBOL(vr41xx_disable_piuint);
  153. void vr41xx_enable_aiuint(uint16_t mask)
  154. {
  155. struct irq_desc *desc = irq_to_desc(AIU_IRQ);
  156. unsigned long flags;
  157. if (current_cpu_type() == CPU_VR4111 ||
  158. current_cpu_type() == CPU_VR4121) {
  159. raw_spin_lock_irqsave(&desc->lock, flags);
  160. icu1_set(MAIUINTREG, mask);
  161. raw_spin_unlock_irqrestore(&desc->lock, flags);
  162. }
  163. }
  164. EXPORT_SYMBOL(vr41xx_enable_aiuint);
  165. void vr41xx_disable_aiuint(uint16_t mask)
  166. {
  167. struct irq_desc *desc = irq_to_desc(AIU_IRQ);
  168. unsigned long flags;
  169. if (current_cpu_type() == CPU_VR4111 ||
  170. current_cpu_type() == CPU_VR4121) {
  171. raw_spin_lock_irqsave(&desc->lock, flags);
  172. icu1_clear(MAIUINTREG, mask);
  173. raw_spin_unlock_irqrestore(&desc->lock, flags);
  174. }
  175. }
  176. EXPORT_SYMBOL(vr41xx_disable_aiuint);
  177. void vr41xx_enable_kiuint(uint16_t mask)
  178. {
  179. struct irq_desc *desc = irq_to_desc(KIU_IRQ);
  180. unsigned long flags;
  181. if (current_cpu_type() == CPU_VR4111 ||
  182. current_cpu_type() == CPU_VR4121) {
  183. raw_spin_lock_irqsave(&desc->lock, flags);
  184. icu1_set(MKIUINTREG, mask);
  185. raw_spin_unlock_irqrestore(&desc->lock, flags);
  186. }
  187. }
  188. EXPORT_SYMBOL(vr41xx_enable_kiuint);
  189. void vr41xx_disable_kiuint(uint16_t mask)
  190. {
  191. struct irq_desc *desc = irq_to_desc(KIU_IRQ);
  192. unsigned long flags;
  193. if (current_cpu_type() == CPU_VR4111 ||
  194. current_cpu_type() == CPU_VR4121) {
  195. raw_spin_lock_irqsave(&desc->lock, flags);
  196. icu1_clear(MKIUINTREG, mask);
  197. raw_spin_unlock_irqrestore(&desc->lock, flags);
  198. }
  199. }
  200. EXPORT_SYMBOL(vr41xx_disable_kiuint);
  201. void vr41xx_enable_macint(uint16_t mask)
  202. {
  203. struct irq_desc *desc = irq_to_desc(ETHERNET_IRQ);
  204. unsigned long flags;
  205. raw_spin_lock_irqsave(&desc->lock, flags);
  206. icu1_set(MMACINTREG, mask);
  207. raw_spin_unlock_irqrestore(&desc->lock, flags);
  208. }
  209. EXPORT_SYMBOL(vr41xx_enable_macint);
  210. void vr41xx_disable_macint(uint16_t mask)
  211. {
  212. struct irq_desc *desc = irq_to_desc(ETHERNET_IRQ);
  213. unsigned long flags;
  214. raw_spin_lock_irqsave(&desc->lock, flags);
  215. icu1_clear(MMACINTREG, mask);
  216. raw_spin_unlock_irqrestore(&desc->lock, flags);
  217. }
  218. EXPORT_SYMBOL(vr41xx_disable_macint);
  219. void vr41xx_enable_dsiuint(uint16_t mask)
  220. {
  221. struct irq_desc *desc = irq_to_desc(DSIU_IRQ);
  222. unsigned long flags;
  223. raw_spin_lock_irqsave(&desc->lock, flags);
  224. icu1_set(MDSIUINTREG, mask);
  225. raw_spin_unlock_irqrestore(&desc->lock, flags);
  226. }
  227. EXPORT_SYMBOL(vr41xx_enable_dsiuint);
  228. void vr41xx_disable_dsiuint(uint16_t mask)
  229. {
  230. struct irq_desc *desc = irq_to_desc(DSIU_IRQ);
  231. unsigned long flags;
  232. raw_spin_lock_irqsave(&desc->lock, flags);
  233. icu1_clear(MDSIUINTREG, mask);
  234. raw_spin_unlock_irqrestore(&desc->lock, flags);
  235. }
  236. EXPORT_SYMBOL(vr41xx_disable_dsiuint);
  237. void vr41xx_enable_firint(uint16_t mask)
  238. {
  239. struct irq_desc *desc = irq_to_desc(FIR_IRQ);
  240. unsigned long flags;
  241. raw_spin_lock_irqsave(&desc->lock, flags);
  242. icu2_set(MFIRINTREG, mask);
  243. raw_spin_unlock_irqrestore(&desc->lock, flags);
  244. }
  245. EXPORT_SYMBOL(vr41xx_enable_firint);
  246. void vr41xx_disable_firint(uint16_t mask)
  247. {
  248. struct irq_desc *desc = irq_to_desc(FIR_IRQ);
  249. unsigned long flags;
  250. raw_spin_lock_irqsave(&desc->lock, flags);
  251. icu2_clear(MFIRINTREG, mask);
  252. raw_spin_unlock_irqrestore(&desc->lock, flags);
  253. }
  254. EXPORT_SYMBOL(vr41xx_disable_firint);
  255. void vr41xx_enable_pciint(void)
  256. {
  257. struct irq_desc *desc = irq_to_desc(PCI_IRQ);
  258. unsigned long flags;
  259. if (current_cpu_type() == CPU_VR4122 ||
  260. current_cpu_type() == CPU_VR4131 ||
  261. current_cpu_type() == CPU_VR4133) {
  262. raw_spin_lock_irqsave(&desc->lock, flags);
  263. icu2_write(MPCIINTREG, PCIINT0);
  264. raw_spin_unlock_irqrestore(&desc->lock, flags);
  265. }
  266. }
  267. EXPORT_SYMBOL(vr41xx_enable_pciint);
  268. void vr41xx_disable_pciint(void)
  269. {
  270. struct irq_desc *desc = irq_to_desc(PCI_IRQ);
  271. unsigned long flags;
  272. if (current_cpu_type() == CPU_VR4122 ||
  273. current_cpu_type() == CPU_VR4131 ||
  274. current_cpu_type() == CPU_VR4133) {
  275. raw_spin_lock_irqsave(&desc->lock, flags);
  276. icu2_write(MPCIINTREG, 0);
  277. raw_spin_unlock_irqrestore(&desc->lock, flags);
  278. }
  279. }
  280. EXPORT_SYMBOL(vr41xx_disable_pciint);
  281. void vr41xx_enable_scuint(void)
  282. {
  283. struct irq_desc *desc = irq_to_desc(SCU_IRQ);
  284. unsigned long flags;
  285. if (current_cpu_type() == CPU_VR4122 ||
  286. current_cpu_type() == CPU_VR4131 ||
  287. current_cpu_type() == CPU_VR4133) {
  288. raw_spin_lock_irqsave(&desc->lock, flags);
  289. icu2_write(MSCUINTREG, SCUINT0);
  290. raw_spin_unlock_irqrestore(&desc->lock, flags);
  291. }
  292. }
  293. EXPORT_SYMBOL(vr41xx_enable_scuint);
  294. void vr41xx_disable_scuint(void)
  295. {
  296. struct irq_desc *desc = irq_to_desc(SCU_IRQ);
  297. unsigned long flags;
  298. if (current_cpu_type() == CPU_VR4122 ||
  299. current_cpu_type() == CPU_VR4131 ||
  300. current_cpu_type() == CPU_VR4133) {
  301. raw_spin_lock_irqsave(&desc->lock, flags);
  302. icu2_write(MSCUINTREG, 0);
  303. raw_spin_unlock_irqrestore(&desc->lock, flags);
  304. }
  305. }
  306. EXPORT_SYMBOL(vr41xx_disable_scuint);
  307. void vr41xx_enable_csiint(uint16_t mask)
  308. {
  309. struct irq_desc *desc = irq_to_desc(CSI_IRQ);
  310. unsigned long flags;
  311. if (current_cpu_type() == CPU_VR4122 ||
  312. current_cpu_type() == CPU_VR4131 ||
  313. current_cpu_type() == CPU_VR4133) {
  314. raw_spin_lock_irqsave(&desc->lock, flags);
  315. icu2_set(MCSIINTREG, mask);
  316. raw_spin_unlock_irqrestore(&desc->lock, flags);
  317. }
  318. }
  319. EXPORT_SYMBOL(vr41xx_enable_csiint);
  320. void vr41xx_disable_csiint(uint16_t mask)
  321. {
  322. struct irq_desc *desc = irq_to_desc(CSI_IRQ);
  323. unsigned long flags;
  324. if (current_cpu_type() == CPU_VR4122 ||
  325. current_cpu_type() == CPU_VR4131 ||
  326. current_cpu_type() == CPU_VR4133) {
  327. raw_spin_lock_irqsave(&desc->lock, flags);
  328. icu2_clear(MCSIINTREG, mask);
  329. raw_spin_unlock_irqrestore(&desc->lock, flags);
  330. }
  331. }
  332. EXPORT_SYMBOL(vr41xx_disable_csiint);
  333. void vr41xx_enable_bcuint(void)
  334. {
  335. struct irq_desc *desc = irq_to_desc(BCU_IRQ);
  336. unsigned long flags;
  337. if (current_cpu_type() == CPU_VR4122 ||
  338. current_cpu_type() == CPU_VR4131 ||
  339. current_cpu_type() == CPU_VR4133) {
  340. raw_spin_lock_irqsave(&desc->lock, flags);
  341. icu2_write(MBCUINTREG, BCUINTR);
  342. raw_spin_unlock_irqrestore(&desc->lock, flags);
  343. }
  344. }
  345. EXPORT_SYMBOL(vr41xx_enable_bcuint);
  346. void vr41xx_disable_bcuint(void)
  347. {
  348. struct irq_desc *desc = irq_to_desc(BCU_IRQ);
  349. unsigned long flags;
  350. if (current_cpu_type() == CPU_VR4122 ||
  351. current_cpu_type() == CPU_VR4131 ||
  352. current_cpu_type() == CPU_VR4133) {
  353. raw_spin_lock_irqsave(&desc->lock, flags);
  354. icu2_write(MBCUINTREG, 0);
  355. raw_spin_unlock_irqrestore(&desc->lock, flags);
  356. }
  357. }
  358. EXPORT_SYMBOL(vr41xx_disable_bcuint);
  359. static void disable_sysint1_irq(struct irq_data *d)
  360. {
  361. icu1_clear(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(d->irq));
  362. }
  363. static void enable_sysint1_irq(struct irq_data *d)
  364. {
  365. icu1_set(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(d->irq));
  366. }
  367. static struct irq_chip sysint1_irq_type = {
  368. .name = "SYSINT1",
  369. .irq_mask = disable_sysint1_irq,
  370. .irq_unmask = enable_sysint1_irq,
  371. };
  372. static void disable_sysint2_irq(struct irq_data *d)
  373. {
  374. icu2_clear(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(d->irq));
  375. }
  376. static void enable_sysint2_irq(struct irq_data *d)
  377. {
  378. icu2_set(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(d->irq));
  379. }
  380. static struct irq_chip sysint2_irq_type = {
  381. .name = "SYSINT2",
  382. .irq_mask = disable_sysint2_irq,
  383. .irq_unmask = enable_sysint2_irq,
  384. };
  385. static inline int set_sysint1_assign(unsigned int irq, unsigned char assign)
  386. {
  387. struct irq_desc *desc = irq_to_desc(irq);
  388. uint16_t intassign0, intassign1;
  389. unsigned int pin;
  390. pin = SYSINT1_IRQ_TO_PIN(irq);
  391. raw_spin_lock_irq(&desc->lock);
  392. intassign0 = icu1_read(INTASSIGN0);
  393. intassign1 = icu1_read(INTASSIGN1);
  394. switch (pin) {
  395. case 0:
  396. intassign0 &= ~INTASSIGN_MASK;
  397. intassign0 |= (uint16_t)assign;
  398. break;
  399. case 1:
  400. intassign0 &= ~(INTASSIGN_MASK << 3);
  401. intassign0 |= (uint16_t)assign << 3;
  402. break;
  403. case 2:
  404. intassign0 &= ~(INTASSIGN_MASK << 6);
  405. intassign0 |= (uint16_t)assign << 6;
  406. break;
  407. case 3:
  408. intassign0 &= ~(INTASSIGN_MASK << 9);
  409. intassign0 |= (uint16_t)assign << 9;
  410. break;
  411. case 8:
  412. intassign0 &= ~(INTASSIGN_MASK << 12);
  413. intassign0 |= (uint16_t)assign << 12;
  414. break;
  415. case 9:
  416. intassign1 &= ~INTASSIGN_MASK;
  417. intassign1 |= (uint16_t)assign;
  418. break;
  419. case 11:
  420. intassign1 &= ~(INTASSIGN_MASK << 6);
  421. intassign1 |= (uint16_t)assign << 6;
  422. break;
  423. case 12:
  424. intassign1 &= ~(INTASSIGN_MASK << 9);
  425. intassign1 |= (uint16_t)assign << 9;
  426. break;
  427. default:
  428. raw_spin_unlock_irq(&desc->lock);
  429. return -EINVAL;
  430. }
  431. sysint1_assign[pin] = assign;
  432. icu1_write(INTASSIGN0, intassign0);
  433. icu1_write(INTASSIGN1, intassign1);
  434. raw_spin_unlock_irq(&desc->lock);
  435. return 0;
  436. }
  437. static inline int set_sysint2_assign(unsigned int irq, unsigned char assign)
  438. {
  439. struct irq_desc *desc = irq_to_desc(irq);
  440. uint16_t intassign2, intassign3;
  441. unsigned int pin;
  442. pin = SYSINT2_IRQ_TO_PIN(irq);
  443. raw_spin_lock_irq(&desc->lock);
  444. intassign2 = icu1_read(INTASSIGN2);
  445. intassign3 = icu1_read(INTASSIGN3);
  446. switch (pin) {
  447. case 0:
  448. intassign2 &= ~INTASSIGN_MASK;
  449. intassign2 |= (uint16_t)assign;
  450. break;
  451. case 1:
  452. intassign2 &= ~(INTASSIGN_MASK << 3);
  453. intassign2 |= (uint16_t)assign << 3;
  454. break;
  455. case 3:
  456. intassign2 &= ~(INTASSIGN_MASK << 6);
  457. intassign2 |= (uint16_t)assign << 6;
  458. break;
  459. case 4:
  460. intassign2 &= ~(INTASSIGN_MASK << 9);
  461. intassign2 |= (uint16_t)assign << 9;
  462. break;
  463. case 5:
  464. intassign2 &= ~(INTASSIGN_MASK << 12);
  465. intassign2 |= (uint16_t)assign << 12;
  466. break;
  467. case 6:
  468. intassign3 &= ~INTASSIGN_MASK;
  469. intassign3 |= (uint16_t)assign;
  470. break;
  471. case 7:
  472. intassign3 &= ~(INTASSIGN_MASK << 3);
  473. intassign3 |= (uint16_t)assign << 3;
  474. break;
  475. case 8:
  476. intassign3 &= ~(INTASSIGN_MASK << 6);
  477. intassign3 |= (uint16_t)assign << 6;
  478. break;
  479. case 9:
  480. intassign3 &= ~(INTASSIGN_MASK << 9);
  481. intassign3 |= (uint16_t)assign << 9;
  482. break;
  483. case 10:
  484. intassign3 &= ~(INTASSIGN_MASK << 12);
  485. intassign3 |= (uint16_t)assign << 12;
  486. break;
  487. default:
  488. raw_spin_unlock_irq(&desc->lock);
  489. return -EINVAL;
  490. }
  491. sysint2_assign[pin] = assign;
  492. icu1_write(INTASSIGN2, intassign2);
  493. icu1_write(INTASSIGN3, intassign3);
  494. raw_spin_unlock_irq(&desc->lock);
  495. return 0;
  496. }
  497. int vr41xx_set_intassign(unsigned int irq, unsigned char intassign)
  498. {
  499. int retval = -EINVAL;
  500. if (current_cpu_type() != CPU_VR4133)
  501. return -EINVAL;
  502. if (intassign > INTASSIGN_MAX)
  503. return -EINVAL;
  504. if (irq >= SYSINT1_IRQ_BASE && irq <= SYSINT1_IRQ_LAST)
  505. retval = set_sysint1_assign(irq, intassign);
  506. else if (irq >= SYSINT2_IRQ_BASE && irq <= SYSINT2_IRQ_LAST)
  507. retval = set_sysint2_assign(irq, intassign);
  508. return retval;
  509. }
  510. EXPORT_SYMBOL(vr41xx_set_intassign);
  511. static int icu_get_irq(unsigned int irq)
  512. {
  513. uint16_t pend1, pend2;
  514. uint16_t mask1, mask2;
  515. int i;
  516. pend1 = icu1_read(SYSINT1REG);
  517. mask1 = icu1_read(MSYSINT1REG);
  518. pend2 = icu2_read(SYSINT2REG);
  519. mask2 = icu2_read(MSYSINT2REG);
  520. mask1 &= pend1;
  521. mask2 &= pend2;
  522. if (mask1) {
  523. for (i = 0; i < 16; i++) {
  524. if (irq == INT_TO_IRQ(sysint1_assign[i]) && (mask1 & (1 << i)))
  525. return SYSINT1_IRQ(i);
  526. }
  527. }
  528. if (mask2) {
  529. for (i = 0; i < 16; i++) {
  530. if (irq == INT_TO_IRQ(sysint2_assign[i]) && (mask2 & (1 << i)))
  531. return SYSINT2_IRQ(i);
  532. }
  533. }
  534. printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
  535. atomic_inc(&irq_err_count);
  536. return -1;
  537. }
  538. static int __init vr41xx_icu_init(void)
  539. {
  540. unsigned long icu1_start, icu2_start;
  541. int i;
  542. switch (current_cpu_type()) {
  543. case CPU_VR4111:
  544. case CPU_VR4121:
  545. icu1_start = ICU1_TYPE1_BASE;
  546. icu2_start = ICU2_TYPE1_BASE;
  547. break;
  548. case CPU_VR4122:
  549. case CPU_VR4131:
  550. case CPU_VR4133:
  551. icu1_start = ICU1_TYPE2_BASE;
  552. icu2_start = ICU2_TYPE2_BASE;
  553. break;
  554. default:
  555. printk(KERN_ERR "ICU: Unexpected CPU of NEC VR4100 series\n");
  556. return -ENODEV;
  557. }
  558. if (request_mem_region(icu1_start, ICU1_SIZE, "ICU") == NULL)
  559. return -EBUSY;
  560. if (request_mem_region(icu2_start, ICU2_SIZE, "ICU") == NULL) {
  561. release_mem_region(icu1_start, ICU1_SIZE);
  562. return -EBUSY;
  563. }
  564. icu1_base = ioremap(icu1_start, ICU1_SIZE);
  565. if (icu1_base == NULL) {
  566. release_mem_region(icu1_start, ICU1_SIZE);
  567. release_mem_region(icu2_start, ICU2_SIZE);
  568. return -ENOMEM;
  569. }
  570. icu2_base = ioremap(icu2_start, ICU2_SIZE);
  571. if (icu2_base == NULL) {
  572. iounmap(icu1_base);
  573. release_mem_region(icu1_start, ICU1_SIZE);
  574. release_mem_region(icu2_start, ICU2_SIZE);
  575. return -ENOMEM;
  576. }
  577. icu1_write(MSYSINT1REG, 0);
  578. icu1_write(MGIUINTLREG, 0xffff);
  579. icu2_write(MSYSINT2REG, 0);
  580. icu2_write(MGIUINTHREG, 0xffff);
  581. for (i = SYSINT1_IRQ_BASE; i <= SYSINT1_IRQ_LAST; i++)
  582. irq_set_chip_and_handler(i, &sysint1_irq_type,
  583. handle_level_irq);
  584. for (i = SYSINT2_IRQ_BASE; i <= SYSINT2_IRQ_LAST; i++)
  585. irq_set_chip_and_handler(i, &sysint2_irq_type,
  586. handle_level_irq);
  587. cascade_irq(INT0_IRQ, icu_get_irq);
  588. cascade_irq(INT1_IRQ, icu_get_irq);
  589. cascade_irq(INT2_IRQ, icu_get_irq);
  590. cascade_irq(INT3_IRQ, icu_get_irq);
  591. cascade_irq(INT4_IRQ, icu_get_irq);
  592. return 0;
  593. }
  594. core_initcall(vr41xx_icu_init);