wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2002 (440 port) |
| 6 | * Scott McNutt, Artesyn Communication Producs, smcnutt@artsyncp.com |
| 7 | * |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 8 | * (C) Copyright 2003 (440GX port) |
| 9 | * Travis B. Sawyer, Sandburst Corporation, tsawyer@sandburst.com |
| 10 | * |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 11 | * (C) Copyright 2008 (PPC440X05 port for Virtex 5 FX) |
| 12 | * Ricardo Ribalda-Universidad Autonoma de Madrid-ricardo.ribalda@uam.es |
| 13 | * Work supported by Qtechnology (htpp://qtec.com) |
| 14 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 15 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <common.h> |
| 19 | #include <watchdog.h> |
| 20 | #include <command.h> |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 21 | #include <asm/processor.h> |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 22 | #include <asm/interrupt.h> |
Stefan Roese | b36df56 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 23 | #include <asm/ppc4xx.h> |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 24 | #include <ppc_asm.tmpl> |
| 25 | #include <commproc.h> |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 26 | |
Stefan Roese | d1631fe | 2008-06-26 13:40:57 +0200 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 28 | |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 29 | /* |
| 30 | * CPM interrupt vector functions. |
| 31 | */ |
| 32 | struct irq_action { |
| 33 | interrupt_handler_t *handler; |
| 34 | void *arg; |
| 35 | int count; |
| 36 | }; |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 37 | static struct irq_action irq_vecs[IRQ_MAX]; |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 38 | |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 39 | #if defined(CONFIG_440) |
| 40 | |
| 41 | /* SPRN changed in 440 */ |
| 42 | static __inline__ void set_evpr(unsigned long val) |
| 43 | { |
| 44 | asm volatile("mtspr 0x03f,%0" : : "r" (val)); |
| 45 | } |
| 46 | |
| 47 | #else /* !defined(CONFIG_440) */ |
| 48 | |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 49 | static __inline__ void set_pit(unsigned long val) |
| 50 | { |
| 51 | asm volatile("mtpit %0" : : "r" (val)); |
| 52 | } |
| 53 | |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 54 | static __inline__ void set_evpr(unsigned long val) |
| 55 | { |
| 56 | asm volatile("mtevpr %0" : : "r" (val)); |
| 57 | } |
| 58 | #endif /* defined(CONFIG_440 */ |
| 59 | |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 60 | int interrupt_init_cpu (unsigned *decrementer_count) |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 61 | { |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 62 | int vec; |
| 63 | unsigned long val; |
| 64 | |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 65 | /* decrementer is automatically reloaded */ |
| 66 | *decrementer_count = 0; |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 67 | |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 68 | /* |
| 69 | * Mark all irqs as free |
| 70 | */ |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 71 | for (vec = 0; vec < IRQ_MAX; vec++) { |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 72 | irq_vecs[vec].handler = NULL; |
| 73 | irq_vecs[vec].arg = NULL; |
| 74 | irq_vecs[vec].count = 0; |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | #ifdef CONFIG_4xx |
| 78 | /* |
| 79 | * Init PIT |
| 80 | */ |
| 81 | #if defined(CONFIG_440) |
Matthias Fuchs | 58ea142 | 2009-07-22 17:27:56 +0200 | [diff] [blame] | 82 | val = mfspr( SPRN_TCR ); |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 83 | val &= (~0x04400000); /* clear DIS & ARE */ |
Matthias Fuchs | 58ea142 | 2009-07-22 17:27:56 +0200 | [diff] [blame] | 84 | mtspr( SPRN_TCR, val ); |
| 85 | mtspr( SPRN_DEC, 0 ); /* Prevent exception after TSR clear*/ |
| 86 | mtspr( SPRN_DECAR, 0 ); /* clear reload */ |
| 87 | mtspr( SPRN_TSR, 0x08000000 ); /* clear DEC status */ |
stroese | 68e0236 | 2005-04-07 05:32:44 +0000 | [diff] [blame] | 88 | val = gd->bd->bi_intfreq/1000; /* 1 msec */ |
Matthias Fuchs | 58ea142 | 2009-07-22 17:27:56 +0200 | [diff] [blame] | 89 | mtspr( SPRN_DECAR, val ); /* Set auto-reload value */ |
| 90 | mtspr( SPRN_DEC, val ); /* Set inital val */ |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 91 | #else |
| 92 | set_pit(gd->bd->bi_intfreq / 1000); |
| 93 | #endif |
| 94 | #endif /* CONFIG_4xx */ |
| 95 | |
| 96 | #ifdef CONFIG_ADCIOP |
| 97 | /* |
| 98 | * Init PIT |
| 99 | */ |
| 100 | set_pit(66000); |
| 101 | #endif |
| 102 | |
| 103 | /* |
| 104 | * Enable PIT |
| 105 | */ |
Matthias Fuchs | 58ea142 | 2009-07-22 17:27:56 +0200 | [diff] [blame] | 106 | val = mfspr(SPRN_TCR); |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 107 | val |= 0x04400000; |
Matthias Fuchs | 58ea142 | 2009-07-22 17:27:56 +0200 | [diff] [blame] | 108 | mtspr(SPRN_TCR, val); |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 109 | |
| 110 | /* |
| 111 | * Set EVPR to 0 |
| 112 | */ |
| 113 | set_evpr(0x00000000); |
| 114 | |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 115 | /* |
Stefan Roese | 60204d0 | 2008-07-18 12:24:41 +0200 | [diff] [blame] | 116 | * Call uic or xilinx_irq pic_enable |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 117 | */ |
| 118 | pic_enable(); |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 119 | |
| 120 | return (0); |
| 121 | } |
| 122 | |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 123 | void timer_interrupt_cpu(struct pt_regs *regs) |
Stefan Roese | 56e4101 | 2008-02-19 22:07:57 +0100 | [diff] [blame] | 124 | { |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 125 | /* nothing to do here */ |
Stefan Roese | 56e4101 | 2008-02-19 22:07:57 +0100 | [diff] [blame] | 126 | return; |
wdenk | ba56f62 | 2004-02-06 23:19:44 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 129 | void interrupt_run_handler(int vec) |
| 130 | { |
| 131 | irq_vecs[vec].count++; |
| 132 | |
| 133 | if (irq_vecs[vec].handler != NULL) { |
| 134 | /* call isr */ |
| 135 | (*irq_vecs[vec].handler) (irq_vecs[vec].arg); |
| 136 | } else { |
| 137 | pic_irq_disable(vec); |
| 138 | printf("Masking bogus interrupt vector %d\n", vec); |
| 139 | } |
| 140 | |
| 141 | pic_irq_ack(vec); |
| 142 | return; |
| 143 | } |
| 144 | |
Stefan Roese | 56e4101 | 2008-02-19 22:07:57 +0100 | [diff] [blame] | 145 | void irq_install_handler(int vec, interrupt_handler_t * handler, void *arg) |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 146 | { |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 147 | /* |
Stefan Roese | 56e4101 | 2008-02-19 22:07:57 +0100 | [diff] [blame] | 148 | * Print warning when replacing with a different irq vector |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 149 | */ |
Stefan Roese | 56e4101 | 2008-02-19 22:07:57 +0100 | [diff] [blame] | 150 | if ((irq_vecs[vec].handler != NULL) && (irq_vecs[vec].handler != handler)) { |
| 151 | printf("Interrupt vector %d: handler 0x%x replacing 0x%x\n", |
| 152 | vec, (uint) handler, (uint) irq_vecs[vec].handler); |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 153 | } |
Stefan Roese | 56e4101 | 2008-02-19 22:07:57 +0100 | [diff] [blame] | 154 | irq_vecs[vec].handler = handler; |
| 155 | irq_vecs[vec].arg = arg; |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 156 | |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 157 | pic_irq_enable(vec); |
| 158 | return; |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 161 | void irq_free_handler(int vec) |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 162 | { |
Stefan Roese | 56e4101 | 2008-02-19 22:07:57 +0100 | [diff] [blame] | 163 | debug("Free interrupt for vector %d ==> %p\n", |
| 164 | vec, irq_vecs[vec].handler); |
| 165 | |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 166 | pic_irq_disable(vec); |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 167 | |
Stefan Roese | 56e4101 | 2008-02-19 22:07:57 +0100 | [diff] [blame] | 168 | irq_vecs[vec].handler = NULL; |
| 169 | irq_vecs[vec].arg = NULL; |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 170 | return; |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Jon Loeliger | 3a1ed1e | 2007-07-09 18:57:22 -0500 | [diff] [blame] | 173 | #if defined(CONFIG_CMD_IRQ) |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 174 | int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 175 | { |
| 176 | int vec; |
| 177 | |
Stefan Roese | 56e4101 | 2008-02-19 22:07:57 +0100 | [diff] [blame] | 178 | printf ("Interrupt-Information:\n"); |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 179 | printf ("Nr Routine Arg Count\n"); |
| 180 | |
Ricardo Ribalda Delgado | d865fd0 | 2008-07-17 11:44:12 +0200 | [diff] [blame] | 181 | for (vec = 0; vec < IRQ_MAX; vec++) { |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 182 | if (irq_vecs[vec].handler != NULL) { |
| 183 | printf ("%02d %08lx %08lx %d\n", |
| 184 | vec, |
| 185 | (ulong)irq_vecs[vec].handler, |
| 186 | (ulong)irq_vecs[vec].arg, |
| 187 | irq_vecs[vec].count); |
| 188 | } |
| 189 | } |
| 190 | |
wdenk | f780aa2 | 2002-09-18 19:21:21 +0000 | [diff] [blame] | 191 | return 0; |
| 192 | } |
Jon Loeliger | 3a1ed1e | 2007-07-09 18:57:22 -0500 | [diff] [blame] | 193 | #endif |