74919371fff9f356ed1fdc65f99f69988aa24111
[linux-flexiantxendom0-3.2.10.git] / arch / arm / mach-pxa / generic.c
1 /*
2  *  linux/arch/arm/mach-pxa/generic.c
3  *
4  *  Author:     Nicolas Pitre
5  *  Created:    Jun 15, 2001
6  *  Copyright:  MontaVista Software Inc.
7  *
8  * Code common to all PXA machines.
9  *
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.
13  *
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
17  * need be.
18  */
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>
24 #include <linux/pm.h>
25
26 #include <asm/hardware.h>
27 #include <asm/system.h>
28 #include <asm/pgtable.h>
29 #include <asm/mach/map.h>
30
31 #include "generic.h"
32
33 /*
34  * Various clock factors driven by the CCCR register.
35  */
36
37 /* Crystal Frequency to Memory Frequency Multiplier (L) */
38 static unsigned char L_clk_mult[32] = { 0, 27, 32, 36, 40, 45, 0, };
39
40 /* Memory Frequency to Run Mode Frequency Multiplier (M) */
41 static unsigned char M_clk_mult[4] = { 0, 1, 2, 4 };
42
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 };
46
47 /* Crystal clock */
48 #define BASE_CLK        3686400
49
50 /*
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.
54  */
55 unsigned int get_clk_frequency_khz(int info)
56 {
57         unsigned long cccr, turbo;
58         unsigned int l, L, m, M, n2, N;
59
60         cccr = CCCR;
61         asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (turbo) );
62
63         l  =  L_clk_mult[(cccr >> 0) & 0x1f];
64         m  =  M_clk_mult[(cccr >> 5) & 0x03];
65         n2 = N2_clk_mult[(cccr >> 7) & 0x07];
66
67         L = l * BASE_CLK;
68         M = m * L;
69         N = n2 * M / 2;
70
71         if(info)
72         {
73                 L += 5000;
74                 printk( KERN_INFO "Memory clock: %d.%02dMHz (*%d)\n",
75                         L / 1000000, (L % 1000000) / 10000, l );
76                 M += 5000;
77                 printk( KERN_INFO "Run Mode clock: %d.%02dMHz (*%d)\n",
78                         M / 1000000, (M % 1000000) / 10000, m );
79                 N += 5000;
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" );
83         }
84
85         return (turbo & 1) ? (N/1000) : (M/1000);
86 }
87
88 EXPORT_SYMBOL(get_clk_frequency_khz);
89
90 /*
91  * Return the current lclk requency in units of 10kHz
92  */
93 unsigned int get_lclk_frequency_10khz(void)
94 {
95         return L_clk_mult[(CCCR >> 0) & 0x1f] * BASE_CLK / 10000;
96 }
97
98 EXPORT_SYMBOL(get_lclk_frequency_10khz);
99
100 /*
101  * Handy function to set GPIO alternate functions
102  */
103
104 void pxa_gpio_mode(int gpio_mode)
105 {
106         long flags;
107         int gpio = gpio_mode & GPIO_MD_MASK_NR;
108         int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
109         int gafr;
110
111         local_irq_save(flags);
112         if (gpio_mode & GPIO_MD_MASK_DIR)
113                 GPDR(gpio) |= GPIO_bit(gpio);
114         else
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);
119 }
120
121 EXPORT_SYMBOL(pxa_gpio_mode);
122
123 /*
124  * Note that 0xfffe0000-0xffffffff is reserved for the vector table and
125  * cache flush area.
126  */
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 */
135 };
136
137 void __init pxa_map_io(void)
138 {
139         iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
140         get_clk_frequency_khz(1);
141 }