1 /*
2 * linux/arch/arm/mach-sa1100/generic.c
3 *
4 * Author: Nicolas Pitre
5 *
6 * Code common to all SA11x0 machines.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Since this file should be linked before any other machine specific file,
13 * the __initcall() here will be executed first. This serves as default
14 * initialization stuff for SA1100 machines which can be overriden later if
15 * need be.
16 */
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
22 #include <linux/pm.h>
23 #include <linux/cpufreq.h>
24
25 #include <asm/hardware.h>
26 #include <asm/system.h>
27 #include <asm/pgtable.h>
28 #include <asm/mach/map.h>
29
30 #include "generic.h"
31
32 #define NR_FREQS 16
33
34 /*
35 * This table is setup for a 3.6864MHz Crystal.
36 */
37 static const unsigned short cclk_frequency_100khz[NR_FREQS] = {
38 590, /* 59.0 MHz */
39 737, /* 73.7 MHz */
40 885, /* 88.5 MHz */
41 1032, /* 103.2 MHz */
42 1180, /* 118.0 MHz */
43 1327, /* 132.7 MHz */
44 1475, /* 147.5 MHz */
45 1622, /* 162.2 MHz */
46 1769, /* 176.9 MHz */
47 1917, /* 191.7 MHz */
48 2064, /* 206.4 MHz */
49 2212, /* 221.2 MHz */
50 2359, /* 235.9 MHz */
51 2507, /* 250.7 MHz */
52 2654, /* 265.4 MHz */
53 2802 /* 280.2 MHz */
54 };
55
56 /*
57 * Return the current CPU clock frequency in units of 100kHz
58 */
get_cclk_frequency(void)59 static inline unsigned short get_cclk_frequency(void)
60 {
61 return cclk_frequency_100khz[PPCR & 0xf];
62 }
63
64 #ifdef CONFIG_CPU_FREQ
sa11x0_freq_to_ppcr(unsigned int khz)65 unsigned int sa11x0_freq_to_ppcr(unsigned int khz)
66 {
67 int i;
68
69 khz /= 100;
70
71 for (i = NR_FREQS - 1; i > 0; i--)
72 if (cclk_frequency_100khz[i] <= khz)
73 break;
74
75 return i;
76 }
77
78 /*
79 * Validate the speed in khz. If we can't generate the precise
80 * frequency requested, round it down (to be on the safe side).
81 */
sa11x0_validatespeed(unsigned int khz)82 unsigned int sa11x0_validatespeed(unsigned int khz)
83 {
84 return cclk_frequency_100khz[sa11x0_freq_to_ppcr(khz)] * 100;
85 }
86
sa11x0_init_clock(void)87 static int __init sa11x0_init_clock(void)
88 {
89 cpufreq_init(cclk_frequency_100khz[PPCR & 0xf] * 100, 59000, 287000);
90 return 0;
91 }
92
93 __initcall(sa11x0_init_clock);
94 #else
95 /*
96 * We still need to provide this so building without cpufreq works.
97 */
cpufreq_get(int cpu)98 unsigned int cpufreq_get(int cpu)
99 {
100 return cclk_frequency_100khz[PPCR & 0xf] * 100;
101 }
102 EXPORT_SYMBOL(cpufreq_get);
103 #endif
104
105 /*
106 * Default power-off for SA1100
107 */
sa1100_power_off(void)108 static void sa1100_power_off(void)
109 {
110 mdelay(100);
111 cli();
112 /* disable internal oscillator, float CS lines */
113 PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
114 /* enable wake-up on GPIO0 (Assabet...) */
115 PWER = GFER = GRER = 1;
116 /*
117 * set scratchpad to zero, just in case it is used as a
118 * restart address by the bootloader.
119 */
120 PSPR = 0;
121 /* enter sleep mode */
122 PMCR = PMCR_SF;
123 }
124
sa1100_init(void)125 static int __init sa1100_init(void)
126 {
127 pm_power_off = sa1100_power_off;
128 return 0;
129 }
130
131 __initcall(sa1100_init);
132
133
134 /*
135 * Common I/O mapping:
136 *
137 * Typically, static virtual address mappings are as follow:
138 *
139 * 0xe8000000-0xefffffff: flash memory (especially when multiple flash
140 * banks need to be mapped contigously)
141 * 0xf0000000-0xf3ffffff: miscellaneous stuff (CPLDs, etc.)
142 * 0xf4000000-0xf4ffffff: SA-1111
143 * 0xf5000000-0xf5ffffff: reserved (used by cache flushing area)
144 * 0xf6000000-0xfffeffff: reserved (internal SA1100 IO defined above)
145 * 0xffff0000-0xffff0fff: SA1100 exception vectors
146 *
147 * Below 0xe8000000 is reserved for vm allocation.
148 *
149 * The machine specific code must provide the extra mapping beside the
150 * default mapping provided here.
151 */
152
153 static struct map_desc standard_io_desc[] __initdata = {
154 /* virtual physical length domain r w c b */
155 { 0xf6000000, 0x20000000, 0x01000000, DOMAIN_IO, 0, 1, 0, 0 }, /* PCMCIA0 IO */
156 { 0xf7000000, 0x30000000, 0x01000000, DOMAIN_IO, 0, 1, 0, 0 }, /* PCMCIA1 IO */
157 { 0xf8000000, 0x80000000, 0x00100000, DOMAIN_IO, 0, 1, 0, 0 }, /* PCM */
158 { 0xfa000000, 0x90000000, 0x00100000, DOMAIN_IO, 0, 1, 0, 0 }, /* SCM */
159 { 0xfc000000, 0xa0000000, 0x00100000, DOMAIN_IO, 0, 1, 0, 0 }, /* MER */
160 { 0xfe000000, 0xb0000000, 0x00200000, DOMAIN_IO, 0, 1, 0, 0 }, /* LCD + DMA */
161 LAST_DESC
162 };
163
sa1100_map_io(void)164 void __init sa1100_map_io(void)
165 {
166 iotable_init(standard_io_desc);
167 }
168