Skip to contentSkip to conversation

iio: vcnl4000: Export near level property for proximity sensor

PATCH Superseded Guido Günther 3 participants 12 messages Mar 25, 2020 – Apr 5, 2020

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover iio: vcnl4000: Export near level property for proximity sensor

If an object can be considered close to the device that has the proximity sensor built in is hardware dependent. Allowing to configure the property via device tree allows to export this device specific value to userspace via ext_info. This is useful for e.g. iio-sensor-proxy.

This came up when adding proximity support to iio-sensor-proxy [1], [2], it is not meant as a vcnl4000 thing but rather as something useful for other proximity sensors too in the future.

I've not converted the vcnl4000 binding docs to yaml but can do so as part of this series in a v2 if the approach makes sense.

Changes from v2:
- as per review comment by Lars-Peter Clausen
https://lore.kernel.org/linux-iio/[email protected]/
Switch sysfs name to nearlevel
- as per review comment by Nishant Malpani
https://lore.kernel.org/linux-iio/[email protected]/
Add manufacturer do binding document name
- as per review comments by Andy Shevchenko
- Drop superfluous blank line
- Check return value of device_property_read_u32 for '!= 0' instead of '< 0'

Changes from v1:
- as per review comments by Jonathan Cameron
https://lore.kernel.org/linux-iio/20200221120519.43b72007@archlinux/
Document new sysfs file in Documentation/ABI/testing/sysfs-bus-iio-proximity
- convert bindings to yaml
- bindings: fix typo in near-level property

[1]: https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/merge_requests/298
[2]: https://lore.kernel.org/linux-iio/[email protected]/

To: Tomas Novotny <[email protected]>, Jonathan Cameron <[email protected]>,Hartmut Knaack <[email protected]>,Lars-Peter Clausen <[email protected]>,Peter Meerwald-Stadler <[email protected]>,"Angus Ainslie (Purism)" <[email protected]>,"Guido Günther" <[email protected]>,Marco Felsch <[email protected]>,Thomas Gleixner <[email protected]>,[email protected],[email protected],[email protected], Andy Shevchenko <[email protected]>,Nishant Malpani <[email protected]>

Guido Günther (4):
dt-bindings: iio: vcnl4000: convert bindings to YAML format
dt-bindings: iio: light: vcnl4000: Add near-level
iio: vcnl4000: Export near level property for proximity sensor
Documentation: ABI: document IIO in_proximity_near_level file

 .../ABI/testing/sysfs-bus-iio-proximity       | 10 ++++
 .../bindings/iio/light/vcnl4000.txt           | 24 ---------
 .../bindings/iio/light/vishay,vcnl4000.yaml   | 53 +++++++++++++++++++
 drivers/iio/light/vcnl4000.c                  | 25 +++++++++
 4 files changed, 88 insertions(+), 24 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-proximity
 delete mode 100644 Documentation/devicetree/bindings/iio/light/vcnl4000.txt
 create mode 100644 Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml
Signature · 1 line
2.23.0
#1 lore raw

PATCH v3 1/4 dt-bindings: iio: vcnl4000: convert bindings to YAML format

Convert the vcnl4000 device tree bindings to the new YAML format.

---
 .../bindings/iio/light/vcnl4000.txt           | 24 ----------
 .../bindings/iio/light/vishay,vcnl4000.yaml   | 45 +++++++++++++++++++
 2 files changed, 45 insertions(+), 24 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/iio/light/vcnl4000.txt
 create mode 100644 Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml
Documentation/devicetree/bindings/iio/light/vcnl4000.txt deleted +0 -24
deleted file mode 100644
index 955af4555c90..000000000000
@@ -1,24 +0,0 @@
-VISHAY VCNL4000 -  Ambient Light and proximity sensor
-
-This driver supports the VCNL4000/10/20/40 and VCNL4200 chips
-
-Required properties:
-
-	-compatible: must be one of :
-        vishay,vcnl4000
-        vishay,vcnl4010
-        vishay,vcnl4020
-        vishay,vcnl4040
-        vishay,vcnl4200
-
-	-reg: I2C address of the sensor, should be one from below based on the model:
-        0x13
-        0x51
-        0x60
-
-Example:
-
-light-sensor@51 {
-	compatible = "vishay,vcnl4200";
-	reg = <0x51>;
-};
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.23.0
maintainer Reviewed-by on v3 1/4
#2 lore raw

Re: [PATCH v3 1/4] dt-bindings: iio: vcnl4000: convert bindings to YAML format

Quoted 10 lines · On Wed, 25 Mar 2020 12:09:05 +0100, =?UTF-8?q?Guido=20G=C3=BCnther?= wrote:

Convert the vcnl4000 device tree bindings to the new YAML format.

---
 .../bindings/iio/light/vcnl4000.txt           | 24 ----------
 .../bindings/iio/light/vishay,vcnl4000.yaml   | 45 +++++++++++++++++++
 2 files changed, 45 insertions(+), 24 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/iio/light/vcnl4000.txt
 create mode 100644 Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml
#3 lore raw

PATCH v3 2/4 dt-bindings: iio: light: vcnl4000: Add near-level

In reply to Guido Günther

This value indicates when userspace should consider an object near to the sensor/device.

---
 .../devicetree/bindings/iio/light/vishay,vcnl4000.yaml    | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +8 -0
index 21ef2eb7a205..ac9e3bb6a505 100644
@@ -25,6 +25,13 @@ properties:
   reg:
     maxItems: 1
 
+  near-level:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Raw proximity values equal or above this level should be
+      considered 'near' to the device (an object is near to the
+      sensor).
+
 required:
   - compatible
   - reg
@@ -40,6 +47,7 @@ examples:
       light-sensor@51 {
               compatible = "vishay,vcnl4200";
               reg = <0x51>;
+              near-level = <220>;
       };
   };
 ...
Signature · 1 line
2.23.0
maintainer
#4 lore raw

Re: [PATCH v3 2/4] dt-bindings: iio: light: vcnl4000: Add near-level

Quoted 4 lines · On Wed, 25 Mar 2020 12:09:06 +0100 Guido Günther <[email protected]> wrote:

This value indicates when userspace should consider an object near to the sensor/device.

I'm fine with this. Note for Rob or other DT people.

This is a new generic binding hence no vendor prefix.

I will ideally want review of both the dt patches though before applying. As we've missed the merge window anyway there is no particular rush.

Thanks,

Jonathan

Quoted 30 lines
---
 .../devicetree/bindings/iio/light/vishay,vcnl4000.yaml    | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +8 -0
index 21ef2eb7a205..ac9e3bb6a505 100644
@@ -25,6 +25,13 @@ properties:
   reg:
     maxItems: 1
 
+  near-level:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Raw proximity values equal or above this level should be
+      considered 'near' to the device (an object is near to the
+      sensor).
+
 required:
   - compatible
   - reg
@@ -40,6 +47,7 @@ examples:
       light-sensor@51 {
               compatible = "vishay,vcnl4200";
               reg = <0x51>;
+              near-level = <220>;
       };
   };
...
maintainer
#5 lore raw

Re: [PATCH v3 2/4] dt-bindings: iio: light: vcnl4000: Add near-level

Quoted 11 lines · Jonathan Cameron
Quoted 4 lines · On Wed, 25 Mar 2020 12:09:06 +0100 Guido Günther <[email protected]> wrote:

This value indicates when userspace should consider an object near to the sensor/device.

I'm fine with this. Note for Rob or other DT people.

This is a new generic binding hence no vendor prefix.

Then document in a common place.

Quoted 21 lines

I will ideally want review of both the dt patches though before applying. As we've missed the merge window anyway there is no particular rush.

Thanks,

Jonathan

Quoted 12 lines
---
 .../devicetree/bindings/iio/light/vishay,vcnl4000.yaml    | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +0 -0
index 21ef2eb7a205..ac9e3bb6a505 100644
@@ -25,6 +25,13 @@ properties:
   reg:
     maxItems: 1
 
Quoted 1 line

Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml properties: · line 28

Quoted 1 line
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +1 -0
+  near-level:

Perhaps proximity-near-level instead.

Quoted 18 lines
Quoted 17 lines
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +7 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Raw proximity values equal or above this level should be
+      considered 'near' to the device (an object is near to the
+      sensor).
+
 required:
   - compatible
   - reg
@@ -40,6 +47,7 @@ examples:
       light-sensor@51 {
               compatible = "vishay,vcnl4200";
               reg = <0x51>;
+              near-level = <220>;
       };
   };
...
maintainer
#6 lore raw

Re: [PATCH v3 2/4] dt-bindings: iio: light: vcnl4000: Add near-level

Quoted 7 lines · On Tue, 31 Mar 2020 15:45:17 -0600 Rob Herring <[email protected]> wrote:
Quoted 6 lines · Jonathan Cameron
Quoted 3 lines · On Wed, 25 Mar 2020 12:09:06 +0100 Guido Günther <[email protected]> wrote:

This value indicates when userspace should consider an object near to the sensor/device.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I'm fine with this. Note for Rob or other DT people.

This is a new generic binding hence no vendor prefix.

Then document in a common place.

Ok.

I guess we need to create a proximity specific binding file.

Documentation/devicetree/bindings/iio/proximity.yaml

Guido, could you do a v4 adding such a file. For now I think this is pretty much all that is proximity specific.

At somepoint we should convert the subsystem wide iio-bindings.txt but not today!

Thanks,

Jonathan

Quoted 22 lines
Quoted 22 lines

I will ideally want review of both the dt patches though before applying. As we've missed the merge window anyway there is no particular rush.

Thanks,

Jonathan

Quoted 12 lines
---
 .../devicetree/bindings/iio/light/vishay,vcnl4000.yaml    | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +0 -0
index 21ef2eb7a205..ac9e3bb6a505 100644
@@ -25,6 +25,13 @@ properties:
   reg:
     maxItems: 1
 
Quoted 3 lines
Quoted 1 line

Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml properties: · line 28

Quoted 1 line
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +1 -0
+  near-level:  

Perhaps proximity-near-level instead.

Makes sense.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +7 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Raw proximity values equal or above this level should be
+      considered 'near' to the device (an object is near to the
+      sensor).
+
 required:
   - compatible
   - reg
@@ -40,6 +47,7 @@ examples:
       light-sensor@51 {
               compatible = "vishay,vcnl4200";
               reg = <0x51>;
+              near-level = <220>;
       };
   };
...
#7 lore raw

Re: [PATCH v3 2/4] dt-bindings: iio: light: vcnl4000: Add near-level

Hi,

Quoted 18 lines · Jonathan Cameron
Quoted 7 lines · On Tue, 31 Mar 2020 15:45:17 -0600 Rob Herring <[email protected]> wrote:
Quoted 6 lines · Jonathan Cameron
Quoted 3 lines · On Wed, 25 Mar 2020 12:09:06 +0100 Guido Günther <[email protected]> wrote:

This value indicates when userspace should consider an object near to the sensor/device.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I'm fine with this. Note for Rob or other DT people.

This is a new generic binding hence no vendor prefix.

Then document in a common place.

Quoted 8 lines

Ok.

I guess we need to create a proximity specific binding file.

Documentation/devicetree/bindings/iio/proximity.yaml

Guido, could you do a v4 adding such a file. For now I think this is pretty much all that is proximity specific.

I did a Documentation/devicetree/bindings/iio/common.yaml:

https://source.puri.sm/guido.gunther/linux-imx8/commit/8b91f0b7fa76ca4b2f3cdc251411829f71f8d810

so we can add new properties there and move iio-bindings.txt over.

Does that work as well? If so I'll send out a v4.
Cheers,
-- Guido

Quoted 56 lines

At somepoint we should convert the subsystem wide iio-bindings.txt but not today!

Thanks,

Jonathan

Quoted 22 lines
Quoted 22 lines

I will ideally want review of both the dt patches though before applying. As we've missed the merge window anyway there is no particular rush.

Thanks,

Jonathan

Quoted 12 lines
---
 .../devicetree/bindings/iio/light/vishay,vcnl4000.yaml    | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +0 -0
index 21ef2eb7a205..ac9e3bb6a505 100644
@@ -25,6 +25,13 @@ properties:
   reg:
     maxItems: 1
 
Quoted 3 lines
Quoted 1 line

Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml properties: · line 28

Quoted 1 line
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +1 -0
+  near-level:  

Perhaps proximity-near-level instead.

Makes sense.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +7 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Raw proximity values equal or above this level should be
+      considered 'near' to the device (an object is near to the
+      sensor).
+
 required:
   - compatible
   - reg
@@ -40,6 +47,7 @@ examples:
       light-sensor@51 {
               compatible = "vishay,vcnl4200";
               reg = <0x51>;
+              near-level = <220>;
       };
   };
...
maintainer
#8 lore raw

Re: [PATCH v3 2/4] dt-bindings: iio: light: vcnl4000: Add near-level

Quoted 29 lines · On Sat, 4 Apr 2020 19:45:21 +0200 Guido Günther <[email protected]> wrote:

Hi,

Quoted 18 lines · Jonathan Cameron
Quoted 7 lines · On Tue, 31 Mar 2020 15:45:17 -0600 Rob Herring <[email protected]> wrote:
Quoted 6 lines · Jonathan Cameron
Quoted 3 lines · On Wed, 25 Mar 2020 12:09:06 +0100 Guido Günther <[email protected]> wrote:

This value indicates when userspace should consider an object near to the sensor/device.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I'm fine with this. Note for Rob or other DT people.

This is a new generic binding hence no vendor prefix.

Then document in a common place.

Quoted 8 lines

Ok.

I guess we need to create a proximity specific binding file.

Documentation/devicetree/bindings/iio/proximity.yaml

Guido, could you do a v4 adding such a file. For now I think this is pretty much all that is proximity specific.

Quoted 7 lines

I did a Documentation/devicetree/bindings/iio/common.yaml:

https://source.puri.sm/guido.gunther/linux-imx8/commit/8b91f0b7fa76ca4b2f3cdc251411829f71f8d810

so we can add new properties there and move iio-bindings.txt over.

Does that work as well? If so I'll send out a v4.

I can't find any real precedence for naming of such files.
So I guess this is still evolving. Send it out and we'll see what Rob thinks.

Jonathan

Quoted 60 lines

Cheers,
-- Guido

Quoted 56 lines

At somepoint we should convert the subsystem wide iio-bindings.txt but not today!

Thanks,

Jonathan

Quoted 22 lines
Quoted 22 lines

I will ideally want review of both the dt patches though before applying. As we've missed the merge window anyway there is no particular rush.

Thanks,

Jonathan

Quoted 12 lines
---
 .../devicetree/bindings/iio/light/vishay,vcnl4000.yaml    | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +0 -0
index 21ef2eb7a205..ac9e3bb6a505 100644
@@ -25,6 +25,13 @@ properties:
   reg:
     maxItems: 1
 
Quoted 3 lines
Quoted 1 line

Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml properties: · line 28

Quoted 1 line
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +1 -0
+  near-level:    

Perhaps proximity-near-level instead.

Makes sense.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Documentation/devicetree/bindings/iio/light/vishay,vcnl4000.yaml +7 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Raw proximity values equal or above this level should be
+      considered 'near' to the device (an object is near to the
+      sensor).
+
 required:
   - compatible
   - reg
@@ -40,6 +47,7 @@ examples:
       light-sensor@51 {
               compatible = "vishay,vcnl4200";
               reg = <0x51>;
+              near-level = <220>;
       };
   };
...
#9 lore raw

PATCH v3 3/4 iio: vcnl4000: Export near level property for proximity sensor

In reply to Guido Günther

When an object can be considered close to the sensor is hardware dependent. Allowing to configure the property via device tree allows to configure this device specific value.

This is useful for e.g. iio-sensor-proxy to indicate to userspace if an object is close to the sensor.

---
 drivers/iio/light/vcnl4000.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/iio/light/vcnl4000.c +25 -0
index ec803c1e81df..a4bac101549e 100644
@@ -83,6 +83,7 @@ struct vcnl4000_data {
 	struct mutex vcnl4000_lock;
 	struct vcnl4200_channel vcnl4200_al;
 	struct vcnl4200_channel vcnl4200_ps;
+	uint32_t near_level;
 };
 
 struct vcnl4000_chip_spec {
@@ -343,6 +344,25 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = {
 	},
 };
 
+static ssize_t vcnl4000_read_near_level(struct iio_dev *indio_dev,
+					uintptr_t priv,
+					const struct iio_chan_spec *chan,
+					char *buf)
+{
+	struct vcnl4000_data *data = iio_priv(indio_dev);
+
+	return sprintf(buf, "%u\n", data->near_level);
+}
+
+static const struct iio_chan_spec_ext_info vcnl4000_ext_info[] = {
+	{
+		.name = "nearlevel",
+		.shared = IIO_SEPARATE,
+		.read = vcnl4000_read_near_level,
+	},
+	{ /* sentinel */ }
+};
+
 static const struct iio_chan_spec vcnl4000_channels[] = {
 	{
 		.type = IIO_LIGHT,
@@ -351,6 +371,7 @@ static const struct iio_chan_spec vcnl4000_channels[] = {
 	}, {
 		.type = IIO_PROXIMITY,
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+		.ext_info = vcnl4000_ext_info,
 	}
 };
 
@@ -440,6 +461,10 @@ static int vcnl4000_probe(struct i2c_client *client,
 	dev_dbg(&client->dev, "%s Ambient light/proximity sensor, Rev: %02x\n",
 		data->chip_spec->prod, data->rev);
 
+	if (device_property_read_u32(&client->dev, "near-level",
+				     &data->near_level))
+		data->near_level = 0;
+
 	indio_dev->dev.parent = &client->dev;
 	indio_dev->info = &vcnl4000_info;
 	indio_dev->channels = vcnl4000_channels;
Signature · 1 line
2.23.0
#10 lore raw

PATCH v3 4/4 Documentation: ABI: document IIO in_proximity_near_level file

In reply to Guido Günther

The vcnl4000 IIO driver introduced a new attribute "in_proximity_near_level". This adds it to the list of documented ABI for sysfs-bus-iio.

---
 Documentation/ABI/testing/sysfs-bus-iio-proximity | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-proximity
Documentation/ABI/testing/sysfs-bus-iio-proximity new file +10 -0
new file mode 100644
index 000000000000..2172f3bb9c64
@@ -0,0 +1,10 @@
+What:		/sys/bus/iio/devices/iio:deviceX/in_proximity_nearlevel
+Date:		March 2020
+KernelVersion:	5.7
+Contact:	[email protected]
+Description:
+		Near level for proximity sensors. This is a single integer
+		value that tells user space when an object should be
+		considered close to the device. If the value read from the
+		sensor is above or equal to the value in this file an object
+		should typically be considered near.
Signature · 1 line
2.23.0
maintainer
#11 lore raw

Re: [PATCH v3 4/4] Documentation: ABI: document IIO in_proximity_near_level file

Quoted 3 lines · On Wed, 25 Mar 2020 12:09:08 +0100 Guido Günther <[email protected]> wrote:

The vcnl4000 IIO driver introduced a new attribute "in_proximity_near_level". This adds it to the list of documented ABI for sysfs-bus-iio.

Description and patch title are now wrong due to dropping the _

I can fix that up whilst applying if nothing else comes up.

The rest of the series looks good to me, just giving time for others to comment before taking this.

Thanks,

Jonathan

Quoted 23 lines
---
 Documentation/ABI/testing/sysfs-bus-iio-proximity | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-proximity
Documentation/ABI/testing/sysfs-bus-iio-proximity new file +10 -0
new file mode 100644
index 000000000000..2172f3bb9c64
@@ -0,0 +1,10 @@
+What:		/sys/bus/iio/devices/iio:deviceX/in_proximity_nearlevel
+Date:		March 2020
+KernelVersion:	5.7
+Contact:	[email protected]
+Description:
+		Near level for proximity sensors. This is a single integer
+		value that tells user space when an object should be
+		considered close to the device. If the value read from the
+		sensor is above or equal to the value in this file an object
+		should typically be considered near.