From patchwork Fri Jul 8 03:22:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Ranostay X-Patchwork-Id: 9219987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0D8E560574 for ; Fri, 8 Jul 2016 03:22:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0317027D13 for ; Fri, 8 Jul 2016 03:22:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAABF2810E; Fri, 8 Jul 2016 03:22:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AE6027D13 for ; Fri, 8 Jul 2016 03:22:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753694AbcGHDWO (ORCPT ); Thu, 7 Jul 2016 23:22:14 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33510 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753600AbcGHDWO (ORCPT ); Thu, 7 Jul 2016 23:22:14 -0400 Received: by mail-pf0-f196.google.com with SMTP id c74so3429494pfb.0 for ; Thu, 07 Jul 2016 20:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=7HhLF3uhlp0cayuMB0xGukiPR95zfl24kXqLLx2c20k=; b=xRXC17EgtZugfGJbfasod55kFHpfIAp0w+tjVysonZEntys8agv3U7xxYrDkoMo2MR agv8RBcXKUJRX7HIklZ8gAOGOIvxWBJJkFQlBksxf1DXsyEgJxMtnM9Mjl5C1mcuzArd AJeT7sMopON1BA8b9H9/CoISf6fX6PTM8y4LFJ/7YpjAWdzwSlQilOKytG5xzZQi9Tmr nT6MeA4XtJwAognWcr3eDg7F2yI7bHQ4WegY4Yz3FqlL9zdZm8jGLCueib5/fQZu0IID fsGFA3Z1DutBm9LO95nGLWNCFwefuv1UFdJjsGQbq3PK16S43WdHqEjibh3JchslDN1S ltPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7HhLF3uhlp0cayuMB0xGukiPR95zfl24kXqLLx2c20k=; b=K576dfdEvTNkEJxCDs2tBZiloePMcOk57nPLPAumjKtwy0KiLjLPzdrhspqBp8+388 x21d8uC4tsPd2CSZahUuwsWWohNstBJDsQuGP3jXi0w/jTcods6kSlJfBIGyPAbCcb0e /ti3zWSZXYjRNs7gkrlFXHKaRVXmk4uxXiwlNCD9t4fCadlWKi59gIwwWte0XFtuLkar h/PxdwUuwfUQn03H/VBqCEMPmub8iA5FIpxZIUc3ZgzK8lyO9dOKHXJuMgU+NvIj4+Nb Dbic4Baqc1wLmHRuiRuL+gvAZWzEqm9W09jMzuvTnE4IIWPUqGLHsEK0c3zy3NXujD1M Cy/A== X-Gm-Message-State: ALyK8tK3ldMI/2WC6gHUGOsD1au9X38oO82kn7xCxPrR0Lf49ESDd1YjEBTcg+pjr1Eh5Q== X-Received: by 10.98.20.216 with SMTP id 207mr6140672pfu.144.1467948133544; Thu, 07 Jul 2016 20:22:13 -0700 (PDT) Received: from localhost.localdomain (c-73-25-156-150.hsd1.or.comcast.net. [73.25.156.150]) by smtp.gmail.com with ESMTPSA id j8sm640893paj.22.2016.07.07.20.22.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Jul 2016 20:22:12 -0700 (PDT) From: Matt Ranostay To: linux-hwmon@vger.kernel.org Cc: Matt Ranostay , Guenter Roeck , David Frey Subject: [PATCH] hwmon: sht3x: add humidity heater element control Date: Thu, 7 Jul 2016 20:22:00 -0700 Message-Id: <1467948120-25304-1-git-send-email-mranostay@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The enables control of the SHT31 sensors heating element that can turned on to remove excess humidity. Cc: Guenter Roeck Cc: David Frey Signed-off-by: Matt Ranostay --- Documentation/hwmon/sht3x | 2 ++ drivers/hwmon/sht3x.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/Documentation/hwmon/sht3x b/Documentation/hwmon/sht3x index f5aa633ed383..fb1d3f1d641f 100644 --- a/Documentation/hwmon/sht3x +++ b/Documentation/hwmon/sht3x @@ -67,6 +67,8 @@ temp1_alarm: alarm flag is set to 1 if the temperature is outside the configured limits. Alarm only works in periodic measure mode humidity1_alarm: alarm flag is set to 1 if the humidity is outside the configured limits. Alarm only works in periodic measure mode +heater_enable: heater enable, 1 for heating element turned on. Heating + element removes excess humidity from sensor 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 diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c index b2c655add70e..05a925257938 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 }; static const unsigned char sht3x_cmd_measure_periodic_mode[] = { 0xe0, 0x00 }; static const unsigned char sht3x_cmd_break[] = { 0x30, 0x93 }; +/* commands for heater control */ +static const unsigned char sht3x_cmd_heater_on[] = { 0x30, 0x6d }; +static const unsigned char sht3x_cmd_heater_off[] = { 0x30, 0x66 }; + /* other commands */ static const unsigned char sht3x_cmd_read_status_reg[] = { 0xf3, 0x2d }; static const unsigned char sht3x_cmd_clear_status_reg[] = { 0x30, 0x41 }; @@ -507,6 +511,51 @@ static ssize_t humidity1_alarm_show(struct device *dev, return scnprintf(buf, PAGE_SIZE, "%d\n", !!(buffer[0] & 0x08)); } +static ssize_t heater_enable_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + char buffer[SHT3X_WORD_LEN + SHT3X_CRC8_LEN]; + int ret; + + ret = status_register_read(dev, attr, buffer, + SHT3X_WORD_LEN + SHT3X_CRC8_LEN); + if (ret) + return ret; + + return scnprintf(buf, PAGE_SIZE, "%d\n", !!(buffer[0] & 0x20)); +} + +static ssize_t heater_enable_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t count) +{ + struct sht3x_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; + int ret; + int status; + + ret = kstrtoint(buf, 0, &status); + if (ret) + return ret; + + mutex_lock(&data->data_lock); + mutex_lock(&data->i2c_lock); + + if (status) + ret = i2c_master_send(client, (char *) &sht3x_cmd_heater_on, + SHT3X_CMD_LENGTH); + else + ret = i2c_master_send(client, (char *) &sht3x_cmd_heater_off, + SHT3X_CMD_LENGTH); + + mutex_unlock(&data->i2c_lock); + mutex_unlock(&data->data_lock); + + return ret; +} + static ssize_t update_interval_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -612,6 +661,8 @@ static SENSOR_DEVICE_ATTR(humidity1_min_hyst, S_IRUGO | S_IWUSR, static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, temp1_alarm_show, NULL, 0); static SENSOR_DEVICE_ATTR(humidity1_alarm, S_IRUGO, humidity1_alarm_show, NULL, 0); +static SENSOR_DEVICE_ATTR(heater_enable, S_IRUGO | S_IWUSR, + heater_enable_show, heater_enable_store, 0); static SENSOR_DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, update_interval_show, update_interval_store, 0); @@ -628,6 +679,7 @@ static struct attribute *sht3x_attrs[] = { &sensor_dev_attr_humidity1_min_hyst.dev_attr.attr, &sensor_dev_attr_temp1_alarm.dev_attr.attr, &sensor_dev_attr_humidity1_alarm.dev_attr.attr, + &sensor_dev_attr_heater_enable.dev_attr.attr, &sensor_dev_attr_update_interval.dev_attr.attr, NULL };