From patchwork Wed Aug 30 23:34:35 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: 9930971 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 AC82560380 for ; Wed, 30 Aug 2017 23:35:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F089287D7 for ; Wed, 30 Aug 2017 23:35:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 929CE287E2; Wed, 30 Aug 2017 23:35:14 +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=unavailable 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 26016287D7 for ; Wed, 30 Aug 2017 23:35:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751155AbdH3XfN (ORCPT ); Wed, 30 Aug 2017 19:35:13 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:36322 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751404AbdH3Xeo (ORCPT ); Wed, 30 Aug 2017 19:34:44 -0400 Received: by mail-pg0-f43.google.com with SMTP id r133so23931760pgr.3 for ; Wed, 30 Aug 2017 16:34:43 -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=Cu04ZLJY7XZmf1TFwgbr5vhbQWyga9sGkKYUNBmPErM=; b=nwaKlg7G7eSn/9OILdjGfKTE0NqF50p4AHSJIxntL6OpQ4fQB112PptWpXfeMm/sKB +GHFzMg0SnwXcCg2X0y7GuQkZuMZUm4jli9FPToEb+uP+D5mNgxjdulHnqQge1O7zNR/ +fwZrbSPFxRhPRUQTrqnQXTvjlXKyj6I4tjXJydjyyesZE/d2nW55o9SjdypPaSQGcH+ Iz9NrzdiNuH5YPIosr7gxf16TL3L1pLuRE4WNiUJ9+UMyjBRdwkW2GDBN+1Yir7H18Ia RMv5kEzKbNd3P9JP546A1rdbjHPUXi/oLHiBBe3S5xqce1gSo6DddNaaFtKSiQ9NbaRX +lmw== 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=Cu04ZLJY7XZmf1TFwgbr5vhbQWyga9sGkKYUNBmPErM=; b=aA5LjXybtePrtObcDL+tSTo3mghEZ9gLuailWfiPOb3B20NlkvAae6JH0Ro+IWN1xI Hlm+5U0wDxEwpopAvvAaeRyMzStUOkfnVMdqb3plbW/S9LVvBpxehZXXq9yiRfAJ5vO+ fnqtzJPbxfB/25jijBAknd0/DBq0p4dQU4eIty/Pwerrf5a1GBAsl9MiGpAwVdGP+lva OFC0msXT9Z6Fr085F/RftXY2VH3HOqVkeRBxIZDKXFFM4Rfq1D2JdtC/olIy/cn+iufF j7IKnqDS39HoinwZ1K4T88ZmE7v857BSVLvEhieKejJruj8GPSP1yK4+93Je3DdyCNcb VWeA== X-Gm-Message-State: AHYfb5heU+dmDkwK6xr9CcdtYOENbic+WRf4sURA6s3gwH3wMjtiyJYh We/Xsm5WtFIaPSpq X-Google-Smtp-Source: ADKCNb7bj1DBfzrkocvs5RCrFhVWzYrv79KAu9KJ+ZvTCHVw0xpBwxytWoo+563iZ3QwrHzksBf8ng== X-Received: by 10.99.1.88 with SMTP id 85mr254286pgb.1.1504136083341; Wed, 30 Aug 2017 16:34:43 -0700 (PDT) Received: from jaghu22.svl.corp.google.com ([100.123.242.38]) by smtp.gmail.com with ESMTPSA id n74sm10288826pfk.45.2017.08.30.16.34.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 16:34:42 -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 v6 3/3] drivers: w1: add hwmon temp support for w1_therm Date: Wed, 30 Aug 2017 16:34:35 -0700 Message-Id: <20170830233435.16500-4-jaghu@google.com> X-Mailer: git-send-email 2.14.1.581.gf28d330327-goog In-Reply-To: <20170830233435.16500-1-jaghu@google.com> References: <20170830233435.16500-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 v5 - no change v6 - rebased on top of char-misc-next branch drivers/w1/slaves/w1_therm.c | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) -- 2.14.1.581.gf28d330327-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 faddc2488c91..259525c3382a 100644 --- a/drivers/w1/slaves/w1_therm.c +++ b/drivers/w1/slaves/w1_therm.c @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -113,19 +114,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 = { @@ -554,6 +608,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