delta.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*
  2. * (C) Copyright 2006
  3. * DENX Software Engineering
  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. #include <common.h>
  24. #include <netdev.h>
  25. #include <i2c.h>
  26. #include <da9030.h>
  27. #include <malloc.h>
  28. #include <command.h>
  29. #include <asm/arch/pxa-regs.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. /* ------------------------------------------------------------------------- */
  32. static void init_DA9030(void);
  33. static void keys_init(void);
  34. static void get_pressed_keys(uchar *s);
  35. static uchar *key_match(uchar *kbd_data);
  36. /*
  37. * Miscelaneous platform dependent initialisations
  38. */
  39. int board_init (void)
  40. {
  41. /* memory and cpu-speed are setup before relocation */
  42. /* so we do _nothing_ here */
  43. /* arch number of Lubbock-Board mk@tbd: fix this! */
  44. gd->bd->bi_arch_number = MACH_TYPE_LUBBOCK;
  45. /* adress of boot parameters */
  46. gd->bd->bi_boot_params = 0xa0000100;
  47. return 0;
  48. }
  49. int board_late_init(void)
  50. {
  51. #ifdef DELTA_CHECK_KEYBD
  52. uchar kbd_data[KEYBD_DATALEN];
  53. char keybd_env[2 * KEYBD_DATALEN + 1];
  54. char *str;
  55. int i;
  56. #endif /* DELTA_CHECK_KEYBD */
  57. setenv("stdout", "serial");
  58. setenv("stderr", "serial");
  59. #ifdef DELTA_CHECK_KEYBD
  60. keys_init();
  61. memset(kbd_data, '\0', KEYBD_DATALEN);
  62. /* check for pressed keys and setup keybd_env */
  63. get_pressed_keys(kbd_data);
  64. for (i = 0; i < KEYBD_DATALEN; ++i) {
  65. sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
  66. }
  67. setenv ("keybd", keybd_env);
  68. str = strdup ((char *)key_match (kbd_data)); /* decode keys */
  69. # ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */
  70. setenv ("preboot", str); /* set or delete definition */
  71. # endif /* CONFIG_PREBOOT */
  72. if (str != NULL) {
  73. free (str);
  74. }
  75. #endif /* DELTA_CHECK_KEYBD */
  76. init_DA9030();
  77. return 0;
  78. }
  79. /*
  80. * Magic Key Handling, mainly copied from board/lwmon/lwmon.c
  81. */
  82. #ifdef DELTA_CHECK_KEYBD
  83. static uchar kbd_magic_prefix[] = "key_magic";
  84. static uchar kbd_command_prefix[] = "key_cmd";
  85. /*
  86. * Get pressed keys
  87. * s is a buffer of size KEYBD_DATALEN-1
  88. */
  89. static void get_pressed_keys(uchar *s)
  90. {
  91. unsigned long val;
  92. val = GPLR3;
  93. if(val & (1<<31))
  94. *s++ = KEYBD_KP_DKIN0;
  95. if(val & (1<<18))
  96. *s++ = KEYBD_KP_DKIN1;
  97. if(val & (1<<29))
  98. *s++ = KEYBD_KP_DKIN2;
  99. if(val & (1<<22))
  100. *s++ = KEYBD_KP_DKIN5;
  101. }
  102. static void keys_init()
  103. {
  104. CKENB |= CKENB_7_GPIO;
  105. udelay(100);
  106. /* Configure GPIOs */
  107. GPIO127 = 0xa840; /* KP_DKIN0 */
  108. GPIO114 = 0xa840; /* KP_DKIN1 */
  109. GPIO125 = 0xa840; /* KP_DKIN2 */
  110. GPIO118 = 0xa840; /* KP_DKIN5 */
  111. /* Configure GPIOs as inputs */
  112. GPDR3 &= ~(1<<31 | 1<<18 | 1<<29 | 1<<22);
  113. GCDR3 = (1<<31 | 1<<18 | 1<<29 | 1<<22);
  114. udelay(100);
  115. }
  116. static int compare_magic (uchar *kbd_data, uchar *str)
  117. {
  118. /* uchar compare[KEYBD_DATALEN-1]; */
  119. uchar compare[KEYBD_DATALEN];
  120. char *nxt;
  121. int i;
  122. /* Don't include modifier byte */
  123. /* memcpy (compare, kbd_data+1, KEYBD_DATALEN-1); */
  124. memcpy (compare, kbd_data, KEYBD_DATALEN);
  125. for (; str != NULL; str = (*nxt) ? (uchar *)(nxt+1) : (uchar *)nxt) {
  126. uchar c;
  127. int k;
  128. c = (uchar) simple_strtoul ((char *)str, (char **) (&nxt), 16);
  129. if (str == (uchar *)nxt) { /* invalid character */
  130. break;
  131. }
  132. /*
  133. * Check if this key matches the input.
  134. * Set matches to zero, so they match only once
  135. * and we can find duplicates or extra keys
  136. */
  137. for (k = 0; k < sizeof(compare); ++k) {
  138. if (compare[k] == '\0') /* only non-zero entries */
  139. continue;
  140. if (c == compare[k]) { /* found matching key */
  141. compare[k] = '\0';
  142. break;
  143. }
  144. }
  145. if (k == sizeof(compare)) {
  146. return -1; /* unmatched key */
  147. }
  148. }
  149. /*
  150. * A full match leaves no keys in the `compare' array,
  151. */
  152. for (i = 0; i < sizeof(compare); ++i) {
  153. if (compare[i])
  154. {
  155. return -1;
  156. }
  157. }
  158. return 0;
  159. }
  160. static uchar *key_match (uchar *kbd_data)
  161. {
  162. char magic[sizeof (kbd_magic_prefix) + 1];
  163. uchar *suffix;
  164. char *kbd_magic_keys;
  165. /*
  166. * The following string defines the characters that can pe appended
  167. * to "key_magic" to form the names of environment variables that
  168. * hold "magic" key codes, i. e. such key codes that can cause
  169. * pre-boot actions. If the string is empty (""), then only
  170. * "key_magic" is checked (old behaviour); the string "125" causes
  171. * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
  172. */
  173. if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
  174. kbd_magic_keys = "";
  175. /* loop over all magic keys;
  176. * use '\0' suffix in case of empty string
  177. */
  178. for (suffix=(uchar *)kbd_magic_keys; *suffix || suffix==(uchar *)kbd_magic_keys; ++suffix) {
  179. sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
  180. #if 0
  181. printf ("### Check magic \"%s\"\n", magic);
  182. #endif
  183. if (compare_magic(kbd_data, (uchar *)getenv(magic)) == 0) {
  184. char cmd_name[sizeof (kbd_command_prefix) + 1];
  185. char *cmd;
  186. sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
  187. cmd = getenv (cmd_name);
  188. #if 0
  189. printf ("### Set PREBOOT to $(%s): \"%s\"\n",
  190. cmd_name, cmd ? cmd : "<<NULL>>");
  191. #endif
  192. *kbd_data = *suffix;
  193. return ((uchar *)cmd);
  194. }
  195. }
  196. #if 0
  197. printf ("### Delete PREBOOT\n");
  198. #endif
  199. *kbd_data = '\0';
  200. return (NULL);
  201. }
  202. int do_kbd (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  203. {
  204. uchar kbd_data[KEYBD_DATALEN];
  205. char keybd_env[2 * KEYBD_DATALEN + 1];
  206. int i;
  207. /* Read keys */
  208. get_pressed_keys(kbd_data);
  209. puts ("Keys:");
  210. for (i = 0; i < KEYBD_DATALEN; ++i) {
  211. sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
  212. printf (" %02x", kbd_data[i]);
  213. }
  214. putc ('\n');
  215. setenv ("keybd", keybd_env);
  216. return 0;
  217. }
  218. U_BOOT_CMD(
  219. kbd, 1, 1, do_kbd,
  220. "read keyboard status",
  221. ""
  222. );
  223. #endif /* DELTA_CHECK_KEYBD */
  224. int dram_init (void)
  225. {
  226. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  227. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  228. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  229. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  230. gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
  231. gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
  232. gd->bd->bi_dram[3].start = PHYS_SDRAM_4;
  233. gd->bd->bi_dram[3].size = PHYS_SDRAM_4_SIZE;
  234. return 0;
  235. }
  236. void i2c_init_board()
  237. {
  238. CKENB |= (CKENB_4_I2C);
  239. /* setup I2C GPIO's */
  240. GPIO32 = 0x801; /* SCL = Alt. Fkt. 1 */
  241. GPIO33 = 0x801; /* SDA = Alt. Fkt. 1 */
  242. }
  243. /* initialize the DA9030 Power Controller */
  244. static void init_DA9030()
  245. {
  246. uchar addr = (uchar) DA9030_I2C_ADDR, val = 0;
  247. CKENB |= CKENB_7_GPIO;
  248. udelay(100);
  249. /* Rising Edge on EXTON to reset DA9030 */
  250. GPIO17 = 0x8800; /* configure GPIO17, no pullup, -down */
  251. GPDR0 |= (1<<17); /* GPIO17 is output */
  252. GSDR0 = (1<<17);
  253. GPCR0 = (1<<17); /* drive GPIO17 low */
  254. GPSR0 = (1<<17); /* drive GPIO17 high */
  255. #if CONFIG_SYS_DA9030_EXTON_DELAY
  256. udelay((unsigned long) CONFIG_SYS_DA9030_EXTON_DELAY); /* wait for DA9030 */
  257. #endif
  258. GPCR0 = (1<<17); /* drive GPIO17 low */
  259. /* reset the watchdog and go active (0xec) */
  260. val = (SYS_CONTROL_A_HWRES_ENABLE |
  261. (0x6<<4) |
  262. SYS_CONTROL_A_WDOG_ACTION |
  263. SYS_CONTROL_A_WATCHDOG);
  264. if(i2c_write(addr, SYS_CONTROL_A, 1, &val, 1)) {
  265. printf("Error accessing DA9030 via i2c.\n");
  266. return;
  267. }
  268. val = 0x80;
  269. if(i2c_write(addr, IRQ_MASK_B, 1, &val, 1)) {
  270. printf("Error accessing DA9030 via i2c.\n");
  271. return;
  272. }
  273. i2c_reg_write(addr, REG_CONTROL_1_97, 0xfd); /* disable LDO1, enable LDO6 */
  274. i2c_reg_write(addr, LDO2_3, 0xd1); /* LDO2 =1,9V, LDO3=3,1V */
  275. i2c_reg_write(addr, LDO4_5, 0xcc); /* LDO2 =1,9V, LDO3=3,1V */
  276. i2c_reg_write(addr, LDO6_SIMCP, 0x3e); /* LDO6=3,2V, SIMCP = 5V support */
  277. i2c_reg_write(addr, LDO7_8, 0xc9); /* LDO7=2,7V, LDO8=3,0V */
  278. i2c_reg_write(addr, LDO9_12, 0xec); /* LDO9=3,0V, LDO12=3,2V */
  279. i2c_reg_write(addr, BUCK, 0x0c); /* Buck=1.2V */
  280. i2c_reg_write(addr, REG_CONTROL_2_98, 0x7f); /* All LDO'S on 8,9,10,11,12,14 */
  281. i2c_reg_write(addr, LDO_10_11, 0xcc); /* LDO10=3.0V LDO11=3.0V */
  282. i2c_reg_write(addr, LDO_15, 0xae); /* LDO15=1.8V, dislock first 3bit */
  283. i2c_reg_write(addr, LDO_14_16, 0x05); /* LDO14=2.8V, LDO16=NB */
  284. i2c_reg_write(addr, LDO_18_19, 0x9c); /* LDO18=3.0V, LDO19=2.7V */
  285. i2c_reg_write(addr, LDO_17_SIMCP0, 0x2c); /* LDO17=3.0V, SIMCP=3V support */
  286. i2c_reg_write(addr, BUCK2_DVC1, 0x9a); /* Buck2=1.5V plus Update support of 520 MHz */
  287. i2c_reg_write(addr, REG_CONTROL_2_18, 0x43); /* Ball on */
  288. i2c_reg_write(addr, MISC_CONTROLB, 0x08); /* session valid enable */
  289. i2c_reg_write(addr, USBPUMP, 0xc1); /* start pump, ignore HW signals */
  290. val = i2c_reg_read(addr, STATUS);
  291. if(val & STATUS_CHDET)
  292. printf("Charger detected, turning on LED.\n");
  293. else {
  294. printf("No charger detetected.\n");
  295. /* undervoltage? print error and power down */
  296. }
  297. }
  298. #if 0
  299. /* reset the DA9030 watchdog */
  300. void hw_watchdog_reset(void)
  301. {
  302. uchar addr = (uchar) DA9030_I2C_ADDR, val = 0;
  303. val = i2c_reg_read(addr, SYS_CONTROL_A);
  304. val |= SYS_CONTROL_A_WATCHDOG;
  305. i2c_reg_write(addr, SYS_CONTROL_A, val);
  306. }
  307. #endif
  308. #ifdef CONFIG_CMD_NET
  309. int board_eth_init(bd_t *bis)
  310. {
  311. int rc = 0;
  312. #ifdef CONFIG_SMC91111
  313. rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
  314. #endif
  315. return rc;
  316. }
  317. #endif