PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
hub_resets.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include "usbdpriv.h"
12
13void usbdRebootInner(void)
14{
15 memPool->m_ohciRegs->HcRhPortStatus[0] = BIT(PORT_RESET);
16 memPool->m_ohciRegs->HcRhPortStatus[1] = BIT(PORT_RESET);
17}
18
19void hubResetDevice(UsbdDevice_t *dev)
20{
21 if ( memPool->m_delayResets )
22 {
23 dev->m_deviceStatus = DEVICE_RESETDELAYED;
24 }
25 else
26 {
27 memPool->m_delayResets = 1;
28 dev->m_deviceStatus = DEVICE_RESETPENDING;
29 dev->m_resetFlag = 1;
30 if ( dev->m_parent == memPool->m_deviceTreeRoot ) // root hub port
31 memPool->m_ohciRegs->HcRhPortStatus[dev->m_attachedToPortNo - 1] = BIT(PORT_RESET);
32 else // normal hub port
33 hubResetDevicePort(dev);
34 }
35}
36
37static int checkDelayedResetsTree(UsbdDevice_t *tree)
38{
39 UsbdDevice_t *dev;
40
41 for ( dev = tree->m_childListStart; dev; dev = dev->m_next )
42 {
43 if ( dev->m_deviceStatus == DEVICE_RESETDELAYED )
44 {
45 hubResetDevice(dev);
46 return 1;
47 }
48 if ( dev->m_childListStart )
49 {
50 if ( (u8)((int)dev->m_deviceStatus - 7) < 2u )
51 {
52 if ( checkDelayedResetsTree(dev) != 0 )
53 return 1;
54 }
55 }
56 }
57 return 0;
58}
59
60int checkDelayedResets(UsbdDevice_t *dev)
61{
62 memPool->m_delayResets = 0;
63 dev->m_resetFlag = 0;
64 checkDelayedResetsTree(memPool->m_deviceTreeRoot);
65 return 0;
66}
67
68void handleRhsc(void)
69{
70 u32 portNum;
71 UsbdDevice_t *port;
72 UsbdDevice_t *next;
73
74 for ( portNum = 0, port = memPool->m_deviceTreeRoot->m_childListStart; port; portNum += 1, port = next )
75 {
76 u32 status;
77
78 next = port->m_next;
79 status = memPool->m_ohciRegs->HcRhPortStatus[portNum];
80 memPool->m_ohciRegs->HcRhPortStatus[portNum] = C_PORT_FLAGS; // reset all flags
81 if ( (status & BIT(PORT_CONNECTION)) != 0 )
82 {
83 if ( port->m_deviceStatus >= (unsigned int)DEVICE_CONNECTED && ((status & BIT(C_PORT_CONNECTION)) != 0) )
84 flushPort(port);
85 if ( port->m_deviceStatus == DEVICE_NOTCONNECTED )
86 {
87 port->m_deviceStatus = DEVICE_CONNECTED;
88 addTimerCallback(&port->m_timer, (TimerCallback)hubResetDevice, port, 501);
89 }
90 else if ( port->m_deviceStatus == DEVICE_RESETPENDING )
91 {
92 if ( (status & BIT(PORT_RESET)) == 0 )
93 {
94 port->m_deviceStatus = DEVICE_RESETCOMPLETE;
95 port->m_isLowSpeedDevice = (status & BIT(PORT_LOW_SPEED)) != 0;
96 if ( openDeviceEndpoint(port, NULL, 0) )
97 hubTimedSetFuncAddress(port);
98 }
99 }
100 }
101 else
102 {
103 flushPort(port);
104 }
105 }
106}