Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2429201imm; Thu, 16 Aug 2018 09:28:20 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyapiLTB9SlysXl8h9e0BPWL9Qcm0UWGTQrb8npADAm5LkI2A/P0khTmbu3zpk/xpAVU2ng X-Received: by 2002:a17:902:4324:: with SMTP id i33-v6mr29561275pld.43.1534436899933; Thu, 16 Aug 2018 09:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534436899; cv=none; d=google.com; s=arc-20160816; b=BTTF8uL7pvB5129UCNqjxrr6Km2aK3Sc7t+KDiKCUxsmx77ri9eXbQa8+pblUBNwYd h5Wg7kJQsEh/NNJrd5y4Jkc7I/3VmgcQQbPf3Jfu9H1ulsNafMAfpbtSYL0lPOgqQmVF XsN4/4nVAHn9B3+SiW3hEV9EiYfzYZYW/xGW7PpG8YtbeJJ+w/WJeIjXX/eKct/Y6PEO lCMq9d437tWBFfGzVqdeeEZHWeJpNkzz+6rMPypcrdbSb8Xje/TQQDlI0IdIdBMIXYF2 ECSV+qE5HUCQDZ2eEW1UiSyTf+knPMApE6m6441Z5z4wZXvKMj1Xtse4O5tS5N99u3oQ AQKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=w4AeQDWslNHt0UI/9pnw6Q8K1DyjjLvo8oOGG+LiX3o=; b=etrjoEJJjRXtCYrW2khK4WE0bAeP6TTlUcnGSENE4vClwHJSsbpAYycgNDovQxeRzG ph6C1z7pl1VWGSqdgMDXbsO712g6h14zNJSCGGV21chLdtOz7ptwCwhxj4D103iulxJ3 MiQt2Nj4wYkASMoFHjlGnqAi8d7OvGf114w3wOZc66OxgQjJyWzZOn+x8hn1iiXqawh7 LXZBxoI1oK5gP1CFoZ48oJcl+DVCXqkC23vV8BHRpM3zdN+Nh+p8p/dDJxbseDL0V9RL 9wM4G2y6/ppAvZgz9EWqYWADPZyRX7ww7S2AN4bpBZVvIL0GF97SnXB9Q006AxvKbxsZ 3paA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=XUn22XEL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si22118030pls.385.2018.08.16.09.27.55; Thu, 16 Aug 2018 09:28:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=XUn22XEL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390117AbeHPLk2 (ORCPT + 99 others); Thu, 16 Aug 2018 07:40:28 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:39922 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731216AbeHPLk1 (ORCPT ); Thu, 16 Aug 2018 07:40:27 -0400 Received: by mail-lj1-f195.google.com with SMTP id l15-v6so3018674lji.6; Thu, 16 Aug 2018 01:43:27 -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 :mime-version:content-transfer-encoding; bh=w4AeQDWslNHt0UI/9pnw6Q8K1DyjjLvo8oOGG+LiX3o=; b=XUn22XEL5/N+56LYa1JntDtHbqrueUirtzwnrYErD2JlOaMqHuH46zkAVIM11FfO9y 5EjTDgZeo0yDdUjuCYaab7ZpnwXgpBVQnP9M+5e9+FO+BMCwvc64tmT31n8SWDuiciHg 4LpolBHppMD1Mt82N9kPHkOFL+EtgM38yslktomG2SGBfnhyOOxNIn3vyb2rxLyQxsw0 WoXz5/9dKLgd86WLWQVBnXa36Tl3a0/gIy74E3r6oyZBkZAwEhlBYMCEOwmStCnT73IU FaD2vRvNw5Fkq0qdnuuIg/PtJeyGs+1QKUGcjuuBB01OU/sYIlqmnGML20XXp5TyMz8O yucw== 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:mime-version:content-transfer-encoding; bh=w4AeQDWslNHt0UI/9pnw6Q8K1DyjjLvo8oOGG+LiX3o=; b=Wu8cCIFR47WAjuLBjFAFEpq+p7POEe0P9kU5tZyVIel8GF3IADbczPwRAknJUmxHfS QHIoHPQK5Ic/GwaqSgApb6IpShiPBE1V71TSTgzgeR93U67/4LnKmlw3luDu/w9eLVQq lgD2pOLOwuoIf5H/2fUJeuYfLEcvVXFPFI/gun1ItWe6QdCzJtzZ+BsCuQO5MAjwxlrX VSYeMOV4honHtagp8Dlzxj54rfHUZMzECijxbAl6fi61NP/UTWLJ7zDcpm16H2+qxdCM c+xSlzYuloBNNDnfPrurCcWKeY50+2XQVsNujvoZUPmLk1i1NDX807UB/cqv7gCPrTdA ZB1A== X-Gm-Message-State: AOUpUlGh3+wY1/ePdl147/iRdBSvkOH93556FQ+8DYoYVghfxkJ/MtkG aB1ERm+Zn28pJRdowS+IcCa32UyE X-Received: by 2002:a2e:4d9d:: with SMTP id c29-v6mr19701265ljd.132.1534409006669; Thu, 16 Aug 2018 01:43:26 -0700 (PDT) Received: from localhost ([87.54.42.112]) by smtp.gmail.com with ESMTPSA id d13-v6sm4847738lfi.74.2018.08.16.01.43.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 Aug 2018 01:43:26 -0700 (PDT) From: Esben Haabendal To: linux-i2c@vger.kernel.org Cc: Esben Haabendal , Wolfram Sang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Lucas Stach , Philipp Zabel , Linus Walleij , Phil Reid , Peter Rosin , Fabio Estevam , linux-kernel@vger.kernel.org Subject: [PATCH v4 2/3] i2c: imx: Simplify stopped state tracking Date: Thu, 16 Aug 2018 10:43:13 +0200 Message-Id: <20180816084315.7857-3-esben.haabendal@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180816084315.7857-1-esben.haabendal@gmail.com> References: <20180816084315.7857-1-esben.haabendal@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 Acked-by: Uwe Kleine-König --- drivers/i2c/busses/i2c-imx.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index ad6adefb64da..c406700789e1 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -421,10 +421,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__); @@ -538,7 +542,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; @@ -567,10 +570,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx) udelay(i2c_imx->disable_delay); } - if (!i2c_imx->stopped) { + if (!i2c_imx->stopped) i2c_imx_bus_busy(i2c_imx, 0); - i2c_imx->stopped = 1; - } /* Disable I2C controller */ temp = i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN, @@ -724,7 +725,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: @@ -850,7 +850,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: -- 2.18.0