http://downloads.netgear.com/files/GPL/GPL_Source_V361j_DM111PSP_series_consumer_rele...
[bcm963xx.git] / kernel / linux / arch / arm / mach-ebsa110 / core.c
1 /*
2  *  linux/arch/arm/mach-ebsa110/core.c
3  *
4  *  Copyright (C) 1998-2001 Russell King
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  *  Extra MM routines for the EBSA-110 architecture
11  */
12 #include <linux/kernel.h>
13 #include <linux/mm.h>
14 #include <linux/interrupt.h>
15 #include <linux/init.h>
16
17 #include <asm/hardware.h>
18 #include <asm/irq.h>
19 #include <asm/io.h>
20 #include <asm/setup.h>
21 #include <asm/mach-types.h>
22 #include <asm/pgtable.h>
23 #include <asm/page.h>
24 #include <asm/system.h>
25
26 #include <asm/mach/arch.h>
27 #include <asm/mach/irq.h>
28 #include <asm/mach/map.h>
29
30 #include <asm/mach/time.h>
31
32 #define IRQ_MASK                0xfe000000      /* read */
33 #define IRQ_MSET                0xfe000000      /* write */
34 #define IRQ_STAT                0xff000000      /* read */
35 #define IRQ_MCLR                0xff000000      /* write */
36
37 static void ebsa110_mask_irq(unsigned int irq)
38 {
39         __raw_writeb(1 << irq, IRQ_MCLR);
40 }
41
42 static void ebsa110_unmask_irq(unsigned int irq)
43 {
44         __raw_writeb(1 << irq, IRQ_MSET);
45 }
46
47 static struct irqchip ebsa110_irq_chip = {
48         .ack    = ebsa110_mask_irq,
49         .mask   = ebsa110_mask_irq,
50         .unmask = ebsa110_unmask_irq,
51 };
52  
53 static void __init ebsa110_init_irq(void)
54 {
55         unsigned long flags;
56         unsigned int irq;
57
58         local_irq_save(flags);
59         __raw_writeb(0xff, IRQ_MCLR);
60         __raw_writeb(0x55, IRQ_MSET);
61         __raw_writeb(0x00, IRQ_MSET);
62         if (__raw_readb(IRQ_MASK) != 0x55)
63                 while (1);
64         __raw_writeb(0xff, IRQ_MCLR);   /* clear all interrupt enables */
65         local_irq_restore(flags);
66
67         for (irq = 0; irq < NR_IRQS; irq++) {
68                 set_irq_chip(irq, &ebsa110_irq_chip);
69                 set_irq_handler(irq, do_level_IRQ);
70                 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
71         }
72 }
73
74 static struct map_desc ebsa110_io_desc[] __initdata = {
75         /*
76          * sparse external-decode ISAIO space
77          */
78         { IRQ_STAT,    TRICK4_PHYS, PGDIR_SIZE,  MT_DEVICE }, /* IRQ_STAT/IRQ_MCLR */
79         { IRQ_MASK,    TRICK3_PHYS, PGDIR_SIZE,  MT_DEVICE }, /* IRQ_MASK/IRQ_MSET */
80         { SOFT_BASE,   TRICK1_PHYS, PGDIR_SIZE,  MT_DEVICE }, /* SOFT_BASE */
81         { PIT_BASE,    TRICK0_PHYS, PGDIR_SIZE,  MT_DEVICE }, /* PIT_BASE */
82
83         /*
84          * self-decode ISAIO space
85          */
86         { ISAIO_BASE,  ISAIO_PHYS,  ISAIO_SIZE,  MT_DEVICE },
87         { ISAMEM_BASE, ISAMEM_PHYS, ISAMEM_SIZE, MT_DEVICE }
88 };
89
90 static void __init ebsa110_map_io(void)
91 {
92         iotable_init(ebsa110_io_desc, ARRAY_SIZE(ebsa110_io_desc));
93 }
94
95
96 #define PIT_CTRL                (PIT_BASE + 0x0d)
97 #define PIT_T2                  (PIT_BASE + 0x09)
98 #define PIT_T1                  (PIT_BASE + 0x05)
99 #define PIT_T0                  (PIT_BASE + 0x01)
100
101 /*
102  * This is the rate at which your MCLK signal toggles (in Hz)
103  * This was measured on a 10 digit frequency counter sampling
104  * over 1 second.
105  */
106 #define MCLK    47894000
107
108 /*
109  * This is the rate at which the PIT timers get clocked
110  */
111 #define CLKBY7  (MCLK / 7)
112
113 /*
114  * This is the counter value.  We tick at 200Hz on this platform.
115  */
116 #define COUNT   ((CLKBY7 + (HZ / 2)) / HZ)
117
118 /*
119  * Get the time offset from the system PIT.  Note that if we have missed an
120  * interrupt, then the PIT counter will roll over (ie, be negative).
121  * This actually works out to be convenient.
122  */
123 static unsigned long ebsa110_gettimeoffset(void)
124 {
125         unsigned long offset, count;
126
127         __raw_writeb(0x40, PIT_CTRL);
128         count = __raw_readb(PIT_T1);
129         count |= __raw_readb(PIT_T1) << 8;
130
131         /*
132          * If count > COUNT, make the number negative.
133          */
134         if (count > COUNT)
135                 count |= 0xffff0000;
136
137         offset = COUNT;
138         offset -= count;
139
140         /*
141          * `offset' is in units of timer counts.  Convert
142          * offset to units of microseconds.
143          */
144         offset = offset * (1000000 / HZ) / COUNT;
145
146         return offset;
147 }
148
149 static irqreturn_t
150 ebsa110_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
151 {
152         u32 count;
153
154         /* latch and read timer 1 */
155         __raw_writeb(0x40, PIT_CTRL);
156         count = __raw_readb(PIT_T1);
157         count |= __raw_readb(PIT_T1) << 8;
158
159         count += COUNT;
160
161         __raw_writeb(count & 0xff, PIT_T1);
162         __raw_writeb(count >> 8, PIT_T1);
163
164         timer_tick(regs);
165
166         return IRQ_HANDLED;
167 }
168
169 static struct irqaction ebsa110_timer_irq = {
170         .name           = "EBSA110 Timer Tick",
171         .flags          = SA_INTERRUPT,
172         .handler        = ebsa110_timer_interrupt
173 };
174
175 /*
176  * Set up timer interrupt.
177  */
178 static void __init ebsa110_init_time(void)
179 {
180         /*
181          * Timer 1, mode 2, LSB/MSB
182          */
183         __raw_writeb(0x70, PIT_CTRL);
184         __raw_writeb(COUNT & 0xff, PIT_T1);
185         __raw_writeb(COUNT >> 8, PIT_T1);
186
187         gettimeoffset = ebsa110_gettimeoffset;
188
189         setup_irq(IRQ_EBSA110_TIMER0, &ebsa110_timer_irq);
190 }
191
192 MACHINE_START(EBSA110, "EBSA110")
193         MAINTAINER("Russell King")
194         BOOT_MEM(0x00000000, 0xe0000000, 0xe0000000)
195         BOOT_PARAMS(0x00000400)
196         DISABLE_PARPORT(0)
197         DISABLE_PARPORT(2)
198         SOFT_REBOOT
199         MAPIO(ebsa110_map_io)
200         INITIRQ(ebsa110_init_irq)
201         INITTIME(ebsa110_init_time)
202 MACHINE_END