From patchwork Tue Feb 14 20:34:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 9572829 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 6C62C60573 for ; Tue, 14 Feb 2017 20:35:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D79327C2D for ; Tue, 14 Feb 2017 20:35:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 522202840E; Tue, 14 Feb 2017 20:35: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=-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 B6EE727C2D for ; Tue, 14 Feb 2017 20:35:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932089AbdBNUfK (ORCPT ); Tue, 14 Feb 2017 15:35:10 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:44084 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755519AbdBNUfD (ORCPT ); Tue, 14 Feb 2017 15:35:03 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1EKXcZf113168 for ; Tue, 14 Feb 2017 15:34:47 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 28kx6w4xu0-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 14 Feb 2017 15:34:46 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 14 Feb 2017 13:34:46 -0700 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 14 Feb 2017 13:34:41 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 4171D19D8026; Tue, 14 Feb 2017 13:33:54 -0700 (MST) Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1EKYfws13566430; Tue, 14 Feb 2017 13:34:41 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 30602136040; Tue, 14 Feb 2017 13:34:41 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.41.179.225]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP id 5323D136049; Tue, 14 Feb 2017 13:34:40 -0700 (MST) From: Eddie James To: linux@roeck-us.net Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, jdelvare@suse.com, corbet@lwn.net, mark.rutland@arm.com, robh+dt@kernel.org, wsa@the-dreams.de, andrew@aj.id.au, benh@kernel.crashing.org, joel@jms.id.au, "Edward A. James" Subject: [PATCH linux v8 5/6] hwmon: occ: Add hwmon implementation for the P8 OCC Date: Tue, 14 Feb 2017 14:34:22 -0600 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487104463-4253-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1487104463-4253-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17021420-8235-0000-0000-00000AF65758 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006616; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000203; SDB=6.00821959; UDB=6.00402062; IPR=6.00599413; BA=6.00005137; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014282; XFM=3.00000011; UTC=2017-02-14 20:34:45 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17021420-8236-0000-0000-0000399863F9 Message-Id: <1487104463-4253-6-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-14_13:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=13 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702140196 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" Add code to tie the hwmon sysfs code and the POWER8 OCC code together, as well as probe the entire driver from the I2C bus. I2C is the communication method between the BMC and the P8 OCC. Signed-off-by: Edward A. James Signed-off-by: Andrew Jeffery Acked-by: Rob Herring --- Documentation/devicetree/bindings/hwmon/occ.txt | 13 ++++ drivers/hwmon/occ/Kconfig | 15 ++++ drivers/hwmon/occ/Makefile | 4 +- drivers/hwmon/occ/occ_p8_i2c.c | 99 +++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/hwmon/occ.txt create mode 100644 drivers/hwmon/occ/occ_p8_i2c.c diff --git a/Documentation/devicetree/bindings/hwmon/occ.txt b/Documentation/devicetree/bindings/hwmon/occ.txt new file mode 100644 index 0000000..b0d2b36 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/occ.txt @@ -0,0 +1,13 @@ +HWMON I2C driver for IBM POWER CPU OCC (On Chip Controller) + +Required properties: + - compatible: must be "ibm,p8-occ-i2c" + - reg: physical address + +Example: +i2c3: i2c-bus@100 { + occ@50 { + compatible = "ibm,p8-occ-i2c"; + reg = <0x50>; + }; +}; diff --git a/drivers/hwmon/occ/Kconfig b/drivers/hwmon/occ/Kconfig index 61be588..d521720 100644 --- a/drivers/hwmon/occ/Kconfig +++ b/drivers/hwmon/occ/Kconfig @@ -11,3 +11,18 @@ menuconfig SENSORS_IBM_OCC Generally this is used by management controllers such as a BMC on an OpenPower system. + +if SENSORS_IBM_OCC + +config SENSORS_IBM_OCC_P8_I2C + tristate "POWER8 OCC hwmon support" + depends on I2C + help + Provide a hwmon sysfs interface for the POWER8 On-Chip Controller, + exposing temperature, frequency and power measurements. This + interface runs on the service processor, not the POWER CPU. + + This driver can also be built as a module. If so, the module will be + called hwmon_occ_p8. + +endif diff --git a/drivers/hwmon/occ/Makefile b/drivers/hwmon/occ/Makefile index f59cca4..864b044 100644 --- a/drivers/hwmon/occ/Makefile +++ b/drivers/hwmon/occ/Makefile @@ -1 +1,3 @@ -obj-$(CONFIG_SENSORS_IBM_OCC) += occ.o occ_sysfs.o occ_scom_i2c.o occ_p8.o +obj-$(CONFIG_SENSORS_IBM_OCC_P8_I2C) += hwmon_occ_p8.o + +hwmon_occ_p8-objs := occ.o occ_sysfs.o occ_scom_i2c.o occ_p8.o occ_p8_i2c.o diff --git a/drivers/hwmon/occ/occ_p8_i2c.c b/drivers/hwmon/occ/occ_p8_i2c.c new file mode 100644 index 0000000..2b4f6dd --- /dev/null +++ b/drivers/hwmon/occ/occ_p8_i2c.c @@ -0,0 +1,99 @@ +/* + * occ_p8_i2c.c - hwmon OCC driver + * + * This file contains the i2c layer for accessing the P8 OCC over i2c bus. + * + * Copyright 2017 IBM Corp. + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "occ_p8.h" +#include "occ_scom_i2c.h" +#include "occ_sysfs.h" +#include "scom.h" + +#define OCC_P8_I2C_NAME "p8-occ-i2c" + +int p8_i2c_getscom(void *bus, u32 address, u64 *data) +{ + /* P8 i2c slave requires scom address to be shifted by 1 */ + address = address << 1; + + return occ_i2c_getscom(bus, address, data); +} + +int p8_i2c_putscom(void *bus, u32 address, u32 data0, u32 data1) +{ + /* P8 i2c slave requires scom address to be shifted by 1 */ + address = address << 1; + + return occ_i2c_putscom(bus, address, data0, data1); +} + +static const struct occ_bus_ops p8_bus_ops = { + .getscom = p8_i2c_getscom, + .putscom = p8_i2c_putscom, +}; + +static int p8_occ_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct occ *occ; + struct occ_sysfs *hwmon; + const u32 *sensor_hwmon_configs = p8_get_sensor_hwmon_configs(); + + occ = p8_occ_init(&client->dev, client, &p8_bus_ops); + if (IS_ERR(occ)) + return PTR_ERR(occ); + + hwmon = occ_sysfs_start(&client->dev, occ, sensor_hwmon_configs, + OCC_P8_I2C_NAME); + if (IS_ERR(hwmon)) + return PTR_ERR(hwmon); + + i2c_set_clientdata(client, occ); + + return 0; +} + +/* used by old-style board info. */ +static const struct i2c_device_id occ_ids[] = { + { OCC_P8_I2C_NAME, 0 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, occ_ids); + +/* used by device table */ +static const struct of_device_id occ_of_match[] = { + { .compatible = "ibm,p8-occ-i2c" }, + {} +}; +MODULE_DEVICE_TABLE(of, occ_of_match); + +static struct i2c_driver p8_occ_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = OCC_P8_I2C_NAME, + .of_match_table = occ_of_match, + }, + .probe = p8_occ_probe, + .id_table = occ_ids, +}; + +module_i2c_driver(p8_occ_driver); + +MODULE_AUTHOR("Eddie James "); +MODULE_DESCRIPTION("BMC P8 OCC hwmon driver"); +MODULE_LICENSE("GPL");