From patchwork Wed Jun 14 21:59:44 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: 9787497 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 1B76D602D9 for ; Wed, 14 Jun 2017 22:00:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F30C2852C for ; Wed, 14 Jun 2017 22:00:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0385D28576; Wed, 14 Jun 2017 22:00:05 +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, 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 895922852C for ; Wed, 14 Jun 2017 22:00:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751606AbdFNV75 (ORCPT ); Wed, 14 Jun 2017 17:59:57 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:34392 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752628AbdFNV7z (ORCPT ); Wed, 14 Jun 2017 17:59:55 -0400 Received: by mail-pf0-f181.google.com with SMTP id s66so6543343pfs.1 for ; Wed, 14 Jun 2017 14:59:55 -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=RCSJScg8z6wRZ/wq2RTGntIRsoTNcAKxOWjNgmEmhWs=; b=Zudbc4imAmTLkwLttRsgBWpDmIzcJre5vXXwMU49A3wpgd3UAo0248J5hgv59CKQ2X Uar8/VLHLNMQ5Va9+3bjjbfX3zVfrNhvT2RdnedmcTnsWamSw2hP0K5NVcdz7qxpZqkx +YWeaCyeaFYz2FOYpu4Qu6Q/LQIMoIEWdaCPmKhc+97gfFacs/4BxIpT08nT8rCP9wOL LH/OpgbBlbehm12agVfoMEKDlcfuGs34onTEGm99j4QAXSiG457wJraq86GhcIKfG/6H Mzp560JpUS9kA05vnieI4QR8NQaSPyEDGSytovxEaC6csNrPVsWXA/D7Yhh/hEYa7qqD mcEg== 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=RCSJScg8z6wRZ/wq2RTGntIRsoTNcAKxOWjNgmEmhWs=; b=ASfzDIJ0lGcqFd+pUah8ZjqelSCqOweozUREM1laNi7VfrdI1Qy2tci0IInkC+QFvu lemAMs7KTDQEKmPXOVIh/W4s98xqH917KerWuGo1QtXVwFxmEvAjMdJaCkni2+ZdjoSL l7gD2i7W1d6hH1chxqbw+zU0wUGa1H4DpLuoCL1cDPXvLwgExhSVaUjFaRFR64O8/V6q bNjA04lEeeXVHMNzwl9EwbhG1Y2LEtQIs3maWbwjw5PoVxhNh4mYi7PU5ZizguF7pOov EXdC8fUvsDix0D0gN05B6fD2xwFKs8IF27Jp72cXePFh622b5rCCoFy0N6L3FQsPjy9V ZnYg== X-Gm-Message-State: AKS2vOwab6h9f9cjdNVvxawJ59VL3UMef4CAqcL1tjkr8stBy2YG3vTL PZp42jxmZs6ImFqo X-Received: by 10.99.154.18 with SMTP id o18mr1992596pge.251.1497477594788; Wed, 14 Jun 2017 14:59:54 -0700 (PDT) Received: from jaghu22.svl.corp.google.com ([100.123.242.38]) by smtp.gmail.com with ESMTPSA id e18sm1787757pfk.118.2017.06.14.14.59.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 14:59:54 -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 v1 3/3] drivers: w1: add hwmon temp support for w1_therm Date: Wed, 14 Jun 2017 14:59:44 -0700 Message-Id: <20170614215944.24984-4-jaghu@google.com> X-Mailer: git-send-email 2.13.1.508.gb3defc5cc-goog In-Reply-To: <20170614215944.24984-1-jaghu@google.com> References: <20170614215944.24984-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 Change-Id: I66c0837d63b5a5839227319608eb8061b917f5fa --- drivers/w1/slaves/w1_therm.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) -- 2.13.1.508.gb3defc5cc-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 88f4cc8c3908..dba2d21fa731 100644 --- a/drivers/w1/slaves/w1_therm.c +++ b/drivers/w1/slaves/w1_therm.c @@ -105,8 +105,12 @@ static ssize_t w1_slave_store(struct device *device, static ssize_t w1_seq_show(struct device *device, struct device_attribute *attr, char *buf); +static ssize_t temp1_input_show(struct device *device, + struct device_attribute *attr, char *buf); + static DEVICE_ATTR_RW(w1_slave); static DEVICE_ATTR_RO(w1_seq); +static DEVICE_ATTR_RO(temp1_input); static struct attribute *w1_therm_attrs[] = { &dev_attr_w1_slave.attr, @@ -118,19 +122,27 @@ static struct attribute *w1_ds28ea00_attrs[] = { &dev_attr_w1_seq.attr, NULL, }; +static struct attribute *w1_therm_hwmon_attrs[] = { + &dev_attr_temp1_input.attr, + NULL, +}; + ATTRIBUTE_GROUPS(w1_therm); ATTRIBUTE_GROUPS(w1_ds28ea00); +ATTRIBUTE_GROUPS(w1_therm_hwmon); static struct w1_family_ops w1_therm_fops = { .add_slave = w1_therm_add_slave, .remove_slave = w1_therm_remove_slave, .groups = w1_therm_groups, + .hwmon_groups = w1_therm_hwmon_groups, }; static struct w1_family_ops w1_ds28ea00_fops = { .add_slave = w1_therm_add_slave, .remove_slave = w1_therm_remove_slave, .groups = w1_ds28ea00_groups, + .hwmon_groups = w1_therm_hwmon_groups, }; static struct w1_family w1_therm_family_DS18S20 = { @@ -559,6 +571,38 @@ static ssize_t w1_slave_show(struct device *device, return ret; } +static ssize_t temp1_input_show(struct device *device, + struct device_attribute *attr, char *buf) +{ + struct w1_slave *sl = dev_get_drvdata(device); + u8 *family_data = sl->family_data; + struct therm_info info; + int ret; + + if (!sl->family_data) + return -ENODEV; + + /* prevent the slave from going away in sleep */ + atomic_inc(THERM_REFCNT(family_data)); + + ret = read_therm(device, sl, &info); + if (ret) + goto dec_refcnt; + + if (!info.verdict) { + dev_warn(device, "Read failed CRC check\n"); + ret = -EIO; + goto dec_refcnt; + } + + ret = sprintf(buf, "%d\n", + w1_convert_temp(info.rom, sl->family->fid)); + +dec_refcnt: + atomic_dec(THERM_REFCNT(family_data)); + return ret; +} + #define W1_42_CHAIN 0x99 #define W1_42_CHAIN_OFF 0x3C #define W1_42_CHAIN_OFF_INV 0xC3