On Thu, Sep 05, 2019 at 01:45:53AM +, Dan Robertson wrote:
> Add support for the Sensirion SHTC3 humidity and temperature sensor to
> the shtc1 module.
>
> Signed-off-by: Dan Robertson
Applied to hwmon-next after making nitpick change (see below).
> ---
> Documentation/hwmon/shtc1.rst | 19
> drivers/hwmon/Kconfig | 4 +--
> drivers/hwmon/shtc1.c | 56 ++-
> 3 files changed, 58 insertions(+), 21 deletions(-)
>
> diff --git a/Documentation/hwmon/shtc1.rst b/Documentation/hwmon/shtc1.rst
> index aa116332ba26..9b0f1eee5bf2 100644
> --- a/Documentation/hwmon/shtc1.rst
> +++ b/Documentation/hwmon/shtc1.rst
> @@ -19,7 +19,17 @@ Supported chips:
>
> Addresses scanned: none
>
> -Datasheet: Not publicly available
> +Datasheet: http://www.sensirion.com/file/datasheet_shtw1
> +
> +
> +
> + * Sensirion SHTC3
> +
> +Prefix: 'shtc3'
> +
> +Addresses scanned: none
> +
> +Datasheet: http://www.sensirion.com/file/datasheet_shtc3
>
>
>
> @@ -30,10 +40,9 @@ Author:
> Description
> ---
>
> -This driver implements support for the Sensirion SHTC1 chip, a humidity and
> -temperature sensor. Temperature is measured in degrees celsius, relative
> -humidity is expressed as a percentage. Driver can be used as well for SHTW1
> -chip, which has the same electrical interface.
> +This driver implements support for the Sensirion SHTC1, SHTW1, and SHTC3
> +chips, a humidity and temperature sensor. Temperature is measured in degrees
> +celsius, relative humidity is expressed as a percentage.
>
> The device communicates with the I2C protocol. All sensors are set to I2C
> address 0x70. See Documentation/i2c/instantiating-devices for methods to
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 650dd71f9724..e8b9b172ed9d 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -1382,8 +1382,8 @@ config SENSORS_SHTC1
> tristate "Sensiron humidity and temperature sensors. SHTC1 and compat."
> depends on I2C
> help
> - If you say yes here you get support for the Sensiron SHTC1 and SHTW1
> - humidity and temperature sensors.
> + If you say yes here you get support for the Sensiron SHTC1, SHTW1,
> + and SHTC3 humidity and temperature sensors.
>
> This driver can also be built as a module. If so, the module
> will be called shtc1.
> diff --git a/drivers/hwmon/shtc1.c b/drivers/hwmon/shtc1.c
> index 83fe08185ac7..3e9a859a2b58 100644
> --- a/drivers/hwmon/shtc1.c
> +++ b/drivers/hwmon/shtc1.c
> @@ -24,19 +24,32 @@ static const unsigned char
> shtc1_cmd_measure_blocking_lpm[]= { 0x64, 0x58 };
> static const unsigned char shtc1_cmd_measure_nonblocking_lpm[] = { 0x60,
> 0x9c };
>
> /* command for reading the ID register */
> -static const unsigned char shtc1_cmd_read_id_reg[] = { 0xef, 0xc8 };
> +static const unsigned char shtc1_cmd_read_id_reg[] = { 0xef,
> 0xc8 };
>
> -/* constants for reading the ID register */
> -#define SHTC1_ID 0x07
> -#define SHTC1_ID_REG_MASK 0x1f
> +/* constants for reading the ID register
> + * SHTC1: 0x0007 with mask 0x001f
> + * SHTW1: 0x0007 with mask 0x001f
> + * SHTC3: 0x0807 with mask 0x083f
> + */
/*
* Multi-line comments look like this
*/
> +#define SHTC3_ID 0x0807
> +#define SHTC3_ID_MASK 0x083f
> +#define SHTC1_ID 0x0007
> +#define SHTC1_ID_MASK 0x001f
>
> /* delays for non-blocking i2c commands, both in us */
> #define SHTC1_NONBLOCKING_WAIT_TIME_HPM 14400
> #define SHTC1_NONBLOCKING_WAIT_TIME_LPM 1000
> +#define SHTC3_NONBLOCKING_WAIT_TIME_HPM 12100
> +#define SHTC3_NONBLOCKING_WAIT_TIME_LPM800
>
> #define SHTC1_CMD_LENGTH 2
> #define SHTC1_RESPONSE_LENGTH 6
>
> +enum shtcx_chips {
> + shtc1,
> + shtc3,
> +};
> +
> struct shtc1_data {
> struct i2c_client *client;
> struct mutex update_lock;
> @@ -47,6 +60,7 @@ struct shtc1_data {
> unsigned int nonblocking_wait_time; /* in us */
>
> struct shtc1_platform_data setup;
> + enum shtcx_chips chip;
>
> int temperature; /* 1000 * temperature in dgr C */
> int humidity; /* 1000 * relative humidity in %RH */
> @@ -157,13 +171,16 @@ static void shtc1_select_command(struct shtc1_data
> *data)
> data->command = data->setup.blocking_io ?
> shtc1_cmd_measure_blocking_hpm :
> shtc1_cmd_measure_nonblocking_hpm;
> - data->nonblocking_wait_time = SHTC1_NONBLOCKING_WAIT_TIME_HPM;
> -
> + data->nonblocking_wait_time = (data->chip == shtc1) ?
> + SHTC1_NONBLOCKING_WAIT_TIME_HPM :
> + SHTC3_NONBLOCKING_WAIT_TIME_HPM;
> } else {
> data->command = data->setup.blocking_io ?
> shtc1_cmd_measure_blocking_lpm :
>