1/* ********************************************************************* 2 * Broadcom Common Firmware Environment (CFE) 3 * 4 * BCM1250CPCI USB commands File: ui_usb_scanlogic.c 5 * 6 * USB test utilities 7 * 8 * Author: Paul Burrell 9 * 10 ********************************************************************* 11 * 12 * Copyright 2000,2001,2002,2003 13 * Broadcom Corporation. All rights reserved. 14 * 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. 21 * 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. 25 * 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. 31 * 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 ********************************************************************* */ 46 47 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" 53 54#include "cfe_timer.h" 55#include "cfe_error.h" 56 57#include "ui_command.h" 58#include "cfe.h" 59 60#include "bsp_config.h" 61 62#include "sl11h.h" 63#include "sbmips.h" 64#include "sb1250_regs.h" 65#include "sb1250_smbus.h" 66 67#include "bcm1250cpci.h" 68 69 70 71/* ********************************************************************* 72 * Constants 73 ********************************************************************* */ 74 75/* ********************************************************************* 76 * Configuration 77 ********************************************************************* */ 78 79/* ********************************************************************* 80 * prototypes 81 ********************************************************************* */ 82 83int ui_init_usbcmds(void); 84static int ui_cmd_usbread(ui_cmdline_t *cmd,int argc,char *argv[]); 85static int ui_cmd_usbwrite(ui_cmdline_t *cmd,int argc,char *argv[]); 86static int ui_cmd_usbreset(ui_cmdline_t *cmd,int argc,char *argv[]); 87static int ui_cmd_usbmemtest(ui_cmdline_t *cmd,int argc,char *argv[]); 88static int ui_cmd_usbfinddevice(ui_cmdline_t *cmd,int argc,char *argv[]); 89 90 91/* ********************************************************************* 92 * Data 93 ********************************************************************* */ 94 95 96/* ********************************************************************* 97 * ui_init_usbcmds() 98 * 99 * Add USB commands to the command table 100 * 101 * Input parameters: 102 * nothing 103 * 104 * Return value: 105 * 0 106 ********************************************************************* */ 107 108 109int ui_init_usbcmds(void) 110{ 111 cmd_addcmd("usb read", 112 ui_cmd_usbread, 113 NULL, 114 "Read register from SL11H USB chip", 115 "usb read <reg>", 116 ""); 117 118 cmd_addcmd("usb write", 119 ui_cmd_usbwrite, 120 NULL, 121 "Write register from SL11H USB chip", 122 "usb write <reg> <data>", 123 ""); 124 125 cmd_addcmd("usb reset", 126 ui_cmd_usbreset, 127 NULL, 128 "Resets the SL11H USB chip", 129 "usb reset", 130 ""); 131 132 cmd_addcmd("usb memtest", 133 ui_cmd_usbmemtest, 134 NULL, 135 "Tests all of the onboard memory on the SL11H USB chip", 136 "usb memtest", 137 ""); 138 139 cmd_addcmd("usb finddevice", 140 ui_cmd_usbfinddevice, 141 NULL, 142 "Scans for peripherals.", 143 "usb find device", 144 ""); 145 146 return 0; 147} 148 149 150/* ********************************************************************* 151 * User interface commands 152 ********************************************************************* */ 153 154static int ui_cmd_usbread(ui_cmdline_t *cmd,int argc,char *argv[]) 155{ 156 char *line; 157 char *p; 158 int address; 159 160 if ((line = cmd_getarg(cmd,0)) == NULL) { 161 return ui_showusage(cmd); 162 } 163 164 /* parse and check command-line args */ 165 address = -1; 166 167 p = gettoken(&line); 168 if (p) address = xtoi(p); 169 170 if ((address < 0) || (address > 0xfF)) { 171 printf("Invalid Address Range on USB read"); 172 return(-1); 173 } 174 175 printf("USB read at address %02X = %02X\n",address,SL11Read(address)); 176 177 return 0; 178} 179 180static int ui_cmd_usbwrite(ui_cmdline_t *cmd,int argc,char *argv[]) 181{ 182 char *line; 183// char *p; 184 int address,data; 185 186 if (argc != 2) { 187 return ui_showusage(cmd); 188 } 189 190 if ((line = cmd_getarg(cmd,0)) == NULL) { 191 return ui_showusage(cmd); 192 } 193 194 195 /* parse and check command-line args */ 196 address = -1; 197 data = -1; 198 199 address = xtoi(argv[0]); 200 data = xtoi(argv[1]); 201 202// p = gettoken(&line); 203// if (p) address = xtoi(p); 204// printf("%s\n",p); 205// p = gettoken(&line); 206// if (p) data = xtoi(p); 207// printf("%s\n",p); 208 209 printf ("%X,%X\n",address,data); 210 211 if ((address < 0) || (address > 0xfF)) { 212 printf("Invalid Address Range on USB write\n"); 213 return(-1); 214 } 215 216 if ((data < 0) || (data > 0xfF)) { 217 printf("Invalid DATA Range on USB write\n"); 218 return(-1); 219 } 220 221 SL11Write(address,data); 222 223 printf("Data written\n"); 224 225 return(0); 226 227} 228 229 230static int ui_cmd_usbreset(ui_cmdline_t *cmd,int argc,char *argv[]) 231{ 232 233 printf("Reseting USB device\n"); 234 USBReset(); 235 printf("USB reset complete\n"); 236 237 return 0; 238 239} 240 241static int ui_cmd_usbmemtest(ui_cmdline_t *cmd,int argc,char *argv[]) 242{ 243 int errors; 244 245 printf("Performing memory test...\n"); 246 errors = SL11HMemTest(); 247 printf("Error Count = %d\n",errors); 248 printf("Memory Test complete.\n"); 249 250 if (errors) { 251 return(-1); 252 } else { 253 return(0); 254 255 } 256 257} 258 259static int ui_cmd_usbfinddevice(ui_cmdline_t *cmd,int argc,char *argv[]) 260{ 261 int status; 262 263 status = uFindUsbDev(0x0); 264 265 return(status); 266 267 268} 269