trab.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. /* #define DEBUG */
  24. #include <common.h>
  25. #include <cmd_bsp.h>
  26. #include <malloc.h>
  27. #include <s3c2400.h>
  28. /* ------------------------------------------------------------------------- */
  29. #ifdef CONFIG_MODEM_SUPPORT
  30. static int key_pressed(void);
  31. extern void disable_putc(void);
  32. extern int do_mdm_init; /* defined in common/main.c */
  33. /*
  34. * We need a delay of at least 500 us after turning on the VFD clock
  35. * before we can read any useful information for the CPLD controlling
  36. * the keyboard switches. Let's play safe and wait 5 ms. The problem
  37. * is that timers are not available yet, so we use a manually timed
  38. * loop.
  39. */
  40. #define KBD_MDELAY 5000
  41. static void udelay_no_timer (int usec)
  42. {
  43. DECLARE_GLOBAL_DATA_PTR;
  44. int i;
  45. int delay = usec * 3;
  46. for (i = 0; i < delay; i ++) gd->bd->bi_arch_number = 145;
  47. }
  48. #endif /* CONFIG_MODEM_SUPPORT */
  49. /*
  50. * Miscellaneous platform dependent initialisations
  51. */
  52. int board_init ()
  53. {
  54. DECLARE_GLOBAL_DATA_PTR;
  55. /* memory and cpu-speed are setup before relocation */
  56. #ifdef CONFIG_TRAB_50MHZ
  57. /* change the clock to be 50 MHz 1:1:1 */
  58. /* MDIV:0x5c PDIV:4 SDIV:2 */
  59. rMPLLCON = 0x5c042;
  60. rCLKDIVN = 0;
  61. #else
  62. /* change the clock to be 133 MHz 1:2:4 */
  63. /* MDIV:0x7d PDIV:4 SDIV:1 */
  64. rMPLLCON = 0x7d041;
  65. rCLKDIVN = 3;
  66. #endif
  67. /* set up the I/O ports */
  68. rPACON = 0x3ffff;
  69. rPBCON = 0xaaaaaaaa;
  70. rPBUP = 0xffff;
  71. /* INPUT nCTS0 nRTS0 TXD[1] TXD[0] RXD[1] RXD[0] */
  72. /* 00, 10, 10, 10, 10, 10, 10 */
  73. rPFCON = (2<<0) | (2<<2) | (2<<4) | (2<<6) | (2<<8) | (2<<10);
  74. #ifdef CONFIG_HWFLOW
  75. /* do not pull up RXD0, RXD1, TXD0, TXD1, CTS0, RTS0 */
  76. rPFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5);
  77. #else
  78. /* do not pull up RXD0, RXD1, TXD0, TXD1 */
  79. rPFUP = (1<<0) | (1<<1) | (1<<2) | (1<<3);
  80. #endif
  81. rPGCON = 0x0;
  82. rPGUP = 0x0;
  83. rOPENCR= 0x0;
  84. /* arch number of SAMSUNG-Board */
  85. /* MACH_TYPE_SMDK2400 */
  86. /* XXX this isn't really correct, but keep it for now */
  87. gd->bd->bi_arch_number = 145;
  88. /* adress of boot parameters */
  89. gd->bd->bi_boot_params = 0x0c000100;
  90. #ifdef CONFIG_MODEM_SUPPORT
  91. /* This stuff is needed by the CPLD to read keyboard data.
  92. * (Copied from the LCD initialization routine.)
  93. */
  94. if (rLCDCON1 == 0) {
  95. extern void init_grid_ctrl(void);
  96. rPCCON = (rPCCON & 0xFFFFFF00)| 0x000000AA;
  97. rPDCON = (rPDCON & 0xFFFFFF03)| 0x000000A8;
  98. #if 0
  99. rPDCON = (rPDCON & 0xFFFFFF00)| 0x000000AA;
  100. #endif
  101. rLCDCON2 = 0x000DC000;
  102. rLCDCON3 = 0x0051000A;
  103. rLCDCON4 = 0x00000001;
  104. rLCDCON5 = 0x00000440;
  105. rLCDCON1 = 0x00000B75;
  106. init_grid_ctrl();
  107. }
  108. udelay_no_timer (KBD_MDELAY);
  109. if (key_pressed()) {
  110. disable_putc(); /* modem doesn't understand banner etc */
  111. do_mdm_init = 1;
  112. }
  113. #endif /* CONFIG_MODEM_SUPPORT */
  114. return 0;
  115. }
  116. int dram_init (void)
  117. {
  118. DECLARE_GLOBAL_DATA_PTR;
  119. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  120. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  121. return 0;
  122. }
  123. /*-----------------------------------------------------------------------
  124. * Keyboard Controller
  125. */
  126. /* Maximum key number */
  127. #define KEYBD_KEY_NUM 4
  128. #define KBD_DATA (((*(volatile ulong *)0x04020000) >> 16) & 0xF)
  129. static uchar *key_match (ulong);
  130. int misc_init_r (void)
  131. {
  132. ulong kbd_data = KBD_DATA;
  133. uchar keybd_env[KEYBD_KEY_NUM + 1];
  134. uchar *str;
  135. int i;
  136. for (i = 0; i < KEYBD_KEY_NUM; ++i) {
  137. keybd_env[i] = '0' + ((kbd_data >> i) & 1);
  138. }
  139. keybd_env[i] = '\0';
  140. debug ("** Setting keybd=\"%s\"\n", keybd_env);
  141. setenv ("keybd", keybd_env);
  142. str = strdup (key_match (kbd_data)); /* decode keys */
  143. #ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */
  144. debug ("** Setting preboot=\"%s\"\n", str);
  145. setenv ("preboot", str); /* set or delete definition */
  146. #endif /* CONFIG_PREBOOT */
  147. if (str != NULL) {
  148. free (str);
  149. }
  150. return (0);
  151. }
  152. #ifdef CONFIG_PREBOOT
  153. static uchar kbd_magic_prefix[] = "key_magic";
  154. static uchar kbd_command_prefix[] = "key_cmd";
  155. static int compare_magic (ulong kbd_data, uchar *str)
  156. {
  157. uchar key_mask;
  158. debug ("compare_magic: kbd: %04lx str: \"%s\"\n",kbd_data,str);
  159. for (; *str; str++)
  160. {
  161. uchar c = *str - '1';
  162. if (c >= KEYBD_KEY_NUM) /* bad key number */
  163. return -1;
  164. key_mask = 1 << c;
  165. if (!(kbd_data & key_mask)) { /* key not pressed */
  166. debug ( "compare_magic: "
  167. "kbd: %04lx mask: %04lx - key not pressed\n",
  168. kbd_data, key_mask );
  169. return -1;
  170. }
  171. kbd_data &= ~key_mask;
  172. }
  173. if (kbd_data) { /* key(s) not released */
  174. debug ( "compare_magic: "
  175. "kbd: %04lx - key(s) not released\n", kbd_data);
  176. return -1;
  177. }
  178. return 0;
  179. }
  180. /*-----------------------------------------------------------------------
  181. * Check if pressed key(s) match magic sequence,
  182. * and return the command string associated with that key(s).
  183. *
  184. * If no key press was decoded, NULL is returned.
  185. *
  186. * Note: the first character of the argument will be overwritten with
  187. * the "magic charcter code" of the decoded key(s), or '\0'.
  188. *
  189. *
  190. * Note: the string points to static environment data and must be
  191. * saved before you call any function that modifies the environment.
  192. */
  193. static uchar *key_match (ulong kbd_data)
  194. {
  195. uchar magic[sizeof (kbd_magic_prefix) + 1];
  196. uchar cmd_name[sizeof (kbd_command_prefix) + 1];
  197. uchar *suffix;
  198. uchar *kbd_magic_keys;
  199. /*
  200. * The following string defines the characters that can pe appended
  201. * to "key_magic" to form the names of environment variables that
  202. * hold "magic" key codes, i. e. such key codes that can cause
  203. * pre-boot actions. If the string is empty (""), then only
  204. * "key_magic" is checked (old behaviour); the string "125" causes
  205. * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
  206. */
  207. if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
  208. kbd_magic_keys = "";
  209. debug ("key_match: magic_keys=\"%s\"\n", kbd_magic_keys);
  210. /* loop over all magic keys;
  211. * use '\0' suffix in case of empty string
  212. */
  213. for (suffix=kbd_magic_keys; *suffix || suffix==kbd_magic_keys; ++suffix)
  214. {
  215. sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
  216. debug ("key_match: magic=\"%s\"\n",
  217. getenv(magic) ? getenv(magic) : "<UNDEFINED>");
  218. if (compare_magic(kbd_data, getenv(magic)) == 0)
  219. {
  220. sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
  221. debug ("key_match: cmdname %s=\"%s\"\n",
  222. cmd_name,
  223. getenv (cmd_name) ?
  224. getenv (cmd_name) :
  225. "<UNDEFINED>");
  226. return (getenv (cmd_name));
  227. }
  228. }
  229. debug ("key_match: no match\n");
  230. return (NULL);
  231. }
  232. #endif /* CONFIG_PREBOOT */
  233. /* Read Keyboard status */
  234. int do_kbd (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  235. {
  236. ulong kbd_data = KBD_DATA;
  237. uchar keybd_env[KEYBD_KEY_NUM + 1];
  238. int i;
  239. puts ("Keys:");
  240. for (i = 0; i < KEYBD_KEY_NUM; ++i) {
  241. keybd_env[i] = '0' + ((kbd_data >> i) & 1);
  242. printf (" %c", keybd_env[i]);
  243. }
  244. keybd_env[i] = '\0';
  245. putc ('\n');
  246. setenv ("keybd", keybd_env);
  247. return 0;
  248. }
  249. #ifdef CONFIG_MODEM_SUPPORT
  250. static int key_pressed(void)
  251. {
  252. return (compare_magic(KBD_DATA, CONFIG_MODEM_KEY_MAGIC) == 0);
  253. }
  254. #endif /* CONFIG_MODEM_SUPPORT */