From patchwork Tue Apr 16 18:36:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Babayev X-Patchwork-Id: 10903835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D683C922 for ; Tue, 16 Apr 2019 18:51:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C12E5289E5 for ; Tue, 16 Apr 2019 18:51:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4E0828A0B; Tue, 16 Apr 2019 18:51:11 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 061DC289E5 for ; Tue, 16 Apr 2019 18:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728405AbfDPSvK (ORCPT ); Tue, 16 Apr 2019 14:51:10 -0400 Received: from rcdn-iport-4.cisco.com ([173.37.86.75]:18672 "EHLO rcdn-iport-4.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbfDPSvK (ORCPT ); Tue, 16 Apr 2019 14:51:10 -0400 X-Greylist: delayed 425 seconds by postgrey-1.27 at vger.kernel.org; Tue, 16 Apr 2019 14:51:10 EDT X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CDAAAKIrZc/51dJa1mHQEBBQEHBQGBUwYBCwGCEIE5MyiyEIF7EIRthgkjNgcOAQMBAQoBAgECbSiFeFIpgRUTgyKCCatWM4owFIEeAYZzhFYXgX+EYYQeG4VsA5F/gQuTLAmCCFOROidrlAugLoFWAi+BVjMaCBsVgyeQbB8DMI4hglEBAQ X-IronPort-AV: E=Sophos;i="5.60,358,1549929600"; d="scan'208";a="548151376" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by rcdn-iport-4.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 16 Apr 2019 18:44:04 +0000 Received: from tusi.cisco.com (tusi.cisco.com [172.24.98.27]) by rcdn-core-6.cisco.com (8.15.2/8.15.2) with ESMTP id x3GIi30W026006; Tue, 16 Apr 2019 18:44:03 GMT From: Ruslan Babayev To: Guenter Roeck Cc: xe-linux-external@cisco.com, Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] hwmon: (pmbus) add support for output voltage registers Date: Tue, 16 Apr 2019 11:36:16 -0700 Message-Id: <20190416183620.39950-1-ruslan@babayev.com> X-Mailer: git-send-email 2.17.1 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 172.24.98.27, tusi.cisco.com X-Outbound-Node: rcdn-core-6.cisco.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 Registers VOUT_COMMAND, VOUT_MARGIN_HIGH and VOUT_MARGIN_LOW are described in PMBUS Spec Part II Rev 1.2. Exposing them in the PMBUS core allows the drivers to turn them on with a corresponding PMBUS_HAVE_VOUT_... flags. Cc: xe-linux-external@cisco.com Signed-off-by: Ruslan Babayev --- drivers/hwmon/pmbus/pmbus.h | 7 ++ drivers/hwmon/pmbus/pmbus_core.c | 183 +++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index 1d24397d36ec..723648b3da36 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h @@ -223,6 +223,9 @@ enum pmbus_regs { * OPERATION */ #define PB_OPERATION_CONTROL_ON BIT(7) +#define PB_OPERATION_MARGIN_HIGH BIT(5) +#define PB_OPERATION_MARGIN_LOW BIT(4) +#define PB_OPERATION_ACT_ON_FAULT BIT(3) /* * CAPABILITY @@ -291,6 +294,7 @@ enum pmbus_fan_mode { percent = 0, rpm }; /* * STATUS_VOUT, STATUS_INPUT */ +#define PB_VOLTAGE_MAX_WARNING BIT(3) #define PB_VOLTAGE_UV_FAULT BIT(4) #define PB_VOLTAGE_UV_WARNING BIT(5) #define PB_VOLTAGE_OV_WARNING BIT(6) @@ -371,6 +375,9 @@ enum pmbus_sensor_classes { #define PMBUS_HAVE_STATUS_VMON BIT(19) #define PMBUS_HAVE_PWM12 BIT(20) #define PMBUS_HAVE_PWM34 BIT(21) +#define PMBUS_HAVE_VOUT_COMMAND BIT(22) +#define PMBUS_HAVE_VOUT_MARGIN_HIGH BIT(23) +#define PMBUS_HAVE_VOUT_MARGIN_LOW BIT(24) #define PMBUS_PAGE_VIRTUAL BIT(31) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 2e2b5851139c..f35b239961e3 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -89,6 +89,14 @@ struct pmbus_label { #define to_pmbus_label(_attr) \ container_of(_attr, struct pmbus_label, attribute) +struct pmbus_operation { + char name[PMBUS_NAME_SIZE]; /* sysfs label name */ + struct sensor_device_attribute attribute; + u8 page; +}; +#define to_pmbus_operation(_attr) \ + container_of(_attr, struct pmbus_operation, attribute) + struct pmbus_data { struct device *dev; struct device *hwmon_dev; @@ -1004,6 +1012,65 @@ static ssize_t pmbus_show_label(struct device *dev, return snprintf(buf, PAGE_SIZE, "%s\n", label->label); } +static ssize_t pmbus_show_operation(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pmbus_operation *operation = to_pmbus_operation(attr); + struct i2c_client *client = to_i2c_client(dev->parent); + int ret; + + ret = pmbus_read_byte_data(client, operation->page, PMBUS_OPERATION); + if (ret < 0) + return ret; + + if (ret & PB_OPERATION_CONTROL_ON) { + if (ret & PB_OPERATION_MARGIN_HIGH) + return snprintf(buf, PAGE_SIZE, "high\n"); + else if (ret & PB_OPERATION_MARGIN_LOW) + return snprintf(buf, PAGE_SIZE, "low\n"); + else + return snprintf(buf, PAGE_SIZE, "on\n"); + } else { + return snprintf(buf, PAGE_SIZE, "off\n"); + } +} + +static ssize_t pmbus_set_operation(struct device *dev, + struct device_attribute *devattr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct pmbus_operation *operation = to_pmbus_operation(attr); + struct i2c_client *client = to_i2c_client(dev->parent); + int ret; + u8 val; + + /* + * sysfs_streq() doesn't need the \n's, but we add them so the strings + * will be shared with pmbus_show_operation() above. + */ + if (sysfs_streq(buf, "on\n")) + val = PB_OPERATION_CONTROL_ON; + else if (sysfs_streq(buf, "off\n")) + val = 0; + else if (sysfs_streq(buf, "high\n")) + val = PB_OPERATION_CONTROL_ON | PB_OPERATION_ACT_ON_FAULT | + PB_OPERATION_MARGIN_HIGH; + else if (sysfs_streq(buf, "low\n")) + val = PB_OPERATION_CONTROL_ON | PB_OPERATION_ACT_ON_FAULT | + PB_OPERATION_MARGIN_LOW; + else + return -EINVAL; + + ret = pmbus_write_byte_data(client, operation->page, + PMBUS_OPERATION, val); + if (ret < 0) + return ret; + + return count; +} + static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr) { if (data->num_attributes >= data->max_attributes - 1) { @@ -1143,6 +1210,29 @@ static int pmbus_add_label(struct pmbus_data *data, return pmbus_add_attribute(data, &a->attr); } +static int pmbus_add_operation(struct pmbus_data *data, const char *name, + int seq, int page) +{ + struct pmbus_operation *operation; + struct sensor_device_attribute *a; + + operation = devm_kzalloc(data->dev, sizeof(*operation), GFP_KERNEL); + if (!operation) + return -ENOMEM; + + a = &operation->attribute; + + snprintf(operation->name, sizeof(operation->name), "%s%d_operation", + name, seq); + + operation->page = page; + + pmbus_attr_init(a, operation->name, S_IRUGO | S_IWUSR, + pmbus_show_operation, pmbus_set_operation, seq); + + return pmbus_add_attribute(data, &a->dev_attr.attr); +} + /* * Search for attributes. Allocate sensors, booleans, and labels as needed. */ @@ -1901,6 +1991,93 @@ static int pmbus_add_fan_attributes(struct i2c_client *client, return 0; } +static const struct pmbus_limit_attr vout_cmd_limit_attrs[] = { + { + .reg = PMBUS_VOUT_MAX, + .attr = "max", + .alarm = "max_alarm", + .sbit = PB_VOLTAGE_MAX_WARNING, + } +}; + +static const struct pmbus_sensor_attr vout_attributes[] = { + { + .reg = PMBUS_VOUT_COMMAND, + .class = PSC_VOLTAGE_OUT, + .label = "command", + .paged = true, + .func = PMBUS_HAVE_VOUT_COMMAND, + .sfunc = PMBUS_HAVE_STATUS_VOUT, + .sbase = PB_STATUS_VOUT_BASE, + .gbit = PB_STATUS_VOUT_OV, + .limit = vout_cmd_limit_attrs, + .nlimit = ARRAY_SIZE(vout_cmd_limit_attrs), + }, { + .reg = PMBUS_VOUT_MARGIN_HIGH, + .class = PSC_VOLTAGE_OUT, + .label = "margin_high", + .paged = true, + .func = PMBUS_HAVE_VOUT_MARGIN_HIGH, + }, { + .reg = PMBUS_VOUT_MARGIN_LOW, + .class = PSC_VOLTAGE_OUT, + .label = "margin_low", + .paged = true, + .func = PMBUS_HAVE_VOUT_MARGIN_LOW, + } +}; + +static int pmbus_add_vout_attrs(struct i2c_client *client, + struct pmbus_data *data, + const char *name, + const struct pmbus_sensor_attr *attr, + int nattrs) +{ + const struct pmbus_driver_info *info = data->info; + struct pmbus_sensor *base; + int i, ret, index, page, pages; + + index = 1; + for (page = 0; page < info->pages; page++) { + if (!pmbus_check_byte_register(client, page, PMBUS_OPERATION)) + continue; + ret = pmbus_add_operation(data, name, index, page); + if (ret) + return ret; + index++; + } + + for (i = 0; i < nattrs; i++) { + index = 1; + pages = attr->paged ? info->pages : 1; + for (page = 0; page < pages; page++) { + if (!(info->func[page] & attr->func)) + continue; + + if (!pmbus_check_word_register(client, page, attr->reg)) + continue; + + base = pmbus_add_sensor(data, name, attr->label, index, + page, attr->reg, attr->class, + true, false, true); + if (!base) + return -ENOMEM; + + if (attr->sfunc) { + ret = pmbus_add_limit_attrs(client, data, info, + name, index, page, + base, attr); + if (ret < 0) + return ret; + } + + index++; + } + attr++; + } + return 0; +} + static int pmbus_find_attributes(struct i2c_client *client, struct pmbus_data *data) { @@ -1912,6 +2089,12 @@ static int pmbus_find_attributes(struct i2c_client *client, if (ret) return ret; + /* Output Voltage sensors */ + ret = pmbus_add_vout_attrs(client, data, "out", vout_attributes, + ARRAY_SIZE(vout_attributes)); + if (ret) + return ret; + /* Current sensors */ ret = pmbus_add_sensor_attrs(client, data, "curr", current_attributes, ARRAY_SIZE(current_attributes)); From patchwork Tue Apr 16 18:36:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Babayev X-Patchwork-Id: 10903837 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59EFE922 for ; Tue, 16 Apr 2019 18:51:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4724C289E5 for ; Tue, 16 Apr 2019 18:51:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B35728A0B; Tue, 16 Apr 2019 18:51:15 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 DF706289E5 for ; Tue, 16 Apr 2019 18:51:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730225AbfDPSvO (ORCPT ); Tue, 16 Apr 2019 14:51:14 -0400 Received: from rcdn-iport-3.cisco.com ([173.37.86.74]:49211 "EHLO rcdn-iport-3.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbfDPSvN (ORCPT ); Tue, 16 Apr 2019 14:51:13 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BiBAAKIrZc/51dJa1mHQEBBQEHBQGBZYIRgTkzKLQLEIRthgkjOBMBAwEBCgECAQJtKIV4UimBFRODIoIJq1YzijAUgR6GdIRWF4F/hGGKJQORf4ELkywJgghTkTona5QLLYg2l0uBZiGBVjMaCBsVgyeQbB8DMJByAQE X-IronPort-AV: E=Sophos;i="5.60,358,1549929600"; d="scan'208";a="537122893" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by rcdn-iport-3.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 16 Apr 2019 18:44:04 +0000 Received: from tusi.cisco.com (tusi.cisco.com [172.24.98.27]) by rcdn-core-6.cisco.com (8.15.2/8.15.2) with ESMTP id x3GIi30X026006; Tue, 16 Apr 2019 18:44:04 GMT From: Ruslan Babayev To: Guenter Roeck Cc: xe-linux-external@cisco.com, Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] hwmon: (pmbus) mark registers READ_VIN and READ_IIN as paged Date: Tue, 16 Apr 2019 11:36:17 -0700 Message-Id: <20190416183620.39950-2-ruslan@babayev.com> X-Mailer: git-send-email 2.17.1 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 172.24.98.27, tusi.cisco.com X-Outbound-Node: rcdn-core-6.cisco.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 On some devices (like IR35215) READ_VIN and READ_IIN registers are paged. For devices where these registers are not paged the extra check ensures we expose only the registers that are actually present. Cc: xe-linux-external@cisco.com Signed-off-by: Ruslan Babayev --- drivers/hwmon/pmbus/pmbus_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index f35b239961e3..fac966967816 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -1379,6 +1379,9 @@ static int pmbus_add_sensor_attrs(struct i2c_client *client, for (page = 0; page < pages; page++) { if (!(info->func[page] & attrs->func)) continue; + if (!pmbus_check_word_register(client, page, + attrs->reg)) + continue; ret = pmbus_add_sensor_attrs_one(client, data, info, name, index, page, attrs); @@ -1498,6 +1501,7 @@ static const struct pmbus_sensor_attr voltage_attributes[] = { .reg = PMBUS_READ_VIN, .class = PSC_VOLTAGE_IN, .label = "vin", + .paged = true, .func = PMBUS_HAVE_VIN, .sfunc = PMBUS_HAVE_STATUS_INPUT, .sbase = PB_STATUS_INPUT_BASE, @@ -1602,6 +1606,7 @@ static const struct pmbus_sensor_attr current_attributes[] = { .reg = PMBUS_READ_IIN, .class = PSC_CURRENT_IN, .label = "iin", + .paged = true, .func = PMBUS_HAVE_IIN, .sfunc = PMBUS_HAVE_STATUS_INPUT, .sbase = PB_STATUS_INPUT_BASE, From patchwork Tue Apr 16 18:36:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Babayev X-Patchwork-Id: 10903841 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7AFC17E0 for ; Tue, 16 Apr 2019 18:51:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3EE7289E5 for ; Tue, 16 Apr 2019 18:51:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7E5F28A0B; Tue, 16 Apr 2019 18:51:27 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 1F621289E5 for ; Tue, 16 Apr 2019 18:51:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728983AbfDPSvV (ORCPT ); Tue, 16 Apr 2019 14:51:21 -0400 Received: from rcdn-iport-3.cisco.com ([173.37.86.74]:49211 "EHLO rcdn-iport-3.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730223AbfDPSvQ (ORCPT ); Tue, 16 Apr 2019 14:51:16 -0400 X-Greylist: delayed 427 seconds by postgrey-1.27 at vger.kernel.org; Tue, 16 Apr 2019 14:51:14 EDT X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BjBAAKIrZc/51dJa1mHQEBBQEHBQGBZYIRgTkzKLIkgWcQgXiCdYYJIzgTAQMBAQoBAgECbSiFeFIpgRUBEoMiggmrVjOKMBSBHoZ0hFYXgX+EYYEEgwUVChGFbAOKXxKHDoELkllTCYIIU5E6J2uUC4tplEWBZiGBVjMaCBsVgyeCFgwLjj8fAzCOIYJRAQE X-IronPort-AV: E=Sophos;i="5.60,358,1549929600"; d="scan'208";a="537122901" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by rcdn-iport-3.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 16 Apr 2019 18:44:06 +0000 Received: from tusi.cisco.com (tusi.cisco.com [172.24.98.27]) by rcdn-core-6.cisco.com (8.15.2/8.15.2) with ESMTP id x3GIi30Y026006; Tue, 16 Apr 2019 18:44:06 GMT From: Ruslan Babayev To: Jean Delvare , Guenter Roeck Cc: xe-linux-external@cisco.com, Jonathan Corbet , linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] hwmon: (pmbus) add support for IR35215 Date: Tue, 16 Apr 2019 11:36:18 -0700 Message-Id: <20190416183620.39950-3-ruslan@babayev.com> X-Mailer: git-send-email 2.17.1 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 172.24.98.27, tusi.cisco.com X-Outbound-Node: rcdn-core-6.cisco.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 Provide support for Infineon Dual Output Digital Multi-Phase Buck Controllers IR35215 and IR3570B. Cc: xe-linux-external@cisco.com Signed-off-by: Ruslan Babayev --- Documentation/hwmon/ir35215 | 98 +++++++++++++++++++++++++++++++++++ drivers/hwmon/pmbus/Kconfig | 10 ++++ drivers/hwmon/pmbus/Makefile | 1 + drivers/hwmon/pmbus/ir35215.c | 91 ++++++++++++++++++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 Documentation/hwmon/ir35215 create mode 100644 drivers/hwmon/pmbus/ir35215.c diff --git a/Documentation/hwmon/ir35215 b/Documentation/hwmon/ir35215 new file mode 100644 index 000000000000..b77481340006 --- /dev/null +++ b/Documentation/hwmon/ir35215 @@ -0,0 +1,98 @@ +Kernel driver ir35215 +===================== + +Supported chips: + * Infinion IR35215 + Prefix: 'ir35215' + Addresses scanned: - + Datasheet: Datasheet is not publicly available. + * Infinion IR3570B + Prefix: 'ir3570b' + Addresses scanned: - + Datasheet: Datasheet is not publicly available. + +Author: Ruslan Babayev + + +Description +----------- + +IR35215 is a Dual Output Digital Multi-Phase Controller + + +Usage Notes +----------- + +This driver does not probe for PMBus devices. You will have to instantiate +devices explicitly. + +Example: the following commands will load the driver for an IR35215 +at address 0x40 on I2C bus #4: + +# modprobe ir35215 +# echo ir35215 0x40 > /sys/bus/i2c/devices/i2c-4/new_device + + +Sysfs attributes +---------------- + +curr[1-2]_label "iin[1-2]" +curr[1-2]_input Measured input current +curr[1-2]_max Maximum current for +curr[1-2]_max_alarm Current high alarm + +curr[3-4]_label "iout[3-4]" +curr[3-4]_input Measured output current +curr[3-4]_crit Critical maximum current +curr[3-4]_crit_alarm Current critical high alarm +curr[3-4]_highest Highest output current +curr[3-4]_lowest Lowest output current +curr[3-4]_max Maximum current +curr[3-4]_max_alarm Current high alarm + +in[1-2]_label "vin[1-2]" +in[1-2]_input Measured input voltage +in[1-2]_crit Critical maximum input voltage +in[1-2]_crit_alarm Input voltage critical high alarm +in[1-2]_highest Highest input voltage +in[1-2]_lowest Lowest input voltage +in[1-2]_min Minimum input voltage +in[1-2]_min_alarm Input voltage low alarm + +in[3-4]_label "vout[3-4]" +in[3-4]_input Measured output voltage +in[3-4]_lcrit Critical minimum output voltage +in[3-4]_lcrit_alarm Output voltage critical low alarm +in[3-4]_crit Critical maximum output voltage +in[3-4]_crit_alarm Output voltage critical high alarm +in[3-4]_highest Highest output voltage +in[3-4]_lowest Lowest output voltage +in[3-4]_max Maximum output voltage +in[3-4]_max_alarm Output voltage high alarm +in[3-4]_min Minimum output voltage +in[3-4]_min_alarm Output voltage low alarm + +out[1-2]_command Commanded output voltage +out[1-2]_margin_high Output voltage when operation is set to "high" +out[1-2]_margin_low Output voltage when operation is set to "low" +out[1-2]_max Maximum output voltage +out[1-2]_max_alarm Output voltage high alarm +out[1-2]_operation Set the output voltage to "on", "off", "high" or "low" + +power1_label "pin" +power1_input Measured input power +power1_alarm Input power high alarm +power1_max Input power limit + +power[2-3]_label "pout[1-2]" +power[2-3]_input Measured output power +power[2-3]_max Output power limit +power[2-3]_max_alarm Output power high alarm + +temp[1-2]_input Measured temperature +temp[1-2]_crit Critical high temperature +temp[1-2]_crit_alarm Chip temperature critical high alarm +temp[1-2]_highest Highest temperature +temp[1-2]_lowest Lowest temperature +temp[1-2]_max Maximum temperature +temp[1-2]_max_alarm Chip temperature high alarm diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig index 629cb45f8557..a7dd5e606061 100644 --- a/drivers/hwmon/pmbus/Kconfig +++ b/drivers/hwmon/pmbus/Kconfig @@ -45,6 +45,16 @@ config SENSORS_IBM_CFFPS This driver can also be built as a module. If so, the module will be called ibm-cffps. +config SENSORS_IR35215 + tristate "Infineon IR35215" + default n + help + If you say yes here you get hardware monitoring support for the + Infineon IR35215 controller. + + This driver can also be built as a module. If so, the module will + be called ir35215. + config SENSORS_IR35221 tristate "Infineon IR35221" help diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile index ea0e39518c21..48643e3bab42 100644 --- a/drivers/hwmon/pmbus/Makefile +++ b/drivers/hwmon/pmbus/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_PMBUS) += pmbus_core.o obj-$(CONFIG_SENSORS_PMBUS) += pmbus.o obj-$(CONFIG_SENSORS_ADM1275) += adm1275.o obj-$(CONFIG_SENSORS_IBM_CFFPS) += ibm-cffps.o +obj-$(CONFIG_SENSORS_IR35215) += ir35215.o obj-$(CONFIG_SENSORS_IR35221) += ir35221.o obj-$(CONFIG_SENSORS_LM25066) += lm25066.o obj-$(CONFIG_SENSORS_LTC2978) += ltc2978.o diff --git a/drivers/hwmon/pmbus/ir35215.c b/drivers/hwmon/pmbus/ir35215.c new file mode 100644 index 000000000000..e50ee465a42d --- /dev/null +++ b/drivers/hwmon/pmbus/ir35215.c @@ -0,0 +1,91 @@ +/* + * Hardware monitoring driver for Infineon IR35215 + * + * Copyright (c) 2019 Cisco Systems. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include "pmbus.h" + +#define COMMON_FUNCS (PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT \ + | PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT \ + | PMBUS_HAVE_PIN | PMBUS_HAVE_POUT \ + | PMBUS_HAVE_TEMP \ + | PMBUS_HAVE_STATUS_VOUT \ + | PMBUS_HAVE_STATUS_IOUT \ + | PMBUS_HAVE_STATUS_INPUT \ + | PMBUS_HAVE_STATUS_TEMP \ + | PMBUS_HAVE_VOUT_MARGIN_HIGH \ + | PMBUS_HAVE_VOUT_MARGIN_LOW \ + ) + + +#define IR35215_FUNCS (COMMON_FUNCS | PMBUS_HAVE_VOUT_COMMAND) +#define IR3570B_FUNCS (COMMON_FUNCS | PMBUS_HAVE_TEMP2) + +static struct pmbus_driver_info ir35215_info = { + .pages = 2, + .format[PSC_VOLTAGE_IN] = linear, + .format[PSC_VOLTAGE_OUT] = linear, + .format[PSC_CURRENT_IN] = linear, + .format[PSC_CURRENT_OUT] = linear, + .format[PSC_POWER] = linear, + .format[PSC_TEMPERATURE] = linear, + .func[0] = IR35215_FUNCS, + .func[1] = IR35215_FUNCS, +}; + +static struct pmbus_driver_info ir3570b_info = { + .pages = 1, + .format[PSC_VOLTAGE_IN] = linear, + .format[PSC_VOLTAGE_OUT] = linear, + .format[PSC_CURRENT_IN] = linear, + .format[PSC_CURRENT_OUT] = linear, + .format[PSC_POWER] = linear, + .format[PSC_TEMPERATURE] = linear, + .func[0] = IR3570B_FUNCS, + .func[1] = IR3570B_FUNCS, +}; + +static int ir35215_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + return pmbus_do_probe(client, id, (void *)id->driver_data); +} + +static const struct i2c_device_id ir35215_id[] = { + {"ir35215", (kernel_ulong_t)&ir35215_info}, + {"ir3570b", (kernel_ulong_t)&ir3570b_info}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, ir35215_id); + +static struct i2c_driver ir35215_driver = { + .driver = { + .name = "ir35215", + }, + .probe = ir35215_probe, + .remove = pmbus_do_remove, + .id_table = ir35215_id, +}; + +module_i2c_driver(ir35215_driver); + +MODULE_AUTHOR("Ruslan Babayev "); +MODULE_DESCRIPTION("PMBus driver for IR35215"); +MODULE_LICENSE("GPL"); From patchwork Tue Apr 16 18:36:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Babayev X-Patchwork-Id: 10903839 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D1B717E0 for ; Tue, 16 Apr 2019 18:51:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A8BE289E5 for ; Tue, 16 Apr 2019 18:51:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E91828A0B; Tue, 16 Apr 2019 18:51:22 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 B236D289E5 for ; Tue, 16 Apr 2019 18:51:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730273AbfDPSvQ (ORCPT ); Tue, 16 Apr 2019 14:51:16 -0400 Received: from rcdn-iport-7.cisco.com ([173.37.86.78]:17352 "EHLO rcdn-iport-7.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbfDPSvP (ORCPT ); Tue, 16 Apr 2019 14:51:15 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BhBAAKIrZc/51dJa1mHQEBBQEHBQGBZYIRgTkzKLQLEIRthgkjOBMBAwEBCgECAQJtKIZKKYEVE4MiggmsCYowFIEehnSEVheBf4RhhDmFbAOTCpMsCYIIU5E6J2uBHYoBiG2gLoFmIYFWMxoIGxWDJ5BsHwMwkHIBAQ X-IronPort-AV: E=Sophos;i="5.60,358,1549929600"; d="scan'208";a="544297874" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by rcdn-iport-7.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 16 Apr 2019 18:44:07 +0000 Received: from tusi.cisco.com (tusi.cisco.com [172.24.98.27]) by rcdn-core-6.cisco.com (8.15.2/8.15.2) with ESMTP id x3GIi30Z026006; Tue, 16 Apr 2019 18:44:07 GMT From: Ruslan Babayev To: Guenter Roeck Cc: xe-linux-external@cisco.com, Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] hwmon: (pmbus/tps40422) add support for output voltage margining Date: Tue, 16 Apr 2019 11:36:19 -0700 Message-Id: <20190416183620.39950-4-ruslan@babayev.com> X-Mailer: git-send-email 2.17.1 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 172.24.98.27, tusi.cisco.com X-Outbound-Node: rcdn-core-6.cisco.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 TPS40422 has MFR_SPECIFIC registers STEP_VREF_MARGIN_HIGH and STEP_VREF_MARGIN_LOW, which are signed 16-bit in units of 2mV. This value is an offset from the nominal reference voltage of 600mV. For instance, the default value of STEP_VREF_MARGIN_LOW is -30 (decimal), which corresponds to a default margin low voltage of 600 - 30 * 2 = 540mV. Introduce tps40422_{read/write}_word_data() callbacks to map the MFR_SPECIFIC registers to standard PMBUS_VOUT_MARGIN_HIGH and PMBUS_VOUT_MARGIN_LOW. For the latter, pmbus_core stores sensor data in linear16 format as specified in VOUT_MODE. Note, that on TPS40422 the exponent is fixed at (-9). The callbacks will perform the necessary conversions. Cc: xe-linux-external@cisco.com Signed-off-by: Ruslan Babayev --- drivers/hwmon/pmbus/tps40422.c | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/hwmon/pmbus/tps40422.c b/drivers/hwmon/pmbus/tps40422.c index 32803825d47e..129d1b0e6b43 100644 --- a/drivers/hwmon/pmbus/tps40422.c +++ b/drivers/hwmon/pmbus/tps40422.c @@ -21,16 +21,70 @@ #include #include "pmbus.h" +#define TPS40422_STEP_VREF_MARGIN_HIGH 0xd5 +#define TPS40422_STEP_VREF_MARGIN_LOW 0xd6 +#define TPS40422_VREF 600 + +static int tps40422_read_word_data(struct i2c_client *client, int page, int reg) +{ + int ret; + + switch (reg) { + case PMBUS_VOUT_MARGIN_HIGH: + reg = TPS40422_STEP_VREF_MARGIN_HIGH; + break; + case PMBUS_VOUT_MARGIN_LOW: + reg = TPS40422_STEP_VREF_MARGIN_LOW; + break; + default: + return -ENODATA; + } + + ret = pmbus_read_word_data(client, page, reg); + if (ret < 0) + return ret; + + ret = (TPS40422_VREF + ((s16)ret) * 2) << 9; + ret = DIV_ROUND_CLOSEST(ret, 1000); + + return ret; +} + +static int tps40422_write_word_data(struct i2c_client *client, int page, + int reg, u16 word) +{ + u16 val; + + switch (reg) { + case PMBUS_VOUT_MARGIN_HIGH: + reg = TPS40422_STEP_VREF_MARGIN_HIGH; + break; + case PMBUS_VOUT_MARGIN_LOW: + reg = TPS40422_STEP_VREF_MARGIN_LOW; + break; + default: + return -ENODATA; + } + + val = ((((long)word * 1000) >> 9) - TPS40422_VREF + 1) / 2; + return pmbus_write_word_data(client, page, reg, val); +} + + static struct pmbus_driver_info tps40422_info = { .pages = 2, + .read_word_data = tps40422_read_word_data, + .write_word_data = tps40422_write_word_data, .format[PSC_VOLTAGE_IN] = linear, .format[PSC_VOLTAGE_OUT] = linear, .format[PSC_TEMPERATURE] = linear, .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP + | PMBUS_HAVE_VOUT_MARGIN_HIGH | PMBUS_HAVE_VOUT_MARGIN_LOW | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP + | PMBUS_HAVE_VOUT_MARGIN_HIGH | PMBUS_HAVE_VOUT_MARGIN_LOW | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, };