]> git.ipfire.org Git - thirdparty/linux.git/blame - arch/arm/mach-ixp4xx/common.c
Linux 3.4
[thirdparty/linux.git] / arch / arm / mach-ixp4xx / common.c
CommitLineData
1da177e4
LT
1/*
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
1da177e4
LT
16#include <linux/kernel.h>
17#include <linux/mm.h>
18#include <linux/init.h>
19#include <linux/serial.h>
1da177e4 20#include <linux/tty.h>
d052d1be 21#include <linux/platform_device.h>
1da177e4 22#include <linux/serial_core.h>
1da177e4
LT
23#include <linux/interrupt.h>
24#include <linux/bitops.h>
25#include <linux/time.h>
26#include <linux/timex.h>
84904d0e 27#include <linux/clocksource.h>
e32f1502 28#include <linux/clockchips.h>
fced80c7 29#include <linux/io.h>
dc28094b 30#include <linux/export.h>
1da177e4 31
a09e64fb
RK
32#include <mach/udc.h>
33#include <mach/hardware.h>
f449588c 34#include <mach/io.h>
1da177e4 35#include <asm/uaccess.h>
1da177e4
LT
36#include <asm/pgtable.h>
37#include <asm/page.h>
38#include <asm/irq.h>
5b0d495c 39#include <asm/sched_clock.h>
86dfe446 40#include <asm/system_misc.h>
1da177e4
LT
41
42#include <asm/mach/map.h>
43#include <asm/mach/irq.h>
44#include <asm/mach/time.h>
45
ceb69a89
MP
46static void __init ixp4xx_clocksource_init(void);
47static void __init ixp4xx_clockevent_init(void);
e32f1502 48static struct clock_event_device clockevent_ixp4xx;
f9a8ca1c 49
1da177e4
LT
50/*************************************************************************
51 * IXP4xx chipset I/O mapping
52 *************************************************************************/
53static struct map_desc ixp4xx_io_desc[] __initdata = {
54 { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
55 .virtual = IXP4XX_PERIPHERAL_BASE_VIRT,
87fe04bd 56 .pfn = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
1da177e4
LT
57 .length = IXP4XX_PERIPHERAL_REGION_SIZE,
58 .type = MT_DEVICE
59 }, { /* Expansion Bus Config Registers */
60 .virtual = IXP4XX_EXP_CFG_BASE_VIRT,
87fe04bd 61 .pfn = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
1da177e4
LT
62 .length = IXP4XX_EXP_CFG_REGION_SIZE,
63 .type = MT_DEVICE
64 }, { /* PCI Registers */
65 .virtual = IXP4XX_PCI_CFG_BASE_VIRT,
87fe04bd 66 .pfn = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
1da177e4
LT
67 .length = IXP4XX_PCI_CFG_REGION_SIZE,
68 .type = MT_DEVICE
5932ae3f
DS
69 },
70#ifdef CONFIG_DEBUG_LL
71 { /* Debug UART mapping */
72 .virtual = IXP4XX_DEBUG_UART_BASE_VIRT,
87fe04bd 73 .pfn = __phys_to_pfn(IXP4XX_DEBUG_UART_BASE_PHYS),
5932ae3f
DS
74 .length = IXP4XX_DEBUG_UART_REGION_SIZE,
75 .type = MT_DEVICE
1da177e4 76 }
5932ae3f 77#endif
1da177e4
LT
78};
79
80void __init ixp4xx_map_io(void)
81{
82 iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
83}
84
85
86/*************************************************************************
87 * IXP4xx chipset IRQ handling
88 *
89 * TODO: GPIO IRQs should be marked invalid until the user of the IRQ
90 * (be it PCI or something else) configures that GPIO line
91 * as an IRQ.
92 **************************************************************************/
bdf82b59
DS
93enum ixp4xx_irq_type {
94 IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
95};
96
984d115b
KH
97/* Each bit represents an IRQ: 1: edge-triggered, 0: level triggered */
98static unsigned long long ixp4xx_irq_edge = 0;
bdf82b59
DS
99
100/*
101 * IRQ -> GPIO mapping table
102 */
6cc1b658 103static signed char irq2gpio[32] = {
bdf82b59
DS
104 -1, -1, -1, -1, -1, -1, 0, 1,
105 -1, -1, -1, -1, -1, -1, -1, -1,
106 -1, -1, -1, 2, 3, 4, 5, 6,
107 7, 8, 9, 10, 11, 12, -1, -1,
108};
109
25735d10
MS
110int gpio_to_irq(int gpio)
111{
112 int irq;
113
114 for (irq = 0; irq < 32; irq++) {
115 if (irq2gpio[irq] == gpio)
116 return irq;
117 }
118 return -EINVAL;
119}
120EXPORT_SYMBOL(gpio_to_irq);
121
efec194f 122int irq_to_gpio(unsigned int irq)
25735d10
MS
123{
124 int gpio = (irq < 32) ? irq2gpio[irq] : -EINVAL;
125
126 if (gpio == -1)
127 return -EINVAL;
128
129 return gpio;
130}
131EXPORT_SYMBOL(irq_to_gpio);
132
ee04087a 133static int ixp4xx_set_irq_type(struct irq_data *d, unsigned int type)
bdf82b59 134{
ee04087a 135 int line = irq2gpio[d->irq];
bdf82b59
DS
136 u32 int_style;
137 enum ixp4xx_irq_type irq_type;
138 volatile u32 *int_reg;
139
140 /*
141 * Only for GPIO IRQs
142 */
143 if (line < 0)
144 return -EINVAL;
145