From d673241248d63397c6289274b54ddb4a7507457b Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 19 Nov 2026 22:50:34 +1100 Subject: [PATCH] iio: aop_sensors: bind als-temp and devmotion6 wherever the AOP offers them The AOP core creates a platform device for every sensor service its firmware announces, named after the service. The als-temp and devmotion6 drivers only matched the device tree compatibles "apple,aop-als-temp" and "apple,aop-devmotion6", and only the T6040/T6041 and T8132 device trees describe those services. On the M1 Pro (T6000) and the M2 (T8112) the firmware announces both services, so als-temp.N.auto and devmotion6.N.auto are created, but nothing binds to them. Register each platform driver under the name of its AOP service. The platform bus then binds it by name to the device the AOP core created, so the firmware's announcement of the service decides whether the driver binds, not a list of device trees. The module aliases change to the device's modalias (platform:als-temp, platform:devmotion6) so that the module loads automatically. The OF match tables stay, so machines whose device tree describes the services bind as before. devmotion6 needs nothing from the device tree. The temperature sensor reads optional calibration from its node; without a node it now uses the sensor defaults, which is what it does today when the bootloader supplies no calibration. The drivers and the T6040/T6041 description come from linux#1054 and linux#1247. Signed-off-by: Ryan Murray --- .../iio/common/aop_sensors/aop_devmotion.rs | 29 ++++++-- drivers/iio/common/aop_sensors/aop_temp.rs | 66 +++++++++++++------ 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/drivers/iio/common/aop_sensors/aop_devmotion.rs b/drivers/iio/common/aop_sensors/aop_devmotion.rs index e392c1435bbd4..44d5a88cd7902 100644 --- a/drivers/iio/common/aop_sensors/aop_devmotion.rs +++ b/drivers/iio/common/aop_sensors/aop_devmotion.rs @@ -18,7 +18,7 @@ use kernel::{ bindings, c_str, device::{self, Core}, dma::Coherent, - module_platform_driver, new_delayed_work, new_mutex, new_spinlock, of, platform, + driver, new_delayed_work, new_mutex, new_spinlock, of, platform, prelude::*, soc::apple::aop::{EPICService, AOP}, sync::{ @@ -29,6 +29,7 @@ use kernel::{ time::{self, delay::fsleep, Delta}, types::{ForeignOwnable, Opaque}, workqueue::{self, impl_has_delayed_work, DelayedWork, Work, WorkItem}, + ThisModule, }; const SUBTYPE_GET_PROPERTY: u16 = 10; @@ -989,10 +990,30 @@ impl platform::Driver for IIOAopDevMotionDriver { } } -module_platform_driver! { - type: IIOAopDevMotionDriver, +/// The AOP core creates the device of a service, named after the service, +/// whenever the firmware announces that service. Registering the driver under +/// the same name lets the platform bus bind it on every machine whose AOP +/// offers the service, with or without a device tree node for it. +const SERVICE_NAME: &CStr = c_str!("devmotion6"); + +#[pin_data] +struct IIOAopDevMotionModule { + #[pin] + _driver: driver::Registration>, +} + +impl kernel::InPlaceModule for IIOAopDevMotionModule { + fn init(module: &'static ThisModule) -> impl PinInit { + try_pin_init!(Self { + _driver <- driver::Registration::new(SERVICE_NAME, module), + }) + } +} + +module! { + type: IIOAopDevMotionModule, name: "iio_aop_devmotion", description: "AOP device-motion fusion driver", license: "Dual MIT/GPL", - alias: ["platform:iio_aop_devmotion"], + alias: ["platform:devmotion6"], } diff --git a/drivers/iio/common/aop_sensors/aop_temp.rs b/drivers/iio/common/aop_sensors/aop_temp.rs index e74ddb231ec4a..af4ba06224e52 100644 --- a/drivers/iio/common/aop_sensors/aop_temp.rs +++ b/drivers/iio/common/aop_sensors/aop_temp.rs @@ -6,6 +6,10 @@ //! Its fake-HID report carries a signed Q16.16 Celsius value and an AOP //! timestamp. Calibration data, when supplied by the bootloader, is sent //! unchanged before reports are enabled. +//! +//! The AOP core creates a device for the service whenever the firmware +//! announces it, and the driver binds to that device by name. A device tree +//! node for the service is optional; it only carries the calibration. use core::{ ffi::{c_int, c_void}, @@ -16,7 +20,7 @@ use core::{ use kernel::{ bindings, c_str, device::{self, Core}, - module_platform_driver, new_spinlock, of, platform, + driver, new_spinlock, of, platform, prelude::*, soc::apple::aop::{EPICService, FakehidListener, FakehidRegistration, AOP}, sync::{ @@ -25,6 +29,7 @@ use kernel::{ Arc, SpinLock, }, types::{ForeignOwnable, Opaque}, + ThisModule, }; const SUBTYPE_SET_PROPERTY: u16 = 4; @@ -81,23 +86,26 @@ struct Control { impl Control { fn new(dev: &device::Device, aop: Arc, service: EPICService) -> Result> { - let node = dev.fwnode().ok_or(ENODEV)?; let mut packets = KVec::new(); - for (prop, name) in CALIBRATION { - if !node.property_present(name) { - continue; + // Without a device tree node for the service there is no calibration + // to send; the sensor then runs on its defaults. + if let Some(node) = dev.fwnode() { + for (prop, name) in CALIBRATION { + if !node.property_present(name) { + continue; + } + let len = node.property_count_elem::(name)?; + let data = node + .property_read_array_vec::(name, len)? + .required_by(dev)?; + let Some(packet) = location0_packet(&data) else { + dev_err!(dev, "{:?} holds no calibration for location 0\n", name); + return Err(EINVAL); + }; + let mut owned = KVec::new(); + owned.extend_from_slice(packet, GFP_KERNEL)?; + packets.push((prop, owned), GFP_KERNEL)?; } - let len = node.property_count_elem::(name)?; - let data = node - .property_read_array_vec::(name, len)? - .required_by(dev)?; - let Some(packet) = location0_packet(&data) else { - dev_err!(dev, "{:?} holds no calibration for location 0\n", name); - return Err(EINVAL); - }; - let mut owned = KVec::new(); - owned.extend_from_slice(packet, GFP_KERNEL)?; - packets.push((prop, owned), GFP_KERNEL)?; } if packets.is_empty() { dev_dbg!( @@ -562,10 +570,30 @@ impl platform::Driver for IIOAopTempDriver { } } -module_platform_driver! { - type: IIOAopTempDriver, +/// The AOP core creates the device of a service, named after the service, +/// whenever the firmware announces that service. Registering the driver under +/// the same name lets the platform bus bind it on every machine whose AOP +/// offers the service, with or without a device tree node for it. +const SERVICE_NAME: &CStr = c_str!("als-temp"); + +#[pin_data] +struct IIOAopTempModule { + #[pin] + _driver: driver::Registration>, +} + +impl kernel::InPlaceModule for IIOAopTempModule { + fn init(module: &'static ThisModule) -> impl PinInit { + try_pin_init!(Self { + _driver <- driver::Registration::new(SERVICE_NAME, module), + }) + } +} + +module! { + type: IIOAopTempModule, name: "iio_aop_temp", description: "AOP temperature sensor driver", license: "Dual MIT/GPL", - alias: ["platform:iio_aop_temp"], + alias: ["platform:als-temp"], }