dt-bindings: iio: light: add ltr390
Subsystems (3)
Anshul Dalal
maintainerPATCH v3 1/2 dt-bindings: iio: light: add ltr390
Add binding for Lite-On LTR390 which is an Ambient/UV light sensor that communicates over i2c with an address of 0x53.
Datasheet: https://optoelectronics.liteon.com/upload/download/DS86-2015-0004/LTR-390UV_Final_%20DS_V1%201.pdf
---
Changes for v3:
- no updates
Changes for v2:
- Added missing properties in the example
Previous versions:
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/
--- .../bindings/iio/light/liteon,ltr390.yaml | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/liteon,ltr390.yaml
Documentation/devicetree/bindings/iio/light/liteon,ltr390.yaml new file +56 -0
@@ -0,0 +1,56 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/liteon,ltr390.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Lite-On LTR390 ALS and UV Sensor + +description: | + The Lite-On LTR390 is an ALS (Ambient Light Sensor) and a UV sensor in a + single package with i2c address of 0x53. + + Datasheet: + https://optoelectronics.liteon.com/upload/download/DS86-2015-0004/LTR-390UV_Final_%20DS_V1%201.pdf + +maintainers: + - Anshul Dalal <[email protected]> + +properties: + compatible: + enum: + - liteon,ltr390 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + description: | + Level interrupt pin with open drain output. + The sensor pulls this pin low when the measured reading is greater than + some configured threshold. + + vdd-supply: true + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + light-sensor@53 { + compatible = "liteon,ltr390"; + reg = <0x53>; + interrupts = <18 IRQ_TYPE_EDGE_FALLING>; + vdd-supply = <&vdd_regulator>; + }; + };
Signature · 1 line
2.42.1
Anshul Dalal
maintainerPATCH v3 2/2 iio: light: driver for Lite-On ltr390
Implements driver for the Ambient/UV Light sensor LTR390. The driver exposes two ways of getting sensor readings:
1. Raw UV Counts directly from the sensor
2. The computed UV Index value with a percision of 2 decimal places
[NOTE] Ambient light sensing has not been implemented yet.
Driver tested on RPi Zero 2W
Datasheet: https://optoelectronics.liteon.com/upload/download/DS86-2015-0004/LTR-390UV_Final_%20DS_V1%201.pdf
---
Changes for v3:
- Formatted header includes
- Replaced instances of LTR390_DEVICE_NAME with "ltr390"
- Use shorthand macro 'guard' for mutex
- Replace instances of dev_err followed by a return with dev_err_probe
- Separate channel for UV Index into a IIO_CHAN_INFO_RAW and _SCALE
- Remove unused IIO_INTENSITY channel
- Warn on invalid product id instead of exiting
- Changed ltr390_id_table to ltr390_of_table [TYPO]
Quoted 1 line
MODULE_DEVICE_TABLE(of, ltr390_of_table)
- Removed of_match_ptr
Changes for v2:
- Fixed typo in LTR390_FRACTIONAL_PRECISION
- Added of_device_id
Previous versions:
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/
--- MAINTAINERS | 7 ++ drivers/iio/light/Kconfig | 11 +++ drivers/iio/light/Makefile | 1 + drivers/iio/light/ltr390.c | 195 +++++++++++++++++++++++++++++++++++++ 4 files changed, 214 insertions(+) create mode 100644 drivers/iio/light/ltr390.c
MAINTAINERS +7 -0
@@ -12484,6 +12484,13 @@ S: Maintained W: http://linux-test-project.github.io/ T: git https://github.com/linux-test-project/ltp.git +LTR390 AMBIENT/UV LIGHT SENSOR DRIVER +M: Anshul Dalal <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/iio/light/liteon,ltr390.yaml +F: drivers/iio/light/ltr390.c + LYNX 28G SERDES PHY DRIVER M: Ioana Ciornei <[email protected]> L: [email protected]
drivers/iio/light/Kconfig +11 -0
@@ -347,6 +347,17 @@ config SENSORS_LM3533 changes. The ALS-control output values can be set per zone for the three current output channels. +config LTR390 + tristate "LTR-390UV-01 ambient light and UV sensor" + depends on I2C + select REGMAP_I2C + help + If you say yes here you get support for the Lite-On LTR-390UV-01 + ambient light and UV sensor. + + This driver can also be built as a module. If so, the module + will be called ltr390. + config LTR501 tristate "LTR-501ALS-01 light sensor" depends on I2C
drivers/iio/light/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_SENSORS_ISL29028) += isl29028.o obj-$(CONFIG_ISL29125) += isl29125.o obj-$(CONFIG_JSA1212) += jsa1212.o obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o +obj-$(CONFIG_LTR390) += ltr390.o obj-$(CONFIG_LTR501) += ltr501.o obj-$(CONFIG_LTRF216A) += ltrf216a.o obj-$(CONFIG_LV0104CS) += lv0104cs.o
drivers/iio/light/ltr390.c new file +195 -0
195 lines not on this page · raw message
Signature · 1 line
2.42.1
Jonathan Cameron
maintainerRe: [PATCH v3 2/2] iio: light: driver for Lite-On ltr390
Quoted 11 lines · On Fri, 8 Dec 2023 15:52:10 +0530 Anshul Dalal <[email protected]> wrote:
Implements driver for the Ambient/UV Light sensor LTR390. The driver exposes two ways of getting sensor readings:
1. Raw UV Counts directly from the sensor
2. The computed UV Index value with a percision of 2 decimal places[NOTE] Ambient light sensing has not been implemented yet.
Driver tested on RPi Zero 2W
Datasheet: https://optoelectronics.liteon.com/upload/download/DS86-2015-0004/LTR-390UV_Final_%20DS_V1%201.pdf
Signed-off-by Anshul Dalal <[email protected]>
I fixed up the case where you use dev_err_probe() in a path called from places other than the probe() callback.
Applied to the togreg branch of iio.git and initially pushed out as testing for 0-day to take a look and see if it can find things we missed
Thanks,
Jonathan
drivers/iio/light/ltr390.c line 83
Quoted 13 lines
drivers/iio/light/ltr390.c new file +13
-0+ +static int ltr390_register_read (struct ltr390_data *data,u8 register_address) +{ +struct device *dev = &data->client->dev; +int ret; +u8 recieve_buffer[3 ]; + +guard (mutex)(&data->lock); + + ret =regmap_bulk_read (data->regmap, register_address, recieve_buffer, +sizeof (recieve_buffer)); +if (ret) + return dev_err_probe(dev, ret,
dev_err_probe() is only intended for use in probe() and functions that are only called from probe()
Quoted 4 lines
drivers/iio/light/ltr390.c new file +4
-0+ "failed to read measurement data"); + +return get_unaligned_le24 (recieve_buffer); +}