blob: 2dccd87677c4944887af39b7b748ef6f91e1a76a [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002
Detlev Zundel792a09e2009-05-13 10:54:10 +02003 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
wdenkc6097192002-11-03 00:24:07 +00004 *
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>
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070027#include <netdev.h>
wdenkc6097192002-11-03 00:24:07 +000028#include <malloc.h>
29#include <s3c2400.h>
wdenk8bde7f72003-06-27 21:31:46 +000030#include <command.h>
wdenkc6097192002-11-03 00:24:07 +000031
Wolfgang Denkd87080b2006-03-31 18:32:53 +020032DECLARE_GLOBAL_DATA_PTR;
wdenkc6097192002-11-03 00:24:07 +000033
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020034#ifdef CONFIG_SYS_BRIGHTNESS
wdenk1cb8e982003-03-06 21:55:29 +000035static void spi_init(void);
36static void wait_transmit_done(void);
wdenk82226bf2003-05-20 20:49:01 +000037static void tsc2000_write(unsigned int page, unsigned int reg,
wdenk1cb8e982003-03-06 21:55:29 +000038 unsigned int data);
39static void tsc2000_set_brightness(void);
40#endif
wdenkc6097192002-11-03 00:24:07 +000041#ifdef CONFIG_MODEM_SUPPORT
42static int key_pressed(void);
43extern void disable_putc(void);
44extern int do_mdm_init; /* defined in common/main.c */
45
46/*
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
51 * loop.
52 */
wdenke95b61c2002-11-04 16:02:40 +000053#define KBD_MDELAY 5000
54static void udelay_no_timer (int usec)
wdenkc6097192002-11-03 00:24:07 +000055{
wdenkc6097192002-11-03 00:24:07 +000056 int i;
wdenke95b61c2002-11-04 16:02:40 +000057 int delay = usec * 3;
wdenkc6097192002-11-03 00:24:07 +000058
wdenk731215e2004-10-10 18:41:04 +000059 for (i = 0; i < delay; i ++) gd->bd->bi_arch_number = MACH_TYPE_TRAB;
wdenkc6097192002-11-03 00:24:07 +000060}
61#endif /* CONFIG_MODEM_SUPPORT */
62
63/*
64 * Miscellaneous platform dependent initialisations
65 */
66
67int board_init ()
68{
wdenk6069ff22003-02-28 00:49:47 +000069#if defined(CONFIG_VFD)
70 extern int vfd_init_clocks(void);
wdenka6c7ad22002-12-03 21:28:10 +000071#endif
wdenk48b42612003-06-19 23:01:32 +000072 S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
73 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
wdenkc6097192002-11-03 00:24:07 +000074
75 /* memory and cpu-speed are setup before relocation */
76#ifdef CONFIG_TRAB_50MHZ
77 /* change the clock to be 50 MHz 1:1:1 */
78 /* MDIV:0x5c PDIV:4 SDIV:2 */
wdenk48b42612003-06-19 23:01:32 +000079 clk_power->MPLLCON = 0x5c042;
80 clk_power->CLKDIVN = 0;
wdenkc6097192002-11-03 00:24:07 +000081#else
82 /* change the clock to be 133 MHz 1:2:4 */
83 /* MDIV:0x7d PDIV:4 SDIV:1 */
wdenk48b42612003-06-19 23:01:32 +000084 clk_power->MPLLCON = 0x7d041;
85 clk_power->CLKDIVN = 3;
wdenkc6097192002-11-03 00:24:07 +000086#endif
87
88 /* set up the I/O ports */
wdenk48b42612003-06-19 23:01:32 +000089 gpio->PACON = 0x3ffff;
90 gpio->PBCON = 0xaaaaaaaa;
91 gpio->PBUP = 0xffff;
wdenkc6097192002-11-03 00:24:07 +000092 /* INPUT nCTS0 nRTS0 TXD[1] TXD[0] RXD[1] RXD[0] */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020093 /* 00, 10, 10, 10, 10, 10, 10 */
wdenk48b42612003-06-19 23:01:32 +000094 gpio->PFCON = (2<<0) | (2<<2) | (2<<4) | (2<<6) | (2<<8) | (2<<10);
wdenkc6097192002-11-03 00:24:07 +000095#ifdef CONFIG_HWFLOW
96 /* do not pull up RXD0, RXD1, TXD0, TXD1, CTS0, RTS0 */
wdenk48b42612003-06-19 23:01:32 +000097 gpio->PFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5);
wdenkc6097192002-11-03 00:24:07 +000098#else
99 /* do not pull up RXD0, RXD1, TXD0, TXD1 */
wdenk48b42612003-06-19 23:01:32 +0000100 gpio->PFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3);
wdenkc6097192002-11-03 00:24:07 +0000101#endif
wdenk48b42612003-06-19 23:01:32 +0000102 gpio->PGCON = 0x0;
103 gpio->PGUP = 0x0;
104 gpio->OPENCR= 0x0;
wdenkc6097192002-11-03 00:24:07 +0000105
wdenk149dded2003-09-10 18:20:28 +0000106 /* suppress flicker of the VFDs */
107 gpio->MISCCR = 0x40;
108 gpio->PFCON |= (2<<12);
109
wdenk731215e2004-10-10 18:41:04 +0000110 gd->bd->bi_arch_number = MACH_TYPE_TRAB;
wdenkc6097192002-11-03 00:24:07 +0000111
112 /* adress of boot parameters */
113 gd->bd->bi_boot_params = 0x0c000100;
114
wdenk1cb8e982003-03-06 21:55:29 +0000115 /* Make sure both buzzers are turned off */
wdenk48b42612003-06-19 23:01:32 +0000116 gpio->PDCON |= 0x5400;
117 gpio->PDDAT &= ~0xE0;
wdenk1cb8e982003-03-06 21:55:29 +0000118
wdenka6c7ad22002-12-03 21:28:10 +0000119#ifdef CONFIG_VFD
wdenk6069ff22003-02-28 00:49:47 +0000120 vfd_init_clocks();
wdenka6c7ad22002-12-03 21:28:10 +0000121#endif /* CONFIG_VFD */
wdenkc6097192002-11-03 00:24:07 +0000122
wdenk6069ff22003-02-28 00:49:47 +0000123#ifdef CONFIG_MODEM_SUPPORT
wdenke95b61c2002-11-04 16:02:40 +0000124 udelay_no_timer (KBD_MDELAY);
wdenkc6097192002-11-03 00:24:07 +0000125
126 if (key_pressed()) {
127 disable_putc(); /* modem doesn't understand banner etc */
128 do_mdm_init = 1;
129 }
130#endif /* CONFIG_MODEM_SUPPORT */
131
wdenk6dff5522003-07-15 07:45:49 +0000132#ifdef CONFIG_DRIVER_S3C24X0_I2C
133 /* Configure I/O ports PG5 und PG6 for I2C */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200134 gpio->PGCON = (gpio->PGCON & 0x003c00) | 0x003c00;
wdenk6dff5522003-07-15 07:45:49 +0000135#endif /* CONFIG_DRIVER_S3C24X0_I2C */
136
wdenkc6097192002-11-03 00:24:07 +0000137 return 0;
138}
139
140int dram_init (void)
141{
wdenkc6097192002-11-03 00:24:07 +0000142 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
143 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
144 return 0;
145}
146
147/*-----------------------------------------------------------------------
148 * Keyboard Controller
149 */
150
151/* Maximum key number */
152#define KEYBD_KEY_NUM 4
153
154#define KBD_DATA (((*(volatile ulong *)0x04020000) >> 16) & 0xF)
155
Wolfgang Denka63c31c2006-06-26 10:54:52 +0200156static char *key_match (ulong);
wdenkc6097192002-11-03 00:24:07 +0000157
158int misc_init_r (void)
159{
160 ulong kbd_data = KBD_DATA;
Wolfgang Denka63c31c2006-06-26 10:54:52 +0200161 char *str;
162 char keybd_env[KEYBD_KEY_NUM + 1];
wdenkc6097192002-11-03 00:24:07 +0000163 int i;
164
Wolfgang Denk4bdb53c2006-06-16 15:56:12 +0200165#ifdef CONFIG_VERSION_VARIABLE
166 {
167 /* Set version variable. Please note, that this variable is
168 * also set in main_loop() later in the boot process. The
169 * version variable has to be set this early, because so it
170 * could be used in script files on an usb stick, which
171 * might be called during do_auto_update() */
172 extern char version_string[];
173
174 setenv ("ver", version_string);
175 }
176#endif /* CONFIG_VERSION_VARIABLE */
177
wdenkf54ebdf2003-09-17 15:10:32 +0000178#ifdef CONFIG_AUTO_UPDATE
Wolfgang Denka3d91812006-08-10 01:58:22 +0200179 {
180 extern int do_auto_update(void);
181 /* this has priority over all else */
182 do_auto_update();
183 }
wdenkf54ebdf2003-09-17 15:10:32 +0000184#endif
185
wdenkc6097192002-11-03 00:24:07 +0000186 for (i = 0; i < KEYBD_KEY_NUM; ++i) {
187 keybd_env[i] = '0' + ((kbd_data >> i) & 1);
188 }
189 keybd_env[i] = '\0';
190 debug ("** Setting keybd=\"%s\"\n", keybd_env);
191 setenv ("keybd", keybd_env);
192
193 str = strdup (key_match (kbd_data)); /* decode keys */
194
195#ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */
196 debug ("** Setting preboot=\"%s\"\n", str);
197 setenv ("preboot", str); /* set or delete definition */
198#endif /* CONFIG_PREBOOT */
199 if (str != NULL) {
200 free (str);
201 }
202
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200203#ifdef CONFIG_SYS_BRIGHTNESS
wdenk1cb8e982003-03-06 21:55:29 +0000204 tsc2000_set_brightness();
205#endif
wdenkc6097192002-11-03 00:24:07 +0000206 return (0);
207}
208
209#ifdef CONFIG_PREBOOT
210
211static uchar kbd_magic_prefix[] = "key_magic";
212static uchar kbd_command_prefix[] = "key_cmd";
213
Wolfgang Denka63c31c2006-06-26 10:54:52 +0200214static int compare_magic (ulong kbd_data, char *str)
wdenkc6097192002-11-03 00:24:07 +0000215{
216 uchar key_mask;
217
218 debug ("compare_magic: kbd: %04lx str: \"%s\"\n",kbd_data,str);
219 for (; *str; str++)
220 {
221 uchar c = *str - '1';
222
223 if (c >= KEYBD_KEY_NUM) /* bad key number */
224 return -1;
225
226 key_mask = 1 << c;
227
228 if (!(kbd_data & key_mask)) { /* key not pressed */
229 debug ( "compare_magic: "
230 "kbd: %04lx mask: %04lx - key not pressed\n",
231 kbd_data, key_mask );
232 return -1;
233 }
234
235 kbd_data &= ~key_mask;
236 }
237
238 if (kbd_data) { /* key(s) not released */
239 debug ( "compare_magic: "
240 "kbd: %04lx - key(s) not released\n", kbd_data);
241 return -1;
242 }
243
244 return 0;
245}
246
247/*-----------------------------------------------------------------------
248 * Check if pressed key(s) match magic sequence,
249 * and return the command string associated with that key(s).
250 *
251 * If no key press was decoded, NULL is returned.
252 *
253 * Note: the first character of the argument will be overwritten with
254 * the "magic charcter code" of the decoded key(s), or '\0'.
255 *
256 *
257 * Note: the string points to static environment data and must be
258 * saved before you call any function that modifies the environment.
259 */
Wolfgang Denka63c31c2006-06-26 10:54:52 +0200260static char *key_match (ulong kbd_data)
wdenkc6097192002-11-03 00:24:07 +0000261{
Wolfgang Denka63c31c2006-06-26 10:54:52 +0200262 char magic[sizeof (kbd_magic_prefix) + 1];
263 char cmd_name[sizeof (kbd_command_prefix) + 1];
264 char *suffix;
265 char *kbd_magic_keys;
wdenkc6097192002-11-03 00:24:07 +0000266
267 /*
268 * The following string defines the characters that can pe appended
269 * to "key_magic" to form the names of environment variables that
270 * hold "magic" key codes, i. e. such key codes that can cause
271 * pre-boot actions. If the string is empty (""), then only
272 * "key_magic" is checked (old behaviour); the string "125" causes
273 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
274 */
275 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
276 kbd_magic_keys = "";
277
278 debug ("key_match: magic_keys=\"%s\"\n", kbd_magic_keys);
279
280 /* loop over all magic keys;
281 * use '\0' suffix in case of empty string
282 */
283 for (suffix=kbd_magic_keys; *suffix || suffix==kbd_magic_keys; ++suffix)
284 {
285 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
286
287 debug ("key_match: magic=\"%s\"\n",
288 getenv(magic) ? getenv(magic) : "<UNDEFINED>");
289
290 if (compare_magic(kbd_data, getenv(magic)) == 0)
291 {
292 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
293 debug ("key_match: cmdname %s=\"%s\"\n",
294 cmd_name,
295 getenv (cmd_name) ?
296 getenv (cmd_name) :
297 "<UNDEFINED>");
298 return (getenv (cmd_name));
299 }
300 }
301 debug ("key_match: no match\n");
302 return (NULL);
303}
304#endif /* CONFIG_PREBOOT */
305
306/* Read Keyboard status */
307int do_kbd (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
308{
309 ulong kbd_data = KBD_DATA;
Wolfgang Denka63c31c2006-06-26 10:54:52 +0200310 char keybd_env[KEYBD_KEY_NUM + 1];
wdenkc6097192002-11-03 00:24:07 +0000311 int i;
312
313 puts ("Keys:");
314 for (i = 0; i < KEYBD_KEY_NUM; ++i) {
315 keybd_env[i] = '0' + ((kbd_data >> i) & 1);
316 printf (" %c", keybd_env[i]);
317 }
318 keybd_env[i] = '\0';
319 putc ('\n');
320 setenv ("keybd", keybd_env);
321 return 0;
322}
323
wdenk0d498392003-07-01 21:06:45 +0000324U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200325 kbd, 1, 1, do_kbd,
Peter Tyser2fb26042009-01-27 18:03:12 -0600326 "read keyboard status",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200327 ""
wdenk8bde7f72003-06-27 21:31:46 +0000328);
329
wdenkc6097192002-11-03 00:24:07 +0000330#ifdef CONFIG_MODEM_SUPPORT
331static int key_pressed(void)
332{
333 return (compare_magic(KBD_DATA, CONFIG_MODEM_KEY_MAGIC) == 0);
334}
335#endif /* CONFIG_MODEM_SUPPORT */
wdenk1cb8e982003-03-06 21:55:29 +0000336
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200337#ifdef CONFIG_SYS_BRIGHTNESS
wdenk1cb8e982003-03-06 21:55:29 +0000338
wdenk48b42612003-06-19 23:01:32 +0000339static inline void SET_CS_TOUCH(void)
340{
341 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
342
343 gpio->PDDAT &= 0x5FF;
344}
345
346static inline void CLR_CS_TOUCH(void)
347{
348 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
349
350 gpio->PDDAT |= 0x200;
351}
wdenk1cb8e982003-03-06 21:55:29 +0000352
353static void spi_init(void)
354{
wdenk48b42612003-06-19 23:01:32 +0000355 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
356 S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI();
wdenk1cb8e982003-03-06 21:55:29 +0000357 int i;
358
359 /* Configure I/O ports. */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200360 gpio->PDCON = (gpio->PDCON & 0xF3FFFF) | 0x040000;
wdenk48b42612003-06-19 23:01:32 +0000361 gpio->PGCON = (gpio->PGCON & 0x0F3FFF) | 0x008000;
362 gpio->PGCON = (gpio->PGCON & 0x0CFFFF) | 0x020000;
363 gpio->PGCON = (gpio->PGCON & 0x03FFFF) | 0x080000;
wdenk1cb8e982003-03-06 21:55:29 +0000364
wdenk48b42612003-06-19 23:01:32 +0000365 CLR_CS_TOUCH();
wdenk1cb8e982003-03-06 21:55:29 +0000366
wdenk48b42612003-06-19 23:01:32 +0000367 spi->ch[0].SPPRE = 0x1F; /* Baudrate ca. 514kHz */
368 spi->ch[0].SPPIN = 0x01; /* SPI-MOSI holds Level after last bit */
369 spi->ch[0].SPCON = 0x1A; /* Polling, Prescaler, Master, CPOL=0, CPHA=1 */
wdenk1cb8e982003-03-06 21:55:29 +0000370
371 /* Dummy byte ensures clock to be low. */
372 for (i = 0; i < 10; i++) {
wdenk48b42612003-06-19 23:01:32 +0000373 spi->ch[0].SPTDAT = 0xFF;
wdenk1cb8e982003-03-06 21:55:29 +0000374 }
wdenk82226bf2003-05-20 20:49:01 +0000375 wait_transmit_done();
wdenk1cb8e982003-03-06 21:55:29 +0000376}
377
378static void wait_transmit_done(void)
379{
wdenk48b42612003-06-19 23:01:32 +0000380 S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI();
381
382 while (!(spi->ch[0].SPSTA & 0x01)); /* wait until transfer is done */
wdenk1cb8e982003-03-06 21:55:29 +0000383}
384
wdenk82226bf2003-05-20 20:49:01 +0000385static void tsc2000_write(unsigned int page, unsigned int reg,
wdenk1cb8e982003-03-06 21:55:29 +0000386 unsigned int data)
387{
wdenk48b42612003-06-19 23:01:32 +0000388 S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI();
wdenk1cb8e982003-03-06 21:55:29 +0000389 unsigned int command;
390
wdenk48b42612003-06-19 23:01:32 +0000391 SET_CS_TOUCH();
wdenk1cb8e982003-03-06 21:55:29 +0000392 command = 0x0000;
393 command |= (page << 11);
394 command |= (reg << 5);
395
wdenk48b42612003-06-19 23:01:32 +0000396 spi->ch[0].SPTDAT = (command & 0xFF00) >> 8;
wdenk1cb8e982003-03-06 21:55:29 +0000397 wait_transmit_done();
wdenk48b42612003-06-19 23:01:32 +0000398 spi->ch[0].SPTDAT = (command & 0x00FF);
wdenk1cb8e982003-03-06 21:55:29 +0000399 wait_transmit_done();
wdenk48b42612003-06-19 23:01:32 +0000400 spi->ch[0].SPTDAT = (data & 0xFF00) >> 8;
wdenk1cb8e982003-03-06 21:55:29 +0000401 wait_transmit_done();
wdenk48b42612003-06-19 23:01:32 +0000402 spi->ch[0].SPTDAT = (data & 0x00FF);
wdenk1cb8e982003-03-06 21:55:29 +0000403 wait_transmit_done();
404
wdenk48b42612003-06-19 23:01:32 +0000405 CLR_CS_TOUCH();
wdenk1cb8e982003-03-06 21:55:29 +0000406}
407
408static void tsc2000_set_brightness(void)
409{
Wolfgang Denka63c31c2006-06-26 10:54:52 +0200410 char tmp[10];
wdenk1cb8e982003-03-06 21:55:29 +0000411 int i, br;
412
413 spi_init();
414 tsc2000_write(1, 2, 0x0); /* Power up DAC */
415
416 i = getenv_r("brightness", tmp, sizeof(tmp));
417 br = (i > 0)
418 ? (int) simple_strtoul (tmp, NULL, 10)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200419 : CONFIG_SYS_BRIGHTNESS;
wdenk1cb8e982003-03-06 21:55:29 +0000420
421 tsc2000_write(0, 0xb, br & 0xff);
422}
423#endif
Ben Warrenb1c0eaa2009-08-25 13:09:37 -0700424
425#ifdef CONFIG_CMD_NET
426int board_eth_init(bd_t *bis)
427{
428 int rc = 0;
429#ifdef CONFIG_CS8900
430 rc = cs8900_initialize(0, CONFIG_CS8900_BASE);
431#endif
432 return rc;
433}
434#endif