Skip to contentSkip to conversation

hwmon: (sht3x)remove blocking_io property

PATCH Applied JuenKit Yip 2 participants 10 messages Jun 16, 2023 – Jun 17, 2023 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 2/6 hwmon: (sht3x)remove blocking_io property

Due to no support on clock-strench, blocking mode was removed and now single-shot mode only uses non-blocking mode.

---
 Documentation/hwmon/sht3x.rst | 14 ++++++--------
 drivers/hwmon/sht3x.c         | 33 +++++++++++----------------------
 2 files changed, 17 insertions(+), 30 deletions(-)
Documentation/hwmon/sht3x.rst +6 -8
index 31fd36b14..be70e2543 100644
@@ -28,16 +28,14 @@ The device communicates with the I2C protocol. Sensors can have the I2C
 addresses 0x44 or 0x45, depending on the wiring. See
 Documentation/i2c/instantiating-devices.rst for methods to instantiate the device.
 
-There are two options configurable by means of sht3x_data:
-
-1. blocking (pull the I2C clock line down while performing the measurement) or
-   non-blocking mode. Blocking mode will guarantee the fastest result but
-   the I2C bus will be busy during that time. By default, non-blocking mode
-   is used. Make sure clock-stretching works properly on your device if you
-   want to use blocking mode.
-2. high or low accuracy. High accuracy is used by default and using it is
+There is only one option configurable by means of sht3x_data:
+
+   high or low accuracy. High accuracy is used by default and using it is
    strongly recommended.
 
+Even if sht3x sensor supports clock-strech(blocking mode) and non-strench
+(non-blocking mode) in single-shot mode, this driver only supports the latter.
+
 The sht3x sensor supports a single shot mode as well as 5 periodic measure
 modes, which can be controlled with the update_interval sysfs interface.
 The allowed update_interval in milliseconds are as follows:
drivers/hwmon/sht3x.c +11 -22
index 580704d93..bbe556f44 100644
@@ -22,12 +22,10 @@
 #include <linux/jiffies.h>
 
 /* commands (high precision mode) */
-static const unsigned char sht3x_cmd_measure_blocking_hpm[]    = { 0x2c, 0x06 };
-static const unsigned char sht3x_cmd_measure_nonblocking_hpm[] = { 0x24, 0x00 };
+static const unsigned char sht3x_cmd_measure_single_hpm[] = { 0x24, 0x00 };
 
 /* commands (low power mode) */
-static const unsigned char sht3x_cmd_measure_blocking_lpm[]    = { 0x2c, 0x10 };
-static const unsigned char sht3x_cmd_measure_nonblocking_lpm[] = { 0x24, 0x16 };
+static const unsigned char sht3x_cmd_measure_single_lpm[] = { 0x24, 0x16 };
 
 /* commands for periodic mode */
 static const unsigned char sht3x_cmd_measure_periodic_mode[]   = { 0xe0, 0x00 };
@@ -41,9 +39,9 @@ static const unsigned char sht3x_cmd_heater_off[]              = { 0x30, 0x66 };
 static const unsigned char sht3x_cmd_read_status_reg[]         = { 0xf3, 0x2d };
 static const unsigned char sht3x_cmd_clear_status_reg[]        = { 0x30, 0x41 };
 
-/* delays for non-blocking i2c commands, both in us */
-#define SHT3X_NONBLOCKING_WAIT_TIME_HPM  15000
-#define SHT3X_NONBLOCKING_WAIT_TIME_LPM   4000
+/* delays for single-shot mode i2c commands, both in us */
+#define SHT3X_SINGLE_WAIT_TIME_HPM  15000
+#define SHT3X_SINGLE_WAIT_TIME_LPM   4000
 
 #define SHT3X_WORD_LEN         2
 #define SHT3X_CMD_LENGTH       2
@@ -134,7 +132,6 @@ struct sht3x_data {
 	const unsigned char *command;
 	u32 wait_time;			/* in us*/
 	unsigned long last_update;	/* last update in periodic mode*/
-	bool blocking_io;
 	bool high_precision;
 
 	/*
@@ -432,26 +429,19 @@ static ssize_t humidity1_limit_store(struct device *dev,
 static void sht3x_select_command(struct sht3x_data *data)
 {
 	/*
-	 * In blocking mode (clock stretching mode) the I2C bus
-	 * is blocked for other traffic, thus the call to i2c_master_recv()
-	 * will wait until the data is ready. For non blocking mode, we
-	 * have to wait ourselves.
+	 * For single-shot mode, only non blocking mode is support,
+	 * we have to wait ourselves for result.
 	 */
 	if (data->mode > 0) {
 		data->command = sht3x_cmd_measure_periodic_mode;
 		data->wait_time = 0;
-	} else if (data->blocking_io) {
-		data->command = data->high_precision ?
-				sht3x_cmd_measure_blocking_hpm :
-				sht3x_cmd_measure_blocking_lpm;
-		data->wait_time = 0;
 	} else {
 		if (data->high_precision) {
-			data->command = sht3x_cmd_measure_nonblocking_hpm;
-			data->wait_time = SHT3X_NONBLOCKING_WAIT_TIME_HPM;
+			data->command = sht3x_cmd_measure_single_hpm;
+			data->wait_time = SHT3X_SINGLE_WAIT_TIME_HPM;
 		} else {
-			data->command = sht3x_cmd_measure_nonblocking_lpm;
-			data->wait_time = SHT3X_NONBLOCKING_WAIT_TIME_LPM;
+			data->command = sht3x_cmd_measure_single_lpm;
+			data->wait_time = SHT3X_SINGLE_WAIT_TIME_LPM;
 		}
 	}
 }
@@ -689,7 +679,6 @@ static int sht3x_probe(struct i2c_client *client)
 	if (!data)
 		return -ENOMEM;
 
-	data->blocking_io = false;
 	data->high_precision = true;
 	data->mode = 0;
 	data->last_update = jiffies - msecs_to_jiffies(3000);
Signature · 1 line
2.30.2
maintainer Applied
#2 lore raw
Quoted 4 lines · JuenKit Yip

Due to no support on clock-strench, blocking mode was removed and now single-shot mode only uses non-blocking mode.

Applied to hwmon-next.

Thanks,
Guenter

Quoted 113 lines
---
 Documentation/hwmon/sht3x.rst | 14 ++++++--------
 drivers/hwmon/sht3x.c         | 33 +++++++++++----------------------
 2 files changed, 17 insertions(+), 30 deletions(-)
Documentation/hwmon/sht3x.rst +6 -8
index 31fd36b14..be70e2543 100644
@@ -28,16 +28,14 @@ The device communicates with the I2C protocol. Sensors can have the I2C
 addresses 0x44 or 0x45, depending on the wiring. See
 Documentation/i2c/instantiating-devices.rst for methods to instantiate the device.
 
-There are two options configurable by means of sht3x_data:
-
-1. blocking (pull the I2C clock line down while performing the measurement) or
-   non-blocking mode. Blocking mode will guarantee the fastest result but
-   the I2C bus will be busy during that time. By default, non-blocking mode
-   is used. Make sure clock-stretching works properly on your device if you
-   want to use blocking mode.
-2. high or low accuracy. High accuracy is used by default and using it is
+There is only one option configurable by means of sht3x_data:
+
+   high or low accuracy. High accuracy is used by default and using it is
    strongly recommended.
 
+Even if sht3x sensor supports clock-strech(blocking mode) and non-strench
+(non-blocking mode) in single-shot mode, this driver only supports the latter.
+
 The sht3x sensor supports a single shot mode as well as 5 periodic measure
 modes, which can be controlled with the update_interval sysfs interface.
 The allowed update_interval in milliseconds are as follows:
drivers/hwmon/sht3x.c +11 -22
index 580704d93..bbe556f44 100644
@@ -22,12 +22,10 @@
 #include <linux/jiffies.h>
 
 /* commands (high precision mode) */
-static const unsigned char sht3x_cmd_measure_blocking_hpm[]    = { 0x2c, 0x06 };
-static const unsigned char sht3x_cmd_measure_nonblocking_hpm[] = { 0x24, 0x00 };
+static const unsigned char sht3x_cmd_measure_single_hpm[] = { 0x24, 0x00 };
 
 /* commands (low power mode) */
-static const unsigned char sht3x_cmd_measure_blocking_lpm[]    = { 0x2c, 0x10 };
-static const unsigned char sht3x_cmd_measure_nonblocking_lpm[] = { 0x24, 0x16 };
+static const unsigned char sht3x_cmd_measure_single_lpm[] = { 0x24, 0x16 };
 
 /* commands for periodic mode */
 static const unsigned char sht3x_cmd_measure_periodic_mode[]   = { 0xe0, 0x00 };
@@ -41,9 +39,9 @@ static const unsigned char sht3x_cmd_heater_off[]              = { 0x30, 0x66 };
 static const unsigned char sht3x_cmd_read_status_reg[]         = { 0xf3, 0x2d };
 static const unsigned char sht3x_cmd_clear_status_reg[]        = { 0x30, 0x41 };
 
-/* delays for non-blocking i2c commands, both in us */
-#define SHT3X_NONBLOCKING_WAIT_TIME_HPM  15000
-#define SHT3X_NONBLOCKING_WAIT_TIME_LPM   4000
+/* delays for single-shot mode i2c commands, both in us */
+#define SHT3X_SINGLE_WAIT_TIME_HPM  15000
+#define SHT3X_SINGLE_WAIT_TIME_LPM   4000
 
 #define SHT3X_WORD_LEN         2
 #define SHT3X_CMD_LENGTH       2
@@ -134,7 +132,6 @@ struct sht3x_data {
 	const unsigned char *command;
 	u32 wait_time;			/* in us*/
 	unsigned long last_update;	/* last update in periodic mode*/
-	bool blocking_io;
 	bool high_precision;
 
 	/*
@@ -432,26 +429,19 @@ static ssize_t humidity1_limit_store(struct device *dev,
 static void sht3x_select_command(struct sht3x_data *data)
 {
 	/*
-	 * In blocking mode (clock stretching mode) the I2C bus
-	 * is blocked for other traffic, thus the call to i2c_master_recv()
-	 * will wait until the data is ready. For non blocking mode, we
-	 * have to wait ourselves.
+	 * For single-shot mode, only non blocking mode is support,
+	 * we have to wait ourselves for result.
 	 */
 	if (data->mode > 0) {
 		data->command = sht3x_cmd_measure_periodic_mode;
 		data->wait_time = 0;
-	} else if (data->blocking_io) {
-		data->command = data->high_precision ?
-				sht3x_cmd_measure_blocking_hpm :
-				sht3x_cmd_measure_blocking_lpm;
-		data->wait_time = 0;
 	} else {
 		if (data->high_precision) {
-			data->command = sht3x_cmd_measure_nonblocking_hpm;
-			data->wait_time = SHT3X_NONBLOCKING_WAIT_TIME_HPM;
+			data->command = sht3x_cmd_measure_single_hpm;
+			data->wait_time = SHT3X_SINGLE_WAIT_TIME_HPM;
 		} else {
-			data->command = sht3x_cmd_measure_nonblocking_lpm;
-			data->wait_time = SHT3X_NONBLOCKING_WAIT_TIME_LPM;
+			data->command = sht3x_cmd_measure_single_lpm;
+			data->wait_time = SHT3X_SINGLE_WAIT_TIME_LPM;
 		}
 	}
 }
@@ -689,7 +679,6 @@ static int sht3x_probe(struct i2c_client *client)
 	if (!data)
 		return -ENOMEM;
 
-	data->blocking_io = false;
 	data->high_precision = true;
 	data->mode = 0;
 	data->last_update = jiffies - msecs_to_jiffies(3000);
#3 lore raw

PATCH v2 3/6 hwmon: (sht3x)replace "high-precision" property to "repeatability"

In reply to a message not in the archive
---
 Documentation/hwmon/sht3x.rst |  2 +-
 drivers/hwmon/sht3x.c         | 21 +++++++++++++--------
 2 files changed, 14 insertions(+), 9 deletions(-)
Documentation/hwmon/sht3x.rst +1 -1
index be70e2543..b4aa561f0 100644
@@ -30,7 +30,7 @@ Documentation/i2c/instantiating-devices.rst for methods to instantiate the devic
 
 There is only one option configurable by means of sht3x_data:
 
-   high or low accuracy. High accuracy is used by default and using it is
+   repeatability: high repeatability is used by default and using it is
    strongly recommended.
 
 Even if sht3x sensor supports clock-strech(blocking mode) and non-strench
drivers/hwmon/sht3x.c +13 -8
index bbe556f44..ecc64febc 100644
@@ -21,10 +21,10 @@
 #include <linux/slab.h>
 #include <linux/jiffies.h>
 
-/* commands (high precision mode) */
+/* commands (high repeatability mode) */
 static const unsigned char sht3x_cmd_measure_single_hpm[] = { 0x24, 0x00 };
 
-/* commands (low power mode) */
+/* commands (low repeatability mode) */
 static const unsigned char sht3x_cmd_measure_single_lpm[] = { 0x24, 0x16 };
 
 /* commands for periodic mode */
@@ -66,9 +66,14 @@ enum sht3x_limits {
 	limit_min_hyst,
 };
 
+enum sht3x_repeatability {
+	low_repeatability,
+	high_repeatability,
+};
+
 DECLARE_CRC8_TABLE(sht3x_crc8_table);
 
-/* periodic measure commands (high precision mode) */
+/* periodic measure commands (high repeatability mode) */
 static const char periodic_measure_commands_hpm[][SHT3X_CMD_LENGTH] = {
 	/* 0.5 measurements per second */
 	{0x20, 0x32},
@@ -82,7 +87,7 @@ static const char periodic_measure_commands_hpm[][SHT3X_CMD_LENGTH] = {
 	{0x27, 0x37},
 };
 
-/* periodic measure commands (low power mode) */
+/* periodic measure commands (low repeatability mode) */
 static const char periodic_measure_commands_lpm[][SHT3X_CMD_LENGTH] = {
 	/* 0.5 measurements per second */
 	{0x20, 0x2f},
@@ -132,7 +137,7 @@ struct sht3x_data {
 	const unsigned char *command;
 	u32 wait_time;			/* in us*/
 	unsigned long last_update;	/* last update in periodic mode*/
-	bool high_precision;
+	enum sht3x_repeatability repeatability;
 
 	/*
 	 * cached values for temperature and humidity and limits
@@ -436,7 +441,7 @@ static void sht3x_select_command(struct sht3x_data *data)
 		data->command = sht3x_cmd_measure_periodic_mode;
 		data->wait_time = 0;
 	} else {
-		if (data->high_precision) {
+		if (data->repeatability == high_repeatability) {
 			data->command = sht3x_cmd_measure_single_hpm;
 			data->wait_time = SHT3X_SINGLE_WAIT_TIME_HPM;
 		} else {
@@ -584,7 +589,7 @@ static ssize_t update_interval_store(struct device *dev,
 	}
 
 	if (mode > 0) {
-		if (data->high_precision)
+		if (data->repeatability == high_repeatability)
 			command = periodic_measure_commands_hpm[mode - 1];
 		else
 			command = periodic_measure_commands_lpm[mode - 1];
@@ -679,7 +684,7 @@ static int sht3x_probe(struct i2c_client *client)
 	if (!data)
 		return -ENOMEM;
 
-	data->high_precision = true;
+	data->repeatability = high_repeatability;
 	data->mode = 0;
 	data->last_update = jiffies - msecs_to_jiffies(3000);
 	data->client = client;
Signature · 1 line
2.30.2
maintainer Applied
#4 lore raw

Re: [PATCH v2 3/6] hwmon: (sht3x)replace "high-precision" property to "repeatability"

Quoted 1 line · JuenKit Yip

Checkpatch rightfully says:

WARNING: Missing commit description - Add an appropriate one

Please always provide a commit description. I'll do that here, so no need to resend, but please keep it in mind when sending future patches.

Applied to hwmon-next.

Thanks,
Guenter

Quoted 96 lines
---
 Documentation/hwmon/sht3x.rst |  2 +-
 drivers/hwmon/sht3x.c         | 21 +++++++++++++--------
 2 files changed, 14 insertions(+), 9 deletions(-)
Documentation/hwmon/sht3x.rst +1 -1
index be70e2543..b4aa561f0 100644
@@ -30,7 +30,7 @@ Documentation/i2c/instantiating-devices.rst for methods to instantiate the devic
 
 There is only one option configurable by means of sht3x_data:
 
-   high or low accuracy. High accuracy is used by default and using it is
+   repeatability: high repeatability is used by default and using it is
    strongly recommended.
 
 Even if sht3x sensor supports clock-strech(blocking mode) and non-strench
drivers/hwmon/sht3x.c +13 -8
index bbe556f44..ecc64febc 100644
@@ -21,10 +21,10 @@
 #include <linux/slab.h>
 #include <linux/jiffies.h>
 
-/* commands (high precision mode) */
+/* commands (high repeatability mode) */
 static const unsigned char sht3x_cmd_measure_single_hpm[] = { 0x24, 0x00 };
 
-/* commands (low power mode) */
+/* commands (low repeatability mode) */
 static const unsigned char sht3x_cmd_measure_single_lpm[] = { 0x24, 0x16 };
 
 /* commands for periodic mode */
@@ -66,9 +66,14 @@ enum sht3x_limits {
 	limit_min_hyst,
 };
 
+enum sht3x_repeatability {
+	low_repeatability,
+	high_repeatability,
+};
+
 DECLARE_CRC8_TABLE(sht3x_crc8_table);
 
-/* periodic measure commands (high precision mode) */
+/* periodic measure commands (high repeatability mode) */
 static const char periodic_measure_commands_hpm[][SHT3X_CMD_LENGTH] = {
 	/* 0.5 measurements per second */
 	{0x20, 0x32},
@@ -82,7 +87,7 @@ static const char periodic_measure_commands_hpm[][SHT3X_CMD_LENGTH] = {
 	{0x27, 0x37},
 };
 
-/* periodic measure commands (low power mode) */
+/* periodic measure commands (low repeatability mode) */
 static const char periodic_measure_commands_lpm[][SHT3X_CMD_LENGTH] = {
 	/* 0.5 measurements per second */
 	{0x20, 0x2f},
@@ -132,7 +137,7 @@ struct sht3x_data {
 	const unsigned char *command;
 	u32 wait_time;			/* in us*/
 	unsigned long last_update;	/* last update in periodic mode*/
-	bool high_precision;
+	enum sht3x_repeatability repeatability;
 
 	/*
 	 * cached values for temperature and humidity and limits
@@ -436,7 +441,7 @@ static void sht3x_select_command(struct sht3x_data *data)
 		data->command = sht3x_cmd_measure_periodic_mode;
 		data->wait_time = 0;
 	} else {
-		if (data->high_precision) {
+		if (data->repeatability == high_repeatability) {
 			data->command = sht3x_cmd_measure_single_hpm;
 			data->wait_time = SHT3X_SINGLE_WAIT_TIME_HPM;
 		} else {
@@ -584,7 +589,7 @@ static ssize_t update_interval_store(struct device *dev,
 	}
 
 	if (mode > 0) {
-		if (data->high_precision)
+		if (data->repeatability == high_repeatability)
 			command = periodic_measure_commands_hpm[mode - 1];
 		else
 			command = periodic_measure_commands_lpm[mode - 1];
@@ -679,7 +684,7 @@ static int sht3x_probe(struct i2c_client *client)
 	if (!data)
 		return -ENOMEM;
 
-	data->high_precision = true;
+	data->repeatability = high_repeatability;
 	data->mode = 0;
 	data->last_update = jiffies - msecs_to_jiffies(3000);
 	data->client = client;
#5 lore raw

PATCH v2 4/6 hwmon: (sht3x)add medium repeatability support

In reply to a message not in the archive

add medium repeatability support for matching datasheet

---
 drivers/hwmon/sht3x.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/hwmon/sht3x.c +24 -0
index ecc64febc..6174b8fa7 100644
@@ -24,6 +24,9 @@
 /* commands (high repeatability mode) */
 static const unsigned char sht3x_cmd_measure_single_hpm[] = { 0x24, 0x00 };
 
+/* commands (medium repeatability mode) */
+static const unsigned char sht3x_cmd_measure_single_mpm[] = { 0x24, 0x0b };
+
 /* commands (low repeatability mode) */
 static const unsigned char sht3x_cmd_measure_single_lpm[] = { 0x24, 0x16 };
 
@@ -41,6 +44,7 @@ static const unsigned char sht3x_cmd_clear_status_reg[]        = { 0x30, 0x41 };
 
 /* delays for single-shot mode i2c commands, both in us */
 #define SHT3X_SINGLE_WAIT_TIME_HPM  15000
+#define SHT3X_SINGLE_WAIT_TIME_MPM   6000
 #define SHT3X_SINGLE_WAIT_TIME_LPM   4000
 
 #define SHT3X_WORD_LEN         2
@@ -68,6 +72,7 @@ enum sht3x_limits {
 
 enum sht3x_repeatability {
 	low_repeatability,
+	medium_repeatability,
 	high_repeatability,
 };
 
@@ -87,6 +92,20 @@ static const char periodic_measure_commands_hpm[][SHT3X_CMD_LENGTH] = {
 	{0x27, 0x37},
 };
 
+/* periodic measure commands (medium repeatability) */
+static const char periodic_measure_commands_mpm[][SHT3X_CMD_LENGTH] = {
+	/* 0.5 measurements per second */
+	{0x20, 0x24},
+	/* 1 measurements per second */
+	{0x21, 0x26},
+	/* 2 measurements per second */
+	{0x22, 0x20},
+	/* 4 measurements per second */
+	{0x23, 0x22},
+	/* 10 measurements per second */
+	{0x27, 0x21},
+};
+
 /* periodic measure commands (low repeatability mode) */
 static const char periodic_measure_commands_lpm[][SHT3X_CMD_LENGTH] = {
 	/* 0.5 measurements per second */
@@ -444,6 +463,9 @@ static void sht3x_select_command(struct sht3x_data *data)
 		if (data->repeatability == high_repeatability) {
 			data->command = sht3x_cmd_measure_single_hpm;
 			data->wait_time = SHT3X_SINGLE_WAIT_TIME_HPM;
+		} else if (data->repeatability ==  medium_repeatability) {
+			data->command = sht3x_cmd_measure_single_mpm;
+			data->wait_time = SHT3X_SINGLE_WAIT_TIME_MPM;
 		} else {
 			data->command = sht3x_cmd_measure_single_lpm;
 			data->wait_time = SHT3X_SINGLE_WAIT_TIME_LPM;
@@ -591,6 +613,8 @@ static ssize_t update_interval_store(struct device *dev,
 	if (mode > 0) {
 		if (data->repeatability == high_repeatability)
 			command = periodic_measure_commands_hpm[mode - 1];
+		else if (data->repeatability == medium_repeatability)
+			command = periodic_measure_commands_mpm[mode - 1];
 		else
 			command = periodic_measure_commands_lpm[mode - 1];
 
Signature · 1 line
2.30.2
maintainer Applied
#6 lore raw

Re: [PATCH v2 4/6] hwmon: (sht3x)add medium repeatability support

Quoted 3 lines · JuenKit Yip

add medium repeatability support for matching datasheet

Applied to hwmon-next.

Thanks,
Guenter

Quoted 74 lines
---
 drivers/hwmon/sht3x.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/hwmon/sht3x.c +24 -0
index ecc64febc..6174b8fa7 100644
@@ -24,6 +24,9 @@
 /* commands (high repeatability mode) */
 static const unsigned char sht3x_cmd_measure_single_hpm[] = { 0x24, 0x00 };
 
+/* commands (medium repeatability mode) */
+static const unsigned char sht3x_cmd_measure_single_mpm[] = { 0x24, 0x0b };
+
 /* commands (low repeatability mode) */
 static const unsigned char sht3x_cmd_measure_single_lpm[] = { 0x24, 0x16 };
 
@@ -41,6 +44,7 @@ static const unsigned char sht3x_cmd_clear_status_reg[]        = { 0x30, 0x41 };
 
 /* delays for single-shot mode i2c commands, both in us */
 #define SHT3X_SINGLE_WAIT_TIME_HPM  15000
+#define SHT3X_SINGLE_WAIT_TIME_MPM   6000
 #define SHT3X_SINGLE_WAIT_TIME_LPM   4000
 
 #define SHT3X_WORD_LEN         2
@@ -68,6 +72,7 @@ enum sht3x_limits {
 
 enum sht3x_repeatability {
 	low_repeatability,
+	medium_repeatability,
 	high_repeatability,
 };
 
@@ -87,6 +92,20 @@ static const char periodic_measure_commands_hpm[][SHT3X_CMD_LENGTH] = {
 	{0x27, 0x37},
 };
 
+/* periodic measure commands (medium repeatability) */
+static const char periodic_measure_commands_mpm[][SHT3X_CMD_LENGTH] = {
+	/* 0.5 measurements per second */
+	{0x20, 0x24},
+	/* 1 measurements per second */
+	{0x21, 0x26},
+	/* 2 measurements per second */
+	{0x22, 0x20},
+	/* 4 measurements per second */
+	{0x23, 0x22},
+	/* 10 measurements per second */
+	{0x27, 0x21},
+};
+
 /* periodic measure commands (low repeatability mode) */
 static const char periodic_measure_commands_lpm[][SHT3X_CMD_LENGTH] = {
 	/* 0.5 measurements per second */
@@ -444,6 +463,9 @@ static void sht3x_select_command(struct sht3x_data *data)
 		if (data->repeatability == high_repeatability) {
 			data->command = sht3x_cmd_measure_single_hpm;
 			data->wait_time = SHT3X_SINGLE_WAIT_TIME_HPM;
+		} else if (data->repeatability ==  medium_repeatability) {
+			data->command = sht3x_cmd_measure_single_mpm;
+			data->wait_time = SHT3X_SINGLE_WAIT_TIME_MPM;
 		} else {
 			data->command = sht3x_cmd_measure_single_lpm;
 			data->wait_time = SHT3X_SINGLE_WAIT_TIME_LPM;
@@ -591,6 +613,8 @@ static ssize_t update_interval_store(struct device *dev,
 	if (mode > 0) {
 		if (data->repeatability == high_repeatability)
 			command = periodic_measure_commands_hpm[mode - 1];
+		else if (data->repeatability == medium_repeatability)
+			command = periodic_measure_commands_mpm[mode - 1];
 		else
 			command = periodic_measure_commands_lpm[mode - 1];
 
#7 lore raw

PATCH v2 5/6 hwmon: (sht3x)add new non-stardard sysfs interface

In reply to a message not in the archive

add "repeatability" interface to sysfs, it could be read or written to control the sensor.

---
 Documentation/hwmon/sht3x.rst | 12 +++++++-----
 drivers/hwmon/sht3x.c         | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 5 deletions(-)
Documentation/hwmon/sht3x.rst +7 -5
index b4aa561f0..87864ffd1 100644
@@ -28,11 +28,6 @@ The device communicates with the I2C protocol. Sensors can have the I2C
 addresses 0x44 or 0x45, depending on the wiring. See
 Documentation/i2c/instantiating-devices.rst for methods to instantiate the device.
 
-There is only one option configurable by means of sht3x_data:
-
-   repeatability: high repeatability is used by default and using it is
-   strongly recommended.
-
 Even if sht3x sensor supports clock-strech(blocking mode) and non-strench
 (non-blocking mode) in single-shot mode, this driver only supports the latter.
 
@@ -83,4 +78,11 @@ heater_enable:      heater enable, heating element removes excess humidity from
 update_interval:    update interval, 0 for single shot, interval in msec
 		    for periodic measurement. If the interval is not supported
 		    by the sensor, the next faster interval is chosen
+repeatability:      write or read repeatability, higher repeatability means
+                    longer measurement duration, lower noise level and
+                    larger energy consumption:
+
+                        - 0: low repeatability
+                        - 1: medium repeatability
+                        - 2: high repeatability
 =================== ============================================================
drivers/hwmon/sht3x.c +33 -0
index 6174b8fa7..adfc11c12 100644
@@ -637,6 +637,37 @@ static ssize_t update_interval_store(struct device *dev,
 	return count;
 }
 
+static ssize_t repeatability_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)
+{
+	struct sht3x_data *data = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%d\n", data->repeatability);
+}
+
+static ssize_t repeatability_store(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf,
+				     size_t count)
+{
+	u8 val;
+	int ret;
+
+	struct sht3x_data *data = dev_get_drvdata(dev);
+
+	ret = kstrtou8(buf, 0, &val);
+	if (ret)
+		return ret;
+
+	if (val < 0 || val > 2)
+		return -EINVAL;
+
+	data->repeatability = val;
+
+	return count;
+}
+
 static SENSOR_DEVICE_ATTR_RO(temp1_input, temp1_input, 0);
 static SENSOR_DEVICE_ATTR_RO(humidity1_input, humidity1_input, 0);
 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);
 static SENSOR_DEVICE_ATTR_RO(humidity1_alarm, humidity1_alarm, 0);
 static SENSOR_DEVICE_ATTR_RW(heater_enable, heater_enable, 0);
 static SENSOR_DEVICE_ATTR_RW(update_interval, update_interval, 0);
+static SENSOR_DEVICE_ATTR_RW(repeatability, repeatability, 0);
 
 static struct attribute *sht3x_attrs[] = {
 	&sensor_dev_attr_temp1_input.dev_attr.attr,
@@ -669,6 +701,7 @@ static struct attribute *sht3x_attrs[] = {
 	&sensor_dev_attr_humidity1_alarm.dev_attr.attr,
 	&sensor_dev_attr_heater_enable.dev_attr.attr,
 	&sensor_dev_attr_update_interval.dev_attr.attr,
+	&sensor_dev_attr_repeatability.dev_attr.attr,
 	NULL
 };
 
Signature · 1 line
2.30.2
maintainer
#8 lore raw

Re: [PATCH v2 5/6] hwmon: (sht3x)add new non-stardard sysfs interface

Quoted 4 lines · JuenKit Yip

add "repeatability" interface to sysfs, it could be read or written to control the sensor.

Checkpatch:

CHECK: Alignment should match open parenthesis #149: FILE: drivers/hwmon/sht3x.c:650:
+static ssize_t repeatability_store(struct device *dev,
+ struct device_attribute *attr,

Another comment inline below. I fixed that up, no need to resend. But please keep it in mind for future patches.

Thanks,
Guenter

Quoted 91 lines
---
 Documentation/hwmon/sht3x.rst | 12 +++++++-----
 drivers/hwmon/sht3x.c         | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 5 deletions(-)
Documentation/hwmon/sht3x.rst +7 -5
index b4aa561f0..87864ffd1 100644
@@ -28,11 +28,6 @@ The device communicates with the I2C protocol. Sensors can have the I2C
 addresses 0x44 or 0x45, depending on the wiring. See
 Documentation/i2c/instantiating-devices.rst for methods to instantiate the device.
 
-There is only one option configurable by means of sht3x_data:
-
-   repeatability: high repeatability is used by default and using it is
-   strongly recommended.
-
 Even if sht3x sensor supports clock-strech(blocking mode) and non-strench
 (non-blocking mode) in single-shot mode, this driver only supports the latter.
 
@@ -83,4 +78,11 @@ heater_enable:      heater enable, heating element removes excess humidity from
 update_interval:    update interval, 0 for single shot, interval in msec
 		    for periodic measurement. If the interval is not supported
 		    by the sensor, the next faster interval is chosen
+repeatability:      write or read repeatability, higher repeatability means
+                    longer measurement duration, lower noise level and
+                    larger energy consumption:
+
+                        - 0: low repeatability
+                        - 1: medium repeatability
+                        - 2: high repeatability
 =================== ============================================================
drivers/hwmon/sht3x.c +33 -0
index 6174b8fa7..adfc11c12 100644
@@ -637,6 +637,37 @@ static ssize_t update_interval_store(struct device *dev,
 	return count;
 }
 
+static ssize_t repeatability_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)
+{
+	struct sht3x_data *data = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%d\n", data->repeatability);
+}
+
+static ssize_t repeatability_store(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf,
+				     size_t count)
+{
+	u8 val;
+	int ret;
+
+	struct sht3x_data *data = dev_get_drvdata(dev);
+
+	ret = kstrtou8(buf, 0, &val);
+	if (ret)
+		return ret;
+
+	if (val < 0 || val > 2)
+		return -EINVAL;
+
+	data->repeatability = val;
+
+	return count;
+}
+
 static SENSOR_DEVICE_ATTR_RO(temp1_input, temp1_input, 0);
 static SENSOR_DEVICE_ATTR_RO(humidity1_input, humidity1_input, 0);
 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);
 static SENSOR_DEVICE_ATTR_RO(humidity1_alarm, humidity1_alarm, 0);
 static SENSOR_DEVICE_ATTR_RW(heater_enable, heater_enable, 0);
 static SENSOR_DEVICE_ATTR_RW(update_interval, update_interval, 0);
+static SENSOR_DEVICE_ATTR_RW(repeatability, repeatability, 0);
 
 static struct attribute *sht3x_attrs[] = {
 	&sensor_dev_attr_temp1_input.dev_attr.attr,
@@ -669,6 +701,7 @@ static struct attribute *sht3x_attrs[] = {
 	&sensor_dev_attr_humidity1_alarm.dev_attr.attr,
 	&sensor_dev_attr_heater_enable.dev_attr.attr,
 	&sensor_dev_attr_update_interval.dev_attr.attr,
+	&sensor_dev_attr_repeatability.dev_attr.attr,
 	NULL
 };
 
#9 lore raw

PATCH v2 6/6 hwmon: (sht3x) complement sysfs interface for sts3x

In reply to a message not in the archive

Compared to sht3x, sts3x has the similiar functions and operations but it has no humidity sensor.

---
 drivers/hwmon/sht3x.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/hwmon/sht3x.c +8 -0
index adfc11c12..ae384ced7 100644
@@ -707,6 +707,14 @@ static struct attribute *sht3x_attrs[] = {
 
 static struct attribute *sts3x_attrs[] = {
 	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_max.dev_attr.attr,
+	&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
+	&sensor_dev_attr_temp1_min.dev_attr.attr,
+	&sensor_dev_attr_temp1_min_hyst.dev_attr.attr,
+	&sensor_dev_attr_temp1_alarm.dev_attr.attr,
+	&sensor_dev_attr_heater_enable.dev_attr.attr,
+	&sensor_dev_attr_update_interval.dev_attr.attr,
+	&sensor_dev_attr_repeatability.dev_attr.attr,
 	NULL
 };
 
Signature · 1 line
2.30.2
maintainer Applied
#10 lore raw

Re: [PATCH v2 6/6] hwmon: (sht3x) complement sysfs interface for sts3x

Quoted 1 line · JuenKit Yip

Compared to sht3x, sts3x has the similiar functions and operations

s/similiar/similar/

Quoted 3 lines

but it has no humidity sensor.

Applied to hwmon-next after fixing the above. Please run checkpatch on your patches; it would have told you.

Thanks,
Guenter

Quoted 23 lines
---
 drivers/hwmon/sht3x.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/hwmon/sht3x.c +8 -0
index adfc11c12..ae384ced7 100644
@@ -707,6 +707,14 @@ static struct attribute *sht3x_attrs[] = {
 
 static struct attribute *sts3x_attrs[] = {
 	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_max.dev_attr.attr,
+	&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
+	&sensor_dev_attr_temp1_min.dev_attr.attr,
+	&sensor_dev_attr_temp1_min_hyst.dev_attr.attr,
+	&sensor_dev_attr_temp1_alarm.dev_attr.attr,
+	&sensor_dev_attr_heater_enable.dev_attr.attr,
+	&sensor_dev_attr_update_interval.dev_attr.attr,
+	&sensor_dev_attr_repeatability.dev_attr.attr,
 	NULL
 };