diff options
-rw-r--r-- | Documentation/hwmon/sht3x | 4 | ||||
-rw-r--r-- | drivers/hwmon/sht3x.c | 50 |
2 files changed, 54 insertions, 0 deletions
diff --git a/Documentation/hwmon/sht3x b/Documentation/hwmon/sht3x index f5aa633ed383..b0d88184f48e 100644 --- a/Documentation/hwmon/sht3x +++ b/Documentation/hwmon/sht3x | |||
@@ -67,6 +67,10 @@ temp1_alarm: alarm flag is set to 1 if the temperature is outside the | |||
67 | configured limits. Alarm only works in periodic measure mode | 67 | configured limits. Alarm only works in periodic measure mode |
68 | humidity1_alarm: alarm flag is set to 1 if the humidity is outside the | 68 | humidity1_alarm: alarm flag is set to 1 if the humidity is outside the |
69 | configured limits. Alarm only works in periodic measure mode | 69 | configured limits. Alarm only works in periodic measure mode |
70 | heater_enable: heater enable, heating element removes excess humidity from | ||
71 | sensor | ||
72 | 0: turned off | ||
73 | 1: turned on | ||
70 | update_interval: update interval, 0 for single shot, interval in msec | 74 | update_interval: update interval, 0 for single shot, interval in msec |
71 | for periodic measurement. If the interval is not supported | 75 | for periodic measurement. If the interval is not supported |
72 | by the sensor, the next faster interval is chosen | 76 | by the sensor, the next faster interval is chosen |
diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c index 707a3f85385b..b73a48832732 100644 --- a/drivers/hwmon/sht3x.c +++ b/drivers/hwmon/sht3x.c | |||
@@ -44,6 +44,10 @@ static const unsigned char sht3x_cmd_measure_nonblocking_lpm[] = { 0x24, 0x16 }; | |||
44 | static const unsigned char sht3x_cmd_measure_periodic_mode[] = { 0xe0, 0x00 }; | 44 | static const unsigned char sht3x_cmd_measure_periodic_mode[] = { 0xe0, 0x00 }; |
45 | static const unsigned char sht3x_cmd_break[] = { 0x30, 0x93 }; | 45 | static const unsigned char sht3x_cmd_break[] = { 0x30, 0x93 }; |
46 | 46 | ||
47 | /* commands for heater control */ | ||
48 | static const unsigned char sht3x_cmd_heater_on[] = { 0x30, 0x6d }; | ||
49 | static const unsigned char sht3x_cmd_heater_off[] = { 0x30, 0x66 }; | ||
50 | |||
47 | /* other commands */ | 51 | /* other commands */ |
48 | static const unsigned char sht3x_cmd_read_status_reg[] = { 0xf3, 0x2d }; | 52 | static const unsigned char sht3x_cmd_read_status_reg[] = { 0xf3, 0x2d }; |
49 | static const unsigned char sht3x_cmd_clear_status_reg[] = { 0x30, 0x41 }; | 53 | static const unsigned char sht3x_cmd_clear_status_reg[] = { 0x30, 0x41 }; |
@@ -507,6 +511,49 @@ static ssize_t humidity1_alarm_show(struct device *dev, | |||
507 | return scnprintf(buf, PAGE_SIZE, "%d\n", !!(buffer[0] & 0x08)); | 511 | return scnprintf(buf, PAGE_SIZE, "%d\n", !!(buffer[0] & 0x08)); |
508 | } | 512 | } |
509 | 513 | ||
514 | static ssize_t heater_enable_show(struct device *dev, | ||
515 | struct device_attribute *attr, | ||
516 | char *buf) | ||
517 | { | ||
518 | char buffer[SHT3X_WORD_LEN + SHT3X_CRC8_LEN]; | ||
519 | int ret; | ||
520 | |||
521 | ret = status_register_read(dev, attr, buffer, | ||
522 | SHT3X_WORD_LEN + SHT3X_CRC8_LEN); | ||
523 | if (ret) | ||
524 | return ret; | ||
525 | |||
526 | return scnprintf(buf, PAGE_SIZE, "%d\n", !!(buffer[0] & 0x20)); | ||
527 | } | ||
528 | |||
529 | static ssize_t heater_enable_store(struct device *dev, | ||
530 | struct device_attribute *attr, | ||
531 | const char *buf, | ||
532 | size_t count) | ||
533 | { | ||
534 | struct sht3x_data *data = dev_get_drvdata(dev); | ||
535 | struct i2c_client *client = data->client; | ||
536 | int ret; | ||
537 | bool status; | ||
538 | |||
539 | ret = kstrtobool(buf, &status); | ||
540 | if (ret) | ||
541 | return ret; | ||
542 | |||
543 | mutex_lock(&data->i2c_lock); | ||
544 | |||
545 | if (status) | ||
546 | ret = i2c_master_send(client, (char *)&sht3x_cmd_heater_on, | ||
547 | SHT3X_CMD_LENGTH); | ||
548 | else | ||
549 | ret = i2c_master_send(client, (char *)&sht3x_cmd_heater_off, | ||
550 | SHT3X_CMD_LENGTH); | ||
551 | |||
552 | mutex_unlock(&data->i2c_lock); | ||
553 | |||
554 | return ret; | ||
555 | } | ||
556 | |||
510 | static ssize_t update_interval_show(struct device *dev, | 557 | static ssize_t update_interval_show(struct device *dev, |
511 | struct device_attribute *attr, | 558 | struct device_attribute *attr, |
512 | char *buf) | 559 | char *buf) |
@@ -612,6 +659,8 @@ static SENSOR_DEVICE_ATTR(humidity1_min_hyst, S_IRUGO | S_IWUSR, | |||
612 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, temp1_alarm_show, NULL, 0); | 659 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, temp1_alarm_show, NULL, 0); |
613 | static SENSOR_DEVICE_ATTR(humidity1_alarm, S_IRUGO, humidity1_alarm_show, | 660 | static SENSOR_DEVICE_ATTR(humidity1_alarm, S_IRUGO, humidity1_alarm_show, |
614 | NULL, 0); | 661 | NULL, 0); |
662 | static SENSOR_DEVICE_ATTR(heater_enable, S_IRUGO | S_IWUSR, | ||
663 | heater_enable_show, heater_enable_store, 0); | ||
615 | static SENSOR_DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, | 664 | static SENSOR_DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, |
616 | update_interval_show, update_interval_store, 0); | 665 | update_interval_show, update_interval_store, 0); |
617 | 666 | ||
@@ -628,6 +677,7 @@ static struct attribute *sht3x_attrs[] = { | |||
628 | &sensor_dev_attr_humidity1_min_hyst.dev_attr.attr, | 677 | &sensor_dev_attr_humidity1_min_hyst.dev_attr.attr, |
629 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, | 678 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
630 | &sensor_dev_attr_humidity1_alarm.dev_attr.attr, | 679 | &sensor_dev_attr_humidity1_alarm.dev_attr.attr, |
680 | &sensor_dev_attr_heater_enable.dev_attr.attr, | ||
631 | &sensor_dev_attr_update_interval.dev_attr.attr, | 681 | &sensor_dev_attr_update_interval.dev_attr.attr, |
632 | NULL | 682 | NULL |
633 | }; | 683 | }; |