From patchwork Thu Jul 13 21:06:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaghathiswari Rankappagounder Natarajan X-Patchwork-Id: 9839537 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 162EE602BD for ; Thu, 13 Jul 2017 18:05:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8059B2875B for ; Thu, 13 Jul 2017 21:07:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 724B42876D; Thu, 13 Jul 2017 21:07:40 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 793DD28756 for ; Thu, 13 Jul 2017 21:07:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752735AbdGMVHF (ORCPT ); Thu, 13 Jul 2017 17:07:05 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:36701 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751295AbdGMVHE (ORCPT ); Thu, 13 Jul 2017 17:07:04 -0400 Received: by mail-pf0-f181.google.com with SMTP id q86so35047860pfl.3 for ; Thu, 13 Jul 2017 14:07:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=svOlv0X4kj32121kWRFfsmOTAlpzXyeoks2p4AETI3M=; b=N8GkbIzY1RyA8B/5sSIR3xzk5hV9WJv46CbOzVcsFWCo7KbByGp+sRXj+zpjcVji3+ xhPwX6nQhqAfwTVoJhR8vC5slZiGrDG4oHBLXCBVPoPXuRHHMGicbL1gl2qrdc1+5BlV b3UzlGW5nBKITuoTYxrKQCdFNnOefK/Mw6VA84QNFYdkKNlg94z2MT47EheNt5+V9Jlw agqlPQ+vC3tt8LzChI7McI62Zo9ghWmM1AgYYq5ECiPHDdVnAHQ8Frn8L1wqTEaGECAr z2+mv862kqPo8BF6wi1mmnHc4iWBSwqD2H/gHiS/crQibBTf5uaTex2vM2i0zzmq9vwd MYNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=svOlv0X4kj32121kWRFfsmOTAlpzXyeoks2p4AETI3M=; b=rSBHjgEx8r2wkCwSdoAcXREMthOA9fw1svz/bwsvFvfqV8ITbmm6kVs9y+sT5C5vPy mVQqaetP6lC5GIOBH9AYAfuVZdC0yCglFexTdFM9iSpIgo3taKLjF72w91kUtq2uTmk1 uENXbloVURX79hDjPxrDx109WG9ZUA9gmXqvLh1b4QP8DX0DMXuhKFmNx+8e4vmHnYhN DDMc0hnUn9SDsrVMaxzBK5t4EEFh3DJ+SEtpu2j6bUnXzb8kWm89F7z7c/XXbZE4toM1 GX3NpvMJyE3/oRIRpREtzn3jLp+nFeIOfX/EUbIZLsjmao28mYqPcBGCKcIfgIwQZoH3 JpHw== X-Gm-Message-State: AIVw110JkqWkv0rTTv2jJiHPPb/OuKWHTwVQtwmvnJOANdCzu9JKVVpi oU+yPkeOHQymLTAD X-Received: by 10.99.0.209 with SMTP id 200mr11397052pga.138.1499980018267; Thu, 13 Jul 2017 14:06:58 -0700 (PDT) Received: from jaghu22.svl.corp.google.com ([100.123.242.38]) by smtp.gmail.com with ESMTPSA id i19sm16244414pfj.78.2017.07.13.14.06.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jul 2017 14:06:57 -0700 (PDT) From: Jaghathiswari Rankappagounder Natarajan To: zbr@ioremap.net, linux-kernel@vger.kernel.org, linux@roeck-us.net, jdelvare@suse.com, linux-hwmon@vger.kernel.org Cc: Jaghathiswari Rankappagounder Natarajan Subject: [PATCH linux v3 3/3] drivers: w1: add hwmon temp support for w1_therm Date: Thu, 13 Jul 2017 14:06:49 -0700 Message-Id: <20170713210649.16188-4-jaghu@google.com> X-Mailer: git-send-email 2.13.2.932.g7449e964c-goog In-Reply-To: <20170713210649.16188-1-jaghu@google.com> References: <20170713210649.16188-1-jaghu@google.com> 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 This change adds hwmon temp support for w1_therm. Signed-off-by: Jaghathiswari Rankappagounder Natarajan Acked-by: Evgeniy Polyakov --- v2 - make changes to support hwmon_device_register_with_info mentioned by Guenter. v3 - used IS_REACHABLE() - rearranged the code to not require forward declarations - used family_data - incremented the reference count with the bus mutex locked - corrected indentation - removed dev_warn message - simplified returning mode - removed write function drivers/w1/slaves/w1_therm.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) -- 2.13.2.932.g7449e964c-goog -- To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c index 64e6a8f38410..b7d13220dd8f 100644 --- a/drivers/w1/slaves/w1_therm.c +++ b/drivers/w1/slaves/w1_therm.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "../w1.h" #include "../w1_int.h" @@ -118,19 +119,77 @@ static struct attribute *w1_ds28ea00_attrs[] = { &dev_attr_w1_seq.attr, NULL, }; + ATTRIBUTE_GROUPS(w1_therm); ATTRIBUTE_GROUPS(w1_ds28ea00); +#if IS_REACHABLE(CONFIG_HWMON) +static int w1_read_temp(struct device *dev, u32 attr, int channel, + long *val); + +static umode_t w1_is_visible(const void *_data, enum hwmon_sensor_types type, + u32 attr, int channel) +{ + return attr == hwmon_temp_input ? 0444 : 0; +} + +static int w1_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + switch (type) { + case hwmon_temp: + return w1_read_temp(dev, attr, channel, val); + default: + return -EOPNOTSUPP; + } +} + +static const u32 w1_temp_config[] = { + HWMON_T_INPUT, + 0 +}; + +static const struct hwmon_channel_info w1_temp = { + .type = hwmon_temp, + .config = w1_temp_config, +}; + +static const struct hwmon_channel_info *w1_info[] = { + &w1_temp, + NULL +}; + +static const struct hwmon_ops w1_hwmon_ops = { + .is_visible = w1_is_visible, + .read = w1_read, +}; + +static const struct hwmon_chip_info w1_chip_info = { + .ops = &w1_hwmon_ops, + .info = w1_info, +}; +#endif + static struct w1_family_ops w1_therm_fops = { .add_slave = w1_therm_add_slave, .remove_slave = w1_therm_remove_slave, .groups = w1_therm_groups, +#if IS_REACHABLE(CONFIG_HWMON) + .chip_info = &w1_chip_info, +#else + .chip_info = NULL, +#endif }; static struct w1_family_ops w1_ds28ea00_fops = { .add_slave = w1_therm_add_slave, .remove_slave = w1_therm_remove_slave, .groups = w1_ds28ea00_groups, +#if IS_REACHABLE(CONFIG_HWMON) + .chip_info = &w1_chip_info, +#else + .chip_info = NULL, +#endif }; static struct w1_family w1_therm_family_DS18S20 = { @@ -559,6 +618,38 @@ static ssize_t w1_slave_show(struct device *device, return ret; } +#if IS_REACHABLE(CONFIG_HWMON) +static int w1_read_temp(struct device *device, u32 attr, int channel, + long *val) +{ + struct w1_slave *sl = dev_get_drvdata(device); + struct therm_info info; + u8 fid = sl->family->fid; + int ret; + + switch (attr) { + case hwmon_temp_input: + ret = read_therm(device, sl, &info); + if (ret) + return ret; + + if (!info.verdict) { + ret = -EIO; + return ret; + } + + *val = w1_convert_temp(info.rom, fid); + ret = 0; + break; + default: + ret = -EOPNOTSUPP; + break; + } + + return ret; +} +#endif + #define W1_42_CHAIN 0x99 #define W1_42_CHAIN_OFF 0x3C #define W1_42_CHAIN_OFF_INV 0xC3