Skip to content

Commit

Permalink
tool: Format code
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Crawford <tcrawford@system76.com>
  • Loading branch information
crawfxrd authored and jackpot51 committed Jan 7, 2025
1 parent 60b838f commit 7e58bcc
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 372 deletions.
5 changes: 1 addition & 4 deletions tool/src/access/hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

use hidapi::HidDevice;

use crate::{
Access,
Error,
};
use crate::{Access, Error};

/// Use USB HID access, only for USB ECs
pub struct AccessHid {
Expand Down
24 changes: 5 additions & 19 deletions tool/src/access/lpc/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

use hwio::{Io, Pio};

use crate::{
Access,
Error,
SuperIo,
Timeout,
timeout,
};
use crate::{timeout, Access, Error, SuperIo, Timeout};

use super::*;

Expand All @@ -24,9 +18,7 @@ impl<T: Timeout + Send> AccessLpcDirect<T> {
pub unsafe fn new(timeout: T) -> Result<Self, Error> {
// Make sure EC ID matches
let mut sio = SuperIo::new(0x2E);
let id =
(sio.read(0x20) as u16) << 8 |
(sio.read(0x21) as u16);
let id = (sio.read(0x20) as u16) << 8 | (sio.read(0x21) as u16);
match id {
0x5570 | 0x8587 => (),
_ => return Err(Error::SuperIoId(id)),
Expand All @@ -41,24 +33,18 @@ impl<T: Timeout + Send> AccessLpcDirect<T> {

/// Read from the command space
unsafe fn read_cmd(&mut self, addr: u8) -> u8 {
Pio::<u8>::new(
self.cmd + (addr as u16)
).read()
Pio::<u8>::new(self.cmd + (addr as u16)).read()
}

/// Write to the command space
unsafe fn write_cmd(&mut self, addr: u8, data: u8) {
Pio::<u8>::new(
self.cmd + (addr as u16)
).write(data)
Pio::<u8>::new(self.cmd + (addr as u16)).write(data)
}

/// Read from the debug space
//TODO: better public interface
pub unsafe fn read_debug(&mut self, addr: u8) -> u8 {
Pio::<u8>::new(
self.dbg + (addr as u16)
).read()
Pio::<u8>::new(self.dbg + (addr as u16)).read()
}

/// Returns Ok if a command can be sent
Expand Down
30 changes: 7 additions & 23 deletions tool/src/access/lpc/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,13 @@

use std::{
fs,
io::{
self,
Read,
Write,
Seek,
SeekFrom,
},
io::{self, Read, Seek, SeekFrom, Write},
os::unix::io::AsRawFd,
path::Path,
time::Duration,
};

use crate::{
Access,
Error,
StdTimeout,
Timeout,
timeout,
};
use crate::{timeout, Access, Error, StdTimeout, Timeout};

use super::*;

Expand All @@ -35,7 +23,7 @@ impl PortLock {
if end < start {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"PortLock::new: end < start"
"PortLock::new: end < start",
));
}
let len = (end - start) + 1;
Expand All @@ -57,26 +45,22 @@ impl PortLock {
return Err(io::Error::last_os_error());
}

Ok(Self {
start,
len,
file,
})
Ok(Self { start, len, file })
}

fn seek(&mut self, offset: u16) -> io::Result<()> {
if offset >= self.len {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"PortLock::seek: offset >= len"
"PortLock::seek: offset >= len",
));
}
let port = self.start + offset;
let pos = self.file.seek(SeekFrom::Start(port as u64))?;
if pos != port as u64 {
return Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"PortLock::seek: failed to seek to port"
"PortLock::seek: failed to seek to port",
));
}
Ok(())
Expand Down Expand Up @@ -106,7 +90,7 @@ impl AccessLpcLinux {
/// Locks ports and then returns access object
pub unsafe fn new(timeout: Duration) -> Result<Self, Error> {
// TODO: is there a better way to probe before running a command?
if ! Path::new("/sys/bus/acpi/devices/17761776:00").is_dir() {
if !Path::new("/sys/bus/acpi/devices/17761776:00").is_dir() {
return Err(Error::Io(io::Error::new(
io::ErrorKind::NotFound,
"Failed to find System76 ACPI device",
Expand Down
20 changes: 5 additions & 15 deletions tool/src/access/lpc/sim.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
// SPDX-License-Identifier: MIT

use std::{
io,
net::UdpSocket,
time::Duration,
};

use crate::{
Access,
Error,
StdTimeout,
Timeout,
timeout,
};
use std::{io, net::UdpSocket, time::Duration};

use crate::{timeout, Access, Error, StdTimeout, Timeout};

use super::*;

Expand All @@ -39,15 +29,15 @@ impl AccessLpcSim {
if self.socket.send(&request)? != request.len() {
return Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"Socket request incorrect size"
"Socket request incorrect size",
));
}

let mut response = [0];
if self.socket.recv(&mut response)? != response.len() {
return Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"Socket response incorrect size"
"Socket response incorrect size",
));
}

Expand Down
10 changes: 2 additions & 8 deletions tool/src/access/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@ pub use self::hid::AccessHid;
#[cfg(feature = "hidapi")]
mod hid;

#[cfg(any(
feature = "redox_hwio",
all(feature = "std", target_os = "linux")
))]
#[cfg(any(feature = "redox_hwio", all(feature = "std", target_os = "linux")))]
pub use self::lpc::*;
#[cfg(any(
feature = "redox_hwio",
all(feature = "std", target_os = "linux")
))]
#[cfg(any(feature = "redox_hwio", all(feature = "std", target_os = "linux")))]
mod lpc;

/// Access method for running an EC command
Expand Down
Loading

0 comments on commit 7e58bcc

Please sign in to comment.