cmd_pmc440.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Matthias Fuchs, esd Gmbh, matthias.fuchs@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. */
  24. #include <common.h>
  25. #include <command.h>
  26. #include <asm/io.h>
  27. #include <asm/cache.h>
  28. #include <asm/processor.h>
  29. #if defined(CONFIG_LOGBUFFER)
  30. #include <logbuff.h>
  31. #endif
  32. #include "pmc440.h"
  33. int is_monarch(void);
  34. int bootstrap_eeprom_write(unsigned dev_addr, unsigned offset,
  35. uchar *buffer, unsigned cnt);
  36. int eeprom_write_enable(unsigned dev_addr, int state);
  37. DECLARE_GLOBAL_DATA_PTR;
  38. #if defined(CONFIG_CMD_BSP)
  39. static int got_fifoirq;
  40. static int got_hcirq;
  41. int fpga_interrupt(u32 arg)
  42. {
  43. pmc440_fpga_t *fpga = (pmc440_fpga_t *)arg;
  44. int rc = -1; /* not for us */
  45. u32 status = FPGA_IN32(&fpga->status);
  46. /* check for interrupt from fifo module */
  47. if (status & STATUS_FIFO_ISF) {
  48. /* disable this int source */
  49. FPGA_OUT32(&fpga->hostctrl, HOSTCTRL_FIFOIE_GATE);
  50. rc = 0;
  51. got_fifoirq = 1; /* trigger backend */
  52. }
  53. if (status & STATUS_HOST_ISF) {
  54. FPGA_OUT32(&fpga->hostctrl, HOSTCTRL_HCINT_GATE);
  55. rc = 0;
  56. got_hcirq = 1;
  57. }
  58. return rc;
  59. }
  60. int do_waithci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  61. {
  62. pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
  63. got_hcirq = 0;
  64. FPGA_CLRBITS(&fpga->ctrla, CTRL_HOST_IE);
  65. FPGA_OUT32(&fpga->hostctrl, HOSTCTRL_HCINT_GATE);
  66. irq_install_handler(IRQ0_FPGA,
  67. (interrupt_handler_t *)fpga_interrupt,
  68. fpga);
  69. FPGA_SETBITS(&fpga->ctrla, CTRL_HOST_IE);
  70. while (!got_hcirq) {
  71. /* Abort if ctrl-c was pressed */
  72. if (ctrlc()) {
  73. puts("\nAbort\n");
  74. break;
  75. }
  76. }
  77. if (got_hcirq)
  78. printf("Got interrupt!\n");
  79. FPGA_CLRBITS(&fpga->ctrla, CTRL_HOST_IE);
  80. irq_free_handler(IRQ0_FPGA);
  81. return 0;
  82. }
  83. U_BOOT_CMD(
  84. waithci, 1, 1, do_waithci,
  85. "Wait for host control interrupt",
  86. ""
  87. );
  88. void dump_fifo(pmc440_fpga_t *fpga, int f, int *n)
  89. {
  90. u32 ctrl;
  91. while (!((ctrl = FPGA_IN32(&fpga->fifo[f].ctrl)) & FIFO_EMPTY)) {
  92. printf("%5d %d %3d %08x",
  93. (*n)++, f, ctrl & (FIFO_LEVEL_MASK | FIFO_FULL),
  94. FPGA_IN32(&fpga->fifo[f].data));
  95. if (ctrl & FIFO_OVERFLOW) {
  96. printf(" OVERFLOW\n");
  97. FPGA_CLRBITS(&fpga->fifo[f].ctrl, FIFO_OVERFLOW);
  98. } else
  99. printf("\n");
  100. }
  101. }
  102. int do_fifo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  103. {
  104. pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
  105. int i;
  106. int n = 0;
  107. u32 ctrl, data, f;
  108. char str[] = "\\|/-";
  109. int abort = 0;
  110. int count = 0;
  111. int count2 = 0;
  112. switch (argc) {
  113. case 1:
  114. /* print all fifos status information */
  115. printf("fifo level status\n");
  116. printf("______________________________\n");
  117. for (i=0; i<FIFO_COUNT; i++) {
  118. ctrl = FPGA_IN32(&fpga->fifo[i].ctrl);
  119. printf(" %d %3d %s%s%s %s\n",
  120. i, ctrl & (FIFO_LEVEL_MASK | FIFO_FULL),
  121. ctrl & FIFO_FULL ? "FULL " : "",
  122. ctrl & FIFO_EMPTY ? "EMPTY " : "",
  123. ctrl & (FIFO_FULL|FIFO_EMPTY) ? "" : "NOT EMPTY",
  124. ctrl & FIFO_OVERFLOW ? "OVERFLOW" : "");
  125. }
  126. break;
  127. case 2:
  128. /* completely read out fifo 'n' */
  129. if (!strcmp(argv[1],"read")) {
  130. printf(" # fifo level data\n");
  131. printf("______________________________\n");
  132. for (i=0; i<FIFO_COUNT; i++)
  133. dump_fifo(fpga, i, &n);
  134. } else if (!strcmp(argv[1],"wait")) {
  135. got_fifoirq = 0;
  136. irq_install_handler(IRQ0_FPGA,
  137. (interrupt_handler_t *)fpga_interrupt,
  138. fpga);
  139. printf(" # fifo level data\n");
  140. printf("______________________________\n");
  141. /* enable all fifo interrupts */
  142. FPGA_OUT32(&fpga->hostctrl,
  143. HOSTCTRL_FIFOIE_GATE | HOSTCTRL_FIFOIE_FLAG);
  144. for (i=0; i<FIFO_COUNT; i++) {
  145. /* enable interrupts from all fifos */
  146. FPGA_SETBITS(&fpga->fifo[i].ctrl, FIFO_IE);
  147. }
  148. while (1) {
  149. /* wait loop */
  150. while (!got_fifoirq) {
  151. count++;
  152. if (!(count % 100)) {
  153. count2++;
  154. putc(0x08); /* backspace */
  155. putc(str[count2 % 4]);
  156. }
  157. /* Abort if ctrl-c was pressed */
  158. if ((abort = ctrlc())) {
  159. puts("\nAbort\n");
  160. break;
  161. }
  162. udelay(1000);
  163. }
  164. if (abort)
  165. break;
  166. /* simple fifo backend */
  167. if (got_fifoirq) {
  168. for (i=0; i<FIFO_COUNT; i++)
  169. dump_fifo(fpga, i, &n);
  170. got_fifoirq = 0;
  171. /* unmask global fifo irq */
  172. FPGA_OUT32(&fpga->hostctrl,
  173. HOSTCTRL_FIFOIE_GATE |
  174. HOSTCTRL_FIFOIE_FLAG);
  175. }
  176. }
  177. /* disable all fifo interrupts */
  178. FPGA_OUT32(&fpga->hostctrl, HOSTCTRL_FIFOIE_GATE);
  179. for (i=0; i<FIFO_COUNT; i++)
  180. FPGA_CLRBITS(&fpga->fifo[i].ctrl, FIFO_IE);
  181. irq_free_handler(IRQ0_FPGA);
  182. } else {
  183. printf("Usage:\nfifo %s\n", cmdtp->help);
  184. return 1;
  185. }
  186. break;
  187. case 4:
  188. case 5:
  189. if (!strcmp(argv[1],"write")) {
  190. /* get fifo number or fifo address */
  191. f = simple_strtoul(argv[2], NULL, 16);
  192. /* data paramter */
  193. data = simple_strtoul(argv[3], NULL, 16);
  194. /* get optional count parameter */
  195. n = 1;
  196. if (argc >= 5)
  197. n = (int)simple_strtoul(argv[4], NULL, 10);
  198. if (f < FIFO_COUNT) {
  199. printf("writing %d x %08x to fifo %d\n",
  200. n, data, f);
  201. for (i=0; i<n; i++)
  202. FPGA_OUT32(&fpga->fifo[f].data, data);
  203. } else {
  204. printf("writing %d x %08x to fifo port at "
  205. "address %08x\n",
  206. n, data, f);
  207. for (i=0; i<n; i++)
  208. out_be32((void *)f, data);
  209. }
  210. } else {
  211. printf("Usage:\nfifo %s\n", cmdtp->help);
  212. return 1;
  213. }
  214. break;
  215. default:
  216. printf("Usage:\nfifo %s\n", cmdtp->help);
  217. return 1;
  218. }
  219. return 0;
  220. }
  221. U_BOOT_CMD(
  222. fifo, 5, 1, do_fifo,
  223. "Fifo module operations",
  224. "wait\nfifo read\n"
  225. "fifo write fifo(0..3) data [cnt=1]\n"
  226. "fifo write address(>=4) data [cnt=1]\n"
  227. " - without arguments: print all fifo's status\n"
  228. " - with 'wait' argument: interrupt driven read from all fifos\n"
  229. " - with 'read' argument: read current contents from all fifos\n"
  230. " - with 'write' argument: write 'data' 'cnt' times to "
  231. "'fifo' or 'address'"
  232. );
  233. int do_setup_bootstrap_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  234. {
  235. ulong sdsdp[5];
  236. ulong delay;
  237. int count=16;
  238. if (argc < 2) {
  239. printf("Usage:\nsbe %s\n", cmdtp->help);
  240. return -1;
  241. }
  242. if (argc > 1) {
  243. if (!strcmp(argv[1], "400")) {
  244. /* PLB=133MHz, PLB/PCI=3 */
  245. printf("Bootstrapping for 400MHz\n");
  246. sdsdp[0]=0x8678624e;
  247. sdsdp[1]=0x095fa030;
  248. sdsdp[2]=0x40082350;
  249. sdsdp[3]=0x0d050000;
  250. } else if (!strcmp(argv[1], "533")) {
  251. /* PLB=133MHz, PLB/PCI=3 */
  252. printf("Bootstrapping for 533MHz\n");
  253. sdsdp[0]=0x87788252;
  254. sdsdp[1]=0x095fa030;
  255. sdsdp[2]=0x40082350;
  256. sdsdp[3]=0x0d050000;
  257. } else if (!strcmp(argv[1], "667")) {
  258. /* PLB=133MHz, PLB/PCI=3 */
  259. printf("Bootstrapping for 667MHz\n");
  260. sdsdp[0]=0x8778a256;
  261. sdsdp[1]=0x095fa030;
  262. sdsdp[2]=0x40082350;
  263. sdsdp[3]=0x0d050000;
  264. } else {
  265. printf("Usage:\nsbe %s\n", cmdtp->help);
  266. return -1;
  267. }
  268. }
  269. if (argc > 2) {
  270. sdsdp[4] = 0;
  271. if (argv[2][0]=='1')
  272. sdsdp[4]=0x19750100;
  273. else if (argv[2][0]=='0')
  274. sdsdp[4]=0x19750000;
  275. if (sdsdp[4])
  276. count += 4;
  277. }
  278. if (argc > 3) {
  279. delay = simple_strtoul(argv[3], NULL, 10);
  280. if (delay > 20)
  281. delay = 20;
  282. sdsdp[4] |= delay;
  283. }
  284. printf("Writing boot EEPROM ...\n");
  285. if (bootstrap_eeprom_write(CONFIG_SYS_I2C_BOOT_EEPROM_ADDR,
  286. 0, (uchar*)sdsdp, count) != 0)
  287. printf("bootstrap_eeprom_write failed\n");
  288. else
  289. printf("done (dump via 'i2c md 52 0.1 14')\n");
  290. return 0;
  291. }
  292. U_BOOT_CMD(
  293. sbe, 4, 0, do_setup_bootstrap_eeprom,
  294. "setup bootstrap eeprom",
  295. "<cpufreq:400|533|667> [<console-uart:0|1> [<bringup delay (0..20s)>]]"
  296. );
  297. #if defined(CONFIG_PRAM)
  298. #include <environment.h>
  299. #include <search.h>
  300. #include <errno.h>
  301. int do_painit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  302. {
  303. u32 pram, nextbase, base;
  304. char *v;
  305. u32 param;
  306. ulong *lptr;
  307. env_t *envp;
  308. char *res;
  309. int len;
  310. v = getenv("pram");
  311. if (v)
  312. pram = simple_strtoul(v, NULL, 10);
  313. else {
  314. printf("Error: pram undefined. Please define pram in KiB\n");
  315. return 1;
  316. }
  317. base = gd->bd->bi_memsize;
  318. #if defined(CONFIG_LOGBUFFER)
  319. base -= LOGBUFF_LEN + LOGBUFF_OVERHEAD;
  320. #endif
  321. /*
  322. * gd->bd->bi_memsize == physical ram size - CONFIG_SYS_MEM_TOP_HIDE
  323. */
  324. param = base - (pram << 10);
  325. printf("PARAM: @%08x\n", param);
  326. debug("memsize=0x%08x, base=0x%08x\n", (u32)gd->bd->bi_memsize, base);
  327. /* clear entire PA ram */
  328. memset((void*)param, 0, (pram << 10));
  329. /* reserve 4k for pointer field */
  330. nextbase = base - 4096;
  331. lptr = (ulong*)(base);
  332. /*
  333. * *(--lptr) = item_size;
  334. * *(--lptr) = base - item_base = distance from field top;
  335. */
  336. /* env is first (4k aligned) */
  337. nextbase -= ((CONFIG_ENV_SIZE + 4096 - 1) & ~(4096 - 1));
  338. envp = (env_t *)nextbase;
  339. res = (char *)envp->data;
  340. len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
  341. if (len < 0) {
  342. error("Cannot export environment: errno = %d\n", errno);
  343. return 1;
  344. }
  345. envp->crc = crc32(0, envp->data, ENV_SIZE);
  346. *(--lptr) = CONFIG_ENV_SIZE; /* size */
  347. *(--lptr) = base - nextbase; /* offset | type=0 */
  348. /* free section */
  349. *(--lptr) = nextbase - param; /* size */
  350. *(--lptr) = (base - param) | 126; /* offset | type=126 */
  351. /* terminate pointer field */
  352. *(--lptr) = crc32(0, (void*)(base - 0x10), 0x10);
  353. *(--lptr) = 0; /* offset=0 -> terminator */
  354. return 0;
  355. }
  356. U_BOOT_CMD(
  357. painit, 1, 1, do_painit,
  358. "prepare PciAccess system",
  359. ""
  360. );
  361. #endif /* CONFIG_PRAM */
  362. int do_selfreset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  363. {
  364. in_be32((void*)CONFIG_SYS_RESET_BASE);
  365. return 0;
  366. }
  367. U_BOOT_CMD(
  368. selfreset, 1, 1, do_selfreset,
  369. "assert self-reset# signal",
  370. ""
  371. );
  372. int do_resetout(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  373. {
  374. pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
  375. /* requiers bootet FPGA and PLD_IOEN_N active */
  376. if (in_be32((void*)GPIO1_OR) & GPIO1_IOEN_N) {
  377. printf("Error: resetout requires a bootet FPGA\n");
  378. return -1;
  379. }
  380. if (argc > 1) {
  381. if (argv[1][0] == '0') {
  382. /* assert */
  383. printf("PMC-RESETOUT# asserted\n");
  384. FPGA_OUT32(&fpga->hostctrl,
  385. HOSTCTRL_PMCRSTOUT_GATE);
  386. } else {
  387. /* deassert */
  388. printf("PMC-RESETOUT# deasserted\n");
  389. FPGA_OUT32(&fpga->hostctrl,
  390. HOSTCTRL_PMCRSTOUT_GATE |
  391. HOSTCTRL_PMCRSTOUT_FLAG);
  392. }
  393. } else {
  394. printf("PMC-RESETOUT# is %s\n",
  395. FPGA_IN32(&fpga->hostctrl) & HOSTCTRL_PMCRSTOUT_FLAG ?
  396. "inactive" : "active");
  397. }
  398. return 0;
  399. }
  400. U_BOOT_CMD(
  401. resetout, 2, 1, do_resetout,
  402. "assert PMC-RESETOUT# signal",
  403. ""
  404. );
  405. int do_inta(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  406. {
  407. if (is_monarch()) {
  408. printf("This command is only supported in non-monarch mode\n");
  409. return -1;
  410. }
  411. if (argc > 1) {
  412. if (argv[1][0] == '0') {
  413. /* assert */
  414. printf("inta# asserted\n");
  415. out_be32((void*)GPIO1_TCR,
  416. in_be32((void*)GPIO1_TCR) | GPIO1_INTA_FAKE);
  417. } else {
  418. /* deassert */
  419. printf("inta# deasserted\n");
  420. out_be32((void*)GPIO1_TCR,
  421. in_be32((void*)GPIO1_TCR) & ~GPIO1_INTA_FAKE);
  422. }
  423. } else {
  424. printf("inta# is %s\n",
  425. in_be32((void*)GPIO1_TCR) & GPIO1_INTA_FAKE ?
  426. "active" : "inactive");
  427. }
  428. return 0;
  429. }
  430. U_BOOT_CMD(
  431. inta, 2, 1, do_inta,
  432. "Assert/Deassert or query INTA# state in non-monarch mode",
  433. ""
  434. );
  435. /* test-only */
  436. int do_pmm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  437. {
  438. ulong pciaddr;
  439. if (argc > 1) {
  440. pciaddr = simple_strtoul(argv[1], NULL, 16);
  441. pciaddr &= 0xf0000000;
  442. /* map PCI address at 0xc0000000 in PLB space */
  443. /* PMM1 Mask/Attribute - disabled b4 setting */
  444. out32r(PCIL0_PMM1MA, 0x00000000);
  445. /* PMM1 Local Address */
  446. out32r(PCIL0_PMM1LA, 0xc0000000);
  447. /* PMM1 PCI Low Address */
  448. out32r(PCIL0_PMM1PCILA, pciaddr);
  449. /* PMM1 PCI High Address */
  450. out32r(PCIL0_PMM1PCIHA, 0x00000000);
  451. /* 256MB + No prefetching, and enable region */
  452. out32r(PCIL0_PMM1MA, 0xf0000001);
  453. } else {
  454. printf("Usage:\npmm %s\n", cmdtp->help);
  455. }
  456. return 0;
  457. }
  458. U_BOOT_CMD(
  459. pmm, 2, 1, do_pmm,
  460. "Setup pmm[1] registers",
  461. "<pciaddr> (pciaddr will be aligned to 256MB)"
  462. );
  463. #if defined(CONFIG_SYS_EEPROM_WREN)
  464. int do_eep_wren(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  465. {
  466. int query = argc == 1;
  467. int state = 0;
  468. if (query) {
  469. /* Query write access state. */
  470. state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, -1);
  471. if (state < 0) {
  472. puts("Query of write access state failed.\n");
  473. } else {
  474. printf("Write access for device 0x%0x is %sabled.\n",
  475. CONFIG_SYS_I2C_EEPROM_ADDR, state ? "en" : "dis");
  476. state = 0;
  477. }
  478. } else {
  479. if ('0' == argv[1][0]) {
  480. /* Disable write access. */
  481. state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, 0);
  482. } else {
  483. /* Enable write access. */
  484. state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, 1);
  485. }
  486. if (state < 0) {
  487. puts("Setup of write access state failed.\n");
  488. }
  489. }
  490. return state;
  491. }
  492. U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
  493. "Enable / disable / query EEPROM write access",
  494. ""
  495. );
  496. #endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */
  497. #endif /* CONFIG_CMD_BSP */