public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Roan van Dijk <roan@protonic.nl>
Cc: Jonathan Cameron <Jonathan.Cameron@Huawei.com>,
	lars@metafoo.de, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: chemical: scd4x: Add pressure compensation
Date: Sat, 8 Jul 2023 15:33:34 +0100	[thread overview]
Message-ID: <20230708153334.034995d9@jic23-huawei> (raw)
In-Reply-To: <e575a7b0-20a4-39c6-9fa5-87185108e683@protonic.nl>

On Thu, 6 Jul 2023 14:27:26 +0200
Roan van Dijk <roan@protonic.nl> wrote:

> It seems I missed that one, didn't know it you can't have a channel with 
> only calibias.
> In the next version of this patch I will change it to an output channel 
> like the other cases.
> I saw the scd30 did this as well.
It's not so much that you can't have such a channel, more that we seem
to have sort of standardized on using a straight forward output for this.

Doesn't change the suggestion for this patch, but there 'might' be a usecase
for such a channel in the future..

Jonathan

> 
> Roan
> 
> On 06-07-2023 03:28, Jonathan Cameron wrote:
> > On Tue,  4 Jul 2023 10:47:06 +0200
> > Roan van Dijk<roan@protonic.nl>  wrote:
> >  
> >> This patch adds pressure compensation to the scd4x driver. The pressure can
> >> be written to the sensor in hPa. The pressure will be compensated
> >> internally by the sensor.
> >>
> >> Signed-off-by: Roan van Dijk<roan@protonic.nl>  
> > Why treat this as a channel with just calibbias?
> >  From what I can recall we've previous treated such cases as an
> > output channel with the advantage that the units are then fully
> > defined.  I may well be forgetting some argument or a case that
> > does it with calibbias though.
> >
> > Jonathan
> >
> >  
> >> ---
> >>   drivers/iio/chemical/scd4x.c | 41 +++++++++++++++++++++++++++++++++---
> >>   1 file changed, 38 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/iio/chemical/scd4x.c b/drivers/iio/chemical/scd4x.c
> >> index a4f22d926400..fe6b3f3f7186 100644
> >> --- a/drivers/iio/chemical/scd4x.c
> >> +++ b/drivers/iio/chemical/scd4x.c
> >> @@ -36,6 +36,8 @@
> >>   #define SCD4X_WRITE_BUF_SIZE 5
> >>   #define SCD4X_FRC_MIN_PPM 0
> >>   #define SCD4X_FRC_MAX_PPM 2000
> >> +#define SCD4X_AMB_PRESSURE_MIN 700
> >> +#define SCD4X_AMB_PRESSURE_MAX 1200
> >>   #define SCD4X_READY_MASK 0x01
> >>   
> >>   /*Commands SCD4X*/
> >> @@ -45,6 +47,8 @@ enum scd4x_cmd {
> >>   	CMD_STOP_MEAS           = 0x3f86,
> >>   	CMD_SET_TEMP_OFFSET     = 0x241d,
> >>   	CMD_GET_TEMP_OFFSET     = 0x2318,
> >> +	CMD_SET_AMB_PRESSURE	= 0xe000,
> >> +	CMD_GET_AMB_PRESSURE	= 0xe000,
> >>   	CMD_FRC                 = 0x362f,
> >>   	CMD_SET_ASC             = 0x2416,
> >>   	CMD_GET_ASC             = 0x2313,
> >> @@ -373,7 +377,10 @@ static int scd4x_read_raw(struct iio_dev *indio_dev,
> >>   		return IIO_VAL_INT_PLUS_MICRO;
> >>   	case IIO_CHAN_INFO_CALIBBIAS:
> >>   		mutex_lock(&state->lock);
> >> -		ret = scd4x_read(state, CMD_GET_TEMP_OFFSET, &tmp, sizeof(tmp));
> >> +		if (chan->type == IIO_TEMP)
> >> +			ret = scd4x_read(state, CMD_GET_TEMP_OFFSET, &tmp, sizeof(tmp));
> >> +		else if (chan->type == IIO_PRESSURE)
> >> +			ret = scd4x_read(state, CMD_GET_AMB_PRESSURE, &tmp, sizeof(tmp));
> >>   		mutex_unlock(&state->lock);
> >>   		if (ret)
> >>   			return ret;
> >> @@ -386,6 +393,25 @@ static int scd4x_read_raw(struct iio_dev *indio_dev,
> >>   	}
> >>   }
> >>   
> >> +static const int scd4x_pressure_calibbias_available[] = {
> >> +	SCD4X_AMB_PRESSURE_MIN, 1, SCD4X_AMB_PRESSURE_MAX,
> >> +};
> >> +
> >> +static int scd4x_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
> >> +			    const int **vals, int *type, int *length, long mask)
> >> +{
> >> +	switch (mask) {
> >> +	case IIO_CHAN_INFO_CALIBBIAS:
> >> +		*vals = scd4x_pressure_calibbias_available;
> >> +		*type = IIO_VAL_INT;
> >> +
> >> +		return IIO_AVAIL_RANGE;
> >> +	}
> >> +
> >> +	return -EINVAL;
> >> +}
> >> +
> >> +
> >>   static int scd4x_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
> >>   				int val, int val2, long mask)
> >>   {
> >> @@ -395,9 +421,11 @@ static int scd4x_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const
> >>   	switch (mask) {
> >>   	case IIO_CHAN_INFO_CALIBBIAS:
> >>   		mutex_lock(&state->lock);
> >> -		ret = scd4x_write(state, CMD_SET_TEMP_OFFSET, val);
> >> +		if (chan->type == IIO_TEMP)
> >> +			ret = scd4x_write(state, CMD_SET_TEMP_OFFSET, val);
> >> +		else if (chan->type == IIO_PRESSURE)
> >> +			ret = scd4x_write(state, CMD_SET_AMB_PRESSURE, val);
> >>   		mutex_unlock(&state->lock);
> >> -
> >>   		return ret;
> >>   	default:
> >>   		return -EINVAL;
> >> @@ -503,9 +531,16 @@ static const struct iio_info scd4x_info = {
> >>   	.attrs = &scd4x_attr_group,
> >>   	.read_raw = scd4x_read_raw,
> >>   	.write_raw = scd4x_write_raw,
> >> +	.read_avail = scd4x_read_avail,
> >>   };
> >>   
> >>   static const struct iio_chan_spec scd4x_channels[] = {
> >> +	{
> >> +		.type = IIO_PRESSURE,
> >> +		.info_mask_separate = BIT(IIO_CHAN_INFO_CALIBBIAS),
> >> +		.info_mask_separate_available = BIT(IIO_CHAN_INFO_CALIBBIAS),
> >> +		.scan_index = -1,
> >> +	},
> >>   	{
> >>   		.type = IIO_CONCENTRATION,
> >>   		.channel2 = IIO_MOD_CO2,  


      parent reply	other threads:[~2023-07-08 14:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-04  8:47 [PATCH] iio: chemical: scd4x: Add pressure compensation Roan van Dijk
2023-07-04 11:34 ` kernel test robot
2023-07-05 13:03 ` Dan Carpenter
2023-07-06  1:28 ` Jonathan Cameron
     [not found]   ` <e575a7b0-20a4-39c6-9fa5-87185108e683@protonic.nl>
2023-07-08 14:33     ` Jonathan Cameron [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=20230708153334.034995d9@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@Huawei.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roan@protonic.nl \
    /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