From patchwork Wed Jan 11 18:10:34 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: 9510971 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 513DA601E7 for ; Wed, 11 Jan 2017 18:12:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32CE728652 for ; Wed, 11 Jan 2017 18:12:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 277CB28654; Wed, 11 Jan 2017 18:12:58 +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 AFDB628652 for ; Wed, 11 Jan 2017 18:12:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S939185AbdAKSL6 (ORCPT ); Wed, 11 Jan 2017 13:11:58 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:34752 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939171AbdAKSK6 (ORCPT ); Wed, 11 Jan 2017 13:10:58 -0500 Received: by mail-io0-f195.google.com with SMTP id c80so14025609iod.1; Wed, 11 Jan 2017 10:10:57 -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=/L929HMOFfYp6GlTJ4Y+Hw1Dwwb31PpHakNvxvfqjK8=; b=AkYv+kPfze5PDcyZ4A44c+BIEzagke4fqMr2VgotM2WWUC/OsyvqTnUNVb1QXOMff+ jTDTEtjXMEQulLApZ/uHfoheTQioT1hmi4xHw3nRbh+26lF6vEAQNAscCElApctbWY3r agmYj6dkDOfIai/X10FOYC1l3XXB4sCyNvI4KYa59Pof3wQ8ib6XjeiS+x4Ejn1t0F9I bbdgDxM+bW44xqr36LFfC90zLpoV7bUD5l4699mRQYYz8Dpa2VyksjMcQHTkbJJI1GjR fiQCN/ATDt/z1evH76GxU+SaL56AyzJVFfxamDCcUjVi1bGAuOmarwxDg8wBBCvyTpdJ F4oQ== 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=/L929HMOFfYp6GlTJ4Y+Hw1Dwwb31PpHakNvxvfqjK8=; b=pUybir3Jlx6cxmTmEiDtRlbJDOrSzs06sN/ZYnBe3aH9sWA7mbPTCBrd7vPdiExRvl ElBuwZ34dLbhFt8nWfvQ0AvavNSFojoLZ0ZubIs3iHM79tRjDLBH9FypCIKkCgzoXchF r0HmSDWY1emBmVZt8l4khByyXJxsaIKPLTKoG637pOGt7a7c9UKo9Gt75+HwmzHaghG1 tzmY1h211SwC8VyuZORYNnvPdTTHxuK3sjbR028beeSAci51Elw5/TZFWsqbSrkpHAEk 76JOfkwi25jXULyCT9N9fDizIug+rKqW3ePktJhx+rkIEMh/K8TKbFfQVllh1FZ6ZeCX BUUQ== X-Gm-Message-State: AIkVDXJYZKaFJ5FjUCQUSCU0BaIM35dxbpDtvLqrbIm1ZIp5wgdKEnNXrvUln3aGsYT1MQ== X-Received: by 10.107.30.141 with SMTP id e135mr10877272ioe.84.1484158256870; Wed, 11 Jan 2017 10:10:56 -0800 (PST) Received: from eajames-austin-w350.austin.ibm.com ([32.97.110.55]) by smtp.gmail.com with ESMTPSA id w143sm3415940itc.0.2017.01.11.10.10.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jan 2017 10:10:56 -0800 (PST) From: eajames.ibm@gmail.com To: linux@roeck-us.net Cc: devicetree@vger.kernel.org, jdelvare@suse.com, corbet@lwn.net, linux-doc@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, 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 v2 3/6] hwmon: occ: Add I2C transport implementation for SCOM operations Date: Wed, 11 Jan 2017 12:10:34 -0600 Message-Id: <1484158237-10014-4-git-send-email-eajames.ibm@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484158237-10014-1-git-send-email-eajames.ibm@gmail.com> References: <1484158237-10014-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 | 73 ++++++++++++++++++++++++++++++++++++++++ drivers/hwmon/occ/occ_scom_i2c.h | 26 ++++++++++++++ 2 files changed, 99 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..a922f83 --- /dev/null +++ b/drivers/hwmon/occ/occ_scom_i2c.c @@ -0,0 +1,73 @@ +/* + * 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 "scom.h" +#include "occ_scom_i2c.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__ */