Skip to content

Commit

Permalink
Remove endpoint (re)init due to port change
Browse files Browse the repository at this point in the history
When the USB device exits the suspend state to resume operation, the
device observes a port change. Before this commit, this port change
would initialize and disable all non-zero endpoints. By resetting
endpoints without re-enabling them, the USB device stops functioning.

We should make sure the endpoints are in a known state before operation,
and we can handle that when responding to bus resets.
  • Loading branch information
mciantyre committed Sep 15, 2023
1 parent a2f2ce5 commit 7097f65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
[Unreleased]
------------

Resolve an issue where endpoints were reset when exiting suspend.

[0.2.1] 2023-03-14
------------------

Expand Down
11 changes: 4 additions & 7 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ impl Driver {
pub fn set_interrupts(&mut self, interrupts: bool) {
if interrupts {
// Keep this in sync with the poll() behaviors
ral::modify_reg!(ral::usb, self.usb, USBINTR, UE: 1, URE: 1, PCE: 1);
ral::modify_reg!(ral::usb, self.usb, USBINTR, UE: 1, URE: 1);
} else {
ral::modify_reg!(ral::usb, self.usb, USBINTR, UE: 0, URE: 0, PCE: 0);
ral::modify_reg!(ral::usb, self.usb, USBINTR, UE: 0, URE: 0);
}
}

Expand Down Expand Up @@ -186,6 +186,8 @@ impl Driver {
"Took too long to handle bus reset"
);
debug!("RESET");

self.initialize_endpoints();
}

/// Check if the endpoint is valid
Expand Down Expand Up @@ -402,11 +404,6 @@ impl Driver {
return PollResult::Reset;
}

if usbsts & USBSTS::PCI::mask != 0 {
ral::write_reg!(ral::usb, self.usb, USBSTS, PCI: 1);
self.initialize_endpoints();
}

if usbsts & USBSTS::UI::mask != 0 {
ral::write_reg!(ral::usb, self.usb, USBSTS, UI: 1);

Expand Down

0 comments on commit 7097f65

Please sign in to comment.