Skip to content

Commit

Permalink
Wakeup thunderbolt controller on hotplug for bonw15-b
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Aug 13, 2024
1 parent 9894c79 commit 879f944
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
hid_backlight,
hotplug::{mux, Detect, HotPlugDetect},
kernel_parameters::{KernelParameter, NmiWatchdog},
runtime_pm::runtime_pm_quirks,
runtime_pm::{runtime_pm_quirks, thunderbolt_hotplug_wakeup},
DBUS_NAME, DBUS_PATH,
};

Expand Down Expand Up @@ -539,7 +539,9 @@ pub async fn daemon() -> anyhow::Result<()> {
}
}

match runtime_pm_quirks() {
let vendor = fs::read_to_string("/sys/class/dmi/id/sys_vendor")?;
let model = fs::read_to_string("/sys/class/dmi/id/product_version")?;
match runtime_pm_quirks(&model, &vendor) {
Ok(()) => (),
Err(err) => {
log::warn!("Failed to set runtime power management quirks: {}", err);
Expand Down Expand Up @@ -622,6 +624,12 @@ pub async fn daemon() -> anyhow::Result<()> {
if hpd[i] != last[i] && hpd[i] {
log::info!("HotPlugDetect {}", i);
let _res = System76Power::hot_plug_detect(&context, i as u64).await;
match thunderbolt_hotplug_wakeup(&vendor, &model) {
Ok(()) => (),
Err(err) => {
log::warn!("Failed to wakeup thunderbolt on hotplug: {}", err);
}
}
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/runtime_pm.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use std::{fs, io};
use sysfs_class::{PciDevice, RuntimePM, RuntimePowerManagement, SysClass};

pub fn runtime_pm_quirks() -> io::Result<()> {
let vendor = fs::read_to_string("/sys/class/dmi/id/sys_vendor")?;
let model = fs::read_to_string("/sys/class/dmi/id/product_version")?;

pub fn runtime_pm_quirks(vendor: &str, model: &str) -> io::Result<()> {
match (vendor.trim(), model.trim()) {
("System76", "bonw15") | ("System76", "bonw15-b") => {
("System76", "bonw15") => {
for dev in PciDevice::all()? {
match (dev.vendor()?, dev.device()?) {
(0x8086, 0x1138) => {
Expand All @@ -25,3 +22,14 @@ pub fn runtime_pm_quirks() -> io::Result<()> {

Ok(())
}

pub fn thunderbolt_hotplug_wakeup(vendor: &str, model: &str) -> io::Result<()> {
match (vendor.trim(), model.trim()) {
("System76", "bonw15") => {
fs::read("/sys/kernel/debug/thunderbolt/0-0/regs")?;
}
(_, _) => {}
}

Ok(())
}

0 comments on commit 879f944

Please sign in to comment.