From patchwork Mon Nov 27 16:31:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 10077221 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 169296028E for ; Mon, 27 Nov 2017 16:31:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08217287E6 for ; Mon, 27 Nov 2017 16:31:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0FA928FB7; Mon, 27 Nov 2017 16:31:42 +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_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 D7AEB28FBB for ; Mon, 27 Nov 2017 16:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753422AbdK0Qbj (ORCPT ); Mon, 27 Nov 2017 11:31:39 -0500 Received: from mail-eopbgr20108.outbound.protection.outlook.com ([40.107.2.108]:19521 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753524AbdK0QbP (ORCPT ); Mon, 27 Nov 2017 11:31:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axentiatech.onmicrosoft.com; s=selector1-axentia-se; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=CYkzEGrV0PiIIQOPSMEAv6nlZPtYaRDFb3QnqN4xV3k=; b=iB+SOsKE1xRWKQ8QQXo71eWErJEPL+IXUwHfOxBadmUtN+JlKGndJincq6juPe3UJyCTbQuQ+DM7gzHCFAQ8lo6IHFP66qJGxgd3FPjUOMzb9IDJfuNTYe0xO+tL9ZP2lqydmygfJE+1KfYxdCvBurB/rC60TWmPdJk9X46hKBk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; Received: from orc.pedanet (85.226.244.23) by AM5PR0202MB2546.eurprd02.prod.outlook.com (2603:10a6:203:6d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.260.4; Mon, 27 Nov 2017 16:31:10 +0000 From: Peter Rosin To: linux-kernel@vger.kernel.org Cc: Peter Rosin , Rob Herring , Mark Rutland , Nicolas Ferre , Alexandre Belloni , Russell King , Guenter Roeck , Jean Delvare , Ludovic Desroches , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hwmon@vger.kernel.org Subject: [PATCH v2 1/2] hwmon: (jc42) optionally try to disable the SMBUS timeout Date: Mon, 27 Nov 2017 17:31:00 +0100 Message-Id: <20171127163101.27859-2-peda@axentia.se> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171127163101.27859-1-peda@axentia.se> References: <20171127163101.27859-1-peda@axentia.se> MIME-Version: 1.0 X-Originating-IP: [85.226.244.23] X-ClientProxiedBy: DB6P18901CA0019.EURP189.PROD.OUTLOOK.COM (2603:10a6:4:16::29) To AM5PR0202MB2546.eurprd02.prod.outlook.com (2603:10a6:203:6d::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5fafe226-f3df-44e0-6a01-08d535b44579 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4603075)(4627115)(201702281549075)(5600026)(4604075)(2017052603199); SRVR:AM5PR0202MB2546; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0202MB2546; 3:sbfXJ9Vwl2JS3IP013VV90ihMtrFOuYi+11fpA0bPwKyzXvGkxbI0y7rKHcdOSfm2SoW71WvytqbPBr6WxyWa7CnOMYbxDmicXoNgezzFWuQQX2rtzEJO/mcSONwEPTe2cDlrWPX4lZBgaWMr3Xpon+H7AG9ImZvrdKVRCmpSK+1eigQBAhxOKBBQwhVB2QPBmi41poJSy6ZEhj8vBsQHEsjHgNI6VDcE3kqAI628W+mWHxqHL1tgKcYNjL9maRQ; 25:iSpLq5aI9JbH7UgDTQl5GVXBkaaw9m7cgyPhhApJfbwW592peFKn9ko7hv6e9JoAdr6wb+RT9RhHBp8bfRO3Eu6RRjjtsWKFVdeNqwNkWa0pvBEzrG1CosbFpdrXsdq5CnKyvv5H6A1EfpckE0JRTyKnK9VTKLZJoC66TtBCPZASczGE3wrTZ0knvVFVABnIFEcwnT/K0edprrDtQ4yvRsiHGLghTWHJ7QFPMU2a59FdEcPjw54LWrzhDbJzByvqsS1Q5fBMYW3vb8OEcE62b2YRfF/PHzEsZ7oBwaWI7/9QeLJbwYbeb5EyCgP67QfrAqEuXubmZWCS9pUPO3xuSQ==; 31:ECcZ1lj53RC4Zp9D53puLQPUEa0hgMpW2DDMzDmIwbC+LZ1O0bSFvIreYXsq0WiIGUwl02SMa4lRwGCayrrjAtSrbmB/QtBjDEVKuTMIGfp0LHIdHRFEeznxeqDJNrLUh0lQnXAGamG+04YSnaUrHDvI3T3R7OEVUhVtMGMVhv6INLFZmY2J0b4WM1W0y3oPXbuakBtP3bEOIMTLQmLB9GU8f9pn/cwujiH7aLjTENs= X-MS-TrafficTypeDiagnostic: AM5PR0202MB2546: X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(3002001)(3231022)(10201501046)(93006095)(93001095)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(20161123564025)(20161123562025)(20161123555025)(2016111802025)(6072148)(6043046)(201708071742011); SRVR:AM5PR0202MB2546; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:AM5PR0202MB2546; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0202MB2546; 4:8p3fKGC5XtocnW+6ozAkPmeuq+F76rf5R1UU/cgKK8D95PiSarn/2yA6hEsgCxM6dnlElki8IN4Rx34tfmgHgLkc1L2mbz8/EqjUC0wNKZdcGnUJ1ZzHQfIucARvMq8Z1fH+wt3Y08xd8f11ARF/HR+26DDj7PGA+ZOZB4qjozWwgIj33/IohLIxOuc8E4jsK9URZcYbJBhklITcoi3kq8Zsh1xR13dkGes22lheJYqF8zvfw5+KcjfPpEIPM7NXHbJRqL+XLrIAm5VQXvOAZQ== X-Forefront-PRVS: 0504F29D72 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(376002)(346002)(366004)(39830400002)(199003)(189002)(101416001)(50226002)(8936002)(68736007)(97736004)(1076002)(6506006)(50986999)(16526018)(3846002)(81156014)(54906003)(53936002)(4326008)(52116002)(478600001)(7416002)(7736002)(189998001)(16586007)(76176999)(81166006)(6116002)(8676002)(305945005)(6486002)(48376002)(47776003)(5660300001)(86362001)(25786009)(74482002)(51416003)(316002)(36756003)(2906002)(2351001)(6916009)(2361001)(6512007)(6666003)(106356001)(2950100002)(33646002)(66066001)(105586002)(50466002)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0202MB2546; H:orc.pedanet; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: axentia.se does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0202MB2546; 23:IAVZjgZb3psKn8eEcprPZGwIrL4bWcyEktED1dj?= =?us-ascii?Q?c88wPY9lD9lzybYp/yH5yf9Pqguv/QaM4TefPI2WLpP/T2q27+VstWioXqwW?= =?us-ascii?Q?dsvlSCizHOjwqwTU/LHP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5nCT+TcLzkfI1XSkevdq1RccNVfiu1WjO0gavzhBAoL2vhVc6Pj5h1XJZaBW6E1/FrVbYbgz8ba0HrZnQFBDhTQr8BGxdiQ8wxN2bEnAl32NZifolZGxF2j8V08h/eNOiYTC5YvHGNfFW/vGhcV5sfmfWNMZg4rrx/+aW/an8f+4R9ATQsZr6TJqqNu5iZXUW8F/MkCuoov SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2017 16:31:10.8138 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5fafe226-f3df-44e0-6a01-08d535b44579 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4ee68585-03e1-4785-942a-df9c1871a234 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0202MB2546 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 With a nxp,se97 chip on an atmel sama5d31 board, the I2C adapter driver is not always capable of avoiding the 25-35 ms timeout as specified by the SMBUS protocol. This may cause silent corruption of the last bit of any transfer, e.g. a one is read instead of a zero if the sensor chip times out. This also affects the eeprom half of the nxp-se97 chip, where this silent corruption was originally noticed. Other I2C adapters probably suffer similar issues, e.g. bit-banging comes to mind as risky... The SMBUS register in the nxp chip is not a standard Jedec register, but it is not special to the nxp chips either, at least the atmel chips have the same mechanism. Therefore, do not special case this on the manufacturer, it is opt-in via the device property anyway. Signed-off-by: Peter Rosin Acked-by: Rob Herring --- Documentation/devicetree/bindings/hwmon/jc42.txt | 4 ++++ drivers/hwmon/jc42.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/jc42.txt b/Documentation/devicetree/bindings/hwmon/jc42.txt index 07a250498fbb..f569db58f64a 100644 --- a/Documentation/devicetree/bindings/hwmon/jc42.txt +++ b/Documentation/devicetree/bindings/hwmon/jc42.txt @@ -34,6 +34,10 @@ Required properties: - reg: I2C address +Optional properties: +- smbus-timeout-disable: When set, the smbus timeout function will be disabled. + This is not supported on all chips. + Example: temp-sensor@1a { diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c index 5f11dc014ed6..e5234f953a6d 100644 --- a/drivers/hwmon/jc42.c +++ b/drivers/hwmon/jc42.c @@ -22,6 +22,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include #include #include @@ -45,6 +46,7 @@ static const unsigned short normal_i2c[] = { #define JC42_REG_TEMP 0x05 #define JC42_REG_MANID 0x06 #define JC42_REG_DEVICEID 0x07 +#define JC42_REG_SMBUS 0x22 /* NXP and Atmel, possibly others? */ /* Status bits in temperature register */ #define JC42_ALARM_CRIT_BIT 15 @@ -75,6 +77,9 @@ static const unsigned short normal_i2c[] = { #define GT_MANID 0x1c68 /* Giantec */ #define GT_MANID2 0x132d /* Giantec, 2nd mfg ID */ +/* SMBUS register */ +#define SMBUS_STMOUT BIT(7) /* SMBus time-out, active low */ + /* Supported chips */ /* Analog Devices */ @@ -495,6 +500,22 @@ static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id) data->extended = !!(cap & JC42_CAP_RANGE); + if (device_property_read_bool(dev, "smbus-timeout-disable")) { + int smbus; + + /* + * Not all chips support this register, but from a + * quick read of various datasheets no chip appears + * incompatible with the below attempt to disable + * the timeout. And the whole thing is opt-in... + */ + smbus = i2c_smbus_read_word_swapped(client, JC42_REG_SMBUS); + if (smbus < 0) + return smbus; + i2c_smbus_write_word_swapped(client, JC42_REG_SMBUS, + smbus | SMBUS_STMOUT); + } + config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG); if (config < 0) return config;