Skip to contentSkip to conversation

iio: light: add support for TI's opt3001 light sensor

PATCH Applied Andreas Dannenberg 2 participants 10 messages Jul 2, 2015 – Jul 23, 2015 8 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover iio: light: add support for TI's opt3001 light sensor

TI's opt3001 light sensor is a simple and yet powerful little device. The device provides 99% IR rejection, automatic full-scale, very low power consumption and measurements from 0.01 to 83k lux.

This patch adds support for that device using the IIO framework.

See http://www.ti.com/product/opt3001 for more information.

Patch History:
v3
Add "ti,opt3001" device tree compatible string
Add device tree binding documentation
v2 (Addressing feedback from Peter Meerwald + additional fixes)
Fix restoring of IRQ mutex functionality in error case Use managed IIO device alloc/registration
Add parenthesis to improve formula readability
Fix error message number formatting
Improve integration time parameter checks
Clean up redundant return value assignments
Fix broken lookup table algorithm
Fix duplicate lookup table entry
Disallow writing of negative event values

The individual commits can be reviewed at:
http://git.ti.com/cgit/cgit.cgi/ti-analog-linux-kernel/adannenb-analog.git/log/?h=opt3001

 .../devicetree/bindings/iio/light/opt3001.txt      |  18 +
 drivers/iio/light/Kconfig                          |  10 +
 drivers/iio/light/Makefile                         |   1 +
 drivers/iio/light/opt3001.c                        | 804 +++++++++++++++++++++
 4 files changed, 833 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/opt3001.txt
 create mode 100644 drivers/iio/light/opt3001.c
Signature · 1 line
1.9.1
#2 lore raw

PATCH v3 1/2 iio: light: add support for TI's opt3001 light sensor

In reply to a message not in the archive

TI's opt3001 light sensor is a simple and yet powerful little device. The device provides 99% IR rejection, automatic full-scale, very low power consumption and measurements from 0.01 to 83k lux.

This patch adds support for that device using the IIO framework.

See http://www.ti.com/product/opt3001 for more information.

---
 drivers/iio/light/Kconfig   |  10 +
 drivers/iio/light/Makefile  |   1 +
 drivers/iio/light/opt3001.c | 804 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 815 insertions(+)
 create mode 100644 drivers/iio/light/opt3001.c
drivers/iio/light/Kconfig +10 -0
index 01a1a16..665b182 100644
@@ -186,6 +186,16 @@ config TCS3414
 	 This driver can also be built as a module.  If so, the module
 	 will be called tcs3414.
 
+config OPT3001
+	tristate "Texas Instruments OPT3001 Light Sensor"
+	depends on I2C
+	help
+	  If you say Y or M here, you get support for Texas Instruments
+	  OPT3001 Ambient Light Sensor.
+
+	  If built as a dynamically linked module, it will be called
+	  opt3001.
+
 config TCS3472
 	tristate "TAOS TCS3472 color light-to-digital converter"
 	depends on I2C
drivers/iio/light/Makefile +1 -0
index ad7c30f..a498631 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_ISL29125)		+= isl29125.o
 obj-$(CONFIG_JSA1212)		+= jsa1212.o
 obj-$(CONFIG_SENSORS_LM3533)	+= lm3533-als.o
 obj-$(CONFIG_LTR501)		+= ltr501.o
+obj-$(CONFIG_OPT3001)		+= opt3001.o
 obj-$(CONFIG_SENSORS_TSL2563)	+= tsl2563.o
 obj-$(CONFIG_TCS3414)		+= tcs3414.o
 obj-$(CONFIG_TCS3472)		+= tcs3472.o
drivers/iio/light/opt3001.c new file +804 -0

804 lines not on this page · raw message

Signature · 1 line
1.9.1
#9 lore raw

PATCH v3 2/2 iio: light: opt3001: Add device tree binding documentation

In reply to a message not in the archive
---
 .../devicetree/bindings/iio/light/opt3001.txt          | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/opt3001.txt
Documentation/devicetree/bindings/iio/light/opt3001.txt new file +18 -0
new file mode 100644
index 0000000..d5f0765
@@ -0,0 +1,18 @@
+* Texas Instruments OPT3001 Ambient Light Sensor
+
+http://www.ti.com/product/opt3001
+
+Required properties:
+  - compatible: should be "ti,opt3001"
+  - reg: the I2C address of the sensor
+  - interrupt-parent: should be the phandle for the interrupt controller
+  - interrupts: interrupt mapping for GPIO IRQ (configure for falling edge)
+
+Example:
+
+opt3001@44 {
+	compatible = "ti,opt3001";
+	reg = <0x44>;
+	interrupt-parent = <&gpio1>;
+	interrupts = <28 IRQ_TYPE_EDGE_FALLING>;
+};
Signature · 1 line
1.9.1
#4 lore raw
In reply to a message not in the archive
Quoted 5 lines · Andreas Dannenberg

TI's opt3001 light sensor is a simple and yet powerful little device. The device provides 99% IR rejection, automatic full-scale, very low power consumption and measurements from 0.01 to 83k lux.

Quoted 7 lines

This patch adds support for that device using the IIO framework.

See http://www.ti.com/product/opt3001 for more information.

Hi Andreas,

Looking pretty good to me, though I'd like to give Peter time to take another look and give his reviewed-by etc.

One really minor suggestion from me...
<snip>

drivers/iio/light/opt3001.c line 704

Quoted 13 lines
drivers/iio/light/opt3001.c new file +13 -0
+
+static int opt3001_probe(struct i2c_client *client,
+		const struct i2c_device_id *id)
+{
+	struct device *dev = &client->dev;
+
+	struct iio_dev *iio;
+	struct opt3001 *opt;
+	int irq = client->irq;
+	int ret = -ENOMEM;
+
+	iio = devm_iio_device_alloc(dev, sizeof(*opt));
+	if (!iio)

return -ENOMEM; would be cleaner, then there is no need to initialize ret either.

Quoted 101 lines
drivers/iio/light/opt3001.c new file +100 -0
+		return ret;
+
+	opt = iio_priv(iio);
+	opt->client = client;
+	opt->dev = dev;
+
+	mutex_init(&opt->lock);
+	init_waitqueue_head(&opt->result_ready_queue);
+	i2c_set_clientdata(client, iio);
+
+	ret = opt3001_read_id(opt);
+	if (ret)
+		return ret;
+
+	ret = opt3001_configure(opt);
+	if (ret)
+		return ret;
+
+	iio->name = client->name;
+	iio->channels = opt3001_channels;
+	iio->num_channels = ARRAY_SIZE(opt3001_channels);
+	iio->dev.parent = dev;
+	iio->modes = INDIO_DIRECT_MODE;
+	iio->info = &opt3001_info;
+
+	ret = devm_iio_device_register(dev, iio);
+	if (ret) {
+		dev_err(dev, "failed to register IIO device\n");
+		return ret;
+	}
+
+	ret = request_threaded_irq(irq, NULL, opt3001_irq,
+			IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+			"opt3001", iio);
+	if (ret) {
+		dev_err(dev, "failed to request IRQ #%d\n", irq);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int opt3001_remove(struct i2c_client *client)
+{
+	struct iio_dev *iio = i2c_get_clientdata(client);
+	struct opt3001 *opt = iio_priv(iio);
+	int ret;
+	u16 reg;
+
+	free_irq(client->irq, iio);
+
+	ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
+	if (ret < 0) {
+		dev_err(opt->dev, "failed to read register %02x\n",
+				OPT3001_CONFIGURATION);
+		return ret;
+	}
+
+	reg = ret;
+	opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN);
+
+	ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION,
+			reg);
+	if (ret < 0) {
+		dev_err(opt->dev, "failed to write register %02x\n",
+				OPT3001_CONFIGURATION);
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct i2c_device_id opt3001_id[] = {
+	{ "opt3001", 0 },
+	{ } /* Terminating Entry */
+};
+MODULE_DEVICE_TABLE(i2c, opt3001_id);
+
+static const struct of_device_id opt3001_of_match[] = {
+	{ .compatible = "ti,opt3001" },
+	{ }
+};
+
+static struct i2c_driver opt3001_driver = {
+	.probe = opt3001_probe,
+	.remove = opt3001_remove,
+	.id_table = opt3001_id,
+
+	.driver = {
+		.name = "opt3001",
+		.of_match_table = of_match_ptr(opt3001_of_match),
+		.owner = THIS_MODULE,
+	},
+};
+
+module_i2c_driver(opt3001_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Andreas Dannenberg <[email protected]>");
+MODULE_DESCRIPTION("Texas Instruments OPT3001 Light Sensor Driver");
#11 lore raw

Re: [PATCH v3 2/2] iio: light: opt3001: Add device tree binding documentation

In reply to a message not in the archive
Quoted 1 line · Andreas Dannenberg

Utterly standard binding so unless someone shouts, I'll pick this up with the driver.

Thanks,

Jonathan

Quoted 30 lines
---
 .../devicetree/bindings/iio/light/opt3001.txt          | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/opt3001.txt
Documentation/devicetree/bindings/iio/light/opt3001.txt new file +18 -0
new file mode 100644
index 0000000..d5f0765
@@ -0,0 +1,18 @@
+* Texas Instruments OPT3001 Ambient Light Sensor
+
+http://www.ti.com/product/opt3001
+
+Required properties:
+  - compatible: should be "ti,opt3001"
+  - reg: the I2C address of the sensor
+  - interrupt-parent: should be the phandle for the interrupt controller
+  - interrupts: interrupt mapping for GPIO IRQ (configure for falling edge)
+
+Example:
+
+opt3001@44 {
+	compatible = "ti,opt3001";
+	reg = <0x44>;
+	interrupt-parent = <&gpio1>;
+	interrupts = <28 IRQ_TYPE_EDGE_FALLING>;
+};
#6 lore raw
In reply to a message not in the archive

On 07/05/2015 09:08 AM, Jonathan Cameron wrote:
<snip>

Quoted 5 lines

Looking pretty good to me, though I'd like to give Peter time to take another look and give his reviewed-by etc.

One really minor suggestion from me...
<snip>

Quoted 15 lines

drivers/iio/light/opt3001.c line 704

Quoted 13 lines
drivers/iio/light/opt3001.c new file +13 -0
+
+static int opt3001_probe(struct i2c_client *client,
+		const struct i2c_device_id *id)
+{
+	struct device *dev = &client->dev;
+
+	struct iio_dev *iio;
+	struct opt3001 *opt;
+	int irq = client->irq;
+	int ret = -ENOMEM;
+
+	iio = devm_iio_device_alloc(dev, sizeof(*opt));
+	if (!iio)

return -ENOMEM; would be cleaner, then there is no need to initialize ret either.

Hi Jonathan,
thanks for looking at my code. While we are waiting for additional feedback would you like me to go ahead and re-spin/re-test the patch with your latest suggestion?

Regards,

Signature · 7 lines
Andreas Dannenberg
Texas Instruments Inc.

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw
In reply to a message not in the archive
Quoted 23 lines · Andreas Dannenberg

On 07/05/2015 09:08 AM, Jonathan Cameron wrote:
<snip>

Quoted 5 lines

Looking pretty good to me, though I'd like to give Peter time to take another look and give his reviewed-by etc.

One really minor suggestion from me...
<snip>

Quoted 15 lines

drivers/iio/light/opt3001.c line 704

Quoted 13 lines
drivers/iio/light/opt3001.c new file +13 -0
+
+static int opt3001_probe(struct i2c_client *client,
+		const struct i2c_device_id *id)
+{
+	struct device *dev = &client->dev;
+
+	struct iio_dev *iio;
+	struct opt3001 *opt;
+	int irq = client->irq;
+	int ret = -ENOMEM;
+
+	iio = devm_iio_device_alloc(dev, sizeof(*opt));
+	if (!iio)

return -ENOMEM; would be cleaner, then there is no need to initialize ret either.

Quoted 6 lines

Hi Jonathan,
thanks for looking at my code. While we are waiting for additional feedback would you like me to go ahead and re-spin/re-test the patch with your latest suggestion?

Regards,

Not to worry, I made that trivial change when applying. There was also some fuzz in the makefiles and kconfig as a result of other drivers going in, but all trivial.

Applied to the togreg branch of iio.git.

Thanks,

Jonathan

#13 lore raw

Re: [PATCH v3 2/2] iio: light: opt3001: Add device tree binding documentation

In reply to a message not in the archive
Quoted 4 lines · Jonathan Cameron
Quoted 1 line · Andreas Dannenberg

Utterly standard binding so unless someone shouts, I'll pick this up with the driver.

Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 40 lines

Thanks,

Jonathan

Quoted 20 lines
---
 .../devicetree/bindings/iio/light/opt3001.txt          | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/opt3001.txt
Documentation/devicetree/bindings/iio/light/opt3001.txt new file +8 -0
new file mode 100644
index 0000000..d5f0765
@@ -0,0 +1,18 @@
+* Texas Instruments OPT3001 Ambient Light Sensor
+
+http://www.ti.com/product/opt3001
+
+Required properties:
+  - compatible: should be "ti,opt3001"
+  - reg: the I2C address of the sensor
+  - interrupt-parent: should be the phandle for the interrupt controller

Documentation/devicetree/bindings/iio/light/opt3001.txt line 18

Quoted 10 lines
Documentation/devicetree/bindings/iio/light/opt3001.txt new file +10 -0
+  - interrupts: interrupt mapping for GPIO IRQ (configure for falling edge)
+
+Example:
+
+opt3001@44 {
+	compatible = "ti,opt3001";
+	reg = <0x44>;
+	interrupt-parent = <&gpio1>;
+	interrupts = <28 IRQ_TYPE_EDGE_FALLING>;
+};

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#15 lore raw

Re: [PATCH v3 2/2] iio: light: opt3001: Add device tree binding documentation

In reply to a message not in the archive

Hi Jon,

Quoted 7 lines · Jonathan Cameron
Quoted 4 lines · Jonathan Cameron
Quoted 1 line · Andreas Dannenberg

Utterly standard binding so unless someone shouts, I'll pick this up with the driver.

Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.

Thanks. Found it on the 'testing' branch, pulled the entire branch, and successfully re-ran all my HW tests without any findings.

Regards,
Andreas

Signature · 2 lines
Andreas Dannenberg
Texas Instruments Inc.
#17 lore raw

Re: [PATCH v3 2/2] iio: light: opt3001: Add device tree binding documentation

In reply to a message not in the archive
Quoted 8 lines · Andreas Dannenberg

Hi Jon,

Quoted 5 lines · Jonathan Cameron
Quoted 4 lines · Jonathan Cameron
Quoted 1 line · Andreas Dannenberg

Utterly standard binding so unless someone shouts, I'll pick this up with the driver.

Quoted 8 lines
Quoted 2 lines

Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.

Thanks. Found it on the 'testing' branch, pulled the entire branch, and successfully re-ran all my HW tests without any findings.

Regards,
Andreas

That's an impressive level of dedication!

Thanks

Jonathan