blob: 6ae605857ca9bfb6764bfbe68761ff960ba35ddb [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>
Russell Kingd052d1b2005-10-29 19:07:23 +010023#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/ioport.h>
25#include <linux/pm.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080026#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Nicolas Pitre2dc20a52006-12-04 20:42:09 +010028#include <linux/sched.h>
29#include <asm/cnt32_to_63.h>
30#include <asm/div64.h>
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/hardware.h>
33#include <asm/irq.h>
34#include <asm/system.h>
35#include <asm/pgtable.h>
36#include <asm/mach/map.h>
37
38#include <asm/arch/pxa-regs.h>
39#include <asm/arch/udc.h>
40#include <asm/arch/pxafb.h>
41#include <asm/arch/mmc.h>
Nicolas Pitre6f475c02005-10-28 16:39:33 +010042#include <asm/arch/irda.h>
Russell Kingeb9181a2005-09-29 09:49:25 +010043#include <asm/arch/i2c.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#include "generic.h"
46
47/*
Nicolas Pitre2dc20a52006-12-04 20:42:09 +010048 * This is the PXA2xx sched_clock implementation. This has a resolution
49 * of at least 308ns and a maximum value that depends on the value of
50 * CLOCK_TICK_RATE.
51 *
52 * The return value is guaranteed to be monotonic in that range as
53 * long as there is always less than 582 seconds between successive
54 * calls to this function.
55 */
56unsigned long long sched_clock(void)
57{
58 unsigned long long v = cnt32_to_63(OSCR);
59 /* Note: top bit ov v needs cleared unless multiplier is even. */
60
61#if CLOCK_TICK_RATE == 3686400
62 /* 1E9 / 3686400 => 78125 / 288, max value = 32025597s (370 days). */
63 /* The <<1 is used to get rid of tick.hi top bit */
64 v *= 78125<<1;
65 do_div(v, 288<<1);
66#elif CLOCK_TICK_RATE == 3250000
67 /* 1E9 / 3250000 => 4000 / 13, max value = 709490156s (8211 days) */
68 v *= 4000;
69 do_div(v, 13);
70#elif CLOCK_TICK_RATE == 3249600
71 /* 1E9 / 3249600 => 625000 / 2031, max value = 4541295s (52 days) */
72 v *= 625000;
73 do_div(v, 2031);
74#else
75#warning "consider fixing sched_clock for your value of CLOCK_TICK_RATE"
76 /*
77 * 96-bit math to perform tick * NSEC_PER_SEC / CLOCK_TICK_RATE for
78 * any value of CLOCK_TICK_RATE. Max value is in the 80 thousand
79 * years range which is nice, but with higher computation cost.
80 */
81 {
82 union {
83 unsigned long long val;
84 struct { unsigned long lo, hi; };
85 } x;
86 unsigned long long y;
87
88 x.val = v;
89 x.hi &= 0x7fffffff;
90 y = (unsigned long long)x.lo * NSEC_PER_SEC;
91 x.lo = y;
92 y = (y >> 32) + (unsigned long long)x.hi * NSEC_PER_SEC;
93 x.hi = do_div(y, CLOCK_TICK_RATE);
94 do_div(x.val, CLOCK_TICK_RATE);
95 x.hi += y;
96 v = x.val;
97 }
98#endif
99
100 return v;
101}
102
103/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 * Handy function to set GPIO alternate functions
105 */
106
107void pxa_gpio_mode(int gpio_mode)
108{
109 unsigned long flags;
110 int gpio = gpio_mode & GPIO_MD_MASK_NR;
111 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
112 int gafr;
113
114 local_irq_save(flags);
115 if (gpio_mode & GPIO_DFLT_LOW)
116 GPCR(gpio) = GPIO_bit(gpio);
117 else if (gpio_mode & GPIO_DFLT_HIGH)
118 GPSR(gpio) = GPIO_bit(gpio);
119 if (gpio_mode & GPIO_MD_MASK_DIR)
120 GPDR(gpio) |= GPIO_bit(gpio);
121 else
122 GPDR(gpio) &= ~GPIO_bit(gpio);
123 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
124 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
125 local_irq_restore(flags);
126}
127
128EXPORT_SYMBOL(pxa_gpio_mode);
129
130/*
131 * Routine to safely enable or disable a clock in the CKEN
132 */
133void pxa_set_cken(int clock, int enable)
134{
135 unsigned long flags;
136 local_irq_save(flags);
137
138 if (enable)
139 CKEN |= clock;
140 else
141 CKEN &= ~clock;
142
143 local_irq_restore(flags);
144}
145
146EXPORT_SYMBOL(pxa_set_cken);
147
148/*
149 * Intel PXA2xx internal register mapping.
150 *
151 * Note 1: not all PXA2xx variants implement all those addresses.
152 *
153 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
154 * and cache flush area.
155 */
156static struct map_desc standard_io_desc[] __initdata = {
Deepak Saxena6f9182e2005-10-28 15:19:01 +0100157 { /* Devs */
158 .virtual = 0xf2000000,
159 .pfn = __phys_to_pfn(0x40000000),
160 .length = 0x02000000,
161 .type = MT_DEVICE
162 }, { /* LCD */
163 .virtual = 0xf4000000,
164 .pfn = __phys_to_pfn(0x44000000),
165 .length = 0x00100000,
166 .type = MT_DEVICE
167 }, { /* Mem Ctl */
168 .virtual = 0xf6000000,
169 .pfn = __phys_to_pfn(0x48000000),
170 .length = 0x00100000,
171 .type = MT_DEVICE
172 }, { /* USB host */
173 .virtual = 0xf8000000,
174 .pfn = __phys_to_pfn(0x4c000000),
175 .length = 0x00100000,
176 .type = MT_DEVICE
177 }, { /* Camera */
178 .virtual = 0xfa000000,
179 .pfn = __phys_to_pfn(0x50000000),
180 .length = 0x00100000,
181 .type = MT_DEVICE
182 }, { /* IMem ctl */
183 .virtual = 0xfe000000,
184 .pfn = __phys_to_pfn(0x58000000),
185 .length = 0x00100000,
186 .type = MT_DEVICE
187 }, { /* UNCACHED_PHYS_0 */
188 .virtual = 0xff000000,
189 .pfn = __phys_to_pfn(0x00000000),
190 .length = 0x00100000,
191 .type = MT_DEVICE
192 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193};
194
195void __init pxa_map_io(void)
196{
197 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
198 get_clk_frequency_khz(1);
199}
200
201
202static struct resource pxamci_resources[] = {
203 [0] = {
204 .start = 0x41100000,
205 .end = 0x41100fff,
206 .flags = IORESOURCE_MEM,
207 },
208 [1] = {
209 .start = IRQ_MMC,
210 .end = IRQ_MMC,
211 .flags = IORESOURCE_IRQ,
212 },
213};
214
215static u64 pxamci_dmamask = 0xffffffffUL;
216
217static struct platform_device pxamci_device = {
218 .name = "pxa2xx-mci",
219 .id = -1,
220 .dev = {
221 .dma_mask = &pxamci_dmamask,
222 .coherent_dma_mask = 0xffffffff,
223 },
224 .num_resources = ARRAY_SIZE(pxamci_resources),
225 .resource = pxamci_resources,
226};
227
228void __init pxa_set_mci_info(struct pxamci_platform_data *info)
229{
230 pxamci_device.dev.platform_data = info;
231}
232
233
234static struct pxa2xx_udc_mach_info pxa_udc_info;
235
236void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
237{
238 memcpy(&pxa_udc_info, info, sizeof *info);
239}
240
241static struct resource pxa2xx_udc_resources[] = {
242 [0] = {
243 .start = 0x40600000,
244 .end = 0x4060ffff,
245 .flags = IORESOURCE_MEM,
246 },
247 [1] = {
248 .start = IRQ_USB,
249 .end = IRQ_USB,
250 .flags = IORESOURCE_IRQ,
251 },
252};
253
254static u64 udc_dma_mask = ~(u32)0;
255
256static struct platform_device udc_device = {
257 .name = "pxa2xx-udc",
258 .id = -1,
259 .resource = pxa2xx_udc_resources,
260 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
261 .dev = {
262 .platform_data = &pxa_udc_info,
263 .dma_mask = &udc_dma_mask,
264 }
265};
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267static struct resource pxafb_resources[] = {
268 [0] = {
269 .start = 0x44000000,
270 .end = 0x4400ffff,
271 .flags = IORESOURCE_MEM,
272 },
273 [1] = {
274 .start = IRQ_LCD,
275 .end = IRQ_LCD,
276 .flags = IORESOURCE_IRQ,
277 },
278};
279
280static u64 fb_dma_mask = ~(u64)0;
281
282static struct platform_device pxafb_device = {
283 .name = "pxa2xx-fb",
284 .id = -1,
285 .dev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 .dma_mask = &fb_dma_mask,
287 .coherent_dma_mask = 0xffffffff,
288 },
289 .num_resources = ARRAY_SIZE(pxafb_resources),
290 .resource = pxafb_resources,
291};
292
Richard Purdied14b2722006-09-20 22:54:21 +0100293void __init set_pxa_fb_info(struct pxafb_mach_info *info)
294{
295 pxafb_device.dev.platform_data = info;
296}
297
Richard Purdiecb38c562005-10-14 16:07:25 +0100298void __init set_pxa_fb_parent(struct device *parent_dev)
299{
300 pxafb_device.dev.parent = parent_dev;
301}
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303static struct platform_device ffuart_device = {
304 .name = "pxa2xx-uart",
305 .id = 0,
306};
307static struct platform_device btuart_device = {
308 .name = "pxa2xx-uart",
309 .id = 1,
310};
311static struct platform_device stuart_device = {
312 .name = "pxa2xx-uart",
313 .id = 2,
314};
Matt Reimerd9e29642005-10-28 16:25:02 +0100315static struct platform_device hwuart_device = {
316 .name = "pxa2xx-uart",
317 .id = 3,
318};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Russell Kingbb9bffc2005-04-30 13:26:06 +0100320static struct resource i2c_resources[] = {
321 {
322 .start = 0x40301680,
323 .end = 0x403016a3,
324 .flags = IORESOURCE_MEM,
325 }, {
326 .start = IRQ_I2C,
327 .end = IRQ_I2C,
328 .flags = IORESOURCE_IRQ,
329 },
330};
331
332static struct platform_device i2c_device = {
333 .name = "pxa2xx-i2c",
334 .id = 0,
335 .resource = i2c_resources,
336 .num_resources = ARRAY_SIZE(i2c_resources),
337};
338
339void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
340{
341 i2c_device.dev.platform_data = info;
342}
343
Matt Reimerb2640b42005-10-20 23:21:18 +0100344static struct resource i2s_resources[] = {
345 {
346 .start = 0x40400000,
347 .end = 0x40400083,
348 .flags = IORESOURCE_MEM,
349 }, {
350 .start = IRQ_I2S,
351 .end = IRQ_I2S,
352 .flags = IORESOURCE_IRQ,
353 },
354};
355
356static struct platform_device i2s_device = {
357 .name = "pxa2xx-i2s",
358 .id = -1,
Ian Campbellb5723522005-10-28 15:31:48 +0100359 .resource = i2s_resources,
Matt Reimerb2640b42005-10-20 23:21:18 +0100360 .num_resources = ARRAY_SIZE(i2s_resources),
361};
362
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100363static u64 pxaficp_dmamask = ~(u32)0;
364
365static struct platform_device pxaficp_device = {
366 .name = "pxa2xx-ir",
367 .id = -1,
368 .dev = {
369 .dma_mask = &pxaficp_dmamask,
370 .coherent_dma_mask = 0xffffffff,
371 },
372};
373
374void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
375{
376 pxaficp_device.dev.platform_data = info;
377}
378
Richard Purdiee842f1c2006-03-27 01:16:46 -0800379static struct platform_device pxartc_device = {
380 .name = "sa1100-rtc",
381 .id = -1,
382};
383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384static struct platform_device *devices[] __initdata = {
385 &pxamci_device,
386 &udc_device,
387 &pxafb_device,
388 &ffuart_device,
389 &btuart_device,
390 &stuart_device,
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100391 &pxaficp_device,
Russell Kingbb9bffc2005-04-30 13:26:06 +0100392 &i2c_device,
Matt Reimerb2640b42005-10-20 23:21:18 +0100393 &i2s_device,
Richard Purdiee842f1c2006-03-27 01:16:46 -0800394 &pxartc_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395};
396
397static int __init pxa_init(void)
398{
Matt Reimerd9e29642005-10-28 16:25:02 +0100399 int cpuid, ret;
400
401 ret = platform_add_devices(devices, ARRAY_SIZE(devices));
402 if (ret)
403 return ret;
404
405 /* Only add HWUART for PXA255/26x; PXA210/250/27x do not have it. */
406 cpuid = read_cpuid(CPUID_ID);
407 if (((cpuid >> 4) & 0xfff) == 0x2d0 ||
408 ((cpuid >> 4) & 0xfff) == 0x290)
409 ret = platform_device_register(&hwuart_device);
410
411 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414subsys_initcall(pxa_init);