From patchwork Wed Aug 30 23:34:33 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: 9930975 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 C4D3460380 for ; Wed, 30 Aug 2017 23:35:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B779D287D7 for ; Wed, 30 Aug 2017 23:35:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC3FF287E2; Wed, 30 Aug 2017 23:35:20 +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 5654C287D7 for ; Wed, 30 Aug 2017 23:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751557AbdH3XfP (ORCPT ); Wed, 30 Aug 2017 19:35:15 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:34871 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751285AbdH3Xek (ORCPT ); Wed, 30 Aug 2017 19:34:40 -0400 Received: by mail-pf0-f174.google.com with SMTP id g13so23410870pfm.2 for ; Wed, 30 Aug 2017 16:34:40 -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=3lnlNFvdUHJ3NLeeuAUMAA/7WlarW9Yh4jU/AQLC8fM=; b=fViXof7aODIyjCTL2dKaZqtjZ3V4P9flKl7Pl/TNcA5rx6cnmW4D4vzvTrawMl7mmK qDKsQ6bUHytL4VNmjeYGMD0MEQZrZZZoUgwoMNWcE45nkPLBi6r5VLEBcrCTkD/n38U7 G6S5bj6i1NyJwFfnZEfoKHLgMaVUQKf8Pb5pDGN1KnhTGRK+pdA72/ZiJZRz78PoqQzL NTgIqS58ZCPcJct+g8qnnEnpbHmZlrHdE82gJD3Zs/MusAxmcrcwe6+GK74HQPWf5iJr j97jcugSYj0paGlttw4cmkVj7cMDVrGLce1u96LqeirqazR9oAKqT5CPdCvY/PoCogjJ yPbA== 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=3lnlNFvdUHJ3NLeeuAUMAA/7WlarW9Yh4jU/AQLC8fM=; b=bUfWsJwgWbRcbjvMBK4XSBAlqGmSOA0xwzwGXDPOZmwdov2GMgmIswb0K92Evt5Cqz GR3oIWDiw1NNeLFkei2AJAt+bdCcIftj1W4bGgWI/1bRveq03qkQtatPdARdU7CQoNfq cKJ0gfn043pbPSFFh8neMjlJIJW8ErjNP54UnARMMl6xTKXteqq4gDmkmkRgH6PWvkTc erURJF4t/ZtgCACqnqXCRY/m7o5DO/JDgimwJi3+KuATKsGbMGOKuZSXS9Bz4TLjqmK2 BMxyuGSTIfcODP4cDsvfOJ99aYsIlBsEeLgTY2z34pZSa1C+Zjh0+Ie077j/G5LVHBU6 jEcw== X-Gm-Message-State: AHYfb5hWjYyUtDCoIbocdL0pWVZKqfpt6XdNW1glQTbg25nYkRqFusFU Sj73asHUxIzNDM50 X-Google-Smtp-Source: ADKCNb4qp2UWhszCxRPZ+DLmsF0vaY1EZbVdcsXbnEMJ9FhjCmr2hO+N0b2MvFbm1BZi3d9POVfdJA== X-Received: by 10.84.210.143 with SMTP id a15mr350797pli.20.1504136079729; Wed, 30 Aug 2017 16:34:39 -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.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 16:34:39 -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 1/3] drivers: w1: add hwmon support structures Date: Wed, 30 Aug 2017 16:34:33 -0700 Message-Id: <20170830233435.16500-2-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 patch has changes to w1.h/w1.c 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. v5 - no change. v6 -rebased on top of char-misc-next branch. drivers/w1/w1.c | 18 +++++++++++++++++- include/linux/w1.h | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-) -- 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/w1.c b/drivers/w1/w1.c index 3c76e1ca4b83..0c2a5a8327bd 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -649,9 +650,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/include/linux/w1.h b/include/linux/w1.h index 90cbe7e65059..5b2972946dda 100644 --- a/include/linux/w1.h +++ b/include/linux/w1.h @@ -68,6 +68,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 { @@ -83,6 +84,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); @@ -250,11 +252,13 @@ void w1_remove_master_device(struct w1_bus_master *master); * @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 *sl); void (*remove_slave)(struct w1_slave *sl); const struct attribute_group **groups; + const struct hwmon_chip_info *chip_info; }; /**