blob: 6c396447c4e078d8ce7e1807c072edfc8c704bb7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/arm/mach-ixp4xx/common.c
3 *
4 * Generic code shared across all IXP4XX platforms
5 *
6 * Maintainer: Deepak Saxena <dsaxena@plexity.net>
7 *
8 * Copyright 2002 (c) Intel Corporation
9 * Copyright 2003-2004 (c) MontaVista, Software, Inc.
10 *
11 * This file is licensed under the terms of the GNU General Public
12 * License version 2. This program is licensed "as is" without any
13 * warranty of any kind, whether express or implied.
14 */
15
16#include <linux/config.h>
17#include <linux/kernel.h>
18#include <linux/mm.h>
19#include <linux/init.h>
20#include <linux/serial.h>
21#include <linux/sched.h>
22#include <linux/tty.h>
23#include <linux/serial_core.h>
24#include <linux/bootmem.h>
25#include <linux/interrupt.h>
26#include <linux/bitops.h>
27#include <linux/time.h>
28#include <linux/timex.h>
29
30#include <asm/hardware.h>
31#include <asm/uaccess.h>
32#include <asm/io.h>
33#include <asm/pgtable.h>
34#include <asm/page.h>
35#include <asm/irq.h>
36
37#include <asm/mach/map.h>
38#include <asm/mach/irq.h>
39#include <asm/mach/time.h>
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041/*************************************************************************
42 * IXP4xx chipset I/O mapping
43 *************************************************************************/
44static struct map_desc ixp4xx_io_desc[] __initdata = {
45 { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
46 .virtual = IXP4XX_PERIPHERAL_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010047 .pfn = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 .length = IXP4XX_PERIPHERAL_REGION_SIZE,
49 .type = MT_DEVICE
50 }, { /* Expansion Bus Config Registers */
51 .virtual = IXP4XX_EXP_CFG_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010052 .pfn = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 .length = IXP4XX_EXP_CFG_REGION_SIZE,
54 .type = MT_DEVICE
55 }, { /* PCI Registers */
56 .virtual = IXP4XX_PCI_CFG_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010057 .pfn = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 .length = IXP4XX_PCI_CFG_REGION_SIZE,
59 .type = MT_DEVICE
Deepak Saxena5932ae32005-06-24 20:54:35 +010060 },
61#ifdef CONFIG_DEBUG_LL
62 { /* Debug UART mapping */
63 .virtual = IXP4XX_DEBUG_UART_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010064 .pfn = __phys_to_pfn(IXP4XX_DEBUG_UART_BASE_PHYS),
Deepak Saxena5932ae32005-06-24 20:54:35 +010065 .length = IXP4XX_DEBUG_UART_REGION_SIZE,
66 .type = MT_DEVICE
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 }
Deepak Saxena5932ae32005-06-24 20:54:35 +010068#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070069};
70
71void __init ixp4xx_map_io(void)
72{
73 iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
74}
75
76
77/*************************************************************************
78 * IXP4xx chipset IRQ handling
79 *
80 * TODO: GPIO IRQs should be marked invalid until the user of the IRQ
81 * (be it PCI or something else) configures that GPIO line
82 * as an IRQ.
83 **************************************************************************/
Deepak Saxenabdf82b52005-08-29 22:46:30 +010084enum ixp4xx_irq_type {
85 IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
86};
87
88static void ixp4xx_config_irq(unsigned irq, enum ixp4xx_irq_type type);
89
90/*
91 * IRQ -> GPIO mapping table
92 */
93static int irq2gpio[32] = {
94 -1, -1, -1, -1, -1, -1, 0, 1,
95 -1, -1, -1, -1, -1, -1, -1, -1,
96 -1, -1, -1, 2, 3, 4, 5, 6,
97 7, 8, 9, 10, 11, 12, -1, -1,
98};
99
100static int ixp4xx_set_irq_type(unsigned int irq, unsigned int type)
101{
102 int line = irq2gpio[irq];
103 u32 int_style;
104 enum ixp4xx_irq_type irq_type;
105 volatile u32 *int_reg;
106
107 /*
108 * Only for GPIO IRQs
109 */
110 if (line < 0)
111 return -EINVAL;
112
113 if (type & IRQT_BOTHEDGE) {
114 int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
115 irq_type = IXP4XX_IRQ_EDGE;
116 } else if (type & IRQT_RISING) {
117 int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
118 irq_type = IXP4XX_IRQ_EDGE;
119 } else if (type & IRQT_FALLING) {
120 int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
121 irq_type = IXP4XX_IRQ_EDGE;
122 } else if (type & IRQT_HIGH) {
123 int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
124 irq_type = IXP4XX_IRQ_LEVEL;
125 } else if (type & IRQT_LOW) {
126 int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
127 irq_type = IXP4XX_IRQ_LEVEL;
David Vrabel6132f9e2005-09-26 19:52:56 +0100128 } else
129 return -EINVAL;
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100130
131 ixp4xx_config_irq(irq, irq_type);
132
133 if (line >= 8) { /* pins 8-15 */
134 line -= 8;
135 int_reg = IXP4XX_GPIO_GPIT2R;
136 } else { /* pins 0-7 */
137 int_reg = IXP4XX_GPIO_GPIT1R;
138 }
139
140 /* Clear the style for the appropriate pin */
141 *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
142 (line * IXP4XX_GPIO_STYLE_SIZE));
143
144 /* Set the new style */
145 *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
David Vrabel6132f9e2005-09-26 19:52:56 +0100146
147 return 0;
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100148}
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150static void ixp4xx_irq_mask(unsigned int irq)
151{
152 if (cpu_is_ixp46x() && irq >= 32)
153 *IXP4XX_ICMR2 &= ~(1 << (irq - 32));
154 else
155 *IXP4XX_ICMR &= ~(1 << irq);
156}
157
158static void ixp4xx_irq_unmask(unsigned int irq)
159{
160 if (cpu_is_ixp46x() && irq >= 32)
161 *IXP4XX_ICMR2 |= (1 << (irq - 32));
162 else
163 *IXP4XX_ICMR |= (1 << irq);
164}
165
166static void ixp4xx_irq_ack(unsigned int irq)
167{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 int line = (irq < 32) ? irq2gpio[irq] : -1;
169
170 if (line >= 0)
171 gpio_line_isr_clear(line);
172}
173
174/*
175 * Level triggered interrupts on GPIO lines can only be cleared when the
176 * interrupt condition disappears.
177 */
178static void ixp4xx_irq_level_unmask(unsigned int irq)
179{
180 ixp4xx_irq_ack(irq);
181 ixp4xx_irq_unmask(irq);
182}
183
184static struct irqchip ixp4xx_irq_level_chip = {
Russell King2be863c2005-09-06 23:13:17 +0100185 .ack = ixp4xx_irq_mask,
186 .mask = ixp4xx_irq_mask,
187 .unmask = ixp4xx_irq_level_unmask,
188 .set_type = ixp4xx_set_irq_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189};
190
191static struct irqchip ixp4xx_irq_edge_chip = {
Russell King2be863c2005-09-06 23:13:17 +0100192 .ack = ixp4xx_irq_ack,
193 .mask = ixp4xx_irq_mask,
194 .unmask = ixp4xx_irq_unmask,
195 .set_type = ixp4xx_set_irq_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196};
197
198static void ixp4xx_config_irq(unsigned irq, enum ixp4xx_irq_type type)
199{
200 switch (type) {
201 case IXP4XX_IRQ_LEVEL:
202 set_irq_chip(irq, &ixp4xx_irq_level_chip);
203 set_irq_handler(irq, do_level_IRQ);
204 break;
205 case IXP4XX_IRQ_EDGE:
206 set_irq_chip(irq, &ixp4xx_irq_edge_chip);
207 set_irq_handler(irq, do_edge_IRQ);
208 break;
209 }
210 set_irq_flags(irq, IRQF_VALID);
211}
212
213void __init ixp4xx_init_irq(void)
214{
215 int i = 0;
216
217 /* Route all sources to IRQ instead of FIQ */
218 *IXP4XX_ICLR = 0x0;
219
220 /* Disable all interrupt */
221 *IXP4XX_ICMR = 0x0;
222
223 if (cpu_is_ixp46x()) {
224 /* Route upper 32 sources to IRQ instead of FIQ */
225 *IXP4XX_ICLR2 = 0x00;
226
227 /* Disable upper 32 interrupts */
228 *IXP4XX_ICMR2 = 0x00;
229 }
230
231 /* Default to all level triggered */
232 for(i = 0; i < NR_IRQS; i++)
233 ixp4xx_config_irq(i, IXP4XX_IRQ_LEVEL);
234}
235
236
237/*************************************************************************
238 * IXP4xx timer tick
239 * We use OS timer1 on the CPU for the timer tick and the timestamp
240 * counter as a source of real clock ticks to account for missed jiffies.
241 *************************************************************************/
242
243static unsigned volatile last_jiffy_time;
244
245#define CLOCK_TICKS_PER_USEC ((CLOCK_TICK_RATE + USEC_PER_SEC/2) / USEC_PER_SEC)
246
247/* IRQs are disabled before entering here from do_gettimeofday() */
248static unsigned long ixp4xx_gettimeoffset(void)
249{
250 u32 elapsed;
251
252 elapsed = *IXP4XX_OSTS - last_jiffy_time;
253
254 return elapsed / CLOCK_TICKS_PER_USEC;
255}
256
257static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
258{
259 write_seqlock(&xtime_lock);
260
261 /* Clear Pending Interrupt by writing '1' to it */
262 *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
263
264 /*
265 * Catch up with the real idea of time
266 */
267 while ((*IXP4XX_OSTS - last_jiffy_time) > LATCH) {
268 timer_tick(regs);
269 last_jiffy_time += LATCH;
270 }
271
272 write_sequnlock(&xtime_lock);
273
274 return IRQ_HANDLED;
275}
276
277static struct irqaction ixp4xx_timer_irq = {
278 .name = "IXP4xx Timer Tick",
Russell King09b8b5f2005-06-26 17:06:36 +0100279 .flags = SA_INTERRUPT | SA_TIMER,
280 .handler = ixp4xx_timer_interrupt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281};
282
283static void __init ixp4xx_timer_init(void)
284{
285 /* Clear Pending Interrupt by writing '1' to it */
286 *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
287
288 /* Setup the Timer counter value */
289 *IXP4XX_OSRT1 = (LATCH & ~IXP4XX_OST_RELOAD_MASK) | IXP4XX_OST_ENABLE;
290
291 /* Reset time-stamp counter */
292 *IXP4XX_OSTS = 0;
293 last_jiffy_time = 0;
294
295 /* Connect the interrupt handler and enable the interrupt */
296 setup_irq(IRQ_IXP4XX_TIMER1, &ixp4xx_timer_irq);
297}
298
299struct sys_timer ixp4xx_timer = {
300 .init = ixp4xx_timer_init,
301 .offset = ixp4xx_gettimeoffset,
302};
303
304static struct resource ixp46x_i2c_resources[] = {
305 [0] = {
306 .start = 0xc8011000,
307 .end = 0xc801101c,
308 .flags = IORESOURCE_MEM,
309 },
310 [1] = {
311 .start = IRQ_IXP4XX_I2C,
312 .end = IRQ_IXP4XX_I2C,
313 .flags = IORESOURCE_IRQ
314 }
315};
316
317/*
318 * I2C controller. The IXP46x uses the same block as the IOP3xx, so
319 * we just use the same device name.
320 */
321static struct platform_device ixp46x_i2c_controller = {
322 .name = "IOP3xx-I2C",
323 .id = 0,
324 .num_resources = 2,
325 .resource = ixp46x_i2c_resources
326};
327
328static struct platform_device *ixp46x_devices[] __initdata = {
329 &ixp46x_i2c_controller
330};
331
332void __init ixp4xx_sys_init(void)
333{
334 if (cpu_is_ixp46x()) {
335 platform_add_devices(ixp46x_devices,
336 ARRAY_SIZE(ixp46x_devices));
337 }
338}
339