]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_fpgad.c
Merge branch 'master' of git://www.denx.de/git/u-boot-imx
[karo-tx-uboot.git] / common / cmd_fpgad.c
1 /*
2  * (C) Copyright 2013
3  * Dirk Eibach,  Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
4  *
5  * based on cmd_mem.c
6  * (C) Copyright 2000
7  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8  *
9  * SPDX-License-Identifier:     GPL-2.0+
10  */
11
12 #include <common.h>
13 #include <command.h>
14
15 #include <gdsys_fpga.h>
16
17 static uint     dp_last_fpga;
18 static uint     dp_last_addr;
19 static 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
28 int do_fpga_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
29 {
30         unsigned int k;
31         unsigned int fpga;
32         ulong   addr, length;
33         int rc = 0;
34         u16     linebuf[DISP_LINE_LEN/sizeof(u16)];
35
36         /*
37          * We use the last specified parameters, unless new ones are
38          * entered.
39          */
40         fpga = dp_last_fpga;
41         addr = dp_last_addr;
42         length = dp_last_length;
43
44         if (argc < 3)
45                 return CMD_RET_USAGE;
46
47         if ((flag & CMD_FLAG_REPEAT) == 0) {
48                 /*
49                  * FPGA is specified since argc > 2
50                  */
51                 fpga = simple_strtoul(argv[1], NULL, 16);
52
53                 /*
54                  * Address is specified since argc > 2
55                  */
56                 addr = simple_strtoul(argv[2], NULL, 16);
57
58                 /*
59                  * If another parameter, it is the length to display.
60                  * Length is the number of objects, not number of bytes.
61                  */
62                 if (argc > 3)
63                         length = simple_strtoul(argv[3], NULL, 16);
64         }
65
66         /* Print the lines. */
67         for (k = 0; k < DISP_LINE_LEN / sizeof(u16); ++k)
68                 fpga_get_reg(fpga, (u16 *)fpga_ptr[fpga] + k, k * sizeof(u16),
69                              &linebuf[k]);
70         print_buffer(addr, (void *)linebuf, sizeof(u16),
71                      length, DISP_LINE_LEN / sizeof(u16));
72         addr += sizeof(u16)*length;
73
74         dp_last_fpga = fpga;
75         dp_last_addr = addr;
76         dp_last_length = length;
77         return rc;
78 }
79
80 U_BOOT_CMD(
81         fpgad,  4,      1,      do_fpga_md,
82         "fpga register display",
83         "fpga address [# of objects]"
84 );