From 85a9fc8f7e69088aa3dbc2b0f93f3ce0246f95a6 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 28 Jan 2024 20:24:29 -0500 Subject: [PATCH] Allow device auto detection to tell steam deck driver the specific model --- .../limits_core/src/json_v2/battery_limit.rs | 6 +-- backend/limits_core/src/json_v2/cpu_limit.rs | 8 ++-- backend/limits_core/src/json_v2/gpu_limit.rs | 4 +- backend/src/main.rs | 2 +- backend/src/persist/driver.rs | 4 +- backend/src/settings/detect/auto_detect.rs | 42 +++++++------------ backend/src/settings/driver.rs | 2 +- backend/src/settings/steam_deck/battery.rs | 14 ++++++- backend/src/settings/steam_deck/cpu.rs | 14 ++++++- backend/src/settings/steam_deck/gpu.rs | 16 ++++++- backend/src/settings/steam_deck/mod.rs | 9 ++-- 11 files changed, 74 insertions(+), 47 deletions(-) diff --git a/backend/limits_core/src/json_v2/battery_limit.rs b/backend/limits_core/src/json_v2/battery_limit.rs index d0d4890..0c3de9d 100644 --- a/backend/limits_core/src/json_v2/battery_limit.rs +++ b/backend/limits_core/src/json_v2/battery_limit.rs @@ -6,8 +6,8 @@ use super::RangeLimit; pub enum BatteryLimitType { #[serde(rename = "GabeBoy", alias = "SteamDeck")] SteamDeck, - #[serde(rename = "GabeBoyAdvance", alias = "SteamDeckAdvance")] - SteamDeckAdvance, + #[serde(rename = "GabeBoySP", alias = "SteamDeckOLED")] + SteamDeckOLED, Generic, Unknown, DevMode, @@ -25,7 +25,7 @@ pub struct GenericBatteryLimit { impl GenericBatteryLimit { pub fn default_for(t: BatteryLimitType) -> Self { match t { - BatteryLimitType::SteamDeck | BatteryLimitType::SteamDeckAdvance => Self::default_steam_deck(), + BatteryLimitType::SteamDeck | BatteryLimitType::SteamDeckOLED => Self::default_steam_deck(), BatteryLimitType::DevMode => Self::default_dev_mode(), _t => Self::default(), } diff --git a/backend/limits_core/src/json_v2/cpu_limit.rs b/backend/limits_core/src/json_v2/cpu_limit.rs index e391078..58af870 100644 --- a/backend/limits_core/src/json_v2/cpu_limit.rs +++ b/backend/limits_core/src/json_v2/cpu_limit.rs @@ -7,8 +7,8 @@ use super::RangeLimit; pub enum CpuLimitType { #[serde(rename = "GabeBoy", alias = "SteamDeck")] SteamDeck, - #[serde(rename = "GabeBoyAdvance", alias = "SteamDeckAdvance")] - SteamDeckAdvance, + #[serde(rename = "GabeBoySP", alias = "SteamDeckOLED")] + SteamDeckOLED, Generic, GenericAMD, Unknown, @@ -25,7 +25,7 @@ pub struct GenericCpusLimit { impl GenericCpusLimit { pub fn default_for(t: CpuLimitType) -> Self { match t { - CpuLimitType::SteamDeck | CpuLimitType::SteamDeckAdvance => { + CpuLimitType::SteamDeck | CpuLimitType::SteamDeckOLED => { Self { cpus: [(); 8].iter().enumerate().map(|(i, _)| GenericCpuLimit::default_for(&t, i)).collect(), global_governors: true, @@ -96,7 +96,7 @@ pub struct GenericCpuLimit { impl GenericCpuLimit { pub fn default_for(t: &CpuLimitType, _index: usize) -> Self { match t { - CpuLimitType::SteamDeck | CpuLimitType::SteamDeckAdvance => Self::default_steam_deck(), + CpuLimitType::SteamDeck | CpuLimitType::SteamDeckOLED => Self::default_steam_deck(), CpuLimitType::DevMode => Self { clock_min: Some(RangeLimit { min: Some(100), max: Some(5000) }), clock_max: Some(RangeLimit { min: Some(100), max: Some(4800) }), diff --git a/backend/limits_core/src/json_v2/gpu_limit.rs b/backend/limits_core/src/json_v2/gpu_limit.rs index 1662149..f7d1dbe 100644 --- a/backend/limits_core/src/json_v2/gpu_limit.rs +++ b/backend/limits_core/src/json_v2/gpu_limit.rs @@ -6,8 +6,6 @@ use super::RangeLimit; pub enum GpuLimitType { #[serde(rename = "GabeBoy", alias = "SteamDeck")] SteamDeck, - #[serde(rename = "GabeBoyAdvance", alias = "SteamDeckAdvance")] - SteamDeckAdvance, #[serde(rename = "GabeBoySP", alias = "SteamDeckOLED")] SteamDeckOLED, Generic, @@ -40,7 +38,7 @@ pub struct GenericGpuLimit { impl GenericGpuLimit { pub fn default_for(t: GpuLimitType) -> Self { match t { - GpuLimitType::SteamDeck | GpuLimitType::SteamDeckAdvance => Self::default_steam_deck(), + GpuLimitType::SteamDeck => Self::default_steam_deck(), GpuLimitType::SteamDeckOLED => Self::default_steam_deck_oled(), GpuLimitType::DevMode => Self::default_dev_mode(), _t => Self::default(), diff --git a/backend/src/main.rs b/backend/src/main.rs index 4ceab20..3a52085 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -337,7 +337,7 @@ fn main() -> Result<(), ()> { #[cfg(debug_assertions)] std::thread::spawn(|| { utility::ioperm_power_ec(); - settings::steam_deck::util::flash_led(); + settings::steam_deck::flash_led(); }); if let Err(e) = loaded_settings.on_set() { diff --git a/backend/src/persist/driver.rs b/backend/src/persist/driver.rs index 56f50d6..7e18a8b 100644 --- a/backend/src/persist/driver.rs +++ b/backend/src/persist/driver.rs @@ -6,8 +6,8 @@ use serde::{Deserialize, Serialize}; pub enum DriverJson { #[serde(rename = "steam-deck", alias = "gabe-boy")] SteamDeck, - #[serde(rename = "steam-deck-oc", alias = "gabe-boy-advance")] - SteamDeckAdvance, + #[serde(rename = "steam-deck-oled", alias = "gabe-boy-sp")] + SteamDeckOLED, #[serde(rename = "generic")] Generic, #[serde(rename = "generic-amd")] diff --git a/backend/src/settings/detect/auto_detect.rs b/backend/src/settings/detect/auto_detect.rs index a9f8b92..31ded4d 100644 --- a/backend/src/settings/detect/auto_detect.rs +++ b/backend/src/settings/detect/auto_detect.rs @@ -156,14 +156,14 @@ pub fn auto_detect0( settings.cpus.clone(), settings.version, relevant_limits.cpu.limits, - )) + ).variant(super::super::steam_deck::Model::LCD)) } - CpuLimitType::SteamDeckAdvance => { + CpuLimitType::SteamDeckOLED => { Box::new(crate::settings::steam_deck::Cpus::from_json_and_limits( settings.cpus.clone(), settings.version, relevant_limits.cpu.limits, - )) + ).variant(super::super::steam_deck::Model::OLED)) } CpuLimitType::Generic => Box::new(crate::settings::generic::Cpus::< crate::settings::generic::Cpu, @@ -201,21 +201,14 @@ pub fn auto_detect0( settings.gpu.clone(), settings.version, relevant_limits.gpu.limits, - )) - } - GpuLimitType::SteamDeckAdvance => { - Box::new(crate::settings::steam_deck::Gpu::from_json_and_limits( - settings.gpu.clone(), - settings.version, - relevant_limits.gpu.limits, - )) + ).variant(super::super::steam_deck::Model::LCD)) } GpuLimitType::SteamDeckOLED => { Box::new(crate::settings::steam_deck::Gpu::from_json_and_limits( settings.gpu.clone(), settings.version, relevant_limits.gpu.limits, - )) + ).variant(super::super::steam_deck::Model::OLED)) } GpuLimitType::Generic => { Box::new(crate::settings::generic::Gpu::from_json_and_limits( @@ -252,14 +245,14 @@ pub fn auto_detect0( settings.battery.clone(), settings.version, relevant_limits.battery.limits, - )) + ).variant(super::super::steam_deck::Model::LCD)) } - BatteryLimitType::SteamDeckAdvance => { + BatteryLimitType::SteamDeckOLED => { Box::new(crate::settings::steam_deck::Battery::from_json_and_limits( settings.battery.clone(), settings.version, relevant_limits.battery.limits, - )) + ).variant(super::super::steam_deck::Model::OLED)) } BatteryLimitType::Generic => Box::new( crate::settings::generic::Battery::from_json_and_limits( @@ -293,10 +286,10 @@ pub fn auto_detect0( } else { let cpu_driver: Box = match relevant_limits.cpu.provider { CpuLimitType::SteamDeck => { - Box::new(crate::settings::steam_deck::Cpus::from_limits(relevant_limits.cpu.limits)) + Box::new(crate::settings::steam_deck::Cpus::from_limits(relevant_limits.cpu.limits).variant(super::super::steam_deck::Model::LCD)) } - CpuLimitType::SteamDeckAdvance => { - Box::new(crate::settings::steam_deck::Cpus::from_limits(relevant_limits.cpu.limits)) + CpuLimitType::SteamDeckOLED => { + Box::new(crate::settings::steam_deck::Cpus::from_limits(relevant_limits.cpu.limits).variant(super::super::steam_deck::Model::OLED)) } CpuLimitType::Generic => { Box::new(crate::settings::generic::Cpus::< @@ -315,13 +308,10 @@ pub fn auto_detect0( }; let gpu_driver: Box = match relevant_limits.gpu.provider { GpuLimitType::SteamDeck => { - Box::new(crate::settings::steam_deck::Gpu::from_limits(relevant_limits.gpu.limits)) - } - GpuLimitType::SteamDeckAdvance => { - Box::new(crate::settings::steam_deck::Gpu::from_limits(relevant_limits.gpu.limits)) + Box::new(crate::settings::steam_deck::Gpu::from_limits(relevant_limits.gpu.limits).variant(super::super::steam_deck::Model::LCD)) } GpuLimitType::SteamDeckOLED => { - Box::new(crate::settings::steam_deck::Gpu::from_limits(relevant_limits.gpu.limits)) + Box::new(crate::settings::steam_deck::Gpu::from_limits(relevant_limits.gpu.limits).variant(super::super::steam_deck::Model::OLED)) } GpuLimitType::Generic => { Box::new(crate::settings::generic::Gpu::from_limits(relevant_limits.gpu.limits)) @@ -338,10 +328,10 @@ pub fn auto_detect0( }; let battery_driver: Box = match relevant_limits.battery.provider { BatteryLimitType::SteamDeck => { - Box::new(crate::settings::steam_deck::Battery::from_limits(relevant_limits.battery.limits)) + Box::new(crate::settings::steam_deck::Battery::from_limits(relevant_limits.battery.limits).variant(super::super::steam_deck::Model::LCD)) } - BatteryLimitType::SteamDeckAdvance => { - Box::new(crate::settings::steam_deck::Battery::from_limits(relevant_limits.battery.limits)) + BatteryLimitType::SteamDeckOLED => { + Box::new(crate::settings::steam_deck::Battery::from_limits(relevant_limits.battery.limits).variant(super::super::steam_deck::Model::OLED)) } BatteryLimitType::Generic => { Box::new(crate::settings::generic::Battery::from_limits(relevant_limits.battery.limits)) diff --git a/backend/src/settings/driver.rs b/backend/src/settings/driver.rs index 73eb1f1..adae096 100644 --- a/backend/src/settings/driver.rs +++ b/backend/src/settings/driver.rs @@ -29,7 +29,7 @@ impl Driver { #[inline] pub fn maybe_do_button() { match super::auto_detect_provider() { - DriverJson::SteamDeck | DriverJson::SteamDeckAdvance => { + DriverJson::SteamDeck | DriverJson::SteamDeckOLED => { crate::settings::steam_deck::flash_led(); } DriverJson::Generic | DriverJson::GenericAMD => { diff --git a/backend/src/settings/steam_deck/battery.rs b/backend/src/settings/steam_deck/battery.rs index e36b127..c0325eb 100644 --- a/backend/src/settings/steam_deck/battery.rs +++ b/backend/src/settings/steam_deck/battery.rs @@ -23,6 +23,7 @@ pub struct Battery { sysfs_bat: PowerSupplyPath, sysfs_hwmon: Arc, bat_ec: Arc>, + variant: super::Model, } #[derive(Debug, Clone)] @@ -542,6 +543,11 @@ impl Battery { self.events.clone() } } + + pub fn variant(mut self, model: super::Model) -> Self { + self.variant = model; + self + } } impl Into for Battery { @@ -579,6 +585,7 @@ impl ProviderBuilder for Battery { sysfs_bat: Self::find_battery_sysfs(None::<&'static str>), sysfs_hwmon: hwmon_sys, bat_ec: ec, + variant: super::Model::LCD, }.remove_charge_limit_instructions(), _ => Self { charge_rate: persistent.charge_rate, @@ -597,6 +604,7 @@ impl ProviderBuilder for Battery { sysfs_bat: Self::find_battery_sysfs(None::<&'static str>), sysfs_hwmon: hwmon_sys, bat_ec: ec, + variant: super::Model::LCD, }.remove_charge_limit_instructions(), } } @@ -612,6 +620,7 @@ impl ProviderBuilder for Battery { sysfs_bat: Self::find_battery_sysfs(None::<&'static str>), sysfs_hwmon: Arc::new(Self::find_hwmon_sysfs(None::<&'static str>)), bat_ec: Arc::new(Mutex::new(UnnamedPowerEC::new())), + variant: super::Model::LCD, }.remove_charge_limit_instructions() } } @@ -806,6 +815,9 @@ impl TBattery for Battery { } fn provider(&self) -> crate::persist::DriverJson { - crate::persist::DriverJson::SteamDeck + match self.variant { + super::Model::LCD => crate::persist::DriverJson::SteamDeck, + super::Model::OLED => crate::persist::DriverJson::SteamDeckOLED, + } } } diff --git a/backend/src/settings/steam_deck/cpu.rs b/backend/src/settings/steam_deck/cpu.rs index 3a5cc56..34671c5 100644 --- a/backend/src/settings/steam_deck/cpu.rs +++ b/backend/src/settings/steam_deck/cpu.rs @@ -30,6 +30,7 @@ pub struct Cpus { pub smt: bool, pub smt_capable: bool, pub(super) limits: GenericCpusLimit, + variant: super::Model, } impl OnSet for Cpus { @@ -100,6 +101,11 @@ impl Cpus { Err(_) => (false, false), } } + + pub fn variant(mut self, model: super::Model) -> Self { + self.variant = model; + self + } } impl ProviderBuilder, GenericCpusLimit> for Cpus { @@ -144,6 +150,7 @@ impl ProviderBuilder, GenericCpusLimit> for Cpus { smt: smt_guess, smt_capable: can_smt, limits: limits, + variant: super::Model::LCD, } } @@ -168,6 +175,7 @@ impl ProviderBuilder, GenericCpusLimit> for Cpus { smt: true, smt_capable: can_smt, limits: limits, + variant: super::Model::LCD, } } else { Self { @@ -175,6 +183,7 @@ impl ProviderBuilder, GenericCpusLimit> for Cpus { smt: false, smt_capable: false, limits: limits, + variant: super::Model::LCD, } } } @@ -218,7 +227,10 @@ impl TCpus for Cpus { } fn provider(&self) -> crate::persist::DriverJson { - crate::persist::DriverJson::SteamDeck + match self.variant { + super::Model::LCD => crate::persist::DriverJson::SteamDeck, + super::Model::OLED => crate::persist::DriverJson::SteamDeckOLED, + } } } diff --git a/backend/src/settings/steam_deck/gpu.rs b/backend/src/settings/steam_deck/gpu.rs index fe918eb..e8aafb0 100644 --- a/backend/src/settings/steam_deck/gpu.rs +++ b/backend/src/settings/steam_deck/gpu.rs @@ -24,7 +24,8 @@ pub struct Gpu { limits: GenericGpuLimit, state: crate::state::steam_deck::Gpu, sysfs_card: BasicEntityPath, - sysfs_hwmon: HwMonPath + sysfs_hwmon: HwMonPath, + variant: super::Model, } // same as CPU @@ -346,6 +347,11 @@ impl Gpu { self.memory_clock = Some(mem_clock.clamp(self.limits.memory_clock.and_then(|lim| lim.min).unwrap_or(MIN_MEMORY_CLOCK), self.limits.memory_clock.and_then(|lim| lim.max).unwrap_or(MAX_MEMORY_CLOCK))); } } + + pub fn variant(mut self, model: super::Model) -> Self { + self.variant = model; + self + } } impl Into for Gpu { @@ -375,6 +381,7 @@ impl ProviderBuilder for Gpu { state: crate::state::steam_deck::Gpu::default(), sysfs_card: Self::find_card_sysfs(persistent.root.clone()), sysfs_hwmon: Self::find_hwmon_sysfs(persistent.root), + variant: super::Model::LCD, }, _ => Self { fast_ppt: persistent.fast_ppt, @@ -385,6 +392,7 @@ impl ProviderBuilder for Gpu { state: crate::state::steam_deck::Gpu::default(), sysfs_card: Self::find_card_sysfs(persistent.root.clone()), sysfs_hwmon: Self::find_hwmon_sysfs(persistent.root), + variant: super::Model::LCD, }, } } @@ -399,6 +407,7 @@ impl ProviderBuilder for Gpu { state: crate::state::steam_deck::Gpu::default(), sysfs_card: Self::find_card_sysfs(None::<&'static str>), sysfs_hwmon: Self::find_hwmon_sysfs(None::<&'static str>), + variant: super::Model::LCD, } } } @@ -485,7 +494,10 @@ impl TGpu for Gpu { } fn provider(&self) -> crate::persist::DriverJson { - crate::persist::DriverJson::SteamDeck + match self.variant { + super::Model::LCD => crate::persist::DriverJson::SteamDeck, + super::Model::OLED => crate::persist::DriverJson::SteamDeckOLED, + } } } diff --git a/backend/src/settings/steam_deck/mod.rs b/backend/src/settings/steam_deck/mod.rs index a87f005..5adc6c6 100644 --- a/backend/src/settings/steam_deck/mod.rs +++ b/backend/src/settings/steam_deck/mod.rs @@ -2,9 +2,6 @@ mod battery; mod cpu; mod gpu; mod power_dpm_force; -#[cfg(debug_assertions)] -pub mod util; -#[cfg(not(debug_assertions))] mod util; pub use battery::Battery; @@ -12,6 +9,12 @@ pub use cpu::Cpus; pub use gpu::Gpu; pub(self) use power_dpm_force::{POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT, DPM_FORCE_LIMITS_ATTRIBUTE}; +#[derive(Debug, Clone, Copy)] +pub enum Model { + LCD, + OLED, +} + pub use util::flash_led; fn _impl_checker() {