PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/source/u-boot/board/eltec/elppc/misc.c

https://bitbucket.org/tfzxyinhao/kindle-fire
C | 261 lines | 171 code | 37 blank | 53 comment | 39 complexity | d7bd4cc9413ecac134bcf24e34706a68 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, 0BSD, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-2.0, BSD-3-Clause, LGPL-2.1, Apache-2.0, AGPL-3.0, GPL-3.0
  1. /*
  2. * (C) Copyright 2002 ELTEC Elektronik AG
  3. * Frank Gottschling <fgottschling@eltec.de>
  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. /* includes */
  24. #include <common.h>
  25. #include <linux/ctype.h>
  26. #include <pci.h>
  27. #include <net.h>
  28. #include "srom.h"
  29. /* imports */
  30. extern char console_buffer[CFG_CBSIZE];
  31. extern int l2_cache_enable (int l2control);
  32. extern int eepro100_write_eeprom (struct eth_device *dev, int location,
  33. int addr_len, unsigned short data);
  34. extern int read_eeprom (struct eth_device *dev, int location, int addr_len);
  35. /*----------------------------------------------------------------------------*/
  36. /*
  37. * read/write to nvram is only byte access
  38. */
  39. void *nvram_read (void *dest, const long src, size_t count)
  40. {
  41. uchar *d = (uchar *) dest;
  42. uchar *s = (uchar *) (CFG_ENV_MAP_ADRS + src);
  43. while (count--)
  44. *d++ = *s++;
  45. return dest;
  46. }
  47. void nvram_write (long dest, const void *src, size_t count)
  48. {
  49. uchar *d = (uchar *) (CFG_ENV_MAP_ADRS + dest);
  50. uchar *s = (uchar *) src;
  51. while (count--)
  52. *d++ = *s++;
  53. }
  54. /*----------------------------------------------------------------------------*/
  55. /*
  56. * handle sroms on ELPPC
  57. * fix ether address
  58. * set serial console as default
  59. */
  60. int misc_init_r (void)
  61. {
  62. revinfo eerev;
  63. u_char *ptr;
  64. u_int i, l, initSrom, copyNv;
  65. char buf[256];
  66. char hex[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0,
  67. 0, 0, 0, 0, 10, 11, 12, 13, 14, 15
  68. };
  69. /* Clock setting for MPC107 i2c */
  70. mpc107_i2c_init (MPC107_EUMB_ADDR, 0x2b);
  71. /* Reset the EPIC */
  72. out32r (MPC107_EUMB_GCR, 0xa0000000);
  73. while (in32r (MPC107_EUMB_GCR) & 0x80000000); /* Wait for reset to complete */
  74. out32r (MPC107_EUMB_GCR, 0x20000000); /* Put into into mixed mode */
  75. while (in32r (MPC107_EUMB_IACKR) != 0xff); /* Clear all pending interrupts */
  76. /*
  77. * Check/Remake revision info
  78. */
  79. initSrom = 0;
  80. copyNv = 0;
  81. /* read out current revision srom contens */
  82. mpc107_srom_load (0x0000, (u_char *) & eerev, sizeof (revinfo),
  83. SECOND_DEVICE, FIRST_BLOCK);
  84. /* read out current nvram shadow image */
  85. nvram_read (buf, CFG_NV_SROM_COPY_ADDR, CFG_SROM_SIZE);
  86. if (strcmp (eerev.magic, "ELTEC") != 0) {
  87. /* srom is not initialized -> create a default revision info */
  88. for (i = 0, ptr = (u_char *) & eerev; i < sizeof (revinfo);
  89. i++)
  90. *ptr++ = 0x00;
  91. strcpy (eerev.magic, "ELTEC");
  92. eerev.revrev[0] = 1;
  93. eerev.revrev[1] = 0;
  94. eerev.size = 0x00E0;
  95. eerev.category[0] = 0x01;
  96. /* node id from dead e128 as default */
  97. eerev.etheraddr[0] = 0x00;
  98. eerev.etheraddr[1] = 0x00;
  99. eerev.etheraddr[2] = 0x5B;
  100. eerev.etheraddr[3] = 0x00;
  101. eerev.etheraddr[4] = 0x2E;
  102. eerev.etheraddr[5] = 0x4D;
  103. /* cache config word for ELPPC */
  104. *(int *) &eerev.res[0] = 0;
  105. initSrom = 1; /* force dialog */
  106. copyNv = 1; /* copy to nvram */
  107. }
  108. if ((copyNv == 0)
  109. && (el_srom_checksum ((u_char *) & eerev, CFG_SROM_SIZE) !=
  110. el_srom_checksum ((u_char *) buf, CFG_SROM_SIZE))) {
  111. printf ("Invalid revision info copy in nvram !\n");
  112. printf ("Press key:\n <c> to copy current revision info to nvram.\n");
  113. printf (" <r> to reenter revision info.\n");
  114. printf ("=> ");
  115. if (0 != readline (NULL)) {
  116. switch ((char) toupper (console_buffer[0])) {
  117. case 'C':
  118. copyNv = 1;
  119. break;
  120. case 'R':
  121. copyNv = 1;
  122. initSrom = 1;
  123. break;
  124. }
  125. }
  126. }
  127. if (initSrom) {
  128. memcpy (buf, &eerev.revision[0][0], 14); /* save all revision info */
  129. printf ("Enter revision number (0-9): %c ",
  130. eerev.revision[0][0]);
  131. if (0 != readline (NULL)) {
  132. eerev.revision[0][0] =
  133. (char) toupper (console_buffer[0]);
  134. memcpy (&eerev.revision[1][0], buf, 12); /* shift rest of rev info */
  135. }
  136. printf ("Enter revision character (A-Z): %c ",
  137. eerev.revision[0][1]);
  138. if (1 == readline (NULL)) {
  139. eerev.revision[0][1] =
  140. (char) toupper (console_buffer[0]);
  141. }
  142. printf ("Enter board name (V-XXXX-XXXX): %s ",
  143. (char *) &eerev.board);
  144. if (11 == readline (NULL)) {
  145. for (i = 0; i < 11; i++)
  146. eerev.board[i] =
  147. (char) toupper (console_buffer[i]);
  148. eerev.board[11] = '\0';
  149. }
  150. printf ("Enter serial number: %s ", (char *) &eerev.serial);
  151. if (6 == readline (NULL)) {
  152. for (i = 0; i < 6; i++)
  153. eerev.serial[i] = console_buffer[i];
  154. eerev.serial[6] = '\0';
  155. }
  156. printf ("Enter ether node ID with leading zero (HEX): %02x%02x%02x%02x%02x%02x ", eerev.etheraddr[0], eerev.etheraddr[1], eerev.etheraddr[2], eerev.etheraddr[3], eerev.etheraddr[4], eerev.etheraddr[5]);
  157. if (12 == readline (NULL)) {
  158. for (i = 0; i < 12; i += 2)
  159. eerev.etheraddr[i >> 1] =
  160. (char) (16 *
  161. hex[toupper
  162. (console_buffer[i]) -
  163. '0'] +
  164. hex[toupper
  165. (console_buffer[i + 1]) -
  166. '0']);
  167. }
  168. l = strlen ((char *) &eerev.text);
  169. printf ("Add to text section (max 64 chr): %s ",
  170. (char *) &eerev.text);
  171. if (0 != readline (NULL)) {
  172. for (i = l; i < 63; i++)
  173. eerev.text[i] = console_buffer[i - l];
  174. eerev.text[63] = '\0';
  175. }
  176. /* prepare network eeprom */
  177. memset (buf, 0, 128);
  178. buf[0] = eerev.etheraddr[1];
  179. buf[1] = eerev.etheraddr[0];
  180. buf[2] = eerev.etheraddr[3];
  181. buf[3] = eerev.etheraddr[2];
  182. buf[4] = eerev.etheraddr[5];
  183. buf[5] = eerev.etheraddr[4];
  184. *(unsigned short *) &buf[20] = 0x48B2;
  185. *(unsigned short *) &buf[22] = 0x0004;
  186. *(unsigned short *) &buf[24] = 0x1433;
  187. printf ("\nSRom: Writing i82559 info ........ ");
  188. if (eepro100_srom_store ((unsigned short *) buf) == -1)
  189. printf ("FAILED\n");
  190. else
  191. printf ("OK\n");
  192. /* update CRC */
  193. eerev.crc =
  194. el_srom_checksum ((u_char *) eerev.board, eerev.size);
  195. /* write new values */
  196. printf ("\nSRom: Writing revision info ...... ");
  197. if (mpc107_srom_store
  198. ((BLOCK_SIZE - sizeof (revinfo)), (u_char *) & eerev,
  199. sizeof (revinfo), SECOND_DEVICE, FIRST_BLOCK) == -1)
  200. printf ("FAILED\n\n");
  201. else
  202. printf ("OK\n\n");
  203. /* write new values as shadow image to nvram */
  204. nvram_write (CFG_NV_SROM_COPY_ADDR, (void *) &eerev,
  205. CFG_SROM_SIZE);
  206. }
  207. /*if (initSrom) */
  208. /* copy current values as shadow image to nvram */
  209. if (initSrom == 0 && copyNv == 1)
  210. nvram_write (CFG_NV_SROM_COPY_ADDR, (void *) &eerev,
  211. CFG_SROM_SIZE);
  212. /* update environment */
  213. sprintf (buf, "%02x:%02x:%02x:%02x:%02x:%02x",
  214. eerev.etheraddr[0], eerev.etheraddr[1],
  215. eerev.etheraddr[2], eerev.etheraddr[3],
  216. eerev.etheraddr[4], eerev.etheraddr[5]);
  217. setenv ("ethaddr", buf);
  218. /* print actual board identification */
  219. printf ("Ident: %s Ser %s Rev %c%c\n",
  220. eerev.board, (char *) &eerev.serial,
  221. eerev.revision[0][0], eerev.revision[0][1]);
  222. return (0);
  223. }
  224. /*----------------------------------------------------------------------------*/