tx4927_irq.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /*
  2. * Common tx4927 irq handler
  3. *
  4. * Author: MontaVista Software, Inc.
  5. * source@mvista.com
  6. *
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  12. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  14. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  15. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  16. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  17. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  18. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  19. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  20. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 675 Mass Ave, Cambridge, MA 02139, USA.
  25. */
  26. #include <linux/errno.h>
  27. #include <linux/init.h>
  28. #include <linux/kernel_stat.h>
  29. #include <linux/module.h>
  30. #include <linux/signal.h>
  31. #include <linux/sched.h>
  32. #include <linux/types.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/ioport.h>
  35. #include <linux/timex.h>
  36. #include <linux/slab.h>
  37. #include <linux/random.h>
  38. #include <linux/irq.h>
  39. #include <linux/bitops.h>
  40. #include <asm/bootinfo.h>
  41. #include <asm/io.h>
  42. #include <asm/irq.h>
  43. #include <asm/mipsregs.h>
  44. #include <asm/system.h>
  45. #include <asm/tx4927/tx4927.h>
  46. /*
  47. * DEBUG
  48. */
  49. #undef TX4927_IRQ_DEBUG
  50. #ifdef TX4927_IRQ_DEBUG
  51. #define TX4927_IRQ_NONE 0x00000000
  52. #define TX4927_IRQ_INFO ( 1 << 0 )
  53. #define TX4927_IRQ_WARN ( 1 << 1 )
  54. #define TX4927_IRQ_EROR ( 1 << 2 )
  55. #define TX4927_IRQ_INIT ( 1 << 5 )
  56. #define TX4927_IRQ_NEST1 ( 1 << 6 )
  57. #define TX4927_IRQ_NEST2 ( 1 << 7 )
  58. #define TX4927_IRQ_NEST3 ( 1 << 8 )
  59. #define TX4927_IRQ_NEST4 ( 1 << 9 )
  60. #define TX4927_IRQ_CP0_INIT ( 1 << 10 )
  61. #define TX4927_IRQ_CP0_ENABLE ( 1 << 13 )
  62. #define TX4927_IRQ_CP0_DISABLE ( 1 << 14 )
  63. #define TX4927_IRQ_CP0_ENDIRQ ( 1 << 16 )
  64. #define TX4927_IRQ_PIC_INIT ( 1 << 20 )
  65. #define TX4927_IRQ_PIC_ENABLE ( 1 << 23 )
  66. #define TX4927_IRQ_PIC_DISABLE ( 1 << 24 )
  67. #define TX4927_IRQ_PIC_ENDIRQ ( 1 << 26 )
  68. #define TX4927_IRQ_ALL 0xffffffff
  69. #endif
  70. #ifdef TX4927_IRQ_DEBUG
  71. static const u32 tx4927_irq_debug_flag = (TX4927_IRQ_NONE
  72. | TX4927_IRQ_INFO
  73. | TX4927_IRQ_WARN | TX4927_IRQ_EROR
  74. // | TX4927_IRQ_CP0_INIT
  75. // | TX4927_IRQ_CP0_ENABLE
  76. // | TX4927_IRQ_CP0_DISABLE
  77. // | TX4927_IRQ_CP0_ENDIRQ
  78. // | TX4927_IRQ_PIC_INIT
  79. // | TX4927_IRQ_PIC_ENABLE
  80. // | TX4927_IRQ_PIC_DISABLE
  81. // | TX4927_IRQ_PIC_ENDIRQ
  82. // | TX4927_IRQ_INIT
  83. // | TX4927_IRQ_NEST1
  84. // | TX4927_IRQ_NEST2
  85. // | TX4927_IRQ_NEST3
  86. // | TX4927_IRQ_NEST4
  87. );
  88. #endif
  89. #ifdef TX4927_IRQ_DEBUG
  90. #define TX4927_IRQ_DPRINTK(flag,str...) \
  91. if ( (tx4927_irq_debug_flag) & (flag) ) \
  92. { \
  93. char tmp[100]; \
  94. sprintf( tmp, str ); \
  95. printk( "%s(%s:%u)::%s", __FUNCTION__, __FILE__, __LINE__, tmp ); \
  96. }
  97. #else
  98. #define TX4927_IRQ_DPRINTK(flag,str...)
  99. #endif
  100. /*
  101. * Forwad definitions for all pic's
  102. */
  103. static void tx4927_irq_cp0_enable(unsigned int irq);
  104. static void tx4927_irq_cp0_disable(unsigned int irq);
  105. static void tx4927_irq_cp0_end(unsigned int irq);
  106. static void tx4927_irq_pic_enable(unsigned int irq);
  107. static void tx4927_irq_pic_disable(unsigned int irq);
  108. static void tx4927_irq_pic_end(unsigned int irq);
  109. /*
  110. * Kernel structs for all pic's
  111. */
  112. #define TX4927_CP0_NAME "TX4927-CP0"
  113. static struct irq_chip tx4927_irq_cp0_type = {
  114. .typename = TX4927_CP0_NAME,
  115. .ack = tx4927_irq_cp0_disable,
  116. .mask = tx4927_irq_cp0_disable,
  117. .mask_ack = tx4927_irq_cp0_disable,
  118. .unmask = tx4927_irq_cp0_enable,
  119. .end = tx4927_irq_cp0_end,
  120. };
  121. #define TX4927_PIC_NAME "TX4927-PIC"
  122. static struct irq_chip tx4927_irq_pic_type = {
  123. .typename = TX4927_PIC_NAME,
  124. .ack = tx4927_irq_pic_disable,
  125. .mask = tx4927_irq_pic_disable,
  126. .mask_ack = tx4927_irq_pic_disable,
  127. .unmask = tx4927_irq_pic_enable,
  128. .end = tx4927_irq_pic_end,
  129. };
  130. #define TX4927_PIC_ACTION(s) { no_action, 0, CPU_MASK_NONE, s, NULL, NULL }
  131. static struct irqaction tx4927_irq_pic_action =
  132. TX4927_PIC_ACTION(TX4927_PIC_NAME);
  133. #define CCP0_STATUS 12
  134. #define CCP0_CAUSE 13
  135. /*
  136. * Functions for cp0
  137. */
  138. #define tx4927_irq_cp0_mask(irq) ( 1 << ( irq-TX4927_IRQ_CP0_BEG+8 ) )
  139. static void
  140. tx4927_irq_cp0_modify(unsigned cp0_reg, unsigned clr_bits, unsigned set_bits)
  141. {
  142. unsigned long val = 0;
  143. switch (cp0_reg) {
  144. case CCP0_STATUS:
  145. val = read_c0_status();
  146. break;
  147. case CCP0_CAUSE:
  148. val = read_c0_cause();
  149. break;
  150. }
  151. val &= (~clr_bits);
  152. val |= (set_bits);
  153. switch (cp0_reg) {
  154. case CCP0_STATUS:{
  155. write_c0_status(val);
  156. break;
  157. }
  158. case CCP0_CAUSE:{
  159. write_c0_cause(val);
  160. break;
  161. }
  162. }
  163. }
  164. static void __init tx4927_irq_cp0_init(void)
  165. {
  166. int i;
  167. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_INIT, "beg=%d end=%d\n",
  168. TX4927_IRQ_CP0_BEG, TX4927_IRQ_CP0_END);
  169. for (i = TX4927_IRQ_CP0_BEG; i <= TX4927_IRQ_CP0_END; i++)
  170. set_irq_chip_and_handler(i, &tx4927_irq_cp0_type,
  171. handle_level_irq);
  172. }
  173. static void tx4927_irq_cp0_enable(unsigned int irq)
  174. {
  175. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENABLE, "irq=%d \n", irq);
  176. tx4927_irq_cp0_modify(CCP0_STATUS, 0, tx4927_irq_cp0_mask(irq));
  177. }
  178. static void tx4927_irq_cp0_disable(unsigned int irq)
  179. {
  180. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_DISABLE, "irq=%d \n", irq);
  181. tx4927_irq_cp0_modify(CCP0_STATUS, tx4927_irq_cp0_mask(irq), 0);
  182. }
  183. static void tx4927_irq_cp0_end(unsigned int irq)
  184. {
  185. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENDIRQ, "irq=%d \n", irq);
  186. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  187. tx4927_irq_cp0_enable(irq);
  188. }
  189. }
  190. /*
  191. * Functions for pic
  192. */
  193. u32 tx4927_irq_pic_addr(int irq)
  194. {
  195. /* MVMCP -- need to formulize this */
  196. irq -= TX4927_IRQ_PIC_BEG;
  197. switch (irq) {
  198. case 17:
  199. case 16:
  200. case 1:
  201. case 0:
  202. return (0xff1ff610);
  203. case 19:
  204. case 18:
  205. case 3:
  206. case 2:
  207. return (0xff1ff614);
  208. case 21:
  209. case 20:
  210. case 5:
  211. case 4:
  212. return (0xff1ff618);
  213. case 23:
  214. case 22:
  215. case 7:
  216. case 6:
  217. return (0xff1ff61c);
  218. case 25:
  219. case 24:
  220. case 9:
  221. case 8:
  222. return (0xff1ff620);
  223. case 27:
  224. case 26:
  225. case 11:
  226. case 10:
  227. return (0xff1ff624);
  228. case 29:
  229. case 28:
  230. case 13:
  231. case 12:
  232. return (0xff1ff628);
  233. case 31:
  234. case 30:
  235. case 15:
  236. case 14:
  237. return (0xff1ff62c);
  238. }
  239. return (0);
  240. }
  241. u32 tx4927_irq_pic_mask(int irq)
  242. {
  243. /* MVMCP -- need to formulize this */
  244. irq -= TX4927_IRQ_PIC_BEG;
  245. switch (irq) {
  246. case 31:
  247. case 29:
  248. case 27:
  249. case 25:
  250. case 23:
  251. case 21:
  252. case 19:
  253. case 17:{
  254. return (0x07000000);
  255. }
  256. case 30:
  257. case 28:
  258. case 26:
  259. case 24:
  260. case 22:
  261. case 20:
  262. case 18:
  263. case 16:{
  264. return (0x00070000);
  265. }
  266. case 15:
  267. case 13:
  268. case 11:
  269. case 9:
  270. case 7:
  271. case 5:
  272. case 3:
  273. case 1:{
  274. return (0x00000700);
  275. }
  276. case 14:
  277. case 12:
  278. case 10:
  279. case 8:
  280. case 6:
  281. case 4:
  282. case 2:
  283. case 0:{
  284. return (0x00000007);
  285. }
  286. }
  287. return (0x00000000);
  288. }
  289. static void tx4927_irq_pic_modify(unsigned pic_reg, unsigned clr_bits,
  290. unsigned set_bits)
  291. {
  292. unsigned long val = 0;
  293. val = TX4927_RD(pic_reg);
  294. val &= (~clr_bits);
  295. val |= (set_bits);
  296. TX4927_WR(pic_reg, val);
  297. }
  298. static void __init tx4927_irq_pic_init(void)
  299. {
  300. int i;
  301. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_INIT, "beg=%d end=%d\n",
  302. TX4927_IRQ_PIC_BEG, TX4927_IRQ_PIC_END);
  303. for (i = TX4927_IRQ_PIC_BEG; i <= TX4927_IRQ_PIC_END; i++)
  304. set_irq_chip_and_handler(i, &tx4927_irq_pic_type,
  305. handle_level_irq);
  306. setup_irq(TX4927_IRQ_NEST_PIC_ON_CP0, &tx4927_irq_pic_action);
  307. TX4927_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
  308. TX4927_WR(0xff1ff600, TX4927_RD(0xff1ff600) | 0x1); /* irq enable */
  309. }
  310. static void tx4927_irq_pic_enable(unsigned int irq)
  311. {
  312. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENABLE, "irq=%d\n", irq);
  313. tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq), 0,
  314. tx4927_irq_pic_mask(irq));
  315. }
  316. static void tx4927_irq_pic_disable(unsigned int irq)
  317. {
  318. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_DISABLE, "irq=%d\n", irq);
  319. tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq),
  320. tx4927_irq_pic_mask(irq), 0);
  321. }
  322. static void tx4927_irq_pic_end(unsigned int irq)
  323. {
  324. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENDIRQ, "irq=%d\n", irq);
  325. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  326. tx4927_irq_pic_enable(irq);
  327. }
  328. }
  329. /*
  330. * Main init functions
  331. */
  332. void __init tx4927_irq_init(void)
  333. {
  334. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "-\n");
  335. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_cp0_init()\n");
  336. tx4927_irq_cp0_init();
  337. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_pic_init()\n");
  338. tx4927_irq_pic_init();
  339. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "+\n");
  340. }
  341. static int tx4927_irq_nested(void)
  342. {
  343. int sw_irq = 0;
  344. u32 level2;
  345. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "-\n");
  346. level2 = TX4927_RD(0xff1ff6a0);
  347. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=level2a=0x%x\n", level2);
  348. if ((level2 & 0x10000) == 0) {
  349. level2 &= 0x1f;
  350. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=level2b=0x%x\n", level2);
  351. sw_irq = TX4927_IRQ_PIC_BEG + level2;
  352. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=sw_irq=%d\n", sw_irq);
  353. if (sw_irq == 27) {
  354. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq-%d\n",
  355. sw_irq);
  356. #ifdef CONFIG_TOSHIBA_RBTX4927
  357. {
  358. sw_irq = toshiba_rbtx4927_irq_nested(sw_irq);
  359. }
  360. #endif
  361. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq+%d\n",
  362. sw_irq);
  363. }
  364. }
  365. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=sw_irq=%d\n", sw_irq);
  366. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "+\n");
  367. return (sw_irq);
  368. }
  369. asmlinkage void plat_irq_dispatch(void)
  370. {
  371. unsigned int pending = read_c0_status() & read_c0_cause();
  372. if (pending & STATUSF_IP7) /* cpu timer */
  373. do_IRQ(TX4927_IRQ_CPU_TIMER);
  374. else if (pending & STATUSF_IP2) { /* tx4927 pic */
  375. unsigned int irq = tx4927_irq_nested();
  376. if (unlikely(irq == 0)) {
  377. spurious_interrupt();
  378. return;
  379. }
  380. do_IRQ(irq);
  381. } else if (pending & STATUSF_IP0) /* user line 0 */
  382. do_IRQ(TX4927_IRQ_USER0);
  383. else if (pending & STATUSF_IP1) /* user line 1 */
  384. do_IRQ(TX4927_IRQ_USER1);
  385. else
  386. spurious_interrupt();
  387. }