Skip to content

Commit

Permalink
USBD: Implemented a new requirement where the order the usb drivers c…
Browse files Browse the repository at this point in the history
…onnect function is called is the same independent of when it is called. Before the order was different depending on whether the USBD driver has finished discovering all connected devices.
  • Loading branch information
radad committed Jan 7, 2009
1 parent 376df98 commit a8c9a3a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
15 changes: 14 additions & 1 deletion iop/usb/usbd/src/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ void probeDeviceTree(Device *tree, UsbDriver *drv) {
}
}

void probeDeviceConnectList(UsbDriver *drv) {
Device *curDevice;
for (curDevice = memPool.deviceConnectedListStart; curDevice != NULL; curDevice = curDevice->nextConnected)
if (curDevice->deviceStatus == DEVICE_READY) {
if (curDevice->devDriver == NULL) {
if (callUsbDriverFunc(drv->probe, curDevice->id, drv->gp) != 0) {
curDevice->devDriver = drv;
callUsbDriverFunc(drv->connect, curDevice->id, drv->gp);
}
}
}
}

int doRegisterDriver(UsbDriver *drv, void *drvGpSeg) {
if (drv->next || drv->prev)
return USB_RC_BUSY;
Expand All @@ -74,7 +87,7 @@ int doRegisterDriver(UsbDriver *drv, void *drvGpSeg) {
drvListEnd = drv;

if (drv->probe)
probeDeviceTree(memPool.deviceTreeRoot, drv);
probeDeviceConnectList(drv);

return 0;
}
Expand Down
24 changes: 23 additions & 1 deletion iop/usb/usbd/src/hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,19 @@ void flushPort(Device *dev) {
while (dev->endpointListStart)
removeEndpointFromDevice(dev, dev->endpointListStart);

if (dev->nextConnected)
dev->nextConnected->prevConnected = dev->prevConnected;
else
memPool.deviceConnectedListEnd = dev->prevConnected;

if (dev->prevConnected)
dev->prevConnected->nextConnected = dev->nextConnected;
else
memPool.deviceConnectedListStart = dev->nextConnected;

dev->nextConnected = NULL;
dev->prevConnected = NULL;

while ((child = dev->childListStart)) {
if (child->next)
child->next->prev = child->prev;
Expand Down Expand Up @@ -407,8 +420,17 @@ void fetchConfigDescriptors(IoRequest *req) {
doControlTransfer(ep, &dev->ioRequest,
USB_DIR_IN | USB_RECIP_DEVICE, USB_REQ_GET_DESCRIPTOR, (USB_DT_CONFIG << 8) | curDescNum, 0, readLen,
dev->staticDeviceDescEndPtr, fetchConfigDescriptors);
} else
} else {
dev->prevConnected = memPool.deviceConnectedListEnd;
if (memPool.deviceConnectedListEnd)
memPool.deviceConnectedListEnd->nextConnected = dev;
else
memPool.deviceConnectedListStart = dev;
dev->nextConnected = NULL;
memPool.deviceConnectedListEnd = dev;

connectNewDevice(dev);
}
} else
killDevice(dev, ep);
}
Expand Down
4 changes: 4 additions & 0 deletions iop/usb/usbd/src/usbdpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ typedef struct _ioRequest {
typedef struct _device {
uint32 id;
struct _device *next, *prev;
struct _device *nextConnected, *prevConnected;
struct _endpoint *endpointListStart, *endpointListEnd;
UsbDriver *devDriver;
uint8 deviceStatus;
Expand Down Expand Up @@ -222,6 +223,9 @@ typedef struct _memPool {

struct _device *deviceTreeRoot;

struct _device *deviceConnectedListStart;
struct _device *deviceConnectedListEnd;

uint32 delayResets;
} MemoryPool;

Expand Down

0 comments on commit a8c9a3a

Please sign in to comment.