From patchwork Wed May 23 09:56:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Esben Haabendal X-Patchwork-Id: 918925 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="uKUuSrd+"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40rScr3gWhz9s0y for ; Wed, 23 May 2018 19:58:04 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932317AbeEWJ4m (ORCPT ); Wed, 23 May 2018 05:56:42 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:38981 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932180AbeEWJ4f (ORCPT ); Wed, 23 May 2018 05:56:35 -0400 Received: by mail-wm0-f68.google.com with SMTP id f8-v6so7443237wmc.4; Wed, 23 May 2018 02:56:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=9FmV4vdjqqeW1PPYZnwpm8QzQHNpH4eDYP4EzpaP/FE=; b=uKUuSrd+Ffish92oXCQZkDKqE9d4z8m+TXwbYowDQtVJMqChtlZhoskxdl0c+sngNU yx9yRtdkgkSnK75Mi1OyAG1IxYDmiHGWXGj5M0ykOwQSe+pFcv10Moa5Od13dKt+UF+F HB+iw/HSUapK0v6Lng6fy6uDU9b2jC4soQcJKV+cIcVdP90a2ZsGI8Z67QXny34lPKYK BQ+Thsn68T27AKraVjU5ZER25VFhxmQ8S2A3cpfS0LWtt72EO0ieWJZTiCbQhYPrg+Rw 1ks6PC87opOJYt36sWhH530r0V/PclnQX8+hyaiPFYvPx+G1WCtgQScS2C7mFM9Xt2p3 CCZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=9FmV4vdjqqeW1PPYZnwpm8QzQHNpH4eDYP4EzpaP/FE=; b=tLrkHGY4kHZJw9Y4aVd0cODk3cqANYakaOdGxAEBfWmLVuk1VelAQpUttZ++BAUwib kEbJ0bAhOU+ALG01hkp7QrwKYciAhvhHHTqHaaxGoKmWSt4wSsfD3NAJEpxI+UJqEuqI qQgG93nT5bMUrHEQyMSZsAX1MIMQT4eY/IH1XrhNFDQElFRvEsVGbpHxTCiTdiJrx5zm 3sw5o7rHEXNkDKNjLu9AgJWvVvQcdHGURbJjks5EjaXwo2025vFF+1DNk+NJqjJ6MEO+ M5ePNwRiKwQaAw7RO+MP5H8FZ1FeWrRM1/vfni4/OoIdpHYrIleMIE7mN865SymGywd0 puDA== X-Gm-Message-State: ALKqPwcKKt5orWmwT28aMWODUJV3LeIxbNCFnduT8W+UE/Mr00hwiNpE AMazTqz6yXuAql43HnAZ5fkQhmhwmbY= X-Google-Smtp-Source: AB8JxZo+X6SqLzZFZNTXs19ABCP1z2TLAgFp/6vpDUoBPg6Jq1K2Pbd0Nzur6dECuz9QZqx4jescvw== X-Received: by 2002:a2e:9158:: with SMTP id q24-v6mr1312068ljg.73.1527069394248; Wed, 23 May 2018 02:56:34 -0700 (PDT) Received: from localhost ([87.54.42.112]) by smtp.gmail.com with ESMTPSA id n5-v6sm3373662ljh.84.2018.05.23.02.56.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 02:56:33 -0700 (PDT) From: Esben Haabendal To: linux-i2c@vger.kernel.org Cc: Esben Haabendal , Wolfram Sang , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lucas Stach , Philipp Zabel , Michail Georgios Etairidis , Wei Jinhua , Phil Reid , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] i2c: imx: Simplify stopped state tracking Date: Wed, 23 May 2018 11:56:22 +0200 Message-Id: <20180523095623.3347-4-esben.haabendal@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180523095623.3347-1-esben.haabendal@gmail.com> References: <20180523095623.3347-1-esben.haabendal@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Esben Haabendal Always update the stopped state when busy status have been checked. This is identical to what was done before, with the exception of error handling. Without this change, some errors cause the stopped state to be left in incorrect state in i2c_imx_stop(), i2c_imx_dma_read(), i2c_imx_read() and i2c_imx_xfer(). Signed-off-by: Esben Haabendal --- drivers/i2c/busses/i2c-imx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 742b548437af..f9c99b123188 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -430,10 +430,14 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy) return -EAGAIN; } - if (for_busy && (temp & I2SR_IBB)) + if (for_busy && (temp & I2SR_IBB)) { + i2c_imx->stopped = 0; break; - if (!for_busy && !(temp & I2SR_IBB)) + } + if (!for_busy && !(temp & I2SR_IBB)) { + i2c_imx->stopped = 1; break; + } if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) { dev_dbg(&i2c_imx->adapter.dev, "<%s> I2C bus is busy\n", __func__); @@ -547,7 +551,6 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx) result = i2c_imx_bus_busy(i2c_imx, 1); if (result) return result; - i2c_imx->stopped = 0; temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK; temp &= ~I2CR_DMAEN; @@ -578,7 +581,6 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx) if (!i2c_imx->stopped) { i2c_imx_bus_busy(i2c_imx, 0); - i2c_imx->stopped = 1; } /* Disable I2C controller */ @@ -733,7 +735,6 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx, temp &= ~(I2CR_MSTA | I2CR_MTX); imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); i2c_imx_bus_busy(i2c_imx, 0); - i2c_imx->stopped = 1; } else { /* * For i2c master receiver repeat restart operation like: @@ -861,7 +862,6 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bo temp &= ~(I2CR_MSTA | I2CR_MTX); imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); i2c_imx_bus_busy(i2c_imx, 0); - i2c_imx->stopped = 1; } else { /* * For i2c master receiver repeat restart operation like: