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,
265 .flags = IORESOURCE_DMA,
270 .flags = IORESOURCE_DMA,
274 static u64 pxamci_dmamask = 0xffffffffUL;
276 struct platform_device pxa_device_mci = {
277 .name = "pxa2xx-mci",
280 .dma_mask = &pxamci_dmamask,
281 .coherent_dma_mask = 0xffffffff,
283 .num_resources = ARRAY_SIZE(pxamci_resources),
284 .resource = pxamci_resources,
287 void __init pxa_set_mci_info(struct pxamci_platform_data *info)
289 pxa_register_device(&pxa_device_mci, info);
293 static struct pxa2xx_udc_mach_info pxa_udc_info;
295 void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
297 memcpy(&pxa_udc_info, info, sizeof *info);
300 static struct resource pxa2xx_udc_resources[] = {
304 .flags = IORESOURCE_MEM,
309 .flags = IORESOURCE_IRQ,
313 static u64 udc_dma_mask = ~(u32)0;
315 struct platform_device pxa_device_udc = {
316 .name = "pxa2xx-udc",
318 .resource = pxa2xx_udc_resources,
319 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
321 .platform_data = &pxa_udc_info,
322 .dma_mask = &udc_dma_mask,
326 static struct resource pxafb_resources[] = {
330 .flags = IORESOURCE_MEM,
335 .flags = IORESOURCE_IRQ,
339 static u64 fb_dma_mask = ~(u64)0;
341 struct platform_device pxa_device_fb = {
345 .dma_mask = &fb_dma_mask,
346 .coherent_dma_mask = 0xffffffff,
348 .num_resources = ARRAY_SIZE(pxafb_resources),
349 .resource = pxafb_resources,
352 void __init set_pxa_fb_info(struct pxafb_mach_info *info)
354 pxa_register_device(&pxa_device_fb, info);
357 void __init set_pxa_fb_parent(struct device *parent_dev)
359 pxa_device_fb.dev.parent = parent_dev;
362 static struct resource pxa_resource_ffuart[] = {
364 .start = __PREG(FFUART),
365 .end = __PREG(FFUART) + 35,
366 .flags = IORESOURCE_MEM,
370 .flags = IORESOURCE_IRQ,
374 struct platform_device pxa_device_ffuart= {
375 .name = "pxa2xx-uart",
377 .resource = pxa_resource_ffuart,
378 .num_resources = ARRAY_SIZE(pxa_resource_ffuart),
381 static struct resource pxa_resource_btuart[] = {
383 .start = __PREG(BTUART),
384 .end = __PREG(BTUART) + 35,
385 .flags = IORESOURCE_MEM,
389 .flags = IORESOURCE_IRQ,
393 struct platform_device pxa_device_btuart = {
394 .name = "pxa2xx-uart",
396 .resource = pxa_resource_btuart,
397 .num_resources = ARRAY_SIZE(pxa_resource_btuart),
400 static struct resource pxa_resource_stuart[] = {
402 .start = __PREG(STUART),
403 .end = __PREG(STUART) + 35,
404 .flags = IORESOURCE_MEM,
408 .flags = IORESOURCE_IRQ,
412 struct platform_device pxa_device_stuart = {
413 .name = "pxa2xx-uart",
415 .resource = pxa_resource_stuart,
416 .num_resources = ARRAY_SIZE(pxa_resource_stuart),
419 static struct resource pxa_resource_hwuart[] = {
421 .start = __PREG(HWUART),
422 .end = __PREG(HWUART) + 47,
423 .flags = IORESOURCE_MEM,
427 .flags = IORESOURCE_IRQ,
431 struct platform_device pxa_device_hwuart = {
432 .name = "pxa2xx-uart",
434 .resource = pxa_resource_hwuart,
435 .num_resources = ARRAY_SIZE(pxa_resource_hwuart),
438 static struct resource pxai2c_resources[] = {
442 .flags = IORESOURCE_MEM,
446 .flags = IORESOURCE_IRQ,
450 struct platform_device pxa_device_i2c = {
451 .name = "pxa2xx-i2c",
453 .resource = pxai2c_resources,
454 .num_resources = ARRAY_SIZE(pxai2c_resources),
457 void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
459 pxa_register_device(&pxa_device_i2c, info);
462 static struct resource pxai2s_resources[] = {
466 .flags = IORESOURCE_MEM,
470 .flags = IORESOURCE_IRQ,
474 struct platform_device pxa_device_i2s = {
475 .name = "pxa2xx-i2s",
477 .resource = pxai2s_resources,
478 .num_resources = ARRAY_SIZE(pxai2s_resources),
481 static u64 pxaficp_dmamask = ~(u32)0;
483 struct platform_device pxa_device_ficp = {
487 .dma_mask = &pxaficp_dmamask,
488 .coherent_dma_mask = 0xffffffff,
492 void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
494 pxa_register_device(&pxa_device_ficp, info);
497 struct platform_device pxa_device_rtc = {
498 .name = "sa1100-rtc",
504 static u64 pxa25x_ssp_dma_mask = DMA_BIT_MASK(32);
506 static struct resource pxa25x_resource_ssp[] = {
510 .flags = IORESOURCE_MEM,
515 .flags = IORESOURCE_IRQ,
521 .flags = IORESOURCE_DMA,
527 .flags = IORESOURCE_DMA,
531 struct platform_device pxa25x_device_ssp = {
532 .name = "pxa25x-ssp",
535 .dma_mask = &pxa25x_ssp_dma_mask,
536 .coherent_dma_mask = DMA_BIT_MASK(32),
538 .resource = pxa25x_resource_ssp,
539 .num_resources = ARRAY_SIZE(pxa25x_resource_ssp),
542 static u64 pxa25x_nssp_dma_mask = DMA_BIT_MASK(32);
544 static struct resource pxa25x_resource_nssp[] = {
548 .flags = IORESOURCE_MEM,
553 .flags = IORESOURCE_IRQ,
559 .flags = IORESOURCE_DMA,
565 .flags = IORESOURCE_DMA,
569 struct platform_device pxa25x_device_nssp = {
570 .name = "pxa25x-nssp",
573 .dma_mask = &pxa25x_nssp_dma_mask,
574 .coherent_dma_mask = DMA_BIT_MASK(32),
576 .resource = pxa25x_resource_nssp,
577 .num_resources = ARRAY_SIZE(pxa25x_resource_nssp),
580 static u64 pxa25x_assp_dma_mask = DMA_BIT_MASK(32);
582 static struct resource pxa25x_resource_assp[] = {
586 .flags = IORESOURCE_MEM,
591 .flags = IORESOURCE_IRQ,
597 .flags = IORESOURCE_DMA,
603 .flags = IORESOURCE_DMA,
607 struct platform_device pxa25x_device_assp = {
608 /* ASSP is basically equivalent to NSSP */
609 .name = "pxa25x-nssp",
612 .dma_mask = &pxa25x_assp_dma_mask,
613 .coherent_dma_mask = DMA_BIT_MASK(32),
615 .resource = pxa25x_resource_assp,
616 .num_resources = ARRAY_SIZE(pxa25x_resource_assp),
618 #endif /* CONFIG_PXA25x */
620 #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
622 static u64 pxa27x_ssp1_dma_mask = DMA_BIT_MASK(32);
624 static struct resource pxa27x_resource_ssp1[] = {
628 .flags = IORESOURCE_MEM,
633 .flags = IORESOURCE_IRQ,
639 .flags = IORESOURCE_DMA,
645 .flags = IORESOURCE_DMA,
649 struct platform_device pxa27x_device_ssp1 = {
650 .name = "pxa27x-ssp",
653 .dma_mask = &pxa27x_ssp1_dma_mask,
654 .coherent_dma_mask = DMA_BIT_MASK(32),
656 .resource = pxa27x_resource_ssp1,
657 .num_resources = ARRAY_SIZE(pxa27x_resource_ssp1),
660 static u64 pxa27x_ssp2_dma_mask = DMA_BIT_MASK(32);
662 static struct resource pxa27x_resource_ssp2[] = {
666 .flags = IORESOURCE_MEM,
671 .flags = IORESOURCE_IRQ,
677 .flags = IORESOURCE_DMA,
683 .flags = IORESOURCE_DMA,
687 struct platform_device pxa27x_device_ssp2 = {
688 .name = "pxa27x-ssp",
691 .dma_mask = &pxa27x_ssp2_dma_mask,
692 .coherent_dma_mask = DMA_BIT_MASK(32),
694 .resource = pxa27x_resource_ssp2,
695 .num_resources = ARRAY_SIZE(pxa27x_resource_ssp2),
698 static u64 pxa27x_ssp3_dma_mask = DMA_BIT_MASK(32);
700 static struct resource pxa27x_resource_ssp3[] = {
704 .flags = IORESOURCE_MEM,
709 .flags = IORESOURCE_IRQ,
715 .flags = IORESOURCE_DMA,
721 .flags = IORESOURCE_DMA,
725 struct platform_device pxa27x_device_ssp3 = {
726 .name = "pxa27x-ssp",
729 .dma_mask = &pxa27x_ssp3_dma_mask,
730 .coherent_dma_mask = DMA_BIT_MASK(32),
732 .resource = pxa27x_resource_ssp3,
733 .num_resources = ARRAY_SIZE(pxa27x_resource_ssp3),
735 #endif /* CONFIG_PXA27x || CONFIG_PXA3xx */
738 static u64 pxa3xx_ssp4_dma_mask = DMA_BIT_MASK(32);
740 static struct resource pxa3xx_resource_ssp4[] = {
744 .flags = IORESOURCE_MEM,
749 .flags = IORESOURCE_IRQ,
755 .flags = IORESOURCE_DMA,
761 .flags = IORESOURCE_DMA,
765 struct platform_device pxa3xx_device_ssp4 = {
766 /* PXA3xx SSP is basically equivalent to PXA27x */
767 .name = "pxa27x-ssp",
770 .dma_mask = &pxa3xx_ssp4_dma_mask,
771 .coherent_dma_mask = DMA_BIT_MASK(32),
773 .resource = pxa3xx_resource_ssp4,
774 .num_resources = ARRAY_SIZE(pxa3xx_resource_ssp4),
776 #endif /* CONFIG_PXA3xx */