From patchwork Thu Jan 26 23:19:15 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: 9540307 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 37A60604AA for ; Thu, 26 Jan 2017 23:20:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E3572830A for ; Thu, 26 Jan 2017 23:20:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22E7B281C3; Thu, 26 Jan 2017 23:20:23 +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 6B60627F07 for ; Thu, 26 Jan 2017 23:20:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753268AbdAZXUD (ORCPT ); Thu, 26 Jan 2017 18:20:03 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:36325 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752896AbdAZXTp (ORCPT ); Thu, 26 Jan 2017 18:19:45 -0500 Received: by mail-qt0-f196.google.com with SMTP id h53so5723219qth.3; Thu, 26 Jan 2017 15:19: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=mUj9Jrp9osEPB3J432NjSEHvmwxY6DeDiNTPUVomaEE=; b=nhBkYY5EwdM8/3Nc5FSTlzWptrgrN3WXqNFdWKB10P2//hVcCZ3Gme16SF6Cc44tBi Ev0P2KDLUIj536uiY8i1UndShj7W6NJGjKxL28HAlMTYdVO3jzP1eGVLtUHAMlHmbSSl 8YyTb7StbOPa+C6ef9MjhQCl3PNKYyUdHbbcF25R25A9xpNqkRVf5qxlmt5bXXhGDlrA AX5I31nX8Y/01S4aTsjmWFOT+1wh6hQfWaEQbCVqWp1ystBJ18jMSIFcyE+G3W7ROVtw HB2+fH2I3gzdHS8eeq8npjdRH0rZdcLTfk50DAVvDG/55wcHnyDS5L7BVmSHdcT8EOr9 eRQA== 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=mUj9Jrp9osEPB3J432NjSEHvmwxY6DeDiNTPUVomaEE=; b=Sq4X1BhGmkwgAWBayQuXQ5UIN1F0NAZ+mMeQhyewk3N7P1qAtfZfgjDDjNqQebsqdL Z/moAS69+JQmLll82lEj5rLKo5gPXjMND5qI6aTPcvFLzMJTu0M54X0wYq37+PXkVKo6 uXE7NeEMZ5dZSbwixzPEut2YmrQnnhOiJGgqV7b3T0mO42pnFLlZpemLeagMUuVTiAkI Tms6P/4IS1LMhDNrq6cCqVVRKVc9xHhNjFZMQ3G4aS0/cuS09+HWSD7UF9Fo32Y+isAE 1FZfS47hHE7khDSYltdx0esnsLqcVelD4pg7yESJL3SejYIhN29MH2OiRJ3ds9QSMRkI QMyw== X-Gm-Message-State: AIkVDXIcq4fZ6l6sDm8zoBXQnPQzuX4bmyvXARU/Hs0bV4FErketNEzGlgcbNAfMSx0jHQ== X-Received: by 10.55.93.131 with SMTP id r125mr5696111qkb.208.1485472783484; Thu, 26 Jan 2017 15:19:43 -0800 (PST) Received: from eajames-austin-w350.austin.ibm.com ([32.97.110.56]) by smtp.gmail.com with ESMTPSA id x62sm2484865qkg.31.2017.01.26.15.19.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Jan 2017 15:19:42 -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, "Edward A. James" Subject: [PATCH linux v4 3/6] hwmon: occ: Add I2C transport implementation for SCOM operations Date: Thu, 26 Jan 2017 17:19:15 -0600 Message-Id: <1485472758-11003-4-git-send-email-eajames.ibm@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1485472758-11003-1-git-send-email-eajames.ibm@gmail.com> References: <1485472758-11003-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 functions to send SCOM operations over I2C bus. The BMC can communicate with the Power8 host processor over I2C, but needs to use SCOM operations in order to access the OCC register space. Signed-off-by: Edward A. James Signed-off-by: Andrew Jeffery --- drivers/hwmon/occ/occ_scom_i2c.c | 77 ++++++++++++++++++++++++++++++++++++++++ drivers/hwmon/occ/occ_scom_i2c.h | 26 ++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 drivers/hwmon/occ/occ_scom_i2c.c create mode 100644 drivers/hwmon/occ/occ_scom_i2c.h diff --git a/drivers/hwmon/occ/occ_scom_i2c.c b/drivers/hwmon/occ/occ_scom_i2c.c new file mode 100644 index 0000000..74bd6ff --- /dev/null +++ b/drivers/hwmon/occ/occ_scom_i2c.c @@ -0,0 +1,77 @@ +/* + * occ_scom_i2c.c - hwmon OCC driver + * + * This file contains the functions for performing SCOM operations over I2C bus + * to access the OCC. + * + * 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 "occ_scom_i2c.h" +#include "scom.h" + +int occ_i2c_getscom(void *bus, u32 address, u64 *data) +{ + ssize_t rc; + u64 buf; + struct i2c_client *client = bus; + struct i2c_msg msgs[2]; + + msgs[0].addr = client->addr; + msgs[0].flags = client->flags & I2C_M_TEN; + msgs[0].len = sizeof(u32); + msgs[0].buf = (char *)&address; + + msgs[1].addr = client->addr; + msgs[1].flags = client->flags & I2C_M_TEN; + msgs[1].flags |= I2C_M_RD; + msgs[1].len = sizeof(u64); + msgs[1].buf = (char *)&buf; + + rc = i2c_transfer(client->adapter, msgs, 2); + if (rc < 0) + return rc; + + *data = be64_to_cpu(buf); + + return 0; +} +EXPORT_SYMBOL(occ_i2c_getscom); + +int occ_i2c_putscom(void *bus, u32 address, u32 data0, u32 data1) +{ + u32 buf[3]; + ssize_t rc; + struct i2c_client *client = bus; + + /* send raw data, user can handle endian */ + buf[0] = address; + buf[1] = data1; + buf[2] = data0; + + rc = i2c_master_send(client, (const char *)buf, sizeof(u32) * 3); + if (rc < 0) + return rc; + else if (rc != sizeof(u32) * 3) + return -EIO; + + return 0; +} +EXPORT_SYMBOL(occ_i2c_putscom); + +MODULE_AUTHOR("Eddie James "); +MODULE_DESCRIPTION("I2C OCC SCOM transport"); +MODULE_LICENSE("GPL"); diff --git a/drivers/hwmon/occ/occ_scom_i2c.h b/drivers/hwmon/occ/occ_scom_i2c.h new file mode 100644 index 0000000..945739c --- /dev/null +++ b/drivers/hwmon/occ/occ_scom_i2c.h @@ -0,0 +1,26 @@ +/* + * occ_scom_i2c.h - hwmon OCC driver + * + * This file contains function protoypes for peforming SCOM operations over I2C + * bus to access the OCC. + * + * 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. + */ + +#ifndef __OCC_SCOM_I2C_H__ +#define __OCC_SCOM_I2C_H__ + +int occ_i2c_getscom(void *bus, u32 address, u64 *data); +int occ_i2c_putscom(void *bus, u32 address, u32 data0, u32 data1); + +#endif /* __OCC_SCOM_I2C_H__ */