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/device.h>
24 #include <linux/ioport.h>
27 #include <asm/hardware.h>
29 #include <asm/system.h>
30 #include <asm/pgtable.h>
31 #include <asm/mach/map.h>
33 #include <asm/arch/udc.h>
38 * Various clock factors driven by the CCCR register.
41 /* Crystal Frequency to Memory Frequency Multiplier (L) */
42 static unsigned char L_clk_mult[32] = { 0, 27, 32, 36, 40, 45, 0, };
44 /* Memory Frequency to Run Mode Frequency Multiplier (M) */
45 static unsigned char M_clk_mult[4] = { 0, 1, 2, 4 };
47 /* Run Mode Frequency to Turbo Mode Frequency Multiplier (N) */
48 /* Note: we store the value N * 2 here. */
49 static unsigned char N2_clk_mult[8] = { 0, 0, 2, 3, 4, 0, 6, 0 };
52 #define BASE_CLK 3686400
55 * Get the clock frequency as reflected by CCCR and the turbo flag.
56 * We assume these values have been applied via a fcs.
57 * If info is not 0 we also display the current settings.
59 unsigned int get_clk_frequency_khz(int info)
61 unsigned long cccr, turbo;
62 unsigned int l, L, m, M, n2, N;
65 asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (turbo) );
67 l = L_clk_mult[(cccr >> 0) & 0x1f];
68 m = M_clk_mult[(cccr >> 5) & 0x03];
69 n2 = N2_clk_mult[(cccr >> 7) & 0x07];
78 printk( KERN_INFO "Memory clock: %d.%02dMHz (*%d)\n",
79 L / 1000000, (L % 1000000) / 10000, l );
81 printk( KERN_INFO "Run Mode clock: %d.%02dMHz (*%d)\n",
82 M / 1000000, (M % 1000000) / 10000, m );
84 printk( KERN_INFO "Turbo Mode clock: %d.%02dMHz (*%d.%d, %sactive)\n",
85 N / 1000000, (N % 1000000) / 10000, n2 / 2, (n2 % 2) * 5,
86 (turbo & 1) ? "" : "in" );
89 return (turbo & 1) ? (N/1000) : (M/1000);
92 EXPORT_SYMBOL(get_clk_frequency_khz);
95 * Return the current lclk requency in units of 10kHz
97 unsigned int get_lclk_frequency_10khz(void)
99 return L_clk_mult[(CCCR >> 0) & 0x1f] * BASE_CLK / 10000;
102 EXPORT_SYMBOL(get_lclk_frequency_10khz);
105 * Handy function to set GPIO alternate functions
108 void pxa_gpio_mode(int gpio_mode)
111 int gpio = gpio_mode & GPIO_MD_MASK_NR;
112 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
115 local_irq_save(flags);
116 if (gpio_mode & GPIO_MD_MASK_DIR)
117 GPDR(gpio) |= GPIO_bit(gpio);
119 GPDR(gpio) &= ~GPIO_bit(gpio);
120 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
121 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
122 local_irq_restore(flags);
125 EXPORT_SYMBOL(pxa_gpio_mode);
128 * Note that 0xfffe0000-0xffffffff is reserved for the vector table and
131 static struct map_desc standard_io_desc[] __initdata = {
132 /* virtual physical length type */
133 { 0xf6000000, 0x20000000, 0x01000000, MT_DEVICE }, /* PCMCIA0 IO */
134 { 0xf7000000, 0x30000000, 0x01000000, MT_DEVICE }, /* PCMCIA1 IO */
135 { 0xf8000000, 0x40000000, 0x01400000, MT_DEVICE }, /* Devs */
136 { 0xfa000000, 0x44000000, 0x00100000, MT_DEVICE }, /* LCD */
137 { 0xfc000000, 0x48000000, 0x00100000, MT_DEVICE }, /* Mem Ctl */
138 { 0xff000000, 0x00000000, 0x00100000, MT_DEVICE } /* UNCACHED_PHYS_0 */
141 void __init pxa_map_io(void)
143 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
144 get_clk_frequency_khz(1);
148 static struct resource pxamci_resources[] = {
152 .flags = IORESOURCE_MEM,
157 .flags = IORESOURCE_IRQ,
161 static u64 pxamci_dmamask = 0xffffffffUL;
163 static struct platform_device pxamci_device = {
167 .dma_mask = &pxamci_dmamask,
169 .num_resources = ARRAY_SIZE(pxamci_resources),
170 .resource = pxamci_resources,
174 static struct pxa2xx_udc_mach_info pxa_udc_info;
176 void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
178 memcpy(&pxa_udc_info, info, sizeof *info);
180 EXPORT_SYMBOL(pxa_set_udc_info);
182 static struct resource pxa2xx_udc_resources[] = {
186 .flags = IORESOURCE_MEM,
191 .flags = IORESOURCE_IRQ,
195 static u64 udc_dma_mask = ~(u32)0;
197 static struct platform_device udc_device = {
198 .name = "pxa2xx_udc",
200 .resource = pxa2xx_udc_resources,
201 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
203 .platform_data = &pxa_udc_info,
204 .dma_mask = &udc_dma_mask,
208 static struct platform_device *devices[] __initdata = {
213 static int __init pxa_init(void)
215 return platform_add_devices(devices, ARRAY_SIZE(devices));
218 subsys_initcall(pxa_init);