From patchwork Mon Oct 30 16:21:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mike.isely@cobaltdigital.com X-Patchwork-Id: 13440759 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 AA09DC4332F for ; Mon, 30 Oct 2023 16:27:25 +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:References:In-Reply-To: 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: List-Owner; bh=wo+gyTWGSvkQet7105/qPYqld082x7QIsEbqlZNol20=; b=lmkzm/nLYjt32T rVvWD+Ta7WlNkfYesEUaEfYffYkADyHMWuOSd1syrh+5DavLq8g2dxn7mVFKezZufYRi6qaaDJRRJ JGDywqNKj4TughAbPAnxgwL7p5la9fIJgW8qL4q0cEAcvTfK3AwF/MBPNQRIyhtpW466uGe+ff0Y9 eK+67CJcYZ507CYXqsPEVlmB+GeygBmePprHCi0lbldpAFKXVBxbycX9EdCqa0maRnbyGctgMH0PC ySn27V7JAVHW1mxDspP9jXeAqkTm6XgILEPG+bjJ8ejb8vvD5U9aAJQFs316JyMs90c1345r2Eh0I Tv+XsLiOHpwch7L6o1FA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qxV6T-003dkP-12; Mon, 30 Oct 2023 16:27:01 +0000 Received: from cnc.isely.net ([192.69.181.175]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qxV68-003dfJ-1Q; Mon, 30 Oct 2023 16:26:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isely.net; s=deb; t=1698682891; bh=hfdYzCdm+x+tKMPgcOZzIeuFJxxf0KYbhVmSfhSKie0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AEhPwc3ik23Rivj/BYW/k5RTjxSASvnPmmZsZ2pJKq0Fu3t/B+OIYQ2KW1Fi3xX9w n+owQehpIKD4JXkT5R0h5K7i2Oatqp3g2yXkk0DZRbLHc1th1QKUcqK4XfX1zvzfjC jVgaAnB5Kv/vejUF++ujkzN3mZbPxg3HOSO9Wf7QL7gdoacwfFZOoKvFBEyM7 Original-Subject: [PATCH 1/2] [i2c-bcm2835] Fully clean up hardware state machine after a timeout Author: mike.isely@cobaltdigital.com Original-Cc: Mike Isely , Mike Isely , Broadcom internal kernel review list , Ray Jui , Scott Branden , linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Received: from cobalt1.eng.cobalt.local (ts3-dock1.isely.net [::ffff:192.168.23.13]) (AUTH: PLAIN isely, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by cnc.isely.net with ESMTPSA id 000000000008093D.00000000653FD80B.000079FF; Mon, 30 Oct 2023 11:21:31 -0500 From: mike.isely@cobaltdigital.com To: Andi Shyti , Florian Fainelli Cc: Mike Isely , Mike Isely , Broadcom internal kernel review list , Ray Jui , Scott Branden , linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] [i2c-bcm2835] Fully clean up hardware state machine after a timeout Date: Mon, 30 Oct 2023 11:21:13 -0500 Message-Id: <20231030162114.3603829-2-mike.isely@cobaltdigital.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231030162114.3603829-1-mike.isely@cobaltdigital.com> References: <20231030162114.3603829-1-mike.isely@cobaltdigital.com> Mime-Version: 1.0 X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231030_092640_563890_122F40EF X-CRM114-Status: GOOD ( 12.34 ) 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 From: Mike Isely When the driver detects a timeout, there's no guarantee that the ISR would have fired. Thus after a timeout, it's the foreground that becomes responsible to reset the hardware state machine. The change here just duplicates what is already implemented in the ISR. Signed-off-by: Mike Isely --- drivers/i2c/busses/i2c-bcm2835.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c index 8ce6d3f49551..96de875394e1 100644 --- a/drivers/i2c/busses/i2c-bcm2835.c +++ b/drivers/i2c/busses/i2c-bcm2835.c @@ -345,42 +345,46 @@ static irqreturn_t bcm2835_i2c_isr(int this_irq, void *data) static int bcm2835_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) { struct bcm2835_i2c_dev *i2c_dev = i2c_get_adapdata(adap); unsigned long time_left; int i; for (i = 0; i < (num - 1); i++) if (msgs[i].flags & I2C_M_RD) { dev_warn_once(i2c_dev->dev, "only one read message supported, has to be last\n"); return -EOPNOTSUPP; } i2c_dev->curr_msg = msgs; i2c_dev->num_msgs = num; reinit_completion(&i2c_dev->completion); bcm2835_i2c_start_transfer(i2c_dev); time_left = wait_for_completion_timeout(&i2c_dev->completion, adap->timeout); bcm2835_i2c_finish_transfer(i2c_dev); if (!time_left) { + /* Since we can't trust the ISR to have cleaned up, do the + * full cleanup here... */ bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_C, BCM2835_I2C_C_CLEAR); + bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_S, BCM2835_I2C_S_CLKT | + BCM2835_I2C_S_ERR | BCM2835_I2C_S_DONE); dev_err(i2c_dev->dev, "i2c transfer timed out\n"); return -ETIMEDOUT; } if (!i2c_dev->msg_err) return num; dev_dbg(i2c_dev->dev, "i2c transfer failed: %x\n", i2c_dev->msg_err); if (i2c_dev->msg_err & BCM2835_I2C_S_ERR) return -EREMOTEIO; return -EIO; }