delta.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. /* board dependant usb stuff */
  83. int usb_board_init()
  84. {
  85. /*
  86. * Enable USB host clock.
  87. */
  88. CKENA |= (CKENA_2_USBHOST | CKENA_20_UDC);
  89. udelay(100);
  90. /* Configure Port 2 for Host (USB Client Registers) */
  91. UP2OCR = 0x3000c;
  92. #if 0
  93. GPIO2_2 = 0x801; /* USBHPEN - Alt. Fkt. 1 */
  94. GPIO3_2 = 0x801; /* USBHPWR - Alt. Fkt. 1 */
  95. #endif
  96. UHCHR |= UHCHR_FHR;
  97. wait_ms(11); /* udelay(11); */
  98. UHCHR &= ~UHCHR_FHR;
  99. UHCHR |= UHCHR_FSBIR;
  100. while (UHCHR & UHCHR_FSBIR)
  101. udelay(1);
  102. #if 0
  103. UHCHR |= UHCHR_PCPL; /* USBHPEN is active low */
  104. UHCHR |= UHCHR_PSPL; /* USBHPWR is active low */
  105. #endif
  106. UHCHR &= ~UHCHR_SSEP0;
  107. UHCHR &= ~UHCHR_SSEP1;
  108. UHCHR &= ~UHCHR_SSE;
  109. return 0;
  110. }
  111. int usb_board_stop()
  112. {
  113. /* may not want to do this */
  114. /* CKENA &= ~(CKENA_2_USBHOST | CKENA_20_UDC); */
  115. return 0;
  116. }
  117. /*
  118. * Magic Key Handling, mainly copied from board/lwmon/lwmon.c
  119. */
  120. #ifdef DELTA_CHECK_KEYBD
  121. static uchar kbd_magic_prefix[] = "key_magic";
  122. static uchar kbd_command_prefix[] = "key_cmd";
  123. /*
  124. * Get pressed keys
  125. * s is a buffer of size KEYBD_DATALEN-1
  126. */
  127. static void get_pressed_keys(uchar *s)
  128. {
  129. unsigned long val;
  130. val = GPLR3;
  131. if(val & (1<<31))
  132. *s++ = KEYBD_KP_DKIN0;
  133. if(val & (1<<18))
  134. *s++ = KEYBD_KP_DKIN1;
  135. if(val & (1<<29))
  136. *s++ = KEYBD_KP_DKIN2;
  137. if(val & (1<<22))
  138. *s++ = KEYBD_KP_DKIN5;
  139. }
  140. static void keys_init()
  141. {
  142. CKENB |= CKENB_7_GPIO;
  143. udelay(100);
  144. /* Configure GPIOs */
  145. GPIO127 = 0xa840; /* KP_DKIN0 */
  146. GPIO114 = 0xa840; /* KP_DKIN1 */
  147. GPIO125 = 0xa840; /* KP_DKIN2 */
  148. GPIO118 = 0xa840; /* KP_DKIN5 */
  149. /* Configure GPIOs as inputs */
  150. GPDR3 &= ~(1<<31 | 1<<18 | 1<<29 | 1<<22);
  151. GCDR3 = (1<<31 | 1<<18 | 1<<29 | 1<<22);
  152. udelay(100);
  153. }
  154. static int compare_magic (uchar *kbd_data, uchar *str)
  155. {
  156. /* uchar compare[KEYBD_DATALEN-1]; */
  157. uchar compare[KEYBD_DATALEN];
  158. char *nxt;
  159. int i;
  160. /* Don't include modifier byte */
  161. /* memcpy (compare, kbd_data+1, KEYBD_DATALEN-1); */
  162. memcpy (compare, kbd_data, KEYBD_DATALEN);
  163. for (; str != NULL; str = (*nxt) ? (uchar *)(nxt+1) : (uchar *)nxt) {
  164. uchar c;
  165. int k;
  166. c = (uchar) simple_strtoul ((char *)str, (char **) (&nxt), 16);
  167. if (str == (uchar *)nxt) { /* invalid character */
  168. break;
  169. }
  170. /*
  171. * Check if this key matches the input.
  172. * Set matches to zero, so they match only once
  173. * and we can find duplicates or extra keys
  174. */
  175. for (k = 0; k < sizeof(compare); ++k) {
  176. if (compare[k] == '\0') /* only non-zero entries */
  177. continue;
  178. if (c == compare[k]) { /* found matching key */
  179. compare[k] = '\0';
  180. break;
  181. }
  182. }
  183. if (k == sizeof(compare)) {
  184. return -1; /* unmatched key */
  185. }
  186. }
  187. /*
  188. * A full match leaves no keys in the `compare' array,
  189. */
  190. for (i = 0; i < sizeof(compare); ++i) {
  191. if (compare[i])
  192. {
  193. return -1;
  194. }
  195. }
  196. return 0;
  197. }
  198. static uchar *key_match (uchar *kbd_data)
  199. {
  200. char magic[sizeof (kbd_magic_prefix) + 1];
  201. uchar *suffix;
  202. char *kbd_magic_keys;
  203. /*
  204. * The following string defines the characters that can pe appended
  205. * to "key_magic" to form the names of environment variables that
  206. * hold "magic" key codes, i. e. such key codes that can cause
  207. * pre-boot actions. If the string is empty (""), then only
  208. * "key_magic" is checked (old behaviour); the string "125" causes
  209. * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
  210. */
  211. if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
  212. kbd_magic_keys = "";
  213. /* loop over all magic keys;
  214. * use '\0' suffix in case of empty string
  215. */
  216. for (suffix=(uchar *)kbd_magic_keys; *suffix || suffix==(uchar *)kbd_magic_keys; ++suffix) {
  217. sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
  218. #if 0
  219. printf ("### Check magic \"%s\"\n", magic);
  220. #endif
  221. if (compare_magic(kbd_data, (uchar *)getenv(magic)) == 0) {
  222. char cmd_name[sizeof (kbd_command_prefix) + 1];
  223. char *cmd;
  224. sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
  225. cmd = getenv (cmd_name);
  226. #if 0
  227. printf ("### Set PREBOOT to $(%s): \"%s\"\n",
  228. cmd_name, cmd ? cmd : "<<NULL>>");
  229. #endif
  230. *kbd_data = *suffix;
  231. return ((uchar *)cmd);
  232. }
  233. }
  234. #if 0
  235. printf ("### Delete PREBOOT\n");
  236. #endif
  237. *kbd_data = '\0';
  238. return (NULL);
  239. }
  240. int do_kbd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  241. {
  242. uchar kbd_data[KEYBD_DATALEN];
  243. char keybd_env[2 * KEYBD_DATALEN + 1];
  244. int i;
  245. /* Read keys */
  246. get_pressed_keys(kbd_data);
  247. puts ("Keys:");
  248. for (i = 0; i < KEYBD_DATALEN; ++i) {
  249. sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
  250. printf (" %02x", kbd_data[i]);
  251. }
  252. putc ('\n');
  253. setenv ("keybd", keybd_env);
  254. return 0;
  255. }
  256. U_BOOT_CMD(
  257. kbd, 1, 1, do_kbd,
  258. "kbd - read keyboard status\n",
  259. NULL
  260. );
  261. #endif /* DELTA_CHECK_KEYBD */
  262. int dram_init (void)
  263. {
  264. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  265. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  266. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  267. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  268. gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
  269. gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
  270. gd->bd->bi_dram[3].start = PHYS_SDRAM_4;
  271. gd->bd->bi_dram[3].size = PHYS_SDRAM_4_SIZE;
  272. return 0;
  273. }
  274. void i2c_init_board()
  275. {
  276. CKENB |= (CKENB_4_I2C);
  277. /* setup I2C GPIO's */
  278. GPIO32 = 0x801; /* SCL = Alt. Fkt. 1 */
  279. GPIO33 = 0x801; /* SDA = Alt. Fkt. 1 */
  280. }
  281. /* initialize the DA9030 Power Controller */
  282. static void init_DA9030()
  283. {
  284. uchar addr = (uchar) DA9030_I2C_ADDR, val = 0;
  285. CKENB |= CKENB_7_GPIO;
  286. udelay(100);
  287. /* Rising Edge on EXTON to reset DA9030 */
  288. GPIO17 = 0x8800; /* configure GPIO17, no pullup, -down */
  289. GPDR0 |= (1<<17); /* GPIO17 is output */
  290. GSDR0 = (1<<17);
  291. GPCR0 = (1<<17); /* drive GPIO17 low */
  292. GPSR0 = (1<<17); /* drive GPIO17 high */
  293. #if CFG_DA9030_EXTON_DELAY
  294. udelay((unsigned long) CFG_DA9030_EXTON_DELAY); /* wait for DA9030 */
  295. #endif
  296. GPCR0 = (1<<17); /* drive GPIO17 low */
  297. /* reset the watchdog and go active (0xec) */
  298. val = (SYS_CONTROL_A_HWRES_ENABLE |
  299. (0x6<<4) |
  300. SYS_CONTROL_A_WDOG_ACTION |
  301. SYS_CONTROL_A_WATCHDOG);
  302. if(i2c_write(addr, SYS_CONTROL_A, 1, &val, 1)) {
  303. printf("Error accessing DA9030 via i2c.\n");
  304. return;
  305. }
  306. val = 0x80;
  307. if(i2c_write(addr, IRQ_MASK_B, 1, &val, 1)) {
  308. printf("Error accessing DA9030 via i2c.\n");
  309. return;
  310. }
  311. i2c_reg_write(addr, REG_CONTROL_1_97, 0xfd); /* disable LDO1, enable LDO6 */
  312. i2c_reg_write(addr, LDO2_3, 0xd1); /* LDO2 =1,9V, LDO3=3,1V */
  313. i2c_reg_write(addr, LDO4_5, 0xcc); /* LDO2 =1,9V, LDO3=3,1V */
  314. i2c_reg_write(addr, LDO6_SIMCP, 0x3e); /* LDO6=3,2V, SIMCP = 5V support */
  315. i2c_reg_write(addr, LDO7_8, 0xc9); /* LDO7=2,7V, LDO8=3,0V */
  316. i2c_reg_write(addr, LDO9_12, 0xec); /* LDO9=3,0V, LDO12=3,2V */
  317. i2c_reg_write(addr, BUCK, 0x0c); /* Buck=1.2V */
  318. i2c_reg_write(addr, REG_CONTROL_2_98, 0x7f); /* All LDO'S on 8,9,10,11,12,14 */
  319. i2c_reg_write(addr, LDO_10_11, 0xcc); /* LDO10=3.0V LDO11=3.0V */
  320. i2c_reg_write(addr, LDO_15, 0xae); /* LDO15=1.8V, dislock first 3bit */
  321. i2c_reg_write(addr, LDO_14_16, 0x05); /* LDO14=2.8V, LDO16=NB */
  322. i2c_reg_write(addr, LDO_18_19, 0x9c); /* LDO18=3.0V, LDO19=2.7V */
  323. i2c_reg_write(addr, LDO_17_SIMCP0, 0x2c); /* LDO17=3.0V, SIMCP=3V support */
  324. i2c_reg_write(addr, BUCK2_DVC1, 0x9a); /* Buck2=1.5V plus Update support of 520 MHz */
  325. i2c_reg_write(addr, REG_CONTROL_2_18, 0x43); /* Ball on */
  326. i2c_reg_write(addr, MISC_CONTROLB, 0x08); /* session valid enable */
  327. i2c_reg_write(addr, USBPUMP, 0xc1); /* start pump, ignore HW signals */
  328. val = i2c_reg_read(addr, STATUS);
  329. if(val & STATUS_CHDET)
  330. printf("Charger detected, turning on LED.\n");
  331. else {
  332. printf("No charger detetected.\n");
  333. /* undervoltage? print error and power down */
  334. }
  335. }
  336. #if 0
  337. /* reset the DA9030 watchdog */
  338. void hw_watchdog_reset(void)
  339. {
  340. uchar addr = (uchar) DA9030_I2C_ADDR, val = 0;
  341. val = i2c_reg_read(addr, SYS_CONTROL_A);
  342. val |= SYS_CONTROL_A_WATCHDOG;
  343. i2c_reg_write(addr, SYS_CONTROL_A, val);
  344. }
  345. #endif