iio: light: gp2ap020a00f: Add VCC supply and GP2AP030A00F support
Subsystems (2)
v3 cover iio: light: gp2ap020a00f: Add VCC supply and GP2AP030A00F support
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.
---
Changes in v3:
- Return -ENODATA when chip match data is missing.
- Use four-line initializers for I2C device IDs.
- Document the 1 ms power-on delay and use USEC_PER_MSEC.
- Align family descriptions and list supported parts in Kconfig help.
- Pack GP2AP030A00F samples as 16-bit values and omit zero shifts.
- Link to v2: https://patch.msgid.link/[email protected]
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/[email protected]
---
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 | 147 +++++++++++++++++++-- 3 files changed, 151 insertions(+), 19 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261107-gp2ap030-99504c2dc038
Best regards,
Signature · 1 line
Linus Walleij <[email protected]>
PATCH v3 1/5 dt-bindings: iio: light: sharp,gp2ap020a00f: Add VCC supply
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
--- Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml +5 -1
@@ -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
Signature · 1 line
2.56.0
PATCH v3 2/5 dt-bindings: iio: light: sharp,gp2ap020a00f: Add GP2AP030A00F
In reply to Linus WalleijThe 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
--- .../devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/iio/light/sharp,gp2ap020a00f.yaml +8 -3
@@ -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 <[email protected]> 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
Signature · 1 line
2.56.0
PATCH v3 3/5 iio: light: gp2ap020a00f: Enable the VCC supply
In reply to Linus WalleijEnable 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.
--- drivers/iio/light/gp2ap020a00f.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/iio/light/gp2ap020a00f.c +4 -0
@@ -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);
Signature · 1 line
2.56.0
PATCH v3 4/5 iio: light: gp2ap020a00f: Prepare for chip variants
In reply to Linus WalleijIntroduce 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.
--- drivers/iio/light/gp2ap020a00f.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-)
drivers/iio/light/gp2ap020a00f.c +27 -7
@@ -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 -ENODATA ; 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,16 @@ 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);
Signature · 1 line
2.56.0
PATCH v3 5/5 iio: light: gp2ap020a00f: Add GP2AP030A00F support
In reply to Linus WalleijThe 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
--- drivers/iio/light/Kconfig | 6 +-- drivers/iio/light/gp2ap020a00f.c | 109 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 107 insertions(+), 8 deletions(-)
drivers/iio/light/Kconfig +3 -3
@@ -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 + GP2AP030A00F 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.
drivers/iio/light/gp2ap020a00f.c +104 -5
218 lines not on this page · raw message
Signature · 1 line
2.56.0
Quoted 11 lines · On Wed, 18 Nov 2026 14:46:07 +0100 Linus Walleij <[email protected]> wrote:
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.
Quoted 3 lines
Assisted by LLM.
Signed-off-by Linus Walleij <[email protected]>
Applied. Thanks,
J
Quoted 42 lines
---
Changes in v3:
- Return-ENODATAwhen chip match data is missing.
- Use four-line initializers for I2C device IDs.
- Document the 1 ms power-on delay and useUSEC_PER_MSEC.
- Align family descriptions and list supported parts inKconfighelp.
- Pack GP2AP030A00F samples as 16-bit values and omit zero shifts.
- Link to v2: https://patch.msgid.link/[email protected]Changes in v2:
- Replace vdd/vio with one optional vcc supply, matching the VCC pin.
- Usedevm_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 selectMANUAL_CALCwhen automatic ALS calculation is absent.
- Reject missing chip match data before accessing the device.
- Usefsleep()for the GP2AP030A00F startup delay.
- Select static channel arrays and counts throughchip_info.
- Link to v1: https://patch.msgid.link/[email protected]---
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 | 147 +++++++++++++++++++-- 3 files changed, 151 insertions(+), 19 deletions(-)---
base-commit:6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261107-gp2ap030-99504c2dc038Best regards,
Signature · 1 line
Linus Walleij <[email protected]>