From patchwork Fri Dec 30 17:56:05 2016 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: 709851 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3tqvMS4Qyrz9sfH for ; Sat, 31 Dec 2016 04:57:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Unozj6Cc"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754068AbcL3R5m (ORCPT ); Fri, 30 Dec 2016 12:57:42 -0500 Received: from mail-it0-f68.google.com ([209.85.214.68]:33475 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751989AbcL3R4n (ORCPT ); Fri, 30 Dec 2016 12:56:43 -0500 Received: by mail-it0-f68.google.com with SMTP id c20so41895140itb.0; Fri, 30 Dec 2016 09:56:42 -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=Unozj6CczQL6Uj+8DpaJxP4fweolrIu1nTftS+9KcV6LkP2+Ua0hGbYBrXFXwI9DnX nXURM4mQIPKeFnkDfNMOYdWh6CJ0ZdSEGet8kPWvB6jDMx7291bHSewwyYXHSYup1yzK ISzjpJAPFuF6BhDhrbotuvqZH/xqw35S80fDb9s8gSTo1iBMmMGVTBkyAxgaTfW4e7Vm NjbMippYrQR8yinhNQxPCB5gMa/V2X0LREiMVekXMkQeXscqw/GC3f3qG1Vv4w5kM56N 58J72z9EfDT2hVtNlU6fKsE9mk3Q9uGbm54I6TPnjWBGkEWA/D6cIXSYSQU8rAbjzsKZ CbBQ== 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=sOUf4wpX91K9TCkBuaOBsGA0sVMC4lQIc6ad7R0kyYIvIBzkik4rSHLIsIw4YGY5ea sD8vrAbh1yEaYZYwPBsDf9iB8qX3GQNZu7swMZC98l/MznCkdDRfq0wU9l5rDS/BCLWc LMNQlKmhoO+2QmEu1wE8MXfFx6l+IafMqiDSglZ2AtPaDU64dWuZjkIGur0xEXUoPG6u gkEZ7IvfbQoQFL6oI5SifYoKkUwUQNKOjB4D7AGHfPGngp1l45p/WGOwQl748/7uGncg xWRRqZtVkpPv9XyQ87h+9cq1yajlrFO7aGJzPZ1vY0Lcx/AYk/LSPpi4wyJOBGfBp/Y0 2MkQ== X-Gm-Message-State: AIkVDXILn1ZIjkdMzHe4P8NGdRiiyxaOcznY57bj5Cvaum9xF8SFYmyk5TeguCon/sfuGA== X-Received: by 10.36.88.143 with SMTP id f137mr36139150itb.67.1483120602020; Fri, 30 Dec 2016 09:56:42 -0800 (PST) Received: from eajames-austin-w350.ibm.com ([32.97.110.51]) by smtp.gmail.com with ESMTPSA id d77sm4524611itc.10.2016.12.30.09.56.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Dec 2016 09:56:41 -0800 (PST) From: eajames.ibm@gmail.com To: linux@roeck-us.net Cc: 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, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, "Edward A. James" Subject: [PATCH linux 3/6] hwmon: occ: Add I2C transport implementation for SCOM operations Date: Fri, 30 Dec 2016 11:56:05 -0600 Message-Id: <1483120568-21082-4-git-send-email-eajames.ibm@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483120568-21082-1-git-send-email-eajames.ibm@gmail.com> References: <1483120568-21082-1-git-send-email-eajames.ibm@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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__ */