2 * (C) Copyright 2007-2008
3 * Matthias Fuchs, esd Gmbh, matthias.fuchs@esd-electronics.com.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
27 #include <asm/cache.h>
28 #include <asm/processor.h>
33 int bootstrap_eeprom_write(unsigned dev_addr, unsigned offset,
34 uchar *buffer, unsigned cnt);
35 int eeprom_write_enable(unsigned dev_addr, int state);
37 DECLARE_GLOBAL_DATA_PTR;
39 #if defined(CONFIG_CMD_BSP)
41 static int got_fifoirq;
44 int fpga_interrupt(u32 arg)
46 pmc440_fpga_t *fpga = (pmc440_fpga_t *)arg;
47 int rc = -1; /* not for us */
48 u32 status = FPGA_IN32(&fpga->status);
50 /* check for interrupt from fifo module */
51 if (status & STATUS_FIFO_ISF) {
52 /* disable this int source */
53 FPGA_OUT32(&fpga->hostctrl, HOSTCTRL_FIFOIE_GATE);
55 got_fifoirq = 1; /* trigger backend */
58 if (status & STATUS_HOST_ISF) {
59 FPGA_OUT32(&fpga->hostctrl, HOSTCTRL_HCINT_GATE);
67 int do_waithci(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
69 pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
73 FPGA_CLRBITS(&fpga->ctrla, CTRL_HOST_IE);
74 FPGA_OUT32(&fpga->hostctrl, HOSTCTRL_HCINT_GATE);
76 irq_install_handler(IRQ0_FPGA,
77 (interrupt_handler_t *)fpga_interrupt,
80 FPGA_SETBITS(&fpga->ctrla, CTRL_HOST_IE);
83 /* Abort if ctrl-c was pressed */
90 printf("Got interrupt!\n");
92 FPGA_CLRBITS(&fpga->ctrla, CTRL_HOST_IE);
93 irq_free_handler(IRQ0_FPGA);
97 waithci, 1, 1, do_waithci,
98 "waithci - Wait for host control interrupt\n",
102 void dump_fifo(pmc440_fpga_t *fpga, int f, int *n)
106 while (!((ctrl = FPGA_IN32(&fpga->fifo[f].ctrl)) & FIFO_EMPTY)) {
107 printf("%5d %d %3d %08x",
108 (*n)++, f, ctrl & (FIFO_LEVEL_MASK | FIFO_FULL),
109 FPGA_IN32(&fpga->fifo[f].data));
110 if (ctrl & FIFO_OVERFLOW) {
111 printf(" OVERFLOW\n");
112 FPGA_CLRBITS(&fpga->fifo[f].ctrl, FIFO_OVERFLOW);
118 int do_fifo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
120 pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
124 char str[] = "\\|/-";
131 /* print all fifos status information */
132 printf("fifo level status\n");
133 printf("______________________________\n");
134 for (i=0; i<FIFO_COUNT; i++) {
135 ctrl = FPGA_IN32(&fpga->fifo[i].ctrl);
136 printf(" %d %3d %s%s%s %s\n",
137 i, ctrl & (FIFO_LEVEL_MASK | FIFO_FULL),
138 ctrl & FIFO_FULL ? "FULL " : "",
139 ctrl & FIFO_EMPTY ? "EMPTY " : "",
140 ctrl & (FIFO_FULL|FIFO_EMPTY) ? "" : "NOT EMPTY",
141 ctrl & FIFO_OVERFLOW ? "OVERFLOW" : "");
146 /* completely read out fifo 'n' */
147 if (!strcmp(argv[1],"read")) {
148 printf(" # fifo level data\n");
149 printf("______________________________\n");
151 for (i=0; i<FIFO_COUNT; i++)
152 dump_fifo(fpga, i, &n);
154 } else if (!strcmp(argv[1],"wait")) {
157 irq_install_handler(IRQ0_FPGA,
158 (interrupt_handler_t *)fpga_interrupt,
161 printf(" # fifo level data\n");
162 printf("______________________________\n");
164 /* enable all fifo interrupts */
165 FPGA_OUT32(&fpga->hostctrl,
166 HOSTCTRL_FIFOIE_GATE | HOSTCTRL_FIFOIE_FLAG);
167 for (i=0; i<FIFO_COUNT; i++) {
168 /* enable interrupts from all fifos */
169 FPGA_SETBITS(&fpga->fifo[i].ctrl, FIFO_IE);
174 while (!got_fifoirq) {
176 if (!(count % 100)) {
178 putc(0x08); /* backspace */
179 putc(str[count2 % 4]);
182 /* Abort if ctrl-c was pressed */
183 if ((abort = ctrlc())) {
192 /* simple fifo backend */
194 for (i=0; i<FIFO_COUNT; i++)
195 dump_fifo(fpga, i, &n);
198 /* unmask global fifo irq */
199 FPGA_OUT32(&fpga->hostctrl,
200 HOSTCTRL_FIFOIE_GATE |
201 HOSTCTRL_FIFOIE_FLAG);
205 /* disable all fifo interrupts */
206 FPGA_OUT32(&fpga->hostctrl, HOSTCTRL_FIFOIE_GATE);
207 for (i=0; i<FIFO_COUNT; i++)
208 FPGA_CLRBITS(&fpga->fifo[i].ctrl, FIFO_IE);
210 irq_free_handler(IRQ0_FPGA);
213 printf("Usage:\nfifo %s\n", cmdtp->help);
220 if (!strcmp(argv[1],"write")) {
221 /* get fifo number or fifo address */
222 f = simple_strtoul(argv[2], NULL, 16);
225 data = simple_strtoul(argv[3], NULL, 16);
227 /* get optional count parameter */
230 n = (int)simple_strtoul(argv[4], NULL, 10);
232 if (f < FIFO_COUNT) {
233 printf("writing %d x %08x to fifo %d\n",
236 FPGA_OUT32(&fpga->fifo[f].data, data);
238 printf("writing %d x %08x to fifo port at "
245 printf("Usage:\nfifo %s\n", cmdtp->help);
251 printf("Usage:\nfifo %s\n", cmdtp->help);
258 "fifo - Fifo module operations\n",
260 "fifo write fifo(0..3) data [cnt=1]\n"
261 "fifo write address(>=4) data [cnt=1]\n"
262 " - without arguments: print all fifo's status\n"
263 " - with 'wait' argument: interrupt driven read from all fifos\n"
264 " - with 'read' argument: read current contents from all fifos\n"
265 " - with 'write' argument: write 'data' 'cnt' times to "
266 "'fifo' or 'address'\n"
269 int do_setup_bootstrap_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
276 printf("Usage:\nsbe %s\n", cmdtp->help);
281 if (!strcmp(argv[1], "400")) {
282 /* PLB=133MHz, PLB/PCI=3 */
283 printf("Bootstrapping for 400MHz\n");
288 } else if (!strcmp(argv[1], "533")) {
289 /* PLB=133MHz, PLB/PCI=3 */
290 printf("Bootstrapping for 533MHz\n");
295 } else if (!strcmp(argv[1], "667")) {
296 /* PLB=133MHz, PLB/PCI=4 */
297 printf("Bootstrapping for 667MHz\n");
302 } else if (!strcmp(argv[1], "test")) {
304 * TODO: this will replace the 667 MHz config above.
305 * But it needs some more testing on a real 667 MHz CPU.
307 printf("Bootstrapping for test"
308 " (667MHz PLB=133PLB PLB/PCI=3)\n");
314 printf("Usage:\nsbe %s\n", cmdtp->help);
323 else if (argv[2][0]=='0')
330 delay = simple_strtoul(argv[3], NULL, 10);
336 printf("Writing boot EEPROM ...\n");
337 if (bootstrap_eeprom_write(CFG_I2C_BOOT_EEPROM_ADDR,
338 0, (uchar*)sdsdp, count) != 0)
339 printf("bootstrap_eeprom_write failed\n");
341 printf("done (dump via 'i2c md 52 0.1 14')\n");
346 sbe, 4, 0, do_setup_bootstrap_eeprom,
347 "sbe - setup bootstrap eeprom\n",
348 "<cpufreq:400|533|667> [<console-uart:0|1> [<bringup delay (0..20s)>]]"
351 #if defined(CONFIG_PRAM)
352 #include <environment.h>
353 extern env_t *env_ptr;
355 int do_painit(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
363 memsize = gd->bd->bi_memsize;
367 pram = simple_strtoul(v, NULL, 10);
369 printf("Error: pram undefined. Please define pram in KiB\n");
373 param = memsize - (pram << 10);
374 printf("PARAM: @%08x\n", param);
376 memset((void*)param, 0, (pram << 10));
377 env_base = memsize - 4096 - ((CFG_ENV_SIZE + 4096) & ~(4096-1));
378 memcpy((void*)env_base, env_ptr, CFG_ENV_SIZE);
380 lptr = (ulong*)memsize;
381 *(--lptr) = CFG_ENV_SIZE;
382 *(--lptr) = memsize - env_base;
383 *(--lptr) = crc32(0, (void*)(memsize - 0x08), 0x08);
386 /* make sure data can be accessed through PCI */
387 flush_dcache_range(param, param + (pram << 10) - 1);
391 painit, 1, 1, do_painit,
392 "painit - prepare PciAccess system\n",
395 #endif /* CONFIG_PRAM */
397 int do_selfreset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
400 if (argv[1][0] == '0') {
402 printf("self-reset# asserted\n");
403 out_be32((void*)GPIO0_TCR,
404 in_be32((void*)GPIO0_TCR) | GPIO0_SELF_RST);
407 printf("self-reset# deasserted\n");
408 out_be32((void*)GPIO0_TCR,
409 in_be32((void*)GPIO0_TCR) & ~GPIO0_SELF_RST);
412 printf("self-reset# is %s\n",
413 in_be32((void*)GPIO0_TCR) & GPIO0_SELF_RST ?
414 "active" : "inactive");
420 selfreset, 2, 1, do_selfreset,
421 "selfreset- assert self-reset# signal\n",
425 int do_resetout(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
427 pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
429 /* requiers bootet FPGA and PLD_IOEN_N active */
430 if (in_be32((void*)GPIO1_OR) & GPIO1_IOEN_N) {
431 printf("Error: resetout requires a bootet FPGA\n");
436 if (argv[1][0] == '0') {
438 printf("PMC-RESETOUT# asserted\n");
439 FPGA_OUT32(&fpga->hostctrl,
440 HOSTCTRL_PMCRSTOUT_GATE);
443 printf("PMC-RESETOUT# deasserted\n");
444 FPGA_OUT32(&fpga->hostctrl,
445 HOSTCTRL_PMCRSTOUT_GATE |
446 HOSTCTRL_PMCRSTOUT_FLAG);
449 printf("PMC-RESETOUT# is %s\n",
450 FPGA_IN32(&fpga->hostctrl) & HOSTCTRL_PMCRSTOUT_FLAG ?
451 "inactive" : "active");
457 resetout, 2, 1, do_resetout,
458 "resetout - assert PMC-RESETOUT# signal\n",
462 int do_inta(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
465 printf("This command is only supported in non-monarch mode\n");
470 if (argv[1][0] == '0') {
472 printf("inta# asserted\n");
473 out_be32((void*)GPIO1_TCR,
474 in_be32((void*)GPIO1_TCR) | GPIO1_INTA_FAKE);
477 printf("inta# deasserted\n");
478 out_be32((void*)GPIO1_TCR,
479 in_be32((void*)GPIO1_TCR) & ~GPIO1_INTA_FAKE);
482 printf("inta# is %s\n",
483 in_be32((void*)GPIO1_TCR) & GPIO1_INTA_FAKE ?
484 "active" : "inactive");
490 "inta - Assert/Deassert or query INTA# state in non-monarch mode\n",
495 int do_pmm(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
500 pciaddr = simple_strtoul(argv[1], NULL, 16);
502 pciaddr &= 0xf0000000;
504 /* map PCI address at 0xc0000000 in PLB space */
506 /* PMM1 Mask/Attribute - disabled b4 setting */
507 out32r(PCIX0_PMM1MA, 0x00000000);
508 /* PMM1 Local Address */
509 out32r(PCIX0_PMM1LA, 0xc0000000);
510 /* PMM1 PCI Low Address */
511 out32r(PCIX0_PMM1PCILA, pciaddr);
512 /* PMM1 PCI High Address */
513 out32r(PCIX0_PMM1PCIHA, 0x00000000);
514 /* 256MB + No prefetching, and enable region */
515 out32r(PCIX0_PMM1MA, 0xf0000001);
517 printf("Usage:\npmm %s\n", cmdtp->help);
523 "pmm - Setup pmm[1] registers\n",
524 "<pciaddr> (pciaddr will be aligned to 256MB)\n"
527 #if defined(CFG_EEPROM_WREN)
528 int do_eep_wren(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
530 int query = argc == 1;
534 /* Query write access state. */
535 state = eeprom_write_enable(CFG_I2C_EEPROM_ADDR, -1);
537 puts("Query of write access state failed.\n");
539 printf("Write access for device 0x%0x is %sabled.\n",
540 CFG_I2C_EEPROM_ADDR, state ? "en" : "dis");
544 if ('0' == argv[1][0]) {
545 /* Disable write access. */
546 state = eeprom_write_enable(CFG_I2C_EEPROM_ADDR, 0);
548 /* Enable write access. */
549 state = eeprom_write_enable(CFG_I2C_EEPROM_ADDR, 1);
552 puts("Setup of write access state failed.\n");
558 U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
559 "eepwren - Enable / disable / query EEPROM write access\n",
561 #endif /* #if defined(CFG_EEPROM_WREN) */
563 #endif /* CONFIG_CMD_BSP */