Skip to content

iio: aop_sensors: aop_als: make calibration firmware optional#457

Closed
juicecultus wants to merge 3 commits intoAsahiLinux:fairydustfrom
juicecultus:fairydust
Closed

iio: aop_sensors: aop_als: make calibration firmware optional#457
juicecultus wants to merge 3 commits intoAsahiLinux:fairydustfrom
juicecultus:fairydust

Conversation

@juicecultus
Copy link

Summary

Make the ALS (Ambient Light Sensor) calibration step non-fatal so the aop_als driver can probe successfully even when apple/aop-als-cal.bin is not present.

Problem

The ALS driver currently fails to probe if the calibration firmware file is missing. On many Apple Silicon machines (particularly M2 MacBook Air), the calibration data is not embedded in the Apple Device Tree and must be extracted separately from a macOS ioreg dump. This means the ALS sensor is completely unusable out of the box.

Changes

  • If the firmware file is present, send calibration data as before
  • If missing, send an empty calibration command and log a warning
  • Ignore the AOP's error response to the calibration command (the AOP returns 0xE00002BC even for valid calibration data extracted from macOS)
  • Always proceed to set the polling interval, which activates the sensor stream

Testing

Tested on MacBook Air 15" M2 (J415) with VD6286 sensor, Asahi Fedora 42, kernel 6.18.10-402:

  • Without cal file: sensor activates, reports lux values (uncalibrated)
  • With cal file extracted from macOS: sensor reports calibrated lux values
  • Verified via /sys/bus/iio/devices/iio:device1/in_illuminance_input and iio-sensor-proxy

Related

Calibration extraction tool and auto-brightness userspace daemon: https://github.com/juicecultus/asahi-auto-brightness

Justin added 3 commits February 22, 2026 22:18
Implement atcphy_configure_pipehandler_usb4() to enable USB4/Thunderbolt
PHY mode on Apple Silicon. Previously this fell back to USB2 with a
warning, preventing Thunderbolt displays from working.

The USB4 pipehandler follows the same BIST sequence as USB3 but switches
the PIPE mux to USB4 (CLK=2, DATA=1 vs USB3 CLK=1, DATA=0). The CIO
tunables for USB4 lane configuration are already loaded from the ADT.

Derived from clean-room analysis of m1n1 hypervisor traces capturing
macOS 13.5 hardware register access on T8112 (M2 MacBook Air).

Observed macOS PHY transition sequence:
  1. USB2 PHY init in host mode on port
  2. DWC3 controller configured as host
  3. USB2 PHY teardown (isolation, power down, clock gating)
  4. USB4 pipehandler mux + BIST sequence (this patch)
…river skeleton

Add initial driver and DT nodes for the Apple ACIO Thunderbolt/USB4
host controller found in Apple Silicon SoCs.

The ACIO is a platform-based Thunderbolt controller consisting of:
  - NHI-like register space for ring buffer DMA
  - IOP coprocessor running Thunderbolt firmware via RTKit
  - DART (IOMMU) for DMA isolation
  - Connection to ATC PHY for USB4 physical layer

This initial commit includes:
  - DT nodes for T8112 (M2): acio0/1, dart-acio0/1, acio-cpu0/1
    (disabled by default until driver is ready)
  - Platform driver skeleton that probes NHI registers and reads caps
  - Kconfig/Makefile integration as CONFIG_APPLE_ACIO
  - RTKit callback stubs for IOP coprocessor communication

Hardware addresses derived from clean-room analysis of macOS ioreg
device tree dumps on T8112 (M2 MacBook Air 15-inch).

TODO:
  - Boot IOP coprocessor via RTKit
  - Initialize ring buffers for Thunderbolt control channel
  - Bridge to Linux thunderbolt subsystem for tunnel management
  - Enable PCIe/DP/USB3 tunneling
The ALS driver currently fails to probe if apple/aop-als-cal.bin is
missing. On many Apple Silicon machines (particularly M2 MacBook Air),
the calibration data is not available in the Apple Device Tree and must
be extracted separately from a macOS ioreg dump.

Make the calibration step non-fatal:
- If the firmware file is present, send it as before.
- If missing, send an empty calibration command and log a warning.
- Ignore the AOP's error response to the calibration command (the AOP
  returns 0xE00002BC even for valid calibration data from macOS).
- Always proceed to set the polling interval, which activates the
  sensor stream.

Without this change, the ALS sensor is completely unusable on systems
where the calibration file has not yet been provisioned.

Tested on MacBook Air 15" M2 (J415) with VD6286 sensor:
- Without cal file: sensor activates, reports lux values (uncalibrated)
- With cal file extracted from macOS: sensor reports calibrated values

Signed-off-by: Justin <justin@juicecultus.dev>
@WhatAmISupposedToPutHere

We intend to handle the calibration files correctly and not use empty calibrations. AsahiLinux/asahi-installer#406

@juicecultus
Copy link
Author

Thanks for the pointer to AsahiLinux/asahi-installer#406 — that's clearly the right approach. Happy to close this PR in favour of the installer-based extraction.

A couple of data points from our testing that may be useful:

  1. Cross-model calibration works: We extracted calibration from a J413 (MacBook Air 13" M2) and it's working fine on a J415 (MacBook Air 15" M2). This aligns with @jannau's observation that the results may not be heavily dependent on per-unit calibration.

  2. Without calibration, the sensor still activates: With our patch (empty calibration fallback), the ALS sensor streams lux values — just uncalibrated. This could be useful as a degraded-but-functional fallback for users who installed before the installer gains calibration extraction, though I understand if you'd prefer not to ship that.

  3. Userspace auto-brightness daemon: We've published a working userspace solution at juicecultus/asahi-auto-brightness that reads lux from IIO sysfs and controls brightness via KDE's D-Bus API (with SuppressIndicator to avoid OSD). Works well with the calibrated sensor. Could be useful for the community until desktop environments add native ALS support for this hardware.

Closing this PR in favour of the installer approach.

@artun42
Copy link

artun42 commented Feb 25, 2026

btw, there's strong anti ai policy in this project, be aware of that.

https://asahilinux.org/docs/project/policies/slop/

@WhatAmISupposedToPutHere
3. **Userspace auto-brightness daemon**: We've published a working userspace solution at [juicecultus/asahi-auto-brightness](https://github.com/juicecultus/asahi-auto-brightness) that reads lux from IIO sysfs and controls brightness via KDE's D-Bus API (with SuppressIndicator to avoid OSD). Works well with the calibrated sensor. Could be useful for the community until desktop environments add native ALS support for this hardware.

I regret to inform you that it appears that you have re-invented the wheel in this case. KDE Plasma already supports ambient light sensors natively, by going into "display & monitor" settings and enabling "Automatically adapt to environment". If you do not see that option - install "iio-sensor-proxy", then log out and log back in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants