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