]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/trab/trab.c
Patch by Guillaume Alexandre,, 04 Nov 2002:
[people/ms/u-boot.git] / board / trab / trab.c
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 */
45 #define KBD_MDELAY 5000
46 static void udelay_no_timer (int usec)
47 {
48 DECLARE_GLOBAL_DATA_PTR;
49
50 int i;
51 int delay = usec * 3;
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 {
63 DECLARE_GLOBAL_DATA_PTR;
64
65 /* memory and cpu-speed are setup before relocation */
66 #ifdef CONFIG_TRAB_50MHZ
67 /* change the clock to be 50 MHz 1:1:1 */
68 /* MDIV:0x5c PDIV:4 SDIV:2 */
69 rMPLLCON = 0x5c042;
70 rCLKDIVN = 0;
71 #else
72 /* change the clock to be 133 MHz 1:2:4 */
73 /* MDIV:0x7d PDIV:4 SDIV:1 */
74 rMPLLCON = 0x7d041;
75 rCLKDIVN = 3;
76 #endif
77
78 /* set up the I/O ports */
79 rPACON = 0x3ffff;
80 rPBCON = 0xaaaaaaaa;
81 rPBUP = 0xffff;
82 /* INPUT nCTS0 nRTS0 TXD[1] TXD[0] RXD[1] RXD[0] */
83 /* 00, 10, 10, 10, 10, 10, 10 */
84 rPFCON = (2<<0) | (2<<2) | (2<<4) | (2<<6) | (2<<8) | (2<<10);
85 #ifdef CONFIG_HWFLOW
86 /* do not pull up RXD0, RXD1, TXD0, TXD1, CTS0, RTS0 */
87 rPFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5);
88 #else
89 /* do not pull up RXD0, RXD1, TXD0, TXD1 */
90 rPFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3);
91 #endif
92 rPGCON = 0x0;
93 rPGUP = 0x0;
94 rOPENCR= 0x0;
95
96 /* arch number of SAMSUNG-Board */
97 /* MACH_TYPE_SMDK2400 */
98 /* XXX this isn't really correct, but keep it for now */
99 gd->bd->bi_arch_number = 145;
100
101 /* adress of boot parameters */
102 gd->bd->bi_boot_params = 0x0c000100;
103
104 #ifdef CONFIG_MODEM_SUPPORT
105 /* This stuff is needed by the CPLD to read keyboard data.
106 * (Copied from the LCD initialization routine.)
107 */
108 if (rLCDCON1 == 0) {
109 extern void init_grid_ctrl(void);
110
111 rPCCON = (rPCCON & 0xFFFFFF00)| 0x000000AA;
112 rPDCON = (rPDCON & 0xFFFFFF03)| 0x000000A8;
113 #if 0
114 rPDCON = (rPDCON & 0xFFFFFF00)| 0x000000AA;
115 #endif
116 rLCDCON2 = 0x000DC000;
117 rLCDCON3 = 0x0051000A;
118 rLCDCON4 = 0x00000001;
119 rLCDCON5 = 0x00000440;
120 rLCDCON1 = 0x00000B75;
121
122 init_grid_ctrl();
123 }
124
125 udelay_no_timer (KBD_MDELAY);
126
127 if (key_pressed()) {
128 disable_putc(); /* modem doesn't understand banner etc */
129 do_mdm_init = 1;
130 }
131 #endif /* CONFIG_MODEM_SUPPORT */
132
133 return 0;
134 }
135
136 int dram_init (void)
137 {
138 DECLARE_GLOBAL_DATA_PTR;
139
140 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
141 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
142 return 0;
143 }
144
145 /*-----------------------------------------------------------------------
146 * Keyboard Controller
147 */
148
149 /* Maximum key number */
150 #define KEYBD_KEY_NUM 4
151
152 #define KBD_DATA (((*(volatile ulong *)0x04020000) >> 16) & 0xF)
153
154 static uchar *key_match (ulong);
155
156 int misc_init_r (void)
157 {
158 ulong kbd_data = KBD_DATA;
159 uchar keybd_env[KEYBD_KEY_NUM + 1];
160 uchar *str;
161 int i;
162
163 for (i = 0; i < KEYBD_KEY_NUM; ++i) {
164 keybd_env[i] = '0' + ((kbd_data >> i) & 1);
165 }
166 keybd_env[i] = '\0';
167 debug ("** Setting keybd=\"%s\"\n", keybd_env);
168 setenv ("keybd", keybd_env);
169
170 str = strdup (key_match (kbd_data)); /* decode keys */
171
172 #ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */
173 debug ("** Setting preboot=\"%s\"\n", str);
174 setenv ("preboot", str); /* set or delete definition */
175 #endif /* CONFIG_PREBOOT */
176 if (str != NULL) {
177 free (str);
178 }
179
180 return (0);
181 }
182
183 #ifdef CONFIG_PREBOOT
184
185 static uchar kbd_magic_prefix[] = "key_magic";
186 static uchar kbd_command_prefix[] = "key_cmd";
187
188 static int compare_magic (ulong kbd_data, uchar *str)
189 {
190 uchar key_mask;
191
192 debug ("compare_magic: kbd: %04lx str: \"%s\"\n",kbd_data,str);
193 for (; *str; str++)
194 {
195 uchar c = *str - '1';
196
197 if (c >= KEYBD_KEY_NUM) /* bad key number */
198 return -1;
199
200 key_mask = 1 << c;
201
202 if (!(kbd_data & key_mask)) { /* key not pressed */
203 debug ( "compare_magic: "
204 "kbd: %04lx mask: %04lx - key not pressed\n",
205 kbd_data, key_mask );
206 return -1;
207 }
208
209 kbd_data &= ~key_mask;
210 }
211
212 if (kbd_data) { /* key(s) not released */
213 debug ( "compare_magic: "
214 "kbd: %04lx - key(s) not released\n", kbd_data);
215 return -1;
216 }
217
218 return 0;
219 }
220
221 /*-----------------------------------------------------------------------
222 * Check if pressed key(s) match magic sequence,
223 * and return the command string associated with that key(s).
224 *
225 * If no key press was decoded, NULL is returned.
226 *
227 * Note: the first character of the argument will be overwritten with
228 * the "magic charcter code" of the decoded key(s), or '\0'.
229 *
230 *
231 * Note: the string points to static environment data and must be
232 * saved before you call any function that modifies the environment.
233 */
234 static uchar *key_match (ulong kbd_data)
235 {
236 uchar magic[sizeof (kbd_magic_prefix) + 1];
237 uchar cmd_name[sizeof (kbd_command_prefix) + 1];
238 uchar *suffix;
239 uchar *kbd_magic_keys;
240
241 /*
242 * The following string defines the characters that can pe appended
243 * to "key_magic" to form the names of environment variables that
244 * hold "magic" key codes, i. e. such key codes that can cause
245 * pre-boot actions. If the string is empty (""), then only
246 * "key_magic" is checked (old behaviour); the string "125" causes
247 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
248 */
249 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
250 kbd_magic_keys = "";
251
252 debug ("key_match: magic_keys=\"%s\"\n", kbd_magic_keys);
253
254 /* loop over all magic keys;
255 * use '\0' suffix in case of empty string
256 */
257 for (suffix=kbd_magic_keys; *suffix || suffix==kbd_magic_keys; ++suffix)
258 {
259 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
260
261 debug ("key_match: magic=\"%s\"\n",
262 getenv(magic) ? getenv(magic) : "<UNDEFINED>");
263
264 if (compare_magic(kbd_data, getenv(magic)) == 0)
265 {
266 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
267 debug ("key_match: cmdname %s=\"%s\"\n",
268 cmd_name,
269 getenv (cmd_name) ?
270 getenv (cmd_name) :
271 "<UNDEFINED>");
272 return (getenv (cmd_name));
273 }
274 }
275 debug ("key_match: no match\n");
276 return (NULL);
277 }
278 #endif /* CONFIG_PREBOOT */
279
280 /* Read Keyboard status */
281 int do_kbd (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
282 {
283 ulong kbd_data = KBD_DATA;
284 uchar keybd_env[KEYBD_KEY_NUM + 1];
285 int i;
286
287 puts ("Keys:");
288 for (i = 0; i < KEYBD_KEY_NUM; ++i) {
289 keybd_env[i] = '0' + ((kbd_data >> i) & 1);
290 printf (" %c", keybd_env[i]);
291 }
292 keybd_env[i] = '\0';
293 putc ('\n');
294 setenv ("keybd", keybd_env);
295 return 0;
296 }
297
298 #ifdef CONFIG_MODEM_SUPPORT
299 static int key_pressed(void)
300 {
301 return (compare_magic(KBD_DATA, CONFIG_MODEM_KEY_MAGIC) == 0);
302 }
303 #endif /* CONFIG_MODEM_SUPPORT */