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
);
111 int pxa_gpio_get_value(unsigned gpio
)
113 return __gpio_get_value(gpio
);
116 EXPORT_SYMBOL(pxa_gpio_get_value
);
119 * Set output GPIO level
121 void pxa_gpio_set_value(unsigned gpio
, int value
)
123 __gpio_set_value(gpio
, value
);
126 EXPORT_SYMBOL(pxa_gpio_set_value
);
129 * Routine to safely enable or disable a clock in the CKEN
131 void __pxa_set_cken(int clock
, int enable
)
134 local_irq_save(flags
);
137 CKEN
|= (1 << clock
);
139 CKEN
&= ~(1 << clock
);
141 local_irq_restore(flags
);
144 EXPORT_SYMBOL(__pxa_set_cken
);
147 * Intel PXA2xx internal register mapping.
149 * Note 1: not all PXA2xx variants implement all those addresses.
151 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
152 * and cache flush area.
154 static struct map_desc standard_io_desc
[] __initdata
= {
156 .virtual = 0xf2000000,
157 .pfn
= __phys_to_pfn(0x40000000),
158 .length
= 0x02000000,
161 .virtual = 0xf4000000,
162 .pfn
= __phys_to_pfn(0x44000000),
163 .length
= 0x00100000,
166 .virtual = 0xf6000000,
167 .pfn
= __phys_to_pfn(0x48000000),
168 .length
= 0x00100000,
171 .virtual = 0xf8000000,
172 .pfn
= __phys_to_pfn(0x4c000000),
173 .length
= 0x00100000,
176 .virtual = 0xfa000000,
177 .pfn
= __phys_to_pfn(0x50000000),
178 .length
= 0x00100000,
181 .virtual = 0xfe000000,
182 .pfn
= __phys_to_pfn(0x58000000),
183 .length
= 0x00100000,
185 }, { /* UNCACHED_PHYS_0 */
186 .virtual = 0xff000000,
187 .pfn
= __phys_to_pfn(0x00000000),
188 .length
= 0x00100000,
193 void __init
pxa_map_io(void)
195 iotable_init(standard_io_desc
, ARRAY_SIZE(standard_io_desc
));
196 get_clk_frequency_khz(1);
200 static struct resource pxamci_resources
[] = {
204 .flags
= IORESOURCE_MEM
,
209 .flags
= IORESOURCE_IRQ
,
213 static u64 pxamci_dmamask
= 0xffffffffUL
;
215 struct platform_device pxa_device_mci
= {
216 .name
= "pxa2xx-mci",
219 .dma_mask
= &pxamci_dmamask
,
220 .coherent_dma_mask
= 0xffffffff,
222 .num_resources
= ARRAY_SIZE(pxamci_resources
),
223 .resource
= pxamci_resources
,
226 void __init
pxa_set_mci_info(struct pxamci_platform_data
*info
)
228 pxa_device_mci
.dev
.platform_data
= info
;
232 static struct pxa2xx_udc_mach_info pxa_udc_info
;
234 void __init
pxa_set_udc_info(struct pxa2xx_udc_mach_info
*info
)
236 memcpy(&pxa_udc_info
, info
, sizeof *info
);
239 static struct resource pxa2xx_udc_resources
[] = {
243 .flags
= IORESOURCE_MEM
,
248 .flags
= IORESOURCE_IRQ
,
252 static u64 udc_dma_mask
= ~(u32
)0;
254 struct platform_device pxa_device_udc
= {
255 .name
= "pxa2xx-udc",
257 .resource
= pxa2xx_udc_resources
,
258 .num_resources
= ARRAY_SIZE(pxa2xx_udc_resources
),
260 .platform_data
= &pxa_udc_info
,
261 .dma_mask
= &udc_dma_mask
,
265 static struct resource pxafb_resources
[] = {
269 .flags
= IORESOURCE_MEM
,
274 .flags
= IORESOURCE_IRQ
,
278 static u64 fb_dma_mask
= ~(u64
)0;
280 struct platform_device pxa_device_fb
= {
284 .dma_mask
= &fb_dma_mask
,
285 .coherent_dma_mask
= 0xffffffff,
287 .num_resources
= ARRAY_SIZE(pxafb_resources
),
288 .resource
= pxafb_resources
,
291 void __init
set_pxa_fb_info(struct pxafb_mach_info
*info
)
293 pxa_device_fb
.dev
.platform_data
= info
;
296 void __init
set_pxa_fb_parent(struct device
*parent_dev
)
298 pxa_device_fb
.dev
.parent
= parent_dev
;
301 static struct resource pxa_resource_ffuart
[] = {
303 .start
= __PREG(FFUART
),
304 .end
= __PREG(FFUART
) + 35,
305 .flags
= IORESOURCE_MEM
,
309 .flags
= IORESOURCE_IRQ
,
313 struct platform_device pxa_device_ffuart
= {
314 .name
= "pxa2xx-uart",
316 .resource
= pxa_resource_ffuart
,
317 .num_resources
= ARRAY_SIZE(pxa_resource_ffuart
),
320 static struct resource pxa_resource_btuart
[] = {
322 .start
= __PREG(BTUART
),
323 .end
= __PREG(BTUART
) + 35,
324 .flags
= IORESOURCE_MEM
,
328 .flags
= IORESOURCE_IRQ
,
332 struct platform_device pxa_device_btuart
= {
333 .name
= "pxa2xx-uart",
335 .resource
= pxa_resource_btuart
,
336 .num_resources
= ARRAY_SIZE(pxa_resource_btuart
),
339 static struct resource pxa_resource_stuart
[] = {
341 .start
= __PREG(STUART
),
342 .end
= __PREG(STUART
) + 35,
343 .flags
= IORESOURCE_MEM
,
347 .flags
= IORESOURCE_IRQ
,
351 struct platform_device pxa_device_stuart
= {
352 .name
= "pxa2xx-uart",
354 .resource
= pxa_resource_stuart
,
355 .num_resources
= ARRAY_SIZE(pxa_resource_stuart
),
358 static struct resource pxa_resource_hwuart
[] = {
360 .start
= __PREG(HWUART
),
361 .end
= __PREG(HWUART
) + 47,
362 .flags
= IORESOURCE_MEM
,
366 .flags
= IORESOURCE_IRQ
,
370 struct platform_device pxa_device_hwuart
= {
371 .name
= "pxa2xx-uart",
373 .resource
= pxa_resource_hwuart
,
374 .num_resources
= ARRAY_SIZE(pxa_resource_hwuart
),
377 static struct resource pxai2c_resources
[] = {
381 .flags
= IORESOURCE_MEM
,
385 .flags
= IORESOURCE_IRQ
,
389 struct platform_device pxa_device_i2c
= {
390 .name
= "pxa2xx-i2c",
392 .resource
= pxai2c_resources
,
393 .num_resources
= ARRAY_SIZE(pxai2c_resources
),
396 void __init
pxa_set_i2c_info(struct i2c_pxa_platform_data
*info
)
398 pxa_device_i2c
.dev
.platform_data
= info
;
401 static struct resource pxai2s_resources
[] = {
405 .flags
= IORESOURCE_MEM
,
409 .flags
= IORESOURCE_IRQ
,
413 struct platform_device pxa_device_i2s
= {
414 .name
= "pxa2xx-i2s",
416 .resource
= pxai2s_resources
,
417 .num_resources
= ARRAY_SIZE(pxai2s_resources
),
420 static u64 pxaficp_dmamask
= ~(u32
)0;
422 struct platform_device pxa_device_ficp
= {
426 .dma_mask
= &pxaficp_dmamask
,
427 .coherent_dma_mask
= 0xffffffff,
431 void __init
pxa_set_ficp_info(struct pxaficp_platform_data
*info
)
433 pxa_device_ficp
.dev
.platform_data
= info
;
436 struct platform_device pxa_device_rtc
= {
437 .name
= "sa1100-rtc",