From patchwork Tue Jun 14 10:13:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Codrin Ciubotariu X-Patchwork-Id: 581790 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80130C43334 for ; Tue, 14 Jun 2022 10:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243248AbiFNKOW (ORCPT ); Tue, 14 Jun 2022 06:14:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242905AbiFNKON (ORCPT ); Tue, 14 Jun 2022 06:14:13 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C98A4615B; Tue, 14 Jun 2022 03:14:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1655201651; x=1686737651; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pgiEnpbzfxx0xiXD6WVAkT4RHdqsHlan76yu59uc6B8=; b=BejxgrJ7HShSO5ow+qM2AnSmwEZcRjRdi0tw7VpngJgA/0kWPKknEjHb zcxN5E5vf2oWXrdYNQ1XI956DfNuT3nNYgLMAXBuQdsdhZM0jInsvYLVB TGlN8du97LHHSHDToBa5K4oLkgvhj3k+DLl/5rqCg7Yp8+R3uACBbNLj1 iC0sjwGPbOfkQzfoDf7RiW2lNUVDh4+UQY6X7nQL0un4GM6Hs+86k6i69 s4RNO9hPfdAUtwcZNX6CUkt1qPmQY5487Dt0/aVmuQIXLm4pWZAGhmIoS X5Snibc/i8h8MEZ5du8tReM3J7g2X11napL0dkACMGiybdm76HV9fJb2q g==; X-IronPort-AV: E=Sophos;i="5.91,299,1647327600"; d="scan'208";a="99927268" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 14 Jun 2022 03:14:10 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Tue, 14 Jun 2022 03:14:10 -0700 Received: from rob-ult-m19940.microchip.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Tue, 14 Jun 2022 03:14:07 -0700 From: Codrin Ciubotariu To: , , CC: , , , , , , , , Codrin Ciubotariu Subject: [RESEND 1/3] i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer() Date: Tue, 14 Jun 2022 13:13:45 +0300 Message-ID: <20220614101347.16910-2-codrin.ciubotariu@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220614101347.16910-1-codrin.ciubotariu@microchip.com> References: <20220614101347.16910-1-codrin.ciubotariu@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This patch doesn't add a functional change, it just separates the recovery from the transfer itself. Signed-off-by: Codrin Ciubotariu --- Removed 'Fixes' tag drivers/i2c/busses/i2c-at91-master.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c index c0c35785a0dc..34df1614bc37 100644 --- a/drivers/i2c/busses/i2c-at91-master.c +++ b/drivers/i2c/busses/i2c-at91-master.c @@ -639,13 +639,6 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev) AT91_TWI_THRCLR | AT91_TWI_LOCKCLR); } - /* - * some faulty I2C slave devices might hold SDA down; - * we can send a bus clear command, hoping that the pins will be - * released - */ - i2c_recover_bus(&dev->adapter); - return ret; } @@ -716,7 +709,17 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num) ret = at91_do_twi_transfer(dev); i2c_put_dma_safe_msg_buf(dma_buf, m_start, !ret); - ret = (ret < 0) ? ret : num; + if (ret < 0) { + /* + * some faulty I2C slave devices might hold SDA down; + * we can send a bus clear command, hoping that the pins will be + * released + */ + i2c_recover_bus(&dev->adapter); + } else { + ret = num; + } + out: pm_runtime_mark_last_busy(dev->dev); pm_runtime_put_autosuspend(dev->dev);