blob: e65441bb76a0777130de4b54f2389d17f20d44cb [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dirk Eibach869b5502013-06-26 16:04:28 +02002/*
3 * (C) Copyright 2013
4 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
5 *
6 * based on cmd_mem.c
7 * (C) Copyright 2000
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Dirk Eibach869b5502013-06-26 16:04:28 +02009 */
10
11#include <common.h>
12#include <command.h>
Simon Glass24b852a2015-11-08 23:47:45 -070013#include <console.h>
Dirk Eibach869b5502013-06-26 16:04:28 +020014
15#include <gdsys_fpga.h>
16
17static uint dp_last_fpga;
18static uint dp_last_addr;
19static uint dp_last_length = 0x40;
20
21/*
22 * FPGA Memory Display
23 *
24 * Syntax:
25 * fpgad {fpga} {addr} {len}
26 */
27#define DISP_LINE_LEN 16
Simon Glass09140112020-05-10 11:40:03 -060028int do_fpga_md(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Dirk Eibach869b5502013-06-26 16:04:28 +020029{
30 unsigned int k;
31 unsigned int fpga;
32 ulong addr, length;
33 int rc = 0;
Dirk Eibachf1cdde22014-11-13 19:21:14 +010034 u16 linebuf[DISP_LINE_LEN/sizeof(u16)];
35 ulong nbytes;
Dirk Eibach869b5502013-06-26 16:04:28 +020036
37 /*
38 * We use the last specified parameters, unless new ones are
39 * entered.
40 */
41 fpga = dp_last_fpga;
42 addr = dp_last_addr;
43 length = dp_last_length;
44
45 if (argc < 3)
46 return CMD_RET_USAGE;
47
48 if ((flag & CMD_FLAG_REPEAT) == 0) {
49 /*
50 * FPGA is specified since argc > 2
51 */
Simon Glass7e5f4602021-07-24 09:03:29 -060052 fpga = hextoul(argv[1], NULL);
Dirk Eibach869b5502013-06-26 16:04:28 +020053
54 /*
55 * Address is specified since argc > 2
56 */
Simon Glass7e5f4602021-07-24 09:03:29 -060057 addr = hextoul(argv[2], NULL);
Dirk Eibach869b5502013-06-26 16:04:28 +020058
59 /*
60 * If another parameter, it is the length to display.
61 * Length is the number of objects, not number of bytes.
62 */
63 if (argc > 3)
Simon Glass7e5f4602021-07-24 09:03:29 -060064 length = hextoul(argv[3], NULL);
Dirk Eibach869b5502013-06-26 16:04:28 +020065 }
66
Dirk Eibachf1cdde22014-11-13 19:21:14 +010067 nbytes = length * sizeof(u16);
68 do {
69 ulong linebytes = (nbytes > DISP_LINE_LEN) ?
70 DISP_LINE_LEN : nbytes;
71
72 for (k = 0; k < linebytes / sizeof(u16); ++k)
73 fpga_get_reg(fpga,
74 (u16 *)fpga_ptr[fpga] + addr
75 / sizeof(u16) + k,
76 addr + k * sizeof(u16),
77 &linebuf[k]);
78 print_buffer(addr, (void *)linebuf, sizeof(u16),
79 linebytes / sizeof(u16),
80 DISP_LINE_LEN / sizeof(u16));
81
82 nbytes -= linebytes;
83 addr += linebytes;
84 if (ctrlc()) {
85 rc = 1;
86 break;
87 }
88 } while (nbytes > 0);
Dirk Eibach869b5502013-06-26 16:04:28 +020089
90 dp_last_fpga = fpga;
91 dp_last_addr = addr;
92 dp_last_length = length;
93 return rc;
94}
95
96U_BOOT_CMD(
97 fpgad, 4, 1, do_fpga_md,
98 "fpga register display",
99 "fpga address [# of objects]"
100);