irq.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * linux/arch/mips/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/wbflush.h>
  34. #include <asm/tx4938/rbtx4938.h>
  35. /**********************************************************************************/
  36. /* Forwad definitions for all pic's */
  37. /**********************************************************************************/
  38. static void tx4938_irq_cp0_enable(unsigned int irq);
  39. static void tx4938_irq_cp0_disable(unsigned int irq);
  40. static void tx4938_irq_cp0_end(unsigned int irq);
  41. static void tx4938_irq_pic_enable(unsigned int irq);
  42. static void tx4938_irq_pic_disable(unsigned int irq);
  43. static void tx4938_irq_pic_end(unsigned int irq);
  44. /**********************************************************************************/
  45. /* Kernel structs for all pic's */
  46. /**********************************************************************************/
  47. #define TX4938_CP0_NAME "TX4938-CP0"
  48. static struct irq_chip tx4938_irq_cp0_type = {
  49. .typename = TX4938_CP0_NAME,
  50. .ack = tx4938_irq_cp0_disable,
  51. .mask = tx4938_irq_cp0_disable,
  52. .mask_ack = tx4938_irq_cp0_disable,
  53. .unmask = tx4938_irq_cp0_enable,
  54. .end = tx4938_irq_cp0_end,
  55. };
  56. #define TX4938_PIC_NAME "TX4938-PIC"
  57. static struct irq_chip tx4938_irq_pic_type = {
  58. .typename = TX4938_PIC_NAME,
  59. .ack = tx4938_irq_pic_disable,
  60. .mask = tx4938_irq_pic_disable,
  61. .mask_ack = tx4938_irq_pic_disable,
  62. .unmask = tx4938_irq_pic_enable,
  63. .end = tx4938_irq_pic_end,
  64. };
  65. static struct irqaction tx4938_irq_pic_action = {
  66. .handler = no_action,
  67. .flags = 0,
  68. .mask = CPU_MASK_NONE,
  69. .name = TX4938_PIC_NAME
  70. };
  71. /**********************************************************************************/
  72. /* Functions for cp0 */
  73. /**********************************************************************************/
  74. #define tx4938_irq_cp0_mask(irq) ( 1 << ( irq-TX4938_IRQ_CP0_BEG+8 ) )
  75. static void __init
  76. tx4938_irq_cp0_init(void)
  77. {
  78. int i;
  79. for (i = TX4938_IRQ_CP0_BEG; i <= TX4938_IRQ_CP0_END; i++)
  80. set_irq_chip_and_handler(i, &tx4938_irq_cp0_type,
  81. handle_level_irq);
  82. }
  83. static void
  84. tx4938_irq_cp0_enable(unsigned int irq)
  85. {
  86. set_c0_status(tx4938_irq_cp0_mask(irq));
  87. }
  88. static void
  89. tx4938_irq_cp0_disable(unsigned int irq)
  90. {
  91. clear_c0_status(tx4938_irq_cp0_mask(irq));
  92. }
  93. static void
  94. tx4938_irq_cp0_end(unsigned int irq)
  95. {
  96. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  97. tx4938_irq_cp0_enable(irq);
  98. }
  99. }
  100. /**********************************************************************************/
  101. /* Functions for pic */
  102. /**********************************************************************************/
  103. u32
  104. tx4938_irq_pic_addr(int irq)
  105. {
  106. /* MVMCP -- need to formulize this */
  107. irq -= TX4938_IRQ_PIC_BEG;
  108. switch (irq) {
  109. case 17:
  110. case 16:
  111. case 1:
  112. case 0:{
  113. return (TX4938_MKA(TX4938_IRC_IRLVL0));
  114. }
  115. case 19:
  116. case 18:
  117. case 3:
  118. case 2:{
  119. return (TX4938_MKA(TX4938_IRC_IRLVL1));
  120. }
  121. case 21:
  122. case 20:
  123. case 5:
  124. case 4:{
  125. return (TX4938_MKA(TX4938_IRC_IRLVL2));
  126. }
  127. case 23:
  128. case 22:
  129. case 7:
  130. case 6:{
  131. return (TX4938_MKA(TX4938_IRC_IRLVL3));
  132. }
  133. case 25:
  134. case 24:
  135. case 9:
  136. case 8:{
  137. return (TX4938_MKA(TX4938_IRC_IRLVL4));
  138. }
  139. case 27:
  140. case 26:
  141. case 11:
  142. case 10:{
  143. return (TX4938_MKA(TX4938_IRC_IRLVL5));
  144. }
  145. case 29:
  146. case 28:
  147. case 13:
  148. case 12:{
  149. return (TX4938_MKA(TX4938_IRC_IRLVL6));
  150. }
  151. case 31:
  152. case 30:
  153. case 15:
  154. case 14:{
  155. return (TX4938_MKA(TX4938_IRC_IRLVL7));
  156. }
  157. }
  158. return 0;
  159. }
  160. u32
  161. tx4938_irq_pic_mask(int irq)
  162. {
  163. /* MVMCP -- need to formulize this */
  164. irq -= TX4938_IRQ_PIC_BEG;
  165. switch (irq) {
  166. case 31:
  167. case 29:
  168. case 27:
  169. case 25:
  170. case 23:
  171. case 21:
  172. case 19:
  173. case 17:{
  174. return (0x07000000);
  175. }
  176. case 30:
  177. case 28:
  178. case 26:
  179. case 24:
  180. case 22:
  181. case 20:
  182. case 18:
  183. case 16:{
  184. return (0x00070000);
  185. }
  186. case 15:
  187. case 13:
  188. case 11:
  189. case 9:
  190. case 7:
  191. case 5:
  192. case 3:
  193. case 1:{
  194. return (0x00000700);
  195. }
  196. case 14:
  197. case 12:
  198. case 10:
  199. case 8:
  200. case 6:
  201. case 4:
  202. case 2:
  203. case 0:{
  204. return (0x00000007);
  205. }
  206. }
  207. return 0x00000000;
  208. }
  209. static void
  210. tx4938_irq_pic_modify(unsigned pic_reg, unsigned clr_bits, unsigned set_bits)
  211. {
  212. unsigned long val = 0;
  213. val = TX4938_RD(pic_reg);
  214. val &= (~clr_bits);
  215. val |= (set_bits);
  216. TX4938_WR(pic_reg, val);
  217. mmiowb();
  218. TX4938_RD(pic_reg);
  219. }
  220. static void __init
  221. tx4938_irq_pic_init(void)
  222. {
  223. int i;
  224. for (i = TX4938_IRQ_PIC_BEG; i <= TX4938_IRQ_PIC_END; i++)
  225. set_irq_chip_and_handler(i, &tx4938_irq_pic_type,
  226. handle_level_irq);
  227. setup_irq(TX4938_IRQ_NEST_PIC_ON_CP0, &tx4938_irq_pic_action);
  228. TX4938_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
  229. TX4938_WR(0xff1ff600, TX4938_RD(0xff1ff600) | 0x1); /* irq enable */
  230. }
  231. static void
  232. tx4938_irq_pic_enable(unsigned int irq)
  233. {
  234. tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq), 0,
  235. tx4938_irq_pic_mask(irq));
  236. }
  237. static void
  238. tx4938_irq_pic_disable(unsigned int irq)
  239. {
  240. tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq),
  241. tx4938_irq_pic_mask(irq), 0);
  242. }
  243. static void
  244. tx4938_irq_pic_end(unsigned int irq)
  245. {
  246. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  247. tx4938_irq_pic_enable(irq);
  248. }
  249. }
  250. /**********************************************************************************/
  251. /* Main init functions */
  252. /**********************************************************************************/
  253. void __init
  254. tx4938_irq_init(void)
  255. {
  256. tx4938_irq_cp0_init();
  257. tx4938_irq_pic_init();
  258. }
  259. int
  260. tx4938_irq_nested(void)
  261. {
  262. int sw_irq = 0;
  263. u32 level2;
  264. level2 = TX4938_RD(0xff1ff6a0);
  265. if ((level2 & 0x10000) == 0) {
  266. level2 &= 0x1f;
  267. sw_irq = TX4938_IRQ_PIC_BEG + level2;
  268. if (sw_irq == 26) {
  269. {
  270. extern int toshiba_rbtx4938_irq_nested(int sw_irq);
  271. sw_irq = toshiba_rbtx4938_irq_nested(sw_irq);
  272. }
  273. }
  274. }
  275. wbflush();
  276. return sw_irq;
  277. }
  278. asmlinkage void plat_irq_dispatch(void)
  279. {
  280. unsigned int pending = read_c0_cause() & read_c0_status();
  281. if (pending & STATUSF_IP7)
  282. do_IRQ(TX4938_IRQ_CPU_TIMER);
  283. else if (pending & STATUSF_IP2) {
  284. int irq = tx4938_irq_nested();
  285. if (irq)
  286. do_IRQ(irq);
  287. else
  288. spurious_interrupt();
  289. } else if (pending & STATUSF_IP1)
  290. do_IRQ(TX4938_IRQ_USER1);
  291. else if (pending & STATUSF_IP0)
  292. do_IRQ(TX4938_IRQ_USER0);
  293. }