From patchwork Thu Sep 3 00:52: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: 254835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BF8EC433E7 for ; Thu, 3 Sep 2020 00:56:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2ACF32080C for ; Thu, 3 Sep 2020 00:56:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jsMUtQ6/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728192AbgICAzw (ORCPT ); Wed, 2 Sep 2020 20:55:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727107AbgICAxy (ORCPT ); Wed, 2 Sep 2020 20:53:54 -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 3A6F3C061246; Wed, 2 Sep 2020 17:53:54 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id u4so534633ljd.10; Wed, 02 Sep 2020 17:53: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=sZD+fCtDbYnWXQk8Be3VFNb2Qop9c99v3RaE1XWrdU8=; b=jsMUtQ6/3ZfGHoMUA/nJYUCzuin8+fIK0w1KtwslMDrrHiSnVsPRwFvVB9oGfMLkF+ IGIOM4kguc6M6jUdiWn42PTxBAAfeIlEhgoUDDgVijIZV8MIcV+abNr/KmHLWefjzaID 2IwMIF0m0hTrutt60Z6Skru5WswWi1Go5PpRCo3kmxs1mnmapDVZrvAqn85vliHrJik3 eK4U5PL5GZbGu7Jtsf/+Cls3/+83mQoVc1g0o2TqOJvtao4YEHFcteKwMYiXuN2IKizO Bgu7+/XkFyyeOo3H7A+0crwMWVSf5AXhbxUF4vbsSiC8mB2ri6/M/gQRg8tRzjXV+OlA hA+A== 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=sZD+fCtDbYnWXQk8Be3VFNb2Qop9c99v3RaE1XWrdU8=; b=KhR4bnjL3tkqx1Ql6DttZ0lrGbvsgMihvE85stBjJe3cbPqAZmYAr7QaREv4GXNOfV ezEDh9koIx8hiMvlAORNxZgwboSZE207Y76MdiBur580rqqylUDvrj9VNnHcWTxSBt3F on05oD4+UlxKQlBOBujJj8JXmMZyrP6zoUrESVq/6lIdTJVz/PzOo+m/jjnGu7FlrMNh qbZeKLEWlbi01a6lbt0iouUfaakUXnLa89x1TRyNENJMA3w/b5JSZQ6e8mh/D4a+wxlO c6CwtFBKfmmhIuC1U3f10VpHHzNYJJlWq8m9jkXzmcuumSmadzRIQ71pPuQlx0C8RMJX QWkw== X-Gm-Message-State: AOAM5313iVA/tGhIE3njpL2+rr+R7i6jYH/oustuip0ufdyS8/kSnE16 QGXNGCIiF9U1/sJQ1GsEXC0= X-Google-Smtp-Source: ABdhPJwmQvdTzq6Zc42d5JlTjGv6d/SWVdYCqbDhGWUnIDz+ujCYWwwgNDxl90+WazHBk6jJK5wPAw== X-Received: by 2002:a2e:9899:: with SMTP id b25mr248714ljj.178.1599094432614; Wed, 02 Sep 2020 17:53: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 g1sm250321ljj.56.2020.09.02.17.53.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 17:53: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 v3 02/22] i2c: tegra: Add missing newline before returns Date: Thu, 3 Sep 2020 03:52:40 +0300 Message-Id: <20200903005300.7894-3-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903005300.7894-1-digetx@gmail.com> References: <20200903005300.7894-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Some places in the code are missing a newline before return, making code more difficult to read and creating inconsistency of the code. This patch adds the missing newlines. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 72f03ded2eae..efc6e97aeb8a 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -317,6 +317,7 @@ static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, reg += (reg >= I2C_TX_FIFO) ? 0x10 : 0x40; else if (i2c_dev->is_vi) reg = 0xc00 + (reg << 2); + return reg; } @@ -392,6 +393,7 @@ static int tegra_i2c_dma_submit(struct tegra_i2c_dev *i2c_dev, size_t len) dma_desc->callback_param = i2c_dev; dmaengine_submit(dma_desc); dma_async_issue_pending(chan); + return 0; } @@ -510,6 +512,7 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) ktime = ktime_get(); } + return 0; err_timeout: @@ -717,6 +720,7 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) clk_disable(i2c_dev->slow_clk); disable_fast_clk: clk_disable(i2c_dev->fast_clk); + return ret; } @@ -1431,6 +1435,7 @@ static u32 tegra_i2c_func(struct i2c_adapter *adap) if (i2c_dev->hw->has_continue_xfer_support) ret |= I2C_FUNC_NOSTART; + return ret; } @@ -1898,6 +1903,7 @@ static int tegra_i2c_remove(struct platform_device *pdev) clk_unprepare(i2c_dev->fast_clk); tegra_i2c_release_dma(i2c_dev); + return 0; } From patchwork Thu Sep 3 00:52: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: 254838 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85FA0C43461 for ; Thu, 3 Sep 2020 00:55:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64778204EC for ; Thu, 3 Sep 2020 00:55:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IBaJQSEy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728157AbgICAz0 (ORCPT ); Wed, 2 Sep 2020 20:55:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727122AbgICAx4 (ORCPT ); Wed, 2 Sep 2020 20:53:56 -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 3C7ADC061249; Wed, 2 Sep 2020 17:53:56 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id z19so845689lfr.4; Wed, 02 Sep 2020 17:53: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=hyq+q97UN4p59/VDrav/iLglYVPxR0jExQlR01K2sGE=; b=IBaJQSEy7AKhSWWM96SzLKbozmy4W2t0TzTqDOAZNxslBH3IoCD2o91OX9kB6mZqRh MS3t4K9ngII+9QmqYbQkvnrj7grru86mVIsfAru4rM6V0TB6NZg6472MNb4EpY/zKRkQ WYYL8V+hroXBy6++hytb/exTxfDu1TDQvjGZFdcyfd/LYS3tSHvmFdXSMAbbHJ35a0wO U8nmj33o1M8QbMolMtgpPlICqrrIOj7imkugLLfCKEBq6ox9C6+Vo81a64ZZ/sixS9iO j6oeEoY9GaVpz7loLI6POxoS2ggoV6bYCJel8PmuPNHam+Sgc8ILtEPsCPKdaZLKVH1l ve9g== 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=hyq+q97UN4p59/VDrav/iLglYVPxR0jExQlR01K2sGE=; b=cE1iFoQfij2JVC6HA5oqZphy71/CXjZfJA3xTwn+R/OcEeJvKIz63uAPSftrwysEeP j1+0WmCXJ9wbE3Xras/6C+s77AvE2ywhl1ztvhmW/mYJpOT2X6GDBYMcQtS5AZG83XoH npjNHSQ/msYevbYRMkrW1fXYvm/e7iGv37yb1a77P+VSwoNdkj1Xx//3am+yII6dQ0V4 dE6TUlyfajXxn3XNvW8bIPsjJj8zCIMH+3YCgifGLbLXOyZ3r10m8NnkO+birqZ36WVO 5zvUeswJnvhMVramMkpiVo3OWEdofsa+X9Rb9f/WWe4GNHCn2MocQ8VnNDKa+xCBFq9Z WNOA== X-Gm-Message-State: AOAM531hoRDU7giGY9F/spDEn7dUstSVS1D4/v74oWogPygOYrwu9KvL R0COZgTWhvLP1Txl5fWGDe8= X-Google-Smtp-Source: ABdhPJyWEW1JSEKu0uSLc+V3ZC7+0QIuApFfHUS+nibUUs0ZNCPzPTMaDrrkxQkjtOhsWl98AU81QQ== X-Received: by 2002:ac2:546f:: with SMTP id e15mr281845lfn.133.1599094434637; Wed, 02 Sep 2020 17:53: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 g1sm250321ljj.56.2020.09.02.17.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 17:53: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 v3 04/22] i2c: tegra: Don't ignore tegra_i2c_flush_fifos() error Date: Thu, 3 Sep 2020 03:52:42 +0300 Message-Id: <20200903005300.7894-5-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903005300.7894-1-digetx@gmail.com> References: <20200903005300.7894-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The tegra_i2c_flush_fifos() may fail and transfer should be aborted in this case. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- 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 79e542cf3e59..b912a7153e3b 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1189,7 +1189,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 Thu Sep 3 00:52:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 254837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F203CC2BBDB for ; Thu, 3 Sep 2020 00:55:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC83B2080C for ; Thu, 3 Sep 2020 00:55:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gd8Mzjmn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728135AbgICAzZ (ORCPT ); Wed, 2 Sep 2020 20:55:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727804AbgICAx6 (ORCPT ); Wed, 2 Sep 2020 20:53:58 -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 5143AC061245; Wed, 2 Sep 2020 17:53:58 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id a15so1448951ljk.2; Wed, 02 Sep 2020 17:53: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=/Fbav35DylyG31VGtNGcRkkQWl1nlYoWvd2/HtfHxMg=; b=Gd8Mzjmn32f0v35D4tGYOAhJQWqbzqMDQD1l6HyRi6zyjY3o4yG1PFNeXkFgrT0WCJ Mnu7cG98PZiFd6mVRQW28auxAjaB/Bp/8H4Iww5IZktX0aDOOmjISknZ2Y1Ia8phPavR vhI9bIFiydnxPaKXc06rJwMLGY+ZKp7kWaFtB/6bzUOeq705C8LCUDb/Bveu984c7EBQ E3GYETNMJn84TYPI6+Q3T4GuBGyXXxbmivbU1jfNmgWWpqeibToqmpjEopfVF69vLw5J GzUKq4topKPjJl/ftGf+v2qd1hwhZBHEpd1kyj7QFsV/AF5Gp/5is30vLtxwcp0IQfuz y+Lw== 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=/Fbav35DylyG31VGtNGcRkkQWl1nlYoWvd2/HtfHxMg=; b=UX4maxzGBA7NmJdeBIGFinvLBSZ1p1ruNSF7kpovUlUGh3ICqnZXFVEtWWpFlSo6yv zVJyahD9lDA9JmrRm0Hq4yU80iFAotMah9Gtl/b6a4K5qcc9y9dnj4rppwLHOlOXFygS /FfYSxw89o252ua76G6KZHYuQrc8cK5RyjxEDN8Dh3uax90E57/DjAMFFYbKlfVWg5n4 nZ/UsUWwKVXeW2s8fPUXkQR6DBS1OTqzP1NHCY/Oi+jneiJ3vsMm5Gkiv8O2FZocFDTP PuebSTyY06kz6C13Xauzz/Idbxp4IfFubhe0tjqKVp8XrvL9jIi0RBDTIiaOurLD1o/Z cupQ== X-Gm-Message-State: AOAM530SpQyb8MVBqUJOemdUOrAj2C5fLGNPI8IEn8u8GyGqnQ2q2Bz1 jOns0VIQfZMsEROLuXsvw0M= X-Google-Smtp-Source: ABdhPJwJjDHDKkUpzQ0cPkBGkWXHGKq3sgUsvGnsE6eYMRLxtL+2wD16LJpEX0Wh9uk63mbn3cvtZA== X-Received: by 2002:a2e:9e43:: with SMTP id g3mr263001ljk.122.1599094436722; Wed, 02 Sep 2020 17:53: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 g1sm250321ljj.56.2020.09.02.17.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 17:53: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 v3 06/22] i2c: tegra: Improve formatting of function variables Date: Thu, 3 Sep 2020 03:52:44 +0300 Message-Id: <20200903005300.7894-7-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903005300.7894-1-digetx@gmail.com> References: <20200903005300.7894-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Reorder the definition of variables in the code in order to make code easier to read. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 51 ++++++++++++++-------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 22f6020e79aa..98b1a5656518 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -419,8 +419,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) @@ -523,11 +523,11 @@ static int tegra_i2c_flush_fifos(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; - u8 *buf = i2c_dev->msg_buf; size_t buf_remaining = i2c_dev->msg_buf_remaining; + u8 *buf = i2c_dev->msg_buf; int words_to_transfer; + int rx_fifo_avail; + u32 val; /* * Catch overflow due to message fully sent @@ -584,11 +584,11 @@ 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; - u8 *buf = i2c_dev->msg_buf; size_t buf_remaining = i2c_dev->msg_buf_remaining; + u8 *buf = i2c_dev->msg_buf; int words_to_transfer; + int tx_fifo_avail; + u32 val; if (i2c_dev->hw->has_mst_fifo) { val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); @@ -794,11 +794,8 @@ static void tegra_i2c_vi_init(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit) { - u32 val; + u32 val, clk_divisor, clk_multiplier, tsu_thd, tlow, thigh; int err; - u32 clk_divisor, clk_multiplier; - u32 tsu_thd; - u8 tlow, thigh; err = reset_control_reset(i2c_dev->rst); if (WARN_ON_ONCE(err)) @@ -906,9 +903,9 @@ static int tegra_i2c_disable_packet_mode(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); @@ -1012,12 +1009,11 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) static void 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}; + unsigned long reg_offset; + u32 val, reg, dma_burst; struct dma_chan *chan; int ret; - unsigned long reg_offset; if (i2c_dev->hw->has_mst_fifo) reg = I2C_MST_FIFO_CONTROL; @@ -1142,9 +1138,9 @@ tegra_i2c_wait_completion_timeout(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); - int err; unsigned long time_left; u32 reg; + int err; reinit_completion(&i2c_dev->msg_complete); reg = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND | @@ -1180,14 +1176,12 @@ 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; + unsigned long time_left, xfer_time = 100; + u32 packet_header, int_mask; u32 *buffer = NULL; - int err = 0; + size_t xfer_size; bool dma; - u16 xfer_time = 100; + int err; err = tegra_i2c_flush_fifos(i2c_dev); if (err) @@ -1381,8 +1375,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) { @@ -1437,8 +1430,8 @@ static u32 tegra_i2c_func(struct i2c_adapter *adap) 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); @@ -1664,14 +1657,12 @@ MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); static int tegra_i2c_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct clk *div_clk, *fast_clk; struct tegra_i2c_dev *i2c_dev; + phys_addr_t base_phys; struct resource *res; - struct clk *div_clk; - struct clk *fast_clk; void __iomem *base; - phys_addr_t base_phys; - int irq; - int ret; + int irq, ret; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); base_phys = res->start; From patchwork Thu Sep 3 00:52: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: 254845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1824DC43461 for ; Thu, 3 Sep 2020 00:54:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E6C2E20758 for ; Thu, 3 Sep 2020 00:54:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cObvUMwP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727892AbgICAyJ (ORCPT ); Wed, 2 Sep 2020 20:54:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727818AbgICAx7 (ORCPT ); Wed, 2 Sep 2020 20:53:59 -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 3C6DFC06124F; Wed, 2 Sep 2020 17:53:59 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id r13so1455778ljm.0; Wed, 02 Sep 2020 17:53: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=TMlA3jr28uMb7L0xhhBkqq30RApgcVYpT2jSq42Q4zw=; b=cObvUMwPsKab4wBfLTRg35yhngfJSHZUNorm6LgzTnhGbwFFAkudXUPrGlzSwnfYsw 8rjLWTmKohk99B/lz5a3mmxyxzzAEwxl3dh7JQGNLEcKLZmyNtI0pVM7vBxjZ9utQLy5 iqfqU6BKVcoc68sIPYziWgWz8+SprYB6xPzl1Xn86Zkzi65ozeNDedCXQSUXh5FtOM0U q3uaBth5x/yUa92M0IdU8jbHOmWP39XmgQmQiGFHqqBiBbxuV326QjAgLeMLC+mmDzgP 7hQA1MBycw/6deo9a2F5eQfoifYMWmJc0rgWg7HS9kP7Bv8V/5b9hgt4wEEp2Yf5egRn 6pww== 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=TMlA3jr28uMb7L0xhhBkqq30RApgcVYpT2jSq42Q4zw=; b=tGlqpIkPTY+2s5dJ9rpz62tGzTSEI9/JWip+wAd029ZmMEe2wpgaGAOPBiyCbsPw9l TZvASNdbOjjW+JKpVV3i2O2Twlhdlxs+EQ8msPfNKPSHBJ1aUzv0UFTrnzf6lBr2gJ3l +a8xxCEKuIGV4H1w6UnHY/Qf0GIxiLV3BTpA20DJNpJr7Hf3IT3hQeiWmg1G5UHmM5Kg XvYH+p5dTXKaZE7PlGrkgdzZdrGf+3KeLjgjEHTBh2pZZh/fVMNvMawuJST1jO6q5VYN OlC2a1MTEO8K1QsU8InLE94f4OGabjEOwdJlcfz0r/S41zSBcb2bP95ELYZLIob+R3Mk +e7g== X-Gm-Message-State: AOAM532SGbaYh0+8/Asoub0ACILJYP98a5l+hnM8WSJuTW3zaMJROhzt p+1qRpQV5319WU7Bu5MDjA5kPrx6r9w= X-Google-Smtp-Source: ABdhPJw6j6sE1V4OWWrXm5q2JE8KSvqHg66382HIAcN3sxocTcr5TzADcGQxxrbbJQeGABySQ9iy5w== X-Received: by 2002:a2e:b8d6:: with SMTP id s22mr283144ljp.284.1599094437694; Wed, 02 Sep 2020 17:53: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 g1sm250321ljj.56.2020.09.02.17.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 17:53: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 v3 07/22] i2c: tegra: Use dev_err_probe() Date: Thu, 3 Sep 2020 03:52:45 +0300 Message-Id: <20200903005300.7894-8-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903005300.7894-1-digetx@gmail.com> References: <20200903005300.7894-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Use dev_err_probe() to replace the manual -EPROBE_DEFER handling, making code cleaner. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 98b1a5656518..409f6bc5caa8 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1656,8 +1656,8 @@ MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); static int tegra_i2c_probe(struct platform_device *pdev) { + struct clk *div_clk, *fast_clk, *slow_clk; struct device *dev = &pdev->dev; - struct clk *div_clk, *fast_clk; struct tegra_i2c_dev *i2c_dev; phys_addr_t base_phys; struct resource *res; @@ -1678,13 +1678,9 @@ static int tegra_i2c_probe(struct platform_device *pdev) irq = res->start; 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, "failed to get div-clk: %ld\n", - PTR_ERR(div_clk)); - - return PTR_ERR(div_clk); - } + if (IS_ERR(div_clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(div_clk), + "failed to get div-clk\n"); i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); if (!i2c_dev) @@ -1723,24 +1719,20 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (!i2c_dev->hw->has_single_clk_source) { fast_clk = devm_clk_get(&pdev->dev, "fast-clk"); - if (IS_ERR(fast_clk)) { - dev_err(dev, "failed to get fast clock\n: %ld\n", - PTR_ERR(fast_clk)); + if (IS_ERR(fast_clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(fast_clk), + "failed to get 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)); + slow_clk = devm_clk_get(dev, "slow"); + if (IS_ERR(slow_clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(slow_clk), + "failed to get slow clock\n"); - return PTR_ERR(i2c_dev->slow_clk); - } + i2c_dev->slow_clk = slow_clk; } platform_set_drvdata(pdev, i2c_dev); From patchwork Thu Sep 3 00:52:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 254836 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D4C6C2D0A5 for ; Thu, 3 Sep 2020 00:55:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70A122086A for ; Thu, 3 Sep 2020 00:55:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QNupbBjy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728113AbgICAzY (ORCPT ); Wed, 2 Sep 2020 20:55:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727852AbgICAyD (ORCPT ); Wed, 2 Sep 2020 20:54:03 -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 4CB51C061247; Wed, 2 Sep 2020 17:54:01 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id e11so1411199ljn.6; Wed, 02 Sep 2020 17:54: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=x1zSL+5XrZ1f5CiQoL/vK+B3H/oDgqCKzqkda5Kz3q8=; b=QNupbBjyW8Qu0LunCK4NJ1lAuNqY0K2uhx2PLJUM7maEzDRBMIOpFKP4qo1gbow9p3 Gwsc+Bbdg34RyuttExzw9toGbH/C/rot/szXnbHoIdiqm4N4a4L3OQe9jdaWcgxwTUji OK0gJzaI1Js0a8I7ub0tR+iwMLT7rOgrHDS9P8Lxna2skgqR3UPUKBXr0pm835fg7H0K UBtK+w9Mz43yZT+CJAv+SDjXlSK/ZorVxtTEQxk2epKbqieN0DB/vuZri60+eh19WC4e jkgdLQ4ivnZDdeC4yVnHq5FDisWaBvkBnrq0fqHLFmVeC1z/ZpnTdpW4MH/a27mm5J6K /f2Q== 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=x1zSL+5XrZ1f5CiQoL/vK+B3H/oDgqCKzqkda5Kz3q8=; b=DrrW1AbPy9uKK/JxtM86BFY66W028pbvbc41qPKo/koiGuN7is7aoWsgfV9tHsBRIA CmGXVGgsdbmlWJ4c/z9ZXZ87VzHW28zLQj1yCbTgTqILiI7OljRklbfs+CbbWIM3q0x3 izOHsHWcdLiow8QRGSRvjAcT0q8Xy9YurklrJXDOWpMAVWeK5pqwqmQOD/vCjmuWwyQe 81UUfAY6MLKG3hLLYsGf09sSUATYXOXjM0W38U2SKwfv+ktQtR4B8tACod+dGkoe8u/T 45zLnfDGq02Pm588nUyWWtjRrHgzInsOckeNcQlYfXVSz4PoBNkomSk/CMs8yjzesmrH we7g== X-Gm-Message-State: AOAM530yCmI92L8tKpkPhvHcz1NkR0mf2gJ+2MA6XgOAFVlhr9zIpIdt QNBYU0lNNEaDpXmk9IJIFQQ= X-Google-Smtp-Source: ABdhPJy0fvwIBTRs/0shQjTtL64TL9+TDhPZuA7M3L+Lq2QAhURoNVIJ2cYYBAg2jkfiS7OtyXuziA== X-Received: by 2002:a2e:7210:: with SMTP id n16mr287821ljc.262.1599094439623; Wed, 02 Sep 2020 17:53: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 g1sm250321ljj.56.2020.09.02.17.53.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 17:53: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 v3 09/22] i2c: tegra: Clean up probe function Date: Thu, 3 Sep 2020 03:52:47 +0300 Message-Id: <20200903005300.7894-10-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903005300.7894-1-digetx@gmail.com> References: <20200903005300.7894-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The driver's probe function code is difficult to read and follow. This patch reorders code of the probe function, forming logical groups that are easy to work with. The clock and hardware initializations are factored out into separate functions in order to keep code clean and ease error unwinding. Driver now makes use of devm_platform_get_and_ioremap_resource() and platform_get_irq() which are replacing boilerplate parts of the code. The dev_err_probe() is now used for reset control retrieval because reset is now requested before clocks, and thus, BPMP driver that provides reset controls for newer SoCs may cause the probe defer. The error message of devm_request_irq() is removed because this function takes care of printing the message by itself. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 359 ++++++++++++++++++--------------- 1 file changed, 196 insertions(+), 163 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index a8ef8619b7ef..35a5d46865bc 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -447,6 +447,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) { @@ -1427,19 +1430,25 @@ static u32 tegra_i2c_func(struct i2c_adapter *adap) return ret; } -static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) +static int tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) { struct device_node *np = i2c_dev->dev->of_node; + u32 bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; bool multi_mode; - int ret; - 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 */ + of_property_read_u32(np, "clock-frequency", &bus_clk_rate); + i2c_dev->bus_clk_rate = bus_clk_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; + + return 0; } static const struct i2c_algorithm tegra_i2c_algo = { @@ -1654,203 +1663,234 @@ static const struct of_device_id tegra_i2c_of_match[] = { }; MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); -static int tegra_i2c_probe(struct platform_device *pdev) +static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev) { - struct clk *div_clk, *fast_clk, *slow_clk; - struct device *dev = &pdev->dev; - struct tegra_i2c_dev *i2c_dev; - phys_addr_t base_phys; - struct resource *res; - void __iomem *base; - int irq, ret; + const struct tegra_i2c_hw_feature *hw = i2c_dev->hw; + struct device *dev = i2c_dev->dev; + struct clk *clk; + int err, mode; + + clk = devm_clk_get(dev, "div-clk"); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), + "failed to get div-clk\n"); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - base_phys = res->start; - base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(base)) - return PTR_ERR(base); + i2c_dev->div_clk = clk; - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (!res) { - dev_err(dev, "no IRQ resource\n"); - return -EINVAL; + if (!hw->has_single_clk_source) { + clk = devm_clk_get(dev, "fast-clk"); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), + "failed to get fast-clk\n"); + + i2c_dev->fast_clk = clk; } - irq = res->start; - div_clk = devm_clk_get(&pdev->dev, "div-clk"); - if (IS_ERR(div_clk)) - return dev_err_probe(&pdev->dev, PTR_ERR(div_clk), - "failed to get div-clk\n"); + if (i2c_dev->is_vi) { + clk = devm_clk_get(dev, "slow"); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), + "failed to get slow clk\n"); - i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); - if (!i2c_dev) - return -ENOMEM; + i2c_dev->slow_clk = clk; + } - 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; - i2c_dev->irq = irq; - i2c_dev->cont_id = pdev->id; - i2c_dev->dev = &pdev->dev; + err = clk_prepare(i2c_dev->fast_clk); + if (err) { + dev_err(dev, "failed to prepare fast clk: %d\n", err); + return err; + } - i2c_dev->rst = devm_reset_control_get_exclusive(&pdev->dev, "i2c"); - if (IS_ERR(i2c_dev->rst)) { - dev_err(dev, "failed to get reset control: %pe\n", - i2c_dev->rst); + err = clk_prepare(i2c_dev->slow_clk); + if (err) { + dev_err(dev, "failed to prepare slow clk: %d\n", err); + goto unprepare_fast_clk; + } - return PTR_ERR(i2c_dev->rst); + err = clk_prepare(i2c_dev->div_clk); + if (err) { + dev_err(dev, "failed to prepare div-clk: %d\n", err); + goto unprepare_slow_clk; } - tegra_i2c_parse_dt(i2c_dev); + if (i2c_dev->is_multimaster_mode) { + err = clk_enable(i2c_dev->div_clk); + if (err) { + dev_err(dev, "failed to enable div-clk: %d\n", err); + goto unprepare_div_clk; + } + } - 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; - init_completion(&i2c_dev->msg_complete); - init_completion(&i2c_dev->dma_complete); + switch (i2c_dev->bus_clk_rate) { + case I2C_MAX_FAST_MODE_FREQ + 1 ... I2C_MAX_FAST_MODE_PLUS_FREQ: + mode = hw->clk_divisor_fast_plus_mode; + break; - if (!i2c_dev->hw->has_single_clk_source) { - fast_clk = devm_clk_get(&pdev->dev, "fast-clk"); - if (IS_ERR(fast_clk)) - return dev_err_probe(&pdev->dev, PTR_ERR(fast_clk), - "failed to get fast clock\n"); + case I2C_MAX_STANDARD_MODE_FREQ + 1 ... I2C_MAX_FAST_MODE_FREQ: + mode = hw->clk_divisor_fast_mode; + break; - i2c_dev->fast_clk = fast_clk; + default: + mode = hw->clk_divisor_std_mode; + break; } - if (i2c_dev->is_vi) { - slow_clk = devm_clk_get(dev, "slow"); - if (IS_ERR(slow_clk)) - return dev_err_probe(&pdev->dev, PTR_ERR(slow_clk), - "failed to get slow clock\n"); + i2c_dev->clk_divisor_non_hs_mode = mode; - i2c_dev->slow_clk = slow_clk; - } + return 0; - platform_set_drvdata(pdev, i2c_dev); +unprepare_div_clk: + clk_unprepare(i2c_dev->div_clk); +unprepare_slow_clk: + clk_unprepare(i2c_dev->slow_clk); +unprepare_fast_clk: + clk_unprepare(i2c_dev->fast_clk); - ret = clk_prepare(i2c_dev->fast_clk); - if (ret < 0) { - dev_err(dev, "failed to prepare fast clock: %d\n", ret); - return ret; - } + return err; +} - 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; - } +static void tegra_i2c_release_clocks(struct tegra_i2c_dev *i2c_dev) +{ + if (i2c_dev->is_multimaster_mode) + clk_disable(i2c_dev->div_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; + clk_unprepare(i2c_dev->div_clk); + clk_unprepare(i2c_dev->slow_clk); + clk_unprepare(i2c_dev->fast_clk); +} - ret = clk_prepare(i2c_dev->div_clk); - if (ret < 0) { - dev_err(dev, "failed to prepare div-clk: %d\n", ret); - goto unprepare_slow_clk; - } +static int tegra_i2c_init_runtime_pm_and_hardware(struct tegra_i2c_dev *i2c_dev) +{ + int ret; /* - * 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(&pdev->dev); - pm_runtime_enable(&pdev->dev); + pm_runtime_irq_safe(i2c_dev->dev); + + pm_runtime_enable(i2c_dev->dev); + ret = pm_runtime_get_sync(i2c_dev->dev); if (ret < 0) { - dev_err(dev, "runtime resume failed\n"); - goto disable_rpm; + dev_err(i2c_dev->dev, "runtime resume failed: %d\n", ret); + pm_runtime_disable(i2c_dev->dev); + return ret; } - if (i2c_dev->is_multimaster_mode) { - ret = clk_enable(i2c_dev->div_clk); - if (ret < 0) { - dev_err(dev, "failed to enable div-clk: %d\n", ret); - goto put_rpm; - } - } + /* initialize hardware state */ + ret = tegra_i2c_init(i2c_dev, false); - if (i2c_dev->hw->supports_bus_clear) - i2c_dev->adapter.bus_recovery_info = &tegra_i2c_recovery_info; + pm_runtime_put(i2c_dev->dev); - ret = tegra_i2c_init_dma(i2c_dev); - if (ret < 0) - goto disable_div_clk; + return ret; +} - ret = tegra_i2c_init(i2c_dev, false); - if (ret) { - dev_err(dev, "failed to initialize I2C controller\n"); - goto release_dma; - } +static int tegra_i2c_probe(struct platform_device *pdev) +{ + struct tegra_i2c_dev *i2c_dev; + struct resource *res; + int err; + i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); + if (!i2c_dev) + return -ENOMEM; + + 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; + + /* initialize virt base of hardware registers */ + i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); + if (IS_ERR(i2c_dev->base)) + return PTR_ERR(i2c_dev->base); + + /* initialize phys base of hardware registers */ + i2c_dev->base_phys = res->start; + + /* initialize controller's interrupt */ + err = platform_get_irq(pdev, 0); + if (err < 0) + return err; + + 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), i2c_dev); - if (ret) { - dev_err(dev, "failed to request IRQ %i\n", i2c_dev->irq); - goto release_dma; + err = devm_request_irq(i2c_dev->dev, i2c_dev->irq, tegra_i2c_isr, + IRQF_NO_SUSPEND, dev_name(i2c_dev->dev), + i2c_dev); + if (err) + return err; + + /* initialize hardware reset control */ + i2c_dev->rst = devm_reset_control_get_exclusive(i2c_dev->dev, "i2c"); + if (IS_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); } - i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); + err = tegra_i2c_parse_dt(i2c_dev); + if (err) + return err; + + err = tegra_i2c_init_clocks(i2c_dev); + if (err) + return err; + + err = tegra_i2c_init_dma(i2c_dev); + if (err) + goto release_clocks; + + err = tegra_i2c_init_runtime_pm_and_hardware(i2c_dev); + if (err) + goto release_dma; + + 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; i2c_dev->adapter.owner = THIS_MODULE; i2c_dev->adapter.class = I2C_CLASS_DEPRECATED; - strlcpy(i2c_dev->adapter.name, dev_name(&pdev->dev), + i2c_dev->adapter.algo = &tegra_i2c_algo; + i2c_dev->adapter.nr = i2c_dev->cont_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(i2c_dev->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; + i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); - pm_runtime_put(&pdev->dev); + err = i2c_add_numbered_adapter(&i2c_dev->adapter); + if (err) + goto release_rpm; return 0; +release_rpm: + pm_runtime_disable(i2c_dev->dev); release_dma: tegra_i2c_release_dma(i2c_dev); +release_clocks: + tegra_i2c_release_clocks(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); - -disable_rpm: - 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); - - return ret; + return err; } static int tegra_i2c_remove(struct platform_device *pdev) @@ -1858,17 +1898,10 @@ 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); - - 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); + pm_runtime_disable(i2c_dev->dev); tegra_i2c_release_dma(i2c_dev); + tegra_i2c_release_clocks(i2c_dev); return 0; } From patchwork Thu Sep 3 00:52: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: 254840 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52E66C2BBD0 for ; Thu, 3 Sep 2020 00:55:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F96120758 for ; Thu, 3 Sep 2020 00:55:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j9CAmor2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727825AbgICAzE (ORCPT ); Wed, 2 Sep 2020 20:55:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727864AbgICAyE (ORCPT ); Wed, 2 Sep 2020 20:54:04 -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 38010C061249; Wed, 2 Sep 2020 17:54:04 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id a15so1449155ljk.2; Wed, 02 Sep 2020 17:54: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=Sc3sYFcL0IEq/C/45fRKWcEzy6eLUtql8SQc3ArwAOw=; b=j9CAmor2iaWVc1iz4R0Dn1r6mpzTi9h/JTOyqyVF2pWfGM0SPAthghLflUOLf1hUl1 gBtriaxI24UXlYd+1WWD1jKJE639150AXXzXUD6F21ZEvB92hj00vmkoKl+7RTwoSJPK wlsLNy4AafNiGM8WIXlmZENQNWm7HIEDZDvdgQ+02051Wo11FOxWjzZ3B02jQ6rDpqXH AR4j5aiu7JekOLF9lpqR9l4KzAUFCzY0F2TGzFUwfU30B3BMeTXmdKIw7iwuHtY1tEgk 20LQ7VXZK0oBAh78UM9aD8Z3QzHXViaRnz2Lyg1tTMNiQEYyxn2gb0RH8NK8mhM81F1O SzOA== 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=Sc3sYFcL0IEq/C/45fRKWcEzy6eLUtql8SQc3ArwAOw=; b=iaxEl0RaTHwXCwgOQdEyTtJFZJf848LSGEjmPXf/++5igsRBWtz9akGCKwHeiI/wlk ChEs6FKm5l9uLnagF84MtUVT1MuBv0/WTgyMgkXe9VrQm+m7Fzz5Mz88ThyT0SRVlJ8Z dUk8BryS722yyGORTs54+O22a8tS8OvvuTQveLrHE0Yk8K/iZ1jTKKdfFrUthXgwLSWv tfO2wKQ52hQum3AWxf//h3lWZFBzjz+omCGV6CE5ud6Dem5mUqn+eO3qKml5q0Ysh8tP cqKk6I88NDzf9J69sT2O1qTW9ElLc5HUa6SJDo/DONsvk2cOQHpfrKBvi/hDyhAn++2C ku6w== X-Gm-Message-State: AOAM531z6dUYdhXM78Z44qMQMHyc3GyFWvvBOs0nXPrU33A0gttkjTt/ vLAuiSGhZHhlKCg4CRZoaPs= X-Google-Smtp-Source: ABdhPJyTAdhWYUHIujeYSpssEq6NJsbcuCh4I5wgcvEpP8uEQOK9Kntj9CgGyhmzbBHyw0EXdHddBg== X-Received: by 2002:a2e:8ed4:: with SMTP id e20mr269317ljl.403.1599094442704; Wed, 02 Sep 2020 17:54: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 g1sm250321ljj.56.2020.09.02.17.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 17:54: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 v3 12/22] i2c: tegra: Factor out error recovery from tegra_i2c_xfer_msg() Date: Thu, 3 Sep 2020 03:52:50 +0300 Message-Id: <20200903005300.7894-13-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903005300.7894-1-digetx@gmail.com> References: <20200903005300.7894-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Factor out error recovery code from tegra_i2c_xfer_msg() in order to make this function easier to read and follow. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 46 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index f6b9345b8dfa..19cea39bd4c4 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1171,6 +1171,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, true); + + /* 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) @@ -1351,24 +1377,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, true); - /* 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 Thu Sep 3 00:52: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: 254839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAB87C433E7 for ; Thu, 3 Sep 2020 00:55:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E1D320758 for ; Thu, 3 Sep 2020 00:55:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IWUZeKXM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728073AbgICAzD (ORCPT ); Wed, 2 Sep 2020 20:55:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727867AbgICAyG (ORCPT ); Wed, 2 Sep 2020 20:54:06 -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 92506C061244; Wed, 2 Sep 2020 17:54:05 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id v23so1451983ljd.1; Wed, 02 Sep 2020 17:54: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=zZ5romOj71w+BP60fF9NtT6rTMQR/LTg+gaRvAuiW7Q=; b=IWUZeKXMHeL7uFx2lG+K6kWnLIogXAV6WYRqYvuDXpyN9BY3r3x+vpVA1pWo7bVnxM ng8FU3p+6CGOj4SGTj0d0dis2tZ1/BpJF7N0b0ZKWxM+Soihf3wBiEOjXYczIk3mXUeu qfCtZjCIAqsfQ6de2Ogls/skxEZSI4t1L9zAOYIT6qalHJMCaUEyVTfj92C652xfUgYS YUi6NqQCLOyJRxug6t4Qv2Et6YCXZX7IsIahcYtWYYesc3OLsZ9PbyvCC3dv7zTNR0cg 7ZeIE0JmAMGtJzWo0GjT2AiYSzA26uSYdfawPTZETmIpGZkqHnpA0bm5TVH6TjX5Ttc3 z8iQ== 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=zZ5romOj71w+BP60fF9NtT6rTMQR/LTg+gaRvAuiW7Q=; b=WdtU5P9LQCzr/oZ1YWwfbaHEhR3LJFlo7f358eJVSBGO9f9NudKbfnsIX1w7IrSjtM +QyEFunp9Ax97/J830KycysRuThsy+Jr/CACy3ytTvtY4xhzNAc5RV2sIMsfYyOkXj0u bURmqis0nFKm94aSIw7cKdNh0Qx1xkl4s5otQNzTaW9x6vmRg3MW8auI8bZpDDXW2AXQ A3a68aOYCt4yImsKAEgFvPmlXt46g5HnQzEIqndmZJu0fFBArxCCOjVe/gE+gaebtguG TGLZdC5VoVL4otPhlThspzX9+42RA+RqD6KpDPdKYf9XYcpN2FyESQjEA+cr+cADquBs lWew== X-Gm-Message-State: AOAM533pMl9vtHfrjOjOUoIsejZDqncYPV7dtYsMkoU4kqNXPK9b4zsa nhlEtPmCHQaFY9o07xX+dDg= X-Google-Smtp-Source: ABdhPJxFFum1VxT9tAN9kFrCa3Gay5WC0Fn6Y9IofUcPj2i+lECyJtorHMHRYe0KZTH3aeRTtzMc3Q== X-Received: by 2002:a2e:6815:: with SMTP id c21mr254180lja.132.1599094443628; Wed, 02 Sep 2020 17:54: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 g1sm250321ljj.56.2020.09.02.17.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 17:54: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 v3 13/22] i2c: tegra: Check errors for both positive and negative values Date: Thu, 3 Sep 2020 03:52:51 +0300 Message-Id: <20200903005300.7894-14-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903005300.7894-1-digetx@gmail.com> References: <20200903005300.7894-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 19cea39bd4c4..0f2b6eb5fa27 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -684,19 +684,19 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) return ret; ret = clk_enable(i2c_dev->fast_clk); - if (ret < 0) { + if (ret) { dev_err(dev, "failed to enable fast clock: %d\n", ret); return ret; } ret = clk_enable(i2c_dev->slow_clk); - if (ret < 0) { + if (ret) { 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) { + if (ret) { dev_err(dev, "failed to enable div clock: %d\n", ret); goto disable_slow_clk; } @@ -1057,7 +1057,7 @@ static void tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, slv_config.device_fc = true; ret = dmaengine_slave_config(chan, &slv_config); - if (ret < 0) { + if (ret) { dev_err(i2c_dev->dev, "DMA config failed: %d\n", ret); dev_err(i2c_dev->dev, "falling back to PIO\n"); tegra_i2c_release_dma(i2c_dev); @@ -1245,7 +1245,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: %d\n", err); return err; @@ -1304,7 +1304,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: %d\n", err); return err; From patchwork Thu Sep 3 00:52:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 254841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71DE4C43461 for ; Thu, 3 Sep 2020 00:55:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50B2620758 for ; Thu, 3 Sep 2020 00:55:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eJ7KNqgd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728012AbgICAyv (ORCPT ); Wed, 2 Sep 2020 20:54:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727881AbgICAyI (ORCPT ); Wed, 2 Sep 2020 20:54: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 F191FC061245; Wed, 2 Sep 2020 17:54:07 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id u4so535135ljd.10; Wed, 02 Sep 2020 17:54:07 -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=awlTr+/jK6xRAU2Z+v5rJTj8OB3fgcHycxXMdhCQDDw=; b=eJ7KNqgdpjQSLf6TzgWaqSc7j4jGso2nIRMoGmjcIiklLFi+/YA1109SbAXUOpPDld B5Z6D6wuTZ2RJ45u0ljD3qS+6ARPhkzUd4KTVwQNOA3El6vSF8EMjZ+hOqYsTabrpAJp FgrMAYT1xvt8rhVJHMz9/o7fHHNmz+CnO/Ci3d6XLbpd8BzhgJUNDQQLW82yjAJKAH6J ue3gGrIrVl2SSEQmgNGFBmhLOn87/JAD8TSIxNY0e/6mq3s9K9W7T7IhZCpMJraeW8T2 QcLRvWsfyGy0RUuil0nLLAT9Lb8cS92l325sDFxF89TW3pLa0UZFOfNGDkd3M0L/SVkT uhUw== 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=awlTr+/jK6xRAU2Z+v5rJTj8OB3fgcHycxXMdhCQDDw=; b=PiszuwtTkY8D38uJhmP1VLBD9iCHEMBOvDDQJq/5t/HjGYhbp1k0BjEK1ulJxdS1ku hpesUUFgV/AfKRnRTBaN3VhWbZj0pM8aPEr7isIzI3ub/mYRUPdraEzKdNT3ImE1JV/a 3MD12twkWTRXKnJflaXaEBmKt5ALpVfR8+OCwkYuHyJsh5JxJQB/14Evy7s8BEq6k2Ip qAGirwYwuXjxwA+UgpMixtLH7MMnAsVzRcxnElhMUa+51tFUd5zzZ7UJR3U1ZNP+lZ0q wqzX6ZimI+wi046TCPoBmf63yX2ljEUOnY6OJbTGq+vuEpnuO9ETpWbzjZbzCnaT0KOa OCyQ== X-Gm-Message-State: AOAM531FyzPXqRml2Vkf8e0TcDSijB6LJ2gaN9P99NOXNLjmm2NOw/0/ G8bXhqeo4QW8bTv6K+Tj3Kk= X-Google-Smtp-Source: ABdhPJwnCApj+uKfGK7ZhoIIjDKz5/UCdf3UKTEJpotbrr0LJQXU2BgmRD2mSrTuradWGr32FYWysA== X-Received: by 2002:a2e:7c0f:: with SMTP id x15mr264099ljc.205.1599094446373; Wed, 02 Sep 2020 17:54:06 -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 g1sm250321ljj.56.2020.09.02.17.54.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 17:54:05 -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 v3 16/22] i2c: tegra: Rename variable in tegra_i2c_issue_bus_clear() Date: Thu, 3 Sep 2020 03:52:54 +0300 Message-Id: <20200903005300.7894-17-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903005300.7894-1-digetx@gmail.com> References: <20200903005300.7894-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index ed8f2a7c2804..67f2f4a0fe86 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1137,21 +1137,21 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) { struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); unsigned long time_left; - u32 reg; + u32 val; 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); if (i2c_dev->hw->has_config_load_reg) { 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, @@ -1161,8 +1161,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; } From patchwork Thu Sep 3 00:52:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 254843 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 615C3C2BBDB for ; Thu, 3 Sep 2020 00:54:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F0A320758 for ; Thu, 3 Sep 2020 00:54:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GjBFoeCE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727818AbgICAyW (ORCPT ); Wed, 2 Sep 2020 20:54:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgICAyJ (ORCPT ); Wed, 2 Sep 2020 20:54:09 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08C3FC06124F; Wed, 2 Sep 2020 17:54:09 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id c2so1356295ljj.12; Wed, 02 Sep 2020 17:54:08 -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=v3237sadmuAVzjAWSClmEC/vrTdnbMPIln63ICsZjrk=; b=GjBFoeCE/uetmIDjgdLwQLg5PViMMWK3sgnj8ePG/WhdrOIOukagB/OMUouH+XyEbH xB2gcIjEif08NFIniawau9Y6TlJUwmBAMoWxN6OQR8LogEsuyDos72wEuyY8qAFYO4NU SXi4qifqzv6N26EVNT6kUd1j1ns+58f83FEzZulYhXeYc+FmFNJITY7AIAFy8ANydIhG AaWPaxPGXQWMyMNzPkvK88yvyrwtlP7VP/sQBSuAxwSDhyvak7CmZbe4gFZDvlqcsEGc wniuMQ2OC8YIg8nB3ynAn6W+r/5/TS5zQ1FKSsA85i8YpCIKiFwjG/am1iEJ6lmG4RoP hIUg== 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=v3237sadmuAVzjAWSClmEC/vrTdnbMPIln63ICsZjrk=; b=q83LTcuc7RDIhvhzO5SchCeeYH2eBUrDLZ2WvFuolmbGALnv77Kx94qqUqdAldaw7p fUvKumgRA/wKk7cglfQFx07Zp2Pn1oj0U/lVxec7verTe8BgFW1xFkyheBkH/ozr76u+ 9drtGtUoXEoO06a1MGz3eAbvB72mTcQLtfVqhU0/MNpDOa0Hewt0l16gnmBdJBZPxilf kzWFbLUIEgDwhcLfEW/EsHEOEEAkCz5Ok1M7ffHsbTJCTdA9IxbvnTNeWMj+oywUBgys yPlmlFfQov+ELyoDcJAW8Re3SFWVjfZUr7ofdIiIQLaApSQgyRCM/5lAR9R0eucV2meJ diug== X-Gm-Message-State: AOAM5309J/FRz5bBDKmMxAkVS1xs3fisfN7UqnnF0qHfN/+NnQb/fHll +T2zKRJb60KCRFPScEb67Sw= X-Google-Smtp-Source: ABdhPJzNDHFUdn+oanCpXc9NrXtZmOXYYW2EW5+u0xIgmi/S9a8UXaSafQhq4E2ZIHErtYSYYfjqVA== X-Received: by 2002:a05:651c:c1:: with SMTP id 1mr275074ljr.146.1599094447364; Wed, 02 Sep 2020 17:54:07 -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 g1sm250321ljj.56.2020.09.02.17.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 17:54:06 -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 v3 17/22] i2c: tegra: Improve driver module description Date: Thu, 3 Sep 2020 03:52:55 +0300 Message-Id: <20200903005300.7894-18-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903005300.7894-1-digetx@gmail.com> References: <20200903005300.7894-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Use proper spelling of "NVIDIA" and don't designate driver as Tegra2-only since newer SoC generations are supported as well. Signed-off-by: Dmitry Osipenko --- 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 67f2f4a0fe86..5b37435fa36d 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1993,6 +1993,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"); From patchwork Thu Sep 3 00:52:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 254844 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 416ADC43461 for ; Thu, 3 Sep 2020 00:54:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 004EF20758 for ; Thu, 3 Sep 2020 00:54:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S/4DaMv/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727949AbgICAyX (ORCPT ); Wed, 2 Sep 2020 20:54:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727906AbgICAyK (ORCPT ); Wed, 2 Sep 2020 20:54:10 -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 14DCDC061246; Wed, 2 Sep 2020 17:54:10 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id w3so1415791ljo.5; Wed, 02 Sep 2020 17:54:09 -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=DBMpRTsDKoEtZa8d3VMxV0RyURLZJ1LTPHjdCaFtbaA=; b=S/4DaMv/Q6FClY8Fxbst4ssvGlkFTwWtIrvzOy4M3mo65nkVLivsLyCI3bIVo9KVtU cG2fSTm8wulJC6w5zrdzewRRSg+F276BOGzXbGFOu4WawmX7SwamlPkYgi5lFk4wH/OV vbEGAnMOF5tOZhY6660Yi1Z/9XqHpkN0ioQDDEnu/jM5Sg3/NSOX7Hw12iwPs6arhlBi d8GAx9lkDiVBtWAt/2fsjwwU+KBZYkawZGk7WLviWGvwuy36s7cjIiHZo4f1jiiVw3Mq GxlYMHRHQppN0647kNZdj8l5Hgjv/8Tcy7qAw8lMogtqyM7677BNUQVBDpZ+Ej+g/A/7 210w== 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=DBMpRTsDKoEtZa8d3VMxV0RyURLZJ1LTPHjdCaFtbaA=; b=Uxh1E5H9J1b0gSNP40u/7BjteNFU4AgrMU475jG/BIbKBr3Jqg1EnNO5krMOguJfZw UHxwL5tiXKBR5h75v7HtXtKD5fC40iaMdJN0QMovx2CkFv3Z7H4pxIi/fihONXRFKFS8 DQBN/ZwcA1TerN5U9RcwFgrpuQiJPIRP2PHUJzKH44+6srmgcJM1Zo1EWQIbvAKj4Uwv 4CdqADPCZrefBpFI9uB46gzuqisL1rC55+nUDI4TIw/lkkjakppGDKe9egTKW0Bhy/UD PlmlKVCojdDR7AnaUoABXNy0kOvYUa4TL7MFnl08R7ynGJVOP0oispohNKIf7r1/W7IZ EWpQ== X-Gm-Message-State: AOAM530NZZKXL7WDcfiZV2Wzdcuz9D2NnaopustaDMfnW5ullf3od8Rs Y046QLY3/B2kQtqXEt/ULak= X-Google-Smtp-Source: ABdhPJyiDGqx212vYKnAE/CEKNrG7OWhce9E9dQB1asOz6pY5+42WCrlcUCq6dtfCOCIYSHF+UCglQ== X-Received: by 2002:a2e:85d5:: with SMTP id h21mr231086ljj.461.1599094448323; Wed, 02 Sep 2020 17:54:08 -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 g1sm250321ljj.56.2020.09.02.17.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 17:54:07 -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 v3 18/22] i2c: tegra: Reorder location of functions in the code Date: Thu, 3 Sep 2020 03:52:56 +0300 Message-Id: <20200903005300.7894-19-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903005300.7894-1-digetx@gmail.com> References: <20200903005300.7894-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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(). Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 550 ++++++++++++++++----------------- 1 file changed, 274 insertions(+), 276 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 5b37435fa36d..f30ac45c2bfd 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -293,8 +293,6 @@ struct tegra_i2c_dev { bool is_curr_atomic_xfer; }; -static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit); - static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned long reg) { @@ -473,186 +471,6 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) return err; } -static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) -{ - ktime_t ktime, ktimeout; - unsigned int offset; - u32 mask, val; - - if (i2c_dev->hw->has_mst_fifo) { - mask = I2C_MST_FIFO_CONTROL_TX_FLUSH | - I2C_MST_FIFO_CONTROL_RX_FLUSH; - offset = I2C_MST_FIFO_CONTROL; - } else { - mask = I2C_FIFO_CONTROL_TX_FLUSH | - I2C_FIFO_CONTROL_RX_FLUSH; - offset = I2C_FIFO_CONTROL; - } - - val = i2c_readl(i2c_dev, offset); - val |= mask; - i2c_writel(i2c_dev, val, offset); - - /* - * ktime_get() may take up to couple milliseconds in a worst case - * and normally FIFOs are flushed, hence let's check the state before - * proceeding to polling. - */ - if (!(i2c_readl(i2c_dev, offset) & mask)) - return 0; - - ktime = ktime_get(); - ktimeout = ktime_add_ms(ktime, 1000); - - while (i2c_readl(i2c_dev, offset) & mask) { - if (ktime_after(ktime, ktimeout)) - goto err_timeout; - - if (i2c_dev->is_curr_atomic_xfer) - mdelay(1); - else - fsleep(1000); - - ktime = ktime_get(); - } - - return 0; - -err_timeout: - dev_err(i2c_dev->dev, "FIFO flushing timed out\n"); - - return -ETIMEDOUT; -} - -static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) -{ - size_t buf_remaining = i2c_dev->msg_buf_remaining; - u8 *buf = i2c_dev->msg_buf; - int words_to_transfer; - int rx_fifo_avail; - u32 val; - - /* - * 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) -{ - size_t buf_remaining = i2c_dev->msg_buf_remaining; - u8 *buf = i2c_dev->msg_buf; - int words_to_transfer; - int tx_fifo_avail; - u32 val; - - 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 @@ -674,66 +492,33 @@ static void tegra_dvc_init(struct tegra_i2c_dev *i2c_dev) dvc_writel(i2c_dev, val, DVC_CTRL_REG1); } -static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) +static void tegra_i2c_vi_init(struct tegra_i2c_dev *i2c_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_enable(i2c_dev->fast_clk); - if (ret) { - dev_err(dev, "failed to enable fast clock: %d\n", ret); - return ret; - } - - ret = clk_enable(i2c_dev->slow_clk); - if (ret) { - dev_err(dev, "failed to enable slow clock: %d\n", ret); - goto disable_fast_clk; - } - - ret = clk_enable(i2c_dev->div_clk); - if (ret) { - dev_err(dev, "failed to enable div clock: %d\n", ret); - goto disable_slow_clk; - } - - /* - * 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, true); - if (ret) - goto disable_div_clk; - } + u32 value; - return 0; + value = FIELD_PREP(I2C_INTERFACE_TIMING_THIGH, 2) | + FIELD_PREP(I2C_INTERFACE_TIMING_TLOW, 4); + i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_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); + 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); - return ret; -} + 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); -static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev) -{ - struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); + 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); - clk_disable(i2c_dev->div_clk); - clk_disable(i2c_dev->slow_clk); - clk_disable(i2c_dev->fast_clk); + value = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND; + i2c_writel(i2c_dev, value, I2C_BUS_CLEAR_CNFG); - return pinctrl_pm_select_idle_state(i2c_dev->dev); + i2c_writel(i2c_dev, 0x0, I2C_TLOW_SEXT); } static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) @@ -765,33 +550,55 @@ 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) +static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) { - u32 value; + ktime_t ktime, ktimeout; + unsigned int offset; + u32 mask, val; - value = FIELD_PREP(I2C_INTERFACE_TIMING_THIGH, 2) | - FIELD_PREP(I2C_INTERFACE_TIMING_TLOW, 4); - i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_0); + if (i2c_dev->hw->has_mst_fifo) { + mask = I2C_MST_FIFO_CONTROL_TX_FLUSH | + I2C_MST_FIFO_CONTROL_RX_FLUSH; + offset = I2C_MST_FIFO_CONTROL; + } else { + mask = I2C_FIFO_CONTROL_TX_FLUSH | + I2C_FIFO_CONTROL_RX_FLUSH; + offset = I2C_FIFO_CONTROL; + } - 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); + val = i2c_readl(i2c_dev, offset); + val |= mask; + i2c_writel(i2c_dev, val, offset); + + /* + * ktime_get() may take up to couple milliseconds in a worst case + * and normally FIFOs are flushed, hence let's check the state before + * proceeding to polling. + */ + if (!(i2c_readl(i2c_dev, offset) & mask)) + return 0; + + ktime = ktime_get(); + ktimeout = ktime_add_ms(ktime, 1000); + + while (i2c_readl(i2c_dev, offset) & mask) { + if (ktime_after(ktime, ktimeout)) + goto err_timeout; - 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); + if (i2c_dev->is_curr_atomic_xfer) + mdelay(1); + else + fsleep(1000); - 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); + ktime = ktime_get(); + } - value = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND; - i2c_writel(i2c_dev, value, I2C_BUS_CLEAR_CNFG); + return 0; - i2c_writel(i2c_dev, 0x0, I2C_TLOW_SEXT); +err_timeout: + dev_err(i2c_dev->dev, "FIFO flushing timed out\n"); + + return -ETIMEDOUT; } static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit) @@ -903,6 +710,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) +{ + size_t buf_remaining = i2c_dev->msg_buf_remaining; + u8 *buf = i2c_dev->msg_buf; + int words_to_transfer; + int rx_fifo_avail; + u32 val; + + /* + * 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) +{ + size_t buf_remaining = i2c_dev->msg_buf_remaining; + u8 *buf = i2c_dev->msg_buf; + int words_to_transfer; + int tx_fifo_avail; + u32 val; + + 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) { const u32 status_err = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; @@ -1454,27 +1390,6 @@ static u32 tegra_i2c_func(struct i2c_adapter *adap) return ret; } -static int tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) -{ - struct device_node *np = i2c_dev->dev->of_node; - u32 bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; - bool multi_mode; - - of_property_read_u32(np, "clock-frequency", &bus_clk_rate); - i2c_dev->bus_clk_rate = bus_clk_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; - - return 0; -} - static const struct i2c_algorithm tegra_i2c_algo = { .master_xfer = tegra_i2c_xfer, .master_xfer_atomic = tegra_i2c_xfer_atomic, @@ -1687,6 +1602,27 @@ static const struct of_device_id tegra_i2c_of_match[] = { }; MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); +static int tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) +{ + struct device_node *np = i2c_dev->dev->of_node; + u32 bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; + bool multi_mode; + + of_property_read_u32(np, "clock-frequency", &bus_clk_rate); + i2c_dev->bus_clk_rate = bus_clk_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; + + return 0; +} + static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev) { const struct tegra_i2c_hw_feature *hw = i2c_dev->hw; @@ -1930,6 +1866,68 @@ 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_enable(i2c_dev->fast_clk); + if (ret) { + dev_err(dev, "failed to enable fast clock: %d\n", ret); + return ret; + } + + ret = clk_enable(i2c_dev->slow_clk); + if (ret) { + dev_err(dev, "failed to enable slow clock: %d\n", ret); + goto disable_fast_clk; + } + + ret = clk_enable(i2c_dev->div_clk); + if (ret) { + dev_err(dev, "failed to enable div clock: %d\n", ret); + goto disable_slow_clk; + } + + /* + * 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, true); + if (ret) + goto disable_div_clk; + } + + 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); + + return ret; +} + +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); + + 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 Thu Sep 3 00:52:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 254842 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90D5BC433E7 for ; Thu, 3 Sep 2020 00:54:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BA5A20758 for ; Thu, 3 Sep 2020 00:54:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R0Og/p/F" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728014AbgICAyo (ORCPT ); Wed, 2 Sep 2020 20:54:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727923AbgICAyN (ORCPT ); Wed, 2 Sep 2020 20:54:13 -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 B0686C06125F; Wed, 2 Sep 2020 17:54:12 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id t7so697617ljo.13; Wed, 02 Sep 2020 17:54:12 -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=Mzbf4DuflBeTQLxzGK/w5XUYkKbYVKcRiZ4UXxyN0qs=; b=R0Og/p/F+WZmlFbPxpOkoj84ltut7sniDMl7815ihQKSQeV0g4N3aQzRBAvEjjrx1V EOCpYZCEj9M5LTYl+LwBbWvYvJMdWNP7fTecVHiuy52EqX/zQFlQgxi2t0KlXiTz1sq/ K2iDD95lcXoMGq5oxz98xfke3V/43K7sAFPXdWPXshMnbwmaGl+VZ/5OvL8UWLgzNzul wMvhFVNg3XV92bQ7+IB1IAE69By/990pf8ZkTURiTFYzmo7/586lG4OirQyJahxBykJ6 p6p02eT1w0ug01gq0lm4v8HYH8viik3d1lNUBmzEokaCFw68lnpCgfxhC35e3K8XyXNV mkJA== 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=Mzbf4DuflBeTQLxzGK/w5XUYkKbYVKcRiZ4UXxyN0qs=; b=Ik1ePwbeunMK93Mlb4IlmRIVYWE+xOkpS7HLuxjHRJfQXqvPSQc0RayZZI53GwkPfV dUhjlPHenKyaDyVSqku36DCWbEm5926yCLnCmYfzBGSyYLsHUGtUekJdht61FFy8o3Ey eOYuwYzw2ZqMoQLOQeEKZ1YfUSBQS+FFJCjNCGmfOnUoHE0HZ2NWMRZa0ACNz/zaAGqX uSHDhfoKUtwnkr6YKpM47Jgu1Qez+zzIj77UwFqw3+gvi/IamkJAhYHnt3WIho+2zAfB op0v8CU3hidU6hLtCIgsMzAbkEPAi+oKRma/zIdgNmHfVH3sVzn7y7wNvKtuWPdpvoT8 v84A== X-Gm-Message-State: AOAM531l83jzyJks0xGSek3OCfb1fiCBkb/d+jWNt4fCEUn1287+Mc57 2Q779Xw9vo6bpftfFipvId8= X-Google-Smtp-Source: ABdhPJwpvEajxxrLAgt1Refmaoy+hMxGz2srOTIk8FRzEIeoDsxo8FaovKwljc6m8/lPht2hqFCk2Q== X-Received: by 2002:a2e:865a:: with SMTP id i26mr249186ljj.246.1599094451145; Wed, 02 Sep 2020 17:54:11 -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 g1sm250321ljj.56.2020.09.02.17.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 17:54:10 -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 v3 21/22] i2c: tegra: Initialization div-clk rate unconditionally Date: Thu, 3 Sep 2020 03:52:59 +0300 Message-Id: <20200903005300.7894-22-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903005300.7894-1-digetx@gmail.com> References: <20200903005300.7894-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 79caf87bb4c0..bc7954c8a5a0 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -601,7 +601,7 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) return -ETIMEDOUT; } -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, clk_divisor, clk_multiplier, tsu_thd, tlow, thigh; int err; @@ -656,16 +656,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 to set div-clk 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) { @@ -1163,7 +1161,7 @@ static int tegra_i2c_error_recover(struct tegra_i2c_dev *i2c_dev, if (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) { @@ -1303,7 +1301,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; } @@ -1324,7 +1322,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; } @@ -1752,7 +1750,7 @@ static int tegra_i2c_init_runtime_pm_and_hardware(struct tegra_i2c_dev *i2c_dev) } /* initialize hardware state */ - ret = tegra_i2c_init(i2c_dev, false); + ret = tegra_i2c_init(i2c_dev); pm_runtime_put(i2c_dev->dev); @@ -1907,7 +1905,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; } @@ -1961,7 +1959,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;