Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4308290pxv; Tue, 27 Jul 2021 04:18:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqgUfB2NMyi4kwgPXwYut/EP378QeQfB6ICCC1npwgLuk4i/cDbtPIjG58nyCZ8xqevft2 X-Received: by 2002:a92:dc8e:: with SMTP id c14mr16957873iln.91.1627384722022; Tue, 27 Jul 2021 04:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627384722; cv=none; d=google.com; s=arc-20160816; b=lWKayu7YSFZkY2G1afDXoRScesbqQd/Ce/fOyKFYgIRU1Znp36sjGBJ3diecg2GjIM twJc8G5TXOS8svmMfCpjK0aFW5Lr6ouaOzLRpULvDrYSWy2nIfrcVUNOXB5tuLNZz34b wju5sbG6myZsaj7e7YhEysIDjqBA869lGkF4uIYHV7vdUdQxt4rmCXVtYDZwnF9vY2fZ brk38Lv9HWPRcs4OPIbZ9oyWfV6i0/sWS0JvIQqhd1NLnV9oYSAlz3QsxmO7XcuIoHcD b4W6/iOmIkok9iYXoOAuKEi3ncrj/6remgsew20Iy7/+GPDKLJY6jAog+Btzh2swUz+L tGSw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:dkim-signature; bh=3QJdTNu+J2PBKcg2ij7xcNLqLbm2i7vMklvqy5uf4mQ=; b=WyzQF38JpvEVAyYLQuS+qDLBfki9DWs5yeuM9q5HEAPjiermFWMHsQr7yHwoVccSUt OKsre+Km801cybsQyq4NwNDDBElJjEVBuBotOqw78og18roDexWnPYu7w/zq55FLckJn ppe1OLO19JmAGMUnDJbTfVG2WdxIpUZ/GdXoEh0AycE8EJf3LYu1eTvnd6UEdLO7SWqU geJK1+tmICV/wcR123kSl1gUT/6crozxYno9jROB40BMR6qrIWamiC1VA/55boEJzrOJ LBipbdhtVObAeIsQebiTuJuqEPEtTRGoXS8CPldxlPPyFmCxmkV5fiU27qBnwbqSpG/L DsWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=Z+dsao88; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i3si2807038ilu.3.2021.07.27.04.18.30; Tue, 27 Jul 2021 04:18:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=Z+dsao88; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236460AbhG0LQN (ORCPT + 99 others); Tue, 27 Jul 2021 07:16:13 -0400 Received: from esa.microchip.iphmx.com ([68.232.154.123]:41871 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236318AbhG0LQM (ORCPT ); Tue, 27 Jul 2021 07:16:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1627384572; x=1658920572; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LmOuN2SVEtSgfrh3uY3qWbumcwZ7+Y6c5mA+/uQGPx4=; b=Z+dsao88OVp5CYDgMgmq7BiLVqlsD6kUqnQU4428ERKebM5xMqBkFrP3 RnmETo49Rmg/9adt3RHDYxtZApUTyWvMBI1hyEcQsHcMusHiOsYh1uhGZ +fL9T9rAndwas+tXEiSKj9DHHLFmYn13y+T1tVpT5AvM71V9qGkEVyZ0y zz2dkTYLfyDzVzA1gg875Xm40JletZb64jvUL7kMbNlaOvLnLWCFfg6la 3QZqFQJ9dUhSb2RSJn1j7UuVTBUQEC6evjzoNc8WRb8aVVUrGrSxmi52x G3uLZRDFnEb3WQF92E6uf1NPvlNqTecfB3cMdcEtRsrqvX/v7ODfRddsq w==; IronPort-SDR: okGvVLCzbmU3BhDmS3Fi/GveNvMwePKJVkXXSMG3FK9SkdeXKXitFXLuoXC6Yvixex2gyJwz6s /ltff842MnPKvs+BmhRxbpUCyKbnLj1xONtWnjtJ4o4hzH6wa40E8M55NEgT3IxsMI+UJgcn3c 6k7WqQswwY7zZOs1AKLt9OvucO9aRiGeUgaxjJF6XGGUPOrlrw1tQ8OVZY/yM0B1iKhzU89rj/ XgxnnNXX4SXG4l1KG0GTf8kxgxQgwAJ/Plh9rNfXeGmI1rkZaz/q3oAPSBjglr0OOOaVLkAevi I8C8YS7APRmWeIUqFUB5gKeK X-IronPort-AV: E=Sophos;i="5.84,273,1620716400"; d="scan'208";a="126088286" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 27 Jul 2021 04:16:12 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 27 Jul 2021 04:16:11 -0700 Received: from rob-ult-m19940.amer.actel.com (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Tue, 27 Jul 2021 04:16:08 -0700 From: Codrin Ciubotariu To: , , CC: , , , , , , , "Codrin Ciubotariu" Subject: [PATCH 1/3] i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer() Date: Tue, 27 Jul 2021 14:15:52 +0300 Message-ID: <20210727111554.1338832-2-codrin.ciubotariu@microchip.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210727111554.1338832-1-codrin.ciubotariu@microchip.com> References: <20210727111554.1338832-1-codrin.ciubotariu@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch doesn't add a functional change, it just separates the recovery from the transfer itself. Fixes: d3d3fdcc4c90 ("i2c: at91: implement i2c bus recovery") Signed-off-by: Codrin Ciubotariu --- 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 1cceb6866689..0352dc09d697 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; } @@ -705,7 +698,17 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num) ret = at91_do_twi_transfer(dev); - 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); -- 2.30.2