From patchwork Fri Aug 19 04:11:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Weber X-Patchwork-Id: 9289309 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 21B86600CB for ; Fri, 19 Aug 2016 04:20:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C6162905E for ; Fri, 19 Aug 2016 04:20:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 013A8290DF; Fri, 19 Aug 2016 04:20:10 +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 7694F2905E for ; Fri, 19 Aug 2016 04:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754018AbcHSEUK (ORCPT ); Fri, 19 Aug 2016 00:20:10 -0400 Received: from ch3vs01.rockwellcollins.com ([205.175.226.27]:39753 "EHLO ch3vs01.rockwellcollins.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753786AbcHSEUJ (ORCPT ); Fri, 19 Aug 2016 00:20:09 -0400 X-Greylist: delayed 492 seconds by postgrey-1.27 at vger.kernel.org; Fri, 19 Aug 2016 00:20:09 EDT Received: from ofwch3n02.rockwellcollins.com (HELO crulimr01.rockwellcollins.com) ([205.175.226.14]) by ch3vs01.rockwellcollins.com with ESMTP; 18 Aug 2016 23:11:09 -0500 X-Received: from largo.rockwellcollins.com (unknown [192.168.140.76]) by crulimr01.rockwellcollins.com (Postfix) with ESMTP id 5B8DA600E3; Thu, 18 Aug 2016 23:11:09 -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] hwmon: Enabled device tree for generic pmbus devices Date: Thu, 18 Aug 2016 23:11:07 -0500 Message-Id: <1471579867-16553-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 This patch adds device tree based enumeration support for generic pmbus sensors ADP4000, BMR453, BMR454, MDT040, NCP4200, NCP4208, PDT003, PDT006, PDT012, TPS40400, TPS544B20, TPS544B25, TPS544C20, TPS544C25, and UDT020. Signed-off-by: Matthew Weber Signed-off-by: Ronak Desai --- drivers/hwmon/pmbus/pmbus.c | 82 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 19 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus.c b/drivers/hwmon/pmbus/pmbus.c index 0a74991..d09c0bb 100644 --- a/drivers/hwmon/pmbus/pmbus.c +++ b/drivers/hwmon/pmbus/pmbus.c @@ -26,6 +26,34 @@ #include #include #include "pmbus.h" +#ifdef CONFIG_OF +#include +#endif + +enum chips { pmbus, generic_sensor }; + +#ifdef CONFIG_OF +static const struct of_device_id generic_pmbus_dt_match[] = { + { .compatible = "on,adp4000", .data = (void *)generic_sensor }, + { .compatible = "ericsson,bmr453", .data = (void *)generic_sensor }, + { .compatible = "ericsson,bmr454", .data = (void *)generic_sensor }, + { .compatible = "lineage,mdt040", .data = (void *)generic_sensor }, + { .compatible = "on,ncp4200", .data = (void *)generic_sensor }, + { .compatible = "on,ncp4208", .data = (void *)generic_sensor }, + { .compatible = "lineage,pdt003", .data = (void *)generic_sensor }, + { .compatible = "lineage,pdt006", .data = (void *)generic_sensor }, + { .compatible = "lineage,pdt012", .data = (void *)generic_sensor }, + { .compatible = "general,pmbus", .data = (void *)pmbus }, + { .compatible = "ti,tps40400", .data = (void *)generic_sensor }, + { .compatible = "ti,tps544b20", .data = (void *)generic_sensor }, + { .compatible = "ti,tps544b25", .data = (void *)generic_sensor }, + { .compatible = "ti,tps544c20", .data = (void *)generic_sensor }, + { .compatible = "ti,tps544c25", .data = (void *)generic_sensor }, + { .compatible = "lineage,udt020", .data = (void *)generic_sensor }, + { } +}; +#endif + /* * Find sensor groups and status registers on each page. @@ -163,6 +191,19 @@ abort: return ret; } +static inline int generic_pmbus_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(generic_pmbus_dt_match, i2c->dev.of_node); + return (int)match->data; + } +#endif + return (int)id->driver_data; +} + static int pmbus_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -173,7 +214,7 @@ static int pmbus_probe(struct i2c_client *client, if (!info) return -ENOMEM; - info->pages = id->driver_data; + info->pages = generic_pmbus_get_driver_data(client, id); info->identify = pmbus_identify; return pmbus_do_probe(client, id, info); @@ -183,22 +224,22 @@ static int pmbus_probe(struct i2c_client *client, * Use driver_data to set the number of pages supported by the chip. */ static const struct i2c_device_id pmbus_id[] = { - {"adp4000", 1}, - {"bmr453", 1}, - {"bmr454", 1}, - {"mdt040", 1}, - {"ncp4200", 1}, - {"ncp4208", 1}, - {"pdt003", 1}, - {"pdt006", 1}, - {"pdt012", 1}, - {"pmbus", 0}, - {"tps40400", 1}, - {"tps544b20", 1}, - {"tps544b25", 1}, - {"tps544c20", 1}, - {"tps544c25", 1}, - {"udt020", 1}, + {"adp4000", generic_sensor}, + {"bmr453", generic_sensor}, + {"bmr454", generic_sensor}, + {"mdt040", generic_sensor}, + {"ncp4200", generic_sensor}, + {"ncp4208", generic_sensor}, + {"pdt003", generic_sensor}, + {"pdt006", generic_sensor}, + {"pdt012", generic_sensor}, + {"pmbus", pmbus}, + {"tps40400", generic_sensor}, + {"tps544b20", generic_sensor}, + {"tps544b25", generic_sensor}, + {"tps544c20", generic_sensor}, + {"tps544c25", generic_sensor}, + {"udt020", generic_sensor}, {} }; @@ -207,8 +248,11 @@ MODULE_DEVICE_TABLE(i2c, pmbus_id); /* This is the driver that will be inserted */ static struct i2c_driver pmbus_driver = { .driver = { - .name = "pmbus", - }, + .name = "pmbus", +#ifdef CONFIG_OF + .of_match_table = of_match_ptr(generic_pmbus_dt_match), +#endif + }, .probe = pmbus_probe, .remove = pmbus_do_remove, .id_table = pmbus_id,