iphase4539.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /*
  2. * (C) Copyright 2002 Wolfgang Grandegger <wg@denx.de>
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <ioports.h>
  24. #include <mpc8260.h>
  25. #include <asm/io.h>
  26. #include <asm/immap_8260.h>
  27. int hwc_flash_size (void);
  28. int hwc_local_sdram_size (void);
  29. int hwc_main_sdram_size (void);
  30. int hwc_serial_number (void);
  31. int hwc_mac_address (char *str);
  32. int hwc_manufact_date (char *str);
  33. int seeprom_read (int addr, uchar * data, int size);
  34. /*
  35. * I/O Port configuration table
  36. *
  37. * if conf is 1, then that port pin will be configured at boot time
  38. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  39. *
  40. * The port definitions are taken from the old firmware (see
  41. * also SYS/H/4539.H):
  42. *
  43. * ppar psor pdir podr pdat
  44. * PA: 0x02ffffff 0x02c00000 0xfc403fe6 0x00000000 0x02403fc0
  45. * PB: 0x0fffdeb0 0x000000b0 0x0f032347 0x00000000 0x0f000290
  46. * PC: 0x030ffa55 0x030f0040 0xbcf005ea 0x00000000 0xc0c0ba7d
  47. * PD: 0x09c04e3c 0x01000e3c 0x0a7ff1c3 0x00000000 0x00ce0ae9
  48. */
  49. const iop_conf_t iop_conf_tab[4][32] = {
  50. /* Port A configuration */
  51. { /* conf ppar psor pdir podr pdat */
  52. {0, 1, 0, 0, 0, 0}, /* PA31 FCC1_TXENB SLAVE */
  53. {0, 1, 0, 1, 0, 0}, /* PA30 FCC1_TXCLAV SLAVE */
  54. {0, 1, 0, 1, 0, 0}, /* PA29 FCC1_TXSOC */
  55. {0, 1, 0, 0, 0, 0}, /* PA28 FCC1_RXENB SLAVE */
  56. {0, 1, 0, 0, 0, 0}, /* PA27 FCC1_RXSOC */
  57. {0, 1, 0, 1, 0, 0}, /* PA26 FCC1_RXCLAV SLAVE */
  58. {0, 1, 0, 1, 0, 1}, /* PA25 FCC1_TXD0 */
  59. {0, 1, 0, 1, 0, 1}, /* PA24 FCC1_TXD1 */
  60. {0, 1, 0, 1, 0, 1}, /* PA23 FCC1_TXD2 */
  61. {0, 1, 0, 1, 0, 1}, /* PA22 FCC1_TXD3 */
  62. {0, 1, 0, 1, 0, 1}, /* PA21 FCC1_TXD4 */
  63. {0, 1, 0, 1, 0, 1}, /* PA20 FCC1_TXD5 */
  64. {0, 1, 0, 1, 0, 1}, /* PA19 FCC1_TXD6 */
  65. {0, 1, 0, 1, 0, 1}, /* PA18 FCC1_TXD7 */
  66. {0, 1, 0, 0, 0, 0}, /* PA17 FCC1_RXD7 */
  67. {0, 1, 0, 0, 0, 0}, /* PA16 FCC1_RXD6 */
  68. {0, 1, 0, 0, 0, 0}, /* PA15 FCC1_RXD5 */
  69. {0, 1, 0, 0, 0, 0}, /* PA14 FCC1_RXD4 */
  70. {0, 1, 0, 0, 0, 0}, /* PA13 FCC1_RXD3 */
  71. {0, 1, 0, 0, 0, 0}, /* PA12 FCC1_RXD2 */
  72. {0, 1, 0, 0, 0, 0}, /* PA11 FCC1_RXD1 */
  73. {0, 1, 0, 0, 0, 0}, /* PA10 FCC1_RXD0 */
  74. {0, 1, 1, 1, 0, 1}, /* PA9 TDMA1_L1TXD */
  75. {0, 1, 1, 0, 0, 0}, /* PA8 TDMA1_L1RXD */
  76. {0, 0, 0, 0, 0, 0}, /* PA7 CONFIG0 */
  77. {0, 1, 1, 0, 0, 1}, /* PA6 TDMA1_L1RSYNC */
  78. {0, 0, 0, 1, 0, 0}, /* PA5 FCC2:RxAddr[2] */
  79. {0, 0, 0, 1, 0, 0}, /* PA4 FCC2:RxAddr[1] */
  80. {0, 0, 0, 1, 0, 0}, /* PA3 FCC2:RxAddr[0] */
  81. {0, 0, 0, 1, 0, 0}, /* PA2 FCC2:TxAddr[0] */
  82. {0, 0, 0, 1, 0, 0}, /* PA1 FCC2:TxAddr[1] */
  83. {0, 0, 0, 1, 0, 0} /* PA0 FCC2:TxAddr[2] */
  84. },
  85. /* Port B configuration */
  86. { /* conf ppar psor pdir podr pdat */
  87. {0, 0, 0, 1, 0, 0}, /* PB31 FCC2_RXSOC */
  88. {0, 0, 0, 1, 0, 0}, /* PB30 FCC2_TXSOC */
  89. {0, 0, 0, 1, 0, 0}, /* PB29 FCC2_RXCLAV */
  90. {0, 0, 0, 0, 0, 0}, /* PB28 CONFIG2 */
  91. {0, 1, 1, 0, 0, 1}, /* PB27 FCC2_TXD0 */
  92. {0, 1, 1, 0, 0, 0}, /* PB26 FCC2_TXD1 */
  93. {0, 0, 0, 1, 0, 0}, /* PB25 FCC2_TXD4 */
  94. {0, 1, 1, 0, 0, 1}, /* PB24 FCC2_TXD5 */
  95. {0, 0, 0, 1, 0, 0}, /* PB23 FCC2_TXD6 */
  96. {0, 1, 0, 1, 0, 1}, /* PB22 FCC2_TXD7 */
  97. {0, 1, 0, 0, 0, 0}, /* PB21 FCC2_RXD7 */
  98. {0, 1, 0, 0, 0, 0}, /* PB20 FCC2_RXD6 */
  99. {0, 1, 0, 0, 0, 0}, /* PB19 FCC2_RXD5 */
  100. {0, 0, 0, 1, 0, 0}, /* PB18 FCC2_RXD4 */
  101. {1, 1, 0, 0, 0, 0}, /* PB17 FCC3_RX_DV */
  102. {1, 1, 0, 0, 0, 0}, /* PB16 FCC3_RX_ER */
  103. {1, 1, 0, 1, 0, 0}, /* PB15 FCC3_TX_ER */
  104. {1, 1, 0, 1, 0, 0}, /* PB14 FCC3_TX_EN */
  105. {1, 1, 0, 0, 0, 0}, /* PB13 FCC3_COL */
  106. {1, 1, 0, 0, 0, 0}, /* PB12 FCC3_CRS */
  107. {1, 1, 0, 0, 0, 0}, /* PB11 FCC3_RXD3 */
  108. {1, 1, 0, 0, 0, 0}, /* PB10 FCC3_RXD2 */
  109. {1, 1, 0, 0, 0, 0}, /* PB9 FCC3_RXD1 */
  110. {1, 1, 0, 0, 0, 0}, /* PB8 FCC3_RXD0 */
  111. {1, 1, 0, 1, 0, 1}, /* PB7 FCC3_TXD0 */
  112. {1, 1, 0, 1, 0, 1}, /* PB6 FCC3_TXD1 */
  113. {1, 1, 0, 1, 0, 1}, /* PB5 FCC3_TXD2 */
  114. {1, 1, 0, 1, 0, 1}, /* PB4 FCC3_TXD3 */
  115. {0, 0, 0, 0, 0, 0}, /* PB3 */
  116. {0, 0, 0, 0, 0, 0}, /* PB2 */
  117. {0, 0, 0, 0, 0, 0}, /* PB1 */
  118. {0, 0, 0, 0, 0, 0}, /* PB0 */
  119. },
  120. /* Port C configuration */
  121. { /* conf ppar psor pdir podr pdat */
  122. {0, 1, 0, 0, 0, 1}, /* PC31 CLK1 */
  123. {0, 0, 0, 1, 0, 0}, /* PC30 U1MASTER_N */
  124. {0, 1, 0, 0, 0, 1}, /* PC29 CLK3 */
  125. {0, 0, 0, 1, 0, 1}, /* PC28 -MT90220_RST */
  126. {0, 1, 0, 0, 0, 1}, /* PC27 CLK5 */
  127. {0, 0, 0, 1, 0, 1}, /* PC26 -QUADFALC_RST */
  128. {0, 1, 1, 1, 0, 1}, /* PC25 BRG4 */
  129. {1, 0, 0, 1, 0, 0}, /* PC24 MDIO */
  130. {1, 0, 0, 1, 0, 0}, /* PC23 MDC */
  131. {0, 1, 0, 0, 0, 1}, /* PC22 CLK10 */
  132. {0, 0, 0, 1, 0, 0}, /* PC21 */
  133. {0, 1, 0, 0, 0, 1}, /* PC20 CLK12 */
  134. {0, 1, 0, 0, 0, 1}, /* PC19 CLK13 */
  135. {1, 1, 0, 0, 0, 1}, /* PC18 CLK14 */
  136. {0, 1, 0, 0, 0, 0}, /* PC17 CLK15 */
  137. {1, 1, 0, 0, 0, 1}, /* PC16 CLK16 */
  138. {0, 1, 1, 0, 0, 0}, /* PC15 FCC1_TXADDR0 SLAVE */
  139. {0, 1, 1, 0, 0, 0}, /* PC14 FCC1_RXADDR0 SLAVE */
  140. {0, 1, 1, 0, 0, 0}, /* PC13 FCC1_TXADDR1 SLAVE */
  141. {0, 1, 1, 0, 0, 0}, /* PC12 FCC1_RXADDR1 SLAVE */
  142. {0, 0, 0, 1, 0, 0}, /* PC11 FCC2_RXD2 */
  143. {0, 0, 0, 1, 0, 0}, /* PC10 FCC2_RXD3 */
  144. {0, 0, 0, 1, 0, 1}, /* PC9 LTMODE */
  145. {0, 0, 0, 1, 0, 1}, /* PC8 SELSYNC */
  146. {0, 1, 1, 0, 0, 0}, /* PC7 FCC1_TXADDR2 SLAVE */
  147. {0, 1, 1, 0, 0, 0}, /* PC6 FCC1_RXADDR2 SLAVE */
  148. {0, 0, 0, 1, 0, 0}, /* PC5 FCC2_TXCLAV MASTER */
  149. {0, 0, 0, 1, 0, 0}, /* PC4 FCC2_RXENB MASTER */
  150. {0, 0, 0, 1, 0, 0}, /* PC3 FCC2_TXD2 */
  151. {0, 0, 0, 1, 0, 0}, /* PC2 FCC2_TXD3 */
  152. {0, 0, 0, 0, 0, 1}, /* PC1 PTMC -PTEENB */
  153. {0, 0, 0, 1, 0, 1}, /* PC0 COMCLK_N */
  154. },
  155. /* Port D configuration */
  156. { /* conf ppar psor pdir podr pdat */
  157. {0, 0, 0, 1, 0, 1}, /* PD31 -CAM_RST */
  158. {0, 0, 0, 1, 0, 0}, /* PD30 FCC2_TXENB */
  159. {0, 1, 1, 0, 0, 0}, /* PD29 FCC1_RXADDR3 SLAVE */
  160. {0, 1, 1, 0, 0, 1}, /* PD28 TDMC1_L1TXD */
  161. {0, 1, 1, 0, 0, 0}, /* PD27 TDMC1_L1RXD */
  162. {0, 1, 1, 0, 0, 1}, /* PD26 TDMC1_L1RSYNC */
  163. {0, 0, 0, 1, 0, 1}, /* PD25 LED0 -OFF */
  164. {0, 0, 0, 1, 0, 1}, /* PD24 LED5 -OFF */
  165. {1, 0, 0, 1, 0, 1}, /* PD23 -LXT971_RST */
  166. {0, 1, 1, 0, 0, 1}, /* PD22 TDMA2_L1TXD */
  167. {0, 1, 1, 0, 0, 0}, /* PD21 TDMA2_L1RXD */
  168. {0, 1, 1, 0, 0, 1}, /* PD20 TDMA2_L1RSYNC */
  169. {0, 0, 0, 1, 0, 0}, /* PD19 FCC2_TXADDR3 */
  170. {0, 0, 0, 1, 0, 0}, /* PD18 FCC2_RXADDR3 */
  171. {0, 1, 0, 1, 0, 0}, /* PD17 BRG2 */
  172. {0, 0, 0, 1, 0, 0}, /* PD16 */
  173. {0, 0, 0, 1, 0, 0}, /* PD15 PT2TO1 */
  174. {0, 0, 0, 1, 0, 1}, /* PD14 PT4TO3 */
  175. {0, 0, 0, 1, 0, 1}, /* PD13 -SWMODE */
  176. {0, 0, 0, 1, 0, 1}, /* PD12 -PTMODE */
  177. {0, 0, 0, 1, 0, 0}, /* PD11 FCC2_RXD0 */
  178. {0, 0, 0, 1, 0, 0}, /* PD10 FCC2_RXD1 */
  179. {1, 1, 0, 1, 0, 1}, /* PD9 SMC1_SMTXD */
  180. {1, 1, 0, 0, 0, 1}, /* PD8 SMC1_SMRXD */
  181. {0, 1, 1, 0, 0, 0}, /* PD7 FCC1_TXADDR3 SLAVE */
  182. {0, 0, 0, 1, 0, 0}, /* PD6 IMAMODE */
  183. {0, 0, 0, 0, 0, 0}, /* PD5 CONFIG2 */
  184. {0, 1, 0, 1, 0, 0}, /* PD4 BRG8 */
  185. {0, 0, 0, 0, 0, 0}, /* PD3 */
  186. {0, 0, 0, 0, 0, 0}, /* PD2 */
  187. {0, 0, 0, 0, 0, 0}, /* PD1 */
  188. {0, 0, 0, 0, 0, 0}, /* PD0 */
  189. }
  190. };
  191. long int initdram (int board_type)
  192. {
  193. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  194. volatile memctl8260_t *memctl = &immap->im_memctl;
  195. volatile uchar *base;
  196. volatile ulong *addr, cnt, val;
  197. ulong save[32]; /* to make test non-destructive */
  198. int i, maxsize;
  199. memctl->memc_psrt = CFG_PSRT;
  200. memctl->memc_mptpr = CFG_MPTPR;
  201. #ifndef CFG_RAMBOOT
  202. immap->im_siu_conf.sc_ppc_acr = 0x00000026;
  203. immap->im_siu_conf.sc_ppc_alrh = 0x01276345;
  204. immap->im_siu_conf.sc_ppc_alrl = 0x89ABCDEF;
  205. immap->im_siu_conf.sc_lcl_acr = 0x00000000;
  206. immap->im_siu_conf.sc_lcl_alrh = 0x01234567;
  207. immap->im_siu_conf.sc_lcl_alrl = 0x89ABCDEF;
  208. immap->im_siu_conf.sc_tescr1 = 0x00004000;
  209. immap->im_siu_conf.sc_ltescr1 = 0x00004000;
  210. /* Init Main SDRAM */
  211. #define OP_VALUE 0x404A241A
  212. #define OP_VALUE_M (OP_VALUE & 0x87FFFFFF);
  213. base = (uchar *) CFG_SDRAM_BASE;
  214. memctl->memc_psdmr = 0x28000000 | OP_VALUE_M;
  215. *base = 0xFF;
  216. memctl->memc_psdmr = 0x08000000 | OP_VALUE_M;
  217. for (i = 0; i < 8; i++)
  218. *base = 0xFF;
  219. memctl->memc_psdmr = 0x18000000 | OP_VALUE_M;
  220. *(base + 0x110) = 0xFF;
  221. memctl->memc_psdmr = OP_VALUE;
  222. memctl->memc_lsdmr = 0x4086A522;
  223. *base = 0xFF;
  224. /* We must be able to test a location outsize the maximum legal size
  225. * to find out THAT we are outside; but this address still has to be
  226. * mapped by the controller. That means, that the initial mapping has
  227. * to be (at least) twice as large as the maximum expected size.
  228. */
  229. maxsize = (1 + (~memctl->memc_or1 | 0x7fff)) / 2;
  230. /*
  231. * Check memory range for valid RAM. A simple memory test determines
  232. * the actually available RAM size between addresses `base' and
  233. * `base + maxsize'. Some (not all) hardware errors are detected:
  234. * - short between address lines
  235. * - short between data lines
  236. */
  237. i = 0;
  238. for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
  239. addr = (volatile ulong *) base + cnt; /* pointer arith! */
  240. save[i++] = *addr;
  241. *addr = ~cnt;
  242. }
  243. addr = (volatile ulong *) base;
  244. save[i] = *addr;
  245. *addr = 0;
  246. if ((val = *addr) != 0) {
  247. *addr = save[i];
  248. return (0);
  249. }
  250. for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
  251. addr = (volatile ulong *) base + cnt; /* pointer arith! */
  252. val = *addr;
  253. *addr = save[--i];
  254. if (val != ~cnt) {
  255. /* Write the actual size to ORx
  256. */
  257. memctl->memc_or1 |= ~(cnt * sizeof (long) - 1);
  258. maxsize = cnt * sizeof (long) / 2;
  259. break;
  260. }
  261. }
  262. maxsize *= 2;
  263. if (maxsize != hwc_main_sdram_size ())
  264. printf ("Oops: memory test has not found all memory!\n");
  265. #endif
  266. icache_enable ();
  267. /* return total ram size of SDRAM */
  268. return (maxsize);
  269. }
  270. int checkboard (void)
  271. {
  272. char string[32];
  273. hwc_manufact_date (string);
  274. printf ("Board: Interphase 4539 (#%d %s)\n",
  275. hwc_serial_number (),
  276. string);
  277. #ifdef DEBUG
  278. printf ("Manufacturing date: %s\n", string);
  279. printf ("Serial number : %d\n", hwc_serial_number ());
  280. printf ("FLASH size : %d MB\n", hwc_flash_size () >> 20);
  281. printf ("Main SDRAM size : %d MB\n", hwc_main_sdram_size () >> 20);
  282. printf ("Local SDRAM size : %d MB\n", hwc_local_sdram_size () >> 20);
  283. hwc_mac_address (string);
  284. printf ("MAC address : %s\n", string);
  285. #endif
  286. return 0;
  287. }
  288. int misc_init_r (void)
  289. {
  290. char *s, str[32];
  291. int num;
  292. if ((s = getenv ("serial#")) == NULL &&
  293. (num = hwc_serial_number ()) != -1) {
  294. sprintf (str, "%06d", num);
  295. setenv ("serial#", str);
  296. }
  297. if ((s = getenv ("ethaddr")) == NULL && hwc_mac_address (str) == 0) {
  298. setenv ("ethaddr", str);
  299. }
  300. return (0);
  301. }
  302. /***************************************************************
  303. * We take some basic Hardware Configuration Parameter from the
  304. * Serial EEPROM conected to the PSpan bridge. We keep it as
  305. * simple as possible.
  306. */
  307. int hwc_flash_size (void)
  308. {
  309. uchar byte;
  310. if (!seeprom_read (0x40, &byte, sizeof (byte))) {
  311. switch ((byte >> 2) & 0x3) {
  312. case 0x1:
  313. return 0x0400000;
  314. break;
  315. case 0x2:
  316. return 0x0800000;
  317. break;
  318. case 0x3:
  319. return 0x1000000;
  320. default:
  321. return 0x0100000;
  322. }
  323. }
  324. return -1;
  325. }
  326. int hwc_local_sdram_size (void)
  327. {
  328. uchar byte;
  329. if (!seeprom_read (0x40, &byte, sizeof (byte))) {
  330. switch ((byte & 0x03)) {
  331. case 0x1:
  332. return 0x0800000;
  333. case 0x2:
  334. return 0x1000000;
  335. default:
  336. return 0; /* not present */
  337. }
  338. }
  339. return -1;
  340. }
  341. int hwc_main_sdram_size (void)
  342. {
  343. uchar byte;
  344. if (!seeprom_read (0x41, &byte, sizeof (byte))) {
  345. return 0x1000000 << ((byte >> 5) & 0x7);
  346. }
  347. return -1;
  348. }
  349. int hwc_serial_number (void)
  350. {
  351. int sn = -1;
  352. if (!seeprom_read (0xa0, (char *) &sn, sizeof (sn))) {
  353. sn = cpu_to_le32 (sn);
  354. }
  355. return sn;
  356. }
  357. int hwc_mac_address (char *str)
  358. {
  359. char mac[6];
  360. if (!seeprom_read (0xb0, mac, sizeof (mac))) {
  361. sprintf (str, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  362. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  363. } else {
  364. strcpy (str, "ERROR");
  365. return -1;
  366. }
  367. return 0;
  368. }
  369. int hwc_manufact_date (char *str)
  370. {
  371. uchar byte;
  372. int value;
  373. if (seeprom_read (0x92, &byte, sizeof (byte)))
  374. goto out;
  375. value = byte;
  376. if (seeprom_read (0x93, &byte, sizeof (byte)))
  377. goto out;
  378. value += byte << 8;
  379. sprintf (str, "%02d/%02d/%04d",
  380. value & 0x1F, (value >> 5) & 0xF,
  381. 1980 + ((value >> 9) & 0x1FF));
  382. return 0;
  383. out:
  384. strcpy (str, "ERROR");
  385. return -1;
  386. }
  387. #define PSPAN_ADDR 0xF0020000
  388. #define EEPROM_REG 0x408
  389. #define EEPROM_READ_CMD 0xA000
  390. #define PSPAN_WRITE(a,v) \
  391. *((volatile unsigned long *)(PSPAN_ADDR+(a))) = v; eieio()
  392. #define PSPAN_READ(a) \
  393. *((volatile unsigned long *)(PSPAN_ADDR+(a)))
  394. int seeprom_read (int addr, uchar * data, int size)
  395. {
  396. ulong val, cmd;
  397. int i;
  398. for (i = 0; i < size; i++) {
  399. cmd = EEPROM_READ_CMD;
  400. cmd |= ((addr + i) << 24) & 0xff000000;
  401. /* Wait for ACT to authorize write */
  402. while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
  403. eieio ();
  404. /* Write command */
  405. PSPAN_WRITE (EEPROM_REG, cmd);
  406. /* Wait for data to be valid */
  407. while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
  408. eieio ();
  409. /* Do it twice, first read might be erratic */
  410. while ((val = PSPAN_READ (EEPROM_REG)) & 0x80)
  411. eieio ();
  412. /* Read error */
  413. if (val & 0x00000040) {
  414. return -1;
  415. } else {
  416. data[i] = (val >> 16) & 0xff;
  417. }
  418. }
  419. return 0;
  420. }