blob: 296539b6359ca43af779f59e5fa078351c14195b [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>
Philipp Zabel3deac042007-02-20 13:58:15 -080039#include <asm/arch/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/arch/udc.h>
41#include <asm/arch/pxafb.h>
42#include <asm/arch/mmc.h>
Nicolas Pitre6f475c02005-10-28 16:39:33 +010043#include <asm/arch/irda.h>
Russell Kingeb9181a2005-09-29 09:49:25 +010044#include <asm/arch/i2c.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Russell King46c41e62007-05-15 15:39:36 +010046#include "devices.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include "generic.h"
48
49/*
Nicolas Pitre2dc20a52006-12-04 20:42:09 +010050 * This is the PXA2xx sched_clock implementation. This has a resolution
51 * of at least 308ns and a maximum value that depends on the value of
52 * CLOCK_TICK_RATE.
53 *
54 * The return value is guaranteed to be monotonic in that range as
55 * long as there is always less than 582 seconds between successive
56 * calls to this function.
57 */
58unsigned long long sched_clock(void)
59{
60 unsigned long long v = cnt32_to_63(OSCR);
61 /* Note: top bit ov v needs cleared unless multiplier is even. */
62
63#if CLOCK_TICK_RATE == 3686400
64 /* 1E9 / 3686400 => 78125 / 288, max value = 32025597s (370 days). */
65 /* The <<1 is used to get rid of tick.hi top bit */
66 v *= 78125<<1;
67 do_div(v, 288<<1);
68#elif CLOCK_TICK_RATE == 3250000
69 /* 1E9 / 3250000 => 4000 / 13, max value = 709490156s (8211 days) */
70 v *= 4000;
71 do_div(v, 13);
72#elif CLOCK_TICK_RATE == 3249600
73 /* 1E9 / 3249600 => 625000 / 2031, max value = 4541295s (52 days) */
74 v *= 625000;
75 do_div(v, 2031);
76#else
77#warning "consider fixing sched_clock for your value of CLOCK_TICK_RATE"
78 /*
79 * 96-bit math to perform tick * NSEC_PER_SEC / CLOCK_TICK_RATE for
80 * any value of CLOCK_TICK_RATE. Max value is in the 80 thousand
Nicolas Pitre0c48d312006-12-22 18:52:56 +010081 * years range and truncation to unsigned long long limits it to
82 * sched_clock's max range of ~584 years. This is nice but with
83 * higher computation cost.
Nicolas Pitre2dc20a52006-12-04 20:42:09 +010084 */
85 {
86 union {
87 unsigned long long val;
88 struct { unsigned long lo, hi; };
89 } x;
90 unsigned long long y;
91
92 x.val = v;
93 x.hi &= 0x7fffffff;
94 y = (unsigned long long)x.lo * NSEC_PER_SEC;
95 x.lo = y;
96 y = (y >> 32) + (unsigned long long)x.hi * NSEC_PER_SEC;
97 x.hi = do_div(y, CLOCK_TICK_RATE);
98 do_div(x.val, CLOCK_TICK_RATE);
99 x.hi += y;
100 v = x.val;
101 }
102#endif
103
104 return v;
105}
106
107/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 * Handy function to set GPIO alternate functions
109 */
110
Philipp Zabel3deac042007-02-20 13:58:15 -0800111int pxa_gpio_mode(int gpio_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
113 unsigned long flags;
114 int gpio = gpio_mode & GPIO_MD_MASK_NR;
115 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
116 int gafr;
117
Philipp Zabel3deac042007-02-20 13:58:15 -0800118 if (gpio > PXA_LAST_GPIO)
119 return -EINVAL;
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 local_irq_save(flags);
122 if (gpio_mode & GPIO_DFLT_LOW)
123 GPCR(gpio) = GPIO_bit(gpio);
124 else if (gpio_mode & GPIO_DFLT_HIGH)
125 GPSR(gpio) = GPIO_bit(gpio);
126 if (gpio_mode & GPIO_MD_MASK_DIR)
127 GPDR(gpio) |= GPIO_bit(gpio);
128 else
129 GPDR(gpio) &= ~GPIO_bit(gpio);
130 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
131 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
132 local_irq_restore(flags);
Philipp Zabel3deac042007-02-20 13:58:15 -0800133
134 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
136
137EXPORT_SYMBOL(pxa_gpio_mode);
138
139/*
Philipp Zabel3deac042007-02-20 13:58:15 -0800140 * Return GPIO level
141 */
142int pxa_gpio_get_value(unsigned gpio)
143{
144 return __gpio_get_value(gpio);
145}
146
147EXPORT_SYMBOL(pxa_gpio_get_value);
148
149/*
150 * Set output GPIO level
151 */
152void pxa_gpio_set_value(unsigned gpio, int value)
153{
154 __gpio_set_value(gpio, value);
155}
156
157EXPORT_SYMBOL(pxa_gpio_set_value);
158
159/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 * Routine to safely enable or disable a clock in the CKEN
161 */
162void pxa_set_cken(int clock, int enable)
163{
164 unsigned long flags;
165 local_irq_save(flags);
166
167 if (enable)
Eric Miao7053acb2007-04-05 04:07:20 +0100168 CKEN |= (1 << clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 else
Eric Miao7053acb2007-04-05 04:07:20 +0100170 CKEN &= ~(1 << clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 local_irq_restore(flags);
173}
174
175EXPORT_SYMBOL(pxa_set_cken);
176
177/*
178 * Intel PXA2xx internal register mapping.
179 *
180 * Note 1: not all PXA2xx variants implement all those addresses.
181 *
182 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
183 * and cache flush area.
184 */
185static struct map_desc standard_io_desc[] __initdata = {
Deepak Saxena6f9182e2005-10-28 15:19:01 +0100186 { /* Devs */
187 .virtual = 0xf2000000,
188 .pfn = __phys_to_pfn(0x40000000),
189 .length = 0x02000000,
190 .type = MT_DEVICE
191 }, { /* LCD */
192 .virtual = 0xf4000000,
193 .pfn = __phys_to_pfn(0x44000000),
194 .length = 0x00100000,
195 .type = MT_DEVICE
196 }, { /* Mem Ctl */
197 .virtual = 0xf6000000,
198 .pfn = __phys_to_pfn(0x48000000),
199 .length = 0x00100000,
200 .type = MT_DEVICE
201 }, { /* USB host */
202 .virtual = 0xf8000000,
203 .pfn = __phys_to_pfn(0x4c000000),
204 .length = 0x00100000,
205 .type = MT_DEVICE
206 }, { /* Camera */
207 .virtual = 0xfa000000,
208 .pfn = __phys_to_pfn(0x50000000),
209 .length = 0x00100000,
210 .type = MT_DEVICE
211 }, { /* IMem ctl */
212 .virtual = 0xfe000000,
213 .pfn = __phys_to_pfn(0x58000000),
214 .length = 0x00100000,
215 .type = MT_DEVICE
216 }, { /* UNCACHED_PHYS_0 */
217 .virtual = 0xff000000,
218 .pfn = __phys_to_pfn(0x00000000),
219 .length = 0x00100000,
220 .type = MT_DEVICE
221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222};
223
224void __init pxa_map_io(void)
225{
226 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
227 get_clk_frequency_khz(1);
228}
229
230
231static struct resource pxamci_resources[] = {
232 [0] = {
233 .start = 0x41100000,
234 .end = 0x41100fff,
235 .flags = IORESOURCE_MEM,
236 },
237 [1] = {
238 .start = IRQ_MMC,
239 .end = IRQ_MMC,
240 .flags = IORESOURCE_IRQ,
241 },
242};
243
244static u64 pxamci_dmamask = 0xffffffffUL;
245
Russell King34f32312007-05-15 10:39:49 +0100246struct platform_device pxamci_device = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 .name = "pxa2xx-mci",
248 .id = -1,
249 .dev = {
250 .dma_mask = &pxamci_dmamask,
251 .coherent_dma_mask = 0xffffffff,
252 },
253 .num_resources = ARRAY_SIZE(pxamci_resources),
254 .resource = pxamci_resources,
255};
256
257void __init pxa_set_mci_info(struct pxamci_platform_data *info)
258{
259 pxamci_device.dev.platform_data = info;
260}
261
262
263static struct pxa2xx_udc_mach_info pxa_udc_info;
264
265void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
266{
267 memcpy(&pxa_udc_info, info, sizeof *info);
268}
269
270static struct resource pxa2xx_udc_resources[] = {
271 [0] = {
272 .start = 0x40600000,
273 .end = 0x4060ffff,
274 .flags = IORESOURCE_MEM,
275 },
276 [1] = {
277 .start = IRQ_USB,
278 .end = IRQ_USB,
279 .flags = IORESOURCE_IRQ,
280 },
281};
282
283static u64 udc_dma_mask = ~(u32)0;
284
Russell King34f32312007-05-15 10:39:49 +0100285struct platform_device pxaudc_device = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 .name = "pxa2xx-udc",
287 .id = -1,
288 .resource = pxa2xx_udc_resources,
289 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
290 .dev = {
291 .platform_data = &pxa_udc_info,
292 .dma_mask = &udc_dma_mask,
293 }
294};
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296static struct resource pxafb_resources[] = {
297 [0] = {
298 .start = 0x44000000,
299 .end = 0x4400ffff,
300 .flags = IORESOURCE_MEM,
301 },
302 [1] = {
303 .start = IRQ_LCD,
304 .end = IRQ_LCD,
305 .flags = IORESOURCE_IRQ,
306 },
307};
308
309static u64 fb_dma_mask = ~(u64)0;
310
Russell King34f32312007-05-15 10:39:49 +0100311struct platform_device pxafb_device = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 .name = "pxa2xx-fb",
313 .id = -1,
314 .dev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 .dma_mask = &fb_dma_mask,
316 .coherent_dma_mask = 0xffffffff,
317 },
318 .num_resources = ARRAY_SIZE(pxafb_resources),
319 .resource = pxafb_resources,
320};
321
Richard Purdied14b2722006-09-20 22:54:21 +0100322void __init set_pxa_fb_info(struct pxafb_mach_info *info)
323{
324 pxafb_device.dev.platform_data = info;
325}
326
Richard Purdiecb38c562005-10-14 16:07:25 +0100327void __init set_pxa_fb_parent(struct device *parent_dev)
328{
329 pxafb_device.dev.parent = parent_dev;
330}
331
Russell King34f32312007-05-15 10:39:49 +0100332struct platform_device ffuart_device = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 .name = "pxa2xx-uart",
334 .id = 0,
335};
Russell King34f32312007-05-15 10:39:49 +0100336struct platform_device btuart_device = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 .name = "pxa2xx-uart",
338 .id = 1,
339};
Russell King34f32312007-05-15 10:39:49 +0100340struct platform_device stuart_device = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 .name = "pxa2xx-uart",
342 .id = 2,
343};
Russell King34f32312007-05-15 10:39:49 +0100344struct platform_device hwuart_device = {
Matt Reimerd9e29642005-10-28 16:25:02 +0100345 .name = "pxa2xx-uart",
346 .id = 3,
347};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Russell King34f32312007-05-15 10:39:49 +0100349static struct resource pxai2c_resources[] = {
Russell Kingbb9bffc2005-04-30 13:26:06 +0100350 {
351 .start = 0x40301680,
352 .end = 0x403016a3,
353 .flags = IORESOURCE_MEM,
354 }, {
355 .start = IRQ_I2C,
356 .end = IRQ_I2C,
357 .flags = IORESOURCE_IRQ,
358 },
359};
360
Russell King34f32312007-05-15 10:39:49 +0100361struct platform_device pxai2c_device = {
Russell Kingbb9bffc2005-04-30 13:26:06 +0100362 .name = "pxa2xx-i2c",
363 .id = 0,
Russell King34f32312007-05-15 10:39:49 +0100364 .resource = pxai2c_resources,
365 .num_resources = ARRAY_SIZE(pxai2c_resources),
Russell Kingbb9bffc2005-04-30 13:26:06 +0100366};
367
368void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
369{
Russell King34f32312007-05-15 10:39:49 +0100370 pxai2c_device.dev.platform_data = info;
Russell Kingbb9bffc2005-04-30 13:26:06 +0100371}
372
Russell King34f32312007-05-15 10:39:49 +0100373static struct resource pxai2s_resources[] = {
Matt Reimerb2640b42005-10-20 23:21:18 +0100374 {
375 .start = 0x40400000,
376 .end = 0x40400083,
377 .flags = IORESOURCE_MEM,
378 }, {
379 .start = IRQ_I2S,
380 .end = IRQ_I2S,
381 .flags = IORESOURCE_IRQ,
382 },
383};
384
Russell King34f32312007-05-15 10:39:49 +0100385struct platform_device pxai2s_device = {
Matt Reimerb2640b42005-10-20 23:21:18 +0100386 .name = "pxa2xx-i2s",
387 .id = -1,
Russell King34f32312007-05-15 10:39:49 +0100388 .resource = pxai2s_resources,
389 .num_resources = ARRAY_SIZE(pxai2s_resources),
Matt Reimerb2640b42005-10-20 23:21:18 +0100390};
391
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100392static u64 pxaficp_dmamask = ~(u32)0;
393
Russell King34f32312007-05-15 10:39:49 +0100394struct platform_device pxaficp_device = {
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100395 .name = "pxa2xx-ir",
396 .id = -1,
397 .dev = {
398 .dma_mask = &pxaficp_dmamask,
399 .coherent_dma_mask = 0xffffffff,
400 },
401};
402
403void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
404{
405 pxaficp_device.dev.platform_data = info;
406}
407
Russell King34f32312007-05-15 10:39:49 +0100408struct platform_device pxartc_device = {
Richard Purdiee842f1c2006-03-27 01:16:46 -0800409 .name = "sa1100-rtc",
410 .id = -1,
411};