1 //<MStar Software> 2 //****************************************************************************** 3 // MStar Software 4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved. 5 // All software, firmware and related documentation herein ("MStar Software") are 6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by 7 // law, including, but not limited to, copyright law and international treaties. 8 // Any use, modification, reproduction, retransmission, or republication of all 9 // or part of MStar Software is expressly prohibited, unless prior written 10 // permission has been granted by MStar. 11 // 12 // By accessing, browsing and/or using MStar Software, you acknowledge that you 13 // have read, understood, and agree, to be bound by below terms ("Terms") and to 14 // comply with all applicable laws and regulations: 15 // 16 // 1. MStar shall retain any and all right, ownership and interest to MStar 17 // Software and any modification/derivatives thereof. 18 // No right, ownership, or interest to MStar Software and any 19 // modification/derivatives thereof is transferred to you under Terms. 20 // 21 // 2. You understand that MStar Software might include, incorporate or be 22 // supplied together with third party`s software and the use of MStar 23 // Software may require additional licenses from third parties. 24 // Therefore, you hereby agree it is your sole responsibility to separately 25 // obtain any and all third party right and license necessary for your use of 26 // such third party`s software. 27 // 28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as 29 // MStar`s confidential information and you agree to keep MStar`s 30 // confidential information in strictest confidence and not disclose to any 31 // third party. 32 // 33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any 34 // kind. Any warranties are hereby expressly disclaimed by MStar, including 35 // without limitation, any warranties of merchantability, non-infringement of 36 // intellectual property rights, fitness for a particular purpose, error free 37 // and in conformity with any international standard. You agree to waive any 38 // claim against MStar for any loss, damage, cost or expense that you may 39 // incur related to your use of MStar Software. 40 // In no event shall MStar be liable for any direct, indirect, incidental or 41 // consequential damages, including without limitation, lost of profit or 42 // revenues, lost or damage of data, and unauthorized system use. 43 // You agree that this Section 4 shall still apply without being affected 44 // even if MStar Software has been modified by MStar in accordance with your 45 // request or instruction for your use, except otherwise agreed by both 46 // parties in writing. 47 // 48 // 5. If requested, MStar may from time to time provide technical supports or 49 // services in relation with MStar Software to you for your use of 50 // MStar Software in conjunction with your or your customer`s product 51 // ("Services"). 52 // You understand and agree that, except otherwise agreed by both parties in 53 // writing, Services are provided on an "AS IS" basis and the warranty 54 // disclaimer set forth in Section 4 above shall apply. 55 // 56 // 6. Nothing contained herein shall be construed as by implication, estoppels 57 // or otherwise: 58 // (a) conferring any license or right to use MStar name, trademark, service 59 // mark, symbol or any other identification; 60 // (b) obligating MStar or any of its affiliates to furnish any person, 61 // including without limitation, you and your customers, any assistance 62 // of any kind whatsoever, or any information; or 63 // (c) conferring any license or right under any intellectual property right. 64 // 65 // 7. These terms shall be governed by and construed in accordance with the laws 66 // of Taiwan, R.O.C., excluding its conflict of law rules. 67 // Any and all dispute arising out hereof or related hereto shall be finally 68 // settled by arbitration referred to the Chinese Arbitration Association, 69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration 70 // Rules of the Association by three (3) arbitrators appointed in accordance 71 // with the said Rules. 72 // The place of arbitration shall be in Taipei, Taiwan and the language shall 73 // be English. 74 // The arbitration award shall be final and binding to both parties. 75 // 76 //****************************************************************************** 77 //<MStar Software> 78 79 #ifndef _CORE_HUB_H_ 80 #define _CORE_HUB_H_ 81 #include <MsTypes.h> 82 83 #include "include/drvList.h" 84 #include "include/drvCompiler.h" 85 #include "include/drvUSBHost.h" 86 #include "include/drvCPE_AMBA.h" 87 #include "drvUsbHostConfig.h" 88 89 #define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE) // root hub 90 #define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER) // root hub port 91 92 #define HUB_CLEAR_TT_BUFFER 8 // TT buffer clear 93 94 #define C_HUB_LOCAL_POWER 0 // hub power operation 95 #define C_HUB_OVER_CURRENT 1 // hub over-current operation 96 97 #define HUB_CHAR_LPSM 0x0003 98 #define HUB_CHAR_COMPOUND 0x0004 99 #define HUB_CHAR_OCPM 0x0018 100 #define HUB_CHAR_TTTT 0x0060 101 #define HUB_CHAR_PORTIND 0x0080 102 103 #define USB_PORT_FEAT_ENABLE 1 // port bitmap port enable 104 #define USB_PORT_FEAT_SUSPEND 2 // port bitmap port suspend 105 #define USB_PORT_FEAT_OVER_CURRENT 3 // port bitmap port over current 106 #define USB_PORT_FEAT_RESET 4 // port bitmap port reset 107 #define USB_PORT_FEAT_POWER 8 // port bitmap port power 108 #define USB_PORT_FEAT_C_CONNECTION 16 // port clear bitmap clear port connection 109 #define USB_PORT_FEAT_C_ENABLE 17 // port clear bitmap clear port enable 110 #define USB_PORT_FEAT_C_SUSPEND 18 // port clear bitmap clear port suspend 111 #define USB_PORT_FEAT_C_OVER_CURRENT 19 // port clear bitmap clear port over current 112 #define USB_PORT_FEAT_C_RESET 20 // port clear bitmap clear port reset 113 114 #define USB_PORT_STAT_CONNECTION 0x0001 // port state connection 115 #define USB_PORT_STAT_ENABLE 0x0002 // port state enable 116 #define USB_PORT_STAT_SUSPEND 0x0004 // port state suspend 117 #define USB_PORT_STAT_OVERCURRENT 0x0008 // port state over current 118 #define USB_PORT_STAT_RESET 0x0010 // port state reset 119 #define USB_PORT_STAT_POWER 0x0100 // port state power 120 #define USB_PORT_STAT_LOW_SPEED 0x0200 // port state low speed 121 #define USB_PORT_STAT_HIGH_SPEED 0x0400 // port state high speed 122 123 #define USB_PORT_STAT_C_CONNECTION 0x0001 // port clear port connection 124 #define USB_PORT_STAT_C_ENABLE 0x0002 // port clear port enable 125 #define USB_PORT_STAT_C_SUSPEND 0x0004 // port clear port suspend 126 #define USB_PORT_STAT_C_OVERCURRENT 0x0008 // port clear port over current 127 #define USB_PORT_STAT_C_RESET 0x0010 // port clear port reset 128 129 struct ms_usb_port_status { // port status 130 MS_U16 wPortStatus; 131 MS_U16 wPortChange; 132 } __attribute__((packed)); 133 134 struct ms_usb_hub_status { // hub status 135 MS_U16 wHubStatus; 136 MS_U16 wHubChange; 137 } __attribute__((packed)); 138 139 #define HUB_STATUS_LOCAL_POWER 0x0001 140 #define HUB_STATUS_OVERCURRENT 0x0002 141 #define HUB_CHANGE_LOCAL_POWER 0x0001 142 #define HUB_CHANGE_OVERCURRENT 0x0002 143 144 145 #define USB_DT_HUB (USB_TYPE_CLASS | 0x09) // hub descriptor 146 #define USB_DT_HUB_NONVAR_SIZE 7 147 148 struct usb_hub_descriptor { 149 MS_U8 bDescLength; 150 MS_U8 bDescriptorType; 151 MS_U8 bNbrPorts; 152 MS_U16 wHubCharacteristics; 153 MS_U8 bPwrOn2PwrGood; 154 MS_U8 bHubContrCurrent; 155 MS_U8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8 + 1]; // add 1 to prevent warning message 156 MS_U8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8 + 1]; 157 } __attribute__((packed)); 158 159 struct usb_device; 160 161 struct usb_tt { 162 struct usb_device *hub; 163 int multi; 164 MS_U32 think_time; 165 166 spinlock_t lock; 167 struct list_head clear_list; 168 }; 169 170 struct usb_tt_clear { 171 struct list_head clear_list; 172 MS_U32 tt; 173 MS_U16 devinfo; 174 }; 175 176 extern void ms_usb_hub_tt_clear_buffer (struct usb_device *ms_dev, int ms_pipe); 177 178 struct usb_hub { 179 struct usb_interface *intf; 180 struct urb *urb; 181 182 char (*buffer)[(USB_MAXCHILDREN + 1 + 7) / 8]; 183 dma_addr_t buffer_dma; 184 union { 185 struct ms_usb_hub_status hub; 186 struct ms_usb_port_status port; 187 }status; // shared by hub and port 188 189 int error; 190 int nerrors; 191 192 //struct list_head hub_list; 193 struct list_head event_list; 194 195 struct usb_hub_descriptor descriptor; 196 //struct semaphore khubd_sem; 197 struct usb_tt tt; 198 MS_U32 limited_power:1; 199 MS_U32 disconnected:1; 200 }; 201 202 #define HUB_RESET_TRIES 5 203 #define HUB_PROBE_TRIES 3 204 #define HUB_ROOT_RESET_TIME 50 205 #define HUB_SHORT_RESET_TIME 10 206 #define HUB_LONG_RESET_TIME 200 207 #define HUB_RESET_TIMEOUT 500 208 #define HUB_DEBOUNCE_STEP 25 209 #define HUB_DEBOUNCE_STABLE 4 // # of counts 210 211 struct s_vPortRange 212 { 213 MS_U32 vPortDevStart; 214 MS_U32 vPortDevEnd; 215 }; 216 217 218 struct stConnDevList 219 { 220 struct usb_device *connDev; 221 }; 222 223 /* root hub related variables */ 224 struct s_gVar4UsbPort 225 { 226 /* declaration initialized */ 227 char name[24]; 228 MS_U8 hostid; 229 struct s_vPortRange vPortRange; 230 char bus_name[24]; 231 char product_desc[24]; 232 MS_U8 *u8pHubStackBuffer; 233 char usb_mutex_name[24]; 234 /* not initial */ 235 struct list_head hub_event; // to support multiple root hub 236 struct cpe_dev cpe_ehci_dev; 237 struct usb_hcd *p_UsbHcd; // for MDrv_UsbDeviceConnect() 238 struct stConnDevList arConnDev[USB_MAXCHILDREN]; 239 MS_S32 _s32MutexUSB; // for critical section 240 int pid; // for Task delete 241 MS_BOOL taskRunning; // for Task delete 242 MS_BOOL taskFinish; // for Task delete 243 MS_BOOL bPark_ok; // for STR 244 }; 245 246 #ifdef ENABLE_XHC_COMPANION 247 struct xhc_comp { 248 MS_U8 port_index; 249 MS_U32 xhci_port_addr; 250 MS_U32 u3top_base; 251 MS_U32 u3phy_A_base; 252 MS_U32 u3phy_D_base; 253 }; 254 #endif 255 256 struct s_RegMap 257 { 258 MS_U32 iFlag; 259 MS_U32 baseUTMI; 260 MS_U32 baseUHC; 261 MS_U32 baseUSBC; 262 MS_U32 baseUSBBC; 263 InterruptNum uhcIRQ; 264 InterruptNum usbcIRQ; 265 #ifdef ENABLE_XHC_COMPANION 266 struct xhc_comp xhci; 267 #endif 268 }; 269 270 struct s_UsbcInfo 271 { 272 MS_U8 portNum; 273 MS_U8 int_pol; 274 MS_U16 intEn; 275 MS_U16 intSts; 276 MS_U8 eventFlag; 277 MS_U8 eventType; 278 }; 279 280 struct s_ChipUsbHostDef 281 { 282 MS_U8 chipID; 283 char name[24]; 284 MS_U8 nRootHub; 285 struct s_RegMap reg[NUM_OF_ROOT_HUB]; 286 struct s_gVar4UsbPort *p_roothub[NUM_OF_ROOT_HUB]; 287 struct s_UsbcInfo usbc_ip[NUM_OF_ROOT_HUB]; 288 MS_U8 u8Park; 289 }; 290 291 #endif 292