Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 1 | /* |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 2 | * (C) Copyright 2008-2011 |
| 3 | * Graeme Russ, <graeme.russ@gmail.com> |
| 4 | * |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 5 | * (C) Copyright 2002 |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 6 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 27 | #include <common.h> |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 28 | #include <asm/io.h> |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 29 | #include <asm/interrupt.h> |
Graeme Russ | 0d992d0 | 2011-08-04 22:05:09 +1000 | [diff] [blame] | 30 | #include <asm/arch/sc520.h> |
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 | void sc520_timer_isr(void) |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 33 | { |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 34 | /* Ack the GP Timer Interrupt */ |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 35 | writeb(0x02, &sc520_mmcr->gptmrsta); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 36 | } |
| 37 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 38 | int timer_init(void) |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 39 | { |
Graeme Russ | cc272eb | 2009-11-24 20:04:17 +1100 | [diff] [blame] | 40 | /* Register the SC520 specific timer interrupt handler */ |
Graeme Russ | 55bed24 | 2011-11-08 02:33:14 +0000 | [diff] [blame] | 41 | register_timer_isr(sc520_timer_isr); |
Graeme Russ | cc272eb | 2009-11-24 20:04:17 +1100 | [diff] [blame] | 42 | |
| 43 | /* Install interrupt handler for GP Timer 1 */ |
| 44 | irq_install_handler (0, timer_isr, NULL); |
| 45 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 46 | /* Map GP Timer 1 to Master PIC IR0 */ |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 47 | writeb(0x01, &sc520_mmcr->gp_tmr_int_map[1]); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 48 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 49 | /* Disable GP Timers 1 & 2 - Allow configuration writes */ |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 50 | writew(0x4000, &sc520_mmcr->gptmr1ctl); |
| 51 | writew(0x4000, &sc520_mmcr->gptmr2ctl); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 52 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 53 | /* Reset GP Timers 1 & 2 */ |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 54 | writew(0x0000, &sc520_mmcr->gptmr1cnt); |
| 55 | writew(0x0000, &sc520_mmcr->gptmr2cnt); |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 56 | |
| 57 | /* Setup GP Timer 2 as a 100kHz (10us) prescaler */ |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 58 | writew(83, &sc520_mmcr->gptmr2maxcmpa); |
| 59 | writew(0xc001, &sc520_mmcr->gptmr2ctl); |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 60 | |
| 61 | /* Setup GP Timer 1 as a 1000 Hz (1ms) interrupt generator */ |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 62 | writew(100, &sc520_mmcr->gptmr1maxcmpa); |
| 63 | writew(0xe009, &sc520_mmcr->gptmr1ctl); |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 64 | |
Graeme Russ | 55bed24 | 2011-11-08 02:33:14 +0000 | [diff] [blame] | 65 | unmask_irq(0); |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 66 | |
Graeme Russ | cf2fb0c | 2009-08-23 12:59:49 +1000 | [diff] [blame] | 67 | /* Clear the GP Timer 1 status register to get the show rolling*/ |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 68 | writeb(0x02, &sc520_mmcr->gptmrsta); |
Graeme Russ | cf2fb0c | 2009-08-23 12:59:49 +1000 | [diff] [blame] | 69 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 70 | return 0; |
| 71 | } |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 72 | |
Graeme Russ | f5f1828 | 2010-04-24 00:05:50 +1000 | [diff] [blame] | 73 | /* Allow boards to override udelay implementation */ |
Ingo van Lil | f0f778a | 2009-11-24 14:09:21 +0100 | [diff] [blame] | 74 | void __udelay(unsigned long usec) |
Graeme Russ | f5f1828 | 2010-04-24 00:05:50 +1000 | [diff] [blame] | 75 | __attribute__((weak, alias("sc520_udelay"))); |
| 76 | |
| 77 | void sc520_udelay(unsigned long usec) |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 78 | { |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 79 | int m = 0; |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 80 | long u; |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 81 | long temp; |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 82 | |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 83 | temp = readw(&sc520_mmcr->swtmrmilli); |
| 84 | temp = readw(&sc520_mmcr->swtmrmicro); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 85 | |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 86 | do { |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 87 | m += readw(&sc520_mmcr->swtmrmilli); |
| 88 | u = readw(&sc520_mmcr->swtmrmicro) + (m * 1000); |
Graeme Russ | 7679d1f | 2009-02-24 21:14:45 +1100 | [diff] [blame] | 89 | } while (u < usec); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 90 | } |