AL3010 introduction
Subsystems (2)
v4 cover AL3010 introduction
These patches implement support for simple iio light sensor AL3010 and also improves and align formating of AL3320a which is origin of al3010 driver.
AL3010 is used in many devices, mostly tegra2/3 based. This effort is aimed for reducing number of out-of-tree patches for tegra tablets and phones.
This sensor is tested on Nexus 7 (2012, grouper/tilapia).
v4
- incorporated previously proposed changes
David Heidelberg (7):
dt-bindings: iio: light: add support for Dyna-Image AL3320A
dt-bindings: iio: light: add support for Dyna-Image AL3010
iio: light: al3320a slightly improve code formatting
iio: light: add Dyna-Image AL3010 driver
iio: light: al3320a implement suspend support
iio: light: al3320a implement devm_add_action_or_reset
iio: light: al3320a allow module autoload and polish
.../devicetree/bindings/iio/light/al3010.yaml | 45 ++++ .../bindings/iio/light/al3320a.yaml | 45 ++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/al3010.c | 240 ++++++++++++++++++ drivers/iio/light/al3320a.c | 72 ++++-- 7 files changed, 398 insertions(+), 17 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/light/al3010.yaml create mode 100644 Documentation/devicetree/bindings/iio/light/al3320a.yaml create mode 100644 drivers/iio/light/al3010.c
Signature · 1 line
2.25.0
PATCH v4 1/7 dt-bindings: iio: light: add support for Dyna-Image AL3320A
This commit add dt-bindings support to al3320a driver and vendor-prefix dynaimage.
--- .../bindings/iio/light/al3320a.yaml | 45 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 47 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/al3320a.yaml
Documentation/devicetree/bindings/iio/light/al3320a.yaml new file +45 -0
@@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0-only) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/al3320a.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Dyna-Image AL3320A sensor + +maintainers: + - David Heidelberg <[email protected]> + +properties: + compatible: + const: dynaimage,al3320a + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: + description: Regulator that provides power to the sensor + +required: + - compatible + - reg + - interrupts + - vdd-supply + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + al3320a@1c { + compatible = "dynaimage,al3320a"; + reg = <0x1c>; + vdd-supply = <&vdd_reg>; + interrupts = <0 99 4>; + }; + };
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -267,6 +267,8 @@ patternProperties: description: Dragino Technology Co., Limited "^dserve,.*": description: dServe Technology B.V. + "^dynaimage,.*": + description: Dyna-Image "^ea,.*": description: Embedded Artists AB "^ebs-systart,.*":
Signature · 1 line
2.25.0
Rob Herring
maintainerRe: [PATCH v4 1/7] dt-bindings: iio: light: add support for Dyna-Image AL3320A
Quoted 17 lines · David Heidelberg
This commit add dt-bindings support to al3320a driver and vendor-prefix dynaimage.
Signed-off-by David Heidelberg <[email protected]>--- .../bindings/iio/light/al3320a.yaml | 45 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 47 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/al3320a.yamlDocumentation/devicetree/bindings/iio/light/al3320a.yaml new file +0
-0
Documentation/devicetree/bindings/iio/light/al3320a.yaml line 1
Quoted 1 line
Documentation/devicetree/bindings/iio/light/al3320a.yaml new file +1
-0@@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0-only)
Dual license new bindings:
(GPL-2.0-only OR BSD-2-Clause)
Quoted 28 lines
Documentation/devicetree/bindings/iio/light/al3320a.yaml new file +28
-0+%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/al3320a.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Dyna-Image AL3320A sensor + +maintainers: + - David Heidelberg <[email protected]> + +properties: + compatible: + const: dynaimage,al3320a + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: + description: Regulator that provides power to the sensor + +required: + - compatible + - reg + - interrupts + - vdd-supply
Documentation/devicetree/bindings/iio/light/al3320a.yaml line 39
Quoted 10 lines
Documentation/devicetree/bindings/iio/light/al3320a.yaml new file +10
-0+ +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + al3320a@1c {
light-sensor@1c
Quoted 22 lines
Documentation/devicetree/bindings/iio/light/al3320a.yaml new file +6
-0+ compatible = "dynaimage,al3320a"; + reg = <0x1c>; + vdd-supply = <&vdd_reg>; + interrupts = <0 99 4>; + }; + };Documentation/devicetree/bindings/vendor-prefixes.yaml +2
-0@@ -267,6 +267,8 @@ patternProperties: description: Dragino Technology Co., Limited "^dserve,.*": description: dServe Technology B.V. + "^dynaimage,.*": + description: Dyna-Image "^ea,.*": description: Embedded Artists AB "^ebs-systart,.*":Signature · 1 line
2.25.0
Re: [PATCH v4 1/7] dt-bindings: iio: light: add support for Dyna-Image AL3320A
Rob Herring <[email protected]> napsal Čt, 6. úno 2020 v 19∶07:
Quoted 24 lines · David Heidelberg
Quoted 14 lines
This commit add dt-bindings support to al3320a driver and
vendor-prefix
dynaimage.Signed-off-by David Heidelberg <[email protected]>---
.../bindings/iio/light/al3320a.yaml | 45 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 47 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/light/al3320a.yamlQuoted 8 lines
diff --git
a/Documentation/devicetree/bindings/iio/light/al3320a.yamlb/Documentation/devicetree/bindings/iio/light/al3320a.yaml
new file mode 100644
index 000000000000..08e7ee4bdf55
---/dev/null
+++b/Documentation/devicetree/bindings/iio/light/al3320a.yaml
@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: (GPL-2.0-only)
Quoted 3 lines
Dual license new bindings:
(GPL-2.0-only OR BSD-2-Clause)
It BSD usage in Linux kernel enforced for bindings?
I'd like to publish my code only under GPL if possible.
Quoted 40 lines
Quoted 29 lines
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/light/al3320a.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Dyna-Image AL3320A sensor
+
+maintainers:
+ - David Heidelberg <[email protected]>
+
+properties:
+ compatible:
+ const: dynaimage,al3320a
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+
+ vdd-supply:
+ description: Regulator that provides power to the sensor
+
+required:+ - compatible + - reg + - interrupts + - vdd-supplyQuoted 10 lines
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ al3320a@1c {
Quoted 1 line
light-sensor@1c
Fixed for next revision, thanks.
Quoted 24 lines
Quoted 24 lines
+ compatible = "dynaimage,al3320a"; + reg = <0x1c>; + vdd-supply = <&vdd_reg>; + interrupts = <0 99 4>;+ };
+ };
diff --gita/Documentation/devicetree/bindings/vendor-prefixes.yamlb/Documentation/devicetree/bindings/vendor-prefixes.yaml
index9cd52d9e1f7f..8d2ebf3d0aa1100644
---a/Documentation/devicetree/bindings/vendor-prefixes.yaml+++b/Documentation/devicetree/bindings/vendor-prefixes.yaml@@ -267,6 +267,8 @@ patternProperties:
description: Dragino Technology Co., Limited
"^dserve,.*":
description: dServe Technology B.V.
+ "^dynaimage,.*":
+ description: Dyna-Image"^ea,.*": description: Embedded Artists AB "^ebs-systart,.*":--
2.25.0
Rob Herring
maintainerRe: [PATCH v4 1/7] dt-bindings: iio: light: add support for Dyna-Image AL3320A
Quoted 30 lines · David Heidelberg
Rob Herring <[email protected]> napsal Čt, 6. úno 2020 v 19∶07:
Quoted 25 lines · David Heidelberg
Quoted 23 lines
This commit add dt-bindings support to al3320a driver and
vendor-prefix
dynaimage.Signed-off-by David Heidelberg <[email protected]>---
.../bindings/iio/light/al3320a.yaml | 45 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 47 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/light/al3320a.yamldiff --git
a/Documentation/devicetree/bindings/iio/light/al3320a.yamlb/Documentation/devicetree/bindings/iio/light/al3320a.yaml
new file mode 100644
index 000000000000..08e7ee4bdf55
---/dev/null
+++b/Documentation/devicetree/bindings/iio/light/al3320a.yaml@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: (GPL-2.0-only)
Quoted 5 lines
Quoted 3 lines
Dual license new bindings:
(GPL-2.0-only OR BSD-2-Clause)
It BSD usage in Linux kernel enforced for bindings?
Yes, bindings are exported and used by other projects. And may get moved out completely.
Quoted 2 lines
I'd like to publish my code only under GPL if possible.
Re: [PATCH v4 1/7] dt-bindings: iio: light: add support for Dyna-Image AL3320A
Rob Herring <[email protected]> napsal Čt, 6. úno 2020 v 14∶27:
Quoted 31 lines · David Heidelberg
Quoted 30 lines
Rob Herring <[email protected]> napsal Čt, 6. úno 2020 v 19∶07:
Quoted 25 lines · David Heidelberg
Quoted 23 lines
This commit add dt-bindings support to al3320a driver and
vendor-prefix
dynaimage.Signed-off-by David Heidelberg <[email protected]>---
.../bindings/iio/light/al3320a.yaml | 45 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 47 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/light/al3320a.yamldiff --git
a/Documentation/devicetree/bindings/iio/light/al3320a.yamlb/Documentation/devicetree/bindings/iio/light/al3320a.yaml
new file mode 100644
index 000000000000..08e7ee4bdf55
---/dev/null
+++b/Documentation/devicetree/bindings/iio/light/al3320a.yaml@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: (GPL-2.0-only)
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Dual license new bindings:
(GPL-2.0-only OR BSD-2-Clause)
It BSD usage in Linux kernel enforced for bindings?
Yes, bindings are exported and used by other projects. And may get moved out completely.
So do I assume right if I'm not dual licencing also under BSD, patch won't get merged?
By principle I don't like to being forced give my work to projects which don't comply with GPL 2. Not much happy about it, but what can I do, when I want this sensors DT merged in...
Due to the fact it's simple definition, I'll dual licence it also to BSD for next patch version.
Quoted 2 lines
Quoted 2 lines
I'd like to publish my code only under GPL if possible.
PATCH v4 2/7 dt-bindings: iio: light: add support for Dyna-Image AL3010
In reply to David HeidelbergThe Dyna-Image AL3010 is a 16-bit digital ambient light sensor which provides a multiple gain function with linear response over a dynamic range 1216/4863/19452/77806.
--- .../devicetree/bindings/iio/light/al3010.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/al3010.yaml
Documentation/devicetree/bindings/iio/light/al3010.yaml new file +45 -0
@@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0-only) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/al3010.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Dyna-Image AL3010 sensor + +maintainers: + - David Heidelberg <[email protected]> + +properties: + compatible: + const: dynaimage,al3010 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: + description: Regulator that provides power to the sensor + +required: + - compatible + - reg + - interrupts + - vdd-supply + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + al3010@1c { + compatible = "dynaimage,al3010"; + reg = <0x1c>; + vdd-supply = <&vdd_reg>; + interrupts = <0 99 4>; + }; + };
Signature · 1 line
2.25.0
Re: [PATCH v4 2/7] dt-bindings: iio: light: add support for Dyna-Image AL3010
Quoted 3 lines · David Heidelberg
The Dyna-Image AL3010 is a 16-bit digital ambient light sensor which provides a multiple gain function with linear response over a dynamic range 1216/4863/19452/77806.
[...]
Quoted 8 lines
Documentation/devicetree/bindings/iio/light/al3010.yaml new file +8
-0+properties: + compatible: + const: dynaimage,al3010 + + reg: + maxItems: 1 + + interrupts:
Documentation/devicetree/bindings/iio/light/al3010.yaml line 29
Quoted 10 lines
Documentation/devicetree/bindings/iio/light/al3010.yaml new file +10
-0+ maxItems: 1 + + vdd-supply: + description: Regulator that provides power to the sensor + +required: + - compatible + - reg + - interrupts + - vdd-supply
Regulator and interrupt should be optional.
Best Regards,
Michał Mirosław
Re: [PATCH v4 2/7] dt-bindings: iio: light: add support for Dyna-Image AL3010
04.02.2020 12:52, Michał Mirosław пишет:
Quoted 17 lines · David Heidelberg
Quoted 3 lines
The Dyna-Image AL3010 is a 16-bit digital ambient light sensor which provides a multiple gain function with linear response over a dynamic range 1216/4863/19452/77806.
[...]
Quoted 12 lines
Documentation/devicetree/bindings/iio/light/al3010.yaml new file +12
-0+properties: + compatible: + const: dynaimage,al3010 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: + description: Regulator that provides power to the sensor
Quoted 8 lines
Documentation/devicetree/bindings/iio/light/al3010.yaml line 29
Quoted 6 lines
Documentation/devicetree/bindings/iio/light/al3010.yaml new file +6
-0+ +required: + - compatible + - reg + - interrupts + - vdd-supplyRegulator and interrupt should be optional.
Indeed, that's a good correction +1
PATCH v4 3/7 iio: light: al3320a slightly improve code formatting
In reply to David Heidelberg- modified to be in part with al3010 driver
- cleanup using bitfield, no functionality change intended
v4
- use GENMASK() and bitfields
- sort headers
- drop init.h unused header
--- drivers/iio/light/al3320a.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/iio/light/al3320a.c +12 -10
@@ -9,9 +9,9 @@* TODO: interrupt support, thresholds */ -#include <linux/module.h> -#include <linux/init.h> +#include <linux/bitfield.h> #include <linux/i2c.h> +#include <linux/module.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h>
@@ -36,8 +36,7 @@#define AL3320A_CONFIG_DISABLE 0x00#define AL3320A_CONFIG_ENABLE 0x01 -#define AL3320A_GAIN_SHIFT 1 -#define AL3320A_GAIN_MASK (BIT(2) | BIT(1)) +#define AL3320A_GAIN_MASK GENMASK(2, 1)/* chip params default values */ #define AL3320A_DEFAULT_MEAN_TIME 4
@@ -90,7 +89,8 @@ static int al3320a_init(struct al3320a_data *data)return ret; ret =i2c_smbus_write_byte_data (data->client,AL3320A_REG_CONFIG_RANGE , -AL3320A_RANGE_3 <<AL3320A_GAIN_SHIFT ); +FIELD_PREP (AL3320A_GAIN_MASK , +AL3320A_RANGE_3 ));if (ret <0 )return ret;
@@ -133,7 +133,7 @@ static int al3320a_read_raw(struct iio_dev *indio_dev,if (ret <0 )return ret; - ret = (ret &AL3320A_GAIN_MASK ) >>AL3320A_GAIN_SHIFT ; + ret =FIELD_GET (AL3320A_GAIN_MASK , ret) *val = al3320a_scales[ret][0 ]; *val2 = al3320a_scales[ret][1 ];
@@ -152,11 +152,13 @@ static int al3320a_write_raw(struct iio_dev *indio_dev,switch (mask) {case IIO_CHAN_INFO_SCALE :for (i =0 ; i <ARRAY_SIZE (al3320a_scales); i++) { -if (val == al3320a_scales[i][0 ] && - val2 == al3320a_scales[i][1 ]) -return i2c_smbus_write_byte_data (data->client, +if (val != al3320a_scales[i][0 ] || + val2 != al3320a_scales[i][1 ]) +continue ; + +return i2c_smbus_write_byte_data (data->client,AL3320A_REG_CONFIG_RANGE , - i <<AL3320A_GAIN_SHIFT ); +FIELD_PREP (AL3320A_GAIN_MASK , i)); }break ; }
Signature · 1 line
2.25.0
Jonathan Cameron
maintainerRe: [PATCH v4 3/7] iio: light: al3320a slightly improve code formatting
Quoted 11 lines · On Tue, 4 Feb 2020 10:30:32 +0100 David Heidelberg <[email protected]> wrote:
- modified to be in part with al3010 driver
- cleanup using bitfield, no functionality change intendedSigned-off-by David Heidelberg <[email protected]>v4
- useGENMASK()and bitfields
- sort headers
- dropinit.hunused headerSigned-off-by David Heidelberg <[email protected]>
Looks good to me. Will pick it up once rest of series is ready.
Thanks,
Jonathan
Quoted 67 lines
--- drivers/iio/light/al3320a.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)drivers/iio/light/al3320a.c +12
-10@@ -9,9 +9,9 @@* TODO: interrupt support, thresholds */ -#include <linux/module.h> -#include <linux/init.h> +#include <linux/bitfield.h> #include <linux/i2c.h> +#include <linux/module.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> @@ -36,8 +36,7 @@#define AL3320A_CONFIG_DISABLE 0x00#define AL3320A_CONFIG_ENABLE 0x01 -#define AL3320A_GAIN_SHIFT 1 -#define AL3320A_GAIN_MASK (BIT(2) | BIT(1)) +#define AL3320A_GAIN_MASK GENMASK(2, 1)/* chip params default values */ #define AL3320A_DEFAULT_MEAN_TIME 4@@ -90,7 +89,8 @@ static int al3320a_init(struct al3320a_data *data)return ret; ret =i2c_smbus_write_byte_data (data->client,AL3320A_REG_CONFIG_RANGE , -AL3320A_RANGE_3 <<AL3320A_GAIN_SHIFT ); +FIELD_PREP (AL3320A_GAIN_MASK , +AL3320A_RANGE_3 ));if (ret <0 )return ret;@@ -133,7 +133,7 @@ static int al3320a_read_raw(struct iio_dev *indio_dev,if (ret <0 )return ret; - ret = (ret &AL3320A_GAIN_MASK ) >>AL3320A_GAIN_SHIFT ; + ret =FIELD_GET (AL3320A_GAIN_MASK , ret) *val = al3320a_scales[ret][0 ]; *val2 = al3320a_scales[ret][1 ];@@ -152,11 +152,13 @@ static int al3320a_write_raw(struct iio_dev *indio_dev,switch (mask) {case IIO_CHAN_INFO_SCALE :for (i =0 ; i <ARRAY_SIZE (al3320a_scales); i++) { -if (val == al3320a_scales[i][0 ] && - val2 == al3320a_scales[i][1 ]) -return i2c_smbus_write_byte_data (data->client, +if (val != al3320a_scales[i][0 ] || + val2 != al3320a_scales[i][1 ]) +continue ; + +return i2c_smbus_write_byte_data (data->client,AL3320A_REG_CONFIG_RANGE , - i <<AL3320A_GAIN_SHIFT ); +FIELD_PREP (AL3320A_GAIN_MASK , i)); }break ; }
Re: [PATCH v4 3/7] iio: light: al3320a slightly improve code formatting
In reply to David Heidelberg04.02.2020 12:30, David Heidelberg пишет:
...
drivers/iio/light/al3320a.c line 39
Quoted 6 lines
#define
AL3320A_CONFIG_DISABLE0x00
#defineAL3320A_CONFIG_ENABLE0x01drivers/iio/light/al3320a.c +1
-2-#define AL3320A_GAIN_SHIFT 1 -#define AL3320A_GAIN_MASK (BIT(2) | BIT(1)) +#define AL3320A_GAIN_MASK GENMASK(2, 1)
Looks like you forgot to compile-test this driver because the AL3320A_GAIN_SHIFT is removed above, while it's still in-use below.
Quoted 9 lines
/* chip params default values */
#defineAL3320A_DEFAULT_MEAN_TIME4drivers/iio/light/al3320a.c +2
-1@@ -90,7 +89,8 @@ static int al3320a_init(struct al3320a_data *data)return ret; ret =i2c_smbus_write_byte_data (data->client,AL3320A_REG_CONFIG_RANGE , -AL3320A_RANGE_3 <<AL3320A_GAIN_SHIFT ); +FIELD_PREP (AL3320A_GAIN_MASK , +AL3320A_RANGE_3 ));
...
Re: [PATCH v4 3/7] iio: light: al3320a slightly improve code formatting
06.02.2020 17:50, Dmitry Osipenko пишет:
Quoted 17 lines
04.02.2020 12:30, David Heidelberg пишет:
...drivers/iio/light/al3320a.c line 39
Quoted 6 lines
#define
AL3320A_CONFIG_DISABLE0x00
#defineAL3320A_CONFIG_ENABLE0x01drivers/iio/light/al3320a.c +1
-2-#define AL3320A_GAIN_SHIFT 1 -#define AL3320A_GAIN_MASK (BIT(2) | BIT(1)) +#define AL3320A_GAIN_MASK GENMASK(2, 1)Looks like you forgot to compile-test this driver because the
AL3320A_GAIN_SHIFTis removed above, while it's still in-use below.Quoted 5 lines
/* chip params default values */
#defineAL3320A_DEFAULT_MEAN_TIME4(quoted diff) +0
-0@@ -90,7 +89,8 @@ static int al3320a_init(struct al3320a_data *data) return ret;
Quoted 6 lines
Quoted 4 lines
drivers/iio/light/al3320a.c +2
-1ret =i2c_smbus_write_byte_data (data->client,AL3320A_REG_CONFIG_RANGE , -AL3320A_RANGE_3 <<AL3320A_GAIN_SHIFT ); +FIELD_PREP (AL3320A_GAIN_MASK , +AL3320A_RANGE_3 ));...
Ah, my bad! Sorry :)
PATCH v4 4/7 iio: light: add Dyna-Image AL3010 driver
In reply to David HeidelbergBased on:
- 3320A in-kernel driver
- https://www.spinics.net/lists/linux-iio/msg25145.html
- https://lore.kernel.org/patchwork/patch/684179/
I decided to keep it aside of AL3320A due to different approach and much simpler design of 3010.
Tested on Nexus 7 2012 (grouper/tilapia).
v4:
- SQUASHed: iio: light: al3010 implement suspend support
- switched from _remove to devm_add_action_or_reset
- implement bitfields FIELD_PREP & FIELD_GET, no functionality change
--- drivers/iio/light/Kconfig | 10 ++ drivers/iio/light/Makefile | 1 + drivers/iio/light/al3010.c | 240 +++++++++++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 drivers/iio/light/al3010.c
drivers/iio/light/Kconfig +10 -0
@@ -43,6 +43,16 @@ config ADUX1020 To compile this driver as a module, choose M here: the module will be called adux1020. +config AL3010 + tristate "AL3010 ambient light sensor" + depends on I2C + help + Say Y here if you want to build a driver for the Dyna Image AL3010 + ambient light sensor. + + To compile this driver as a module, choose M here: the + module will be called al3010. + config AL3320A tristate "AL3320A ambient light sensor" depends on I2C
drivers/iio/light/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_ACPI_ALS) += acpi-als.o obj-$(CONFIG_ADJD_S311) += adjd_s311.o obj-$(CONFIG_ADUX1020) += adux1020.o +obj-$(CONFIG_AL3010) += al3010.o obj-$(CONFIG_AL3320A) += al3320a.o obj-$(CONFIG_APDS9300) += apds9300.o obj-$(CONFIG_APDS9960) += apds9960.o
drivers/iio/light/al3010.c new file +240 -0
240 lines not on this page · raw message
Signature · 1 line
2.25.0
Re: [PATCH v4 4/7] iio: light: add Dyna-Image AL3010 driver
04.02.2020 12:30, David Heidelberg пишет:
Quoted 8 lines
Based on:
- 3320A in-kernel driver
- https://www.spinics.net/lists/linux-iio/msg25145.html
- https://lore.kernel.org/patchwork/patch/684179/I decided to keep it aside of AL3320A due to different approach and much simpler design of 3010.
Quoted 7 lines
Tested on Nexus 7 2012 (grouper/tilapia).
Tested-by David Heidelberg <[email protected]>Tested-by Dmitry Osipenko <[email protected]>Tested-by Michał Mirosław <[email protected]>Reviewed-by Dmitry Osipenko <[email protected]>Signed-off-by David Heidelberg <[email protected]>
Yours signed-off-by tag is duplicated.
Quoted 9 lines
v4:
- SQUASHed: iio: light: al3010 implement suspend support
- switched from_removetodevm_add_action_or_reset
- implement bitfieldsFIELD_PREP&FIELD_GET, no functionality changeSigned-off-by David Heidelberg <[email protected]>---
^^^
It's more preferred to put the change log under the ---, that way it won't end up in the commit's message and patch will still apply because everything in between of --- and the diff is ignored by the git am.
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ +#define AL3010_GAIN_MASK (BIT(6) | BIT(5) | BIT(4))
What about to use GENMASK macro here:
#define AL3010_GAIN_MASK GENMASK(6, 4))
Jonathan Cameron
maintainerRe: [PATCH v4 4/7] iio: light: add Dyna-Image AL3010 driver
In reply to David HeidelbergQuoted 16 lines · On Tue, 4 Feb 2020 10:30:34 +0100 David Heidelberg <[email protected]> wrote:
Based on:
- 3320A in-kernel driver
- https://www.spinics.net/lists/linux-iio/msg25145.html
- https://lore.kernel.org/patchwork/patch/684179/I decided to keep it aside of AL3320A due to different approach and much simpler design of 3010.
Tested on Nexus 7 2012 (grouper/tilapia).
Tested-by David Heidelberg <[email protected]>Tested-by Dmitry Osipenko <[email protected]>Tested-by Michał Mirosław <[email protected]>Reviewed-by Dmitry Osipenko <[email protected]>Signed-off-by David Heidelberg <[email protected]>
Quoted 6 lines
v4:
- SQUASHed: iio: light: al3010 implement suspend support
- switched from_removetodevm_add_action_or_reset
- implement bitfieldsFIELD_PREP&FIELD_GET, no functionality changeSigned-off-by David Heidelberg <[email protected]>
This is fine as is, but you might want to think about adding basic regulator control as VDD might not be turned on.
Then there is the follow up question on whether it is sensible to disable VDD in the suspend path.
Thanks,
Jonathan
Quoted 286 lines
--- drivers/iio/light/Kconfig | 10 ++ drivers/iio/light/Makefile | 1 + drivers/iio/light/al3010.c | 240 +++++++++++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 drivers/iio/light/al3010.cdrivers/iio/light/Kconfig +10
-0@@ -43,6 +43,16 @@ config ADUX1020 To compile this driver as a module, choose M here: the module will be called adux1020. +config AL3010 + tristate "AL3010 ambient light sensor" + depends on I2C + help + Say Y here if you want to build a driver for the Dyna Image AL3010 + ambient light sensor. + + To compile this driver as a module, choose M here: the + module will be called al3010. + config AL3320A tristate "AL3320A ambient light sensor" depends on I2Cdrivers/iio/light/Makefile +1
-0@@ -7,6 +7,7 @@ obj-$(CONFIG_ACPI_ALS) += acpi-als.o obj-$(CONFIG_ADJD_S311) += adjd_s311.o obj-$(CONFIG_ADUX1020) += adux1020.o +obj-$(CONFIG_AL3010) += al3010.o obj-$(CONFIG_AL3320A) += al3320a.o obj-$(CONFIG_APDS9300) += apds9300.o obj-$(CONFIG_APDS9960) += apds9960.odrivers/iio/light/al3010.c new file +240
-0@@ -0,0 +1,240 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* AL3010 - Dyna Image Ambient Light Sensor +* +* Copyright (c) 2014, Intel Corporation. +* Copyright (c) 2016, Dyna-Image Corp. +* +* IIO driver for AL3010 (7-bit I2C slave address 0x1C). +* +* TODO: interrupt support, thresholds +* When the driver will get support for interrupt handling, then interrupt +* will need to be disabled before turning sensor OFF in order to avoid +* potential races with the interrupt handling. +*/ + +#include <linux/bitfield.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/of.h> + +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> + +#define AL3010_DRV_NAME "al3010" + +#define AL3010_REG_SYSTEM 0x00 +#define AL3010_REG_DATA_LOW 0x0c +#define AL3010_REG_CONFIG 0x10 + +#define AL3010_CONFIG_DISABLE 0x00 +#define AL3010_CONFIG_ENABLE 0x01 + +#define AL3010_GAIN_MASK (BIT(6) | BIT(5) | BIT(4)) + +#define AL3010_SCALE_AVAILABLE "1.1872 0.2968 0.0742 0.018" + +enum al3xxxx_range { +AL3XXX_RANGE_1 ,/* 77806 lx */ +AL3XXX_RANGE_2 ,/* 19542 lx */ +AL3XXX_RANGE_3 ,/* 4863 lx */ +AL3XXX_RANGE_4 /* 1216 lx */ +}; + +static const int al3010_scales[][2 ] = { + {0 ,1187200 }, {0 ,296800 }, {0 ,74200 }, {0 ,18600 } +}; + +struct al3010_data { +struct i2c_client *client; +}; + +static const struct iio_chan_spec al3010_channels[] = { + { + .type =IIO_LIGHT , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ), + } +}; + +static IIO_CONST_ATTR(in_illuminance_scale_available, AL3010_SCALE_AVAILABLE); + +static struct attribute *al3010_attributes[] = { + &iio_const_attr_in_illuminance_scale_available.dev_attr.attr, +NULL , +}; + +static const struct attribute_group al3010_attribute_group = { + .attrs = al3010_attributes, +}; + +static int al3010_set_pwr (struct i2c_client *client,bool pwr) +{ +u8 val = pwr ?AL3010_CONFIG_ENABLE :AL3010_CONFIG_DISABLE ; +return i2c_smbus_write_byte_data (client,AL3010_REG_SYSTEM , val); +} + +static void al3010_set_pwr_off (void *_data) +{ +struct al3010_data *data = _data; + +al3010_set_pwr (data->client, false); +} + +static int al3010_init (struct al3010_data *data) +{ +int ret; + + ret =al3010_set_pwr (data->client, true); + +if (ret <0 ) +return ret; + + ret =i2c_smbus_write_byte_data (data->client,AL3010_REG_CONFIG , +FIELD_PREP (AL3010_GAIN_MASK , +AL3XXX_RANGE_3 )); +if (ret <0 ) +return ret; + +return 0 ; +} + +static int al3010_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int *val, +int *val2,long mask) +{ +struct al3010_data *data =iio_priv (indio_dev); +int ret; + +switch (mask) { +case IIO_CHAN_INFO_RAW : +/* +* ALS ADC value is stored in two adjacent registers: +* - low byte of output is stored at AL3010_REG_DATA_LOW +* - high byte of output is stored at AL3010_REG_DATA_LOW + 1 +*/ + ret =i2c_smbus_read_word_data (data->client, +AL3010_REG_DATA_LOW ); +if (ret <0 ) +return ret; + *val = ret; +return IIO_VAL_INT ; +case IIO_CHAN_INFO_SCALE : + ret =i2c_smbus_read_byte_data (data->client, +AL3010_REG_CONFIG ); +if (ret <0 ) +return ret; + + ret =FIELD_GET (AL3010_GAIN_MASK , ret); + *val = al3010_scales[ret][0 ]; + *val2 = al3010_scales[ret][1 ]; + +return IIO_VAL_INT_PLUS_MICRO ; + } +return -EINVAL ; +} + +static int al3010_write_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int val, +int val2,long mask) +{ +struct al3010_data *data =iio_priv (indio_dev); +int i; + +switch (mask) { +case IIO_CHAN_INFO_SCALE : +for (i =0 ; i <ARRAY_SIZE (al3010_scales); i++) { +if (val != al3010_scales[i][0 ] || + val2 != al3010_scales[i][1 ]) +continue ; + +return i2c_smbus_write_byte_data (data->client, +AL3010_REG_CONFIG , +FIELD_PREP (AL3010_GAIN_MASK , i)); + } +break ; + } +return -EINVAL ; +} + +static const struct iio_info al3010_info = { + .read_raw = al3010_read_raw, + .write_raw = al3010_write_raw, + .attrs = &al3010_attribute_group, +}; + +static int al3010_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct al3010_data *data; +struct iio_dev *indio_dev; +int ret; + + indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); +if (!indio_dev) +return -ENOMEM ; + + data =iio_priv (indio_dev); +i2c_set_clientdata (client, indio_dev); + data->client = client; + + indio_dev->dev.parent = &client->dev; + indio_dev->info = &al3010_info; + indio_dev->name =AL3010_DRV_NAME ; + indio_dev->channels = al3010_channels; + indio_dev->num_channels =ARRAY_SIZE (al3010_channels); + indio_dev->modes =INDIO_DIRECT_MODE ; + + ret =al3010_init (data); +if (ret <0 ) { +dev_err (&client->dev,"al3010 chip init failed\n" ); +return ret; + } + + ret =devm_add_action_or_reset (&client->dev, + al3010_set_pwr_off, + data); +if (ret <0 ) +return ret; + +return devm_iio_device_register (&client->dev, indio_dev); +} + +static int __maybe_unused al3010_suspend (struct device *dev) +{ +return al3010_set_pwr (to_i2c_client (dev), false); +} + +static int __maybe_unused al3010_resume (struct device *dev) +{ +return al3010_set_pwr (to_i2c_client (dev), true); +} + +SIMPLE_DEV_PM_OPS (al3010_pm_ops, al3010_suspend, al3010_resume); + +static const struct i2c_device_id al3010_id[] = { + {"al3010" , }, + {} +}; +MODULE_DEVICE_TABLE (i2c, al3010_id); + +static const struct of_device_id al3010_of_match[] = { + { .compatible ="dynaimage,al3010" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, al3010_of_match); + +static struct i2c_driver al3010_driver = { + .driver = { + .name =AL3010_DRV_NAME , + .of_match_table = al3010_of_match, + .pm = &al3010_pm_ops, + }, + .probe = al3010_probe, + .id_table = al3010_id, +}; +module_i2c_driver (al3010_driver); + +MODULE_AUTHOR ("Daniel Baluta <[email protected]>" ); +MODULE_DESCRIPTION ("AL3010 Ambient Light Sensor driver" ); +MODULE_LICENSE ("GPL v2" );
Re: [PATCH v4 4/7] iio: light: add Dyna-Image AL3010 driver
06.02.2020 14:48, Jonathan Cameron пишет:
Quoted 24 lines
Quoted 21 lines · On Tue, 4 Feb 2020 10:30:34 +0100 David Heidelberg <[email protected]> wrote:
Based on:
- 3320A in-kernel driver
- https://www.spinics.net/lists/linux-iio/msg25145.html
- https://lore.kernel.org/patchwork/patch/684179/I decided to keep it aside of AL3320A due to different approach and much simpler design of 3010.
Tested on Nexus 7 2012 (grouper/tilapia).
Tested-by David Heidelberg <[email protected]>Tested-by Dmitry Osipenko <[email protected]>Tested-by Michał Mirosław <[email protected]>Reviewed-by Dmitry Osipenko <[email protected]>Signed-off-by David Heidelberg <[email protected]>v4:
- SQUASHed: iio: light: al3010 implement suspend support
- switched from_removetodevm_add_action_or_reset
- implement bitfieldsFIELD_PREP&FIELD_GET, no functionality change
Quoted 6 lines
Quoted 1 line
Signed-off-by David Heidelberg <[email protected]>This is fine as is, but you might want to think about adding basic regulator control as VDD might not be turned on.
Then there is the follow up question on whether it is sensible to disable VDD in the suspend path.
Nexus 7 uses always-ON regulator for the AL3010 VDD. It should be better if VDD enable/disable could be implemented by somebody who could actually test it.
PATCH v4 5/7 iio: light: al3320a implement suspend support
In reply to David HeidelbergAL3320a is fairly simple chip, so for suspend is enough to disable and later enable it again.
--- drivers/iio/light/al3320a.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
drivers/iio/light/al3320a.c +25 -5
@@ -7,6 +7,9 @@* IIO driver for AL3320A (7-bit I2C slave address 0x1C). * * TODO: interrupt support, thresholds +* When the driver will get support for interrupt handling, then interrupt +* will need to be disabled before turning sensor OFF in order to avoid +* potential races with the interrupt handling. */ #include <linux/bitfield.h>
@@ -78,13 +81,18 @@ static const struct attribute_group al3320a_attribute_group = { .attrs = al3320a_attributes, }; +static int al3320a_set_pwr (struct i2c_client *client,bool pwr) +{ +u8 val = pwr ?AL3320A_CONFIG_ENABLE :AL3320A_CONFIG_DISABLE ; +return i2c_smbus_write_byte_data (data->client,AL3320A_REG_CONFIG , val); +} +static int al3320a_init (struct al3320a_data *data) {int ret; -/* power on */ - ret =i2c_smbus_write_byte_data (data->client,AL3320A_REG_CONFIG , -AL3320A_CONFIG_ENABLE ); + ret =al3320a_set_pwr (data->client, true); +if (ret <0 )return ret;
@@ -203,10 +211,21 @@ static int al3320a_probe(struct i2c_client *client,static int al3320a_remove (struct i2c_client *client) { -return i2c_smbus_write_byte_data (client,AL3320A_REG_CONFIG , -AL3320A_CONFIG_DISABLE ); +return al3320a_set_pwr (client, false); } +static int __maybe_unused al3320a_suspend (struct device *dev) +{ +return al3320a_set_pwr (to_i2c_client (dev), false); +} + +static int __maybe_unused al3320a_resume (struct device *dev) +{ +return al3320a_set_pwr (to_i2c_client (dev), true); +} + +SIMPLE_DEV_PM_OPS (al3320a_pm_ops, al3320a_suspend, al3320a_resume); +static const struct i2c_device_id al3320a_id[] = { {"al3320a" ,0 }, {}
@@ -216,6 +235,7 @@ MODULE_DEVICE_TABLE(i2c, al3320a_id);static struct i2c_driver al3320a_driver = { .driver = { .name =AL3320A_DRV_NAME , + .pm = &al3320a_pm_ops, }, .probe = al3320a_probe, .remove = al3320a_remove,
Signature · 1 line
2.25.0
PATCH v4 6/7 iio: light: al3320a implement devm_add_action_or_reset
In reply to David HeidelbergUse devm_add_action_or_reset to automatically disable the device and allow you to get rid of the remove function entirely.
--- drivers/iio/light/al3320a.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/iio/light/al3320a.c +14 -6
@@ -87,6 +87,13 @@ static int al3320a_set_pwr(struct i2c_client *client, bool pwr)return i2c_smbus_write_byte_data (data->client,AL3320A_REG_CONFIG , val); } +static void al3320a_set_pwr_off (void *_data) +{ +struct al3320a_data *data = _data; + +al3320a_set_pwr (data->client, false); +} +static int al3320a_init (struct al3320a_data *data) {int ret;
@@ -206,12 +213,14 @@ static int al3320a_probe(struct i2c_client *client,dev_err (&client->dev,"al3320a chip init failed\n" );return ret; } -return devm_iio_device_register (&client->dev, indio_dev); -} -static int al3320a_remove (struct i2c_client *client) -{ -return al3320a_set_pwr (client, false); + ret =devm_add_action_or_reset (&client->dev, + al3320a_set_pwr_off, + data); +if (ret <0 ) +return ret; + +return devm_iio_device_register (&client->dev, indio_dev); }static int __maybe_unused al3320a_suspend (struct device *dev)
@@ -238,7 +247,6 @@ static struct i2c_driver al3320a_driver = { .pm = &al3320a_pm_ops, }, .probe = al3320a_probe, - .remove = al3320a_remove, .id_table = al3320a_id, };
Signature · 1 line
2.25.0
PATCH v4 7/7 iio: light: al3320a allow module autoload and polish
In reply to David Heidelberg- allow autoloading when build as module and defined inside DT
v4
- dropping of init.h header moved to previous patches
--- drivers/iio/light/al3320a.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/iio/light/al3320a.c +8 -0
@@ -15,6 +15,7 @@#include <linux/bitfield.h> #include <linux/i2c.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h>
@@ -241,9 +242,16 @@ static const struct i2c_device_id al3320a_id[] = { };MODULE_DEVICE_TABLE (i2c, al3320a_id); +static const struct of_device_id al3320a_of_match[] = { + { .compatible ="dynaimage,al3320a" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, al3320a_of_match); +static struct i2c_driver al3320a_driver = { .driver = { .name =AL3320A_DRV_NAME , + .of_match_table = al3320a_of_match, .pm = &al3320a_pm_ops, }, .probe = al3320a_probe,
Signature · 1 line
2.25.0