3 * Gary Jennejohn, DENX Software Engineering, <gj@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,
31 /* ------------------------------------------------------------------------- */
34 static void spi_init(void);
35 static void wait_transmit_done(void);
36 static void tsc2000_write(unsigned int page, unsigned int reg,
38 static void tsc2000_set_brightness(void);
40 #ifdef CONFIG_MODEM_SUPPORT
41 static int key_pressed(void);
42 extern void disable_putc(void);
43 extern int do_mdm_init; /* defined in common/main.c */
46 * We need a delay of at least 500 us after turning on the VFD clock
47 * before we can read any useful information for the CPLD controlling
48 * the keyboard switches. Let's play safe and wait 5 ms. The problem
49 * is that timers are not available yet, so we use a manually timed
52 #define KBD_MDELAY 5000
53 static void udelay_no_timer (int usec)
55 DECLARE_GLOBAL_DATA_PTR;
60 for (i = 0; i < delay; i ++) gd->bd->bi_arch_number = 145;
62 #endif /* CONFIG_MODEM_SUPPORT */
65 * Miscellaneous platform dependent initialisations
70 #if defined(CONFIG_VFD)
71 extern int vfd_init_clocks(void);
73 DECLARE_GLOBAL_DATA_PTR;
74 S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
75 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
77 /* memory and cpu-speed are setup before relocation */
78 #ifdef CONFIG_TRAB_50MHZ
79 /* change the clock to be 50 MHz 1:1:1 */
80 /* MDIV:0x5c PDIV:4 SDIV:2 */
81 clk_power->MPLLCON = 0x5c042;
82 clk_power->CLKDIVN = 0;
84 /* change the clock to be 133 MHz 1:2:4 */
85 /* MDIV:0x7d PDIV:4 SDIV:1 */
86 clk_power->MPLLCON = 0x7d041;
87 clk_power->CLKDIVN = 3;
90 /* set up the I/O ports */
91 gpio->PACON = 0x3ffff;
92 gpio->PBCON = 0xaaaaaaaa;
94 /* INPUT nCTS0 nRTS0 TXD[1] TXD[0] RXD[1] RXD[0] */
95 /* 00, 10, 10, 10, 10, 10, 10 */
96 gpio->PFCON = (2<<0) | (2<<2) | (2<<4) | (2<<6) | (2<<8) | (2<<10);
98 /* do not pull up RXD0, RXD1, TXD0, TXD1, CTS0, RTS0 */
99 gpio->PFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5);
101 /* do not pull up RXD0, RXD1, TXD0, TXD1 */
102 gpio->PFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3);
108 /* arch number of SAMSUNG-Board */
109 /* MACH_TYPE_SMDK2400 */
110 /* XXX this isn't really correct, but keep it for now */
111 gd->bd->bi_arch_number = 145;
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 */
138 DECLARE_GLOBAL_DATA_PTR;
140 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
141 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
145 /*-----------------------------------------------------------------------
146 * Keyboard Controller
149 /* Maximum key number */
150 #define KEYBD_KEY_NUM 4
152 #define KBD_DATA (((*(volatile ulong *)0x04020000) >> 16) & 0xF)
154 static uchar *key_match (ulong);
156 int misc_init_r (void)
158 ulong kbd_data = KBD_DATA;
159 uchar keybd_env[KEYBD_KEY_NUM + 1];
163 for (i = 0; i < KEYBD_KEY_NUM; ++i) {
164 keybd_env[i] = '0' + ((kbd_data >> i) & 1);
167 debug ("** Setting keybd=\"%s\"\n", keybd_env);
168 setenv ("keybd", keybd_env);
170 str = strdup (key_match (kbd_data)); /* decode keys */
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 */
180 #ifdef CFG_BRIGHTNESS
181 tsc2000_set_brightness();
186 #ifdef CONFIG_PREBOOT
188 static uchar kbd_magic_prefix[] = "key_magic";
189 static uchar kbd_command_prefix[] = "key_cmd";
191 static int compare_magic (ulong kbd_data, uchar *str)
195 debug ("compare_magic: kbd: %04lx str: \"%s\"\n",kbd_data,str);
198 uchar c = *str - '1';
200 if (c >= KEYBD_KEY_NUM) /* bad key number */
205 if (!(kbd_data & key_mask)) { /* key not pressed */
206 debug ( "compare_magic: "
207 "kbd: %04lx mask: %04lx - key not pressed\n",
208 kbd_data, key_mask );
212 kbd_data &= ~key_mask;
215 if (kbd_data) { /* key(s) not released */
216 debug ( "compare_magic: "
217 "kbd: %04lx - key(s) not released\n", kbd_data);
224 /*-----------------------------------------------------------------------
225 * Check if pressed key(s) match magic sequence,
226 * and return the command string associated with that key(s).
228 * If no key press was decoded, NULL is returned.
230 * Note: the first character of the argument will be overwritten with
231 * the "magic charcter code" of the decoded key(s), or '\0'.
234 * Note: the string points to static environment data and must be
235 * saved before you call any function that modifies the environment.
237 static uchar *key_match (ulong kbd_data)
239 uchar magic[sizeof (kbd_magic_prefix) + 1];
240 uchar cmd_name[sizeof (kbd_command_prefix) + 1];
242 uchar *kbd_magic_keys;
245 * The following string defines the characters that can pe appended
246 * to "key_magic" to form the names of environment variables that
247 * hold "magic" key codes, i. e. such key codes that can cause
248 * pre-boot actions. If the string is empty (""), then only
249 * "key_magic" is checked (old behaviour); the string "125" causes
250 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
252 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
255 debug ("key_match: magic_keys=\"%s\"\n", kbd_magic_keys);
257 /* loop over all magic keys;
258 * use '\0' suffix in case of empty string
260 for (suffix=kbd_magic_keys; *suffix || suffix==kbd_magic_keys; ++suffix)
262 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
264 debug ("key_match: magic=\"%s\"\n",
265 getenv(magic) ? getenv(magic) : "<UNDEFINED>");
267 if (compare_magic(kbd_data, getenv(magic)) == 0)
269 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
270 debug ("key_match: cmdname %s=\"%s\"\n",
275 return (getenv (cmd_name));
278 debug ("key_match: no match\n");
281 #endif /* CONFIG_PREBOOT */
283 /* Read Keyboard status */
284 int do_kbd (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
286 ulong kbd_data = KBD_DATA;
287 uchar keybd_env[KEYBD_KEY_NUM + 1];
291 for (i = 0; i < KEYBD_KEY_NUM; ++i) {
292 keybd_env[i] = '0' + ((kbd_data >> i) & 1);
293 printf (" %c", keybd_env[i]);
297 setenv ("keybd", keybd_env);
303 "kbd - read keyboard status\n",
307 #ifdef CONFIG_MODEM_SUPPORT
308 static int key_pressed(void)
310 return (compare_magic(KBD_DATA, CONFIG_MODEM_KEY_MAGIC) == 0);
312 #endif /* CONFIG_MODEM_SUPPORT */
314 #ifdef CFG_BRIGHTNESS
316 static inline void SET_CS_TOUCH(void)
318 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
320 gpio->PDDAT &= 0x5FF;
323 static inline void CLR_CS_TOUCH(void)
325 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
327 gpio->PDDAT |= 0x200;
330 static void spi_init(void)
332 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
333 S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI();
336 /* Configure I/O ports. */
337 gpio->PDCON = (gpio->PDCON & 0xF3FFFF) | 0x040000;
338 gpio->PGCON = (gpio->PGCON & 0x0F3FFF) | 0x008000;
339 gpio->PGCON = (gpio->PGCON & 0x0CFFFF) | 0x020000;
340 gpio->PGCON = (gpio->PGCON & 0x03FFFF) | 0x080000;
344 spi->ch[0].SPPRE = 0x1F; /* Baudrate ca. 514kHz */
345 spi->ch[0].SPPIN = 0x01; /* SPI-MOSI holds Level after last bit */
346 spi->ch[0].SPCON = 0x1A; /* Polling, Prescaler, Master, CPOL=0, CPHA=1 */
348 /* Dummy byte ensures clock to be low. */
349 for (i = 0; i < 10; i++) {
350 spi->ch[0].SPTDAT = 0xFF;
352 wait_transmit_done();
355 static void wait_transmit_done(void)
357 S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI();
359 while (!(spi->ch[0].SPSTA & 0x01)); /* wait until transfer is done */
362 static void tsc2000_write(unsigned int page, unsigned int reg,
365 S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI();
366 unsigned int command;
370 command |= (page << 11);
371 command |= (reg << 5);
373 spi->ch[0].SPTDAT = (command & 0xFF00) >> 8;
374 wait_transmit_done();
375 spi->ch[0].SPTDAT = (command & 0x00FF);
376 wait_transmit_done();
377 spi->ch[0].SPTDAT = (data & 0xFF00) >> 8;
378 wait_transmit_done();
379 spi->ch[0].SPTDAT = (data & 0x00FF);
380 wait_transmit_done();
385 static void tsc2000_set_brightness(void)
391 tsc2000_write(1, 2, 0x0); /* Power up DAC */
393 i = getenv_r("brightness", tmp, sizeof(tmp));
395 ? (int) simple_strtoul (tmp, NULL, 10)
398 tsc2000_write(0, 0xb, br & 0xff);