~ubuntu-branches/ubuntu/saucy/u-boot/saucy

« back to all changes in this revision

Viewing changes to common/usb.c

  • Committer: Package Import Robot
  • Author(s): Clint Adams
  • Date: 2012-05-01 18:07:19 UTC
  • mfrom: (16.1.23 sid)
  • Revision ID: package-import@ubuntu.com-20120501180719-rjntk3287im4a0ns
Tags: 2012.04.01-1
* New upstream version.
  - Update mipsel-native-endianness.diff.
  - Update no-error-on-set-but-unused-variables.diff (partially merged).
  - Drop kirkwood_spi-irq_mask.diff (merged).
  - Drop kirkwood-disable-l2c.diff (merged).

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
static int dev_index;
74
74
static int running;
75
75
static int asynch_allowed;
76
 
static struct devrequest setup_packet;
77
76
 
78
77
char usb_started; /* flag for the started/stopped USB status */
79
78
 
80
79
/**********************************************************************
81
80
 * some forward declerations...
82
81
 */
83
 
void usb_scan_devices(void);
84
 
 
85
 
int usb_hub_probe(struct usb_device *dev, int ifnum);
86
 
void usb_hub_reset(void);
87
 
static int hub_port_reset(struct usb_device *dev, int port,
88
 
                          unsigned short *portstat);
89
 
 
90
 
/***********************************************************************
91
 
 * wait_ms
92
 
 */
93
 
 
94
 
inline void wait_ms(unsigned long ms)
95
 
{
96
 
        while (ms-- > 0)
97
 
                udelay(1000);
98
 
}
 
82
static void usb_scan_devices(void);
99
83
 
100
84
/***************************************************************************
101
85
 * Init USB Device
185
169
                        unsigned short value, unsigned short index,
186
170
                        void *data, unsigned short size, int timeout)
187
171
{
 
172
        struct devrequest setup_packet;
 
173
 
188
174
        if ((timeout == 0) && (!asynch_allowed)) {
189
175
                /* request for a asynch control pipe is not allowed */
190
176
                return -1;
213
199
        while (timeout--) {
214
200
                if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
215
201
                        break;
216
 
                wait_ms(1);
 
202
                mdelay(1);
217
203
        }
218
204
        if (dev->status)
219
205
                return -1;
237
223
        while (timeout--) {
238
224
                if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
239
225
                        break;
240
 
                wait_ms(1);
 
226
                mdelay(1);
241
227
        }
242
228
        *actual_length = dev->act_len;
243
229
        if (dev->status == 0)
316
302
/*
317
303
 * set the max packed value of all endpoints in the given configuration
318
304
 */
319
 
int usb_set_maxpacket(struct usb_device *dev)
 
305
static int usb_set_maxpacket(struct usb_device *dev)
320
306
{
321
307
        int i, ii;
322
308
 
331
317
 * Parse the config, located in buffer, and fills the dev->config structure.
332
318
 * Note that all little/big endian swapping are done automatically.
333
319
 */
334
 
int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
 
320
static int usb_parse_config(struct usb_device *dev,
 
321
                        unsigned char *buffer, int cfgno)
335
322
{
336
323
        struct usb_descriptor_header *head;
337
324
        int index, ifno, epno, curr_if_num;
450
437
/**********************************************************************
451
438
 * get_descriptor type
452
439
 */
453
 
int usb_get_descriptor(struct usb_device *dev, unsigned char type,
 
440
static int usb_get_descriptor(struct usb_device *dev, unsigned char type,
454
441
                        unsigned char index, void *buf, int size)
455
442
{
456
443
        int res;
500
487
 * set address of a device to the value in dev->devnum.
501
488
 * This can only be done by addressing the device via the default address (0)
502
489
 */
503
 
int usb_set_address(struct usb_device *dev)
 
490
static int usb_set_address(struct usb_device *dev)
504
491
{
505
492
        int res;
506
493
 
553
540
/********************************************************************
554
541
 * set configuration number to configuration
555
542
 */
556
 
int usb_set_configuration(struct usb_device *dev, int configuration)
 
543
static int usb_set_configuration(struct usb_device *dev, int configuration)
557
544
{
558
545
        int res;
559
546
        USB_PRINTF("set configuration %d\n", configuration);
616
603
/********************************************************************
617
604
 * get string index in buffer
618
605
 */
619
 
int usb_get_string(struct usb_device *dev, unsigned short langid,
 
606
static int usb_get_string(struct usb_device *dev, unsigned short langid,
620
607
                   unsigned char index, void *buf, int size)
621
608
{
622
609
        int i;
900
887
                return 1;
901
888
        }
902
889
 
903
 
        wait_ms(10);    /* Let the SET_ADDRESS settle */
 
890
        mdelay(10);     /* Let the SET_ADDRESS settle */
904
891
 
905
892
        tmp = sizeof(dev->descriptor);
906
893
 
954
941
}
955
942
 
956
943
/* build device Tree  */
957
 
void usb_scan_devices(void)
 
944
static void usb_scan_devices(void)
958
945
{
959
946
        int i;
960
947
        struct usb_device *dev;
978
965
        USB_PRINTF("scan end\n");
979
966
}
980
967
 
981
 
 
982
 
/****************************************************************************
983
 
 * HUB "Driver"
984
 
 * Probes device for being a hub and configurate it
985
 
 */
986
 
 
987
 
static struct usb_hub_device hub_dev[USB_MAX_HUB];
988
 
static int usb_hub_index;
989
 
 
990
 
 
991
 
int usb_get_hub_descriptor(struct usb_device *dev, void *data, int size)
992
 
{
993
 
        return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
994
 
                USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB,
995
 
                USB_DT_HUB << 8, 0, data, size, USB_CNTL_TIMEOUT);
996
 
}
997
 
 
998
 
int usb_clear_hub_feature(struct usb_device *dev, int feature)
999
 
{
1000
 
        return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1001
 
                                USB_REQ_CLEAR_FEATURE, USB_RT_HUB, feature,
1002
 
                                0, NULL, 0, USB_CNTL_TIMEOUT);
1003
 
}
1004
 
 
1005
 
int usb_clear_port_feature(struct usb_device *dev, int port, int feature)
1006
 
{
1007
 
        return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1008
 
                                USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature,
1009
 
                                port, NULL, 0, USB_CNTL_TIMEOUT);
1010
 
}
1011
 
 
1012
 
int usb_set_port_feature(struct usb_device *dev, int port, int feature)
1013
 
{
1014
 
        return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1015
 
                                USB_REQ_SET_FEATURE, USB_RT_PORT, feature,
1016
 
                                port, NULL, 0, USB_CNTL_TIMEOUT);
1017
 
}
1018
 
 
1019
 
int usb_get_hub_status(struct usb_device *dev, void *data)
1020
 
{
1021
 
        return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
1022
 
                        USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_HUB, 0, 0,
1023
 
                        data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT);
1024
 
}
1025
 
 
1026
 
int usb_get_port_status(struct usb_device *dev, int port, void *data)
1027
 
{
1028
 
        return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
1029
 
                        USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port,
1030
 
                        data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT);
1031
 
}
1032
 
 
1033
 
 
1034
 
static void usb_hub_power_on(struct usb_hub_device *hub)
1035
 
{
1036
 
        int i;
1037
 
        struct usb_device *dev;
1038
 
 
1039
 
        dev = hub->pusb_dev;
1040
 
        /* Enable power to the ports */
1041
 
        USB_HUB_PRINTF("enabling power on all ports\n");
1042
 
        for (i = 0; i < dev->maxchild; i++) {
1043
 
                usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
1044
 
                USB_HUB_PRINTF("port %d returns %lX\n", i + 1, dev->status);
1045
 
                wait_ms(hub->desc.bPwrOn2PwrGood * 2);
1046
 
        }
1047
 
}
1048
 
 
1049
 
void usb_hub_reset(void)
1050
 
{
1051
 
        usb_hub_index = 0;
1052
 
}
1053
 
 
1054
 
struct usb_hub_device *usb_hub_allocate(void)
1055
 
{
1056
 
        if (usb_hub_index < USB_MAX_HUB)
1057
 
                return &hub_dev[usb_hub_index++];
1058
 
 
1059
 
        printf("ERROR: USB_MAX_HUB (%d) reached\n", USB_MAX_HUB);
1060
 
        return NULL;
1061
 
}
1062
 
 
1063
 
#define MAX_TRIES 5
1064
 
 
1065
 
static inline char *portspeed(int portstatus)
1066
 
{
1067
 
        if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED))
1068
 
                return "480 Mb/s";
1069
 
        else if (portstatus & (1 << USB_PORT_FEAT_LOWSPEED))
1070
 
                return "1.5 Mb/s";
1071
 
        else
1072
 
                return "12 Mb/s";
1073
 
}
1074
 
 
1075
 
static int hub_port_reset(struct usb_device *dev, int port,
1076
 
                        unsigned short *portstat)
1077
 
{
1078
 
        int tries;
1079
 
        struct usb_port_status portsts;
1080
 
        unsigned short portstatus, portchange;
1081
 
 
1082
 
        USB_HUB_PRINTF("hub_port_reset: resetting port %d...\n", port);
1083
 
        for (tries = 0; tries < MAX_TRIES; tries++) {
1084
 
 
1085
 
                usb_set_port_feature(dev, port + 1, USB_PORT_FEAT_RESET);
1086
 
                wait_ms(200);
1087
 
 
1088
 
                if (usb_get_port_status(dev, port + 1, &portsts) < 0) {
1089
 
                        USB_HUB_PRINTF("get_port_status failed status %lX\n",
1090
 
                                        dev->status);
1091
 
                        return -1;
1092
 
                }
1093
 
                portstatus = le16_to_cpu(portsts.wPortStatus);
1094
 
                portchange = le16_to_cpu(portsts.wPortChange);
1095
 
 
1096
 
                USB_HUB_PRINTF("portstatus %x, change %x, %s\n",
1097
 
                                portstatus, portchange,
1098
 
                                portspeed(portstatus));
1099
 
 
1100
 
                USB_HUB_PRINTF("STAT_C_CONNECTION = %d STAT_CONNECTION = %d" \
1101
 
                               "  USB_PORT_STAT_ENABLE %d\n",
1102
 
                        (portchange & USB_PORT_STAT_C_CONNECTION) ? 1 : 0,
1103
 
                        (portstatus & USB_PORT_STAT_CONNECTION) ? 1 : 0,
1104
 
                        (portstatus & USB_PORT_STAT_ENABLE) ? 1 : 0);
1105
 
 
1106
 
                if ((portchange & USB_PORT_STAT_C_CONNECTION) ||
1107
 
                    !(portstatus & USB_PORT_STAT_CONNECTION))
1108
 
                        return -1;
1109
 
 
1110
 
                if (portstatus & USB_PORT_STAT_ENABLE)
1111
 
                        break;
1112
 
 
1113
 
                wait_ms(200);
1114
 
        }
1115
 
 
1116
 
        if (tries == MAX_TRIES) {
1117
 
                USB_HUB_PRINTF("Cannot enable port %i after %i retries, " \
1118
 
                                "disabling port.\n", port + 1, MAX_TRIES);
1119
 
                USB_HUB_PRINTF("Maybe the USB cable is bad?\n");
1120
 
                return -1;
1121
 
        }
1122
 
 
1123
 
        usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_RESET);
1124
 
        *portstat = portstatus;
1125
 
        return 0;
1126
 
}
1127
 
 
1128
 
 
1129
 
void usb_hub_port_connect_change(struct usb_device *dev, int port)
1130
 
{
1131
 
        struct usb_device *usb;
1132
 
        struct usb_port_status portsts;
1133
 
        unsigned short portstatus;
1134
 
 
1135
 
        /* Check status */
1136
 
        if (usb_get_port_status(dev, port + 1, &portsts) < 0) {
1137
 
                USB_HUB_PRINTF("get_port_status failed\n");
1138
 
                return;
1139
 
        }
1140
 
 
1141
 
        portstatus = le16_to_cpu(portsts.wPortStatus);
1142
 
        USB_HUB_PRINTF("portstatus %x, change %x, %s\n",
1143
 
                        portstatus,
1144
 
                        le16_to_cpu(portsts.wPortChange),
1145
 
                        portspeed(portstatus));
1146
 
 
1147
 
        /* Clear the connection change status */
1148
 
        usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION);
1149
 
 
1150
 
        /* Disconnect any existing devices under this port */
1151
 
        if (((!(portstatus & USB_PORT_STAT_CONNECTION)) &&
1152
 
             (!(portstatus & USB_PORT_STAT_ENABLE))) || (dev->children[port])) {
1153
 
                USB_HUB_PRINTF("usb_disconnect(&hub->children[port]);\n");
1154
 
                /* Return now if nothing is connected */
1155
 
                if (!(portstatus & USB_PORT_STAT_CONNECTION))
1156
 
                        return;
1157
 
        }
1158
 
        wait_ms(200);
1159
 
 
1160
 
        /* Reset the port */
1161
 
        if (hub_port_reset(dev, port, &portstatus) < 0) {
1162
 
                printf("cannot reset port %i!?\n", port + 1);
1163
 
                return;
1164
 
        }
1165
 
 
1166
 
        wait_ms(200);
1167
 
 
1168
 
        /* Allocate a new device struct for it */
1169
 
        usb = usb_alloc_new_device();
1170
 
 
1171
 
        if (portstatus & USB_PORT_STAT_HIGH_SPEED)
1172
 
                usb->speed = USB_SPEED_HIGH;
1173
 
        else if (portstatus & USB_PORT_STAT_LOW_SPEED)
1174
 
                usb->speed = USB_SPEED_LOW;
1175
 
        else
1176
 
                usb->speed = USB_SPEED_FULL;
1177
 
 
1178
 
        dev->children[port] = usb;
1179
 
        usb->parent = dev;
1180
 
        usb->portnr = port + 1;
1181
 
        /* Run it through the hoops (find a driver, etc) */
1182
 
        if (usb_new_device(usb)) {
1183
 
                /* Woops, disable the port */
1184
 
                USB_HUB_PRINTF("hub: disabling port %d\n", port + 1);
1185
 
                usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE);
1186
 
        }
1187
 
}
1188
 
 
1189
 
 
1190
 
int usb_hub_configure(struct usb_device *dev)
1191
 
{
1192
 
        int i;
1193
 
        unsigned char buffer[USB_BUFSIZ], *bitmap;
1194
 
        struct usb_hub_descriptor *descriptor;
1195
 
        struct usb_hub_device *hub;
1196
 
#ifdef USB_HUB_DEBUG
1197
 
        struct usb_hub_status *hubsts;
1198
 
#endif
1199
 
 
1200
 
        /* "allocate" Hub device */
1201
 
        hub = usb_hub_allocate();
1202
 
        if (hub == NULL)
1203
 
                return -1;
1204
 
        hub->pusb_dev = dev;
1205
 
        /* Get the the hub descriptor */
1206
 
        if (usb_get_hub_descriptor(dev, buffer, 4) < 0) {
1207
 
                USB_HUB_PRINTF("usb_hub_configure: failed to get hub " \
1208
 
                                   "descriptor, giving up %lX\n", dev->status);
1209
 
                return -1;
1210
 
        }
1211
 
        descriptor = (struct usb_hub_descriptor *)buffer;
1212
 
 
1213
 
        /* silence compiler warning if USB_BUFSIZ is > 256 [= sizeof(char)] */
1214
 
        i = descriptor->bLength;
1215
 
        if (i > USB_BUFSIZ) {
1216
 
                USB_HUB_PRINTF("usb_hub_configure: failed to get hub " \
1217
 
                                "descriptor - too long: %d\n",
1218
 
                                descriptor->bLength);
1219
 
                return -1;
1220
 
        }
1221
 
 
1222
 
        if (usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0) {
1223
 
                USB_HUB_PRINTF("usb_hub_configure: failed to get hub " \
1224
 
                                "descriptor 2nd giving up %lX\n", dev->status);
1225
 
                return -1;
1226
 
        }
1227
 
        memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength);
1228
 
        /* adjust 16bit values */
1229
 
        hub->desc.wHubCharacteristics =
1230
 
                                le16_to_cpu(descriptor->wHubCharacteristics);
1231
 
        /* set the bitmap */
1232
 
        bitmap = (unsigned char *)&hub->desc.DeviceRemovable[0];
1233
 
        /* devices not removable by default */
1234
 
        memset(bitmap, 0xff, (USB_MAXCHILDREN+1+7)/8);
1235
 
        bitmap = (unsigned char *)&hub->desc.PortPowerCtrlMask[0];
1236
 
        memset(bitmap, 0xff, (USB_MAXCHILDREN+1+7)/8); /* PowerMask = 1B */
1237
 
 
1238
 
        for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
1239
 
                hub->desc.DeviceRemovable[i] = descriptor->DeviceRemovable[i];
1240
 
 
1241
 
        for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
1242
 
                hub->desc.PortPowerCtrlMask[i] = descriptor->PortPowerCtrlMask[i];
1243
 
 
1244
 
        dev->maxchild = descriptor->bNbrPorts;
1245
 
        USB_HUB_PRINTF("%d ports detected\n", dev->maxchild);
1246
 
 
1247
 
        switch (hub->desc.wHubCharacteristics & HUB_CHAR_LPSM) {
1248
 
        case 0x00:
1249
 
                USB_HUB_PRINTF("ganged power switching\n");
1250
 
                break;
1251
 
        case 0x01:
1252
 
                USB_HUB_PRINTF("individual port power switching\n");
1253
 
                break;
1254
 
        case 0x02:
1255
 
        case 0x03:
1256
 
                USB_HUB_PRINTF("unknown reserved power switching mode\n");
1257
 
                break;
1258
 
        }
1259
 
 
1260
 
        if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND)
1261
 
                USB_HUB_PRINTF("part of a compound device\n");
1262
 
        else
1263
 
                USB_HUB_PRINTF("standalone hub\n");
1264
 
 
1265
 
        switch (hub->desc.wHubCharacteristics & HUB_CHAR_OCPM) {
1266
 
        case 0x00:
1267
 
                USB_HUB_PRINTF("global over-current protection\n");
1268
 
                break;
1269
 
        case 0x08:
1270
 
                USB_HUB_PRINTF("individual port over-current protection\n");
1271
 
                break;
1272
 
        case 0x10:
1273
 
        case 0x18:
1274
 
                USB_HUB_PRINTF("no over-current protection\n");
1275
 
                break;
1276
 
        }
1277
 
 
1278
 
        USB_HUB_PRINTF("power on to power good time: %dms\n",
1279
 
                        descriptor->bPwrOn2PwrGood * 2);
1280
 
        USB_HUB_PRINTF("hub controller current requirement: %dmA\n",
1281
 
                        descriptor->bHubContrCurrent);
1282
 
 
1283
 
        for (i = 0; i < dev->maxchild; i++)
1284
 
                USB_HUB_PRINTF("port %d is%s removable\n", i + 1,
1285
 
                        hub->desc.DeviceRemovable[(i + 1) / 8] & \
1286
 
                                           (1 << ((i + 1) % 8)) ? " not" : "");
1287
 
 
1288
 
        if (sizeof(struct usb_hub_status) > USB_BUFSIZ) {
1289
 
                USB_HUB_PRINTF("usb_hub_configure: failed to get Status - " \
1290
 
                                "too long: %d\n", descriptor->bLength);
1291
 
                return -1;
1292
 
        }
1293
 
 
1294
 
        if (usb_get_hub_status(dev, buffer) < 0) {
1295
 
                USB_HUB_PRINTF("usb_hub_configure: failed to get Status %lX\n",
1296
 
                                dev->status);
1297
 
                return -1;
1298
 
        }
1299
 
 
1300
 
#ifdef USB_HUB_DEBUG
1301
 
        hubsts = (struct usb_hub_status *)buffer;
1302
 
#endif
1303
 
        USB_HUB_PRINTF("get_hub_status returned status %X, change %X\n",
1304
 
                        le16_to_cpu(hubsts->wHubStatus),
1305
 
                        le16_to_cpu(hubsts->wHubChange));
1306
 
        USB_HUB_PRINTF("local power source is %s\n",
1307
 
                (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_LOCAL_POWER) ? \
1308
 
                "lost (inactive)" : "good");
1309
 
        USB_HUB_PRINTF("%sover-current condition exists\n",
1310
 
                (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_OVERCURRENT) ? \
1311
 
                "" : "no ");
1312
 
        usb_hub_power_on(hub);
1313
 
 
1314
 
        for (i = 0; i < dev->maxchild; i++) {
1315
 
                struct usb_port_status portsts;
1316
 
                unsigned short portstatus, portchange;
1317
 
 
1318
 
                if (usb_get_port_status(dev, i + 1, &portsts) < 0) {
1319
 
                        USB_HUB_PRINTF("get_port_status failed\n");
1320
 
                        continue;
1321
 
                }
1322
 
 
1323
 
                portstatus = le16_to_cpu(portsts.wPortStatus);
1324
 
                portchange = le16_to_cpu(portsts.wPortChange);
1325
 
                USB_HUB_PRINTF("Port %d Status %X Change %X\n",
1326
 
                                i + 1, portstatus, portchange);
1327
 
 
1328
 
                if (portchange & USB_PORT_STAT_C_CONNECTION) {
1329
 
                        USB_HUB_PRINTF("port %d connection change\n", i + 1);
1330
 
                        usb_hub_port_connect_change(dev, i);
1331
 
                }
1332
 
                if (portchange & USB_PORT_STAT_C_ENABLE) {
1333
 
                        USB_HUB_PRINTF("port %d enable change, status %x\n",
1334
 
                                        i + 1, portstatus);
1335
 
                        usb_clear_port_feature(dev, i + 1,
1336
 
                                                USB_PORT_FEAT_C_ENABLE);
1337
 
 
1338
 
                        /* EM interference sometimes causes bad shielded USB
1339
 
                         * devices to be shutdown by the hub, this hack enables
1340
 
                         * them again. Works at least with mouse driver */
1341
 
                        if (!(portstatus & USB_PORT_STAT_ENABLE) &&
1342
 
                             (portstatus & USB_PORT_STAT_CONNECTION) &&
1343
 
                             ((dev->children[i]))) {
1344
 
                                USB_HUB_PRINTF("already running port %i "  \
1345
 
                                                "disabled by hub (EMI?), " \
1346
 
                                                "re-enabling...\n", i + 1);
1347
 
                                        usb_hub_port_connect_change(dev, i);
1348
 
                        }
1349
 
                }
1350
 
                if (portstatus & USB_PORT_STAT_SUSPEND) {
1351
 
                        USB_HUB_PRINTF("port %d suspend change\n", i + 1);
1352
 
                        usb_clear_port_feature(dev, i + 1,
1353
 
                                                USB_PORT_FEAT_SUSPEND);
1354
 
                }
1355
 
 
1356
 
                if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
1357
 
                        USB_HUB_PRINTF("port %d over-current change\n", i + 1);
1358
 
                        usb_clear_port_feature(dev, i + 1,
1359
 
                                                USB_PORT_FEAT_C_OVER_CURRENT);
1360
 
                        usb_hub_power_on(hub);
1361
 
                }
1362
 
 
1363
 
                if (portchange & USB_PORT_STAT_C_RESET) {
1364
 
                        USB_HUB_PRINTF("port %d reset change\n", i + 1);
1365
 
                        usb_clear_port_feature(dev, i + 1,
1366
 
                                                USB_PORT_FEAT_C_RESET);
1367
 
                }
1368
 
        } /* end for i all ports */
1369
 
 
1370
 
        return 0;
1371
 
}
1372
 
 
1373
 
int usb_hub_probe(struct usb_device *dev, int ifnum)
1374
 
{
1375
 
        struct usb_interface *iface;
1376
 
        struct usb_endpoint_descriptor *ep;
1377
 
        int ret;
1378
 
 
1379
 
        iface = &dev->config.if_desc[ifnum];
1380
 
        /* Is it a hub? */
1381
 
        if (iface->desc.bInterfaceClass != USB_CLASS_HUB)
1382
 
                return 0;
1383
 
        /* Some hubs have a subclass of 1, which AFAICT according to the */
1384
 
        /*  specs is not defined, but it works */
1385
 
        if ((iface->desc.bInterfaceSubClass != 0) &&
1386
 
            (iface->desc.bInterfaceSubClass != 1))
1387
 
                return 0;
1388
 
        /* Multiple endpoints? What kind of mutant ninja-hub is this? */
1389
 
        if (iface->desc.bNumEndpoints != 1)
1390
 
                return 0;
1391
 
        ep = &iface->ep_desc[0];
1392
 
        /* Output endpoint? Curiousier and curiousier.. */
1393
 
        if (!(ep->bEndpointAddress & USB_DIR_IN))
1394
 
                return 0;
1395
 
        /* If it's not an interrupt endpoint, we'd better punt! */
1396
 
        if ((ep->bmAttributes & 3) != 3)
1397
 
                return 0;
1398
 
        /* We found a hub */
1399
 
        USB_HUB_PRINTF("USB hub found\n");
1400
 
        ret = usb_hub_configure(dev);
1401
 
        return ret;
1402
 
}
1403
 
 
1404
968
/* EOF */