3 * - By John Hodge (thePowersGang)
12 #include <workqueue.h>
17 void USB_PortCtl_Init(void);
18 void USB_PortCtl_Worker(void *Unused);
19 void USB_PortCtl_SetPortFeature(tUSBHub *Hub, int Port, int Feat);
20 void USB_PortCtl_ClearPortFeature(tUSBHub *Hub, int Port, int Feat);
21 int USB_PortCtl_GetPortStatus(tUSBHub *Hub, int Port, int Flag);
24 tWorkqueue gUSB_PortCtl_WorkQueue;
27 void USB_PortCtl_Init(void)
29 Workqueue_Init(&gUSB_PortCtl_WorkQueue, "USB Port Reset Work Queue", offsetof(tUSBHubPort, ListNext));
30 Proc_SpawnWorker(USB_PortCtl_Worker, NULL);
33 void USB_PortCtl_Worker(void *Unused)
35 Threads_SetName("USB PortCtl Worker");
41 port = Workqueue_GetWork(&gUSB_PortCtl_WorkQueue);
43 Log_Warning("USB", "PortCtl Workqueue returned NULL");
46 hub = (tUSBHub*)(port - port->PortNum) - 1;
48 LOG("port = %p, hub = %p", port, hub);
54 USB_PortCtl_SetPortFeature(hub, port->PortNum, PORT_RESET);
55 LOG("Port reset starting");
58 USB_PortCtl_ClearPortFeature(hub, port->PortNum, PORT_RESET);
59 Time_Delay(10); // May take up to 2ms for reset to clear
62 USB_PortCtl_SetPortFeature(hub, port->PortNum, PORT_ENABLE);
63 // Begin connect processing
64 LOG("Reset complete, marking connection");
66 USB_DeviceConnected(hub, port->PortNum);
69 Log_Warning("USB", "PortCtl worker: Unknown port state %i",
76 void USB_PortCtl_BeginReset(tUSBHub *Hub, int Port)
78 LOG("Starting %p %i", Hub, Port);
79 // Set status field in hub structure
80 Hub->Ports[Port].Status = 1;
81 Hub->Ports[Port].PortNum = Port;
82 // Add to the work queue
83 Workqueue_AddWork(&gUSB_PortCtl_WorkQueue, &Hub->Ports[Port]);
87 void USB_PortCtl_SetPortFeature(tUSBHub *Hub, int Port, int Feat)
89 if( Hub->Interface->Driver == NULL ) {
91 tUSBHost *host = Hub->Interface->Dev->Host;
92 ASSERT(host->HostDef->SetPortFeature);
93 host->HostDef->SetPortFeature(host->Ptr, Port, Feat);
97 Hub_SetPortFeature(Hub->Interface, Port, Feat);
101 void USB_PortCtl_ClearPortFeature(tUSBHub *Hub, int Port, int Feat)
103 if( Hub->Interface->Driver == NULL ) {
105 tUSBHost *host = Hub->Interface->Dev->Host;
106 ASSERT(host->HostDef->ClearPortFeature);
107 host->HostDef->ClearPortFeature(host->Ptr, Port, Feat);
111 Hub_ClearPortFeature(Hub->Interface, Port, Feat);
115 int USB_PortCtl_GetPortStatus(tUSBHub *Hub, int Port, int Flag)
117 if( Hub->Interface->Driver == NULL ) {
119 tUSBHost *host = Hub->Interface->Dev->Host;
120 ASSERT(host->HostDef->GetPortStatus);
121 return host->HostDef->GetPortStatus(host->Ptr, Port, Flag);
125 return Hub_GetPortStatus(Hub->Interface, Port, Flag);