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