linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] iio: stk3310: Export near level property for proximity sensor
@ 2022-04-20 11:25 Arnaud Ferraris
  2022-04-20 11:25 ` [PATCH v2 1/2] dt-bindings: iio: light: stk33xx: Add proximity-near-level Arnaud Ferraris
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Arnaud Ferraris @ 2022-04-20 11:25 UTC (permalink / raw)
  To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring, Krzysztof Kozlowski
  Cc: linux-iio, devicetree, linux-kernel, kernel

Userspace tools like iio-sensor-proxy need to be instructed the value from
which they should consider an object is "near". This threshold can be
exported through the sysfs ABI based on the "proximity-near-level"
device-tree property.

This patchset implements this property for the stk3310 driver and adds the
necessary bits to export its value to userspace. It is based on similar
changes applied to the vcnl4000 and ltr501 drivers.

Changes in v2:
  - drop zero-assignment as the variable won't be modified if DT property
    is missing

Arnaud Ferraris (2):
  dt-bindings: iio: light: stk33xx: Add proximity-near-level
  iio: stk3310: Export near level property for proximity sensor

 .../bindings/iio/light/stk33xx.yaml           |  6 +++++
 drivers/iio/light/stk3310.c                   | 25 +++++++++++++++++++
 2 files changed, 31 insertions(+)

-- 
2.35.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] dt-bindings: iio: light: stk33xx: Add proximity-near-level
  2022-04-20 11:25 [PATCH v2 0/2] iio: stk3310: Export near level property for proximity sensor Arnaud Ferraris
@ 2022-04-20 11:25 ` Arnaud Ferraris
  2022-04-21  7:30   ` Krzysztof Kozlowski
  2022-04-20 11:25 ` [PATCH v2 2/2] iio: stk3310: Export near level property for proximity sensor Arnaud Ferraris
  2022-04-24 16:57 ` [PATCH v2 0/2] " Jonathan Cameron
  2 siblings, 1 reply; 5+ messages in thread
From: Arnaud Ferraris @ 2022-04-20 11:25 UTC (permalink / raw)
  To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring, Krzysztof Kozlowski
  Cc: linux-iio, devicetree, linux-kernel, kernel

This allows exporting the value from which userspace should assert an
object is "near".

Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
---
 Documentation/devicetree/bindings/iio/light/stk33xx.yaml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/light/stk33xx.yaml b/Documentation/devicetree/bindings/iio/light/stk33xx.yaml
index f92bf7b2b7f0..f6e22dc9814a 100644
--- a/Documentation/devicetree/bindings/iio/light/stk33xx.yaml
+++ b/Documentation/devicetree/bindings/iio/light/stk33xx.yaml
@@ -13,6 +13,9 @@ maintainers:
 description: |
   Ambient light and proximity sensor over an i2c interface.
 
+allOf:
+  - $ref: ../common.yaml#
+
 properties:
   compatible:
     enum:
@@ -26,6 +29,8 @@ properties:
   interrupts:
     maxItems: 1
 
+  proximity-near-level: true
+
 required:
   - compatible
   - reg
@@ -44,6 +49,7 @@ examples:
         stk3310@48 {
                 compatible = "sensortek,stk3310";
                 reg = <0x48>;
+                proximity-near-level = <25>;
                 interrupt-parent = <&gpio1>;
                 interrupts = <5 IRQ_TYPE_LEVEL_LOW>;
         };
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] iio: stk3310: Export near level property for proximity sensor
  2022-04-20 11:25 [PATCH v2 0/2] iio: stk3310: Export near level property for proximity sensor Arnaud Ferraris
  2022-04-20 11:25 ` [PATCH v2 1/2] dt-bindings: iio: light: stk33xx: Add proximity-near-level Arnaud Ferraris
@ 2022-04-20 11:25 ` Arnaud Ferraris
  2022-04-24 16:57 ` [PATCH v2 0/2] " Jonathan Cameron
  2 siblings, 0 replies; 5+ messages in thread
From: Arnaud Ferraris @ 2022-04-20 11:25 UTC (permalink / raw)
  To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring, Krzysztof Kozlowski
  Cc: linux-iio, devicetree, linux-kernel, kernel

This makes the value from which an object should be considered "near"
available to userspace. This hardware-dependent value should be set
in the device-tree.

Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
---
Changes in v2:
  - drop zero-assignment as the variable won't be set if DT property is
    missing

 drivers/iio/light/stk3310.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
index 1d02dfbc29d1..b578b46276cc 100644
--- a/drivers/iio/light/stk3310.c
+++ b/drivers/iio/light/stk3310.c
@@ -106,6 +106,7 @@ struct stk3310_data {
 	struct mutex lock;
 	bool als_enabled;
 	bool ps_enabled;
+	uint32_t ps_near_level;
 	u64 timestamp;
 	struct regmap *regmap;
 	struct regmap_field *reg_state;
@@ -135,6 +136,25 @@ static const struct iio_event_spec stk3310_events[] = {
 	},
 };
 
+static ssize_t stk3310_read_near_level(struct iio_dev *indio_dev,
+				       uintptr_t priv,
+				       const struct iio_chan_spec *chan,
+				       char *buf)
+{
+	struct stk3310_data *data = iio_priv(indio_dev);
+
+	return sprintf(buf, "%u\n", data->ps_near_level);
+}
+
+static const struct iio_chan_spec_ext_info stk3310_ext_info[] = {
+	{
+		.name = "nearlevel",
+		.shared = IIO_SEPARATE,
+		.read = stk3310_read_near_level,
+	},
+	{ /* sentinel */ }
+};
+
 static const struct iio_chan_spec stk3310_channels[] = {
 	{
 		.type = IIO_LIGHT,
@@ -151,6 +171,7 @@ static const struct iio_chan_spec stk3310_channels[] = {
 			BIT(IIO_CHAN_INFO_INT_TIME),
 		.event_spec = stk3310_events,
 		.num_event_specs = ARRAY_SIZE(stk3310_events),
+		.ext_info = stk3310_ext_info,
 	}
 };
 
@@ -581,6 +602,10 @@ static int stk3310_probe(struct i2c_client *client,
 	data = iio_priv(indio_dev);
 	data->client = client;
 	i2c_set_clientdata(client, indio_dev);
+
+	device_property_read_u32(&client->dev, "proximity-near-level",
+				 &data->ps_near_level);
+
 	mutex_init(&data->lock);
 
 	ret = stk3310_regmap_init(data);
-- 
2.35.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] dt-bindings: iio: light: stk33xx: Add proximity-near-level
  2022-04-20 11:25 ` [PATCH v2 1/2] dt-bindings: iio: light: stk33xx: Add proximity-near-level Arnaud Ferraris
@ 2022-04-21  7:30   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-21  7:30 UTC (permalink / raw)
  To: Arnaud Ferraris, Jonathan Cameron, Lars-Peter Clausen,
	Rob Herring, Krzysztof Kozlowski
  Cc: linux-iio, devicetree, linux-kernel, kernel

On 20/04/2022 13:25, Arnaud Ferraris wrote:
> This allows exporting the value from which userspace should assert an
> object is "near".
> 
> Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] iio: stk3310: Export near level property for proximity sensor
  2022-04-20 11:25 [PATCH v2 0/2] iio: stk3310: Export near level property for proximity sensor Arnaud Ferraris
  2022-04-20 11:25 ` [PATCH v2 1/2] dt-bindings: iio: light: stk33xx: Add proximity-near-level Arnaud Ferraris
  2022-04-20 11:25 ` [PATCH v2 2/2] iio: stk3310: Export near level property for proximity sensor Arnaud Ferraris
@ 2022-04-24 16:57 ` Jonathan Cameron
  2 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2022-04-24 16:57 UTC (permalink / raw)
  To: Arnaud Ferraris
  Cc: Lars-Peter Clausen, Rob Herring, Krzysztof Kozlowski, linux-iio,
	devicetree, linux-kernel, kernel

On Wed, 20 Apr 2022 13:25:38 +0200
Arnaud Ferraris <arnaud.ferraris@collabora.com> wrote:

> Userspace tools like iio-sensor-proxy need to be instructed the value from
> which they should consider an object is "near". This threshold can be
> exported through the sysfs ABI based on the "proximity-near-level"
> device-tree property.
> 
> This patchset implements this property for the stk3310 driver and adds the
> necessary bits to export its value to userspace. It is based on similar
> changes applied to the vcnl4000 and ltr501 drivers.
> 
Series applied to the togreg branch of iio.git and pushed out as testing for
0-day to work it's magic.

Thanks,

Jonathan

> Changes in v2:
>   - drop zero-assignment as the variable won't be modified if DT property
>     is missing
> 
> Arnaud Ferraris (2):
>   dt-bindings: iio: light: stk33xx: Add proximity-near-level
>   iio: stk3310: Export near level property for proximity sensor
> 
>  .../bindings/iio/light/stk33xx.yaml           |  6 +++++
>  drivers/iio/light/stk3310.c                   | 25 +++++++++++++++++++
>  2 files changed, 31 insertions(+)
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-04-24 16:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20 11:25 [PATCH v2 0/2] iio: stk3310: Export near level property for proximity sensor Arnaud Ferraris
2022-04-20 11:25 ` [PATCH v2 1/2] dt-bindings: iio: light: stk33xx: Add proximity-near-level Arnaud Ferraris
2022-04-21  7:30   ` Krzysztof Kozlowski
2022-04-20 11:25 ` [PATCH v2 2/2] iio: stk3310: Export near level property for proximity sensor Arnaud Ferraris
2022-04-24 16:57 ` [PATCH v2 0/2] " Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).