kernel: bump 4.14 to 4.14.172
[openwrt/staging/rmilecki.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 diff --git a/Documentation/ABI/testing/sysfs-bus-iio-sps30 b/Documentation/ABI/testing/sysfs-bus-iio-sps30
25 new file mode 100644
26 index 000000000000..e7ce2c57635e
27 --- /dev/null
28 +++ b/Documentation/ABI/testing/sysfs-bus-iio-sps30
29 @@ -0,0 +1,8 @@
30 +What: /sys/bus/iio/devices/iio:deviceX/start_cleaning
31 +Date: December 2018
32 +KernelVersion: 4.22
33 +Contact: linux-iio@vger.kernel.org
34 +Description:
35 + Writing 1 starts sensor self cleaning. Internal fan accelerates
36 + to its maximum speed and keeps spinning for about 10 seconds in
37 + order to blow out accumulated dust.
38 diff --git a/drivers/iio/chemical/sps30.c b/drivers/iio/chemical/sps30.c
39 index fa3cd409b90b..f3b4390c8f5c 100644
40 --- a/drivers/iio/chemical/sps30.c
41 +++ b/drivers/iio/chemical/sps30.c
42 @@ -7,7 +7,6 @@
43 * I2C slave address: 0x69
44 *
45 * TODO:
46 - * - support for turning on fan cleaning
47 * - support for reading/setting auto cleaning interval
48 */
49
50 @@ -37,6 +36,7 @@
51 #define SPS30_READ_DATA_READY_FLAG 0x0202
52 #define SPS30_READ_DATA 0x0300
53 #define SPS30_READ_SERIAL 0xd033
54 +#define SPS30_START_FAN_CLEANING 0x5607
55
56 enum {
57 PM1,
58 @@ -104,6 +104,7 @@ static int sps30_do_cmd(struct sps30_state *state, u16 cmd, u8 *data, int size)
59 break;
60 case SPS30_STOP_MEAS:
61 case SPS30_RESET:
62 + case SPS30_START_FAN_CLEANING:
63 ret = sps30_write_then_read(state, buf, 2, NULL, 0);
64 break;
65 case SPS30_READ_DATA_READY_FLAG:
66 @@ -275,7 +276,39 @@ static int sps30_read_raw(struct iio_dev *indio_dev,
67 return -EINVAL;
68 }
69
70 +static ssize_t start_cleaning_store(struct device *dev,
71 + struct device_attribute *attr,
72 + const char *buf, size_t len)
73 +{
74 + struct iio_dev *indio_dev = dev_to_iio_dev(dev);
75 + struct sps30_state *state = iio_priv(indio_dev);
76 + int val, ret;
77 +
78 + if (kstrtoint(buf, 0, &val) || val != 1)
79 + return -EINVAL;
80 +
81 + mutex_lock(&state->lock);
82 + ret = sps30_do_cmd(state, SPS30_START_FAN_CLEANING, NULL, 0);
83 + mutex_unlock(&state->lock);
84 + if (ret)
85 + return ret;
86 +
87 + return len;
88 +}
89 +
90 +static IIO_DEVICE_ATTR_WO(start_cleaning, 0);
91 +
92 +static struct attribute *sps30_attrs[] = {
93 + &iio_dev_attr_start_cleaning.dev_attr.attr,
94 + NULL
95 +};
96 +
97 +static const struct attribute_group sps30_attr_group = {
98 + .attrs = sps30_attrs,
99 +};
100 +
101 static const struct iio_info sps30_info = {
102 + .attrs = &sps30_attr_group,
103 .read_raw = sps30_read_raw,
104 };
105