From patchwork Mon Jul 17 23:09:04 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: 9846455 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 535066037F for ; Mon, 17 Jul 2017 23:09:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7351D21E5A for ; Mon, 17 Jul 2017 23:09:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6857425223; Mon, 17 Jul 2017 23:09:30 +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 1B54821E5A for ; Mon, 17 Jul 2017 23:09:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751669AbdGQXJP (ORCPT ); Mon, 17 Jul 2017 19:09:15 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:33366 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751557AbdGQXJN (ORCPT ); Mon, 17 Jul 2017 19:09:13 -0400 Received: by mail-pg0-f45.google.com with SMTP id k14so2134478pgr.0 for ; Mon, 17 Jul 2017 16:09:13 -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=np30OaSrf7WUtHRWBcPdZRef+vu+0KHLDEK6Fvwu0WU=; b=iBz7mkSOU4e3MeBEINQAnImqcAqyjYJoTSGK0s6YgmHz6X7ij43svNeOD6EVB6QBW2 4NXCFqz4b/T5+4S44oAOl8qnLsHRSwu4Po3ymoZcrWeYKOVlt3nfGfn8vym9Sc+iR34N VloqRXkIwdNzuTaqDESkYjmBtrY93nuU4PAhpAGZ+DwmdvIf6+QwDbF03768/ApyW6Ga nNzkriikiRCJ9NL2EXWjfaUuWFJBBQ2Sc64BBJ1Xm6QAR+4fcvN6LrpHdPHTp66uo+x3 Omfv5/cIkjxzB/61XVP+uJP2cq1T7kRTd4DQmfaRas8idhWu/WOW5EFnC99zSnZnNsN8 Ma6A== 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=np30OaSrf7WUtHRWBcPdZRef+vu+0KHLDEK6Fvwu0WU=; b=pio53xO1MAKNxQhhykeC/O3nZYz+2JbsTgFbUTVGjMTl2ysK+llO9L8gsT7zZmiQ1o YgLaPwHBgbI38XJ8g0p0FiTwT/S+0808jr74oakHWXHr44yVNl8WNrtD4W16GrVtmNpA u2EjWT2Mng3+A9w7GbtJiryo1pqU4A9kJj4vLxmVMR0gqmSmksc+fUCx7R43QgtRK4Aq ow6xVapQZZ7//CQDnv38ClfdvmX1A7R0VuSx8eIhvpDH+f3562Mwkqtk2V7dLnI5GPoZ SJakvR9JeclpMbcUB7NTjfxRWO7cFHiynF8wjxvLeAcmXbbLd13bZRnMnvgb8otBBdM2 Ac3Q== X-Gm-Message-State: AIVw110Sthdjf8RhUM4QEdgL4tesYX5E6PuUm4jYkK3MDNHsQCkdZxbn QCUMc4Hcg1NYiBbb X-Received: by 10.98.206.9 with SMTP id y9mr8733354pfg.236.1500332952308; Mon, 17 Jul 2017 16:09:12 -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.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Jul 2017 16:09:11 -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 1/3] drivers: w1: add hwmon support structures Date: Mon, 17 Jul 2017 16:09:04 -0700 Message-Id: <20170717230906.4084-2-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 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; }; /**