cmd_pmc440.c 13 KB

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