tx4927_irq.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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/config.h>
  27. #include <linux/errno.h>
  28. #include <linux/init.h>
  29. #include <linux/kernel_stat.h>
  30. #include <linux/module.h>
  31. #include <linux/signal.h>
  32. #include <linux/sched.h>
  33. #include <linux/types.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/ioport.h>
  36. #include <linux/timex.h>
  37. #include <linux/slab.h>
  38. #include <linux/random.h>
  39. #include <linux/irq.h>
  40. #include <linux/bitops.h>
  41. #include <asm/bootinfo.h>
  42. #include <asm/io.h>
  43. #include <asm/irq.h>
  44. #include <asm/mipsregs.h>
  45. #include <asm/system.h>
  46. #include <asm/tx4927/tx4927.h>
  47. /*
  48. * DEBUG
  49. */
  50. #undef TX4927_IRQ_DEBUG
  51. #ifdef TX4927_IRQ_DEBUG
  52. #define TX4927_IRQ_NONE 0x00000000
  53. #define TX4927_IRQ_INFO ( 1 << 0 )
  54. #define TX4927_IRQ_WARN ( 1 << 1 )
  55. #define TX4927_IRQ_EROR ( 1 << 2 )
  56. #define TX4927_IRQ_INIT ( 1 << 5 )
  57. #define TX4927_IRQ_NEST1 ( 1 << 6 )
  58. #define TX4927_IRQ_NEST2 ( 1 << 7 )
  59. #define TX4927_IRQ_NEST3 ( 1 << 8 )
  60. #define TX4927_IRQ_NEST4 ( 1 << 9 )
  61. #define TX4927_IRQ_CP0_INIT ( 1 << 10 )
  62. #define TX4927_IRQ_CP0_STARTUP ( 1 << 11 )
  63. #define TX4927_IRQ_CP0_SHUTDOWN ( 1 << 12 )
  64. #define TX4927_IRQ_CP0_ENABLE ( 1 << 13 )
  65. #define TX4927_IRQ_CP0_DISABLE ( 1 << 14 )
  66. #define TX4927_IRQ_CP0_MASK ( 1 << 15 )
  67. #define TX4927_IRQ_CP0_ENDIRQ ( 1 << 16 )
  68. #define TX4927_IRQ_PIC_INIT ( 1 << 20 )
  69. #define TX4927_IRQ_PIC_STARTUP ( 1 << 21 )
  70. #define TX4927_IRQ_PIC_SHUTDOWN ( 1 << 22 )
  71. #define TX4927_IRQ_PIC_ENABLE ( 1 << 23 )
  72. #define TX4927_IRQ_PIC_DISABLE ( 1 << 24 )
  73. #define TX4927_IRQ_PIC_MASK ( 1 << 25 )
  74. #define TX4927_IRQ_PIC_ENDIRQ ( 1 << 26 )
  75. #define TX4927_IRQ_ALL 0xffffffff
  76. #endif
  77. #ifdef TX4927_IRQ_DEBUG
  78. static const u32 tx4927_irq_debug_flag = (TX4927_IRQ_NONE
  79. | TX4927_IRQ_INFO
  80. | TX4927_IRQ_WARN | TX4927_IRQ_EROR
  81. // | TX4927_IRQ_CP0_INIT
  82. // | TX4927_IRQ_CP0_STARTUP
  83. // | TX4927_IRQ_CP0_SHUTDOWN
  84. // | TX4927_IRQ_CP0_ENABLE
  85. // | TX4927_IRQ_CP0_DISABLE
  86. // | TX4927_IRQ_CP0_MASK
  87. // | TX4927_IRQ_CP0_ENDIRQ
  88. // | TX4927_IRQ_PIC_INIT
  89. // | TX4927_IRQ_PIC_STARTUP
  90. // | TX4927_IRQ_PIC_SHUTDOWN
  91. // | TX4927_IRQ_PIC_ENABLE
  92. // | TX4927_IRQ_PIC_DISABLE
  93. // | TX4927_IRQ_PIC_MASK
  94. // | TX4927_IRQ_PIC_ENDIRQ
  95. // | TX4927_IRQ_INIT
  96. // | TX4927_IRQ_NEST1
  97. // | TX4927_IRQ_NEST2
  98. // | TX4927_IRQ_NEST3
  99. // | TX4927_IRQ_NEST4
  100. );
  101. #endif
  102. #ifdef TX4927_IRQ_DEBUG
  103. #define TX4927_IRQ_DPRINTK(flag,str...) \
  104. if ( (tx4927_irq_debug_flag) & (flag) ) \
  105. { \
  106. char tmp[100]; \
  107. sprintf( tmp, str ); \
  108. printk( "%s(%s:%u)::%s", __FUNCTION__, __FILE__, __LINE__, tmp ); \
  109. }
  110. #else
  111. #define TX4927_IRQ_DPRINTK(flag,str...)
  112. #endif
  113. /*
  114. * Forwad definitions for all pic's
  115. */
  116. static unsigned int tx4927_irq_cp0_startup(unsigned int irq);
  117. static void tx4927_irq_cp0_shutdown(unsigned int irq);
  118. static void tx4927_irq_cp0_enable(unsigned int irq);
  119. static void tx4927_irq_cp0_disable(unsigned int irq);
  120. static void tx4927_irq_cp0_mask_and_ack(unsigned int irq);
  121. static void tx4927_irq_cp0_end(unsigned int irq);
  122. static unsigned int tx4927_irq_pic_startup(unsigned int irq);
  123. static void tx4927_irq_pic_shutdown(unsigned int irq);
  124. static void tx4927_irq_pic_enable(unsigned int irq);
  125. static void tx4927_irq_pic_disable(unsigned int irq);
  126. static void tx4927_irq_pic_mask_and_ack(unsigned int irq);
  127. static void tx4927_irq_pic_end(unsigned int irq);
  128. /*
  129. * Kernel structs for all pic's
  130. */
  131. static DEFINE_SPINLOCK(tx4927_cp0_lock);
  132. static DEFINE_SPINLOCK(tx4927_pic_lock);
  133. #define TX4927_CP0_NAME "TX4927-CP0"
  134. static struct hw_interrupt_type tx4927_irq_cp0_type = {
  135. .typename = TX4927_CP0_NAME,
  136. .startup = tx4927_irq_cp0_startup,
  137. .shutdown = tx4927_irq_cp0_shutdown,
  138. .enable = tx4927_irq_cp0_enable,
  139. .disable = tx4927_irq_cp0_disable,
  140. .ack = tx4927_irq_cp0_mask_and_ack,
  141. .end = tx4927_irq_cp0_end,
  142. .set_affinity = NULL
  143. };
  144. #define TX4927_PIC_NAME "TX4927-PIC"
  145. static struct hw_interrupt_type tx4927_irq_pic_type = {
  146. .typename = TX4927_PIC_NAME,
  147. .startup = tx4927_irq_pic_startup,
  148. .shutdown = tx4927_irq_pic_shutdown,
  149. .enable = tx4927_irq_pic_enable,
  150. .disable = tx4927_irq_pic_disable,
  151. .ack = tx4927_irq_pic_mask_and_ack,
  152. .end = tx4927_irq_pic_end,
  153. .set_affinity = NULL
  154. };
  155. #define TX4927_PIC_ACTION(s) { no_action, 0, CPU_MASK_NONE, s, NULL, NULL }
  156. static struct irqaction tx4927_irq_pic_action =
  157. TX4927_PIC_ACTION(TX4927_PIC_NAME);
  158. #define CCP0_STATUS 12
  159. #define CCP0_CAUSE 13
  160. /*
  161. * Functions for cp0
  162. */
  163. #define tx4927_irq_cp0_mask(irq) ( 1 << ( irq-TX4927_IRQ_CP0_BEG+8 ) )
  164. static void
  165. tx4927_irq_cp0_modify(unsigned cp0_reg, unsigned clr_bits, unsigned set_bits)
  166. {
  167. unsigned long val = 0;
  168. switch (cp0_reg) {
  169. case CCP0_STATUS:
  170. val = read_c0_status();
  171. break;
  172. case CCP0_CAUSE:
  173. val = read_c0_cause();
  174. break;
  175. }
  176. val &= (~clr_bits);
  177. val |= (set_bits);
  178. switch (cp0_reg) {
  179. case CCP0_STATUS:{
  180. write_c0_status(val);
  181. break;
  182. }
  183. case CCP0_CAUSE:{
  184. write_c0_cause(val);
  185. break;
  186. }
  187. }
  188. return;
  189. }
  190. static void __init tx4927_irq_cp0_init(void)
  191. {
  192. int i;
  193. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_INIT, "beg=%d end=%d\n",
  194. TX4927_IRQ_CP0_BEG, TX4927_IRQ_CP0_END);
  195. for (i = TX4927_IRQ_CP0_BEG; i <= TX4927_IRQ_CP0_END; i++) {
  196. irq_desc[i].status = IRQ_DISABLED;
  197. irq_desc[i].action = 0;
  198. irq_desc[i].depth = 1;
  199. irq_desc[i].handler = &tx4927_irq_cp0_type;
  200. }
  201. return;
  202. }
  203. static unsigned int tx4927_irq_cp0_startup(unsigned int irq)
  204. {
  205. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_STARTUP, "irq=%d \n", irq);
  206. tx4927_irq_cp0_enable(irq);
  207. return (0);
  208. }
  209. static void tx4927_irq_cp0_shutdown(unsigned int irq)
  210. {
  211. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_SHUTDOWN, "irq=%d \n", irq);
  212. tx4927_irq_cp0_disable(irq);
  213. return;
  214. }
  215. static void tx4927_irq_cp0_enable(unsigned int irq)
  216. {
  217. unsigned long flags;
  218. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENABLE, "irq=%d \n", irq);
  219. spin_lock_irqsave(&tx4927_cp0_lock, flags);
  220. tx4927_irq_cp0_modify(CCP0_STATUS, 0, tx4927_irq_cp0_mask(irq));
  221. spin_unlock_irqrestore(&tx4927_cp0_lock, flags);
  222. return;
  223. }
  224. static void tx4927_irq_cp0_disable(unsigned int irq)
  225. {
  226. unsigned long flags;
  227. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_DISABLE, "irq=%d \n", irq);
  228. spin_lock_irqsave(&tx4927_cp0_lock, flags);
  229. tx4927_irq_cp0_modify(CCP0_STATUS, tx4927_irq_cp0_mask(irq), 0);
  230. spin_unlock_irqrestore(&tx4927_cp0_lock, flags);
  231. return;
  232. }
  233. static void tx4927_irq_cp0_mask_and_ack(unsigned int irq)
  234. {
  235. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_MASK, "irq=%d \n", irq);
  236. tx4927_irq_cp0_disable(irq);
  237. return;
  238. }
  239. static void tx4927_irq_cp0_end(unsigned int irq)
  240. {
  241. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENDIRQ, "irq=%d \n", irq);
  242. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  243. tx4927_irq_cp0_enable(irq);
  244. }
  245. return;
  246. }
  247. /*
  248. * Functions for pic
  249. */
  250. u32 tx4927_irq_pic_addr(int irq)
  251. {
  252. /* MVMCP -- need to formulize this */
  253. irq -= TX4927_IRQ_PIC_BEG;
  254. switch (irq) {
  255. case 17:
  256. case 16:
  257. case 1:
  258. case 0:
  259. return (0xff1ff610);
  260. case 19:
  261. case 18:
  262. case 3:
  263. case 2:
  264. return (0xff1ff614);
  265. case 21:
  266. case 20:
  267. case 5:
  268. case 4:
  269. return (0xff1ff618);
  270. case 23:
  271. case 22:
  272. case 7:
  273. case 6:
  274. return (0xff1ff61c);
  275. case 25:
  276. case 24:
  277. case 9:
  278. case 8:
  279. return (0xff1ff620);
  280. case 27:
  281. case 26:
  282. case 11:
  283. case 10:
  284. return (0xff1ff624);
  285. case 29:
  286. case 28:
  287. case 13:
  288. case 12:
  289. return (0xff1ff628);
  290. case 31:
  291. case 30:
  292. case 15:
  293. case 14:
  294. return (0xff1ff62c);
  295. }
  296. return (0);
  297. }
  298. u32 tx4927_irq_pic_mask(int irq)
  299. {
  300. /* MVMCP -- need to formulize this */
  301. irq -= TX4927_IRQ_PIC_BEG;
  302. switch (irq) {
  303. case 31:
  304. case 29:
  305. case 27:
  306. case 25:
  307. case 23:
  308. case 21:
  309. case 19:
  310. case 17:{
  311. return (0x07000000);
  312. }
  313. case 30:
  314. case 28:
  315. case 26:
  316. case 24:
  317. case 22:
  318. case 20:
  319. case 18:
  320. case 16:{
  321. return (0x00070000);
  322. }
  323. case 15:
  324. case 13:
  325. case 11:
  326. case 9:
  327. case 7:
  328. case 5:
  329. case 3:
  330. case 1:{
  331. return (0x00000700);
  332. }
  333. case 14:
  334. case 12:
  335. case 10:
  336. case 8:
  337. case 6:
  338. case 4:
  339. case 2:
  340. case 0:{
  341. return (0x00000007);
  342. }
  343. }
  344. return (0x00000000);
  345. }
  346. static void tx4927_irq_pic_modify(unsigned pic_reg, unsigned clr_bits,
  347. unsigned set_bits)
  348. {
  349. unsigned long val = 0;
  350. val = TX4927_RD(pic_reg);
  351. val &= (~clr_bits);
  352. val |= (set_bits);
  353. TX4927_WR(pic_reg, val);
  354. return;
  355. }
  356. static void __init tx4927_irq_pic_init(void)
  357. {
  358. unsigned long flags;
  359. int i;
  360. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_INIT, "beg=%d end=%d\n",
  361. TX4927_IRQ_PIC_BEG, TX4927_IRQ_PIC_END);
  362. for (i = TX4927_IRQ_PIC_BEG; i <= TX4927_IRQ_PIC_END; i++) {
  363. irq_desc[i].status = IRQ_DISABLED;
  364. irq_desc[i].action = 0;
  365. irq_desc[i].depth = 2;
  366. irq_desc[i].handler = &tx4927_irq_pic_type;
  367. }
  368. setup_irq(TX4927_IRQ_NEST_PIC_ON_CP0, &tx4927_irq_pic_action);
  369. spin_lock_irqsave(&tx4927_pic_lock, flags);
  370. TX4927_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
  371. TX4927_WR(0xff1ff600, TX4927_RD(0xff1ff600) | 0x1); /* irq enable */
  372. spin_unlock_irqrestore(&tx4927_pic_lock, flags);
  373. return;
  374. }
  375. static unsigned int tx4927_irq_pic_startup(unsigned int irq)
  376. {
  377. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_STARTUP, "irq=%d\n", irq);
  378. tx4927_irq_pic_enable(irq);
  379. return (0);
  380. }
  381. static void tx4927_irq_pic_shutdown(unsigned int irq)
  382. {
  383. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_SHUTDOWN, "irq=%d\n", irq);
  384. tx4927_irq_pic_disable(irq);
  385. return;
  386. }
  387. static void tx4927_irq_pic_enable(unsigned int irq)
  388. {
  389. unsigned long flags;
  390. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENABLE, "irq=%d\n", irq);
  391. spin_lock_irqsave(&tx4927_pic_lock, flags);
  392. tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq), 0,
  393. tx4927_irq_pic_mask(irq));
  394. spin_unlock_irqrestore(&tx4927_pic_lock, flags);
  395. return;
  396. }
  397. static void tx4927_irq_pic_disable(unsigned int irq)
  398. {
  399. unsigned long flags;
  400. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_DISABLE, "irq=%d\n", irq);
  401. spin_lock_irqsave(&tx4927_pic_lock, flags);
  402. tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq),
  403. tx4927_irq_pic_mask(irq), 0);
  404. spin_unlock_irqrestore(&tx4927_pic_lock, flags);
  405. return;
  406. }
  407. static void tx4927_irq_pic_mask_and_ack(unsigned int irq)
  408. {
  409. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_MASK, "irq=%d\n", irq);
  410. tx4927_irq_pic_disable(irq);
  411. return;
  412. }
  413. static void tx4927_irq_pic_end(unsigned int irq)
  414. {
  415. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENDIRQ, "irq=%d\n", irq);
  416. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  417. tx4927_irq_pic_enable(irq);
  418. }
  419. return;
  420. }
  421. /*
  422. * Main init functions
  423. */
  424. void __init tx4927_irq_init(void)
  425. {
  426. extern asmlinkage void tx4927_irq_handler(void);
  427. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "-\n");
  428. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_cp0_init()\n");
  429. tx4927_irq_cp0_init();
  430. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_pic_init()\n");
  431. tx4927_irq_pic_init();
  432. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT,
  433. "=Calling set_except_vector(tx4927_irq_handler)\n");
  434. set_except_vector(0, tx4927_irq_handler);
  435. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "+\n");
  436. return;
  437. }
  438. int tx4927_irq_nested(void)
  439. {
  440. int sw_irq = 0;
  441. u32 level2;
  442. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "-\n");
  443. level2 = TX4927_RD(0xff1ff6a0);
  444. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=level2a=0x%x\n", level2);
  445. if ((level2 & 0x10000) == 0) {
  446. level2 &= 0x1f;
  447. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=level2b=0x%x\n", level2);
  448. sw_irq = TX4927_IRQ_PIC_BEG + level2;
  449. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=sw_irq=%d\n", sw_irq);
  450. if (sw_irq == 27) {
  451. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq-%d\n",
  452. sw_irq);
  453. #ifdef CONFIG_TOSHIBA_RBTX4927
  454. {
  455. sw_irq = toshiba_rbtx4927_irq_nested(sw_irq);
  456. }
  457. #endif
  458. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq+%d\n",
  459. sw_irq);
  460. }
  461. }
  462. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=sw_irq=%d\n", sw_irq);
  463. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "+\n");
  464. return (sw_irq);
  465. }