From patchwork Mon Jul 17 23:09:06 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: 9846457 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 53EC26037F for ; Mon, 17 Jul 2017 23:09:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7391221E5A for ; Mon, 17 Jul 2017 23:09:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6877B25223; Mon, 17 Jul 2017 23:09:32 +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 CF01221E5A for ; Mon, 17 Jul 2017 23:09:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751836AbdGQXJa (ORCPT ); Mon, 17 Jul 2017 19:09:30 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:34688 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751661AbdGQXJP (ORCPT ); Mon, 17 Jul 2017 19:09:15 -0400 Received: by mail-pf0-f180.google.com with SMTP id q85so1990350pfq.1 for ; Mon, 17 Jul 2017 16:09:15 -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=zEkNyU+xJRuXq26LI5PvGfXmyo3qxmPOSyN6EdkrUEs=; b=AEgj8mRMNwCQHOt1h0NtwnD7JH6sOHiIF9pFulcpxzHtWTA5B22p74hov51UghvGOi sn7sOXZM9osgrvH69Nli89Kl6QgRW72rne1PFhxjlN9sVO2YxPuFFQiAIzNi9qdPchKy wIwLNRQtQzK6Etejf1tu9aKUabeq83nd10vbNUUgQwy+4eSuC7DUgkOPRgl8p4DJBEv+ tMkwGrXGsSqgCP8j7fjaeZjUJ4m9+UbGlvL9Of5Kd8dbKtCVcI8cZ+Npsjs6NJN6A9fN cpP0RevPHO+38Ep1+x9GaSUjhqpjP9sZMkUdNciJx+DKP4540qI/Lysck0AX2h5dzD7T niUA== 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=zEkNyU+xJRuXq26LI5PvGfXmyo3qxmPOSyN6EdkrUEs=; b=QALQBnCOrn5ITF3vZJcr2yqsQIiNvmNKMC43XKKIvwRqSbznvul/F0oRGlCWaX7lsy ARrk/fbQOcFqOpWWDN95IwpcoU6l5KwCCvOvfRFupyiR4hEMzpCzH8zgASJfRURxYD4H 853Vdx5HURQdb+2jj+aehQ6CM42iMcDxDgS0Z9FPIgT7FeOHb9rzBplvZDF+q+cjo8sF u1UT3+z6cVdiCWyjE2DuXWc8N24Q6x7/w4jC5Yk/QV8DzkvYxUSgyNCNv6Nhd4dMaFI7 pOtG7zgcHrsq8Fy251Feup6cIOGqB8OGsmAOnW9SR+YJjJf/RoyI//oFHFVgb+8mXXcp s3wQ== X-Gm-Message-State: AIVw110tzxpndmW7ycFh6vQNIRiS99fKVzNExYPCEd5UgdC9WevJ6U1h T4UCmm65PLddh1FwsdNy/Q== X-Received: by 10.98.218.20 with SMTP id c20mr21782462pfh.112.1500332955180; Mon, 17 Jul 2017 16:09:15 -0700 (PDT) Received: from jaghu22.svl.corp.google.com ([100.123.242.38]) by smtp.gmail.com with ESMTPSA id e131sm461273pgc.64.2017.07.17.16.09.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Jul 2017 16:09:14 -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, gregkh@linuxfoundation.org Cc: Jaghathiswari Rankappagounder Natarajan Subject: [PATCH linux v5 3/3] drivers: w1: add hwmon temp support for w1_therm Date: Mon, 17 Jul 2017 16:09:06 -0700 Message-Id: <20170717230906.4084-4-jaghu@google.com> X-Mailer: git-send-email 2.13.2.932.g7449e964c-goog In-Reply-To: <20170717230906.4084-1-jaghu@google.com> References: <20170717230906.4084-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 Acked-by: Guenter Roeck --- 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 v4 - used W1_CHIP_INFO - corrected formatting drivers/w1/slaves/w1_therm.c | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 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..c99886ac1dbf 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,72 @@ 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, +}; +#define W1_CHIPINFO (&w1_chip_info) +#else +#define W1_CHIPINFO NULL +#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, + .chip_info = W1_CHIPINFO, }; static struct w1_family_ops w1_ds28ea00_fops = { .add_slave = w1_therm_add_slave, .remove_slave = w1_therm_remove_slave, .groups = w1_ds28ea00_groups, + .chip_info = W1_CHIPINFO, }; static struct w1_family w1_therm_family_DS18S20 = { @@ -559,6 +613,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