From patchwork Mon Jan 30 23:42:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: eajames.ibm@gmail.com X-Patchwork-Id: 9546187 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 E954360417 for ; Mon, 30 Jan 2017 23:44:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E146F283ED for ; Mon, 30 Jan 2017 23:44:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5FCA28406; Mon, 30 Jan 2017 23:44:03 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable 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 64285283ED for ; Mon, 30 Jan 2017 23:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753452AbdA3Xnv (ORCPT ); Mon, 30 Jan 2017 18:43:51 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:33908 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751153AbdA3Xnp (ORCPT ); Mon, 30 Jan 2017 18:43:45 -0500 Received: by mail-it0-f66.google.com with SMTP id o185so17230907itb.1; Mon, 30 Jan 2017 15:42:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u+ZK0d8L6gEkhoFwhiYz87j5YS485eoj8n/fLMaSiGs=; b=jP7UnKbckUpI1QOL1mdNci15GABYy4hJNMtjO1DGTRNjnH2mkTuWCDNr8YBfXqT4CX EVVDpudeKIukxFh2Tif2Oq9nW4vKCG4JzFS0Uwt6UPRQq9skZ5hnZf4tMxh9ng4QKLwE mw8cE/tp/O86YAu0KDYfEQiL4tmY3Vc1f8leBbW7BgloNhh46AOEt+Tpvv+8M/udZ2In OHi9BApogItEVp25e3qE5jIeGnWr+Xfja9znL+GSHeST8G8hzWiJzkOfOF+9AcMa0tla JvUR8Q9pgSt0D78LcaIlgAUhDp6vt8kM3hA1RC4lPZjE6jYKLX7I9IaCrsq3VJ52qfhn gQ5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u+ZK0d8L6gEkhoFwhiYz87j5YS485eoj8n/fLMaSiGs=; b=ZLlYlxK6Rfo+Q8qK6DMoz+qbRkdSCgJ4FLXCV0CFuI+WhdZIxuP3qfVQ/oLO6agnd5 mpGJbOpQ0eemEMUIOwXEaiVhWD13ZrHnxfAH2u4ZnvEHoJGyFRpfd2skxk3XtEsYwgom oqdvo77iWtPH5nqmiwhM8raU+k9wElhdkBk5lkqqvPSiUB7AaOR9b2+1XLCvRx8vvRRm eg5d/WcVtSlBMAUs49khTmSV6JaV+B28ibU/tnPV5tEIt83WxGL1akSqy7gnnNOiHCyE IiWRUN/Y4JSmV3tyBh41bRz33ZlZMPl5e6VL5I4/Muni+VR2gfxzJrW60xd/yaAdyDYW GnXw== X-Gm-Message-State: AIkVDXJyncJy7uLepf/KwsUbVmnnVn3Rssr8R6zJx145coFCn1hgxiDDWDp1ngf1uRS4nA== X-Received: by 10.36.26.9 with SMTP id 9mr18049439iti.25.1485819764393; Mon, 30 Jan 2017 15:42:44 -0800 (PST) Received: from oc3016140333.ibm.com ([32.97.110.56]) by smtp.gmail.com with ESMTPSA id k6sm9125544ioe.1.2017.01.30.15.42.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jan 2017 15:42:43 -0800 (PST) From: eajames.ibm@gmail.com 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, joel@jms.id.au, benh@kernel.crashing.org, eajames@linux.vnet.ibm.com, "Edward A. James" Subject: [PATCH linux v5 5/6] hwmon: occ: Add hwmon implementation for the P8 OCC Date: Mon, 30 Jan 2017 17:42:17 -0600 Message-Id: <1485819738-957-6-git-send-email-eajames.ibm@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1485819738-957-1-git-send-email-eajames.ibm@gmail.com> References: <1485819738-957-1-git-send-email-eajames.ibm@gmail.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 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 --- Documentation/devicetree/bindings/hwmon/occ.txt | 13 +++ drivers/hwmon/occ/Kconfig | 14 ++++ drivers/hwmon/occ/Makefile | 1 + drivers/hwmon/occ/p8_occ_i2c.c | 104 ++++++++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/occ.txt create mode 100644 drivers/hwmon/occ/p8_occ_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 cdb64a7..3a5188f 100644 --- a/drivers/hwmon/occ/Kconfig +++ b/drivers/hwmon/occ/Kconfig @@ -13,3 +13,17 @@ menuconfig SENSORS_PPC_OCC This driver can also be built as a module. If so, the module will be called occ. + +if SENSORS_PPC_OCC + +config SENSORS_PPC_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 driver can also be built as a module. If so, the module will be + called p8-occ-i2c. + +endif diff --git a/drivers/hwmon/occ/Makefile b/drivers/hwmon/occ/Makefile index a6881f9..9294b58 100644 --- a/drivers/hwmon/occ/Makefile +++ b/drivers/hwmon/occ/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_SENSORS_PPC_OCC) += occ.o occ_sysfs.o +obj-$(CONFIG_SENSORS_PPC_OCC_P8_I2C) += occ_scom_i2c.o occ_p8.o p8_occ_i2c.o diff --git a/drivers/hwmon/occ/p8_occ_i2c.c b/drivers/hwmon/occ/p8_occ_i2c.c new file mode 100644 index 0000000..6273040 --- /dev/null +++ b/drivers/hwmon/occ/p8_occ_i2c.c @@ -0,0 +1,104 @@ +/* + * p8_occ_i2c.c - hwmon OCC driver + * + * This file contains the i2c layer for accessing the P8 OCC over i2c bus. + * + * Copyright 2016 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. + * + * 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 +#include +#include +#include "occ_p8.h" +#include "occ_scom_i2c.h" +#include "occ_sysfs.h" +#include "scom.h" + +#define P8_OCC_I2C_NAME "p8-occ-i2c" + +int p8_i2c_getscom(void *bus, u32 address, u64 *data) +{ + /* P8 i2c slave requires 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 address to be shifted by 1 */ + address = address << 1; + + return occ_i2c_putscom(bus, address, data0, data1); +} + +static 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_start(&client->dev, client, &p8_bus_ops); + if (IS_ERR(occ)) + return PTR_ERR(occ); + + hwmon = occ_sysfs_start(&client->dev, occ, sensor_hwmon_configs, + P8_OCC_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[] = { + { P8_OCC_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 = P8_OCC_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");