Skip to content

Commit af5ab55

Browse files
Hunterteaegggroeck
authored andcommitted
hwmon: (sht3x) Add new non-stardard sysfs attribute
Add "repeatability" attribute to sysfs, it could be read or written to control the sensor. Signed-off-by: JuenKit Yip <JuenKit_Yip@hotmail.com> Link: https://lore.kernel.org/r/DB4PR10MB6261B507C7656E3568DA33E39258A@DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM [groeck: Fixed multi-line alignment; dropped check of unsigned against < 0] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 3d2c211 commit af5ab55

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

Documentation/hwmon/sht3x.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ The device communicates with the I2C protocol. Sensors can have the I2C
2828
addresses 0x44 or 0x45, depending on the wiring. See
2929
Documentation/i2c/instantiating-devices.rst for methods to instantiate the device.
3030

31-
There is only one option configurable by means of sht3x_data:
32-
33-
repeatability: high repeatability is used by default and using it is
34-
strongly recommended.
35-
3631
Even if sht3x sensor supports clock-strech(blocking mode) and non-strench
3732
(non-blocking mode) in single-shot mode, this driver only supports the latter.
3833

@@ -83,4 +78,11 @@ heater_enable: heater enable, heating element removes excess humidity from
8378
update_interval: update interval, 0 for single shot, interval in msec
8479
for periodic measurement. If the interval is not supported
8580
by the sensor, the next faster interval is chosen
81+
repeatability: write or read repeatability, higher repeatability means
82+
longer measurement duration, lower noise level and
83+
larger energy consumption:
84+
85+
- 0: low repeatability
86+
- 1: medium repeatability
87+
- 2: high repeatability
8688
=================== ============================================================

drivers/hwmon/sht3x.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,37 @@ static ssize_t update_interval_store(struct device *dev,
637637
return count;
638638
}
639639

640+
static ssize_t repeatability_show(struct device *dev,
641+
struct device_attribute *attr,
642+
char *buf)
643+
{
644+
struct sht3x_data *data = dev_get_drvdata(dev);
645+
646+
return sysfs_emit(buf, "%d\n", data->repeatability);
647+
}
648+
649+
static ssize_t repeatability_store(struct device *dev,
650+
struct device_attribute *attr,
651+
const char *buf,
652+
size_t count)
653+
{
654+
int ret;
655+
u8 val;
656+
657+
struct sht3x_data *data = dev_get_drvdata(dev);
658+
659+
ret = kstrtou8(buf, 0, &val);
660+
if (ret)
661+
return ret;
662+
663+
if (val > 2)
664+
return -EINVAL;
665+
666+
data->repeatability = val;
667+
668+
return count;
669+
}
670+
640671
static SENSOR_DEVICE_ATTR_RO(temp1_input, temp1_input, 0);
641672
static SENSOR_DEVICE_ATTR_RO(humidity1_input, humidity1_input, 0);
642673
static SENSOR_DEVICE_ATTR_RW(temp1_max, temp1_limit, limit_max);
@@ -653,6 +684,7 @@ static SENSOR_DEVICE_ATTR_RO(temp1_alarm, temp1_alarm, 0);
653684
static SENSOR_DEVICE_ATTR_RO(humidity1_alarm, humidity1_alarm, 0);
654685
static SENSOR_DEVICE_ATTR_RW(heater_enable, heater_enable, 0);
655686
static SENSOR_DEVICE_ATTR_RW(update_interval, update_interval, 0);
687+
static SENSOR_DEVICE_ATTR_RW(repeatability, repeatability, 0);
656688

657689
static struct attribute *sht3x_attrs[] = {
658690
&sensor_dev_attr_temp1_input.dev_attr.attr,
@@ -669,6 +701,7 @@ static struct attribute *sht3x_attrs[] = {
669701
&sensor_dev_attr_humidity1_alarm.dev_attr.attr,
670702
&sensor_dev_attr_heater_enable.dev_attr.attr,
671703
&sensor_dev_attr_update_interval.dev_attr.attr,
704+
&sensor_dev_attr_repeatability.dev_attr.attr,
672705
NULL
673706
};
674707

0 commit comments

Comments
 (0)