wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
Detlev Zundel | f1b3f2b | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 3 | * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 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> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 27 | #include <malloc.h> |
| 28 | #include <s3c2400.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 29 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 30 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 31 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 32 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 33 | #ifdef CONFIG_SYS_BRIGHTNESS |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 34 | static void spi_init(void); |
| 35 | static void wait_transmit_done(void); |
wdenk | 2699155 | 2003-05-20 20:49:01 +0000 | [diff] [blame] | 36 | static void tsc2000_write(unsigned int page, unsigned int reg, |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 37 | unsigned int data); |
| 38 | static void tsc2000_set_brightness(void); |
| 39 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 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 */ |
| 44 | |
| 45 | /* |
| 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 |
| 50 | * loop. |
| 51 | */ |
wdenk | e95b61c | 2002-11-04 16:02:40 +0000 | [diff] [blame] | 52 | #define KBD_MDELAY 5000 |
| 53 | static void udelay_no_timer (int usec) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 54 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 55 | int i; |
wdenk | e95b61c | 2002-11-04 16:02:40 +0000 | [diff] [blame] | 56 | int delay = usec * 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 57 | |
wdenk | 767fbd4 | 2004-10-10 18:41:04 +0000 | [diff] [blame] | 58 | for (i = 0; i < delay; i ++) gd->bd->bi_arch_number = MACH_TYPE_TRAB; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 59 | } |
| 60 | #endif /* CONFIG_MODEM_SUPPORT */ |
| 61 | |
| 62 | /* |
| 63 | * Miscellaneous platform dependent initialisations |
| 64 | */ |
| 65 | |
| 66 | int board_init () |
| 67 | { |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 68 | #if defined(CONFIG_VFD) |
| 69 | extern int vfd_init_clocks(void); |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 70 | #endif |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 71 | S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER(); |
| 72 | S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 73 | |
| 74 | /* memory and cpu-speed are setup before relocation */ |
| 75 | #ifdef CONFIG_TRAB_50MHZ |
| 76 | /* change the clock to be 50 MHz 1:1:1 */ |
| 77 | /* MDIV:0x5c PDIV:4 SDIV:2 */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 78 | clk_power->MPLLCON = 0x5c042; |
| 79 | clk_power->CLKDIVN = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 80 | #else |
| 81 | /* change the clock to be 133 MHz 1:2:4 */ |
| 82 | /* MDIV:0x7d PDIV:4 SDIV:1 */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 83 | clk_power->MPLLCON = 0x7d041; |
| 84 | clk_power->CLKDIVN = 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 85 | #endif |
| 86 | |
| 87 | /* set up the I/O ports */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 88 | gpio->PACON = 0x3ffff; |
| 89 | gpio->PBCON = 0xaaaaaaaa; |
| 90 | gpio->PBUP = 0xffff; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 91 | /* INPUT nCTS0 nRTS0 TXD[1] TXD[0] RXD[1] RXD[0] */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 92 | /* 00, 10, 10, 10, 10, 10, 10 */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 93 | gpio->PFCON = (2<<0) | (2<<2) | (2<<4) | (2<<6) | (2<<8) | (2<<10); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 94 | #ifdef CONFIG_HWFLOW |
| 95 | /* do not pull up RXD0, RXD1, TXD0, TXD1, CTS0, RTS0 */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 96 | gpio->PFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 97 | #else |
| 98 | /* do not pull up RXD0, RXD1, TXD0, TXD1 */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 99 | gpio->PFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 100 | #endif |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 101 | gpio->PGCON = 0x0; |
| 102 | gpio->PGUP = 0x0; |
| 103 | gpio->OPENCR= 0x0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 104 | |
wdenk | de887eb | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 105 | /* suppress flicker of the VFDs */ |
| 106 | gpio->MISCCR = 0x40; |
| 107 | gpio->PFCON |= (2<<12); |
| 108 | |
wdenk | 767fbd4 | 2004-10-10 18:41:04 +0000 | [diff] [blame] | 109 | gd->bd->bi_arch_number = MACH_TYPE_TRAB; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 110 | |
| 111 | /* adress of boot parameters */ |
| 112 | gd->bd->bi_boot_params = 0x0c000100; |
| 113 | |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 114 | /* Make sure both buzzers are turned off */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 115 | gpio->PDCON |= 0x5400; |
| 116 | gpio->PDDAT &= ~0xE0; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 117 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 118 | #ifdef CONFIG_VFD |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 119 | vfd_init_clocks(); |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 120 | #endif /* CONFIG_VFD */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 121 | |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 122 | #ifdef CONFIG_MODEM_SUPPORT |
wdenk | e95b61c | 2002-11-04 16:02:40 +0000 | [diff] [blame] | 123 | udelay_no_timer (KBD_MDELAY); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 124 | |
| 125 | if (key_pressed()) { |
| 126 | disable_putc(); /* modem doesn't understand banner etc */ |
| 127 | do_mdm_init = 1; |
| 128 | } |
| 129 | #endif /* CONFIG_MODEM_SUPPORT */ |
| 130 | |
wdenk | ca9bc76 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 131 | #ifdef CONFIG_DRIVER_S3C24X0_I2C |
| 132 | /* Configure I/O ports PG5 und PG6 for I2C */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 133 | gpio->PGCON = (gpio->PGCON & 0x003c00) | 0x003c00; |
wdenk | ca9bc76 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 134 | #endif /* CONFIG_DRIVER_S3C24X0_I2C */ |
| 135 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | int dram_init (void) |
| 140 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 141 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 142 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | /*----------------------------------------------------------------------- |
| 147 | * Keyboard Controller |
| 148 | */ |
| 149 | |
| 150 | /* Maximum key number */ |
| 151 | #define KEYBD_KEY_NUM 4 |
| 152 | |
| 153 | #define KBD_DATA (((*(volatile ulong *)0x04020000) >> 16) & 0xF) |
| 154 | |
Wolfgang Denk | 031621b | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 155 | static char *key_match (ulong); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 156 | |
| 157 | int misc_init_r (void) |
| 158 | { |
| 159 | ulong kbd_data = KBD_DATA; |
Wolfgang Denk | 031621b | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 160 | char *str; |
| 161 | char keybd_env[KEYBD_KEY_NUM + 1]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 162 | int i; |
| 163 | |
Wolfgang Denk | fe287cb | 2006-06-16 15:56:12 +0200 | [diff] [blame] | 164 | #ifdef CONFIG_VERSION_VARIABLE |
| 165 | { |
| 166 | /* Set version variable. Please note, that this variable is |
| 167 | * also set in main_loop() later in the boot process. The |
| 168 | * version variable has to be set this early, because so it |
| 169 | * could be used in script files on an usb stick, which |
| 170 | * might be called during do_auto_update() */ |
| 171 | extern char version_string[]; |
| 172 | |
| 173 | setenv ("ver", version_string); |
| 174 | } |
| 175 | #endif /* CONFIG_VERSION_VARIABLE */ |
| 176 | |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 177 | #ifdef CONFIG_AUTO_UPDATE |
Wolfgang Denk | db0edc6 | 2006-08-10 01:58:22 +0200 | [diff] [blame] | 178 | { |
| 179 | extern int do_auto_update(void); |
| 180 | /* this has priority over all else */ |
| 181 | do_auto_update(); |
| 182 | } |
wdenk | f6a6ac1 | 2003-09-17 15:10:32 +0000 | [diff] [blame] | 183 | #endif |
| 184 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 185 | for (i = 0; i < KEYBD_KEY_NUM; ++i) { |
| 186 | keybd_env[i] = '0' + ((kbd_data >> i) & 1); |
| 187 | } |
| 188 | keybd_env[i] = '\0'; |
| 189 | debug ("** Setting keybd=\"%s\"\n", keybd_env); |
| 190 | setenv ("keybd", keybd_env); |
| 191 | |
| 192 | str = strdup (key_match (kbd_data)); /* decode keys */ |
| 193 | |
| 194 | #ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */ |
| 195 | debug ("** Setting preboot=\"%s\"\n", str); |
| 196 | setenv ("preboot", str); /* set or delete definition */ |
| 197 | #endif /* CONFIG_PREBOOT */ |
| 198 | if (str != NULL) { |
| 199 | free (str); |
| 200 | } |
| 201 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 202 | #ifdef CONFIG_SYS_BRIGHTNESS |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 203 | tsc2000_set_brightness(); |
| 204 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 205 | return (0); |
| 206 | } |
| 207 | |
| 208 | #ifdef CONFIG_PREBOOT |
| 209 | |
| 210 | static uchar kbd_magic_prefix[] = "key_magic"; |
| 211 | static uchar kbd_command_prefix[] = "key_cmd"; |
| 212 | |
Wolfgang Denk | 031621b | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 213 | static int compare_magic (ulong kbd_data, char *str) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 214 | { |
| 215 | uchar key_mask; |
| 216 | |
| 217 | debug ("compare_magic: kbd: %04lx str: \"%s\"\n",kbd_data,str); |
| 218 | for (; *str; str++) |
| 219 | { |
| 220 | uchar c = *str - '1'; |
| 221 | |
| 222 | if (c >= KEYBD_KEY_NUM) /* bad key number */ |
| 223 | return -1; |
| 224 | |
| 225 | key_mask = 1 << c; |
| 226 | |
| 227 | if (!(kbd_data & key_mask)) { /* key not pressed */ |
| 228 | debug ( "compare_magic: " |
| 229 | "kbd: %04lx mask: %04lx - key not pressed\n", |
| 230 | kbd_data, key_mask ); |
| 231 | return -1; |
| 232 | } |
| 233 | |
| 234 | kbd_data &= ~key_mask; |
| 235 | } |
| 236 | |
| 237 | if (kbd_data) { /* key(s) not released */ |
| 238 | debug ( "compare_magic: " |
| 239 | "kbd: %04lx - key(s) not released\n", kbd_data); |
| 240 | return -1; |
| 241 | } |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | /*----------------------------------------------------------------------- |
| 247 | * Check if pressed key(s) match magic sequence, |
| 248 | * and return the command string associated with that key(s). |
| 249 | * |
| 250 | * If no key press was decoded, NULL is returned. |
| 251 | * |
| 252 | * Note: the first character of the argument will be overwritten with |
| 253 | * the "magic charcter code" of the decoded key(s), or '\0'. |
| 254 | * |
| 255 | * |
| 256 | * Note: the string points to static environment data and must be |
| 257 | * saved before you call any function that modifies the environment. |
| 258 | */ |
Wolfgang Denk | 031621b | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 259 | static char *key_match (ulong kbd_data) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 260 | { |
Wolfgang Denk | 031621b | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 261 | char magic[sizeof (kbd_magic_prefix) + 1]; |
| 262 | char cmd_name[sizeof (kbd_command_prefix) + 1]; |
| 263 | char *suffix; |
| 264 | char *kbd_magic_keys; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 265 | |
| 266 | /* |
| 267 | * The following string defines the characters that can pe appended |
| 268 | * to "key_magic" to form the names of environment variables that |
| 269 | * hold "magic" key codes, i. e. such key codes that can cause |
| 270 | * pre-boot actions. If the string is empty (""), then only |
| 271 | * "key_magic" is checked (old behaviour); the string "125" causes |
| 272 | * checks for "key_magic1", "key_magic2" and "key_magic5", etc. |
| 273 | */ |
| 274 | if ((kbd_magic_keys = getenv ("magic_keys")) == NULL) |
| 275 | kbd_magic_keys = ""; |
| 276 | |
| 277 | debug ("key_match: magic_keys=\"%s\"\n", kbd_magic_keys); |
| 278 | |
| 279 | /* loop over all magic keys; |
| 280 | * use '\0' suffix in case of empty string |
| 281 | */ |
| 282 | for (suffix=kbd_magic_keys; *suffix || suffix==kbd_magic_keys; ++suffix) |
| 283 | { |
| 284 | sprintf (magic, "%s%c", kbd_magic_prefix, *suffix); |
| 285 | |
| 286 | debug ("key_match: magic=\"%s\"\n", |
| 287 | getenv(magic) ? getenv(magic) : "<UNDEFINED>"); |
| 288 | |
| 289 | if (compare_magic(kbd_data, getenv(magic)) == 0) |
| 290 | { |
| 291 | sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix); |
| 292 | debug ("key_match: cmdname %s=\"%s\"\n", |
| 293 | cmd_name, |
| 294 | getenv (cmd_name) ? |
| 295 | getenv (cmd_name) : |
| 296 | "<UNDEFINED>"); |
| 297 | return (getenv (cmd_name)); |
| 298 | } |
| 299 | } |
| 300 | debug ("key_match: no match\n"); |
| 301 | return (NULL); |
| 302 | } |
| 303 | #endif /* CONFIG_PREBOOT */ |
| 304 | |
| 305 | /* Read Keyboard status */ |
| 306 | int do_kbd (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 307 | { |
| 308 | ulong kbd_data = KBD_DATA; |
Wolfgang Denk | 031621b | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 309 | char keybd_env[KEYBD_KEY_NUM + 1]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 310 | int i; |
| 311 | |
| 312 | puts ("Keys:"); |
| 313 | for (i = 0; i < KEYBD_KEY_NUM; ++i) { |
| 314 | keybd_env[i] = '0' + ((kbd_data >> i) & 1); |
| 315 | printf (" %c", keybd_env[i]); |
| 316 | } |
| 317 | keybd_env[i] = '\0'; |
| 318 | putc ('\n'); |
| 319 | setenv ("keybd", keybd_env); |
| 320 | return 0; |
| 321 | } |
| 322 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 323 | U_BOOT_CMD( |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 324 | kbd, 1, 1, do_kbd, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 325 | "read keyboard status", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 326 | "" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 327 | ); |
| 328 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 329 | #ifdef CONFIG_MODEM_SUPPORT |
| 330 | static int key_pressed(void) |
| 331 | { |
| 332 | return (compare_magic(KBD_DATA, CONFIG_MODEM_KEY_MAGIC) == 0); |
| 333 | } |
| 334 | #endif /* CONFIG_MODEM_SUPPORT */ |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 335 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 336 | #ifdef CONFIG_SYS_BRIGHTNESS |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 337 | |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 338 | static inline void SET_CS_TOUCH(void) |
| 339 | { |
| 340 | S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); |
| 341 | |
| 342 | gpio->PDDAT &= 0x5FF; |
| 343 | } |
| 344 | |
| 345 | static inline void CLR_CS_TOUCH(void) |
| 346 | { |
| 347 | S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); |
| 348 | |
| 349 | gpio->PDDAT |= 0x200; |
| 350 | } |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 351 | |
| 352 | static void spi_init(void) |
| 353 | { |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 354 | S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); |
| 355 | S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI(); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 356 | int i; |
| 357 | |
| 358 | /* Configure I/O ports. */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 359 | gpio->PDCON = (gpio->PDCON & 0xF3FFFF) | 0x040000; |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 360 | gpio->PGCON = (gpio->PGCON & 0x0F3FFF) | 0x008000; |
| 361 | gpio->PGCON = (gpio->PGCON & 0x0CFFFF) | 0x020000; |
| 362 | gpio->PGCON = (gpio->PGCON & 0x03FFFF) | 0x080000; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 363 | |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 364 | CLR_CS_TOUCH(); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 365 | |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 366 | spi->ch[0].SPPRE = 0x1F; /* Baudrate ca. 514kHz */ |
| 367 | spi->ch[0].SPPIN = 0x01; /* SPI-MOSI holds Level after last bit */ |
| 368 | spi->ch[0].SPCON = 0x1A; /* Polling, Prescaler, Master, CPOL=0, CPHA=1 */ |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 369 | |
| 370 | /* Dummy byte ensures clock to be low. */ |
| 371 | for (i = 0; i < 10; i++) { |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 372 | spi->ch[0].SPTDAT = 0xFF; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 373 | } |
wdenk | 2699155 | 2003-05-20 20:49:01 +0000 | [diff] [blame] | 374 | wait_transmit_done(); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static void wait_transmit_done(void) |
| 378 | { |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 379 | S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI(); |
| 380 | |
| 381 | while (!(spi->ch[0].SPSTA & 0x01)); /* wait until transfer is done */ |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 382 | } |
| 383 | |
wdenk | 2699155 | 2003-05-20 20:49:01 +0000 | [diff] [blame] | 384 | static void tsc2000_write(unsigned int page, unsigned int reg, |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 385 | unsigned int data) |
| 386 | { |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 387 | S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI(); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 388 | unsigned int command; |
| 389 | |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 390 | SET_CS_TOUCH(); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 391 | command = 0x0000; |
| 392 | command |= (page << 11); |
| 393 | command |= (reg << 5); |
| 394 | |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 395 | spi->ch[0].SPTDAT = (command & 0xFF00) >> 8; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 396 | wait_transmit_done(); |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 397 | spi->ch[0].SPTDAT = (command & 0x00FF); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 398 | wait_transmit_done(); |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 399 | spi->ch[0].SPTDAT = (data & 0xFF00) >> 8; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 400 | wait_transmit_done(); |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 401 | spi->ch[0].SPTDAT = (data & 0x00FF); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 402 | wait_transmit_done(); |
| 403 | |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 404 | CLR_CS_TOUCH(); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | static void tsc2000_set_brightness(void) |
| 408 | { |
Wolfgang Denk | 031621b | 2006-06-26 10:54:52 +0200 | [diff] [blame] | 409 | char tmp[10]; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 410 | int i, br; |
| 411 | |
| 412 | spi_init(); |
| 413 | tsc2000_write(1, 2, 0x0); /* Power up DAC */ |
| 414 | |
| 415 | i = getenv_r("brightness", tmp, sizeof(tmp)); |
| 416 | br = (i > 0) |
| 417 | ? (int) simple_strtoul (tmp, NULL, 10) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 418 | : CONFIG_SYS_BRIGHTNESS; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 419 | |
| 420 | tsc2000_write(0, 0xb, br & 0xff); |
| 421 | } |
| 422 | #endif |