interrupts.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. * Hacked for MPC8260 by Murray.Jensen@cmst.csiro.au, 22-Oct-00
  24. */
  25. #include <common.h>
  26. #include <watchdog.h>
  27. #include <command.h>
  28. #include <mpc8260.h>
  29. #include <mpc8260_irq.h>
  30. #include <asm/processor.h>
  31. #ifdef CONFIG_STATUS_LED
  32. #include <status_led.h>
  33. #endif
  34. /****************************************************************************/
  35. unsigned decrementer_count; /* count val for 1e6/HZ microseconds */
  36. struct irq_action {
  37. interrupt_handler_t *handler;
  38. void *arg;
  39. ulong count;
  40. };
  41. static struct irq_action irq_handlers[NR_IRQS];
  42. static ulong ppc_cached_irq_mask[NR_MASK_WORDS];
  43. /****************************************************************************/
  44. /* this section was ripped out of arch/ppc/kernel/ppc8260_pic.c in the */
  45. /* Linux/PPC 2.4.x source. There was no copyright notice in that file. */
  46. /* The 8260 internal interrupt controller. It is usually
  47. * the only interrupt controller.
  48. * There are two 32-bit registers (high/low) for up to 64
  49. * possible interrupts.
  50. *
  51. * Now, the fun starts.....Interrupt Numbers DO NOT MAP
  52. * in a simple arithmetic fashion to mask or pending registers.
  53. * That is, interrupt 4 does not map to bit position 4.
  54. * We create two tables, indexed by vector number, to indicate
  55. * which register to use and which bit in the register to use.
  56. */
  57. static u_char irq_to_siureg[] = {
  58. 1, 1, 1, 1, 1, 1, 1, 1,
  59. 1, 1, 1, 1, 1, 1, 1, 1,
  60. 0, 0, 0, 0, 0, 0, 0, 0,
  61. 0, 0, 0, 0, 0, 0, 0, 0,
  62. 1, 1, 1, 1, 1, 1, 1, 1,
  63. 1, 1, 1, 1, 1, 1, 1, 1,
  64. 0, 0, 0, 0, 0, 0, 0, 0,
  65. 0, 0, 0, 0, 0, 0, 0, 0
  66. };
  67. static u_char irq_to_siubit[] = {
  68. 31, 16, 17, 18, 19, 20, 21, 22,
  69. 23, 24, 25, 26, 27, 28, 29, 30,
  70. 29, 30, 16, 17, 18, 19, 20, 21,
  71. 22, 23, 24, 25, 26, 27, 28, 31,
  72. 0, 1, 2, 3, 4, 5, 6, 7,
  73. 8, 9, 10, 11, 12, 13, 14, 15,
  74. 15, 14, 13, 12, 11, 10, 9, 8,
  75. 7, 6, 5, 4, 3, 2, 1, 0
  76. };
  77. static void m8260_mask_irq (unsigned int irq_nr)
  78. {
  79. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  80. int bit, word;
  81. volatile uint *simr;
  82. bit = irq_to_siubit[irq_nr];
  83. word = irq_to_siureg[irq_nr];
  84. simr = &(immr->im_intctl.ic_simrh);
  85. ppc_cached_irq_mask[word] &= ~(1 << (31 - bit));
  86. simr[word] = ppc_cached_irq_mask[word];
  87. }
  88. static void m8260_unmask_irq (unsigned int irq_nr)
  89. {
  90. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  91. int bit, word;
  92. volatile uint *simr;
  93. bit = irq_to_siubit[irq_nr];
  94. word = irq_to_siureg[irq_nr];
  95. simr = &(immr->im_intctl.ic_simrh);
  96. ppc_cached_irq_mask[word] |= (1 << (31 - bit));
  97. simr[word] = ppc_cached_irq_mask[word];
  98. }
  99. static void m8260_mask_and_ack (unsigned int irq_nr)
  100. {
  101. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  102. int bit, word;
  103. volatile uint *simr, *sipnr;
  104. bit = irq_to_siubit[irq_nr];
  105. word = irq_to_siureg[irq_nr];
  106. simr = &(immr->im_intctl.ic_simrh);
  107. sipnr = &(immr->im_intctl.ic_sipnrh);
  108. ppc_cached_irq_mask[word] &= ~(1 << (31 - bit));
  109. simr[word] = ppc_cached_irq_mask[word];
  110. sipnr[word] = 1 << (31 - bit);
  111. }
  112. static int m8260_get_irq (struct pt_regs *regs)
  113. {
  114. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  115. int irq;
  116. unsigned long bits;
  117. /* For MPC8260, read the SIVEC register and shift the bits down
  118. * to get the irq number. */
  119. bits = immr->im_intctl.ic_sivec;
  120. irq = bits >> 26;
  121. return irq;
  122. }
  123. /* end of code ripped out of arch/ppc/kernel/ppc8260_pic.c */
  124. /****************************************************************************/
  125. static __inline__ unsigned long get_msr (void)
  126. {
  127. unsigned long msr;
  128. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  129. return msr;
  130. }
  131. static __inline__ void set_msr (unsigned long msr)
  132. {
  133. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  134. }
  135. static __inline__ unsigned long get_dec (void)
  136. {
  137. unsigned long val;
  138. __asm__ __volatile__ ("mfdec %0":"=r" (val):);
  139. return val;
  140. }
  141. static __inline__ void set_dec (unsigned long val)
  142. {
  143. __asm__ __volatile__ ("mtdec %0"::"r" (val));
  144. }
  145. void enable_interrupts (void)
  146. {
  147. set_msr (get_msr () | MSR_EE);
  148. }
  149. /* returns flag if MSR_EE was set before */
  150. int disable_interrupts (void)
  151. {
  152. ulong msr = get_msr ();
  153. set_msr (msr & ~MSR_EE);
  154. return ((msr & MSR_EE) != 0);
  155. }
  156. /****************************************************************************/
  157. int interrupt_init (void)
  158. {
  159. DECLARE_GLOBAL_DATA_PTR;
  160. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  161. decrementer_count = (gd->bus_clk / 4) / CFG_HZ;
  162. /* Initialize the default interrupt mapping priorities */
  163. immr->im_intctl.ic_sicr = 0;
  164. immr->im_intctl.ic_siprr = 0x05309770;
  165. immr->im_intctl.ic_scprrh = 0x05309770;
  166. immr->im_intctl.ic_scprrl = 0x05309770;
  167. /* disable all interrupts and clear all pending bits */
  168. immr->im_intctl.ic_simrh = ppc_cached_irq_mask[0] = 0;
  169. immr->im_intctl.ic_simrl = ppc_cached_irq_mask[1] = 0;
  170. immr->im_intctl.ic_sipnrh = 0xffffffff;
  171. immr->im_intctl.ic_sipnrl = 0xffffffff;
  172. set_dec (decrementer_count);
  173. set_msr (get_msr () | MSR_EE);
  174. return (0);
  175. }
  176. /****************************************************************************/
  177. /*
  178. * Handle external interrupts
  179. */
  180. void external_interrupt (struct pt_regs *regs)
  181. {
  182. int irq, unmask = 1;
  183. irq = m8260_get_irq (regs);
  184. m8260_mask_and_ack (irq);
  185. set_msr (get_msr () | MSR_EE);
  186. if (irq_handlers[irq].handler != NULL)
  187. (*irq_handlers[irq].handler) (irq_handlers[irq].arg);
  188. else {
  189. printf ("\nBogus External Interrupt IRQ %d\n", irq);
  190. /*
  191. * turn off the bogus interrupt, otherwise it
  192. * might repeat forever
  193. */
  194. unmask = 0;
  195. }
  196. if (unmask)
  197. m8260_unmask_irq (irq);
  198. }
  199. /****************************************************************************/
  200. /*
  201. * Install and free an interrupt handler.
  202. */
  203. void
  204. irq_install_handler (int irq, interrupt_handler_t * handler, void *arg)
  205. {
  206. if (irq < 0 || irq >= NR_IRQS) {
  207. printf ("irq_install_handler: bad irq number %d\n", irq);
  208. return;
  209. }
  210. if (irq_handlers[irq].handler != NULL)
  211. printf ("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
  212. (ulong) handler, (ulong) irq_handlers[irq].handler);
  213. irq_handlers[irq].handler = handler;
  214. irq_handlers[irq].arg = arg;
  215. m8260_unmask_irq (irq);
  216. }
  217. void irq_free_handler (int irq)
  218. {
  219. if (irq < 0 || irq >= NR_IRQS) {
  220. printf ("irq_free_handler: bad irq number %d\n", irq);
  221. return;
  222. }
  223. m8260_mask_irq (irq);
  224. irq_handlers[irq].handler = NULL;
  225. irq_handlers[irq].arg = NULL;
  226. }
  227. /****************************************************************************/
  228. volatile ulong timestamp = 0;
  229. /*
  230. * timer_interrupt - gets called when the decrementer overflows,
  231. * with interrupts disabled.
  232. * Trivial implementation - no need to be really accurate.
  233. */
  234. void timer_interrupt (struct pt_regs *regs)
  235. {
  236. #if defined(CONFIG_WATCHDOG) || defined(CFG_HYMOD_DBLEDS)
  237. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  238. #endif /* CONFIG_WATCHDOG */
  239. /* Restore Decrementer Count */
  240. set_dec (decrementer_count);
  241. timestamp++;
  242. #if defined(CONFIG_WATCHDOG) || \
  243. defined(CFG_CMA_LCD_HEARTBEAT) || \
  244. defined(CFG_HYMOD_DBLEDS)
  245. if ((timestamp % CFG_HZ) == 0) {
  246. #if defined(CFG_CMA_LCD_HEARTBEAT)
  247. extern void lcd_heartbeat (void);
  248. #endif /* CFG_CMA_LCD_HEARTBEAT */
  249. #if defined(CFG_HYMOD_DBLEDS)
  250. volatile iop8260_t *iop = &immr->im_ioport;
  251. static int shift = 0;
  252. #endif /* CFG_HYMOD_DBLEDS */
  253. #if defined(CFG_CMA_LCD_HEARTBEAT)
  254. lcd_heartbeat ();
  255. #endif /* CFG_CMA_LCD_HEARTBEAT */
  256. #if defined(CONFIG_WATCHDOG)
  257. reset_8260_watchdog (immr);
  258. #endif /* CONFIG_WATCHDOG */
  259. #if defined(CFG_HYMOD_DBLEDS)
  260. /* hymod daughter board LEDs */
  261. if (++shift > 3)
  262. shift = 0;
  263. iop->iop_pdatd =
  264. (iop->iop_pdatd & ~0x0f000000) | (1 << (24 + shift));
  265. #endif /* CFG_HYMOD_DBLEDS */
  266. }
  267. #endif /* CONFIG_WATCHDOG || CFG_CMA_LCD_HEARTBEAT */
  268. #ifdef CONFIG_STATUS_LED
  269. status_led_tick (timestamp);
  270. #endif /* CONFIG_STATUS_LED */
  271. }
  272. /****************************************************************************/
  273. void reset_timer (void)
  274. {
  275. timestamp = 0;
  276. }
  277. ulong get_timer (ulong base)
  278. {
  279. return (timestamp - base);
  280. }
  281. void set_timer (ulong t)
  282. {
  283. timestamp = t;
  284. }
  285. /****************************************************************************/
  286. #if (CONFIG_COMMANDS & CFG_CMD_IRQ)
  287. /* ripped this out of ppc4xx/interrupts.c */
  288. /*******************************************************************************
  289. *
  290. * irqinfo - print information about PCI devices
  291. *
  292. */
  293. void
  294. do_irqinfo (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  295. {
  296. int irq, re_enable;
  297. re_enable = disable_interrupts ();
  298. printf ("\nInterrupt-Information:\n");
  299. printf ("Nr Routine Arg Count\n");
  300. for (irq = 0; irq < 32; irq++)
  301. if (irq_handlers[irq].handler != NULL)
  302. printf ("%02d %08lx %08lx %ld\n", irq,
  303. (ulong) irq_handlers[irq].handler,
  304. (ulong) irq_handlers[irq].arg,
  305. irq_handlers[irq].count);
  306. if (re_enable)
  307. enable_interrupts ();
  308. }
  309. #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */