Support for Avago APDS9306 Ambient Light Sensor
Subhajit Ghosh
maintainerv9 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.
v8 -> v9:
- Added const at several places as per review
- Removed 'ret' from iio_gts_find_new_gain_by_old_gain_time() as it is not used. The current implementaion of the above function passes all my tests of changing integration times, scales and gains from userspace.
- Using the same apds9306_event_spec for both als and clear channels struct iio_chan_spec definitions.
- Used IIO_MOD_EVENT_CODE() macro for Intensity channel events
- Changes as per review:
https://lore.kernel.org/all/20240303151422.5fc3c2f2@jic23-huawei/
v7 -> v8:
- Renamed APDS9306_INT_CH_CLEAR to APDS9306_INT_SRC_CLEAR macro for higher readability
- Removed APDS9306_CHANNEL macro for higher readability
- Updated iio_push_event() functions with correct type of events (Light or Intensity)
- Updated variable name "event_ch_is_light" to "int_src" and change as per review to fix compiler warning
- Used scope for guard() functions
- Other fixes as per reviews
https://lore.kernel.org/all/20240224151340.3f2f51e8@jic23-huawei/
https://lore.kernel.org/all/[email protected]/
v7 -> v8 Bindings:
- Updated commit message as mentioned by Jonathan
https://lore.kernel.org/all/20240224143803.27efa14f@jic23-huawei/
v6 -> v7:
- Made comments to struct part_id_gts_multiplier as kernel doc
- Removed static_asserts for array sizes
- Moved regmap_field from driver private data structure and removed regfield_ prefix to reduce names
- Used "struct apds9306_regfields *rf = &data->rf" in the respective functions to reduce names
- Removed apds9306_runtime_power_on() and apds9306_runtime_power_off() functions in favour of using the runtime_pm calls directly from calling functions.
- Fixed indentations
https://lore.kernel.org/all/[email protected]/#r
v6 -> v7 Bindings:
- Updated commit message
- Removed wrong patch dependency statement from commit messages
- Updates tags
https://lore.kernel.org/all/20240206-gambling-tricycle-510794e20ca8@spud/
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 missing 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 | 1355 +++++++++++++++++ 5 files changed, 1383 insertions(+), 49 deletions(-) delete mode 100644 Documentation/devicetree/bindings/iio/light/avago,apds9960.yaml create mode 100644 drivers/iio/light/apds9306.c
base-commit: 45ec2f5f6ed3ec3a79ba1329ad585497cdcbe663
Signature · 1 line
2.34.1
Subhajit Ghosh
maintainerPATCH v9 1/5 dt-bindings: iio: light: Merge APDS9300 and APDS9960 schemas
Merge very similar schemas for APDS9300 and APDS9960.
---
v8 -> v9:
- No change
v7 -> v8:
- No change
v6 -> v7:
- No change
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 v9 2/5 dt-bindings: iio: light: adps9300: Add missing vdd-supply
In reply to Subhajit GhoshAll devices covered by the binding have a vdd supply.
---
v8 -> v9:
- No change
v7 -> v8:
- No change
v6 -> v7:
- Changed the subject line of the commit
- Updated commit message
- Removed wrong patch dependency statement
- Added tag
https://lore.kernel.org/all/20240210170112.6528a3d4@jic23-huawei/
https://lore.kernel.org/all/20240206-gambling-tricycle-510794e20ca8@spud/
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
Subhajit Ghosh
maintainerPATCH v9 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
---
v8 -> v9:
- No change
v7 -> v8:
- No change
v6 -> v7:
- Removed wrong patch dependency statement
- Added tag
https://lore.kernel.org/all/20240210170258.17fd1099@jic23-huawei/
https://lore.kernel.org/all/20240206-gambling-tricycle-510794e20ca8@spud/
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
Subhajit Ghosh
maintainerPATCH v9 4/5 dt-bindings: iio: light: Avago APDS9306
In reply to Subhajit GhoshExtend avago,apds9300.yaml schema file to support apds9306 device.
---
v8 -> v9:
- No change
v7 -> v8:
- Updated commit message as mentioned by Jonathan
https://lore.kernel.org/all/20240224143803.27efa14f@jic23-huawei/
v6 -> v7:
- Removed wrong patch dependency statement
- Added tag
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/20240206-gambling-tricycle-510794e20ca8@spud/
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
Subhajit Ghosh
maintainerPATCH v9 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.
---
v8 -> v9:
- Added const at several places as per review
- Removed 'ret' from iio_gts_find_new_gain_by_old_gain_time() as it is not used. The current implementaion of the above function passes all my tests of changing integration times, scales and gains from userspace.
- Using the same apds9306_event_spec for both als and clear channels struct iio_chan_spec definitions.
- Used IIO_MOD_EVENT_CODE() macro for Intensity channel events
- Changes as per review:
https://lore.kernel.org/all/20240303151422.5fc3c2f2@jic23-huawei/
v7 -> v8:
- Renamed APDS9306_INT_CH_CLEAR to APDS9306_INT_SRC_CLEAR macro for higher readability
- Removed APDS9306_CHANNEL macro for higher readability
- Updated iio_push_event() functions with correct type of events (Light or Intensity)
- Updated variable name "event_ch_is_light" to "int_src" and change as per review to fix compiler warning
- Used scope for guard() functions
- Other fixes as per reviews
https://lore.kernel.org/all/20240224151340.3f2f51e8@jic23-huawei/
https://lore.kernel.org/all/[email protected]/
v6 -> v7:
- Made comments to struct part_id_gts_multiplier as kernel doc
- Removed static_asserts for array sizes
- Moved regmap_field types from driver private data structure to a new structure and removed regfield_ prefix to reduce names
- Used "struct apds9306_regfields *rf = &data->rf" in the respective functions to reduce names
- Removed apds9306_runtime_power_on() and apds9306_runtime_power_off() functions in favour of using the runtime_pm calls directly from calling functions.
- Fixed indentations
https://lore.kernel.org/all/[email protected]/#r
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 | 1355 ++++++++++++++++++++++++++++++++++ 3 files changed, 1368 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 +1355 -0
1,355 lines not on this page · raw message
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v9 5/5] iio: light: Add support for APDS9306 Light Sensor
Quoted 11 lines · On Sat, 9 Mar 2024 21:20:31 +1030 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.
Quoted 4 lines
This driver also uses the IIO GTS (Gain Time Scale) Helpers Namespace for Scales, Gains and Integration time implementation.
Signed-off-by Subhajit Ghosh <[email protected]>
A few things inline, on trivial that I'll tidy up, the other a potential suggestion for simplifying the code, but not something I'm going to ask for a v10 for. If you like the suggestion then a follow up patch, if not then fair enough - may be a case of "don't let perfect be the enemy of good" or maybe you disagree.
Anyhow, series applied to the togreg-normal branch of iio.git and pushed out for 0-day to take a look at it. This is 6.10 material now.
Thanks,
Jonathan
Quoted 10 lines
drivers/iio/light/apds9306.c new file +10
-0+static const struct iio_chan_spec apds9306_channels_with_events[] = { + { + .type =IIO_LIGHT , + .info_mask_shared_by_all =BIT (IIO_CHAN_INFO_INT_TIME ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ), + .info_mask_shared_by_all_available =BIT (IIO_CHAN_INFO_INT_TIME ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ), + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ), + .info_mask_separate_available =BIT (IIO_CHAN_INFO_SCALE ),
drivers/iio/light/apds9306.c line 261
Quoted 10 lines
drivers/iio/light/apds9306.c new file +10
-0+ .event_spec = apds9306_event_spec, + .num_event_specs = ARRAY_SIZE(apds9306_event_spec), + }, { + .type = IIO_INTENSITY, + .info_mask_shared_by_all =BIT (IIO_CHAN_INFO_INT_TIME ) | + BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available =BIT (IIO_CHAN_INFO_INT_TIME ) | + BIT(IIO_CHAN_INFO_SAMP_FREQ), + .channel2 = IIO_MOD_LIGHT_CLEAR, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
Trivial but odd field order - I'll tidy that up whilst applying.
Quoted 84 lines
drivers/iio/light/apds9306.c new file +81
-0+ .modified = 1, + .event_spec = apds9306_event_spec, + .num_event_specs = ARRAY_SIZE(apds9306_event_spec), + }, +}; + +static const struct iio_chan_spec apds9306_channels_without_events[] = { + { + .type =IIO_LIGHT , + .info_mask_shared_by_all =BIT (IIO_CHAN_INFO_INT_TIME ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ), + .info_mask_shared_by_all_available =BIT (IIO_CHAN_INFO_INT_TIME ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ), + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ), + .info_mask_separate_available =BIT (IIO_CHAN_INFO_SCALE ), + }, { + .type =IIO_INTENSITY , + .info_mask_shared_by_all =BIT (IIO_CHAN_INFO_INT_TIME ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ), + .info_mask_shared_by_all_available =BIT (IIO_CHAN_INFO_INT_TIME ) | +BIT (IIO_CHAN_INFO_SAMP_FREQ ), + .channel2 =IIO_MOD_LIGHT_CLEAR , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ), + .modified =1 , + }, +}; + +/* INT_PERSISTENCE available */ +static IIO_CONST_ATTR(thresh_either_period_available, "[0 1 15]"); + +/* ALS_THRESH_VAR available */ +static IIO_CONST_ATTR(thresh_adaptive_either_values_available, "[0 1 7]"); + +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 int apds9306_write_event_config (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir, +int state) +{ +struct apds9306_data *data =iio_priv (indio_dev); +struct apds9306_regfields *rf = &data->rf; +int ret, val; + + state = !!state; + +switch (type) { +case IIO_EV_TYPE_THRESH : { +guard (mutex)(&data->mutex); + +/* +* If interrupt is enabled, the channel is set before enabling +* the interrupt. In case of disable, no need to switch +* channels. In case of different channel is selected while +* interrupt in on, just change the channel. +*/ +if (state) { +if (chan->type ==IIO_LIGHT ) + val =1 ; +else if (chan->type ==IIO_INTENSITY ) + val =0 ; +else +return -EINVAL ; + + ret =regmap_field_write (rf->int_src, val); +if (ret) +return ret; + } + + ret =regmap_field_read (rf->int_en, &val); +if (ret) +return ret; + +if (val == state) +return 0 ;
drivers/iio/light/apds9306.c
Quoted 10 lines
drivers/iio/light/apds9306.c new file +10
-0+ + ret =regmap_field_write (rf->int_en, state); +if (ret) +return ret; + +if (state) +return pm_runtime_resume_and_get (data->dev); + +pm_runtime_mark_last_busy (data->dev); +pm_runtime_put_autosuspend (data->dev);
Note this isn't a reason to do a v10, just a possible suggestion for what I think is more readable code.
Flow here is complex, maybe we'd have been better with skipping the state = !!state, rename val to more explicit enabled above and something like..
ret = regmap_field_read(rf->int_en, &enabled);
if (ret)
return ret;
if (state) {
if (chan->type == IIO_LIGHT)
ret = regmap_field_write(rf->int_src, 1);
else if (chan->type == IIO_INTENSITY)
ret = regmap_field_write(rf->int_src, 0);
else
return -EINVAL;
if (ret)
return ret;
if (enabled) /* Already enabled */
return 0;
ret = regmap_field_write(rf->int_en, 1);
if (ret)
return ret;
return pm_runtime_resume_and_get(data->dev);
} else { // Could drop this else but I think it's useful to show the either or flow.
if (!enabled)
return 0;
ret = regmap_field_write(rf->int_en, 0);
if (ret)
return ret;
pm_runtime_mark_last_busy(data->dev);
pm_runtime_put_autosuspend(data->dev);
return 0;
}
} Quoted 27 lines
drivers/iio/light/apds9306.c new file +26
-0+ +return 0 ; + } +case IIO_EV_TYPE_THRESH_ADAPTIVE : +return regmap_field_write (rf->int_thresh_var_en, state); +default : +return -EINVAL ; + } +} + +static void apds9306_powerdown (void *ptr) +{ +struct apds9306_data *data = (struct apds9306_data *)ptr; +struct apds9306_regfields *rf = &data->rf; +int ret; + + ret =regmap_field_write (rf->int_thresh_var_en,0 ); +if (ret) +return ; + + ret =regmap_field_write (rf->int_en,0 ); +if (ret) +return ; + +apds9306_power_state (data, false); +}
...
Subhajit Ghosh
maintainerRe: [PATCH v9 5/5] iio: light: Add support for APDS9306 Light Sensor
Quoted 87 lines
Quoted 43 lines
drivers/iio/light/apds9306.c new file +42
-0+ +static int apds9306_write_event_config (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir, +int state) +{ +struct apds9306_data *data =iio_priv (indio_dev); +struct apds9306_regfields *rf = &data->rf; +int ret, val; + + state = !!state; + +switch (type) { +case IIO_EV_TYPE_THRESH : { +guard (mutex)(&data->mutex); + +/* +* If interrupt is enabled, the channel is set before enabling +* the interrupt. In case of disable, no need to switch +* channels. In case of different channel is selected while +* interrupt in on, just change the channel. +*/ +if (state) { +if (chan->type ==IIO_LIGHT ) + val =1 ; +else if (chan->type ==IIO_INTENSITY ) + val =0 ; +else +return -EINVAL ; + + ret =regmap_field_write (rf->int_src, val); +if (ret) +return ret; + } + + ret =regmap_field_read (rf->int_en, &val); +if (ret) +return ret; + +if (val == state) +return 0 ;drivers/iio/light/apds9306.c line 1120
Quoted 10 lines
drivers/iio/light/apds9306.c new file +10
-0+ + ret =regmap_field_write (rf->int_en, state); +if (ret) +return ret; + +if (state) +return pm_runtime_resume_and_get (data->dev); + +pm_runtime_mark_last_busy (data->dev); +pm_runtime_put_autosuspend (data->dev);Note this isn't a reason to do a v10, just a possible suggestion for what I think is more readable code.
Flow here is complex, maybe we'd have been better with skipping the state = !!state, rename val to more explicit enabled above and something like..
ret = regmap_field_read(rf->int_en, &enabled); if (ret) return ret; if (state) { if (chan->type == IIO_LIGHT) ret = regmap_field_write(rf->int_src, 1); else if (chan->type == IIO_INTENSITY) ret = regmap_field_write(rf->int_src, 0); else return -EINVAL; if (ret) return ret; if (enabled) /* Already enabled */ return 0; ret = regmap_field_write(rf->int_en, 1); if (ret) return ret; return pm_runtime_resume_and_get(data->dev); } else { // Could drop this else but I think it's useful to show the either or flow. if (!enabled) return 0; ret = regmap_field_write(rf->int_en, 0);
Quoted 8 lines
if (ret) return ret; pm_runtime_mark_last_busy(data->dev); pm_runtime_put_autosuspend(data->dev); return 0; } }
Yes, this is much simpler and readable. I will prepare a follow up patch for this.
Thank you for reviewing and applying the series.
Regards,
Subhajit Ghosh
Quoted 30 lines
Quoted 27 lines
drivers/iio/light/apds9306.c new file +26
-0+ +return 0 ; + } +case IIO_EV_TYPE_THRESH_ADAPTIVE : +return regmap_field_write (rf->int_thresh_var_en, state); +default : +return -EINVAL ; + } +} + +static void apds9306_powerdown (void *ptr) +{ +struct apds9306_data *data = (struct apds9306_data *)ptr; +struct apds9306_regfields *rf = &data->rf; +int ret; + + ret =regmap_field_write (rf->int_thresh_var_en,0 ); +if (ret) +return ; + + ret =regmap_field_write (rf->int_en,0 ); +if (ret) +return ; + +apds9306_power_state (data, false); +}...
Quoted 17 lines · Subhajit Ghosh
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.
...
Quoted 4 lines
- Removed 'ret' from
iio_gts_find_new_gain_by_old_gain_time()as it is not used. The current implementaion of the above function passes all my tests of changing integration times, scales and gains from userspace.
This is weird. I believe we have to fix the API first before adding / dropping the return value from it. This odd API which makes everybody confused.
Signature · 2 lines
With Best Regards, Andy Shevchenko