1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
22e192b24SSimon Glass /*
32e192b24SSimon Glass * (C) Copyright 2013
42e192b24SSimon Glass * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
52e192b24SSimon Glass *
62e192b24SSimon Glass * based on cmd_mem.c
72e192b24SSimon Glass * (C) Copyright 2000
82e192b24SSimon Glass * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
92e192b24SSimon Glass */
102e192b24SSimon Glass
112e192b24SSimon Glass #include <common.h>
122e192b24SSimon Glass #include <command.h>
132e192b24SSimon Glass #include <console.h>
142e192b24SSimon Glass
152e192b24SSimon Glass #include <gdsys_fpga.h>
162e192b24SSimon Glass
172e192b24SSimon Glass static uint dp_last_fpga;
182e192b24SSimon Glass static uint dp_last_addr;
192e192b24SSimon Glass static uint dp_last_length = 0x40;
202e192b24SSimon Glass
212e192b24SSimon Glass /*
222e192b24SSimon Glass * FPGA Memory Display
232e192b24SSimon Glass *
242e192b24SSimon Glass * Syntax:
252e192b24SSimon Glass * fpgad {fpga} {addr} {len}
262e192b24SSimon Glass */
272e192b24SSimon Glass #define DISP_LINE_LEN 16
do_fpga_md(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])282e192b24SSimon Glass int do_fpga_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
292e192b24SSimon Glass {
302e192b24SSimon Glass unsigned int k;
312e192b24SSimon Glass unsigned int fpga;
322e192b24SSimon Glass ulong addr, length;
332e192b24SSimon Glass int rc = 0;
342e192b24SSimon Glass u16 linebuf[DISP_LINE_LEN/sizeof(u16)];
352e192b24SSimon Glass ulong nbytes;
362e192b24SSimon Glass
372e192b24SSimon Glass /*
382e192b24SSimon Glass * We use the last specified parameters, unless new ones are
392e192b24SSimon Glass * entered.
402e192b24SSimon Glass */
412e192b24SSimon Glass fpga = dp_last_fpga;
422e192b24SSimon Glass addr = dp_last_addr;
432e192b24SSimon Glass length = dp_last_length;
442e192b24SSimon Glass
452e192b24SSimon Glass if (argc < 3)
462e192b24SSimon Glass return CMD_RET_USAGE;
472e192b24SSimon Glass
482e192b24SSimon Glass if ((flag & CMD_FLAG_REPEAT) == 0) {
492e192b24SSimon Glass /*
502e192b24SSimon Glass * FPGA is specified since argc > 2
512e192b24SSimon Glass */
522e192b24SSimon Glass fpga = simple_strtoul(argv[1], NULL, 16);
532e192b24SSimon Glass
542e192b24SSimon Glass /*
552e192b24SSimon Glass * Address is specified since argc > 2
562e192b24SSimon Glass */
572e192b24SSimon Glass addr = simple_strtoul(argv[2], NULL, 16);
582e192b24SSimon Glass
592e192b24SSimon Glass /*
602e192b24SSimon Glass * If another parameter, it is the length to display.
612e192b24SSimon Glass * Length is the number of objects, not number of bytes.
622e192b24SSimon Glass */
632e192b24SSimon Glass if (argc > 3)
642e192b24SSimon Glass length = simple_strtoul(argv[3], NULL, 16);
652e192b24SSimon Glass }
662e192b24SSimon Glass
672e192b24SSimon Glass nbytes = length * sizeof(u16);
682e192b24SSimon Glass do {
692e192b24SSimon Glass ulong linebytes = (nbytes > DISP_LINE_LEN) ?
702e192b24SSimon Glass DISP_LINE_LEN : nbytes;
712e192b24SSimon Glass
722e192b24SSimon Glass for (k = 0; k < linebytes / sizeof(u16); ++k)
732e192b24SSimon Glass fpga_get_reg(fpga,
742e192b24SSimon Glass (u16 *)fpga_ptr[fpga] + addr
752e192b24SSimon Glass / sizeof(u16) + k,
762e192b24SSimon Glass addr + k * sizeof(u16),
772e192b24SSimon Glass &linebuf[k]);
782e192b24SSimon Glass print_buffer(addr, (void *)linebuf, sizeof(u16),
792e192b24SSimon Glass linebytes / sizeof(u16),
802e192b24SSimon Glass DISP_LINE_LEN / sizeof(u16));
812e192b24SSimon Glass
822e192b24SSimon Glass nbytes -= linebytes;
832e192b24SSimon Glass addr += linebytes;
842e192b24SSimon Glass if (ctrlc()) {
852e192b24SSimon Glass rc = 1;
862e192b24SSimon Glass break;
872e192b24SSimon Glass }
882e192b24SSimon Glass } while (nbytes > 0);
892e192b24SSimon Glass
902e192b24SSimon Glass dp_last_fpga = fpga;
912e192b24SSimon Glass dp_last_addr = addr;
922e192b24SSimon Glass dp_last_length = length;
932e192b24SSimon Glass return rc;
942e192b24SSimon Glass }
952e192b24SSimon Glass
962e192b24SSimon Glass U_BOOT_CMD(
972e192b24SSimon Glass fpgad, 4, 1, do_fpga_md,
982e192b24SSimon Glass "fpga register display",
992e192b24SSimon Glass "fpga address [# of objects]"
1002e192b24SSimon Glass );
101