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