GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / arch / mips / board / lausanne / src / ui_lausanne.c
blobb8ef5b2f2fc4df7056d3cfe449178935aab6b17b
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * SWARM-specific commands File: ui_lausanne.c
5 *
6 * A temporary sandbox for misc test routines and commands.
7 *
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
9 *
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
48 #include "lib_types.h"
49 #include "lib_string.h"
50 #include "lib_queue.h"
51 #include "lib_malloc.h"
52 #include "lib_printf.h"
54 #include "cfe_timer.h"
55 #include "cfe_iocb.h"
56 #include "cfe_device.h"
57 #include "cfe_ioctl.h"
58 #include "cfe_devfuncs.h"
59 #include "cfe_error.h"
60 #include "cfe_console.h"
62 #include "ui_command.h"
63 #include "cfe.h"
65 #include "bsp_config.h"
67 #include "sbmips.h"
68 #include "sb1250_regs.h"
69 #include "sb1250_scd.h"
71 #include "sb1250_genbus.h"
73 #include "sb1250_pass2.h"
74 #include "dev_flash.h"
75 #include "lausanne.h"
77 /* *********************************************************************
78 * Configuration
79 ********************************************************************* */
81 /* *********************************************************************
82 * prototypes
83 ********************************************************************* */
85 int ui_init_swarmcmds(void);
87 int ui_init_cpldcmds(void);
88 static int ui_cmd_writecpld(ui_cmdline_t *cmd,int argc,char *argv[]);
89 static int ui_cmd_readcpld(ui_cmdline_t *cmd,int argc,char *argv[]);
90 static int ui_cmd_burstwcpld(ui_cmdline_t *cmd,int argc,char *argv[]);
91 static int ui_cmd_burstrcpld(ui_cmdline_t *cmd,int argc,char *argv[]);
92 static int ui_cmd_config_flash(ui_cmdline_t *cmd,int argc,char *argv[]);
95 #if CFG_VGACONSOLE
96 static int ui_cmd_vgadump(ui_cmdline_t *cmd,int argc,char *argv[]);
97 static int ui_cmd_vgainit(ui_cmdline_t *cmd,int argc,char *argv[]);
98 extern int vga_biosinit(void);
99 extern void vgaraw_dump(char *tail);
100 #endif
104 /* *********************************************************************
105 * Data
106 ********************************************************************* */
109 /* *********************************************************************
110 * ui_init_swarmcmds()
112 * Add SWARM-specific commands to the command table
114 * Input parameters:
115 * nothing
117 * Return value:
119 ********************************************************************* */
122 int ui_init_swarmcmds(void)
124 #if CFG_VGACONSOLE
125 cmd_addcmd("vga init",
126 ui_cmd_vgainit,
127 NULL,
128 "Initialize the VGA adapter.",
129 "vgainit",
130 "");
132 cmd_addcmd("vga dumpbios",
133 ui_cmd_vgadump,
134 NULL,
135 "Dump the VGA BIOS to the console",
136 "vga dumpbios",
137 "");
138 #endif
141 return 0;
150 #if CFG_VGACONSOLE
151 static int ui_cmd_vgainit(ui_cmdline_t *cmd,int argc,char *argv[])
153 int res;
155 res = vga_biosinit();
157 xprintf("vgaraw_init returns %d\n",res);
159 return 0;
162 static int ui_cmd_vgadump(ui_cmdline_t *cmd,int argc,char *argv[])
164 char *x;
166 x = cmd_getarg(cmd,0);
167 if (!x) x = "";
169 vgaraw_dump(x);
171 return 0;
173 #endif
176 int ui_init_cpldcmds(void)
179 cmd_addcmd("write cpld",
180 ui_cmd_writecpld,
181 NULL,
182 "Write bytes to the cpld",
183 "write cpld",
184 "");
186 cmd_addcmd("read cpld",
187 ui_cmd_readcpld,
188 NULL,
189 "Read bytes from the cpld",
190 "read cpld",
191 "");
193 cmd_addcmd("burstw cpld",
194 ui_cmd_burstwcpld,
195 NULL,
196 "Write to the cpld in 8-bit BURST MODE",
197 "burstw cpld",
198 "");
200 cmd_addcmd("burstr cpld",
201 ui_cmd_burstrcpld,
202 NULL,
203 "Read from the cpld in 8-bit BURST MODE",
204 "burstr cpld",
205 "");
207 cmd_addcmd("config flash",
208 ui_cmd_config_flash,
209 NULL,
210 "Configure the flash (flash1) while NOT booting from flash.",
211 "config flash [-n|-w] [-b|-o]",
212 "-n;switch flash1 to 8-bit mode|"
213 "-w;switch flash1 to 16-bit mode|"
214 "-b;burst on|"
215 "-o;burst off");
216 return 0;
220 /* NORMAL WRITE to the cpld
221 * Write 8'b01010101 to address 8'b00000001 of the cpld
223 static int ui_cmd_writecpld(ui_cmdline_t *cmd,int argc,char *argv[])
225 // make sure burst mode is DISABLED
226 *((volatile uint64_t *)PHYS_TO_K1(A_IO_EXT_CS_BASE(CPLD_CS))) = CPLD_CONFIG;
228 xprintf ("writing 0x55 to cpld address 0x01\n");
229 *((volatile uint8_t *) PHYS_TO_K1(0x100B0001)) = (uint8_t) (0x55);
230 xprintf("Done.\n\n");
231 return 0;
235 /* NORMAL READ to the cpld
236 * The cpld is programmed to output the current cpld SUM if address 0x00 is
237 * read. However, if any other address is read, then the cpld will output
238 * 5'b00000 concatenated with the lowest three address bits.
239 * ie.
240 * reading address 0xFF will return 0x07.
241 * reading address 0x4A will return 0x02.
242 * reading address 0x09 will return 0x01.
244 static int ui_cmd_readcpld(ui_cmdline_t *cmd,int argc,char *argv[])
247 uint8_t data;
249 // make sure burst mode is DISABLED
250 *((volatile uint64_t *)PHYS_TO_K1(A_IO_EXT_CS_BASE(CPLD_CS))) = CPLD_CONFIG;
252 data = *((volatile uint8_t *) PHYS_TO_K1(0x100B00FC));
253 xprintf ("CPLD address 0xFC contains 0x%2X\n", data);
254 xprintf ("This value should be 0x04\n\n");
255 data = *((volatile uint8_t *) PHYS_TO_K1(0x100B0000));
256 xprintf ("CPLD address 0x00 contains 0x%2X\n\n", data);
258 return 0;
262 /* BURST WRITE to the cpld
263 * Maximum burst size (without doing a UAC store) to cpld is 8 bytes.
264 * byte1: 0x01
265 * byte2: 0x02
266 * byte3: 0x04
267 * byte4: 0x08
268 * byte5: 0x10
269 * byte6: 0x20
270 * byte7: 0x40
271 * byte8: 0x80
272 * To do the burst, write the 64-bit value 0x8040201008040201 to the cpld.
273 * At the end of the burst, the cpld SUM register should contain 0xFF.
275 static int ui_cmd_burstwcpld(ui_cmdline_t *cmd,int argc,char *argv[])
277 // enable burst mode
278 *((volatile uint64_t *)PHYS_TO_K1(A_IO_EXT_CS_BASE(CPLD_CS))) = CPLD_CONFIG | M_IO_BURST_EN;
280 xprintf("burst writing 8 bytes (0x8040201008040201) to cpld address 0x00\n");
281 *((volatile uint64_t *) PHYS_TO_K1(0x100B0000)) = (uint64_t) (0x8040201008040201);
282 xprintf("Done.\n\n");
284 return 0;
288 /* BURST READ to the cpld
289 * Burst reading the cpld at address 0x00 should return
290 * 0x07060504030201 concatenated with the cpld SUM[7:0]
292 static int ui_cmd_burstrcpld(ui_cmdline_t *cmd,int argc,char *argv[])
294 uint64_t data;
296 // enable burst mode
297 *((volatile uint64_t *)PHYS_TO_K1(A_IO_EXT_CS_BASE(CPLD_CS))) = CPLD_CONFIG | M_IO_BURST_EN;
299 data = *((volatile uint64_t *) PHYS_TO_K1(0x100B0000));
300 xprintf ("Address 0x00 of cpld contains (by burst reading) 0x%16X\n", data);
301 xprintf ("This value should be 0x07060504030201FF if a burst write was just exectued\n\n");
303 return 0;
306 static int ui_cmd_config_flash(ui_cmdline_t *cmd,int argc,char *argv[])
308 int fh;
309 int flash_mode = 0;
310 int burst_on = 0;
312 fh = cfe_open("flash1");
313 if (fh < 0) {
314 xprintf("Could not open device flash1\n");
315 return CFE_ERR_DEVNOTFOUND;
318 if (cmd_sw_isset(cmd,"-w")) {
320 /*switch to 16-bit mode*/
321 flash_mode = INTEL_FLASH_16BIT;
323 else if (cmd_sw_isset(cmd,"-n")) {
324 /*switch to 8-bit mode*/
325 flash_mode = INTEL_FLASH_8BIT;
327 cfe_ioctl(fh,IOCTL_FLASH_DATA_WIDTH_MODE,(uint8_t *) &flash_mode, sizeof(flash_mode),NULL,0);
329 if (cmd_sw_isset(cmd,"-b")) {
330 burst_on = 1;
332 else if (cmd_sw_isset(cmd,"-o")) {
333 burst_on = 0;
335 cfe_ioctl(fh,IOCTL_FLASH_BURST_MODE,(uint8_t *) &burst_on, sizeof(burst_on),NULL,0);
337 cfe_close(fh);
338 return 0;