irq.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * ITE 8172G interrupt/setup routines.
  4. *
  5. * Copyright 2000,2001 MontaVista Software Inc.
  6. * Author: MontaVista Software, Inc.
  7. * ppopov@mvista.com or source@mvista.com
  8. *
  9. * Part of this file was derived from Carsten Langgaard's
  10. * arch/mips/mips-boards/atlas/atlas_int.c.
  11. *
  12. * Carsten Langgaard, carstenl@mips.com
  13. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License as published by the
  17. * Free Software Foundation; either version 2 of the License, or (at your
  18. * option) any later version.
  19. *
  20. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  21. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  23. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  26. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  27. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  29. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * You should have received a copy of the GNU General Public License along
  32. * with this program; if not, write to the Free Software Foundation, Inc.,
  33. * 675 Mass Ave, Cambridge, MA 02139, USA.
  34. */
  35. #include <linux/errno.h>
  36. #include <linux/init.h>
  37. #include <linux/irq.h>
  38. #include <linux/kernel_stat.h>
  39. #include <linux/module.h>
  40. #include <linux/signal.h>
  41. #include <linux/sched.h>
  42. #include <linux/types.h>
  43. #include <linux/interrupt.h>
  44. #include <linux/ioport.h>
  45. #include <linux/timex.h>
  46. #include <linux/slab.h>
  47. #include <linux/random.h>
  48. #include <linux/serial_reg.h>
  49. #include <linux/bitops.h>
  50. #include <asm/bootinfo.h>
  51. #include <asm/io.h>
  52. #include <asm/mipsregs.h>
  53. #include <asm/system.h>
  54. #include <asm/it8172/it8172.h>
  55. #include <asm/it8172/it8172_int.h>
  56. #include <asm/it8172/it8172_dbg.h>
  57. /* revisit */
  58. #define EXT_IRQ0_TO_IP 2 /* IP 2 */
  59. #define EXT_IRQ5_TO_IP 7 /* IP 7 */
  60. #define ALLINTS_NOTIMER (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4)
  61. extern void set_debug_traps(void);
  62. extern void mips_timer_interrupt(int irq, struct pt_regs *regs);
  63. struct it8172_intc_regs volatile *it8172_hw0_icregs =
  64. (struct it8172_intc_regs volatile *)(KSEG1ADDR(IT8172_PCI_IO_BASE + IT_INTC_BASE));
  65. static void disable_it8172_irq(unsigned int irq_nr)
  66. {
  67. if ( (irq_nr >= IT8172_LPC_IRQ_BASE) && (irq_nr <= IT8172_SERIRQ_15)) {
  68. /* LPC interrupt */
  69. it8172_hw0_icregs->lpc_mask |=
  70. (1 << (irq_nr - IT8172_LPC_IRQ_BASE));
  71. } else if ( (irq_nr >= IT8172_LB_IRQ_BASE) && (irq_nr <= IT8172_IOCHK_IRQ)) {
  72. /* Local Bus interrupt */
  73. it8172_hw0_icregs->lb_mask |=
  74. (1 << (irq_nr - IT8172_LB_IRQ_BASE));
  75. } else if ( (irq_nr >= IT8172_PCI_DEV_IRQ_BASE) && (irq_nr <= IT8172_DMA_IRQ)) {
  76. /* PCI and other interrupts */
  77. it8172_hw0_icregs->pci_mask |=
  78. (1 << (irq_nr - IT8172_PCI_DEV_IRQ_BASE));
  79. } else if ( (irq_nr >= IT8172_NMI_IRQ_BASE) && (irq_nr <= IT8172_POWER_NMI_IRQ)) {
  80. /* NMI interrupts */
  81. it8172_hw0_icregs->nmi_mask |=
  82. (1 << (irq_nr - IT8172_NMI_IRQ_BASE));
  83. } else {
  84. panic("disable_it8172_irq: bad irq %d", irq_nr);
  85. }
  86. }
  87. static void enable_it8172_irq(unsigned int irq_nr)
  88. {
  89. if ( (irq_nr >= IT8172_LPC_IRQ_BASE) && (irq_nr <= IT8172_SERIRQ_15)) {
  90. /* LPC interrupt */
  91. it8172_hw0_icregs->lpc_mask &=
  92. ~(1 << (irq_nr - IT8172_LPC_IRQ_BASE));
  93. }
  94. else if ( (irq_nr >= IT8172_LB_IRQ_BASE) && (irq_nr <= IT8172_IOCHK_IRQ)) {
  95. /* Local Bus interrupt */
  96. it8172_hw0_icregs->lb_mask &=
  97. ~(1 << (irq_nr - IT8172_LB_IRQ_BASE));
  98. }
  99. else if ( (irq_nr >= IT8172_PCI_DEV_IRQ_BASE) && (irq_nr <= IT8172_DMA_IRQ)) {
  100. /* PCI and other interrupts */
  101. it8172_hw0_icregs->pci_mask &=
  102. ~(1 << (irq_nr - IT8172_PCI_DEV_IRQ_BASE));
  103. }
  104. else if ( (irq_nr >= IT8172_NMI_IRQ_BASE) && (irq_nr <= IT8172_POWER_NMI_IRQ)) {
  105. /* NMI interrupts */
  106. it8172_hw0_icregs->nmi_mask &=
  107. ~(1 << (irq_nr - IT8172_NMI_IRQ_BASE));
  108. }
  109. else {
  110. panic("enable_it8172_irq: bad irq %d", irq_nr);
  111. }
  112. }
  113. static unsigned int startup_ite_irq(unsigned int irq)
  114. {
  115. enable_it8172_irq(irq);
  116. return 0;
  117. }
  118. #define shutdown_ite_irq disable_it8172_irq
  119. #define mask_and_ack_ite_irq disable_it8172_irq
  120. static void end_ite_irq(unsigned int irq)
  121. {
  122. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  123. enable_it8172_irq(irq);
  124. }
  125. static struct hw_interrupt_type it8172_irq_type = {
  126. .typename = "ITE8172",
  127. .startup = startup_ite_irq,
  128. .shutdown = shutdown_ite_irq,
  129. .enable = enable_it8172_irq,
  130. .disable = disable_it8172_irq,
  131. .ack = mask_and_ack_ite_irq,
  132. .end = end_ite_irq,
  133. };
  134. static void enable_none(unsigned int irq) { }
  135. static unsigned int startup_none(unsigned int irq) { return 0; }
  136. static void disable_none(unsigned int irq) { }
  137. static void ack_none(unsigned int irq) { }
  138. /* startup is the same as "enable", shutdown is same as "disable" */
  139. #define shutdown_none disable_none
  140. #define end_none enable_none
  141. static struct hw_interrupt_type cp0_irq_type = {
  142. .typename = "CP0 Count",
  143. .startup = startup_none,
  144. .shutdown = shutdown_none,
  145. .enable = enable_none,
  146. .disable = disable_none,
  147. .ack = ack_none,
  148. .end = end_none
  149. };
  150. void enable_cpu_timer(void)
  151. {
  152. unsigned long flags;
  153. local_irq_save(flags);
  154. set_c0_status(0x100 << EXT_IRQ5_TO_IP);
  155. local_irq_restore(flags);
  156. }
  157. void __init arch_init_irq(void)
  158. {
  159. int i;
  160. unsigned long flags;
  161. /* mask all interrupts */
  162. it8172_hw0_icregs->lb_mask = 0xffff;
  163. it8172_hw0_icregs->lpc_mask = 0xffff;
  164. it8172_hw0_icregs->pci_mask = 0xffff;
  165. it8172_hw0_icregs->nmi_mask = 0xffff;
  166. /* make all interrupts level triggered */
  167. it8172_hw0_icregs->lb_trigger = 0;
  168. it8172_hw0_icregs->lpc_trigger = 0;
  169. it8172_hw0_icregs->pci_trigger = 0;
  170. it8172_hw0_icregs->nmi_trigger = 0;
  171. /* active level setting */
  172. /* uart, keyboard, and mouse are active high */
  173. it8172_hw0_icregs->lpc_level = (0x10 | 0x2 | 0x1000);
  174. it8172_hw0_icregs->lb_level |= 0x20;
  175. /* keyboard and mouse are edge triggered */
  176. it8172_hw0_icregs->lpc_trigger |= (0x2 | 0x1000);
  177. #if 0
  178. // Enable this piece of code to make internal USB interrupt
  179. // edge triggered.
  180. it8172_hw0_icregs->pci_trigger |=
  181. (1 << (IT8172_USB_IRQ - IT8172_PCI_DEV_IRQ_BASE));
  182. it8172_hw0_icregs->pci_level &=
  183. ~(1 << (IT8172_USB_IRQ - IT8172_PCI_DEV_IRQ_BASE));
  184. #endif
  185. for (i = 0; i <= IT8172_LAST_IRQ; i++) {
  186. irq_desc[i].handler = &it8172_irq_type;
  187. spin_lock_init(&irq_desc[i].lock);
  188. }
  189. irq_desc[MIPS_CPU_TIMER_IRQ].handler = &cp0_irq_type;
  190. set_c0_status(ALLINTS_NOTIMER);
  191. }
  192. void mips_spurious_interrupt(struct pt_regs *regs)
  193. {
  194. #if 1
  195. return;
  196. #else
  197. unsigned long status, cause;
  198. printk("got spurious interrupt\n");
  199. status = read_c0_status();
  200. cause = read_c0_cause();
  201. printk("status %x cause %x\n", status, cause);
  202. printk("epc %x badvaddr %x \n", regs->cp0_epc, regs->cp0_badvaddr);
  203. #endif
  204. }
  205. void it8172_hw0_irqdispatch(struct pt_regs *regs)
  206. {
  207. int irq;
  208. unsigned short intstatus = 0, status = 0;
  209. intstatus = it8172_hw0_icregs->intstatus;
  210. if (intstatus & 0x8) {
  211. panic("Got NMI interrupt");
  212. } else if (intstatus & 0x4) {
  213. /* PCI interrupt */
  214. irq = 0;
  215. status |= it8172_hw0_icregs->pci_req;
  216. while (!(status & 0x1)) {
  217. irq++;
  218. status >>= 1;
  219. }
  220. irq += IT8172_PCI_DEV_IRQ_BASE;
  221. } else if (intstatus & 0x1) {
  222. /* Local Bus interrupt */
  223. irq = 0;
  224. status |= it8172_hw0_icregs->lb_req;
  225. while (!(status & 0x1)) {
  226. irq++;
  227. status >>= 1;
  228. }
  229. irq += IT8172_LB_IRQ_BASE;
  230. } else if (intstatus & 0x2) {
  231. /* LPC interrupt */
  232. /* Since some lpc interrupts are edge triggered,
  233. * we could lose an interrupt this way because
  234. * we acknowledge all ints at onces. Revisit.
  235. */
  236. status |= it8172_hw0_icregs->lpc_req;
  237. it8172_hw0_icregs->lpc_req = 0; /* acknowledge ints */
  238. irq = 0;
  239. while (!(status & 0x1)) {
  240. irq++;
  241. status >>= 1;
  242. }
  243. irq += IT8172_LPC_IRQ_BASE;
  244. } else
  245. return;
  246. do_IRQ(irq, regs);
  247. }
  248. asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
  249. {
  250. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  251. if (!pending)
  252. mips_spurious_interrupt(regs);
  253. else if (pending & CAUSEF_IP7)
  254. ll_timer_interrupt(127, regs);
  255. else if (pending & CAUSEF_IP2)
  256. it8172_hw0_irqdispatch(regs);
  257. }
  258. void show_pending_irqs(void)
  259. {
  260. fputs("intstatus: ");
  261. put32(it8172_hw0_icregs->intstatus);
  262. puts("");
  263. fputs("pci_req: ");
  264. put32(it8172_hw0_icregs->pci_req);
  265. puts("");
  266. fputs("lb_req: ");
  267. put32(it8172_hw0_icregs->lb_req);
  268. puts("");
  269. fputs("lpc_req: ");
  270. put32(it8172_hw0_icregs->lpc_req);
  271. puts("");
  272. }