Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>. |
| 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 | |
| 24 | /* stuff specific for the sc520, but independent of implementation */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <asm/interrupt.h> |
| 28 | #include <asm/ic/sc520.h> |
| 29 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 30 | void sc520_timer_isr(void) |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 31 | { |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 32 | /* Ack the GP Timer Interrupt */ |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 33 | sc520_mmcr->gptmrsta = 0x02; |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 34 | } |
| 35 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 36 | int timer_init(void) |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 37 | { |
Graeme Russ | cc272eb | 2009-11-24 20:04:17 +1100 | [diff] [blame^] | 38 | /* Register the SC520 specific timer interrupt handler */ |
| 39 | register_timer_isr (sc520_timer_isr); |
| 40 | |
| 41 | /* Install interrupt handler for GP Timer 1 */ |
| 42 | irq_install_handler (0, timer_isr, NULL); |
| 43 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 44 | /* Map GP Timer 1 to Master PIC IR0 */ |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 45 | sc520_mmcr->gp_tmr_int_map[1] = 0x01; |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 46 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 47 | /* Disable GP Timers 1 & 2 - Allow configuration writes */ |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 48 | sc520_mmcr->gptmr1ctl = 0x4000; |
| 49 | sc520_mmcr->gptmr2ctl = 0x4000; |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 50 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 51 | /* Reset GP Timers 1 & 2 */ |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 52 | sc520_mmcr->gptmr1cnt = 0x0000; |
| 53 | sc520_mmcr->gptmr2cnt = 0x0000; |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 54 | |
| 55 | /* Setup GP Timer 2 as a 100kHz (10us) prescaler */ |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 56 | sc520_mmcr->gptmr2maxcmpa = 83; |
| 57 | sc520_mmcr->gptmr2ctl = 0xc001; |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 58 | |
| 59 | /* Setup GP Timer 1 as a 1000 Hz (1ms) interrupt generator */ |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 60 | sc520_mmcr->gptmr1maxcmpa = 100; |
| 61 | sc520_mmcr->gptmr1ctl = 0xe009; |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 62 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 63 | unmask_irq (0); |
| 64 | |
Graeme Russ | cf2fb0c | 2009-08-23 12:59:49 +1000 | [diff] [blame] | 65 | /* Clear the GP Timer 1 status register to get the show rolling*/ |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 66 | sc520_mmcr->gptmrsta = 0x02; |
Graeme Russ | cf2fb0c | 2009-08-23 12:59:49 +1000 | [diff] [blame] | 67 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 68 | return 0; |
| 69 | } |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 70 | |
| 71 | void udelay(unsigned long usec) |
| 72 | { |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 73 | int m = 0; |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 74 | long u; |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 75 | long temp; |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 76 | |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 77 | temp = sc520_mmcr->swtmrmilli; |
| 78 | temp = sc520_mmcr->swtmrmicro; |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 79 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 80 | do { |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 81 | m += sc520_mmcr->swtmrmilli; |
| 82 | u = sc520_mmcr->swtmrmicro + (m * 1000); |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 83 | } while (u < usec); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 84 | } |