irq.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 unsigned int tx4938_irq_cp0_startup(unsigned int irq);
  39. static void tx4938_irq_cp0_shutdown(unsigned int irq);
  40. static void tx4938_irq_cp0_enable(unsigned int irq);
  41. static void tx4938_irq_cp0_disable(unsigned int irq);
  42. static void tx4938_irq_cp0_mask_and_ack(unsigned int irq);
  43. static void tx4938_irq_cp0_end(unsigned int irq);
  44. static unsigned int tx4938_irq_pic_startup(unsigned int irq);
  45. static void tx4938_irq_pic_shutdown(unsigned int irq);
  46. static void tx4938_irq_pic_enable(unsigned int irq);
  47. static void tx4938_irq_pic_disable(unsigned int irq);
  48. static void tx4938_irq_pic_mask_and_ack(unsigned int irq);
  49. static void tx4938_irq_pic_end(unsigned int irq);
  50. /**********************************************************************************/
  51. /* Kernel structs for all pic's */
  52. /**********************************************************************************/
  53. DEFINE_SPINLOCK(tx4938_cp0_lock);
  54. DEFINE_SPINLOCK(tx4938_pic_lock);
  55. #define TX4938_CP0_NAME "TX4938-CP0"
  56. static struct irq_chip tx4938_irq_cp0_type = {
  57. .typename = TX4938_CP0_NAME,
  58. .startup = tx4938_irq_cp0_startup,
  59. .shutdown = tx4938_irq_cp0_shutdown,
  60. .enable = tx4938_irq_cp0_enable,
  61. .disable = tx4938_irq_cp0_disable,
  62. .ack = tx4938_irq_cp0_mask_and_ack,
  63. .end = tx4938_irq_cp0_end,
  64. .set_affinity = NULL
  65. };
  66. #define TX4938_PIC_NAME "TX4938-PIC"
  67. static struct irq_chip tx4938_irq_pic_type = {
  68. .typename = TX4938_PIC_NAME,
  69. .startup = tx4938_irq_pic_startup,
  70. .shutdown = tx4938_irq_pic_shutdown,
  71. .enable = tx4938_irq_pic_enable,
  72. .disable = tx4938_irq_pic_disable,
  73. .ack = tx4938_irq_pic_mask_and_ack,
  74. .end = tx4938_irq_pic_end,
  75. .set_affinity = NULL
  76. };
  77. static struct irqaction tx4938_irq_pic_action = {
  78. .handler = no_action,
  79. .flags = 0,
  80. .mask = CPU_MASK_NONE,
  81. .name = TX4938_PIC_NAME
  82. };
  83. /**********************************************************************************/
  84. /* Functions for cp0 */
  85. /**********************************************************************************/
  86. #define tx4938_irq_cp0_mask(irq) ( 1 << ( irq-TX4938_IRQ_CP0_BEG+8 ) )
  87. static void __init
  88. tx4938_irq_cp0_init(void)
  89. {
  90. int i;
  91. for (i = TX4938_IRQ_CP0_BEG; i <= TX4938_IRQ_CP0_END; i++) {
  92. irq_desc[i].status = IRQ_DISABLED;
  93. irq_desc[i].action = 0;
  94. irq_desc[i].depth = 1;
  95. irq_desc[i].chip = &tx4938_irq_cp0_type;
  96. }
  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. }
  125. static void
  126. tx4938_irq_cp0_mask_and_ack(unsigned int irq)
  127. {
  128. tx4938_irq_cp0_disable(irq);
  129. }
  130. static void
  131. tx4938_irq_cp0_end(unsigned int irq)
  132. {
  133. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  134. tx4938_irq_cp0_enable(irq);
  135. }
  136. }
  137. /**********************************************************************************/
  138. /* Functions for pic */
  139. /**********************************************************************************/
  140. u32
  141. tx4938_irq_pic_addr(int irq)
  142. {
  143. /* MVMCP -- need to formulize this */
  144. irq -= TX4938_IRQ_PIC_BEG;
  145. switch (irq) {
  146. case 17:
  147. case 16:
  148. case 1:
  149. case 0:{
  150. return (TX4938_MKA(TX4938_IRC_IRLVL0));
  151. }
  152. case 19:
  153. case 18:
  154. case 3:
  155. case 2:{
  156. return (TX4938_MKA(TX4938_IRC_IRLVL1));
  157. }
  158. case 21:
  159. case 20:
  160. case 5:
  161. case 4:{
  162. return (TX4938_MKA(TX4938_IRC_IRLVL2));
  163. }
  164. case 23:
  165. case 22:
  166. case 7:
  167. case 6:{
  168. return (TX4938_MKA(TX4938_IRC_IRLVL3));
  169. }
  170. case 25:
  171. case 24:
  172. case 9:
  173. case 8:{
  174. return (TX4938_MKA(TX4938_IRC_IRLVL4));
  175. }
  176. case 27:
  177. case 26:
  178. case 11:
  179. case 10:{
  180. return (TX4938_MKA(TX4938_IRC_IRLVL5));
  181. }
  182. case 29:
  183. case 28:
  184. case 13:
  185. case 12:{
  186. return (TX4938_MKA(TX4938_IRC_IRLVL6));
  187. }
  188. case 31:
  189. case 30:
  190. case 15:
  191. case 14:{
  192. return (TX4938_MKA(TX4938_IRC_IRLVL7));
  193. }
  194. }
  195. return 0;
  196. }
  197. u32
  198. tx4938_irq_pic_mask(int irq)
  199. {
  200. /* MVMCP -- need to formulize this */
  201. irq -= TX4938_IRQ_PIC_BEG;
  202. switch (irq) {
  203. case 31:
  204. case 29:
  205. case 27:
  206. case 25:
  207. case 23:
  208. case 21:
  209. case 19:
  210. case 17:{
  211. return (0x07000000);
  212. }
  213. case 30:
  214. case 28:
  215. case 26:
  216. case 24:
  217. case 22:
  218. case 20:
  219. case 18:
  220. case 16:{
  221. return (0x00070000);
  222. }
  223. case 15:
  224. case 13:
  225. case 11:
  226. case 9:
  227. case 7:
  228. case 5:
  229. case 3:
  230. case 1:{
  231. return (0x00000700);
  232. }
  233. case 14:
  234. case 12:
  235. case 10:
  236. case 8:
  237. case 6:
  238. case 4:
  239. case 2:
  240. case 0:{
  241. return (0x00000007);
  242. }
  243. }
  244. return 0x00000000;
  245. }
  246. static void
  247. tx4938_irq_pic_modify(unsigned pic_reg, unsigned clr_bits, unsigned set_bits)
  248. {
  249. unsigned long val = 0;
  250. val = TX4938_RD(pic_reg);
  251. val &= (~clr_bits);
  252. val |= (set_bits);
  253. TX4938_WR(pic_reg, val);
  254. mmiowb();
  255. TX4938_RD(pic_reg);
  256. }
  257. static void __init
  258. tx4938_irq_pic_init(void)
  259. {
  260. unsigned long flags;
  261. int i;
  262. for (i = TX4938_IRQ_PIC_BEG; i <= TX4938_IRQ_PIC_END; i++) {
  263. irq_desc[i].status = IRQ_DISABLED;
  264. irq_desc[i].action = 0;
  265. irq_desc[i].depth = 2;
  266. irq_desc[i].chip = &tx4938_irq_pic_type;
  267. }
  268. setup_irq(TX4938_IRQ_NEST_PIC_ON_CP0, &tx4938_irq_pic_action);
  269. spin_lock_irqsave(&tx4938_pic_lock, flags);
  270. TX4938_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
  271. TX4938_WR(0xff1ff600, TX4938_RD(0xff1ff600) | 0x1); /* irq enable */
  272. spin_unlock_irqrestore(&tx4938_pic_lock, flags);
  273. }
  274. static unsigned int
  275. tx4938_irq_pic_startup(unsigned int irq)
  276. {
  277. tx4938_irq_pic_enable(irq);
  278. return 0;
  279. }
  280. static void
  281. tx4938_irq_pic_shutdown(unsigned int irq)
  282. {
  283. tx4938_irq_pic_disable(irq);
  284. }
  285. static void
  286. tx4938_irq_pic_enable(unsigned int irq)
  287. {
  288. unsigned long flags;
  289. spin_lock_irqsave(&tx4938_pic_lock, flags);
  290. tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq), 0,
  291. tx4938_irq_pic_mask(irq));
  292. spin_unlock_irqrestore(&tx4938_pic_lock, flags);
  293. }
  294. static void
  295. tx4938_irq_pic_disable(unsigned int irq)
  296. {
  297. unsigned long flags;
  298. spin_lock_irqsave(&tx4938_pic_lock, flags);
  299. tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq),
  300. tx4938_irq_pic_mask(irq), 0);
  301. spin_unlock_irqrestore(&tx4938_pic_lock, flags);
  302. }
  303. static void
  304. tx4938_irq_pic_mask_and_ack(unsigned int irq)
  305. {
  306. tx4938_irq_pic_disable(irq);
  307. }
  308. static void
  309. tx4938_irq_pic_end(unsigned int irq)
  310. {
  311. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  312. tx4938_irq_pic_enable(irq);
  313. }
  314. }
  315. /**********************************************************************************/
  316. /* Main init functions */
  317. /**********************************************************************************/
  318. void __init
  319. tx4938_irq_init(void)
  320. {
  321. tx4938_irq_cp0_init();
  322. tx4938_irq_pic_init();
  323. }
  324. int
  325. tx4938_irq_nested(void)
  326. {
  327. int sw_irq = 0;
  328. u32 level2;
  329. level2 = TX4938_RD(0xff1ff6a0);
  330. if ((level2 & 0x10000) == 0) {
  331. level2 &= 0x1f;
  332. sw_irq = TX4938_IRQ_PIC_BEG + level2;
  333. if (sw_irq == 26) {
  334. {
  335. extern int toshiba_rbtx4938_irq_nested(int sw_irq);
  336. sw_irq = toshiba_rbtx4938_irq_nested(sw_irq);
  337. }
  338. }
  339. }
  340. wbflush();
  341. return sw_irq;
  342. }
  343. asmlinkage void plat_irq_dispatch(void)
  344. {
  345. unsigned int pending = read_c0_cause() & read_c0_status();
  346. if (pending & STATUSF_IP7)
  347. do_IRQ(TX4938_IRQ_CPU_TIMER);
  348. else if (pending & STATUSF_IP2) {
  349. int irq = tx4938_irq_nested();
  350. if (irq)
  351. do_IRQ(irq);
  352. else
  353. spurious_interrupt();
  354. } else if (pending & STATUSF_IP1)
  355. do_IRQ(TX4938_IRQ_USER1);
  356. else if (pending & STATUSF_IP0)
  357. do_IRQ(TX4938_IRQ_USER0);
  358. }