From 2f15288beb5abac5d1285547261ab3d22b2a6a1f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 28 Nov 2022 06:52:20 -0700 Subject: [PATCH] xhci: Perform both port reset and controller reset --- xhcid/src/xhci/mod.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/xhcid/src/xhci/mod.rs b/xhcid/src/xhci/mod.rs index 368557d030..7ba5b208c3 100644 --- a/xhcid/src/xhci/mod.rs +++ b/xhcid/src/xhci/mod.rs @@ -336,6 +336,17 @@ impl Xhci { } pub fn init(&mut self, max_slots: u8) -> Result<()> { + // Set run/stop to 0 + debug!("Stopping xHC."); + self.op.get_mut().unwrap().usb_cmd.writef(1, false); + + // Warm reset + debug!("Reset xHC"); + self.op.get_mut().unwrap().usb_cmd.writef(1 << 1, true); + while self.op.get_mut().unwrap().usb_cmd.readf(1 << 1) { + thread::yield_now(); + } + // Set enabled slots debug!("Setting enabled slots to {}.", max_slots); self.op.get_mut().unwrap().config.write(max_slots as u32); @@ -382,7 +393,7 @@ impl Xhci { self.setup_scratchpads()?; // Set run/stop to 1 - info!("Starting xHC."); + debug!("Starting xHC."); self.op.get_mut().unwrap().usb_cmd.writef(1, true); // Wait until controller is running @@ -472,6 +483,17 @@ impl Xhci { let port_count = { self.ports.lock().unwrap().len() }; for i in 0..port_count { + //TODO: only reset if USB 2.0? + debug!("Port reset"); + { + let port = &mut self.ports.lock().unwrap()[i]; + port.portsc.writef(port::PortFlags::PORT_PR.bits(), true); + while port.portsc.readf(port::PortFlags::PORT_PR.bits()) { + //while ! port.flags().contains(port::PortFlags::PORT_PRC) { + std::thread::yield_now(); + } + } + let (data, state, speed, flags) = { let port = &self.ports.lock().unwrap()[i]; (port.read(), port.state(), port.speed(), port.flags())