Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1908136pxb; Wed, 30 Mar 2022 12:20:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxASgc2p/ZxKyhJwJt45Uc/dirgrJzga8f4SpdBqsanL8Pn30ZbhSLY4o3mBsr5nDIWQTxf X-Received: by 2002:a17:907:961f:b0:6db:c8f3:dc72 with SMTP id gb31-20020a170907961f00b006dbc8f3dc72mr1223483ejc.92.1648668023844; Wed, 30 Mar 2022 12:20:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648668023; cv=none; d=google.com; s=arc-20160816; b=a8wdopNlaz+EFRXoFjZlElKIyJRzeEm1AJ1IQ78p6FOe8c+BG7kNmV0z53U4dq8ZYR EXyoFOrOad9UPFWVMGgg3TwJz1fXu1Ib8Q/2jJXoAXNCO1WN3wzgzwDqWfCZc+BbSz8j ed/MWWDQ2qMPnVitDrYFiuNg6NUiMf+EGYiEIys3iX+SGNwHqejPO2/W4TPG6fMddn+b h6hGgKR/3WM+cqom1E4khItcfTyltaX7c/7bXVvFPJGOIX00ptFAR/7bPMAko5N/pHYD U/NVEwp1/uk6HRNJHJAVHS7uP2mLFaCwvo/aPpdAceg/XgaX7Zr1dTo6VNR1pGSMZhHg 9NHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:dkim-signature:from; bh=MNw6TZjQg12ilqVca1Iyk/1Sr/JwKEtEFZo4CqiuRdA=; b=i6bFL42RScI4boDdo9BAKSK/7WOi/ZGXUJibcDJQnZDF8ee+W729AcNxc1GdQsjdTw XkqPy/NJxR3qEpOwXc8nsTHNht10UdE61I/a4Mrf7vhCjnLRt5jxKRTR01REiVFYNwE8 SHuKvQKH8VW0R0ZJ9cxwESGuq6V7rR8+AHxCvU6x7nXSxokd5RdznyKI7GNsN9V49Bpa EUnQKHjLrJ1ImZu1iHIY0vZp3jtvvLovYLbAaArZ7DSxbwKnwFqQprt3+9FzjEpM/xQ9 A8ta88nqETNJP+g50AcalftG9WdrYDln1PPHh9jLM5U2b/SIAGCfHFiikYzVsEynBn5k lzsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cutebit.org header.s=mail header.b="MK0FFNR/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cutebit.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bi22-20020a170906a25600b006df7ac950c9si19570401ejb.870.2022.03.30.12.19.56; Wed, 30 Mar 2022 12:20:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cutebit.org header.s=mail header.b="MK0FFNR/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cutebit.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240614AbiC2Skb (ORCPT + 99 others); Tue, 29 Mar 2022 14:40:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240150AbiC2Sk3 (ORCPT ); Tue, 29 Mar 2022 14:40:29 -0400 Received: from hutie.ust.cz (unknown [IPv6:2a03:3b40:fe:f0::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2B3E6401 for ; Tue, 29 Mar 2022 11:38:43 -0700 (PDT) From: =?UTF-8?q?Martin=20Povi=C5=A1er?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cutebit.org; s=mail; t=1648579115; bh=MNw6TZjQg12ilqVca1Iyk/1Sr/JwKEtEFZo4CqiuRdA=; h=From:To:Cc:Subject:Date; b=MK0FFNR/dSMhYqsYkSiQpNIza2jECdZ01Sz1FG5KrRdcROhl1cEAdsLSEG4wXdfeM eEMzqSrFbkDtDZ9SN0WP0Wmg5wGWgEy3BVWpFBv37e0G916tpdI4G+MZ3CvqY2yZzb ovpC3Ak2hp3f1boVZ3YgYRmmBggUEat5PHwD2+Dw= To: Hector Martin , Sven Peter , Michael Ellerman Cc: Alyssa Rosenzweig , Benjamin Herrenschmidt , Paul Mackerras , Jean Delvare , Olof Johansson , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Janne Grunau , =?UTF-8?q?Martin=20Povi=C5=A1er?= Subject: [PATCH] i2c: pasemi: Wait for write xfers to finish Date: Tue, 29 Mar 2022 20:38:17 +0200 Message-Id: <20220329183817.21656-1-povik+lin@cutebit.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_FAIL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wait for completion of write transfers before returning from the driver. At first sight it may seem advantageous to leave write transfers queued for the controller to carry out on its own time, but there's a couple of issues with it: * Driver doesn't check for FIFO space. * The queued writes can complete while the driver is in its I2C read transfer path which means it will get confused by the raising of XEN (the 'transaction ended' signal). This can cause a spurious ENODATA error due to premature reading of the MRXFIFO register. Adding the wait fixes some unreliability issues with the driver. There's some efficiency cost to it (especially with pasemi_smb_waitready doing its polling), but that will be alleviated once the driver receives interrupt support. Fixes: beb58aa39e6e ("i2c: PA Semi SMBus driver") Signed-off-by: Martin PoviĊĦer --- Tested on Apple's t8103 chip. To my knowledge the PA Semi controller in its pre-Apple occurences behaves the same as far as this patch is concerned. drivers/i2c/busses/i2c-pasemi-core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/i2c/busses/i2c-pasemi-core.c b/drivers/i2c/busses/i2c-pasemi-core.c index 7728c8460dc0..9028ffb58cc0 100644 --- a/drivers/i2c/busses/i2c-pasemi-core.c +++ b/drivers/i2c/busses/i2c-pasemi-core.c @@ -137,6 +137,12 @@ static int pasemi_i2c_xfer_msg(struct i2c_adapter *adapter, TXFIFO_WR(smbus, msg->buf[msg->len-1] | (stop ? MTXFIFO_STOP : 0)); + + if (stop) { + err = pasemi_smb_waitready(smbus); + if (err) + goto reset_out; + } } return 0; -- 2.33.0