tx4927_irq.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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_PIC_INIT ( 1 << 20 )
  64. #define TX4927_IRQ_PIC_ENABLE ( 1 << 23 )
  65. #define TX4927_IRQ_PIC_DISABLE ( 1 << 24 )
  66. #define TX4927_IRQ_ALL 0xffffffff
  67. #endif
  68. #ifdef TX4927_IRQ_DEBUG
  69. static const u32 tx4927_irq_debug_flag = (TX4927_IRQ_NONE
  70. | TX4927_IRQ_INFO
  71. | TX4927_IRQ_WARN | TX4927_IRQ_EROR
  72. // | TX4927_IRQ_CP0_INIT
  73. // | TX4927_IRQ_CP0_ENABLE
  74. // | TX4927_IRQ_CP0_ENDIRQ
  75. // | TX4927_IRQ_PIC_INIT
  76. // | TX4927_IRQ_PIC_ENABLE
  77. // | TX4927_IRQ_PIC_DISABLE
  78. // | TX4927_IRQ_INIT
  79. // | TX4927_IRQ_NEST1
  80. // | TX4927_IRQ_NEST2
  81. // | TX4927_IRQ_NEST3
  82. // | TX4927_IRQ_NEST4
  83. );
  84. #endif
  85. #ifdef TX4927_IRQ_DEBUG
  86. #define TX4927_IRQ_DPRINTK(flag,str...) \
  87. if ( (tx4927_irq_debug_flag) & (flag) ) \
  88. { \
  89. char tmp[100]; \
  90. sprintf( tmp, str ); \
  91. printk( "%s(%s:%u)::%s", __FUNCTION__, __FILE__, __LINE__, tmp ); \
  92. }
  93. #else
  94. #define TX4927_IRQ_DPRINTK(flag,str...)
  95. #endif
  96. /*
  97. * Forwad definitions for all pic's
  98. */
  99. static void tx4927_irq_cp0_enable(unsigned int irq);
  100. static void tx4927_irq_cp0_disable(unsigned int irq);
  101. static void tx4927_irq_pic_enable(unsigned int irq);
  102. static void tx4927_irq_pic_disable(unsigned int irq);
  103. /*
  104. * Kernel structs for all pic's
  105. */
  106. #define TX4927_CP0_NAME "TX4927-CP0"
  107. static struct irq_chip tx4927_irq_cp0_type = {
  108. .name = TX4927_CP0_NAME,
  109. .ack = tx4927_irq_cp0_disable,
  110. .mask = tx4927_irq_cp0_disable,
  111. .mask_ack = tx4927_irq_cp0_disable,
  112. .unmask = tx4927_irq_cp0_enable,
  113. };
  114. #define TX4927_PIC_NAME "TX4927-PIC"
  115. static struct irq_chip tx4927_irq_pic_type = {
  116. .name = TX4927_PIC_NAME,
  117. .ack = tx4927_irq_pic_disable,
  118. .mask = tx4927_irq_pic_disable,
  119. .mask_ack = tx4927_irq_pic_disable,
  120. .unmask = tx4927_irq_pic_enable,
  121. };
  122. #define TX4927_PIC_ACTION(s) { no_action, 0, CPU_MASK_NONE, s, NULL, NULL }
  123. static struct irqaction tx4927_irq_pic_action =
  124. TX4927_PIC_ACTION(TX4927_PIC_NAME);
  125. #define CCP0_STATUS 12
  126. #define CCP0_CAUSE 13
  127. /*
  128. * Functions for cp0
  129. */
  130. #define tx4927_irq_cp0_mask(irq) ( 1 << ( irq-TX4927_IRQ_CP0_BEG+8 ) )
  131. static void
  132. tx4927_irq_cp0_modify(unsigned cp0_reg, unsigned clr_bits, unsigned set_bits)
  133. {
  134. unsigned long val = 0;
  135. switch (cp0_reg) {
  136. case CCP0_STATUS:
  137. val = read_c0_status();
  138. break;
  139. case CCP0_CAUSE:
  140. val = read_c0_cause();
  141. break;
  142. }
  143. val &= (~clr_bits);
  144. val |= (set_bits);
  145. switch (cp0_reg) {
  146. case CCP0_STATUS:{
  147. write_c0_status(val);
  148. break;
  149. }
  150. case CCP0_CAUSE:{
  151. write_c0_cause(val);
  152. break;
  153. }
  154. }
  155. }
  156. static void __init tx4927_irq_cp0_init(void)
  157. {
  158. int i;
  159. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_INIT, "beg=%d end=%d\n",
  160. TX4927_IRQ_CP0_BEG, TX4927_IRQ_CP0_END);
  161. for (i = TX4927_IRQ_CP0_BEG; i <= TX4927_IRQ_CP0_END; i++)
  162. set_irq_chip_and_handler(i, &tx4927_irq_cp0_type,
  163. handle_level_irq);
  164. }
  165. static void tx4927_irq_cp0_enable(unsigned int irq)
  166. {
  167. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENABLE, "irq=%d \n", irq);
  168. tx4927_irq_cp0_modify(CCP0_STATUS, 0, tx4927_irq_cp0_mask(irq));
  169. }
  170. static void tx4927_irq_cp0_disable(unsigned int irq)
  171. {
  172. TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_DISABLE, "irq=%d \n", irq);
  173. tx4927_irq_cp0_modify(CCP0_STATUS, tx4927_irq_cp0_mask(irq), 0);
  174. }
  175. /*
  176. * Functions for pic
  177. */
  178. u32 tx4927_irq_pic_addr(int irq)
  179. {
  180. /* MVMCP -- need to formulize this */
  181. irq -= TX4927_IRQ_PIC_BEG;
  182. switch (irq) {
  183. case 17:
  184. case 16:
  185. case 1:
  186. case 0:
  187. return (0xff1ff610);
  188. case 19:
  189. case 18:
  190. case 3:
  191. case 2:
  192. return (0xff1ff614);
  193. case 21:
  194. case 20:
  195. case 5:
  196. case 4:
  197. return (0xff1ff618);
  198. case 23:
  199. case 22:
  200. case 7:
  201. case 6:
  202. return (0xff1ff61c);
  203. case 25:
  204. case 24:
  205. case 9:
  206. case 8:
  207. return (0xff1ff620);
  208. case 27:
  209. case 26:
  210. case 11:
  211. case 10:
  212. return (0xff1ff624);
  213. case 29:
  214. case 28:
  215. case 13:
  216. case 12:
  217. return (0xff1ff628);
  218. case 31:
  219. case 30:
  220. case 15:
  221. case 14:
  222. return (0xff1ff62c);
  223. }
  224. return (0);
  225. }
  226. u32 tx4927_irq_pic_mask(int irq)
  227. {
  228. /* MVMCP -- need to formulize this */
  229. irq -= TX4927_IRQ_PIC_BEG;
  230. switch (irq) {
  231. case 31:
  232. case 29:
  233. case 27:
  234. case 25:
  235. case 23:
  236. case 21:
  237. case 19:
  238. case 17:{
  239. return (0x07000000);
  240. }
  241. case 30:
  242. case 28:
  243. case 26:
  244. case 24:
  245. case 22:
  246. case 20:
  247. case 18:
  248. case 16:{
  249. return (0x00070000);
  250. }
  251. case 15:
  252. case 13:
  253. case 11:
  254. case 9:
  255. case 7:
  256. case 5:
  257. case 3:
  258. case 1:{
  259. return (0x00000700);
  260. }
  261. case 14:
  262. case 12:
  263. case 10:
  264. case 8:
  265. case 6:
  266. case 4:
  267. case 2:
  268. case 0:{
  269. return (0x00000007);
  270. }
  271. }
  272. return (0x00000000);
  273. }
  274. static void tx4927_irq_pic_modify(unsigned pic_reg, unsigned clr_bits,
  275. unsigned set_bits)
  276. {
  277. unsigned long val = 0;
  278. val = TX4927_RD(pic_reg);
  279. val &= (~clr_bits);
  280. val |= (set_bits);
  281. TX4927_WR(pic_reg, val);
  282. }
  283. static void __init tx4927_irq_pic_init(void)
  284. {
  285. int i;
  286. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_INIT, "beg=%d end=%d\n",
  287. TX4927_IRQ_PIC_BEG, TX4927_IRQ_PIC_END);
  288. for (i = TX4927_IRQ_PIC_BEG; i <= TX4927_IRQ_PIC_END; i++)
  289. set_irq_chip_and_handler(i, &tx4927_irq_pic_type,
  290. handle_level_irq);
  291. setup_irq(TX4927_IRQ_NEST_PIC_ON_CP0, &tx4927_irq_pic_action);
  292. TX4927_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
  293. TX4927_WR(0xff1ff600, TX4927_RD(0xff1ff600) | 0x1); /* irq enable */
  294. }
  295. static void tx4927_irq_pic_enable(unsigned int irq)
  296. {
  297. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENABLE, "irq=%d\n", irq);
  298. tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq), 0,
  299. tx4927_irq_pic_mask(irq));
  300. }
  301. static void tx4927_irq_pic_disable(unsigned int irq)
  302. {
  303. TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_DISABLE, "irq=%d\n", irq);
  304. tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq),
  305. tx4927_irq_pic_mask(irq), 0);
  306. }
  307. /*
  308. * Main init functions
  309. */
  310. void __init tx4927_irq_init(void)
  311. {
  312. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "-\n");
  313. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_cp0_init()\n");
  314. tx4927_irq_cp0_init();
  315. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_pic_init()\n");
  316. tx4927_irq_pic_init();
  317. TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "+\n");
  318. }
  319. static int tx4927_irq_nested(void)
  320. {
  321. int sw_irq = 0;
  322. u32 level2;
  323. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "-\n");
  324. level2 = TX4927_RD(0xff1ff6a0);
  325. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=level2a=0x%x\n", level2);
  326. if ((level2 & 0x10000) == 0) {
  327. level2 &= 0x1f;
  328. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=level2b=0x%x\n", level2);
  329. sw_irq = TX4927_IRQ_PIC_BEG + level2;
  330. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=sw_irq=%d\n", sw_irq);
  331. if (sw_irq == 27) {
  332. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq-%d\n",
  333. sw_irq);
  334. #ifdef CONFIG_TOSHIBA_RBTX4927
  335. {
  336. sw_irq = toshiba_rbtx4927_irq_nested(sw_irq);
  337. }
  338. #endif
  339. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq+%d\n",
  340. sw_irq);
  341. }
  342. }
  343. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=sw_irq=%d\n", sw_irq);
  344. TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "+\n");
  345. return (sw_irq);
  346. }
  347. asmlinkage void plat_irq_dispatch(void)
  348. {
  349. unsigned int pending = read_c0_status() & read_c0_cause();
  350. if (pending & STATUSF_IP7) /* cpu timer */
  351. do_IRQ(TX4927_IRQ_CPU_TIMER);
  352. else if (pending & STATUSF_IP2) { /* tx4927 pic */
  353. unsigned int irq = tx4927_irq_nested();
  354. if (unlikely(irq == 0)) {
  355. spurious_interrupt();
  356. return;
  357. }
  358. do_IRQ(irq);
  359. } else if (pending & STATUSF_IP0) /* user line 0 */
  360. do_IRQ(TX4927_IRQ_USER0);
  361. else if (pending & STATUSF_IP1) /* user line 1 */
  362. do_IRQ(TX4927_IRQ_USER1);
  363. else
  364. spurious_interrupt();
  365. }