iio: light: Add support for Capella cm36686 and cm36672p sensors
Subsystems (3)
v2 cover iio: light: Add support for Capella cm36686 and cm36672p sensors
This patch series adds support for Capella cm36686 and cm36672p ambient light and proximity sensors.
Capella cm36686 is a combined ambient light and proximity sensor with adjustable integration time, interrupt and hysteresis support. It has the slave address of 0x60. cm36672p is fully compatible with cm36686, except that it is a proximity-only sensor.
Unfortunately, datasheets for these sensors are not publicly available. This code is based on Android downstream kernels for devices which did use these sensors and a previous submission for cm36672p to mailing lists:
https://github.com/LineageOS/android_kernel_xiaomi_msm8992/blob/cm-14.1/drivers/iio/light/cm36686.c
https://github.com/shakalaca/ASUS_ZenFone_ZD551KL/blob/android-6.0/kernel/drivers/input/misc/cm36283.c
https://lore.kernel.org/linux-iio/[email protected]/
The following code has been tested on Asus ZenFone 2 Laser/Selfie, which uses cm36686 as its ambient light and proximity sensor.
This is my first driver on Linux, so I appreciate all the feedback and patience I receive.
Changes since v1:
- Add copyright information.
- Sort includes in alphabetical order.
- Add trailing commas.
- Remove blank spaces where unnecessary.
- Add a fallback for capella,cm36686 compatible.
- Make power supplies required.
- Add '-microamp' suffix for capella,proximity-led-current.
- Replace local caching and i2c_smbus calls with regmap API.
- Make interrupt optional.
- Add action or reset only after setup is done.
- Replace mutex_[un]lock calls with guard(mutex)
- Add comments on where mutex is used.
- Add comments on proximity register defaults.
- Remove default proximity sensor duty ratio and integration time. Those were taken from the testing device and had no real reason to be there.
- Replace dev_err_probe on device's part ID with a warning.
- Replace chip->supplies property with a single devm_regulator_bulk_get_enable call.
- Use individual structs instead of array-style device info
- Remove enums which are no longer used.
---
Erikas Bitovtas (2):
dt-bindings: Add binding document for cm36686
iio: light: Add support for Capella cm36686 and cm36672p sensors
.../bindings/iio/light/capella,cm36686.yaml | 97 +++ drivers/iio/light/Kconfig | 11 + drivers/iio/light/Makefile | 1 + drivers/iio/light/cm36686.c | 940 +++++++++++++++++++++ 4 files changed, 1049 insertions(+)
---
base-commit: 9845cf73f7db6094c0d8419d6adb848028f4a921
change-id: 20260201-cm36686-fc7a8385f1cd
Best regards,
Signature · 1 line
Erikas Bitovtas <[email protected]>
PATCH v2 1/2 dt-bindings: Add binding document for cm36686
Document the Capella cm36686 ambient light and proximity sensor devicetree bindings.
--- .../bindings/iio/light/capella,cm36686.yaml | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+)
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml new file +97 -0
@@ -0,0 +1,97 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/capella,cm36686.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Capella cm36686 I2C Ambient Light and Proximity sensor + +maintainers: + - Erikas Bitovtas <[email protected]> + +properties: + compatible: + oneOf: + - const: capella,cm36672p + - items: + - const: capella,cm36686 + - const: capella,cm36672p + + reg: + maxItems: 1 + description: I2C address of the device. Must be 0x60 for both cm36686 + and cm36672p sensors. + + interrupts: + maxItems: 1 + + vdd-supply: + description: + Regulator that provides power to the sensor. + + vddio-supply: + description: + Regulator used to power IO and I2C bus. + + vled-supply: + description: + Regulator used to power proximity LED + + proximity-near-level: true + + capella,proximity-led-current-microamp: + description: + Current for proximity IR LED + enum: [50000, 75000, 100000, 120000, 140000, 160000, 180000, 200000] + default: 50000 + + capella,glass-factor: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Lux amplification factor to account for packaging - a number by which a + lux reading is multiplied. + default: 1 + +allOf: + - if: + properties: + compatible: + enum: + - capella,cm36672p + then: + properties: + capella,glass-factor: false + +additionalProperties: false + +required: + - compatible + - reg + - vdd-supply + - vddio-supply + - vled-supply + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + light-sensor@60 { + compatible = "capella,cm36686", "capella,cm36672p"; + reg = <0x60>; + + vdd-supply = <&pm8916_l8>; + vddio-supply = <&pm8916_l6>; + vled-supply = <®_prox_vled>; + + interrupts-extended = <&tlmm 113 IRQ_TYPE_EDGE_FALLING>; + + proximity-near-level = <30>; + + capella,glass-factor = <16>; + capella,proximity-led-current-microamp = <100000>; + }; + };
Signature · 1 line
2.53.0
Re: [PATCH v2 1/2] dt-bindings: Add binding document for cm36686
Quoted 2 lines · Erikas Bitovtas
Document the Capella cm36686 ambient light and proximity sensor devicetree bindings.
Please use subject prefixes matching the subsystem. You can get them for example with git log --oneline -- DIRECTORY_OR_FILE on the directory your patch is touching. For bindings, the preferred subjects are explained here:
https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html#i-for-patch-submitters
A nit, subject: drop second/last, redundant "bindings document". The "dt-bindings" prefix is already stating that these are bindings. See also:
https://elixir.bootlin.com/linux/v6.17-rc3/source/Documentation/devicetree/bindings/submitting-patches.rst#L18
You are just missing one redundant name for the redundant-subject-bingo.
dt-bindings: iio: Add Capella CM....
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml
Quoted 11 lines
Signed-off-by Erikas Bitovtas <[email protected]>--- .../bindings/iio/light/capella,cm36686.yaml | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+)Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml new file +0
-0
cm36672p instead, since that's the fallback... although
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml line 7
Quoted 8 lines
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml new file +7
-0@@ -0,0 +1,97 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/capella,cm36686.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Capella cm36686 I2C Ambient Light and Proximity sensor
Compatible says cm36672p... Confusing.
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml line 18
Quoted 11 lines
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml new file +11
-0+ +maintainers: + - Erikas Bitovtas <[email protected]> + +properties: + compatible: + oneOf: + - const: capella,cm36672p + - items: + - const: capella,cm36686 + - const: capella,cm36672p
Why higher number is the fallback? Explain this in the commit msg.
Quoted 12 lines
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml new file +12
-0+ + reg: + maxItems: 1 + description: I2C address of the device. Must be 0x60 for both cm36686 + and cm36672p sensors. + + interrupts: + maxItems: 1 + + vdd-supply: + description: + Regulator that provides power to the sensor.
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml line 40
Quoted 10 lines
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml new file +10
-0+ + vddio-supply: + description: + Regulator used to power IO and I2C bus. + + vled-supply: + description: + Regulator used to power proximity LED + + proximity-near-level: true
Drop
Quoted 14 lines
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml new file +14
-0+ + capella,proximity-led-current-microamp: + description: + Current for proximity IR LED + enum: [50000, 75000, 100000, 120000, 140000, 160000, 180000, 200000] + default: 50000 + + capella,glass-factor: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Lux amplification factor to account for packaging - a number by which a + lux reading is multiplied. + default: 1 +
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml line 64
Quoted 10 lines
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml new file +10
-0+allOf: + - if: + properties: + compatible: + enum: + - capella,cm36672p + then: + properties: + capella,glass-factor: false +
Missing ref to common.yaml.
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml line 65
Quoted 1 line
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml new file +1
-0+additionalProperties: false
And this goes after required as unevaluatedProperties.
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml line 73
Quoted 8 lines
Documentation/devicetree/bindings/iio/light/capella,cm36686.yaml new file +8
-0+ +required: + - compatible + - reg + - vdd-supply + - vddio-supply + - vled-supply +
Best regards,
Krzysztof
Re: [PATCH v2 1/2] dt-bindings: Add binding document for cm36686
Quoted 2 lines
Compatible says cm36672p... Confusing.
Why higher number is the fallback? Explain this in the commit msg.
This driver was initially written for cm36686, which is an ambient light and proximity sensor. But cm36672p shares the same register and regfield layout, it is just missing an ambient light channel, because it is a proximity-only sensor and has no ambient light registers.
In v1 the compatible looked like this:
compatible:
enum:
- capella,cm36686
- capella,cm36672p
Re: [PATCH v2 1/2] dt-bindings: Add binding document for cm36686
Quoted 7 lines · Erikas Bitovtas
Quoted 2 lines
Compatible says cm36672p... Confusing.
Why higher number is the fallback? Explain this in the commit msg.This driver was initially written for cm36686, which is an ambient light and proximity sensor. But cm36672p shares the same register and regfield layout, it is just missing an ambient light channel, because it is a proximity-only sensor and has no ambient light registers.
so cm36672p is the base and cm36686 is superset? Then the binding should be named as the base. Just like the compatible list.
Quoted 6 lines
In v1 the compatible looked like this:
compatible:
enum:
- capella,cm36686
- capella,cm36672p
You just removed entire context except my comment, so what do you refer to exactly? I have many of such emails per day.
Best regards,
Krzysztof
PATCH v2 2/2 iio: light: Add support for Capella cm36686 and cm36672p sensors
In reply to Erikas BitovtasThis driver adds the initial support for the Capella cm36686 ambient light and proximity sensor and cm36672p proximity sensor.
--- drivers/iio/light/Kconfig | 11 + drivers/iio/light/Makefile | 1 + drivers/iio/light/cm36686.c | 940 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 952 insertions(+)
drivers/iio/light/Kconfig +11 -0
@@ -220,6 +220,17 @@ config CM36651 To compile this driver as a module, choose M here: the module will be called cm36651. +config CM36686 + depends on I2C + tristate "CM36686 driver" + help + Say Y here if you use cm36686. + This option enables ambient light & proximity sensor using + Capella cm36686 device driver. + + To compile this driver as a module, choose M here: + the module will be called cm36686. + config IIO_CROS_EC_LIGHT_PROX tristate "ChromeOS EC Light and Proximity Sensors" depends on IIO_CROS_EC_SENSORS_CORE
drivers/iio/light/Makefile +1 -0
@@ -23,6 +23,7 @@ obj-$(CONFIG_CM3232) += cm3232.o obj-$(CONFIG_CM3323) += cm3323.o obj-$(CONFIG_CM3605) += cm3605.o obj-$(CONFIG_CM36651) += cm36651.o +obj-$(CONFIG_CM36686) += cm36686.o obj-$(CONFIG_IIO_CROS_EC_LIGHT_PROX) += cros_ec_light_prox.o obj-$(CONFIG_GP2AP002) += gp2ap002.o obj-$(CONFIG_GP2AP020A00F) += gp2ap020a00f.o
drivers/iio/light/cm36686.c new file +940 -0
940 lines not on this page · raw message
Signature · 1 line
2.53.0
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Erikas,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 9845cf73f7db6094c0d8419d6adb848028f4a921]
url: https://github.com/intel-lab-lkp/linux/commits/Erikas-Bitovtas/dt-bindings-Add-binding-document-for-cm36686/20260209-222640 base: 9845cf73f7db6094c0d8419d6adb848028f4a921 patch link: https://lore.kernel.org/r/20260209-cm36686-v2-2-a48126d2b124%40gmail.com patch subject: [PATCH v2 2/2] iio: light: Add support for Capella cm36686 and cm36672p sensors config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20260210/[email protected]/config) compiler: sh4-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260210/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> Warning: drivers/iio/light/cm36686.c:2 This comment starts with '/**', but isn't a kernel-doc comment. Refer to Documentation/doc-guide/kernel-doc.rst
* Copyright (C) 2026 Erikas Bitovtas <[email protected]>
Warning: drivers/iio/light/cm36686.c:299 This comment starts with '/**', but isn't a kernel-doc comment. Refer to Documentation/doc-guide/kernel-doc.rst
* This is taken from Xiaomi's driver for cm36686. The device tree for cm36686
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 7 lines · Erikas Bitovtas
This patch series adds support for Capella cm36686 and cm36672p ambient light and proximity sensors.
Capella cm36686 is a combined ambient light and proximity sensor with adjustable integration time, interrupt and hysteresis support. It has the slave address of
0x60. cm36672p is fully compatible with cm36686, except that it is a proximity-only sensor.
So, can we share the code (assuming there is a driver and it already uses or may be converted to regmap APIs)?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 7 lines · Erikas Bitovtas
This patch series adds support for Capella cm36686 and cm36672p ambient light and proximity sensors.
Capella cm36686 is a combined ambient light and proximity sensor with adjustable integration time, interrupt and hysteresis support. It has the slave address of
0x60. cm36672p is fully compatible with cm36686, except that it is a proximity-only sensor.So, can we share the code (assuming there is a driver and it already uses or may be converted to regmap APIs)?
Ah, it's being added with the same driver... So, have you checked if there is any similar HW with the available driver in upstream?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 10 lines · Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Erikas Bitovtas
This patch series adds support for Capella cm36686 and cm36672p ambient light and proximity sensors.
Capella cm36686 is a combined ambient light and proximity sensor with adjustable integration time, interrupt and hysteresis support. It has the slave address of
0x60. cm36672p is fully compatible with cm36686, except that it is a proximity-only sensor.
Quoted 6 lines
Quoted 2 lines
So, can we share the code (assuming there is a driver and it already uses or may be converted to regmap APIs)?
Ah, it's being added with the same driver... So, have you checked if there is any similar HW with the available driver in upstream?
I checked only for other Capella sensors, I forgot that Vishay acquired Capella Microsystems. Now that I checked, vcnl4040 uses the same registers and regfields as cm36686 and can be used instead...
I am sorry for wasting your time. Should I add a fallback to vcnl4040's devicetree schema and add cm36672p support by excluding the light channels instead?
Quoted 18 lines · On Mon, 9 Feb 2026 20:20:07 +0200 Erikas Bitovtas <[email protected]> wrote:
Quoted 10 lines · Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Erikas Bitovtas
This patch series adds support for Capella cm36686 and cm36672p ambient light and proximity sensors.
Capella cm36686 is a combined ambient light and proximity sensor with adjustable integration time, interrupt and hysteresis support. It has the slave address of
0x60. cm36672p is fully compatible with cm36686, except that it is a proximity-only sensor.Quoted 6 lines
Quoted 2 lines
So, can we share the code (assuming there is a driver and it already uses or may be converted to regmap APIs)?
Ah, it's being added with the same driver... So, have you checked if there is any similar HW with the available driver in upstream?
Quoted 6 lines
I checked only for other Capella sensors, I forgot that Vishay acquired Capella Microsystems. Now that I checked, vcnl4040 uses the same registers and regfields as cm36686 and can be used instead...
I am sorry for wasting your time. Should I add a fallback to vcnl4040's devicetree schema and add cm36672p support by excluding the light channels instead?
Sounds good to me.
Jonathan