delta.c 9.2 KB

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