blob: 1c34946ee16e60c0fb3f6ff6491efc276455e108 [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);
eric miao2c8086a2007-09-11 19:13:17 -070054 else if (cpu_is_pxa27x())
Russell King15a40332007-08-20 10:07:44 +010055 return pxa27x_get_clk_frequency_khz(info);
eric miao2c8086a2007-09-11 19:13:17 -070056 else
57 return pxa3xx_get_clk_frequency_khz(info);
Russell King15a40332007-08-20 10:07:44 +010058}
59EXPORT_SYMBOL(get_clk_frequency_khz);
60
61/*
62 * Return the current memory clock frequency in units of 10kHz
63 */
64unsigned int get_memclk_frequency_10khz(void)
65{
66 if (cpu_is_pxa21x() || cpu_is_pxa25x())
67 return pxa25x_get_memclk_frequency_10khz();
eric miao2c8086a2007-09-11 19:13:17 -070068 else if (cpu_is_pxa27x())
Russell King15a40332007-08-20 10:07:44 +010069 return pxa27x_get_memclk_frequency_10khz();
eric miao2c8086a2007-09-11 19:13:17 -070070 else
71 return pxa3xx_get_memclk_frequency_10khz();
Russell King15a40332007-08-20 10:07:44 +010072}
73EXPORT_SYMBOL(get_memclk_frequency_10khz);
74
75/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 * Handy function to set GPIO alternate functions
77 */
eric miao30f0b402007-08-29 10:18:47 +010078int pxa_last_gpio;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Philipp Zabel3deac042007-02-20 13:58:15 -080080int pxa_gpio_mode(int gpio_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
82 unsigned long flags;
83 int gpio = gpio_mode & GPIO_MD_MASK_NR;
84 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
85 int gafr;
86
eric miao30f0b402007-08-29 10:18:47 +010087 if (gpio > pxa_last_gpio)
Philipp Zabel3deac042007-02-20 13:58:15 -080088 return -EINVAL;
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 local_irq_save(flags);
91 if (gpio_mode & GPIO_DFLT_LOW)
92 GPCR(gpio) = GPIO_bit(gpio);
93 else if (gpio_mode & GPIO_DFLT_HIGH)
94 GPSR(gpio) = GPIO_bit(gpio);
95 if (gpio_mode & GPIO_MD_MASK_DIR)
96 GPDR(gpio) |= GPIO_bit(gpio);
97 else
98 GPDR(gpio) &= ~GPIO_bit(gpio);
99 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
100 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
101 local_irq_restore(flags);
Philipp Zabel3deac042007-02-20 13:58:15 -0800102
103 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
106EXPORT_SYMBOL(pxa_gpio_mode);
107
Russell King3e0cc7e2007-10-02 14:28:01 +0100108int gpio_direction_input(unsigned gpio)
109{
110 unsigned long flags;
111 u32 mask;
112
113 if (gpio > pxa_last_gpio)
114 return -EINVAL;
115
116 mask = GPIO_bit(gpio);
117 local_irq_save(flags);
118 GPDR(gpio) &= ~mask;
119 local_irq_restore(flags);
120
121 return 0;
122}
123EXPORT_SYMBOL(gpio_direction_input);
124
125int gpio_direction_output(unsigned gpio, int value)
126{
127 unsigned long flags;
128 u32 mask;
129
130 if (gpio > pxa_last_gpio)
131 return -EINVAL;
132
133 mask = GPIO_bit(gpio);
134 local_irq_save(flags);
135 if (value)
136 GPSR(gpio) = mask;
137 else
138 GPCR(gpio) = mask;
139 GPDR(gpio) |= mask;
140 local_irq_restore(flags);
141
142 return 0;
143}
144EXPORT_SYMBOL(gpio_direction_output);
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146/*
Philipp Zabel3deac042007-02-20 13:58:15 -0800147 * Return GPIO level
148 */
149int pxa_gpio_get_value(unsigned gpio)
150{
151 return __gpio_get_value(gpio);
152}
153
154EXPORT_SYMBOL(pxa_gpio_get_value);
155
156/*
157 * Set output GPIO level
158 */
159void pxa_gpio_set_value(unsigned gpio, int value)
160{
161 __gpio_set_value(gpio, value);
162}
163
164EXPORT_SYMBOL(pxa_gpio_set_value);
165
166/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 * Routine to safely enable or disable a clock in the CKEN
168 */
Russell Kinga7073b82007-09-19 09:33:55 +0100169void __pxa_set_cken(int clock, int enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
171 unsigned long flags;
172 local_irq_save(flags);
173
174 if (enable)
Eric Miao7053acb2007-04-05 04:07:20 +0100175 CKEN |= (1 << clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 else
Eric Miao7053acb2007-04-05 04:07:20 +0100177 CKEN &= ~(1 << clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 local_irq_restore(flags);
180}
181
Russell Kinga7073b82007-09-19 09:33:55 +0100182EXPORT_SYMBOL(__pxa_set_cken);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184/*
185 * Intel PXA2xx internal register mapping.
186 *
187 * Note 1: not all PXA2xx variants implement all those addresses.
188 *
189 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
190 * and cache flush area.
191 */
192static struct map_desc standard_io_desc[] __initdata = {
Deepak Saxena6f9182e2005-10-28 15:19:01 +0100193 { /* Devs */
194 .virtual = 0xf2000000,
195 .pfn = __phys_to_pfn(0x40000000),
196 .length = 0x02000000,
197 .type = MT_DEVICE
198 }, { /* LCD */
199 .virtual = 0xf4000000,
200 .pfn = __phys_to_pfn(0x44000000),
201 .length = 0x00100000,
202 .type = MT_DEVICE
203 }, { /* Mem Ctl */
204 .virtual = 0xf6000000,
205 .pfn = __phys_to_pfn(0x48000000),
206 .length = 0x00100000,
207 .type = MT_DEVICE
208 }, { /* USB host */
209 .virtual = 0xf8000000,
210 .pfn = __phys_to_pfn(0x4c000000),
211 .length = 0x00100000,
212 .type = MT_DEVICE
213 }, { /* Camera */
214 .virtual = 0xfa000000,
215 .pfn = __phys_to_pfn(0x50000000),
216 .length = 0x00100000,
217 .type = MT_DEVICE
218 }, { /* IMem ctl */
219 .virtual = 0xfe000000,
220 .pfn = __phys_to_pfn(0x58000000),
221 .length = 0x00100000,
222 .type = MT_DEVICE
223 }, { /* UNCACHED_PHYS_0 */
224 .virtual = 0xff000000,
225 .pfn = __phys_to_pfn(0x00000000),
226 .length = 0x00100000,
227 .type = MT_DEVICE
228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229};
230
231void __init pxa_map_io(void)
232{
233 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
234 get_clk_frequency_khz(1);
235}
236
237
238static struct resource pxamci_resources[] = {
239 [0] = {
240 .start = 0x41100000,
241 .end = 0x41100fff,
242 .flags = IORESOURCE_MEM,
243 },
244 [1] = {
245 .start = IRQ_MMC,
246 .end = IRQ_MMC,
247 .flags = IORESOURCE_IRQ,
248 },
249};
250
251static u64 pxamci_dmamask = 0xffffffffUL;
252
Eric Miaoe09d02e2007-07-17 10:45:58 +0100253struct platform_device pxa_device_mci = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 .name = "pxa2xx-mci",
255 .id = -1,
256 .dev = {
257 .dma_mask = &pxamci_dmamask,
258 .coherent_dma_mask = 0xffffffff,
259 },
260 .num_resources = ARRAY_SIZE(pxamci_resources),
261 .resource = pxamci_resources,
262};
263
264void __init pxa_set_mci_info(struct pxamci_platform_data *info)
265{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100266 pxa_device_mci.dev.platform_data = info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
269
270static struct pxa2xx_udc_mach_info pxa_udc_info;
271
272void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
273{
274 memcpy(&pxa_udc_info, info, sizeof *info);
275}
276
277static struct resource pxa2xx_udc_resources[] = {
278 [0] = {
279 .start = 0x40600000,
280 .end = 0x4060ffff,
281 .flags = IORESOURCE_MEM,
282 },
283 [1] = {
284 .start = IRQ_USB,
285 .end = IRQ_USB,
286 .flags = IORESOURCE_IRQ,
287 },
288};
289
290static u64 udc_dma_mask = ~(u32)0;
291
Eric Miaoe09d02e2007-07-17 10:45:58 +0100292struct platform_device pxa_device_udc = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 .name = "pxa2xx-udc",
294 .id = -1,
295 .resource = pxa2xx_udc_resources,
296 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
297 .dev = {
298 .platform_data = &pxa_udc_info,
299 .dma_mask = &udc_dma_mask,
300 }
301};
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303static struct resource pxafb_resources[] = {
304 [0] = {
305 .start = 0x44000000,
306 .end = 0x4400ffff,
307 .flags = IORESOURCE_MEM,
308 },
309 [1] = {
310 .start = IRQ_LCD,
311 .end = IRQ_LCD,
312 .flags = IORESOURCE_IRQ,
313 },
314};
315
316static u64 fb_dma_mask = ~(u64)0;
317
Eric Miaoe09d02e2007-07-17 10:45:58 +0100318struct platform_device pxa_device_fb = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 .name = "pxa2xx-fb",
320 .id = -1,
321 .dev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 .dma_mask = &fb_dma_mask,
323 .coherent_dma_mask = 0xffffffff,
324 },
325 .num_resources = ARRAY_SIZE(pxafb_resources),
326 .resource = pxafb_resources,
327};
328
Richard Purdied14b2722006-09-20 22:54:21 +0100329void __init set_pxa_fb_info(struct pxafb_mach_info *info)
330{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100331 pxa_device_fb.dev.platform_data = info;
Richard Purdied14b2722006-09-20 22:54:21 +0100332}
333
Richard Purdiecb38c562005-10-14 16:07:25 +0100334void __init set_pxa_fb_parent(struct device *parent_dev)
335{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100336 pxa_device_fb.dev.parent = parent_dev;
Richard Purdiecb38c562005-10-14 16:07:25 +0100337}
338
Russell Kinge259a3a2007-08-20 09:47:41 +0100339static struct resource pxa_resource_ffuart[] = {
340 {
341 .start = __PREG(FFUART),
342 .end = __PREG(FFUART) + 35,
343 .flags = IORESOURCE_MEM,
344 }, {
345 .start = IRQ_FFUART,
346 .end = IRQ_FFUART,
347 .flags = IORESOURCE_IRQ,
348 }
349};
350
Eric Miaoe09d02e2007-07-17 10:45:58 +0100351struct platform_device pxa_device_ffuart= {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 .name = "pxa2xx-uart",
353 .id = 0,
Russell Kinge259a3a2007-08-20 09:47:41 +0100354 .resource = pxa_resource_ffuart,
355 .num_resources = ARRAY_SIZE(pxa_resource_ffuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356};
Russell Kinge259a3a2007-08-20 09:47:41 +0100357
358static struct resource pxa_resource_btuart[] = {
359 {
360 .start = __PREG(BTUART),
361 .end = __PREG(BTUART) + 35,
362 .flags = IORESOURCE_MEM,
363 }, {
364 .start = IRQ_BTUART,
365 .end = IRQ_BTUART,
366 .flags = IORESOURCE_IRQ,
367 }
368};
369
Eric Miaoe09d02e2007-07-17 10:45:58 +0100370struct platform_device pxa_device_btuart = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 .name = "pxa2xx-uart",
372 .id = 1,
Russell Kinge259a3a2007-08-20 09:47:41 +0100373 .resource = pxa_resource_btuart,
374 .num_resources = ARRAY_SIZE(pxa_resource_btuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375};
Russell Kinge259a3a2007-08-20 09:47:41 +0100376
377static struct resource pxa_resource_stuart[] = {
378 {
379 .start = __PREG(STUART),
380 .end = __PREG(STUART) + 35,
381 .flags = IORESOURCE_MEM,
382 }, {
383 .start = IRQ_STUART,
384 .end = IRQ_STUART,
385 .flags = IORESOURCE_IRQ,
386 }
387};
388
Eric Miaoe09d02e2007-07-17 10:45:58 +0100389struct platform_device pxa_device_stuart = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 .name = "pxa2xx-uart",
391 .id = 2,
Russell Kinge259a3a2007-08-20 09:47:41 +0100392 .resource = pxa_resource_stuart,
393 .num_resources = ARRAY_SIZE(pxa_resource_stuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394};
Russell Kinge259a3a2007-08-20 09:47:41 +0100395
396static struct resource pxa_resource_hwuart[] = {
397 {
398 .start = __PREG(HWUART),
399 .end = __PREG(HWUART) + 47,
400 .flags = IORESOURCE_MEM,
401 }, {
402 .start = IRQ_HWUART,
403 .end = IRQ_HWUART,
404 .flags = IORESOURCE_IRQ,
405 }
406};
407
Eric Miaoe09d02e2007-07-17 10:45:58 +0100408struct platform_device pxa_device_hwuart = {
Matt Reimerd9e29642005-10-28 16:25:02 +0100409 .name = "pxa2xx-uart",
410 .id = 3,
Russell Kinge259a3a2007-08-20 09:47:41 +0100411 .resource = pxa_resource_hwuart,
412 .num_resources = ARRAY_SIZE(pxa_resource_hwuart),
Matt Reimerd9e29642005-10-28 16:25:02 +0100413};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Russell King34f32312007-05-15 10:39:49 +0100415static struct resource pxai2c_resources[] = {
Russell Kingbb9bffc2005-04-30 13:26:06 +0100416 {
417 .start = 0x40301680,
418 .end = 0x403016a3,
419 .flags = IORESOURCE_MEM,
420 }, {
421 .start = IRQ_I2C,
422 .end = IRQ_I2C,
423 .flags = IORESOURCE_IRQ,
424 },
425};
426
Eric Miaoe09d02e2007-07-17 10:45:58 +0100427struct platform_device pxa_device_i2c = {
Russell Kingbb9bffc2005-04-30 13:26:06 +0100428 .name = "pxa2xx-i2c",
429 .id = 0,
Russell King34f32312007-05-15 10:39:49 +0100430 .resource = pxai2c_resources,
431 .num_resources = ARRAY_SIZE(pxai2c_resources),
Russell Kingbb9bffc2005-04-30 13:26:06 +0100432};
433
434void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
435{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100436 pxa_device_i2c.dev.platform_data = info;
Russell Kingbb9bffc2005-04-30 13:26:06 +0100437}
438
Russell King34f32312007-05-15 10:39:49 +0100439static struct resource pxai2s_resources[] = {
Matt Reimerb2640b42005-10-20 23:21:18 +0100440 {
441 .start = 0x40400000,
442 .end = 0x40400083,
443 .flags = IORESOURCE_MEM,
444 }, {
445 .start = IRQ_I2S,
446 .end = IRQ_I2S,
447 .flags = IORESOURCE_IRQ,
448 },
449};
450
Eric Miaoe09d02e2007-07-17 10:45:58 +0100451struct platform_device pxa_device_i2s = {
Matt Reimerb2640b42005-10-20 23:21:18 +0100452 .name = "pxa2xx-i2s",
453 .id = -1,
Russell King34f32312007-05-15 10:39:49 +0100454 .resource = pxai2s_resources,
455 .num_resources = ARRAY_SIZE(pxai2s_resources),
Matt Reimerb2640b42005-10-20 23:21:18 +0100456};
457
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100458static u64 pxaficp_dmamask = ~(u32)0;
459
Eric Miaoe09d02e2007-07-17 10:45:58 +0100460struct platform_device pxa_device_ficp = {
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100461 .name = "pxa2xx-ir",
462 .id = -1,
463 .dev = {
464 .dma_mask = &pxaficp_dmamask,
465 .coherent_dma_mask = 0xffffffff,
466 },
467};
468
469void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
470{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100471 pxa_device_ficp.dev.platform_data = info;
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100472}
473
Eric Miaoe09d02e2007-07-17 10:45:58 +0100474struct platform_device pxa_device_rtc = {
Richard Purdiee842f1c2006-03-27 01:16:46 -0800475 .name = "sa1100-rtc",
476 .id = -1,
477};