Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v2 0/5] iio: light: gp2ap020a00f: Add VCC supply and GP2AP030A00F support
@ 2026-11-08 21:43 Linus Walleij
  2026-11-08 21:43 ` [PATCH v2 1/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add VCC supply Linus Walleij
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Linus Walleij @ 2026-11-08 21:43 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park
  Cc: devicetree, Linus Walleij

Describe and enable the optional VCC supply for the GP2AP020A00F and
GP2AP030A00F. Preserve compatibility with existing device trees that only
describe the LED supply.

Extend the existing binding and driver to support the GP2AP030A00F. It
shares the register layout, but has different proximity resolution
encodings and no automatic lux calculation. Select model-specific
initialization, keep reserved bits clear and expose fixed-range raw
clear and infrared counts. Keep generic supply handling in separate
patches from the model-specific binding and driver additions.

Assisted by LLM.

Signed-off-by: Linus Walleij <linusw@kernel.org>
---
Changes in v2:
- Replace vdd/vio with one optional vcc supply, matching the VCC pin.
- Use devm_regulator_get_enable() for VCC, allowing dummy regulators.
- Move the VLED description into the generic supply binding patch.
- Split variant infrastructure from GP2AP030A00F support.
- Use "GP2AP020A00F and similar" in family descriptions.
- Use reverse Christmas tree ordering for local declarations.
- Explicitly select MANUAL_CALC when automatic ALS calculation is absent.
- Reject missing chip match data before accessing the device.
- Use fsleep() for the GP2AP030A00F startup delay.
- Select static channel arrays and counts through chip_info.
- Link to v1: https://patch.msgid.link/20261108-gp2ap030-v1-0-55314eb7055b@kernel.org

---
Linus Walleij (5):
      dt-bindings: iio: light: sharp,gp2ap020a00f: Add VCC supply
      dt-bindings: iio: light: sharp,gp2ap020a00f: Add GP2AP030A00F
      iio: light: gp2ap020a00f: Enable the VCC supply
      iio: light: gp2ap020a00f: Prepare for chip variants
      iio: light: gp2ap020a00f: Add GP2AP030A00F support

 .../bindings/iio/light/sharp,gp2ap020a00f.yaml     |  17 ++-
 drivers/iio/light/Kconfig                          |   6 +-
 drivers/iio/light/gp2ap020a00f.c                   | 136 +++++++++++++++++++--
 3 files changed, 143 insertions(+), 16 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261107-gp2ap030-99504c2dc038

Best regards,
--  
Linus Walleij <linusw@kernel.org>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add VCC supply
  2026-11-08 21:43 [PATCH v2 0/5] iio: light: gp2ap020a00f: Add VCC supply and GP2AP030A00F support Linus Walleij
@ 2026-11-08 21:43 ` Linus Walleij
  2026-11-09 12:54   ` Krzysztof Kozlowski
  2026-11-08 21:44 ` [PATCH v2 2/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add GP2AP030A00F Linus Walleij
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Linus Walleij @ 2026-11-08 21:43 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park
  Cc: devicetree, Linus Walleij

Describe the sensor core supply as vcc-supply, following the VCC pin
name in the GP2AP030A00F datasheet. VI2C denotes the I2C and interrupt
pull-up voltage, not a separate sensor supply pin.

Keep the property optional to preserve compatibility with existing
device trees that only describe vled-supply.

Document the existing LED supply as the infrared LED anode supply
(LEDA).

Datasheet: https://global.sharp/products/device/lineup/data/pdf/datasheet/gp2ap030a00f_e.pdf
Link: https://global.sharp/corporate/news/110721.html
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml b/Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml
index 3fabf1f576cf..afba0b005b34 100644
--- a/Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml
+++ b/Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml
@@ -22,7 +22,11 @@ properties:
   interrupts:
     maxItems: 1
 
-  vled-supply: true
+  vcc-supply:
+    description: Sensor core power supply (VCC).
+
+  vled-supply:
+    description: Infrared LED anode power supply (LEDA).
 
 additionalProperties: false
 

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 2/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add GP2AP030A00F
  2026-11-08 21:43 [PATCH v2 0/5] iio: light: gp2ap020a00f: Add VCC supply and GP2AP030A00F support Linus Walleij
  2026-11-08 21:43 ` [PATCH v2 1/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add VCC supply Linus Walleij
@ 2026-11-08 21:44 ` Linus Walleij
  2026-11-09 12:54   ` Krzysztof Kozlowski
  2026-11-08 21:44 ` [PATCH v2 3/5] iio: light: gp2ap020a00f: Enable the VCC supply Linus Walleij
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Linus Walleij @ 2026-11-08 21:44 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park
  Cc: devicetree, Linus Walleij

The GP2AP030A00F uses the same register address layout and interrupt
interface as the GP2AP020A00F, but returns raw clear and infrared counts
instead of providing automatic illuminance calculation. Describe it in
the existing binding with its own compatible.

Datasheet: https://global.sharp/products/device/lineup/data/pdf/datasheet/gp2ap030a00f_e.pdf
Datasheet: https://jp.sharp/products/device/doc/opto/gp2ap030a00f_appl_e.pdf
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 .../devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml     | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml b/Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml
index afba0b005b34..f4a262dbc956 100644
--- a/Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml
+++ b/Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml
@@ -4,17 +4,22 @@
 $id: http://devicetree.org/schemas/iio/light/sharp,gp2ap020a00f.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: Sharp GP2AP020A00F I2C Proximity/ALS sensor
+title: Sharp GP2AP020A00F and similar proximity and ambient light sensors
 
 maintainers:
   - Kyungmin Park <kyungmin.park@samsung.com>
 
 description: |
-  The proximity detector sensor requires power supply for its built-in led.
+  The sensors provide digital clear, infrared and proximity measurements.
+  The GP2AP020A00F can also calculate illuminance internally, while the
+  GP2AP030A00F exposes raw clear and infrared photodiode counts.
+  The proximity detector requires a power supply for its built-in LED.
 
 properties:
   compatible:
-    const: sharp,gp2ap020a00f
+    enum:
+      - sharp,gp2ap020a00f
+      - sharp,gp2ap030a00f
 
   reg:
     maxItems: 1

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 3/5] iio: light: gp2ap020a00f: Enable the VCC supply
  2026-11-08 21:43 [PATCH v2 0/5] iio: light: gp2ap020a00f: Add VCC supply and GP2AP030A00F support Linus Walleij
  2026-11-08 21:43 ` [PATCH v2 1/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add VCC supply Linus Walleij
  2026-11-08 21:44 ` [PATCH v2 2/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add GP2AP030A00F Linus Walleij
@ 2026-11-08 21:44 ` Linus Walleij
  2026-11-09  9:21   ` Joshua Crofts
  2026-11-08 21:44 ` [PATCH v2 4/5] iio: light: gp2ap020a00f: Prepare for chip variants Linus Walleij
  2026-11-08 21:44 ` [PATCH v2 5/5] iio: light: gp2ap020a00f: Add GP2AP030A00F support Linus Walleij
  4 siblings, 1 reply; 13+ messages in thread
From: Linus Walleij @ 2026-11-08 21:44 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park
  Cc: devicetree, Linus Walleij

Enable the VCC supply before accessing the device. Use the managed
helper so it is disabled on probe failure and removal. Let the regulator
framework provide a dummy regulator for an unspecified supply, and
propagate errors, including deferred probe.

Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/iio/light/gp2ap020a00f.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
index b435dc5e8706..dc07d137f084 100644
--- a/drivers/iio/light/gp2ap020a00f.c
+++ b/drivers/iio/light/gp2ap020a00f.c
@@ -1414,6 +1414,10 @@ static int gp2ap020a00f_probe(struct i2c_client *client)
 
 	data = iio_priv(indio_dev);
 
+	err = devm_regulator_get_enable(dev, "vcc");
+	if (err)
+		return dev_err_probe(dev, err, "Failed to enable VCC supply\n");
+
 	data->vled_reg = devm_regulator_get(dev, "vled");
 	if (IS_ERR(data->vled_reg))
 		return PTR_ERR(data->vled_reg);

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 4/5] iio: light: gp2ap020a00f: Prepare for chip variants
  2026-11-08 21:43 [PATCH v2 0/5] iio: light: gp2ap020a00f: Add VCC supply and GP2AP030A00F support Linus Walleij
                   ` (2 preceding siblings ...)
  2026-11-08 21:44 ` [PATCH v2 3/5] iio: light: gp2ap020a00f: Enable the VCC supply Linus Walleij
@ 2026-11-08 21:44 ` Linus Walleij
  2026-11-09  9:20   ` Joshua Crofts
  2026-11-09 23:14   ` Andy Shevchenko
  2026-11-08 21:44 ` [PATCH v2 5/5] iio: light: gp2ap020a00f: Add GP2AP030A00F support Linus Walleij
  4 siblings, 2 replies; 13+ messages in thread
From: Linus Walleij @ 2026-11-08 21:44 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park
  Cc: devicetree, Linus Walleij

Introduce chip data for the device name, initialization table and channel
layout, including the channel count. Use I2C/OF match data to select it
during probe, preparing for sensors with shared register layouts and
different initialization settings.

Populate only the GP2AP020A00F data, keeping its register values,
channels and operating behavior unchanged.

Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/iio/light/gp2ap020a00f.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
index dc07d137f084..5464311515c7 100644
--- a/drivers/iio/light/gp2ap020a00f.c
+++ b/drivers/iio/light/gp2ap020a00f.c
@@ -234,7 +234,15 @@ enum gp2ap020a00f_thresh_val_id {
 	GP2AP020A00F_THRESH_PH,
 };
 
+struct gp2ap020a00f_chip_info {
+	const char *name;
+	const u8 *reg_init_tab;
+	const struct iio_chan_spec *channels;
+	unsigned int num_channels;
+};
+
 struct gp2ap020a00f_data {
+	const struct gp2ap020a00f_chip_info *chip_info;
 	struct i2c_client *client;
 	struct mutex lock;
 	char *buffer;
@@ -1309,6 +1317,13 @@ static const struct iio_chan_spec gp2ap020a00f_channels[] = {
 	IIO_CHAN_SOFT_TIMESTAMP(GP2AP020A00F_CHAN_TIMESTAMP),
 };
 
+static const struct gp2ap020a00f_chip_info gp2ap020a00f_chip_info = {
+	.name = "gp2ap020a00f",
+	.reg_init_tab = gp2ap020a00f_reg_init_tab,
+	.channels = gp2ap020a00f_channels,
+	.num_channels = ARRAY_SIZE(gp2ap020a00f_channels),
+};
+
 static const struct iio_info gp2ap020a00f_info = {
 	.read_raw = &gp2ap020a00f_read_raw,
 	.read_event_value = &gp2ap020a00f_read_event_val,
@@ -1401,7 +1416,6 @@ static const struct iio_buffer_setup_ops gp2ap020a00f_buffer_setup_ops = {
 
 static int gp2ap020a00f_probe(struct i2c_client *client)
 {
-	const struct i2c_device_id *id = i2c_client_get_device_id(client);
 	struct device *dev = &client->dev;
 	struct gp2ap020a00f_data *data;
 	struct iio_dev *indio_dev;
@@ -1413,6 +1427,9 @@ static int gp2ap020a00f_probe(struct i2c_client *client)
 		return -ENOMEM;
 
 	data = iio_priv(indio_dev);
+	data->chip_info = i2c_get_match_data(client);
+	if (!data->chip_info)
+		return -EINVAL;
 
 	err = devm_regulator_get_enable(dev, "vcc");
 	if (err)
@@ -1435,7 +1452,7 @@ static int gp2ap020a00f_probe(struct i2c_client *client)
 
 	/* Initialize device registers */
 	err = regmap_bulk_write(regmap, GP2AP020A00F_OP_REG,
-			gp2ap020a00f_reg_init_tab,
+			data->chip_info->reg_init_tab,
 			ARRAY_SIZE(gp2ap020a00f_reg_init_tab));
 
 	if (err < 0) {
@@ -1451,10 +1468,10 @@ static int gp2ap020a00f_probe(struct i2c_client *client)
 	init_waitqueue_head(&data->data_ready_queue);
 
 	mutex_init(&data->lock);
-	indio_dev->channels = gp2ap020a00f_channels;
-	indio_dev->num_channels = ARRAY_SIZE(gp2ap020a00f_channels);
+	indio_dev->channels = data->chip_info->channels;
+	indio_dev->num_channels = data->chip_info->num_channels;
 	indio_dev->info = &gp2ap020a00f_info;
-	indio_dev->name = id->name;
+	indio_dev->name = data->chip_info->name;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
 	/* Allocate buffer */
@@ -1530,13 +1547,14 @@ static void gp2ap020a00f_remove(struct i2c_client *client)
 }
 
 static const struct i2c_device_id gp2ap020a00f_id[] = {
-	{ .name = "gp2ap020a00f" },
+	{ .name = "gp2ap020a00f",
+	  .driver_data = (kernel_ulong_t)&gp2ap020a00f_chip_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, gp2ap020a00f_id);
 
 static const struct of_device_id gp2ap020a00f_of_match[] = {
-	{ .compatible = "sharp,gp2ap020a00f" },
+	{ .compatible = "sharp,gp2ap020a00f", .data = &gp2ap020a00f_chip_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, gp2ap020a00f_of_match);

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 5/5] iio: light: gp2ap020a00f: Add GP2AP030A00F support
  2026-11-08 21:43 [PATCH v2 0/5] iio: light: gp2ap020a00f: Add VCC supply and GP2AP030A00F support Linus Walleij
                   ` (3 preceding siblings ...)
  2026-11-08 21:44 ` [PATCH v2 4/5] iio: light: gp2ap020a00f: Prepare for chip variants Linus Walleij
@ 2026-11-08 21:44 ` Linus Walleij
  2026-11-09  9:25   ` Joshua Crofts
  2026-11-09 23:17   ` Andy Shevchenko
  4 siblings, 2 replies; 13+ messages in thread
From: Linus Walleij @ 2026-11-08 21:44 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park
  Cc: devicetree, Linus Walleij

The GP2AP030A00F has the same register addresses and interrupt modes
as the GP2AP020A00F, but does not implement its automatic
illuminance calculation or selectable ambient-light cancellation.

Datasheet: https://jp.sharp/products/device/doc/opto/gp2ap030a00f_appl_e.pdf
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/iio/light/Kconfig        |   6 +--
 drivers/iio/light/gp2ap020a00f.c | 100 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 101 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 462fff1ddef2..89fe003371b8 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -259,15 +259,15 @@ config GP2AP002
 	  module will be called gp2ap002.
 
 config GP2AP020A00F
-	tristate "Sharp GP2AP020A00F Proximity/ALS sensor"
+	tristate "Sharp GP2AP020A00F and similar Proximity/ALS sensors"
 	depends on I2C
 	select REGMAP_I2C
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
 	select IRQ_WORK
 	help
-	  Say Y here if you have a Sharp GP2AP020A00F proximity/ALS combo-chip
-	  hooked to an I2C bus.
+	  Say Y here to enable support for the Sharp GP2AP020A00F and similar
+	  proximity/ALS combo-chips hooked to an I2C bus.
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called gp2ap020a00f.
diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
index 5464311515c7..813a64ee627c 100644
--- a/drivers/iio/light/gp2ap020a00f.c
+++ b/drivers/iio/light/gp2ap020a00f.c
@@ -54,6 +54,11 @@
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
 
+/*
+ * The GP2AP030A00F shares the register layout, but has no TYPE or ALC bit.
+ * Its D0 and D1 registers always contain raw clear and infrared counts.
+ */
+
 /* Registers */
 #define GP2AP020A00F_OP_REG	0x00 /* Basic operations */
 #define GP2AP020A00F_ALS_REG	0x01 /* ALS related settings */
@@ -137,6 +142,7 @@
 #define GP2AP020A00F_RES_P_6_25ms_x2	0x28
 #define GP2AP020A00F_RES_P_1_56ms_x2	0x30
 #define GP2AP020A00F_RES_P_0_39ms_x2	0x38
+#define GP2AP030A00F_RES_P_1_56ms_x2	0x18
 #define GP2AP020A00F_RANGE_P_MASK	0x07 /* PS: Max measurable range */
 #define GP2AP020A00F_RANGE_P_x1		0x00
 #define GP2AP020A00F_RANGE_P_x2		0x01
@@ -158,6 +164,7 @@
 #define GP2AP020A00F_IS_27_5mA		0x10
 #define GP2AP020A00F_IS_55mA		0x20
 #define GP2AP020A00F_IS_110mA		0x30
+#define GP2AP030A00F_IS_130mA		0x30
 #define GP2AP020A00F_PIN_MASK		0x0c /* INT terminal setting */
 #define GP2AP020A00F_PIN_ALS_OR_PS	0x00
 #define GP2AP020A00F_PIN_ALS		0x04
@@ -239,6 +246,7 @@ struct gp2ap020a00f_chip_info {
 	const u8 *reg_init_tab;
 	const struct iio_chan_spec *channels;
 	unsigned int num_channels;
+	bool has_als_auto;
 };
 
 struct gp2ap020a00f_data {
@@ -276,6 +284,17 @@ static const u8 gp2ap020a00f_reg_init_tab[] = {
 	[GP2AP020A00F_PH_H_REG] = 0,
 };
 
+static const u8 gp2ap030a00f_reg_init_tab[ARRAY_SIZE(gp2ap020a00f_reg_init_tab)] = {
+	[GP2AP020A00F_OP_REG] = GP2AP020A00F_OP3_SHUTDOWN,
+	[GP2AP020A00F_ALS_REG] = GP2AP020A00F_RES_A_100ms |
+				 GP2AP020A00F_RANGE_A_x8,
+	[GP2AP020A00F_PS_REG] = GP2AP030A00F_RES_P_1_56ms_x2 |
+				GP2AP020A00F_RANGE_P_x4,
+	[GP2AP020A00F_LED_REG] = GP2AP020A00F_INTVAL_0 |
+				 GP2AP030A00F_IS_130mA |
+				 GP2AP020A00F_FREQ_327_5kHz,
+};
+
 static bool gp2ap020a00f_is_volatile_reg(struct device *dev, unsigned int reg)
 {
 	switch (reg) {
@@ -371,6 +390,7 @@ static const struct gp2ap020a00f_mutable_config_regs {
 static int gp2ap020a00f_set_operation_mode(struct gp2ap020a00f_data *data,
 					enum gp2ap020a00f_opmode op)
 {
+	u8 op_reg = opmode_regs_settings[op].op_reg;
 	unsigned int op_reg_val;
 	int err;
 
@@ -409,12 +429,16 @@ static int gp2ap020a00f_set_operation_mode(struct gp2ap020a00f_data *data,
 			return err;
 	}
 
+	if (!data->chip_info->has_als_auto)
+		op_reg = (op_reg & ~GP2AP020A00F_TYPE_MASK) |
+			 GP2AP020A00F_TYPE_MANUAL_CALC;
+
 	/* Set OP_REG and apply operation mode (power on / off) */
 	err = regmap_update_bits(data->regmap,
 				 GP2AP020A00F_OP_REG,
 				 GP2AP020A00F_OP_MASK | GP2AP020A00F_OP2_MASK |
 				 GP2AP020A00F_OP3_MASK | GP2AP020A00F_TYPE_MASK,
-				 opmode_regs_settings[op].op_reg);
+				 op_reg);
 	if (err < 0)
 		return err;
 
@@ -446,6 +470,8 @@ static int gp2ap020a00f_write_event_threshold(struct gp2ap020a00f_data *data,
 
 	if (!enable)
 		thresh_reg_val = 0;
+	else if (!data->chip_info->has_als_auto)
+		thresh_reg_val = min(data->thresh_val[th_val_id], 65535U);
 	else if (test_bit(GP2AP020A00F_FLAG_LUX_MODE_HI, &data->flags) &&
 		 th_val_id != GP2AP020A00F_THRESH_PL &&
 		 th_val_id != GP2AP020A00F_THRESH_PH)
@@ -709,6 +735,10 @@ static bool gp2ap020a00f_adjust_lux_mode(struct gp2ap020a00f_data *data,
 	u8 new_range = 0xff;
 	int err;
 
+	/* GP2AP030A00F thresholds and samples are raw counts at a fixed range. */
+	if (!data->chip_info->has_als_auto)
+		return false;
+
 	if (!test_bit(GP2AP020A00F_FLAG_LUX_MODE_HI, &data->flags)) {
 		if (output_val > 16000) {
 			set_bit(GP2AP020A00F_FLAG_LUX_MODE_HI, &data->flags);
@@ -1317,11 +1347,71 @@ static const struct iio_chan_spec gp2ap020a00f_channels[] = {
 	IIO_CHAN_SOFT_TIMESTAMP(GP2AP020A00F_CHAN_TIMESTAMP),
 };
 
+static const struct iio_chan_spec gp2ap030a00f_channels[] = {
+	{
+		.type = IIO_LIGHT,
+		.channel2 = IIO_MOD_LIGHT_CLEAR,
+		.modified = 1,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+		.scan_type = {
+			.sign = 'u',
+			.realbits = 16,
+			.shift = 0,
+			.storagebits = 32,
+			.endianness = IIO_LE,
+		},
+		.scan_index = GP2AP020A00F_SCAN_MODE_LIGHT_CLEAR,
+		.address = GP2AP020A00F_D0_L_REG,
+		.event_spec = gp2ap020a00f_event_spec_light,
+		.num_event_specs = ARRAY_SIZE(gp2ap020a00f_event_spec_light),
+	},
+	{
+		.type = IIO_LIGHT,
+		.channel2 = IIO_MOD_LIGHT_IR,
+		.modified = 1,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+		.scan_type = {
+			.sign = 'u',
+			.realbits = 16,
+			.shift = 0,
+			.storagebits = 32,
+			.endianness = IIO_LE,
+		},
+		.scan_index = GP2AP020A00F_SCAN_MODE_LIGHT_IR,
+		.address = GP2AP020A00F_D1_L_REG,
+	},
+	{
+		.type = IIO_PROXIMITY,
+		.modified = 0,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+		.scan_type = {
+			.sign = 'u',
+			.realbits = 16,
+			.shift = 0,
+			.storagebits = 16,
+			.endianness = IIO_LE,
+		},
+		.scan_index = GP2AP020A00F_SCAN_MODE_PROXIMITY,
+		.address = GP2AP020A00F_D2_L_REG,
+		.event_spec = gp2ap020a00f_event_spec_prox,
+		.num_event_specs = ARRAY_SIZE(gp2ap020a00f_event_spec_prox),
+	},
+	IIO_CHAN_SOFT_TIMESTAMP(GP2AP020A00F_CHAN_TIMESTAMP),
+};
+
 static const struct gp2ap020a00f_chip_info gp2ap020a00f_chip_info = {
 	.name = "gp2ap020a00f",
 	.reg_init_tab = gp2ap020a00f_reg_init_tab,
 	.channels = gp2ap020a00f_channels,
 	.num_channels = ARRAY_SIZE(gp2ap020a00f_channels),
+	.has_als_auto = true,
+};
+
+static const struct gp2ap020a00f_chip_info gp2ap030a00f_chip_info = {
+	.name = "gp2ap030a00f",
+	.reg_init_tab = gp2ap030a00f_reg_init_tab,
+	.channels = gp2ap030a00f_channels,
+	.num_channels = ARRAY_SIZE(gp2ap030a00f_channels),
 };
 
 static const struct iio_info gp2ap020a00f_info = {
@@ -1450,6 +1540,9 @@ static int gp2ap020a00f_probe(struct i2c_client *client)
 		goto error_regulator_disable;
 	}
 
+	if (!data->chip_info->has_als_auto)
+		fsleep(1000);
+
 	/* Initialize device registers */
 	err = regmap_bulk_write(regmap, GP2AP020A00F_OP_REG,
 			data->chip_info->reg_init_tab,
@@ -1549,12 +1642,15 @@ static void gp2ap020a00f_remove(struct i2c_client *client)
 static const struct i2c_device_id gp2ap020a00f_id[] = {
 	{ .name = "gp2ap020a00f",
 	  .driver_data = (kernel_ulong_t)&gp2ap020a00f_chip_info },
+	{ .name = "gp2ap030a00f",
+	  .driver_data = (kernel_ulong_t)&gp2ap030a00f_chip_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, gp2ap020a00f_id);
 
 static const struct of_device_id gp2ap020a00f_of_match[] = {
 	{ .compatible = "sharp,gp2ap020a00f", .data = &gp2ap020a00f_chip_info },
+	{ .compatible = "sharp,gp2ap030a00f", .data = &gp2ap030a00f_chip_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, gp2ap020a00f_of_match);
@@ -1571,5 +1667,5 @@ static struct i2c_driver gp2ap020a00f_driver = {
 module_i2c_driver(gp2ap020a00f_driver);
 
 MODULE_AUTHOR("Jacek Anaszewski <j.anaszewski@samsung.com>");
-MODULE_DESCRIPTION("Sharp GP2AP020A00F Proximity/ALS sensor driver");
+MODULE_DESCRIPTION("Sharp GP2AP020A00F and similar proximity/ALS sensor driver");
 MODULE_LICENSE("GPL v2");

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 4/5] iio: light: gp2ap020a00f: Prepare for chip variants
  2026-11-08 21:44 ` [PATCH v2 4/5] iio: light: gp2ap020a00f: Prepare for chip variants Linus Walleij
@ 2026-11-09  9:20   ` Joshua Crofts
  2026-11-09 23:14   ` Andy Shevchenko
  1 sibling, 0 replies; 13+ messages in thread
From: Joshua Crofts @ 2026-11-09  9:20 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park, devicetree

On Sun, 08 Nov 2026 22:44:02 +0100
Linus Walleij <linusw@kernel.org> wrote:

...

>  static int gp2ap020a00f_probe(struct i2c_client *client)
>  {
> -	const struct i2c_device_id *id = i2c_client_get_device_id(client);
>  	struct device *dev = &client->dev;
>  	struct gp2ap020a00f_data *data;
>  	struct iio_dev *indio_dev;
> @@ -1413,6 +1427,9 @@ static int gp2ap020a00f_probe(struct i2c_client *client)
>  		return -ENOMEM;
>  
>  	data = iio_priv(indio_dev);
> +	data->chip_info = i2c_get_match_data(client);
> +	if (!data->chip_info)
> +		return -EINVAL;

-ENODATA is better.

Otherwise LGTM.

Reviewed-by: Joshua Crofts <crofts@kernel.org>

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 3/5] iio: light: gp2ap020a00f: Enable the VCC supply
  2026-11-08 21:44 ` [PATCH v2 3/5] iio: light: gp2ap020a00f: Enable the VCC supply Linus Walleij
@ 2026-11-09  9:21   ` Joshua Crofts
  0 siblings, 0 replies; 13+ messages in thread
From: Joshua Crofts @ 2026-11-09  9:21 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park, devicetree

On Sun, 08 Nov 2026 22:44:01 +0100
Linus Walleij <linusw@kernel.org> wrote:

> Enable the VCC supply before accessing the device. Use the managed
> helper so it is disabled on probe failure and removal. Let the regulator
> framework provide a dummy regulator for an unspecified supply, and
> propagate errors, including deferred probe.
> 
> Signed-off-by: Linus Walleij <linusw@kernel.org>
> ---

Reviewed-by: Joshua Crofts <crofts@kernel.org>

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 5/5] iio: light: gp2ap020a00f: Add GP2AP030A00F support
  2026-11-08 21:44 ` [PATCH v2 5/5] iio: light: gp2ap020a00f: Add GP2AP030A00F support Linus Walleij
@ 2026-11-09  9:25   ` Joshua Crofts
  2026-11-09 23:17   ` Andy Shevchenko
  1 sibling, 0 replies; 13+ messages in thread
From: Joshua Crofts @ 2026-11-09  9:25 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park, devicetree

On Sun, 08 Nov 2026 22:44:03 +0100
Linus Walleij <linusw@kernel.org> wrote:

...

>  static const struct iio_info gp2ap020a00f_info = {
> @@ -1450,6 +1540,9 @@ static int gp2ap020a00f_probe(struct i2c_client *client)
>  		goto error_regulator_disable;
>  	}
>  
> +	if (!data->chip_info->has_als_auto)
> +		fsleep(1000);

Maybe a comment on why 1000 specifically (datasheet reference etc.).

Reviewed-by: Joshua Crofts <crofts@kernel.org>

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add VCC supply
  2026-11-08 21:43 ` [PATCH v2 1/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add VCC supply Linus Walleij
@ 2026-11-09 12:54   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-09 12:54 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park, devicetree

On Sun, Nov 08, 2026 at 10:43:59PM +0100, Linus Walleij wrote:
> Describe the sensor core supply as vcc-supply, following the VCC pin
> name in the GP2AP030A00F datasheet. VI2C denotes the I2C and interrupt
> pull-up voltage, not a separate sensor supply pin.
> 
> Keep the property optional to preserve compatibility with existing
> device trees that only describe vled-supply.
> 
> Document the existing LED supply as the infrared LED anode supply
> (LEDA).
> 
> Datasheet: https://global.sharp/products/device/lineup/data/pdf/datasheet/gp2ap030a00f_e.pdf
> Link: https://global.sharp/corporate/news/110721.html
> Signed-off-by: Linus Walleij <linusw@kernel.org>
> ---
>  Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add GP2AP030A00F
  2026-11-08 21:44 ` [PATCH v2 2/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add GP2AP030A00F Linus Walleij
@ 2026-11-09 12:54   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-09 12:54 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park, devicetree

On Sun, Nov 08, 2026 at 10:44:00PM +0100, Linus Walleij wrote:
> The GP2AP030A00F uses the same register address layout and interrupt
> interface as the GP2AP020A00F, but returns raw clear and infrared counts
> instead of providing automatic illuminance calculation. Describe it in
> the existing binding with its own compatible.
> 
> Datasheet: https://global.sharp/products/device/lineup/data/pdf/datasheet/gp2ap030a00f_e.pdf
> Datasheet: https://jp.sharp/products/device/doc/opto/gp2ap030a00f_appl_e.pdf
> Signed-off-by: Linus Walleij <linusw@kernel.org>
> ---
>  .../devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml     | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 4/5] iio: light: gp2ap020a00f: Prepare for chip variants
  2026-11-08 21:44 ` [PATCH v2 4/5] iio: light: gp2ap020a00f: Prepare for chip variants Linus Walleij
  2026-11-09  9:20   ` Joshua Crofts
@ 2026-11-09 23:14   ` Andy Shevchenko
  1 sibling, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2026-11-09 23:14 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park, devicetree

On Sun, Nov 08, 2026 at 10:44:02PM +0100, Linus Walleij wrote:
> Introduce chip data for the device name, initialization table and channel
> layout, including the channel count. Use I2C/OF match data to select it
> during probe, preparing for sensors with shared register layouts and
> different initialization settings.
> 
> Populate only the GP2AP020A00F data, keeping its register values,
> channels and operating behavior unchanged.

...

>  	data = iio_priv(indio_dev);
> +	data->chip_info = i2c_get_match_data(client);
> +	if (!data->chip_info)
> +		return -EINVAL;

-ENODATA

...

>  static const struct i2c_device_id gp2ap020a00f_id[] = {
> -	{ .name = "gp2ap020a00f" },
> +	{ .name = "gp2ap020a00f",
> +	  .driver_data = (kernel_ulong_t)&gp2ap020a00f_chip_info },

It's unusual style, either make it 4 lines or 1 line per entry.

>  	{ }
>  };

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 5/5] iio: light: gp2ap020a00f: Add GP2AP030A00F support
  2026-11-08 21:44 ` [PATCH v2 5/5] iio: light: gp2ap020a00f: Add GP2AP030A00F support Linus Walleij
  2026-11-09  9:25   ` Joshua Crofts
@ 2026-11-09 23:17   ` Andy Shevchenko
  1 sibling, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2026-11-09 23:17 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Kyungmin Park, devicetree

On Sun, Nov 08, 2026 at 10:44:03PM +0100, Linus Walleij wrote:
> The GP2AP030A00F has the same register addresses and interrupt modes
> as the GP2AP020A00F, but does not implement its automatic
> illuminance calculation or selectable ambient-light cancellation.

...

>  config GP2AP020A00F
> -	tristate "Sharp GP2AP020A00F Proximity/ALS sensor"
> +	tristate "Sharp GP2AP020A00F and similar Proximity/ALS sensors"

Also make sure the text in MODULE_DESCRIPTION() and perhaps top comment in the
code matches the above (ideally be the same).

>  	depends on I2C
>  	select REGMAP_I2C
>  	select IIO_BUFFER
>  	select IIO_TRIGGERED_BUFFER
>  	select IRQ_WORK
>  	help
> -	  Say Y here if you have a Sharp GP2AP020A00F proximity/ALS combo-chip
> -	  hooked to an I2C bus.
> +	  Say Y here to enable support for the Sharp GP2AP020A00F and similar
> +	  proximity/ALS combo-chips hooked to an I2C bus.

Here we actually want more precise list of supported part numbers.

...

/* ...a comment to explain the delay... */

> +	if (!data->chip_info->has_als_auto)
> +		fsleep(1000);

1 * USEC_PER_MSEC

...

> +	{ .name = "gp2ap030a00f",
> +	  .driver_data = (kernel_ulong_t)&gp2ap030a00f_chip_info },

Same comment about the chosen style.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-11-09 23:17 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-08 21:43 [PATCH v2 0/5] iio: light: gp2ap020a00f: Add VCC supply and GP2AP030A00F support Linus Walleij
2026-11-08 21:43 ` [PATCH v2 1/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add VCC supply Linus Walleij
2026-11-09 12:54   ` Krzysztof Kozlowski
2026-11-08 21:44 ` [PATCH v2 2/5] dt-bindings: iio: light: sharp,gp2ap020a00f: Add GP2AP030A00F Linus Walleij
2026-11-09 12:54   ` Krzysztof Kozlowski
2026-11-08 21:44 ` [PATCH v2 3/5] iio: light: gp2ap020a00f: Enable the VCC supply Linus Walleij
2026-11-09  9:21   ` Joshua Crofts
2026-11-08 21:44 ` [PATCH v2 4/5] iio: light: gp2ap020a00f: Prepare for chip variants Linus Walleij
2026-11-09  9:20   ` Joshua Crofts
2026-11-09 23:14   ` Andy Shevchenko
2026-11-08 21:44 ` [PATCH v2 5/5] iio: light: gp2ap020a00f: Add GP2AP030A00F support Linus Walleij
2026-11-09  9:25   ` Joshua Crofts
2026-11-09 23:17   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox