delta.c 9.3 KB

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