Skip to content

Commit 98e8788

Browse files
committed
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 <[email protected]>
1 parent 13e9c67 commit 98e8788

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

framework_lib/src/chromium_ec/cros_ec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct CrosEcCommandV2 {
5555
data: [u8; IN_SIZE],
5656
}
5757

58-
const DEV_PATH: &str = "/dev/cros_ec";
58+
pub const DEV_PATH: &str = "/dev/cros_ec";
5959

6060
lazy_static! {
6161
static ref CROS_EC_FD: Arc<Mutex<Option<std::fs::File>>> = Arc::new(Mutex::new(None));

framework_lib/src/chromium_ec/mod.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,20 @@ impl Default for CrosEc {
239239
///
240240
/// Depending on the availability we choose the first one as default
241241
fn available_drivers() -> Vec<CrosEcDriverType> {
242-
vec![
243-
#[cfg(feature = "win_driver")]
244-
CrosEcDriverType::Windows,
245-
#[cfg(feature = "cros_ec_driver")]
246-
CrosEcDriverType::CrosEc,
247-
#[cfg(not(feature = "windows"))]
248-
CrosEcDriverType::Portio,
249-
]
242+
let mut drivers = vec![];
243+
244+
#[cfg(feature = "win_driver")]
245+
drivers.push(CrosEcDriverType::Windows);
246+
247+
#[cfg(feature = "cros_ec_driver")]
248+
if std::path::Path::new(cros_ec::DEV_PATH).exists() {
249+
drivers.push(CrosEcDriverType::CrosEc);
250+
}
251+
252+
#[cfg(not(feature = "windows"))]
253+
drivers.push(CrosEcDriverType::Portio);
254+
255+
drivers
250256
}
251257

252258
impl CrosEc {

0 commit comments

Comments
 (0)