Support for Texas Instruments OPT4060 RGBW Color sensor.
Subsystems (3)
v6 cover Support for Texas Instruments OPT4060 RGBW Color sensor.
This patch series adds support for Texas Instruments OPT4060 RGBW Color sensor using the i2c interface.
The driver exposes raw adc values for red, green, blue and clear. The illuminance is exposed as a calculated value in lux, the calculation uses the wide spectrum green channel as base. The relative normalized color components for red, green and blue are exposed as scaled values. Those values give the relative colors independently of the light intensity. Integration time can be configured through sysfs as well. The OPT4060 sensor supports both rising and falling threshold interrupts. These interrupts are exposed as IIO events. The driver also implements an IIO triggered buffer with a trigger for conversion ready interrupts.
Changes in v6:
- Modified the driver to work with any trigger. Verified using iio-trig-sysfs.
- Fixed return in opt4060_trigger_set_state(...).
- Break added in opt4060_read_ev_period(...).
- Struct and variable declaration chnages in opt4060_trigger_handler(...).
- Events changed to modified and not unmodified.
- Moved variable declaration from case statement in opt4060_read_event(...), and opt4060_write_event(...), found by test robot.
- Init_completion() moved to a place related to IRQ.
- Documentation: Added opt4060.rst with description of calculations.
- Ducumentation: Added missing _raw parameters in Documentation/ABI/testing/sysfs-bus-iio
- Link to V5: https://lore.kernel.org/lkml/[email protected]/
Changes in v5:
- Cover letter: Description adapted to new channel and trigger setup.
- Trigger for threshold removed.
- Channel setup modified according to email discussion.
- Switched to aligned_s64 from linux-next.
- Endianness in buffer changed to IIO_CPU.
- opt4060_read_raw_value(...) changed to avoid endian issue plus early return.
- opt4060_read_chan_value(...) split of in several for new channel setup.
- Improved return values in multiple places.
- The preenable callback removed, functionality moved to set_state.
- Irq setup removed from opt4060_irq_thread(...).
- Flipped logic with early return in opt4060_trigger_one_shot(...).
- devm_add_action_or_reset(...) moved to after opt4060_load_defaults(...).
- Documentation: Added sysfs-bus-iio-light-opt4060 with channel descriptions.
- Added hard coded name indio_dev->name.
- Modified opt4060_volatile_reg(...) to make test robot happy.
- Link to V4: https://lore.kernel.org/lkml/[email protected]/
Changes in v4:
- Fix for a warning found by test robot in opt4060_write_event(...).
- Correction of early return in opt4060_write_event(...) and opt4060_read_event(...), missed from review of version 2.
- Correction of timeout for sample conversion.
- Correction of bug when changing integration time with buffer enabled.
- Link to V3: https://lore.kernel.org/lkml/[email protected]/
Changes in v3:
- Cover letter: Removed lux from description.
- OPT_4060_DRV_NAME define removed.
- Corrected alignment for struct opt4060_buffer.
- Added description of the CRC calculation.
- Cleaned variable declaration in several places.
- Added a path for the non-irq case in opt4060_read_chan_value(...).
- Added a description of processed values.
- Use of regmap_clear_bits in opt4060_power_down(...).
- Switched to IIO_INTENSITY instead of IIO_LIGHT.
- Correction of channel index in IIO_UNMOD_EVENT_CODE, found by test robot.
- Added iio_chan_spec for the non-irq case without events.
- Fixed braces in a few if-else statements.
- Refactoring with early returns in a few places to reduce indentation.
- Replaced for_each_set_bit with iio_for_each_active_channel.
- Removed various too obvious comments.
- Fixed various other code style problems.
- Link to V2: https://lore.kernel.org/lkml/[email protected]/
Changes in v2:
- dt-bindings: Removed incorrect allOf.
- dt-bindings: Changed to generic node name.
- Correction in opt4060_trigger_one_shot(...) for continuous mode.
- Correction in opt4060_power_down(...), wrong register was read.
- Corrected usage of active_scan_mask in opt4060_trigger_handler(...).
- Clean-up of various comments.
- Link to V1: https://lore.kernel.org/lkml/[email protected]/
Per-Daniel Olsson (2):
dt-bindings: iio: light: Document TI OPT4060 RGBW sensor
iio: light: Add support for TI OPT4060 color sensor
Documentation/ABI/testing/sysfs-bus-iio | 4 + .../bindings/iio/light/ti,opt4060.yaml | 51 + Documentation/iio/index.rst | 1 + Documentation/iio/opt4060.rst | 52 + drivers/iio/light/Kconfig | 13 + drivers/iio/light/Makefile | 1 + drivers/iio/light/opt4060.c | 1295 +++++++++++++++++ 7 files changed, 1417 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/ti,opt4060.yaml create mode 100644 Documentation/iio/opt4060.rst create mode 100644 drivers/iio/light/opt4060.c
--
2.39.5
PATCH v6 1/2 dt-bindings: iio: light: Document TI OPT4060 RGBW sensor
Add devicetree bindings for the OPT4060 RGBW color sensor.
--- .../bindings/iio/light/ti,opt4060.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/ti,opt4060.yaml
Documentation/devicetree/bindings/iio/light/ti,opt4060.yaml new file +51 -0
@@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/ti,opt4060.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Texas Instruments OPT4060 RGBW Color Sensor + +maintainers: + - Per-Daniel Olsson <[email protected]> + +description: + Texas Instrument RGBW high resolution color sensor over I2C. + https://www.ti.com/lit/gpn/opt4060 + +properties: + compatible: + enum: + - ti,opt4060 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: + description: Regulator that provides power to the sensor. + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + light-sensor@44 { + compatible = "ti,opt4060"; + reg = <0x44>; + vdd-supply = <&vdd_reg>; + interrupt-parent = <&gpio5>; + interrupts = <13 IRQ_TYPE_EDGE_FALLING>; + }; + }; +...
Signature · 1 line
2.39.5
Re: [PATCH v6 1/2] dt-bindings: iio: light: Document TI OPT4060 RGBW sensor
Quoted 31 lines · Per-Daniel Olsson
Add devicetree bindings for the OPT4060 RGBW color sensor.
Reviewed-by Krzysztof Kozlowski <[email protected]>Signed-off-by Per-Daniel Olsson <[email protected]>--- .../bindings/iio/light/ti,opt4060.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/ti,opt4060.yamlDocumentation/devicetree/bindings/iio/light/ti,opt4060.yaml new file +16
-0@@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/ti,opt4060.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Texas Instruments OPT4060 RGBW Color Sensor + +maintainers: + - Per-Daniel Olsson <[email protected]> + +description: + Texas Instrument RGBW high resolution color sensor over I2C. + https://www.ti.com/lit/gpn/opt4060 + +properties:
Documentation/devicetree/bindings/iio/light/ti,opt4060.yaml line 26
Quoted 10 lines
Documentation/devicetree/bindings/iio/light/ti,opt4060.yaml new file +10
-0+ compatible: + enum: + - ti,opt4060 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 +
You could simply use vdd-supply: true, as it is obvious what it does.
Documentation/devicetree/bindings/iio/light/ti,opt4060.yaml line 29
Quoted 3 lines
Documentation/devicetree/bindings/iio/light/ti,opt4060.yaml new file +3
-0+ vdd-supply: + description: Regulator that provides power to the sensor. +
is vdd-supply not required?
Quoted 12 lines
Documentation/devicetree/bindings/iio/light/ti,opt4060.yaml new file +12
-0+required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>; + #size-cells = <0>;
Documentation/devicetree/bindings/iio/light/ti,opt4060.yaml line 51
Quoted 10 lines
Documentation/devicetree/bindings/iio/light/ti,opt4060.yaml new file +10
-0+ + light-sensor@44 { + compatible = "ti,opt4060"; + reg = <0x44>; + vdd-supply = <&vdd_reg>; + interrupt-parent = <&gpio5>; + interrupts = <13 IRQ_TYPE_EDGE_FALLING>; + }; + }; +...
Best regards,
Javier Carrasco
PATCH v6 2/2 iio: light: Add support for TI OPT4060 color sensor
In reply to Per-Daniel OlssonAdd support for Texas Instruments OPT4060 RGBW Color sensor.
--- Documentation/ABI/testing/sysfs-bus-iio | 4 + Documentation/iio/index.rst | 1 + Documentation/iio/opt4060.rst | 52 + drivers/iio/light/Kconfig | 13 + drivers/iio/light/Makefile | 1 + drivers/iio/light/opt4060.c | 1295 +++++++++++++++++++++++ 6 files changed, 1366 insertions(+) create mode 100644 Documentation/iio/opt4060.rst create mode 100644 drivers/iio/light/opt4060.c
Documentation/ABI/testing/sysfs-bus-iio +4 -0
@@ -1633,6 +1633,10 @@ What: /sys/.../iio:deviceX/in_intensityY_uv_raw What: /sys/.../iio:deviceX/in_intensityY_uva_raw What: /sys/.../iio:deviceX/in_intensityY_uvb_raw What: /sys/.../iio:deviceX/in_intensityY_duv_raw +What: /sys/.../iio:deviceX/in_intensity_red_raw +What: /sys/.../iio:deviceX/in_intensity_green_raw +What: /sys/.../iio:deviceX/in_intensity_blue_raw +What: /sys/.../iio:deviceX/in_intensity_clear_raw KernelVersion: 3.4 Contact: [email protected] Description:
Documentation/iio/index.rst +1 -0
@@ -29,3 +29,4 @@ Industrial I/O Kernel Drivers adxl380 bno055 ep93xx_adc + opt4060
Documentation/iio/opt4060.rst new file +52 -0
53 lines not on this page · raw message
drivers/iio/light/Kconfig +13 -0
@@ -491,6 +491,19 @@ config OPT4001 If built as a dynamically linked module, it will be called opt4001. +config OPT4060 + tristate "Texas Instruments OPT4060 RGBW Color Sensor" + depends on I2C + select REGMAP_I2C + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + If you say Y or M here, you get support for Texas Instruments + OPT4060 RGBW Color Sensor. + + If built as a dynamically linked module, it will be called + opt4060. + config PA12203001 tristate "TXC PA12203001 light and proximity sensor" depends on I2C
drivers/iio/light/Makefile +1 -0
@@ -42,6 +42,7 @@ obj-$(CONFIG_MAX44009) += max44009.o obj-$(CONFIG_NOA1305) += noa1305.o obj-$(CONFIG_OPT3001) += opt3001.o obj-$(CONFIG_OPT4001) += opt4001.o +obj-$(CONFIG_OPT4060) += opt4060.o obj-$(CONFIG_PA12203001) += pa12203001.o obj-$(CONFIG_ROHM_BU27008) += rohm-bu27008.o obj-$(CONFIG_ROHM_BU27034) += rohm-bu27034.o
drivers/iio/light/opt4060.c new file +1295 -0
1,295 lines not on this page · raw message
Signature · 1 line
2.39.5
Re: [PATCH v6 2/2] iio: light: Add support for TI OPT4060 color sensor
Hello Per-Daniel,
A few minor comments inline, LGTM in general.
Quoted 3 lines · Per-Daniel Olsson
Add support for Texas Instruments OPT4060 RGBW Color sensor.
Signed-off-by Per-Daniel Olsson <[email protected]>
...
Quoted 10 lines
+ * Function for calculating color components independent of light intensity. The
+ * raw values are multiplied by individual factors that correspond to the
+ * sensitivity of the different color filters. The returned value is normalized.
+ */drivers/iio/light/opt4060.c new file +6
-0+static int opt4060_read_chan_scale (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2) +{ +struct opt4060_chip *chip =iio_priv (indio_dev); +static const u32 color_factors[] = {24 ,10 ,13 };
drivers/iio/light/opt4060.c line 395
Quoted 10 lines
drivers/iio/light/opt4060.c new file +10
-0+u32 adc_raw[3 ], sum =0 , rem; +int ret; + + ret =opt4060_trigger_new_samples (indio_dev); +if (ret) { +dev_err (chip->dev,"Failed to trigger new samples.\n" ); +return ret; + } + +for (int color =OPT4060_RED ; color <=OPT4060_BLUE ; color++) {
Nit: no need for parenthesis around adc_raw[color].
Quoted 4 lines
drivers/iio/light/opt4060.c new file +4
-0+ ret =opt4060_read_raw_value (chip, indio_dev->channels[color].address, + &(adc_raw[color])); +if (ret) { +dev_err (chip->dev,"Reading raw channel data failed\n" );
drivers/iio/light/opt4060.c line 409
Quoted 10 lines
drivers/iio/light/opt4060.c new file +10
-0+return ret; + } + adc_raw[color] *= color_factors[color]; + sum += adc_raw[color]; + } + *val =div_u64_rem ((u64 )adc_raw[chan->scan_index], sum, &rem); + *val2 =DIV_U64_ROUND_CLOSEST ((u64)(rem *MICRO ), sum); +return IIO_VAL_INT_PLUS_MICRO ; +} +
Nit: wrong alignment in the second line of the arguments.
Quoted 25 lines
drivers/iio/light/opt4060.c new file +25
-0+static ssize_t opt4060_read_ev_period (struct opt4060_chip *chip,int *val, +int *val2) +{ +int ret, pers, fault_count, int_time; +u64 uval; + + int_time = opt4060_int_time_reg[chip->int_time][0 ]; + + ret =regmap_read (chip->regmap,OPT4060_CTRL , &fault_count); +if (ret <0 ) +return ret; + + fault_count = fault_count &OPT4060_CTRL_FAULT_COUNT_MASK ; +switch (fault_count) { +case OPT4060_CTRL_FAULT_COUNT_2 : + pers =2 ; +break ; +case OPT4060_CTRL_FAULT_COUNT_4 : + pers =4 ; +break ; +case OPT4060_CTRL_FAULT_COUNT_8 : + pers =8 ; +break ; + +default :
drivers/iio/light/opt4060.c line 735
Quoted 10 lines
drivers/iio/light/opt4060.c new file +10
-0+ pers =1 ; +break ; + } + + uval =mul_u32_u32 (int_time, pers); + *val =div_u64_rem (uval,MICRO , val2); + +return IIO_VAL_INT_PLUS_MICRO ; +} +
Same here.
drivers/iio/light/opt4060.c line 738
Quoted 3 lines
drivers/iio/light/opt4060.c new file +3
-0+static ssize_t opt4060_write_ev_period (struct opt4060_chip *chip,int val, +int val2) +{
Note that state has become a bool, so if a new version of this driver is required, please use a newer base (e.g. linux-next, iio/testing) to avoid future issues.
drivers/iio/light/opt4060.c line 925
Quoted 8 lines
drivers/iio/light/opt4060.c new file +8
-0+static int opt4060_write_event_config (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir,int state) +{ +int ch_sel, ch_idx = chan->scan_index; +struct opt4060_chip *chip =iio_priv (indio_dev); +int ret;
Best regards,
Javier Carrasco