kernel: bump 4.19 to 4.19.108
[openwrt/staging/chunkeey.git] / target / linux / generic / backport-4.19 / 501-v5.1-iio-chemical-sps30-add-support-for-self-cleaning.patch
1 From c546d49656143855093c7b7fde60866e6e23a69d Mon Sep 17 00:00:00 2001
2 From: Tomasz Duszynski <tduszyns@gmail.com>
3 Date: Tue, 18 Dec 2018 21:28:09 +0100
4 Subject: [PATCH] iio: chemical: sps30: add support for self cleaning
5
6 Self cleaning is especially useful in cases where sensor undergoes
7 frequent power on/off cycles. In such scenarios it is recommended to
8 turn self cleaning at least once per week in order to maintain reliable
9 measurements.
10
11 Self cleaning is activated by writing 1 to a dedicated attribute.
12 Internal fan accelerates to its maximum speed and keeps spinning
13 for about 10 seconds blowing out accumulated dust.
14
15 Signed-off-by: Tomasz Duszynski <tduszyns@gmail.com>
16 Tested-by: Andreas Brauchli <andreas.brauchli@sensirion.com>
17 Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
18 ---
19 Documentation/ABI/testing/sysfs-bus-iio-sps30 | 8 +++++
20 drivers/iio/chemical/sps30.c | 35 ++++++++++++++++++-
21 2 files changed, 42 insertions(+), 1 deletion(-)
22 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-sps30
23
24 --- /dev/null
25 +++ b/Documentation/ABI/testing/sysfs-bus-iio-sps30
26 @@ -0,0 +1,8 @@
27 +What: /sys/bus/iio/devices/iio:deviceX/start_cleaning
28 +Date: December 2018
29 +KernelVersion: 4.22
30 +Contact: linux-iio@vger.kernel.org
31 +Description:
32 + Writing 1 starts sensor self cleaning. Internal fan accelerates
33 + to its maximum speed and keeps spinning for about 10 seconds in
34 + order to blow out accumulated dust.
35 --- a/drivers/iio/chemical/sps30.c
36 +++ b/drivers/iio/chemical/sps30.c
37 @@ -7,7 +7,6 @@
38 * I2C slave address: 0x69
39 *
40 * TODO:
41 - * - support for turning on fan cleaning
42 * - support for reading/setting auto cleaning interval
43 */
44
45 @@ -37,6 +36,7 @@
46 #define SPS30_READ_DATA_READY_FLAG 0x0202
47 #define SPS30_READ_DATA 0x0300
48 #define SPS30_READ_SERIAL 0xd033
49 +#define SPS30_START_FAN_CLEANING 0x5607
50
51 enum {
52 PM1,
53 @@ -104,6 +104,7 @@ static int sps30_do_cmd(struct sps30_sta
54 break;
55 case SPS30_STOP_MEAS:
56 case SPS30_RESET:
57 + case SPS30_START_FAN_CLEANING:
58 ret = sps30_write_then_read(state, buf, 2, NULL, 0);
59 break;
60 case SPS30_READ_DATA_READY_FLAG:
61 @@ -275,7 +276,39 @@ static int sps30_read_raw(struct iio_dev
62 return -EINVAL;
63 }
64
65 +static ssize_t start_cleaning_store(struct device *dev,
66 + struct device_attribute *attr,
67 + const char *buf, size_t len)
68 +{
69 + struct iio_dev *indio_dev = dev_to_iio_dev(dev);
70 + struct sps30_state *state = iio_priv(indio_dev);
71 + int val, ret;
72 +
73 + if (kstrtoint(buf, 0, &val) || val != 1)
74 + return -EINVAL;
75 +
76 + mutex_lock(&state->lock);
77 + ret = sps30_do_cmd(state, SPS30_START_FAN_CLEANING, NULL, 0);
78 + mutex_unlock(&state->lock);
79 + if (ret)
80 + return ret;
81 +
82 + return len;
83 +}
84 +
85 +static IIO_DEVICE_ATTR_WO(start_cleaning, 0);
86 +
87 +static struct attribute *sps30_attrs[] = {
88 + &iio_dev_attr_start_cleaning.dev_attr.attr,
89 + NULL
90 +};
91 +
92 +static const struct attribute_group sps30_attr_group = {
93 + .attrs = sps30_attrs,
94 +};
95 +
96 static const struct iio_info sps30_info = {
97 + .attrs = &sps30_attr_group,
98 .read_raw = sps30_read_raw,
99 };
100