http://downloads.netgear.com/files/GPL/GPL_Source_V361j_DM111PSP_series_consumer_rele...
[bcm963xx.git] / kernel / linux / arch / arm / mach-pxa / pxa27x.c
1 /*
2  *  linux/arch/arm/mach-pxa/pxa27x.c
3  *
4  *  Author:     Nicolas Pitre
5  *  Created:    Nov 05, 2002
6  *  Copyright:  MontaVista Software Inc.
7  *
8  * Code specific to PXA27x aka Bulverde.
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 #include <linux/config.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/pm.h>
19
20 #include <asm/hardware.h>
21
22 #include "generic.h"
23
24 /* Crystal clock: 13MHz */
25 #define BASE_CLK        13000000
26
27 /*
28  * Get the clock frequency as reflected by CCSR and the turbo flag.
29  * We assume these values have been applied via a fcs.
30  * If info is not 0 we also display the current settings.
31  */
32 unsigned int get_clk_frequency_khz( int info)
33 {
34         unsigned long ccsr, clkcfg;
35         unsigned int l, L, m, M, n2, N, S;
36         int cccr_a, t, ht, b;
37
38         ccsr = CCSR;
39         cccr_a = CCCR & (1 << 25);
40
41         /* Read clkcfg register: it has turbo, b, half-turbo (and f) */
42         asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (clkcfg) );
43         t  = clkcfg & (1 << 1);
44         ht = clkcfg & (1 << 2);
45         b  = clkcfg & (1 << 3);
46
47         l  = ccsr & 0x1f;
48         n2 = (ccsr>>7) & 0xf;
49         m  = (l <= 10) ? 1 : (l <= 20) ? 2 : 4;
50
51         L  = l * BASE_CLK;
52         N  = (L * n2) / 2;
53         M  = (!cccr_a) ? (L/m) : ((b) ? L : (L/2));
54         S  = (b) ? L : (L/2);
55
56         if (info) {
57                 printk( KERN_INFO "Run Mode clock: %d.%02dMHz (*%d)\n",
58                         L / 1000000, (L % 1000000) / 10000, l );
59                 printk( KERN_INFO "Turbo Mode clock: %d.%02dMHz (*%d.%d, %sactive)\n",
60                         N / 1000000, (N % 1000000)/10000, n2 / 2, (n2 % 2)*5,
61                         (t) ? "" : "in" );
62                 printk( KERN_INFO "Memory clock: %d.%02dMHz (/%d)\n",
63                         M / 1000000, (M % 1000000) / 10000, m );
64                 printk( KERN_INFO "System bus clock: %d.%02dMHz \n",
65                         S / 1000000, (S % 1000000) / 10000 );
66         }
67
68         return (t) ? (N/1000) : (L/1000);
69 }
70
71 /*
72  * Return the current mem clock frequency in units of 10kHz as
73  * reflected by CCCR[A], B, and L
74  */
75 unsigned int get_memclk_frequency_10khz(void)
76 {
77         unsigned long ccsr, clkcfg;
78         unsigned int l, L, m, M;
79         int cccr_a, b;
80
81         ccsr = CCSR;
82         cccr_a = CCCR & (1 << 25);
83
84         /* Read clkcfg register: it has turbo, b, half-turbo (and f) */
85         asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (clkcfg) );
86         b = clkcfg & (1 << 3);
87
88         l = ccsr & 0x1f;
89         m = (l <= 10) ? 1 : (l <= 20) ? 2 : 4;
90
91         L = l * BASE_CLK;
92         M = (!cccr_a) ? (L/m) : ((b) ? L : (L/2));
93
94         return (M / 10000);
95 }
96
97 /*
98  * Return the current LCD clock frequency in units of 10kHz as
99  */
100 unsigned int get_lcdclk_frequency_10khz(void)
101 {
102         unsigned long ccsr;
103         unsigned int l, L, k, K;
104
105         ccsr = CCSR;
106
107         l = ccsr & 0x1f;
108         k = (l <= 7) ? 1 : (l <= 16) ? 2 : 4;
109
110         L = l * BASE_CLK;
111         K = L / k;
112
113         return (K / 10000);
114 }
115
116 EXPORT_SYMBOL(get_clk_frequency_khz);
117 EXPORT_SYMBOL(get_memclk_frequency_10khz);
118 EXPORT_SYMBOL(get_lcdclk_frequency_10khz);