Merge ../bleed-2.6
[deliverable/linux.git] / arch / arm / mach-pxa / generic.c
1 /*
2 * linux/arch/arm/mach-pxa/generic.c
3 *
4 * Author: Nicolas Pitre
5 * Created: Jun 15, 2001
6 * Copyright: MontaVista Software Inc.
7 *
8 * Code common to all PXA machines.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * Since this file should be linked before any other machine specific file,
15 * the __initcall() here will be executed first. This serves as default
16 * initialization stuff for PXA machines which can be overridden later if
17 * need be.
18 */
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/delay.h>
23 #include <linux/device.h>
24 #include <linux/ioport.h>
25 #include <linux/pm.h>
26
27 #include <asm/hardware.h>
28 #include <asm/irq.h>
29 #include <asm/system.h>
30 #include <asm/pgtable.h>
31 #include <asm/mach/map.h>
32
33 #include <asm/arch/pxa-regs.h>
34 #include <asm/arch/udc.h>
35 #include <asm/arch/pxafb.h>
36 #include <asm/arch/mmc.h>
37 #include <asm/arch/irda.h>
38 #include <asm/arch/i2c.h>
39
40 #include "generic.h"
41
42 /*
43 * Handy function to set GPIO alternate functions
44 */
45
46 void pxa_gpio_mode(int gpio_mode)
47 {
48 unsigned long flags;
49 int gpio = gpio_mode & GPIO_MD_MASK_NR;
50 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
51 int gafr;
52
53 local_irq_save(flags);
54 if (gpio_mode & GPIO_DFLT_LOW)
55 GPCR(gpio) = GPIO_bit(gpio);
56 else if (gpio_mode & GPIO_DFLT_HIGH)
57 GPSR(gpio) = GPIO_bit(gpio);
58 if (gpio_mode & GPIO_MD_MASK_DIR)
59 GPDR(gpio) |= GPIO_bit(gpio);
60 else
61 GPDR(gpio) &= ~GPIO_bit(gpio);
62 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
63 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
64 local_irq_restore(flags);
65 }
66
67 EXPORT_SYMBOL(pxa_gpio_mode);
68
69 /*
70 * Routine to safely enable or disable a clock in the CKEN
71 */
72 void pxa_set_cken(int clock, int enable)
73 {
74 unsigned long flags;
75 local_irq_save(flags);
76
77 if (enable)
78 CKEN |= clock;
79 else
80 CKEN &= ~clock;
81
82 local_irq_restore(flags);
83 }
84
85 EXPORT_SYMBOL(pxa_set_cken);
86
87 /*
88 * Intel PXA2xx internal register mapping.
89 *
90 * Note 1: not all PXA2xx variants implement all those addresses.
91 *
92 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
93 * and cache flush area.
94 */
95 static struct map_desc standard_io_desc[] __initdata = {
96 { /* Devs */
97 .virtual = 0xf2000000,
98 .pfn = __phys_to_pfn(0x40000000),
99 .length = 0x02000000,
100 .type = MT_DEVICE
101 }, { /* LCD */
102 .virtual = 0xf4000000,
103 .pfn = __phys_to_pfn(0x44000000),
104 .length = 0x00100000,
105 .type = MT_DEVICE
106 }, { /* Mem Ctl */
107 .virtual = 0xf6000000,
108 .pfn = __phys_to_pfn(0x48000000),
109 .length = 0x00100000,
110 .type = MT_DEVICE
111 }, { /* USB host */
112 .virtual = 0xf8000000,
113 .pfn = __phys_to_pfn(0x4c000000),
114 .length = 0x00100000,
115 .type = MT_DEVICE
116 }, { /* Camera */
117 .virtual = 0xfa000000,
118 .pfn = __phys_to_pfn(0x50000000),
119 .length = 0x00100000,
120 .type = MT_DEVICE
121 }, { /* IMem ctl */
122 .virtual = 0xfe000000,
123 .pfn = __phys_to_pfn(0x58000000),
124 .length = 0x00100000,
125 .type = MT_DEVICE
126 }, { /* UNCACHED_PHYS_0 */
127 .virtual = 0xff000000,
128 .pfn = __phys_to_pfn(0x00000000),
129 .length = 0x00100000,
130 .type = MT_DEVICE
131 }
132 };
133
134 void __init pxa_map_io(void)
135 {
136 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
137 get_clk_frequency_khz(1);
138 }
139
140
141 static struct resource pxamci_resources[] = {
142 [0] = {
143 .start = 0x41100000,
144 .end = 0x41100fff,
145 .flags = IORESOURCE_MEM,
146 },
147 [1] = {
148 .start = IRQ_MMC,
149 .end = IRQ_MMC,
150 .flags = IORESOURCE_IRQ,
151 },
152 };
153
154 static u64 pxamci_dmamask = 0xffffffffUL;
155
156 static struct platform_device pxamci_device = {
157 .name = "pxa2xx-mci",
158 .id = -1,
159 .dev = {
160 .dma_mask = &pxamci_dmamask,
161 .coherent_dma_mask = 0xffffffff,
162 },
163 .num_resources = ARRAY_SIZE(pxamci_resources),
164 .resource = pxamci_resources,
165 };
166
167 void __init pxa_set_mci_info(struct pxamci_platform_data *info)
168 {
169 pxamci_device.dev.platform_data = info;
170 }
171
172
173 static struct pxa2xx_udc_mach_info pxa_udc_info;
174
175 void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
176 {
177 memcpy(&pxa_udc_info, info, sizeof *info);
178 }
179
180 static struct resource pxa2xx_udc_resources[] = {
181 [0] = {
182 .start = 0x40600000,
183 .end = 0x4060ffff,
184 .flags = IORESOURCE_MEM,
185 },
186 [1] = {
187 .start = IRQ_USB,
188 .end = IRQ_USB,
189 .flags = IORESOURCE_IRQ,
190 },
191 };
192
193 static u64 udc_dma_mask = ~(u32)0;
194
195 static struct platform_device udc_device = {
196 .name = "pxa2xx-udc",
197 .id = -1,
198 .resource = pxa2xx_udc_resources,
199 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
200 .dev = {
201 .platform_data = &pxa_udc_info,
202 .dma_mask = &udc_dma_mask,
203 }
204 };
205
206 static struct pxafb_mach_info pxa_fb_info;
207
208 void __init set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info)
209 {
210 memcpy(&pxa_fb_info,hard_pxa_fb_info,sizeof(struct pxafb_mach_info));
211 }
212
213 static struct resource pxafb_resources[] = {
214 [0] = {
215 .start = 0x44000000,
216 .end = 0x4400ffff,
217 .flags = IORESOURCE_MEM,
218 },
219 [1] = {
220 .start = IRQ_LCD,
221 .end = IRQ_LCD,
222 .flags = IORESOURCE_IRQ,
223 },
224 };
225
226 static u64 fb_dma_mask = ~(u64)0;
227
228 static struct platform_device pxafb_device = {
229 .name = "pxa2xx-fb",
230 .id = -1,
231 .dev = {
232 .platform_data = &pxa_fb_info,
233 .dma_mask = &fb_dma_mask,
234 .coherent_dma_mask = 0xffffffff,
235 },
236 .num_resources = ARRAY_SIZE(pxafb_resources),
237 .resource = pxafb_resources,
238 };
239
240 void __init set_pxa_fb_parent(struct device *parent_dev)
241 {
242 pxafb_device.dev.parent = parent_dev;
243 }
244
245 static struct platform_device ffuart_device = {
246 .name = "pxa2xx-uart",
247 .id = 0,
248 };
249 static struct platform_device btuart_device = {
250 .name = "pxa2xx-uart",
251 .id = 1,
252 };
253 static struct platform_device stuart_device = {
254 .name = "pxa2xx-uart",
255 .id = 2,
256 };
257 static struct platform_device hwuart_device = {
258 .name = "pxa2xx-uart",
259 .id = 3,
260 };
261
262 static struct resource i2c_resources[] = {
263 {
264 .start = 0x40301680,
265 .end = 0x403016a3,
266 .flags = IORESOURCE_MEM,
267 }, {
268 .start = IRQ_I2C,
269 .end = IRQ_I2C,
270 .flags = IORESOURCE_IRQ,
271 },
272 };
273
274 static struct platform_device i2c_device = {
275 .name = "pxa2xx-i2c",
276 .id = 0,
277 .resource = i2c_resources,
278 .num_resources = ARRAY_SIZE(i2c_resources),
279 };
280
281 void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
282 {
283 i2c_device.dev.platform_data = info;
284 }
285
286 static struct resource i2s_resources[] = {
287 {
288 .start = 0x40400000,
289 .end = 0x40400083,
290 .flags = IORESOURCE_MEM,
291 }, {
292 .start = IRQ_I2S,
293 .end = IRQ_I2S,
294 .flags = IORESOURCE_IRQ,
295 },
296 };
297
298 static struct platform_device i2s_device = {
299 .name = "pxa2xx-i2s",
300 .id = -1,
301 .resource = i2s_resources,
302 .num_resources = ARRAY_SIZE(i2s_resources),
303 };
304
305 static u64 pxaficp_dmamask = ~(u32)0;
306
307 static struct platform_device pxaficp_device = {
308 .name = "pxa2xx-ir",
309 .id = -1,
310 .dev = {
311 .dma_mask = &pxaficp_dmamask,
312 .coherent_dma_mask = 0xffffffff,
313 },
314 };
315
316 void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
317 {
318 pxaficp_device.dev.platform_data = info;
319 }
320
321 static struct platform_device *devices[] __initdata = {
322 &pxamci_device,
323 &udc_device,
324 &pxafb_device,
325 &ffuart_device,
326 &btuart_device,
327 &stuart_device,
328 &pxaficp_device,
329 &i2c_device,
330 &i2s_device,
331 };
332
333 static int __init pxa_init(void)
334 {
335 int cpuid, ret;
336
337 ret = platform_add_devices(devices, ARRAY_SIZE(devices));
338 if (ret)
339 return ret;
340
341 /* Only add HWUART for PXA255/26x; PXA210/250/27x do not have it. */
342 cpuid = read_cpuid(CPUID_ID);
343 if (((cpuid >> 4) & 0xfff) == 0x2d0 ||
344 ((cpuid >> 4) & 0xfff) == 0x290)
345 ret = platform_device_register(&hwuart_device);
346
347 return ret;
348 }
349
350 subsys_initcall(pxa_init);
This page took 0.03663 seconds and 5 git commands to generate.