From patchwork Mon Sep 4 01:25:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommy Huang X-Patchwork-Id: 13373397 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E814C83F2D for ; Mon, 4 Sep 2023 01:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=E8+Xz2PacWT9wLdVfgBFhaRD70wiMaZt683moKq+C3U=; b=OgRm/um1X35e1I I19HL+A1CIpE4sbHDFe/Qz8Ld/j/fuxJEapQORzLIjTeXEa24puDpF0vPgHngMTFs8Az87zU0atvA kTViLSDv1+hc9znb+2LpwPvhSH7TLmimdyr2I4EMeb+wbs6nn4kufXa5aybZOxpdlTRPDINm/JkMU l0VaWDLkQcEPwU1dp/pbT2/X+G9T+s3XVaO6bfjRis708IYg2AxHUEQwif+0S0M52tlCctBmSGeEw mVmXkic7UjafbwyxNiQx9Cv7XEYh25+Y8IfRBMmpkJDdNyoKmTAPduyxMzIFztpcqBaEuZyI+WAcg bJeiMUXSB7C7PY1WJ43w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qcyLF-0037pM-1w; Mon, 04 Sep 2023 01:25:25 +0000 Received: from mail.aspeedtech.com ([211.20.114.72] helo=TWMBX03.aspeed.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qcyL9-0037op-0g for linux-arm-kernel@lists.infradead.org; Mon, 04 Sep 2023 01:25:23 +0000 Received: from TWMBX02.aspeed.com (192.168.0.24) by TWMBX03.aspeed.com (192.168.0.62) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 4 Sep 2023 09:25:06 +0800 Received: from twmbx02.aspeed.com (192.168.10.10) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 4 Sep 2023 09:25:06 +0800 From: Tommy Huang To: , , , , CC: , , , , , , , , Subject: [PATCH] i2c: aspeed: Reset the i2c controller when timeout occurs Date: Mon, 4 Sep 2023 09:25:05 +0800 Message-ID: <20230904012505.340455-1-tommy_huang@aspeedtech.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230903_182519_262046_9FEBAAD3 X-CRM114-Status: GOOD ( 12.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Reset the i2c controller when an i2c transfer timeout occurs. The remaining interrupts and device should be reset to avoid unpredictable controller behavior. Fixes: 2e57b7cebb98 ("i2c: aspeed: Add multi-master use case support") Cc: Jae Hyun Yoo Cc: # v5.1+ Signed-off-by: Tommy Huang Reviewed-by: Andi Shyti --- drivers/i2c/busses/i2c-aspeed.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 2e5acfeb76c8..5a416b39b818 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -698,13 +698,16 @@ static int aspeed_i2c_master_xfer(struct i2c_adapter *adap, if (time_left == 0) { /* - * If timed out and bus is still busy in a multi master - * environment, attempt recovery at here. + * In a multi-master setup, if a timeout occurs, attempt + * recovery. But if the bus is idle, we still need to reset the + * i2c controller to clear the remaining interrupts. */ if (bus->multi_master && (readl(bus->base + ASPEED_I2C_CMD_REG) & ASPEED_I2CD_BUS_BUSY_STS)) aspeed_i2c_recover_bus(bus); + else + aspeed_i2c_reset(bus); /* * If timed out and the state is still pending, drop the pending