;COMMENT /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;************************************************************************** ;** ** ;** I N T E L P R O P R I E T A R Y ** ;** ** ;** COPYRIGHT (c) 1996, 1997 BY INTEL CORPORATION. ALL RIGHTS ** ;** RESERVED. NO PART OF THIS PROGRAM OR PUBLICATION MAY ** ;** BE REPRODUCED, TRANSMITTED, TRANSCRIBED, STORED IN A ** ;** RETRIEVAL SYSTEM, OR TRANSLATED INTO ANY LANGUAGE OR COMPUTER ** ;** LANGUAGE IN ANY FORM OR BY ANY MEANS, ELECTRONIC, MECHANICAL, ** ;** MAGNETIC, OPTICAL, CHEMICAL, MANUAL, OR OTHERWISE, WITHOUT ** ;** THE PRIOR WRITTEN PERMISSION OF : ** ;** ** ;** INTEL CORPORATION ** ;** ** ;** 2200 MISSON COLLEGE BLVD ** ;** ** ;** SANTA CLARA, CALIFORNIA 95052-8119 ** ;** ** ;**$Author: kschultz $ ;**$Modtime: 09 Sep 1996 13:42:48 $ ;**$Revision: 1.0 $ ; Chl addede 7/24 status stage to ReturnSetClassDevice: ;************************************************************************** INCLUDE "8x931HX.INC" INCLUDE "SWITCH.INC" ;Changes Desired. ;HSTAT, move EP1STL to bit 6 to make it equal to other endpoints ;Does it make since ot put EP1EN at bit 0 for same reason? public GetClassDeviceCommand public GetClassOtherCommand public SetClassDeviceCommand public SetClassOtherCommand public InitilizeHubVariables extern bRequest:DATA, wValue:DATA, wIndex:DATA extern gbFControlBufferLocation:DATA extern LoadBuffer:CODE extern init_serial, putc_ser, putret_ser, puts_ser, putc_hex_ser extern InitializeEmbeddedFunction:CODE, SV_ResetRoutine DEFINE HUB_CODE_SEGMENT, SPACE=CODE SEGMENT HUB_CODE_SEGMENT COMMENT *------------------------------------------------------------ Function name : InitilizeHubVariables Brief Description : This routine simply initlizes the Repeater Code varaibles : right now. Not other vaibles are used. Regs preserved : No reg. is saved --------------------------------------------------------------------* InitilizeHubVariables: lcall SV_ResetRoutine ret COMMENT *------------------------------------------------------------ Function name : GetHubClassDeviceCommand Brief Description : Processes a Get Hub Class Device Command : All data from this is written into the FIFO : and the proper count is written to TXCNT. Regs preserved : No reg. is saved Regs Used : A --------------------------------------------------------------------* SCOPE GetClassDeviceCommand: GetHubClassDeviceCommand: mov A, bRequest cjne A, #GET_DESCRIPTOR, ?CheckGetHubStatus GetHubDescriptor: ; The following code just enables/disables the embeded ; downstream port. ; It also hides the changes from the ; the host clering the status change bits. ; chl added back in on 7/22 mov A, SWITCH_PORT jb ACC.ATTACHED_BIT, LEAVE_CONNECTED push HPINDEX mov HPINDEX, #EMBEDDED_PORT_NUMBER anl HPSC, #00h pop HPINDEX LEAVE_CONNECTED: ; ********************** GET DESCRIPTOR, HUB ******************* mov A, SWITCH_PORT jb ACC.ATTACHED_BIT, GiveAttachedDescriptor GiveUnattachedDescriptor: ; Descriptor 0 mov gbFControlBufferLocation+0, #HIGH (BEGIN_HUB_DESCRIPTOR0) mov gbFControlBufferLocation+1, #LOW (BEGIN_HUB_DESCRIPTOR0) sjmp JUMP_HERE GiveAttachedDescriptor: ; Descriptor 1 mov gbFControlBufferLocation+0, #HIGH (BEGIN_HUB_DESCRIPTOR1) mov gbFControlBufferLocation+1, #LOW (BEGIN_HUB_DESCRIPTOR1) JUMP_HERE: mov A, #LOW (END_HUB_DESCRIPTOR1 - BEGIN_HUB_DESCRIPTOR1) ; they are both the same length mov B, #HIGH (END_HUB_DESCRIPTOR1 - BEGIN_HUB_DESCRIPTOR1) ljmp LoadBuffer ?CheckGetHubStatus: cjne A , #GET_STATUS, ReturnGetClassDevice GetHubStatus: ;------------------------------------------------ ;- GET HUB STATUS ;------------------------------------------------ mov A , HSTAT anl A , #03h mov TXDAT, A mov TXDAT, #0 mov A , HSTAT RR A RR A anl A , #03 mov TXDAT, A mov TXDAT, #0 mov TXCNTL, #4 sjmp ReturnGetClassDevice ReturnGetClassDevice: ret COMMENT *------------------------------------------------------------ Function name : GetClassOtherCommand Brief Description : This routine executes two commands. : GetBusState Retuns 1 byte of status information : GetPortStatus Retuns a 4 byte of status information Regs preserved : No reg. is saved Regs Used : A --------------------------------------------------------------------* SCOPE GetClassOtherCommand: mov A , bRequest cjne A , #GET_STATUS, ?CheckGetBusState ;------------------------------------------------ ;- GET PORT STATUS ;- Brief Description : Returns 4 byte bus status ;------------------------------------------------ GetPortStatus: push B push HPINDEX mov HPINDEX, wIndex+1 ; Select the disired port to get the data from. ; wPortStatus First ; If this is a HongKong then make the host ; think that this port is permanantly disabled ; by returning te status values showing disconnected. mov A, wIndex+1 cjne A, #EMBEDDED_PORT_NUMBER, NotInternalPort mov A, SWITCH_PORT jb ACC.ATTACHED_BIT, NotInternalPort ; If it's attached, treat as normal port. ; otherwise show disonnected SHOW_DISCONNECT: mov TXDAT, #00h mov TXDAT, #01h mov TXDAT, #00h mov TXDAT, #00h mov TXCNTL, #04h sjmp DoneGetPortStatus NotInternalPort: mov A , HPSTAT ; Get the first byte of wPortStatus mov B, A anl A , #07h jnb B.PRSTAT_BIT, ?FirstByteDone orl A , #10h ?FirstByteDone: mov TXDAT, A ; Load first byte into FIFO ; DO SECOND BYTE mov A, #00h jnb B.PPSTAT_BIT, ?Check_LS ; If the PP bit set, then set the corresponding ; value in the report orl A , #01h ?Check_LS: jnb B.LSSTAT_BIT, ?SendByte2 ; If the LS bit set, then set the corresponding orl A , #02h ; value in the report ?SendByte2: mov TXDAT, A ; DO THIRD BYTE ; Now get the LSB of the wPortChange byte ?GetwPortChange: mov A , HPSC anl A , #1Fh mov TXDAT, A mov TXDAT, #0 mov TXCNTL, #4h DoneGetPortStatus: pop HPINDEX ; Restore the index pop B jmp ReturnGetClassOther ?CheckGetBusState: cjne A , #GET_STATE, ReturnBadGetClassOtherCommand ;------------------------------------------------ ;- GET BUS STATE ;- Brief Description : Returns bus state, Bit 0 = V-, Bit 1 = V+ ;------------------------------------------------ GetBusState: push HPINDEX mov HPINDEX, wIndex+1 ; Select the disired port to get the data from. mov A, HPSTAT RL A RL A anl A, #03h mov TXDAT, A mov TXCNTL, #1h pop HPINDEX sjmp ReturnGetClassOther ReturnBadGetClassOtherCommand: ReturnGetClassOther: ret COMMENT *------------------------------------------------------------ Function name : SetClassDeviceCommand Brief Description : Sets & Clears the hub featues. : ClearHubFeature : SetHubFeature : Regs preserved : No reg. is saved Regs Used : A --------------------------------------------------------------------* SCOPE SetClassDeviceCommand: mov A , bRequest cjne A , #CLEAR_FEATURE, CheckSetHubFeature ClearHubFeature: mov A , wValue+1 ; Get Feature Selector CheckLocalPower: cjne A , #C_HUB_LOCAL_POWER, CheckOverCurrent ; Not supported on this chip , just return jmp ReturnSetClassDevice CheckOverCurrent: cjne A , #C_HUB_OVER_CURRENT, ReturnBadSetClassDeviceCommand anl HSTAT, #CLEAR_OVISC_MASK jmp ReturnSetClassDevice CheckSetHubFeature: ; There is no such thing as a SetHubFeature ; since there are no Hub Features that can be set. SetHubFeature: ReturnBadSetClassDeviceCommand: jmp BadCommandStatus ReturnSetClassDevice: mov TXCNTL, #00h ; status stage ret COMMENT *------------------------------------------------------------ Function name : SetClassOtherCommand Brief Description : Excutes either a SetPortFeature or ClearPortFeature : These routines are called via a jump to reduce : stack size Regs preserved : No reg. is saved Regs Used : A --------------------------------------------------------------------* SCOPE SetClassOtherCommand: mov A , bRequest cjne A , #CLEAR_FEATURE, CheckSetHubOtherFeature jmp ClearPortFeature CheckSetHubOtherFeature: cjne A , #SET_FEATURE, ReturnBadSetClassOtherCommand jmp SetPortFeature ReturnBadSetClassOtherCommand: jmp BadCommandStatus COMMENT *------------------------------------------------------------ Function name : ClearPortFeature Brief Description : Clears the feature contained in R0 = LSB of wValue Regs preserved : No reg. is saved --------------------------------------------------------------------* SCOPE ClearPortFeature: push HPINDEX ; Save the current port - Restored in GoodHandshakeStatus mov HPINDEX, wIndex+1 ; Select the disired port to get the data from. mov A , wValue+1 ; Get Feature Selector ClearPortConnection: ; Not Used as this is hardwired CheckClearPortEable: cjne A , #PORT_ENABLE, CheckClearPortSuspend mov HPCON, #DISABLE_PORT_CMD jmp GoodNoDataCommandStatus CheckClearPortSuspend: cjne A , #PORT_SUSPEND, CheckClearPortPower mov A , wIndex+1 ; Get the port to suspend. ; If it's the internal one call ; the function routine to do the ; resume call. cjne A , #EMBEDDED_PORT_NUMBER, Clear1 ;-------------------------------------------- ; EMBEDDED RESUME ; Call the embedded function and have it wake ; up as well. ;-------------------------------------------- Call DoEmbeddedResume Clear1: mov HPCON, #RESUME_PORT_CMD jmp GoodNoDataCommandStatus CheckClearPortPower: cjne A , #PORT_POWER, CheckClearPortConnectionSC push ACC ; Save ACC mov ACC, HPINDEX ; HPINDEX would have been set ; before comming into this routine. add A, #2 movc A, @A+PC ; ; sjmp ClearPortPower clearPortPowerMasks: db 0FFh ; 0 = Bit 0 = Port 0, Illegal but we will ignore it. db 0FDh ; 1 = Bit 1 = Port 1,- Embedded Port db 0FBh ; 2 = Bit 2 = Port 2, db 0F7h ; 3 = Bit 3 = Port 3 db 0EFh ; 4 = Bit 4 = Port 4 db 0DFh ; 5 = Bit 5 = Port 4 ClearPortPower: anl HPPWR, A ; Use mask to turn off port. pop ACC jmp GoodNoDataCommandStatus CheckClearPortConnectionSC: cjne A, #C_PORT_CONNECTION, CheckClearPortEnableSC anl HPSC, #CLEAR_PCSC_MASK jmp GoodNoDataCommandStatus CheckClearPortEnableSC: cjne A, #C_PORT_ENABLE, CheckClearPortSuspendSC anl HPSC, #CLEAR_PESC_MASK jmp GoodNoDataCommandStatus CheckClearPortSuspendSC: cjne A, #C_PORT_SUSPEND, CheckClearPortResetSC anl HPSC, #CLEAR_PSSC_MASK jmp GoodNoDataCommandStatus CheckClearPortResetSC: cjne A, #C_PORT_RESET, CheckClearPortOVRISC anl HPSC, #CLEAR_RSTSC_MASK jmp GoodNoDataCommandStatus CheckClearPortOVRISC: cjne A, #C_PORT_OVER_CURRENT, IllegalFeatureSelector anl HPSC, #CLEAR_OVISC_MASK jmp GoodNoDataCommandStatus IllegalFeatureSelector: Jmp BadCommandStatus COMMENT *------------------------------------------------------------ Function name : SetPortFeature Brief Description : Sets the feature contained in R0 = LSB of wValue Regs preserved : HPINDEX --------------------------------------------------------------------* SCOPE SetPortFeature: push HPINDEX ; Save the current port-Restored in GoodHandshakeStatus mov HPINDEX, wIndex+1 ; Select the disired port to get the data from. mov A, wValue+1 ; Get Feature Selector ?CheckSetPortEable: cjne A, #PORT_ENABLE, ?CheckSetPortSuspend mov HPCON, #ENABLE_PORT_CMD jmp GoodNoDataCommandStatus ?CheckSetPortSuspend: cjne A, #PORT_SUSPEND, ?CheckSetPortReset mov A, HPINDEX cjne A, #EMBEDDED_PORT_NUMBER, Set1 ;-------------------------------------------- ; EMBEDDED SUSPEND ; Call the embedded function and have it go to ; sleep. ;-------------------------------------------- Call DoEmbeddedSuspend Set1: mov HPCON, #SUSPEND_PORT_CMD jmp GoodNoDataCommandStatus ?CheckSetPortReset: cjne A, #PORT_RESET, ?CheckSetPortPower mov HPCON, #RESET_ENABLE_PORT_CMD ; DO the reset. mov A, HPINDEX ; Now if this is 1(HongKong), then wait for the reset ; to complete and then call the software reset ; which will configure the hardware as well. cjne A, #EMBEDDED_PORT_NUMBER, Set2 ; EMBEDDED RESET ; Reset the embedded function ; Tell it to change its ways or else ResetDoneWaitLoop: mov A, HPSTAT jnb ACC.PRSTAT_BIT, ResetDoneWaitLoop ; Wait for reset to be applied. ; This will happen at EOF. ; Since the embedded function will ; actually reset at EOF and clear all ; of the USB registers. ; This loop is here so we can tell ; when it's safe to initilize the registers. lcall InitializeEmbeddedFunction ; Init the embedded function. Set2: jmp GoodNoDataCommandStatus ?CheckSetPortPower: cjne A, #PORT_POWER, BadCommandStatus push ACC ; Save ACC mov ACC, HPINDEX ; HPINDEX would have been set ; before comming into this routine. add A, #2 movc A, @A+PC sjmp SetPortPower SetPortPowerMasks: db 000h ; 0 = Bit 0 = Port 0, Illegal but we will ignore it. db 002h ; 1 = Bit 1 = Port 1, = Embedded Port db 004h ; 2 = Bit 2 = Port 2, db 008h ; 3 = Bit 3 = Port 3 db 010h ; 4 = Bit 4 = Port 4 db 020h ; 5 = Bit 5 = Port 5 nop ; to help the disassembler out. SetPortPower: orl HPPWR, A ; Use mask to shut off port. pop ACC jmp GoodNoDataCommandStatus GoodNoDataCommandStatus: pop HPINDEX mov TXCNTL, #0h ret BadCommandStatus: orl EPCON, #0C0h ; stall it pop HPINDEX ret DoEmbeddedResume: ret DoEmbeddedSuspend: ret DoEmbeddedReset: ret ;************************************************************************ ;************* HUB DESCRIPTOR **************************************** ;************************************************************************ ; ; NOTE!!!!! '251 is a Big Endian machine. Words and DWords are stored with the ; LSB in the numerically higher address. ; ;******************************************************************* ;********* Standalone Hub ***************************************** ;******************************************************************* BEGIN_HUB_DESCRIPTOR0: gHub0_bLength: db END_HUB_DESCRIPTOR0-BEGIN_HUB_DESCRIPTOR0 gHub0_bDescriptorType: db HUB_DESCR gHub0_NumPorts: db 05h ; Supports 5 ports, 4 external & 1 internal gHub0_wHubCharacteristics: dw 00h ; Ganged Power, NotCompound, Gloabl OverIProct gHub0_bPwrOn2PwrGood: db 016h ; Approx 40mSecs for Power to stabalize gHub0_bHubConrCurrent: db 100d ; 100 milliamps gHub0_bDeviceRemovable: db 002h ; P1,2,3,4,5 Removable, P4 not removable gHub0_bPortPwrCtrlMask: db 0h ; All ports respond to Ganged Power Commands END_HUB_DESCRIPTOR0: ;******************************************************************* ;********* Hub with embedded function ***************************** ;******************************************************************* BEGIN_HUB_DESCRIPTOR1: gHub1_bLength: db END_HUB_DESCRIPTOR1-BEGIN_HUB_DESCRIPTOR1 gHub1_bDescriptorType: db HUB_DESCR gHub1_NumPorts: db 05h ; Supports 5 ports, 4 external & 1 internal gHub1_wHubCharacteristics: dw 00h ; Ganged Power, NotCompound, Gloabl OverIProct gHub1_bPwrOn2PwrGood: db 016h ; Approx 40mSecs for Power to stabalize gHub1_bHubConrCurrent: db 100d ; 100 milliamps gHub1_bDeviceRemovable: db 002h ; P1 not removable gHub1_bPortPwrCtrlMask: db 002h ; All ports respond to Ganged Power Commands END_HUB_DESCRIPTOR1: OVRI_MSG: db "Attempting to clear over current .... !", CR,LF,NUL HSTAT_BEFORE_CLEAR:db " Value of HSTAT before clearing OVISC bit: ",NUL HSTAT_AFTER_CLEAR:db " Value of HSTAT after clearing OVISC bit: ",NUL END