Skip to contentSkip to conversation

Add LTRF216A Driver

PATCH Superseded Shreeya Patel 3 participants 9 messages Jul 11, 2022

Subsystems (2)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v7 cover Add LTRF216A Driver

This patchset adds support for ltrf216a Ambient Light Sensor and documents the DT bindings for the same.

Changes in v7
- Add regmap support.
- Fix runtime power management implementation.
- Fix the ordering of devm and non-devm functions.
- Use DEFINE_RUNTIME_DEV_PM_OPS macro
- Fix the error reported by kernel test robot for bindings.

Changes in v6
- Fix some errors reported by kernel test robot.
- Add protocol details for the datasheet link.
- Remove useless assignments.
- Add unit details for read data delay macro.
- Use pm_sleep_ptr().

Changes in v5
- Add power management support.
- Add reset functionality.
- Use readx_poll_timeout() to get data.
- Cleanup some of the redundant code.
- Update int_time_fac after I2C write is successful.
- Rename mutex to lock.
- Use Reverse Xmas tree pattern for all variable definitions.
- Improve error handling messages and add error codes.
- Add one more MODULE_AUTHOR.
- Remove cleardata which was reading data for infrared light.
- Remove patch for deprecated vendor prefix [PATCH v4 3/3].
- Remove deprecated string from DT binding document.

Changes in v4
- Add more descriptive comment for mutex lock
- Fix mutex locking in read_raw()
- Use i2c_smbus_read_i2c_block_data()

Changes in v3
- Use u16 instead of u8 for int_time_fac
- Reorder headers in ltrf216a.c file
- Remove int_time_mapping table and use int_time_available
- Fix indentation in the bindings file.

Changes in v2
- Add support for 25ms and 50ms integration time.
- Rename some of the macros as per names given in datasheet
- Add a comment for the mutex lock
- Use read_avail callback instead of attributes and set the appropriate _available bit.
- Use FIELD_PREP() at appropriate places.
- Add a constant lookup table for integration time and reg val
- Use BIT() macro for magic numbers.
- Improve error handling at few places.
- Use get_unaligned_le24() and div_u64()
- Use probe_new() callback and devm functions
- Return errors in probe using dev_err_probe()
- Use DEFINE_SIMPLE_DEV_PM_OPS()
- Correct the formula for lux to use 0.45 instead of 0.8
- Add interrupt and power supply property in DT bindings
- Add vendor prefix name as per the alphabetical order.

Shreeya Patel (2):
dt-bindings: Document ltrf216a light sensor bindings
iio: light: Add support for ltrf216a sensor

 .../bindings/iio/light/liteon,ltrf216a.yaml   |  49 ++
 drivers/iio/light/Kconfig                     |  11 +
 drivers/iio/light/Makefile                    |   1 +
 drivers/iio/light/ltrf216a.c                  | 423 ++++++++++++++++++
 4 files changed, 484 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/liteon,ltrf216a.yaml
 create mode 100644 drivers/iio/light/ltrf216a.c
Signature · 1 line
2.30.2
#1 lore raw

PATCH v7 1/2 dt-bindings: Document ltrf216a light sensor bindings

Add devicetree bindings for ltrf216a ambient light sensor.

---

Changes in v7
- Fix the error reported by kernel test robot.

Changes in v5
- Remove deprecated string 'ltr' from the bindings.

Changes in v3
- Fix indentation in the example section

Changes in v2
- Take over the maintainership for the bindings
- Add interrupt and power supply property in DT bindings

 .../bindings/iio/light/liteon,ltrf216a.yaml   | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/liteon,ltrf216a.yaml
Documentation/devicetree/bindings/iio/light/liteon,ltrf216a.yaml new file +49 -0
new file mode 100644
index 000000000000..7de1b0e721ca
@@ -0,0 +1,49 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/light/liteon,ltrf216a.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: LTRF216A Ambient Light Sensor
+
+maintainers:
+  - Shreeya Patel <[email protected]>
+
+description:
+  Ambient light sensing with an i2c interface.
+
+properties:
+  compatible:
+    const: liteon,ltrf216a
+
+  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@53 {
+            compatible = "liteon,ltrf216a";
+            reg = <0x53>;
+            vdd-supply = <&vdd_regulator>;
+            interrupt-parent = <&gpio0>;
+            interrupts = <5 IRQ_TYPE_LEVEL_LOW>;
+        };
+    };
Signature · 1 line
2.30.2
#2 lore raw

PATCH v7 2/2 iio: light: Add support for ltrf216a sensor

In reply to Shreeya Patel

From: Zhigang Shi <[email protected]>

Add initial support for ltrf216a ambient light sensor.

Datasheet: https://gitlab.steamos.cloud/shreeya/iio/-/blob/main/LTRF216A.pdf

---

Note :-

This patch generates the below mentioned warnings due to not documenting the 'ltr' string in vendors-prefix.yaml and liteon,ltrf216a.yaml files. The thread for the discussion of not documenting 'ltr' as deprecated prefix can be found here.
https://lore.kernel.org/lkml/[email protected]/

There are released devices which uses ltr216a light sensor and exposes the vendor prefix name as 'ltr' through ACPI. Hence, we would like to add this string under compatible property which would help probe the light sensor driver.

WARNING: DT compatible string "ltr,ltrf216a" appears un-documented -- check ./Documentation/devicetree/bindings/
#474: FILE: drivers/iio/light/ltrf216a.c:421:
+ { .compatible = "ltr,ltrf216a", },

WARNING: DT compatible string vendor "ltr" appears un-documented -- check ./Documentation/devicetree/bindings/vendor-prefixes.yaml #474: FILE: drivers/iio/light/ltrf216a.c:421:
+ { .compatible = "ltr,ltrf216a", },

Changes in v7
- Add regmap support.
- Fix runtime power management implementation.
- Fix the ordering of devm and non-devm functions.
- Use DEFINE_RUNTIME_DEV_PM_OPS macro

Changes in v6
- Fix some errors reported by kernel test robot.
- Add protocol details for the datasheet link.
- Remove useless assignments.
- Add unit details for read data delay macro.
- Use pm_sleep_ptr().

Changes in v5
- Add power management support.
- Add reset functionality.
- Use readx_poll_timeout() to get data.
- Cleanup some of the redundant code.
- Update int_time_fac after I2C write is successful.
- Rename mutex to lock.
- Use Reverse Xmas tree pattern for all variable definitions.
- Improve error handling messages and add error codes.
- Add one more MODULE_AUTHOR.
- Remove cleardata which was reading data for infrared light.

Changes in v4
- Add more descriptive comment for mutex lock
- Fix mutex locking in read_raw()
- Use i2c_smbus_read_i2c_block_data()

Changes in v3
- Use u16 instead of u8 for int_time_fac
- Reorder headers in ltrf216a.c file
- Remove int_time_mapping table and use int_time_available

Changes in v2
- Add support for 25ms and 50ms integration time.
- Rename some of the macros as per names given in datasheet
- Add a comment for the mutex lock
- Use read_avail callback instead of attributes and set the appropriate _available bit.
- Use FIELD_PREP() at appropriate places.
- Add a constant lookup table for integration time and reg val
- Use BIT() macro for magic numbers.
- Improve error handling at few places.
- Use get_unaligned_le24() and div_u64()
- Use probe_new() callback and devm functions
- Return errors in probe using dev_err_probe()
- Use DEFINE_SIMPLE_DEV_PM_OPS()
- Correct the formula for lux to use 0.45 instead of 0.8

 drivers/iio/light/Kconfig    |  11 +
 drivers/iio/light/Makefile   |   1 +
 drivers/iio/light/ltrf216a.c | 423 +++++++++++++++++++++++++++++++++++
 3 files changed, 435 insertions(+)
 create mode 100644 drivers/iio/light/ltrf216a.c
drivers/iio/light/Kconfig +11 -0
index 8537e88f02e3..7cf6e8490123 100644
@@ -331,6 +331,17 @@ config LTR501
 	  This driver can also be built as a module.  If so, the module
 	  will be called ltr501.
 
+config LTRF216A
+	tristate "Liteon LTRF216A Light Sensor"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  If you say Y or M here, you get support for Liteon LTRF216A
+	  Ambient Light Sensor.
+
+	  If built as a dynamically linked module, it will be called
+	  ltrf216a.
+
 config LV0104CS
 	tristate "LV0104CS Ambient Light Sensor"
 	depends on I2C
drivers/iio/light/Makefile +1 -0
index d10912faf964..6f23817fae6f 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_ISL29125)		+= isl29125.o
 obj-$(CONFIG_JSA1212)		+= jsa1212.o
 obj-$(CONFIG_SENSORS_LM3533)	+= lm3533-als.o
 obj-$(CONFIG_LTR501)		+= ltr501.o
+obj-$(CONFIG_LTRF216A)		+= ltrf216a.o
 obj-$(CONFIG_LV0104CS)		+= lv0104cs.o
 obj-$(CONFIG_MAX44000)		+= max44000.o
 obj-$(CONFIG_MAX44009)		+= max44009.o
drivers/iio/light/ltrf216a.c new file +423 -0

423 lines not on this page · raw message

Signature · 1 line
2.30.2
#3 lore raw

Re: [PATCH v7 2/2] iio: light: Add support for ltrf216a sensor

Quoted 9 lines · Shreeya Patel

From: Zhigang Shi <[email protected]>

Add initial support for ltrf216a ambient light sensor.

Datasheet: https://gitlab.steamos.cloud/shreeya/iio/-/blob/main/LTRF216A.pdf

Submitter's SoB always has to be last among SoBs in the proposed change.
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#when-to-use-acked-by-cc-and-co-developed-by

...

drivers/iio/light/ltrf216a.c line 182

Quoted 13 lines
drivers/iio/light/ltrf216a.c new file +12 -0
+static int ltrf216a_set_power_state(struct ltrf216a_data *data, bool on)
+{
+       struct device *dev = &data->client->dev;
+       int ret;
+
+       if (on) {
+               ret = pm_runtime_resume_and_get(dev);
+               if (ret < 0) {
+                       dev_err(dev, "Failed to resume runtime PM: %d\n", ret);
+                       return ret;
+               }
 
+

Unneeded blank line.

Quoted 7 lines
drivers/iio/light/ltrf216a.c new file +7 -0
+       } else {
+               pm_runtime_mark_last_busy(dev);
+               ret = pm_runtime_put_autosuspend(dev);
+       }
+
+       return ret;
+}

...

drivers/iio/light/ltrf216a.c line 203

Quoted 7 lines
drivers/iio/light/ltrf216a.c new file +7 -0
+       ret = regmap_read_poll_timeout(data->regmap, LTRF216A_MAIN_STATUS,
+                                      val, val & LTRF216A_ALS_DATA_STATUS,
+                                      LTRF216A_ALS_READ_DATA_DELAY_US,
+                                      LTRF216A_ALS_READ_DATA_DELAY_US * 50);
+       if (ret) {
+               dev_err(dev, "Timed out waiting for valid data from LTRF216A_MAIN_STATUS reg: %d\n",
+                       ret);

THe message is a bit misleading. The loop might be broken by the I/O error.

Quoted 8 lines
drivers/iio/light/ltrf216a.c new file +8 -0
+               return ret;
+       }
+
+       ret = regmap_bulk_read(data->regmap, addr, buf, sizeof(buf));
+       if (ret < 0) {
+               dev_err(dev, "Error reading measurement data: %d\n", ret);
+               return ret;
+       }

...

drivers/iio/light/ltrf216a.c line 311

Quoted 5 lines
drivers/iio/light/ltrf216a.c new file +5 -0
+static const struct regmap_config ltrf216a_regmap_config = {
+       .name = LTRF216A_DRV_NAME,
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = LTRF216A_MAX_REG,

Why do you use regmap locking? What for?

Quoted 1 line

+};

...

drivers/iio/light/ltrf216a.c line 329

Quoted 4 lines
drivers/iio/light/ltrf216a.c new file +4 -0
+       data->regmap = devm_regmap_init_i2c(client, &ltrf216a_regmap_config);
+       if (IS_ERR(data->regmap)) {
+               dev_err(&client->dev, "Regmap initialization failed.\n");
+               return PTR_ERR(data->regmap);

return dev_err_probe(...);

Quoted 1 line

+ }

...

drivers/iio/light/ltrf216a.c line 349

Quoted 4 lines
drivers/iio/light/ltrf216a.c new file +4 -0
+       ret = devm_pm_runtime_enable(&client->dev);
+       if (ret < 0) {
+               dev_err_probe(&client->dev, ret, "Failed to enable runtime PM\n");
+               return ret;

Ditto.

Quoted 1 line

+ }

...

drivers/iio/light/ltrf216a.c line 358

Quoted 4 lines
drivers/iio/light/ltrf216a.c new file +4 -0
+               ret = ltrf216a_init(indio_dev);
+               if (ret) {
+                       dev_err_probe(&client->dev, ret, "Failed to enable the sensor\n");
+                       return ret;

Ditto.

Quoted 1 line

+ }

...

Quoted 1 line

+ if (ret < 0)

For all these ' < 0', please explain what positive return value means there, if any, and why it's being ignored.

...

drivers/iio/light/ltrf216a.c line 397

Quoted 2 lines
drivers/iio/light/ltrf216a.c new file +2 -0
+static const struct i2c_device_id ltrf216a_id[] = {
+       { LTRF216A_DRV_NAME, 0 },

Please, use the string literal directly since it's kinda an ABI, defining above for potential changes is not a good idea. Also you may drop the ', 0' part.

Quoted 2 lines
(quoted diff) +2 -0
+       {}
+};

...

drivers/iio/light/ltrf216a.c line 411

Quoted 4 lines
drivers/iio/light/ltrf216a.c new file +3 -0
+static struct i2c_driver ltrf216a_driver = {
+       .driver = {
 
+               .name = LTRF216A_DRV_NAME,

Ditto.

Quoted 6 lines
drivers/iio/light/ltrf216a.c new file +6 -0
+               .pm = pm_ptr(&ltrf216a_pm_ops),
+               .of_match_table = ltrf216a_of_match,
+       },
+       .probe_new      = ltrf216a_probe,
+       .id_table       = ltrf216a_id,
+};
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v7 2/2] iio: light: Add support for ltrf216a sensor

Quoted 56 lines · Andy Shevchenko
Quoted 8 lines · Shreeya Patel

From: Zhigang Shi <[email protected]>

Add initial support for ltrf216a ambient light sensor.

Datasheet: https://gitlab.steamos.cloud/shreeya/iio/-/blob/main/LTRF216A.pdf

Submitter's SoB always has to be last among SoBs in the proposed change.
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#when-to-use-acked-by-cc-and-co-developed-by

...

drivers/iio/light/ltrf216a.c line 182

Quoted 12 lines
drivers/iio/light/ltrf216a.c new file +12 -0
+static int ltrf216a_set_power_state(struct ltrf216a_data *data, bool on)
+{
+       struct device *dev = &data->client->dev;
+       int ret;
+
+       if (on) {
+               ret = pm_runtime_resume_and_get(dev);
+               if (ret < 0) {
+                       dev_err(dev, "Failed to resume runtime PM: %d\n", ret);
+                       return ret;
+               }
+

Unneeded blank line.

Quoted 7 lines
drivers/iio/light/ltrf216a.c new file +7 -0
+       } else {
+               pm_runtime_mark_last_busy(dev);
+               ret = pm_runtime_put_autosuspend(dev);
+       }
+
+       return ret;
+}

...

drivers/iio/light/ltrf216a.c line 203

Quoted 7 lines
drivers/iio/light/ltrf216a.c new file +7 -0
+       ret = regmap_read_poll_timeout(data->regmap, LTRF216A_MAIN_STATUS,
+                                      val, val & LTRF216A_ALS_DATA_STATUS,
+                                      LTRF216A_ALS_READ_DATA_DELAY_US,
+                                      LTRF216A_ALS_READ_DATA_DELAY_US * 50);
+       if (ret) {
+               dev_err(dev, "Timed out waiting for valid data from LTRF216A_MAIN_STATUS reg: %d\n",
+                       ret);

THe message is a bit misleading. The loop might be broken by the I/O error.

drivers/iio/light/ltrf216a.c line 211

Quoted 8 lines
drivers/iio/light/ltrf216a.c new file +8 -0
+               return ret;
+       }
+
+       ret = regmap_bulk_read(data->regmap, addr, buf, sizeof(buf));
+       if (ret < 0) {
+               dev_err(dev, "Error reading measurement data: %d\n", ret);
+               return ret;
+       }
Quoted 9 lines

...

drivers/iio/light/ltrf216a.c line 311

Quoted 5 lines
drivers/iio/light/ltrf216a.c new file +5 -0
+static const struct regmap_config ltrf216a_regmap_config = {
+       .name = LTRF216A_DRV_NAME,
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = LTRF216A_MAX_REG,

Why do you use regmap locking? What for?

Hi Andy,

Why do we want to skip the internal locking if it doesn't bring any benefits?

Quoted 57 lines
Quoted 1 line

+};

...

drivers/iio/light/ltrf216a.c line 329

Quoted 4 lines
drivers/iio/light/ltrf216a.c new file +4 -0
+       data->regmap = devm_regmap_init_i2c(client, &ltrf216a_regmap_config);
+       if (IS_ERR(data->regmap)) {
+               dev_err(&client->dev, "Regmap initialization failed.\n");
+               return PTR_ERR(data->regmap);

return dev_err_probe(...);

Quoted 1 line

+ }

...

drivers/iio/light/ltrf216a.c line 349

Quoted 4 lines
drivers/iio/light/ltrf216a.c new file +4 -0
+       ret = devm_pm_runtime_enable(&client->dev);
+       if (ret < 0) {
+               dev_err_probe(&client->dev, ret, "Failed to enable runtime PM\n");
+               return ret;

Ditto.

Quoted 1 line

+ }

...

drivers/iio/light/ltrf216a.c line 358

Quoted 4 lines
drivers/iio/light/ltrf216a.c new file +4 -0
+               ret = ltrf216a_init(indio_dev);
+               if (ret) {
+                       dev_err_probe(&client->dev, ret, "Failed to enable the sensor\n");
+                       return ret;

Ditto.

Quoted 1 line

+ }

...

Quoted 1 line

+ if (ret < 0)

For all these ' < 0', please explain what positive return value means there, if any, and why it's being ignored.

...

drivers/iio/light/ltrf216a.c line 397

Quoted 2 lines
drivers/iio/light/ltrf216a.c new file +2 -0
+static const struct i2c_device_id ltrf216a_id[] = {
+       { LTRF216A_DRV_NAME, 0 },

Please, use the string literal directly since it's kinda an ABI, defining above for potential changes is not a good idea. Also you may drop the ', 0' part.

Quoted 2 lines
(quoted diff) +2 -0
+       {}
+};

...

drivers/iio/light/ltrf216a.c line 411

Quoted 3 lines
drivers/iio/light/ltrf216a.c new file +3 -0
+static struct i2c_driver ltrf216a_driver = {
+       .driver = {
+               .name = LTRF216A_DRV_NAME,

Ditto.

Quoted 6 lines
drivers/iio/light/ltrf216a.c new file +6 -0
+               .pm = pm_ptr(&ltrf216a_pm_ops),
+               .of_match_table = ltrf216a_of_match,
+       },
+       .probe_new      = ltrf216a_probe,
+       .id_table       = ltrf216a_id,
+};
#5 lore raw

Re: [PATCH v7 2/2] iio: light: Add support for ltrf216a sensor

Quoted 2 lines · Shreeya Patel
Quoted 1 line · Andy Shevchenko

On Mon, Jul 11, 2022 at 1:30 PM Shreeya Patel

Please, remove unneeded context when replying!

...

Quoted 9 lines
Quoted 6 lines

drivers/iio/light/ltrf216a.c line 311

Quoted 5 lines
drivers/iio/light/ltrf216a.c new file +5 -0
+static const struct regmap_config ltrf216a_regmap_config = {
+       .name = LTRF216A_DRV_NAME,
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = LTRF216A_MAX_REG,

Why do you use regmap locking? What for?

Why do we want to skip the internal locking if it doesn't bring any benefits?

Can you elaborate on the "no benefits" part, please?

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

Re: [PATCH v7 2/2] iio: light: Add support for ltrf216a sensor

Quoted 14 lines · Andy Shevchenko
Quoted 2 lines · Shreeya Patel
Quoted 1 line · Andy Shevchenko

On Mon, Jul 11, 2022 at 1:30 PM Shreeya Patel

Please, remove unneeded context when replying!

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/iio/light/ltrf216a.c new file +5 -0
+static const struct regmap_config ltrf216a_regmap_config = {
+       .name = LTRF216A_DRV_NAME,
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = LTRF216A_MAX_REG,
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Why do you use regmap locking? What for?

Why do we want to skip the internal locking if it doesn't bring any benefits?

Can you elaborate on the "no benefits" part, please?

Since the regmap's lock will never be contended, thus it's free to keep using it. If later on we will need to change the driver's code such that the lock will become needed, then we won't need to bother with re-enabling it. The comment to the driver's mutex states clearly that it's intended to protect the cached value.

Hence what is point in disabling the regmap's lock? There are very few drivers that disable the regmap's lock and most of them do that for the good reason.

Signature · 2 lines
Best regards,
Dmitry
#7 lore raw

Re: [PATCH v7 2/2] iio: light: Add support for ltrf216a sensor

Quoted 5 lines · Dmitry Osipenko
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Shreeya Patel
Quoted 1 line · Andy Shevchenko

On Mon, Jul 11, 2022 at 1:30 PM Shreeya Patel

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/iio/light/ltrf216a.c new file +5 -0
+static const struct regmap_config ltrf216a_regmap_config = {
+       .name = LTRF216A_DRV_NAME,
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = LTRF216A_MAX_REG,
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Why do you use regmap locking? What for?

Why do we want to skip the internal locking if it doesn't bring any benefits?

Can you elaborate on the "no benefits" part, please?

Since the regmap's lock will never be contended, thus it's free to keep

I'm skeptical about "free" here. My concerns are:
1) grosser code base;
2) slower code flow (even nop takes time to process).

Quoted 8 lines

using it. If later on we will need to change the driver's code such that the lock will become needed, then we won't need to bother with re-enabling it. The comment to the driver's mutex states clearly that it's intended to protect the cached value.

Hence what is point in disabling the regmap's lock? There are very few drivers that disable the regmap's lock and most of them do that for the good reason.

Most of the drivers that have its own lock _and_ regmap lock took the locking scheme wrong. It is 101 when writing a driver to have a clear picture of what lock protects what data (or I/O).

Even if lock is _almost_ free, it's still required to provide understanding of how each of the locks is being used in the code.

That said, the main point of my review comment is to make the author think about it, or just elaborate if it has been thought through already.

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

Re: [PATCH v7 2/2] iio: light: Add support for ltrf216a sensor

Quoted 41 lines · Andy Shevchenko
Quoted 5 lines · Dmitry Osipenko
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Shreeya Patel
Quoted 1 line · Andy Shevchenko

On Mon, Jul 11, 2022 at 1:30 PM Shreeya Patel

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/iio/light/ltrf216a.c new file +5 -0
+static const struct regmap_config ltrf216a_regmap_config = {
+       .name = LTRF216A_DRV_NAME,
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = LTRF216A_MAX_REG,
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Why do you use regmap locking? What for?

Why do we want to skip the internal locking if it doesn't bring any benefits?

Can you elaborate on the "no benefits" part, please?

Since the regmap's lock will never be contended, thus it's free to keep

I'm skeptical about "free" here. My concerns are:
1) grosser code base;
2) slower code flow (even nop takes time to process).

Quoted 8 lines

using it. If later on we will need to change the driver's code such that the lock will become needed, then we won't need to bother with re-enabling it. The comment to the driver's mutex states clearly that it's intended to protect the cached value.

Hence what is point in disabling the regmap's lock? There are very few drivers that disable the regmap's lock and most of them do that for the good reason.

Most of the drivers that have its own lock _and_ regmap lock took the locking scheme wrong. It is 101 when writing a driver to have a clear picture of what lock protects what data (or I/O).

Quoted 6 lines

Even if lock is _almost_ free, it's still required to provide understanding of how each of the locks is being used in the code.

That said, the main point of my review comment is to make the author think about it, or just elaborate if it has been thought through already.

Alright, thank you for clarifying yours point! I helped Shreeya a tad with preparing the v7 and disabling the regmap's lock wasn't under question. Since this driver isn't about performance and a nanosecond improvement isn't worthwhile in comparison to the the I2C transfer time, should be cleaner to keep the regmap's lock in place, IMO. I'll let Shreeya to answer next time, sorry for jumping in.

Signature · 2 lines
Best regards,
Dmitry