From patchwork Tue Sep 29 22:19:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 285749 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83189C47427 for ; Tue, 29 Sep 2020 22:21:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 298F62075F for ; Tue, 29 Sep 2020 22:21:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mc/E4ToD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729556AbgI2WVd (ORCPT ); Tue, 29 Sep 2020 18:21:33 -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-Google-Smtp-Source: ABdhPJz6TIzFfZdHb10hjtWTGhgBVLghgdE2BqQEU4Cg40A8BNOY7Tvd/7Hw5JacVHa+CvjcQm4IDA== 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?b?TWljaGHFgiBNaXJvc8WCYXc=?= , 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 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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[],