]>
Commit | Line | Data |
---|---|---|
c609719b WD |
1 | /* |
2 | * (C) Copyright 2002 | |
3 | * Gary Jennejohn, DENX Software Engineering, <gj@denx.de> | |
4 | * | |
5 | * See file CREDITS for list of people who contributed to this | |
6 | * project. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public License as | |
10 | * published by the Free Software Foundation; either version 2 of | |
11 | * the License, or (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
21 | * MA 02111-1307 USA | |
22 | */ | |
23 | ||
24 | /* #define DEBUG */ | |
25 | ||
26 | #include <common.h> | |
27 | #include <cmd_bsp.h> | |
28 | #include <malloc.h> | |
29 | #include <s3c2400.h> | |
30 | ||
31 | /* ------------------------------------------------------------------------- */ | |
32 | ||
33 | #ifdef CONFIG_MODEM_SUPPORT | |
34 | static int key_pressed(void); | |
35 | extern void disable_putc(void); | |
36 | extern int do_mdm_init; /* defined in common/main.c */ | |
37 | ||
38 | /* | |
39 | * We need a delay of at least 500 us after turning on the VFD clock | |
40 | * before we can read any useful information for the CPLD controlling | |
41 | * the keyboard switches. Let's play safe and wait 5 ms. The problem | |
42 | * is that timers are not available yet, so we use a manually timed | |
43 | * loop. | |
44 | */ | |
e95b61cf WD |
45 | #define KBD_MDELAY 5000 |
46 | static void udelay_no_timer (int usec) | |
c609719b WD |
47 | { |
48 | DECLARE_GLOBAL_DATA_PTR; | |
49 | ||
50 | int i; | |
e95b61cf | 51 | int delay = usec * 3; |
c609719b WD |
52 | |
53 | for (i = 0; i < delay; i ++) gd->bd->bi_arch_number = 145; | |
54 | } | |
55 | #endif /* CONFIG_MODEM_SUPPORT */ | |
56 | ||
57 | /* | |
58 | * Miscellaneous platform dependent initialisations | |
59 | */ | |
60 | ||
61 | int board_init () | |
62 | { | |
a6c7ad2f WD |
63 | #if defined(CONFIG_MODEM_SUPPORT) && defined(CONFIG_VFD) |
64 | ulong size; | |
65 | unsigned long addr; | |
66 | extern void mem_malloc_init (ulong); | |
67 | extern int drv_vfd_init(void); | |
68 | #endif | |
c609719b WD |
69 | DECLARE_GLOBAL_DATA_PTR; |
70 | ||
71 | /* memory and cpu-speed are setup before relocation */ | |
72 | #ifdef CONFIG_TRAB_50MHZ | |
73 | /* change the clock to be 50 MHz 1:1:1 */ | |
74 | /* MDIV:0x5c PDIV:4 SDIV:2 */ | |
75 | rMPLLCON = 0x5c042; | |
76 | rCLKDIVN = 0; | |
77 | #else | |
78 | /* change the clock to be 133 MHz 1:2:4 */ | |
79 | /* MDIV:0x7d PDIV:4 SDIV:1 */ | |
80 | rMPLLCON = 0x7d041; | |
81 | rCLKDIVN = 3; | |
82 | #endif | |
83 | ||
84 | /* set up the I/O ports */ | |
85 | rPACON = 0x3ffff; | |
86 | rPBCON = 0xaaaaaaaa; | |
87 | rPBUP = 0xffff; | |
88 | /* INPUT nCTS0 nRTS0 TXD[1] TXD[0] RXD[1] RXD[0] */ | |
89 | /* 00, 10, 10, 10, 10, 10, 10 */ | |
90 | rPFCON = (2<<0) | (2<<2) | (2<<4) | (2<<6) | (2<<8) | (2<<10); | |
91 | #ifdef CONFIG_HWFLOW | |
92 | /* do not pull up RXD0, RXD1, TXD0, TXD1, CTS0, RTS0 */ | |
93 | rPFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5); | |
94 | #else | |
95 | /* do not pull up RXD0, RXD1, TXD0, TXD1 */ | |
96 | rPFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3); | |
97 | #endif | |
98 | rPGCON = 0x0; | |
99 | rPGUP = 0x0; | |
100 | rOPENCR= 0x0; | |
101 | ||
102 | /* arch number of SAMSUNG-Board */ | |
103 | /* MACH_TYPE_SMDK2400 */ | |
104 | /* XXX this isn't really correct, but keep it for now */ | |
105 | gd->bd->bi_arch_number = 145; | |
106 | ||
107 | /* adress of boot parameters */ | |
108 | gd->bd->bi_boot_params = 0x0c000100; | |
109 | ||
110 | #ifdef CONFIG_MODEM_SUPPORT | |
a6c7ad2f WD |
111 | #ifdef CONFIG_VFD |
112 | #ifndef PAGE_SIZE | |
113 | #define PAGE_SIZE 4096 | |
c609719b | 114 | #endif |
a6c7ad2f WD |
115 | /* |
116 | * reserve memory for VFD display (always full pages) | |
117 | */ | |
118 | /* armboot_real_end is defined in the board-specific linker script */ | |
119 | addr = (_armboot_real_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); | |
120 | size = vfd_setmem (addr); | |
121 | gd->fb_base = addr; | |
122 | /* round to the next page boundary */ | |
123 | addr += size; | |
124 | addr = (addr + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); | |
125 | mem_malloc_init (addr); | |
126 | /* must do this after the framebuffer is allocated */ | |
127 | drv_vfd_init(); | |
128 | #endif /* CONFIG_VFD */ | |
c609719b | 129 | |
e95b61cf | 130 | udelay_no_timer (KBD_MDELAY); |
c609719b WD |
131 | |
132 | if (key_pressed()) { | |
133 | disable_putc(); /* modem doesn't understand banner etc */ | |
134 | do_mdm_init = 1; | |
135 | } | |
136 | #endif /* CONFIG_MODEM_SUPPORT */ | |
137 | ||
138 | return 0; | |
139 | } | |
140 | ||
141 | int dram_init (void) | |
142 | { | |
143 | DECLARE_GLOBAL_DATA_PTR; | |
144 | ||
145 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; | |
146 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; | |
147 | return 0; | |
148 | } | |
149 | ||
150 | /*----------------------------------------------------------------------- | |
151 | * Keyboard Controller | |
152 | */ | |
153 | ||
154 | /* Maximum key number */ | |
155 | #define KEYBD_KEY_NUM 4 | |
156 | ||
157 | #define KBD_DATA (((*(volatile ulong *)0x04020000) >> 16) & 0xF) | |
158 | ||
159 | static uchar *key_match (ulong); | |
160 | ||
161 | int misc_init_r (void) | |
162 | { | |
163 | ulong kbd_data = KBD_DATA; | |
164 | uchar keybd_env[KEYBD_KEY_NUM + 1]; | |
165 | uchar *str; | |
166 | int i; | |
167 | ||
168 | for (i = 0; i < KEYBD_KEY_NUM; ++i) { | |
169 | keybd_env[i] = '0' + ((kbd_data >> i) & 1); | |
170 | } | |
171 | keybd_env[i] = '\0'; | |
172 | debug ("** Setting keybd=\"%s\"\n", keybd_env); | |
173 | setenv ("keybd", keybd_env); | |
174 | ||
175 | str = strdup (key_match (kbd_data)); /* decode keys */ | |
176 | ||
177 | #ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */ | |
178 | debug ("** Setting preboot=\"%s\"\n", str); | |
179 | setenv ("preboot", str); /* set or delete definition */ | |
180 | #endif /* CONFIG_PREBOOT */ | |
181 | if (str != NULL) { | |
182 | free (str); | |
183 | } | |
184 | ||
185 | return (0); | |
186 | } | |
187 | ||
188 | #ifdef CONFIG_PREBOOT | |
189 | ||
190 | static uchar kbd_magic_prefix[] = "key_magic"; | |
191 | static uchar kbd_command_prefix[] = "key_cmd"; | |
192 | ||
193 | static int compare_magic (ulong kbd_data, uchar *str) | |
194 | { | |
195 | uchar key_mask; | |
196 | ||
197 | debug ("compare_magic: kbd: %04lx str: \"%s\"\n",kbd_data,str); | |
198 | for (; *str; str++) | |
199 | { | |
200 | uchar c = *str - '1'; | |
201 | ||
202 | if (c >= KEYBD_KEY_NUM) /* bad key number */ | |
203 | return -1; | |
204 | ||
205 | key_mask = 1 << c; | |
206 | ||
207 | if (!(kbd_data & key_mask)) { /* key not pressed */ | |
208 | debug ( "compare_magic: " | |
209 | "kbd: %04lx mask: %04lx - key not pressed\n", | |
210 | kbd_data, key_mask ); | |
211 | return -1; | |
212 | } | |
213 | ||
214 | kbd_data &= ~key_mask; | |
215 | } | |
216 | ||
217 | if (kbd_data) { /* key(s) not released */ | |
218 | debug ( "compare_magic: " | |
219 | "kbd: %04lx - key(s) not released\n", kbd_data); | |
220 | return -1; | |
221 | } | |
222 | ||
223 | return 0; | |
224 | } | |
225 | ||
226 | /*----------------------------------------------------------------------- | |
227 | * Check if pressed key(s) match magic sequence, | |
228 | * and return the command string associated with that key(s). | |
229 | * | |
230 | * If no key press was decoded, NULL is returned. | |
231 | * | |
232 | * Note: the first character of the argument will be overwritten with | |
233 | * the "magic charcter code" of the decoded key(s), or '\0'. | |
234 | * | |
235 | * | |
236 | * Note: the string points to static environment data and must be | |
237 | * saved before you call any function that modifies the environment. | |
238 | */ | |
239 | static uchar *key_match (ulong kbd_data) | |
240 | { | |
241 | uchar magic[sizeof (kbd_magic_prefix) + 1]; | |
242 | uchar cmd_name[sizeof (kbd_command_prefix) + 1]; | |
243 | uchar *suffix; | |
244 | uchar *kbd_magic_keys; | |
245 | ||
246 | /* | |
247 | * The following string defines the characters that can pe appended | |
248 | * to "key_magic" to form the names of environment variables that | |
249 | * hold "magic" key codes, i. e. such key codes that can cause | |
250 | * pre-boot actions. If the string is empty (""), then only | |
251 | * "key_magic" is checked (old behaviour); the string "125" causes | |
252 | * checks for "key_magic1", "key_magic2" and "key_magic5", etc. | |
253 | */ | |
254 | if ((kbd_magic_keys = getenv ("magic_keys")) == NULL) | |
255 | kbd_magic_keys = ""; | |
256 | ||
257 | debug ("key_match: magic_keys=\"%s\"\n", kbd_magic_keys); | |
258 | ||
259 | /* loop over all magic keys; | |
260 | * use '\0' suffix in case of empty string | |
261 | */ | |
262 | for (suffix=kbd_magic_keys; *suffix || suffix==kbd_magic_keys; ++suffix) | |
263 | { | |
264 | sprintf (magic, "%s%c", kbd_magic_prefix, *suffix); | |
265 | ||
266 | debug ("key_match: magic=\"%s\"\n", | |
267 | getenv(magic) ? getenv(magic) : "<UNDEFINED>"); | |
268 | ||
269 | if (compare_magic(kbd_data, getenv(magic)) == 0) | |
270 | { | |
271 | sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix); | |
272 | debug ("key_match: cmdname %s=\"%s\"\n", | |
273 | cmd_name, | |
274 | getenv (cmd_name) ? | |
275 | getenv (cmd_name) : | |
276 | "<UNDEFINED>"); | |
277 | return (getenv (cmd_name)); | |
278 | } | |
279 | } | |
280 | debug ("key_match: no match\n"); | |
281 | return (NULL); | |
282 | } | |
283 | #endif /* CONFIG_PREBOOT */ | |
284 | ||
285 | /* Read Keyboard status */ | |
286 | int do_kbd (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) | |
287 | { | |
288 | ulong kbd_data = KBD_DATA; | |
289 | uchar keybd_env[KEYBD_KEY_NUM + 1]; | |
290 | int i; | |
291 | ||
292 | puts ("Keys:"); | |
293 | for (i = 0; i < KEYBD_KEY_NUM; ++i) { | |
294 | keybd_env[i] = '0' + ((kbd_data >> i) & 1); | |
295 | printf (" %c", keybd_env[i]); | |
296 | } | |
297 | keybd_env[i] = '\0'; | |
298 | putc ('\n'); | |
299 | setenv ("keybd", keybd_env); | |
300 | return 0; | |
301 | } | |
302 | ||
303 | #ifdef CONFIG_MODEM_SUPPORT | |
304 | static int key_pressed(void) | |
305 | { | |
306 | return (compare_magic(KBD_DATA, CONFIG_MODEM_KEY_MAGIC) == 0); | |
307 | } | |
308 | #endif /* CONFIG_MODEM_SUPPORT */ |