2 * arch/arm/mach-ixp4xx/common.c
4 * Generic code shared across all IXP4XX platforms
6 * Maintainer: Deepak Saxena <dsaxena@plexity.net>
8 * Copyright 2002 (c) Intel Corporation
9 * Copyright 2003-2004 (c) MontaVista, Software, Inc.
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.
16 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/serial.h>
20 #include <linux/sched.h>
21 #include <linux/tty.h>
22 #include <linux/platform_device.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 #include <linux/clocksource.h>
31 #include <asm/arch/udc.h>
32 #include <asm/hardware.h>
33 #include <asm/uaccess.h>
35 #include <asm/pgtable.h>
39 #include <asm/mach/map.h>
40 #include <asm/mach/irq.h>
41 #include <asm/mach/time.h>
43 static int __init ixp4xx_clocksource_init(void);
45 /*************************************************************************
46 * IXP4xx chipset I/O mapping
47 *************************************************************************/
48 static struct map_desc ixp4xx_io_desc[] __initdata = {
49 { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
50 .virtual = IXP4XX_PERIPHERAL_BASE_VIRT,
51 .pfn = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
52 .length = IXP4XX_PERIPHERAL_REGION_SIZE,
54 }, { /* Expansion Bus Config Registers */
55 .virtual = IXP4XX_EXP_CFG_BASE_VIRT,
56 .pfn = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
57 .length = IXP4XX_EXP_CFG_REGION_SIZE,
59 }, { /* PCI Registers */
60 .virtual = IXP4XX_PCI_CFG_BASE_VIRT,
61 .pfn = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
62 .length = IXP4XX_PCI_CFG_REGION_SIZE,
65 #ifdef CONFIG_DEBUG_LL
66 { /* Debug UART mapping */
67 .virtual = IXP4XX_DEBUG_UART_BASE_VIRT,
68 .pfn = __phys_to_pfn(IXP4XX_DEBUG_UART_BASE_PHYS),
69 .length = IXP4XX_DEBUG_UART_REGION_SIZE,
75 void __init ixp4xx_map_io(void)
77 iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
81 /*************************************************************************
82 * IXP4xx chipset IRQ handling
84 * TODO: GPIO IRQs should be marked invalid until the user of the IRQ
85 * (be it PCI or something else) configures that GPIO line
87 **************************************************************************/
88 enum ixp4xx_irq_type {
89 IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
92 /* Each bit represents an IRQ: 1: edge-triggered, 0: level triggered */
93 static unsigned long long ixp4xx_irq_edge = 0;
96 * IRQ -> GPIO mapping table
98 static signed char irq2gpio[32] = {
99 -1, -1, -1, -1, -1, -1, 0, 1,
100 -1, -1, -1, -1, -1, -1, -1, -1,
101 -1, -1, -1, 2, 3, 4, 5, 6,
102 7, 8, 9, 10, 11, 12, -1, -1,
105 int gpio_to_irq(int gpio)
109 for (irq = 0; irq < 32; irq++) {
110 if (irq2gpio[irq] == gpio)
115 EXPORT_SYMBOL(gpio_to_irq);
117 int irq_to_gpio(int irq)
119 int gpio = (irq < 32) ? irq2gpio[irq] : -EINVAL;
126 EXPORT_SYMBOL(irq_to_gpio);
128 static int ixp4xx_set_irq_type(unsigned int irq, unsigned int type)
130 int line = irq2gpio[irq];
132 enum ixp4xx_irq_type irq_type;
133 volatile u32 *int_reg;
143 int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
144 irq_type = IXP4XX_IRQ_EDGE;
147 int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
148 irq_type = IXP4XX_IRQ_EDGE;
151 int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
152 irq_type = IXP4XX_IRQ_EDGE;
155 int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
156 irq_type = IXP4XX_IRQ_LEVEL;
159 int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
160 irq_type = IXP4XX_IRQ_LEVEL;
166 if (irq_type == IXP4XX_IRQ_EDGE)
167 ixp4xx_irq_edge |= (1 << irq);
169 ixp4xx_irq_edge &= ~(1 << irq);
171 if (line >= 8) { /* pins 8-15 */
173 int_reg = IXP4XX_GPIO_GPIT2R;
174 } else { /* pins 0-7 */
175 int_reg = IXP4XX_GPIO_GPIT1R;
178 /* Clear the style for the appropriate pin */
179 *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
180 (line * IXP4XX_GPIO_STYLE_SIZE));
182 *IXP4XX_GPIO_GPISR = (1 << line);
184 /* Set the new style */
185 *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
187 /* Configure the line as an input */
188 gpio_line_config(line, IXP4XX_GPIO_IN);
193 static void ixp4xx_irq_mask(unsigned int irq)
195 if (cpu_is_ixp46x() && irq >= 32)
196 *IXP4XX_ICMR2 &= ~(1 << (irq - 32));
198 *IXP4XX_ICMR &= ~(1 << irq);
201 static void ixp4xx_irq_ack(unsigned int irq)
203 int line = (irq < 32) ? irq2gpio[irq] : -1;
206 *IXP4XX_GPIO_GPISR = (1 << line);
210 * Level triggered interrupts on GPIO lines can only be cleared when the
211 * interrupt condition disappears.
213 static void ixp4xx_irq_unmask(unsigned int irq)
215 if (!(ixp4xx_irq_edge & (1 << irq)))
218 if (cpu_is_ixp46x() && irq >= 32)
219 *IXP4XX_ICMR2 |= (1 << (irq - 32));
221 *IXP4XX_ICMR |= (1 << irq);
224 static struct irq_chip ixp4xx_irq_chip = {
226 .ack = ixp4xx_irq_ack,
227 .mask = ixp4xx_irq_mask,
228 .unmask = ixp4xx_irq_unmask,
229 .set_type = ixp4xx_set_irq_type,
232 void __init ixp4xx_init_irq(void)
236 /* Route all sources to IRQ instead of FIQ */
239 /* Disable all interrupt */
242 if (cpu_is_ixp46x()) {
243 /* Route upper 32 sources to IRQ instead of FIQ */
244 *IXP4XX_ICLR2 = 0x00;
246 /* Disable upper 32 interrupts */
247 *IXP4XX_ICMR2 = 0x00;
250 /* Default to all level triggered */
251 for(i = 0; i < NR_IRQS; i++) {
252 set_irq_chip(i, &ixp4xx_irq_chip);
253 set_irq_handler(i, handle_level_irq);
254 set_irq_flags(i, IRQF_VALID);
259 /*************************************************************************
261 * We use OS timer1 on the CPU for the timer tick and the timestamp
262 * counter as a source of real clock ticks to account for missed jiffies.
263 *************************************************************************/
265 static unsigned volatile last_jiffy_time;
267 #define CLOCK_TICKS_PER_USEC ((CLOCK_TICK_RATE + USEC_PER_SEC/2) / USEC_PER_SEC)
269 static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id)
271 write_seqlock(&xtime_lock);
273 /* Clear Pending Interrupt by writing '1' to it */
274 *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
277 * Catch up with the real idea of time
279 while ((signed long)(*IXP4XX_OSTS - last_jiffy_time) >= LATCH) {
281 last_jiffy_time += LATCH;
284 write_sequnlock(&xtime_lock);
289 static struct irqaction ixp4xx_timer_irq = {
290 .name = "IXP4xx Timer Tick",
291 .flags = IRQF_DISABLED | IRQF_TIMER,
292 .handler = ixp4xx_timer_interrupt,
295 static void __init ixp4xx_timer_init(void)
297 /* Clear Pending Interrupt by writing '1' to it */
298 *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
300 /* Setup the Timer counter value */
301 *IXP4XX_OSRT1 = (LATCH & ~IXP4XX_OST_RELOAD_MASK) | IXP4XX_OST_ENABLE;
303 /* Reset time-stamp counter */
307 /* Connect the interrupt handler and enable the interrupt */
308 setup_irq(IRQ_IXP4XX_TIMER1, &ixp4xx_timer_irq);
310 ixp4xx_clocksource_init();
313 struct sys_timer ixp4xx_timer = {
314 .init = ixp4xx_timer_init,
317 static struct pxa2xx_udc_mach_info ixp4xx_udc_info;
319 void __init ixp4xx_set_udc_info(struct pxa2xx_udc_mach_info *info)
321 memcpy(&ixp4xx_udc_info, info, sizeof *info);
324 static struct resource ixp4xx_udc_resources[] = {
328 .flags = IORESOURCE_MEM,
331 .start = IRQ_IXP4XX_USB,
332 .end = IRQ_IXP4XX_USB,
333 .flags = IORESOURCE_IRQ,
338 * USB device controller. The IXP4xx uses the same controller as PXA2XX,
339 * so we just use the same device.
341 static struct platform_device ixp4xx_udc_device = {
342 .name = "pxa2xx-udc",
345 .resource = ixp4xx_udc_resources,
347 .platform_data = &ixp4xx_udc_info,
351 static struct platform_device *ixp4xx_devices[] __initdata = {
355 static struct resource ixp46x_i2c_resources[] = {
359 .flags = IORESOURCE_MEM,
362 .start = IRQ_IXP4XX_I2C,
363 .end = IRQ_IXP4XX_I2C,
364 .flags = IORESOURCE_IRQ
369 * I2C controller. The IXP46x uses the same block as the IOP3xx, so
370 * we just use the same device name.
372 static struct platform_device ixp46x_i2c_controller = {
373 .name = "IOP3xx-I2C",
376 .resource = ixp46x_i2c_resources
379 static struct platform_device *ixp46x_devices[] __initdata = {
380 &ixp46x_i2c_controller
383 unsigned long ixp4xx_exp_bus_size;
384 EXPORT_SYMBOL(ixp4xx_exp_bus_size);
386 void __init ixp4xx_sys_init(void)
388 ixp4xx_exp_bus_size = SZ_16M;
390 platform_add_devices(ixp4xx_devices, ARRAY_SIZE(ixp4xx_devices));
392 if (cpu_is_ixp46x()) {
395 platform_add_devices(ixp46x_devices,
396 ARRAY_SIZE(ixp46x_devices));
398 for (region = 0; region < 7; region++) {
399 if((*(IXP4XX_EXP_REG(0x4 * region)) & 0x200)) {
400 ixp4xx_exp_bus_size = SZ_32M;
406 printk("IXP4xx: Using %luMiB expansion bus window size\n",
407 ixp4xx_exp_bus_size >> 20);
410 cycle_t ixp4xx_get_cycles(void)
415 static struct clocksource clocksource_ixp4xx = {
418 .read = ixp4xx_get_cycles,
419 .mask = CLOCKSOURCE_MASK(32),
421 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
424 unsigned long ixp4xx_timer_freq = FREQ;
425 static int __init ixp4xx_clocksource_init(void)
427 clocksource_ixp4xx.mult =
428 clocksource_hz2mult(ixp4xx_timer_freq,
429 clocksource_ixp4xx.shift);
430 clocksource_register(&clocksource_ixp4xx);