From patchwork Mon Jan 16 21:13:36 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: 9519495 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 09F2960209 for ; Mon, 16 Jan 2017 21:15:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDBFC28111 for ; Mon, 16 Jan 2017 21:15:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0F76281F9; Mon, 16 Jan 2017 21:15:19 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,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 7CB9B28111 for ; Mon, 16 Jan 2017 21:15:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751610AbdAPVPF (ORCPT ); Mon, 16 Jan 2017 16:15:05 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:33171 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751179AbdAPVOJ (ORCPT ); Mon, 16 Jan 2017 16:14:09 -0500 Received: by mail-io0-f193.google.com with SMTP id 101so13830000iom.0; Mon, 16 Jan 2017 13:14:09 -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=JHCa8SmT66vft1R7Xa5MqQlbPeUSEG0+CJGJ96dALME=; b=NBzI66DznHDiSRV4k6by8JwbmqU+69cFiShrBAnXGd0JQr6gs2Cyk9peUYIFo8+EzC Rg2XRs7Xs73iybyjRBsbFDWMwk5Y98lJpys7GlqkVQi26AeoLfKGJCqObONpa38EBfy6 j0RXkMM0KWZ+YdZNf5jaaRSW9rIebxj7W5IT1ohlkR8Ym15A6TRBTRofE1P2pfG18MIP 11Eranq/CoA1Yuxx+j3IYiOUi9/G4H1aU1lUvebrqFTUdUaxS93NzSFtxEOkRIhvT/PH AWBgoWnWJySSnnhb8r29/Jx6p137AM/PyGJXBbwI0ZHkPBVxQayuhfzozzTu7kvCB8Kh 2TCw== 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=JHCa8SmT66vft1R7Xa5MqQlbPeUSEG0+CJGJ96dALME=; b=qZSnhRG8vXjjDTwzzFeA0wz1TFyCu6wugH8DPKzj3OmUiv6FLjnFhtvhz8XpEWrFD9 vf+HPLuI4ID5ML71UKDOr/IcycfK7CW60KSClCNEtRc6vejKfYbbkSKNZ9lOAx2rh0HX ONCCczwIxqHyfeAY69/pUJr2WRr9GY1d8VDsoJamT5qqPmb4uVMK2A+45JCYUOtFJJga mud0UxR8SPLWdskMbZeXcHFyIOPSL0IaqiBHyCf4NsEtNHm0cES7YgmvXnu7e9+r/uy8 7HsnXlNTRdFXNvNdE83azxnHXx2g1vRRd18js4ZEiYKdgXgIZU7ktLUFEGO5X/bYrqVk oKiQ== X-Gm-Message-State: AIkVDXJszfrau5YLtgfJFQevVEEVtxnOncnzcVZWbzVY+eRvfoJgxLZ0cxAyAD0DQ4M9jQ== X-Received: by 10.107.169.205 with SMTP id f74mr38246059ioj.28.1484601248670; Mon, 16 Jan 2017 13:14:08 -0800 (PST) Received: from eajames-austin-w350.austin.ibm.com ([32.97.110.55]) by smtp.gmail.com with ESMTPSA id i62sm6220452itb.12.2017.01.16.13.14.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Jan 2017 13:14:07 -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 v3 3/6] hwmon: occ: Add I2C transport implementation for SCOM operations Date: Mon, 16 Jan 2017 15:13:36 -0600 Message-Id: <1484601219-30196-4-git-send-email-eajames.ibm@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484601219-30196-1-git-send-email-eajames.ibm@gmail.com> References: <1484601219-30196-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 | 72 ++++++++++++++++++++++++++++++++++++++++ drivers/hwmon/occ/occ_scom_i2c.h | 26 +++++++++++++++ 2 files changed, 98 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..8b4ca13 --- /dev/null +++ b/drivers/hwmon/occ/occ_scom_i2c.c @@ -0,0 +1,72 @@ +/* + * 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; + + rc = i2c_master_send(client, (const char *)&address, sizeof(u32)); + if (rc < 0) + return rc; + else if (rc != sizeof(u32)) + return -EIO; + + rc = i2c_master_recv(client, (char *)&buf, sizeof(u64)); + if (rc < 0) + return rc; + else if (rc != sizeof(u64)) + return -EIO; + + *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; + + 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__ */