delta.c 9.6 KB

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