Merge branch 'master' of git://localhost/acess2
[tpg/acess2.git] / KernelLand / Modules / USB / Core / hub.c
index 69599e1..23f3a36 100644 (file)
@@ -5,7 +5,7 @@
  * hub.c
  * - Basic hub driver
  */
-#define DEBUG  1
+#define DEBUG  0
 #include <usb_hub.h>
 #include <timers.h>
 
 // resvd
 #define SET_FEATURE    3
 
-#define PORT_CONNECTION        0
-#define PORT_ENABLE    1
-#define PORT_SUSPEND   2
-#define PORT_OVER_CURRENT      3
-#define PORT_RESET     4
-#define PORT_POWER     8
-#define PORT_LOW_SPEED 9
-#define C_PORT_CONNECTION      16
-#define C_PORT_ENABLE  17
-#define C_PORT_SUSPEND 18
-#define C_PORT_OVER_CURRENT    19
-#define C_PORT_RESET   20
-#define PORT_TEST      21
-#define PORT_INDICATOR 21
-
 struct sHubDescriptor
 {
        Uint8   DescLength;
@@ -56,6 +41,9 @@ void  Hub_Connected(tUSBInterface *Dev, void *Descriptors, size_t Length);
 void   Hub_Disconnected(tUSBInterface *Dev);
 void   Hub_PortStatusChange(tUSBInterface *Dev, int Endpoint, int Length, void *Data);
 void   Hub_int_HandleChange(tUSBInterface *Dev, int Port);
+void   Hub_SetPortFeature(tUSBInterface *Dev, int Port, int Feat);
+void   Hub_ClearPortFeature(tUSBInterface *HubDev, int Port, int Feat);
+int    Hub_GetPortStatus(tUSBInterface *HubDev, int Port, int Flag);
 
 // === GLOBALS ===
 tUSBDriver     gUSBHub_Driver = {
@@ -123,8 +111,9 @@ void Hub_PortStatusChange(tUSBInterface *Dev, int Endpoint, int Length, void *Da
        for( i = 0; i < info->nPorts; i += 8, status ++ )
        {
                if( i/8 >= Length )     break;
-               if( *status == 0 )      continue;
-       
+               LOG("status[%i] = %x", i/8, *status);
+               if( *status == 0 )      continue;       
+
                for( int j = 0; j < 8; j ++ )
                        if( *status & (1 << j) )
                                Hub_int_HandleChange(Dev, i+j);
@@ -149,13 +138,8 @@ void Hub_int_HandleChange(tUSBInterface *Dev, int Port)
                        // - Power on port
                        USB_Request(Dev, 0, 0x23, SET_FEATURE, PORT_POWER, Port, 0, NULL);
                        Time_Delay(info->PowerOnDelay);
-                       // - Reset
-                       USB_Request(Dev, 0, 0x23, SET_FEATURE, PORT_RESET, Port, 0, NULL);
-                       Time_Delay(20); // Spec says 10ms after reset, but how long is reset?
-                       // - Enable
-                       USB_Request(Dev, 0, 0x23, SET_FEATURE, PORT_ENABLE, Port, 0, NULL);
-                       // - Poke USB Stack
-                       USB_DeviceConnected(info->HubPtr, Port);
+                       // - Start reset process
+                       USB_PortCtl_BeginReset(info->HubPtr, Port);
                }
                else {
                        // Disconnected
@@ -178,3 +162,20 @@ void Hub_int_HandleChange(tUSBInterface *Dev, int Port)
                USB_Request(Dev, 0, 0x23, CLEAR_FEATURE, C_PORT_RESET, Port, 0, NULL);
        }
 }
+
+void Hub_SetPortFeature(tUSBInterface *Dev, int Port, int Feat)
+{
+       USB_Request(Dev, 0, 0x23, SET_FEATURE, Feat, Port, 0, NULL);
+}
+
+void Hub_ClearPortFeature(tUSBInterface *Dev, int Port, int Feat)
+{
+       USB_Request(Dev, 0, 0x23, CLEAR_FEATURE, Feat, Port, 0, NULL);
+}
+
+int Hub_GetPortStatus(tUSBInterface *Dev, int Port, int Flag)
+{
+       Uint16  status[2];      // Status, Change
+       USB_Request(Dev, 0, 0xA3, GET_STATUS, 0, Port, 4, status);
+       return !!(status[0] & (1 << Flag));
+}

UCC git Repository :: git.ucc.asn.au