blob: eed95eaf58cd9fb375cdd50de83123c20ef9013c [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 */
eric miao30f0b402007-08-29 10:18:47 +010074int pxa_last_gpio;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Philipp Zabel3deac042007-02-20 13:58:15 -080076int pxa_gpio_mode(int gpio_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
78 unsigned long flags;
79 int gpio = gpio_mode & GPIO_MD_MASK_NR;
80 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
81 int gafr;
82
eric miao30f0b402007-08-29 10:18:47 +010083 if (gpio > pxa_last_gpio)
Philipp Zabel3deac042007-02-20 13:58:15 -080084 return -EINVAL;
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 local_irq_save(flags);
87 if (gpio_mode & GPIO_DFLT_LOW)
88 GPCR(gpio) = GPIO_bit(gpio);
89 else if (gpio_mode & GPIO_DFLT_HIGH)
90 GPSR(gpio) = GPIO_bit(gpio);
91 if (gpio_mode & GPIO_MD_MASK_DIR)
92 GPDR(gpio) |= GPIO_bit(gpio);
93 else
94 GPDR(gpio) &= ~GPIO_bit(gpio);
95 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
96 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
97 local_irq_restore(flags);
Philipp Zabel3deac042007-02-20 13:58:15 -080098
99 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
102EXPORT_SYMBOL(pxa_gpio_mode);
103
104/*
Philipp Zabel3deac042007-02-20 13:58:15 -0800105 * Return GPIO level
106 */
107int pxa_gpio_get_value(unsigned gpio)
108{
109 return __gpio_get_value(gpio);
110}
111
112EXPORT_SYMBOL(pxa_gpio_get_value);
113
114/*
115 * Set output GPIO level
116 */
117void pxa_gpio_set_value(unsigned gpio, int value)
118{
119 __gpio_set_value(gpio, value);
120}
121
122EXPORT_SYMBOL(pxa_gpio_set_value);
123
124/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 * Routine to safely enable or disable a clock in the CKEN
126 */
Russell Kinga7073b82007-09-19 09:33:55 +0100127void __pxa_set_cken(int clock, int enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 unsigned long flags;
130 local_irq_save(flags);
131
132 if (enable)
Eric Miao7053acb2007-04-05 04:07:20 +0100133 CKEN |= (1 << clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 else
Eric Miao7053acb2007-04-05 04:07:20 +0100135 CKEN &= ~(1 << clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 local_irq_restore(flags);
138}
139
Russell Kinga7073b82007-09-19 09:33:55 +0100140EXPORT_SYMBOL(__pxa_set_cken);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142/*
143 * Intel PXA2xx internal register mapping.
144 *
145 * Note 1: not all PXA2xx variants implement all those addresses.
146 *
147 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
148 * and cache flush area.
149 */
150static struct map_desc standard_io_desc[] __initdata = {
Deepak Saxena6f9182e2005-10-28 15:19:01 +0100151 { /* Devs */
152 .virtual = 0xf2000000,
153 .pfn = __phys_to_pfn(0x40000000),
154 .length = 0x02000000,
155 .type = MT_DEVICE
156 }, { /* LCD */
157 .virtual = 0xf4000000,
158 .pfn = __phys_to_pfn(0x44000000),
159 .length = 0x00100000,
160 .type = MT_DEVICE
161 }, { /* Mem Ctl */
162 .virtual = 0xf6000000,
163 .pfn = __phys_to_pfn(0x48000000),
164 .length = 0x00100000,
165 .type = MT_DEVICE
166 }, { /* USB host */
167 .virtual = 0xf8000000,
168 .pfn = __phys_to_pfn(0x4c000000),
169 .length = 0x00100000,
170 .type = MT_DEVICE
171 }, { /* Camera */
172 .virtual = 0xfa000000,
173 .pfn = __phys_to_pfn(0x50000000),
174 .length = 0x00100000,
175 .type = MT_DEVICE
176 }, { /* IMem ctl */
177 .virtual = 0xfe000000,
178 .pfn = __phys_to_pfn(0x58000000),
179 .length = 0x00100000,
180 .type = MT_DEVICE
181 }, { /* UNCACHED_PHYS_0 */
182 .virtual = 0xff000000,
183 .pfn = __phys_to_pfn(0x00000000),
184 .length = 0x00100000,
185 .type = MT_DEVICE
186 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187};
188
189void __init pxa_map_io(void)
190{
191 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
192 get_clk_frequency_khz(1);
193}
194
195
196static struct resource pxamci_resources[] = {
197 [0] = {
198 .start = 0x41100000,
199 .end = 0x41100fff,
200 .flags = IORESOURCE_MEM,
201 },
202 [1] = {
203 .start = IRQ_MMC,
204 .end = IRQ_MMC,
205 .flags = IORESOURCE_IRQ,
206 },
207};
208
209static u64 pxamci_dmamask = 0xffffffffUL;
210
Eric Miaoe09d02e2007-07-17 10:45:58 +0100211struct platform_device pxa_device_mci = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 .name = "pxa2xx-mci",
213 .id = -1,
214 .dev = {
215 .dma_mask = &pxamci_dmamask,
216 .coherent_dma_mask = 0xffffffff,
217 },
218 .num_resources = ARRAY_SIZE(pxamci_resources),
219 .resource = pxamci_resources,
220};
221
222void __init pxa_set_mci_info(struct pxamci_platform_data *info)
223{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100224 pxa_device_mci.dev.platform_data = info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
227
228static struct pxa2xx_udc_mach_info pxa_udc_info;
229
230void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
231{
232 memcpy(&pxa_udc_info, info, sizeof *info);
233}
234
235static struct resource pxa2xx_udc_resources[] = {
236 [0] = {
237 .start = 0x40600000,
238 .end = 0x4060ffff,
239 .flags = IORESOURCE_MEM,
240 },
241 [1] = {
242 .start = IRQ_USB,
243 .end = IRQ_USB,
244 .flags = IORESOURCE_IRQ,
245 },
246};
247
248static u64 udc_dma_mask = ~(u32)0;
249
Eric Miaoe09d02e2007-07-17 10:45:58 +0100250struct platform_device pxa_device_udc = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 .name = "pxa2xx-udc",
252 .id = -1,
253 .resource = pxa2xx_udc_resources,
254 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
255 .dev = {
256 .platform_data = &pxa_udc_info,
257 .dma_mask = &udc_dma_mask,
258 }
259};
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261static struct resource pxafb_resources[] = {
262 [0] = {
263 .start = 0x44000000,
264 .end = 0x4400ffff,
265 .flags = IORESOURCE_MEM,
266 },
267 [1] = {
268 .start = IRQ_LCD,
269 .end = IRQ_LCD,
270 .flags = IORESOURCE_IRQ,
271 },
272};
273
274static u64 fb_dma_mask = ~(u64)0;
275
Eric Miaoe09d02e2007-07-17 10:45:58 +0100276struct platform_device pxa_device_fb = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 .name = "pxa2xx-fb",
278 .id = -1,
279 .dev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 .dma_mask = &fb_dma_mask,
281 .coherent_dma_mask = 0xffffffff,
282 },
283 .num_resources = ARRAY_SIZE(pxafb_resources),
284 .resource = pxafb_resources,
285};
286
Richard Purdied14b2722006-09-20 22:54:21 +0100287void __init set_pxa_fb_info(struct pxafb_mach_info *info)
288{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100289 pxa_device_fb.dev.platform_data = info;
Richard Purdied14b2722006-09-20 22:54:21 +0100290}
291
Richard Purdiecb38c562005-10-14 16:07:25 +0100292void __init set_pxa_fb_parent(struct device *parent_dev)
293{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100294 pxa_device_fb.dev.parent = parent_dev;
Richard Purdiecb38c562005-10-14 16:07:25 +0100295}
296
Russell Kinge259a3a2007-08-20 09:47:41 +0100297static struct resource pxa_resource_ffuart[] = {
298 {
299 .start = __PREG(FFUART),
300 .end = __PREG(FFUART) + 35,
301 .flags = IORESOURCE_MEM,
302 }, {
303 .start = IRQ_FFUART,
304 .end = IRQ_FFUART,
305 .flags = IORESOURCE_IRQ,
306 }
307};
308
Eric Miaoe09d02e2007-07-17 10:45:58 +0100309struct platform_device pxa_device_ffuart= {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 .name = "pxa2xx-uart",
311 .id = 0,
Russell Kinge259a3a2007-08-20 09:47:41 +0100312 .resource = pxa_resource_ffuart,
313 .num_resources = ARRAY_SIZE(pxa_resource_ffuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314};
Russell Kinge259a3a2007-08-20 09:47:41 +0100315
316static struct resource pxa_resource_btuart[] = {
317 {
318 .start = __PREG(BTUART),
319 .end = __PREG(BTUART) + 35,
320 .flags = IORESOURCE_MEM,
321 }, {
322 .start = IRQ_BTUART,
323 .end = IRQ_BTUART,
324 .flags = IORESOURCE_IRQ,
325 }
326};
327
Eric Miaoe09d02e2007-07-17 10:45:58 +0100328struct platform_device pxa_device_btuart = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 .name = "pxa2xx-uart",
330 .id = 1,
Russell Kinge259a3a2007-08-20 09:47:41 +0100331 .resource = pxa_resource_btuart,
332 .num_resources = ARRAY_SIZE(pxa_resource_btuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333};
Russell Kinge259a3a2007-08-20 09:47:41 +0100334
335static struct resource pxa_resource_stuart[] = {
336 {
337 .start = __PREG(STUART),
338 .end = __PREG(STUART) + 35,
339 .flags = IORESOURCE_MEM,
340 }, {
341 .start = IRQ_STUART,
342 .end = IRQ_STUART,
343 .flags = IORESOURCE_IRQ,
344 }
345};
346
Eric Miaoe09d02e2007-07-17 10:45:58 +0100347struct platform_device pxa_device_stuart = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 .name = "pxa2xx-uart",
349 .id = 2,
Russell Kinge259a3a2007-08-20 09:47:41 +0100350 .resource = pxa_resource_stuart,
351 .num_resources = ARRAY_SIZE(pxa_resource_stuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352};
Russell Kinge259a3a2007-08-20 09:47:41 +0100353
354static struct resource pxa_resource_hwuart[] = {
355 {
356 .start = __PREG(HWUART),
357 .end = __PREG(HWUART) + 47,
358 .flags = IORESOURCE_MEM,
359 }, {
360 .start = IRQ_HWUART,
361 .end = IRQ_HWUART,
362 .flags = IORESOURCE_IRQ,
363 }
364};
365
Eric Miaoe09d02e2007-07-17 10:45:58 +0100366struct platform_device pxa_device_hwuart = {
Matt Reimerd9e29642005-10-28 16:25:02 +0100367 .name = "pxa2xx-uart",
368 .id = 3,
Russell Kinge259a3a2007-08-20 09:47:41 +0100369 .resource = pxa_resource_hwuart,
370 .num_resources = ARRAY_SIZE(pxa_resource_hwuart),
Matt Reimerd9e29642005-10-28 16:25:02 +0100371};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Russell King34f32312007-05-15 10:39:49 +0100373static struct resource pxai2c_resources[] = {
Russell Kingbb9bffc2005-04-30 13:26:06 +0100374 {
375 .start = 0x40301680,
376 .end = 0x403016a3,
377 .flags = IORESOURCE_MEM,
378 }, {
379 .start = IRQ_I2C,
380 .end = IRQ_I2C,
381 .flags = IORESOURCE_IRQ,
382 },
383};
384
Eric Miaoe09d02e2007-07-17 10:45:58 +0100385struct platform_device pxa_device_i2c = {
Russell Kingbb9bffc2005-04-30 13:26:06 +0100386 .name = "pxa2xx-i2c",
387 .id = 0,
Russell King34f32312007-05-15 10:39:49 +0100388 .resource = pxai2c_resources,
389 .num_resources = ARRAY_SIZE(pxai2c_resources),
Russell Kingbb9bffc2005-04-30 13:26:06 +0100390};
391
392void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
393{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100394 pxa_device_i2c.dev.platform_data = info;
Russell Kingbb9bffc2005-04-30 13:26:06 +0100395}
396
Russell King34f32312007-05-15 10:39:49 +0100397static struct resource pxai2s_resources[] = {
Matt Reimerb2640b42005-10-20 23:21:18 +0100398 {
399 .start = 0x40400000,
400 .end = 0x40400083,
401 .flags = IORESOURCE_MEM,
402 }, {
403 .start = IRQ_I2S,
404 .end = IRQ_I2S,
405 .flags = IORESOURCE_IRQ,
406 },
407};
408
Eric Miaoe09d02e2007-07-17 10:45:58 +0100409struct platform_device pxa_device_i2s = {
Matt Reimerb2640b42005-10-20 23:21:18 +0100410 .name = "pxa2xx-i2s",
411 .id = -1,
Russell King34f32312007-05-15 10:39:49 +0100412 .resource = pxai2s_resources,
413 .num_resources = ARRAY_SIZE(pxai2s_resources),
Matt Reimerb2640b42005-10-20 23:21:18 +0100414};
415
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100416static u64 pxaficp_dmamask = ~(u32)0;
417
Eric Miaoe09d02e2007-07-17 10:45:58 +0100418struct platform_device pxa_device_ficp = {
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100419 .name = "pxa2xx-ir",
420 .id = -1,
421 .dev = {
422 .dma_mask = &pxaficp_dmamask,
423 .coherent_dma_mask = 0xffffffff,
424 },
425};
426
427void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
428{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100429 pxa_device_ficp.dev.platform_data = info;
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100430}
431
Eric Miaoe09d02e2007-07-17 10:45:58 +0100432struct platform_device pxa_device_rtc = {
Richard Purdiee842f1c2006-03-27 01:16:46 -0800433 .name = "sa1100-rtc",
434 .id = -1,
435};