3 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
32 DECLARE_GLOBAL_DATA_PTR;
34 #ifdef CONFIG_SYS_BRIGHTNESS
35 static void spi_init(void);
36 static void wait_transmit_done(void);
37 static void tsc2000_write(unsigned int page, unsigned int reg,
39 static void tsc2000_set_brightness(void);
41 #ifdef CONFIG_MODEM_SUPPORT
42 static int key_pressed(void);
43 extern void disable_putc(void);
44 extern int do_mdm_init; /* defined in common/main.c */
47 * We need a delay of at least 500 us after turning on the VFD clock
48 * before we can read any useful information for the CPLD controlling
49 * the keyboard switches. Let's play safe and wait 5 ms. The problem
50 * is that timers are not available yet, so we use a manually timed
53 #define KBD_MDELAY 5000
54 static void udelay_no_timer (int usec)
59 for (i = 0; i < delay; i ++) gd->bd->bi_arch_number = MACH_TYPE_TRAB;
61 #endif /* CONFIG_MODEM_SUPPORT */
64 * Miscellaneous platform dependent initialisations
69 #if defined(CONFIG_VFD)
70 extern int vfd_init_clocks(void);
72 struct s3c24x0_clock_power * const clk_power =
73 s3c24x0_get_base_clock_power();
74 struct s3c24x0_gpio * const gpio = s3c24x0_get_base_gpio();
76 /* memory and cpu-speed are setup before relocation */
77 #ifdef CONFIG_TRAB_50MHZ
78 /* change the clock to be 50 MHz 1:1:1 */
79 /* MDIV:0x5c PDIV:4 SDIV:2 */
80 clk_power->MPLLCON = 0x5c042;
81 clk_power->CLKDIVN = 0;
83 /* change the clock to be 133 MHz 1:2:4 */
84 /* MDIV:0x7d PDIV:4 SDIV:1 */
85 clk_power->MPLLCON = 0x7d041;
86 clk_power->CLKDIVN = 3;
89 /* set up the I/O ports */
90 gpio->PACON = 0x3ffff;
91 gpio->PBCON = 0xaaaaaaaa;
93 /* INPUT nCTS0 nRTS0 TXD[1] TXD[0] RXD[1] RXD[0] */
94 /* 00, 10, 10, 10, 10, 10, 10 */
95 gpio->PFCON = (2<<0) | (2<<2) | (2<<4) | (2<<6) | (2<<8) | (2<<10);
97 /* do not pull up RXD0, RXD1, TXD0, TXD1, CTS0, RTS0 */
98 gpio->PFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5);
100 /* do not pull up RXD0, RXD1, TXD0, TXD1 */
101 gpio->PFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3);
107 /* suppress flicker of the VFDs */
109 gpio->PFCON |= (2<<12);
111 gd->bd->bi_arch_number = MACH_TYPE_TRAB;
113 /* adress of boot parameters */
114 gd->bd->bi_boot_params = 0x0c000100;
116 /* Make sure both buzzers are turned off */
117 gpio->PDCON |= 0x5400;
118 gpio->PDDAT &= ~0xE0;
122 #endif /* CONFIG_VFD */
124 #ifdef CONFIG_MODEM_SUPPORT
125 udelay_no_timer (KBD_MDELAY);
128 disable_putc(); /* modem doesn't understand banner etc */
131 #endif /* CONFIG_MODEM_SUPPORT */
133 #ifdef CONFIG_DRIVER_S3C24X0_I2C
134 /* Configure I/O ports PG5 und PG6 for I2C */
135 gpio->PGCON = (gpio->PGCON & 0x003c00) | 0x003c00;
136 #endif /* CONFIG_DRIVER_S3C24X0_I2C */
143 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
144 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
148 /*-----------------------------------------------------------------------
149 * Keyboard Controller
152 /* Maximum key number */
153 #define KEYBD_KEY_NUM 4
155 #define KBD_DATA (((*(volatile ulong *)0x04020000) >> 16) & 0xF)
157 static char *key_match (ulong);
159 int misc_init_r (void)
161 ulong kbd_data = KBD_DATA;
163 char keybd_env[KEYBD_KEY_NUM + 1];
166 #ifdef CONFIG_VERSION_VARIABLE
168 /* Set version variable. Please note, that this variable is
169 * also set in main_loop() later in the boot process. The
170 * version variable has to be set this early, because so it
171 * could be used in script files on an usb stick, which
172 * might be called during do_auto_update() */
173 extern char version_string[];
175 setenv ("ver", version_string);
177 #endif /* CONFIG_VERSION_VARIABLE */
179 #ifdef CONFIG_AUTO_UPDATE
181 extern int do_auto_update(void);
182 /* this has priority over all else */
187 for (i = 0; i < KEYBD_KEY_NUM; ++i) {
188 keybd_env[i] = '0' + ((kbd_data >> i) & 1);
191 debug ("** Setting keybd=\"%s\"\n", keybd_env);
192 setenv ("keybd", keybd_env);
194 str = strdup (key_match (kbd_data)); /* decode keys */
196 #ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */
197 debug ("** Setting preboot=\"%s\"\n", str);
198 setenv ("preboot", str); /* set or delete definition */
199 #endif /* CONFIG_PREBOOT */
204 #ifdef CONFIG_SYS_BRIGHTNESS
205 tsc2000_set_brightness();
210 #ifdef CONFIG_PREBOOT
212 static uchar kbd_magic_prefix[] = "key_magic";
213 static uchar kbd_command_prefix[] = "key_cmd";
215 static int compare_magic (ulong kbd_data, char *str)
219 debug ("compare_magic: kbd: %04lx str: \"%s\"\n",kbd_data,str);
222 uchar c = *str - '1';
224 if (c >= KEYBD_KEY_NUM) /* bad key number */
229 if (!(kbd_data & key_mask)) { /* key not pressed */
230 debug ( "compare_magic: "
231 "kbd: %04lx mask: %04lx - key not pressed\n",
232 kbd_data, key_mask );
236 kbd_data &= ~key_mask;
239 if (kbd_data) { /* key(s) not released */
240 debug ( "compare_magic: "
241 "kbd: %04lx - key(s) not released\n", kbd_data);
248 /*-----------------------------------------------------------------------
249 * Check if pressed key(s) match magic sequence,
250 * and return the command string associated with that key(s).
252 * If no key press was decoded, NULL is returned.
254 * Note: the first character of the argument will be overwritten with
255 * the "magic charcter code" of the decoded key(s), or '\0'.
258 * Note: the string points to static environment data and must be
259 * saved before you call any function that modifies the environment.
261 static char *key_match (ulong kbd_data)
263 char magic[sizeof (kbd_magic_prefix) + 1];
264 char cmd_name[sizeof (kbd_command_prefix) + 1];
266 char *kbd_magic_keys;
269 * The following string defines the characters that can pe appended
270 * to "key_magic" to form the names of environment variables that
271 * hold "magic" key codes, i. e. such key codes that can cause
272 * pre-boot actions. If the string is empty (""), then only
273 * "key_magic" is checked (old behaviour); the string "125" causes
274 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
276 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
279 debug ("key_match: magic_keys=\"%s\"\n", kbd_magic_keys);
281 /* loop over all magic keys;
282 * use '\0' suffix in case of empty string
284 for (suffix=kbd_magic_keys; *suffix || suffix==kbd_magic_keys; ++suffix)
286 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
288 debug ("key_match: magic=\"%s\"\n",
289 getenv(magic) ? getenv(magic) : "<UNDEFINED>");
291 if (compare_magic(kbd_data, getenv(magic)) == 0)
293 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
294 debug ("key_match: cmdname %s=\"%s\"\n",
299 return (getenv (cmd_name));
302 debug ("key_match: no match\n");
305 #endif /* CONFIG_PREBOOT */
307 /* Read Keyboard status */
308 int do_kbd (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
310 ulong kbd_data = KBD_DATA;
311 char keybd_env[KEYBD_KEY_NUM + 1];
315 for (i = 0; i < KEYBD_KEY_NUM; ++i) {
316 keybd_env[i] = '0' + ((kbd_data >> i) & 1);
317 printf (" %c", keybd_env[i]);
321 setenv ("keybd", keybd_env);
327 "read keyboard status",
331 #ifdef CONFIG_MODEM_SUPPORT
332 static int key_pressed(void)
334 return (compare_magic(KBD_DATA, CONFIG_MODEM_KEY_MAGIC) == 0);
336 #endif /* CONFIG_MODEM_SUPPORT */
338 #ifdef CONFIG_SYS_BRIGHTNESS
340 static inline void SET_CS_TOUCH(void)
342 struct s3c24x0_gpio * const gpio = s3c24x0_get_base_gpio();
344 gpio->PDDAT &= 0x5FF;
347 static inline void CLR_CS_TOUCH(void)
349 struct s3c24x0_gpio * const gpio = s3c24x0_get_base_gpio();
351 gpio->PDDAT |= 0x200;
354 static void spi_init(void)
356 struct s3c24x0_gpio * const gpio = s3c24x0_get_base_gpio();
357 struct s3c24x0_spi * const spi = s3c24x0_get_base_spi();
360 /* Configure I/O ports. */
361 gpio->PDCON = (gpio->PDCON & 0xF3FFFF) | 0x040000;
362 gpio->PGCON = (gpio->PGCON & 0x0F3FFF) | 0x008000;
363 gpio->PGCON = (gpio->PGCON & 0x0CFFFF) | 0x020000;
364 gpio->PGCON = (gpio->PGCON & 0x03FFFF) | 0x080000;
368 spi->ch[0].SPPRE = 0x1F; /* Baudrate ca. 514kHz */
369 spi->ch[0].SPPIN = 0x01; /* SPI-MOSI holds Level after last bit */
370 spi->ch[0].SPCON = 0x1A; /* Polling, Prescaler, Master, CPOL=0, CPHA=1 */
372 /* Dummy byte ensures clock to be low. */
373 for (i = 0; i < 10; i++) {
374 spi->ch[0].SPTDAT = 0xFF;
376 wait_transmit_done();
379 static void wait_transmit_done(void)
381 struct s3c24x0_spi * const spi = s3c24x0_get_base_spi();
383 while (!(spi->ch[0].SPSTA & 0x01)); /* wait until transfer is done */
386 static void tsc2000_write(unsigned int page, unsigned int reg,
389 struct s3c24x0_spi * const spi = s3c24x0_get_base_spi();
390 unsigned int command;
394 command |= (page << 11);
395 command |= (reg << 5);
397 spi->ch[0].SPTDAT = (command & 0xFF00) >> 8;
398 wait_transmit_done();
399 spi->ch[0].SPTDAT = (command & 0x00FF);
400 wait_transmit_done();
401 spi->ch[0].SPTDAT = (data & 0xFF00) >> 8;
402 wait_transmit_done();
403 spi->ch[0].SPTDAT = (data & 0x00FF);
404 wait_transmit_done();
409 static void tsc2000_set_brightness(void)
415 tsc2000_write(1, 2, 0x0); /* Power up DAC */
417 i = getenv_r("brightness", tmp, sizeof(tmp));
419 ? (int) simple_strtoul (tmp, NULL, 10)
420 : CONFIG_SYS_BRIGHTNESS;
422 tsc2000_write(0, 0xb, br & 0xff);
426 #ifdef CONFIG_CMD_NET
427 int board_eth_init(bd_t *bis)
431 rc = cs8900_initialize(0, CONFIG_CS8900_BASE);