blob: 3248bc9b94955ba934c914c6aef4763ae4e9a1c2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Nicolas Pitre6f475c02005-10-28 16:39:33 +010037#include <asm/arch/irda.h>
Russell Kingeb9181a2005-09-29 09:49:25 +010038#include <asm/arch/i2c.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#include "generic.h"
41
42/*
43 * Handy function to set GPIO alternate functions
44 */
45
46void 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
67EXPORT_SYMBOL(pxa_gpio_mode);
68
69/*
70 * Routine to safely enable or disable a clock in the CKEN
71 */
72void 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
85EXPORT_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 */
95static struct map_desc standard_io_desc[] __initdata = {
Deepak Saxena6f9182e2005-10-28 15:19:01 +010096 { /* 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132};
133
134void __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
141static 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
154static u64 pxamci_dmamask = 0xffffffffUL;
155
156static 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
167void __init pxa_set_mci_info(struct pxamci_platform_data *info)
168{
169 pxamci_device.dev.platform_data = info;
170}
171
172
173static struct pxa2xx_udc_mach_info pxa_udc_info;
174
175void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
176{
177 memcpy(&pxa_udc_info, info, sizeof *info);
178}
179
180static 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
193static u64 udc_dma_mask = ~(u32)0;
194
195static 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
206static struct pxafb_mach_info pxa_fb_info;
207
208void __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
213static 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
226static u64 fb_dma_mask = ~(u64)0;
227
228static 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
Richard Purdiecb38c562005-10-14 16:07:25 +0100240void __init set_pxa_fb_parent(struct device *parent_dev)
241{
242 pxafb_device.dev.parent = parent_dev;
243}
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245static struct platform_device ffuart_device = {
246 .name = "pxa2xx-uart",
247 .id = 0,
248};
249static struct platform_device btuart_device = {
250 .name = "pxa2xx-uart",
251 .id = 1,
252};
253static struct platform_device stuart_device = {
254 .name = "pxa2xx-uart",
255 .id = 2,
256};
Matt Reimerd9e29642005-10-28 16:25:02 +0100257static struct platform_device hwuart_device = {
258 .name = "pxa2xx-uart",
259 .id = 3,
260};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Russell Kingbb9bffc2005-04-30 13:26:06 +0100262static 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
274static 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
281void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
282{
283 i2c_device.dev.platform_data = info;
284}
285
Matt Reimerb2640b42005-10-20 23:21:18 +0100286static 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
298static struct platform_device i2s_device = {
299 .name = "pxa2xx-i2s",
300 .id = -1,
Ian Campbellb5723522005-10-28 15:31:48 +0100301 .resource = i2s_resources,
Matt Reimerb2640b42005-10-20 23:21:18 +0100302 .num_resources = ARRAY_SIZE(i2s_resources),
303};
304
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100305static u64 pxaficp_dmamask = ~(u32)0;
306
307static 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
316void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
317{
318 pxaficp_device.dev.platform_data = info;
319}
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321static struct platform_device *devices[] __initdata = {
322 &pxamci_device,
323 &udc_device,
324 &pxafb_device,
325 &ffuart_device,
326 &btuart_device,
327 &stuart_device,
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100328 &pxaficp_device,
Russell Kingbb9bffc2005-04-30 13:26:06 +0100329 &i2c_device,
Matt Reimerb2640b42005-10-20 23:21:18 +0100330 &i2s_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331};
332
333static int __init pxa_init(void)
334{
Matt Reimerd9e29642005-10-28 16:25:02 +0100335 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348}
349
350subsys_initcall(pxa_init);