icu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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 <yyuasa@mvista.com or source@mvista.com>
  6. * Copyright (C) 2003-2005 Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
  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. <yyuasa@mvista.com> or <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@hh.iij4u.or.jp>
  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/vr41xx.h>
  41. static void __iomem *icu1_base;
  42. static void __iomem *icu2_base;
  43. static unsigned char sysint1_assign[16] = {
  44. 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  45. static unsigned char sysint2_assign[16] = {
  46. 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  47. #define ICU1_TYPE1_BASE 0x0b000080UL
  48. #define ICU2_TYPE1_BASE 0x0b000200UL
  49. #define ICU1_TYPE2_BASE 0x0f000080UL
  50. #define ICU2_TYPE2_BASE 0x0f0000a0UL
  51. #define ICU1_SIZE 0x20
  52. #define ICU2_SIZE 0x1c
  53. #define SYSINT1REG 0x00
  54. #define PIUINTREG 0x02
  55. #define INTASSIGN0 0x04
  56. #define INTASSIGN1 0x06
  57. #define GIUINTLREG 0x08
  58. #define DSIUINTREG 0x0a
  59. #define MSYSINT1REG 0x0c
  60. #define MPIUINTREG 0x0e
  61. #define MAIUINTREG 0x10
  62. #define MKIUINTREG 0x12
  63. #define MGIUINTLREG 0x14
  64. #define MDSIUINTREG 0x16
  65. #define NMIREG 0x18
  66. #define SOFTREG 0x1a
  67. #define INTASSIGN2 0x1c
  68. #define INTASSIGN3 0x1e
  69. #define SYSINT2REG 0x00
  70. #define GIUINTHREG 0x02
  71. #define FIRINTREG 0x04
  72. #define MSYSINT2REG 0x06
  73. #define MGIUINTHREG 0x08
  74. #define MFIRINTREG 0x0a
  75. #define PCIINTREG 0x0c
  76. #define PCIINT0 0x0001
  77. #define SCUINTREG 0x0e
  78. #define SCUINT0 0x0001
  79. #define CSIINTREG 0x10
  80. #define MPCIINTREG 0x12
  81. #define MSCUINTREG 0x14
  82. #define MCSIINTREG 0x16
  83. #define BCUINTREG 0x18
  84. #define BCUINTR 0x0001
  85. #define MBCUINTREG 0x1a
  86. #define SYSINT1_IRQ_TO_PIN(x) ((x) - SYSINT1_IRQ_BASE) /* Pin 0-15 */
  87. #define SYSINT2_IRQ_TO_PIN(x) ((x) - SYSINT2_IRQ_BASE) /* Pin 0-15 */
  88. #define INT_TO_IRQ(x) ((x) + 2) /* Int0-4 -> IRQ2-6 */
  89. #define icu1_read(offset) readw(icu1_base + (offset))
  90. #define icu1_write(offset, value) writew((value), icu1_base + (offset))
  91. #define icu2_read(offset) readw(icu2_base + (offset))
  92. #define icu2_write(offset, value) writew((value), icu2_base + (offset))
  93. #define INTASSIGN_MAX 4
  94. #define INTASSIGN_MASK 0x0007
  95. static inline uint16_t icu1_set(uint8_t offset, uint16_t set)
  96. {
  97. uint16_t data;
  98. data = icu1_read(offset);
  99. data |= set;
  100. icu1_write(offset, data);
  101. return data;
  102. }
  103. static inline uint16_t icu1_clear(uint8_t offset, uint16_t clear)
  104. {
  105. uint16_t data;
  106. data = icu1_read(offset);
  107. data &= ~clear;
  108. icu1_write(offset, data);
  109. return data;
  110. }
  111. static inline uint16_t icu2_set(uint8_t offset, uint16_t set)
  112. {
  113. uint16_t data;
  114. data = icu2_read(offset);
  115. data |= set;
  116. icu2_write(offset, data);
  117. return data;
  118. }
  119. static inline uint16_t icu2_clear(uint8_t offset, uint16_t clear)
  120. {
  121. uint16_t data;
  122. data = icu2_read(offset);
  123. data &= ~clear;
  124. icu2_write(offset, data);
  125. return data;
  126. }
  127. void vr41xx_enable_piuint(uint16_t mask)
  128. {
  129. irq_desc_t *desc = irq_desc + PIU_IRQ;
  130. unsigned long flags;
  131. if (current_cpu_data.cputype == CPU_VR4111 ||
  132. current_cpu_data.cputype == CPU_VR4121) {
  133. spin_lock_irqsave(&desc->lock, flags);
  134. icu1_set(MPIUINTREG, mask);
  135. spin_unlock_irqrestore(&desc->lock, flags);
  136. }
  137. }
  138. EXPORT_SYMBOL(vr41xx_enable_piuint);
  139. void vr41xx_disable_piuint(uint16_t mask)
  140. {
  141. irq_desc_t *desc = irq_desc + PIU_IRQ;
  142. unsigned long flags;
  143. if (current_cpu_data.cputype == CPU_VR4111 ||
  144. current_cpu_data.cputype == CPU_VR4121) {
  145. spin_lock_irqsave(&desc->lock, flags);
  146. icu1_clear(MPIUINTREG, mask);
  147. spin_unlock_irqrestore(&desc->lock, flags);
  148. }
  149. }
  150. EXPORT_SYMBOL(vr41xx_disable_piuint);
  151. void vr41xx_enable_aiuint(uint16_t mask)
  152. {
  153. irq_desc_t *desc = irq_desc + AIU_IRQ;
  154. unsigned long flags;
  155. if (current_cpu_data.cputype == CPU_VR4111 ||
  156. current_cpu_data.cputype == CPU_VR4121) {
  157. spin_lock_irqsave(&desc->lock, flags);
  158. icu1_set(MAIUINTREG, mask);
  159. spin_unlock_irqrestore(&desc->lock, flags);
  160. }
  161. }
  162. EXPORT_SYMBOL(vr41xx_enable_aiuint);
  163. void vr41xx_disable_aiuint(uint16_t mask)
  164. {
  165. irq_desc_t *desc = irq_desc + AIU_IRQ;
  166. unsigned long flags;
  167. if (current_cpu_data.cputype == CPU_VR4111 ||
  168. current_cpu_data.cputype == CPU_VR4121) {
  169. spin_lock_irqsave(&desc->lock, flags);
  170. icu1_clear(MAIUINTREG, mask);
  171. spin_unlock_irqrestore(&desc->lock, flags);
  172. }
  173. }
  174. EXPORT_SYMBOL(vr41xx_disable_aiuint);
  175. void vr41xx_enable_kiuint(uint16_t mask)
  176. {
  177. irq_desc_t *desc = irq_desc + KIU_IRQ;
  178. unsigned long flags;
  179. if (current_cpu_data.cputype == CPU_VR4111 ||
  180. current_cpu_data.cputype == CPU_VR4121) {
  181. spin_lock_irqsave(&desc->lock, flags);
  182. icu1_set(MKIUINTREG, mask);
  183. spin_unlock_irqrestore(&desc->lock, flags);
  184. }
  185. }
  186. EXPORT_SYMBOL(vr41xx_enable_kiuint);
  187. void vr41xx_disable_kiuint(uint16_t mask)
  188. {
  189. irq_desc_t *desc = irq_desc + KIU_IRQ;
  190. unsigned long flags;
  191. if (current_cpu_data.cputype == CPU_VR4111 ||
  192. current_cpu_data.cputype == CPU_VR4121) {
  193. spin_lock_irqsave(&desc->lock, flags);
  194. icu1_clear(MKIUINTREG, mask);
  195. spin_unlock_irqrestore(&desc->lock, flags);
  196. }
  197. }
  198. EXPORT_SYMBOL(vr41xx_disable_kiuint);
  199. void vr41xx_enable_dsiuint(uint16_t mask)
  200. {
  201. irq_desc_t *desc = irq_desc + DSIU_IRQ;
  202. unsigned long flags;
  203. spin_lock_irqsave(&desc->lock, flags);
  204. icu1_set(MDSIUINTREG, mask);
  205. spin_unlock_irqrestore(&desc->lock, flags);
  206. }
  207. EXPORT_SYMBOL(vr41xx_enable_dsiuint);
  208. void vr41xx_disable_dsiuint(uint16_t mask)
  209. {
  210. irq_desc_t *desc = irq_desc + DSIU_IRQ;
  211. unsigned long flags;
  212. spin_lock_irqsave(&desc->lock, flags);
  213. icu1_clear(MDSIUINTREG, mask);
  214. spin_unlock_irqrestore(&desc->lock, flags);
  215. }
  216. EXPORT_SYMBOL(vr41xx_disable_dsiuint);
  217. void vr41xx_enable_firint(uint16_t mask)
  218. {
  219. irq_desc_t *desc = irq_desc + FIR_IRQ;
  220. unsigned long flags;
  221. spin_lock_irqsave(&desc->lock, flags);
  222. icu2_set(MFIRINTREG, mask);
  223. spin_unlock_irqrestore(&desc->lock, flags);
  224. }
  225. EXPORT_SYMBOL(vr41xx_enable_firint);
  226. void vr41xx_disable_firint(uint16_t mask)
  227. {
  228. irq_desc_t *desc = irq_desc + FIR_IRQ;
  229. unsigned long flags;
  230. spin_lock_irqsave(&desc->lock, flags);
  231. icu2_clear(MFIRINTREG, mask);
  232. spin_unlock_irqrestore(&desc->lock, flags);
  233. }
  234. EXPORT_SYMBOL(vr41xx_disable_firint);
  235. void vr41xx_enable_pciint(void)
  236. {
  237. irq_desc_t *desc = irq_desc + PCI_IRQ;
  238. unsigned long flags;
  239. if (current_cpu_data.cputype == CPU_VR4122 ||
  240. current_cpu_data.cputype == CPU_VR4131 ||
  241. current_cpu_data.cputype == CPU_VR4133) {
  242. spin_lock_irqsave(&desc->lock, flags);
  243. icu2_write(MPCIINTREG, PCIINT0);
  244. spin_unlock_irqrestore(&desc->lock, flags);
  245. }
  246. }
  247. EXPORT_SYMBOL(vr41xx_enable_pciint);
  248. void vr41xx_disable_pciint(void)
  249. {
  250. irq_desc_t *desc = irq_desc + PCI_IRQ;
  251. unsigned long flags;
  252. if (current_cpu_data.cputype == CPU_VR4122 ||
  253. current_cpu_data.cputype == CPU_VR4131 ||
  254. current_cpu_data.cputype == CPU_VR4133) {
  255. spin_lock_irqsave(&desc->lock, flags);
  256. icu2_write(MPCIINTREG, 0);
  257. spin_unlock_irqrestore(&desc->lock, flags);
  258. }
  259. }
  260. EXPORT_SYMBOL(vr41xx_disable_pciint);
  261. void vr41xx_enable_scuint(void)
  262. {
  263. irq_desc_t *desc = irq_desc + SCU_IRQ;
  264. unsigned long flags;
  265. if (current_cpu_data.cputype == CPU_VR4122 ||
  266. current_cpu_data.cputype == CPU_VR4131 ||
  267. current_cpu_data.cputype == CPU_VR4133) {
  268. spin_lock_irqsave(&desc->lock, flags);
  269. icu2_write(MSCUINTREG, SCUINT0);
  270. spin_unlock_irqrestore(&desc->lock, flags);
  271. }
  272. }
  273. EXPORT_SYMBOL(vr41xx_enable_scuint);
  274. void vr41xx_disable_scuint(void)
  275. {
  276. irq_desc_t *desc = irq_desc + SCU_IRQ;
  277. unsigned long flags;
  278. if (current_cpu_data.cputype == CPU_VR4122 ||
  279. current_cpu_data.cputype == CPU_VR4131 ||
  280. current_cpu_data.cputype == CPU_VR4133) {
  281. spin_lock_irqsave(&desc->lock, flags);
  282. icu2_write(MSCUINTREG, 0);
  283. spin_unlock_irqrestore(&desc->lock, flags);
  284. }
  285. }
  286. EXPORT_SYMBOL(vr41xx_disable_scuint);
  287. void vr41xx_enable_csiint(uint16_t mask)
  288. {
  289. irq_desc_t *desc = irq_desc + CSI_IRQ;
  290. unsigned long flags;
  291. if (current_cpu_data.cputype == CPU_VR4122 ||
  292. current_cpu_data.cputype == CPU_VR4131 ||
  293. current_cpu_data.cputype == CPU_VR4133) {
  294. spin_lock_irqsave(&desc->lock, flags);
  295. icu2_set(MCSIINTREG, mask);
  296. spin_unlock_irqrestore(&desc->lock, flags);
  297. }
  298. }
  299. EXPORT_SYMBOL(vr41xx_enable_csiint);
  300. void vr41xx_disable_csiint(uint16_t mask)
  301. {
  302. irq_desc_t *desc = irq_desc + CSI_IRQ;
  303. unsigned long flags;
  304. if (current_cpu_data.cputype == CPU_VR4122 ||
  305. current_cpu_data.cputype == CPU_VR4131 ||
  306. current_cpu_data.cputype == CPU_VR4133) {
  307. spin_lock_irqsave(&desc->lock, flags);
  308. icu2_clear(MCSIINTREG, mask);
  309. spin_unlock_irqrestore(&desc->lock, flags);
  310. }
  311. }
  312. EXPORT_SYMBOL(vr41xx_disable_csiint);
  313. void vr41xx_enable_bcuint(void)
  314. {
  315. irq_desc_t *desc = irq_desc + BCU_IRQ;
  316. unsigned long flags;
  317. if (current_cpu_data.cputype == CPU_VR4122 ||
  318. current_cpu_data.cputype == CPU_VR4131 ||
  319. current_cpu_data.cputype == CPU_VR4133) {
  320. spin_lock_irqsave(&desc->lock, flags);
  321. icu2_write(MBCUINTREG, BCUINTR);
  322. spin_unlock_irqrestore(&desc->lock, flags);
  323. }
  324. }
  325. EXPORT_SYMBOL(vr41xx_enable_bcuint);
  326. void vr41xx_disable_bcuint(void)
  327. {
  328. irq_desc_t *desc = irq_desc + BCU_IRQ;
  329. unsigned long flags;
  330. if (current_cpu_data.cputype == CPU_VR4122 ||
  331. current_cpu_data.cputype == CPU_VR4131 ||
  332. current_cpu_data.cputype == CPU_VR4133) {
  333. spin_lock_irqsave(&desc->lock, flags);
  334. icu2_write(MBCUINTREG, 0);
  335. spin_unlock_irqrestore(&desc->lock, flags);
  336. }
  337. }
  338. EXPORT_SYMBOL(vr41xx_disable_bcuint);
  339. static unsigned int startup_sysint1_irq(unsigned int irq)
  340. {
  341. icu1_set(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(irq));
  342. return 0; /* never anything pending */
  343. }
  344. static void shutdown_sysint1_irq(unsigned int irq)
  345. {
  346. icu1_clear(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(irq));
  347. }
  348. static void enable_sysint1_irq(unsigned int irq)
  349. {
  350. icu1_set(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(irq));
  351. }
  352. #define disable_sysint1_irq shutdown_sysint1_irq
  353. #define ack_sysint1_irq shutdown_sysint1_irq
  354. static void end_sysint1_irq(unsigned int irq)
  355. {
  356. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  357. icu1_set(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(irq));
  358. }
  359. static struct hw_interrupt_type sysint1_irq_type = {
  360. .typename = "SYSINT1",
  361. .startup = startup_sysint1_irq,
  362. .shutdown = shutdown_sysint1_irq,
  363. .enable = enable_sysint1_irq,
  364. .disable = disable_sysint1_irq,
  365. .ack = ack_sysint1_irq,
  366. .end = end_sysint1_irq,
  367. };
  368. static unsigned int startup_sysint2_irq(unsigned int irq)
  369. {
  370. icu2_set(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(irq));
  371. return 0; /* never anything pending */
  372. }
  373. static void shutdown_sysint2_irq(unsigned int irq)
  374. {
  375. icu2_clear(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(irq));
  376. }
  377. static void enable_sysint2_irq(unsigned int irq)
  378. {
  379. icu2_set(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(irq));
  380. }
  381. #define disable_sysint2_irq shutdown_sysint2_irq
  382. #define ack_sysint2_irq shutdown_sysint2_irq
  383. static void end_sysint2_irq(unsigned int irq)
  384. {
  385. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  386. icu2_set(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(irq));
  387. }
  388. static struct hw_interrupt_type sysint2_irq_type = {
  389. .typename = "SYSINT2",
  390. .startup = startup_sysint2_irq,
  391. .shutdown = shutdown_sysint2_irq,
  392. .enable = enable_sysint2_irq,
  393. .disable = disable_sysint2_irq,
  394. .ack = ack_sysint2_irq,
  395. .end = end_sysint2_irq,
  396. };
  397. static inline int set_sysint1_assign(unsigned int irq, unsigned char assign)
  398. {
  399. irq_desc_t *desc = irq_desc + irq;
  400. uint16_t intassign0, intassign1;
  401. unsigned int pin;
  402. pin = SYSINT1_IRQ_TO_PIN(irq);
  403. spin_lock_irq(&desc->lock);
  404. intassign0 = icu1_read(INTASSIGN0);
  405. intassign1 = icu1_read(INTASSIGN1);
  406. switch (pin) {
  407. case 0:
  408. intassign0 &= ~INTASSIGN_MASK;
  409. intassign0 |= (uint16_t)assign;
  410. break;
  411. case 1:
  412. intassign0 &= ~(INTASSIGN_MASK << 3);
  413. intassign0 |= (uint16_t)assign << 3;
  414. break;
  415. case 2:
  416. intassign0 &= ~(INTASSIGN_MASK << 6);
  417. intassign0 |= (uint16_t)assign << 6;
  418. break;
  419. case 3:
  420. intassign0 &= ~(INTASSIGN_MASK << 9);
  421. intassign0 |= (uint16_t)assign << 9;
  422. break;
  423. case 8:
  424. intassign0 &= ~(INTASSIGN_MASK << 12);
  425. intassign0 |= (uint16_t)assign << 12;
  426. break;
  427. case 9:
  428. intassign1 &= ~INTASSIGN_MASK;
  429. intassign1 |= (uint16_t)assign;
  430. break;
  431. case 11:
  432. intassign1 &= ~(INTASSIGN_MASK << 6);
  433. intassign1 |= (uint16_t)assign << 6;
  434. break;
  435. case 12:
  436. intassign1 &= ~(INTASSIGN_MASK << 9);
  437. intassign1 |= (uint16_t)assign << 9;
  438. break;
  439. default:
  440. return -EINVAL;
  441. }
  442. sysint1_assign[pin] = assign;
  443. icu1_write(INTASSIGN0, intassign0);
  444. icu1_write(INTASSIGN1, intassign1);
  445. spin_unlock_irq(&desc->lock);
  446. return 0;
  447. }
  448. static inline int set_sysint2_assign(unsigned int irq, unsigned char assign)
  449. {
  450. irq_desc_t *desc = irq_desc + irq;
  451. uint16_t intassign2, intassign3;
  452. unsigned int pin;
  453. pin = SYSINT2_IRQ_TO_PIN(irq);
  454. spin_lock_irq(&desc->lock);
  455. intassign2 = icu1_read(INTASSIGN2);
  456. intassign3 = icu1_read(INTASSIGN3);
  457. switch (pin) {
  458. case 0:
  459. intassign2 &= ~INTASSIGN_MASK;
  460. intassign2 |= (uint16_t)assign;
  461. break;
  462. case 1:
  463. intassign2 &= ~(INTASSIGN_MASK << 3);
  464. intassign2 |= (uint16_t)assign << 3;
  465. break;
  466. case 3:
  467. intassign2 &= ~(INTASSIGN_MASK << 6);
  468. intassign2 |= (uint16_t)assign << 6;
  469. break;
  470. case 4:
  471. intassign2 &= ~(INTASSIGN_MASK << 9);
  472. intassign2 |= (uint16_t)assign << 9;
  473. break;
  474. case 5:
  475. intassign2 &= ~(INTASSIGN_MASK << 12);
  476. intassign2 |= (uint16_t)assign << 12;
  477. break;
  478. case 6:
  479. intassign3 &= ~INTASSIGN_MASK;
  480. intassign3 |= (uint16_t)assign;
  481. break;
  482. case 7:
  483. intassign3 &= ~(INTASSIGN_MASK << 3);
  484. intassign3 |= (uint16_t)assign << 3;
  485. break;
  486. case 8:
  487. intassign3 &= ~(INTASSIGN_MASK << 6);
  488. intassign3 |= (uint16_t)assign << 6;
  489. break;
  490. case 9:
  491. intassign3 &= ~(INTASSIGN_MASK << 9);
  492. intassign3 |= (uint16_t)assign << 9;
  493. break;
  494. case 10:
  495. intassign3 &= ~(INTASSIGN_MASK << 12);
  496. intassign3 |= (uint16_t)assign << 12;
  497. break;
  498. default:
  499. return -EINVAL;
  500. }
  501. sysint2_assign[pin] = assign;
  502. icu1_write(INTASSIGN2, intassign2);
  503. icu1_write(INTASSIGN3, intassign3);
  504. spin_unlock_irq(&desc->lock);
  505. return 0;
  506. }
  507. int vr41xx_set_intassign(unsigned int irq, unsigned char intassign)
  508. {
  509. int retval = -EINVAL;
  510. if (current_cpu_data.cputype != CPU_VR4133)
  511. return -EINVAL;
  512. if (intassign > INTASSIGN_MAX)
  513. return -EINVAL;
  514. if (irq >= SYSINT1_IRQ_BASE && irq <= SYSINT1_IRQ_LAST)
  515. retval = set_sysint1_assign(irq, intassign);
  516. else if (irq >= SYSINT2_IRQ_BASE && irq <= SYSINT2_IRQ_LAST)
  517. retval = set_sysint2_assign(irq, intassign);
  518. return retval;
  519. }
  520. EXPORT_SYMBOL(vr41xx_set_intassign);
  521. static int icu_get_irq(unsigned int irq, struct pt_regs *regs)
  522. {
  523. uint16_t pend1, pend2;
  524. uint16_t mask1, mask2;
  525. int i;
  526. pend1 = icu1_read(SYSINT1REG);
  527. mask1 = icu1_read(MSYSINT1REG);
  528. pend2 = icu2_read(SYSINT2REG);
  529. mask2 = icu2_read(MSYSINT2REG);
  530. mask1 &= pend1;
  531. mask2 &= pend2;
  532. if (mask1) {
  533. for (i = 0; i < 16; i++) {
  534. if (irq == INT_TO_IRQ(sysint1_assign[i]) && (mask1 & (1 << i)))
  535. return SYSINT1_IRQ(i);
  536. }
  537. }
  538. if (mask2) {
  539. for (i = 0; i < 16; i++) {
  540. if (irq == INT_TO_IRQ(sysint2_assign[i]) && (mask2 & (1 << i)))
  541. return SYSINT2_IRQ(i);
  542. }
  543. }
  544. printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
  545. atomic_inc(&irq_err_count);
  546. return -1;
  547. }
  548. static int __init vr41xx_icu_init(void)
  549. {
  550. unsigned long icu1_start, icu2_start;
  551. int i;
  552. switch (current_cpu_data.cputype) {
  553. case CPU_VR4111:
  554. case CPU_VR4121:
  555. icu1_start = ICU1_TYPE1_BASE;
  556. icu2_start = ICU2_TYPE1_BASE;
  557. break;
  558. case CPU_VR4122:
  559. case CPU_VR4131:
  560. case CPU_VR4133:
  561. icu1_start = ICU1_TYPE2_BASE;
  562. icu2_start = ICU2_TYPE2_BASE;
  563. break;
  564. default:
  565. printk(KERN_ERR "ICU: Unexpected CPU of NEC VR4100 series\n");
  566. return -ENODEV;
  567. }
  568. if (request_mem_region(icu1_start, ICU1_SIZE, "ICU") == NULL)
  569. return -EBUSY;
  570. if (request_mem_region(icu2_start, ICU2_SIZE, "ICU") == NULL) {
  571. release_mem_region(icu1_start, ICU1_SIZE);
  572. return -EBUSY;
  573. }
  574. icu1_base = ioremap(icu1_start, ICU1_SIZE);
  575. if (icu1_base == NULL) {
  576. release_mem_region(icu1_start, ICU1_SIZE);
  577. release_mem_region(icu2_start, ICU2_SIZE);
  578. return -ENOMEM;
  579. }
  580. icu2_base = ioremap(icu2_start, ICU2_SIZE);
  581. if (icu2_base == NULL) {
  582. iounmap(icu1_base);
  583. release_mem_region(icu1_start, ICU1_SIZE);
  584. release_mem_region(icu2_start, ICU2_SIZE);
  585. return -ENOMEM;
  586. }
  587. icu1_write(MSYSINT1REG, 0);
  588. icu1_write(MGIUINTLREG, 0xffff);
  589. icu2_write(MSYSINT2REG, 0);
  590. icu2_write(MGIUINTHREG, 0xffff);
  591. for (i = SYSINT1_IRQ_BASE; i <= SYSINT1_IRQ_LAST; i++)
  592. irq_desc[i].handler = &sysint1_irq_type;
  593. for (i = SYSINT2_IRQ_BASE; i <= SYSINT2_IRQ_LAST; i++)
  594. irq_desc[i].handler = &sysint2_irq_type;
  595. cascade_irq(INT0_IRQ, icu_get_irq);
  596. cascade_irq(INT1_IRQ, icu_get_irq);
  597. cascade_irq(INT2_IRQ, icu_get_irq);
  598. cascade_irq(INT3_IRQ, icu_get_irq);
  599. cascade_irq(INT4_IRQ, icu_get_irq);
  600. return 0;
  601. }
  602. core_initcall(vr41xx_icu_init);