blob: 1c5413fc6e74ad5e5a6127066759f491306859f1 [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
28#include <asm/hardware.h>
29#include <asm/irq.h>
30#include <asm/system.h>
31#include <asm/pgtable.h>
32#include <asm/mach/map.h>
33
34#include <asm/arch/pxa-regs.h>
Philipp Zabel3deac042007-02-20 13:58:15 -080035#include <asm/arch/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/arch/udc.h>
37#include <asm/arch/pxafb.h>
38#include <asm/arch/mmc.h>
Nicolas Pitre6f475c02005-10-28 16:39:33 +010039#include <asm/arch/irda.h>
Russell Kingeb9181a2005-09-29 09:49:25 +010040#include <asm/arch/i2c.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Russell King46c41e62007-05-15 15:39:36 +010042#include "devices.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include "generic.h"
44
45/*
Russell King15a40332007-08-20 10:07:44 +010046 * Get the clock frequency as reflected by CCCR and the turbo flag.
47 * We assume these values have been applied via a fcs.
48 * If info is not 0 we also display the current settings.
49 */
50unsigned int get_clk_frequency_khz(int info)
51{
52 if (cpu_is_pxa21x() || cpu_is_pxa25x())
53 return pxa25x_get_clk_frequency_khz(info);
54 else
55 return pxa27x_get_clk_frequency_khz(info);
56}
57EXPORT_SYMBOL(get_clk_frequency_khz);
58
59/*
60 * Return the current memory clock frequency in units of 10kHz
61 */
62unsigned int get_memclk_frequency_10khz(void)
63{
64 if (cpu_is_pxa21x() || cpu_is_pxa25x())
65 return pxa25x_get_memclk_frequency_10khz();
66 else
67 return pxa27x_get_memclk_frequency_10khz();
68}
69EXPORT_SYMBOL(get_memclk_frequency_10khz);
70
71/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * Handy function to set GPIO alternate functions
73 */
74
Philipp Zabel3deac042007-02-20 13:58:15 -080075int pxa_gpio_mode(int gpio_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 unsigned long flags;
78 int gpio = gpio_mode & GPIO_MD_MASK_NR;
79 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
80 int gafr;
81
Philipp Zabel3deac042007-02-20 13:58:15 -080082 if (gpio > PXA_LAST_GPIO)
83 return -EINVAL;
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 local_irq_save(flags);
86 if (gpio_mode & GPIO_DFLT_LOW)
87 GPCR(gpio) = GPIO_bit(gpio);
88 else if (gpio_mode & GPIO_DFLT_HIGH)
89 GPSR(gpio) = GPIO_bit(gpio);
90 if (gpio_mode & GPIO_MD_MASK_DIR)
91 GPDR(gpio) |= GPIO_bit(gpio);
92 else
93 GPDR(gpio) &= ~GPIO_bit(gpio);
94 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
95 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
96 local_irq_restore(flags);
Philipp Zabel3deac042007-02-20 13:58:15 -080097
98 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
101EXPORT_SYMBOL(pxa_gpio_mode);
102
103/*
Philipp Zabel3deac042007-02-20 13:58:15 -0800104 * Return GPIO level
105 */
106int pxa_gpio_get_value(unsigned gpio)
107{
108 return __gpio_get_value(gpio);
109}
110
111EXPORT_SYMBOL(pxa_gpio_get_value);
112
113/*
114 * Set output GPIO level
115 */
116void pxa_gpio_set_value(unsigned gpio, int value)
117{
118 __gpio_set_value(gpio, value);
119}
120
121EXPORT_SYMBOL(pxa_gpio_set_value);
122
123/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 * Routine to safely enable or disable a clock in the CKEN
125 */
Russell Kinga7073b82007-09-19 09:33:55 +0100126void __pxa_set_cken(int clock, int enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
128 unsigned long flags;
129 local_irq_save(flags);
130
131 if (enable)
Eric Miao7053acb2007-04-05 04:07:20 +0100132 CKEN |= (1 << clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 else
Eric Miao7053acb2007-04-05 04:07:20 +0100134 CKEN &= ~(1 << clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 local_irq_restore(flags);
137}
138
Russell Kinga7073b82007-09-19 09:33:55 +0100139EXPORT_SYMBOL(__pxa_set_cken);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141/*
142 * Intel PXA2xx internal register mapping.
143 *
144 * Note 1: not all PXA2xx variants implement all those addresses.
145 *
146 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
147 * and cache flush area.
148 */
149static struct map_desc standard_io_desc[] __initdata = {
Deepak Saxena6f9182e2005-10-28 15:19:01 +0100150 { /* Devs */
151 .virtual = 0xf2000000,
152 .pfn = __phys_to_pfn(0x40000000),
153 .length = 0x02000000,
154 .type = MT_DEVICE
155 }, { /* LCD */
156 .virtual = 0xf4000000,
157 .pfn = __phys_to_pfn(0x44000000),
158 .length = 0x00100000,
159 .type = MT_DEVICE
160 }, { /* Mem Ctl */
161 .virtual = 0xf6000000,
162 .pfn = __phys_to_pfn(0x48000000),
163 .length = 0x00100000,
164 .type = MT_DEVICE
165 }, { /* USB host */
166 .virtual = 0xf8000000,
167 .pfn = __phys_to_pfn(0x4c000000),
168 .length = 0x00100000,
169 .type = MT_DEVICE
170 }, { /* Camera */
171 .virtual = 0xfa000000,
172 .pfn = __phys_to_pfn(0x50000000),
173 .length = 0x00100000,
174 .type = MT_DEVICE
175 }, { /* IMem ctl */
176 .virtual = 0xfe000000,
177 .pfn = __phys_to_pfn(0x58000000),
178 .length = 0x00100000,
179 .type = MT_DEVICE
180 }, { /* UNCACHED_PHYS_0 */
181 .virtual = 0xff000000,
182 .pfn = __phys_to_pfn(0x00000000),
183 .length = 0x00100000,
184 .type = MT_DEVICE
185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186};
187
188void __init pxa_map_io(void)
189{
190 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
191 get_clk_frequency_khz(1);
192}
193
194
195static struct resource pxamci_resources[] = {
196 [0] = {
197 .start = 0x41100000,
198 .end = 0x41100fff,
199 .flags = IORESOURCE_MEM,
200 },
201 [1] = {
202 .start = IRQ_MMC,
203 .end = IRQ_MMC,
204 .flags = IORESOURCE_IRQ,
205 },
206};
207
208static u64 pxamci_dmamask = 0xffffffffUL;
209
Eric Miaoe09d02e2007-07-17 10:45:58 +0100210struct platform_device pxa_device_mci = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 .name = "pxa2xx-mci",
212 .id = -1,
213 .dev = {
214 .dma_mask = &pxamci_dmamask,
215 .coherent_dma_mask = 0xffffffff,
216 },
217 .num_resources = ARRAY_SIZE(pxamci_resources),
218 .resource = pxamci_resources,
219};
220
221void __init pxa_set_mci_info(struct pxamci_platform_data *info)
222{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100223 pxa_device_mci.dev.platform_data = info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225
226
227static struct pxa2xx_udc_mach_info pxa_udc_info;
228
229void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
230{
231 memcpy(&pxa_udc_info, info, sizeof *info);
232}
233
234static struct resource pxa2xx_udc_resources[] = {
235 [0] = {
236 .start = 0x40600000,
237 .end = 0x4060ffff,
238 .flags = IORESOURCE_MEM,
239 },
240 [1] = {
241 .start = IRQ_USB,
242 .end = IRQ_USB,
243 .flags = IORESOURCE_IRQ,
244 },
245};
246
247static u64 udc_dma_mask = ~(u32)0;
248
Eric Miaoe09d02e2007-07-17 10:45:58 +0100249struct platform_device pxa_device_udc = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 .name = "pxa2xx-udc",
251 .id = -1,
252 .resource = pxa2xx_udc_resources,
253 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
254 .dev = {
255 .platform_data = &pxa_udc_info,
256 .dma_mask = &udc_dma_mask,
257 }
258};
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260static struct resource pxafb_resources[] = {
261 [0] = {
262 .start = 0x44000000,
263 .end = 0x4400ffff,
264 .flags = IORESOURCE_MEM,
265 },
266 [1] = {
267 .start = IRQ_LCD,
268 .end = IRQ_LCD,
269 .flags = IORESOURCE_IRQ,
270 },
271};
272
273static u64 fb_dma_mask = ~(u64)0;
274
Eric Miaoe09d02e2007-07-17 10:45:58 +0100275struct platform_device pxa_device_fb = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 .name = "pxa2xx-fb",
277 .id = -1,
278 .dev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 .dma_mask = &fb_dma_mask,
280 .coherent_dma_mask = 0xffffffff,
281 },
282 .num_resources = ARRAY_SIZE(pxafb_resources),
283 .resource = pxafb_resources,
284};
285
Richard Purdied14b2722006-09-20 22:54:21 +0100286void __init set_pxa_fb_info(struct pxafb_mach_info *info)
287{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100288 pxa_device_fb.dev.platform_data = info;
Richard Purdied14b2722006-09-20 22:54:21 +0100289}
290
Richard Purdiecb38c562005-10-14 16:07:25 +0100291void __init set_pxa_fb_parent(struct device *parent_dev)
292{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100293 pxa_device_fb.dev.parent = parent_dev;
Richard Purdiecb38c562005-10-14 16:07:25 +0100294}
295
Russell Kinge259a3a2007-08-20 09:47:41 +0100296static struct resource pxa_resource_ffuart[] = {
297 {
298 .start = __PREG(FFUART),
299 .end = __PREG(FFUART) + 35,
300 .flags = IORESOURCE_MEM,
301 }, {
302 .start = IRQ_FFUART,
303 .end = IRQ_FFUART,
304 .flags = IORESOURCE_IRQ,
305 }
306};
307
Eric Miaoe09d02e2007-07-17 10:45:58 +0100308struct platform_device pxa_device_ffuart= {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 .name = "pxa2xx-uart",
310 .id = 0,
Russell Kinge259a3a2007-08-20 09:47:41 +0100311 .resource = pxa_resource_ffuart,
312 .num_resources = ARRAY_SIZE(pxa_resource_ffuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313};
Russell Kinge259a3a2007-08-20 09:47:41 +0100314
315static struct resource pxa_resource_btuart[] = {
316 {
317 .start = __PREG(BTUART),
318 .end = __PREG(BTUART) + 35,
319 .flags = IORESOURCE_MEM,
320 }, {
321 .start = IRQ_BTUART,
322 .end = IRQ_BTUART,
323 .flags = IORESOURCE_IRQ,
324 }
325};
326
Eric Miaoe09d02e2007-07-17 10:45:58 +0100327struct platform_device pxa_device_btuart = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 .name = "pxa2xx-uart",
329 .id = 1,
Russell Kinge259a3a2007-08-20 09:47:41 +0100330 .resource = pxa_resource_btuart,
331 .num_resources = ARRAY_SIZE(pxa_resource_btuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332};
Russell Kinge259a3a2007-08-20 09:47:41 +0100333
334static struct resource pxa_resource_stuart[] = {
335 {
336 .start = __PREG(STUART),
337 .end = __PREG(STUART) + 35,
338 .flags = IORESOURCE_MEM,
339 }, {
340 .start = IRQ_STUART,
341 .end = IRQ_STUART,
342 .flags = IORESOURCE_IRQ,
343 }
344};
345
Eric Miaoe09d02e2007-07-17 10:45:58 +0100346struct platform_device pxa_device_stuart = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 .name = "pxa2xx-uart",
348 .id = 2,
Russell Kinge259a3a2007-08-20 09:47:41 +0100349 .resource = pxa_resource_stuart,
350 .num_resources = ARRAY_SIZE(pxa_resource_stuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351};
Russell Kinge259a3a2007-08-20 09:47:41 +0100352
353static struct resource pxa_resource_hwuart[] = {
354 {
355 .start = __PREG(HWUART),
356 .end = __PREG(HWUART) + 47,
357 .flags = IORESOURCE_MEM,
358 }, {
359 .start = IRQ_HWUART,
360 .end = IRQ_HWUART,
361 .flags = IORESOURCE_IRQ,
362 }
363};
364
Eric Miaoe09d02e2007-07-17 10:45:58 +0100365struct platform_device pxa_device_hwuart = {
Matt Reimerd9e29642005-10-28 16:25:02 +0100366 .name = "pxa2xx-uart",
367 .id = 3,
Russell Kinge259a3a2007-08-20 09:47:41 +0100368 .resource = pxa_resource_hwuart,
369 .num_resources = ARRAY_SIZE(pxa_resource_hwuart),
Matt Reimerd9e29642005-10-28 16:25:02 +0100370};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Russell King34f32312007-05-15 10:39:49 +0100372static struct resource pxai2c_resources[] = {
Russell Kingbb9bffc2005-04-30 13:26:06 +0100373 {
374 .start = 0x40301680,
375 .end = 0x403016a3,
376 .flags = IORESOURCE_MEM,
377 }, {
378 .start = IRQ_I2C,
379 .end = IRQ_I2C,
380 .flags = IORESOURCE_IRQ,
381 },
382};
383
Eric Miaoe09d02e2007-07-17 10:45:58 +0100384struct platform_device pxa_device_i2c = {
Russell Kingbb9bffc2005-04-30 13:26:06 +0100385 .name = "pxa2xx-i2c",
386 .id = 0,
Russell King34f32312007-05-15 10:39:49 +0100387 .resource = pxai2c_resources,
388 .num_resources = ARRAY_SIZE(pxai2c_resources),
Russell Kingbb9bffc2005-04-30 13:26:06 +0100389};
390
391void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
392{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100393 pxa_device_i2c.dev.platform_data = info;
Russell Kingbb9bffc2005-04-30 13:26:06 +0100394}
395
Russell King34f32312007-05-15 10:39:49 +0100396static struct resource pxai2s_resources[] = {
Matt Reimerb2640b42005-10-20 23:21:18 +0100397 {
398 .start = 0x40400000,
399 .end = 0x40400083,
400 .flags = IORESOURCE_MEM,
401 }, {
402 .start = IRQ_I2S,
403 .end = IRQ_I2S,
404 .flags = IORESOURCE_IRQ,
405 },
406};
407
Eric Miaoe09d02e2007-07-17 10:45:58 +0100408struct platform_device pxa_device_i2s = {
Matt Reimerb2640b42005-10-20 23:21:18 +0100409 .name = "pxa2xx-i2s",
410 .id = -1,
Russell King34f32312007-05-15 10:39:49 +0100411 .resource = pxai2s_resources,
412 .num_resources = ARRAY_SIZE(pxai2s_resources),
Matt Reimerb2640b42005-10-20 23:21:18 +0100413};
414
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100415static u64 pxaficp_dmamask = ~(u32)0;
416
Eric Miaoe09d02e2007-07-17 10:45:58 +0100417struct platform_device pxa_device_ficp = {
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100418 .name = "pxa2xx-ir",
419 .id = -1,
420 .dev = {
421 .dma_mask = &pxaficp_dmamask,
422 .coherent_dma_mask = 0xffffffff,
423 },
424};
425
426void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
427{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100428 pxa_device_ficp.dev.platform_data = info;
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100429}
430
Eric Miaoe09d02e2007-07-17 10:45:58 +0100431struct platform_device pxa_device_rtc = {
Richard Purdiee842f1c2006-03-27 01:16:46 -0800432 .name = "sa1100-rtc",
433 .id = -1,
434};