Skip to content

Commit 13ee833

Browse files
committed
fixup! iio: common: Add AOP sensor drivers.
switch to platform::Device Signed-off-by: Janne Grunau <[email protected]>
1 parent 826db8b commit 13ee833

3 files changed

Lines changed: 19 additions & 25 deletions

File tree

drivers/iio/common/aop_sensors/aop_als.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,28 @@
55
//! Copyright (C) The Asahi Linux Contributors
66
77
use kernel::{
8-
bindings, c_str, device,
8+
bindings, c_str,
99
iio::common::aop_sensors::{AopSensorData, IIORegistration, MessageProcessor},
1010
module_platform_driver,
1111
of::{self, Node},
1212
platform,
1313
prelude::*,
1414
soc::apple::aop::{EPICService, AOP},
1515
sync::Arc,
16-
types::{ARef, ForeignOwnable},
16+
types::ForeignOwnable,
1717
};
1818

1919
const EPIC_SUBTYPE_SET_ALS_PROPERTY: u16 = 0x4;
2020

21-
fn enable_als(
22-
aop: &dyn AOP,
23-
dev: &ARef<device::Device>,
24-
of: &Node,
25-
svc: &EPICService,
26-
) -> Result<()> {
21+
fn enable_als(aop: &dyn AOP, dev: &platform::Device, of: &Node, svc: &EPICService) -> Result<()> {
2722
if let Some(prop) = of.find_property(c_str!("apple,als-calibration")) {
2823
set_als_property(aop, svc, 0xb, prop.value())?;
2924
set_als_property(aop, svc, 0, &200000u32.to_le_bytes())?;
3025
} else {
31-
dev_warn!(dev, "ALS Calibration not found, will not enable it");
26+
dev_warn!(
27+
dev.as_ref(),
28+
"ALS Calibration not found, will not enable it"
29+
);
3230
}
3331
Ok(())
3432
}
@@ -85,7 +83,7 @@ impl platform::Driver for IIOAopAlsDriver {
8583
pdev: &mut platform::Device,
8684
_info: Option<&()>,
8785
) -> Result<Pin<KBox<IIOAopAlsDriver>>> {
88-
let dev = pdev.get_device();
86+
let dev = pdev.as_ref();
8987
let parent = dev.parent().unwrap();
9088
// SAFETY: our parent is AOP, and AopDriver is repr(transparent) for Arc<dyn Aop>
9189
let adata_ptr = unsafe { Pin::<KBox<Arc<dyn AOP>>>::borrow(parent.get_drvdata()) };
@@ -98,9 +96,9 @@ impl platform::Driver for IIOAopAlsDriver {
9896
.get_child_by_name(c_str!("als"))
9997
.ok_or(EIO)?;
10098
let ty = bindings::BINDINGS_IIO_LIGHT;
101-
let data = AopSensorData::new(dev.clone(), ty, MsgProc(40))?;
99+
let data = AopSensorData::new(pdev.clone(), ty, MsgProc(40))?;
102100
adata.add_fakehid_listener(service, data.clone())?;
103-
enable_als(adata.as_ref(), &dev, &of, &service)?;
101+
enable_als(adata.as_ref(), pdev, &of, &service)?;
104102
let info_mask = 1 << bindings::BINDINGS_IIO_CHAN_INFO_PROCESSED;
105103
Ok(KBox::pin(
106104
IIOAopAlsDriver(IIORegistration::<MsgProc>::new(

drivers/iio/common/aop_sensors/aop_las.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl platform::Driver for IIOAopLasDriver {
3636
pdev: &mut platform::Device,
3737
_info: Option<&()>,
3838
) -> Result<Pin<KBox<IIOAopLasDriver>>> {
39-
let dev = pdev.get_device();
39+
let dev = pdev.as_ref();
4040
let parent = dev.parent().unwrap();
4141
// SAFETY: our parent is AOP, and AopDriver is repr(transparent) for Arc<dyn Aop>
4242
let adata_ptr = unsafe { Pin::<KBox<Arc<dyn AOP>>>::borrow(parent.get_drvdata()) };
@@ -45,7 +45,7 @@ impl platform::Driver for IIOAopLasDriver {
4545
let service = unsafe { *((*dev.as_raw()).platform_data as *const EPICService) };
4646

4747
let ty = bindings::BINDINGS_IIO_ANGL;
48-
let data = AopSensorData::new(dev, ty, MsgProc)?;
48+
let data = AopSensorData::new(pdev.clone(), ty, MsgProc)?;
4949
adata.add_fakehid_listener(service, data.clone())?;
5050
let info_mask = 1 << bindings::BINDINGS_IIO_CHAN_INFO_RAW;
5151
Ok(KBox::pin(

rust/kernel/iio/common/aop_sensors.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,26 @@ use core::ptr;
99
use core::sync::atomic::{AtomicU32, Ordering};
1010

1111
use kernel::{
12-
bindings, device,
13-
prelude::*,
14-
soc::apple::aop::FakehidListener,
15-
sync::Arc,
16-
types::{ARef, ForeignOwnable},
17-
ThisModule,
12+
bindings, platform, prelude::*, soc::apple::aop::FakehidListener, sync::Arc,
13+
types::ForeignOwnable, ThisModule,
1814
};
1915

2016
pub trait MessageProcessor {
2117
fn process(&self, message: &[u8]) -> u32;
2218
}
2319

2420
pub struct AopSensorData<T: MessageProcessor> {
25-
dev: ARef<device::Device>,
21+
dev: platform::Device,
2622
ty: u32,
2723
value: AtomicU32,
2824
msg_proc: T,
2925
}
3026

3127
impl<T: MessageProcessor> AopSensorData<T> {
32-
pub fn new(dev: ARef<device::Device>, ty: u32, msg_proc: T) -> Result<Arc<AopSensorData<T>>> {
28+
pub fn new(dev: platform::Device, ty: u32, msg_proc: T) -> Result<Arc<AopSensorData<T>>> {
3329
Ok(Arc::new(
3430
AopSensorData {
35-
dev: dev.clone(),
31+
dev,
3632
ty,
3733
value: AtomicU32::new(0),
3834
msg_proc,
@@ -124,7 +120,7 @@ impl<T: MessageProcessor + 'static> IIORegistration<T> {
124120
registered: false,
125121
_p: PhantomData,
126122
};
127-
this.dev = unsafe { bindings::iio_device_alloc(data.dev.as_raw(), 0) };
123+
this.dev = unsafe { bindings::iio_device_alloc(data.dev.as_ref().as_raw(), 0) };
128124
unsafe {
129125
(*this.dev).priv_ = data.clone().into_foreign() as _;
130126
(*this.dev).name = name.as_ptr() as _;
@@ -135,7 +131,7 @@ impl<T: MessageProcessor + 'static> IIORegistration<T> {
135131
}
136132
let ret = unsafe { bindings::__iio_device_register(this.dev, module.as_ptr()) };
137133
if ret < 0 {
138-
dev_err!(data.dev, "Unable to register iio sensor");
134+
dev_err!(data.dev.as_ref(), "Unable to register iio sensor");
139135
return Err(Error::from_errno(ret));
140136
}
141137
this.registered = true;

0 commit comments

Comments
 (0)