iio: light: AL3010 introduction
Subsystems (2)
cover iio: light: 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).
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: al3010 implement suspend support
iio: light: al3320a implement suspend support
iio: light: al3320a allow module autoload and polish
.../devicetree/bindings/iio/light/al3010.yaml | 40 +++ .../bindings/iio/light/al3320a.yaml | 40 +++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/al3010.c | 237 ++++++++++++++++++ drivers/iio/light/al3320a.c | 63 +++-- 7 files changed, 379 insertions(+), 14 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 v2 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.
Partly based on unmerged commit:
"iio: Add Dyna-Image AP3223 ambient light and proximity driver"
--- .../bindings/iio/light/al3320a.yaml | 40 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 42 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/al3320a.yaml
Documentation/devicetree/bindings/iio/light/al3320a.yaml new file +40 -0
@@ -0,0 +1,40 @@ +# 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 + - interrupt + - vdd-supply + +examples: + - | + i2c { + 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 v2 1/7] dt-bindings: iio: light: add support for Dyna-Image AL3320A
Quoted 5 lines · David Heidelberg
This commit add dt-bindings support to al3320a driver and vendor-prefix dynaimage.
Partly based on unmerged commit:
"iio: Add Dyna-Image AP3223 ambient light and proximity driver"
Quoted 7 lines
Signed-off-by David Heidelberg <[email protected]>--- .../bindings/iio/light/al3320a.yaml | 40 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 42 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/al3320a.yaml
My bot found errors running 'make dt_binding_check' on your patch:
Documentation/devicetree/bindings/display/simple-framebuffer.example.dts:21.16-37.11: Warning (chosen_node_is_root): /example-0/chosen: chosen node must be at root node Documentation/devicetree/bindings/iio/light/al3320a.example.dts:20.17-30: Warning (reg_format): /example-0/i2c/al3320a@1c:reg: property has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1) Documentation/devicetree/bindings/iio/light/al3320a.example.dt.yaml: Warning (pci_device_bus_num): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/light/al3320a.example.dts:17.5-24.11: Warning (i2c_bus_bridge): /example-0/i2c: incorrect #address-cells for I2C bus Documentation/devicetree/bindings/iio/light/al3320a.example.dts:17.5-24.11: Warning (i2c_bus_bridge): /example-0/i2c: incorrect #size-cells for I2C bus Documentation/devicetree/bindings/iio/light/al3320a.example.dt.yaml: Warning (i2c_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/light/al3320a.example.dt.yaml: Warning (i2c_bus_reg): Failed prerequisite 'i2c_bus_bridge' Documentation/devicetree/bindings/iio/light/al3320a.example.dt.yaml: Warning (spi_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/light/al3320a.example.dts:18.24-23.15: Warning (avoid_default_addr_size): /example-0/i2c/al3320a@1c: Relying on default #address-cells value Documentation/devicetree/bindings/iio/light/al3320a.example.dts:18.24-23.15: Warning (avoid_default_addr_size): /example-0/i2c/al3320a@1c: Relying on default #size-cells value /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/light/al3320a.example.dt.yaml: al3320a@1c: 'interrupt' is a required property
See https://patchwork.ozlabs.org/patch/1230353
Please check and re-submit.
PATCH v2 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 | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/al3010.yaml
Documentation/devicetree/bindings/iio/light/al3010.yaml new file +40 -0
@@ -0,0 +1,40 @@ +# 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 + - interrupt + - vdd-supply + +examples: + - | + i2c { + al3010@1c { + compatible = "dynaimage,al3010"; + reg = <0x1c>; + vdd-supply = <&vdd_reg>; + interrupts = <0 99 4>; + }; + };
Signature · 1 line
2.25.0
Re: [PATCH v2 2/7] dt-bindings: iio: light: add support for Dyna-Image AL3010
28.01.2020 16:30, David Heidelberg пишет:
Quoted 6 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.
Signed-off-by David Heidelberg <[email protected]>---
Rob Herring
maintainerRe: [PATCH v2 2/7] dt-bindings: iio: light: add support for Dyna-Image AL3010
In reply to David HeidelbergQuoted 10 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.
Signed-off-by David Heidelberg <[email protected]>--- .../devicetree/bindings/iio/light/al3010.yaml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/al3010.yaml
My bot found errors running 'make dt_binding_check' on your patch:
Documentation/devicetree/bindings/display/simple-framebuffer.example.dts:21.16-37.11: Warning (chosen_node_is_root): /example-0/chosen: chosen node must be at root node Documentation/devicetree/bindings/iio/light/al3010.example.dts:20.17-30: Warning (reg_format): /example-0/i2c/al3010@1c:reg: property has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1) Documentation/devicetree/bindings/iio/light/al3010.example.dt.yaml: Warning (pci_device_bus_num): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/light/al3010.example.dts:17.5-24.11: Warning (i2c_bus_bridge): /example-0/i2c: incorrect #address-cells for I2C bus Documentation/devicetree/bindings/iio/light/al3010.example.dts:17.5-24.11: Warning (i2c_bus_bridge): /example-0/i2c: incorrect #size-cells for I2C bus Documentation/devicetree/bindings/iio/light/al3010.example.dt.yaml: Warning (i2c_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/light/al3010.example.dt.yaml: Warning (i2c_bus_reg): Failed prerequisite 'i2c_bus_bridge' Documentation/devicetree/bindings/iio/light/al3010.example.dt.yaml: Warning (spi_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/light/al3010.example.dts:18.23-23.15: Warning (avoid_default_addr_size): /example-0/i2c/al3010@1c: Relying on default #address-cells value Documentation/devicetree/bindings/iio/light/al3010.example.dts:18.23-23.15: Warning (avoid_default_addr_size): /example-0/i2c/al3010@1c: Relying on default #size-cells value /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/light/al3010.example.dt.yaml: al3010@1c: 'interrupt' is a required property
See https://patchwork.ozlabs.org/patch/1230351
Please check and re-submit.
Re: [PATCH v2 2/7] dt-bindings: iio: light: add support for Dyna-Image AL3010
31.01.2020 17:24, Rob Herring пишет:
Quoted 26 lines · David Heidelberg
Quoted 10 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.
Signed-off-by David Heidelberg <[email protected]>--- .../devicetree/bindings/iio/light/al3010.yaml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/al3010.yamlMy bot found errors running 'make
dt_binding_check' on your patch:Documentation/devicetree/bindings/display/simple-framebuffer.example.dts:21.16-37.11: Warning (
chosen_node_is_root): /example-0/chosen: chosen node must be at root node Documentation/devicetree/bindings/iio/light/al3010.example.dts:20.17-30: Warning (reg_format): /example-0/i2c/al3010@1c:reg: property has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)Documentation/devicetree/bindings/iio/light/al3010.example.dt.yaml: Warning (pci_device_bus_num): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/light/al3010.example.dts:17.5-24.11: Warning (i2c_bus_bridge): /example-0/i2c: incorrect #address-cells for I2C bus Documentation/devicetree/bindings/iio/light/al3010.example.dts:17.5-24.11: Warning (i2c_bus_bridge): /example-0/i2c: incorrect #size-cells for I2C busDocumentation/devicetree/bindings/iio/light/al3010.example.dt.yaml: Warning (i2c_bus_reg): Failed prerequisite 'reg_format'Documentation/devicetree/bindings/iio/light/al3010.example.dt.yaml: Warning (i2c_bus_reg): Failed prerequisite 'i2c_bus_bridge'Documentation/devicetree/bindings/iio/light/al3010.example.dt.yaml: Warning (spi_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/light/al3010.example.dts:18.23-23.15: Warning (avoid_default_addr_size): /example-0/i2c/al3010@1c: Relying on default #address-cells value Documentation/devicetree/bindings/iio/light/al3010.example.dts:18.23-23.15: Warning (avoid_default_addr_size): /example-0/i2c/al3010@1c: Relying on default #size-cells value /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/light/al3010.example.dt.yaml: al3010@1c: 'interrupt' is a required property
Quoted 3 lines
See https://patchwork.ozlabs.org/patch/1230351
Please check and re-submit.
The bot is right.
Documentation/devicetree/bindings/iio/light/al3010.yaml line 28
Quoted 5 lines
Documentation/devicetree/bindings/iio/light/al3010.yaml new file +4
-0+required: + - compatible + - reg + - interrupt
^ (s) is missing
Quoted 1 line
+ - vdd-supply
PATCH v2 3/7 iio: light: al3320a slightly improve code formatting
In reply to David HeidelbergModified to be in part with al3010 driver.
--- drivers/iio/light/al3320a.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/iio/light/al3320a.c +14 -7
@@ -38,6 +38,11 @@#define AL3320A_GAIN_SHIFT 1#define AL3320A_GAIN_MASK (BIT(2) | BIT(1)) +#define AL3320A_GAIN_READ (g) \ + (((g) & AL3320A_GAIN_MASK) >> AL3320A_GAIN_SHIFT) +#define AL3320A_GAIN_WRITE (g) \ + (((g) << AL3320A_GAIN_SHIFT) & AL3320A_GAIN_MASK) +/* chip params default values */ #define AL3320A_DEFAULT_MEAN_TIME 4
@@ -90,7 +95,7 @@ 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 ); +AL3320A_GAIN_WRITE (AL3320A_RANGE_3 ));if (ret <0 )return ret;
@@ -133,7 +138,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 =AL3320A_GAIN_READ (ret); *val = al3320a_scales[ret][0 ]; *val2 = al3320a_scales[ret][1 ];
@@ -152,11 +157,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, -AL3320A_REG_CONFIG_RANGE , - i <<AL3320A_GAIN_SHIFT ); +if (val != al3320a_scales[i][0 ] || + val2 != al3320a_scales[i][1 ]) +continue ; + +return i2c_smbus_write_byte_data (data->client, +AL3320A_REG_CONFIG_RANGE , +AL3320A_GAIN_WRITE (i)); }break ; }
Signature · 1 line
2.25.0
PATCH v2 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).
--- drivers/iio/light/Kconfig | 10 ++ drivers/iio/light/Makefile | 1 + drivers/iio/light/al3010.c | 217 +++++++++++++++++++++++++++++++++++++ 3 files changed, 228 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 +217 -0
217 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH v2 5/7 iio: light: al3010 implement suspend support
In reply to David HeidelbergAL3010 is fairly simple chip, so for suspend is enough to disable and later enable it again.
--- drivers/iio/light/al3010.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
drivers/iio/light/al3010.c +25 -5
@@ -8,6 +8,9 @@* 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/i2c.h>
@@ -71,13 +74,18 @@ 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 int al3010_init (struct al3010_data *data) {int ret; -/* power on */ - ret =i2c_smbus_write_byte_data (data->client,AL3010_REG_SYSTEM , -AL3010_CONFIG_ENABLE ); + ret =al3010_set_pwr (data->client, true); +if (ret <0 )return ret;
@@ -185,10 +193,21 @@ static int al3010_probe(struct i2c_client *client,static int al3010_remove (struct i2c_client *client) { -return i2c_smbus_write_byte_data (client,AL3010_REG_SYSTEM , -AL3010_CONFIG_DISABLE ); +return al3010_set_pwr (client, false); } +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" ,0 }, {}
@@ -205,6 +224,7 @@ static struct i2c_driver al3010_driver = { .driver = { .name = AL3010_DRV_NAME, .of_match_table = al3010_of_match, + .pm = &al3010_pm_ops, }, .probe = al3010_probe, .remove = al3010_remove,
Signature · 1 line
2.25.0
Re: [PATCH v2 5/7] iio: light: al3010 implement suspend support
28.01.2020 16:30, David Heidelberg пишет:
Quoted 7 lines
AL3010 is fairly simple chip, so for suspend is enough to disable and later enable it again.
Signed-off-by David Heidelberg <[email protected]>--- drivers/iio/light/al3010.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
PATCH v2 6/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 | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-)
drivers/iio/light/al3320a.c +26 -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/module.h>
@@ -84,13 +87,19 @@ 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;
@@ -208,10 +217,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 }, {}
@@ -221,6 +241,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 v2 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
- drop init.h and alphabetically sort includes
--- drivers/iio/light/al3320a.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/iio/light/al3320a.c +9 -2
@@ -12,9 +12,9 @@* potential races with the interrupt handling. */ -#include <linux/module.h> -#include <linux/init.h> #include <linux/i2c.h> +#include <linux/module.h> +#include <linux/of.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h>
@@ -238,9 +238,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