Support for Avago APDS9306 Ambient Light Sensor
Subhajit Ghosh
maintainerv6 cover Support for Avago APDS9306 Ambient Light Sensor
Support for Avago APDS9306 Ambient Light Sensor.
Driver support for Avago (Broadcom) APDS9306 Ambient Light Sensor. It has two channels - ALS and CLEAR. The ALS (Ambient Light Sensor) channel approximates the response of the human-eye providing direct read out where the output count is proportional to ambient light levels. It is internally temperature compensated and rejects 50Hz and 60Hz flicker caused by artificial light sources. Hardware interrupt configuration is optional. It is a low power device with 20 bit resolution and has configurable adaptive interrupt mode and interrupt persistence mode. The device also features inbuilt hardware gain, multiple integration time selection options and sampling frequency selection options.
This driver also uses the IIO GTS (Gain Time Scale) Helpers Namespace for Scales, Gains and Integration time implementation.
1 directory, 18 files
v5 -> v6:
- Changes as per review
- Update kernel doc for private data
- Change IIO Event Spec definitions
- Update guard mutex lock implementation
- Add pm_runtime_get()
- Update styling
v5 -> v6 Bindings
- Write proper commit messages
- Add vdd-supply in a separate commit
- Add Interrupt macro in a separate commit
v2 -> v5:
- Bumped up the version:
RFC->v0->v1->v2->v3 (Earlier scheme) v1->v2->v3->v4->v5 (Scheme after review) (Current scheme)
- Added separate patch to merge schemas for APDS9300 and APDS9906. Added APDS9306 support on top of that.
- Removed scale attribute for Intensity channel:
- Dropped caching of hardware gain, repeat rate and integration time and updated code as per earlier reviews.
- Added descriptive commit messages
- Fixed wrongly formatted commit messages
- Added changelog in right positions
- Link to v2:
https://lore.kernel.org/lkml/[email protected]/
v2 -> v5 Bindings:
- Removed 'required' for Interrupts and 'oneOf' for compatibility strings as per below reviews:
- Implemented changes as per previous reviews:
Subhajit Ghosh (5):
dt-bindings: iio: light: Merge APDS9300 and APDS9960 schemas
dt-bindings: iio: light: adps9300: Add property vdd-supply
dt-bindings: iio: light: adps9300: Update interrupt definitions
dt-bindings: iio: light: Avago APDS9306
iio: light: Add support for APDS9306 Light Sensor
.../bindings/iio/light/avago,apds9300.yaml | 20 +- .../bindings/iio/light/avago,apds9960.yaml | 44 - drivers/iio/light/Kconfig | 12 + drivers/iio/light/Makefile | 1 + drivers/iio/light/apds9306.c | 1335 +++++++++++++++++ 5 files changed, 1363 insertions(+), 49 deletions(-) delete mode 100644 Documentation/devicetree/bindings/iio/light/avago,apds9960.yaml create mode 100644 drivers/iio/light/apds9306.c
base-commit: b555d191561a7f89b8d2108dff687d9bc4284e48
Signature · 1 line
2.34.1
Subhajit Ghosh
maintainerPATCH v6 1/5 dt-bindings: iio: light: Merge APDS9300 and APDS9960 schemas
Merge very similar schemas for APDS9300 and APDS9960.
---
v5 -> v6:
- Write proper commit messages
v2 -> v5:
- Removed 'required' for Interrupts and 'oneOf' for compatibility strings as per below reviews:
--- .../bindings/iio/light/avago,apds9300.yaml | 11 +++-- .../bindings/iio/light/avago,apds9960.yaml | 44 ------------------- 2 files changed, 7 insertions(+), 48 deletions(-) delete mode 100644 Documentation/devicetree/bindings/iio/light/avago,apds9960.yaml
Documentation/devicetree/bindings/iio/light/avago,apds9300.yaml +7 -4
@@ -4,17 +4,20 @@ $id: http://devicetree.org/schemas/iio/light/avago,apds9300.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Avago APDS9300 ambient light sensor +title: Avago Gesture/RGB/ALS/Proximity sensors maintainers: - - Jonathan Cameron <[email protected]> + - Subhajit Ghosh <[email protected]> description: | - Datasheet at https://www.avagotech.com/docs/AV02-1077EN + Datasheet: https://www.avagotech.com/docs/AV02-1077EN + Datasheet: https://www.avagotech.com/docs/AV02-4191EN properties: compatible: - const: avago,apds9300 + enum: + - avago,apds9300 + - avago,apds9960 reg: maxItems: 1
Documentation/devicetree/bindings/iio/light/avago,apds9960.yaml deleted +0 -44
44 lines not on this page · raw message
Signature · 1 line
2.34.1
Subhajit Ghosh
maintainerPATCH v6 2/5 dt-bindings: iio: light: adps9300: Add property vdd-supply
In reply to Subhajit GhoshAdd vdd-supply property which is valid and useful for all the devices in this schema.
this patch depends on patch:
"dt-bindings: iio: light: Merge APDS9300 and APDS9960 schemas"
---
v5 -> v6:
- Separate commit for individual change as per below review:
--- .../devicetree/bindings/iio/light/avago,apds9300.yaml | 3 +++ 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/iio/light/avago,apds9300.yaml +3 -0
@@ -25,6 +25,8 @@ properties: interrupts: maxItems: 1 + vdd-supply: true + additionalProperties: false required:
@@ -42,6 +44,7 @@ examples: reg = <0x39>; interrupt-parent = <&gpio2>; interrupts = <29 8>; + vdd-supply = <®ulator_3v3>; }; }; ...
Signature · 1 line
2.34.1
Re: [PATCH v6 2/5] dt-bindings: iio: light: adps9300: Add property vdd-supply
Quoted 2 lines · Subhajit Ghosh
Add vdd-supply property which is valid and useful for all the devices in this schema.
Why is it useful? How is it useful? DT describes the hardware, not because something is "useful".
Quoted 3 lines
this patch depends on patch:
"dt-bindings: iio: light: Merge APDS9300 and APDS9960 schemas"
This is unrelated and does not make any sense in commit msg. Drop.
Best regards,
Krzysztof
Subhajit Ghosh
maintainerRe: [PATCH v6 2/5] dt-bindings: iio: light: adps9300: Add property vdd-supply
Hi Krzysztof,
Quoted 6 lines · Krzysztof Kozlowski
Quoted 2 lines · Subhajit Ghosh
Add vdd-supply property which is valid and useful for all the devices in this schema.
Why is it useful? How is it useful? DT describes the hardware, not because something is "useful".
I am adding this property based on a previous review:
https://lore.kernel.org/all/20240121153655.5f734180@jic23-huawei/
Does the below commit message in this context make sense to you? "Add vdd-supply property for all the devices in this schema."
Quoted 6 lines
Quoted 4 lines
this patch depends on patch:
"dt-bindings: iio: light: Merge APDS9300 and APDS9960 schemas"This is unrelated and does not make any sense in commit msg. Drop.
Apologies for the silly questions:
What does the "Drop" signify? Are you asking me to drop/delete the above "...patch depends..." message or does it have any other meaning?
In the next version, do I include the ack tag by Conor for this commit?
Quoted 5 lines
Best regards,
Krzysztof
Thank you for reviewing.
Regards,
Subhajit Ghosh
Re: [PATCH v6 2/5] dt-bindings: iio: light: adps9300: Add property vdd-supply
Quoted 11 lines · Subhajit Ghosh
Hi Krzysztof,
Quoted 6 lines · Krzysztof Kozlowski
Quoted 2 lines · Subhajit Ghosh
Add vdd-supply property which is valid and useful for all the devices in this schema.
Why is it useful? How is it useful? DT describes the hardware, not because something is "useful".
I am adding this property based on a previous review:
https://lore.kernel.org/all/20240121153655.5f734180@jic23-huawei/
The property was there already.
Quoted 3 lines
Does the below commit message in this context make sense to you? "Add vdd-supply property for all the devices in this schema."
It's still poor. You should say why, e.g. because devices have it.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
this patch depends on patch:
"dt-bindings: iio: light: Merge APDS9300 and APDS9960 schemas"This is unrelated and does not make any sense in commit msg. Drop.
Apologies for the silly questions:
What does the "Drop" signify? Are you asking me to drop/delete the above "...patch depends..." message or does it have any other meaning?
Drop entire paragraph.
Best regards,
Krzysztof
Jonathan Cameron
maintainerRe: [PATCH v6 2/5] dt-bindings: iio: light: adps9300: Add property vdd-supply
Quoted 13 lines · On Fri, 9 Feb 2024 08:33:11 +0100 Krzysztof Kozlowski…
Quoted 11 lines · Subhajit Ghosh
Hi Krzysztof,
Quoted 6 lines · Krzysztof Kozlowski
Quoted 2 lines · Subhajit Ghosh
Add vdd-supply property which is valid and useful for all the devices in this schema.
Why is it useful? How is it useful? DT describes the hardware, not because something is "useful".
I am adding this property based on a previous review:
https://lore.kernel.org/all/20240121153655.5f734180@jic23-huawei/
Quoted 7 lines
The property was there already.
Quoted 3 lines
Does the below commit message in this context make sense to you? "Add vdd-supply property for all the devices in this schema."
It's still poor. You should say why, e.g. because devices have it.
I'd change the patch title to:
dt-bindings: iio: light: adps9300: Add missing vdd-supply
For description something simple like:
All devices covered by the binding have a vdd supply.
Quoted 17 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
this patch depends on patch:
"dt-bindings: iio: light: Merge APDS9300 and APDS9960 schemas"This is unrelated and does not make any sense in commit msg. Drop.
Apologies for the silly questions:
What does the "Drop" signify? Are you asking me to drop/delete the above "...patch depends..." message or does it have any other meaning?Drop entire paragraph.
Best regards,
Krzysztof
Subhajit Ghosh
maintainerPATCH v6 3/5 dt-bindings: iio: light: adps9300: Update interrupt definitions
In reply to Subhajit GhoshInclude irq.h and irq level macro in the example for readability
this patch depends on patch:
"dt-bindings: iio: light: Add property vdd-supply"
---
v5 -> v6:
- Separate commit for individual change as per below review:
--- .../devicetree/bindings/iio/light/avago,apds9300.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/iio/light/avago,apds9300.yaml +3 -1
@@ -35,6 +35,8 @@ required: examples: - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { #address-cells = <1>; #size-cells = <0>;
@@ -43,7 +45,7 @@ examples: compatible = "avago,apds9300"; reg = <0x39>; interrupt-parent = <&gpio2>; - interrupts = <29 8>; + interrupts = <29 IRQ_TYPE_LEVEL_LOW>; vdd-supply = <®ulator_3v3>; }; };
Signature · 1 line
2.34.1
Re: [PATCH v6 3/5] dt-bindings: iio: light: adps9300: Update interrupt definitions
Quoted 4 lines · Subhajit Ghosh
Include
irq.hand irq level macro in the example for readabilitythis patch depends on patch:
"dt-bindings: iio: light: Add property vdd-supply"
Please, don't write such useless dependencies. This is neither true nor useful.
Best regards,
Krzysztof
Subhajit Ghosh
maintainerRe: [PATCH v6 3/5] dt-bindings: iio: light: adps9300: Update interrupt definitions
Quoted 8 lines · Krzysztof Kozlowski
Quoted 4 lines · Subhajit Ghosh
Include
irq.hand irq level macro in the example for readabilitythis patch depends on patch:
"dt-bindings: iio: light: Add property vdd-supply"Please, don't write such useless dependencies. This is neither true nor useful.
Understood.
Quoted 5 lines
Best regards,
Krzysztof
Thank you for reviewing.
Regards,
Subhajit Ghosh
Jonathan Cameron
maintainerRe: [PATCH v6 3/5] dt-bindings: iio: light: adps9300: Update interrupt definitions
Quoted 10 lines · On Thu, 8 Feb 2024 21:23:09 +1030 Subhajit Ghosh…
Quoted 8 lines · Krzysztof Kozlowski
Quoted 4 lines · Subhajit Ghosh
Include
irq.hand irq level macro in the example for readabilitythis patch depends on patch:
"dt-bindings: iio: light: Add property vdd-supply"Please, don't write such useless dependencies. This is neither true nor useful.
Understood.
Just for reference:
If there were such a dependency (beyond noise in the diff) then there is still no need to state it when the patches are in the same series.
Jonathan
Quoted 9 lines
Quoted 5 lines
Best regards,
KrzysztofThank you for reviewing.
Regards,
Subhajit Ghosh
Subhajit Ghosh
maintainerPATCH v6 4/5 dt-bindings: iio: light: Avago APDS9306
In reply to Subhajit GhoshDriver support for Avago (Broadcom) APDS9306 Ambient Light Sensor. Extend avago,apds9300.yaml schema file to support apds9306 device.
this patch depends on patch:
"dt-bindings: iio: light: adps9300: Update interrupt definitions"
---
v5 -> v6:
- Write proper commit messages
- Add vdd-supply in a separate commit
- Add Interrupt macro in a separate commit
v2 -> v5:
- Removed 'required' for Interrupts and 'oneOf' for compatibility strings as per below reviews:
--- Documentation/devicetree/bindings/iio/light/avago,apds9300.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/iio/light/avago,apds9300.yaml +2 -0
@@ -12,11 +12,13 @@ maintainers: description: | Datasheet: https://www.avagotech.com/docs/AV02-1077EN Datasheet: https://www.avagotech.com/docs/AV02-4191EN + Datasheet: https://www.avagotech.com/docs/AV02-4755EN properties: compatible: enum: - avago,apds9300 + - avago,apds9306 - avago,apds9960 reg:
Signature · 1 line
2.34.1
Re: [PATCH v6 4/5] dt-bindings: iio: light: Avago APDS9306
Quoted 5 lines · Subhajit Ghosh
Driver support for Avago (Broadcom) APDS9306 Ambient Light Sensor. Extend avago,apds9300.yaml schema file to support apds9306 device.
this patch depends on patch:
"dt-bindings: iio: light: adps9300: Update interrupt definitions"
Drop the paragraph, not helping. There is no dependency here.
Best regards,
Krzysztof
Subhajit Ghosh
maintainerRe: [PATCH v6 4/5] dt-bindings: iio: light: Avago APDS9306
Hi Krzysztof,
Quoted 8 lines · Krzysztof Kozlowski
Quoted 5 lines · Subhajit Ghosh
Driver support for Avago (Broadcom) APDS9306 Ambient Light Sensor. Extend avago,apds9300.yaml schema file to support apds9306 device.
this patch depends on patch:
"dt-bindings: iio: light: adps9300: Update interrupt definitions"Drop the paragraph, not helping. There is no dependency here.
In the submitting patches guide, I read that if one patch depends on another, it should be mentioned.
If I try to apply this patch with "git am", it fails without first applying the patch dependency mentioned above. Is that fine? Again, sorry about the silly questions, just don't want to assume stuff!
Quoted 4 lines
Best regards,
Krzysztof
Thank you for reviewing.
Regards,
Subhajit Ghosh
Re: [PATCH v6 4/5] dt-bindings: iio: light: Avago APDS9306
Quoted 10 lines · Subhajit Ghosh
Hi Krzysztof,
Quoted 7 lines · Krzysztof Kozlowski
Quoted 5 lines · Subhajit Ghosh
Driver support for Avago (Broadcom) APDS9306 Ambient Light Sensor. Extend avago,apds9300.yaml schema file to support apds9306 device.
this patch depends on patch:
"dt-bindings: iio: light: adps9300: Update interrupt definitions"
Quoted 6 lines
Quoted 1 line
Drop the paragraph, not helping. There is no dependency here.
In the submitting patches guide, I read that if one patch depends on another, it should be mentioned.
If I try to apply this patch with "git am", it fails without first applying the patch dependency mentioned above. Is that fine? Again, sorry about the silly questions, just don't want to assume stuff!
It's another patch in the same series, I don't think you should bother mentioning this at all. If there's a dependency on another series, then you should mention it under the --- line.
Cheers,
Conor.
Re: [PATCH v6 4/5] dt-bindings: iio: light: Avago APDS9306
In reply to Subhajit GhoshQuoted 7 lines · Subhajit Ghosh
Hi Krzysztof,
Quoted 4 lines · Krzysztof Kozlowski
Quoted 3 lines · Subhajit Ghosh
Driver support for Avago (Broadcom) APDS9306 Ambient Light Sensor. Extend avago,apds9300.yaml schema file to support apds9306 device.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
this patch depends on patch:
"dt-bindings: iio: light: adps9300: Update interrupt definitions"Drop the paragraph, not helping. There is no dependency here.
In the submitting patches guide, I read that if one patch depends on another, it should be mentioned.
On another patchset! Not on other patch within patchset. Anyway, submitting patches don't tell to store it in Git forever because it does not make sense.
Third, there is no dependency.
Quoted 2 lines
If I try to apply this patch with "git am", it fails without first applying the patch dependency mentioned above. Is that fine?
It's just context.
Best regards,
Krzysztof
Subhajit Ghosh
maintainerPATCH v6 5/5 iio: light: Add support for APDS9306 Light Sensor
In reply to Subhajit GhoshDriver support for Avago (Broadcom) APDS9306 Ambient Light Sensor. It has two channels - ALS and CLEAR. The ALS (Ambient Light Sensor) channel approximates the response of the human-eye providing direct read out where the output count is proportional to ambient light levels. It is internally temperature compensated and rejects 50Hz and 60Hz flicker caused by artificial light sources. Hardware interrupt configuration is optional. It is a low power device with 20 bit resolution and has configurable adaptive interrupt mode and interrupt persistence mode. The device also features inbuilt hardware gain, multiple integration time selection options and sampling frequency selection options.
This driver also uses the IIO GTS (Gain Time Scale) Helpers Namespace for Scales, Gains and Integration time implementation.
---
v5 -> v6:
- Changes as per review
- Update kernel doc for private data
- Change IIO Event Spec definitions
- Update guard mutex lock implementation
- Add pm_runtime_get()
- Update styling
v2 -> v5:
- Removed scale attribute for Intensity channel:
- Dropped caching of hardware gain, repeat rate and integration time and updated code as per earlier reviews.
--- drivers/iio/light/Kconfig | 12 + drivers/iio/light/Makefile | 1 + drivers/iio/light/apds9306.c | 1335 ++++++++++++++++++++++++++++++++++ 3 files changed, 1348 insertions(+) create mode 100644 drivers/iio/light/apds9306.c
drivers/iio/light/Kconfig +12 -0
@@ -73,6 +73,18 @@ config APDS9300 To compile this driver as a module, choose M here: the module will be called apds9300. +config APDS9306 + tristate "Avago APDS9306 Ambient Light Sensor" + depends on I2C + select REGMAP_I2C + select IIO_GTS_HELPER + help + If you say Y or M here, you get support for Avago APDS9306 + Ambient Light Sensor. + + If built as a dynamically linked module, it will be called + apds9306. + config APDS9960 tristate "Avago APDS9960 gesture/RGB/ALS/proximity sensor" select REGMAP_I2C
drivers/iio/light/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_ADUX1020) += adux1020.o obj-$(CONFIG_AL3010) += al3010.o obj-$(CONFIG_AL3320A) += al3320a.o obj-$(CONFIG_APDS9300) += apds9300.o +obj-$(CONFIG_APDS9306) += apds9306.o obj-$(CONFIG_APDS9960) += apds9960.o obj-$(CONFIG_AS73211) += as73211.o obj-$(CONFIG_BH1750) += bh1750.o
drivers/iio/light/apds9306.c new file +1335 -0
1,335 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v6 5/5] iio: light: Add support for APDS9306 Light Sensor
Quoted 13 lines · Subhajit Ghosh
Driver support for Avago (Broadcom) APDS9306 Ambient Light Sensor. It has two channels - ALS and CLEAR. The ALS (Ambient Light Sensor) channel approximates the response of the human-eye providing direct read out where the output count is proportional to ambient light levels. It is internally temperature compensated and rejects 50Hz and 60Hz flicker caused by artificial light sources. Hardware interrupt configuration is optional. It is a low power device with 20 bit resolution and has configurable adaptive interrupt mode and interrupt persistence mode. The device also features inbuilt hardware gain, multiple integration time selection options and sampling frequency selection options.
This driver also uses the IIO GTS (Gain Time Scale) Helpers Namespace for Scales, Gains and Integration time implementation.
...
Quoted 1 line
+#define
APDS9306_ALS_READ_DATA_DELAY_US20000
(20 * USEC_PER_MSEC) ?
...
Quoted 1 line
+/*
Make it real kernel doc?
Quoted 5 lines
+ * struct
part_id_gts_multiplier- Part no. and corresponding gts multiplier
+ *
+ * GTS (Gain Time Scale) are helper functions for Light sensors which along
+ * with hardware gains also has gains associated with Integration times.
+ *
Quoted 8 lines
+ * There are two variants of the device with slightly different characteristics,
+ * they have same ADC count for different Lux levels as mentioned in the
+ * datasheet. This multiplier array is used to store the derived Lux per count
+ * value for the two variants to be used by the GTS helper functions.
+ *
+ *part_id: Part ID of the device
+ *max_scale_int: Multiplier foriio_init_iio_gts()
+ *max_scale_nano: Multiplier foriio_init_iio_gts()
(It will be wrong format for referring fields, but easy to fix.)
Quoted 1 line
+ */
...
Review
Quoted 2 lines
(quoted diff) +2
-0+static_assert(ARRAY_SIZE(apds9306_repeat_rate_freq) == + APDS9306_NUM_REPEAT_RATES);
Just make that define to be inside [] in the respective array and drop this static assert. The assertion might make sense to have different arrays to be synchronized and when their maximums are different due to semantics (not your case AFAICS).
...
drivers/iio/light/apds9306.c line 135
Quoted 2 lines
drivers/iio/light/apds9306.c new file +2
-0+static_assert (ARRAY_SIZE (apds9306_repeat_rate_period) == +APDS9306_NUM_REPEAT_RATES );
Ditto.
...
drivers/iio/light/apds9306.c line 164
Quoted 1 line
drivers/iio/light/apds9306.c new file +1
-0+struct mutex mutex;
checkpatch probably wants this to have a comment.
...
drivers/iio/light/apds9306.c line 176
Quoted 10 lines
drivers/iio/light/apds9306.c new file +10
-0+struct regmap_field *regfield_sw_reset; +struct regmap_field *regfield_en; +struct regmap_field *regfield_intg_time; +struct regmap_field *regfield_repeat_rate; +struct regmap_field *regfield_gain; +struct regmap_field *regfield_int_src; +struct regmap_field *regfield_int_thresh_var_en; +struct regmap_field *regfield_int_en; +struct regmap_field *regfield_int_persist_val; +struct regmap_field *regfield_int_thresh_var_val;
May we reduce the names by
struct {
...
struct regmap_field *int_persist_val;
struct regmap_field *int_thresh_var_val;
} regfield;In the code
struct regfield *rf = &priv->regfield; rf->int...
...
Quoted 9 lines
drivers/iio/light/apds9306.c new file +9
-0+static struct attribute *apds9306_event_attributes[] = { + &iio_const_attr_thresh_either_period_available.dev_attr.attr, + &iio_const_attr_thresh_adaptive_either_values_available.dev_attr.attr, +NULL +}; + +static const struct attribute_group apds9306_event_attr_group = { + .attrs = apds9306_event_attributes, +};
...
Quoted 8 lines
drivers/iio/light/apds9306.c new file +8
-0+static int apds9306_runtime_power_on (struct device *dev) +{ +int ret; + + ret =pm_runtime_resume_and_get (dev); +if (ret <0 ) +dev_err_ratelimited (dev,"runtime resume failed: %d\n" , ret); +
drivers/iio/light/apds9306.c line 477
Quoted 10 lines
drivers/iio/light/apds9306.c new file +10
-0+return ret; +} + +static int apds9306_runtime_power_off (struct device *dev) +{ +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); + +return 0 ; +}
Seems to me like useless wrappers. Why do you need that message? Btw, it's used only twice, open coding saves the LoCs! Try making the next submission so the driver LoCs is < 1400.
...
drivers/iio/light/apds9306.c line 524
Quoted 3 lines
drivers/iio/light/apds9306.c new file +3
-0+ ret = regmap_read_poll_timeout(data->regmap, APDS9306_MAIN_STATUS_REG, + status, (status & (APDS9306_ALS_DATA_STAT_MASK | + APDS9306_ALS_INT_STAT_MASK)) ||
Oh, this is interesting indentation...
drivers/iio/light/apds9306.c line 526
Quoted 2 lines
drivers/iio/light/apds9306.c new file +2
-0+ data->read_data_available, + APDS9306_ALS_READ_DATA_DELAY_US, delay * 2);
Can we write it as
ret = regmap_read_poll_timeout(data->regmap, APDS9306_MAIN_STATUS_REG, status, data->read_data_available || (status & (APDS9306_ALS_DATA_STAT_MASK | APDS9306_ALS_INT_STAT_MASK)), APDS9306_ALS_READ_DATA_DELAY_US, delay * 2);
?
Quoted 2 lines
(quoted diff) +2
-0+ if (ret) + return ret;
...
drivers/iio/light/apds9306.c line 1004
Quoted 6 lines
drivers/iio/light/apds9306.c new file +5
-0+switch (type) { +case IIO_EV_TYPE_THRESH : +if (dir ==IIO_EV_DIR_EITHER && info ==IIO_EV_INFO_PERIOD ) +return apds9306_event_period_set (data, val); +else
Redundant 'else'.
Quoted 6 lines
drivers/iio/light/apds9306.c new file +6
-0+return apds9306_event_thresh_set (data, dir, val); +case IIO_EV_TYPE_THRESH_ADAPTIVE : +return apds9306_event_thresh_adaptive_set (data, val); +default : +return -EINVAL ; + }
...
drivers/iio/light/apds9306.c line 1036
Quoted 3 lines
drivers/iio/light/apds9306.c new file +3
-0+if (chan->type ==IIO_LIGHT ) +return int_en & event_ch_is_light; +else if (chan->type ==IIO_INTENSITY )
Ditto.
Quoted 1 line
drivers/iio/light/apds9306.c new file +1
-0+return int_en & !event_ch_is_light;
...
drivers/iio/light/apds9306.c line 1103
Quoted 4 lines
drivers/iio/light/apds9306.c new file +3
-0+case IIO_EV_TYPE_THRESH_ADAPTIVE : +return regmap_field_write (data->regfield_int_thresh_var_en, + state);
One line?
...
drivers/iio/light/apds9306.c line 1137
Quoted 10 lines
drivers/iio/light/apds9306.c new file +10
-0+static int apds9306_init_iio_gts (struct apds9306_data *data) +{ +int i, ret, part_id; + + ret =regmap_read (data->regmap,APDS9306_PART_ID_REG , &part_id); +if (ret) +return ret; + +for (i =0 ; i <ARRAY_SIZE (apds9306_gts_mul); i++) { +if (part_id == apds9306_gts_mul[i].part_id)
break; } if (i == ARRAY_SIZE(...)) return -...; return devm_iio_init_iio_gts(data->dev, apds9306_gts_mul[i].max_scale_int, apds9306_gts_mul[i].max_scale_nano, apds9306_gains, ARRAY_SIZE(apds9306_gains), apds9306_itimes, ARRAY_SIZE(apds9306_itimes), &data->gts);
?
Quoted 10 lines
drivers/iio/light/apds9306.c new file +10
-0+return devm_iio_init_iio_gts (data->dev, + apds9306_gts_mul[i].max_scale_int, + apds9306_gts_mul[i].max_scale_nano, + apds9306_gains,ARRAY_SIZE (apds9306_gains), + apds9306_itimes,ARRAY_SIZE (apds9306_itimes), + &data->gts); + } + +return -ENXIO ; +}
...
drivers/iio/light/apds9306.c line 1248
Quoted 2 lines
drivers/iio/light/apds9306.c new file +2
-0+return dev_err_probe (dev, ret, +"regfield initialization failed\n" );
One line.
...
drivers/iio/light/apds9306.c line 1260
Quoted 2 lines
drivers/iio/light/apds9306.c new file +2
-0+ indio_dev->num_channels = +ARRAY_SIZE (apds9306_channels_with_events);
Ditto.
...
drivers/iio/light/apds9306.c line 1263
Quoted 3 lines
drivers/iio/light/apds9306.c new file +3
-0+ ret =devm_request_threaded_irq (dev, client->irq,NULL , + apds9306_irq_handler,IRQF_ONESHOT , +"apds9306_event" , indio_dev);
Fix indentation.
drivers/iio/light/apds9306.c line 1266
Quoted 4 lines
drivers/iio/light/apds9306.c new file +3
-0+if (ret) +return dev_err_probe (dev, ret, +"failed to assign interrupt.\n" );
One line.
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ return dev_err_probe(dev, ret, + "failed to add action or reset\n");
Ditto.
drivers/iio/light/apds9306.c line 1290
Quoted 3 lines
drivers/iio/light/apds9306.c new file +3
-0+if (ret) +return dev_err_probe (dev, ret, +"failed iio device registration\n" );
Ditto.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Subhajit Ghosh
maintainerRe: [PATCH v6 5/5] iio: light: Add support for APDS9306 Light Sensor
Hi Andy,
Quoted 12 lines
Quoted 1 line
+ */
...
Review
Quoted 2 lines
(quoted diff) +2
-0+static_assert(ARRAY_SIZE(apds9306_repeat_rate_freq) == + APDS9306_NUM_REPEAT_RATES);Just make that define to be inside [] in the respective array and drop this static assert. The assertion might make sense to have different arrays to be synchronized and when their maximums are different due to semantics (not your case AFAICS).
Quoted 8 lines
...
drivers/iio/light/apds9306.c line 135
Quoted 2 lines
drivers/iio/light/apds9306.c new file +2
-0+static_assert (ARRAY_SIZE (apds9306_repeat_rate_period) == +APDS9306_NUM_REPEAT_RATES );Ditto.
...
I apologize for this. You pointed me out in an earlier review, I misunderstood it and used the macro in two static asserts! It will be fixed.
Quoted 4 lines
drivers/iio/light/apds9306.c line 164
Quoted 2 lines
drivers/iio/light/apds9306.c new file +1
-0+struct mutex mutex;checkpatch probably wants this to have a comment.
I used the mainline checkpatch, it did not through any explicit warnings or errors regarding this.
As per previous review pointed below, I removed the the comment from here to kernel doc:
https://lore.kernel.org/all/20240121152332.6b15666a@jic23-huawei/
Do you still want me to add a comment before struct mutex?
Quoted 54 lines
...
drivers/iio/light/apds9306.c line 176
Quoted 10 lines
drivers/iio/light/apds9306.c new file +10
-0+struct regmap_field *regfield_sw_reset; +struct regmap_field *regfield_en; +struct regmap_field *regfield_intg_time; +struct regmap_field *regfield_repeat_rate; +struct regmap_field *regfield_gain; +struct regmap_field *regfield_int_src; +struct regmap_field *regfield_int_thresh_var_en; +struct regmap_field *regfield_int_en; +struct regmap_field *regfield_int_persist_val; +struct regmap_field *regfield_int_thresh_var_val;May we reduce the names by
struct { ... struct regmap_field *int_persist_val; struct regmap_field *int_thresh_var_val; } regfield;In the code
struct regfield *rf = &priv->regfield; rf->int......
Quoted 9 lines
drivers/iio/light/apds9306.c new file +9
-0+static struct attribute *apds9306_event_attributes[] = { + &iio_const_attr_thresh_either_period_available.dev_attr.attr, + &iio_const_attr_thresh_adaptive_either_values_available.dev_attr.attr, +NULL +}; + +static const struct attribute_group apds9306_event_attr_group = { + .attrs = apds9306_event_attributes, +};...
Quoted 12 lines
drivers/iio/light/apds9306.c new file +12
-0+static int apds9306_runtime_power_on (struct device *dev) +{ +int ret; + + ret =pm_runtime_resume_and_get (dev); +if (ret <0 ) +dev_err_ratelimited (dev,"runtime resume failed: %d\n" , ret); + +return ret; +} + +static int apds9306_runtime_power_off (struct device *dev)
Quoted 8 lines
drivers/iio/light/apds9306.c line 477
Quoted 6 lines
drivers/iio/light/apds9306.c new file +6
-0+{ +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); + +return 0 ; +}Seems to me like useless wrappers. Why do you need that message?
No specific need for that message, however the wrapper was suggested in a previous review:
https://lore.kernel.org/all/[email protected]/
Do you still want me to use the pm functions directly from the calling functions?
Quoted 1 line
Btw, it's used only twice, open coding saves the LoCs!
Yes, it makes sense.
Quoted 1 line
Try making the next submission so the driver LoCs is < 1400.
The current driver file is 1335 lines, next one, I will definitely try to keep in under 1400 lines.
Quoted 2 lines
...
Acknowledging all other review comments. Thank you for reviewing.
Regards,
Subhajit Ghosh
Re: [PATCH v6 5/5] iio: light: Add support for APDS9306 Light Sensor
On Wed, Feb 07, 2024 at 09:37:37PM +1030, Subhajit Ghosh wrote:
...
Quoted 7 lines
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+static_assert(ARRAY_SIZE(apds9306_repeat_rate_freq) == + APDS9306_NUM_REPEAT_RATES);Just make that define to be inside [] in the respective array and drop this static assert. The assertion might make sense to have different arrays to be synchronized and when their maximums are different due to semantics (not your case AFAICS).
...
Quoted 7 lines
Quoted 4 lines
drivers/iio/light/apds9306.c line 135
Quoted 2 lines
drivers/iio/light/apds9306.c new file +2
-0+static_assert (ARRAY_SIZE (apds9306_repeat_rate_period) == +APDS9306_NUM_REPEAT_RATES );Ditto.
I apologize for this. You pointed me out in an earlier review, I misunderstood it and used the macro in two static asserts! It will be fixed.
It might be used, but not must be, use your common sense!
In this case it's easier to have all defined properly from the beginning.
...
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
drivers/iio/light/apds9306.c new file +12
-0+static int apds9306_runtime_power_on (struct device *dev) +{ +int ret; + + ret =pm_runtime_resume_and_get (dev); +if (ret <0 ) +dev_err_ratelimited (dev,"runtime resume failed: %d\n" , ret); + +return ret; +} + +static int apds9306_runtime_power_off (struct device *dev)Quoted 8 lines
drivers/iio/light/apds9306.c line 477
Quoted 6 lines
drivers/iio/light/apds9306.c new file +6
-0+{ +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); + +return 0 ; +}Seems to me like useless wrappers. Why do you need that message?
Quoted 2 lines
No specific need for that message, however the wrapper was suggested in a previous review:
https://lore.kernel.org/all/[email protected]/
I see, what I meant in previous review is to split to separate helpers. Now, when we see how it looks like and how many actual users, we may go further and drop them.
Quoted 1 line
Do you still want me to use the pm functions directly from the calling functions?
It seems a good move forward.
Quoted 2 lines
Quoted 1 line
Btw, it's used only twice, open coding saves the LoCs!
Yes, it makes sense.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 3 lines · Subhajit Ghosh
dt-bindings: iio: light: adps9300: Add property vdd-supply
dt-bindings: iio: light: adps9300: Update interrupt definitions
dt-bindings: iio: light: Avago APDS9306
For these 3,
Cheers,
Conor.
Subhajit Ghosh
maintainerQuoted 10 lines · Conor Dooley
Quoted 3 lines · Subhajit Ghosh
dt-bindings: iio: light: adps9300: Add property vdd-supply
dt-bindings: iio: light: adps9300: Update interrupt definitions
dt-bindings: iio: light: Avago APDS9306For these 3,
Acked-by Conor Dooley <[email protected]>Cheers,
Conor.
Thank you very much Conor.
Regards,
Subhajit Ghosh