irq.c 6.6 KB

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