From patchwork Thu Jul 13 21:06:47 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: 9839549 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 E67D6602BD for ; Thu, 13 Jul 2017 18:05:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E24925F3E for ; Thu, 13 Jul 2017 21:07:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 527AF28179; Thu, 13 Jul 2017 21:07:42 +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 074BA2872A for ; Thu, 13 Jul 2017 21:07:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752807AbdGMVH1 (ORCPT ); Thu, 13 Jul 2017 17:07:27 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:33135 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752314AbdGMVG4 (ORCPT ); Thu, 13 Jul 2017 17:06:56 -0400 Received: by mail-pg0-f54.google.com with SMTP id k14so35422157pgr.0 for ; Thu, 13 Jul 2017 14:06: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=Nq8gfsD3KTVpTfFYJlqsrnuU0ZOCltqe+LgDNLc9a08=; b=rASD+wplVyhKK3HwfsDlndzQFgxZNm6A4s7aa8dcx4XF+pWvlQe71RLo7PcxkS1MEb UtZIfX5ZH7srZfWJYQ8AXYK3ZQWwpCh+Vjkhq5J1L2s0S/h/6FFhl1dV3f/EK+9I845C zTzBUmMNj0Nm7vAWq5aYPWVFKlrFn1RIgVQ1lOGfts8cElB9BtInjYE1b6vdj+wVVAYi CFyFX8y+eMA0GfLf3qE9JoqY2QijtBJiikewxFTstwqPkJ7j3HMSXzBX4GWyRDMV1Zdk AtSkGDH+8DDE08egAjRKus9vKwUnYXuNm6jwch5rGlgDFyCUSeTR+cnbTSMW2UK79khO C4xA== 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=Nq8gfsD3KTVpTfFYJlqsrnuU0ZOCltqe+LgDNLc9a08=; b=JRRwqj523cvR5rfzolrsAlhOeEn5MV940pU9ub/7Eb3fAvxuWHOqanmf//XvA8u+Cp wXKVaLJvKUkO/7jmsFlb8aP2Nu1XWJ/OwtfRiGixSUptNs+cQNiaBEGTzHNg39w3zj9R NsMoFplkHWgwBcfsfcLaS00npJAvprmG5pg0mer0GVyq1dSY3jnv5TxLUzLBVAiuDoHO y+CI2NFCS6com6BRR5vZ6ZbZi1OwdqBRa4/Xg0yefo+LThvbSKFLIBT097VLxTaA62TG 0of3oX1SO97nSybjIy5IdvH8LWHfa8wzTCrq/WPYApPNFY0eAdMoKh1nzQplad9kcRu8 bacQ== X-Gm-Message-State: AIVw1118Y8TtnHWjFHMGKMMmMx/JMkgAP2FBhAFLqCS8dX1B3eDEENGi uUgFfwkzxxOX5uYG X-Received: by 10.84.169.67 with SMTP id g61mr12038425plb.155.1499980015295; Thu, 13 Jul 2017 14:06:55 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jul 2017 14:06: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 v3 1/3] drivers: w1: add hwmon support structures Date: Thu, 13 Jul 2017 14:06:47 -0700 Message-Id: <20170713210649.16188-2-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 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. 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..0e5423c1d31c 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; }; /**