cpci405.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /*
  2. * (C) Copyright 2001-2003
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
  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 <asm/processor.h>
  25. #include <command.h>
  26. #include <malloc.h>
  27. #include <net.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); /*cmd_boot.c*/
  30. #if 0
  31. #define FPGA_DEBUG
  32. #endif
  33. /* fpga configuration data - generated by bin2cc */
  34. const unsigned char fpgadata[] =
  35. {
  36. #ifdef CONFIG_CPCI405_VER2
  37. # ifdef CONFIG_CPCI405AB
  38. # include "fpgadata_cpci405ab.c"
  39. # else
  40. # include "fpgadata_cpci4052.c"
  41. # endif
  42. #else
  43. # include "fpgadata_cpci405.c"
  44. #endif
  45. };
  46. /*
  47. * include common fpga code (for esd boards)
  48. */
  49. #include "../common/fpga.c"
  50. #include "../common/auto_update.h"
  51. #ifdef CONFIG_CPCI405AB
  52. au_image_t au_image[] = {
  53. {"cpci405ab/preinst.img", 0, -1, AU_SCRIPT},
  54. {"cpci405ab/pImage", 0xffc00000, 0x000c0000, AU_NOR},
  55. {"cpci405ab/pImage.initrd", 0xffcc0000, 0x00300000, AU_NOR},
  56. {"cpci405ab/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE},
  57. {"cpci405ab/postinst.img", 0, 0, AU_SCRIPT},
  58. };
  59. #else
  60. #ifdef CONFIG_CPCI405_VER2
  61. au_image_t au_image[] = {
  62. {"cpci4052/preinst.img", 0, -1, AU_SCRIPT},
  63. {"cpci4052/pImage", 0xffc00000, 0x000c0000, AU_NOR},
  64. {"cpci4052/pImage.initrd", 0xffcc0000, 0x00300000, AU_NOR},
  65. {"cpci4052/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE},
  66. {"cpci4052/postinst.img", 0, 0, AU_SCRIPT},
  67. };
  68. #else
  69. au_image_t au_image[] = {
  70. {"cpci405/preinst.img", 0, -1, AU_SCRIPT},
  71. {"cpci405/pImage", 0xffc00000, 0x000c0000, AU_NOR},
  72. {"cpci405/pImage.initrd", 0xffcc0000, 0x00310000, AU_NOR},
  73. {"cpci405/u-boot.img", 0xfffd0000, 0x00030000, AU_FIRMWARE},
  74. {"cpci405/postinst.img", 0, 0, AU_SCRIPT},
  75. };
  76. #endif
  77. #endif
  78. int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0]));
  79. /* Prototypes */
  80. int cpci405_version(void);
  81. int gunzip(void *, int, unsigned char *, unsigned long *);
  82. void lxt971_no_sleep(void);
  83. int board_early_init_f (void)
  84. {
  85. #ifndef CONFIG_CPCI405_VER2
  86. int index, len, i;
  87. int status;
  88. #endif
  89. #ifdef FPGA_DEBUG
  90. /* set up serial port with default baudrate */
  91. (void) get_clocks ();
  92. gd->baudrate = CONFIG_BAUDRATE;
  93. serial_init ();
  94. console_init_f();
  95. #endif
  96. /*
  97. * First pull fpga-prg pin low, to disable fpga logic (on version 2 board)
  98. */
  99. out32(GPIO0_ODR, 0x00000000); /* no open drain pins */
  100. out32(GPIO0_TCR, CFG_FPGA_PRG); /* setup for output */
  101. out32(GPIO0_OR, CFG_FPGA_PRG); /* set output pins to high */
  102. out32(GPIO0_OR, 0); /* pull prg low */
  103. /*
  104. * Boot onboard FPGA
  105. */
  106. #ifndef CONFIG_CPCI405_VER2
  107. if (cpci405_version() == 1) {
  108. status = fpga_boot((unsigned char *)fpgadata, sizeof(fpgadata));
  109. if (status != 0) {
  110. /* booting FPGA failed */
  111. #ifndef FPGA_DEBUG
  112. /* set up serial port with default baudrate */
  113. (void) get_clocks ();
  114. gd->baudrate = CONFIG_BAUDRATE;
  115. serial_init ();
  116. console_init_f();
  117. #endif
  118. printf("\nFPGA: Booting failed ");
  119. switch (status) {
  120. case ERROR_FPGA_PRG_INIT_LOW:
  121. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  122. break;
  123. case ERROR_FPGA_PRG_INIT_HIGH:
  124. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  125. break;
  126. case ERROR_FPGA_PRG_DONE:
  127. printf("(Timeout: DONE not high after programming FPGA)\n ");
  128. break;
  129. }
  130. /* display infos on fpgaimage */
  131. index = 15;
  132. for (i=0; i<4; i++) {
  133. len = fpgadata[index];
  134. printf("FPGA: %s\n", &(fpgadata[index+1]));
  135. index += len+3;
  136. }
  137. putc ('\n');
  138. /* delayed reboot */
  139. for (i=20; i>0; i--) {
  140. printf("Rebooting in %2d seconds \r",i);
  141. for (index=0;index<1000;index++)
  142. udelay(1000);
  143. }
  144. putc ('\n');
  145. do_reset(NULL, 0, 0, NULL);
  146. }
  147. }
  148. #endif /* !CONFIG_CPCI405_VER2 */
  149. /*
  150. * IRQ 0-15 405GP internally generated; active high; level sensitive
  151. * IRQ 16 405GP internally generated; active low; level sensitive
  152. * IRQ 17-24 RESERVED
  153. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  154. * IRQ 26 (EXT IRQ 1) CAN1 (+FPGA on CPCI4052) ; active low; level sensitive
  155. * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive
  156. * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive
  157. * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
  158. * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive
  159. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  160. */
  161. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  162. mtdcr(uicer, 0x00000000); /* disable all ints */
  163. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  164. if (cpci405_version() == 3) {
  165. mtdcr(uicpr, 0xFFFFFF99); /* set int polarities */
  166. } else {
  167. mtdcr(uicpr, 0xFFFFFF81); /* set int polarities */
  168. }
  169. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  170. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  171. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  172. return 0;
  173. }
  174. /* ------------------------------------------------------------------------- */
  175. int ctermm2(void)
  176. {
  177. #ifdef CONFIG_CPCI405_VER2
  178. return 0; /* no, board is cpci405 */
  179. #else
  180. if ((*(unsigned char *)0xf0000400 == 0x00) &&
  181. (*(unsigned char *)0xf0000401 == 0x01))
  182. return 0; /* no, board is cpci405 */
  183. else
  184. return -1; /* yes, board is cterm-m2 */
  185. #endif
  186. }
  187. int cpci405_host(void)
  188. {
  189. if (mfdcr(strap) & PSR_PCI_ARBIT_EN)
  190. return -1; /* yes, board is cpci405 host */
  191. else
  192. return 0; /* no, board is cpci405 adapter */
  193. }
  194. int cpci405_version(void)
  195. {
  196. unsigned long cntrl0Reg;
  197. unsigned long value;
  198. /*
  199. * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO)
  200. */
  201. cntrl0Reg = mfdcr(cntrl0);
  202. mtdcr(cntrl0, cntrl0Reg | 0x03000000);
  203. out32(GPIO0_ODR, in32(GPIO0_ODR) & ~0x00180000);
  204. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~0x00180000);
  205. udelay(1000); /* wait some time before reading input */
  206. value = in32(GPIO0_IR) & 0x00180000; /* get config bits */
  207. /*
  208. * Restore GPIO settings
  209. */
  210. mtdcr(cntrl0, cntrl0Reg);
  211. switch (value) {
  212. case 0x00180000:
  213. /* CS2==1 && CS3==1 -> version 1 */
  214. return 1;
  215. case 0x00080000:
  216. /* CS2==0 && CS3==1 -> version 2 */
  217. return 2;
  218. case 0x00100000:
  219. /* CS2==1 && CS3==0 -> version 3 */
  220. return 3;
  221. case 0x00000000:
  222. /* CS2==0 && CS3==0 -> version 4 */
  223. return 4;
  224. default:
  225. /* should not be reached! */
  226. return 2;
  227. }
  228. }
  229. int misc_init_f (void)
  230. {
  231. return 0; /* dummy implementation */
  232. }
  233. int misc_init_r (void)
  234. {
  235. unsigned long cntrl0Reg;
  236. /* adjust flash start and offset */
  237. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  238. gd->bd->bi_flashoffset = 0;
  239. #ifdef CONFIG_CPCI405_VER2
  240. {
  241. unsigned char *dst;
  242. ulong len = sizeof(fpgadata);
  243. int status;
  244. int index;
  245. int i;
  246. /*
  247. * On CPCI-405 version 2 the environment is saved in eeprom!
  248. * FPGA can be gzip compressed (malloc) and booted this late.
  249. */
  250. if (cpci405_version() >= 2) {
  251. /*
  252. * Setup GPIO pins (CS6+CS7 as GPIO)
  253. */
  254. cntrl0Reg = mfdcr(cntrl0);
  255. mtdcr(cntrl0, cntrl0Reg | 0x00300000);
  256. dst = malloc(CFG_FPGA_MAX_SIZE);
  257. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  258. printf ("GUNZIP ERROR - must RESET board to recover\n");
  259. do_reset (NULL, 0, 0, NULL);
  260. }
  261. status = fpga_boot(dst, len);
  262. if (status != 0) {
  263. printf("\nFPGA: Booting failed ");
  264. switch (status) {
  265. case ERROR_FPGA_PRG_INIT_LOW:
  266. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  267. break;
  268. case ERROR_FPGA_PRG_INIT_HIGH:
  269. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  270. break;
  271. case ERROR_FPGA_PRG_DONE:
  272. printf("(Timeout: DONE not high after programming FPGA)\n ");
  273. break;
  274. }
  275. /* display infos on fpgaimage */
  276. index = 15;
  277. for (i=0; i<4; i++) {
  278. len = dst[index];
  279. printf("FPGA: %s\n", &(dst[index+1]));
  280. index += len+3;
  281. }
  282. putc ('\n');
  283. /* delayed reboot */
  284. for (i=20; i>0; i--) {
  285. printf("Rebooting in %2d seconds \r",i);
  286. for (index=0;index<1000;index++)
  287. udelay(1000);
  288. }
  289. putc ('\n');
  290. do_reset(NULL, 0, 0, NULL);
  291. }
  292. /* restore gpio/cs settings */
  293. mtdcr(cntrl0, cntrl0Reg);
  294. puts("FPGA: ");
  295. /* display infos on fpgaimage */
  296. index = 15;
  297. for (i=0; i<4; i++) {
  298. len = dst[index];
  299. printf("%s ", &(dst[index+1]));
  300. index += len+3;
  301. }
  302. putc ('\n');
  303. free(dst);
  304. /*
  305. * Reset FPGA via FPGA_DATA pin
  306. */
  307. SET_FPGA(FPGA_PRG | FPGA_CLK);
  308. udelay(1000); /* wait 1ms */
  309. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  310. udelay(1000); /* wait 1ms */
  311. if (cpci405_version() == 3) {
  312. volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR;
  313. volatile unsigned char *leds = (unsigned char *)CFG_LED_ADDR;
  314. /*
  315. * Enable outputs in fpga on version 3 board
  316. */
  317. *fpga_mode |= CFG_FPGA_MODE_ENABLE_OUTPUT;
  318. /*
  319. * Set outputs to 0
  320. */
  321. *leds = 0x00;
  322. /*
  323. * Reset external DUART
  324. */
  325. *fpga_mode |= CFG_FPGA_MODE_DUART_RESET;
  326. udelay(100);
  327. *fpga_mode &= ~(CFG_FPGA_MODE_DUART_RESET);
  328. }
  329. }
  330. else {
  331. puts("\n*** U-Boot Version does not match Board Version!\n");
  332. puts("*** CPCI-405 Version 1.x detected!\n");
  333. puts("*** Please use correct U-Boot version (CPCI405 instead of CPCI4052)!\n\n");
  334. }
  335. }
  336. #else /* CONFIG_CPCI405_VER2 */
  337. #if 0 /* test-only: code-plug now not relavant for ip-address any more */
  338. /*
  339. * Generate last byte of ip-addr from code-plug @ 0xf0000400
  340. */
  341. if (ctermm2()) {
  342. char str[32];
  343. unsigned char ipbyte = *(unsigned char *)0xf0000400;
  344. /*
  345. * Only overwrite ip-addr with allowed values
  346. */
  347. if ((ipbyte != 0x00) && (ipbyte != 0xff)) {
  348. bd->bi_ip_addr = (bd->bi_ip_addr & 0xffffff00) | ipbyte;
  349. sprintf(str, "%ld.%ld.%ld.%ld",
  350. (bd->bi_ip_addr & 0xff000000) >> 24,
  351. (bd->bi_ip_addr & 0x00ff0000) >> 16,
  352. (bd->bi_ip_addr & 0x0000ff00) >> 8,
  353. (bd->bi_ip_addr & 0x000000ff));
  354. setenv("ipaddr", str);
  355. }
  356. }
  357. #endif
  358. if (cpci405_version() >= 2) {
  359. puts("\n*** U-Boot Version does not match Board Version!\n");
  360. puts("*** CPCI-405 Board Version 2.x detected!\n");
  361. puts("*** Please use correct U-Boot version (CPCI4052 instead of CPCI405)!\n\n");
  362. }
  363. #endif /* CONFIG_CPCI405_VER2 */
  364. /*
  365. * Select cts (and not dsr) on uart1
  366. */
  367. cntrl0Reg = mfdcr(cntrl0);
  368. mtdcr(cntrl0, cntrl0Reg | 0x00001000);
  369. return (0);
  370. }
  371. /*
  372. * Check Board Identity:
  373. */
  374. int checkboard (void)
  375. {
  376. #ifndef CONFIG_CPCI405_VER2
  377. int index;
  378. int len;
  379. #endif
  380. char str[64];
  381. int i = getenv_r ("serial#", str, sizeof(str));
  382. unsigned short ver;
  383. puts ("Board: ");
  384. if (i == -1) {
  385. puts ("### No HW ID - assuming CPCI405");
  386. } else {
  387. puts(str);
  388. }
  389. ver = cpci405_version();
  390. printf(" (Ver %d.x, ", ver);
  391. #if 0 /* test-only */
  392. if (ver >= 2) {
  393. volatile u16 *fpga_status = (u16 *)CFG_FPGA_BASE_ADDR + 1;
  394. if (*fpga_status & CFG_FPGA_STATUS_FLASH) {
  395. puts ("FLASH Bank B, ");
  396. } else {
  397. puts ("FLASH Bank A, ");
  398. }
  399. }
  400. #endif
  401. if (ctermm2()) {
  402. char str[4];
  403. /*
  404. * Read board-id and save in env-variable
  405. */
  406. sprintf(str, "%d", *(unsigned char *)0xf0000400);
  407. setenv("boardid", str);
  408. printf("CTERM-M2 - Id=%s)", str);
  409. } else {
  410. if (cpci405_host()) {
  411. puts ("PCI Host Version)");
  412. } else {
  413. puts ("PCI Adapter Version)");
  414. }
  415. }
  416. #ifndef CONFIG_CPCI405_VER2
  417. puts ("\nFPGA: ");
  418. /* display infos on fpgaimage */
  419. index = 15;
  420. for (i=0; i<4; i++) {
  421. len = fpgadata[index];
  422. printf("%s ", &(fpgadata[index+1]));
  423. index += len+3;
  424. }
  425. #endif
  426. putc ('\n');
  427. /*
  428. * Disable sleep mode in LXT971
  429. */
  430. lxt971_no_sleep();
  431. return 0;
  432. }
  433. /* ------------------------------------------------------------------------- */
  434. long int initdram (int board_type)
  435. {
  436. unsigned long val;
  437. mtdcr(memcfga, mem_mb0cf);
  438. val = mfdcr(memcfgd);
  439. #if 0
  440. printf("\nmb0cf=%x\n", val); /* test-only */
  441. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  442. #endif
  443. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  444. }
  445. /* ------------------------------------------------------------------------- */
  446. int testdram (void)
  447. {
  448. /* TODO: XXX XXX XXX */
  449. printf ("test: 16 MB - ok\n");
  450. return (0);
  451. }
  452. /* ------------------------------------------------------------------------- */
  453. #ifdef CONFIG_CPCI405_VER2
  454. #ifdef CONFIG_IDE_RESET
  455. void ide_set_reset(int on)
  456. {
  457. volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR;
  458. /*
  459. * Assert or deassert CompactFlash Reset Pin
  460. */
  461. if (on) { /* assert RESET */
  462. *fpga_mode &= ~(CFG_FPGA_MODE_CF_RESET);
  463. } else { /* release RESET */
  464. *fpga_mode |= CFG_FPGA_MODE_CF_RESET;
  465. }
  466. }
  467. #endif /* CONFIG_IDE_RESET */
  468. #endif /* CONFIG_CPCI405_VER2 */
  469. #ifdef CONFIG_CPCI405AB
  470. #define ONE_WIRE_CLEAR (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_MODE) \
  471. |= CFG_FPGA_MODE_1WIRE_DIR)
  472. #define ONE_WIRE_SET (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_MODE) \
  473. &= ~CFG_FPGA_MODE_1WIRE_DIR)
  474. #define ONE_WIRE_GET (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_STATUS) \
  475. & CFG_FPGA_MODE_1WIRE)
  476. /*
  477. * Generate a 1-wire reset, return 1 if no presence detect was found,
  478. * return 0 otherwise.
  479. * (NOTE: Does not handle alarm presence from DS2404/DS1994)
  480. */
  481. int OWTouchReset(void)
  482. {
  483. int result;
  484. ONE_WIRE_CLEAR;
  485. udelay(480);
  486. ONE_WIRE_SET;
  487. udelay(70);
  488. result = ONE_WIRE_GET;
  489. udelay(410);
  490. return result;
  491. }
  492. /*
  493. * Send 1 a 1-wire write bit.
  494. * Provide 10us recovery time.
  495. */
  496. void OWWriteBit(int bit)
  497. {
  498. if (bit) {
  499. /*
  500. * write '1' bit
  501. */
  502. ONE_WIRE_CLEAR;
  503. udelay(6);
  504. ONE_WIRE_SET;
  505. udelay(64);
  506. } else {
  507. /*
  508. * write '0' bit
  509. */
  510. ONE_WIRE_CLEAR;
  511. udelay(60);
  512. ONE_WIRE_SET;
  513. udelay(10);
  514. }
  515. }
  516. /*
  517. * Read a bit from the 1-wire bus and return it.
  518. * Provide 10us recovery time.
  519. */
  520. int OWReadBit(void)
  521. {
  522. int result;
  523. ONE_WIRE_CLEAR;
  524. udelay(6);
  525. ONE_WIRE_SET;
  526. udelay(9);
  527. result = ONE_WIRE_GET;
  528. udelay(55);
  529. return result;
  530. }
  531. void OWWriteByte(int data)
  532. {
  533. int loop;
  534. for (loop=0; loop<8; loop++) {
  535. OWWriteBit(data & 0x01);
  536. data >>= 1;
  537. }
  538. }
  539. int OWReadByte(void)
  540. {
  541. int loop, result = 0;
  542. for (loop=0; loop<8; loop++) {
  543. result >>= 1;
  544. if (OWReadBit()) {
  545. result |= 0x80;
  546. }
  547. }
  548. return result;
  549. }
  550. int do_onewire(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  551. {
  552. volatile unsigned short val;
  553. int result;
  554. int i;
  555. unsigned char ow_id[6];
  556. char str[32];
  557. unsigned char ow_crc;
  558. /*
  559. * Clear 1-wire bit (open drain with pull-up)
  560. */
  561. val = *(volatile unsigned short *)0xf0400000;
  562. val &= ~0x1000; /* clear 1-wire bit */
  563. *(volatile unsigned short *)0xf0400000 = val;
  564. result = OWTouchReset();
  565. if (result != 0) {
  566. puts("No 1-wire device detected!\n");
  567. }
  568. OWWriteByte(0x33); /* send read rom command */
  569. OWReadByte(); /* skip family code ( == 0x01) */
  570. for (i=0; i<6; i++) {
  571. ow_id[i] = OWReadByte();
  572. }
  573. ow_crc = OWReadByte(); /* read crc */
  574. sprintf(str, "%08X%04X", *(unsigned int *)&ow_id[0], *(unsigned short *)&ow_id[4]);
  575. printf("Setting environment variable 'ow_id' to %s\n", str);
  576. setenv("ow_id", str);
  577. return 0;
  578. }
  579. U_BOOT_CMD(
  580. onewire, 1, 1, do_onewire,
  581. "onewire - Read 1-write ID\n",
  582. NULL
  583. );
  584. #define CFG_I2C_EEPROM_ADDR_2 0x51 /* EEPROM CAT28WC32 */
  585. #define CFG_ENV_SIZE_2 0x800 /* 2048 bytes may be used for env vars*/
  586. /*
  587. * Write backplane ip-address...
  588. */
  589. int do_get_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  590. {
  591. bd_t *bd = gd->bd;
  592. char *buf;
  593. ulong crc;
  594. char str[32];
  595. char *ptr;
  596. IPaddr_t ipaddr;
  597. buf = malloc(CFG_ENV_SIZE_2);
  598. if (eeprom_read(CFG_I2C_EEPROM_ADDR_2, 0, (uchar *)buf, CFG_ENV_SIZE_2)) {
  599. puts("\nError reading backplane EEPROM!\n");
  600. } else {
  601. crc = crc32(0, (uchar *)(buf+4), CFG_ENV_SIZE_2-4);
  602. if (crc != *(ulong *)buf) {
  603. printf("ERROR: crc mismatch %08lx %08lx\n", crc, *(ulong *)buf);
  604. return -1;
  605. }
  606. /*
  607. * Find bp_ip
  608. */
  609. ptr = strstr(buf+4, "bp_ip=");
  610. if (ptr == NULL) {
  611. printf("ERROR: bp_ip not found!\n");
  612. return -1;
  613. }
  614. ptr += 6;
  615. ipaddr = string_to_ip(ptr);
  616. /*
  617. * Update whole ip-addr
  618. */
  619. bd->bi_ip_addr = ipaddr;
  620. sprintf(str, "%ld.%ld.%ld.%ld",
  621. (bd->bi_ip_addr & 0xff000000) >> 24,
  622. (bd->bi_ip_addr & 0x00ff0000) >> 16,
  623. (bd->bi_ip_addr & 0x0000ff00) >> 8,
  624. (bd->bi_ip_addr & 0x000000ff));
  625. setenv("ipaddr", str);
  626. printf("Updated ip_addr from bp_eeprom to %s!\n", str);
  627. }
  628. free(buf);
  629. return 0;
  630. }
  631. U_BOOT_CMD(
  632. getbpip, 1, 1, do_get_bpip,
  633. "getbpip - Update IP-Address with Backplane IP-Address\n",
  634. NULL
  635. );
  636. /*
  637. * Set and print backplane ip...
  638. */
  639. int do_set_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  640. {
  641. char *buf;
  642. char str[32];
  643. ulong crc;
  644. if (argc < 2) {
  645. puts("ERROR!\n");
  646. return -1;
  647. }
  648. printf("Setting bp_ip to %s\n", argv[1]);
  649. buf = malloc(CFG_ENV_SIZE_2);
  650. memset(buf, 0, CFG_ENV_SIZE_2);
  651. sprintf(str, "bp_ip=%s", argv[1]);
  652. strcpy(buf+4, str);
  653. crc = crc32(0, (uchar *)(buf+4), CFG_ENV_SIZE_2-4);
  654. *(ulong *)buf = crc;
  655. if (eeprom_write(CFG_I2C_EEPROM_ADDR_2, 0, (uchar *)buf, CFG_ENV_SIZE_2)) {
  656. puts("\nError writing backplane EEPROM!\n");
  657. }
  658. free(buf);
  659. return 0;
  660. }
  661. U_BOOT_CMD(
  662. setbpip, 2, 1, do_set_bpip,
  663. "setbpip - Write Backplane IP-Address\n",
  664. NULL
  665. );
  666. #endif /* CONFIG_CPCI405AB */