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/config.h>
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/delay.h>
26 #include <asm/hardware.h>
27 #include <asm/system.h>
28 #include <asm/pgtable.h>
29 #include <asm/mach/map.h>
34 * Various clock factors driven by the CCCR register.
37 /* Crystal Frequency to Memory Frequency Multiplier (L) */
38 static unsigned char L_clk_mult[32] = { 0, 27, 32, 36, 40, 45, 0, };
40 /* Memory Frequency to Run Mode Frequency Multiplier (M) */
41 static unsigned char M_clk_mult[4] = { 0, 1, 2, 4 };
43 /* Run Mode Frequency to Turbo Mode Frequency Multiplier (N) */
44 /* Note: we store the value N * 2 here. */
45 static unsigned char N2_clk_mult[8] = { 0, 0, 2, 3, 4, 0, 6, 0 };
48 #define BASE_CLK 3686400
51 * Get the clock frequency as reflected by CCCR and the turbo flag.
52 * We assume these values have been applied via a fcs.
53 * If info is not 0 we also display the current settings.
55 unsigned int get_clk_frequency_khz(int info)
57 unsigned long cccr, turbo;
58 unsigned int l, L, m, M, n2, N;
61 asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (turbo) );
63 l = L_clk_mult[(cccr >> 0) & 0x1f];
64 m = M_clk_mult[(cccr >> 5) & 0x03];
65 n2 = N2_clk_mult[(cccr >> 7) & 0x07];
74 printk( KERN_INFO "Memory clock: %d.%02dMHz (*%d)\n",
75 L / 1000000, (L % 1000000) / 10000, l );
77 printk( KERN_INFO "Run Mode clock: %d.%02dMHz (*%d)\n",
78 M / 1000000, (M % 1000000) / 10000, m );
80 printk( KERN_INFO "Turbo Mode clock: %d.%02dMHz (*%d.%d, %sactive)\n",
81 N / 1000000, (N % 1000000) / 10000, n2 / 2, (n2 % 2) * 5,
82 (turbo & 1) ? "" : "in" );
85 return (turbo & 1) ? (N/1000) : (M/1000);
88 EXPORT_SYMBOL(get_clk_frequency_khz);
91 * Return the current lclk requency in units of 10kHz
93 unsigned int get_lclk_frequency_10khz(void)
95 return L_clk_mult[(CCCR >> 0) & 0x1f] * BASE_CLK / 10000;
98 EXPORT_SYMBOL(get_lclk_frequency_10khz);
101 * Handy function to set GPIO alternate functions
104 void pxa_gpio_mode(int gpio_mode)
107 int gpio = gpio_mode & GPIO_MD_MASK_NR;
108 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
111 local_irq_save(flags);
112 if (gpio_mode & GPIO_MD_MASK_DIR)
113 GPDR(gpio) |= GPIO_bit(gpio);
115 GPDR(gpio) &= ~GPIO_bit(gpio);
116 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
117 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
118 local_irq_restore(flags);
121 EXPORT_SYMBOL(pxa_gpio_mode);
124 * Note that 0xfffe0000-0xffffffff is reserved for the vector table and
127 static struct map_desc standard_io_desc[] __initdata = {
128 /* virtual physical length type */
129 { 0xf6000000, 0x20000000, 0x01000000, MT_DEVICE }, /* PCMCIA0 IO */
130 { 0xf7000000, 0x30000000, 0x01000000, MT_DEVICE }, /* PCMCIA1 IO */
131 { 0xf8000000, 0x40000000, 0x01400000, MT_DEVICE }, /* Devs */
132 { 0xfa000000, 0x44000000, 0x00100000, MT_DEVICE }, /* LCD */
133 { 0xfc000000, 0x48000000, 0x00100000, MT_DEVICE }, /* Mem Ctl */
134 { 0xff000000, 0x00000000, 0x00100000, MT_DEVICE } /* UNCACHED_PHYS_0 */
137 void __init pxa_map_io(void)
139 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
140 get_clk_frequency_khz(1);