Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4127318pxk; Tue, 29 Sep 2020 15:23:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHDqWQt+DKw5rWJ/ogiwFtR+4bFSs3Mb/ttVICvsSM3vgnuxDpJV7T9NHSJISQYmZnNdOn X-Received: by 2002:a05:6402:1451:: with SMTP id d17mr5614425edx.48.1601418226581; Tue, 29 Sep 2020 15:23:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601418226; cv=none; d=google.com; s=arc-20160816; b=tRV1AdC8pw5yOul8qS18xHtG5nMCB+Gn/lVonDFwvw2SAMmd4pfq8LN1GDW4XNmaCG 7Ywv8q6O0dK7fLgzLpSqsgArN6jbTa0T0ZcwMNOUGAjRHGUCfuuBd42Y7MyuepElZeq+ hf3BqehGOdiay8YrYyR0RM4jf0mZ75kicI2BTPBFymZXnrX8J8gIMzwals7ruMyV+i0f jfUHci7/efk+UaO2ZZiRh3OjgmXs/0vetTDf8nHQAVGie+5/kN/GsE0LLQlLnnWKhC/m Ff9QBlL2k5q2gOe1rckQ0IdFT2SuzuTlKH05YrZy6b6T/rLwVwrQFPpSJhs7nTp+KEOF JkNw== 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 :dkim-signature; bh=IJPW2qjg5IMKXCGe896iaRoUfwQvNo7FkLK94cFe4zY=; b=N/x3u1TCMBUJWKdlJ8Hb2jEpCtLGNAIqF6LkqUkQYdIg0i1KS2OqLUksGp6gVgFk6Z YYa/5OcDaxucSQNXXnSDT+1ppn9Jh46xCuJCRhRCK28MyViQMY887bniRCNdR8UemWd+ d+1DA3Q5p6SSybDiAjOd9X/mjAuPUYIpPnmzjXMH2hNb9eZ7qgpxsJTFNPy6DOuRk5lI wwFA6dkGQVQz3zy6oz6HatXsbFpF80cwYtuS6N6IdwEw0Fcuf9LEQ26BExTsHUS0Gotq fkrBP7BnKxjsb3jFSd6HVa4gUkXVBk2Fl+Kuqkiik4v9dKm6Q+csznszOK4QSMnDbtTC C/1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Mc/E4ToD"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ec11si3583767ejb.540.2020.09.29.15.23.24; Tue, 29 Sep 2020 15:23:46 -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=pass header.i=@gmail.com header.s=20161025 header.b="Mc/E4ToD"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729645AbgI2WVq (ORCPT + 99 others); Tue, 29 Sep 2020 18:21:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729209AbgI2WU7 (ORCPT ); Tue, 29 Sep 2020 18:20:59 -0400 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A6E8C0613D2; Tue, 29 Sep 2020 15:20:59 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id y2so7394547lfy.10; Tue, 29 Sep 2020 15:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IJPW2qjg5IMKXCGe896iaRoUfwQvNo7FkLK94cFe4zY=; b=Mc/E4ToDkDEHiU5xetMyjkbQ4M0s+p7WwiDvmZ3d+8ppOCXTMntHy06mlMWceElZ2N TC3lVeLuJ/lusWbOthArnFX3FkTccLlP+g7PfpT1ByAwsphV/iBynEPchtOKra0taem3 7lxPdd+rSiNXEmOdGRahw3xLjdwAc8AFYejTmEvlRO2iA7KBD7sSMqgzOd+EF+PTzFeJ EDRRrToi8seFOunQ4yevdQ0+KSCJ2GKy2Tl2TLjA4OswHo8bdRrpvLctVYuw4uYUkVsg Ldd4Zd6p8iL9G9mPpW9L0MGeE9zLtyIgYOqLRlJSWJoLa+37PxeQcUO4w78cJ+v05Udg rhnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IJPW2qjg5IMKXCGe896iaRoUfwQvNo7FkLK94cFe4zY=; b=NsdmY8/6ljWAlVevkw2tlJEpr8UEB6W/VZKmYK9zuJ98gXJfuU77IT10bDOTOqkVK8 +hSbEqQGoEfA+9BsICfjZboVtyTHjlzK177yrkgtrqwviDD2npaGhEgGFBd5IejmRQWH gMH3EfWeLh44f87ZkuX0tYInQgCnd5b8LBP162eAhLXVPmzJd0Y21pA+WKhDY9ymUx3L IYreaQ6dAO1BlYa75YelWA6xL1tTRzA1/gv1+EPXirb4uvcVHd7iFdRmVvoiV5aXlMtk k561pGT2nmoogpIuL8V35o2evEbaGqKDNK9kO+qgqzqenzXHTEXgqKRN6To/wf6tK93z fedQ== X-Gm-Message-State: AOAM532nqXKP5onwZcRUxOPeiTPl1tQU4rlBYcRTzcUImkdwqk0bpoVI EzcLBPGny6RA2kB5AgAy7Mk= X-Received: by 2002:a19:7fcb:: with SMTP id a194mr1844910lfd.121.1601418057447; Tue, 29 Sep 2020 15:20:57 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id q18sm3379750lfr.138.2020.09.29.15.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2020 15:20:56 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 22/32] i2c: tegra: Factor out error recovery from tegra_i2c_xfer_msg() Date: Wed, 30 Sep 2020 01:19:05 +0300 Message-Id: <20200929221915.10979-23-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200929221915.10979-1-digetx@gmail.com> References: <20200929221915.10979-1-digetx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Factor out error recovery code from tegra_i2c_xfer_msg() in order to make this function easier to read and follow. Reviewed-by: Michał Mirosław Reviewed-by: Andy Shevchenko Acked-by: Thierry Reding Tested-by: Thierry Reding Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 46 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index f8bee67370aa..95d257cbd800 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1105,6 +1105,32 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) return -EAGAIN; } +static int tegra_i2c_error_recover(struct tegra_i2c_dev *i2c_dev, + struct i2c_msg *msg) +{ + if (i2c_dev->msg_err == I2C_ERR_NONE) + return 0; + + tegra_i2c_init(i2c_dev); + + /* start recovery upon arbitration loss in single master mode */ + if (i2c_dev->msg_err == I2C_ERR_ARBITRATION_LOST) { + if (!i2c_dev->is_multimaster_mode) + return i2c_recover_bus(&i2c_dev->adapter); + + return -EAGAIN; + } + + if (i2c_dev->msg_err == I2C_ERR_NO_ACK) { + if (msg->flags & I2C_M_IGNORE_NAK) + return 0; + + return -EREMOTEIO; + } + + return -EIO; +} + static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, struct i2c_msg *msg, enum msg_end_type end_state) @@ -1288,24 +1314,12 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->msg_err); i2c_dev->is_curr_dma_xfer = false; - if (i2c_dev->msg_err == I2C_ERR_NONE) - return 0; - tegra_i2c_init(i2c_dev); - /* start recovery upon arbitration loss in single master mode */ - if (i2c_dev->msg_err == I2C_ERR_ARBITRATION_LOST) { - if (!i2c_dev->is_multimaster_mode) - return i2c_recover_bus(&i2c_dev->adapter); - return -EAGAIN; - } - - if (i2c_dev->msg_err == I2C_ERR_NO_ACK) { - if (msg->flags & I2C_M_IGNORE_NAK) - return 0; - return -EREMOTEIO; - } + err = tegra_i2c_error_recover(i2c_dev, msg); + if (err) + return err; - return -EIO; + return 0; } static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], -- 2.27.0