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
65 USB_DeviceConnected(hub, port->PortNum);
71 void USB_PortCtl_BeginReset(tUSBHub *Hub, int Port)
73 LOG("Starting %p %i", Hub, Port);
74 // Set status field in hub structure
75 Hub->Ports[Port].Status = 1;
76 Hub->Ports[Port].PortNum = Port;
77 // Add to the work queue
78 Workqueue_AddWork(&gUSB_PortCtl_WorkQueue, &Hub->Ports[Port]);
81 void USB_PortCtl_SetPortFeature(tUSBHub *Hub, int Port, int Feat)
83 if( Hub->Interface->Driver == NULL ) {
85 tUSBHost *host = Hub->Interface->Dev->Host;
86 ASSERT(host->HostDef->SetPortFeature);
87 host->HostDef->SetPortFeature(host->Ptr, Port, Feat);
91 Hub_SetPortFeature(Hub->Interface, Port, Feat);
95 void USB_PortCtl_ClearPortFeature(tUSBHub *Hub, int Port, int Feat)
97 if( Hub->Interface->Driver == NULL ) {
99 tUSBHost *host = Hub->Interface->Dev->Host;
100 ASSERT(host->HostDef->ClearPortFeature);
101 host->HostDef->ClearPortFeature(host->Ptr, Port, Feat);
105 Hub_ClearPortFeature(Hub->Interface, Port, Feat);
109 int USB_PortCtl_GetPortStatus(tUSBHub *Hub, int Port, int Flag)
111 if( Hub->Interface->Driver == NULL ) {
113 tUSBHost *host = Hub->Interface->Dev->Host;
114 ASSERT(host->HostDef->GetPortStatus);
115 return host->HostDef->GetPortStatus(host->Ptr, Port, Flag);
119 return Hub_GetPortStatus(Hub->Interface, Port, Flag);