]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_fpgad.c
Merge branch 'master' of git://www.denx.de/git/u-boot-ppc4xx
[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  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28 #include <common.h>
29 #include <command.h>
30
31 #include <gdsys_fpga.h>
32
33 static uint     dp_last_fpga;
34 static uint     dp_last_addr;
35 static uint     dp_last_length = 0x40;
36
37 /*
38  * FPGA Memory Display
39  *
40  * Syntax:
41  *      fpgad {fpga} {addr} {len}
42  */
43 #define DISP_LINE_LEN   16
44 int do_fpga_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
45 {
46         unsigned int k;
47         unsigned int fpga;
48         ulong   addr, length;
49         int rc = 0;
50         u16     linebuf[DISP_LINE_LEN/sizeof(u16)];
51
52         /*
53          * We use the last specified parameters, unless new ones are
54          * entered.
55          */
56         fpga = dp_last_fpga;
57         addr = dp_last_addr;
58         length = dp_last_length;
59
60         if (argc < 3)
61                 return CMD_RET_USAGE;
62
63         if ((flag & CMD_FLAG_REPEAT) == 0) {
64                 /*
65                  * FPGA is specified since argc > 2
66                  */
67                 fpga = simple_strtoul(argv[1], NULL, 16);
68
69                 /*
70                  * Address is specified since argc > 2
71                  */
72                 addr = simple_strtoul(argv[2], NULL, 16);
73
74                 /*
75                  * If another parameter, it is the length to display.
76                  * Length is the number of objects, not number of bytes.
77                  */
78                 if (argc > 3)
79                         length = simple_strtoul(argv[3], NULL, 16);
80         }
81
82         /* Print the lines. */
83         for (k = 0; k < DISP_LINE_LEN / sizeof(u16); ++k)
84                 fpga_get_reg(fpga, (u16 *)fpga_ptr[fpga] + k, k * sizeof(u16),
85                              &linebuf[k]);
86         print_buffer(addr, (void *)linebuf, sizeof(u16),
87                      length, DISP_LINE_LEN / sizeof(u16));
88         addr += sizeof(u16)*length;
89
90         dp_last_fpga = fpga;
91         dp_last_addr = addr;
92         dp_last_length = length;
93         return rc;
94 }
95
96 U_BOOT_CMD(
97         fpgad,  4,      1,      do_fpga_md,
98         "fpga register display",
99         "fpga address [# of objects]"
100 );