Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2004 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
TsiChungLiew | 45a25bf | 2007-07-05 23:27:40 -0500 | [diff] [blame] | 6 | * (C) Copyright 2007 Freescale Semiconductor Inc |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 7 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <watchdog.h> |
| 12 | #include <asm/processor.h> |
TsiChungLiew | 45a25bf | 2007-07-05 23:27:40 -0500 | [diff] [blame] | 13 | #include <asm/immap.h> |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 14 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 15 | #define NR_IRQS (CONFIG_SYS_NUM_IRQS) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 16 | |
| 17 | /* |
| 18 | * Interrupt vector functions. |
| 19 | */ |
| 20 | struct interrupt_action { |
| 21 | interrupt_handler_t *handler; |
| 22 | void *arg; |
| 23 | }; |
| 24 | |
| 25 | static struct interrupt_action irq_vecs[NR_IRQS]; |
| 26 | |
| 27 | static __inline__ unsigned short get_sr (void) |
| 28 | { |
| 29 | unsigned short sr; |
| 30 | |
| 31 | asm volatile ("move.w %%sr,%0":"=r" (sr):); |
| 32 | |
| 33 | return sr; |
| 34 | } |
| 35 | |
| 36 | static __inline__ void set_sr (unsigned short sr) |
| 37 | { |
| 38 | asm volatile ("move.w %0,%%sr"::"r" (sr)); |
| 39 | } |
| 40 | |
| 41 | /************************************************************************/ |
| 42 | /* |
| 43 | * Install and free an interrupt handler |
| 44 | */ |
| 45 | void irq_install_handler (int vec, interrupt_handler_t * handler, void *arg) |
| 46 | { |
Graeme Russ | 626d073 | 2008-12-08 20:04:51 +1100 | [diff] [blame] | 47 | if ((vec < 0) || (vec >= NR_IRQS)) { |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 48 | printf ("irq_install_handler: wrong interrupt vector %d\n", |
| 49 | vec); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | irq_vecs[vec].handler = handler; |
| 54 | irq_vecs[vec].arg = arg; |
| 55 | } |
| 56 | |
| 57 | void irq_free_handler (int vec) |
| 58 | { |
Graeme Russ | 626d073 | 2008-12-08 20:04:51 +1100 | [diff] [blame] | 59 | if ((vec < 0) || (vec >= NR_IRQS)) { |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 60 | return; |
| 61 | } |
| 62 | |
| 63 | irq_vecs[vec].handler = NULL; |
| 64 | irq_vecs[vec].arg = NULL; |
| 65 | } |
| 66 | |
| 67 | void enable_interrupts (void) |
| 68 | { |
| 69 | unsigned short sr; |
| 70 | |
| 71 | sr = get_sr (); |
| 72 | set_sr (sr & ~0x0700); |
| 73 | } |
| 74 | |
| 75 | int disable_interrupts (void) |
| 76 | { |
| 77 | unsigned short sr; |
| 78 | |
| 79 | sr = get_sr (); |
| 80 | set_sr (sr | 0x0700); |
| 81 | |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 82 | return ((sr & 0x0700) == 0); /* return true, if interrupts were enabled before */ |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void int_handler (struct pt_regs *fp) |
| 86 | { |
| 87 | int vec; |
| 88 | |
| 89 | vec = (fp->vector >> 2) & 0xff; |
| 90 | if (vec > 0x40) |
| 91 | vec -= 0x40; |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 92 | |
| 93 | if (irq_vecs[vec].handler != NULL) { |
| 94 | irq_vecs[vec].handler (irq_vecs[vec].arg); |
| 95 | } else { |
| 96 | printf ("\nBogus External Interrupt Vector %d\n", vec); |
| 97 | } |
| 98 | } |