Skip to content

io: light: tcs3472: Add TMD3782 proximity support#445

Open
playday3008 wants to merge 8 commits intomsm8916-mainline:msm8916/6.12.1from
playday3008:wip/msm8916/6.12.1/tmd3782
Open

io: light: tcs3472: Add TMD3782 proximity support#445
playday3008 wants to merge 8 commits intomsm8916-mainline:msm8916/6.12.1from
playday3008:wip/msm8916/6.12.1/tmd3782

Conversation

@playday3008
Copy link
Copy Markdown

Add TMD3782 RGBC + proximity sensor support to the tcs3472 driver and enable it on Samsung Galaxy A5/A7 device trees.

Driver changes (patches 1-6):

  • dt-bindings: Add amstaos,tcs3472.yaml schema
  • OF match table, regulator support, per-variant chip_info struct
  • TMD3782 register definitions, chip ID detection, CONTROL/PPULSE init
  • Proximity channel (IIO_PROXIMITY) with threshold events (rising/falling)
  • Direct-mode and buffered proximity reads with PEN/WEN coordination

Device tree changes (patches 7-8):

  • msm8916-samsung-a5u-eur: TMD3782 on blsp_i2c2, GPIO8 VDD, GPIO113 IRQ
  • msm8939-samsung-a7: TMD3782 on bit-banged i2c-sensor, pm8916_l17 VDD

Based on msm8916/6.12.1 from msm8916-mainline/linux.

Comment thread arch/arm64/boot/dts/qcom/msm8916-samsung-a5u-eur.dts Outdated
Comment thread arch/arm64/boot/dts/qcom/msm8916-samsung-a5u-eur.dts Outdated
Comment thread arch/arm64/boot/dts/qcom/msm8916-samsung-a5u-eur.dts Outdated
Comment thread arch/arm64/boot/dts/qcom/msm8939-samsung-a7.dts Outdated
Comment thread arch/arm64/boot/dts/qcom/msm8939-samsung-a7.dts Outdated
Comment thread drivers/iio/light/tcs3472.c
@wonderfulShrineMaidenOfParadise
Copy link
Copy Markdown

arm64: dts: qcom: msm8916-samsung-a5u-eur: Add proximity/light sensor
...

The a5-zt variant inherits this node via its include of a5u-eur.dts.

Note that a5-zt no longer exists in newer branches and it's now a5ltezt.
Besides a5ltezt is not in mainline.

Comment thread arch/arm64/boot/dts/qcom/msm8939-samsung-a7.dts Outdated
PlayDay added 8 commits April 29, 2026 16:25
Add devicetree binding for the AMS/TAOS TCS3472 RGBC color light sensor
and TMD3782 RGBC + proximity sensor. The TCS3472 has no existing binding
despite having a mainline driver since 2013.

The TMD3782 is a superset of TCS3472 adding an integrated proximity
detector with IR LED. Additional properties for proximity configuration
(pulse count, LED current, LED supply) are optional and only relevant
for TMD3782.
Add of_device_id table for devicetree-based probing of TCS3472 and
TMD3782 sensors. Add optional vdd/vddio regulator support with 2.4ms
power-on settling delay.

Update tcs3472_powerdown() to write 0x00 for full chip power-down
instead of only clearing AEN+PON. This is a behavior change: the old
code preserved AIEN, the new code clears everything. This is safe
because resume now performs a full register restore.

Update resume to rewrite all configuration registers (ATIME, WTIME,
thresholds, PERS, CONFIG, CONTROL, ENABLE) and clear stale interrupt
flags. This hardens against potential register state loss during PON=0.

Remove hardcoded IRQF_TRIGGER_FALLING from request_threaded_irq to let
the devicetree specify the interrupt trigger type.
Add tcs3472_chip_info struct to hold per-variant channel arrays,
channel counts, and feature flags. This prepares for adding TMD3782
proximity support without scattering variant checks throughout the
driver.

No functional change — only TCS3472 is populated. The TMD3782 entry
will be added when proximity support lands.
Add proximity register definitions for the TMD3782 (PILT, PIHT, PPULSE,
PDATA, PIEN, PEN, WEN, PINT, PVALID) and interrupt clear commands.

Detect TMD3782 chip IDs (0x60 for TMD37821, 0x69 for TMD37823) in
probe. Initialize the CONTROL register with the mandatory bit 5 and
LED drive current from the led-max-microamp DT property. Configure
proximity pulse count from DT (default 8) and set PPERS to 3 to match
downstream behavior.

Fix the PERS register write to merge both APERS and PPERS nibbles,
preventing the existing bug where writing APERS clobbers PPERS.

Extend resume to restore proximity thresholds, pulse count, and clear
stale interrupt flags from both ALS and proximity.
Add proximity channel (IIO_PROXIMITY, scan_index 4) to TMD3782 channel
array. The proximity data register at 0x1C fits the existing trigger
handler's CDATA+2*i arithmetic naturally: 0xB4+8 = 0xBC.

Add proximity threshold events (rising/falling/enable) with a separate
event spec — no IIO_EV_INFO_PERIOD since PPERS uses a linear count,
not the non-linear APERS mapping. PPERS is fixed at 3 (not configurable
by userspace in v1).

Extend event value read/write for proximity thresholds (PILT/PIHT).
Extend write_event_config to manage PEN+WEN+PIEN for proximity events,
with proper coordination against buffer enable state. Guard against
enabling interrupts when no IRQ is configured.

Extend interrupt handler to check both AINT and PINT in STATUS and
clear only the interrupts actually observed, preventing a race where
a new interrupt between STATUS read and clear would be silently lost.
Extend tcs3472_req_data() to accept a status mask parameter for polling
AVALID, PVALID, or both.

For direct-mode proximity reads (in_proximity_raw), temporarily enable
PEN+WEN when no events or buffer are active. Uses a re-check-under-lock
pattern on teardown to avoid clobbering concurrent event enables.

Add buffer preenable/postdisable callbacks that manage PEN+WEN when the
proximity channel (scan_index 4) is in the active scan mask. This
prevents the trigger handler from hanging on PVALID when PEN is off.
Coordinates with event enable state so neither path clobbers the other.
Add TMD3782 RGBC + proximity sensor on blsp_i2c2 at address 0x39.
Uses GPIO113 as level-triggered interrupt input and GPIO8 as VDD
enable for the sensor (modeled as a fixed regulator).

The sensor shares the I2C bus with the existing BMC150 accelerometer
and magnetometer. VDD (GPIO8) and VDDIO (pm8916_l5) need explicit
control.

The a5-zt variant inherits this node via its include of a5u-eur.dts.
Add TMD3782 RGBC + proximity sensor on the bit-banged i2c-sensor bus
at address 0x39. Uses GPIO113 as level-triggered interrupt input.

Unlike the A5 which uses a GPIO-controlled fixed regulator for sensor
VDD, the A7 powers the sensor directly from pm8916_l17.
@playday3008 playday3008 force-pushed the wip/msm8916/6.12.1/tmd3782 branch from 803ff70 to 8798788 Compare April 29, 2026 14:27
@playday3008
Copy link
Copy Markdown
Author

Note that a5-zt no longer exists in newer branches and it's now a5ltezt. Besides a5ltezt is not in mainline.

Well, I was working against same kernel version that was in pmOS edge for Galaxy A5, couldn't get latest kernel from source running, so, was writing patches against same version that was on device.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants