From patchwork Fri Aug 19 04:00:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Weber X-Patchwork-Id: 9289305 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 12DF2600CB for ; Fri, 19 Aug 2016 04:09:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1F9A28F41 for ; Fri, 19 Aug 2016 04:09:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4CA028EEF; Fri, 19 Aug 2016 04:09:06 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 8125C28EEF for ; Fri, 19 Aug 2016 04:09:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753725AbcHSEJG (ORCPT ); Fri, 19 Aug 2016 00:09:06 -0400 Received: from secvs02.rockwellcollins.com ([205.175.225.241]:39456 "EHLO secvs02.rockwellcollins.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750838AbcHSEJG (ORCPT ); Fri, 19 Aug 2016 00:09:06 -0400 X-Greylist: delayed 455 seconds by postgrey-1.27 at vger.kernel.org; Fri, 19 Aug 2016 00:09:05 EDT Received: from unknown (HELO crulimr02.rockwellcollins.com) ([131.198.26.125]) by secvs02.rockwellcollins.com with ESMTP; 18 Aug 2016 23:00:34 -0500 X-Received: from largo.rockwellcollins.com (unknown [192.168.140.76]) by crulimr02.rockwellcollins.com (Postfix) with ESMTP id 497D060063; Thu, 18 Aug 2016 23:00:34 -0500 (CDT) From: Matt Weber To: linux-hwmon@vger.kernel.org Cc: linux@roeck-us.net, jdelvare@suse.com, Matt Weber , Ronak Desai Subject: [PATCH 1/2] hwmon: (ucd9000) basic device tree support Date: Thu, 18 Aug 2016 23:00:23 -0500 Message-Id: <1471579224-16075-1-git-send-email-matthew.weber@rockwellcollins.com> X-Mailer: git-send-email 1.9.1 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 Enables basic enumeration of ucd9000 devices via device tree. Signed-off-by: Ronak Desai Signed-off-by: Matthew Weber --- drivers/hwmon/pmbus/ucd9000.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c index fbb1479..207c30e 100644 --- a/drivers/hwmon/pmbus/ucd9000.c +++ b/drivers/hwmon/pmbus/ucd9000.c @@ -27,6 +27,9 @@ #include #include #include "pmbus.h" +#ifdef CONFIG_OF +#include +#endif enum chips { ucd9000, ucd90120, ucd90124, ucd9090, ucd90910 }; @@ -108,6 +111,18 @@ static int ucd9000_read_byte_data(struct i2c_client *client, int page, int reg) return ret; } +#ifdef CONFIG_OF +static struct of_device_id ucd9000_dt_match[] = { + { .compatible = "ti,ucd9000", .data = (void *)ucd9000 }, + { .compatible = "ti,ucd90120", .data = (void *)ucd90120 }, + { .compatible = "ti,ucd90124", .data = (void *)ucd90124 }, + { .compatible = "ti,ucd9090", .data = (void *)ucd9090 }, + { .compatible = "ti,ucd90910", .data = (void *)ucd90910 }, + { } +}; +#endif + + static const struct i2c_device_id ucd9000_id[] = { {"ucd9000", ucd9000}, {"ucd90120", ucd90120}, @@ -118,6 +133,20 @@ static const struct i2c_device_id ucd9000_id[] = { }; MODULE_DEVICE_TABLE(i2c, ucd9000_id); +static inline int ucd9000_get_driver_data(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ +#ifdef CONFIG_OF + if (i2c->dev.of_node) { + const struct of_device_id *match; + match = of_match_node(ucd9000_dt_match, i2c->dev.of_node); + return (int)match->data; + } +#endif + return (int)id->driver_data; +} + + static int ucd9000_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -150,10 +179,10 @@ static int ucd9000_probe(struct i2c_client *client, return -ENODEV; } - if (id->driver_data != ucd9000 && id->driver_data != mid->driver_data) + if ((ucd9000_get_driver_data(client,id) != ucd9000) && + (ucd9000_get_driver_data(client, id) != mid->driver_data)) dev_notice(&client->dev, - "Device mismatch: Configured %s, detected %s\n", - id->name, mid->name); + "Device mismatch: Detected %s device\n", mid->name); data = devm_kzalloc(&client->dev, sizeof(struct ucd9000_data), GFP_KERNEL); @@ -233,6 +262,9 @@ static int ucd9000_probe(struct i2c_client *client, static struct i2c_driver ucd9000_driver = { .driver = { .name = "ucd9000", +#ifdef CONFIG_OF + .of_match_table = of_match_ptr(ucd9000_dt_match), +#endif }, .probe = ucd9000_probe, .remove = pmbus_do_remove,