Skip to contentSkip to conversation

iio: light: add al3000a als support

PATCH Applied Svyatoslav Ryhel 5 participants 15 messages Feb 17, 2025 – Mar 6, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover iio: light: add al3000a als support

AL3000a is an illuminance sensor found in ASUS TF101 tablet.

---
Changes on switching from v3 to v4:
- return write function directly
- clean up and fix i2c_device_id

Changes on switching from v2 to v3:
- droped linux/iio/sysfs.h
- set driver name directly
- switched to IIO_CHAN_INFO_PROCESSED
- split al3000a_set_pwr into 2 functions
- added i2c_device_id
- improved code formatting

Changes on switching from v1 to v2:
- sort compatible alphabetically in schema
- clarify commit descriptions
- convert to use regmap
- arrangle lux conversion table in rows of 8
- add more used headers
- improve code formatting
---

Svyatoslav Ryhel (3):
dt-bindings: iio: light: al3010: add al3000a support
iio: light: Add support for AL3000a illuminance sensor
ARM: tegra: tf101: Add al3000a illuminance sensor node

 .../bindings/iio/light/dynaimage,al3010.yaml  |   6 +-
 .../boot/dts/nvidia/tegra20-asus-tf101.dts    |  11 +
 drivers/iio/light/Kconfig                     |  10 +
 drivers/iio/light/Makefile                    |   1 +
 drivers/iio/light/al3000a.c                   | 209 ++++++++++++++++++
 5 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100644 drivers/iio/light/al3000a.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/3 dt-bindings: iio: light: al3010: add al3000a support

AL3000a is an ambient light sensor quite closely related to exising AL3010 and can reuse exising schema for AL3010.

---
 .../devicetree/bindings/iio/light/dynaimage,al3010.yaml     | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/iio/light/dynaimage,al3010.yaml +4 -2
index a3a979553e32..f1048c30e73e 100644
@@ -4,14 +4,16 @@
 $id: http://devicetree.org/schemas/iio/light/dynaimage,al3010.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: Dyna-Image AL3010 sensor
+title: Dyna-Image AL3000a/AL3010 sensor
 
 maintainers:
   - David Heidelberg <[email protected]>
 
 properties:
   compatible:
-    const: dynaimage,al3010
+    enum:
+      - dynaimage,al3000a
+      - dynaimage,al3010
 
   reg:
     maxItems: 1
Signature · 1 line
2.43.0
Acked-by on v4 1/3
#2 lore raw

Re: [PATCH v4 1/3] dt-bindings: iio: light: al3010: add al3000a support

Quoted 8 lines · Svyatoslav Ryhel

AL3000a is an ambient light sensor quite closely related to exising AL3010 and can reuse exising schema for AL3010.

---
 .../devicetree/bindings/iio/light/dynaimage,al3010.yaml     | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Best regards,
Krzysztof

#3 lore raw

PATCH v4 2/3 iio: light: Add support for AL3000a illuminance sensor

In reply to Svyatoslav Ryhel

AL3000a is a simple I2C-based ambient light sensor, which is closely related to AL3010 and AL3320a, but has significantly different way of processing data generated by the sensor.

---
 drivers/iio/light/Kconfig   |  10 ++
 drivers/iio/light/Makefile  |   1 +
 drivers/iio/light/al3000a.c | 209 ++++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+)
 create mode 100644 drivers/iio/light/al3000a.c
drivers/iio/light/Kconfig +10 -0
index 29ffa8491927..37f83e1d8893 100644
@@ -43,6 +43,16 @@ config ADUX1020
 	 To compile this driver as a module, choose M here: the
 	 module will be called adux1020.
 
+config AL3000A
+	tristate "AL3000a ambient light sensor"
+	depends on I2C
+	help
+	  Say Y here if you want to build a driver for the Dyna Image AL3000a
+	  ambient light sensor.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called al3000a.
+
 config AL3010
 	tristate "AL3010 ambient light sensor"
 	depends on I2C
drivers/iio/light/Makefile +1 -0
index f14a37442712..03f10786273a 100644
@@ -7,6 +7,7 @@
 obj-$(CONFIG_ACPI_ALS)		+= acpi-als.o
 obj-$(CONFIG_ADJD_S311)		+= adjd_s311.o
 obj-$(CONFIG_ADUX1020)		+= adux1020.o
+obj-$(CONFIG_AL3000A)		+= al3000a.o
 obj-$(CONFIG_AL3010)		+= al3010.o
 obj-$(CONFIG_AL3320A)		+= al3320a.o
 obj-$(CONFIG_APDS9300)		+= apds9300.o
drivers/iio/light/al3000a.c new file +209 -0

209 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v4 2/3
#4 lore raw

Re: [PATCH v4 2/3] iio: light: Add support for AL3000a illuminance sensor

Quoted 3 lines · Svyatoslav Ryhel

AL3000a is a simple I2C-based ambient light sensor, which is closely related to AL3010 and AL3320a, but has significantly different way of processing data generated by the sensor.

LGTM, FWIW,

...

drivers/iio/light/al3000a.c line 83

Quoted 13 lines
drivers/iio/light/al3000a.c new file +13 -0
+static void al3000a_set_pwr_off(void *_data)
+{
+	struct al3000a_data *data = _data;
+	struct device *dev = regmap_get_device(data->regmap);
+	int ret;
+
+	ret = regmap_write(data->regmap, AL3000A_REG_SYSTEM, AL3000A_CONFIG_DISABLE);
+	if (ret)
+		dev_err(dev, "failed to write system register\n");
+
+	ret = regulator_disable(data->vdd_supply);
+	if (ret)
+		dev_err(dev, "failed to disable vdd power supply\n");

I dunno what we can do on errors, but at least user will be informed what was failed.

Quoted 1 line

+}

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw

Re: [PATCH v4 2/3] iio: light: Add support for AL3000a illuminance sensor

In reply to Svyatoslav Ryhel
Quoted 8 lines · On Mon, 17 Feb 2025 16:03:35 +0200 Svyatoslav Ryhel <[email protected]> wrote:

AL3000a is a simple I2C-based ambient light sensor, which is closely related to AL3010 and AL3320a, but has significantly different way of processing data generated by the sensor.

Whilst I am confused by earlier statements about not having information on the conversion to illuminance values, I'm going to assume the look up table in here is based on some reasonable data from somewhere and hence that this is a sensor with appropriate filtering of the light to be able to do a non linear conversion from the value read and standard light curves.

As such the IIO_LIGHT channel type is fine for this device.

Applied patches 1 and 2 to the togreg branch of iio.git. Note that I'll initially push this out as testing to allow the autobuilders to see if they can find any issues that we missed. Patch 3 will need to go via the appropriate SoC tree as normal.

Jonathan

Quoted 83 lines
---
 drivers/iio/light/Kconfig   |  10 ++
 drivers/iio/light/Makefile  |   1 +
 drivers/iio/light/al3000a.c | 209 ++++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+)
 create mode 100644 drivers/iio/light/al3000a.c
drivers/iio/light/Kconfig +10 -0
index 29ffa8491927..37f83e1d8893 100644
@@ -43,6 +43,16 @@ config ADUX1020
 	 To compile this driver as a module, choose M here: the
 	 module will be called adux1020.
 
+config AL3000A
+	tristate "AL3000a ambient light sensor"
+	depends on I2C
+	help
+	  Say Y here if you want to build a driver for the Dyna Image AL3000a
+	  ambient light sensor.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called al3000a.
+
 config AL3010
 	tristate "AL3010 ambient light sensor"
 	depends on I2C
drivers/iio/light/Makefile +1 -0
index f14a37442712..03f10786273a 100644
@@ -7,6 +7,7 @@
 obj-$(CONFIG_ACPI_ALS)		+= acpi-als.o
 obj-$(CONFIG_ADJD_S311)		+= adjd_s311.o
 obj-$(CONFIG_ADUX1020)		+= adux1020.o
+obj-$(CONFIG_AL3000A)		+= al3000a.o
 obj-$(CONFIG_AL3010)		+= al3010.o
 obj-$(CONFIG_AL3320A)		+= al3320a.o
 obj-$(CONFIG_APDS9300)		+= apds9300.o
drivers/iio/light/al3000a.c new file +37 -0
new file mode 100644
index 000000000000..e2fbb1270040
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/array_size.h>
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/pm.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/types.h>
+
+#include <linux/iio/iio.h>
+
+#define AL3000A_REG_SYSTEM		0x00
+#define AL3000A_REG_DATA		0x05
+
+#define AL3000A_CONFIG_ENABLE		0x00
+#define AL3000A_CONFIG_DISABLE		0x0b
+#define AL3000A_CONFIG_RESET		0x0f
+#define AL3000A_GAIN_MASK		GENMASK(5, 0)
+
+/*
+ * These are pre-calculated lux values based on possible output of sensor
+ * (range 0x00 - 0x3F)
+ */
+static const u32 lux_table[] = {
+	1, 1, 1, 2, 2, 2, 3, 4,					/* 0 - 7 */
+	4, 5, 6, 7, 9, 11, 13, 16,				/* 8 - 15 */
+	19, 22, 27, 32, 39, 46, 56, 67,				/* 16 - 23 */
+	80, 96, 116, 139, 167, 200, 240, 289,			/* 24 - 31 */
+	347, 416, 499, 600, 720, 864, 1037, 1245,		/* 32 - 39 */
+	1495, 1795, 2155, 2587, 3105, 3728, 4475, 5373,		/* 40 - 47 */
+	6450, 7743, 9296, 11160, 13397, 16084, 19309, 23180,	/* 48 - 55 */
+	27828, 33408, 40107, 48148, 57803, 69393, 83306, 100000 /* 56 - 63 */
+};
#6 lore raw

Re: [PATCH v4 2/3] iio: light: Add support for AL3000a illuminance sensor

сб, 22 лют. 2025 р. о 14:53 Jonathan Cameron <[email protected]> пише:

Quoted 13 lines
Quoted 8 lines · On Mon, 17 Feb 2025 16:03:35 +0200 Svyatoslav Ryhel <[email protected]> wrote:

AL3000a is a simple I2C-based ambient light sensor, which is closely related to AL3010 and AL3320a, but has significantly different way of processing data generated by the sensor.

Quoted 9 lines

Whilst I am confused by earlier statements about not having information on the conversion to illuminance values, I'm going to assume the look up table in here is based on some reasonable data from somewhere and hence that this is a sensor with appropriate filtering of the light to be able to do a non linear conversion from the value read and standard light curves.

As such the IIO_LIGHT channel type is fine for this device.

Thank you, but IIO_INTENSITY may be proper channel as well, after your explanations. If you wish, I may upload v5 with swapping LIGHT with INTENSITY.

Quoted 91 lines

Applied patches 1 and 2 to the togreg branch of iio.git. Note that I'll initially push this out as testing to allow the autobuilders to see if they can find any issues that we missed. Patch 3 will need to go via the appropriate SoC tree as normal.

Jonathan

Quoted 83 lines
---
 drivers/iio/light/Kconfig   |  10 ++
 drivers/iio/light/Makefile  |   1 +
 drivers/iio/light/al3000a.c | 209 ++++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+)
 create mode 100644 drivers/iio/light/al3000a.c
drivers/iio/light/Kconfig +10 -0
index 29ffa8491927..37f83e1d8893 100644
@@ -43,6 +43,16 @@ config ADUX1020
       To compile this driver as a module, choose M here: the
       module will be called adux1020.
 
+config AL3000A
+     tristate "AL3000a ambient light sensor"
+     depends on I2C
+     help
+       Say Y here if you want to build a driver for the Dyna Image AL3000a
+       ambient light sensor.
+
+       To compile this driver as a module, choose M here: the
+       module will be called al3000a.
+
 config AL3010
      tristate "AL3010 ambient light sensor"
      depends on I2C
drivers/iio/light/Makefile +1 -0
index f14a37442712..03f10786273a 100644
@@ -7,6 +7,7 @@
 obj-$(CONFIG_ACPI_ALS)               += acpi-als.o
 obj-$(CONFIG_ADJD_S311)              += adjd_s311.o
 obj-$(CONFIG_ADUX1020)               += adux1020.o
+obj-$(CONFIG_AL3000A)                += al3000a.o
 obj-$(CONFIG_AL3010)         += al3010.o
 obj-$(CONFIG_AL3320A)                += al3320a.o
 obj-$(CONFIG_APDS9300)               += apds9300.o
drivers/iio/light/al3000a.c new file +37 -0
new file mode 100644
index 000000000000..e2fbb1270040
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/array_size.h>
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/pm.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/types.h>
+
+#include <linux/iio/iio.h>
+
+#define AL3000A_REG_SYSTEM           0x00
+#define AL3000A_REG_DATA             0x05
+
+#define AL3000A_CONFIG_ENABLE                0x00
+#define AL3000A_CONFIG_DISABLE               0x0b
+#define AL3000A_CONFIG_RESET         0x0f
+#define AL3000A_GAIN_MASK            GENMASK(5, 0)
+
+/*
+ * These are pre-calculated lux values based on possible output of sensor
+ * (range 0x00 - 0x3F)
+ */
+static const u32 lux_table[] = {
+     1, 1, 1, 2, 2, 2, 3, 4,                                 /* 0 - 7 */
+     4, 5, 6, 7, 9, 11, 13, 16,                              /* 8 - 15 */
+     19, 22, 27, 32, 39, 46, 56, 67,                         /* 16 - 23 */
+     80, 96, 116, 139, 167, 200, 240, 289,                   /* 24 - 31 */
+     347, 416, 499, 600, 720, 864, 1037, 1245,               /* 32 - 39 */
+     1495, 1795, 2155, 2587, 3105, 3728, 4475, 5373,         /* 40 - 47 */
+     6450, 7743, 9296, 11160, 13397, 16084, 19309, 23180,    /* 48 - 55 */
+     27828, 33408, 40107, 48148, 57803, 69393, 83306, 100000 /* 56 - 63 */
+};
maintainer
#7 lore raw

Re: [PATCH v4 2/3] iio: light: Add support for AL3000a illuminance sensor

Quoted 21 lines · On Sat, 22 Feb 2025 14:56:41 +0200 Svyatoslav Ryhel <[email protected]> wrote:

сб, 22 лют. 2025 р. о 14:53 Jonathan Cameron <[email protected]> пише:

Quoted 20 lines
Quoted 8 lines · On Mon, 17 Feb 2025 16:03:35 +0200 Svyatoslav Ryhel <[email protected]> wrote:

AL3000a is a simple I2C-based ambient light sensor, which is closely related to AL3010 and AL3320a, but has significantly different way of processing data generated by the sensor.

Whilst I am confused by earlier statements about not having information on the conversion to illuminance values, I'm going to assume the look up table in here is based on some reasonable data from somewhere and hence that this is a sensor with appropriate filtering of the light to be able to do a non linear conversion from the value read and standard light curves.

Quoted 6 lines
Quoted 2 lines

As such the IIO_LIGHT channel type is fine for this device.

Thank you, but IIO_INTENSITY may be proper channel as well, after your explanations. If you wish, I may upload v5 with swapping LIGHT with INTENSITY.

Where does the lux_table set of values come from?
That seems to be key question for this driver.

Quoted 92 lines
Quoted 92 lines

Applied patches 1 and 2 to the togreg branch of iio.git. Note that I'll initially push this out as testing to allow the autobuilders to see if they can find any issues that we missed. Patch 3 will need to go via the appropriate SoC tree as normal.

Jonathan

Quoted 83 lines
---
 drivers/iio/light/Kconfig   |  10 ++
 drivers/iio/light/Makefile  |   1 +
 drivers/iio/light/al3000a.c | 209 ++++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+)
 create mode 100644 drivers/iio/light/al3000a.c
drivers/iio/light/Kconfig +10 -0
index 29ffa8491927..37f83e1d8893 100644
@@ -43,6 +43,16 @@ config ADUX1020
       To compile this driver as a module, choose M here: the
       module will be called adux1020.
 
+config AL3000A
+     tristate "AL3000a ambient light sensor"
+     depends on I2C
+     help
+       Say Y here if you want to build a driver for the Dyna Image AL3000a
+       ambient light sensor.
+
+       To compile this driver as a module, choose M here: the
+       module will be called al3000a.
+
 config AL3010
      tristate "AL3010 ambient light sensor"
      depends on I2C
drivers/iio/light/Makefile +1 -0
index f14a37442712..03f10786273a 100644
@@ -7,6 +7,7 @@
 obj-$(CONFIG_ACPI_ALS)               += acpi-als.o
 obj-$(CONFIG_ADJD_S311)              += adjd_s311.o
 obj-$(CONFIG_ADUX1020)               += adux1020.o
+obj-$(CONFIG_AL3000A)                += al3000a.o
 obj-$(CONFIG_AL3010)         += al3010.o
 obj-$(CONFIG_AL3320A)                += al3320a.o
 obj-$(CONFIG_APDS9300)               += apds9300.o
drivers/iio/light/al3000a.c new file +37 -0
new file mode 100644
index 000000000000..e2fbb1270040
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/array_size.h>
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/pm.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/types.h>
+
+#include <linux/iio/iio.h>
+
+#define AL3000A_REG_SYSTEM           0x00
+#define AL3000A_REG_DATA             0x05
+
+#define AL3000A_CONFIG_ENABLE                0x00
+#define AL3000A_CONFIG_DISABLE               0x0b
+#define AL3000A_CONFIG_RESET         0x0f
+#define AL3000A_GAIN_MASK            GENMASK(5, 0)
+
+/*
+ * These are pre-calculated lux values based on possible output of sensor
+ * (range 0x00 - 0x3F)
+ */
+static const u32 lux_table[] = {
+     1, 1, 1, 2, 2, 2, 3, 4,                                 /* 0 - 7 */
+     4, 5, 6, 7, 9, 11, 13, 16,                              /* 8 - 15 */
+     19, 22, 27, 32, 39, 46, 56, 67,                         /* 16 - 23 */
+     80, 96, 116, 139, 167, 200, 240, 289,                   /* 24 - 31 */
+     347, 416, 499, 600, 720, 864, 1037, 1245,               /* 32 - 39 */
+     1495, 1795, 2155, 2587, 3105, 3728, 4475, 5373,         /* 40 - 47 */
+     6450, 7743, 9296, 11160, 13397, 16084, 19309, 23180,    /* 48 - 55 */
+     27828, 33408, 40107, 48148, 57803, 69393, 83306, 100000 /* 56 - 63 */
+};  
#8 lore raw

Re: [PATCH v4 2/3] iio: light: Add support for AL3000a illuminance sensor

сб, 22 лют. 2025 р. о 19:25 Jonathan Cameron <[email protected]> пише:

Quoted 28 lines
Quoted 24 lines · On Sat, 22 Feb 2025 14:56:41 +0200 Svyatoslav Ryhel <[email protected]> wrote:

сб, 22 лют. 2025 р. о 14:53 Jonathan Cameron <[email protected]> пише:

Quoted 22 lines
Quoted 8 lines · On Mon, 17 Feb 2025 16:03:35 +0200 Svyatoslav Ryhel <[email protected]> wrote:

AL3000a is a simple I2C-based ambient light sensor, which is closely related to AL3010 and AL3320a, but has significantly different way of processing data generated by the sensor.

Whilst I am confused by earlier statements about not having information on the conversion to illuminance values, I'm going to assume the look up table in here is based on some reasonable data from somewhere and hence that this is a sensor with appropriate filtering of the light to be able to do a non linear conversion from the value read and standard light curves.

As such the IIO_LIGHT channel type is fine for this device.

Quoted 7 lines
Quoted 3 lines

Thank you, but IIO_INTENSITY may be proper channel as well, after your explanations. If you wish, I may upload v5 with swapping LIGHT with INTENSITY.

Where does the lux_table set of values come from?
That seems to be key question for this driver.

3.1.10 kernel driver for this device

Quoted 93 lines
Quoted 92 lines
Quoted 92 lines

Applied patches 1 and 2 to the togreg branch of iio.git. Note that I'll initially push this out as testing to allow the autobuilders to see if they can find any issues that we missed. Patch 3 will need to go via the appropriate SoC tree as normal.

Jonathan

Quoted 83 lines
---
 drivers/iio/light/Kconfig   |  10 ++
 drivers/iio/light/Makefile  |   1 +
 drivers/iio/light/al3000a.c | 209 ++++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+)
 create mode 100644 drivers/iio/light/al3000a.c
drivers/iio/light/Kconfig +10 -0
index 29ffa8491927..37f83e1d8893 100644
@@ -43,6 +43,16 @@ config ADUX1020
       To compile this driver as a module, choose M here: the
       module will be called adux1020.
 
+config AL3000A
+     tristate "AL3000a ambient light sensor"
+     depends on I2C
+     help
+       Say Y here if you want to build a driver for the Dyna Image AL3000a
+       ambient light sensor.
+
+       To compile this driver as a module, choose M here: the
+       module will be called al3000a.
+
 config AL3010
      tristate "AL3010 ambient light sensor"
      depends on I2C
drivers/iio/light/Makefile +1 -0
index f14a37442712..03f10786273a 100644
@@ -7,6 +7,7 @@
 obj-$(CONFIG_ACPI_ALS)               += acpi-als.o
 obj-$(CONFIG_ADJD_S311)              += adjd_s311.o
 obj-$(CONFIG_ADUX1020)               += adux1020.o
+obj-$(CONFIG_AL3000A)                += al3000a.o
 obj-$(CONFIG_AL3010)         += al3010.o
 obj-$(CONFIG_AL3320A)                += al3320a.o
 obj-$(CONFIG_APDS9300)               += apds9300.o
drivers/iio/light/al3000a.c new file +37 -0
new file mode 100644
index 000000000000..e2fbb1270040
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/array_size.h>
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/pm.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/types.h>
+
+#include <linux/iio/iio.h>
+
+#define AL3000A_REG_SYSTEM           0x00
+#define AL3000A_REG_DATA             0x05
+
+#define AL3000A_CONFIG_ENABLE                0x00
+#define AL3000A_CONFIG_DISABLE               0x0b
+#define AL3000A_CONFIG_RESET         0x0f
+#define AL3000A_GAIN_MASK            GENMASK(5, 0)
+
+/*
+ * These are pre-calculated lux values based on possible output of sensor
+ * (range 0x00 - 0x3F)
+ */
+static const u32 lux_table[] = {
+     1, 1, 1, 2, 2, 2, 3, 4,                                 /* 0 - 7 */
+     4, 5, 6, 7, 9, 11, 13, 16,                              /* 8 - 15 */
+     19, 22, 27, 32, 39, 46, 56, 67,                         /* 16 - 23 */
+     80, 96, 116, 139, 167, 200, 240, 289,                   /* 24 - 31 */
+     347, 416, 499, 600, 720, 864, 1037, 1245,               /* 32 - 39 */
+     1495, 1795, 2155, 2587, 3105, 3728, 4475, 5373,         /* 40 - 47 */
+     6450, 7743, 9296, 11160, 13397, 16084, 19309, 23180,    /* 48 - 55 */
+     27828, 33408, 40107, 48148, 57803, 69393, 83306, 100000 /* 56 - 63 */
+};
maintainer
#9 lore raw

Re: [PATCH v4 2/3] iio: light: Add support for AL3000a illuminance sensor

Quoted 33 lines · On Sat, 22 Feb 2025 19:27:22 +0200 Svyatoslav Ryhel <[email protected]> wrote:

сб, 22 лют. 2025 р. о 19:25 Jonathan Cameron <[email protected]> пише:

Quoted 32 lines
Quoted 27 lines · On Sat, 22 Feb 2025 14:56:41 +0200 Svyatoslav Ryhel <[email protected]> wrote:

сб, 22 лют. 2025 р. о 14:53 Jonathan Cameron <[email protected]> пише:

Quoted 13 lines
Quoted 8 lines · On Mon, 17 Feb 2025 16:03:35 +0200 Svyatoslav Ryhel <[email protected]> wrote:

AL3000a is a simple I2C-based ambient light sensor, which is closely related to AL3010 and AL3320a, but has significantly different way of processing data generated by the sensor.

Quoted 9 lines

Whilst I am confused by earlier statements about not having information on the conversion to illuminance values, I'm going to assume the look up table in here is based on some reasonable data from somewhere and hence that this is a sensor with appropriate filtering of the light to be able to do a non linear conversion from the value read and standard light curves.

As such the IIO_LIGHT channel type is fine for this device.

Thank you, but IIO_INTENSITY may be proper channel as well, after your explanations. If you wish, I may upload v5 with swapping LIGHT with INTENSITY.

Quoted 5 lines
Quoted 3 lines

Where does the lux_table set of values come from?
That seems to be key question for this driver.

3.1.10 kernel driver for this device

Ok. So until we know otherwise let us trust that data as being correct.

Jonathan

Quoted 95 lines
Quoted 94 lines
Quoted 93 lines
Quoted 93 lines

Applied patches 1 and 2 to the togreg branch of iio.git. Note that I'll initially push this out as testing to allow the autobuilders to see if they can find any issues that we missed. Patch 3 will need to go via the appropriate SoC tree as normal.

Jonathan

Quoted 83 lines
---
 drivers/iio/light/Kconfig   |  10 ++
 drivers/iio/light/Makefile  |   1 +
 drivers/iio/light/al3000a.c | 209 ++++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+)
 create mode 100644 drivers/iio/light/al3000a.c
drivers/iio/light/Kconfig +10 -0
index 29ffa8491927..37f83e1d8893 100644
@@ -43,6 +43,16 @@ config ADUX1020
       To compile this driver as a module, choose M here: the
       module will be called adux1020.
 
+config AL3000A
+     tristate "AL3000a ambient light sensor"
+     depends on I2C
+     help
+       Say Y here if you want to build a driver for the Dyna Image AL3000a
+       ambient light sensor.
+
+       To compile this driver as a module, choose M here: the
+       module will be called al3000a.
+
 config AL3010
      tristate "AL3010 ambient light sensor"
      depends on I2C
drivers/iio/light/Makefile +1 -0
index f14a37442712..03f10786273a 100644
@@ -7,6 +7,7 @@
 obj-$(CONFIG_ACPI_ALS)               += acpi-als.o
 obj-$(CONFIG_ADJD_S311)              += adjd_s311.o
 obj-$(CONFIG_ADUX1020)               += adux1020.o
+obj-$(CONFIG_AL3000A)                += al3000a.o
 obj-$(CONFIG_AL3010)         += al3010.o
 obj-$(CONFIG_AL3320A)                += al3320a.o
 obj-$(CONFIG_APDS9300)               += apds9300.o
drivers/iio/light/al3000a.c new file +37 -0
new file mode 100644
index 000000000000..e2fbb1270040
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/array_size.h>
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/pm.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/types.h>
+
+#include <linux/iio/iio.h>
+
+#define AL3000A_REG_SYSTEM           0x00
+#define AL3000A_REG_DATA             0x05
+
+#define AL3000A_CONFIG_ENABLE                0x00
+#define AL3000A_CONFIG_DISABLE               0x0b
+#define AL3000A_CONFIG_RESET         0x0f
+#define AL3000A_GAIN_MASK            GENMASK(5, 0)
+
+/*
+ * These are pre-calculated lux values based on possible output of sensor
+ * (range 0x00 - 0x3F)
+ */
+static const u32 lux_table[] = {
+     1, 1, 1, 2, 2, 2, 3, 4,                                 /* 0 - 7 */
+     4, 5, 6, 7, 9, 11, 13, 16,                              /* 8 - 15 */
+     19, 22, 27, 32, 39, 46, 56, 67,                         /* 16 - 23 */
+     80, 96, 116, 139, 167, 200, 240, 289,                   /* 24 - 31 */
+     347, 416, 499, 600, 720, 864, 1037, 1245,               /* 32 - 39 */
+     1495, 1795, 2155, 2587, 3105, 3728, 4475, 5373,         /* 40 - 47 */
+     6450, 7743, 9296, 11160, 13397, 16084, 19309, 23180,    /* 48 - 55 */
+     27828, 33408, 40107, 48148, 57803, 69393, 83306, 100000 /* 56 - 63 */
+};  
#10 lore raw

PATCH v4 3/3 ARM: tegra: tf101: Add al3000a illuminance sensor node

In reply to Svyatoslav Ryhel

Bind al3000a illuminance sensor found in ASUS TF101

---
 arch/arm/boot/dts/nvidia/tegra20-asus-tf101.dts | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/boot/dts/nvidia/tegra20-asus-tf101.dts +11 -0
index 975ec24195ca..fcf3d6dd64a2 100644
@@ -1123,6 +1123,17 @@ smart-battery@b {
 				sbs,poll-retry-count = <10>;
 				power-supplies = <&mains>;
 			};
+
+			/* Dynaimage ambient light sensor */
+			light-sensor@1c {
+				compatible = "dynaimage,al3000a";
+				reg = <0x1c>;
+
+				interrupt-parent = <&gpio>;
+				interrupts = <TEGRA_GPIO(Z, 2) IRQ_TYPE_LEVEL_HIGH>;
+
+				vdd-supply = <&vdd_1v8_sys>;
+			};
 		};
 	};
 
Signature · 1 line
2.43.0
maintainer
#12 lore raw
In reply to Svyatoslav Ryhel
Quoted 1 line · On Mon, 17 Feb 2025 16:03:33 +0200 Svyatoslav Ryhel <[email protected]> wrote:

AL3000a is an illuminance sensor found in ASUS TF101 tablet.

Hi Svyatoslav,

Just a small request. Please reduce rate of sending new versions. That tends to give time for discussions on earlier versions to progress and for more reviewers to see the current version.

I'd suggest at least 3-4 days between versions. It's great to responsive to reviewers of course!

Jonathan

Quoted 36 lines

---
Changes on switching from v3 to v4:
- return write function directly
- clean up and fix i2c_device_id

Changes on switching from v2 to v3:
- droped linux/iio/sysfs.h
- set driver name directly
- switched to IIO_CHAN_INFO_PROCESSED
- split al3000a_set_pwr into 2 functions
- added i2c_device_id
- improved code formatting

Changes on switching from v1 to v2:
- sort compatible alphabetically in schema
- clarify commit descriptions
- convert to use regmap
- arrangle lux conversion table in rows of 8
- add more used headers
- improve code formatting
---

Svyatoslav Ryhel (3):
dt-bindings: iio: light: al3010: add al3000a support
iio: light: Add support for AL3000a illuminance sensor
ARM: tegra: tf101: Add al3000a illuminance sensor node

 .../bindings/iio/light/dynaimage,al3010.yaml  |   6 +-
 .../boot/dts/nvidia/tegra20-asus-tf101.dts    |  11 +
 drivers/iio/light/Kconfig                     |  10 +
 drivers/iio/light/Makefile                    |   1 +
 drivers/iio/light/al3000a.c                   | 209 ++++++++++++++++++
 5 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100644 drivers/iio/light/al3000a.c
#13 lore raw

пн, 17 лют. 2025 р. о 16:30 Jonathan Cameron <[email protected]> пише:

Quoted 7 lines
Quoted 1 line · On Mon, 17 Feb 2025 16:03:33 +0200 Svyatoslav Ryhel <[email protected]> wrote:

AL3000a is an illuminance sensor found in ASUS TF101 tablet.

Hi Svyatoslav,

Quoted 10 lines

Just a small request. Please reduce rate of sending new versions. That tends to give time for discussions on earlier versions to progress and for more reviewers to see the current version.

I'd suggest at least 3-4 days between versions. It's great to responsive to reviewers of course!

Jonathan

Once you are satisfied with amount of time patch will hang, let me know, I will upload new version. Thank you.

Quoted 37 lines
Quoted 36 lines

---
Changes on switching from v3 to v4:
- return write function directly
- clean up and fix i2c_device_id

Changes on switching from v2 to v3:
- droped linux/iio/sysfs.h
- set driver name directly
- switched to IIO_CHAN_INFO_PROCESSED
- split al3000a_set_pwr into 2 functions
- added i2c_device_id
- improved code formatting

Changes on switching from v1 to v2:
- sort compatible alphabetically in schema
- clarify commit descriptions
- convert to use regmap
- arrangle lux conversion table in rows of 8
- add more used headers
- improve code formatting
---

Svyatoslav Ryhel (3):
dt-bindings: iio: light: al3010: add al3000a support
iio: light: Add support for AL3000a illuminance sensor
ARM: tegra: tf101: Add al3000a illuminance sensor node

 .../bindings/iio/light/dynaimage,al3010.yaml  |   6 +-
 .../boot/dts/nvidia/tegra20-asus-tf101.dts    |  11 +
 drivers/iio/light/Kconfig                     |  10 +
 drivers/iio/light/Makefile                    |   1 +
 drivers/iio/light/al3000a.c                   | 209 ++++++++++++++++++
 5 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100644 drivers/iio/light/al3000a.c
maintainer
#14 lore raw
Quoted 15 lines · On Mon, 17 Feb 2025 16:33:45 +0200 Svyatoslav Ryhel <[email protected]> wrote:

пн, 17 лют. 2025 р. о 16:30 Jonathan Cameron <[email protected]> пише:

Quoted 14 lines
Quoted 1 line · On Mon, 17 Feb 2025 16:03:33 +0200 Svyatoslav Ryhel <[email protected]> wrote:

AL3000a is an illuminance sensor found in ASUS TF101 tablet.

Hi Svyatoslav,

Just a small request. Please reduce rate of sending new versions. That tends to give time for discussions on earlier versions to progress and for more reviewers to see the current version.

I'd suggest at least 3-4 days between versions. It's great to responsive to reviewers of course!

Quoted 6 lines
Quoted 3 lines

Jonathan

Once you are satisfied with amount of time patch will hang, let me know, I will upload new version. Thank you.

That approach will never work. Just use 1 week between versions
if you need a simple number.

Jonathan

Quoted 38 lines
Quoted 38 lines
Quoted 37 lines

---
Changes on switching from v3 to v4:
- return write function directly
- clean up and fix i2c_device_id

Changes on switching from v2 to v3:
- droped linux/iio/sysfs.h
- set driver name directly
- switched to IIO_CHAN_INFO_PROCESSED
- split al3000a_set_pwr into 2 functions
- added i2c_device_id
- improved code formatting

Changes on switching from v1 to v2:
- sort compatible alphabetically in schema
- clarify commit descriptions
- convert to use regmap
- arrangle lux conversion table in rows of 8
- add more used headers
- improve code formatting
---

Svyatoslav Ryhel (3):
dt-bindings: iio: light: al3010: add al3000a support
iio: light: Add support for AL3000a illuminance sensor
ARM: tegra: tf101: Add al3000a illuminance sensor node

 .../bindings/iio/light/dynaimage,al3010.yaml  |   6 +-
 .../boot/dts/nvidia/tegra20-asus-tf101.dts    |  11 +
 drivers/iio/light/Kconfig                     |  10 +
 drivers/iio/light/Makefile                    |   1 +
 drivers/iio/light/al3000a.c                   | 209 ++++++++++++++++++
 5 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100644 drivers/iio/light/al3000a.c