wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 Josef Baumgartner <josef.baumgartner@telex.de> |
| 3 | * |
| 4 | * (C) Copyright 2000-2004 |
| 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <watchdog.h> |
| 28 | #include <asm/processor.h> |
| 29 | |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 30 | #ifdef CONFIG_M5271 |
| 31 | #include <asm/m5271.h> |
| 32 | #include <asm/immap_5271.h> |
| 33 | #endif |
| 34 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 35 | #ifdef CONFIG_M5272 |
| 36 | #include <asm/m5272.h> |
| 37 | #include <asm/immap_5272.h> |
| 38 | #endif |
| 39 | |
| 40 | #ifdef CONFIG_M5282 |
| 41 | #include <asm/m5282.h> |
| 42 | #include <asm/immap_5282.h> |
| 43 | #endif |
| 44 | |
stroese | 8c725b9 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 45 | #ifdef CONFIG_M5249 |
| 46 | #include <asm/m5249.h> |
| 47 | #endif |
| 48 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 49 | |
| 50 | #define NR_IRQS 31 |
| 51 | |
| 52 | /* |
| 53 | * Interrupt vector functions. |
| 54 | */ |
| 55 | struct interrupt_action { |
| 56 | interrupt_handler_t *handler; |
| 57 | void *arg; |
wdenk | b2daeb8 | 2004-02-12 14:09:38 +0000 | [diff] [blame] | 58 | }; |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 59 | |
| 60 | static struct interrupt_action irq_vecs[NR_IRQS]; |
| 61 | |
| 62 | static __inline__ unsigned short get_sr (void) |
| 63 | { |
| 64 | unsigned short sr; |
| 65 | |
| 66 | asm volatile ("move.w %%sr,%0":"=r" (sr):); |
| 67 | |
| 68 | return sr; |
| 69 | } |
| 70 | |
| 71 | static __inline__ void set_sr (unsigned short sr) |
| 72 | { |
| 73 | asm volatile ("move.w %0,%%sr"::"r" (sr)); |
| 74 | } |
| 75 | |
| 76 | /************************************************************************/ |
| 77 | /* |
| 78 | * Install and free an interrupt handler |
| 79 | */ |
| 80 | void irq_install_handler (int vec, interrupt_handler_t * handler, void *arg) |
| 81 | { |
| 82 | #ifdef CONFIG_M5272 |
| 83 | volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1); |
| 84 | #endif |
| 85 | int vec_base = 0; |
| 86 | |
| 87 | #ifdef CONFIG_M5272 |
| 88 | vec_base = intp->int_pivr & 0xe0; |
| 89 | #endif |
| 90 | |
| 91 | if ((vec < vec_base) || (vec > vec_base + NR_IRQS)) { |
| 92 | printf ("irq_install_handler: wrong interrupt vector %d\n", |
| 93 | vec); |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | irq_vecs[vec - vec_base].handler = handler; |
| 98 | irq_vecs[vec - vec_base].arg = arg; |
| 99 | } |
| 100 | |
| 101 | void irq_free_handler (int vec) |
| 102 | { |
| 103 | #ifdef CONFIG_M5272 |
| 104 | volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1); |
| 105 | #endif |
| 106 | int vec_base = 0; |
| 107 | |
| 108 | #ifdef CONFIG_M5272 |
| 109 | vec_base = intp->int_pivr & 0xe0; |
| 110 | #endif |
| 111 | |
| 112 | if ((vec < vec_base) || (vec > vec_base + NR_IRQS)) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | irq_vecs[vec - vec_base].handler = NULL; |
| 117 | irq_vecs[vec - vec_base].arg = NULL; |
| 118 | } |
| 119 | |
| 120 | void enable_interrupts (void) |
| 121 | { |
| 122 | unsigned short sr; |
| 123 | |
| 124 | sr = get_sr (); |
| 125 | set_sr (sr & ~0x0700); |
| 126 | } |
| 127 | |
| 128 | int disable_interrupts (void) |
| 129 | { |
| 130 | unsigned short sr; |
| 131 | |
| 132 | sr = get_sr (); |
| 133 | set_sr (sr | 0x0700); |
| 134 | |
| 135 | return ((sr & 0x0700) == 0); /* return TRUE, if interrupts were enabled before */ |
| 136 | } |
| 137 | |
| 138 | void int_handler (struct pt_regs *fp) |
| 139 | { |
| 140 | #ifdef CONFIG_M5272 |
| 141 | volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1); |
| 142 | #endif |
| 143 | int vec, vec_base = 0; |
| 144 | |
| 145 | vec = (fp->vector >> 2) & 0xff; |
| 146 | #ifdef CONFIG_M5272 |
| 147 | vec_base = intp->int_pivr & 0xe0; |
| 148 | #endif |
| 149 | |
| 150 | if (irq_vecs[vec - vec_base].handler != NULL) { |
| 151 | irq_vecs[vec - |
| 152 | vec_base].handler (irq_vecs[vec - vec_base].arg); |
| 153 | } else { |
stroese | 8c725b9 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 154 | printf ("\nBogus External Interrupt Vector %d\n", vec); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
stroese | 8c725b9 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 158 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 159 | #ifdef CONFIG_M5272 |
| 160 | int interrupt_init (void) |
| 161 | { |
| 162 | volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1); |
| 163 | |
| 164 | /* disable all external interrupts */ |
| 165 | intp->int_icr1 = 0x88888888; |
| 166 | intp->int_icr2 = 0x88888888; |
| 167 | intp->int_icr3 = 0x88888888; |
| 168 | intp->int_icr4 = 0x88888888; |
| 169 | intp->int_pitr = 0x00000000; |
| 170 | /* initialize vector register */ |
| 171 | intp->int_pivr = 0x40; |
| 172 | |
| 173 | enable_interrupts (); |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | #endif |
| 178 | |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 179 | #if defined(CONFIG_M5282) || defined(CONFIG_M5271) |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 180 | int interrupt_init (void) |
| 181 | { |
| 182 | return 0; |
| 183 | } |
| 184 | #endif |
stroese | 8c725b9 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 185 | |
| 186 | #ifdef CONFIG_M5249 |
| 187 | int interrupt_init (void) |
| 188 | { |
| 189 | enable_interrupts (); |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | #endif |