This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / arm / mach-h720x / cpu-h7202.c
1 /*
2  * linux/arch/arm/mach-h720x/cpu-h7202.c
3  *
4  * Copyright (C) 2003 Thomas Gleixner <tglx@linutronix.de>
5  *               2003 Robert Schwebel <r.schwebel@pengutronix.de>
6  *               2004 Sascha Hauer    <s.hauer@pengutronix.de>
7  *
8  * processor specific stuff for the Hynix h7201
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  */
15
16 #include <linux/init.h>
17 #include <linux/interrupt.h>
18 #include <linux/module.h>
19 #include <asm/types.h>
20 #include <asm/hardware.h>
21 #include <asm/irq.h>
22 #include <asm/arch/irqs.h>
23 #include <asm/mach/irq.h>
24 #include <asm/mach/time.h>
25 #include <linux/device.h>
26
27 static struct resource h7202ps2_resources[] = {
28         [0] = {
29                 .start  = 0x8002c000,
30                 .end    = 0x8002c040,
31                 .flags  = IORESOURCE_MEM,
32         },
33         [1] = {
34                 .start  = IRQ_PS2,
35                 .end    = IRQ_PS2,
36                 .flags  = IORESOURCE_IRQ,
37         },
38 };
39
40 static struct platform_device h7202ps2_device = {
41         .name           = "h7202ps2",
42         .id             = -1,
43         .num_resources  = ARRAY_SIZE(h7202ps2_resources),
44         .resource       = h7202ps2_resources,
45 };
46
47 static struct platform_device *devices[] __initdata = {
48         &h7202ps2_device,
49 };
50
51 extern unsigned long h720x_gettimeoffset(void);
52 extern void __init h720x_init_irq (void);
53
54 /* Although we have two interrupt lines for the timers, we only have one
55  * status register which clears all pending timer interrupts on reading. So
56  * we have to handle all timer interrupts in one place.
57  */
58 static void
59 h7202_timerx_demux_handler(unsigned int irq_unused, struct irqdesc *desc,
60                         struct pt_regs *regs)
61 {
62         unsigned int mask, irq;
63
64         mask = CPU_REG (TIMER_VIRT, TIMER_TOPSTAT);
65
66         if ( mask & TSTAT_T0INT ) {
67                 timer_tick(regs);
68                 if( mask == TSTAT_T0INT )
69                         return;
70         }
71
72         mask >>= 1;
73         irq = IRQ_TIMER1;
74         desc = irq_desc + irq;
75         while (mask) {
76                 if (mask & 1)
77                         desc->handle(irq, desc, regs);
78                 irq++;
79                 desc++;
80                 mask >>= 1;
81         }
82 }
83
84 /*
85  * Timer interrupt handler
86  */
87 static irqreturn_t
88 h7202_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
89 {
90         h7202_timerx_demux_handler(0, NULL, regs);
91         return IRQ_HANDLED;
92 }
93
94 /*
95  * mask multiplexed timer irq's
96  */
97 static void inline mask_timerx_irq (u32 irq)
98 {
99         unsigned int bit;
100         bit = 2 << ((irq == IRQ_TIMER64B) ? 4 : (irq - IRQ_TIMER1));
101         CPU_REG (TIMER_VIRT, TIMER_TOPCTRL) &= ~bit;
102 }
103
104 /*
105  * unmask multiplexed timer irq's
106  */
107 static void inline unmask_timerx_irq (u32 irq)
108 {
109         unsigned int bit;
110         bit = 2 << ((irq == IRQ_TIMER64B) ? 4 : (irq - IRQ_TIMER1));
111         CPU_REG (TIMER_VIRT, TIMER_TOPCTRL) |= bit;
112 }
113
114 static struct irqchip h7202_timerx_chip = {
115         .ack = mask_timerx_irq,
116         .mask = mask_timerx_irq,
117         .unmask = unmask_timerx_irq,
118 };
119
120 static struct irqaction h7202_timer_irq = {
121         .name           = "h7202 Timer Tick",
122         .flags          = SA_INTERRUPT,
123         .handler        = h7202_timer_interrupt
124 };
125
126 /*
127  * Setup TIMER0 as system timer
128  */
129 void __init h7202_init_time(void)
130 {
131         gettimeoffset = h720x_gettimeoffset;
132
133         CPU_REG (TIMER_VIRT, TM0_PERIOD) = LATCH;
134         CPU_REG (TIMER_VIRT, TM0_CTRL) = TM_RESET;
135         CPU_REG (TIMER_VIRT, TM0_CTRL) = TM_REPEAT | TM_START;
136         CPU_REG (TIMER_VIRT, TIMER_TOPCTRL) = ENABLE_TM0_INTR | TIMER_ENABLE_BIT;
137
138         setup_irq(IRQ_TIMER0, &h7202_timer_irq);
139 }
140
141 void __init h7202_init_irq (void)
142 {
143         int     irq;
144
145         CPU_REG (GPIO_E_VIRT, GPIO_MASK) = 0x0;
146
147         for (irq = IRQ_TIMER1;
148                           irq < IRQ_CHAINED_TIMERX(NR_TIMERX_IRQS); irq++) {
149                 mask_timerx_irq(irq);
150                 set_irq_chip(irq, &h7202_timerx_chip);
151                 set_irq_handler(irq, do_edge_IRQ);
152                 set_irq_flags(irq, IRQF_VALID );
153         }
154         set_irq_chained_handler(IRQ_TIMERX, h7202_timerx_demux_handler);
155
156         h720x_init_irq();
157 }
158
159 void __init init_hw_h7202(void)
160 {
161         /* Enable clocks */
162         CPU_REG (PMU_BASE, PMU_PLL_CTRL) |= PLL_2_EN | PLL_1_EN | PLL_3_MUTE;
163
164         (void) platform_add_devices(devices, ARRAY_SIZE(devices));
165 }