trab.c 7.3 KB

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