GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / arch / mips / board / p5064 / src / p5064_commands.c
blob8327c034a095b954f1d17734e1cd5e0de6ba6718
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * P5064-specific commands File: P5064_COMMANDS.C
5 *
6 * This module contains special command extensions for the
7 * Algorithmics P5064 port of CFE.
9 * NOTE: Some of the routines in this module were borrowed
10 * from PMON.
12 * Author: Mitch Lichtenberg (mpl@broadcom.com)
14 *********************************************************************
16 * Copyright 2000,2001,2002,2003
17 * Broadcom Corporation. All rights reserved.
19 * This software is furnished under license and may be used and
20 * copied only in accordance with the following terms and
21 * conditions. Subject to these conditions, you may download,
22 * copy, install, use, modify and distribute modified or unmodified
23 * copies of this software in source and/or binary form. No title
24 * or ownership is transferred hereby.
26 * 1) Any source code used, modified or distributed must reproduce
27 * and retain this copyright notice and list of conditions
28 * as they appear in the source file.
30 * 2) No right is granted to use any trade name, trademark, or
31 * logo of Broadcom Corporation. The "Broadcom Corporation"
32 * name may not be used to endorse or promote products derived
33 * from this software without the prior written permission of
34 * Broadcom Corporation.
36 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
37 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
38 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
39 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
40 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
41 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
42 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
44 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
45 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
46 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
47 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
48 * THE POSSIBILITY OF SUCH DAMAGE.
49 ********************************************************************* */
52 #include "sbmips.h"
53 #include "lib_types.h"
54 #include "lib_string.h"
55 #include "lib_queue.h"
56 #include "lib_malloc.h"
57 #include "lib_printf.h"
59 #include "cfe_iocb.h"
60 #include "cfe_device.h"
61 #include "cfe_console.h"
62 #include "cfe_devfuncs.h"
63 #include "cfe_timer.h"
64 #include "cfe_ioctl.h"
66 #include "cfe_error.h"
67 #include "env_subr.h"
68 #include "ui_command.h"
69 #include "cfe.h"
71 #include "sbd.h"
72 #include "rtc.h"
74 #include "pcivar.h"
76 #include "dev_flash.h"
79 #if !defined(__MIPSEB) && !defined(__MIPSEL)
80 #error "You must define either __MIPSEB or __MIPSEL"
81 #endif
84 int ui_init_p5064cmds(void);
85 static int ui_cmd_pcmcia(ui_cmdline_t *cmd,int argc,char *argv[]);
86 static int ui_cmd_poweroff(ui_cmdline_t *cmd,int argc,char *argv[]);
88 #if CFG_VGACONSOLE
89 static int ui_cmd_vgadump(ui_cmdline_t *cmd,int argc,char *argv[]);
90 static int ui_cmd_vgainit(ui_cmdline_t *cmd,int argc,char *argv[]);
91 extern int vga_biosinit(void);
92 extern void vgaraw_dump(char *tail);
93 #endif
94 static int ui_cmd_flashtest(ui_cmdline_t *cmd,int argc,char *argv[]);
96 #define INB(x) inb(x)
97 #define INW(x) inw(x)
98 #define INL(x) inl(x)
100 #define OUTB(x,y) outb(x,y)
101 #define OUTW(x,y) outw(x,y)
102 #define OUTL(x,y) outl(x,y)
107 int ui_init_p5064cmds(void)
110 cmd_addcmd("pcmcia",
111 ui_cmd_pcmcia,
112 NULL,
113 "pcmcia stuff",
114 "pcmcia",
115 "");
117 cmd_addcmd("power off",
118 ui_cmd_poweroff,
119 NULL,
120 "Power off the system.",
121 "power off\n\n"
122 "This command turns off the power for systems that support it.",
123 "");
125 #if CFG_VGACONSOLE
126 cmd_addcmd("vga init",
127 ui_cmd_vgainit,
128 NULL,
129 "Initialize the VGA adapter.",
130 "vgainit",
131 "");
133 cmd_addcmd("vga dumpbios",
134 ui_cmd_vgadump,
135 NULL,
136 "Dump the VGA BIOS to the console",
137 "vga dumpbios",
138 "");
139 #endif
141 cmd_addcmd("test flash",
142 ui_cmd_flashtest,
143 NULL,
144 "Read manufacturer ID from flash",
145 "test flash",
146 "");
148 return 0;
152 unsigned int
153 apc_bis (int reg, unsigned int val)
155 unsigned int rtcsa, o, n;
157 if (BOARD_REVISION < 'C')
158 return ~0;
160 OUTB(RTC_ADDR_PORT, RTC_STATUSA);
161 rtcsa = INB(RTC_DATA_PORT);
162 if ((rtcsa & RTCSA_DVMASK) != RTC_DV2_OSC_ON)
163 OUTB(RTC_DATA_PORT, (rtcsa & ~RTCSA_DVMASK) | RTC_DV2_OSC_ON);
165 OUTB(RTC_ADDR_PORT, reg);
166 o = INB(RTC_DATA_PORT);
167 n = o | val;
168 if (o != n) {
169 OUTB(RTC_DATA_PORT, n);
172 /* paranoia - switch back to bank 0 */
173 OUTB(RTC_ADDR_PORT, RTC_STATUSA);
174 OUTB(RTC_DATA_PORT, (rtcsa & ~RTCSA_DVMASK) | RTC_DV0_OSC_ON);
176 return (o);
180 #if CFG_VGACONSOLE
181 static int ui_cmd_vgainit(ui_cmdline_t *cmd,int argc,char *argv[])
183 int res;
185 res = vga_biosinit();
187 xprintf("vgaraw_init returns %d\n",res);
189 return 0;
192 static int ui_cmd_vgadump(ui_cmdline_t *cmd,int argc,char *argv[])
194 char *x;
196 x = cmd_getarg(cmd,0);
197 if (!x) x = "";
199 vgaraw_dump(x);
201 return 0;
203 #endif
206 static void pcicdump(int slot)
208 uint8_t b;
209 int idx,idx2;
211 for (idx = 0; idx < 63; idx+=16) {
212 xprintf("%02X: ",idx);
213 for (idx2 = 0; idx2 < 16; idx2++) {
214 OUTB(0x3E0,idx+idx2+slot*64);
215 b = INB(0x3E1);
216 xprintf("%02X ",b);
218 xprintf("\n");
222 #define PCICSET(reg,val) OUTB(0x3E0,(reg)); OUTB(0x3E1,(val))
223 #define PCICGET(reg,val) OUTB(0x3E0,(reg)); val = INB(0x3E1)
225 static int ui_cmd_pcmcia(ui_cmdline_t *cmd,int argc,char *argv[])
227 char *tok;
228 char *reg,*val;
229 uint32_t start,stop;
230 uint32_t offset;
231 uint8_t *ptr;
233 tok = cmd_getarg(cmd,0);
234 if (!tok) tok = "dump";
236 if (strcmp(tok,"dump") == 0) {
237 xprintf("Slot 0:\n"); pcicdump(0);
238 xprintf("\n");
239 xprintf("Slot 1:\n"); pcicdump(1);
241 if (strcmp(tok,"set") == 0) {
242 reg = cmd_getarg(cmd,1);
243 val = cmd_getarg(cmd,2);
244 if (!reg || !val) {
245 xprintf("pcmcia set reg val\n");
246 return -1;
248 PCICSET(xtoi(reg),xtoi(val));
250 if (strcmp(tok,"on") == 0) {
251 PCICSET(0x2F,0x70);
252 PCICSET(0x02,0x30);
253 cfe_sleep(CFE_HZ/4);
254 PCICSET(0x02,0xB0);
256 if (strcmp(tok,"map") == 0) {
257 reg = cmd_getarg(cmd,1);
258 val = cmd_getarg(cmd,2);
259 if (!reg) {
260 xprintf("pcmcia map start stop [a]\n");
261 return -1;
263 start = xtoi(reg);
264 stop = xtoi(val);
265 PCICSET(0x06,0x00);
266 PCICSET(0x10,(start >> 12) & 0xFF);
267 PCICSET(0x11,((start >> 20) & 0x0F) | 0x00);
268 PCICSET(0x12,(stop >> 12) & 0xFF);
269 PCICSET(0x13,((stop >> 20) & 0x0F) | 0x00);
271 offset = (uint32_t) ((int32_t) 0 - (int32_t) start);
272 xprintf("Offset = %08X\n",offset);
274 PCICSET(0x14,(offset >> 12) & 0xFF);
275 PCICSET(0x15,(((offset >> 20) & 0x3F) | (cmd_getarg(cmd,3) ? 0x40 : 0)));
277 PCICSET(0x06,0x01);
280 if (strcmp(tok,"detect") == 0) {
281 uint8_t det,newdet;
282 PCICGET(0x01,det);
283 xprintf("%02X ",det);
284 while (!console_status()) {
285 PCICGET(0x01,newdet);
286 if (det != newdet) {
287 det = newdet;
288 xprintf("%02X ",det);
292 if (strcmp(tok,"tuples") == 0) {
293 reg = cmd_getarg(cmd,1);
294 if (!reg) {
295 xprintf("pcmcia tuples isa-addr\n");
296 return -1;
298 start = xtoi(reg);
299 ptr = (uint8_t *) (intptr_t) (0xB0000000 | start);
300 while (*ptr != 0xFF) {
301 uint8_t tpl,len;
303 tpl = *ptr;
304 ptr+=2;
305 len = *ptr;
306 ptr+=2;
307 xprintf("Tuple @ %04X type %02X len %d Data ",
308 (((uint32_t) (intptr_t) ptr) & 0xFFFF) >> 1,tpl,len);
309 while (len) {
310 xprintf("%02X ",*ptr);
311 ptr += 2;
312 len--;
314 xprintf("\n");
318 return 0;
322 static int ui_cmd_poweroff(ui_cmdline_t *cmd,int argc,char *argv[])
324 xprintf("Power off.\n");
325 apc_bis(RTC_BANK2_APCR1, APCR1_SOC);
326 for (;;) ;
327 return 0;
331 static char *flashtypes[] = {
332 "Unknown","SRAM","ROM","Flash"
335 static int ui_cmd_flashtest(ui_cmdline_t *cmd,int argc,char *argv[])
337 flash_info_t info;
338 int fd;
339 int retlen;
340 int res = 0;
341 int idx;
342 flash_sector_t sector;
343 nvram_info_t nvraminfo;
344 char *devname;
346 devname = cmd_getarg(cmd,0);
347 if (!devname) return ui_showusage(cmd);
349 fd = cfe_open(devname);
350 if (fd < 0) {
351 ui_showerror(fd,"Could not open flash device %s",devname);
352 return fd;
355 res = cfe_ioctl(fd,IOCTL_FLASH_GETINFO,(uint8_t *) &info,sizeof(flash_info_t),&retlen,0);
356 if (res == 0) {
357 printf("FLASH: Base %016llX size %08X type %02X(%s) flags %08X\n",
358 info.flash_base,info.flash_size,info.flash_type,flashtypes[info.flash_type],
359 info.flash_flags);
361 else {
362 printf("FLASH: Could not determine flash information\n");
365 res = cfe_ioctl(fd,IOCTL_NVRAM_GETINFO,(uint8_t *) &nvraminfo,sizeof(nvram_info_t),&retlen,0);
366 if (res == 0) {
367 printf("NVRAM: Offset %08X Size %08X EraseFlg %d\n",
368 nvraminfo.nvram_offset,nvraminfo.nvram_size,nvraminfo.nvram_eraseflg);
370 else {
371 printf("NVRAM: Not supported by this flash\n");
374 if (info.flash_type == FLASH_TYPE_FLASH) {
375 printf("Flash sector information:\n");
377 idx = 0;
378 for (;;) {
379 sector.flash_sector_idx = idx;
380 res = cfe_ioctl(fd,IOCTL_FLASH_GETSECTORS,(uint8_t *) &sector,sizeof(flash_sector_t),&retlen,0);
381 if (res != 0) {
382 printf("ioctl error\n");
383 break;
385 if (sector.flash_sector_status == FLASH_SECTOR_INVALID) break;
386 printf(" Sector %d offset %08X size %d\n",
387 sector.flash_sector_idx,
388 sector.flash_sector_offset,
389 sector.flash_sector_size);
390 idx++;
394 cfe_close(fd);
395 return 0;