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>
27 #include <linux/dma-mapping.h>
29 #include <asm/hardware.h>
31 #include <asm/system.h>
32 #include <asm/pgtable.h>
33 #include <asm/mach/map.h>
35 #include <asm/arch/pxa-regs.h>
36 #include <asm/arch/gpio.h>
37 #include <asm/arch/udc.h>
38 #include <asm/arch/pxafb.h>
39 #include <asm/arch/mmc.h>
40 #include <asm/arch/irda.h>
41 #include <asm/arch/i2c.h>
47 * Get the clock frequency as reflected by CCCR and the turbo flag.
48 * We assume these values have been applied via a fcs.
49 * If info is not 0 we also display the current settings.
51 unsigned int get_clk_frequency_khz(int info)
53 if (cpu_is_pxa21x() || cpu_is_pxa25x())
54 return pxa25x_get_clk_frequency_khz(info);
55 else if (cpu_is_pxa27x())
56 return pxa27x_get_clk_frequency_khz(info);
58 return pxa3xx_get_clk_frequency_khz(info);
60 EXPORT_SYMBOL(get_clk_frequency_khz);
63 * Return the current memory clock frequency in units of 10kHz
65 unsigned int get_memclk_frequency_10khz(void)
67 if (cpu_is_pxa21x() || cpu_is_pxa25x())
68 return pxa25x_get_memclk_frequency_10khz();
69 else if (cpu_is_pxa27x())
70 return pxa27x_get_memclk_frequency_10khz();
72 return pxa3xx_get_memclk_frequency_10khz();
74 EXPORT_SYMBOL(get_memclk_frequency_10khz);
77 * Handy function to set GPIO alternate functions
81 int pxa_gpio_mode(int gpio_mode)
84 int gpio = gpio_mode & GPIO_MD_MASK_NR;
85 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
88 if (gpio > pxa_last_gpio)
91 local_irq_save(flags);
92 if (gpio_mode & GPIO_DFLT_LOW)
93 GPCR(gpio) = GPIO_bit(gpio);
94 else if (gpio_mode & GPIO_DFLT_HIGH)
95 GPSR(gpio) = GPIO_bit(gpio);
96 if (gpio_mode & GPIO_MD_MASK_DIR)
97 GPDR(gpio) |= GPIO_bit(gpio);
99 GPDR(gpio) &= ~GPIO_bit(gpio);
100 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
101 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
102 local_irq_restore(flags);
107 EXPORT_SYMBOL(pxa_gpio_mode);
109 int gpio_direction_input(unsigned gpio)
114 if (gpio > pxa_last_gpio)
117 mask = GPIO_bit(gpio);
118 local_irq_save(flags);
120 local_irq_restore(flags);
124 EXPORT_SYMBOL(gpio_direction_input);
126 int gpio_direction_output(unsigned gpio, int value)
131 if (gpio > pxa_last_gpio)
134 mask = GPIO_bit(gpio);
135 local_irq_save(flags);
141 local_irq_restore(flags);
145 EXPORT_SYMBOL(gpio_direction_output);
150 int pxa_gpio_get_value(unsigned gpio)
152 return __gpio_get_value(gpio);
155 EXPORT_SYMBOL(pxa_gpio_get_value);
158 * Set output GPIO level
160 void pxa_gpio_set_value(unsigned gpio, int value)
162 __gpio_set_value(gpio, value);
165 EXPORT_SYMBOL(pxa_gpio_set_value);
168 * Routine to safely enable or disable a clock in the CKEN
170 void __pxa_set_cken(int clock, int enable)
173 local_irq_save(flags);
176 CKEN |= (1 << clock);
178 CKEN &= ~(1 << clock);
180 local_irq_restore(flags);
183 EXPORT_SYMBOL(__pxa_set_cken);
186 * Intel PXA2xx internal register mapping.
188 * Note 1: not all PXA2xx variants implement all those addresses.
190 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
191 * and cache flush area.
193 static struct map_desc standard_io_desc[] __initdata = {
195 .virtual = 0xf2000000,
196 .pfn = __phys_to_pfn(0x40000000),
197 .length = 0x02000000,
200 .virtual = 0xf4000000,
201 .pfn = __phys_to_pfn(0x44000000),
202 .length = 0x00100000,
205 .virtual = 0xf6000000,
206 .pfn = __phys_to_pfn(0x48000000),
207 .length = 0x00100000,
210 .virtual = 0xf8000000,
211 .pfn = __phys_to_pfn(0x4c000000),
212 .length = 0x00100000,
215 .virtual = 0xfa000000,
216 .pfn = __phys_to_pfn(0x50000000),
217 .length = 0x00100000,
220 .virtual = 0xfe000000,
221 .pfn = __phys_to_pfn(0x58000000),
222 .length = 0x00100000,
224 }, { /* UNCACHED_PHYS_0 */
225 .virtual = 0xff000000,
226 .pfn = __phys_to_pfn(0x00000000),
227 .length = 0x00100000,
232 void __init pxa_map_io(void)
234 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
235 get_clk_frequency_khz(1);
239 void __init pxa_register_device(struct platform_device *dev, void *data)
243 dev->dev.platform_data = data;
245 ret = platform_device_register(dev);
247 dev_err(&dev->dev, "unable to register device: %d\n", ret);
251 static struct resource pxamci_resources[] = {
255 .flags = IORESOURCE_MEM,
260 .flags = IORESOURCE_IRQ,
264 static u64 pxamci_dmamask = 0xffffffffUL;
266 struct platform_device pxa_device_mci = {
267 .name = "pxa2xx-mci",
270 .dma_mask = &pxamci_dmamask,
271 .coherent_dma_mask = 0xffffffff,
273 .num_resources = ARRAY_SIZE(pxamci_resources),
274 .resource = pxamci_resources,
277 void __init pxa_set_mci_info(struct pxamci_platform_data *info)
279 pxa_register_device(&pxa_device_mci, info);
283 static struct pxa2xx_udc_mach_info pxa_udc_info;
285 void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
287 memcpy(&pxa_udc_info, info, sizeof *info);
290 static struct resource pxa2xx_udc_resources[] = {
294 .flags = IORESOURCE_MEM,
299 .flags = IORESOURCE_IRQ,
303 static u64 udc_dma_mask = ~(u32)0;
305 struct platform_device pxa_device_udc = {
306 .name = "pxa2xx-udc",
308 .resource = pxa2xx_udc_resources,
309 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
311 .platform_data = &pxa_udc_info,
312 .dma_mask = &udc_dma_mask,
316 static struct resource pxafb_resources[] = {
320 .flags = IORESOURCE_MEM,
325 .flags = IORESOURCE_IRQ,
329 static u64 fb_dma_mask = ~(u64)0;
331 struct platform_device pxa_device_fb = {
335 .dma_mask = &fb_dma_mask,
336 .coherent_dma_mask = 0xffffffff,
338 .num_resources = ARRAY_SIZE(pxafb_resources),
339 .resource = pxafb_resources,
342 void __init set_pxa_fb_info(struct pxafb_mach_info *info)
344 pxa_register_device(&pxa_device_fb, info);
347 void __init set_pxa_fb_parent(struct device *parent_dev)
349 pxa_device_fb.dev.parent = parent_dev;
352 static struct resource pxa_resource_ffuart[] = {
354 .start = __PREG(FFUART),
355 .end = __PREG(FFUART) + 35,
356 .flags = IORESOURCE_MEM,
360 .flags = IORESOURCE_IRQ,
364 struct platform_device pxa_device_ffuart= {
365 .name = "pxa2xx-uart",
367 .resource = pxa_resource_ffuart,
368 .num_resources = ARRAY_SIZE(pxa_resource_ffuart),
371 static struct resource pxa_resource_btuart[] = {
373 .start = __PREG(BTUART),
374 .end = __PREG(BTUART) + 35,
375 .flags = IORESOURCE_MEM,
379 .flags = IORESOURCE_IRQ,
383 struct platform_device pxa_device_btuart = {
384 .name = "pxa2xx-uart",
386 .resource = pxa_resource_btuart,
387 .num_resources = ARRAY_SIZE(pxa_resource_btuart),
390 static struct resource pxa_resource_stuart[] = {
392 .start = __PREG(STUART),
393 .end = __PREG(STUART) + 35,
394 .flags = IORESOURCE_MEM,
398 .flags = IORESOURCE_IRQ,
402 struct platform_device pxa_device_stuart = {
403 .name = "pxa2xx-uart",
405 .resource = pxa_resource_stuart,
406 .num_resources = ARRAY_SIZE(pxa_resource_stuart),
409 static struct resource pxa_resource_hwuart[] = {
411 .start = __PREG(HWUART),
412 .end = __PREG(HWUART) + 47,
413 .flags = IORESOURCE_MEM,
417 .flags = IORESOURCE_IRQ,
421 struct platform_device pxa_device_hwuart = {
422 .name = "pxa2xx-uart",
424 .resource = pxa_resource_hwuart,
425 .num_resources = ARRAY_SIZE(pxa_resource_hwuart),
428 static struct resource pxai2c_resources[] = {
432 .flags = IORESOURCE_MEM,
436 .flags = IORESOURCE_IRQ,
440 struct platform_device pxa_device_i2c = {
441 .name = "pxa2xx-i2c",
443 .resource = pxai2c_resources,
444 .num_resources = ARRAY_SIZE(pxai2c_resources),
447 void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
449 pxa_register_device(&pxa_device_i2c, info);
452 static struct resource pxai2s_resources[] = {
456 .flags = IORESOURCE_MEM,
460 .flags = IORESOURCE_IRQ,
464 struct platform_device pxa_device_i2s = {
465 .name = "pxa2xx-i2s",
467 .resource = pxai2s_resources,
468 .num_resources = ARRAY_SIZE(pxai2s_resources),
471 static u64 pxaficp_dmamask = ~(u32)0;
473 struct platform_device pxa_device_ficp = {
477 .dma_mask = &pxaficp_dmamask,
478 .coherent_dma_mask = 0xffffffff,
482 void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
484 pxa_register_device(&pxa_device_ficp, info);
487 struct platform_device pxa_device_rtc = {
488 .name = "sa1100-rtc",
494 static u64 pxa25x_ssp_dma_mask = DMA_BIT_MASK(32);
496 static struct resource pxa25x_resource_ssp[] = {
500 .flags = IORESOURCE_MEM,
505 .flags = IORESOURCE_IRQ,
511 .flags = IORESOURCE_DMA,
517 .flags = IORESOURCE_DMA,
521 struct platform_device pxa25x_device_ssp = {
522 .name = "pxa25x-ssp",
525 .dma_mask = &pxa25x_ssp_dma_mask,
526 .coherent_dma_mask = DMA_BIT_MASK(32),
528 .resource = pxa25x_resource_ssp,
529 .num_resources = ARRAY_SIZE(pxa25x_resource_ssp),
532 static u64 pxa25x_nssp_dma_mask = DMA_BIT_MASK(32);
534 static struct resource pxa25x_resource_nssp[] = {
538 .flags = IORESOURCE_MEM,
543 .flags = IORESOURCE_IRQ,
549 .flags = IORESOURCE_DMA,
555 .flags = IORESOURCE_DMA,
559 struct platform_device pxa25x_device_nssp = {
560 .name = "pxa25x-nssp",
563 .dma_mask = &pxa25x_nssp_dma_mask,
564 .coherent_dma_mask = DMA_BIT_MASK(32),
566 .resource = pxa25x_resource_nssp,
567 .num_resources = ARRAY_SIZE(pxa25x_resource_nssp),
570 static u64 pxa25x_assp_dma_mask = DMA_BIT_MASK(32);
572 static struct resource pxa25x_resource_assp[] = {
576 .flags = IORESOURCE_MEM,
581 .flags = IORESOURCE_IRQ,
587 .flags = IORESOURCE_DMA,
593 .flags = IORESOURCE_DMA,
597 struct platform_device pxa25x_device_assp = {
598 /* ASSP is basically equivalent to NSSP */
599 .name = "pxa25x-nssp",
602 .dma_mask = &pxa25x_assp_dma_mask,
603 .coherent_dma_mask = DMA_BIT_MASK(32),
605 .resource = pxa25x_resource_assp,
606 .num_resources = ARRAY_SIZE(pxa25x_resource_assp),
608 #endif /* CONFIG_PXA25x */
610 #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
612 static u64 pxa27x_ssp1_dma_mask = DMA_BIT_MASK(32);
614 static struct resource pxa27x_resource_ssp1[] = {
618 .flags = IORESOURCE_MEM,
623 .flags = IORESOURCE_IRQ,
629 .flags = IORESOURCE_DMA,
635 .flags = IORESOURCE_DMA,
639 struct platform_device pxa27x_device_ssp1 = {
640 .name = "pxa27x-ssp",
643 .dma_mask = &pxa27x_ssp1_dma_mask,
644 .coherent_dma_mask = DMA_BIT_MASK(32),
646 .resource = pxa27x_resource_ssp1,
647 .num_resources = ARRAY_SIZE(pxa27x_resource_ssp1),
650 static u64 pxa27x_ssp2_dma_mask = DMA_BIT_MASK(32);
652 static struct resource pxa27x_resource_ssp2[] = {
656 .flags = IORESOURCE_MEM,
661 .flags = IORESOURCE_IRQ,
667 .flags = IORESOURCE_DMA,
673 .flags = IORESOURCE_DMA,
677 struct platform_device pxa27x_device_ssp2 = {
678 .name = "pxa27x-ssp",
681 .dma_mask = &pxa27x_ssp2_dma_mask,
682 .coherent_dma_mask = DMA_BIT_MASK(32),
684 .resource = pxa27x_resource_ssp2,
685 .num_resources = ARRAY_SIZE(pxa27x_resource_ssp2),
688 static u64 pxa27x_ssp3_dma_mask = DMA_BIT_MASK(32);
690 static struct resource pxa27x_resource_ssp3[] = {
694 .flags = IORESOURCE_MEM,
699 .flags = IORESOURCE_IRQ,
705 .flags = IORESOURCE_DMA,
711 .flags = IORESOURCE_DMA,
715 struct platform_device pxa27x_device_ssp3 = {
716 .name = "pxa27x-ssp",
719 .dma_mask = &pxa27x_ssp3_dma_mask,
720 .coherent_dma_mask = DMA_BIT_MASK(32),
722 .resource = pxa27x_resource_ssp3,
723 .num_resources = ARRAY_SIZE(pxa27x_resource_ssp3),
725 #endif /* CONFIG_PXA27x || CONFIG_PXA3xx */
728 static u64 pxa3xx_ssp4_dma_mask = DMA_BIT_MASK(32);
730 static struct resource pxa3xx_resource_ssp4[] = {
734 .flags = IORESOURCE_MEM,
739 .flags = IORESOURCE_IRQ,
745 .flags = IORESOURCE_DMA,
751 .flags = IORESOURCE_DMA,
755 struct platform_device pxa3xx_device_ssp4 = {
756 /* PXA3xx SSP is basically equivalent to PXA27x */
757 .name = "pxa27x-ssp",
760 .dma_mask = &pxa3xx_ssp4_dma_mask,
761 .coherent_dma_mask = DMA_BIT_MASK(32),
763 .resource = pxa3xx_resource_ssp4,
764 .num_resources = ARRAY_SIZE(pxa3xx_resource_ssp4),
766 #endif /* CONFIG_PXA3xx */