cpci405.c 18 KB

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