From patchwork Thu Jul 13 22:41:05 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: 9839683 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 0415C602D8 for ; Thu, 13 Jul 2017 22:41:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3658627F97 for ; Thu, 13 Jul 2017 22:41:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B06428778; Thu, 13 Jul 2017 22:41:55 +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=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 B237D28113 for ; Thu, 13 Jul 2017 22:41:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753100AbdGMWlR (ORCPT ); Thu, 13 Jul 2017 18:41:17 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:35617 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753009AbdGMWlP (ORCPT ); Thu, 13 Jul 2017 18:41:15 -0400 Received: by mail-pf0-f169.google.com with SMTP id c73so36034733pfk.2 for ; Thu, 13 Jul 2017 15:41: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=vRce3Ix8oYH9aBWtxGJJxv5mg+AsXteOzrXpRgO8SFM=; b=TsmM7GRtRZyb5oPD+OaKkqOD3PCeZWaAXkXXxUPbJrhd6hahknI1sxJU0C7f1HuvZa 51XxZP8KiUWJdrvka55gjzGDwfkS0204j2UoFis+ZvahNjMkx7jPvFKlIA4m8Pffrh5W /QB4Y4hC1hflrRUAKXZ5y1cob7YhkEZkTBRivaGyFXl5x7+MkB5Moo/qscJdXe0Er65j ScW2NneLupgvPkop/5LO9CdRRqe2hZEekVAozCHCja+HG11tcRF5UnwFyyTOvF/h0JIU sF+BWnqmd5O08eYI8EwNRBlsWihETiDwhjrzqO69S4jeWmwoHhjE3rv9DEsNMrqvP64J HWwg== 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=vRce3Ix8oYH9aBWtxGJJxv5mg+AsXteOzrXpRgO8SFM=; b=dofOzht5xONhcJi1I6gdYECYNUeyvTkI/4iGD2wxx/xbthWlJ+y5uqaKm4cnCFSza2 LGEuCefyUdIV2Oc650WGrbeOAYblUVZA6eJKhPk67SpKWn3tTiJg/Q5MTniVdqkIBv3A gIsp+a13xKRESmJASoNqvyCCTDFojn4clYzCmEtO725OhToyo+0RUCXGCLk/12ESuBJP lNsJbMHMkRuDK2ub2MNZ4YLwM3idkW6+1bx1eTBEL288FOoY/t52mWkJFrPQ0Pn7n7+J Zuj8O1KJOEiIxbw6TjWdlgkXEg/wuTjVvnZZBcSJWmnHaVrIi/Frpddjt5R2P3dMgA7I 7VAA== X-Gm-Message-State: AIVw110lFjsJPBJTHiYH1iFWVU3wDMGUegKH7565j9mGvia5L83FCelb kNkNDW1RMZ1CVfmz X-Received: by 10.84.131.74 with SMTP id 68mr12562204pld.8.1499985674564; Thu, 13 Jul 2017 15:41:14 -0700 (PDT) Received: from jaghu22.svl.corp.google.com ([100.123.242.38]) by smtp.gmail.com with ESMTPSA id h90sm17149260pfh.133.2017.07.13.15.41.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jul 2017 15:41:13 -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 v4 1/3] drivers: w1: add hwmon support structures Date: Thu, 13 Jul 2017 15:41:05 -0700 Message-Id: <20170713224107.12789-2-jaghu@google.com> X-Mailer: git-send-email 2.13.2.932.g7449e964c-goog In-Reply-To: <20170713224107.12789-1-jaghu@google.com> References: <20170713224107.12789-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 patch has changes to w1.h/w1.c/w1_family.h generic files to add (optional) hwmon support structures. Signed-off-by: Jaghathiswari Rankappagounder Natarajan Acked-by: Evgeniy Polyakov Acked-by: Guenter Roeck --- v2 - made changes to support hwmon_device_register_with_info mentioned by Guenter. v3 - used IS_REACHABLE(CONFIG_HWMON). - removed hwmon device first before removing slave. v4 - moved && to be in the previous line. drivers/w1/w1.c | 18 +++++++++++++++++- drivers/w1/w1.h | 2 ++ drivers/w1/w1_family.h | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) -- 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/w1.c b/drivers/w1/w1.c index e213c678bbfe..6485603131e8 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -659,9 +660,24 @@ static int w1_family_notify(unsigned long action, struct w1_slave *sl) return err; } } - + if (IS_REACHABLE(CONFIG_HWMON) && fops->chip_info) { + struct device *hwmon + = hwmon_device_register_with_info(&sl->dev, + "w1_slave_temp", sl, + fops->chip_info, + NULL); + if (IS_ERR(hwmon)) { + dev_warn(&sl->dev, + "could not create hwmon device\n"); + } else { + sl->hwmon = hwmon; + } + } break; case BUS_NOTIFY_DEL_DEVICE: + if (IS_REACHABLE(CONFIG_HWMON) && fops->chip_info && + sl->hwmon) + hwmon_device_unregister(sl->hwmon); if (fops->remove_slave) sl->family->fops->remove_slave(sl); if (fops->groups) diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h index 129895f562b0..74ef1a543856 100644 --- a/drivers/w1/w1.h +++ b/drivers/w1/w1.h @@ -83,6 +83,7 @@ struct w1_reg_num * @family: module for device family type * @family_data: pointer for use by the family module * @dev: kernel device identifier + * @hwmon: pointer to hwmon device * */ struct w1_slave @@ -99,6 +100,7 @@ struct w1_slave struct w1_family *family; void *family_data; struct device dev; + struct device *hwmon; }; typedef void (*w1_slave_found_callback)(struct w1_master *, u64); diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h index 10a7a0767187..9001851e1316 100644 --- a/drivers/w1/w1_family.h +++ b/drivers/w1/w1_family.h @@ -55,12 +55,14 @@ struct w1_slave; * @add_slave: add_slave * @remove_slave: remove_slave * @groups: sysfs group + * @chip_info: pointer to struct hwmon_chip_info */ struct w1_family_ops { int (* add_slave)(struct w1_slave *); void (* remove_slave)(struct w1_slave *); const struct attribute_group **groups; + const struct hwmon_chip_info *chip_info; }; /**