From patchwork Tue Sep 8 22:39:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360215 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=fZfZvEZj; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKw74Tt9z9sSJ for ; Wed, 9 Sep 2020 08:44:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730288AbgIHWoh (ORCPT ); Tue, 8 Sep 2020 18:44:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729529AbgIHWk0 (ORCPT ); Tue, 8 Sep 2020 18:40:26 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2D7EC061755; Tue, 8 Sep 2020 15:40:25 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id w3so977948ljo.5; Tue, 08 Sep 2020 15:40:25 -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=gfmOtG2LX9A+Kel844rjarke+NfElZZeKMZp8MuQx6I=; b=fZfZvEZj6u44b7Am/o2aIpGaKyuR49qUu5RTpwVop3Zxe5k5LaU0bZY7jyvMo1i3d8 etWEqKT/uTlBkX+DwGl24cj3ST4xe+K4llf3U7WhI2NlEYDzyRJQyGqkZOmR8fuH9pxs vk57RgfpxCd+QgoJC8tYt/7TBFNQ9B+R7lhg8whPDzNa/oBY3P0hnx0TO9AD6ALWMAHi o02G/EzLufCkliF7IuaCpgcPLaBVIV9W6ItObT4Dhpr5CHBI6+1WsmT6RMQRqkXNnsMt frVZTZptQVKTjCi83TEXYSAwqQ8j99eQ+KTEQI2AAE1DMtGJMGY3edcKWDDYVguDiwed /Apw== 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=gfmOtG2LX9A+Kel844rjarke+NfElZZeKMZp8MuQx6I=; b=V7Nk6e5WNyzklGp63IS1bCld1DyZKcsMHeXJf3cp+qaJezlMo+/3KPQujc2CSV39Po kNiMM8QW505G4QBd7PykVBAdxApmLU+KGQNcLuRgnlndRt8ZTFcAL7mJGAhpsYRsEtad yPVONu4lF3ATC5yxqRBuYy0HnnqC73nfUY/5EmSnTZZ1VpwZ9XbBBXHCa+kUamxABWnT W4eYA8uV00w3lNFDSJgx3d+1y65cUqwqool4BB+6P8XKEyX8uS6MKB8xVmoxZQnVHlsD B2neK42V2VYyQ2g+vCW6J2DgwCQwG2V2Bk34Jmul3DQ/BGBQAi+RJShkD/qCvzP4XRGW mHPw== X-Gm-Message-State: AOAM533QHKzJuU8MUVkaTK3IL/NVADlSqvW5/9T6ssOeNjCyUfUPxKTq pQ7ZpDmflgxb9KSPfuADQyA= X-Google-Smtp-Source: ABdhPJzSb2gPSUQiuFgN9L+zVFOsZdnWXBVVdz31UomLReL5JmxTqPGDgRqEnq5Cg/fafVl7yBSs8A== X-Received: by 2002:a2e:965a:: with SMTP id z26mr376908ljh.88.1599604824100; Tue, 08 Sep 2020 15:40:24 -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 s15sm268311ljp.25.2020.09.08.15.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:23 -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 v7 01/34] i2c: tegra: Make tegra_i2c_flush_fifos() usable in atomic transfer Date: Wed, 9 Sep 2020 01:39:33 +0300 Message-Id: <20200908224006.25636-2-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The tegra_i2c_flush_fifos() shouldn't sleep in atomic transfer and jiffies are not updating if interrupts are disabled. Let's switch to use iopoll API helpers for register-polling. The iopoll API provides helpers for both atomic and non-atomic cases. Note that this patch doesn't fix any known problem because normally FIFO is flushed at the time of starting a new transfer. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 00d3e4d7a01e..ab88cdd70376 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -470,9 +470,9 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) { - unsigned long timeout = jiffies + HZ; - unsigned int offset; - u32 mask, val; + u32 mask, val, offset, reg_offset; + void __iomem *addr; + int err; if (i2c_dev->hw->has_mst_fifo) { mask = I2C_MST_FIFO_CONTROL_TX_FLUSH | @@ -488,12 +488,19 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) val |= mask; i2c_writel(i2c_dev, val, offset); - while (i2c_readl(i2c_dev, offset) & mask) { - if (time_after(jiffies, timeout)) { - dev_warn(i2c_dev->dev, "timeout waiting for fifo flush\n"); - return -ETIMEDOUT; - } - usleep_range(1000, 2000); + reg_offset = tegra_i2c_reg_addr(i2c_dev, offset); + addr = i2c_dev->base + reg_offset; + + if (i2c_dev->is_curr_atomic_xfer) + err = readl_relaxed_poll_timeout_atomic(addr, val, !(val & mask), + 1000, 1000000); + else + err = readl_relaxed_poll_timeout(addr, val, !(val & mask), + 1000, 1000000); + + if (err) { + dev_err(i2c_dev->dev, "failed to flush FIFO\n"); + return err; } return 0; } From patchwork Tue Sep 8 22:39:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360206 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=rzdlwT25; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKvx5ttRz9sSJ for ; Wed, 9 Sep 2020 08:44:29 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729912AbgIHWko (ORCPT ); Tue, 8 Sep 2020 18:40:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729622AbgIHWk1 (ORCPT ); Tue, 8 Sep 2020 18:40:27 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82F79C061573; Tue, 8 Sep 2020 15:40:26 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id a22so928532ljp.13; Tue, 08 Sep 2020 15:40:26 -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=Lmosp0zHTCuESLy5/lSjNc1iMwH+IzUsdjaB+ieXAnU=; b=rzdlwT25l1DMsCJMzVnTYm9A0ddyNdzkSN5ZNDUuOWWGIMJG61qGef3/66njGxYkj7 7jvHPJb7iTRdJLPbxzbvMhM0GUhjZ2xJzbxYjizNHvBJOMVNsCLV5b7STwY6u1bo5hY7 TlBKaNUPnu5sjQvO/jjolI/WS7jsqYvsdGlg2RA5A3rw8ZmkKC8w717HnMIO08Hlxn4k mWG6OMoxyg9S79OLdUJr13X7zqcCCLQMvfatCcE4/kAoUpErQEbMJKAuRPME2snEfP8f d8q07B/mkSTD+mlw6aduUsaJeesTqtxTdgelSUU+rp5FWlvWRqK4bVp6qd5XIk/+blDL EQCg== 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=Lmosp0zHTCuESLy5/lSjNc1iMwH+IzUsdjaB+ieXAnU=; b=QcW7bdBeZbcZl/Vbz6G6N8U+dVKGAWrl6AJaEZ0n/lM6TU/JIkWjFAdsPDaoRXwTzH b6sDC+CtvMesDWVz/dA4xFPaZ0oCITRZtfPcA3YsdlBknSMzHeAC7ilahxLf5OwcmG6d ksDDwgPNZHO7KCI+RxXA1o1eHNJC3XCFbyO06A1XUYGQuZCfV+b87O4O1o1JKiH222vL uN0k3tyjnarGdKu8faV/PzXsP3tu6Z9vPCCl4fFGNVkS7vJoXtxq6tdBrn7hKJOgmaam 52WJg91HYdbD6/AoZkvMtchQhVzZ+C1e3rOmMrroeiNsiBFYt/nbYebzp94Fv0VTVj8v FrXw== X-Gm-Message-State: AOAM533nkYpF9I3UIgbPgFAnvtGipw2kCEBSaPBo1d6SVeT/H7FDzjaA rIdQ26cXZ05EqdyCPDuSZRQ= X-Google-Smtp-Source: ABdhPJz5nBCX3R0V/FlzmRC7J8XLN0h/WAwUFe3PE7jCQ4ZZ4cE+fuywkgJt+pgj3vU4BAx7CuSFYQ== X-Received: by 2002:a05:651c:107b:: with SMTP id y27mr326040ljm.338.1599604825025; Tue, 08 Sep 2020 15:40:25 -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 s15sm268311ljp.25.2020.09.08.15.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:24 -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 v7 02/34] i2c: tegra: Add missing pm_runtime_put() Date: Wed, 9 Sep 2020 01:39:34 +0300 Message-Id: <20200908224006.25636-3-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The pm_runtime_get_sync() always bumps refcount regardless of whether it succeeds or fails. Hence driver is responsible for restoring of the RPM refcounting. This patch adds missing RPM puts which restore refcounting in a case of pm_runtime_get_sync() error. Suggested-by: Andy Shevchenko Signed-off-by: Dmitry Osipenko Reviewed-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index ab88cdd70376..4e7d0eec0dd3 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1375,6 +1375,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], ret = pm_runtime_get_sync(i2c_dev->dev); if (ret < 0) { dev_err(i2c_dev->dev, "runtime resume failed %d\n", ret); + pm_runtime_put_noidle(i2c_dev->dev); return ret; } @@ -1786,7 +1787,7 @@ static int tegra_i2c_probe(struct platform_device *pdev) ret = pm_runtime_get_sync(i2c_dev->dev); if (ret < 0) { dev_err(&pdev->dev, "runtime resume failed\n"); - goto disable_rpm; + goto put_rpm; } } @@ -1851,7 +1852,6 @@ static int tegra_i2c_probe(struct platform_device *pdev) else tegra_i2c_runtime_suspend(&pdev->dev); -disable_rpm: if (pm_runtime_enabled(&pdev->dev)) pm_runtime_disable(&pdev->dev); From patchwork Tue Sep 8 22:39:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360156 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=DeyKLD//; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKqd2CGGz9sTK for ; Wed, 9 Sep 2020 08:40:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729824AbgIHWkk (ORCPT ); Tue, 8 Sep 2020 18:40:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729663AbgIHWk2 (ORCPT ); Tue, 8 Sep 2020 18:40:28 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A61E2C061755; Tue, 8 Sep 2020 15:40:27 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id u4so940800ljd.10; Tue, 08 Sep 2020 15:40:27 -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=8EoeQfm2V7iEFCAPBa5UMm2YWlodiF1UtVHJ3u58T+Y=; b=DeyKLD//BU8Ez6r28Edj0FvXCyEA1O2F6QmsnIh9wMrf9GW5Z+A4KjoD9OT4dB0WFh A3HOjyFw0mMTISgaEkj2vprkCycg1qRVBC49UG5CCeqrkA3DdmfmMOKo2OQKZOBb3OVg B/wv3D3b45vdadhCMkkh0D98Fkd80pN3BHiXqZwUmAmt47OG5blZdxCvAsIxrjA/PasB tJpXKH8UMlJjgVyxfkARgrMTDQiQfET3V8xZ5F/9cI3ucTcrtW+HpOS2/NUQ3CS78rJy b5IDMJ14obStxky4odGdJ/ORjj3XJUXjnftAGAuUEqVqfa/ItI2Mtn7pHp6WHBmmh6Ji +ogg== 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=8EoeQfm2V7iEFCAPBa5UMm2YWlodiF1UtVHJ3u58T+Y=; b=eeH3slvAFKEbwXAQtLCIscixr7Z5laHAoCZZj+jTkGWlbkBdl7AsgJgyRoooB0q1RD UXqWNazSKlnrTVcWKRZynmVLpmPTENNKz7kXKiE4xBk00GcOuVchDsxxx0QMP5FEtuyp DZ9NKf/e2kJNcAR3Cj/iALLwx9vabhK/YcIGQpprFNzD0iD9wMcuIZIrAcw+TliiCPWG pFJrQF7K/f5uWzctckbD9bpTlI9ink3luseJ3EwbU/o32G53V1XM+49niCTXu2VUg/P5 OiAUSr/DOJKPYmCsLvTsiskJnOraGjQhOSjF8h/2UAM74lRWOFDoOFE2a+ZFvsasL3sC YGrA== X-Gm-Message-State: AOAM533O+r79U93jlAbLnEBfZtXX4R+TJZn1Fx6hYfQcAkN8Fy6p/unU j/hplfl1WDydu3DmzXezD4A= X-Google-Smtp-Source: ABdhPJwyLqjNSu9T36XxAXOl2bf/3PFF9f3L+CE3KOj2/ieTPTS2ILq0cPpuFumJiSg9gvMgHiN0WA== X-Received: by 2002:a05:651c:134a:: with SMTP id j10mr352391ljb.337.1599604825884; Tue, 08 Sep 2020 15:40:25 -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 s15sm268311ljp.25.2020.09.08.15.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:25 -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 v7 03/34] i2c: tegra: Handle potential error of tegra_i2c_flush_fifos() Date: Wed, 9 Sep 2020 01:39:35 +0300 Message-Id: <20200908224006.25636-4-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Technically the tegra_i2c_flush_fifos() may fail and transfer should be aborted in this case, but this shouldn't ever happen in practice unless there is a bug somewhere in the driver. Let's add the error check just for completeness. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Reviewed-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 4e7d0eec0dd3..88d6e7bb14a2 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1177,7 +1177,9 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, bool dma; u16 xfer_time = 100; - tegra_i2c_flush_fifos(i2c_dev); + err = tegra_i2c_flush_fifos(i2c_dev); + if (err) + return err; i2c_dev->msg_buf = msg->buf; i2c_dev->msg_buf_remaining = msg->len; From patchwork Tue Sep 8 22:39:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360157 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=M4tYoOsT; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKqd4zt3z9sSJ for ; Wed, 9 Sep 2020 08:40:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729860AbgIHWko (ORCPT ); Tue, 8 Sep 2020 18:40:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725997AbgIHWk2 (ORCPT ); Tue, 8 Sep 2020 18:40:28 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CCA8C061756; Tue, 8 Sep 2020 15:40:28 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id y4so958854ljk.8; Tue, 08 Sep 2020 15:40:28 -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=j3XbNtVZD6rVkiU+YdggTYpRd5hx/FUuMpH7Z/8WhF0=; b=M4tYoOsTKHBpbjgmEGpja25ZjPU7TCMxUZA+6/I6qkhXuDU4p6WAXYfOp+Goee8ixd TcIDRFMwkT98jZ/R4bkjA0vXRE+sQOooStH9wppyTo7A8d8nBmlzE3lIxBmBB2/O+1hO a5NPi3F3ARzpAWftHCeUUKTDqXUPLMtE9SivwOUoRGNvTw+dTKvqhLTW+i1B8nD8xwn0 QLaTYI7kpwE4hqEChB5hj4bqwjZ5AVFaKToiso7nEBoMpeqy/ZGqz9CmDGxZFToQvEsQ Ha1qwYuiCEghqYXHThLoy7XWfnajR8Ti3mdllzc7lXebr1IVkRGhV123SZnHHn1QSz0C y1sA== 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=j3XbNtVZD6rVkiU+YdggTYpRd5hx/FUuMpH7Z/8WhF0=; b=lgKLkymPjuPRpgc1HGIx5AsgMPOHcU2yeoK33xcJOqlnKySSb5F7Jzbjb5hncc+7eJ iboZYGftGM45MkN1xIyNC94UgEMVjiqdqcHQ+wciYhFGiopup/qUQXQ0GwF2dIZjovQJ 0LD3219n93CFXmDDdmY2BhPbFOAjhIJpzUoETr80mGVWSWWQ50VUhIlfjEeOzT8DEil6 zqrLlWWki2A+h11eK6xu8yz1tjIiPIZokj7ojysMoUGiWq3o5+oeqXH1Br3pHXO1JfaB pKnlnkhAO8Vh+pBxtXYoKJJn1aRguwEuez6UPluuPlQup/zRC1sA9noqjNt2GLRqR3T5 YaQg== X-Gm-Message-State: AOAM5336Fni4/DiOrE9HXqoatOrugkTgPT76ZlvL9UQDhnlVtvj6UP4h NPY85QYhRLfAYEYRcok+1Bk= X-Google-Smtp-Source: ABdhPJxLflmSI+W+pxXtlsMfQYPSvuXhcUdX5YfRuY25Tah3QgO1pjWOxUhX1JAWoXGSLSWzySWEKQ== X-Received: by 2002:a2e:b4fc:: with SMTP id s28mr325583ljm.305.1599604826804; Tue, 08 Sep 2020 15:40:26 -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 s15sm268311ljp.25.2020.09.08.15.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:26 -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 v7 04/34] i2c: tegra: Mask interrupt in tegra_i2c_issue_bus_clear() Date: Wed, 9 Sep 2020 01:39:36 +0300 Message-Id: <20200908224006.25636-5-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The tegra_i2c_issue_bus_clear() may fail and in this case BUS_CLR_DONE stays unmasked. Hence let's mask it for consistency. This patch doesn't fix any known problems. Signed-off-by: Dmitry Osipenko Reviewed-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 88d6e7bb14a2..1d1ce266255a 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1149,6 +1149,8 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) time_left = tegra_i2c_wait_completion_timeout( i2c_dev, &i2c_dev->msg_complete, 50); + tegra_i2c_mask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); + if (time_left == 0) { dev_err(i2c_dev->dev, "timed out for bus clear\n"); return -ETIMEDOUT; From patchwork Tue Sep 8 22:39:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360154 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=YEkDRUQ4; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKqc3h5pz9sSJ for ; Wed, 9 Sep 2020 08:40:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729799AbgIHWkj (ORCPT ); Tue, 8 Sep 2020 18:40:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729691AbgIHWka (ORCPT ); Tue, 8 Sep 2020 18:40:30 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54927C061757; Tue, 8 Sep 2020 15:40:29 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id s205so968432lja.7; Tue, 08 Sep 2020 15:40:29 -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=gtWM+t6m46QP11MMan80ce8w5SnWZJRPt/gPtC0Z3c4=; b=YEkDRUQ4JBpKnBjLVUO/4HTt8RvgLTv1KPV2h7aJEuhuAR5V6HBzVsqOhA1uCLMNu9 IvGMPztxwGNbsTZczStbDnix5DlVnUUrzjyiH9Q95El7aVec9pPBP2hgkNgw5T2oTtA9 AH33DfvpVkPmz3F0Wt2pL9RZoJe86iwuxE4KD8ZrwCcfJZrn7NCO9JFAQVCpOFFnwzKQ 1kv+qt4UpcNIvNngkisSpB6MKrP8lEEzEXh40Gzog48ufW4x49D1evSMQRlZuIqXNLme SsvE/qUJTKqrJtBVgoQW7WRyKkxbMraEMOfngWyR0A3j5q6GhrywFc4WYRYnl8CuT08O me8w== 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=gtWM+t6m46QP11MMan80ce8w5SnWZJRPt/gPtC0Z3c4=; b=gSXSCUb0GqGVxl4/JWRvf/RVdVtsJGzHXe7WtcAaOcAxzexVElJWB7LVvn10c2FfBC 8fMUCVhE2G9ykElTzdpl67D+QIQusaaylbi+t9TEoI2tsLv4dSxDSEDUZbgZ5jRbqldL +RIYohRp7SWLHPuw0/8dZnMBQO9fgqyOxJvU4qr5dKArPdFZ4732IJ/Pf9kqAnNHPb6w UyaJUBGo8R3+XxQvqtsPyVpR1AfHnGuVBe2m5cqIlWIQxY8sYv/PkxIRwTY0hmZkTEl+ yIrX8MZ43ghbVwZHiRrTUUQod/ezpCyjN6sAG8rn0E1fa8X/T3yv1/6GpiBn5aMI8b5n VsIA== X-Gm-Message-State: AOAM530Hr/9ptVu5nVLTveU+TgQ9SpodJc1tnalaqTQpqB2yLTJFR/8N eheAa0O8JlY9gfWEsOni8Mw= X-Google-Smtp-Source: ABdhPJwGy/IHkk89ivWQC3u+ZfB8C/86/MWssg7G1TQMl+7AcfKVBWKFwUJ0Apth+TQqTcv5QI0cbw== X-Received: by 2002:a2e:9057:: with SMTP id n23mr358754ljg.411.1599604827709; Tue, 08 Sep 2020 15:40:27 -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 s15sm268311ljp.25.2020.09.08.15.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:27 -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 v7 05/34] i2c: tegra: Initialize div-clk rate unconditionally Date: Wed, 9 Sep 2020 01:39:37 +0300 Message-Id: <20200908224006.25636-6-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org It doesn't make sense to conditionalize the div-clk rate changes because rate is fixed and it won't ever change once it's set at the driver's probe time. All further changes are NO-OPs because CCF caches rate and skips rate-change if rate is unchanged. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 1d1ce266255a..720a75439e91 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -293,7 +293,7 @@ struct tegra_i2c_dev { bool is_curr_atomic_xfer; }; -static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit); +static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev); static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned long reg) @@ -691,7 +691,7 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) * domain ON. */ if (i2c_dev->is_vi) { - ret = tegra_i2c_init(i2c_dev, true); + ret = tegra_i2c_init(i2c_dev); if (ret) goto disable_div_clk; } @@ -778,7 +778,7 @@ static void tegra_i2c_vi_init(struct tegra_i2c_dev *i2c_dev) i2c_writel(i2c_dev, 0x0, I2C_TLOW_SEXT); } -static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit) +static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) { u32 val; int err; @@ -836,16 +836,14 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit) if (i2c_dev->hw->has_interface_timing_reg && tsu_thd) i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1); - if (!clk_reinit) { - clk_multiplier = (tlow + thigh + 2); - clk_multiplier *= (i2c_dev->clk_divisor_non_hs_mode + 1); - err = clk_set_rate(i2c_dev->div_clk, - i2c_dev->bus_clk_rate * clk_multiplier); - if (err) { - dev_err(i2c_dev->dev, - "failed changing clock rate: %d\n", err); - return err; - } + clk_multiplier = tlow + thigh + 2; + clk_multiplier *= i2c_dev->clk_divisor_non_hs_mode + 1; + + err = clk_set_rate(i2c_dev->div_clk, + i2c_dev->bus_clk_rate * clk_multiplier); + if (err) { + dev_err(i2c_dev->dev, "failed to set div-clk rate: %d\n", err); + return err; } if (!i2c_dev->is_dvc && !i2c_dev->is_vi) { @@ -1319,7 +1317,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (!time_left && !completion_done(&i2c_dev->dma_complete)) { dev_err(i2c_dev->dev, "DMA transfer timeout\n"); - tegra_i2c_init(i2c_dev, true); + tegra_i2c_init(i2c_dev); return -ETIMEDOUT; } @@ -1340,7 +1338,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (time_left == 0) { dev_err(i2c_dev->dev, "i2c transfer timed out\n"); - tegra_i2c_init(i2c_dev, true); + tegra_i2c_init(i2c_dev); return -ETIMEDOUT; } @@ -1352,7 +1350,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (likely(i2c_dev->msg_err == I2C_ERR_NONE)) return 0; - tegra_i2c_init(i2c_dev, true); + 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) @@ -1811,7 +1809,7 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (ret < 0) goto disable_div_clk; - ret = tegra_i2c_init(i2c_dev, false); + ret = tegra_i2c_init(i2c_dev); if (ret) { dev_err(&pdev->dev, "Failed to initialize i2c controller\n"); goto release_dma; @@ -1918,7 +1916,7 @@ static int __maybe_unused tegra_i2c_resume(struct device *dev) if (err) return err; - err = tegra_i2c_init(i2c_dev, false); + err = tegra_i2c_init(i2c_dev); if (err) return err; From patchwork Tue Sep 8 22:39:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=RVSwExZb; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKw71qfQz9sTK for ; Wed, 9 Sep 2020 08:44:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730268AbgIHWoh (ORCPT ); Tue, 8 Sep 2020 18:44:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729692AbgIHWkb (ORCPT ); Tue, 8 Sep 2020 18:40:31 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 563E6C0613ED; Tue, 8 Sep 2020 15:40:30 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id v23so1013193ljd.1; Tue, 08 Sep 2020 15:40:30 -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=z3/ictLAUjgwyR6p93PByXq4qxQ+4mmKUUiuuNtvitg=; b=RVSwExZb5g6VGMN9jgLaaogOEs+SCmeYNMrbZLzFudt2+fgEJqRTD7+wjFNAjq+GSX DwS/ekeO264iQikprxouo/pWuNzTHnkPbLYBdWpmTnN0Aa2BY7o+WcRQiFipn5Aw+DNX NDqM3mMND+Buiy12iflTp/qgNTITGaH/OZXYG6JLprr8VUJZriw2Uy58Lbn9yu1vVF6x VCKibYqgcHsRdzOVaB2M5uwYbIZHgPvR5c2wIOowrv+r8/nHvVJsFcnmjPTwUbcXRIfS UqypX13SBZEe0p4sXg+/SYGs2ta+aeK4YiyzXQEkGBwBzCPaFQ4C64wRic/Djg4RTiWI h0Mw== 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=z3/ictLAUjgwyR6p93PByXq4qxQ+4mmKUUiuuNtvitg=; b=INohu18XCPVa6Lg+kK7OxQtTgwoJaHrPiqpchcTSjUTDmtsY0frFw7FYydDtArEtMz OhLd25hgPAuWxefX5U0cWTFNThxEJf04oa/xC14lMuzi+aKH4bOUUAFd64goSLf0Srm9 doOYaiXsF20aUTse3BnwzktsRqPMkA4FaniGJ0wOQBmerLR+KohUfXJje1zzNR6rKo/A ILT/CGufnB0qVPVeh3ln/aiPoRlBD9Lqt4dqg5Hp9WCmSkSLP+IGJ5AMxIG99AkSvDyu XpqY6KCXW6kiHSM+lAXHD/EQNgerYPS9DgCuIKQy6QkvXHudARWpObP0q7SVBN8njdib zBTw== X-Gm-Message-State: AOAM531/i53HO3E6qROYENGX9mrHmn0bElYGZUCGyzHt0FIeAnVZEPku eL5KkWJ9ROns2/OdmCyJUhM= X-Google-Smtp-Source: ABdhPJyX1YoOUM7TmrF1Tt90nRobfOWrkp0B5ytydyQfSfvGOBsZbNwqU7376UDGCkx37u0RPRzFmA== X-Received: by 2002:a2e:7c09:: with SMTP id x9mr339432ljc.192.1599604828752; Tue, 08 Sep 2020 15:40:28 -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 s15sm268311ljp.25.2020.09.08.15.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:28 -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 v7 06/34] i2c: tegra: Remove i2c_dev.clk_divisor_non_hs_mode member Date: Wed, 9 Sep 2020 01:39:38 +0300 Message-Id: <20200908224006.25636-7-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The "non_hs_mode" divisor value is fixed, thus there is no need to have the variable i2c_dev.clk_divisor_non_hs_mode struct member. Let's remove it and move the mode selection into tegra_i2c_init() where it can be united with the timing selection. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding Reviewed-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 46 ++++++++++++++++------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 720a75439e91..85ed0e02d48c 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -250,7 +250,6 @@ struct tegra_i2c_hw_feature { * @msg_buf_remaining: size of unsent data in the message buffer * @msg_read: identifies read transfers * @bus_clk_rate: current I2C bus clock rate - * @clk_divisor_non_hs_mode: clock divider for non-high-speed modes * @is_multimaster_mode: track if I2C controller is in multi-master mode * @tx_dma_chan: DMA transmit channel * @rx_dma_chan: DMA receive channel @@ -281,7 +280,6 @@ struct tegra_i2c_dev { size_t msg_buf_remaining; int msg_read; u32 bus_clk_rate; - u16 clk_divisor_non_hs_mode; bool is_multimaster_mode; struct dma_chan *tx_dma_chan; struct dma_chan *rx_dma_chan; @@ -783,6 +781,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) u32 val; int err; u32 clk_divisor, clk_multiplier; + u32 non_hs_mode; u32 tsu_thd; u8 tlow, thigh; @@ -805,24 +804,33 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) if (i2c_dev->is_vi) tegra_i2c_vi_init(i2c_dev); - /* Make sure clock divisor programmed correctly */ - clk_divisor = FIELD_PREP(I2C_CLK_DIVISOR_HSMODE, - i2c_dev->hw->clk_divisor_hs_mode) | - FIELD_PREP(I2C_CLK_DIVISOR_STD_FAST_MODE, - i2c_dev->clk_divisor_non_hs_mode); - i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); - - if (i2c_dev->bus_clk_rate > I2C_MAX_STANDARD_MODE_FREQ && - i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_PLUS_FREQ) { + switch (i2c_dev->bus_clk_rate) { + case I2C_MAX_STANDARD_MODE_FREQ + 1 ... I2C_MAX_FAST_MODE_PLUS_FREQ: + default: tlow = i2c_dev->hw->tlow_fast_fastplus_mode; thigh = i2c_dev->hw->thigh_fast_fastplus_mode; tsu_thd = i2c_dev->hw->setup_hold_time_fast_fast_plus_mode; - } else { + + if (i2c_dev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ) + non_hs_mode = i2c_dev->hw->clk_divisor_fast_plus_mode; + else + non_hs_mode = i2c_dev->hw->clk_divisor_fast_mode; + break; + + case 0 ... I2C_MAX_STANDARD_MODE_FREQ: tlow = i2c_dev->hw->tlow_std_mode; thigh = i2c_dev->hw->thigh_std_mode; tsu_thd = i2c_dev->hw->setup_hold_time_std_mode; + non_hs_mode = i2c_dev->hw->clk_divisor_std_mode; + break; } + /* Make sure clock divisor programmed correctly */ + clk_divisor = FIELD_PREP(I2C_CLK_DIVISOR_HSMODE, + i2c_dev->hw->clk_divisor_hs_mode) | + FIELD_PREP(I2C_CLK_DIVISOR_STD_FAST_MODE, non_hs_mode); + i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); + if (i2c_dev->hw->has_interface_timing_reg) { val = FIELD_PREP(I2C_INTERFACE_TIMING_THIGH, thigh) | FIELD_PREP(I2C_INTERFACE_TIMING_TLOW, tlow); @@ -837,7 +845,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1); clk_multiplier = tlow + thigh + 2; - clk_multiplier *= i2c_dev->clk_divisor_non_hs_mode + 1; + clk_multiplier *= non_hs_mode + 1; err = clk_set_rate(i2c_dev->div_clk, i2c_dev->bus_clk_rate * clk_multiplier); @@ -1751,18 +1759,6 @@ static int tegra_i2c_probe(struct platform_device *pdev) goto unprepare_fast_clk; } - if (i2c_dev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ && - i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_PLUS_FREQ) - i2c_dev->clk_divisor_non_hs_mode = - i2c_dev->hw->clk_divisor_fast_plus_mode; - else if (i2c_dev->bus_clk_rate > I2C_MAX_STANDARD_MODE_FREQ && - i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_FREQ) - i2c_dev->clk_divisor_non_hs_mode = - i2c_dev->hw->clk_divisor_fast_mode; - else - i2c_dev->clk_divisor_non_hs_mode = - i2c_dev->hw->clk_divisor_std_mode; - ret = clk_prepare(i2c_dev->div_clk); if (ret < 0) { dev_err(i2c_dev->dev, "Clock prepare failed %d\n", ret); From patchwork Tue Sep 8 22:39:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360218 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=eMQPVJTF; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKwt2JYmz9sSJ for ; Wed, 9 Sep 2020 08:45:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730256AbgIHWog (ORCPT ); Tue, 8 Sep 2020 18:44:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729738AbgIHWkc (ORCPT ); Tue, 8 Sep 2020 18:40:32 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E70FC061786; Tue, 8 Sep 2020 15:40:31 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id y4so958990ljk.8; Tue, 08 Sep 2020 15:40:31 -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=vFGzjwGX1HKX5lyPoG6GisXiLAg0DIxIZ91bMI/VsTM=; b=eMQPVJTFqzzJJU+fR1Tg+FLsWgFN/WttSJ65sBIBxxA3wfUjHpw2LcCkM5bHLXNlNN bKiaq/r9BU2C+JZtfnqjUNthJ5ArsUMGQkDf0aX1GPJ9daIcMMG3BFj7a1YNk2S2yj2g UNrDfGtw63L5fTZcwlKflDzhF0Y79CHwksg7y1KeUC56crN5ynnK2xDCu8t9gdpcPQ4j Gz50RlHcm3DAZDEKkng1Xz65DkwC8QD7VD4htL/HO0MMNjD8ZQB5iRTS8CP5w8Ik78/M njU1vFOR4Y2DQlDxUS4gUgWUXGBIhcb7cVDxmCcCzqDZDDE591S9C1OFCJsX8KoivhRt wTUg== 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=vFGzjwGX1HKX5lyPoG6GisXiLAg0DIxIZ91bMI/VsTM=; b=csCphjvJetgadCfgTH6YbTCpTRQnM+JTnGF1ZsO6CmjHOZLP6xfgvMTN4FnGXYNmWT 5aWIdj8XnmUcA2RhHFRB05xKZmwSmY4Ec9FP+ptn2ATXt5NcgV86spa+PFCjRVLTwcG0 RlW5gWX8naMSuWVT1bQnra61onjHtYz5q8rkm3EoQp+U5czt2hXVX+Sy1nJif48po/PT TpAVL4LaWZACNxF9+5X3xeJTaZYFo261h7rz00iyATLo9p157Q9ETKyAIsalKe2uLSb1 BYTw98KwqpTd83C/Owv5WbcL9q6dInEdSxNPCR13L4E0cLl+yOOWQSopmas2nXLeBV7v WR5w== X-Gm-Message-State: AOAM533at+Ha/xOKip5wUbAIF7HqjP4bpwXOlU5SadrLj5c6k8tPJNjy sykAhSmPOAUX0yNijV6FSLg= X-Google-Smtp-Source: ABdhPJzeEztwjLNlGWUlc+lV5x86WPM0cYBqg0EEIBlUrmuwFbj7tx6coINFI/LyfMT6KlHYSXy1Yg== X-Received: by 2002:a2e:9d1:: with SMTP id 200mr314298ljj.349.1599604829725; Tue, 08 Sep 2020 15:40:29 -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 s15sm268311ljp.25.2020.09.08.15.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:29 -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 v7 07/34] i2c: tegra: Runtime PM always available on Tegra Date: Wed, 9 Sep 2020 01:39:39 +0300 Message-Id: <20200908224006.25636-8-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The runtime PM is guaranteed to be always available on Tegra after commit 40b2bb1b132a ("ARM: tegra: enforce PM requirement"). Hence let's remove all the RPM-availability checking and handling from the code. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Reviewed-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 85ed0e02d48c..a52c72135390 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1775,18 +1775,10 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (!i2c_dev->is_vi) pm_runtime_irq_safe(&pdev->dev); pm_runtime_enable(&pdev->dev); - if (!pm_runtime_enabled(&pdev->dev)) { - ret = tegra_i2c_runtime_resume(&pdev->dev); - if (ret < 0) { - dev_err(&pdev->dev, "runtime resume failed\n"); - goto unprepare_div_clk; - } - } else { - ret = pm_runtime_get_sync(i2c_dev->dev); - if (ret < 0) { - dev_err(&pdev->dev, "runtime resume failed\n"); - goto put_rpm; - } + ret = pm_runtime_get_sync(i2c_dev->dev); + if (ret < 0) { + dev_err(dev, "runtime resume failed\n"); + goto put_rpm; } if (i2c_dev->is_multimaster_mode) { @@ -1845,15 +1837,8 @@ static int tegra_i2c_probe(struct platform_device *pdev) clk_disable(i2c_dev->div_clk); put_rpm: - if (pm_runtime_enabled(&pdev->dev)) - pm_runtime_put_sync(&pdev->dev); - else - tegra_i2c_runtime_suspend(&pdev->dev); - - if (pm_runtime_enabled(&pdev->dev)) - pm_runtime_disable(&pdev->dev); - -unprepare_div_clk: + pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); clk_unprepare(i2c_dev->div_clk); unprepare_slow_clk: @@ -1875,8 +1860,6 @@ static int tegra_i2c_remove(struct platform_device *pdev) clk_disable(i2c_dev->div_clk); pm_runtime_disable(&pdev->dev); - if (!pm_runtime_status_suspended(&pdev->dev)) - tegra_i2c_runtime_suspend(&pdev->dev); clk_unprepare(i2c_dev->div_clk); clk_unprepare(i2c_dev->slow_clk); From patchwork Tue Sep 8 22:39:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360219 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=L18wV+wn; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKwv6GRHz9sSJ for ; Wed, 9 Sep 2020 08:45:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729305AbgIHWof (ORCPT ); Tue, 8 Sep 2020 18:44:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729741AbgIHWke (ORCPT ); Tue, 8 Sep 2020 18:40:34 -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 2F090C061795; Tue, 8 Sep 2020 15:40:32 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id y11so539038lfl.5; Tue, 08 Sep 2020 15:40:32 -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=4LurUv+YpHFsrZm3AgTKy4azZ/BxWvLTGRcrIRYEkzE=; b=L18wV+wnH0keseljrFVA8esoGN3whHrxEVuzpkw/Wuo8sWkUNtBUWJlYhQCx8Y7gIq tmv8pEx+s+e2l7KCgOcmwQeSQDOoaCauu20+Lb58KxGVAuB/o+NrQHiUlZkTL5AV3D7g HXpK7lxQnJ6MDq6h3AAvMSFcI0KGuivt29VWfe/t+9UYUxr7ZFMiskWY4lYWfYiDlmbx 6+qNPsgpt0T7CZnnKp3ROED3tLWL5qHuk4z9spl8mxqLnhH500cljdtgjMlkTCXc+E6n S38uF8yeZC2BdLgcDjK8nrzRMcn5HYhpyG4zzwbZCuBE3+6T2LaMOwfqlxRDXxvlPalK hLeQ== 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=4LurUv+YpHFsrZm3AgTKy4azZ/BxWvLTGRcrIRYEkzE=; b=jvmGz6MthzeXVM5AS6uSZKsDP9CjR3MEK0kbcGcQUrCl8Eqz6t4xcLl4dqurHTfJiF ekLIE8/PPM4Ym9VWxA/KlkYvO4qfQNj1pIxzWsZ5S+2yqrp2KtK7p6rzYHnpBI7CixeS z/PXCAhoEco1ocrvnJ4pfvcog4j9SQaUIjo0bjU5M0khcSuTqN67lzOtEPwTXHM4DO3y Zr+KjCQrUaxsbC2gIe3om1CKc1DcOsM8r6+nDAxM054+D0xYgFwMoV+BJdx42sKt4z12 Rr3IkFY/rIAqQdcUGji+IfhOTh9tUGNtI8FXWNHO60YlsW8bctkeOvAZJa3hPO50/qLv 5ozw== X-Gm-Message-State: AOAM532qUGDN+6e9kRZR4iWOpL6akMGQLQHM/6vYkJhul9pViDnj4J2z CCGRWLnEnZMM3LmwNhYTFOTcE+Yy2Ko= X-Google-Smtp-Source: ABdhPJwXgGv98Q8MCP/+yWmHEGVU4LL7IL3YE2N1rgnyO/lRJcDV7FKxzrhUhEfZn1Q7v96qfJLbfw== X-Received: by 2002:a19:4bd6:: with SMTP id y205mr541701lfa.182.1599604830685; Tue, 08 Sep 2020 15:40:30 -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 s15sm268311ljp.25.2020.09.08.15.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:30 -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 v7 08/34] i2c: tegra: Remove error message used for devm_request_irq() failure Date: Wed, 9 Sep 2020 01:39:40 +0300 Message-Id: <20200908224006.25636-9-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The error message prints number of vIRQ, which isn't a useful information. In practice devm_request_irq() never fails, hence let's remove the bogus message in order to make code cleaner. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding Reviewed-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index a52c72135390..b813c0976c10 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1807,10 +1807,8 @@ static int tegra_i2c_probe(struct platform_device *pdev) ret = devm_request_irq(&pdev->dev, i2c_dev->irq, tegra_i2c_isr, IRQF_NO_SUSPEND, dev_name(&pdev->dev), i2c_dev); - if (ret) { - dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq); + if (ret) goto release_dma; - } i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); i2c_dev->adapter.owner = THIS_MODULE; From patchwork Tue Sep 8 22:39:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360210 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=k0FXwgXU; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKw50gwlz9sT6 for ; Wed, 9 Sep 2020 08:44:37 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730252AbgIHWof (ORCPT ); Tue, 8 Sep 2020 18:44:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729753AbgIHWkd (ORCPT ); Tue, 8 Sep 2020 18:40:33 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14F00C061796; Tue, 8 Sep 2020 15:40:33 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id d15so518968lfq.11; Tue, 08 Sep 2020 15:40:32 -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=9wL/ufnc3lNtiNLFNRaxPcM6Cg+5dtTmA95pTCa3ATE=; b=k0FXwgXU4mcLT2A1bI1T5cGF4NpYgRsLXvTsSxLorCYWjIvUzbrx1kOANwqigl2kJO LMlx2XKGehgjtV8npzI9eIRDkoR4wtKFX/fJpElnqc6r2sExJ7sQEgsrrXUq1FuN6p7x y/P/wCQ9MQuT+iykAIr4SLMHNbfpfpI/cA9/z6gEwhHbb9nOXCy6Lg9dlGawONsjenC/ CuR594I6HyXGla4cbNnA0ZFzI1EmG9gxHEl8U+j3SRIj9JuySePM5z8SiRqcQXTRyXWa MAnWKBSBFnyQsMXeTUvrst9hHnjUWt/pRf6moV9IMRu7JsLgiFZ9ykpFu0DE05xklISp 6mFw== 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=9wL/ufnc3lNtiNLFNRaxPcM6Cg+5dtTmA95pTCa3ATE=; b=PPrRrx4fnf3AMMJZWf8W+zAnUERiDG9M1deUtp0qPh/rO7B3cTy/VMY2rvHX9ZqRne 75Re6DUq5Ynq0sDwtjCxEJY/TJU86IREJn3oB25izpsEvkcY7Yn/o6a4YN0rNDaqfaTy 6KQ7V2Ntd3/w/52KqaOQxaHpntrSkvV1pJdCUZhZlMeIUetofI6lIX2w6nUkVh3e+bKE sbhIreuZzNWxSjJc3n2f4ERowE+Y93UK22sdD3JJI7NO93d4S7NCdI/md8rY8XTtBiuM 95iDMhI0DLPwAKEu4DVQ4p7d1GC9f8lW+sSXdyAkCVydWRzQK8iMupbVEsqRs0dkud3k DH9A== X-Gm-Message-State: AOAM532MO8/rHWGO8MPVf4knVwl2wH++4c4WrVn/hgJl2zR4zOORR9d6 UyNvrNY9uOGjqUcIyS2n0uI= X-Google-Smtp-Source: ABdhPJy51+CIlV3Kafu6FPuvjssxWd9ZnLRfgcIdHX58Me6ywjavsG+4DHx4qhjtT8wZLRHdoyT+6Q== X-Received: by 2002:a19:587:: with SMTP id 129mr541797lff.200.1599604831525; Tue, 08 Sep 2020 15:40:31 -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 s15sm268311ljp.25.2020.09.08.15.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:31 -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 v7 09/34] i2c: tegra: Use reset_control_reset() Date: Wed, 9 Sep 2020 01:39:41 +0300 Message-Id: <20200908224006.25636-10-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Use a single reset_control_reset() instead of assert/deasset couple in order to make code cleaner a tad. Note that the reset_control_reset() uses 1 microsecond delay instead of 2 that was used previously, but this shouldn't matter because one microsecond is a default reset time for most of Tegra peripherals and TRM doesn't mention anything special in regards to I2C controller's reset propagation time. In addition don't ignore potential error of the reset control by emitting a noisy warning if it fails, which will indicate an existence of a severe problem, while still allow machine to boot up. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index b813c0976c10..90ba2f5327c5 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -785,9 +785,16 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) u32 tsu_thd; u8 tlow, thigh; - reset_control_assert(i2c_dev->rst); - udelay(2); - reset_control_deassert(i2c_dev->rst); + /* + * The reset shouldn't ever fail in practice. The failure will be a + * sign of a severe problem that needs to be resolved. Still we don't + * want to fail the initialization completely because this may break + * kernel boot up since voltage regulators use I2C. Hence, we will + * emit a noisy warning on error, which won't stay unnoticed and + * won't hose machine entirely. + */ + err = reset_control_reset(i2c_dev->rst); + WARN_ON_ONCE(err); if (i2c_dev->is_dvc) tegra_dvc_init(i2c_dev); From patchwork Tue Sep 8 22:39:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360208 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=M0GKSFGX; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKw34RKcz9sSJ for ; Wed, 9 Sep 2020 08:44:35 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730177AbgIHWod (ORCPT ); Tue, 8 Sep 2020 18:44:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729785AbgIHWkf (ORCPT ); Tue, 8 Sep 2020 18:40:35 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3DB3C061573; Tue, 8 Sep 2020 15:40:33 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id s205so968665lja.7; Tue, 08 Sep 2020 15:40:33 -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=HtsscUVX9USqMNRXBDByuYOqMY2muh1bB3NfySu7tl8=; b=M0GKSFGXs1N0/dC1oIfvbKkX7t8uMGVsRdeutQ4M7SP41Z4SRUAc9/hF2dh00e9V9C S4g44yWY+ReBonSunG1jUTLzdU+YbRq9L3KtI0EeZIFahKtbTWIp6LPZShM8YPHLDPm0 D93Gr7Le7vRopTtOMgqqWkZDGBX/uy16FC7h6uMY7KE5ecy5yPIg2dETblXTMqQnqYcm kjhK4B4KmPTYOnIHoJ0sMNoNjNGGBjXDP5EPnIplo9gQAhTUMnxBYGhu10ONf92QdSsS fTpOzvOIo7EUGaXpPYTczO8SNGPQXwLiJA9yYpBAC6xHpuQ8u7rQtU2+cSgPmCOT4SL4 xd4w== 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=HtsscUVX9USqMNRXBDByuYOqMY2muh1bB3NfySu7tl8=; b=DW+xLWfPA9czdB9eI2jRLj2jkrYcqpJpBGVWzBkCbyC7IziVYCjxKgZ1YeUujw+HMm 8OXX21KoKksZ5g6KZUdtAtwZC+HmuMavQO0zHMOpD+fUv7rGGDm+GXJB9ypkAFKOY/5P eCWQFF+p9Atps3eL173JpGGoePV9xEBEWous5toiAkbOHbHGPkOnnNUOg295VlIbk6wv hCXgGu65gwU1tF6W7q28XUTK4d6TvS4BGlhbC8sy9jx4UtdRYgWvP+1HTZordSiE8Jrw Q5oTZ7AAKZATkFKaJiZLxhrhvKRBbjvIROq/765qilC47XyvuCsZnusjrF22PMJYl4GA CgLg== X-Gm-Message-State: AOAM531nIodBwTLyKcO+F2QvLchgwuslJFEBScAUyq6yK1TQewjiXRpP IVeJsWIpotsOON01G0m4bDt4Q2ac8pQ= X-Google-Smtp-Source: ABdhPJwya7t5UTyvAQulCZgcQ6S7CGRWZjbUd8+UKTbrAApSVAdNtsnFvYDbJ2lAPBfVvgPWXmTujg== X-Received: by 2002:a2e:8159:: with SMTP id t25mr348939ljg.137.1599604832426; Tue, 08 Sep 2020 15:40:32 -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 s15sm268311ljp.25.2020.09.08.15.40.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:32 -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 v7 10/34] i2c: tegra: Use devm_platform_get_and_ioremap_resource() Date: Wed, 9 Sep 2020 01:39:42 +0300 Message-Id: <20200908224006.25636-11-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Driver now uses devm_platform_get_and_ioremap_resource() which replaces the typical boilerplate code and makes code cleaner. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 90ba2f5327c5..c2bbdf92b11f 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1678,12 +1678,12 @@ static int tegra_i2c_probe(struct platform_device *pdev) int irq; int ret; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - base_phys = res->start; - base = devm_ioremap_resource(&pdev->dev, res); + base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(base)) return PTR_ERR(base); + base_phys = res->start; + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (!res) { dev_err(&pdev->dev, "no irq resource\n"); From patchwork Tue Sep 8 22:39:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360220 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=q49T129r; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKww389kz9sTK for ; Wed, 9 Sep 2020 08:45:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729663AbgIHWoa (ORCPT ); Tue, 8 Sep 2020 18:44:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729789AbgIHWkf (ORCPT ); Tue, 8 Sep 2020 18:40:35 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4565C061755; Tue, 8 Sep 2020 15:40:34 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id z19so539370lfr.4; Tue, 08 Sep 2020 15:40:34 -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=hUUPRBULDiyvblMhx4V1F89haxR9rFzQ0ynZsEU3uxo=; b=q49T129r199DY86luMHEEwZ9WtFc3zQtkHwjuP6f9NlMeFtqaaUcMVaCn4BWdIOOUq +8+FJj7DNngx83sxHkfXuPrtkdg+2z197Moi4Tltxq25j+cFQMOQF3Fspgeo1ZbMuOMw x7Lcp20TOkzKNPOrnIjmoI104ybs3Xt2PnK4XBs6/6E9Da/uppoozgyh4jlD4VPvvlAx cQbuAYmqvQalv3hZ5S8Oc4oQsX0dfXUueHOkDhU+GfF2TfR+JTInu4yT7jgQtHncNs+m nJ44njw89Vs0srK71N6lvp8SPkxPrheoTG0c0bB+/nWfl2wMdHg1wA3qwGqkkq/g5uSY j7Fw== 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=hUUPRBULDiyvblMhx4V1F89haxR9rFzQ0ynZsEU3uxo=; b=mLMgqrs81p4kY8BScscPsxZ//urZofKmdgybd9knzj7b3OP4A8luzVx4bs2UMBn0BJ IChSaZwXZcNjKrienNPEai/u3jsIKJcm+0hwE/g2omLJVHkWiTbf6Pcbvh4F5IrtZWsS nNHSGTlgoJk4fIMQAOPkkqUt6M3Qku9fl8OyjM4yW/8IuoUV9hVDjqPaaOgSdYm4f4PD kMLnhyE3a3yffId30HiM7OmNHVWk+kSP8EE00wWHL4gzHnT1DkJ9vm2JLREeuGkQo/tK vIJP8KbqZvbJ3T3FXJtOi3iO/28DWRmfcH95XRjKtfjzXyUOqX49wfoB+/2dye3Mfecd Uc1w== X-Gm-Message-State: AOAM532KcsYRIIJYoQW9pL4apkAdpoV7jgVceS+CDxZETIA+za5a/6f2 fs/+5Eh6DhSWlC6MOrC12rA= X-Google-Smtp-Source: ABdhPJz36wiwn0eDZa3Bo/dxiocNuoVT7nH0pYUDdmf/IKYoSD8ReB5v8KaOc9emkFVtqsvvr0X8lg== X-Received: by 2002:a05:6512:70f:: with SMTP id b15mr537966lfs.39.1599604833326; Tue, 08 Sep 2020 15:40:33 -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 s15sm268311ljp.25.2020.09.08.15.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:32 -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 v7 11/34] i2c: tegra: Use platform_get_irq() Date: Wed, 9 Sep 2020 01:39:43 +0300 Message-Id: <20200908224006.25636-12-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Use common helper for retrieval of the interrupt number in order to make code cleaner. Note that platform_get_irq() prints error message by itself. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index c2bbdf92b11f..505b5d37077d 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1684,12 +1684,9 @@ static int tegra_i2c_probe(struct platform_device *pdev) base_phys = res->start; - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (!res) { - dev_err(&pdev->dev, "no irq resource\n"); - return -EINVAL; - } - irq = res->start; + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; div_clk = devm_clk_get(&pdev->dev, "div-clk"); if (IS_ERR(div_clk)) { From patchwork Tue Sep 8 22:39:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360165 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=sOamcot0; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKrM4Tqzz9sSJ for ; Wed, 9 Sep 2020 08:41:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729014AbgIHWlV (ORCPT ); Tue, 8 Sep 2020 18:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730104AbgIHWlI (ORCPT ); Tue, 8 Sep 2020 18:41:08 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DAC2C061798; Tue, 8 Sep 2020 15:40:55 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id d15so519284lfq.11; Tue, 08 Sep 2020 15:40:55 -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=RlXXo/oXcGZ19zHatOgRwbpyu+kfoGQBR492tWarJmw=; b=sOamcot0eBCHts1nNB14SOxQfd/XFNcdlPczW5tbcsl0+/vNCzSVz+6d8Xy0Oigsn5 TwmZorPti2dvsH/0g70Eg6/ohjvHHgal1dQs/yb56l/jsXTmRl1HBIAJ/m5GMUqoYi+7 WAQoZx2DTz2yN7biD5XSetAsYgAVCjVJzHyKs9O2x8ek6qCZOr0hOUAHSu1v8lH7HDIX f0EzTv1QBTejWUHrU8bX4ATd75ba+60kZETxOy5C6aMQZFRg5tXQ9b+qD8bfxm0hUPN+ V6x1xjYzEgCxfU9HVAGsvCPKV2jGXvqZzuXIGfhsYs9BX4WpaMxmFpHHEp20TGszSGbR Zh7w== 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=RlXXo/oXcGZ19zHatOgRwbpyu+kfoGQBR492tWarJmw=; b=p6/Dk37Th+d7xs32b7rSkJ088JpvcTBNvs9lXmdfOW6IH6unLmlRFoEPBz1ArPD80p DhDHQ7D2dljiCTygm876l7qvZPHM+7tMOVwP2Pn6nnNNnqpoWUanRwWaCZhGSGWdfmN8 XY5AdS+rhm6ITI0Y0uQpiJNubq2oBjm7Gi3kA5utI+Ph6PnTsbjz9YpxHq0JTMnxMS5l k2qybvJl9Jwn6sk9FdEF47L9SDloMgZFNlHLUbTpNmGFM1mJYgaU3HrrBeTGjGVhnXhH PmMe/jaH7OMjGTo4jUwtwVHmzc71mcH/UuhkIamzJeHVUk6vx4MtaQRA1+rcLp29ipo9 AHRg== X-Gm-Message-State: AOAM530H7JVap3FiwGZSl53qh1cUiOJlFVqYvbXVSf/EOuQ185/QgXWb fmSXhHM4g1xffITHq8g3ZSk= X-Google-Smtp-Source: ABdhPJxebPVH3BkpNA0CU/AFwxQTgLMgNImYTd/0vEtx2WrlGOpD8i5v7FkeU4XjXWLB0tcyEH4F9A== X-Received: by 2002:a19:4e:: with SMTP id 75mr523326lfa.159.1599604838598; Tue, 08 Sep 2020 15:40:38 -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 s15sm268311ljp.25.2020.09.08.15.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:33 -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 v7 12/34] i2c: tegra: Use clk-bulk helpers Date: Wed, 9 Sep 2020 01:39:44 +0300 Message-Id: <20200908224006.25636-13-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Use clk-bulk helpers and factor out clocks initialization into separate function in order to make code cleaner. The clocks initialization now performed after reset-control initialization in order to avoid a noisy -PROBE_DEFER errors on T186+ from the clk-bulk helper which doesn't silence this error code. Hence reset_control_get() now may return -EPROBE_DEFER on newer Tegra SoCs because they use BPMP driver that provides reset controls and BPMP doesn't come up early during boot. Previously rst was protected by the clocks retrieval and now this patch makes dev_err_probe() to be used for the rst error handling. Suggested-by: Andy Shevchenko Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 187 ++++++++++++--------------------- 1 file changed, 67 insertions(+), 120 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 505b5d37077d..c6a29a8069d9 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -165,9 +165,6 @@ enum msg_end_type { * @has_continue_xfer_support: Continue transfer supports. * @has_per_pkt_xfer_complete_irq: Has enable/disable capability for transfer * complete interrupt per packet basis. - * @has_single_clk_source: The I2C controller has single clock source. Tegra30 - * and earlier SoCs have two clock sources i.e. div-clk and - * fast-clk. * @has_config_load_reg: Has the config load register to load the new * configuration. * @clk_divisor_hs_mode: Clock divisor in HS mode. @@ -208,7 +205,6 @@ enum msg_end_type { struct tegra_i2c_hw_feature { bool has_continue_xfer_support; bool has_per_pkt_xfer_complete_irq; - bool has_single_clk_source; bool has_config_load_reg; int clk_divisor_hs_mode; int clk_divisor_std_mode; @@ -236,7 +232,8 @@ struct tegra_i2c_hw_feature { * @hw: Tegra I2C HW feature * @adapter: core I2C layer adapter information * @div_clk: clock reference for div clock of I2C controller - * @fast_clk: clock reference for fast clock of I2C controller + * @clocks: array of I2C controller clocks + * @nclocks: number of clocks in the array * @rst: reset control for the I2C controller * @base: ioremapped registers cookie * @base_phys: physical base address of the I2C controller @@ -265,8 +262,8 @@ struct tegra_i2c_dev { const struct tegra_i2c_hw_feature *hw; struct i2c_adapter adapter; struct clk *div_clk; - struct clk *fast_clk; - struct clk *slow_clk; + struct clk_bulk_data *clocks; + unsigned int nclocks; struct reset_control *rst; void __iomem *base; phys_addr_t base_phys; @@ -662,25 +659,9 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) if (ret) return ret; - ret = clk_enable(i2c_dev->fast_clk); - if (ret < 0) { - dev_err(i2c_dev->dev, - "Enabling fast clk failed, err %d\n", ret); + ret = clk_bulk_enable(i2c_dev->nclocks, i2c_dev->clocks); + if (ret) return ret; - } - - ret = clk_enable(i2c_dev->slow_clk); - if (ret < 0) { - dev_err(dev, "failed to enable slow clock: %d\n", ret); - goto disable_fast_clk; - } - - ret = clk_enable(i2c_dev->div_clk); - if (ret < 0) { - dev_err(i2c_dev->dev, - "Enabling div clk failed, err %d\n", ret); - goto disable_slow_clk; - } /* * VI I2C device is attached to VE power domain which goes through @@ -691,17 +672,14 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) if (i2c_dev->is_vi) { ret = tegra_i2c_init(i2c_dev); if (ret) - goto disable_div_clk; + goto disable_clocks; } return 0; -disable_div_clk: - clk_disable(i2c_dev->div_clk); -disable_slow_clk: - clk_disable(i2c_dev->slow_clk); -disable_fast_clk: - clk_disable(i2c_dev->fast_clk); +disable_clocks: + clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); + return ret; } @@ -709,9 +687,7 @@ static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev) { struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); - clk_disable(i2c_dev->div_clk); - clk_disable(i2c_dev->slow_clk); - clk_disable(i2c_dev->fast_clk); + clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); return pinctrl_pm_select_idle_state(i2c_dev->dev); } @@ -1479,7 +1455,6 @@ static struct i2c_bus_recovery_info tegra_i2c_recovery_info = { static const struct tegra_i2c_hw_feature tegra20_i2c_hw = { .has_continue_xfer_support = false, .has_per_pkt_xfer_complete_irq = false, - .has_single_clk_source = false, .clk_divisor_hs_mode = 3, .clk_divisor_std_mode = 0, .clk_divisor_fast_mode = 0, @@ -1504,7 +1479,6 @@ static const struct tegra_i2c_hw_feature tegra20_i2c_hw = { static const struct tegra_i2c_hw_feature tegra30_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = false, - .has_single_clk_source = false, .clk_divisor_hs_mode = 3, .clk_divisor_std_mode = 0, .clk_divisor_fast_mode = 0, @@ -1529,7 +1503,6 @@ static const struct tegra_i2c_hw_feature tegra30_i2c_hw = { static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = true, - .has_single_clk_source = true, .clk_divisor_hs_mode = 1, .clk_divisor_std_mode = 0x19, .clk_divisor_fast_mode = 0x19, @@ -1554,7 +1527,6 @@ static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { static const struct tegra_i2c_hw_feature tegra124_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = true, - .has_single_clk_source = true, .clk_divisor_hs_mode = 1, .clk_divisor_std_mode = 0x19, .clk_divisor_fast_mode = 0x19, @@ -1579,7 +1551,6 @@ static const struct tegra_i2c_hw_feature tegra124_i2c_hw = { static const struct tegra_i2c_hw_feature tegra210_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = true, - .has_single_clk_source = true, .clk_divisor_hs_mode = 1, .clk_divisor_std_mode = 0x19, .clk_divisor_fast_mode = 0x19, @@ -1604,7 +1575,6 @@ static const struct tegra_i2c_hw_feature tegra210_i2c_hw = { static const struct tegra_i2c_hw_feature tegra186_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = true, - .has_single_clk_source = true, .clk_divisor_hs_mode = 1, .clk_divisor_std_mode = 0x16, .clk_divisor_fast_mode = 0x19, @@ -1629,7 +1599,6 @@ static const struct tegra_i2c_hw_feature tegra186_i2c_hw = { static const struct tegra_i2c_hw_feature tegra194_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = true, - .has_single_clk_source = true, .clk_divisor_hs_mode = 1, .clk_divisor_std_mode = 0x4f, .clk_divisor_fast_mode = 0x3c, @@ -1666,13 +1635,58 @@ static const struct of_device_id tegra_i2c_of_match[] = { }; MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); +static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev) +{ + unsigned int i; + int err; + + err = devm_clk_bulk_get_all(i2c_dev->dev, &i2c_dev->clocks); + if (err < 0) + return err; + + i2c_dev->nclocks = err; + + err = clk_bulk_prepare(i2c_dev->nclocks, i2c_dev->clocks); + if (err) + return err; + + for (i = 0; i < i2c_dev->nclocks; i++) { + if (!strcmp(i2c_dev->clocks[i].id, "div-clk")) { + i2c_dev->div_clk = i2c_dev->clocks[i].clk; + break; + } + } + + if (!i2c_dev->is_multimaster_mode) + return 0; + + err = clk_enable(i2c_dev->div_clk); + if (err) { + dev_err(i2c_dev->dev, "failed to enable div-clk: %d\n", err); + goto unprepare_clocks; + } + + return 0; + +unprepare_clocks: + clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks); + + return err; +} + +static void tegra_i2c_release_clocks(struct tegra_i2c_dev *i2c_dev) +{ + if (i2c_dev->is_multimaster_mode) + clk_disable(i2c_dev->div_clk); + + clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks); +} + static int tegra_i2c_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct tegra_i2c_dev *i2c_dev; struct resource *res; - struct clk *div_clk; - struct clk *fast_clk; void __iomem *base; phys_addr_t base_phys; int irq; @@ -1688,21 +1702,12 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (irq < 0) return irq; - div_clk = devm_clk_get(&pdev->dev, "div-clk"); - if (IS_ERR(div_clk)) { - if (PTR_ERR(div_clk) != -EPROBE_DEFER) - dev_err(&pdev->dev, "missing controller clock\n"); - - return PTR_ERR(div_clk); - } - i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); if (!i2c_dev) return -ENOMEM; i2c_dev->base = base; i2c_dev->base_phys = base_phys; - i2c_dev->div_clk = div_clk; i2c_dev->adapter.algo = &tegra_i2c_algo; i2c_dev->adapter.retries = 1; i2c_dev->adapter.timeout = 6 * HZ; @@ -1712,12 +1717,17 @@ static int tegra_i2c_probe(struct platform_device *pdev) i2c_dev->rst = devm_reset_control_get_exclusive(&pdev->dev, "i2c"); if (IS_ERR(i2c_dev->rst)) { - dev_err(&pdev->dev, "missing controller reset\n"); + dev_err_probe(&pdev->dev, PTR_ERR(i2c_dev->rst), + "failed to get reset control\n"); return PTR_ERR(i2c_dev->rst); } tegra_i2c_parse_dt(i2c_dev); + ret = tegra_i2c_init_clocks(i2c_dev); + if (ret) + return ret; + i2c_dev->hw = of_device_get_match_data(&pdev->dev); i2c_dev->is_dvc = of_device_is_compatible(pdev->dev.of_node, "nvidia,tegra20-i2c-dvc"); @@ -1729,46 +1739,8 @@ static int tegra_i2c_probe(struct platform_device *pdev) init_completion(&i2c_dev->msg_complete); init_completion(&i2c_dev->dma_complete); - if (!i2c_dev->hw->has_single_clk_source) { - fast_clk = devm_clk_get(&pdev->dev, "fast-clk"); - if (IS_ERR(fast_clk)) { - dev_err(&pdev->dev, "missing fast clock\n"); - return PTR_ERR(fast_clk); - } - i2c_dev->fast_clk = fast_clk; - } - - if (i2c_dev->is_vi) { - i2c_dev->slow_clk = devm_clk_get(dev, "slow"); - if (IS_ERR(i2c_dev->slow_clk)) { - if (PTR_ERR(i2c_dev->slow_clk) != -EPROBE_DEFER) - dev_err(dev, "failed to get slow clock: %ld\n", - PTR_ERR(i2c_dev->slow_clk)); - - return PTR_ERR(i2c_dev->slow_clk); - } - } - platform_set_drvdata(pdev, i2c_dev); - ret = clk_prepare(i2c_dev->fast_clk); - if (ret < 0) { - dev_err(i2c_dev->dev, "Clock prepare failed %d\n", ret); - return ret; - } - - ret = clk_prepare(i2c_dev->slow_clk); - if (ret < 0) { - dev_err(dev, "failed to prepare slow clock: %d\n", ret); - goto unprepare_fast_clk; - } - - ret = clk_prepare(i2c_dev->div_clk); - if (ret < 0) { - dev_err(i2c_dev->dev, "Clock prepare failed %d\n", ret); - goto unprepare_slow_clk; - } - /* * VI I2C is in VE power domain which is not always on and not * an IRQ safe. So, IRQ safe device can't be attached to a non-IRQ @@ -1785,21 +1757,12 @@ static int tegra_i2c_probe(struct platform_device *pdev) goto put_rpm; } - if (i2c_dev->is_multimaster_mode) { - ret = clk_enable(i2c_dev->div_clk); - if (ret < 0) { - dev_err(i2c_dev->dev, "div_clk enable failed %d\n", - ret); - goto put_rpm; - } - } - if (i2c_dev->hw->supports_bus_clear) i2c_dev->adapter.bus_recovery_info = &tegra_i2c_recovery_info; ret = tegra_i2c_init_dma(i2c_dev); if (ret < 0) - goto disable_div_clk; + goto put_rpm; ret = tegra_i2c_init(i2c_dev); if (ret) { @@ -1834,20 +1797,10 @@ static int tegra_i2c_probe(struct platform_device *pdev) release_dma: tegra_i2c_release_dma(i2c_dev); -disable_div_clk: - if (i2c_dev->is_multimaster_mode) - clk_disable(i2c_dev->div_clk); - put_rpm: pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); - clk_unprepare(i2c_dev->div_clk); - -unprepare_slow_clk: - clk_unprepare(i2c_dev->slow_clk); - -unprepare_fast_clk: - clk_unprepare(i2c_dev->fast_clk); + tegra_i2c_release_clocks(i2c_dev); return ret; } @@ -1858,16 +1811,10 @@ static int tegra_i2c_remove(struct platform_device *pdev) i2c_del_adapter(&i2c_dev->adapter); - if (i2c_dev->is_multimaster_mode) - clk_disable(i2c_dev->div_clk); - pm_runtime_disable(&pdev->dev); - clk_unprepare(i2c_dev->div_clk); - clk_unprepare(i2c_dev->slow_clk); - clk_unprepare(i2c_dev->fast_clk); - tegra_i2c_release_dma(i2c_dev); + tegra_i2c_release_clocks(i2c_dev); return 0; } From patchwork Tue Sep 8 22:39:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360160 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=XgaMSUI3; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKrG6Cqxz9sSJ for ; Wed, 9 Sep 2020 08:41:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730079AbgIHWlC (ORCPT ); Tue, 8 Sep 2020 18:41:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729961AbgIHWkq (ORCPT ); Tue, 8 Sep 2020 18:40:46 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C783EC061573; Tue, 8 Sep 2020 15:40:45 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id a15so1003002ljk.2; Tue, 08 Sep 2020 15:40:45 -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=0XBZLDfH4kqBUBs9C1cyVQsph7rHRjiYes9QzEnkvlE=; b=XgaMSUI3ZEBWtGlpiuYwsI1hsO6BdSusSk5BGyPlsiqrkGKhEL9yuzDrOCbz+5BtXX f7+otHA9UKZHAcoYBljlj44fjVYVX+gez/nzfsVbTTU17qnUzXGYcZ/eWgXhMTjSwyR8 wDhcIZTyukQpYC+gxVxBaokBLJLi2GzpuSOC/6Jmkiu+LxiJv2RLBBxDbC3eAGqxDOo+ vweyyZ4VF/UCln1gVg8mmG634/CC1ROFKbnEke9p6W4Pu6xW9JdzL3bMp9vKhZtX2Rke ka4JqXolyDEKv9nMI0IDLvsBhpX6RahdTD62Vv21SgyzlF+XuwM+QhSEVsZ1BE/TWNLu ztyQ== 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=0XBZLDfH4kqBUBs9C1cyVQsph7rHRjiYes9QzEnkvlE=; b=c5n/FNROjZD0mQLzb4oqjDKlGyajyODWvjpr1Pfj/mJ16DbBVH1+JXc+Z75vxNREsu 17IgdjCYlvTeruOBQruLiK9y6csbNgM1oCCW5Zpgwwy6B3hehp9eI7esFmT4XT4Efyv/ pd+sfhvVbPQGwF5uK/vqhH/cdFuYmvOnI8/pyCYRMTSYZSoFvh23PiliC4Iv7FgPQ53J bpZ1AuKXK7lk+hYvL0fvs3kjiqBCHLUHScwsmnjTo3srfKQctk02Y7DM58fuLytlG+Pw ynnjjV8xE4yBUs/229iO6GONC2QIapsrwpp2qCBpYQoCzpgbHQQmOanxBZeNpxqcok9N 2bYQ== X-Gm-Message-State: AOAM533XmuTH+blldLctcXD4x0GLFawEQZz0unlnAqxE1ZWrtm7DY6k5 urEL35hPbRbEF/V3DURHOsU= X-Google-Smtp-Source: ABdhPJye63ZcCwiuphm1b1+1K7l3XePgTiUGdtQiA4NJbSx9TjC3AXOxwfW08CeoA7OSo2jSOEuTGw== X-Received: by 2002:a2e:7213:: with SMTP id n19mr354579ljc.326.1599604844296; Tue, 08 Sep 2020 15:40:44 -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 s15sm268311ljp.25.2020.09.08.15.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:43 -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 v7 13/34] i2c: tegra: Move out all device-tree parsing into tegra_i2c_parse_dt() Date: Wed, 9 Sep 2020 01:39:45 +0300 Message-Id: <20200908224006.25636-14-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Move out code related to device-tree parsing from the probe function into tegra_i2c_parse_dt() in order to make code more consistent. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index c6a29a8069d9..79d1cefdc901 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1428,6 +1428,12 @@ static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) multi_mode = of_property_read_bool(np, "multi-master"); i2c_dev->is_multimaster_mode = multi_mode; + + if (of_device_is_compatible(np, "nvidia,tegra20-i2c-dvc")) + i2c_dev->is_dvc = true; + + if (of_device_is_compatible(np, "nvidia,tegra210-i2c-vi")) + i2c_dev->is_vi = true; } static const struct i2c_algorithm tegra_i2c_algo = { @@ -1729,10 +1735,6 @@ static int tegra_i2c_probe(struct platform_device *pdev) return ret; i2c_dev->hw = of_device_get_match_data(&pdev->dev); - i2c_dev->is_dvc = of_device_is_compatible(pdev->dev.of_node, - "nvidia,tegra20-i2c-dvc"); - i2c_dev->is_vi = of_device_is_compatible(dev->of_node, - "nvidia,tegra210-i2c-vi"); i2c_dev->adapter.quirks = i2c_dev->hw->quirks; i2c_dev->dma_buf_size = i2c_dev->adapter.quirks->max_write_len + I2C_PACKET_HEADER_SIZE; From patchwork Tue Sep 8 22:39:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=YcAviJs9; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKrL4jC1z9sSJ for ; Wed, 9 Sep 2020 08:41:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728350AbgIHWlS (ORCPT ); Tue, 8 Sep 2020 18:41:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729993AbgIHWkr (ORCPT ); Tue, 8 Sep 2020 18:40:47 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5DADC061755; Tue, 8 Sep 2020 15:40:46 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id y4so959658ljk.8; Tue, 08 Sep 2020 15:40:46 -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=DrVLHYam86b5sg92T3Noj715XaTTRZtUMxwVoek/NFY=; b=YcAviJs9bu0V3KbV/FlxweAbSo6vcDlU/D+FpRl1QZpacZ4cREaCW8XRTGGVTbVYpq hEiyI2kwrwEWa+sMOf8+DeGEa5ViUgCu8chvQ4TWcvCpCf48bCiEsecKxad85X34FXuh p47F36mXlwPeXb7jUomM3vI0qTJ88jrTGRVrQ44rnQ0knM0AqPpMG2QcPjYVtqdzvPkV Q3atsCd9TEk0DLa7EpX1H2gEKUAd1Z19dMHsZlNOlDsPtJNQWwfNa7QNlQ8wJs1ikmVB mKhn+6PuOg/EAk2SjFOyBhlwqHXS3ElVrf6To4fz6S8pbAL5vVAq1f3PTWtqaNMJQt0O A45Q== 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=DrVLHYam86b5sg92T3Noj715XaTTRZtUMxwVoek/NFY=; b=jP6qWT8rquNPfV9yxcM8tCT6bCNE+wRtE4zUB8Tw1HH7A4pkUPg0RDaC0Ua68DOoGS +kvjLNVTfhJGB1xuPuVvJd8GOyDITwZg7yPtDh6YmCp8biccx2+6knUR7eeGgmrE4Fp3 UaXWHU7/vP3ejn8FM5U6uuLr7Bm5ByMmu7ecZPhflg9nq9X234Wt/iQT1ylF1lUYAsI2 0gW0Fbia1TfsbbEXJqQnAbgX5VZ6ogwbGtTScr6jcWY8a4KetkpVCGZpka5i8ryA8KH0 lW6/AzuPXnMjjiDfyyKvhiUgO7b5M5QmdZV4pzMOfxrwoRncHVDjhFrPQwTM+mgwzZsz 6SZw== X-Gm-Message-State: AOAM531OBbAhuISfkvTHxsUD2VBHyF65M5//yjhc2yUPBOucRPBMHa/q WzBlNPQbB/DtAKkuJEULoqA= X-Google-Smtp-Source: ABdhPJwZZs1kgoiw9MTPiD7TieniCk0hhIhYiTNo3j19mQqhnmlcg94VaOKcm1Eg2/iWQPF2Ms4YPA== X-Received: by 2002:a2e:88c4:: with SMTP id a4mr316433ljk.393.1599604845280; Tue, 08 Sep 2020 15:40:45 -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 s15sm268311ljp.25.2020.09.08.15.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:44 -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 v7 14/34] i2c: tegra: Clean up probe function Date: Wed, 9 Sep 2020 01:39:46 +0300 Message-Id: <20200908224006.25636-15-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The driver's probe function code is a bit difficult to read. This patch reorders code of the probe function, forming groups of code that are easy to work with. The probe tear-down order now matches the driver-removal order. Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding Reviewed-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 100 ++++++++++++++++----------------- 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 79d1cefdc901..7c91bbb3f95c 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -440,6 +440,9 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) i2c_dev->tx_dma_chan = chan; + i2c_dev->dma_buf_size = i2c_dev->hw->quirks->max_write_len + + I2C_PACKET_HEADER_SIZE; + dma_buf = dma_alloc_coherent(i2c_dev->dev, i2c_dev->dma_buf_size, &dma_phys, GFP_KERNEL | __GFP_NOWARN); if (!dma_buf) { @@ -1693,34 +1696,42 @@ static int tegra_i2c_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct tegra_i2c_dev *i2c_dev; struct resource *res; - void __iomem *base; - phys_addr_t base_phys; - int irq; int ret; - base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); - if (IS_ERR(base)) - return PTR_ERR(base); - - base_phys = res->start; - - irq = platform_get_irq(pdev, 0); - if (irq < 0) - return irq; - i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); if (!i2c_dev) return -ENOMEM; - i2c_dev->base = base; - i2c_dev->base_phys = base_phys; - i2c_dev->adapter.algo = &tegra_i2c_algo; - i2c_dev->adapter.retries = 1; - i2c_dev->adapter.timeout = 6 * HZ; - i2c_dev->irq = irq; + platform_set_drvdata(pdev, i2c_dev); + + init_completion(&i2c_dev->msg_complete); + init_completion(&i2c_dev->dma_complete); + + i2c_dev->hw = of_device_get_match_data(&pdev->dev); i2c_dev->cont_id = pdev->id; i2c_dev->dev = &pdev->dev; + i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); + if (IS_ERR(i2c_dev->base)) + return PTR_ERR(i2c_dev->base); + + i2c_dev->base_phys = res->start; + + ret = platform_get_irq(pdev, 0); + if (ret < 0) + return ret; + + i2c_dev->irq = ret; + + /* interrupt will be enabled during of transfer time */ + irq_set_status_flags(i2c_dev->irq, IRQ_NOAUTOEN); + + ret = devm_request_irq(&pdev->dev, i2c_dev->irq, tegra_i2c_isr, + IRQF_NO_SUSPEND, dev_name(&pdev->dev), + i2c_dev); + if (ret) + return ret; + i2c_dev->rst = devm_reset_control_get_exclusive(&pdev->dev, "i2c"); if (IS_ERR(i2c_dev->rst)) { dev_err_probe(&pdev->dev, PTR_ERR(i2c_dev->rst), @@ -1734,14 +1745,9 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (ret) return ret; - i2c_dev->hw = of_device_get_match_data(&pdev->dev); - i2c_dev->adapter.quirks = i2c_dev->hw->quirks; - i2c_dev->dma_buf_size = i2c_dev->adapter.quirks->max_write_len + - I2C_PACKET_HEADER_SIZE; - init_completion(&i2c_dev->msg_complete); - init_completion(&i2c_dev->dma_complete); - - platform_set_drvdata(pdev, i2c_dev); + ret = tegra_i2c_init_dma(i2c_dev); + if (ret) + goto release_clocks; /* * VI I2C is in VE power domain which is not always on and not @@ -1759,49 +1765,41 @@ static int tegra_i2c_probe(struct platform_device *pdev) goto put_rpm; } - if (i2c_dev->hw->supports_bus_clear) - i2c_dev->adapter.bus_recovery_info = &tegra_i2c_recovery_info; - - ret = tegra_i2c_init_dma(i2c_dev); - if (ret < 0) - goto put_rpm; - ret = tegra_i2c_init(i2c_dev); - if (ret) { - dev_err(&pdev->dev, "Failed to initialize i2c controller\n"); - goto release_dma; - } - - irq_set_status_flags(i2c_dev->irq, IRQ_NOAUTOEN); - - ret = devm_request_irq(&pdev->dev, i2c_dev->irq, tegra_i2c_isr, - IRQF_NO_SUSPEND, dev_name(&pdev->dev), i2c_dev); if (ret) - goto release_dma; + goto put_rpm; i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); + i2c_dev->adapter.dev.of_node = pdev->dev.of_node; + i2c_dev->adapter.dev.parent = &pdev->dev; + i2c_dev->adapter.retries = 1; + i2c_dev->adapter.timeout = 6 * HZ; + i2c_dev->adapter.quirks = i2c_dev->hw->quirks; i2c_dev->adapter.owner = THIS_MODULE; i2c_dev->adapter.class = I2C_CLASS_DEPRECATED; + i2c_dev->adapter.algo = &tegra_i2c_algo; + i2c_dev->adapter.nr = pdev->id; + + if (i2c_dev->hw->supports_bus_clear) + i2c_dev->adapter.bus_recovery_info = &tegra_i2c_recovery_info; + strlcpy(i2c_dev->adapter.name, dev_name(&pdev->dev), sizeof(i2c_dev->adapter.name)); - i2c_dev->adapter.dev.parent = &pdev->dev; - i2c_dev->adapter.nr = pdev->id; - i2c_dev->adapter.dev.of_node = pdev->dev.of_node; ret = i2c_add_numbered_adapter(&i2c_dev->adapter); if (ret) - goto release_dma; + goto put_rpm; pm_runtime_put(&pdev->dev); return 0; -release_dma: - tegra_i2c_release_dma(i2c_dev); - put_rpm: pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); + + tegra_i2c_release_dma(i2c_dev); +release_clocks: tegra_i2c_release_clocks(i2c_dev); return ret; From patchwork Tue Sep 8 22:39:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ck/QlV+i; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKrK3HgZz9sSJ for ; Wed, 9 Sep 2020 08:41:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730157AbgIHWlP (ORCPT ); Tue, 8 Sep 2020 18:41:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730022AbgIHWks (ORCPT ); Tue, 8 Sep 2020 18:40:48 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB866C061756; Tue, 8 Sep 2020 15:40:47 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id u27so513999lfm.13; Tue, 08 Sep 2020 15:40:47 -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=Sx+nXOlAzzOpeCoSxuSQBRXbIIe7OJzTAxYeK7yxhgA=; b=ck/QlV+ihn0oolIr2M/MYp6lxtHaUodapKrFKV/xJgAHSQThCGa+HGc/bZyeoaaZTS MtkvjJ1fGqeyDkXUgqrYh++axD61DX0Zeaaz3sp2Kv/2/lMdsRumO4NXo0JFhOVKM3G9 2xdpBdCdY7eNYAHTOLPkdoAU5wKNznsOyKX92cHeD16jToI6zowX8XcUysOdjnwEz1Au kxV4iRr3diM/1NH8ec6jXKMZnNwIl/y/1Ehpktc7mHpVaLu+OG/cvlC6F1l/vR835MQI ZDtmvZ9AkZ3/h69+l2+zgxItyDSBQG4eIevdIcbNFaj4FYVwBKThrb0C6swO8KwyDdr+ vgRQ== 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=Sx+nXOlAzzOpeCoSxuSQBRXbIIe7OJzTAxYeK7yxhgA=; b=aAvDWp9kIElJe3iM3kATdBnXLJN93kWDqkRo3/w7b0UZKxkMSHsNAwuAABJnbKG5ny FyRPiNqDD41ZmMmyTpzxun+xbnAsHb/CXRRkaD+4w20AyZuDxlc7/fax/lQhFq086D6+ +jUF5dujoMLz4owsknOz93eP1HMjAzNJ96sHnzoYxZ0Et1IEQ+ULy3enBU++BWUXWMyN aORKfNcsRGhrLTzhPcc+2JqdOyDyX9VrPAchCej28qTjOvmwMHzqEO4sQg4azymChBuD oBSWvy576M/+StRGea9VPx7WFyhfNrAHSkXUq1ro+y1TheafbGPJMSV5pBVbSSwVxyvb XkOw== X-Gm-Message-State: AOAM530/0oCQL/GnPDwCbX0dt5bdxAWTAStqGAYKphlZhgkORJUoXwX6 OKcVaGnAR9cQh8sm01hHpuQ= X-Google-Smtp-Source: ABdhPJx4lwp/S9f7SkgaTgpUrUpN6g0b4iIGeptcBzDEunAL87LSw2M5+97BgOvZAwZS6W/h6dpIlw== X-Received: by 2002:a05:6512:207:: with SMTP id a7mr530892lfo.127.1599604846249; Tue, 08 Sep 2020 15:40:46 -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 s15sm268311ljp.25.2020.09.08.15.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:45 -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 v7 15/34] i2c: tegra: Reorder location of functions in the code Date: Wed, 9 Sep 2020 01:39:47 +0300 Message-Id: <20200908224006.25636-16-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Reorder location of functions in the code in order to have definition of functions closer to the place of the invocation. This change makes easier to navigate around the code and removes the need to have a prototype for tegra_i2c_init(). Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 486 ++++++++++++++++----------------- 1 file changed, 242 insertions(+), 244 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 7c91bbb3f95c..5a0bb5b3876c 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -288,8 +288,6 @@ struct tegra_i2c_dev { bool is_curr_atomic_xfer; }; -static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev); - static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned long reg) { @@ -466,6 +464,56 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) return err; } +/* + * One of the Tegra I2C blocks is inside the DVC (Digital Voltage Controller) + * block. This block is identical to the rest of the I2C blocks, except that + * it only supports master mode, it has registers moved around, and it needs + * some extra init to get it into I2C mode. The register moves are handled + * by i2c_readl and i2c_writel + */ +static void tegra_dvc_init(struct tegra_i2c_dev *i2c_dev) +{ + u32 val; + + val = dvc_readl(i2c_dev, DVC_CTRL_REG3); + val |= DVC_CTRL_REG3_SW_PROG; + val |= DVC_CTRL_REG3_I2C_DONE_INTR_EN; + dvc_writel(i2c_dev, val, DVC_CTRL_REG3); + + val = dvc_readl(i2c_dev, DVC_CTRL_REG1); + val |= DVC_CTRL_REG1_INTR_EN; + dvc_writel(i2c_dev, val, DVC_CTRL_REG1); +} + +static void tegra_i2c_vi_init(struct tegra_i2c_dev *i2c_dev) +{ + u32 value; + + value = FIELD_PREP(I2C_INTERFACE_TIMING_THIGH, 2) | + FIELD_PREP(I2C_INTERFACE_TIMING_TLOW, 4); + i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_0); + + value = FIELD_PREP(I2C_INTERFACE_TIMING_TBUF, 4) | + FIELD_PREP(I2C_INTERFACE_TIMING_TSU_STO, 7) | + FIELD_PREP(I2C_INTERFACE_TIMING_THD_STA, 4) | + FIELD_PREP(I2C_INTERFACE_TIMING_TSU_STA, 4); + i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_1); + + value = FIELD_PREP(I2C_HS_INTERFACE_TIMING_THIGH, 3) | + FIELD_PREP(I2C_HS_INTERFACE_TIMING_TLOW, 8); + i2c_writel(i2c_dev, value, I2C_HS_INTERFACE_TIMING_0); + + value = FIELD_PREP(I2C_HS_INTERFACE_TIMING_TSU_STO, 11) | + FIELD_PREP(I2C_HS_INTERFACE_TIMING_THD_STA, 11) | + FIELD_PREP(I2C_HS_INTERFACE_TIMING_TSU_STA, 11); + i2c_writel(i2c_dev, value, I2C_HS_INTERFACE_TIMING_1); + + value = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND; + i2c_writel(i2c_dev, value, I2C_BUS_CLEAR_CNFG); + + i2c_writel(i2c_dev, 0x0, I2C_TLOW_SEXT); +} + static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) { u32 mask, val, offset, reg_offset; @@ -503,198 +551,6 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) return 0; } -static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) -{ - u32 val; - int rx_fifo_avail; - u8 *buf = i2c_dev->msg_buf; - size_t buf_remaining = i2c_dev->msg_buf_remaining; - int words_to_transfer; - - /* - * Catch overflow due to message fully sent - * before the check for RX FIFO availability. - */ - if (WARN_ON_ONCE(!(i2c_dev->msg_buf_remaining))) - return -EINVAL; - - if (i2c_dev->hw->has_mst_fifo) { - val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); - rx_fifo_avail = FIELD_GET(I2C_MST_FIFO_STATUS_RX, val); - } else { - val = i2c_readl(i2c_dev, I2C_FIFO_STATUS); - rx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_RX, val); - } - - /* Rounds down to not include partial word at the end of buf */ - words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; - if (words_to_transfer > rx_fifo_avail) - words_to_transfer = rx_fifo_avail; - - i2c_readsl(i2c_dev, buf, I2C_RX_FIFO, words_to_transfer); - - buf += words_to_transfer * BYTES_PER_FIFO_WORD; - buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; - rx_fifo_avail -= words_to_transfer; - - /* - * If there is a partial word at the end of buf, handle it manually to - * prevent overwriting past the end of buf - */ - if (rx_fifo_avail > 0 && buf_remaining > 0) { - /* - * buf_remaining > 3 check not needed as rx_fifo_avail == 0 - * when (words_to_transfer was > rx_fifo_avail) earlier - * in this function. - */ - val = i2c_readl(i2c_dev, I2C_RX_FIFO); - val = cpu_to_le32(val); - memcpy(buf, &val, buf_remaining); - buf_remaining = 0; - rx_fifo_avail--; - } - - /* RX FIFO must be drained, otherwise it's an Overflow case. */ - if (WARN_ON_ONCE(rx_fifo_avail)) - return -EINVAL; - - i2c_dev->msg_buf_remaining = buf_remaining; - i2c_dev->msg_buf = buf; - - return 0; -} - -static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) -{ - u32 val; - int tx_fifo_avail; - u8 *buf = i2c_dev->msg_buf; - size_t buf_remaining = i2c_dev->msg_buf_remaining; - int words_to_transfer; - - if (i2c_dev->hw->has_mst_fifo) { - val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); - tx_fifo_avail = FIELD_GET(I2C_MST_FIFO_STATUS_TX, val); - } else { - val = i2c_readl(i2c_dev, I2C_FIFO_STATUS); - tx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_TX, val); - } - - /* Rounds down to not include partial word at the end of buf */ - words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; - - /* It's very common to have < 4 bytes, so optimize that case. */ - if (words_to_transfer) { - if (words_to_transfer > tx_fifo_avail) - words_to_transfer = tx_fifo_avail; - - /* - * Update state before writing to FIFO. If this casues us - * to finish writing all bytes (AKA buf_remaining goes to 0) we - * have a potential for an interrupt (PACKET_XFER_COMPLETE is - * not maskable). We need to make sure that the isr sees - * buf_remaining as 0 and doesn't call us back re-entrantly. - */ - buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; - tx_fifo_avail -= words_to_transfer; - i2c_dev->msg_buf_remaining = buf_remaining; - i2c_dev->msg_buf = buf + - words_to_transfer * BYTES_PER_FIFO_WORD; - barrier(); - - i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer); - - buf += words_to_transfer * BYTES_PER_FIFO_WORD; - } - - /* - * If there is a partial word at the end of buf, handle it manually to - * prevent reading past the end of buf, which could cross a page - * boundary and fault. - */ - if (tx_fifo_avail > 0 && buf_remaining > 0) { - /* - * buf_remaining > 3 check not needed as tx_fifo_avail == 0 - * when (words_to_transfer was > tx_fifo_avail) earlier - * in this function for non-zero words_to_transfer. - */ - memcpy(&val, buf, buf_remaining); - val = le32_to_cpu(val); - - /* Again update before writing to FIFO to make sure isr sees. */ - i2c_dev->msg_buf_remaining = 0; - i2c_dev->msg_buf = NULL; - barrier(); - - i2c_writel(i2c_dev, val, I2C_TX_FIFO); - } - - return 0; -} - -/* - * One of the Tegra I2C blocks is inside the DVC (Digital Voltage Controller) - * block. This block is identical to the rest of the I2C blocks, except that - * it only supports master mode, it has registers moved around, and it needs - * some extra init to get it into I2C mode. The register moves are handled - * by i2c_readl and i2c_writel - */ -static void tegra_dvc_init(struct tegra_i2c_dev *i2c_dev) -{ - u32 val; - - val = dvc_readl(i2c_dev, DVC_CTRL_REG3); - val |= DVC_CTRL_REG3_SW_PROG; - val |= DVC_CTRL_REG3_I2C_DONE_INTR_EN; - dvc_writel(i2c_dev, val, DVC_CTRL_REG3); - - val = dvc_readl(i2c_dev, DVC_CTRL_REG1); - val |= DVC_CTRL_REG1_INTR_EN; - dvc_writel(i2c_dev, val, DVC_CTRL_REG1); -} - -static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) -{ - struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); - int ret; - - ret = pinctrl_pm_select_default_state(i2c_dev->dev); - if (ret) - return ret; - - ret = clk_bulk_enable(i2c_dev->nclocks, i2c_dev->clocks); - if (ret) - return ret; - - /* - * VI I2C device is attached to VE power domain which goes through - * power ON/OFF during PM runtime resume/suspend. So, controller - * should go through reset and need to re-initialize after power - * domain ON. - */ - if (i2c_dev->is_vi) { - ret = tegra_i2c_init(i2c_dev); - if (ret) - goto disable_clocks; - } - - return 0; - -disable_clocks: - clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); - - return ret; -} - -static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev) -{ - struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); - - clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); - - return pinctrl_pm_select_idle_state(i2c_dev->dev); -} - static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) { unsigned long reg_offset; @@ -726,35 +582,6 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) return 0; } -static void tegra_i2c_vi_init(struct tegra_i2c_dev *i2c_dev) -{ - u32 value; - - value = FIELD_PREP(I2C_INTERFACE_TIMING_THIGH, 2) | - FIELD_PREP(I2C_INTERFACE_TIMING_TLOW, 4); - i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_0); - - value = FIELD_PREP(I2C_INTERFACE_TIMING_TBUF, 4) | - FIELD_PREP(I2C_INTERFACE_TIMING_TSU_STO, 7) | - FIELD_PREP(I2C_INTERFACE_TIMING_THD_STA, 4) | - FIELD_PREP(I2C_INTERFACE_TIMING_TSU_STA, 4); - i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_1); - - value = FIELD_PREP(I2C_HS_INTERFACE_TIMING_THIGH, 3) | - FIELD_PREP(I2C_HS_INTERFACE_TIMING_TLOW, 8); - i2c_writel(i2c_dev, value, I2C_HS_INTERFACE_TIMING_0); - - value = FIELD_PREP(I2C_HS_INTERFACE_TIMING_TSU_STO, 11) | - FIELD_PREP(I2C_HS_INTERFACE_TIMING_THD_STA, 11) | - FIELD_PREP(I2C_HS_INTERFACE_TIMING_TSU_STA, 11); - i2c_writel(i2c_dev, value, I2C_HS_INTERFACE_TIMING_1); - - value = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND; - i2c_writel(i2c_dev, value, I2C_BUS_CLEAR_CNFG); - - i2c_writel(i2c_dev, 0x0, I2C_TLOW_SEXT); -} - static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) { u32 val; @@ -882,6 +709,135 @@ static int tegra_i2c_disable_packet_mode(struct tegra_i2c_dev *i2c_dev) return tegra_i2c_wait_for_config_load(i2c_dev); } +static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) +{ + u32 val; + int rx_fifo_avail; + u8 *buf = i2c_dev->msg_buf; + size_t buf_remaining = i2c_dev->msg_buf_remaining; + int words_to_transfer; + + /* + * Catch overflow due to message fully sent + * before the check for RX FIFO availability. + */ + if (WARN_ON_ONCE(!(i2c_dev->msg_buf_remaining))) + return -EINVAL; + + if (i2c_dev->hw->has_mst_fifo) { + val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); + rx_fifo_avail = FIELD_GET(I2C_MST_FIFO_STATUS_RX, val); + } else { + val = i2c_readl(i2c_dev, I2C_FIFO_STATUS); + rx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_RX, val); + } + + /* Rounds down to not include partial word at the end of buf */ + words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; + if (words_to_transfer > rx_fifo_avail) + words_to_transfer = rx_fifo_avail; + + i2c_readsl(i2c_dev, buf, I2C_RX_FIFO, words_to_transfer); + + buf += words_to_transfer * BYTES_PER_FIFO_WORD; + buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; + rx_fifo_avail -= words_to_transfer; + + /* + * If there is a partial word at the end of buf, handle it manually to + * prevent overwriting past the end of buf + */ + if (rx_fifo_avail > 0 && buf_remaining > 0) { + /* + * buf_remaining > 3 check not needed as rx_fifo_avail == 0 + * when (words_to_transfer was > rx_fifo_avail) earlier + * in this function. + */ + val = i2c_readl(i2c_dev, I2C_RX_FIFO); + val = cpu_to_le32(val); + memcpy(buf, &val, buf_remaining); + buf_remaining = 0; + rx_fifo_avail--; + } + + /* RX FIFO must be drained, otherwise it's an Overflow case. */ + if (WARN_ON_ONCE(rx_fifo_avail)) + return -EINVAL; + + i2c_dev->msg_buf_remaining = buf_remaining; + i2c_dev->msg_buf = buf; + + return 0; +} + +static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) +{ + u32 val; + int tx_fifo_avail; + u8 *buf = i2c_dev->msg_buf; + size_t buf_remaining = i2c_dev->msg_buf_remaining; + int words_to_transfer; + + if (i2c_dev->hw->has_mst_fifo) { + val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); + tx_fifo_avail = FIELD_GET(I2C_MST_FIFO_STATUS_TX, val); + } else { + val = i2c_readl(i2c_dev, I2C_FIFO_STATUS); + tx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_TX, val); + } + + /* Rounds down to not include partial word at the end of buf */ + words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; + + /* It's very common to have < 4 bytes, so optimize that case. */ + if (words_to_transfer) { + if (words_to_transfer > tx_fifo_avail) + words_to_transfer = tx_fifo_avail; + + /* + * Update state before writing to FIFO. If this casues us + * to finish writing all bytes (AKA buf_remaining goes to 0) we + * have a potential for an interrupt (PACKET_XFER_COMPLETE is + * not maskable). We need to make sure that the isr sees + * buf_remaining as 0 and doesn't call us back re-entrantly. + */ + buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; + tx_fifo_avail -= words_to_transfer; + i2c_dev->msg_buf_remaining = buf_remaining; + i2c_dev->msg_buf = buf + + words_to_transfer * BYTES_PER_FIFO_WORD; + barrier(); + + i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer); + + buf += words_to_transfer * BYTES_PER_FIFO_WORD; + } + + /* + * If there is a partial word at the end of buf, handle it manually to + * prevent reading past the end of buf, which could cross a page + * boundary and fault. + */ + if (tx_fifo_avail > 0 && buf_remaining > 0) { + /* + * buf_remaining > 3 check not needed as tx_fifo_avail == 0 + * when (words_to_transfer was > tx_fifo_avail) earlier + * in this function for non-zero words_to_transfer. + */ + memcpy(&val, buf, buf_remaining); + val = le32_to_cpu(val); + + /* Again update before writing to FIFO to make sure isr sees. */ + i2c_dev->msg_buf_remaining = 0; + i2c_dev->msg_buf = NULL; + barrier(); + + i2c_writel(i2c_dev, val, I2C_TX_FIFO); + } + + return 0; +} + static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) { u32 status; @@ -1418,27 +1374,6 @@ static u32 tegra_i2c_func(struct i2c_adapter *adap) return ret; } -static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) -{ - struct device_node *np = i2c_dev->dev->of_node; - int ret; - bool multi_mode; - - ret = of_property_read_u32(np, "clock-frequency", - &i2c_dev->bus_clk_rate); - if (ret) - i2c_dev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */ - - multi_mode = of_property_read_bool(np, "multi-master"); - i2c_dev->is_multimaster_mode = multi_mode; - - if (of_device_is_compatible(np, "nvidia,tegra20-i2c-dvc")) - i2c_dev->is_dvc = true; - - if (of_device_is_compatible(np, "nvidia,tegra210-i2c-vi")) - i2c_dev->is_vi = true; -} - static const struct i2c_algorithm tegra_i2c_algo = { .master_xfer = tegra_i2c_xfer, .master_xfer_atomic = tegra_i2c_xfer_atomic, @@ -1644,6 +1579,27 @@ static const struct of_device_id tegra_i2c_of_match[] = { }; MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); +static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) +{ + struct device_node *np = i2c_dev->dev->of_node; + int ret; + bool multi_mode; + + ret = of_property_read_u32(np, "clock-frequency", + &i2c_dev->bus_clk_rate); + if (ret) + i2c_dev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */ + + multi_mode = of_property_read_bool(np, "multi-master"); + i2c_dev->is_multimaster_mode = multi_mode; + + if (of_device_is_compatible(np, "nvidia,tegra20-i2c-dvc")) + i2c_dev->is_dvc = true; + + if (of_device_is_compatible(np, "nvidia,tegra210-i2c-vi")) + i2c_dev->is_vi = true; +} + static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev) { unsigned int i; @@ -1818,6 +1774,48 @@ static int tegra_i2c_remove(struct platform_device *pdev) return 0; } +static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) +{ + struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); + int ret; + + ret = pinctrl_pm_select_default_state(i2c_dev->dev); + if (ret) + return ret; + + ret = clk_bulk_enable(i2c_dev->nclocks, i2c_dev->clocks); + if (ret) + return ret; + + /* + * VI I2C device is attached to VE power domain which goes through + * power ON/OFF during PM runtime resume/suspend. So, controller + * should go through reset and need to re-initialize after power + * domain ON. + */ + if (i2c_dev->is_vi) { + ret = tegra_i2c_init(i2c_dev); + if (ret) + goto disable_clocks; + } + + return 0; + +disable_clocks: + clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); + + return ret; +} + +static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev) +{ + struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); + + clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); + + return pinctrl_pm_select_idle_state(i2c_dev->dev); +} + static int __maybe_unused tegra_i2c_suspend(struct device *dev) { struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); From patchwork Tue Sep 8 22:39:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360202 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=X2pzHZ7h; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKvX4kl2z9sSJ for ; Wed, 9 Sep 2020 08:44:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730376AbgIHWoH (ORCPT ); Tue, 8 Sep 2020 18:44:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730030AbgIHWkt (ORCPT ); Tue, 8 Sep 2020 18:40:49 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD71FC061757; Tue, 8 Sep 2020 15:40:48 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id c2so938538ljj.12; Tue, 08 Sep 2020 15:40:48 -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=XiCNom3qeiM4/HKNi2tbRXmQDZ+48GTNMpi9iQMW9rk=; b=X2pzHZ7hj2uWs1U1oTtnzDpD/pB+tlNateDbFmEplEPbkjW1y86/62B0tg1awBcLsr b29RQU5eo39EMXZP6RoBHs5SMDHS9nQRy8oact3xz5wWjOQrybgPPMrrqDC0sjKuFBgj lHDC1KySZWVSlTuT9BxCs18GqPN2XQQ7ibxFh1jfuOAba1qJb9QsH6Eq83P47vA4EGwB y39XC56P/cZ4N6PrdcaLpA/erJjLvd+QQzAV1BsNF3b7qdfAIewJ925UZjismDS/44l4 VwLvD20NTkGcdHwXAgqz+ypeNnsOTdPZWSF/xRVU4rqbP7MT5igYo9yOzF4K4FnUs0jq V/bA== 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=XiCNom3qeiM4/HKNi2tbRXmQDZ+48GTNMpi9iQMW9rk=; b=QT4Mfyii3MxVq8abflC5meoSMbDob5uXSI4dFesnjOZ1so1M2qbLyeGIf2beeDS2fP S+0DVnNatdBtnA6BSoYuPcbp0oIgR6M1T/RTuY0DbTTGPn0WxnPNBxQv42EEevOSTfX4 tmnAdfcgVCPV0GyNavyyuX1vmxBgEYR7XuLfNsfkRCRn9+JFNokjUqa/HXa6iacTUm5s 0ouJ1ivAY9riQr4Lt0rrPfdrmM/cvzHuoCfH3kPVTbEuiT7wUoYi0HllhBB7xBKPAF4p /utgU0Q3L1xYaJllI788slbBKgJ9H0n9bKvtP55QHhSx50DMOFv18TlmFDoRvIGTZQa/ V7zA== X-Gm-Message-State: AOAM530lAmGvQxau+QrEQn9n0doX2PrltXuUsFyZSP61oL7bHavr9EeJ bv0YxQyDb/YGovIBsXWHhlw= X-Google-Smtp-Source: ABdhPJzcFheTR5/u5z6+j8Eje+GnpuWUgmHbzFMkNcHOQP09DHsWwELgG1+ZUQqqygSNCeRnZmd6kw== X-Received: by 2002:a2e:9dcb:: with SMTP id x11mr77160ljj.450.1599604847306; Tue, 08 Sep 2020 15:40:47 -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 s15sm268311ljp.25.2020.09.08.15.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:46 -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 v7 16/34] i2c: tegra: Clean up variable types Date: Wed, 9 Sep 2020 01:39:48 +0300 Message-Id: <20200908224006.25636-17-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Don't use signed types for unsigned values and use consistent types for sibling variables. Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 5a0bb5b3876c..71e82a68c942 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -206,20 +206,20 @@ struct tegra_i2c_hw_feature { bool has_continue_xfer_support; bool has_per_pkt_xfer_complete_irq; bool has_config_load_reg; - int clk_divisor_hs_mode; - int clk_divisor_std_mode; - int clk_divisor_fast_mode; - u16 clk_divisor_fast_plus_mode; + u32 clk_divisor_hs_mode; + u32 clk_divisor_std_mode; + u32 clk_divisor_fast_mode; + u32 clk_divisor_fast_plus_mode; bool has_multi_master_mode; bool has_slcg_override_reg; bool has_mst_fifo; const struct i2c_adapter_quirks *quirks; bool supports_bus_clear; bool has_apb_dma; - u8 tlow_std_mode; - u8 thigh_std_mode; - u8 tlow_fast_fastplus_mode; - u8 thigh_fast_fastplus_mode; + u32 tlow_std_mode; + u32 thigh_std_mode; + u32 tlow_fast_fastplus_mode; + u32 thigh_fast_fastplus_mode; u32 setup_hold_time_std_mode; u32 setup_hold_time_fast_fast_plus_mode; u32 setup_hold_time_hs_mode; @@ -267,15 +267,15 @@ struct tegra_i2c_dev { struct reset_control *rst; void __iomem *base; phys_addr_t base_phys; - int cont_id; - int irq; - int is_dvc; + unsigned int cont_id; + unsigned int irq; + bool is_dvc; bool is_vi; struct completion msg_complete; int msg_err; u8 *msg_buf; size_t msg_buf_remaining; - int msg_read; + bool msg_read; u32 bus_clk_rate; bool is_multimaster_mode; struct dma_chan *tx_dma_chan; @@ -329,13 +329,13 @@ static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) } static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data, - unsigned long reg, int len) + unsigned long reg, unsigned int len) { writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); } static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data, - unsigned long reg, int len) + unsigned long reg, unsigned int len) { readsl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); } @@ -712,10 +712,10 @@ static int tegra_i2c_disable_packet_mode(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) { u32 val; - int rx_fifo_avail; + unsigned int rx_fifo_avail; u8 *buf = i2c_dev->msg_buf; size_t buf_remaining = i2c_dev->msg_buf_remaining; - int words_to_transfer; + unsigned int words_to_transfer; /* * Catch overflow due to message fully sent @@ -773,10 +773,10 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) { u32 val; - int tx_fifo_avail; + unsigned int tx_fifo_avail; u8 *buf = i2c_dev->msg_buf; size_t buf_remaining = i2c_dev->msg_buf_remaining; - int words_to_transfer; + unsigned int words_to_transfer; if (i2c_dev->hw->has_mst_fifo) { val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); @@ -1134,7 +1134,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->msg_buf = msg->buf; i2c_dev->msg_buf_remaining = msg->len; i2c_dev->msg_err = I2C_ERR_NONE; - i2c_dev->msg_read = (msg->flags & I2C_M_RD); + i2c_dev->msg_read = !!(msg->flags & I2C_M_RD); reinit_completion(&i2c_dev->msg_complete); if (i2c_dev->msg_read) From patchwork Tue Sep 8 22:39:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360204 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Mlr6R/1l; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKvt3k0Yz9sSJ for ; Wed, 9 Sep 2020 08:44:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730203AbgIHWoG (ORCPT ); Tue, 8 Sep 2020 18:44:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730054AbgIHWku (ORCPT ); Tue, 8 Sep 2020 18:40:50 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0847C061573; Tue, 8 Sep 2020 15:40:49 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id y11so539405lfl.5; Tue, 08 Sep 2020 15:40:49 -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=e1fEwvYGVc4Rjygf6C1JwpQ8Ow8K6KfjGtqJJ79slO8=; b=Mlr6R/1l4hKnL+YI84D/CMKw3csSXxA5bp//v92tFjvz8zuOva72KP5A64ui7nvrD0 uimCtB1InIu/44d8gr98G4OksCcnW+2Gr9YV03Q3x0Fc14tYnjirC0KFfNBmzITsWaOd EsGCzd2frJxu7R3W3aFlsMG2Hk4e41d71EuJYjccyxqoDxUNz7/7cXP4dLINmVViz6Ii FwkGClUmAVBBGcjEscNdF4xvS1Onm8UFZ8T2Gg6MI+Wpqt48ncA614UEx2X9RFkbVp7z bu8/knXp0Lvf9+m1wALtHesOwJgdSf+LydEMnK7iq8AyRz35KYpC6BAti3mIqNQXG8qc d0uA== 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=e1fEwvYGVc4Rjygf6C1JwpQ8Ow8K6KfjGtqJJ79slO8=; b=hpM8zxIPXXLTpCCYxi6RrTW3Qb1JuZVavT4pF/1niXbdaOini41vAD6/K673WIDvWn Me0wYVMwEc6jq7BZllAknw/4ls++RMJX4JTIHkfhQgANrLyGFUskGij0zMM2rs29BtDL avgWX3FGJ16BFwgFB/Wy1L4GVG8YWJnR3Fv4GZNpfdGnINBNAXtE6Wkvv4y75TYOcWAk 46Okf9+fW5ngKYRNtVOX7LBqD0lhGcGnJiJAXR4s8kH79+1IGxmTk7mljP0MtjNvegSp vRbGMwW45ncVb+dtkYLBG9CmnamyG86Ju8VkXWRMJW9+GW9sVxrDHw5f3xDtmYVby0Bc vneg== X-Gm-Message-State: AOAM531eGW/ghnsu8QWZgVejqm+JTZG77O5xOrBW165k1M+HYW1KurBc 6G3HW1M4txh1dXheZvpjUQc= X-Google-Smtp-Source: ABdhPJyYRnAwV78qx0If7eGiPj5aYVpnoOn40HTT8DyE/y9S2NeEQ8y0562g4b6N+S8MpsV8qtjkzA== X-Received: by 2002:a19:5e5d:: with SMTP id z29mr542824lfi.32.1599604848234; Tue, 08 Sep 2020 15:40:48 -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 s15sm268311ljp.25.2020.09.08.15.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:47 -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 v7 17/34] i2c: tegra: Remove outdated barrier() Date: Wed, 9 Sep 2020 01:39:49 +0300 Message-Id: <20200908224006.25636-18-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The barrier() was intended to reduce possibility of racing with the interrupt handler, but driver's code evolved significantly and today's driver enables interrupt only when it waits for completion notification. Hence barrier() has no good use anymore, let's remove it. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 71e82a68c942..ab83d1de6c94 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -795,18 +795,17 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) words_to_transfer = tx_fifo_avail; /* - * Update state before writing to FIFO. If this casues us - * to finish writing all bytes (AKA buf_remaining goes to 0) we - * have a potential for an interrupt (PACKET_XFER_COMPLETE is - * not maskable). We need to make sure that the isr sees - * buf_remaining as 0 and doesn't call us back re-entrantly. + * Update state before writing to FIFO. Note that this may + * cause us to finish writing all bytes (AKA buf_remaining + * goes to 0), hence we have a potential for an interrupt + * (PACKET_XFER_COMPLETE is not maskable), but GIC interrupt + * is disabled at this point. */ buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; tx_fifo_avail -= words_to_transfer; i2c_dev->msg_buf_remaining = buf_remaining; i2c_dev->msg_buf = buf + words_to_transfer * BYTES_PER_FIFO_WORD; - barrier(); i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer); @@ -827,10 +826,8 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) memcpy(&val, buf, buf_remaining); val = le32_to_cpu(val); - /* Again update before writing to FIFO to make sure isr sees. */ i2c_dev->msg_buf_remaining = 0; i2c_dev->msg_buf = NULL; - barrier(); i2c_writel(i2c_dev, val, I2C_TX_FIFO); } From patchwork Tue Sep 8 22:39:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360195 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=GKaIGoW2; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKtc6Btsz9sSJ for ; Wed, 9 Sep 2020 08:43:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730449AbgIHWnU (ORCPT ); Tue, 8 Sep 2020 18:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730061AbgIHWkv (ORCPT ); Tue, 8 Sep 2020 18:40:51 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E7ADC0613ED; Tue, 8 Sep 2020 15:40:50 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id w3so979016ljo.5; Tue, 08 Sep 2020 15:40:50 -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=vt074qs5q9X80njl/qgMdrzDxZl3IE1TA/FY/LhUnus=; b=GKaIGoW2ALg97bdq3bg3fbgjtxZIIfMy/3fNOq9Q+poS4Q3CgXXiRA1TR760nAdfuS OLc9b8Zh8SWxLXgBr4+fOCKK9pwyZoW79ijM+pA9fx+rmP+KK9O0KQlQdqkNhbmiucus q1cPRANn44Hp68WIvImEJYwShTXv423IKm60kMqwdkSk0NCjxR4HSfHUybkOZJC1K23e vICJm0hKZHwovNFn2sRiBQm/XoRXLrO0rYKL27CizU5JRBPnpq3+Iu1roAwAYNXexoG3 ob3xajZ8muWsaxCz218eJ174JiQIvm1XawjnktYtmRoMplkeTdL4IAbv83YRlItgZuws ymQw== 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=vt074qs5q9X80njl/qgMdrzDxZl3IE1TA/FY/LhUnus=; b=JRIisf2BUqfKtM2xkLVAoUfU27Cewh07Rm3VfZ+xrYpaUEhxSd4hJtg9bRWCfus5At 5i3iKIO+fJoDVPssezOD17Ewb9/pRIfHo/xnObzY4kJjmwIgOLKwde8uvgyKby+1OrNe E8cxuMfNJGhAe0b7i94ka16eVbmElW3ambs06c8spkB+siDGnKj3en5pYVMfWg2/dmQp 6OQH8EN0AvbkNZCTOMB3LJdFKOC5ieWh1S2q1OHj8DliDYXJJIU1CXMgjdtve1bamIAE kqa6KCS6HgmKwfZbbZPzdfVwRyKBRW3ihTaET9gK3dTjj740/3mzEMjpkBDQsAZYJ+Zb IgxQ== X-Gm-Message-State: AOAM530vZbR1MG3YXYm/SLdto2T9P+Cq00879dV8Zi8CqDjAU4uv0rnK gvCQtW6vvEYWrZq5e7YCM84= X-Google-Smtp-Source: ABdhPJyFsMHjGA/jVCf2SfHIvrcVDY+xUHDE0CnTzJuUxwQNnvvSyBa5kOXPNYDSMBgxbLDh4ol5ew== X-Received: by 2002:a2e:6a16:: with SMTP id f22mr317724ljc.15.1599604849130; Tue, 08 Sep 2020 15:40:49 -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 s15sm268311ljp.25.2020.09.08.15.40.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:48 -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 v7 18/34] i2c: tegra: Remove likely/unlikely from the code Date: Wed, 9 Sep 2020 01:39:50 +0300 Message-Id: <20200908224006.25636-19-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The likely/unlikely annotations should be used only in a hot paths of performance-critical code. The I2C driver doesn't have such paths, and thus, there is no justification for usage of likely/unlikely annotations in the code. Hence remove them. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index ab83d1de6c94..fd0d51ec447f 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -852,7 +852,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) goto err; } - if (unlikely(status & status_err)) { + if (status & status_err) { tegra_i2c_disable_packet_mode(i2c_dev); if (status & I2C_INT_NO_ACK) i2c_dev->msg_err |= I2C_ERR_NO_ACK; @@ -1294,7 +1294,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->msg_err); i2c_dev->is_curr_dma_xfer = false; - if (likely(i2c_dev->msg_err == I2C_ERR_NONE)) + if (i2c_dev->msg_err == I2C_ERR_NONE) return 0; tegra_i2c_init(i2c_dev); From patchwork Tue Sep 8 22:39:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=XiARmRmb; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKvS5ffYz9sTN for ; Wed, 9 Sep 2020 08:44:04 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730438AbgIHWnT (ORCPT ); Tue, 8 Sep 2020 18:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729960AbgIHWkw (ORCPT ); Tue, 8 Sep 2020 18:40:52 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B31EC061786; Tue, 8 Sep 2020 15:40:51 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id y11so539436lfl.5; Tue, 08 Sep 2020 15:40:51 -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=OsS78V1q+vZh1E8rpIjUMymq1NkW9yJlg2YzWQ5yU2Q=; b=XiARmRmbnNZ4NWlQiTVVG4fosLLQzEeW7+ChTDquOEbbSmVRhwAVSagypkEzif7/A3 42qz7xjJJiTn+QWu5j8bhNN5HL5glhWp3D4LjX8aQOARYTtFZMK/nhoON1POQt0h5OyP KBUqihHu30MNyM+niFjPkb0OCYZKIRdALZHQC1D9FDZYy2hYEMvSN1rM/JMsHvK2as70 JT5+ElQFRlQiGNmdjmEiwLhUsFDR3GIEMPftRvRddATwiRIWpDfJlDP5wxaRXqrESGhz 9DGtokYICSJuPif7PGIM676yyyRPo+eycwbuSKYlJrcUZeu26X0+wOjjtwhMnKuv1sBs J8BA== 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=OsS78V1q+vZh1E8rpIjUMymq1NkW9yJlg2YzWQ5yU2Q=; b=K0Id2milbExfTpu3FftffVBG98vVwruQNhqXxCISfxwlkCDdewdoRux/CDXtpeBsW7 tyvthErqOPlQdcdAgcbilqBlSsD5Iw3DBLk/Z/y5PGrtOJ/PbpCm04amSlO1rNWXZPeb 8ZDuTLdLh9BfsRz8uQ9RYHYv/CyViYIgMN2nIKNbQejpWLjDBPAPPbDpDvVjOldraRX6 xFDK4oSA9TsN6sT95/VPgm682a2f2a8aSK/VSOG9aPMJWIhAYrFoxkzW+e1vIBEUEnv/ FiyB7ZyctOmGavw/G0FY3TZuhkp7+wVLj9OR3iujmqafKPR8NwB99J01GEKe4/32NFGQ 5vzw== X-Gm-Message-State: AOAM530LxJ2fwaI44yuAovCjXz0Wa+yPKk+UP9mdkviysiO9FhD8Cxse uBuG4uCSirPdrQ7Nt3qoVEo= X-Google-Smtp-Source: ABdhPJxebxvAnU369b/8BgvoNKzHmcKr5pAlLHT0O6e6oAf8IW0HtBDIFP7IsaumPhnZD6XtMEPH1Q== X-Received: by 2002:a19:644f:: with SMTP id b15mr537917lfj.136.1599604850110; Tue, 08 Sep 2020 15:40:50 -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 s15sm268311ljp.25.2020.09.08.15.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:49 -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 v7 19/34] i2c: tegra: Remove redundant check in tegra_i2c_issue_bus_clear() Date: Wed, 9 Sep 2020 01:39:51 +0300 Message-Id: <20200908224006.25636-20-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The tegra_i2c_wait_for_config_load() checks for 'has_config_load_reg' by itself, hence there is no need to duplicate the check. Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index fd0d51ec447f..18968302457f 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1082,11 +1082,10 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) reg = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND | I2C_BC_TERMINATE; i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); - if (i2c_dev->hw->has_config_load_reg) { - err = tegra_i2c_wait_for_config_load(i2c_dev); - if (err) - return err; - } + + err = tegra_i2c_wait_for_config_load(i2c_dev); + if (err) + return err; reg |= I2C_BC_ENABLE; i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); From patchwork Tue Sep 8 22:39:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360199 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=XkRAd9F1; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKvT1BH5z9sSJ for ; Wed, 9 Sep 2020 08:44:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730436AbgIHWnT (ORCPT ); Tue, 8 Sep 2020 18:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730067AbgIHWky (ORCPT ); Tue, 8 Sep 2020 18:40:54 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F4BFC061795; Tue, 8 Sep 2020 15:40:52 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id r24so1001184ljm.3; Tue, 08 Sep 2020 15:40:52 -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=G5sX0D1OOGjolxT/VG080HLXywGd79i8TKu1JUMhCA8=; b=XkRAd9F1VgWPvS2/GW8/trcBf50+hZYFTSm8Rirs/eHspSdeM+3DNhDf9Xyvr5WWIm IHspGfSm5rb52b34Jv8EReHJVpr7dE9/9PsT08RkcXxDgjDu5S/LllcioSJDZXTgOgzR SiztacyZvZvctlt+8ePCErl/umZaF42qOCfwph+stdHj9A9X/z4DAsWSi+xwQ+kgEKTf +YV50rXa3S8kRlCq0uxpMzfGYSkGCbV40U1W2pZ2bPPDgppCB3paJHIftQsm6WJU6XB9 dm0Me9nlDyL1oMIKBgGOULhbWaKsAXXUmNlYrgnBvV67iFuPMA8UBX6rNzUWlBs/w/Hk 6Jeg== 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=G5sX0D1OOGjolxT/VG080HLXywGd79i8TKu1JUMhCA8=; b=m8HsFJQf5JcCLxBCST7tblq823Z7A4Mu6aiFu2AnD0KUBmnVe7hFkJvUjMCsLXeWqw OLXcFwU4VS+8TZA4R2ZvBn6bsG1nnVYEGzAVtI14CykBE3Cu8J1pb3i0yYvg0uB93WpV 5KvNvtIcSV7TBntkMd6iUOknxuYpBZo3txdn27H2Dz4MdwuDJk2bIdy9pqTRTtpLluCn smrX4NFJIhc/L8LkfDOVlbf4JUAb5ukfL/MnATkuMxc2LiynNLD9y66Lpto0ilAqtvZ2 isCXtUC2uRqUi8BgNpe8dz5FnPi8qeRASSt1VXkHamZg+HscFHus2vbqk/43gUJFKYWG 9W4Q== X-Gm-Message-State: AOAM530kYSLdQuHLKfGBFpvvxctKGxx9q/Z+44jk5F1Ca0/asO2O4BHn 98mDKvYQj27IDnRFrpmERZg= X-Google-Smtp-Source: ABdhPJyJfoW9fgynm/YfnI2mSrvSutXG4zj6VNYGsqXkOWGyMyudaHftLwhgznSHQcFHK2VjcxV7CA== X-Received: by 2002:a05:651c:554:: with SMTP id q20mr378888ljp.348.1599604850960; Tue, 08 Sep 2020 15:40:50 -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 s15sm268311ljp.25.2020.09.08.15.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:50 -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 v7 20/34] i2c: tegra: Remove "dma" variable from tegra_i2c_xfer_msg() Date: Wed, 9 Sep 2020 01:39:52 +0300 Message-Id: <20200908224006.25636-21-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The "dma" variable of tegra_i2c_xfer_msg() function doesn't bring much in regards to readability and generation of the code. Besides readability, it's also not very nice that the is_curr_dma_xfer is initialized in tegra_i2c_xfer_msg() and then could be overridden by tegra_i2c_config_fifo_trig(). In a result, the "dma" variable creates slight confusion since it's not instantly obvious why it's set after tegra_i2c_config_fifo_trig(). Hence should be better to have the variable removed. This makes code more consistent. Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 18968302457f..76d3a05b10fc 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1120,7 +1120,6 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, size_t xfer_size; u32 *buffer = NULL; int err = 0; - bool dma; u16 xfer_time = 100; err = tegra_i2c_flush_fifos(i2c_dev); @@ -1143,7 +1142,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->dma_buf && !i2c_dev->is_curr_atomic_xfer; tegra_i2c_config_fifo_trig(i2c_dev, xfer_size); - dma = i2c_dev->is_curr_dma_xfer; + /* * Transfer time in mSec = Total bits / transfer rate * Total bits = 9 bits per byte (including ACK bit) + Start & stop bits @@ -1153,7 +1152,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; tegra_i2c_unmask_irq(i2c_dev, int_mask); - if (dma) { + if (i2c_dev->is_curr_dma_xfer) { if (i2c_dev->msg_read) { dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, @@ -1181,13 +1180,13 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, PACKET_HEADER0_PROTOCOL_I2C) | FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) | FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1); - if (dma && !i2c_dev->msg_read) + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) *buffer++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); packet_header = msg->len - 1; - if (dma && !i2c_dev->msg_read) + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) *buffer++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); @@ -1207,13 +1206,13 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, packet_header |= I2C_HEADER_CONT_ON_NAK; if (msg->flags & I2C_M_RD) packet_header |= I2C_HEADER_READ; - if (dma && !i2c_dev->msg_read) + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) *buffer++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); if (!i2c_dev->msg_read) { - if (dma) { + if (i2c_dev->is_curr_dma_xfer) { memcpy(buffer, msg->buf, msg->len); dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, @@ -1233,7 +1232,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (i2c_dev->hw->has_per_pkt_xfer_complete_irq) int_mask |= I2C_INT_PACKET_XFER_COMPLETE; - if (!dma) { + if (!i2c_dev->is_curr_dma_xfer) { if (msg->flags & I2C_M_RD) int_mask |= I2C_INT_RX_FIFO_DATA_REQ; else if (i2c_dev->msg_buf_remaining) @@ -1244,7 +1243,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, dev_dbg(i2c_dev->dev, "unmasked irq: %02x\n", i2c_readl(i2c_dev, I2C_INT_MASK)); - if (dma) { + if (i2c_dev->is_curr_dma_xfer) { time_left = tegra_i2c_wait_completion_timeout( i2c_dev, &i2c_dev->dma_complete, xfer_time); From patchwork Tue Sep 8 22:39:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360201 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=rnVd4cTb; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKvV167qz9sSJ for ; Wed, 9 Sep 2020 08:44:06 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730430AbgIHWnT (ORCPT ); Tue, 8 Sep 2020 18:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730073AbgIHWky (ORCPT ); Tue, 8 Sep 2020 18:40:54 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5995AC061796; Tue, 8 Sep 2020 15:40:53 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id n25so991600ljj.4; Tue, 08 Sep 2020 15:40:53 -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=cXVjQ8tBGvi88Q3dqadI+S4l2h32UDxPkNgdMyWN/ps=; b=rnVd4cTbVh+Phcmm/EYwb9cJVGctt7NC8DOpLYHkyc1borSEi69laZ1mriUqX8djX7 Sc0PYukYR6x+s+ja5IjDNwcXL+tnRdYzEnX/kBXSnfMRteZt/En0WnXL0LtSg+bd+7yn Q6p6APAe5wQlNg1q1xaqewY+xmfVTZRAZr7b4mOfY7xWKjYfovBbcB5gvnybj0BY7N4W ZVlphs36JksqqVhWMv7euMetE6U2bqCz0x5m9d/GYJ1izka0rjz7vI/s2Dsdi9vmbnXz p9uY2g0GGiYeHJrxW8pHQdtEL2wAy+tfc9AcdCCfQJqps5/Fz+wW5AM6nToMYGIou+rT GYSg== 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=cXVjQ8tBGvi88Q3dqadI+S4l2h32UDxPkNgdMyWN/ps=; b=Txl6qqnBw5GLWgKunmQKXzFeNwYwGsGEE6X6HytpJZFw//sZYivLC/Y13C+TPIrAO7 JiXu0rCVaOS2d7xj85chDNUAU8sNSS2v9/S2FZRyL7h053d/fibGRe1/BRq5JKLaQbHP HQ2UILD0xEq/3AKVoeeaxTwBHNc3Y99pOM1ekUGspnSfpGgnL0iHUp9RkkqAA+Ue9ANr BpxbLFRuXOJ+dclscagBn47xrcYG4R/6tH5A3ZxhF3BFNmUbBJcKCLbefpcRUqY/JGiT jFfIfIkSB85c7AG7277/PSe4XT4bCBK3Lq92DxYYXYb5cNLoP3CqadfcLzUh8XK77N8j 7CPA== X-Gm-Message-State: AOAM530zSgr/tNC4zdG/M2Ey76MGAjNiTgYRi8Ekx9/hjCUmVlaIWyay aUVnWv4RM2H8mvCUM5DtyFA= X-Google-Smtp-Source: ABdhPJy3yGatK4uH7DrsKjp72dQFgAXBSdPTKTAcfPVTfHIiN54fn/KrFv5JgZthCrJsELBBKQUxlg== X-Received: by 2002:a2e:b5d9:: with SMTP id g25mr319707ljn.335.1599604851862; Tue, 08 Sep 2020 15:40:51 -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 s15sm268311ljp.25.2020.09.08.15.40.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:51 -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 v7 21/34] i2c: tegra: Don't fall back to PIO mode if DMA configuration fails Date: Wed, 9 Sep 2020 01:39:53 +0300 Message-Id: <20200908224006.25636-22-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The DMA code path has been tested well enough and the DMA configuration performed by tegra_i2c_config_fifo_trig() shouldn't ever fail in practice. Hence let's remove the obscure transfer-mode switching in order to have a cleaner and simpler code. Now I2C transfer will be failed if DMA configuration fails. Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 76d3a05b10fc..574b59a8b2a2 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -940,8 +940,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) return IRQ_HANDLED; } -static void tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, - size_t len) +static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) { u32 val, reg; u8 dma_burst; @@ -992,12 +991,10 @@ static void tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, if (ret < 0) { dev_err(i2c_dev->dev, "DMA slave config failed: %d\n", ret); - dev_err(i2c_dev->dev, "falling back to PIO\n"); - tegra_i2c_release_dma(i2c_dev); - i2c_dev->is_curr_dma_xfer = false; - } else { - goto out; + return ret; } + + goto out; } if (i2c_dev->hw->has_mst_fifo) @@ -1008,6 +1005,8 @@ static void tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, I2C_FIFO_CONTROL_RX_TRIG(1); out: i2c_writel(i2c_dev, val, reg); + + return 0; } static unsigned long @@ -1141,7 +1140,10 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->is_curr_dma_xfer = (xfer_size > I2C_PIO_MODE_PREFERRED_LEN) && i2c_dev->dma_buf && !i2c_dev->is_curr_atomic_xfer; - tegra_i2c_config_fifo_trig(i2c_dev, xfer_size); + + err = tegra_i2c_config_fifo_trig(i2c_dev, xfer_size); + if (err) + return err; /* * Transfer time in mSec = Total bits / transfer rate From patchwork Tue Sep 8 22:39:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ftT9thJu; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKt84NvCz9sT6 for ; Wed, 9 Sep 2020 08:42:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730376AbgIHWmz (ORCPT ); Tue, 8 Sep 2020 18:42:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730085AbgIHWlC (ORCPT ); Tue, 8 Sep 2020 18:41:02 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35E4BC061755; Tue, 8 Sep 2020 15:40:54 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id k25so1014175ljk.0; Tue, 08 Sep 2020 15:40:54 -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=CAzw7V00TNX6Xyj54SjfhvDwqPQuqQxiXL39qRNRLzs=; b=ftT9thJu9ax+chR6bmG+7u1BCWASWmnn+8ql9OmEf7QAkMrHCH+IQFr66NGK60H7jR C5elwkJ6bPKXEodeUVOi/tDAIu99OaUNJSjOYcHtoYyTEoRqQhZA/o1ZmjB3Dd/JyAoi R38DT4MThF66FcgBzrA8Hjozrxm/7UPjuVRdXhl7xHB90MzSn2TjRrHOEBjIurJl+ZSa RWuiD+fDiWeW/Fvq1D7u/gdaxBq0qf9R+Nb1+WEdfBwRUjTmCDKEHypv16/r7MJXPk00 gXvZ5vT5RpZX7nRUvYuGgMcg2cZocgCCfZ5z76zKNWmnF6ym62NrhC+10EDLKB1O6jU0 IgPw== 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=CAzw7V00TNX6Xyj54SjfhvDwqPQuqQxiXL39qRNRLzs=; b=P0OfAnDI5f3Bm/hcDxMM6T1EA+hjAiZ1JMw+Haq2jwCyvHtu3zzYc3QrUcijeX/inq +pXxE1sPon02FaNanicsENnDXmuWQdIq6pEyN6knDYT0sEyn5vkgwCOA/e1VdsGizZDe Rfog3acHrYb6pIYptpc3DkLkj8P0OqzGeBSDuqe89njJWQ2Z+AHvNyE2tG6Rht7D/+3s yHecIOD5oCQEU7T4Fm8pvjPHPUvXXglJ0LsYIhj6XFMzafo+5bItd5zl+reH8y95kSqV RqaRw2eeDT7+zsESMG7WWngGARRkJocZE+57qn7C2P9BLdwnLE+E8bnadxnEY357zTeX HtZg== X-Gm-Message-State: AOAM530iR99RJXKAu6kpm77pu2cCfhwRDVm4n+Fg8jSPmMn2slyqWoK5 zOODqz9KGv6OfaNruTnr+JeVp7d9ifc= X-Google-Smtp-Source: ABdhPJyhcVugkgOesde5UMymh8sGKlbpJo+aamGHMiWT1mnPqIi4H0hovaA8T6mTPcRpv7DyVZj8zQ== X-Received: by 2002:a2e:4554:: with SMTP id s81mr361302lja.121.1599604852679; Tue, 08 Sep 2020 15:40:52 -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 s15sm268311ljp.25.2020.09.08.15.40.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:52 -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 v7 22/34] i2c: tegra: Rename wait/poll functions Date: Wed, 9 Sep 2020 01:39:54 +0300 Message-Id: <20200908224006.25636-23-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Drop '_timeout' postfix from the wait/poll completion function names in order to make the names shorter, making code cleaner a tad. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 574b59a8b2a2..102d26c01dff 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1009,10 +1009,9 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) return 0; } -static unsigned long -tegra_i2c_poll_completion_timeout(struct tegra_i2c_dev *i2c_dev, - struct completion *complete, - unsigned int timeout_ms) +static unsigned long tegra_i2c_poll_completion(struct tegra_i2c_dev *i2c_dev, + struct completion *complete, + unsigned int timeout_ms) { ktime_t ktime = ktime_get(); ktime_t ktimeout = ktime_add_ms(ktime, timeout_ms); @@ -1036,16 +1035,14 @@ tegra_i2c_poll_completion_timeout(struct tegra_i2c_dev *i2c_dev, return 0; } -static unsigned long -tegra_i2c_wait_completion_timeout(struct tegra_i2c_dev *i2c_dev, - struct completion *complete, - unsigned int timeout_ms) +static unsigned long tegra_i2c_wait_completion(struct tegra_i2c_dev *i2c_dev, + struct completion *complete, + unsigned int timeout_ms) { unsigned long ret; if (i2c_dev->is_curr_atomic_xfer) { - ret = tegra_i2c_poll_completion_timeout(i2c_dev, complete, - timeout_ms); + ret = tegra_i2c_poll_completion(i2c_dev, complete, timeout_ms); } else { enable_irq(i2c_dev->irq); ret = wait_for_completion_timeout(complete, @@ -1063,8 +1060,7 @@ tegra_i2c_wait_completion_timeout(struct tegra_i2c_dev *i2c_dev, * needs to be checked after timeout. */ if (ret == 0) - ret = tegra_i2c_poll_completion_timeout(i2c_dev, - complete, 0); + ret = tegra_i2c_poll_completion(i2c_dev, complete, 0); } return ret; @@ -1090,8 +1086,7 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); tegra_i2c_unmask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); - time_left = tegra_i2c_wait_completion_timeout( - i2c_dev, &i2c_dev->msg_complete, 50); + time_left = tegra_i2c_wait_completion(i2c_dev, &i2c_dev->msg_complete, 50); tegra_i2c_mask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); if (time_left == 0) { @@ -1246,8 +1241,9 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_readl(i2c_dev, I2C_INT_MASK)); if (i2c_dev->is_curr_dma_xfer) { - time_left = tegra_i2c_wait_completion_timeout( - i2c_dev, &i2c_dev->dma_complete, xfer_time); + time_left = tegra_i2c_wait_completion(i2c_dev, + &i2c_dev->dma_complete, + xfer_time); /* * Synchronize DMA first, since dmaengine_terminate_sync() @@ -1278,8 +1274,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, } } - time_left = tegra_i2c_wait_completion_timeout( - i2c_dev, &i2c_dev->msg_complete, xfer_time); + time_left = tegra_i2c_wait_completion(i2c_dev, &i2c_dev->msg_complete, + xfer_time); tegra_i2c_mask_irq(i2c_dev, int_mask); From patchwork Tue Sep 8 22:39:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=BReUNAOT; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKt93KpHz9sT6 for ; Wed, 9 Sep 2020 08:42:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730380AbgIHWm4 (ORCPT ); Tue, 8 Sep 2020 18:42:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730092AbgIHWlC (ORCPT ); Tue, 8 Sep 2020 18:41:02 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15F71C061797; Tue, 8 Sep 2020 15:40:55 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id k25so952902ljg.9; Tue, 08 Sep 2020 15:40:55 -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=S+lQblIYfMC0xoCVoTRie/3/bKbUPeIIfvh4Qt7sKEM=; b=BReUNAOTlJ4hBKM8LA0UIHTP/4IFUyCKrrkLbmFXhldyy98NTypenEo9AFp3kr4Ey5 aAmsLKaR2esoCEqYRMOtqYmXPx2DvFloqQozmnYQzZ2LHWhCZvrWZsW6xRZx/HtvZBHY 0DgOEhvyR7t1+BhRRwb4sIQfYWO0shB/wSj9Co6omVM8n99qN+GG8P/uKzUoUxiW4/Ai AiifHlyL7oeOVMlGO0iFxbAXyCQdgtPMAfTDPPC8N6MjKUjkzS63P5G7d8hj6cnrbeAR e4Pl4GSmb+UE6xZIz2oMTDiBz2Z63GJg1tVnP/u3LCsZdowKfiAp3y6OM3UDtsb9NXqY DgnQ== 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=S+lQblIYfMC0xoCVoTRie/3/bKbUPeIIfvh4Qt7sKEM=; b=Gpt6LjkIgZzNyJOlX4+/ilVELw71iRqpHrz82fMKZ3rTtaW2p3Klh1FDja5SKZw/Ou fnAjYKmKWzKCJZhmzQJLzUo2ruciiyNwZKTN5vN1jpDdPnIDO1WmeFVb3ktUos7tI4it ixcB2AzZM/ibrY+dw+m0YQdA4r9V7IyEp9SIPu2nZMyLwZV8mEH13euCtv8LrcoC0FQw EnEquXYW35g11/vdog5MavM/teyojdBaYigOjIg27Etqw7+1CM2tsaCgpcs4iPwv/tUY miSrF9odp5FwKf+iuVLagM4h+r7WVmuy/DYPKgKezTtFUR0WcDIAB2PdrM4vecIfOHfg 9RDQ== X-Gm-Message-State: AOAM530Xl10Zg1JeCthCiOC30nt05D0HRim4+Zm2oF6H81kEBHFVbgCp VRgv1tN0BkbXGvJ3AX8OafM= X-Google-Smtp-Source: ABdhPJzHj/rYs+ujEiyukjCmncUFWTHbyN0yNFjNW+CTHM1nEdl7kZi7vOkIIJT8+GB/YseJbVJwYQ== X-Received: by 2002:a2e:7d0e:: with SMTP id y14mr337450ljc.254.1599604853524; Tue, 08 Sep 2020 15:40:53 -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 s15sm268311ljp.25.2020.09.08.15.40.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:53 -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 v7 23/34] i2c: tegra: Factor out error recovery from tegra_i2c_xfer_msg() Date: Wed, 9 Sep 2020 01:39:55 +0300 Message-Id: <20200908224006.25636-24-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@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 Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- 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 102d26c01dff..1ec2490d06ac 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1104,6 +1104,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) @@ -1290,24 +1316,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[], From patchwork Tue Sep 8 22:39:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=aql52p9i; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKsm1NZyz9sTK for ; Wed, 9 Sep 2020 08:42:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730179AbgIHWmW (ORCPT ); Tue, 8 Sep 2020 18:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730111AbgIHWlI (ORCPT ); Tue, 8 Sep 2020 18:41:08 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32C3FC061799; Tue, 8 Sep 2020 15:40:56 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id a15so1003388ljk.2; Tue, 08 Sep 2020 15:40:55 -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=52FpCY19v8txNVEIA3tvXS78M6BS9WeMsOxp4mspQSw=; b=aql52p9iNKhvSMl82dfDyHZ2rhbVlh6n4zYpf90JB8J1HePXzT9kwXtMKsd2gCraxU bXJbtm7CbumdRk/3RCS6cuHCB+VjjX7Kf7KdXOX9DE1mgPs58M1zGJFy1u7wd8uXfYDI IttGjjnRQyZVv0+9vP0KYc2UQHW88lHTP+dEKcmeEOmk7+nsJpnA4qVbyIWJ6xiKrFQW K+D3jXOmr11MwVrfIvhArxBOaMdoXN0rSz7e2rrjlBQe3BYRQrjGitoNk9Rggx4JCQNI nPoaH5rbUXACAar8bSKT+uCbmq7y46P7MtdDdwmGq8TxUbL7lU9HTmQ+ZjkwbzkiRgat h4YA== 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=52FpCY19v8txNVEIA3tvXS78M6BS9WeMsOxp4mspQSw=; b=qTC+Jzwp8sWWAt57i8lVaOHhsL01LSK31jPEVcRQOw6aTHyIMoqFzTnBI0TmVZQGYW qLevEpnF3zFBNanfsR29t1dhfYCIQEbc8sjw7/THtNFRELJJFm5SvsrbL116kyCJCP+l 6yZRIY8IR5S+ABoEOa2Y8pdRtxSih6V0hsyaIQ/BHIyMkVvDi9B9Q7eq2s9E5SO4l5SF uj/katP0Ft3F+/Yb8ClzkGjcxp5GoajHSBjNDiZvZ3vRJfxSniA6xiLyjGnVeZGMra7H XOpXJDuB16P1UPNGc//kuESfKc7KMC21y5LJ0+w8exBblrOHI/+7wE44p+3ytl3F/EGp i1sw== X-Gm-Message-State: AOAM532bI18P+HUjE4+LZRazj7hFpT++rFON1zrnoi0x4Fd2b1l2MwFw ktVBmmsyesl0kOx+d92fjlU= X-Google-Smtp-Source: ABdhPJzWwQmS67ElTp2lV9Kz4kvfcMOxw8MOyLQYV/PDWhi42h9MB1/PCcFgDbCK7gvpUd5qtWdZGw== X-Received: by 2002:a2e:3615:: with SMTP id d21mr368647lja.111.1599604854421; Tue, 08 Sep 2020 15:40:54 -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 s15sm268311ljp.25.2020.09.08.15.40.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:54 -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 v7 24/34] i2c: tegra: Factor out packet header setup from tegra_i2c_xfer_msg() Date: Wed, 9 Sep 2020 01:39:56 +0300 Message-Id: <20200908224006.25636-25-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The code related to packet header setting up is a bit messy and makes tegra_i2c_xfer_msg() more difficult to read than it could be. Let's factor the packet header setup from tegra_i2c_xfer_msg() into separate function in order to make code easier to read and follow. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 92 ++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 1ec2490d06ac..405b87e28a98 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1104,6 +1104,57 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) return -EAGAIN; } +static void tegra_i2c_push_packet_header(struct tegra_i2c_dev *i2c_dev, + struct i2c_msg *msg, + enum msg_end_type end_state) +{ + u32 *dma_buf = i2c_dev->dma_buf; + u32 packet_header; + + packet_header = FIELD_PREP(PACKET_HEADER0_HEADER_SIZE, 0) | + FIELD_PREP(PACKET_HEADER0_PROTOCOL, + PACKET_HEADER0_PROTOCOL_I2C) | + FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) | + FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1); + + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + *dma_buf++ = packet_header; + else + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); + + packet_header = msg->len - 1; + + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + *dma_buf++ = packet_header; + else + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); + + packet_header = I2C_HEADER_IE_ENABLE; + + if (end_state == MSG_END_CONTINUE) + packet_header |= I2C_HEADER_CONTINUE_XFER; + else if (end_state == MSG_END_REPEAT_START) + packet_header |= I2C_HEADER_REPEAT_START; + + if (msg->flags & I2C_M_TEN) { + packet_header |= msg->addr; + packet_header |= I2C_HEADER_10BIT_ADDR; + } else { + packet_header |= msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT; + } + + if (msg->flags & I2C_M_IGNORE_NAK) + packet_header |= I2C_HEADER_CONT_ON_NAK; + + if (msg->flags & I2C_M_RD) + packet_header |= I2C_HEADER_READ; + + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + *dma_buf++ = packet_header; + else + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); +} + static int tegra_i2c_error_recover(struct tegra_i2c_dev *i2c_dev, struct i2c_msg *msg) { @@ -1134,11 +1185,9 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, struct i2c_msg *msg, enum msg_end_type end_state) { - u32 packet_header; u32 int_mask; unsigned long time_left; size_t xfer_size; - u32 *buffer = NULL; int err = 0; u16 xfer_time = 100; @@ -1194,49 +1243,14 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->dma_phys, xfer_size, DMA_TO_DEVICE); - buffer = i2c_dev->dma_buf; } } - packet_header = FIELD_PREP(PACKET_HEADER0_HEADER_SIZE, 0) | - FIELD_PREP(PACKET_HEADER0_PROTOCOL, - PACKET_HEADER0_PROTOCOL_I2C) | - FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) | - FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1); - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) - *buffer++ = packet_header; - else - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); - - packet_header = msg->len - 1; - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) - *buffer++ = packet_header; - else - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); - - packet_header = I2C_HEADER_IE_ENABLE; - if (end_state == MSG_END_CONTINUE) - packet_header |= I2C_HEADER_CONTINUE_XFER; - else if (end_state == MSG_END_REPEAT_START) - packet_header |= I2C_HEADER_REPEAT_START; - if (msg->flags & I2C_M_TEN) { - packet_header |= msg->addr; - packet_header |= I2C_HEADER_10BIT_ADDR; - } else { - packet_header |= msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT; - } - if (msg->flags & I2C_M_IGNORE_NAK) - packet_header |= I2C_HEADER_CONT_ON_NAK; - if (msg->flags & I2C_M_RD) - packet_header |= I2C_HEADER_READ; - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) - *buffer++ = packet_header; - else - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); + tegra_i2c_push_packet_header(i2c_dev, msg, end_state); if (!i2c_dev->msg_read) { if (i2c_dev->is_curr_dma_xfer) { - memcpy(buffer, msg->buf, msg->len); + memcpy(i2c_dev->dma_buf, msg->buf, msg->len); dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, xfer_size, From patchwork Tue Sep 8 22:39:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=TtvybQnK; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKt50Vmbz9sSJ for ; Wed, 9 Sep 2020 08:42:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729212AbgIHWmi (ORCPT ); Tue, 8 Sep 2020 18:42:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730108AbgIHWlI (ORCPT ); Tue, 8 Sep 2020 18:41:08 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1B71C06179A; Tue, 8 Sep 2020 15:40:56 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id w3so979228ljo.5; Tue, 08 Sep 2020 15:40:56 -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=iEbcroyclPM32znD3jMsfQr6kaGo31473mKkTmIRL3k=; b=TtvybQnKNTkOTqeMDWzeYdDuUNQwSqwrgxOU9V6VVMpg+ncyAdGg9CQvAm7vhcRQTA V3dzCclsnhxHAAk6WoMr11ZqZvxRba48k7+78ydg9QgIfHbbtRXGxWPv/MEkQ+XnNDwF XfpqRIoNb5/w8XTUZIR0D6zvs9SPEtXc9fkGQKYp8ARDeC5vH2UASIlB3ZgUkwUK4AAs gX8ILbv4umDnSnt3usO8Jgo6/x3yb2UzljnzMis0yexku/mRX6GBUKQO5oIp2KZEdI9e feUT8V+zgyu2JFV1xg26P6pSCGqqrYFyGE2RwP98tC2HYcJuF60yfCJA7Xf9fWLJQe1e tFCg== 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=iEbcroyclPM32znD3jMsfQr6kaGo31473mKkTmIRL3k=; b=iddGFpqeErQckeTKviOReONyD4zDzfLnX1TMRyusQfrdFBgHC+S4x8WxCwmN2C4MJH VAtkfd4xWRy7Qd8UeVCw13Jg06L1ULxNTeT1GC8fQUFbeHjYU2EBOD/9rqvhquRsKloS erxPaiz3ugSRjy81IatNZzlYNHCALofHUqTR2fFuZZJsF6cPAyybrm4qGQBXFiBkLjfG I+ldtOY/7Sl1lLGLYY+Ny9chBaKFdoW6orJqjwgdka60zMSk+PpK+wJNVfkVOD5V5lol H/Hm0fbcSBb71TIPmOb2Mh72f2LHZfCr5bRVt+hcQd3+FxCAA8N7L52LtlRt3VFNkA+z iv7A== X-Gm-Message-State: AOAM533VA6inbhjopw0eyinjWX/lGoDraXC53w5g49Xmkz/4kVlp70lg spRJq7nipEdwn/zfmB6dG14= X-Google-Smtp-Source: ABdhPJwn6x5X9YiCCGO045+Nb42EaST+kxZacnsQFgL87zY1QRSS9fNmyVXBwllYquq3bMMNET50vA== X-Received: by 2002:a2e:6f1c:: with SMTP id k28mr320416ljc.297.1599604855373; Tue, 08 Sep 2020 15:40:55 -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 s15sm268311ljp.25.2020.09.08.15.40.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:54 -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 v7 25/34] i2c: tegra: Factor out register polling into separate function Date: Wed, 9 Sep 2020 01:39:57 +0300 Message-Id: <20200908224006.25636-26-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Factor out register polling into a separate function in order to remove boilerplate code and make code cleaner. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding Reviewed-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 57 +++++++++++++++------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 405b87e28a98..e071de9ce106 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -514,10 +514,24 @@ static void tegra_i2c_vi_init(struct tegra_i2c_dev *i2c_dev) i2c_writel(i2c_dev, 0x0, I2C_TLOW_SEXT); } +static int tegra_i2c_poll_register(struct tegra_i2c_dev *i2c_dev, + u32 reg, u32 mask, u32 delay_us, + u32 timeout_us) +{ + void __iomem *addr = i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg); + u32 val; + + if (!i2c_dev->is_curr_atomic_xfer) + return readl_relaxed_poll_timeout(addr, val, !(val & mask), + delay_us, timeout_us); + + return readl_relaxed_poll_timeout_atomic(addr, val, !(val & mask), + delay_us, timeout_us); +} + static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) { - u32 mask, val, offset, reg_offset; - void __iomem *addr; + u32 mask, val, offset; int err; if (i2c_dev->hw->has_mst_fifo) { @@ -534,16 +548,7 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) val |= mask; i2c_writel(i2c_dev, val, offset); - reg_offset = tegra_i2c_reg_addr(i2c_dev, offset); - addr = i2c_dev->base + reg_offset; - - if (i2c_dev->is_curr_atomic_xfer) - err = readl_relaxed_poll_timeout_atomic(addr, val, !(val & mask), - 1000, 1000000); - else - err = readl_relaxed_poll_timeout(addr, val, !(val & mask), - 1000, 1000000); - + err = tegra_i2c_poll_register(i2c_dev, offset, mask, 1000, 1000000); if (err) { dev_err(i2c_dev->dev, "failed to flush FIFO\n"); return err; @@ -553,30 +558,18 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) { - unsigned long reg_offset; - void __iomem *addr; - u32 val; int err; - if (i2c_dev->hw->has_config_load_reg) { - reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_CONFIG_LOAD); - addr = i2c_dev->base + reg_offset; - i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD); + if (!i2c_dev->hw->has_config_load_reg) + return 0; - if (i2c_dev->is_curr_atomic_xfer) - err = readl_relaxed_poll_timeout_atomic( - addr, val, val == 0, 1000, - I2C_CONFIG_LOAD_TIMEOUT); - else - err = readl_relaxed_poll_timeout( - addr, val, val == 0, 1000, - I2C_CONFIG_LOAD_TIMEOUT); + i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD); - if (err) { - dev_warn(i2c_dev->dev, - "timeout waiting for config load\n"); - return err; - } + err = tegra_i2c_poll_register(i2c_dev, I2C_CONFIG_LOAD, 0xffffffff, + 1000, I2C_CONFIG_LOAD_TIMEOUT); + if (err) { + dev_warn(i2c_dev->dev, "timeout waiting for config load\n"); + return err; } return 0; From patchwork Tue Sep 8 22:39:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=aZ1HvNn9; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKsq3FRgz9sTK for ; Wed, 9 Sep 2020 08:42:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728350AbgIHWmh (ORCPT ); Tue, 8 Sep 2020 18:42:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730099AbgIHWlI (ORCPT ); Tue, 8 Sep 2020 18:41:08 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3CE6C06179B; Tue, 8 Sep 2020 15:40:57 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id y4so960110ljk.8; Tue, 08 Sep 2020 15:40:57 -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=xsrTDZsPANlBlVqC91x6N4Fz7EajBgNDYNawxzVHs1M=; b=aZ1HvNn97AouC9BNqcj+//07v+vLdVTMKB1MPiWaEgS6q3G3ENI/b0G13/GaS+La88 lqMkDHI12IO9wV/X87bTC5kk7Nwa5CeCeqJWAHHJM/4XgtrW01bSJw32t2zBT5ZLJkKB qY/zdRnyhaegsEU69ZKCHfVQXAzsCcHsYP6XxOUA5w83olb4bE+whzL2nfmGXl32IAcI TBNgDxmpEZZzzs6QfqAkDd3Pnd5t4N9QH7jXj8brtVpKHnO3SDVZaP/QHxR2DvobnYFI /Ul7TeYUWWgRvMc+aq0wTgE16TwGWdAPisEDHE8eu0V9xLFJlTSJgw2LOI4Yg4cI5Ao4 1e2Q== 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=xsrTDZsPANlBlVqC91x6N4Fz7EajBgNDYNawxzVHs1M=; b=LVPmN45uK6fSGbir5QGMWlAmyxqx7xnCn7VFrlzNcqM0Y7UTzbc+hysHYcdDvGp4vx 7CWjn7VbWny+cN9+eSNg9+Q3MQzJ/nOT3lip/lPoOeV8s0O1Tkf+7PluaG3U7RGOA+Pb yP9RKomfHYrk6fzJFvIyzANGVZJA99jltRnV9+RtzBFcGHfC+KtjpZ/dzDgEwBfidZ6J VuylgETMFO+76MeAF0iRINdCwqdtUUh9RRfwfWlnfTsjD9luU8HCIifD2E7KAdnMzeXU 36vIMZqswOFOgB5q9dHRyyTzWMOH/BCuQmIZlnjOGznw8nVi/AwIo+5gVGgbNbJK+zt0 VpvA== X-Gm-Message-State: AOAM532SlRrpFEiGYtwtdh0d+8KoVq9T58JjGo6DuUft6aTxT8GZGDS1 KPxILI1HSKS8YXrWe3iNdKs= X-Google-Smtp-Source: ABdhPJzOF9qWatisc3SQjVSmEAQV1LFLrz69M4S6yh2DkDrU1u6q8kdAvdOHN07hNMZdrqi3OVGeVQ== X-Received: by 2002:a2e:93cd:: with SMTP id p13mr364352ljh.460.1599604856207; Tue, 08 Sep 2020 15:40:56 -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 s15sm268311ljp.25.2020.09.08.15.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:55 -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 v7 26/34] i2c: tegra: Factor out hardware initialization into separate function Date: Wed, 9 Sep 2020 01:39:58 +0300 Message-Id: <20200908224006.25636-27-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Factor out hardware initialization into a separate function from the probe function. The only place where runtime PM needs to be resumed during probe is the place of hardware initialization, hence it makes sense to factor out it in order to have a bit cleaner error handling in tegra_i2c_probe(). Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index e071de9ce106..2f39366b6d55 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1661,9 +1661,23 @@ static void tegra_i2c_release_clocks(struct tegra_i2c_dev *i2c_dev) clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks); } +static int tegra_i2c_init_hardware(struct tegra_i2c_dev *i2c_dev) +{ + int ret; + + ret = pm_runtime_get_sync(i2c_dev->dev); + if (ret < 0) + dev_err(i2c_dev->dev, "runtime resume failed: %d\n", ret); + else + ret = tegra_i2c_init(i2c_dev); + + pm_runtime_put(i2c_dev->dev); + + return ret; +} + static int tegra_i2c_probe(struct platform_device *pdev) { - struct device *dev = &pdev->dev; struct tegra_i2c_dev *i2c_dev; struct resource *res; int ret; @@ -1729,15 +1743,10 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (!i2c_dev->is_vi) pm_runtime_irq_safe(&pdev->dev); pm_runtime_enable(&pdev->dev); - ret = pm_runtime_get_sync(i2c_dev->dev); - if (ret < 0) { - dev_err(dev, "runtime resume failed\n"); - goto put_rpm; - } - ret = tegra_i2c_init(i2c_dev); + ret = tegra_i2c_init_hardware(i2c_dev); if (ret) - goto put_rpm; + goto release_rpm; i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); i2c_dev->adapter.dev.of_node = pdev->dev.of_node; @@ -1758,14 +1767,11 @@ static int tegra_i2c_probe(struct platform_device *pdev) ret = i2c_add_numbered_adapter(&i2c_dev->adapter); if (ret) - goto put_rpm; - - pm_runtime_put(&pdev->dev); + goto release_rpm; return 0; -put_rpm: - pm_runtime_put_sync(&pdev->dev); +release_rpm: pm_runtime_disable(&pdev->dev); tegra_i2c_release_dma(i2c_dev); From patchwork Tue Sep 8 22:39:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=HHLAh3c4; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKt81HW5z9sSJ for ; Wed, 9 Sep 2020 08:42:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730369AbgIHWmz (ORCPT ); Tue, 8 Sep 2020 18:42:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730115AbgIHWlI (ORCPT ); Tue, 8 Sep 2020 18:41:08 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A22BC06179E; Tue, 8 Sep 2020 15:40:58 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id a15so1003494ljk.2; Tue, 08 Sep 2020 15:40: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=t5B6ysa7LjN/iHtlHoBH00Loul7JOotcYLDG2pE2B3U=; b=HHLAh3c4kVDtHud7bBCoc46guztvJ3zdyscQeEZy+Gf6FSRbdxhgpSjkQoDV7pt1Xu NaqYHUXS82yPuFmwVBXKY+02cDxE67TmDSsxYYk0pQtR2L1I6gzhtFOdtdYt45aw+y+B RZLg6hFJQaKLELyVxmxVMCics2Wz3HbBIdX+usPTujyCAmuwNQetPCkZN3WSxll0XdYk /g5RUvKifbWnKAl8U7xhBbfzmDasDCzLVAT490Cphyir3v09nnUOa1IXrEBUj47Jsl8q l571jX1WqerxXHCB1krrGL/bKbdnK9mYGjI+AedoSzTpc+tUA7ihKlArtVlpZgY/ugJe JsTQ== 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=t5B6ysa7LjN/iHtlHoBH00Loul7JOotcYLDG2pE2B3U=; b=UkJmExcsHq6lpiCtO2DXH4U72/G550s1ukYKfJEQ12ENfrdeP4nISvVpv61QeSU2q8 dfTGIQV66xI6KTPeqq7rt76yvXOG/xdRViVggNlCAnJjzMMwQ0YLx82+Azz+qJLbxuls u7cl1YfaGZyZIcKae0FfLSCbSEMvmTg14grA9mAUGM5kOZE3z3/Jc03cO4QmthuCbhCF 2zMsZuPkRAwG+cqAi99CXKTemqJl868VQi7LjEmGVv5ZdIoveOAlhFoZ7Rw7VxLWDLf/ LVch2thX9ZjqOpYP7vtQdt/jb/NnMp5KOpzS2On1hTf3KKxP+zBfwohQI0P8qzRG6svD F2vw== X-Gm-Message-State: AOAM532XM7krRpqZbTyFQzO1hVD6+vFU4vmTBBXvK49GjRTY5vmxZLIB bSGYl7AmCaBHkMpcFyH1h13M4PnN34M= X-Google-Smtp-Source: ABdhPJw+agA+k4JlD3PPK/iBNjFyQOinKeXX6tv4eYz6XiCqt6dFSa77U58OrOl28+AiefObVIv9yw== X-Received: by 2002:a2e:8681:: with SMTP id l1mr341010lji.108.1599604857092; Tue, 08 Sep 2020 15:40: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 s15sm268311ljp.25.2020.09.08.15.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40: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 v7 27/34] i2c: tegra: Check errors for both positive and negative values Date: Wed, 9 Sep 2020 01:39:59 +0300 Message-Id: <20200908224006.25636-28-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The driver's code is inconsistent in regards to the error values checking. The correct way should be to check both positive and negative values. This patch cleans up the error-checks in the code. Note that the pm_runtime_get_sync() could return positive value on success, hence only relevant parts of the code are changed by this patch. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 2f39366b6d55..fe672cfebe12 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -981,7 +981,7 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) slv_config.device_fc = true; ret = dmaengine_slave_config(chan, &slv_config); - if (ret < 0) { + if (ret) { dev_err(i2c_dev->dev, "DMA slave config failed: %d\n", ret); return ret; @@ -1224,7 +1224,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size, DMA_FROM_DEVICE); err = tegra_i2c_dma_submit(i2c_dev, xfer_size); - if (err < 0) { + if (err) { dev_err(i2c_dev->dev, "starting RX DMA failed, err %d\n", err); @@ -1249,7 +1249,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size, DMA_TO_DEVICE); err = tegra_i2c_dma_submit(i2c_dev, xfer_size); - if (err < 0) { + if (err) { dev_err(i2c_dev->dev, "starting TX DMA failed, err %d\n", err); From patchwork Tue Sep 8 22:40:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=FoEWJ739; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKtY1qlZz9sT6 for ; Wed, 9 Sep 2020 08:43:17 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729397AbgIHWmz (ORCPT ); Tue, 8 Sep 2020 18:42:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730116AbgIHWlI (ORCPT ); Tue, 8 Sep 2020 18:41:08 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C43C06179F; Tue, 8 Sep 2020 15:40:59 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id k25so1014409ljk.0; Tue, 08 Sep 2020 15:40:59 -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=GqX7EAitDfk5FuQKkylcPiJFZGC8+mAMTNK0jlhGt/k=; b=FoEWJ7390BbRlvcaxx+i8uqgVVPIXVQ0CotoZFM8erHl+zQj2H6BFIdQ4Z1VC3/OYr 2lJ66/nw8F9iM/U+cKvs/a/6r7c3ElNHdrTlpfc6/oBP+PqfGOiavY/Y8ZIGOab2yWBd Rr6/i89dm9rlrNeayLLKst0F+wgvEP0l2UM2UX2UNnOSs1vtRRQUMVeAN2x42QnlixQu /hFc8XRCygrM8/VyxL6M+jgEHuX6Ou++zvL9fzYqfKM9HdtF9e1ubMrHeCUPHozhUUJ3 LGXWWoNqQmUPyDfPR1evURvudAIuuJ2WjGGECZGYlpM+CVDF4yNvoR5rOpZ3VY3tuMhk uVNw== 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=GqX7EAitDfk5FuQKkylcPiJFZGC8+mAMTNK0jlhGt/k=; b=MS/ztXmTjYtC8HnchAWaiWT1926mmDDewIT67LTK5M6cBi0oNTwcpVdfB91/wD28S+ zrlr2hLNUynOVPCe8O5f500lYzS7aflLKlEV2w1W7aLEVBWDth7vos/CJ7rNSui9vQJ1 bVTv4STn2ExYHvEx6jQYCsdEAZTr6s3++cpTvfFXZEgZfH0Ei97Bh3ufmRk0usG97LhS 33KgX1DzEUZW9Qkj1bDoNY3E2wkXEiIfFbM+AoA+xGFTbLRssyyk4g2jdLhuZRIwYQF0 jRLIdbNoDRNhCVAmEqDMVoU+/UlBzLPk7LBGdiMZ5IrG9KxCW9aayNCaOjBzRIS8BRtC 0yog== X-Gm-Message-State: AOAM530mDkzs6275SHUst2kPMbVIR/FR4Dfh/TqOQ6bR093xzaJxamCm Mds1nBtifOF6OT8fMj2vWEA= X-Google-Smtp-Source: ABdhPJzsFKsmzTgpqHw5CIoFQtYWLen0Gt3lYLM+RSGhqdtYLnyDUaC40Mcxbf5ZwZoEHWXAL4wGHQ== X-Received: by 2002:a2e:9919:: with SMTP id v25mr359031lji.167.1599604857958; Tue, 08 Sep 2020 15:40: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 s15sm268311ljp.25.2020.09.08.15.40.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:57 -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 v7 28/34] i2c: tegra: Consolidate error handling in tegra_i2c_xfer_msg() Date: Wed, 9 Sep 2020 01:40:00 +0300 Message-Id: <20200908224006.25636-29-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Consolidate error handling in tegra_i2c_xfer_msg() into a common code path in order to make code cleaner. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index fe672cfebe12..ac40c87f1c21 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1293,8 +1293,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (!time_left && !completion_done(&i2c_dev->dma_complete)) { dev_err(i2c_dev->dev, "DMA transfer timeout\n"); - tegra_i2c_init(i2c_dev); - return -ETIMEDOUT; + err = -ETIMEDOUT; + goto reset_hardware; } if (i2c_dev->msg_read && i2c_dev->msg_err == I2C_ERR_NONE) { @@ -1314,8 +1314,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (time_left == 0) { dev_err(i2c_dev->dev, "i2c transfer timed out\n"); - tegra_i2c_init(i2c_dev); - return -ETIMEDOUT; + err = -ETIMEDOUT; + goto reset_hardware; } dev_dbg(i2c_dev->dev, "transfer complete: %lu %d %d\n", @@ -1329,6 +1329,11 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, return err; return 0; + +reset_hardware: + tegra_i2c_init(i2c_dev); + + return err; } static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], From patchwork Tue Sep 8 22:40:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=FPhQFowQ; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKsV2XKHz9sSJ for ; Wed, 9 Sep 2020 08:42:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726694AbgIHWmT (ORCPT ); Tue, 8 Sep 2020 18:42:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730131AbgIHWlI (ORCPT ); Tue, 8 Sep 2020 18:41:08 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63D4AC0617A0; Tue, 8 Sep 2020 15:41:00 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id r24so1001520ljm.3; Tue, 08 Sep 2020 15:41:00 -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=Jp6sLoMvSh2T712L5Y0H84TY9KtRLg7Lg5NuMcGn8oY=; b=FPhQFowQarLiiZwI6sJZ8U/6C0aTSgTO8uvITkJT+HNS2UbLBfGKep1FFlIDQ0u1dg DPiczwFumyLE7edkU/maCwZa650Jbycssu8MgLfZ1cOEb/ghtID7FIwIl+N9VNbJFm/D NfVmerXoRSRxTXtN/Uac4DjPdq6ICvA6+6/XzVItleZ8B/trZ+9s3fui8OE/7NOn5JmQ zpfwsYj92/f94NR/Mu2qFmdP98CRWVx/X7i78cCbHqWbdykeLCPEoaxq5TwauXZXOpaZ qZWO/rVcMuJAtgbb6UDGxkIkY5464cko0/rkEPK6G7zmfOn36y8eMCS0VUxmkCInTTlF +NNA== 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=Jp6sLoMvSh2T712L5Y0H84TY9KtRLg7Lg5NuMcGn8oY=; b=Q/KqxOYZ8r1gQpZ/McWi1POIzUyH2pzCJi1yRvMyvb7B/AXq4IBxKt/Xfz1IqqBiNT y/19Cal1JN8kyOa5KcGvtiM3alwvdeEoF975gpXA3e5O633vcAIrbHrGj5Uf/hYF3A94 aOrmCKst+rmIwuDoRHe1RFkVpAGh9+DyO9ccDNGIJRVKB+6N7R0c/AUD/sR4bi0/aoQ5 PEuX8ar08qfNoinzv+GMVO8YkXyuT3GVf4BFR0AKBxcHdmvQk19FKLdojgpYU2wsvNsq 9k1JrWQ+yhcYhGYQkDsHPvP0lMYHyMgFVfzULLHh4VneJS3t8uqXdQ3gRB6PE73/qp87 zxLg== X-Gm-Message-State: AOAM533Mhutl35bL0qDFD3iamChPHPuaarTrNIOhzcsTPTstiPXy+Hi7 5fTp1mEjsXFemTKJJXLRhqMa7TBk2Us= X-Google-Smtp-Source: ABdhPJztZWUEnyiTWjQV6lOD5lhS0sFIEp2WQffuBeULcUuz9Xe64roVfgDvRb7qW1Crf4rQjxWPgA== X-Received: by 2002:a2e:a550:: with SMTP id e16mr194696ljn.125.1599604858840; Tue, 08 Sep 2020 15:40:58 -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 s15sm268311ljp.25.2020.09.08.15.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:58 -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 v7 29/34] i2c: tegra: Improve formatting of variables Date: Wed, 9 Sep 2020 01:40:01 +0300 Message-Id: <20200908224006.25636-30-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Reorder definition of variables in the code to have them sorted by length and grouped logically, also replace "unsigned long" with "u32". Do this in order to make code easier to read. Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 97 ++++++++++++++++------------------ 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index ac40c87f1c21..2376f502d299 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -259,42 +259,48 @@ struct tegra_i2c_hw_feature { */ struct tegra_i2c_dev { struct device *dev; - const struct tegra_i2c_hw_feature *hw; struct i2c_adapter adapter; - struct clk *div_clk; - struct clk_bulk_data *clocks; - unsigned int nclocks; + + const struct tegra_i2c_hw_feature *hw; struct reset_control *rst; - void __iomem *base; - phys_addr_t base_phys; unsigned int cont_id; unsigned int irq; - bool is_dvc; - bool is_vi; + + phys_addr_t base_phys; + void __iomem *base; + + struct clk_bulk_data *clocks; + unsigned int nclocks; + + struct clk *div_clk; + u32 bus_clk_rate; + struct completion msg_complete; + size_t msg_buf_remaining; int msg_err; u8 *msg_buf; - size_t msg_buf_remaining; - bool msg_read; - u32 bus_clk_rate; - bool is_multimaster_mode; + + struct completion dma_complete; struct dma_chan *tx_dma_chan; struct dma_chan *rx_dma_chan; + unsigned int dma_buf_size; dma_addr_t dma_phys; u32 *dma_buf; - unsigned int dma_buf_size; - bool is_curr_dma_xfer; - struct completion dma_complete; + + bool is_multimaster_mode; bool is_curr_atomic_xfer; + bool is_curr_dma_xfer; + bool msg_read; + bool is_dvc; + bool is_vi; }; -static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, - unsigned long reg) +static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, u32 reg) { writel_relaxed(val, i2c_dev->base + reg); } -static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) +static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, u32 reg) { return readl_relaxed(i2c_dev->base + reg); } @@ -303,8 +309,7 @@ static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) * i2c_writel and i2c_readl will offset the register if necessary to talk * to the I2C block inside the DVC block */ -static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, - unsigned long reg) +static u32 tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, u32 reg) { if (i2c_dev->is_dvc) reg += (reg >= I2C_TX_FIFO) ? 0x10 : 0x40; @@ -313,8 +318,7 @@ static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, return reg; } -static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, - unsigned long reg) +static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, u32 reg) { writel_relaxed(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); @@ -323,19 +327,19 @@ static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); } -static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) +static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, u32 reg) { return readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); } static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data, - unsigned long reg, unsigned int len) + u32 reg, unsigned int len) { writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); } static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data, - unsigned long reg, unsigned int len) + u32 reg, unsigned int len) { readsl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); } @@ -410,8 +414,8 @@ static void tegra_i2c_release_dma(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) { struct dma_chan *chan; - u32 *dma_buf; dma_addr_t dma_phys; + u32 *dma_buf; int err; if (!i2c_dev->hw->has_apb_dma || i2c_dev->is_vi) @@ -577,12 +581,8 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) { - u32 val; + u32 val, clk_divisor, clk_multiplier, tsu_thd, tlow, thigh, non_hs_mode; int err; - u32 clk_divisor, clk_multiplier; - u32 non_hs_mode; - u32 tsu_thd; - u8 tlow, thigh; /* * The reset shouldn't ever fail in practice. The failure will be a @@ -704,11 +704,10 @@ static int tegra_i2c_disable_packet_mode(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) { - u32 val; - unsigned int rx_fifo_avail; - u8 *buf = i2c_dev->msg_buf; size_t buf_remaining = i2c_dev->msg_buf_remaining; - unsigned int words_to_transfer; + unsigned int words_to_transfer, rx_fifo_avail; + u8 *buf = i2c_dev->msg_buf; + u32 val; /* * Catch overflow due to message fully sent @@ -765,11 +764,10 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) { - u32 val; - unsigned int tx_fifo_avail; - u8 *buf = i2c_dev->msg_buf; size_t buf_remaining = i2c_dev->msg_buf_remaining; - unsigned int words_to_transfer; + unsigned int words_to_transfer, tx_fifo_avail; + u8 *buf = i2c_dev->msg_buf; + u32 val; if (i2c_dev->hw->has_mst_fifo) { val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); @@ -830,9 +828,9 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) { - u32 status; const u32 status_err = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; struct tegra_i2c_dev *i2c_dev = dev_id; + u32 status; status = i2c_readl(i2c_dev, I2C_INT_STATUS); @@ -935,12 +933,10 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) { - u32 val, reg; - u8 dma_burst; struct dma_slave_config slv_config = {0}; + u32 val, reg, dma_burst, reg_offset; struct dma_chan *chan; int ret; - unsigned long reg_offset; if (i2c_dev->hw->has_mst_fifo) reg = I2C_MST_FIFO_CONTROL; @@ -1062,9 +1058,8 @@ static unsigned long tegra_i2c_wait_completion(struct tegra_i2c_dev *i2c_dev, static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) { struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); + u32 reg, time_left; int err; - unsigned long time_left; - u32 reg; reinit_completion(&i2c_dev->msg_complete); reg = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND | @@ -1178,11 +1173,10 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, struct i2c_msg *msg, enum msg_end_type end_state) { - u32 int_mask; - unsigned long time_left; + unsigned long time_left, xfer_time = 100; size_t xfer_size; - int err = 0; - u16 xfer_time = 100; + u32 int_mask; + int err; err = tegra_i2c_flush_fifos(i2c_dev); if (err) @@ -1340,8 +1334,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) { struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); - int i; - int ret; + int i, ret; ret = pm_runtime_get_sync(i2c_dev->dev); if (ret < 0) { @@ -1601,8 +1594,8 @@ MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) { struct device_node *np = i2c_dev->dev->of_node; - int ret; bool multi_mode; + int ret; ret = of_property_read_u32(np, "clock-frequency", &i2c_dev->bus_clk_rate); From patchwork Tue Sep 8 22:40:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=kyPbNz2Y; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKsm5Btwz9sTR for ; Wed, 9 Sep 2020 08:42:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729860AbgIHWmV (ORCPT ); Tue, 8 Sep 2020 18:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730136AbgIHWlI (ORCPT ); Tue, 8 Sep 2020 18:41:08 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7651BC0617A1; Tue, 8 Sep 2020 15:41:01 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id k25so953156ljg.9; Tue, 08 Sep 2020 15:41:01 -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=NpODj2NiQneb1Ai/nnQoJVaH8tkXiqedjwXwvKgnGaI=; b=kyPbNz2YjTFHujaVnsAJfKlZUYs4Gx+22xBrNd/J4bfkq84vOu+sdPc9VgBgv85hww tR9PZNg5HNiqYPlZ8iPAIE77ewd3twl+R3xEYy+YljcyVFELdwKZDki89nNS8+3MkjdU PsdGQ904EPrRKz1QKkMwRiBD7kU8yd6qnrhIe/xrYCoJDMkT/gNcFMARX5dXmExehbkB 6N+sLia0feY+umgYNUSXa/5tkkx2a4qljV29tKriLd2ej3b9TWdtIqm/gpX9XqdRei3Z 0ZVKq3s6Bzzm5k6XWZLMoAXOvGwZUXalEPhARWU2wCYkXitPfgUW81GRvqf/C8Uj9kd0 2PBA== 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=NpODj2NiQneb1Ai/nnQoJVaH8tkXiqedjwXwvKgnGaI=; b=A0huLbRJMAXA8WeIawr77tCR3DO8UW6n3E6wX3o318j5vHdI3AWJt6Qt+rpcmj6hxb nF+KC6IqJGJwpNB4nUMC0pljH5mRxPMIV/E11d519P0vqUZNYdymA2xSIGVhAwnYb/qc h0NE51cQL87L4lS6yhrf37+8YLJY91vNZtkb3rdbF5g+6WiQAcqSYCEEoWxyE9JGhUvk Clx2nhdUDcHznmpAZ9QPJHeWb7pSHvaoLm7gEnxis0zEehFgtON+QLuUb7faEQ24dYBx Q/JYAIVj+n3cEIJ6ZN3SGXK4JQyBT0TPKeZda7FJJuX/Ubl/Zgmxxi2vZ/D57EYry1bF Qm8Q== X-Gm-Message-State: AOAM531gr2n1IVzudTHw1UWEeWjaMZV1GTByGELcF3UzeYO/z1+tIF9U CaH1wvbjx/KpE2atzjcdvSo= X-Google-Smtp-Source: ABdhPJxhlQ6MnsG2po3A3yw/JZtwk7M59XqDLJyM/uolUYBZpMBmQzTlhoiOvTaBjcgtQrQZdcrfpA== X-Received: by 2002:a2e:8153:: with SMTP id t19mr372370ljg.334.1599604859832; Tue, 08 Sep 2020 15:40:59 -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 s15sm268311ljp.25.2020.09.08.15.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:40:59 -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 v7 30/34] i2c: tegra: Clean up variable names Date: Wed, 9 Sep 2020 01:40:02 +0300 Message-Id: <20200908224006.25636-31-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Rename "ret" variables to "err" in order to make code a bit more expressive, emphasizing that the returned value is an error code. Same vice versa, where appropriate. Rename variable "reg" to "val" in order to better reflect the actual usage of the variable in the code and to make naming consistent with the rest of the code. Use briefer names for a few members of the tegra_i2c_dev structure in order to improve readability of the code. All dev/&pdev->dev are replaced with i2c_dev->dev in order to have uniform code style across the driver. Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding Acked-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 173 ++++++++++++++++----------------- 1 file changed, 86 insertions(+), 87 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 2376f502d299..fbdb206f0161 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -247,15 +247,15 @@ struct tegra_i2c_hw_feature { * @msg_buf_remaining: size of unsent data in the message buffer * @msg_read: identifies read transfers * @bus_clk_rate: current I2C bus clock rate - * @is_multimaster_mode: track if I2C controller is in multi-master mode + * @multimaster_mode: indicates that I2C controller is in multi-master mode * @tx_dma_chan: DMA transmit channel * @rx_dma_chan: DMA receive channel * @dma_phys: handle to DMA resources * @dma_buf: pointer to allocated DMA buffer * @dma_buf_size: DMA buffer size - * @is_curr_dma_xfer: indicates active DMA transfer + * @dma_mode: indicates active DMA transfer * @dma_complete: DMA completion notifier - * @is_curr_atomic_xfer: indicates active atomic transfer + * @atomic_mode: indicates active atomic transfer */ struct tegra_i2c_dev { struct device *dev; @@ -287,9 +287,9 @@ struct tegra_i2c_dev { dma_addr_t dma_phys; u32 *dma_buf; - bool is_multimaster_mode; - bool is_curr_atomic_xfer; - bool is_curr_dma_xfer; + bool multimaster_mode; + bool atomic_mode; + bool dma_mode; bool msg_read; bool is_dvc; bool is_vi; @@ -525,7 +525,7 @@ static int tegra_i2c_poll_register(struct tegra_i2c_dev *i2c_dev, void __iomem *addr = i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg); u32 val; - if (!i2c_dev->is_curr_atomic_xfer) + if (!i2c_dev->atomic_mode) return readl_relaxed_poll_timeout(addr, val, !(val & mask), delay_us, timeout_us); @@ -673,7 +673,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) if (err) return err; - if (i2c_dev->is_multimaster_mode && i2c_dev->hw->has_slcg_override_reg) + if (i2c_dev->multimaster_mode && i2c_dev->hw->has_slcg_override_reg) i2c_writel(i2c_dev, I2C_MST_CORE_CLKEN_OVR, I2C_CLKEN_OVERRIDE); err = tegra_i2c_wait_for_config_load(i2c_dev); @@ -859,7 +859,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) if (i2c_dev->hw->supports_bus_clear && (status & I2C_INT_BUS_CLR_DONE)) goto err; - if (!i2c_dev->is_curr_dma_xfer) { + if (!i2c_dev->dma_mode) { if (i2c_dev->msg_read && (status & I2C_INT_RX_FIFO_DATA_REQ)) { if (tegra_i2c_empty_rx_fifo(i2c_dev)) { /* @@ -893,7 +893,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) * so forcing msg_buf_remaining to 0 in DMA mode. */ if (status & I2C_INT_PACKET_XFER_COMPLETE) { - if (i2c_dev->is_curr_dma_xfer) + if (i2c_dev->dma_mode) i2c_dev->msg_buf_remaining = 0; /* * Underflow error condition: XFER_COMPLETE before message @@ -917,7 +917,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) if (i2c_dev->is_dvc) dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS); - if (i2c_dev->is_curr_dma_xfer) { + if (i2c_dev->dma_mode) { if (i2c_dev->msg_read) dmaengine_terminate_async(i2c_dev->rx_dma_chan); else @@ -936,14 +936,14 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) struct dma_slave_config slv_config = {0}; u32 val, reg, dma_burst, reg_offset; struct dma_chan *chan; - int ret; + int err; if (i2c_dev->hw->has_mst_fifo) reg = I2C_MST_FIFO_CONTROL; else reg = I2C_FIFO_CONTROL; - if (i2c_dev->is_curr_dma_xfer) { + if (i2c_dev->dma_mode) { if (len & 0xF) dma_burst = 1; else if (len & 0x10) @@ -976,11 +976,11 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) } slv_config.device_fc = true; - ret = dmaengine_slave_config(chan, &slv_config); - if (ret) { + err = dmaengine_slave_config(chan, &slv_config); + if (err) { dev_err(i2c_dev->dev, "DMA slave config failed: %d\n", - ret); - return ret; + err); + return err; } goto out; @@ -1030,7 +1030,7 @@ static unsigned long tegra_i2c_wait_completion(struct tegra_i2c_dev *i2c_dev, { unsigned long ret; - if (i2c_dev->is_curr_atomic_xfer) { + if (i2c_dev->atomic_mode) { ret = tegra_i2c_poll_completion(i2c_dev, complete, timeout_ms); } else { enable_irq(i2c_dev->irq); @@ -1058,20 +1058,20 @@ static unsigned long tegra_i2c_wait_completion(struct tegra_i2c_dev *i2c_dev, static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) { struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); - u32 reg, time_left; + u32 val, time_left; int err; reinit_completion(&i2c_dev->msg_complete); - reg = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND | + val = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND | I2C_BC_TERMINATE; - i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); + i2c_writel(i2c_dev, val, I2C_BUS_CLEAR_CNFG); err = tegra_i2c_wait_for_config_load(i2c_dev); if (err) return err; - reg |= I2C_BC_ENABLE; - i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); + val |= I2C_BC_ENABLE; + i2c_writel(i2c_dev, val, I2C_BUS_CLEAR_CNFG); tegra_i2c_unmask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); time_left = tegra_i2c_wait_completion(i2c_dev, &i2c_dev->msg_complete, 50); @@ -1082,8 +1082,8 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) return -ETIMEDOUT; } - reg = i2c_readl(i2c_dev, I2C_BUS_CLEAR_STATUS); - if (!(reg & I2C_BC_STATUS)) { + val = i2c_readl(i2c_dev, I2C_BUS_CLEAR_STATUS); + if (!(val & I2C_BC_STATUS)) { dev_err(i2c_dev->dev, "un-recovered arbitration lost\n"); return -EIO; @@ -1105,14 +1105,14 @@ static void tegra_i2c_push_packet_header(struct tegra_i2c_dev *i2c_dev, FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) | FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1); - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + if (i2c_dev->dma_mode && !i2c_dev->msg_read) *dma_buf++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); packet_header = msg->len - 1; - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + if (i2c_dev->dma_mode && !i2c_dev->msg_read) *dma_buf++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); @@ -1137,7 +1137,7 @@ static void tegra_i2c_push_packet_header(struct tegra_i2c_dev *i2c_dev, if (msg->flags & I2C_M_RD) packet_header |= I2C_HEADER_READ; - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + if (i2c_dev->dma_mode && !i2c_dev->msg_read) *dma_buf++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); @@ -1153,7 +1153,7 @@ static int tegra_i2c_error_recover(struct tegra_i2c_dev *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) + if (!i2c_dev->multimaster_mode) return i2c_recover_bus(&i2c_dev->adapter); return -EAGAIN; @@ -1194,9 +1194,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size = msg->len + I2C_PACKET_HEADER_SIZE; xfer_size = ALIGN(xfer_size, BYTES_PER_FIFO_WORD); - i2c_dev->is_curr_dma_xfer = (xfer_size > I2C_PIO_MODE_PREFERRED_LEN) && - i2c_dev->dma_buf && - !i2c_dev->is_curr_atomic_xfer; + i2c_dev->dma_mode = (xfer_size > I2C_PIO_MODE_PREFERRED_LEN) && + i2c_dev->dma_buf && !i2c_dev->atomic_mode; err = tegra_i2c_config_fifo_trig(i2c_dev, xfer_size); if (err) @@ -1211,7 +1210,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; tegra_i2c_unmask_irq(i2c_dev, int_mask); - if (i2c_dev->is_curr_dma_xfer) { + if (i2c_dev->dma_mode) { if (i2c_dev->msg_read) { dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, @@ -1236,7 +1235,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, tegra_i2c_push_packet_header(i2c_dev, msg, end_state); if (!i2c_dev->msg_read) { - if (i2c_dev->is_curr_dma_xfer) { + if (i2c_dev->dma_mode) { memcpy(i2c_dev->dma_buf, msg->buf, msg->len); dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, @@ -1256,7 +1255,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (i2c_dev->hw->has_per_pkt_xfer_complete_irq) int_mask |= I2C_INT_PACKET_XFER_COMPLETE; - if (!i2c_dev->is_curr_dma_xfer) { + if (!i2c_dev->dma_mode) { if (msg->flags & I2C_M_RD) int_mask |= I2C_INT_RX_FIFO_DATA_REQ; else if (i2c_dev->msg_buf_remaining) @@ -1267,7 +1266,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, dev_dbg(i2c_dev->dev, "unmasked irq: %02x\n", i2c_readl(i2c_dev, I2C_INT_MASK)); - if (i2c_dev->is_curr_dma_xfer) { + if (i2c_dev->dma_mode) { time_left = tegra_i2c_wait_completion(i2c_dev, &i2c_dev->dma_complete, xfer_time); @@ -1316,7 +1315,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, time_left, completion_done(&i2c_dev->msg_complete), i2c_dev->msg_err); - i2c_dev->is_curr_dma_xfer = false; + i2c_dev->dma_mode = false; err = tegra_i2c_error_recover(i2c_dev, msg); if (err) @@ -1368,9 +1367,9 @@ static int tegra_i2c_xfer_atomic(struct i2c_adapter *adap, struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); int ret; - i2c_dev->is_curr_atomic_xfer = true; + i2c_dev->atomic_mode = true; ret = tegra_i2c_xfer(adap, msgs, num); - i2c_dev->is_curr_atomic_xfer = false; + i2c_dev->atomic_mode = false; return ret; } @@ -1595,15 +1594,15 @@ static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) { struct device_node *np = i2c_dev->dev->of_node; bool multi_mode; - int ret; + int err; - ret = of_property_read_u32(np, "clock-frequency", + err = of_property_read_u32(np, "clock-frequency", &i2c_dev->bus_clk_rate); - if (ret) + if (err) i2c_dev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */ multi_mode = of_property_read_bool(np, "multi-master"); - i2c_dev->is_multimaster_mode = multi_mode; + i2c_dev->multimaster_mode = multi_mode; if (of_device_is_compatible(np, "nvidia,tegra20-i2c-dvc")) i2c_dev->is_dvc = true; @@ -1634,7 +1633,7 @@ static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev) } } - if (!i2c_dev->is_multimaster_mode) + if (!i2c_dev->multimaster_mode) return 0; err = clk_enable(i2c_dev->div_clk); @@ -1653,7 +1652,7 @@ static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev) static void tegra_i2c_release_clocks(struct tegra_i2c_dev *i2c_dev) { - if (i2c_dev->is_multimaster_mode) + if (i2c_dev->multimaster_mode) clk_disable(i2c_dev->div_clk); clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks); @@ -1678,7 +1677,7 @@ static int tegra_i2c_probe(struct platform_device *pdev) { struct tegra_i2c_dev *i2c_dev; struct resource *res; - int ret; + int err; i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); if (!i2c_dev) @@ -1699,36 +1698,36 @@ static int tegra_i2c_probe(struct platform_device *pdev) i2c_dev->base_phys = res->start; - ret = platform_get_irq(pdev, 0); - if (ret < 0) - return ret; + err = platform_get_irq(pdev, 0); + if (err < 0) + return err; - i2c_dev->irq = ret; + i2c_dev->irq = err; /* interrupt will be enabled during of transfer time */ irq_set_status_flags(i2c_dev->irq, IRQ_NOAUTOEN); - ret = devm_request_irq(&pdev->dev, i2c_dev->irq, tegra_i2c_isr, - IRQF_NO_SUSPEND, dev_name(&pdev->dev), + err = devm_request_irq(i2c_dev->dev, i2c_dev->irq, tegra_i2c_isr, + IRQF_NO_SUSPEND, dev_name(i2c_dev->dev), i2c_dev); - if (ret) - return ret; + if (err) + return err; - i2c_dev->rst = devm_reset_control_get_exclusive(&pdev->dev, "i2c"); + i2c_dev->rst = devm_reset_control_get_exclusive(i2c_dev->dev, "i2c"); if (IS_ERR(i2c_dev->rst)) { - dev_err_probe(&pdev->dev, PTR_ERR(i2c_dev->rst), + dev_err_probe(i2c_dev->dev, PTR_ERR(i2c_dev->rst), "failed to get reset control\n"); return PTR_ERR(i2c_dev->rst); } tegra_i2c_parse_dt(i2c_dev); - ret = tegra_i2c_init_clocks(i2c_dev); - if (ret) - return ret; + err = tegra_i2c_init_clocks(i2c_dev); + if (err) + return err; - ret = tegra_i2c_init_dma(i2c_dev); - if (ret) + err = tegra_i2c_init_dma(i2c_dev); + if (err) goto release_clocks; /* @@ -1739,16 +1738,16 @@ static int tegra_i2c_probe(struct platform_device *pdev) * not be used for atomic transfers. */ if (!i2c_dev->is_vi) - pm_runtime_irq_safe(&pdev->dev); - pm_runtime_enable(&pdev->dev); + pm_runtime_irq_safe(i2c_dev->dev); + pm_runtime_enable(i2c_dev->dev); - ret = tegra_i2c_init_hardware(i2c_dev); - if (ret) + err = tegra_i2c_init_hardware(i2c_dev); + if (err) goto release_rpm; i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); - i2c_dev->adapter.dev.of_node = pdev->dev.of_node; - i2c_dev->adapter.dev.parent = &pdev->dev; + i2c_dev->adapter.dev.of_node = i2c_dev->dev->of_node; + i2c_dev->adapter.dev.parent = i2c_dev->dev; i2c_dev->adapter.retries = 1; i2c_dev->adapter.timeout = 6 * HZ; i2c_dev->adapter.quirks = i2c_dev->hw->quirks; @@ -1760,23 +1759,23 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (i2c_dev->hw->supports_bus_clear) i2c_dev->adapter.bus_recovery_info = &tegra_i2c_recovery_info; - strlcpy(i2c_dev->adapter.name, dev_name(&pdev->dev), + strlcpy(i2c_dev->adapter.name, dev_name(i2c_dev->dev), sizeof(i2c_dev->adapter.name)); - ret = i2c_add_numbered_adapter(&i2c_dev->adapter); - if (ret) + err = i2c_add_numbered_adapter(&i2c_dev->adapter); + if (err) goto release_rpm; return 0; release_rpm: - pm_runtime_disable(&pdev->dev); + pm_runtime_disable(i2c_dev->dev); tegra_i2c_release_dma(i2c_dev); release_clocks: tegra_i2c_release_clocks(i2c_dev); - return ret; + return err; } static int tegra_i2c_remove(struct platform_device *pdev) @@ -1785,7 +1784,7 @@ static int tegra_i2c_remove(struct platform_device *pdev) i2c_del_adapter(&i2c_dev->adapter); - pm_runtime_disable(&pdev->dev); + pm_runtime_disable(i2c_dev->dev); tegra_i2c_release_dma(i2c_dev); tegra_i2c_release_clocks(i2c_dev); @@ -1795,15 +1794,15 @@ static int tegra_i2c_remove(struct platform_device *pdev) static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) { struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); - int ret; + int err; - ret = pinctrl_pm_select_default_state(i2c_dev->dev); - if (ret) - return ret; + err = pinctrl_pm_select_default_state(dev); + if (err) + return err; - ret = clk_bulk_enable(i2c_dev->nclocks, i2c_dev->clocks); - if (ret) - return ret; + err = clk_bulk_enable(i2c_dev->nclocks, i2c_dev->clocks); + if (err) + return err; /* * VI I2C device is attached to VE power domain which goes through @@ -1812,8 +1811,8 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) * domain ON. */ if (i2c_dev->is_vi) { - ret = tegra_i2c_init(i2c_dev); - if (ret) + err = tegra_i2c_init(i2c_dev); + if (err) goto disable_clocks; } @@ -1822,7 +1821,7 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) disable_clocks: clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); - return ret; + return err; } static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev) @@ -1831,20 +1830,20 @@ static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev) clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); - return pinctrl_pm_select_idle_state(i2c_dev->dev); + return pinctrl_pm_select_idle_state(dev); } static int __maybe_unused tegra_i2c_suspend(struct device *dev) { struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); - int err = 0; + int ret = 0; i2c_mark_adapter_suspended(&i2c_dev->adapter); if (!pm_runtime_status_suspended(dev)) - err = tegra_i2c_runtime_suspend(dev); + ret = tegra_i2c_runtime_suspend(dev); - return err; + return ret; } static int __maybe_unused tegra_i2c_resume(struct device *dev) From patchwork Tue Sep 8 22:40:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360166 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=DHS0IHy5; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKrV4wP0z9sT6 for ; Wed, 9 Sep 2020 08:41:30 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730179AbgIHWl1 (ORCPT ); Tue, 8 Sep 2020 18:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730145AbgIHWlR (ORCPT ); Tue, 8 Sep 2020 18:41:17 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 519E6C061756; Tue, 8 Sep 2020 15:41:02 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id d15so519400lfq.11; Tue, 08 Sep 2020 15:41:02 -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=oviyJhmxGVJwejdEp6ESdVhw01ZwrI+dnJ0EEmLjDYE=; b=DHS0IHy5hiyB33l1bY1SRZw+CWa1CYU91p6nGs1lNCulm2AMgo3Nd5F+NJ8sgHJrN1 OZpCXfgzPq3tgyIKx41VuLcdsgdDZtvoTKY3mPDi9MJ/oplYfYiPcbFZvIyVhSnSpShN qu+ZcF1KO9+1SWJ2KlDoz8BUL98YT//6U0E9hiZX/aEoJkKL7dfHUl4PWRyYGm3+nNVW X42WbpSqPj6r2jf/pC8/uOKDs8awzgije51J2GxsuvYT6vbGxRR4lt/XtW4cNQ9B2wW9 jjpeb/j2+7wFmL47OeiT616Wr5eI/75YdQDUHHIcorGDbfvQ9at2GsET1VtUafMIHGlY dXgg== 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=oviyJhmxGVJwejdEp6ESdVhw01ZwrI+dnJ0EEmLjDYE=; b=ADK3DiV+dZHBGXy3KV54H70GTosG8KJ3jHzIElhg87evIo2+5pITstmb4df+t2/E8X nzuXWmcRZCJjEvEkDSf7+sjLRgnXywMdjlhZGLd6neP5VreBufV1u9i1gox+As0OYQJZ hYch4xqCCbzX7R8QZ1xxfTfByl8tVtxkF9IaWKKI/kzG3nOUsm1MlkjY3Ovsi1v4okLC CcDXNMFPiju+OSWuD88ZLtySGv8HPOeX4j7M01GY7Gv81gFqStMuACSEgJlKJzE+JLAV BEA9+T4hxd655lal1GXk7n9VKQm2SZVmGPrSR0psADZFW8kmxoVEbdx6EUa3VdyMD56q Lkrw== X-Gm-Message-State: AOAM530tmjICH7LRczjbk32CsOA/TYvmxZP0E7+X3q+DENrLP4sLepHd iZLV3LjBHbA3tU0KXd+3ajE= X-Google-Smtp-Source: ABdhPJyQ9D9g8tyYZ6zsvdE14KuU8F+2cG/eVGFWYnZEwgpjRUGE9mnDeA/bigb3TUS37sgFzh5tSQ== X-Received: by 2002:a05:6512:3692:: with SMTP id d18mr550585lfs.62.1599604860776; Tue, 08 Sep 2020 15:41:00 -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 s15sm268311ljp.25.2020.09.08.15.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:41:00 -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 v7 31/34] i2c: tegra: Clean up printk messages Date: Wed, 9 Sep 2020 01:40:03 +0300 Message-Id: <20200908224006.25636-32-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org This patch unifies style of all messages in the driver by starting them with a lowercase letter and using consistent capitalization and wording for all messages. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 37 +++++++++++++--------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index fbdb206f0161..558b1f2934a0 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -381,7 +381,8 @@ static int tegra_i2c_dma_submit(struct tegra_i2c_dev *i2c_dev, size_t len) len, dir, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); if (!dma_desc) { - dev_err(i2c_dev->dev, "failed to get DMA descriptor\n"); + dev_err(i2c_dev->dev, "failed to get %s DMA descriptor\n", + i2c_dev->msg_read ? "RX" : "TX"); return -EINVAL; } @@ -422,7 +423,7 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) return 0; if (!IS_ENABLED(CONFIG_TEGRA20_APB_DMA)) { - dev_dbg(i2c_dev->dev, "Support for APB DMA not enabled!\n"); + dev_dbg(i2c_dev->dev, "DMA support not enabled\n"); return 0; } @@ -448,7 +449,7 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) dma_buf = dma_alloc_coherent(i2c_dev->dev, i2c_dev->dma_buf_size, &dma_phys, GFP_KERNEL | __GFP_NOWARN); if (!dma_buf) { - dev_err(i2c_dev->dev, "failed to allocate the DMA buffer\n"); + dev_err(i2c_dev->dev, "failed to allocate DMA buffer\n"); err = -ENOMEM; goto err_out; } @@ -572,7 +573,7 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) err = tegra_i2c_poll_register(i2c_dev, I2C_CONFIG_LOAD, 0xffffffff, 1000, I2C_CONFIG_LOAD_TIMEOUT); if (err) { - dev_warn(i2c_dev->dev, "timeout waiting for config load\n"); + dev_err(i2c_dev->dev, "failed to load config\n"); return err; } @@ -835,7 +836,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) status = i2c_readl(i2c_dev, I2C_INT_STATUS); if (status == 0) { - dev_warn(i2c_dev->dev, "irq status 0 %08x %08x %08x\n", + dev_warn(i2c_dev->dev, "IRQ status 0 %08x %08x %08x\n", i2c_readl(i2c_dev, I2C_PACKET_TRANSFER_STATUS), i2c_readl(i2c_dev, I2C_STATUS), i2c_readl(i2c_dev, I2C_CNFG)); @@ -978,8 +979,7 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) slv_config.device_fc = true; err = dmaengine_slave_config(chan, &slv_config); if (err) { - dev_err(i2c_dev->dev, "DMA slave config failed: %d\n", - err); + dev_err(i2c_dev->dev, "DMA config failed: %d\n", err); return err; } @@ -1078,14 +1078,13 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) tegra_i2c_mask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); if (time_left == 0) { - dev_err(i2c_dev->dev, "timed out for bus clear\n"); + dev_err(i2c_dev->dev, "failed to clear bus\n"); return -ETIMEDOUT; } val = i2c_readl(i2c_dev, I2C_BUS_CLEAR_STATUS); if (!(val & I2C_BC_STATUS)) { - dev_err(i2c_dev->dev, - "un-recovered arbitration lost\n"); + dev_err(i2c_dev->dev, "un-recovered arbitration lost\n"); return -EIO; } @@ -1217,12 +1216,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size, DMA_FROM_DEVICE); err = tegra_i2c_dma_submit(i2c_dev, xfer_size); - if (err) { - dev_err(i2c_dev->dev, - "starting RX DMA failed, err %d\n", - err); + if (err) return err; - } } else { dma_sync_single_for_cpu(i2c_dev->dev, @@ -1242,12 +1237,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size, DMA_TO_DEVICE); err = tegra_i2c_dma_submit(i2c_dev, xfer_size); - if (err) { - dev_err(i2c_dev->dev, - "starting TX DMA failed, err %d\n", - err); + if (err) return err; - } } else { tegra_i2c_fill_tx_fifo(i2c_dev); } @@ -1263,7 +1254,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, } tegra_i2c_unmask_irq(i2c_dev, int_mask); - dev_dbg(i2c_dev->dev, "unmasked irq: %02x\n", + dev_dbg(i2c_dev->dev, "unmasked IRQ: %02x\n", i2c_readl(i2c_dev, I2C_INT_MASK)); if (i2c_dev->dma_mode) { @@ -1285,7 +1276,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->tx_dma_chan); if (!time_left && !completion_done(&i2c_dev->dma_complete)) { - dev_err(i2c_dev->dev, "DMA transfer timeout\n"); + dev_err(i2c_dev->dev, "DMA transfer timed out\n"); err = -ETIMEDOUT; goto reset_hardware; } @@ -1306,7 +1297,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, tegra_i2c_mask_irq(i2c_dev, int_mask); if (time_left == 0) { - dev_err(i2c_dev->dev, "i2c transfer timed out\n"); + dev_err(i2c_dev->dev, "I2C transfer timed out\n"); err = -ETIMEDOUT; goto reset_hardware; } From patchwork Tue Sep 8 22:40:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=C3iqTq8t; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKsR4hT2z9sT6 for ; Wed, 9 Sep 2020 08:42:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730170AbgIHWl0 (ORCPT ); Tue, 8 Sep 2020 18:41:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730150AbgIHWlR (ORCPT ); Tue, 8 Sep 2020 18:41:17 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFE9FC0617A2; Tue, 8 Sep 2020 15:41:03 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id s205so969912lja.7; Tue, 08 Sep 2020 15:41:03 -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=MkQIHtlT+EaxxlgKU1ijG4ML1x4ggl2oAqernIv3ZEM=; b=C3iqTq8tMd3OYGvawn1iexSQn7B8zIq9NA01L1LZ58yzCcccVr0TC9HgrEgU64FqtZ u3wcksZckAmHLfWVYiVKMD1tZ7+qECieGUTBw3Se8kUyV/Q0QhZdAx2SVWdVhaoyB1/T ofCnBNZmEgFhI7Bl2mrzjyrbcMFGfAfim9a5Vdt8nO65MiFceGD+fKJ+H8y0bXSIoEnN WJCyMGk6uZXEDtPvM2HnIA5s2gBf8fjeFh/KV3MWVaJLwaVRGM+dQa4pKMtDEOExasYE DgOecZFA906SGemtItT0bbZfHlAZrazy3rLdKc2hb//ZKkYriYXzC/4ZlKiukf/aqOYr /Uxw== 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=MkQIHtlT+EaxxlgKU1ijG4ML1x4ggl2oAqernIv3ZEM=; b=U28wjxRBnXyQ3w/Qe8tN0U+HxVPM7nTeCDT+YnSDgfciRyxVpaMmUIWNMrnf4Wh4uB pKIIWuZ6UEO9la00ptOngeJr0t0nNh2KNkLI9QCepvIYxeU3gK8fmUGKfUV4E16j1RnH xCKIuwmN3UNwKCBdJEUp3qsJVAUo51qPwC+KFqwyK/3k9UaE70aeF/v8mDNpkMCc461U QA/tSQ/KVcIhIy8pKPGjmUBE5GZHSqNErDMHqiHHfgJY6JjrMnRm1MEM2SSJQoQAMUUZ TECoHFpkgA+ZzDcdc3F9lcMkvqEgMhpX00208DwhbL1DAD6LoOdyz39Td+7zOfysHiEp s8JA== X-Gm-Message-State: AOAM531+m3g1v9Q2I8dbmpdVRd6lRViNj1svCIo688+LewiUmWFedq5q e0v3o9n+0KRaEz44PzihA9o= X-Google-Smtp-Source: ABdhPJxNmaVTJ1oB8402nXkYY1fhPLPPavO5VuQvfvU5i/ZyMvlRGWcKbI0O0RmKu7baFlC22JdTJw== X-Received: by 2002:a05:651c:555:: with SMTP id q21mr338292ljp.203.1599604862057; Tue, 08 Sep 2020 15:41:02 -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 s15sm268311ljp.25.2020.09.08.15.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:41:01 -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 v7 32/34] i2c: tegra: Clean up and improve comments Date: Wed, 9 Sep 2020 01:40:04 +0300 Message-Id: <20200908224006.25636-33-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Make all comments to be consistent in regards to capitalization and punctuation, correct spelling and grammar errors, improve wording. Signed-off-by: Dmitry Osipenko Tested-by: Thierry Reding Reviewed-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 88 ++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 558b1f2934a0..31fbc6181dd5 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -136,7 +136,7 @@ /* configuration load timeout in microseconds */ #define I2C_CONFIG_LOAD_TIMEOUT 1000000 -/* Packet header size in bytes */ +/* packet header size in bytes */ #define I2C_PACKET_HEADER_SIZE 12 /* @@ -148,11 +148,10 @@ #define I2C_PIO_MODE_PREFERRED_LEN 32 /* - * msg_end_type: The bus control which need to be send at end of transfer. - * @MSG_END_STOP: Send stop pulse at end of transfer. - * @MSG_END_REPEAT_START: Send repeat start at end of transfer. - * @MSG_END_CONTINUE: The following on message is coming and so do not send - * stop or repeat start. + * msg_end_type: The bus control which needs to be sent at end of transfer. + * @MSG_END_STOP: Send stop pulse. + * @MSG_END_REPEAT_START: Send repeat-start. + * @MSG_END_CONTINUE: Don't send stop or repeat-start. */ enum msg_end_type { MSG_END_STOP, @@ -161,10 +160,10 @@ enum msg_end_type { }; /** - * struct tegra_i2c_hw_feature : Different HW support on Tegra - * @has_continue_xfer_support: Continue transfer supports. + * struct tegra_i2c_hw_feature : per hardware generation features + * @has_continue_xfer_support: Continue-transfer supported. * @has_per_pkt_xfer_complete_irq: Has enable/disable capability for transfer - * complete interrupt per packet basis. + * completion interrupt on per packet basis. * @has_config_load_reg: Has the config load register to load the new * configuration. * @clk_divisor_hs_mode: Clock divisor in HS mode. @@ -184,7 +183,7 @@ enum msg_end_type { * @has_mst_fifo: The I2C controller contains the new MST FIFO interface that * provides additional features and allows for longer messages to * be transferred in one go. - * @quirks: i2c adapter quirks for limiting write/read transfer size and not + * @quirks: I2C adapter quirks for limiting write/read transfer size and not * allowing 0 length transfers. * @supports_bus_clear: Bus Clear support to recover from bus hang during * SDA stuck low from device for some unknown reasons. @@ -245,7 +244,7 @@ struct tegra_i2c_hw_feature { * @msg_err: error code for completed message * @msg_buf: pointer to current message data * @msg_buf_remaining: size of unsent data in the message buffer - * @msg_read: identifies read transfers + * @msg_read: indicates read direction of a transfer * @bus_clk_rate: current I2C bus clock rate * @multimaster_mode: indicates that I2C controller is in multi-master mode * @tx_dma_chan: DMA transmit channel @@ -306,8 +305,8 @@ static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, u32 reg) } /* - * i2c_writel and i2c_readl will offset the register if necessary to talk - * to the I2C block inside the DVC block + * If necessary, i2c_writel() and i2c_readl() will offset the register + * in order to talk to the I2C block inside the DVC block. */ static u32 tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, u32 reg) { @@ -322,7 +321,7 @@ static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, u32 reg) { writel_relaxed(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); - /* Read back register to make sure that register writes completed */ + /* read back register to make sure that register writes completed */ if (reg != I2C_TX_FIFO) readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); } @@ -474,7 +473,7 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) * block. This block is identical to the rest of the I2C blocks, except that * it only supports master mode, it has registers moved around, and it needs * some extra init to get it into I2C mode. The register moves are handled - * by i2c_readl and i2c_writel + * by i2c_readl() and i2c_writel(). */ static void tegra_dvc_init(struct tegra_i2c_dev *i2c_dev) { @@ -632,7 +631,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) break; } - /* Make sure clock divisor programmed correctly */ + /* make sure clock divisor programmed correctly */ clk_divisor = FIELD_PREP(I2C_CLK_DIVISOR_HSMODE, i2c_dev->hw->clk_divisor_hs_mode) | FIELD_PREP(I2C_CLK_DIVISOR_STD_FAST_MODE, non_hs_mode); @@ -645,8 +644,8 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) } /* - * configure setup and hold times only when tsu_thd is non-zero. - * otherwise, preserve the chip default values + * Configure setup and hold times only when tsu_thd is non-zero. + * Otherwise, preserve the chip default values. */ if (i2c_dev->hw->has_interface_timing_reg && tsu_thd) i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1); @@ -690,7 +689,7 @@ static int tegra_i2c_disable_packet_mode(struct tegra_i2c_dev *i2c_dev) /* * NACK interrupt is generated before the I2C controller generates - * the STOP condition on the bus. So wait for 2 clock periods + * the STOP condition on the bus. So, wait for 2 clock periods * before disabling the controller so that the STOP condition has * been delivered properly. */ @@ -711,8 +710,8 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) u32 val; /* - * Catch overflow due to message fully sent - * before the check for RX FIFO availability. + * Catch overflow due to message fully sent before the check for + * RX FIFO availability. */ if (WARN_ON_ONCE(!(i2c_dev->msg_buf_remaining))) return -EINVAL; @@ -725,7 +724,7 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) rx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_RX, val); } - /* Rounds down to not include partial word at the end of buf */ + /* round down to exclude partial word at the end of buffer */ words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; if (words_to_transfer > rx_fifo_avail) words_to_transfer = rx_fifo_avail; @@ -737,8 +736,8 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) rx_fifo_avail -= words_to_transfer; /* - * If there is a partial word at the end of buf, handle it manually to - * prevent overwriting past the end of buf + * If there is a partial word at the end of buffer, handle it + * manually to prevent overwriting past the end of buffer. */ if (rx_fifo_avail > 0 && buf_remaining > 0) { /* @@ -778,10 +777,15 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) tx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_TX, val); } - /* Rounds down to not include partial word at the end of buf */ + /* round down to exclude partial word at the end of buffer */ words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; - /* It's very common to have < 4 bytes, so optimize that case. */ + /* + * This hunk pushes 4 bytes at a time into the TX FIFO. + * + * It's very common to have < 4 bytes, hence there is no word + * to push if we have less than 4 bytes to transfer. + */ if (words_to_transfer) { if (words_to_transfer > tx_fifo_avail) words_to_transfer = tx_fifo_avail; @@ -805,8 +809,8 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) } /* - * If there is a partial word at the end of buf, handle it manually to - * prevent reading past the end of buf, which could cross a page + * If there is a partial word at the end of buffer, handle it manually + * to prevent reading past the end of buffer, which could cross a page * boundary and fault. */ if (tx_fifo_avail > 0 && buf_remaining > 0) { @@ -854,7 +858,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) } /* - * I2C transfer is terminated during the bus clear so skip + * I2C transfer is terminated during the bus clear, so skip * processing the other interrupts. */ if (i2c_dev->hw->supports_bus_clear && (status & I2C_INT_BUS_CLR_DONE)) @@ -890,7 +894,8 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) * During message read XFER_COMPLETE interrupt is triggered prior to * DMA completion and during message write XFER_COMPLETE interrupt is * triggered after DMA completion. - * PACKETS_XFER_COMPLETE indicates completion of all bytes of transfer. + * + * PACKETS_XFER_COMPLETE indicates completion of all bytes of transfer, * so forcing msg_buf_remaining to 0 in DMA mode. */ if (status & I2C_INT_PACKET_XFER_COMPLETE) { @@ -908,7 +913,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) } goto done; err: - /* An error occurred, mask all interrupts */ + /* mask all interrupts on error */ tegra_i2c_mask_irq(i2c_dev, I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST | I2C_INT_PACKET_XFER_COMPLETE | I2C_INT_TX_FIFO_DATA_REQ | I2C_INT_RX_FIFO_DATA_REQ); @@ -1337,6 +1342,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], enum msg_end_type end_type = MSG_END_STOP; if (i < (num - 1)) { + /* check whether follow up message is coming */ if (msgs[i + 1].flags & I2C_M_NOSTART) end_type = MSG_END_CONTINUE; else @@ -1566,7 +1572,6 @@ static const struct tegra_i2c_hw_feature tegra194_i2c_hw = { .has_interface_timing_reg = true, }; -/* Match table for of_platform binding */ static const struct of_device_id tegra_i2c_of_match[] = { { .compatible = "nvidia,tegra194-i2c", .data = &tegra194_i2c_hw, }, { .compatible = "nvidia,tegra186-i2c", .data = &tegra186_i2c_hw, }, @@ -1590,7 +1595,7 @@ static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) err = of_property_read_u32(np, "clock-frequency", &i2c_dev->bus_clk_rate); if (err) - i2c_dev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */ + i2c_dev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; multi_mode = of_property_read_bool(np, "multi-master"); i2c_dev->multimaster_mode = multi_mode; @@ -1722,11 +1727,13 @@ static int tegra_i2c_probe(struct platform_device *pdev) goto release_clocks; /* - * VI I2C is in VE power domain which is not always on and not - * an IRQ safe. So, IRQ safe device can't be attached to a non-IRQ - * safe domain as it prevents powering off the PM domain. - * Also, VI I2C device don't need to use runtime IRQ safe as it will - * not be used for atomic transfers. + * VI I2C is in VE power domain which is not always ON and not + * IRQ-safe. Thus, IRQ-safe device shouldn't be attached to a + * non IRQ-safe domain because this prevents powering off the power + * domain. + * + * VI I2C device shouldn't be marked as IRQ-safe because VI I2C won't + * be used for atomic transfers. */ if (!i2c_dev->is_vi) pm_runtime_irq_safe(i2c_dev->dev); @@ -1797,9 +1804,8 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) /* * VI I2C device is attached to VE power domain which goes through - * power ON/OFF during PM runtime resume/suspend. So, controller - * should go through reset and need to re-initialize after power - * domain ON. + * power ON/OFF during of runtime PM resume/suspend, meaning that + * controller needs to be re-initialized after power ON. */ if (i2c_dev->is_vi) { err = tegra_i2c_init(i2c_dev); From patchwork Tue Sep 8 22:40: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: 1360171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Ln3Vqu2r; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKsR1p86z9sTK for ; Wed, 9 Sep 2020 08:42:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730181AbgIHWl3 (ORCPT ); Tue, 8 Sep 2020 18:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730159AbgIHWlR (ORCPT ); Tue, 8 Sep 2020 18:41:17 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A7BAC0617A3; Tue, 8 Sep 2020 15:41:04 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id s205so969970lja.7; Tue, 08 Sep 2020 15:41:04 -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=SkYg8jYSt0RnPP78g1FN0JmBI7qdBbZu2ufkw6F83lI=; b=Ln3Vqu2rimLfxBeQ0zNl7pKjcYsEX7iBexfp5u/9Kfy+yeOHS3Fj87bBJ/tIyVMs6j dRERUyEK7pe6LN9YpVFTVefSlOcjA/i/G8JwV2a5phCAB4DUu8mBeuA0mP97s4ic+82a X/2LUS/pflSlu2BEU8jBdr0rNHqJ6OVDttHTQRdn1M89M3owMNPv1mbSEmgAw9UxNQzA jl/yuJHLCm1pPgmmK1faTANF2Kau6x008qAIo3LP6U3KV9QRvkUQoMm1Mz2+lI/dWAHU irYyy+ECQ4+KX83YToIiWJVWtjsyhoSpHAMgm6WWNqODJXPi1rS7nP3P7XqLJJX5i+V5 BeOg== 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=SkYg8jYSt0RnPP78g1FN0JmBI7qdBbZu2ufkw6F83lI=; b=VgVYeBrpE+fakR/VtayPuTXXFMNO3MCLM9I83/TwY1vVOxFDVAJ4ZKqC5GEPV7O0OD nNBtpoqs9d9Iv3ApKHFOnIMQtqR/dnHs/c4wurf9jg7YuVanqKmajIUGvZhqfshhsVvq KH2833mVn/cNwlBhL1905piLPkqwNyNx+twtCyzm7EOTeKZgeiUspkmDkOAC6qYikKYL L/8NNkLAcyBm7Ne5s1EyLyf5zFaiu5FvJ6JYbWMULsYdc+5VrduSmjUkxHxS2KKrrT/5 4TY/GUiaIfvPkhvgHz2sYmA3ba5bQKvvnne9NP+q4uLwA5vGnRRWFyHb+YcAigxsbedH OCVw== X-Gm-Message-State: AOAM531YOLlSUpmVh5u7gUVJi1BPYfBZQRUC17dTbgoXXsgzynScbQTi 4eobxIXQ27YsWD1S1tZ8N0w= X-Google-Smtp-Source: ABdhPJw6mZ6h0Qy8AQox10aewxD8yb1BSDrYpe/278HFy+6tZhkvboXkRyP0uChBmZ3WeHO40SOAOw== X-Received: by 2002:a2e:8041:: with SMTP id p1mr392069ljg.164.1599604863031; Tue, 08 Sep 2020 15:41:03 -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 s15sm268311ljp.25.2020.09.08.15.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:41:02 -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 v7 33/34] i2c: tegra: Clean up whitespaces, newlines and indentation Date: Wed, 9 Sep 2020 01:40:05 +0300 Message-Id: <20200908224006.25636-34-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Some places in the code are missing newlines or have unnecessary whitespaces and newlines. This creates inconsistency of the code and hurts readability. This patch removes the unnecessary and adds necessary whitespaces / newlines, clears indentation of the code. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 72 +++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 31fbc6181dd5..087f98010963 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -314,6 +314,7 @@ static u32 tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, u32 reg) reg += (reg >= I2C_TX_FIFO) ? 0x10 : 0x40; else if (i2c_dev->is_vi) reg = 0xc00 + (reg << 2); + return reg; } @@ -373,9 +374,12 @@ static int tegra_i2c_dma_submit(struct tegra_i2c_dev *i2c_dev, size_t len) struct dma_chan *chan; dev_dbg(i2c_dev->dev, "starting DMA for length: %zu\n", len); + reinit_completion(&i2c_dev->dma_complete); + dir = i2c_dev->msg_read ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV; chan = i2c_dev->msg_read ? i2c_dev->rx_dma_chan : i2c_dev->tx_dma_chan; + dma_desc = dmaengine_prep_slave_single(chan, i2c_dev->dma_phys, len, dir, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); @@ -387,8 +391,10 @@ static int tegra_i2c_dma_submit(struct tegra_i2c_dev *i2c_dev, size_t len) dma_desc->callback = tegra_i2c_dma_complete; dma_desc->callback_param = i2c_dev; + dmaengine_submit(dma_desc); dma_async_issue_pending(chan); + return 0; } @@ -455,6 +461,7 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) i2c_dev->dma_buf = dma_buf; i2c_dev->dma_phys = dma_phys; + return 0; err_out: @@ -557,6 +564,7 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) dev_err(i2c_dev->dev, "failed to flush FIFO\n"); return err; } + return 0; } @@ -650,8 +658,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) if (i2c_dev->hw->has_interface_timing_reg && tsu_thd) i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1); - clk_multiplier = tlow + thigh + 2; - clk_multiplier *= non_hs_mode + 1; + clk_multiplier = (tlow + thigh + 2) * (non_hs_mode + 1); err = clk_set_rate(i2c_dev->div_clk, i2c_dev->bus_clk_rate * clk_multiplier); @@ -799,9 +806,9 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) */ buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; tx_fifo_avail -= words_to_transfer; + i2c_dev->msg_buf_remaining = buf_remaining; - i2c_dev->msg_buf = buf + - words_to_transfer * BYTES_PER_FIFO_WORD; + i2c_dev->msg_buf = buf + words_to_transfer * BYTES_PER_FIFO_WORD; i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer); @@ -914,12 +921,18 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) goto done; err: /* mask all interrupts on error */ - tegra_i2c_mask_irq(i2c_dev, I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST | - I2C_INT_PACKET_XFER_COMPLETE | I2C_INT_TX_FIFO_DATA_REQ | - I2C_INT_RX_FIFO_DATA_REQ); + tegra_i2c_mask_irq(i2c_dev, + I2C_INT_NO_ACK | + I2C_INT_ARBITRATION_LOST | + I2C_INT_PACKET_XFER_COMPLETE | + I2C_INT_TX_FIFO_DATA_REQ | + I2C_INT_RX_FIFO_DATA_REQ); + if (i2c_dev->hw->supports_bus_clear) tegra_i2c_mask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); + i2c_writel(i2c_dev, status, I2C_INT_STATUS); + if (i2c_dev->is_dvc) dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS); @@ -960,6 +973,7 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) if (i2c_dev->msg_read) { chan = i2c_dev->rx_dma_chan; reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_RX_FIFO); + slv_config.src_addr = i2c_dev->base_phys + reg_offset; slv_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; slv_config.src_maxburst = dma_burst; @@ -971,6 +985,7 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) } else { chan = i2c_dev->tx_dma_chan; reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_TX_FIFO); + slv_config.dst_addr = i2c_dev->base_phys + reg_offset; slv_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; slv_config.dst_maxburst = dma_burst; @@ -1067,6 +1082,7 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) int err; reinit_completion(&i2c_dev->msg_complete); + val = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND | I2C_BC_TERMINATE; i2c_writel(i2c_dev, val, I2C_BUS_CLEAR_CNFG); @@ -1198,7 +1214,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size = msg->len + I2C_PACKET_HEADER_SIZE; xfer_size = ALIGN(xfer_size, BYTES_PER_FIFO_WORD); - i2c_dev->dma_mode = (xfer_size > I2C_PIO_MODE_PREFERRED_LEN) && + + i2c_dev->dma_mode = xfer_size > I2C_PIO_MODE_PREFERRED_LEN && i2c_dev->dma_buf && !i2c_dev->atomic_mode; err = tegra_i2c_config_fifo_trig(i2c_dev, xfer_size); @@ -1210,25 +1227,24 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, * Total bits = 9 bits per byte (including ACK bit) + Start & stop bits */ xfer_time += DIV_ROUND_CLOSEST(((xfer_size * 9) + 2) * MSEC_PER_SEC, - i2c_dev->bus_clk_rate); + i2c_dev->bus_clk_rate); int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; tegra_i2c_unmask_irq(i2c_dev, int_mask); + if (i2c_dev->dma_mode) { if (i2c_dev->msg_read) { dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, - xfer_size, - DMA_FROM_DEVICE); + xfer_size, DMA_FROM_DEVICE); + err = tegra_i2c_dma_submit(i2c_dev, xfer_size); if (err) return err; - } else { dma_sync_single_for_cpu(i2c_dev->dev, i2c_dev->dma_phys, - xfer_size, - DMA_TO_DEVICE); + xfer_size, DMA_TO_DEVICE); } } @@ -1237,10 +1253,11 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (!i2c_dev->msg_read) { if (i2c_dev->dma_mode) { memcpy(i2c_dev->dma_buf, msg->buf, msg->len); + dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, - xfer_size, - DMA_TO_DEVICE); + xfer_size, DMA_TO_DEVICE); + err = tegra_i2c_dma_submit(i2c_dev, xfer_size); if (err) return err; @@ -1251,6 +1268,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (i2c_dev->hw->has_per_pkt_xfer_complete_irq) int_mask |= I2C_INT_PACKET_XFER_COMPLETE; + if (!i2c_dev->dma_mode) { if (msg->flags & I2C_M_RD) int_mask |= I2C_INT_RX_FIFO_DATA_REQ; @@ -1289,10 +1307,9 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (i2c_dev->msg_read && i2c_dev->msg_err == I2C_ERR_NONE) { dma_sync_single_for_cpu(i2c_dev->dev, i2c_dev->dma_phys, - xfer_size, - DMA_FROM_DEVICE); - memcpy(i2c_dev->msg_buf, i2c_dev->dma_buf, - msg->len); + xfer_size, DMA_FROM_DEVICE); + + memcpy(i2c_dev->msg_buf, i2c_dev->dma_buf, msg->len); } } @@ -1379,6 +1396,7 @@ static u32 tegra_i2c_func(struct i2c_adapter *adap) if (i2c_dev->hw->has_continue_xfer_support) ret |= I2C_FUNC_NOSTART; + return ret; } @@ -1737,6 +1755,7 @@ static int tegra_i2c_probe(struct platform_device *pdev) */ if (!i2c_dev->is_vi) pm_runtime_irq_safe(i2c_dev->dev); + pm_runtime_enable(i2c_dev->dev); err = tegra_i2c_init_hardware(i2c_dev); @@ -1781,11 +1800,11 @@ static int tegra_i2c_remove(struct platform_device *pdev) struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev); i2c_del_adapter(&i2c_dev->adapter); - pm_runtime_disable(i2c_dev->dev); tegra_i2c_release_dma(i2c_dev); tegra_i2c_release_clocks(i2c_dev); + return 0; } @@ -1883,15 +1902,14 @@ static const struct dev_pm_ops tegra_i2c_pm = { }; static struct platform_driver tegra_i2c_driver = { - .probe = tegra_i2c_probe, - .remove = tegra_i2c_remove, - .driver = { - .name = "tegra-i2c", + .probe = tegra_i2c_probe, + .remove = tegra_i2c_remove, + .driver = { + .name = "tegra-i2c", .of_match_table = tegra_i2c_of_match, - .pm = &tegra_i2c_pm, + .pm = &tegra_i2c_pm, }, }; - module_platform_driver(tegra_i2c_driver); MODULE_DESCRIPTION("nVidia Tegra2 I2C Bus Controller driver"); From patchwork Tue Sep 8 22:40:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1360168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=UWKnvayz; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BmKrW5b3Wz9sTN for ; Wed, 9 Sep 2020 08:41:31 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730184AbgIHWl3 (ORCPT ); Tue, 8 Sep 2020 18:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730161AbgIHWlR (ORCPT ); Tue, 8 Sep 2020 18:41:17 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0763C0617A4; Tue, 8 Sep 2020 15:41:05 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id z17so515474lfi.12; Tue, 08 Sep 2020 15:41:05 -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=wTOTLcjkkLtXssJ2ZijwIYtMxeJXm/EDwQWOhPT57kQ=; b=UWKnvayzBIo8IJvyj6xeZAbLh+4JYiwBojik1Y2qZ4K7BYF2Pb+z9PwEn8Yz2XpvS4 VweCEIzB1KsASsEe05X3iB4FM+/wE/YhGYT8b5UxPjbCSpjiGQn9FJypmX0C9653HiHW 34p8q8MW5eg5ONZr71YWjnzkiPBMNhiVBF9abFDPh7gIGkn6a5NiUO8cZzgdduJdHT02 /F3JyGSLR9tU9QR776DwUD0ix4UuHYnFPQzb7fmf5kH4fpOD7aYnX26+VUu6OV6IXYPF +XBo/hqzz9he4+xoXqkUQc/BlETKFrSYhwMr3GhuiYJF7uk5l8IUJlYOvoLFqXc5x/F+ xz9g== 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=wTOTLcjkkLtXssJ2ZijwIYtMxeJXm/EDwQWOhPT57kQ=; b=LuCvdA2ReHSJRY5AlwISR1Su4KHp7R1hWNZnxIZ0ErVNdUbbHVMt7Eybwc324wkW1/ u/u+626871pPPux2R95R9P+1Qr6hR8IF7J/bwgrKMa2l3t4ml+DnhwGmb2LKfRTJP5jk 97DoE3Lu52jCAZuPj/BPGS36l2SCqfy/fOa0aCmV9e6r8Y21m4mRDOhhfnZvzC03oOaS KxI20nuSZb185Cej329ROgzFv8elrCTiL4dnNz6WKTiW+8x4xCCR6jl+o2cOFB9clF58 G/2J2y7scokPrmGGXoXB+qJjnWh5xtA1ORzyGZ3Qg7yo7NsAuJwLbC4bnEbfR1I1H+G7 68tA== X-Gm-Message-State: AOAM530I75caor0w1UtCIBtfPEg452yvCL9s//IVlPXmbTmDDGs+PrrA 1ogaC6jF5HqOTuJw5XD67nOjzOAPuCg= X-Google-Smtp-Source: ABdhPJyG8o8852Td7IDedsDkJi3Xs2rjPRURztg5cedM+vp/9v/nP4CL3hDLG3pSyFG4VZ91aZvgLQ== X-Received: by 2002:a19:42c4:: with SMTP id p187mr530742lfa.149.1599604864077; Tue, 08 Sep 2020 15:41:04 -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 s15sm268311ljp.25.2020.09.08.15.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 15:41:03 -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 v7 34/34] i2c: tegra: Improve driver module description Date: Wed, 9 Sep 2020 01:40:06 +0300 Message-Id: <20200908224006.25636-35-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908224006.25636-1-digetx@gmail.com> References: <20200908224006.25636-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Use proper spelling of "NVIDIA" and don't designate driver as Tegra2-only since newer SoC generations are supported as well. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko Acked-by: Thierry Reding Tested-by: Thierry Reding --- drivers/i2c/busses/i2c-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 087f98010963..1b56d63bdd3c 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1912,6 +1912,6 @@ static struct platform_driver tegra_i2c_driver = { }; module_platform_driver(tegra_i2c_driver); -MODULE_DESCRIPTION("nVidia Tegra2 I2C Bus Controller driver"); +MODULE_DESCRIPTION("NVIDIA Tegra I2C Bus Controller driver"); MODULE_AUTHOR("Colin Cross"); MODULE_LICENSE("GPL v2");