Linux IIO development
 help / color / mirror / Atom feed
From: Arnaud Ferraris <arnaud.ferraris@collabora.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel@collabora.com
Subject: Re: [PATCH 2/2] iio: stk3310: Export near level property for proximity sensor
Date: Wed, 20 Apr 2022 11:36:20 +0200	[thread overview]
Message-ID: <9b1cb44f-43dc-8926-9dab-00032ab59640@collabora.com> (raw)
In-Reply-To: <20220416172651.695d4439@jic23-huawei>

Hi Jonathan,

Le 16/04/2022 à 18:26, Jonathan Cameron a écrit :
> On Fri, 15 Apr 2022 10:50:18 +0200
> Arnaud Ferraris <arnaud.ferraris@collabora.com> wrote:
> 
>> 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>
> Hi Arnaud,
> 
> Minor request to slightly modify how you do this inline.
> Otherwise looks good to me.
> 
> Thanks,
> 
> Jonathan
> 
>> ---
>>   drivers/iio/light/stk3310.c | 26 ++++++++++++++++++++++++++
>>   1 file changed, 26 insertions(+)
>>
>> diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
>> index 1d02dfbc29d1..7792456323ef 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,11 @@ static int stk3310_probe(struct i2c_client *client,
>>   	data = iio_priv(indio_dev);
>>   	data->client = client;
>>   	i2c_set_clientdata(client, indio_dev);
>> +
>> +	if (device_property_read_u32(&client->dev, "proximity-near-level",
>> +				     &data->ps_near_level))
>> +		data->ps_near_level = 0;
> 
> Prefer this pattern.
> 
> 	data->ps_near_level = 0;
> 	device_property_read_u32(&client->dev, "proximity-near-level",
> 				 &data->ps_near_level);
> taking advantage of the fact that the output won't be set unless
> the property read succeeds.

That's a good suggestion indeed! We can even get rid of the initial 
assignment as the struct is zero-initialized on alloc, will send a v2 in 
a moment.

Thanks,
Arnaud

> 
>> +
>>   	mutex_init(&data->lock);
>>   
>>   	ret = stk3310_regmap_init(data);
> 

      reply	other threads:[~2022-04-20  9:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15  8:50 [PATCH 0/2] iio: stk3310: Export near level property for proximity sensor Arnaud Ferraris
2022-04-15  8:50 ` [PATCH 1/2] dt-bindings: iio: light: stk33xx: Add proximity-near-level Arnaud Ferraris
2022-04-15  8:50 ` [PATCH 2/2] iio: stk3310: Export near level property for proximity sensor Arnaud Ferraris
2022-04-16 16:26   ` Jonathan Cameron
2022-04-20  9:36     ` Arnaud Ferraris [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9b1cb44f-43dc-8926-9dab-00032ab59640@collabora.com \
    --to=arnaud.ferraris@collabora.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=kernel@collabora.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox