blob: 1cf3bde1a5d21ce0b76d1b6f3170443f89d53bc0 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/kernel.h>
17#include <linux/mm.h>
18#include <linux/init.h>
19#include <linux/serial.h>
20#include <linux/sched.h>
21#include <linux/tty.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010022#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#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>
Kevin Hilman84904d02006-09-22 00:58:57 +010029#include <linux/clocksource.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Milan Svobodae520a362006-12-01 11:36:41 +010031#include <asm/arch/udc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/hardware.h>
33#include <asm/uaccess.h>
34#include <asm/io.h>
35#include <asm/pgtable.h>
36#include <asm/page.h>
37#include <asm/irq.h>
38
39#include <asm/mach/map.h>
40#include <asm/mach/irq.h>
41#include <asm/mach/time.h>
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/*************************************************************************
44 * IXP4xx chipset I/O mapping
45 *************************************************************************/
46static struct map_desc ixp4xx_io_desc[] __initdata = {
47 { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
48 .virtual = IXP4XX_PERIPHERAL_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010049 .pfn = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 .length = IXP4XX_PERIPHERAL_REGION_SIZE,
51 .type = MT_DEVICE
52 }, { /* Expansion Bus Config Registers */
53 .virtual = IXP4XX_EXP_CFG_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010054 .pfn = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 .length = IXP4XX_EXP_CFG_REGION_SIZE,
56 .type = MT_DEVICE
57 }, { /* PCI Registers */
58 .virtual = IXP4XX_PCI_CFG_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010059 .pfn = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 .length = IXP4XX_PCI_CFG_REGION_SIZE,
61 .type = MT_DEVICE
Deepak Saxena5932ae32005-06-24 20:54:35 +010062 },
63#ifdef CONFIG_DEBUG_LL
64 { /* Debug UART mapping */
65 .virtual = IXP4XX_DEBUG_UART_BASE_VIRT,
Deepak Saxena87fe04b2005-10-28 15:18:59 +010066 .pfn = __phys_to_pfn(IXP4XX_DEBUG_UART_BASE_PHYS),
Deepak Saxena5932ae32005-06-24 20:54:35 +010067 .length = IXP4XX_DEBUG_UART_REGION_SIZE,
68 .type = MT_DEVICE
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
Deepak Saxena5932ae32005-06-24 20:54:35 +010070#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070071};
72
73void __init ixp4xx_map_io(void)
74{
75 iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
76}
77
78
79/*************************************************************************
80 * IXP4xx chipset IRQ handling
81 *
82 * TODO: GPIO IRQs should be marked invalid until the user of the IRQ
83 * (be it PCI or something else) configures that GPIO line
84 * as an IRQ.
85 **************************************************************************/
Deepak Saxenabdf82b52005-08-29 22:46:30 +010086enum ixp4xx_irq_type {
87 IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
88};
89
Kevin Hilman984d1152006-11-03 01:47:20 +010090/* Each bit represents an IRQ: 1: edge-triggered, 0: level triggered */
91static unsigned long long ixp4xx_irq_edge = 0;
Deepak Saxenabdf82b52005-08-29 22:46:30 +010092
93/*
94 * IRQ -> GPIO mapping table
95 */
Lennert Buytenhek6cc1b652006-04-20 21:24:38 +010096static signed char irq2gpio[32] = {
Deepak Saxenabdf82b52005-08-29 22:46:30 +010097 -1, -1, -1, -1, -1, -1, 0, 1,
98 -1, -1, -1, -1, -1, -1, -1, -1,
99 -1, -1, -1, 2, 3, 4, 5, 6,
100 7, 8, 9, 10, 11, 12, -1, -1,
101};
102
103static int ixp4xx_set_irq_type(unsigned int irq, unsigned int type)
104{
105 int line = irq2gpio[irq];
106 u32 int_style;
107 enum ixp4xx_irq_type irq_type;
108 volatile u32 *int_reg;
109
110 /*
111 * Only for GPIO IRQs
112 */
113 if (line < 0)
114 return -EINVAL;
115
Mårten Wikström06e44792006-02-22 22:27:23 +0000116 switch (type){
117 case IRQT_BOTHEDGE:
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100118 int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
119 irq_type = IXP4XX_IRQ_EDGE;
Mårten Wikström06e44792006-02-22 22:27:23 +0000120 break;
121 case IRQT_RISING:
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100122 int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
123 irq_type = IXP4XX_IRQ_EDGE;
Mårten Wikström06e44792006-02-22 22:27:23 +0000124 break;
125 case IRQT_FALLING:
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100126 int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
127 irq_type = IXP4XX_IRQ_EDGE;
Mårten Wikström06e44792006-02-22 22:27:23 +0000128 break;
129 case IRQT_HIGH:
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100130 int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
131 irq_type = IXP4XX_IRQ_LEVEL;
Mårten Wikström06e44792006-02-22 22:27:23 +0000132 break;
133 case IRQT_LOW:
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100134 int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
135 irq_type = IXP4XX_IRQ_LEVEL;
Mårten Wikström06e44792006-02-22 22:27:23 +0000136 break;
137 default:
David Vrabel6132f9e2005-09-26 19:52:56 +0100138 return -EINVAL;
Mårten Wikström06e44792006-02-22 22:27:23 +0000139 }
Kevin Hilman984d1152006-11-03 01:47:20 +0100140
141 if (irq_type == IXP4XX_IRQ_EDGE)
142 ixp4xx_irq_edge |= (1 << irq);
143 else
144 ixp4xx_irq_edge &= ~(1 << irq);
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100145
146 if (line >= 8) { /* pins 8-15 */
147 line -= 8;
148 int_reg = IXP4XX_GPIO_GPIT2R;
149 } else { /* pins 0-7 */
150 int_reg = IXP4XX_GPIO_GPIT1R;
151 }
152
153 /* Clear the style for the appropriate pin */
154 *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
155 (line * IXP4XX_GPIO_STYLE_SIZE));
156
Deepak Saxenaf7e8bbb82006-01-04 17:17:10 +0000157 *IXP4XX_GPIO_GPISR = (1 << line);
158
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100159 /* Set the new style */
160 *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
David Vrabel6132f9e2005-09-26 19:52:56 +0100161
Alessandro Zummo73deb7d2006-03-20 17:10:12 +0000162 /* Configure the line as an input */
163 gpio_line_config(line, IXP4XX_GPIO_IN);
164
David Vrabel6132f9e2005-09-26 19:52:56 +0100165 return 0;
Deepak Saxenabdf82b52005-08-29 22:46:30 +0100166}
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168static void ixp4xx_irq_mask(unsigned int irq)
169{
170 if (cpu_is_ixp46x() && irq >= 32)
171 *IXP4XX_ICMR2 &= ~(1 << (irq - 32));
172 else
173 *IXP4XX_ICMR &= ~(1 << irq);
174}
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176static void ixp4xx_irq_ack(unsigned int irq)
177{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 int line = (irq < 32) ? irq2gpio[irq] : -1;
179
180 if (line >= 0)
Deepak Saxenaf7e8bbb82006-01-04 17:17:10 +0000181 *IXP4XX_GPIO_GPISR = (1 << line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
183
184/*
185 * Level triggered interrupts on GPIO lines can only be cleared when the
186 * interrupt condition disappears.
187 */
Kevin Hilman984d1152006-11-03 01:47:20 +0100188static void ixp4xx_irq_unmask(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
Kevin Hilman984d1152006-11-03 01:47:20 +0100190 if (!(ixp4xx_irq_edge & (1 << irq)))
191 ixp4xx_irq_ack(irq);
192
193 if (cpu_is_ixp46x() && irq >= 32)
194 *IXP4XX_ICMR2 |= (1 << (irq - 32));
195 else
196 *IXP4XX_ICMR |= (1 << irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
Russell King10dd5ce2006-11-23 11:41:32 +0000199static struct irq_chip ixp4xx_irq_chip = {
Kevin Hilman984d1152006-11-03 01:47:20 +0100200 .name = "IXP4xx",
Russell King2be863c2005-09-06 23:13:17 +0100201 .ack = ixp4xx_irq_ack,
202 .mask = ixp4xx_irq_mask,
203 .unmask = ixp4xx_irq_unmask,
204 .set_type = ixp4xx_set_irq_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205};
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207void __init ixp4xx_init_irq(void)
208{
209 int i = 0;
210
211 /* Route all sources to IRQ instead of FIQ */
212 *IXP4XX_ICLR = 0x0;
213
214 /* Disable all interrupt */
215 *IXP4XX_ICMR = 0x0;
216
217 if (cpu_is_ixp46x()) {
218 /* Route upper 32 sources to IRQ instead of FIQ */
219 *IXP4XX_ICLR2 = 0x00;
220
221 /* Disable upper 32 interrupts */
222 *IXP4XX_ICMR2 = 0x00;
223 }
224
225 /* Default to all level triggered */
Kevin Hilman984d1152006-11-03 01:47:20 +0100226 for(i = 0; i < NR_IRQS; i++) {
227 set_irq_chip(i, &ixp4xx_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +0000228 set_irq_handler(i, handle_level_irq);
Kevin Hilman984d1152006-11-03 01:47:20 +0100229 set_irq_flags(i, IRQF_VALID);
230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
233
234/*************************************************************************
235 * IXP4xx timer tick
236 * We use OS timer1 on the CPU for the timer tick and the timestamp
237 * counter as a source of real clock ticks to account for missed jiffies.
238 *************************************************************************/
239
240static unsigned volatile last_jiffy_time;
241
242#define CLOCK_TICKS_PER_USEC ((CLOCK_TICK_RATE + USEC_PER_SEC/2) / USEC_PER_SEC)
243
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700244static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 write_seqlock(&xtime_lock);
247
248 /* Clear Pending Interrupt by writing '1' to it */
249 *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
250
251 /*
252 * Catch up with the real idea of time
253 */
Lennert Buytenhekf869afa2006-06-22 10:30:53 +0100254 while ((signed long)(*IXP4XX_OSTS - last_jiffy_time) >= LATCH) {
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700255 timer_tick();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 last_jiffy_time += LATCH;
257 }
258
259 write_sequnlock(&xtime_lock);
260
261 return IRQ_HANDLED;
262}
263
264static struct irqaction ixp4xx_timer_irq = {
265 .name = "IXP4xx Timer Tick",
Thomas Gleixner52e405e2006-07-03 02:20:05 +0200266 .flags = IRQF_DISABLED | IRQF_TIMER,
Russell King09b8b5f2005-06-26 17:06:36 +0100267 .handler = ixp4xx_timer_interrupt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268};
269
270static void __init ixp4xx_timer_init(void)
271{
272 /* Clear Pending Interrupt by writing '1' to it */
273 *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
274
275 /* Setup the Timer counter value */
276 *IXP4XX_OSRT1 = (LATCH & ~IXP4XX_OST_RELOAD_MASK) | IXP4XX_OST_ENABLE;
277
278 /* Reset time-stamp counter */
279 *IXP4XX_OSTS = 0;
280 last_jiffy_time = 0;
281
282 /* Connect the interrupt handler and enable the interrupt */
283 setup_irq(IRQ_IXP4XX_TIMER1, &ixp4xx_timer_irq);
284}
285
286struct sys_timer ixp4xx_timer = {
287 .init = ixp4xx_timer_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288};
289
Milan Svobodae520a362006-12-01 11:36:41 +0100290static struct pxa2xx_udc_mach_info ixp4xx_udc_info;
291
292void __init ixp4xx_set_udc_info(struct pxa2xx_udc_mach_info *info)
293{
294 memcpy(&ixp4xx_udc_info, info, sizeof *info);
295}
296
297static struct resource ixp4xx_udc_resources[] = {
298 [0] = {
299 .start = 0xc800b000,
300 .end = 0xc800bfff,
301 .flags = IORESOURCE_MEM,
302 },
303 [1] = {
304 .start = IRQ_IXP4XX_USB,
305 .end = IRQ_IXP4XX_USB,
306 .flags = IORESOURCE_IRQ,
307 },
308};
309
310/*
311 * USB device controller. The IXP4xx uses the same controller as PXA2XX,
312 * so we just use the same device.
313 */
314static struct platform_device ixp4xx_udc_device = {
315 .name = "pxa2xx-udc",
316 .id = -1,
317 .num_resources = 2,
318 .resource = ixp4xx_udc_resources,
319 .dev = {
320 .platform_data = &ixp4xx_udc_info,
321 },
322};
323
324static struct platform_device *ixp4xx_devices[] __initdata = {
325 &ixp4xx_udc_device,
326};
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328static struct resource ixp46x_i2c_resources[] = {
329 [0] = {
330 .start = 0xc8011000,
331 .end = 0xc801101c,
332 .flags = IORESOURCE_MEM,
333 },
334 [1] = {
335 .start = IRQ_IXP4XX_I2C,
336 .end = IRQ_IXP4XX_I2C,
337 .flags = IORESOURCE_IRQ
338 }
339};
340
341/*
342 * I2C controller. The IXP46x uses the same block as the IOP3xx, so
343 * we just use the same device name.
344 */
345static struct platform_device ixp46x_i2c_controller = {
346 .name = "IOP3xx-I2C",
347 .id = 0,
348 .num_resources = 2,
349 .resource = ixp46x_i2c_resources
350};
351
352static struct platform_device *ixp46x_devices[] __initdata = {
353 &ixp46x_i2c_controller
354};
355
Deepak Saxena54e269e2006-01-05 20:59:29 +0000356unsigned long ixp4xx_exp_bus_size;
David Vrabel1e74c892006-01-18 22:46:43 +0000357EXPORT_SYMBOL(ixp4xx_exp_bus_size);
Deepak Saxena54e269e2006-01-05 20:59:29 +0000358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359void __init ixp4xx_sys_init(void)
360{
Deepak Saxena54e269e2006-01-05 20:59:29 +0000361 ixp4xx_exp_bus_size = SZ_16M;
362
Milan Svobodae520a362006-12-01 11:36:41 +0100363 platform_add_devices(ixp4xx_devices, ARRAY_SIZE(ixp4xx_devices));
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 if (cpu_is_ixp46x()) {
Deepak Saxena54e269e2006-01-05 20:59:29 +0000366 int region;
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 platform_add_devices(ixp46x_devices,
369 ARRAY_SIZE(ixp46x_devices));
Deepak Saxena54e269e2006-01-05 20:59:29 +0000370
371 for (region = 0; region < 7; region++) {
372 if((*(IXP4XX_EXP_REG(0x4 * region)) & 0x200)) {
373 ixp4xx_exp_bus_size = SZ_32M;
374 break;
375 }
376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
Deepak Saxena54e269e2006-01-05 20:59:29 +0000378
David Vrabel1e74c892006-01-18 22:46:43 +0000379 printk("IXP4xx: Using %luMiB expansion bus window size\n",
Deepak Saxena54e269e2006-01-05 20:59:29 +0000380 ixp4xx_exp_bus_size >> 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381}
382
Kevin Hilman84904d02006-09-22 00:58:57 +0100383cycle_t ixp4xx_get_cycles(void)
384{
385 return *IXP4XX_OSTS;
386}
387
388static struct clocksource clocksource_ixp4xx = {
389 .name = "OSTS",
390 .rating = 200,
391 .read = ixp4xx_get_cycles,
392 .mask = CLOCKSOURCE_MASK(32),
393 .shift = 20,
394 .is_continuous = 1,
395};
396
397unsigned long ixp4xx_timer_freq = FREQ;
398static int __init ixp4xx_clocksource_init(void)
399{
400 clocksource_ixp4xx.mult =
401 clocksource_hz2mult(ixp4xx_timer_freq,
402 clocksource_ixp4xx.shift);
403 clocksource_register(&clocksource_ixp4xx);
404
405 return 0;
406}
407
408device_initcall(ixp4xx_clocksource_init);