From f49e6b5ddf60554ba77c978f6ca19098b0823869 Mon Sep 17 00:00:00 2001 From: boochow Date: Sat, 24 Feb 2018 23:26:44 +0900 Subject: [PATCH 1/6] fix: do not enable Split if low speed device is connected to root hub directly --- source/hcd/dwc/designware20.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/hcd/dwc/designware20.c b/source/hcd/dwc/designware20.c index 34d21ad..80d2b2b 100644 --- a/source/hcd/dwc/designware20.c +++ b/source/hcd/dwc/designware20.c @@ -247,7 +247,7 @@ Result HcdPrepareChannel(struct UsbDevice *device, u8 channel, // Clear split control. ClearReg(&Host->Channel[channel].SplitControl); - if (pipe->Speed != High) { + if ((pipe->Speed != High) && (device->Parent != NULL) && (device->Parent->Speed == High) && (device->Parent->Parent != NULL)) { Host->Channel[channel].SplitControl.SplitEnable = true; Host->Channel[channel].SplitControl.HubAddress = device->Parent->Number; Host->Channel[channel].SplitControl.PortAddress = device->PortNumber; From 4f73f0bd5aea6180062bfb007425013b0f1c40bb Mon Sep 17 00:00:00 2001 From: boochow Date: Sun, 25 Feb 2018 17:54:23 +0900 Subject: [PATCH 2/6] fix: wait 25msec when a FS/LS device connected to the route hub returns errors --- source/hcd/dwc/designware20.c | 50 ++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/source/hcd/dwc/designware20.c b/source/hcd/dwc/designware20.c index 80d2b2b..f84d3f6 100644 --- a/source/hcd/dwc/designware20.c +++ b/source/hcd/dwc/designware20.c @@ -367,32 +367,34 @@ Result HcdChannelSendWaitOne(struct UsbDevice *device, } while (true); ReadBackReg(&Host->Channel[channel].TransferSize); - if (Host->Channel[channel].SplitControl.SplitEnable) { + if (pipe->Speed != High) { if (Host->Channel[channel].Interrupt.Acknowledgement) { - for (tries = 0; tries < 3; tries++) { - SetReg(&Host->Channel[channel].Interrupt); - WriteThroughReg(&Host->Channel[channel].Interrupt); - - ReadBackReg(&Host->Channel[channel].SplitControl); - Host->Channel[channel].SplitControl.CompleteSplit = true; - WriteThroughReg(&Host->Channel[channel].SplitControl); + if (Host->Channel[channel].SplitControl.SplitEnable) { + for (tries = 0; tries < 3; tries++) { + SetReg(&Host->Channel[channel].Interrupt); + WriteThroughReg(&Host->Channel[channel].Interrupt); + + ReadBackReg(&Host->Channel[channel].SplitControl); + Host->Channel[channel].SplitControl.CompleteSplit = true; + WriteThroughReg(&Host->Channel[channel].SplitControl); - Host->Channel[channel].Characteristic.Enable = true; - Host->Channel[channel].Characteristic.Disable = false; - WriteThroughReg(&Host->Channel[channel].Characteristic); - - timeout = 0; - do { - if (timeout++ == RequestTimeout) { - LOGF("HCD: Request split completion to %s has timed out.\n", UsbGetDescription(device)); - device->Error = ConnectionError; - return ErrorTimeout; - } - ReadBackReg(&Host->Channel[channel].Interrupt); - if (!Host->Channel[channel].Interrupt.Halt) MicroDelay(100); - else break; - } while (true); - if (!Host->Channel[channel].Interrupt.NotYet) break; + Host->Channel[channel].Characteristic.Enable = true; + Host->Channel[channel].Characteristic.Disable = false; + WriteThroughReg(&Host->Channel[channel].Characteristic); + + timeout = 0; + do { + if (timeout++ == RequestTimeout) { + LOGF("HCD: Request split completion to %s has timed out.\n", UsbGetDescription(device)); + device->Error = ConnectionError; + return ErrorTimeout; + } + ReadBackReg(&Host->Channel[channel].Interrupt); + if (!Host->Channel[channel].Interrupt.Halt) MicroDelay(100); + else break; + } while (true); + if (!Host->Channel[channel].Interrupt.NotYet) break; + } } if (tries == 3) { From e187bbec108b97101aa96cd9d88de55a17bfe3b4 Mon Sep 17 00:00:00 2001 From: boochow Date: Sun, 25 Feb 2018 19:24:38 +0900 Subject: [PATCH 3/6] refactor: move 'complete split' codes and its error check codes into single block --- source/hcd/dwc/designware20.c | 50 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/source/hcd/dwc/designware20.c b/source/hcd/dwc/designware20.c index f84d3f6..a8e4c8b 100644 --- a/source/hcd/dwc/designware20.c +++ b/source/hcd/dwc/designware20.c @@ -368,33 +368,31 @@ Result HcdChannelSendWaitOne(struct UsbDevice *device, ReadBackReg(&Host->Channel[channel].TransferSize); if (pipe->Speed != High) { - if (Host->Channel[channel].Interrupt.Acknowledgement) { - if (Host->Channel[channel].SplitControl.SplitEnable) { - for (tries = 0; tries < 3; tries++) { - SetReg(&Host->Channel[channel].Interrupt); - WriteThroughReg(&Host->Channel[channel].Interrupt); - - ReadBackReg(&Host->Channel[channel].SplitControl); - Host->Channel[channel].SplitControl.CompleteSplit = true; - WriteThroughReg(&Host->Channel[channel].SplitControl); + if ((Host->Channel[channel].Interrupt.Acknowledgement) && (Host->Channel[channel].SplitControl.SplitEnable)) { + for (tries = 0; tries < 3; tries++) { + SetReg(&Host->Channel[channel].Interrupt); + WriteThroughReg(&Host->Channel[channel].Interrupt); + + ReadBackReg(&Host->Channel[channel].SplitControl); + Host->Channel[channel].SplitControl.CompleteSplit = true; + WriteThroughReg(&Host->Channel[channel].SplitControl); - Host->Channel[channel].Characteristic.Enable = true; - Host->Channel[channel].Characteristic.Disable = false; - WriteThroughReg(&Host->Channel[channel].Characteristic); - - timeout = 0; - do { - if (timeout++ == RequestTimeout) { - LOGF("HCD: Request split completion to %s has timed out.\n", UsbGetDescription(device)); - device->Error = ConnectionError; - return ErrorTimeout; - } - ReadBackReg(&Host->Channel[channel].Interrupt); - if (!Host->Channel[channel].Interrupt.Halt) MicroDelay(100); - else break; - } while (true); - if (!Host->Channel[channel].Interrupt.NotYet) break; - } + Host->Channel[channel].Characteristic.Enable = true; + Host->Channel[channel].Characteristic.Disable = false; + WriteThroughReg(&Host->Channel[channel].Characteristic); + + timeout = 0; + do { + if (timeout++ == RequestTimeout) { + LOGF("HCD: Request split completion to %s has timed out.\n", UsbGetDescription(device)); + device->Error = ConnectionError; + return ErrorTimeout; + } + ReadBackReg(&Host->Channel[channel].Interrupt); + if (!Host->Channel[channel].Interrupt.Halt) MicroDelay(100); + else break; + } while (true); + if (!Host->Channel[channel].Interrupt.NotYet) break; } if (tries == 3) { From 2d7f8b692320d86132f5b73fd0c9be4a2e0118f3 Mon Sep 17 00:00:00 2001 From: boochow Date: Sun, 4 Mar 2018 12:16:00 +0900 Subject: [PATCH 4/6] fix: set ConnectedChanged bit when a device is unplugged from the root hub. --- source/device/hub.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/device/hub.c b/source/device/hub.c index bfb4ebc..c66d5b7 100644 --- a/source/device/hub.c +++ b/source/device/hub.c @@ -382,8 +382,10 @@ Result HubCheckConnection(struct UsbDevice *device, u8 port) { Result result; struct HubPortFullStatus *portStatus; struct HubDevice *data; + int prevConnected; data = (struct HubDevice*)device->DriverData; + prevConnected = data->PortStatus[port].Status.Connected; if ((result = HubPortGetStatus(device, port)) != OK) { if (result != ErrorDisconnected) @@ -391,7 +393,10 @@ Result HubCheckConnection(struct UsbDevice *device, u8 port) { return result; } portStatus = &data->PortStatus[port]; - + if (prevConnected != portStatus->Status.Connected) { + portStatus->Change.ConnectedChanged = true; + } + if (portStatus->Change.ConnectedChanged) { HubPortConnectionChanged(device, port); } @@ -549,4 +554,4 @@ Result HubAttach(struct UsbDevice *device, u32 interfaceNumber) { } return OK; -} \ No newline at end of file +} From 63bbfa06a91206290e342fb938df0b310a70f69c Mon Sep 17 00:00:00 2001 From: boochow Date: Sat, 5 May 2018 11:27:38 +0900 Subject: [PATCH 5/6] fix warning message "extra tokens at end of #endif" of hid.h --- include/device/hid/hid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/device/hid/hid.h b/include/device/hid/hid.h index cc9d0f9..f74289b 100644 --- a/include/device/hid/hid.h +++ b/include/device/hid/hid.h @@ -161,4 +161,4 @@ Result HidAttach(struct UsbDevice *device, u32 interfaceNumber); } #endif -#endif HID_H_ +#endif // HID_H_ From 7a8329bec756977d10f49859cda7bf18854db489 Mon Sep 17 00:00:00 2001 From: boochow Date: Sun, 23 Dec 2018 01:45:14 +0900 Subject: [PATCH 6/6] fix: check connection status only when the port belongs to root hub --- source/device/hub.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/device/hub.c b/source/device/hub.c index c66d5b7..c0753ce 100644 --- a/source/device/hub.c +++ b/source/device/hub.c @@ -393,8 +393,10 @@ Result HubCheckConnection(struct UsbDevice *device, u8 port) { return result; } portStatus = &data->PortStatus[port]; - if (prevConnected != portStatus->Status.Connected) { - portStatus->Change.ConnectedChanged = true; + if (device == UsbGetRootHub()) { + if (prevConnected != portStatus->Status.Connected) { + portStatus->Change.ConnectedChanged = true; + } } if (portStatus->Change.ConnectedChanged) {