irq.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /*
  2. * linux/arch/mps/tx4938/common/irq.c
  3. *
  4. * Common tx4938 irq handler
  5. * Copyright (C) 2000-2001 Toshiba Corporation
  6. *
  7. * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the
  8. * terms of the GNU General Public License version 2. This program is
  9. * licensed "as is" without any warranty of any kind, whether express
  10. * or implied.
  11. *
  12. * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com)
  13. */
  14. #include <linux/errno.h>
  15. #include <linux/init.h>
  16. #include <linux/kernel_stat.h>
  17. #include <linux/module.h>
  18. #include <linux/signal.h>
  19. #include <linux/sched.h>
  20. #include <linux/types.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/ioport.h>
  23. #include <linux/timex.h>
  24. #include <linux/slab.h>
  25. #include <linux/random.h>
  26. #include <linux/irq.h>
  27. #include <asm/bitops.h>
  28. #include <asm/bootinfo.h>
  29. #include <asm/io.h>
  30. #include <asm/irq.h>
  31. #include <asm/mipsregs.h>
  32. #include <asm/system.h>
  33. #include <asm/tx4938/rbtx4938.h>
  34. /**********************************************************************************/
  35. /* Forwad definitions for all pic's */
  36. /**********************************************************************************/
  37. static unsigned int tx4938_irq_cp0_startup(unsigned int irq);
  38. static void tx4938_irq_cp0_shutdown(unsigned int irq);
  39. static void tx4938_irq_cp0_enable(unsigned int irq);
  40. static void tx4938_irq_cp0_disable(unsigned int irq);
  41. static void tx4938_irq_cp0_mask_and_ack(unsigned int irq);
  42. static void tx4938_irq_cp0_end(unsigned int irq);
  43. static unsigned int tx4938_irq_pic_startup(unsigned int irq);
  44. static void tx4938_irq_pic_shutdown(unsigned int irq);
  45. static void tx4938_irq_pic_enable(unsigned int irq);
  46. static void tx4938_irq_pic_disable(unsigned int irq);
  47. static void tx4938_irq_pic_mask_and_ack(unsigned int irq);
  48. static void tx4938_irq_pic_end(unsigned int irq);
  49. /**********************************************************************************/
  50. /* Kernel structs for all pic's */
  51. /**********************************************************************************/
  52. DEFINE_SPINLOCK(tx4938_cp0_lock);
  53. DEFINE_SPINLOCK(tx4938_pic_lock);
  54. #define TX4938_CP0_NAME "TX4938-CP0"
  55. static struct hw_interrupt_type tx4938_irq_cp0_type = {
  56. .typename = TX4938_CP0_NAME,
  57. .startup = tx4938_irq_cp0_startup,
  58. .shutdown = tx4938_irq_cp0_shutdown,
  59. .enable = tx4938_irq_cp0_enable,
  60. .disable = tx4938_irq_cp0_disable,
  61. .ack = tx4938_irq_cp0_mask_and_ack,
  62. .end = tx4938_irq_cp0_end,
  63. .set_affinity = NULL
  64. };
  65. #define TX4938_PIC_NAME "TX4938-PIC"
  66. static struct hw_interrupt_type tx4938_irq_pic_type = {
  67. .typename = TX4938_PIC_NAME,
  68. .startup = tx4938_irq_pic_startup,
  69. .shutdown = tx4938_irq_pic_shutdown,
  70. .enable = tx4938_irq_pic_enable,
  71. .disable = tx4938_irq_pic_disable,
  72. .ack = tx4938_irq_pic_mask_and_ack,
  73. .end = tx4938_irq_pic_end,
  74. .set_affinity = NULL
  75. };
  76. static struct irqaction tx4938_irq_pic_action = {
  77. .handler = no_action,
  78. .flags = 0,
  79. .mask = CPU_MASK_NONE,
  80. .name = TX4938_PIC_NAME
  81. };
  82. /**********************************************************************************/
  83. /* Functions for cp0 */
  84. /**********************************************************************************/
  85. #define tx4938_irq_cp0_mask(irq) ( 1 << ( irq-TX4938_IRQ_CP0_BEG+8 ) )
  86. static void __init
  87. tx4938_irq_cp0_init(void)
  88. {
  89. int i;
  90. for (i = TX4938_IRQ_CP0_BEG; i <= TX4938_IRQ_CP0_END; i++) {
  91. irq_desc[i].status = IRQ_DISABLED;
  92. irq_desc[i].action = 0;
  93. irq_desc[i].depth = 1;
  94. irq_desc[i].handler = &tx4938_irq_cp0_type;
  95. }
  96. return;
  97. }
  98. static unsigned int
  99. tx4938_irq_cp0_startup(unsigned int irq)
  100. {
  101. tx4938_irq_cp0_enable(irq);
  102. return (0);
  103. }
  104. static void
  105. tx4938_irq_cp0_shutdown(unsigned int irq)
  106. {
  107. tx4938_irq_cp0_disable(irq);
  108. }
  109. static void
  110. tx4938_irq_cp0_enable(unsigned int irq)
  111. {
  112. unsigned long flags;
  113. spin_lock_irqsave(&tx4938_cp0_lock, flags);
  114. set_c0_status(tx4938_irq_cp0_mask(irq));
  115. spin_unlock_irqrestore(&tx4938_cp0_lock, flags);
  116. }
  117. static void
  118. tx4938_irq_cp0_disable(unsigned int irq)
  119. {
  120. unsigned long flags;
  121. spin_lock_irqsave(&tx4938_cp0_lock, flags);
  122. clear_c0_status(tx4938_irq_cp0_mask(irq));
  123. spin_unlock_irqrestore(&tx4938_cp0_lock, flags);
  124. return;
  125. }
  126. static void
  127. tx4938_irq_cp0_mask_and_ack(unsigned int irq)
  128. {
  129. tx4938_irq_cp0_disable(irq);
  130. return;
  131. }
  132. static void
  133. tx4938_irq_cp0_end(unsigned int irq)
  134. {
  135. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  136. tx4938_irq_cp0_enable(irq);
  137. }
  138. return;
  139. }
  140. /**********************************************************************************/
  141. /* Functions for pic */
  142. /**********************************************************************************/
  143. u32
  144. tx4938_irq_pic_addr(int irq)
  145. {
  146. /* MVMCP -- need to formulize this */
  147. irq -= TX4938_IRQ_PIC_BEG;
  148. switch (irq) {
  149. case 17:
  150. case 16:
  151. case 1:
  152. case 0:{
  153. return (TX4938_MKA(TX4938_IRC_IRLVL0));
  154. }
  155. case 19:
  156. case 18:
  157. case 3:
  158. case 2:{
  159. return (TX4938_MKA(TX4938_IRC_IRLVL1));
  160. }
  161. case 21:
  162. case 20:
  163. case 5:
  164. case 4:{
  165. return (TX4938_MKA(TX4938_IRC_IRLVL2));
  166. }
  167. case 23:
  168. case 22:
  169. case 7:
  170. case 6:{
  171. return (TX4938_MKA(TX4938_IRC_IRLVL3));
  172. }
  173. case 25:
  174. case 24:
  175. case 9:
  176. case 8:{
  177. return (TX4938_MKA(TX4938_IRC_IRLVL4));
  178. }
  179. case 27:
  180. case 26:
  181. case 11:
  182. case 10:{
  183. return (TX4938_MKA(TX4938_IRC_IRLVL5));
  184. }
  185. case 29:
  186. case 28:
  187. case 13:
  188. case 12:{
  189. return (TX4938_MKA(TX4938_IRC_IRLVL6));
  190. }
  191. case 31:
  192. case 30:
  193. case 15:
  194. case 14:{
  195. return (TX4938_MKA(TX4938_IRC_IRLVL7));
  196. }
  197. }
  198. return (0);
  199. }
  200. u32
  201. tx4938_irq_pic_mask(int irq)
  202. {
  203. /* MVMCP -- need to formulize this */
  204. irq -= TX4938_IRQ_PIC_BEG;
  205. switch (irq) {
  206. case 31:
  207. case 29:
  208. case 27:
  209. case 25:
  210. case 23:
  211. case 21:
  212. case 19:
  213. case 17:{
  214. return (0x07000000);
  215. }
  216. case 30:
  217. case 28:
  218. case 26:
  219. case 24:
  220. case 22:
  221. case 20:
  222. case 18:
  223. case 16:{
  224. return (0x00070000);
  225. }
  226. case 15:
  227. case 13:
  228. case 11:
  229. case 9:
  230. case 7:
  231. case 5:
  232. case 3:
  233. case 1:{
  234. return (0x00000700);
  235. }
  236. case 14:
  237. case 12:
  238. case 10:
  239. case 8:
  240. case 6:
  241. case 4:
  242. case 2:
  243. case 0:{
  244. return (0x00000007);
  245. }
  246. }
  247. return (0x00000000);
  248. }
  249. static void
  250. tx4938_irq_pic_modify(unsigned pic_reg, unsigned clr_bits, unsigned set_bits)
  251. {
  252. unsigned long val = 0;
  253. val = TX4938_RD(pic_reg);
  254. val &= (~clr_bits);
  255. val |= (set_bits);
  256. TX4938_WR(pic_reg, val);
  257. mmiowb();
  258. TX4938_RD(pic_reg);
  259. return;
  260. }
  261. static void __init
  262. tx4938_irq_pic_init(void)
  263. {
  264. unsigned long flags;
  265. int i;
  266. for (i = TX4938_IRQ_PIC_BEG; i <= TX4938_IRQ_PIC_END; i++) {
  267. irq_desc[i].status = IRQ_DISABLED;
  268. irq_desc[i].action = 0;
  269. irq_desc[i].depth = 2;
  270. irq_desc[i].handler = &tx4938_irq_pic_type;
  271. }
  272. setup_irq(TX4938_IRQ_NEST_PIC_ON_CP0, &tx4938_irq_pic_action);
  273. spin_lock_irqsave(&tx4938_pic_lock, flags);
  274. TX4938_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
  275. TX4938_WR(0xff1ff600, TX4938_RD(0xff1ff600) | 0x1); /* irq enable */
  276. spin_unlock_irqrestore(&tx4938_pic_lock, flags);
  277. return;
  278. }
  279. static unsigned int
  280. tx4938_irq_pic_startup(unsigned int irq)
  281. {
  282. tx4938_irq_pic_enable(irq);
  283. return (0);
  284. }
  285. static void
  286. tx4938_irq_pic_shutdown(unsigned int irq)
  287. {
  288. tx4938_irq_pic_disable(irq);
  289. return;
  290. }
  291. static void
  292. tx4938_irq_pic_enable(unsigned int irq)
  293. {
  294. unsigned long flags;
  295. spin_lock_irqsave(&tx4938_pic_lock, flags);
  296. tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq), 0,
  297. tx4938_irq_pic_mask(irq));
  298. spin_unlock_irqrestore(&tx4938_pic_lock, flags);
  299. return;
  300. }
  301. static void
  302. tx4938_irq_pic_disable(unsigned int irq)
  303. {
  304. unsigned long flags;
  305. spin_lock_irqsave(&tx4938_pic_lock, flags);
  306. tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq),
  307. tx4938_irq_pic_mask(irq), 0);
  308. spin_unlock_irqrestore(&tx4938_pic_lock, flags);
  309. return;
  310. }
  311. static void
  312. tx4938_irq_pic_mask_and_ack(unsigned int irq)
  313. {
  314. tx4938_irq_pic_disable(irq);
  315. return;
  316. }
  317. static void
  318. tx4938_irq_pic_end(unsigned int irq)
  319. {
  320. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  321. tx4938_irq_pic_enable(irq);
  322. }
  323. return;
  324. }
  325. /**********************************************************************************/
  326. /* Main init functions */
  327. /**********************************************************************************/
  328. void __init
  329. tx4938_irq_init(void)
  330. {
  331. tx4938_irq_cp0_init();
  332. tx4938_irq_pic_init();
  333. return;
  334. }
  335. int
  336. tx4938_irq_nested(void)
  337. {
  338. int sw_irq = 0;
  339. u32 level2;
  340. level2 = TX4938_RD(0xff1ff6a0);
  341. if ((level2 & 0x10000) == 0) {
  342. level2 &= 0x1f;
  343. sw_irq = TX4938_IRQ_PIC_BEG + level2;
  344. if (sw_irq == 26) {
  345. {
  346. extern int toshiba_rbtx4938_irq_nested(int sw_irq);
  347. sw_irq = toshiba_rbtx4938_irq_nested(sw_irq);
  348. }
  349. }
  350. }
  351. wbflush();
  352. return (sw_irq);
  353. }
  354. asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
  355. {
  356. unsigned int pending = read_c0_cause() & read_c0_status();
  357. if (pending & STATUSF_IP7)
  358. do_IRQ(TX4938_IRQ_CPU_TIMER, regs);
  359. else if (pending & STATUSF_IP2) {
  360. int irq = tx4938_irq_nested();
  361. if (irq)
  362. do_IRQ(irq, regs);
  363. else
  364. spurious_interrupt(regs);
  365. } else if (pending & STATUSF_IP1)
  366. do_IRQ(TX4938_IRQ_USER1, regs);
  367. else if (pending & STATUSF_IP0)
  368. do_IRQ(TX4938_IRQ_USER0, regs);
  369. }