blob: 98df63898d1d4392c8eb57824959c703804d623d [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/*
46 * Handy function to set GPIO alternate functions
47 */
48
Philipp Zabel3deac042007-02-20 13:58:15 -080049int pxa_gpio_mode(int gpio_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
51 unsigned long flags;
52 int gpio = gpio_mode & GPIO_MD_MASK_NR;
53 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
54 int gafr;
55
Philipp Zabel3deac042007-02-20 13:58:15 -080056 if (gpio > PXA_LAST_GPIO)
57 return -EINVAL;
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 local_irq_save(flags);
60 if (gpio_mode & GPIO_DFLT_LOW)
61 GPCR(gpio) = GPIO_bit(gpio);
62 else if (gpio_mode & GPIO_DFLT_HIGH)
63 GPSR(gpio) = GPIO_bit(gpio);
64 if (gpio_mode & GPIO_MD_MASK_DIR)
65 GPDR(gpio) |= GPIO_bit(gpio);
66 else
67 GPDR(gpio) &= ~GPIO_bit(gpio);
68 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
69 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
70 local_irq_restore(flags);
Philipp Zabel3deac042007-02-20 13:58:15 -080071
72 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
75EXPORT_SYMBOL(pxa_gpio_mode);
76
77/*
Philipp Zabel3deac042007-02-20 13:58:15 -080078 * Return GPIO level
79 */
80int pxa_gpio_get_value(unsigned gpio)
81{
82 return __gpio_get_value(gpio);
83}
84
85EXPORT_SYMBOL(pxa_gpio_get_value);
86
87/*
88 * Set output GPIO level
89 */
90void pxa_gpio_set_value(unsigned gpio, int value)
91{
92 __gpio_set_value(gpio, value);
93}
94
95EXPORT_SYMBOL(pxa_gpio_set_value);
96
97/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 * Routine to safely enable or disable a clock in the CKEN
99 */
100void pxa_set_cken(int clock, int enable)
101{
102 unsigned long flags;
103 local_irq_save(flags);
104
105 if (enable)
Eric Miao7053acb2007-04-05 04:07:20 +0100106 CKEN |= (1 << clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 else
Eric Miao7053acb2007-04-05 04:07:20 +0100108 CKEN &= ~(1 << clock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 local_irq_restore(flags);
111}
112
113EXPORT_SYMBOL(pxa_set_cken);
114
115/*
116 * Intel PXA2xx internal register mapping.
117 *
118 * Note 1: not all PXA2xx variants implement all those addresses.
119 *
120 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
121 * and cache flush area.
122 */
123static struct map_desc standard_io_desc[] __initdata = {
Deepak Saxena6f9182e2005-10-28 15:19:01 +0100124 { /* Devs */
125 .virtual = 0xf2000000,
126 .pfn = __phys_to_pfn(0x40000000),
127 .length = 0x02000000,
128 .type = MT_DEVICE
129 }, { /* LCD */
130 .virtual = 0xf4000000,
131 .pfn = __phys_to_pfn(0x44000000),
132 .length = 0x00100000,
133 .type = MT_DEVICE
134 }, { /* Mem Ctl */
135 .virtual = 0xf6000000,
136 .pfn = __phys_to_pfn(0x48000000),
137 .length = 0x00100000,
138 .type = MT_DEVICE
139 }, { /* USB host */
140 .virtual = 0xf8000000,
141 .pfn = __phys_to_pfn(0x4c000000),
142 .length = 0x00100000,
143 .type = MT_DEVICE
144 }, { /* Camera */
145 .virtual = 0xfa000000,
146 .pfn = __phys_to_pfn(0x50000000),
147 .length = 0x00100000,
148 .type = MT_DEVICE
149 }, { /* IMem ctl */
150 .virtual = 0xfe000000,
151 .pfn = __phys_to_pfn(0x58000000),
152 .length = 0x00100000,
153 .type = MT_DEVICE
154 }, { /* UNCACHED_PHYS_0 */
155 .virtual = 0xff000000,
156 .pfn = __phys_to_pfn(0x00000000),
157 .length = 0x00100000,
158 .type = MT_DEVICE
159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160};
161
162void __init pxa_map_io(void)
163{
164 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
165 get_clk_frequency_khz(1);
166}
167
168
169static struct resource pxamci_resources[] = {
170 [0] = {
171 .start = 0x41100000,
172 .end = 0x41100fff,
173 .flags = IORESOURCE_MEM,
174 },
175 [1] = {
176 .start = IRQ_MMC,
177 .end = IRQ_MMC,
178 .flags = IORESOURCE_IRQ,
179 },
180};
181
182static u64 pxamci_dmamask = 0xffffffffUL;
183
Eric Miaoe09d02e2007-07-17 10:45:58 +0100184struct platform_device pxa_device_mci = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 .name = "pxa2xx-mci",
186 .id = -1,
187 .dev = {
188 .dma_mask = &pxamci_dmamask,
189 .coherent_dma_mask = 0xffffffff,
190 },
191 .num_resources = ARRAY_SIZE(pxamci_resources),
192 .resource = pxamci_resources,
193};
194
195void __init pxa_set_mci_info(struct pxamci_platform_data *info)
196{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100197 pxa_device_mci.dev.platform_data = info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
200
201static struct pxa2xx_udc_mach_info pxa_udc_info;
202
203void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
204{
205 memcpy(&pxa_udc_info, info, sizeof *info);
206}
207
208static struct resource pxa2xx_udc_resources[] = {
209 [0] = {
210 .start = 0x40600000,
211 .end = 0x4060ffff,
212 .flags = IORESOURCE_MEM,
213 },
214 [1] = {
215 .start = IRQ_USB,
216 .end = IRQ_USB,
217 .flags = IORESOURCE_IRQ,
218 },
219};
220
221static u64 udc_dma_mask = ~(u32)0;
222
Eric Miaoe09d02e2007-07-17 10:45:58 +0100223struct platform_device pxa_device_udc = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 .name = "pxa2xx-udc",
225 .id = -1,
226 .resource = pxa2xx_udc_resources,
227 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
228 .dev = {
229 .platform_data = &pxa_udc_info,
230 .dma_mask = &udc_dma_mask,
231 }
232};
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234static struct resource pxafb_resources[] = {
235 [0] = {
236 .start = 0x44000000,
237 .end = 0x4400ffff,
238 .flags = IORESOURCE_MEM,
239 },
240 [1] = {
241 .start = IRQ_LCD,
242 .end = IRQ_LCD,
243 .flags = IORESOURCE_IRQ,
244 },
245};
246
247static u64 fb_dma_mask = ~(u64)0;
248
Eric Miaoe09d02e2007-07-17 10:45:58 +0100249struct platform_device pxa_device_fb = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 .name = "pxa2xx-fb",
251 .id = -1,
252 .dev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 .dma_mask = &fb_dma_mask,
254 .coherent_dma_mask = 0xffffffff,
255 },
256 .num_resources = ARRAY_SIZE(pxafb_resources),
257 .resource = pxafb_resources,
258};
259
Richard Purdied14b2722006-09-20 22:54:21 +0100260void __init set_pxa_fb_info(struct pxafb_mach_info *info)
261{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100262 pxa_device_fb.dev.platform_data = info;
Richard Purdied14b2722006-09-20 22:54:21 +0100263}
264
Richard Purdiecb38c562005-10-14 16:07:25 +0100265void __init set_pxa_fb_parent(struct device *parent_dev)
266{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100267 pxa_device_fb.dev.parent = parent_dev;
Richard Purdiecb38c562005-10-14 16:07:25 +0100268}
269
Russell Kinge259a3a2007-08-20 09:47:41 +0100270static struct resource pxa_resource_ffuart[] = {
271 {
272 .start = __PREG(FFUART),
273 .end = __PREG(FFUART) + 35,
274 .flags = IORESOURCE_MEM,
275 }, {
276 .start = IRQ_FFUART,
277 .end = IRQ_FFUART,
278 .flags = IORESOURCE_IRQ,
279 }
280};
281
Eric Miaoe09d02e2007-07-17 10:45:58 +0100282struct platform_device pxa_device_ffuart= {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 .name = "pxa2xx-uart",
284 .id = 0,
Russell Kinge259a3a2007-08-20 09:47:41 +0100285 .resource = pxa_resource_ffuart,
286 .num_resources = ARRAY_SIZE(pxa_resource_ffuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287};
Russell Kinge259a3a2007-08-20 09:47:41 +0100288
289static struct resource pxa_resource_btuart[] = {
290 {
291 .start = __PREG(BTUART),
292 .end = __PREG(BTUART) + 35,
293 .flags = IORESOURCE_MEM,
294 }, {
295 .start = IRQ_BTUART,
296 .end = IRQ_BTUART,
297 .flags = IORESOURCE_IRQ,
298 }
299};
300
Eric Miaoe09d02e2007-07-17 10:45:58 +0100301struct platform_device pxa_device_btuart = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 .name = "pxa2xx-uart",
303 .id = 1,
Russell Kinge259a3a2007-08-20 09:47:41 +0100304 .resource = pxa_resource_btuart,
305 .num_resources = ARRAY_SIZE(pxa_resource_btuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306};
Russell Kinge259a3a2007-08-20 09:47:41 +0100307
308static struct resource pxa_resource_stuart[] = {
309 {
310 .start = __PREG(STUART),
311 .end = __PREG(STUART) + 35,
312 .flags = IORESOURCE_MEM,
313 }, {
314 .start = IRQ_STUART,
315 .end = IRQ_STUART,
316 .flags = IORESOURCE_IRQ,
317 }
318};
319
Eric Miaoe09d02e2007-07-17 10:45:58 +0100320struct platform_device pxa_device_stuart = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 .name = "pxa2xx-uart",
322 .id = 2,
Russell Kinge259a3a2007-08-20 09:47:41 +0100323 .resource = pxa_resource_stuart,
324 .num_resources = ARRAY_SIZE(pxa_resource_stuart),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325};
Russell Kinge259a3a2007-08-20 09:47:41 +0100326
327static struct resource pxa_resource_hwuart[] = {
328 {
329 .start = __PREG(HWUART),
330 .end = __PREG(HWUART) + 47,
331 .flags = IORESOURCE_MEM,
332 }, {
333 .start = IRQ_HWUART,
334 .end = IRQ_HWUART,
335 .flags = IORESOURCE_IRQ,
336 }
337};
338
Eric Miaoe09d02e2007-07-17 10:45:58 +0100339struct platform_device pxa_device_hwuart = {
Matt Reimerd9e29642005-10-28 16:25:02 +0100340 .name = "pxa2xx-uart",
341 .id = 3,
Russell Kinge259a3a2007-08-20 09:47:41 +0100342 .resource = pxa_resource_hwuart,
343 .num_resources = ARRAY_SIZE(pxa_resource_hwuart),
Matt Reimerd9e29642005-10-28 16:25:02 +0100344};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Russell King34f32312007-05-15 10:39:49 +0100346static struct resource pxai2c_resources[] = {
Russell Kingbb9bffc2005-04-30 13:26:06 +0100347 {
348 .start = 0x40301680,
349 .end = 0x403016a3,
350 .flags = IORESOURCE_MEM,
351 }, {
352 .start = IRQ_I2C,
353 .end = IRQ_I2C,
354 .flags = IORESOURCE_IRQ,
355 },
356};
357
Eric Miaoe09d02e2007-07-17 10:45:58 +0100358struct platform_device pxa_device_i2c = {
Russell Kingbb9bffc2005-04-30 13:26:06 +0100359 .name = "pxa2xx-i2c",
360 .id = 0,
Russell King34f32312007-05-15 10:39:49 +0100361 .resource = pxai2c_resources,
362 .num_resources = ARRAY_SIZE(pxai2c_resources),
Russell Kingbb9bffc2005-04-30 13:26:06 +0100363};
364
365void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
366{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100367 pxa_device_i2c.dev.platform_data = info;
Russell Kingbb9bffc2005-04-30 13:26:06 +0100368}
369
Russell King34f32312007-05-15 10:39:49 +0100370static struct resource pxai2s_resources[] = {
Matt Reimerb2640b42005-10-20 23:21:18 +0100371 {
372 .start = 0x40400000,
373 .end = 0x40400083,
374 .flags = IORESOURCE_MEM,
375 }, {
376 .start = IRQ_I2S,
377 .end = IRQ_I2S,
378 .flags = IORESOURCE_IRQ,
379 },
380};
381
Eric Miaoe09d02e2007-07-17 10:45:58 +0100382struct platform_device pxa_device_i2s = {
Matt Reimerb2640b42005-10-20 23:21:18 +0100383 .name = "pxa2xx-i2s",
384 .id = -1,
Russell King34f32312007-05-15 10:39:49 +0100385 .resource = pxai2s_resources,
386 .num_resources = ARRAY_SIZE(pxai2s_resources),
Matt Reimerb2640b42005-10-20 23:21:18 +0100387};
388
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100389static u64 pxaficp_dmamask = ~(u32)0;
390
Eric Miaoe09d02e2007-07-17 10:45:58 +0100391struct platform_device pxa_device_ficp = {
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100392 .name = "pxa2xx-ir",
393 .id = -1,
394 .dev = {
395 .dma_mask = &pxaficp_dmamask,
396 .coherent_dma_mask = 0xffffffff,
397 },
398};
399
400void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
401{
Eric Miaoe09d02e2007-07-17 10:45:58 +0100402 pxa_device_ficp.dev.platform_data = info;
Nicolas Pitre6f475c02005-10-28 16:39:33 +0100403}
404
Eric Miaoe09d02e2007-07-17 10:45:58 +0100405struct platform_device pxa_device_rtc = {
Richard Purdiee842f1c2006-03-27 01:16:46 -0800406 .name = "sa1100-rtc",
407 .id = -1,
408};