From patchwork Tue Aug 8 03:25:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 9886459 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 6371460363 for ; Tue, 8 Aug 2017 03:26:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 577C528790 for ; Tue, 8 Aug 2017 03:26:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C6CA2879E; Tue, 8 Aug 2017 03:26:04 +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 E002C28790 for ; Tue, 8 Aug 2017 03:26:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751961AbdHHD0D (ORCPT ); Mon, 7 Aug 2017 23:26:03 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39056 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751834AbdHHD0D (ORCPT ); Mon, 7 Aug 2017 23:26:03 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v783NmDB010217 for ; Mon, 7 Aug 2017 23:26:02 -0400 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0b-001b2d01.pphosted.com with ESMTP id 2c734gckyu-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 07 Aug 2017 23:26:02 -0400 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 7 Aug 2017 23:26:02 -0400 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 7 Aug 2017 23:25:58 -0400 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v783PwjZ23134388; Tue, 8 Aug 2017 03:25:58 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1B9E7112040; Mon, 7 Aug 2017 23:25:50 -0400 (EDT) Received: from oc3016140333.ibm.com (unknown [9.85.166.253]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP id 4E619112034; Mon, 7 Aug 2017 23:25:49 -0400 (EDT) From: Eddie James To: linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, joel@jms.id.au, andrew@aj.id.au, jk@ozlabs.org, cbostic@linux.vnet.ibm.com, eajames@linux.vnet.ibm.com, "Edward A. James" Subject: [RFC 3/3] drivers/hwmon/pmbus: Add sensor status to pmbus attributes Date: Mon, 7 Aug 2017 22:25:48 -0500 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1502162748-16372-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1502162748-16372-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17080803-2213-0000-0000-000002062A9A X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007504; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000217; SDB=6.00899142; UDB=6.00450021; IPR=6.00679347; BA=6.00005516; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016585; XFM=3.00000015; UTC=2017-08-08 03:26:00 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17080803-2214-0000-0000-0000572547F6 Message-Id: <1502162748-16372-4-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-08-08_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1708080055 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 From: "Edward A. James" Extend the pmbus core to provide status registers for attributes. Signed-off-by: Edward A. James --- drivers/hwmon/pmbus/pmbus_core.c | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 3b53fa7..00ce145 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -86,6 +86,14 @@ struct pmbus_label { #define to_pmbus_label(_attr) \ container_of(_attr, struct pmbus_label, attribute) +struct pmbus_status { + char name[PMBUS_NAME_SIZE]; /* sysfs status name */ + struct device_attribute attribute; + int reg; +}; +#define to_pmbus_status(_attr) \ + container_of(_attr, struct pmbus_status, attribute) + struct pmbus_data { struct device *dev; struct device *hwmon_dev; @@ -851,6 +859,16 @@ static ssize_t pmbus_show_label(struct device *dev, return snprintf(buf, PAGE_SIZE, "%s\n", label->label); } +static ssize_t pmbus_show_status(struct device *dev, + struct device_attribute *da, char *buf) +{ + struct pmbus_status *status = to_pmbus_status(da); + struct pmbus_data *data = pmbus_update_device(dev); + + return snprintf(buf, PAGE_SIZE, "%02x\n", + pmbus_get_status(data, status->reg) & 0xFF); +} + static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr) { if (data->num_attributes >= data->max_attributes - 1) { @@ -983,6 +1001,25 @@ static int pmbus_add_label(struct pmbus_data *data, return pmbus_add_attribute(data, &a->attr); } +static int pmbus_add_status(struct pmbus_data *data, const char *name, int seq, + int reg) +{ + struct pmbus_status *status; + struct device_attribute *a; + + status = devm_kzalloc(data->dev, sizeof(*status), GFP_KERNEL); + if (!status) + return -ENOMEM; + + a = &status->attribute; + + snprintf(status->name, sizeof(status->name), "%s%d_status", name, seq); + status->reg = reg; + + pmbus_dev_attr_init(a, status->name, S_IRUGO, pmbus_show_status, NULL); + return pmbus_add_attribute(data, &a->attr); +} + /* * Search for attributes. Allocate sensors, booleans, and labels as needed. */ @@ -1105,6 +1142,16 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client, return ret; } } + if (attr->sbase > 0 && attr->sbase < PB_STATUS_VMON_BASE) { + /* Add "status" attribute for physical status registers to dump + * the contents. This is pretty useful for hardware diagnostic + * purposes, as an alarm or fault bit doesn't necessarily + * provide all the info available. + */ + ret = pmbus_add_status(data, name, index, attr->sbase + page); + if (ret) + return ret; + } return 0; } @@ -1693,6 +1740,10 @@ static int pmbus_add_fan_attributes(struct i2c_client *client, PB_FAN_FAN1_FAULT >> (f & 1)); if (ret) return ret; + ret = pmbus_add_status(data, "fan", index, + base); + if (ret) + return ret; } index++; }