1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Sensirion SHT3x-DIS humidity and temperature sensor driver.
3 * The SHT3x comes in many different versions, this driver is for the
6 * Copyright (C) 2016 Sensirion AG, Switzerland
7 * Author: David Frey <david.frey@sensirion.com>
8 * Author: Pascal Sachs <pascal.sachs@sensirion.com>
12 #include <linux/crc8.h>
13 #include <linux/debugfs.h>
14 #include <linux/delay.h>
15 #include <linux/err.h>
16 #include <linux/hwmon.h>
17 #include <linux/hwmon-sysfs.h>
18 #include <linux/i2c.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/jiffies.h>
25 /* commands (high repeatability mode) */
26 static const unsigned char sht3x_cmd_measure_single_hpm
[] = { 0x24, 0x00 };
28 /* commands (medium repeatability mode) */
29 static const unsigned char sht3x_cmd_measure_single_mpm
[] = { 0x24, 0x0b };
31 /* commands (low repeatability mode) */
32 static const unsigned char sht3x_cmd_measure_single_lpm
[] = { 0x24, 0x16 };
34 /* commands for periodic mode */
35 static const unsigned char sht3x_cmd_measure_periodic_mode
[] = { 0xe0, 0x00 };
36 static const unsigned char sht3x_cmd_break
[] = { 0x30, 0x93 };
38 /* commands for heater control */
39 static const unsigned char sht3x_cmd_heater_on
[] = { 0x30, 0x6d };
40 static const unsigned char sht3x_cmd_heater_off
[] = { 0x30, 0x66 };
43 static const unsigned char sht3x_cmd_read_status_reg
[] = { 0xf3, 0x2d };
44 static const unsigned char sht3x_cmd_clear_status_reg
[] = { 0x30, 0x41 };
45 static const unsigned char sht3x_cmd_read_serial_number
[] = { 0x37, 0x80 };
47 static struct dentry
*debugfs
;
49 /* delays for single-shot mode i2c commands, both in us */
50 #define SHT3X_SINGLE_WAIT_TIME_HPM 15000
51 #define SHT3X_SINGLE_WAIT_TIME_MPM 6000
52 #define SHT3X_SINGLE_WAIT_TIME_LPM 4000
54 #define SHT3X_WORD_LEN 2
55 #define SHT3X_CMD_LENGTH 2
56 #define SHT3X_CRC8_LEN 1
57 #define SHT3X_RESPONSE_LENGTH 6
58 #define SHT3X_CRC8_POLYNOMIAL 0x31
59 #define SHT3X_CRC8_INIT 0xFF
60 #define SHT3X_MIN_TEMPERATURE -45000
61 #define SHT3X_MAX_TEMPERATURE 130000
62 #define SHT3X_MIN_HUMIDITY 0
63 #define SHT3X_MAX_HUMIDITY 100000
77 enum sht3x_repeatability
{
83 DECLARE_CRC8_TABLE(sht3x_crc8_table
);
85 /* periodic measure commands (high repeatability mode) */
86 static const char periodic_measure_commands_hpm
[][SHT3X_CMD_LENGTH
] = {
87 /* 0.5 measurements per second */
89 /* 1 measurements per second */
91 /* 2 measurements per second */
93 /* 4 measurements per second */
95 /* 10 measurements per second */
99 /* periodic measure commands (medium repeatability) */
100 static const char periodic_measure_commands_mpm
[][SHT3X_CMD_LENGTH
] = {
101 /* 0.5 measurements per second */
103 /* 1 measurements per second */
105 /* 2 measurements per second */
107 /* 4 measurements per second */
109 /* 10 measurements per second */
113 /* periodic measure commands (low repeatability mode) */
114 static const char periodic_measure_commands_lpm
[][SHT3X_CMD_LENGTH
] = {
115 /* 0.5 measurements per second */
117 /* 1 measurements per second */
119 /* 2 measurements per second */
121 /* 4 measurements per second */
123 /* 10 measurements per second */
127 struct sht3x_limit_commands
{
128 const char read_command
[SHT3X_CMD_LENGTH
];
129 const char write_command
[SHT3X_CMD_LENGTH
];
132 static const struct sht3x_limit_commands limit_commands
[] = {
133 /* temp1_max, humidity1_max */
134 [limit_max
] = { {0xe1, 0x1f}, {0x61, 0x1d} },
135 /* temp_1_max_hyst, humidity1_max_hyst */
136 [limit_max_hyst
] = { {0xe1, 0x14}, {0x61, 0x16} },
137 /* temp1_min, humidity1_min */
138 [limit_min
] = { {0xe1, 0x02}, {0x61, 0x00} },
139 /* temp_1_min_hyst, humidity1_min_hyst */
140 [limit_min_hyst
] = { {0xe1, 0x09}, {0x61, 0x0B} },
143 #define SHT3X_NUM_LIMIT_CMD ARRAY_SIZE(limit_commands)
145 static const u16 mode_to_update_interval
[] = {
154 static const struct hwmon_channel_info
* const sht3x_channel_info
[] = {
155 HWMON_CHANNEL_INFO(chip
, HWMON_C_UPDATE_INTERVAL
),
156 HWMON_CHANNEL_INFO(temp
, HWMON_T_INPUT
| HWMON_T_MIN
|
157 HWMON_T_MIN_HYST
| HWMON_T_MAX
|
158 HWMON_T_MAX_HYST
| HWMON_T_ALARM
),
159 HWMON_CHANNEL_INFO(humidity
, HWMON_H_INPUT
| HWMON_H_MIN
|
160 HWMON_H_MIN_HYST
| HWMON_H_MAX
|
161 HWMON_H_MAX_HYST
| HWMON_H_ALARM
),
166 struct i2c_client
*client
;
167 enum sht3x_chips chip_id
;
168 struct mutex i2c_lock
; /* lock for sending i2c commands */
169 struct mutex data_lock
; /* lock for updating driver data */
170 struct dentry
*sensor_dir
;
173 const unsigned char *command
;
174 u32 wait_time
; /* in us*/
175 unsigned long last_update
; /* last update in periodic mode*/
176 enum sht3x_repeatability repeatability
;
180 * cached values for temperature and humidity and limits
181 * the limits arrays have the following order:
182 * max, max_hyst, min, min_hyst
185 int temperature_limits
[SHT3X_NUM_LIMIT_CMD
];
187 u32 humidity_limits
[SHT3X_NUM_LIMIT_CMD
];
190 static u8
get_mode_from_update_interval(u16 value
)
193 u8 number_of_modes
= ARRAY_SIZE(mode_to_update_interval
);
198 /* find next faster update interval */
199 for (index
= 1; index
< number_of_modes
; index
++) {
200 if (mode_to_update_interval
[index
] <= value
)
204 return number_of_modes
- 1;
207 static int sht3x_read_from_command(struct i2c_client
*client
,
208 struct sht3x_data
*data
,
210 char *buf
, int length
, u32 wait_time
)
214 mutex_lock(&data
->i2c_lock
);
215 ret
= i2c_master_send(client
, command
, SHT3X_CMD_LENGTH
);
217 if (ret
!= SHT3X_CMD_LENGTH
) {
218 ret
= ret
< 0 ? ret
: -EIO
;
223 usleep_range(wait_time
, wait_time
+ 1000);
225 ret
= i2c_master_recv(client
, buf
, length
);
227 ret
= ret
< 0 ? ret
: -EIO
;
233 mutex_unlock(&data
->i2c_lock
);
237 static int sht3x_extract_temperature(u16 raw
)
241 * T = -45 + 175 * ST / 2^16
242 * Adapted for integer fixed point (3 digit) arithmetic.
244 return ((21875 * (int)raw
) >> 13) - 45000;
247 static u32
sht3x_extract_humidity(u16 raw
)
251 * RH = 100 * SRH / 2^16
252 * Adapted for integer fixed point (3 digit) arithmetic.
254 return (12500 * (u32
)raw
) >> 13;
257 static struct sht3x_data
*sht3x_update_client(struct device
*dev
)
259 struct sht3x_data
*data
= dev_get_drvdata(dev
);
260 struct i2c_client
*client
= data
->client
;
261 u16 interval_ms
= mode_to_update_interval
[data
->mode
];
262 unsigned long interval_jiffies
= msecs_to_jiffies(interval_ms
);
263 unsigned char buf
[SHT3X_RESPONSE_LENGTH
];
267 mutex_lock(&data
->data_lock
);
269 * Only update cached readings once per update interval in periodic
270 * mode. In single shot mode the sensor measures values on demand, so
271 * every time the sysfs interface is called, a measurement is triggered.
272 * In periodic mode however, the measurement process is handled
273 * internally by the sensor and reading out sensor values only makes
274 * sense if a new reading is available.
276 if (time_after(jiffies
, data
->last_update
+ interval_jiffies
)) {
277 ret
= sht3x_read_from_command(client
, data
, data
->command
, buf
,
278 sizeof(buf
), data
->wait_time
);
282 val
= be16_to_cpup((__be16
*)buf
);
283 data
->temperature
= sht3x_extract_temperature(val
);
284 val
= be16_to_cpup((__be16
*)(buf
+ 3));
285 data
->humidity
= sht3x_extract_humidity(val
);
286 data
->last_update
= jiffies
;
290 mutex_unlock(&data
->data_lock
);
297 static int temp1_input_read(struct device
*dev
)
299 struct sht3x_data
*data
= sht3x_update_client(dev
);
302 return PTR_ERR(data
);
304 return data
->temperature
;
307 static int humidity1_input_read(struct device
*dev
)
309 struct sht3x_data
*data
= sht3x_update_client(dev
);
312 return PTR_ERR(data
);
314 return data
->humidity
;
318 * limits_update must only be called from probe or with data_lock held
320 static int limits_update(struct sht3x_data
*data
)
327 char buffer
[SHT3X_RESPONSE_LENGTH
];
328 const struct sht3x_limit_commands
*commands
;
329 struct i2c_client
*client
= data
->client
;
331 for (index
= 0; index
< SHT3X_NUM_LIMIT_CMD
; index
++) {
332 commands
= &limit_commands
[index
];
333 ret
= sht3x_read_from_command(client
, data
,
334 commands
->read_command
, buffer
,
335 SHT3X_RESPONSE_LENGTH
, 0);
340 raw
= be16_to_cpup((__be16
*)buffer
);
341 temperature
= sht3x_extract_temperature((raw
& 0x01ff) << 7);
342 humidity
= sht3x_extract_humidity(raw
& 0xfe00);
343 data
->temperature_limits
[index
] = temperature
;
344 data
->humidity_limits
[index
] = humidity
;
350 static int temp1_limit_read(struct device
*dev
, int index
)
352 struct sht3x_data
*data
= dev_get_drvdata(dev
);
354 return data
->temperature_limits
[index
];
357 static int humidity1_limit_read(struct device
*dev
, int index
)
359 struct sht3x_data
*data
= dev_get_drvdata(dev
);
361 return data
->humidity_limits
[index
];
365 * limit_write must only be called with data_lock held
367 static size_t limit_write(struct device
*dev
,
372 char buffer
[SHT3X_CMD_LENGTH
+ SHT3X_WORD_LEN
+ SHT3X_CRC8_LEN
];
373 char *position
= buffer
;
376 struct sht3x_data
*data
= dev_get_drvdata(dev
);
377 struct i2c_client
*client
= data
->client
;
378 const struct sht3x_limit_commands
*commands
;
380 commands
= &limit_commands
[index
];
382 memcpy(position
, commands
->write_command
, SHT3X_CMD_LENGTH
);
383 position
+= SHT3X_CMD_LENGTH
;
385 * ST = (T + 45) / 175 * 2^16
386 * SRH = RH / 100 * 2^16
387 * adapted for fixed point arithmetic and packed the same as
390 raw
= ((u32
)(temperature
+ 45000) * 24543) >> (16 + 7);
391 raw
|= ((humidity
* 42950) >> 16) & 0xfe00;
393 *((__be16
*)position
) = cpu_to_be16(raw
);
394 position
+= SHT3X_WORD_LEN
;
395 *position
= crc8(sht3x_crc8_table
,
396 position
- SHT3X_WORD_LEN
,
400 mutex_lock(&data
->i2c_lock
);
401 ret
= i2c_master_send(client
, buffer
, sizeof(buffer
));
402 mutex_unlock(&data
->i2c_lock
);
404 if (ret
!= sizeof(buffer
))
405 return ret
< 0 ? ret
: -EIO
;
407 data
->temperature_limits
[index
] = temperature
;
408 data
->humidity_limits
[index
] = humidity
;
413 static int temp1_limit_write(struct device
*dev
, int index
, int val
)
417 struct sht3x_data
*data
= dev_get_drvdata(dev
);
419 temperature
= clamp_val(val
, SHT3X_MIN_TEMPERATURE
,
420 SHT3X_MAX_TEMPERATURE
);
421 mutex_lock(&data
->data_lock
);
422 ret
= limit_write(dev
, index
, temperature
,
423 data
->humidity_limits
[index
]);
424 mutex_unlock(&data
->data_lock
);
429 static int humidity1_limit_write(struct device
*dev
, int index
, int val
)
433 struct sht3x_data
*data
= dev_get_drvdata(dev
);
435 humidity
= clamp_val(val
, SHT3X_MIN_HUMIDITY
, SHT3X_MAX_HUMIDITY
);
436 mutex_lock(&data
->data_lock
);
437 ret
= limit_write(dev
, index
, data
->temperature_limits
[index
],
439 mutex_unlock(&data
->data_lock
);
444 static void sht3x_select_command(struct sht3x_data
*data
)
447 * For single-shot mode, only non blocking mode is support,
448 * we have to wait ourselves for result.
450 if (data
->mode
> 0) {
451 data
->command
= sht3x_cmd_measure_periodic_mode
;
454 if (data
->repeatability
== high_repeatability
) {
455 data
->command
= sht3x_cmd_measure_single_hpm
;
456 data
->wait_time
= SHT3X_SINGLE_WAIT_TIME_HPM
;
457 } else if (data
->repeatability
== medium_repeatability
) {
458 data
->command
= sht3x_cmd_measure_single_mpm
;
459 data
->wait_time
= SHT3X_SINGLE_WAIT_TIME_MPM
;
461 data
->command
= sht3x_cmd_measure_single_lpm
;
462 data
->wait_time
= SHT3X_SINGLE_WAIT_TIME_LPM
;
467 static int status_register_read(struct device
*dev
,
468 char *buffer
, int length
)
471 struct sht3x_data
*data
= dev_get_drvdata(dev
);
472 struct i2c_client
*client
= data
->client
;
474 ret
= sht3x_read_from_command(client
, data
, sht3x_cmd_read_status_reg
,
480 static int temp1_alarm_read(struct device
*dev
)
482 char buffer
[SHT3X_WORD_LEN
+ SHT3X_CRC8_LEN
];
485 ret
= status_register_read(dev
, buffer
,
486 SHT3X_WORD_LEN
+ SHT3X_CRC8_LEN
);
490 return !!(buffer
[0] & 0x04);
493 static int humidity1_alarm_read(struct device
*dev
)
495 char buffer
[SHT3X_WORD_LEN
+ SHT3X_CRC8_LEN
];
498 ret
= status_register_read(dev
, buffer
,
499 SHT3X_WORD_LEN
+ SHT3X_CRC8_LEN
);
503 return !!(buffer
[0] & 0x08);
506 static ssize_t
heater_enable_show(struct device
*dev
,
507 struct device_attribute
*attr
,
510 char buffer
[SHT3X_WORD_LEN
+ SHT3X_CRC8_LEN
];
513 ret
= status_register_read(dev
, buffer
,
514 SHT3X_WORD_LEN
+ SHT3X_CRC8_LEN
);
518 return sysfs_emit(buf
, "%d\n", !!(buffer
[0] & 0x20));
521 static ssize_t
heater_enable_store(struct device
*dev
,
522 struct device_attribute
*attr
,
526 struct sht3x_data
*data
= dev_get_drvdata(dev
);
527 struct i2c_client
*client
= data
->client
;
531 ret
= kstrtobool(buf
, &status
);
535 mutex_lock(&data
->i2c_lock
);
538 ret
= i2c_master_send(client
, (char *)&sht3x_cmd_heater_on
,
541 ret
= i2c_master_send(client
, (char *)&sht3x_cmd_heater_off
,
544 mutex_unlock(&data
->i2c_lock
);
549 static int update_interval_read(struct device
*dev
)
551 struct sht3x_data
*data
= dev_get_drvdata(dev
);
553 return mode_to_update_interval
[data
->mode
];
556 static int update_interval_write(struct device
*dev
, int val
)
561 struct sht3x_data
*data
= dev_get_drvdata(dev
);
562 struct i2c_client
*client
= data
->client
;
564 mode
= get_mode_from_update_interval(val
);
566 mutex_lock(&data
->data_lock
);
567 /* mode did not change */
568 if (mode
== data
->mode
) {
569 mutex_unlock(&data
->data_lock
);
573 mutex_lock(&data
->i2c_lock
);
575 * Abort periodic measure mode.
576 * To do any changes to the configuration while in periodic mode, we
577 * have to send a break command to the sensor, which then falls back
578 * to single shot (mode = 0).
580 if (data
->mode
> 0) {
581 ret
= i2c_master_send(client
, sht3x_cmd_break
,
583 if (ret
!= SHT3X_CMD_LENGTH
)
589 if (data
->repeatability
== high_repeatability
)
590 command
= periodic_measure_commands_hpm
[mode
- 1];
591 else if (data
->repeatability
== medium_repeatability
)
592 command
= periodic_measure_commands_mpm
[mode
- 1];
594 command
= periodic_measure_commands_lpm
[mode
- 1];
597 ret
= i2c_master_send(client
, command
, SHT3X_CMD_LENGTH
);
598 if (ret
!= SHT3X_CMD_LENGTH
)
602 /* select mode and command */
604 sht3x_select_command(data
);
607 mutex_unlock(&data
->i2c_lock
);
608 mutex_unlock(&data
->data_lock
);
609 if (ret
!= SHT3X_CMD_LENGTH
)
610 return ret
< 0 ? ret
: -EIO
;
615 static ssize_t
repeatability_show(struct device
*dev
,
616 struct device_attribute
*attr
,
619 struct sht3x_data
*data
= dev_get_drvdata(dev
);
621 return sysfs_emit(buf
, "%d\n", data
->repeatability
);
624 static ssize_t
repeatability_store(struct device
*dev
,
625 struct device_attribute
*attr
,
632 struct sht3x_data
*data
= dev_get_drvdata(dev
);
634 ret
= kstrtou8(buf
, 0, &val
);
641 data
->repeatability
= val
;
646 static SENSOR_DEVICE_ATTR_RW(heater_enable
, heater_enable
, 0);
647 static SENSOR_DEVICE_ATTR_RW(repeatability
, repeatability
, 0);
649 static struct attribute
*sht3x_attrs
[] = {
650 &sensor_dev_attr_heater_enable
.dev_attr
.attr
,
651 &sensor_dev_attr_repeatability
.dev_attr
.attr
,
655 ATTRIBUTE_GROUPS(sht3x
);
657 static umode_t
sht3x_is_visible(const void *data
, enum hwmon_sensor_types type
,
658 u32 attr
, int channel
)
660 const struct sht3x_data
*chip_data
= data
;
665 case hwmon_chip_update_interval
:
673 case hwmon_temp_input
:
674 case hwmon_temp_alarm
:
677 case hwmon_temp_max_hyst
:
679 case hwmon_temp_min_hyst
:
686 if (chip_data
->chip_id
== sts3x
)
689 case hwmon_humidity_input
:
690 case hwmon_humidity_alarm
:
692 case hwmon_humidity_max
:
693 case hwmon_humidity_max_hyst
:
694 case hwmon_humidity_min
:
695 case hwmon_humidity_min_hyst
:
708 static int sht3x_read(struct device
*dev
, enum hwmon_sensor_types type
,
709 u32 attr
, int channel
, long *val
)
711 enum sht3x_limits index
;
716 case hwmon_chip_update_interval
:
717 *val
= update_interval_read(dev
);
725 case hwmon_temp_input
:
726 *val
= temp1_input_read(dev
);
728 case hwmon_temp_alarm
:
729 *val
= temp1_alarm_read(dev
);
733 *val
= temp1_limit_read(dev
, index
);
735 case hwmon_temp_max_hyst
:
736 index
= limit_max_hyst
;
737 *val
= temp1_limit_read(dev
, index
);
741 *val
= temp1_limit_read(dev
, index
);
743 case hwmon_temp_min_hyst
:
744 index
= limit_min_hyst
;
745 *val
= temp1_limit_read(dev
, index
);
753 case hwmon_humidity_input
:
754 *val
= humidity1_input_read(dev
);
756 case hwmon_humidity_alarm
:
757 *val
= humidity1_alarm_read(dev
);
759 case hwmon_humidity_max
:
761 *val
= humidity1_limit_read(dev
, index
);
763 case hwmon_humidity_max_hyst
:
764 index
= limit_max_hyst
;
765 *val
= humidity1_limit_read(dev
, index
);
767 case hwmon_humidity_min
:
769 *val
= humidity1_limit_read(dev
, index
);
771 case hwmon_humidity_min_hyst
:
772 index
= limit_min_hyst
;
773 *val
= humidity1_limit_read(dev
, index
);
786 static int sht3x_write(struct device
*dev
, enum hwmon_sensor_types type
,
787 u32 attr
, int channel
, long val
)
789 enum sht3x_limits index
;
794 case hwmon_chip_update_interval
:
795 return update_interval_write(dev
, val
);
804 case hwmon_temp_max_hyst
:
805 index
= limit_max_hyst
;
810 case hwmon_temp_min_hyst
:
811 index
= limit_min_hyst
;
816 return temp1_limit_write(dev
, index
, val
);
819 case hwmon_humidity_max
:
822 case hwmon_humidity_max_hyst
:
823 index
= limit_max_hyst
;
825 case hwmon_humidity_min
:
828 case hwmon_humidity_min_hyst
:
829 index
= limit_min_hyst
;
834 return humidity1_limit_write(dev
, index
, val
);
840 static void sht3x_debugfs_init(struct sht3x_data
*data
)
844 snprintf(name
, sizeof(name
), "i2c%u-%02x",
845 data
->client
->adapter
->nr
, data
->client
->addr
);
846 data
->sensor_dir
= debugfs_create_dir(name
, debugfs
);
847 debugfs_create_u32("serial_number", 0444,
848 data
->sensor_dir
, &data
->serial_number
);
851 static void sht3x_debugfs_remove(void *sensor_dir
)
853 debugfs_remove_recursive(sensor_dir
);
856 static int sht3x_serial_number_read(struct sht3x_data
*data
)
859 char buffer
[SHT3X_RESPONSE_LENGTH
];
860 struct i2c_client
*client
= data
->client
;
862 ret
= sht3x_read_from_command(client
, data
,
863 sht3x_cmd_read_serial_number
,
865 SHT3X_RESPONSE_LENGTH
, 0);
869 data
->serial_number
= (buffer
[0] << 24) | (buffer
[1] << 16) |
870 (buffer
[3] << 8) | buffer
[4];
874 static const struct hwmon_ops sht3x_ops
= {
875 .is_visible
= sht3x_is_visible
,
877 .write
= sht3x_write
,
880 static const struct hwmon_chip_info sht3x_chip_info
= {
882 .info
= sht3x_channel_info
,
885 static int sht3x_probe(struct i2c_client
*client
)
888 struct sht3x_data
*data
;
889 struct device
*hwmon_dev
;
890 struct i2c_adapter
*adap
= client
->adapter
;
891 struct device
*dev
= &client
->dev
;
894 * we require full i2c support since the sht3x uses multi-byte read and
895 * writes as well as multi-byte commands which are not supported by
898 if (!i2c_check_functionality(adap
, I2C_FUNC_I2C
))
901 ret
= i2c_master_send(client
, sht3x_cmd_clear_status_reg
,
903 if (ret
!= SHT3X_CMD_LENGTH
)
904 return ret
< 0 ? ret
: -ENODEV
;
906 data
= devm_kzalloc(dev
, sizeof(*data
), GFP_KERNEL
);
910 data
->repeatability
= high_repeatability
;
912 data
->last_update
= jiffies
- msecs_to_jiffies(3000);
913 data
->client
= client
;
914 data
->chip_id
= (uintptr_t)i2c_get_match_data(client
);
915 crc8_populate_msb(sht3x_crc8_table
, SHT3X_CRC8_POLYNOMIAL
);
917 sht3x_select_command(data
);
919 mutex_init(&data
->i2c_lock
);
920 mutex_init(&data
->data_lock
);
923 * An attempt to read limits register too early
924 * causes a NACK response from the chip.
925 * Waiting for an empirical delay of 500 us solves the issue.
927 usleep_range(500, 600);
929 ret
= limits_update(data
);
933 ret
= sht3x_serial_number_read(data
);
935 dev_dbg(dev
, "unable to read serial number\n");
937 sht3x_debugfs_init(data
);
938 ret
= devm_add_action_or_reset(dev
,
939 sht3x_debugfs_remove
,
945 hwmon_dev
= devm_hwmon_device_register_with_info(dev
,
951 if (IS_ERR(hwmon_dev
))
952 dev_dbg(dev
, "unable to register hwmon device\n");
954 return PTR_ERR_OR_ZERO(hwmon_dev
);
957 /* device ID table */
958 static const struct i2c_device_id sht3x_ids
[] = {
964 MODULE_DEVICE_TABLE(i2c
, sht3x_ids
);
966 static struct i2c_driver sht3x_i2c_driver
= {
967 .driver
.name
= "sht3x",
968 .probe
= sht3x_probe
,
969 .id_table
= sht3x_ids
,
972 static int __init
sht3x_init(void)
974 debugfs
= debugfs_create_dir("sht3x", NULL
);
975 return i2c_add_driver(&sht3x_i2c_driver
);
977 module_init(sht3x_init
);
979 static void __exit
sht3x_cleanup(void)
981 debugfs_remove_recursive(debugfs
);
982 i2c_del_driver(&sht3x_i2c_driver
);
984 module_exit(sht3x_cleanup
);
986 MODULE_AUTHOR("David Frey <david.frey@sensirion.com>");
987 MODULE_AUTHOR("Pascal Sachs <pascal.sachs@sensirion.com>");
988 MODULE_DESCRIPTION("Sensirion SHT3x humidity and temperature sensor driver");
989 MODULE_LICENSE("GPL");