Linux-IIO Archive on lore.kernel.org
 help / Atom feed
* [PATCH v2] iio: chemical: sps30: add support for self cleaning
@ 2018-12-18 20:28 Tomasz Duszynski
  2018-12-22 17:23 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Tomasz Duszynski @ 2018-12-18 20:28 UTC (permalink / raw)
  To: linux-iio; +Cc: linux-kernel, Tomasz Duszynski

Self cleaning is especially useful in cases where sensor undergoes
frequent power on/off cycles. In such scenarios it is recommended to
turn self cleaning at least once per week in order to maintain reliable
measurements.

Self cleaning is activated by writing 1 to a dedicated attribute.
Internal fan accelerates to its maximum speed and keeps spinning
for about 10 seconds blowing out accumulated dust.

Signed-off-by: Tomasz Duszynski <tduszyns@gmail.com>
---
v2:
 * removed TODO item
 * sensor cleaning is not measurement related per se so drop in_ prefix

 Documentation/ABI/testing/sysfs-bus-iio-sps30 |  8 +++++
 drivers/iio/chemical/sps30.c                  | 35 ++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-sps30

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-sps30 b/Documentation/ABI/testing/sysfs-bus-iio-sps30
new file mode 100644
index 000000000000..e7ce2c57635e
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-sps30
@@ -0,0 +1,8 @@
+What:		/sys/bus/iio/devices/iio:deviceX/start_cleaning
+Date:		December 2018
+KernelVersion:	4.22
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Writing 1 starts sensor self cleaning. Internal fan accelerates
+		to its maximum speed and keeps spinning for about 10 seconds in
+		order to blow out accumulated dust.
diff --git a/drivers/iio/chemical/sps30.c b/drivers/iio/chemical/sps30.c
index fa3cd409b90b..f3b4390c8f5c 100644
--- a/drivers/iio/chemical/sps30.c
+++ b/drivers/iio/chemical/sps30.c
@@ -7,7 +7,6 @@
  * I2C slave address: 0x69
  *
  * TODO:
- *  - support for turning on fan cleaning
  *  - support for reading/setting auto cleaning interval
  */

@@ -37,6 +36,7 @@
 #define SPS30_READ_DATA_READY_FLAG 0x0202
 #define SPS30_READ_DATA 0x0300
 #define SPS30_READ_SERIAL 0xd033
+#define SPS30_START_FAN_CLEANING 0x5607

 enum {
 	PM1,
@@ -104,6 +104,7 @@ static int sps30_do_cmd(struct sps30_state *state, u16 cmd, u8 *data, int size)
 		break;
 	case SPS30_STOP_MEAS:
 	case SPS30_RESET:
+	case SPS30_START_FAN_CLEANING:
 		ret = sps30_write_then_read(state, buf, 2, NULL, 0);
 		break;
 	case SPS30_READ_DATA_READY_FLAG:
@@ -275,7 +276,39 @@ static int sps30_read_raw(struct iio_dev *indio_dev,
 	return -EINVAL;
 }

+static ssize_t start_cleaning_store(struct device *dev,
+				    struct device_attribute *attr,
+				    const char *buf, size_t len)
+{
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	struct sps30_state *state = iio_priv(indio_dev);
+	int val, ret;
+
+	if (kstrtoint(buf, 0, &val) || val != 1)
+		return -EINVAL;
+
+	mutex_lock(&state->lock);
+	ret = sps30_do_cmd(state, SPS30_START_FAN_CLEANING, NULL, 0);
+	mutex_unlock(&state->lock);
+	if (ret)
+		return ret;
+
+	return len;
+}
+
+static IIO_DEVICE_ATTR_WO(start_cleaning, 0);
+
+static struct attribute *sps30_attrs[] = {
+	&iio_dev_attr_start_cleaning.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group sps30_attr_group = {
+	.attrs = sps30_attrs,
+};
+
 static const struct iio_info sps30_info = {
+	.attrs = &sps30_attr_group,
 	.read_raw = sps30_read_raw,
 };

--
2.20.1


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

* Re: [PATCH v2] iio: chemical: sps30: add support for self cleaning
  2018-12-18 20:28 [PATCH v2] iio: chemical: sps30: add support for self cleaning Tomasz Duszynski
@ 2018-12-22 17:23 ` Jonathan Cameron
  2018-12-28 14:47   ` Andreas Brauchli
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2018-12-22 17:23 UTC (permalink / raw)
  To: Tomasz Duszynski; +Cc: linux-iio, linux-kernel

On Tue, 18 Dec 2018 21:28:09 +0100
Tomasz Duszynski <tduszyns@gmail.com> wrote:

> Self cleaning is especially useful in cases where sensor undergoes
> frequent power on/off cycles. In such scenarios it is recommended to
> turn self cleaning at least once per week in order to maintain reliable
> measurements.
> 
> Self cleaning is activated by writing 1 to a dedicated attribute.
> Internal fan accelerates to its maximum speed and keeps spinning
> for about 10 seconds blowing out accumulated dust.
> 
> Signed-off-by: Tomasz Duszynski <tduszyns@gmail.com>
Applied to the togreg branch of iio.git.   I took this today rather than
leaving it on the list for longer simply because I'm not sure I'll be
very timely in applying patches.

If anyone has any comments, it'll only be out as testing so we can
still modify if that make sense for at least the next couple of weeks.

Thanks,

Jonathan

> ---
> v2:
>  * removed TODO item
>  * sensor cleaning is not measurement related per se so drop in_ prefix
> 
>  Documentation/ABI/testing/sysfs-bus-iio-sps30 |  8 +++++
>  drivers/iio/chemical/sps30.c                  | 35 ++++++++++++++++++-
>  2 files changed, 42 insertions(+), 1 deletion(-)
>  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-sps30
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-sps30 b/Documentation/ABI/testing/sysfs-bus-iio-sps30
> new file mode 100644
> index 000000000000..e7ce2c57635e
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-sps30
> @@ -0,0 +1,8 @@
> +What:		/sys/bus/iio/devices/iio:deviceX/start_cleaning
> +Date:		December 2018
> +KernelVersion:	4.22
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		Writing 1 starts sensor self cleaning. Internal fan accelerates
> +		to its maximum speed and keeps spinning for about 10 seconds in
> +		order to blow out accumulated dust.
> diff --git a/drivers/iio/chemical/sps30.c b/drivers/iio/chemical/sps30.c
> index fa3cd409b90b..f3b4390c8f5c 100644
> --- a/drivers/iio/chemical/sps30.c
> +++ b/drivers/iio/chemical/sps30.c
> @@ -7,7 +7,6 @@
>   * I2C slave address: 0x69
>   *
>   * TODO:
> - *  - support for turning on fan cleaning
>   *  - support for reading/setting auto cleaning interval
>   */
> 
> @@ -37,6 +36,7 @@
>  #define SPS30_READ_DATA_READY_FLAG 0x0202
>  #define SPS30_READ_DATA 0x0300
>  #define SPS30_READ_SERIAL 0xd033
> +#define SPS30_START_FAN_CLEANING 0x5607
> 
>  enum {
>  	PM1,
> @@ -104,6 +104,7 @@ static int sps30_do_cmd(struct sps30_state *state, u16 cmd, u8 *data, int size)
>  		break;
>  	case SPS30_STOP_MEAS:
>  	case SPS30_RESET:
> +	case SPS30_START_FAN_CLEANING:
>  		ret = sps30_write_then_read(state, buf, 2, NULL, 0);
>  		break;
>  	case SPS30_READ_DATA_READY_FLAG:
> @@ -275,7 +276,39 @@ static int sps30_read_raw(struct iio_dev *indio_dev,
>  	return -EINVAL;
>  }
> 
> +static ssize_t start_cleaning_store(struct device *dev,
> +				    struct device_attribute *attr,
> +				    const char *buf, size_t len)
> +{
> +	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> +	struct sps30_state *state = iio_priv(indio_dev);
> +	int val, ret;
> +
> +	if (kstrtoint(buf, 0, &val) || val != 1)
> +		return -EINVAL;
> +
> +	mutex_lock(&state->lock);
> +	ret = sps30_do_cmd(state, SPS30_START_FAN_CLEANING, NULL, 0);
> +	mutex_unlock(&state->lock);
> +	if (ret)
> +		return ret;
> +
> +	return len;
> +}
> +
> +static IIO_DEVICE_ATTR_WO(start_cleaning, 0);
> +
> +static struct attribute *sps30_attrs[] = {
> +	&iio_dev_attr_start_cleaning.dev_attr.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group sps30_attr_group = {
> +	.attrs = sps30_attrs,
> +};
> +
>  static const struct iio_info sps30_info = {
> +	.attrs = &sps30_attr_group,
>  	.read_raw = sps30_read_raw,
>  };
> 
> --
> 2.20.1
> 


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

* Re: [PATCH v2] iio: chemical: sps30: add support for self cleaning
  2018-12-22 17:23 ` Jonathan Cameron
@ 2018-12-28 14:47   ` Andreas Brauchli
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Brauchli @ 2018-12-28 14:47 UTC (permalink / raw)
  To: Jonathan Cameron, Tomasz Duszynski
  Cc: andreas.brauchli, linux-iio, linux-kernel

On Sat, 22 Dec 2018 17:23:46 +0000
Jonathan Cameron <jic23@kernel.org> wrote:

> On Tue, 18 Dec 2018 21:28:09 +0100
> Tomasz Duszynski <tduszyns@gmail.com> wrote:
> 
> > Self cleaning is especially useful in cases where sensor undergoes
> > frequent power on/off cycles. In such scenarios it is recommended to
> > turn self cleaning at least once per week in order to maintain reliable
> > measurements.
> > 
> > Self cleaning is activated by writing 1 to a dedicated attribute.
> > Internal fan accelerates to its maximum speed and keeps spinning
> > for about 10 seconds blowing out accumulated dust.
> > 
> > Signed-off-by: Tomasz Duszynski <tduszyns@gmail.com>
> Applied to the togreg branch of iio.git.   I took this today rather than
> leaving it on the list for longer simply because I'm not sure I'll be
> very timely in applying patches.
> 
> If anyone has any comments, it'll only be out as testing so we can
> still modify if that make sense for at least the next couple of weeks.

I backported and tested the whole series on a 4.9.53 raspberry pi with an SPS30.

Tested-by: Andreas Brauchli <andreas.brauchli@sensirion.com>

Cheers,
Andreas

> 
> Thanks,
> 
> Jonathan
> 
> > ---
> > v2:
> >  * removed TODO item
> >  * sensor cleaning is not measurement related per se so drop in_ prefix
> > 
> >  Documentation/ABI/testing/sysfs-bus-iio-sps30 |  8 +++++
> >  drivers/iio/chemical/sps30.c                  | 35 ++++++++++++++++++-
> >  2 files changed, 42 insertions(+), 1 deletion(-)
> >  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-sps30
> > 
> > diff --git a/Documentation/ABI/testing/sysfs-bus-iio-sps30
> b/Documentation/ABI/testing/sysfs-bus-iio-sps30
> > new file mode 100644
> > index 000000000000..e7ce2c57635e
> > --- /dev/null
> > +++ b/Documentation/ABI/testing/sysfs-bus-iio-sps30
> > @@ -0,0 +1,8 @@
> > +What:		/sys/bus/iio/devices/iio:deviceX/start_cleaning
> > +Date:		December 2018
> > +KernelVersion:	4.22
> > +Contact:	linux-iio@vger.kernel.org
> > +Description:
> > +		Writing 1 starts sensor self cleaning. Internal fan accelerates
> > +		to its maximum speed and keeps spinning for about 10 seconds in
> > +		order to blow out accumulated dust.
> > diff --git a/drivers/iio/chemical/sps30.c b/drivers/iio/chemical/sps30.c
> > index fa3cd409b90b..f3b4390c8f5c 100644
> > --- a/drivers/iio/chemical/sps30.c
> > +++ b/drivers/iio/chemical/sps30.c
> > @@ -7,7 +7,6 @@
> >   * I2C slave address: 0x69
> >   *
> >   * TODO:
> > - *  - support for turning on fan cleaning
> >   *  - support for reading/setting auto cleaning interval
> >   */
> > 
> > @@ -37,6 +36,7 @@
> >  #define SPS30_READ_DATA_READY_FLAG 0x0202
> >  #define SPS30_READ_DATA 0x0300
> >  #define SPS30_READ_SERIAL 0xd033
> > +#define SPS30_START_FAN_CLEANING 0x5607
> > 
> >  enum {
> >  	PM1,
> > @@ -104,6 +104,7 @@ static int sps30_do_cmd(struct sps30_state *state, u16 cmd, u8 *data, int
> size)
> >  		break;
> >  	case SPS30_STOP_MEAS:
> >  	case SPS30_RESET:
> > +	case SPS30_START_FAN_CLEANING:
> >  		ret = sps30_write_then_read(state, buf, 2, NULL, 0);
> >  		break;
> >  	case SPS30_READ_DATA_READY_FLAG:
> > @@ -275,7 +276,39 @@ static int sps30_read_raw(struct iio_dev *indio_dev,
> >  	return -EINVAL;
> >  }
> > 
> > +static ssize_t start_cleaning_store(struct device *dev,
> > +				    struct device_attribute *attr,
> > +				    const char *buf, size_t len)
> > +{
> > +	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> > +	struct sps30_state *state = iio_priv(indio_dev);
> > +	int val, ret;
> > +
> > +	if (kstrtoint(buf, 0, &val) || val != 1)
> > +		return -EINVAL;
> > +
> > +	mutex_lock(&state->lock);
> > +	ret = sps30_do_cmd(state, SPS30_START_FAN_CLEANING, NULL, 0);
> > +	mutex_unlock(&state->lock);
> > +	if (ret)
> > +		return ret;
> > +
> > +	return len;
> > +}
> > +
> > +static IIO_DEVICE_ATTR_WO(start_cleaning, 0);
> > +
> > +static struct attribute *sps30_attrs[] = {
> > +	&iio_dev_attr_start_cleaning.dev_attr.attr,
> > +	NULL
> > +};
> > +
> > +static const struct attribute_group sps30_attr_group = {
> > +	.attrs = sps30_attrs,
> > +};
> > +
> >  static const struct iio_info sps30_info = {
> > +	.attrs = &sps30_attr_group,
> >  	.read_raw = sps30_read_raw,
> >  };
> > 
> > --
> > 2.20.1
> > 

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-18 20:28 [PATCH v2] iio: chemical: sps30: add support for self cleaning Tomasz Duszynski
2018-12-22 17:23 ` Jonathan Cameron
2018-12-28 14:47   ` Andreas Brauchli

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox