2 * linux/arch/arm/mach-pxa/generic.c
4 * Author: Nicolas Pitre
5 * Created: Jun 15, 2001
6 * Copyright: MontaVista Software Inc.
8 * Code common to all PXA machines.
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.
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
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/delay.h>
23 #include <linux/platform_device.h>
24 #include <linux/ioport.h>
26 #include <linux/string.h>
28 #include <asm/hardware.h>
30 #include <asm/system.h>
31 #include <asm/pgtable.h>
32 #include <asm/mach/map.h>
34 #include <asm/arch/pxa-regs.h>
35 #include <asm/arch/gpio.h>
36 #include <asm/arch/udc.h>
37 #include <asm/arch/pxafb.h>
38 #include <asm/arch/mmc.h>
39 #include <asm/arch/irda.h>
40 #include <asm/arch/i2c.h>
46 * 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.
50 unsigned int get_clk_frequency_khz(int info
)
52 if (cpu_is_pxa21x() || cpu_is_pxa25x())
53 return pxa25x_get_clk_frequency_khz(info
);
54 else if (cpu_is_pxa27x())
55 return pxa27x_get_clk_frequency_khz(info
);
57 return pxa3xx_get_clk_frequency_khz(info
);
59 EXPORT_SYMBOL(get_clk_frequency_khz
);
62 * Return the current memory clock frequency in units of 10kHz
64 unsigned int get_memclk_frequency_10khz(void)
66 if (cpu_is_pxa21x() || cpu_is_pxa25x())
67 return pxa25x_get_memclk_frequency_10khz();
68 else if (cpu_is_pxa27x())
69 return pxa27x_get_memclk_frequency_10khz();
71 return pxa3xx_get_memclk_frequency_10khz();
73 EXPORT_SYMBOL(get_memclk_frequency_10khz
);
76 * Handy function to set GPIO alternate functions
80 int pxa_gpio_mode(int gpio_mode
)
83 int gpio
= gpio_mode
& GPIO_MD_MASK_NR
;
84 int fn
= (gpio_mode
& GPIO_MD_MASK_FN
) >> 8;
87 if (gpio
> pxa_last_gpio
)
90 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
);
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
);
106 EXPORT_SYMBOL(pxa_gpio_mode
);
108 int gpio_direction_input(unsigned gpio
)
113 if (gpio
> pxa_last_gpio
)
116 mask
= GPIO_bit(gpio
);
117 local_irq_save(flags
);
119 local_irq_restore(flags
);
123 EXPORT_SYMBOL(gpio_direction_input
);
125 int gpio_direction_output(unsigned gpio
, int value
)
130 if (gpio
> pxa_last_gpio
)
133 mask
= GPIO_bit(gpio
);
134 local_irq_save(flags
);
140 local_irq_restore(flags
);
144 EXPORT_SYMBOL(gpio_direction_output
);
149 int pxa_gpio_get_value(unsigned gpio
)
151 return __gpio_get_value(gpio
);
154 EXPORT_SYMBOL(pxa_gpio_get_value
);
157 * Set output GPIO level
159 void pxa_gpio_set_value(unsigned gpio
, int value
)
161 __gpio_set_value(gpio
, value
);
164 EXPORT_SYMBOL(pxa_gpio_set_value
);
167 * Routine to safely enable or disable a clock in the CKEN
169 void __pxa_set_cken(int clock
, int enable
)
172 local_irq_save(flags
);
175 CKEN
|= (1 << clock
);
177 CKEN
&= ~(1 << clock
);
179 local_irq_restore(flags
);
182 EXPORT_SYMBOL(__pxa_set_cken
);
185 * Intel PXA2xx internal register mapping.
187 * Note 1: not all PXA2xx variants implement all those addresses.
189 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
190 * and cache flush area.
192 static struct map_desc standard_io_desc
[] __initdata
= {
194 .virtual = 0xf2000000,
195 .pfn
= __phys_to_pfn(0x40000000),
196 .length
= 0x02000000,
199 .virtual = 0xf4000000,
200 .pfn
= __phys_to_pfn(0x44000000),
201 .length
= 0x00100000,
204 .virtual = 0xf6000000,
205 .pfn
= __phys_to_pfn(0x48000000),
206 .length
= 0x00100000,
209 .virtual = 0xf8000000,
210 .pfn
= __phys_to_pfn(0x4c000000),
211 .length
= 0x00100000,
214 .virtual = 0xfa000000,
215 .pfn
= __phys_to_pfn(0x50000000),
216 .length
= 0x00100000,
219 .virtual = 0xfe000000,
220 .pfn
= __phys_to_pfn(0x58000000),
221 .length
= 0x00100000,
223 }, { /* UNCACHED_PHYS_0 */
224 .virtual = 0xff000000,
225 .pfn
= __phys_to_pfn(0x00000000),
226 .length
= 0x00100000,
231 void __init
pxa_map_io(void)
233 iotable_init(standard_io_desc
, ARRAY_SIZE(standard_io_desc
));
234 get_clk_frequency_khz(1);
238 void __init
pxa_register_device(struct platform_device
*dev
, void *data
)
242 dev
->dev
.platform_data
= data
;
244 ret
= platform_device_register(dev
);
246 dev_err(&dev
->dev
, "unable to register device: %d\n", ret
);
250 static struct resource pxamci_resources
[] = {
254 .flags
= IORESOURCE_MEM
,
259 .flags
= IORESOURCE_IRQ
,
263 static u64 pxamci_dmamask
= 0xffffffffUL
;
265 struct platform_device pxa_device_mci
= {
266 .name
= "pxa2xx-mci",
269 .dma_mask
= &pxamci_dmamask
,
270 .coherent_dma_mask
= 0xffffffff,
272 .num_resources
= ARRAY_SIZE(pxamci_resources
),
273 .resource
= pxamci_resources
,
276 void __init
pxa_set_mci_info(struct pxamci_platform_data
*info
)
278 pxa_register_device(&pxa_device_mci
, info
);
282 static struct pxa2xx_udc_mach_info pxa_udc_info
;
284 void __init
pxa_set_udc_info(struct pxa2xx_udc_mach_info
*info
)
286 memcpy(&pxa_udc_info
, info
, sizeof *info
);
289 static struct resource pxa2xx_udc_resources
[] = {
293 .flags
= IORESOURCE_MEM
,
298 .flags
= IORESOURCE_IRQ
,
302 static u64 udc_dma_mask
= ~(u32
)0;
304 struct platform_device pxa_device_udc
= {
305 .name
= "pxa2xx-udc",
307 .resource
= pxa2xx_udc_resources
,
308 .num_resources
= ARRAY_SIZE(pxa2xx_udc_resources
),
310 .platform_data
= &pxa_udc_info
,
311 .dma_mask
= &udc_dma_mask
,
315 static struct resource pxafb_resources
[] = {
319 .flags
= IORESOURCE_MEM
,
324 .flags
= IORESOURCE_IRQ
,
328 static u64 fb_dma_mask
= ~(u64
)0;
330 struct platform_device pxa_device_fb
= {
334 .dma_mask
= &fb_dma_mask
,
335 .coherent_dma_mask
= 0xffffffff,
337 .num_resources
= ARRAY_SIZE(pxafb_resources
),
338 .resource
= pxafb_resources
,
341 void __init
set_pxa_fb_info(struct pxafb_mach_info
*info
)
343 pxa_register_device(&pxa_device_fb
, info
);
346 void __init
set_pxa_fb_parent(struct device
*parent_dev
)
348 pxa_device_fb
.dev
.parent
= parent_dev
;
351 static struct resource pxa_resource_ffuart
[] = {
353 .start
= __PREG(FFUART
),
354 .end
= __PREG(FFUART
) + 35,
355 .flags
= IORESOURCE_MEM
,
359 .flags
= IORESOURCE_IRQ
,
363 struct platform_device pxa_device_ffuart
= {
364 .name
= "pxa2xx-uart",
366 .resource
= pxa_resource_ffuart
,
367 .num_resources
= ARRAY_SIZE(pxa_resource_ffuart
),
370 static struct resource pxa_resource_btuart
[] = {
372 .start
= __PREG(BTUART
),
373 .end
= __PREG(BTUART
) + 35,
374 .flags
= IORESOURCE_MEM
,
378 .flags
= IORESOURCE_IRQ
,
382 struct platform_device pxa_device_btuart
= {
383 .name
= "pxa2xx-uart",
385 .resource
= pxa_resource_btuart
,
386 .num_resources
= ARRAY_SIZE(pxa_resource_btuart
),
389 static struct resource pxa_resource_stuart
[] = {
391 .start
= __PREG(STUART
),
392 .end
= __PREG(STUART
) + 35,
393 .flags
= IORESOURCE_MEM
,
397 .flags
= IORESOURCE_IRQ
,
401 struct platform_device pxa_device_stuart
= {
402 .name
= "pxa2xx-uart",
404 .resource
= pxa_resource_stuart
,
405 .num_resources
= ARRAY_SIZE(pxa_resource_stuart
),
408 static struct resource pxa_resource_hwuart
[] = {
410 .start
= __PREG(HWUART
),
411 .end
= __PREG(HWUART
) + 47,
412 .flags
= IORESOURCE_MEM
,
416 .flags
= IORESOURCE_IRQ
,
420 struct platform_device pxa_device_hwuart
= {
421 .name
= "pxa2xx-uart",
423 .resource
= pxa_resource_hwuart
,
424 .num_resources
= ARRAY_SIZE(pxa_resource_hwuart
),
427 static struct resource pxai2c_resources
[] = {
431 .flags
= IORESOURCE_MEM
,
435 .flags
= IORESOURCE_IRQ
,
439 struct platform_device pxa_device_i2c
= {
440 .name
= "pxa2xx-i2c",
442 .resource
= pxai2c_resources
,
443 .num_resources
= ARRAY_SIZE(pxai2c_resources
),
446 void __init
pxa_set_i2c_info(struct i2c_pxa_platform_data
*info
)
448 pxa_register_device(&pxa_device_i2c
, info
);
451 static struct resource pxai2s_resources
[] = {
455 .flags
= IORESOURCE_MEM
,
459 .flags
= IORESOURCE_IRQ
,
463 struct platform_device pxa_device_i2s
= {
464 .name
= "pxa2xx-i2s",
466 .resource
= pxai2s_resources
,
467 .num_resources
= ARRAY_SIZE(pxai2s_resources
),
470 static u64 pxaficp_dmamask
= ~(u32
)0;
472 struct platform_device pxa_device_ficp
= {
476 .dma_mask
= &pxaficp_dmamask
,
477 .coherent_dma_mask
= 0xffffffff,
481 void __init
pxa_set_ficp_info(struct pxaficp_platform_data
*info
)
483 pxa_register_device(&pxa_device_ficp
, info
);
486 struct platform_device pxa_device_rtc
= {
487 .name
= "sa1100-rtc",