From 98e8788ba6f9a00e71e585e4625b4549e0d08fc8 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 30 Oct 2023 15:31:54 +0800 Subject: [PATCH] chromium_ec: Use portio if /dev/cros_ec does not exist Then users don't manually have to specify `--driver portio` if the cros_ec kernel driver is not loaded. Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/cros_ec.rs | 2 +- framework_lib/src/chromium_ec/mod.rs | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/framework_lib/src/chromium_ec/cros_ec.rs b/framework_lib/src/chromium_ec/cros_ec.rs index a3b4928a..372c45ff 100644 --- a/framework_lib/src/chromium_ec/cros_ec.rs +++ b/framework_lib/src/chromium_ec/cros_ec.rs @@ -55,7 +55,7 @@ struct CrosEcCommandV2 { data: [u8; IN_SIZE], } -const DEV_PATH: &str = "/dev/cros_ec"; +pub const DEV_PATH: &str = "/dev/cros_ec"; lazy_static! { static ref CROS_EC_FD: Arc>> = Arc::new(Mutex::new(None)); diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index e0a3094a..4ca04926 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -239,14 +239,20 @@ impl Default for CrosEc { /// /// Depending on the availability we choose the first one as default fn available_drivers() -> Vec { - vec![ - #[cfg(feature = "win_driver")] - CrosEcDriverType::Windows, - #[cfg(feature = "cros_ec_driver")] - CrosEcDriverType::CrosEc, - #[cfg(not(feature = "windows"))] - CrosEcDriverType::Portio, - ] + let mut drivers = vec![]; + + #[cfg(feature = "win_driver")] + drivers.push(CrosEcDriverType::Windows); + + #[cfg(feature = "cros_ec_driver")] + if std::path::Path::new(cros_ec::DEV_PATH).exists() { + drivers.push(CrosEcDriverType::CrosEc); + } + + #[cfg(not(feature = "windows"))] + drivers.push(CrosEcDriverType::Portio); + + drivers } impl CrosEc {