icu.c 17 KB

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