Received: by 10.223.164.202 with SMTP id h10csp4446759wrb; Mon, 20 Nov 2017 15:57:27 -0800 (PST) X-Google-Smtp-Source: AGs4zMZJozdQn2t5XmyMIvP+ko77WIOFAzLelGaJxuD9VnVYOXgMvBV3CDw6+MS9J+cLTT93DjUD X-Received: by 10.98.181.9 with SMTP id y9mr6754288pfe.206.1511222247585; Mon, 20 Nov 2017 15:57:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511222247; cv=none; d=google.com; s=arc-20160816; b=Fu4BJ3aRD4u/OOvsM8Ec0WkvzJdDGSlqlU5vtIZjLAnU41a3lvK5AGGyCs+rEml1Ju WVE8ipV3xEaAAjlZD8yPyy9QsmNNLWhjSsM6baCsgfdt6njQ2rFx1vDwzeGLMA1m0QY9 HidzVMWVPOz/aYQ6Gh/t3/U4Bkd2OQsp9fXgUxkOcoHFlfWUr0AD3jpv6bygUHGL8GZC nkhcgJM0m4SXPIoA8m+gFl9XtEhtHUw107QbANMYRs8YaddHGp8xw2kHSxJlkdirg7iS ZNPeLGNorE9rI0ZJu+ZDcBLh1q1gWGWln6SoarWLODvegv8H78sQPFm3STIE+qp3NgU1 y7Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=q0KHMw7LlZZ/G4Z5jfVPzcE7mplhTeX/yGYQhqp2jc4=; b=GrPW1KgfIquSjR+go4T8kPPDhcT/HuHaoLnVIq+NN/hkH66ll1vlskWBWhYVvTnkjq LY1wrmEsZXYRmzfzi5iz+vuiGvA74W09kj3Cc9zzmXzRSRWQ/ygnnUE5KrDUW7wXmubg yC5DITAtuR1ZqNdkZYiNyfgLjV58+KTNCTwCFMeDI1Cymot5VsfBG+3a+Z9v6d232EAG DPeoSusgQN01ZakIjl6RGDHoj8oljkoyKEaGnCRXWHDmlONnoS+TuJW+aCze+BCMwe84 nR9GXtKFkFogp5p1bGPSSYauPg5FBBW+6u/58Tn3Cz926X9Mq61D8Ar7Ig489hMVlIgI nS/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s1si9125605pgq.14.2017.11.20.15.57.17; Mon, 20 Nov 2017 15:57:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752619AbdKTXzK (ORCPT + 70 others); Mon, 20 Nov 2017 18:55:10 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:50306 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752190AbdKTXyH (ORCPT ); Mon, 20 Nov 2017 18:54:07 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAKNnM8V111159 for ; Mon, 20 Nov 2017 18:54:07 -0500 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ec8qyrud5-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 20 Nov 2017 18:54:06 -0500 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 20 Nov 2017 16:54:06 -0700 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 20 Nov 2017 16:54:01 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAKNs1ew65470546; Mon, 20 Nov 2017 16:54:01 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4120EBE03B; Mon, 20 Nov 2017 16:54:01 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.41.174.252]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 9E949BE038; Mon, 20 Nov 2017 16:54:00 -0700 (MST) From: Eddie James To: linux-kernel@vger.kernel.org Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, linux@roeck-us.net, jdelvare@suse.com, corbet@lwn.net, mark.rutland@arm.com, robh+dt@kernel.org, joel@jms.id.au, eajames@linux.vnet.ibm.com, "Edward A. James" Subject: [PATCH v3 10/12] hwmon (occ): Add non-hwmon attributes Date: Mon, 20 Nov 2017 17:53:39 -0600 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1511222021-562-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1511222021-562-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112023-0008-0000-0000-000008E71FFD X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008101; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000240; SDB=6.00948826; UDB=6.00479139; IPR=6.00729108; BA=6.00005702; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018113; XFM=3.00000015; UTC=2017-11-20 23:54:05 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112023-0009-0000-0000-000044D83BD7 Message-Id: <1511222021-562-11-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-20_12:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711200318 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Edward A. James" Create device attributes for additional OCC properties that do not belong as hwmon sensors. These provide additional information as to the state of the processor and system. Signed-off-by: Edward A. James --- drivers/hwmon/occ/common.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/hwmon/occ/common.h | 1 + drivers/hwmon/occ/p8_i2c.c | 10 +++++ drivers/hwmon/occ/p9_sbe.c | 2 + 4 files changed, 106 insertions(+) diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c index 337f286b..53e3592 100644 --- a/drivers/hwmon/occ/common.c +++ b/drivers/hwmon/occ/common.c @@ -24,6 +24,14 @@ #define OCC_FRU_TYPE_VRM 0x3 +/* OCC status bits */ +#define OCC_STAT_MASTER 0x80 +#define OCC_STAT_ACTIVE 0x01 +#define OCC_EXT_STAT_DVFS_OT 0x80 +#define OCC_EXT_STAT_DVFS_POWER 0x40 +#define OCC_EXT_STAT_MEM_THROTTLE 0x20 +#define OCC_EXT_STAT_QUICK_DROP 0x10 + /* OCC sensor type and version definitions */ struct temp_sensor_1 { @@ -1108,6 +1116,81 @@ static int occ_setup_sensor_attrs(struct occ *occ) return 0; } +static ssize_t occ_show_status(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int rc; + int val = 0; + struct occ *occ = dev_get_drvdata(dev); + struct occ_poll_response_header *header; + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); + + rc = occ_update_response(occ); + if (rc) + return rc; + + header = (struct occ_poll_response_header *)occ->resp.data; + + switch (sattr->index) { + case 0: + val = (header->status & OCC_STAT_MASTER) ? 1 : 0; + break; + case 1: + val = (header->status & OCC_STAT_ACTIVE) ? 1 : 0; + break; + case 2: + val = (header->ext_status & OCC_EXT_STAT_DVFS_OT) ? 1 : 0; + break; + case 3: + val = (header->ext_status & OCC_EXT_STAT_DVFS_POWER) ? 1 : 0; + break; + case 4: + val = (header->ext_status & OCC_EXT_STAT_MEM_THROTTLE) ? 1 : 0; + break; + case 5: + val = (header->ext_status & OCC_EXT_STAT_QUICK_DROP) ? 1 : 0; + break; + case 6: + val = header->occ_state; + break; + case 7: + if (header->status & OCC_STAT_MASTER) + val = hweight8(header->occs_present); + else + val = 1; + break; + default: + return -EINVAL; + } + + return snprintf(buf, PAGE_SIZE - 1, "%d\n", val); +} + +static SENSOR_DEVICE_ATTR(occ_master, 0444, occ_show_status, NULL, 0); +static SENSOR_DEVICE_ATTR(occ_active, 0444, occ_show_status, NULL, 1); +static SENSOR_DEVICE_ATTR(occ_dvfs_ot, 0444, occ_show_status, NULL, 2); +static SENSOR_DEVICE_ATTR(occ_dvfs_power, 0444, occ_show_status, NULL, 3); +static SENSOR_DEVICE_ATTR(occ_mem_throttle, 0444, occ_show_status, NULL, 4); +static SENSOR_DEVICE_ATTR(occ_quick_drop, 0444, occ_show_status, NULL, 5); +static SENSOR_DEVICE_ATTR(occ_status, 0444, occ_show_status, NULL, 6); +static SENSOR_DEVICE_ATTR(occs_present, 0444, occ_show_status, NULL, 7); + +static struct attribute *occ_attributes[] = { + &sensor_dev_attr_occ_master.dev_attr.attr, + &sensor_dev_attr_occ_active.dev_attr.attr, + &sensor_dev_attr_occ_dvfs_ot.dev_attr.attr, + &sensor_dev_attr_occ_dvfs_power.dev_attr.attr, + &sensor_dev_attr_occ_mem_throttle.dev_attr.attr, + &sensor_dev_attr_occ_quick_drop.dev_attr.attr, + &sensor_dev_attr_occ_status.dev_attr.attr, + &sensor_dev_attr_occs_present.dev_attr.attr, + NULL +}; + +static const struct attribute_group occ_attr_group = { + .attrs = occ_attributes, +}; + /* only need to do this once at startup, as OCC won't change sensors on us */ static void occ_parse_poll_response(struct occ *occ) { @@ -1188,5 +1271,15 @@ int occ_setup(struct occ *occ, const char *name) return rc; } + rc = sysfs_create_group(&occ->bus_dev->kobj, &occ_attr_group); + if (rc) + dev_warn(occ->bus_dev, "failed to create status attrs: %d\n", + rc); + return 0; } + +void occ_shutdown(struct occ *occ) +{ + sysfs_remove_group(&occ->bus_dev->kobj, &occ_attr_group); +} diff --git a/drivers/hwmon/occ/common.h b/drivers/hwmon/occ/common.h index 049c3b4..dc9e06d 100644 --- a/drivers/hwmon/occ/common.h +++ b/drivers/hwmon/occ/common.h @@ -110,5 +110,6 @@ struct occ { }; int occ_setup(struct occ *occ, const char *name); +void occ_shutdown(struct occ *occ); #endif /* OCC_COMMON_H */ diff --git a/drivers/hwmon/occ/p8_i2c.c b/drivers/hwmon/occ/p8_i2c.c index 8032c0b..d719632 100644 --- a/drivers/hwmon/occ/p8_i2c.c +++ b/drivers/hwmon/occ/p8_i2c.c @@ -230,6 +230,15 @@ static int p8_i2c_occ_probe(struct i2c_client *client, return occ_setup(occ, "p8_occ"); } +static int p8_i2c_occ_remove(struct i2c_client *client) +{ + struct occ *occ = dev_get_drvdata(&client->dev); + + occ_shutdown(occ); + + return 0; +} + static const struct of_device_id p8_i2c_occ_of_match[] = { { .compatible = "ibm,p8-occ-hwmon" }, {} @@ -243,6 +252,7 @@ static int p8_i2c_occ_probe(struct i2c_client *client, .of_match_table = p8_i2c_occ_of_match, }, .probe = p8_i2c_occ_probe, + .remove = p8_i2c_occ_remove, }; module_i2c_driver(p8_i2c_occ_driver); diff --git a/drivers/hwmon/occ/p9_sbe.c b/drivers/hwmon/occ/p9_sbe.c index be3a469..7dbe4d5 100644 --- a/drivers/hwmon/occ/p9_sbe.c +++ b/drivers/hwmon/occ/p9_sbe.c @@ -135,6 +135,8 @@ static int p9_sbe_occ_remove(struct platform_device *pdev) p9_sbe_occ->sbe = NULL; p9_sbe_occ_close_client(p9_sbe_occ); + occ_shutdown(occ); + return 0; } -- 1.8.3.1 From 1584920896541004931@xxx Fri Nov 24 04:39:12 +0000 2017 X-GM-THRID: 1584920896541004931 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread