From patchwork Tue Sep 8 02:09:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359338 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Tm9/FIKE; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BlpYz6hTZz9sR4 for ; Tue, 8 Sep 2020 12:12:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728302AbgIHCLw (ORCPT ); Mon, 7 Sep 2020 22:11:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728210AbgIHCLi (ORCPT ); Mon, 7 Sep 2020 22:11:38 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D7E8C061573; Mon, 7 Sep 2020 19:11:38 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id q8so8317345lfb.6; Mon, 07 Sep 2020 19:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gfmOtG2LX9A+Kel844rjarke+NfElZZeKMZp8MuQx6I=; b=Tm9/FIKEgk29yAi0gO/78j3swf1duBjircnaXPLyClkolmcK28ErMw5bcOf2C7Ujpt fT7XSGveqqyhId/l/DXscLwXQwo83fWp5Ww+uMvDGag9Ugz290vefzuwFOxDL1ieovFl 2s7D2ZHoiClBXuGrWyqZB6i0CGMNzUWmQdmTozRaiAktWvDUDimVv9zyiZ7I9cIQZpW5 9zHQgnkWqVv5XPnpLiJ32Z38cnPOyRHIwm8gPO8exALfsyoEwSkYfCEEWZ8d3jigCMY8 ENvjAgGCg+TRnw/SZLrsJ5hhhFbsYvTg8jHMG8XmQ2cb5iyvn7wrj03vgDNjeZ6d712q 3cDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gfmOtG2LX9A+Kel844rjarke+NfElZZeKMZp8MuQx6I=; b=F+SIGO/aUG9vOpEIxSyJyy8OURR43NUGGy16Oode2pNCtLsrCaHE1UOujM+GUZ1F/Z OE1Zb/cEJlTiYHmOh7KxMMP7x7V4lGH3/FBs4eh4c215O3saH9utbyiMQNqZNP0V5Bbj 0JaBMyigKxTnBFbcdOF1YiAuQPPPflqBGnbMZ3iHQ/MSNzsGtrXPq05LZE13yrvBaidG 3T/11Y8wfnWzaQvWGz9t9Car2874XECDUjP0ZwK6zQbEZf7ZUe7IKPsNm+Bs4D3K6SXc lrUa8W4CsJKuhV/3svxbVTG2Gr+4W8bvfuAFRazhPqEVJAk9ZRO4Lj9jJPwW+Rys1g7S IbBw== X-Gm-Message-State: AOAM530vpHawqz4C0ePE4du2MDTimzBJPsElmAftj5+j2eWH0IDklZyB VeOVGS4fTv80n3eVXmlL7YVVgcLUuGc= X-Google-Smtp-Source: ABdhPJxbhNZzdrhpduoiWG3QfFL5U8JRQEbaHSxR1Ll28MYeIk+N2mqh1fi5WIu0cCDDAw5IH+v7aA== X-Received: by 2002:ac2:4891:: with SMTP id x17mr11233554lfc.28.1599531096485; Mon, 07 Sep 2020 19:11:36 -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 j12sm9070085lfj.5.2020.09.07.19.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:35 -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 v6 01/35] i2c: tegra: Make tegra_i2c_flush_fifos() usable in atomic transfer Date: Tue, 8 Sep 2020 05:09:47 +0300 Message-Id: <20200908021021.9123-2-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The tegra_i2c_flush_fifos() shouldn't sleep in atomic transfer and jiffies are not updating if interrupts are disabled. Let's switch to use iopoll API helpers for register-polling. The iopoll API provides helpers for both atomic and non-atomic cases. Note that this patch doesn't fix any known problem because normally FIFO is flushed at the time of starting a new transfer. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 00d3e4d7a01e..ab88cdd70376 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -470,9 +470,9 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) { - unsigned long timeout = jiffies + HZ; - unsigned int offset; - u32 mask, val; + u32 mask, val, offset, reg_offset; + void __iomem *addr; + int err; if (i2c_dev->hw->has_mst_fifo) { mask = I2C_MST_FIFO_CONTROL_TX_FLUSH | @@ -488,12 +488,19 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) val |= mask; i2c_writel(i2c_dev, val, offset); - while (i2c_readl(i2c_dev, offset) & mask) { - if (time_after(jiffies, timeout)) { - dev_warn(i2c_dev->dev, "timeout waiting for fifo flush\n"); - return -ETIMEDOUT; - } - usleep_range(1000, 2000); + reg_offset = tegra_i2c_reg_addr(i2c_dev, offset); + addr = i2c_dev->base + reg_offset; + + if (i2c_dev->is_curr_atomic_xfer) + err = readl_relaxed_poll_timeout_atomic(addr, val, !(val & mask), + 1000, 1000000); + else + err = readl_relaxed_poll_timeout(addr, val, !(val & mask), + 1000, 1000000); + + if (err) { + dev_err(i2c_dev->dev, "failed to flush FIFO\n"); + return err; } return 0; } From patchwork Tue Sep 8 02:09:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359389 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=njGalvId; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BlpfN1rKrz9sTW for ; Tue, 8 Sep 2020 12:15:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728315AbgIHCMA (ORCPT ); Mon, 7 Sep 2020 22:12:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728252AbgIHCLj (ORCPT ); Mon, 7 Sep 2020 22:11:39 -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 F0F47C061755; Mon, 7 Sep 2020 19:11:38 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id y4so18006973ljk.8; Mon, 07 Sep 2020 19:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lmosp0zHTCuESLy5/lSjNc1iMwH+IzUsdjaB+ieXAnU=; b=njGalvIdcm6ut/39tvF1ZFtPfjvs52Rky4wNb5FqTwhfXWfNO031Nllgei/KMWivpb QLEyQ7WV1pIWZ4ZeogfXEC6JaQQDeF1nZ91oufJOpgI7O6a9dX7YP5FyBcpuiQ1+Wujz Nusvsywu9fLKk8L93SxEfjnlf9n6l0wG/nJvwjstMI0EOIViu7aV0B2TgVau083vrV5h zrpGvWgUa52Zl0hVD4k1m6RlFLzOHqvQTtJ6gzrwPfwrjSThPzOyWiga3PorW8EIXZVk GDyiENV+9LNalbYocFTO5pgR3OQyIkp+fgA63m3Cy0UrqhWiVHDAEgYQZ08qqETmTkYK NwMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lmosp0zHTCuESLy5/lSjNc1iMwH+IzUsdjaB+ieXAnU=; b=SM10G8xurhbJw4RmrRIWmOsx9fXhRO3iKaX9rMx4LBkgWuHznpKv5vqBdXjiYGWGXq +jjX4bNK95Ja2XP0GGutcEDnaRfWp2SksmxQ1qH+kEB2hio6EQkpCHWUq2q6AlR5pe4U PUk+W3SixI2zgQWdscdN9pqpfCp2oCedDiTAvy+RVSytsEDQVy0zk1YDqOxfP2gX0OKB FZ9FlYW4KPLXoNEp0SOxqCIBP2XHrlw9+wXjJO/Rnj3yEGcehubP30cgPPEmd6oLrNM/ 6jsQ7n5hop53undFAIeR7LA3RXeVV4JhEANrFKQEY3I+SdHA1HuMFJOhCqW5+fSbBq+q B/8w== X-Gm-Message-State: AOAM530AP63qJgMhP3uDbFfmwWg/ki5fvI/62eSkDsWx2r0pLqKxQdHk 9BCrUG8vH5QgjIPReNoB21U= X-Google-Smtp-Source: ABdhPJxjCcvuwQ6ZDiRBXEciJzc2XrhENUGOgLk87wPQP/VE9K86UYQR9oq+wW1kpzFqyZk15Difog== X-Received: by 2002:a2e:9785:: with SMTP id y5mr5919782lji.452.1599531097413; Mon, 07 Sep 2020 19:11:37 -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 j12sm9070085lfj.5.2020.09.07.19.11.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:36 -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 v6 02/35] i2c: tegra: Add missing runtime PM put Date: Tue, 8 Sep 2020 05:09:48 +0300 Message-Id: <20200908021021.9123-3-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The pm_runtime_get_sync() always bumps refcount regardless of whether it succeeds or fails. Hence driver is responsible for restoring of the RPM refcounting. This patch adds missing RPM puts which restore refcounting in a case of pm_runtime_get_sync() error. Suggested-by: Andy Shevchenko Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index ab88cdd70376..4e7d0eec0dd3 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1375,6 +1375,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], ret = pm_runtime_get_sync(i2c_dev->dev); if (ret < 0) { dev_err(i2c_dev->dev, "runtime resume failed %d\n", ret); + pm_runtime_put_noidle(i2c_dev->dev); return ret; } @@ -1786,7 +1787,7 @@ static int tegra_i2c_probe(struct platform_device *pdev) ret = pm_runtime_get_sync(i2c_dev->dev); if (ret < 0) { dev_err(&pdev->dev, "runtime resume failed\n"); - goto disable_rpm; + goto put_rpm; } } @@ -1851,7 +1852,6 @@ static int tegra_i2c_probe(struct platform_device *pdev) else tegra_i2c_runtime_suspend(&pdev->dev); -disable_rpm: if (pm_runtime_enabled(&pdev->dev)) pm_runtime_disable(&pdev->dev); From patchwork Tue Sep 8 02:09:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359339 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=u/kGAeoO; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BlpZ074P5z9sTK for ; Tue, 8 Sep 2020 12:12:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728348AbgIHCME (ORCPT ); Mon, 7 Sep 2020 22:12:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728254AbgIHCLl (ORCPT ); Mon, 7 Sep 2020 22:11:41 -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 E8B53C061756; Mon, 7 Sep 2020 19:11:39 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id a22so11625411ljp.13; Mon, 07 Sep 2020 19:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8EoeQfm2V7iEFCAPBa5UMm2YWlodiF1UtVHJ3u58T+Y=; b=u/kGAeoOT8mhEp6dIdJveTArpuHIhO/yjU8QlPRVm4p9dIBm9+fme2Zd0e7OCAhmaY fq1XXPRpIv1Mfi3wo+APVP33i0rg7nDfaqUMqekhGMjrmJLMgPxN5HQbx4HaC3DBlXLG oot6Q1FSQDVJ0tTOVp/BZ+VwPOzUvz7ld69fzCxgtnxsTI0Cp4/nzI9Ba82MoweXzVtB PF2fCSHQC8C1TfUxOl8OwwkoSvJoN+JrRtb6MttVT18wxArGjqmbVmOS1fGbWW/vQiMo MhEzk/ahyFMFqt7hK65UNkF0rstBJPlZgDbRwy8fpl9U8kQ3bNXnWjMdGl4p5g/SXkd9 fUGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8EoeQfm2V7iEFCAPBa5UMm2YWlodiF1UtVHJ3u58T+Y=; b=ZlDhf53Py9B2zm6oWHzlcU2DpcYegXQaj5jCDRd7253WEu6ip3BPIWD/04qi3ZXZ8U KrWUfAWxEV4DCQNYcCYu1zLZLKvjxAbZysJ3EFtNCKBk2mzdzPK104CMBPmmA/IW4rhM tXIUZXnz0vwnrUJNx+WlLMWvGG8T5N77audIFTo8EICIB+ezCkwvDcKwL+JDixPYvkO0 biVx/Heaz3uF+s9lmXEMb2B7t/VGlhxxj1yRYxyz3ZdwL9vd3h5QVYBfmCN0O+oPxZtW 0QP2MxvoLuCgnxgQbPIExCszi5lmJUKVPGulWncQ1+z2/Nv7N/hZFgIZCSftOGh7p/BH Jb5Q== X-Gm-Message-State: AOAM533H7Vz4iaTy4wLsoas0RIPd+5s7zFC2LKDB9fOZ/A1QDkv3HqnC yjDhIl1IHxbUm97ISrueoMk= X-Google-Smtp-Source: ABdhPJzFbAeVVVVno6VkUk61rrvmXxH6eJGhPCRlFZ0KCNe6prQAsmvBFYKphwQ/ypmiFzt+PDkHVg== X-Received: by 2002:a2e:9d83:: with SMTP id c3mr6405416ljj.385.1599531098389; Mon, 07 Sep 2020 19:11:38 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:37 -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 v6 03/35] i2c: tegra: Handle potential error of tegra_i2c_flush_fifos() Date: Tue, 8 Sep 2020 05:09:49 +0300 Message-Id: <20200908021021.9123-4-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Technically the tegra_i2c_flush_fifos() may fail and transfer should be aborted in this case, but this shouldn't ever happen in practice unless there is a bug somewhere in the driver. Let's add the error check just for completeness. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 4e7d0eec0dd3..88d6e7bb14a2 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1177,7 +1177,9 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, bool dma; u16 xfer_time = 100; - tegra_i2c_flush_fifos(i2c_dev); + err = tegra_i2c_flush_fifos(i2c_dev); + if (err) + return err; i2c_dev->msg_buf = msg->buf; i2c_dev->msg_buf_remaining = msg->len; From patchwork Tue Sep 8 02:09:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359342 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=bfACNC4m; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BlpZ61HR3z9sTM for ; Tue, 8 Sep 2020 12:12:14 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728365AbgIHCMF (ORCPT ); Mon, 7 Sep 2020 22:12:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728255AbgIHCLl (ORCPT ); Mon, 7 Sep 2020 22:11:41 -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 B3ECBC061573; Mon, 7 Sep 2020 19:11:40 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id c2so17973045ljj.12; Mon, 07 Sep 2020 19:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j3XbNtVZD6rVkiU+YdggTYpRd5hx/FUuMpH7Z/8WhF0=; b=bfACNC4mgijqjZUM0XhCOrQ1IF9F6EHmKtbubf/SDt+AQSXgsA3SJ6fkGubv7LUxQb X3A3AAoeTyVWVqDeek9DQl0LrCIuBIVr28UPKqa7u2ouRTDNMcDVcHAMKARMyJLQZRiE plq4Scz4VisdUOrhEpjauonuuwrl2k2x/tOP/dmg+9Hp/8QIfuCo+iV6itR7gLzygZgf 05dG78W0tVYW3Vm1Wy+XEShv+8ekrZ2BAFX3XZoVVIZOvNpbMsH3b7P7pjH+f8zSN874 u13o5ziUz/NfXNqAAjD/+EyASi5Umm4Kx4arIiiLL/x6aGdxWccL+Ejd5Tbyfn8klz3c 0vJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j3XbNtVZD6rVkiU+YdggTYpRd5hx/FUuMpH7Z/8WhF0=; b=gP3e1tFQNWS7z/7BPw0Go/lLl1vcMFdOzP/XYeZ98UkpBWx6iWYlWPLNtU7CFuX3Ke pP/B9+K4fED4R6rpmyEl7kE/BEvx9QP1Bh6qpSfcA3WHE0pa9Bt3O74Amxax/VokJjjS ZpcNCqguGtu/glPina6G0+OUTohAzmuDpC/VwfYOzOa6sjEOyB+Ra3e8dXT68oN3iTjG b6xqGZkW536AA3cQcLn3/ctVwSwersKsAvM7kqdH5gaPGYKZWY4BrDzsD4aljMfgmIcD KO+GhPnwvauJ6WLaStQ2ByAmUvG8uo2i8xayMNbP+VWw5ZblomTepJ6XYRJquyXLVHIa 25ug== X-Gm-Message-State: AOAM531G7UcGd2ZjdLaa3Skt8L0yTwuvJJUBZeuIIOP1sx5GR4XW2Vxw MldJsyv8NXkkfIpkUcC1qH8= X-Google-Smtp-Source: ABdhPJwnXyhIPrOlQ+HMfbgSOwjbhn8/IKD62gk8XYrkiImPXVDd+tsTBBNLHafEMTJVjJWxR/RGiA== X-Received: by 2002:a2e:b5b0:: with SMTP id f16mr12103956ljn.316.1599531099258; Mon, 07 Sep 2020 19:11:39 -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 j12sm9070085lfj.5.2020.09.07.19.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:38 -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 v6 04/35] i2c: tegra: Mask interrupt in tegra_i2c_issue_bus_clear() Date: Tue, 8 Sep 2020 05:09:50 +0300 Message-Id: <20200908021021.9123-5-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The tegra_i2c_issue_bus_clear() may fail and in this case BUS_CLR_DONE stays unmasked. Hence let's mask it for consistency. This patch doesn't fix any known problems. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 88d6e7bb14a2..1d1ce266255a 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1149,6 +1149,8 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) time_left = tegra_i2c_wait_completion_timeout( i2c_dev, &i2c_dev->msg_complete, 50); + tegra_i2c_mask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); + if (time_left == 0) { dev_err(i2c_dev->dev, "timed out for bus clear\n"); return -ETIMEDOUT; From patchwork Tue Sep 8 02:09:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=roM5EgkE; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpfs2yLfz9sTK for ; Tue, 8 Sep 2020 12:16:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729154AbgIHCQU (ORCPT ); Mon, 7 Sep 2020 22:16:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728257AbgIHCLm (ORCPT ); Mon, 7 Sep 2020 22:11:42 -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 938EAC061757; Mon, 7 Sep 2020 19:11:41 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id t23so18045766ljc.3; Mon, 07 Sep 2020 19:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gtWM+t6m46QP11MMan80ce8w5SnWZJRPt/gPtC0Z3c4=; b=roM5EgkE3kL20XAASfhTqgpqsORfz1ebmnETI1x1rOoc6sS4wRSvn2bUOwyidBHzIc XOhLBKbyD+v3NkOgg5L1225KTSocxm7kHPO7dYHtE8yQuqCvusET2ToSpmcJtWON2Biw 8R/owXsjg4UsW7iw8kaRBkAu/VPg+E7OaAZ/qNFrvxG+S3hA77sEtGWMYPqGWjFYpvbC AGmip2C8PTO/wjw9ehWS7lm2pCkKYu6qwSMdVvxMbLuOIsy1uYFuky3OJ0PU175QdXMH R9VaAyFkfX/aLal9sEKXgetvKsot8uyVRQOwC7e+ELMV0sQl5Cp1caKlLpGNw0j+z5o8 S62Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gtWM+t6m46QP11MMan80ce8w5SnWZJRPt/gPtC0Z3c4=; b=G07iSvcpKSLUpTq0hjttfgF8WrDiBOVsS51Mvq7q0vDcmr0Bo3TVl1qljY2iF4Ddc+ 2g4fwjXjiBvCaMMQbRpOsyx6ffOYPg02zzO1s+QjcSJzmP64O7gOKi8iWZIAvtbZrQ/d 2CMLJGzQ+eviNGtftgyJBHDa5iS2nrNa7T4nqkRtR7SZbDccv8Bu3RQZoEur5cFuHvBP h52GflhaBS52jJ+Gp+Dtygf+TE2cj/erLgRh5mfOa3iVMyXoE/HKla0KDx+Imj9PYfyQ m1w5fA6mtkIVTzd892UvnRNVsjxU6u1cTTAy2UJFVnGxL8hp8cIl/zrMUDmRbhdSC4V2 RzLQ== X-Gm-Message-State: AOAM533X77zXDgWbjHxRB0+vFggitOl76yaQbvoqRBBoOUOGWjm5OqDK GrbZyfciCZIAWPRBWFTxCRQ= X-Google-Smtp-Source: ABdhPJwb8ot4luUZbU+AR5PJis0Kr/Gfzxf+TYFKZ/cSUxOwRLeuk7H90MctqhyT8V0y2a7fK+/41g== X-Received: by 2002:a05:651c:386:: with SMTP id e6mr2963611ljp.424.1599531100081; Mon, 07 Sep 2020 19:11:40 -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 j12sm9070085lfj.5.2020.09.07.19.11.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:39 -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 v6 05/35] i2c: tegra: Initialize div-clk rate unconditionally Date: Tue, 8 Sep 2020 05:09:51 +0300 Message-Id: <20200908021021.9123-6-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org It doesn't make sense to conditionalize the div-clk rate changes because rate is fixed and it won't ever change once it's set at the driver's probe time. All further changes are NO-OPs because CCF caches rate and skips rate-change if rate is unchanged. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 1d1ce266255a..720a75439e91 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -293,7 +293,7 @@ struct tegra_i2c_dev { bool is_curr_atomic_xfer; }; -static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit); +static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev); static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned long reg) @@ -691,7 +691,7 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) * domain ON. */ if (i2c_dev->is_vi) { - ret = tegra_i2c_init(i2c_dev, true); + ret = tegra_i2c_init(i2c_dev); if (ret) goto disable_div_clk; } @@ -778,7 +778,7 @@ static void tegra_i2c_vi_init(struct tegra_i2c_dev *i2c_dev) i2c_writel(i2c_dev, 0x0, I2C_TLOW_SEXT); } -static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit) +static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) { u32 val; int err; @@ -836,16 +836,14 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit) if (i2c_dev->hw->has_interface_timing_reg && tsu_thd) i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1); - if (!clk_reinit) { - clk_multiplier = (tlow + thigh + 2); - clk_multiplier *= (i2c_dev->clk_divisor_non_hs_mode + 1); - err = clk_set_rate(i2c_dev->div_clk, - i2c_dev->bus_clk_rate * clk_multiplier); - if (err) { - dev_err(i2c_dev->dev, - "failed changing clock rate: %d\n", err); - return err; - } + clk_multiplier = tlow + thigh + 2; + clk_multiplier *= i2c_dev->clk_divisor_non_hs_mode + 1; + + err = clk_set_rate(i2c_dev->div_clk, + i2c_dev->bus_clk_rate * clk_multiplier); + if (err) { + dev_err(i2c_dev->dev, "failed to set div-clk rate: %d\n", err); + return err; } if (!i2c_dev->is_dvc && !i2c_dev->is_vi) { @@ -1319,7 +1317,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (!time_left && !completion_done(&i2c_dev->dma_complete)) { dev_err(i2c_dev->dev, "DMA transfer timeout\n"); - tegra_i2c_init(i2c_dev, true); + tegra_i2c_init(i2c_dev); return -ETIMEDOUT; } @@ -1340,7 +1338,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (time_left == 0) { dev_err(i2c_dev->dev, "i2c transfer timed out\n"); - tegra_i2c_init(i2c_dev, true); + tegra_i2c_init(i2c_dev); return -ETIMEDOUT; } @@ -1352,7 +1350,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (likely(i2c_dev->msg_err == I2C_ERR_NONE)) return 0; - tegra_i2c_init(i2c_dev, true); + tegra_i2c_init(i2c_dev); /* start recovery upon arbitration loss in single master mode */ if (i2c_dev->msg_err == I2C_ERR_ARBITRATION_LOST) { if (!i2c_dev->is_multimaster_mode) @@ -1811,7 +1809,7 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (ret < 0) goto disable_div_clk; - ret = tegra_i2c_init(i2c_dev, false); + ret = tegra_i2c_init(i2c_dev); if (ret) { dev_err(&pdev->dev, "Failed to initialize i2c controller\n"); goto release_dma; @@ -1918,7 +1916,7 @@ static int __maybe_unused tegra_i2c_resume(struct device *dev) if (err) return err; - err = tegra_i2c_init(i2c_dev, false); + err = tegra_i2c_init(i2c_dev); if (err) return err; From patchwork Tue Sep 8 02:09:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=IGyBGppr; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BlpgN6Mtlz9sTW for ; Tue, 8 Sep 2020 12:16:48 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728598AbgIHCQT (ORCPT ); Mon, 7 Sep 2020 22:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728245AbgIHCLn (ORCPT ); Mon, 7 Sep 2020 22:11:43 -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 7F3C2C061575; Mon, 7 Sep 2020 19:11:42 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id w3so18002414ljo.5; Mon, 07 Sep 2020 19:11:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z3/ictLAUjgwyR6p93PByXq4qxQ+4mmKUUiuuNtvitg=; b=IGyBGppr0Ur4wEoimgG2Y8yso+JEvaxd1/v1p6aljcMlYcSrY0lzokZ3ODIbOkTwdk ue8AhRfE5CFCA7sdSgujCDehkLS78lfPBDTySfN1ljnvAS2YuX7+V5AsoHBawC2iIHCx gV2qQUH6OipuGqRSbdxitzbLwxJQ/bnmEFeJjpns/qJNBh3CA62eENrR82yr5n70ltvz BNfJVsaF0gZLcyyr0AwPHkaMBSwt5ieSt0vb0kfnetLOupo1Wchzzvrm0qe3u9RK4cSm I/mrF2RGUOCdoO4P3MyGhygEK2SDibjrZ0YJCSj+Rng+mgr4a9UitJBBKZ39Wp7UZkAL /OHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z3/ictLAUjgwyR6p93PByXq4qxQ+4mmKUUiuuNtvitg=; b=R3h7bON+DlKlHM45qOUFyEjhB84b5NOnX77RX5k7tLgaR58RZapCmOi36HV25aI8tL DicSS551AeyFVXlDgKlN+X+2StrqnhTCMAQIRkgf6hcnb9K1VNInTVHx9pCIrSEh7fl2 Mv30rPJS9+KkQeb+k2hUcZO27mSYv/SOoqBj9eWSk7HHyM38WZhC9OloJhtXSiY8Ar0o N6yW1mIEmPIh6phU0B3EpCp0TSKyr+AezvRcMc07FIeJvd7tedeCoPqi84ftdk9nSauX vznT49dO20XqlqaekfB4dX8kigFX7Ls5c5kIppDtN1DwSoubnqdvAOnaCwtj/U6eqCLm ubDw== X-Gm-Message-State: AOAM53107fcOlXGnxvKEMzUw5aGkYBkNLS9Wf2YX6fHS2zhLRNhI8Hiz 8DCEkwXeOeHatapX0nx6NZs= X-Google-Smtp-Source: ABdhPJz2bvj2HaDgoVHtbxK+WdOY9T6KsP82co81kDPofesEu6z9qwFDIGREYAtXgoVtKPsKvQi0mg== X-Received: by 2002:a2e:9d8a:: with SMTP id c10mr6965071ljj.83.1599531100977; Mon, 07 Sep 2020 19:11:40 -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 j12sm9070085lfj.5.2020.09.07.19.11.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:40 -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 v6 06/35] i2c: tegra: Remove i2c_dev.clk_divisor_non_hs_mode member Date: Tue, 8 Sep 2020 05:09:52 +0300 Message-Id: <20200908021021.9123-7-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The "non_hs_mode" divisor value is fixed, thus there is no need to have the variable i2c_dev.clk_divisor_non_hs_mode struct member. Let's remove it and move the mode selection into tegra_i2c_init() where it can be united with the timing selection. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 46 ++++++++++++++++------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 720a75439e91..85ed0e02d48c 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -250,7 +250,6 @@ struct tegra_i2c_hw_feature { * @msg_buf_remaining: size of unsent data in the message buffer * @msg_read: identifies read transfers * @bus_clk_rate: current I2C bus clock rate - * @clk_divisor_non_hs_mode: clock divider for non-high-speed modes * @is_multimaster_mode: track if I2C controller is in multi-master mode * @tx_dma_chan: DMA transmit channel * @rx_dma_chan: DMA receive channel @@ -281,7 +280,6 @@ struct tegra_i2c_dev { size_t msg_buf_remaining; int msg_read; u32 bus_clk_rate; - u16 clk_divisor_non_hs_mode; bool is_multimaster_mode; struct dma_chan *tx_dma_chan; struct dma_chan *rx_dma_chan; @@ -783,6 +781,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) u32 val; int err; u32 clk_divisor, clk_multiplier; + u32 non_hs_mode; u32 tsu_thd; u8 tlow, thigh; @@ -805,24 +804,33 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) if (i2c_dev->is_vi) tegra_i2c_vi_init(i2c_dev); - /* Make sure clock divisor programmed correctly */ - clk_divisor = FIELD_PREP(I2C_CLK_DIVISOR_HSMODE, - i2c_dev->hw->clk_divisor_hs_mode) | - FIELD_PREP(I2C_CLK_DIVISOR_STD_FAST_MODE, - i2c_dev->clk_divisor_non_hs_mode); - i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); - - if (i2c_dev->bus_clk_rate > I2C_MAX_STANDARD_MODE_FREQ && - i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_PLUS_FREQ) { + switch (i2c_dev->bus_clk_rate) { + case I2C_MAX_STANDARD_MODE_FREQ + 1 ... I2C_MAX_FAST_MODE_PLUS_FREQ: + default: tlow = i2c_dev->hw->tlow_fast_fastplus_mode; thigh = i2c_dev->hw->thigh_fast_fastplus_mode; tsu_thd = i2c_dev->hw->setup_hold_time_fast_fast_plus_mode; - } else { + + if (i2c_dev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ) + non_hs_mode = i2c_dev->hw->clk_divisor_fast_plus_mode; + else + non_hs_mode = i2c_dev->hw->clk_divisor_fast_mode; + break; + + case 0 ... I2C_MAX_STANDARD_MODE_FREQ: tlow = i2c_dev->hw->tlow_std_mode; thigh = i2c_dev->hw->thigh_std_mode; tsu_thd = i2c_dev->hw->setup_hold_time_std_mode; + non_hs_mode = i2c_dev->hw->clk_divisor_std_mode; + break; } + /* Make sure clock divisor programmed correctly */ + clk_divisor = FIELD_PREP(I2C_CLK_DIVISOR_HSMODE, + i2c_dev->hw->clk_divisor_hs_mode) | + FIELD_PREP(I2C_CLK_DIVISOR_STD_FAST_MODE, non_hs_mode); + i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); + if (i2c_dev->hw->has_interface_timing_reg) { val = FIELD_PREP(I2C_INTERFACE_TIMING_THIGH, thigh) | FIELD_PREP(I2C_INTERFACE_TIMING_TLOW, tlow); @@ -837,7 +845,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1); clk_multiplier = tlow + thigh + 2; - clk_multiplier *= i2c_dev->clk_divisor_non_hs_mode + 1; + clk_multiplier *= non_hs_mode + 1; err = clk_set_rate(i2c_dev->div_clk, i2c_dev->bus_clk_rate * clk_multiplier); @@ -1751,18 +1759,6 @@ static int tegra_i2c_probe(struct platform_device *pdev) goto unprepare_fast_clk; } - if (i2c_dev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ && - i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_PLUS_FREQ) - i2c_dev->clk_divisor_non_hs_mode = - i2c_dev->hw->clk_divisor_fast_plus_mode; - else if (i2c_dev->bus_clk_rate > I2C_MAX_STANDARD_MODE_FREQ && - i2c_dev->bus_clk_rate <= I2C_MAX_FAST_MODE_FREQ) - i2c_dev->clk_divisor_non_hs_mode = - i2c_dev->hw->clk_divisor_fast_mode; - else - i2c_dev->clk_divisor_non_hs_mode = - i2c_dev->hw->clk_divisor_std_mode; - ret = clk_prepare(i2c_dev->div_clk); if (ret < 0) { dev_err(i2c_dev->dev, "Clock prepare failed %d\n", ret); From patchwork Tue Sep 8 02:09:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359399 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=T5y9qhD9; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpfq4ScFz9sR4 for ; Tue, 8 Sep 2020 12:16:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728562AbgIHCQR (ORCPT ); Mon, 7 Sep 2020 22:16:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728272AbgIHCLo (ORCPT ); Mon, 7 Sep 2020 22:11:44 -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 7243CC0613ED; Mon, 7 Sep 2020 19:11:43 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id t23so18045828ljc.3; Mon, 07 Sep 2020 19:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vFGzjwGX1HKX5lyPoG6GisXiLAg0DIxIZ91bMI/VsTM=; b=T5y9qhD98NS9lAKyvB7qsB4SlfoBe6Juq/2QacU0JtvFXyHAB1xQ8sQoG21fSaNiCR QKJpEf24zVDTnItxK4P/ppOUFmJMd0Nqnk5mtthHwx6yVGdDobW4MJVZB+jsZ9I+iIFv 7u+y6LXKnjnGiZ4A+SNSYBZEBstRCDEKu1lVzk5hHtkjd3WWQNF5R0ZJdH3NxsO5Naet QXxNezItUcP0bwVrUiBJO/2Pl0Io5AUCllbfCnmy6ff2JBOuYEJ8wsM5sY3TINjSJEO0 6JNquyjfzZJTvteBV6BIPtkdLj1FfO+0HxqwqtrIDi9ZtRsXOmrI9O/l2n3KbJ5H2nHj NQEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vFGzjwGX1HKX5lyPoG6GisXiLAg0DIxIZ91bMI/VsTM=; b=DVtHF7kAEiCnZJFm9wDEr3p8jKPN3+pz3IElYYHQyrp6T1nshyGyW+bN2RMG06Ffcf BD6bpPCXP72aA6sRsv9oOSy2Uq5kNUlmFxdYQYzR/9FAVEiyumg3+NRwHAKmNHUp6IXo P0qKBH2833EqzKcrhcrf2DXVmmUwGp3pBbf9jF8IpLvKnLJf7PT8M4HmXJ+w6OD0+YGE 406rH93sG8QJiciUC0onOHeJq4dvKZ/Y/YalZ/arEk+CSP8P5GjfIu6SHmcOCvL5H2rF tTYofA16F5LMG+ZzcEgHoeel+XnTQcrdsO94pDaRlsfQ4QUMvFaIiWjVYWhgaX9HNK6P 9M9Q== X-Gm-Message-State: AOAM531XVYqOgmCRBSibRozu5UAZj0kNPNc27d0cGcTu2PKla/WPHUaS Nu29LmNlb/Aq5OzegUfuYgo= X-Google-Smtp-Source: ABdhPJyrQLtWtUtIPtGlO2UJGpCycfMwO0MduT3Qk3o8BSX0UetXZ2XYI7Oy1ZuSLypOxlTDJC0EFw== X-Received: by 2002:a05:651c:141:: with SMTP id c1mr996963ljd.182.1599531101953; Mon, 07 Sep 2020 19:11:41 -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 j12sm9070085lfj.5.2020.09.07.19.11.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:41 -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 v6 07/35] i2c: tegra: Runtime PM always available on Tegra Date: Tue, 8 Sep 2020 05:09:53 +0300 Message-Id: <20200908021021.9123-8-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The runtime PM is guaranteed to be always available on Tegra after commit 40b2bb1b132a ("ARM: tegra: enforce PM requirement"). Hence let's remove all the RPM-availability checking and handling from the code. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 85ed0e02d48c..a52c72135390 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1775,18 +1775,10 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (!i2c_dev->is_vi) pm_runtime_irq_safe(&pdev->dev); pm_runtime_enable(&pdev->dev); - if (!pm_runtime_enabled(&pdev->dev)) { - ret = tegra_i2c_runtime_resume(&pdev->dev); - if (ret < 0) { - dev_err(&pdev->dev, "runtime resume failed\n"); - goto unprepare_div_clk; - } - } else { - ret = pm_runtime_get_sync(i2c_dev->dev); - if (ret < 0) { - dev_err(&pdev->dev, "runtime resume failed\n"); - goto put_rpm; - } + ret = pm_runtime_get_sync(i2c_dev->dev); + if (ret < 0) { + dev_err(dev, "runtime resume failed\n"); + goto put_rpm; } if (i2c_dev->is_multimaster_mode) { @@ -1845,15 +1837,8 @@ static int tegra_i2c_probe(struct platform_device *pdev) clk_disable(i2c_dev->div_clk); put_rpm: - if (pm_runtime_enabled(&pdev->dev)) - pm_runtime_put_sync(&pdev->dev); - else - tegra_i2c_runtime_suspend(&pdev->dev); - - if (pm_runtime_enabled(&pdev->dev)) - pm_runtime_disable(&pdev->dev); - -unprepare_div_clk: + pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); clk_unprepare(i2c_dev->div_clk); unprepare_slow_clk: @@ -1875,8 +1860,6 @@ static int tegra_i2c_remove(struct platform_device *pdev) clk_disable(i2c_dev->div_clk); pm_runtime_disable(&pdev->dev); - if (!pm_runtime_status_suspended(&pdev->dev)) - tegra_i2c_runtime_suspend(&pdev->dev); clk_unprepare(i2c_dev->div_clk); clk_unprepare(i2c_dev->slow_clk); From patchwork Tue Sep 8 02:09:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359401 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=OOCvpUWj; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpfr6c11z9sR4 for ; Tue, 8 Sep 2020 12:16:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728757AbgIHCQS (ORCPT ); Mon, 7 Sep 2020 22:16:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728273AbgIHCLo (ORCPT ); Mon, 7 Sep 2020 22:11:44 -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 4C76CC061786; Mon, 7 Sep 2020 19:11:44 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id v23so18076422ljd.1; Mon, 07 Sep 2020 19:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4LurUv+YpHFsrZm3AgTKy4azZ/BxWvLTGRcrIRYEkzE=; b=OOCvpUWjIT421nqNEXwbXTwgIeA5X4h2Wx0v7XLajJgW5QWSmAH6jc4Rk7kquOf0fK qa/HCYvo46YsN7PQkyEQh/yyFBGrtnxf2hwTObXadXIgtSnbVlXPHNxhFC0KLXnCEM7G OjK1xfbo5I8qWZe6VGgeM+vcTpGjaOfaG2vlJaaH3dY8ie9hyBf4Eel6BxE+quVo5Zbj 3QKzEkGELZtSzZck36qiRLi/d6BFASJzb6ZWnzmne2D4GD+9DJsEC4cwHKnCr840/GNq b8y+f6ImVZ+Unle2TYoTDa2+h9ljKGXndr2MM7e2NWLOkuIf2ifKV9zjZiKRyQ2oW0DO D/OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4LurUv+YpHFsrZm3AgTKy4azZ/BxWvLTGRcrIRYEkzE=; b=V5MuD6op9cZeNKpJAYKjUw1JnnTgW0Cj8ELZ2BNXl/IRe22ey3wV87MTftztc9mLiU /WI351gWYB8NIEUxwOWaDX7QGdViSHobyM1xi/+lueSvyNQD2IQtwaDf9st2rG0UCBAQ At/EUTcFrAPv/afGtWftjy7xSEbnPc6MSI6UVtvdgRMcB+1KHXnehIBm7/c/goMMZ5Bw nTYOEyyzGySk3iDtA+kTfeKCL7vctdHWjcwCBIXB9UFNfRBMe2vio/XTiP8WgBy4K9V8 hJy3oymP4CZeu+tgwQ5TIF+URNTlpXcNEIDascrH0//mDkgnFGNMRFWYm2Krf6NTHZNb LfXw== X-Gm-Message-State: AOAM531hMlTRv123n/NLQq7D8l6WtUX9AdB7f4hh0YkbjoXYwI0e0s0z O0obel9vaOb7ahTbtLMEguPnHr3+y0M= X-Google-Smtp-Source: ABdhPJxWSVvqEv0wjHt404BOiIUvdySwHMpgG546eO7wUznuf605L76/nnA8b3Jc2dGes2Gau/5TAQ== X-Received: by 2002:a2e:9212:: with SMTP id k18mr6725550ljg.241.1599531102790; Mon, 07 Sep 2020 19:11:42 -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 j12sm9070085lfj.5.2020.09.07.19.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:42 -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 v6 08/35] i2c: tegra: Remove error message used for devm_request_irq() failure Date: Tue, 8 Sep 2020 05:09:54 +0300 Message-Id: <20200908021021.9123-9-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The error message prints number of vIRQ, which isn't a useful information. In practice devm_request_irq() never fails, hence let's remove the bogus message in order to make code cleaner. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index a52c72135390..b813c0976c10 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1807,10 +1807,8 @@ static int tegra_i2c_probe(struct platform_device *pdev) ret = devm_request_irq(&pdev->dev, i2c_dev->irq, tegra_i2c_isr, IRQF_NO_SUSPEND, dev_name(&pdev->dev), i2c_dev); - if (ret) { - dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq); + if (ret) goto release_dma; - } i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); i2c_dev->adapter.owner = THIS_MODULE; From patchwork Tue Sep 8 02:09:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=kQQ5yRgT; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpfk5LdMz9sTK for ; Tue, 8 Sep 2020 12:16:14 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728517AbgIHCP4 (ORCPT ); Mon, 7 Sep 2020 22:15:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728275AbgIHCLq (ORCPT ); Mon, 7 Sep 2020 22:11:46 -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 20176C061755; Mon, 7 Sep 2020 19:11:45 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id b19so17986470lji.11; Mon, 07 Sep 2020 19:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9wL/ufnc3lNtiNLFNRaxPcM6Cg+5dtTmA95pTCa3ATE=; b=kQQ5yRgToSqKZtbeM1mLp+n9KNsuxWn8CPgaSZSBNnkTnjcxBW25gTCORF3AW/8VCz +rU+8hLtyUBf5IZA5FP8yRTocyEZ7UHGbL8q34S8GiggB/eWGx8oKrRmGvgxA8UJ6a9F +XG4aN1EaytABjB42SYZm8QbyPxjUXAjQRc2haYJKV8iYb+uWcfmTOsnVEzrLSeqhVex ALhV06lKDdQxR8THA1IGXHcJ80T6RHd5JdfVf+nL7Qjd8RZ3YbeectWhhM8k6w5c52TP afCyvBLvaeLf4PLswFTw885EpWztfCotnFuyZLCSGStN58DYfRA6uR6uvlimk4unseDm fC7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9wL/ufnc3lNtiNLFNRaxPcM6Cg+5dtTmA95pTCa3ATE=; b=QwlyUCSN0zvwkU8BTum5OnNPatl/jj0Zv5TpHnsdIAnojyj+gFtLCCQvVr5/25q/5v wnvSmzQa/fDRvSyD1OE1t7ElUqzwAh+dHu1Zi4fSEQ6NVkA3UxPdQkIXKDgWOFxdi16+ 3LTlyU+w9/cUGpXU3iWO54LC+5nJjd/r1VR3wCGnOTi1Ok4A1EEmwsoAdt3eJcq0UFom Uva1Shd2TBYAboBNTf9rDnYULByfZ/bW6hw35qU+HXFBzPo96SWyW5LbqqOV2IJnPXKv 51yOB0lTF4Zxv4TtGElIR4mpkkGi3jajYY9/Dd/HBpJ+bD8Y/ckDkhtvyG6D00fzKRiI SLPw== X-Gm-Message-State: AOAM5306cj6PUdHZqZXGuyytCr/E4N3+JXbwR5a1P3pNC0b7h2D1qBp4 bCgsQcICNsI7hZ1HvcBA4PY= X-Google-Smtp-Source: ABdhPJwaDffkzdplR7onoD0M9OXTT8yaHwzKdXcUTIu4i54uPl9TI2+3gvjT9F51anR+Zlh8qZNf6A== X-Received: by 2002:a2e:8e30:: with SMTP id r16mr10630255ljk.304.1599531103607; Mon, 07 Sep 2020 19:11:43 -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 j12sm9070085lfj.5.2020.09.07.19.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:43 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 09/35] i2c: tegra: Use reset_control_reset() Date: Tue, 8 Sep 2020 05:09:55 +0300 Message-Id: <20200908021021.9123-10-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Use a single reset_control_reset() instead of assert/deasset couple in order to make code cleaner a tad. Note that the reset_control_reset() uses 1 microsecond delay instead of 2 that was used previously, but this shouldn't matter because one microsecond is a default reset time for most of Tegra peripherals and TRM doesn't mention anything special in regards to I2C controller's reset propagation time. In addition don't ignore potential error of the reset control by emitting a noisy warning if it fails, which will indicate an existence of a severe problem, while still allow machine to boot up. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index b813c0976c10..90ba2f5327c5 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -785,9 +785,16 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) u32 tsu_thd; u8 tlow, thigh; - reset_control_assert(i2c_dev->rst); - udelay(2); - reset_control_deassert(i2c_dev->rst); + /* + * The reset shouldn't ever fail in practice. The failure will be a + * sign of a severe problem that needs to be resolved. Still we don't + * want to fail the initialization completely because this may break + * kernel boot up since voltage regulators use I2C. Hence, we will + * emit a noisy warning on error, which won't stay unnoticed and + * won't hose machine entirely. + */ + err = reset_control_reset(i2c_dev->rst); + WARN_ON_ONCE(err); if (i2c_dev->is_dvc) tegra_dvc_init(i2c_dev); From patchwork Tue Sep 8 02:09:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=fa2KeXtA; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BlpgP4Xypz9sTX for ; Tue, 8 Sep 2020 12:16:49 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728275AbgIHCQR (ORCPT ); Mon, 7 Sep 2020 22:16:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728277AbgIHCLq (ORCPT ); Mon, 7 Sep 2020 22:11:46 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14DD3C061795; Mon, 7 Sep 2020 19:11:46 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id b12so8304879lfp.9; Mon, 07 Sep 2020 19:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HtsscUVX9USqMNRXBDByuYOqMY2muh1bB3NfySu7tl8=; b=fa2KeXtAHAMJQOqBaP5RMOJTBSw+cDEK6ojVorwGCj4qKTPLaDySziuD5peEJGTu7k cD20ecHaj5uUdDOjratvenhjB9If0XSmdqzGfSBAhB9RkdcTTnbRG7WlsF2C1a4Y7Ay7 AD/vk5sdfBfl1rNtrX5njAcU+iiLpMR8jsmkzhVGAZ3g3a8Fj4olBN9MB9ZvSWN1SEf3 0Vg4fYgk4T6cKISxEPua4jzV+3uHw57W1055TYEL+WQf2mqEMTV4KTbQfuclQq7pU5he XJqJnyb/nJ/hxpRIsbmzG1t7E/QXFrvENHYfHa7QKiwNRsB4YMkZ6V+xfVTkWhiWbAEH oo9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HtsscUVX9USqMNRXBDByuYOqMY2muh1bB3NfySu7tl8=; b=tLEZG+hEDz9Y3w/cNFHcjlmwC9Fii2TY9zckVQSoBYeI/EgsNo8m4n7rs9X4CZTAAg kWUGzuZxxjmgzKxJh2Y/CRkHQBlmtsiOmFqQPX4+bcj3p9gitPcsPiPVs5JKRmgqeOjY Zp5pcVKrJdFPzKeWmaC8TeKctvRH2TyeJR2s3JKd4QbnC2voYQkMmSYUgq3Ddsqwz9MU IjVhjHGeVP5zbhKT8EdxZNt8ZKyc82uD8P5/lkaHXA8NT5dH5HHGCjHRkBIs79xuaC/a OywQlPSzkvyVzm05RjbZVO8LALpHpAUFxwP4GRpXmdqgLdq6uMziCp4ubcZINTw/OEbS nXKg== X-Gm-Message-State: AOAM531MxTBxvVB7OgGzcNVCwLKxkxC5O3e05KRvd73ZkyLHCZXpVVFG aG/pUrH2MJXXjfNRPqXxGcA= X-Google-Smtp-Source: ABdhPJx7gNa1jKMbZzebHb1QwcP2ueIhpoe7fO7AvO/g6zQT/AFsGuEWw9z3y5QO8cYAUNxLt+a62A== X-Received: by 2002:a19:7604:: with SMTP id c4mr11501739lff.132.1599531104430; Mon, 07 Sep 2020 19:11:44 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:44 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 10/35] i2c: tegra: Use devm_platform_get_and_ioremap_resource() Date: Tue, 8 Sep 2020 05:09:56 +0300 Message-Id: <20200908021021.9123-11-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Driver now uses devm_platform_get_and_ioremap_resource() which replaces the typical boilerplate code and makes code cleaner. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 90ba2f5327c5..c2bbdf92b11f 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1678,12 +1678,12 @@ static int tegra_i2c_probe(struct platform_device *pdev) int irq; int ret; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - base_phys = res->start; - base = devm_ioremap_resource(&pdev->dev, res); + base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(base)) return PTR_ERR(base); + base_phys = res->start; + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (!res) { dev_err(&pdev->dev, "no irq resource\n"); From patchwork Tue Sep 8 02:09:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=nRGyRvM3; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpfp0RKJz9sTK for ; Tue, 8 Sep 2020 12:16:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728255AbgIHCP4 (ORCPT ); Mon, 7 Sep 2020 22:15:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728282AbgIHCLu (ORCPT ); Mon, 7 Sep 2020 22:11:50 -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 C2D61C061796; Mon, 7 Sep 2020 19:11:46 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id k25so17981521ljg.9; Mon, 07 Sep 2020 19:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hUUPRBULDiyvblMhx4V1F89haxR9rFzQ0ynZsEU3uxo=; b=nRGyRvM39J7Dc0NKd4+T9T4q9xmMp5RPRHo5+CUnrLdaLF7fTamBp89GlCu9bYtQPs ji7f3iu8HUO0Zap9c43X7AEtbNfdN2RBI3kOm9lBx0rVQZrEwN61rGD5GBur/ddYhTlq 3ZaPxUMFiT5uKiKiLeJs3zbyzhudtNy2LsBeZ5i4O58uiFyTXM9KLfkHYoKjb61+hqI4 vKcePjfmvfinzbQ6vctR11ihcoTaPl2lqwCSDPPXoOK6Mk6W66JRIE0MPuAKuFZSh3hR JwD/loQLHdRhi4dB0v6Jr7Jr6cXuXS0O2lU/fan8TRJxgpttTCFO9t2Fx9QzmXLv5wC1 WDiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hUUPRBULDiyvblMhx4V1F89haxR9rFzQ0ynZsEU3uxo=; b=LHN18FKWii0b7BiIVNzt2ynYslejPrEKPvp3WvDFuJK6IZIMaDSoatWQPPoJf4nq0n xHn21dJk3lr6WyR0/wHfFm5TV0dHLmB+O7UK9GNvyJE9t4mpfou+fni7iq+2c2VaxQhm nf+cwQfLE6sAdJUW2o2pWczHmnz8j2D7GZYMxXgRg9sDf+Mxri0K57jZY6PXoQB8lkit Xj2CqgmLleRHdYZTRI1WCeGnp7xhKK+PJGNzpbTHwwIfv27uAlAhi2jsD0gjT2LgGaZr PIHvhrFJFXkQ2TPYoccnLB/FL6/9d9m+RDuiCoPtFiX3+nnkKatZ73iHMvA63EuCRlZ0 YN3Q== X-Gm-Message-State: AOAM533jAJ2tI8WAj+FG9ho6TiepNOf4WBrpDbgaampvItC+F2hUjoCO 3Q/FbgHgX7EEfqnkkAxKizI= X-Google-Smtp-Source: ABdhPJzqJzpQh1N+5SKPnHfngu+Z5Ok1l46TN7zqP9VJfHlNyyjrMU0f435od7m7CG21nzSiI4+EBQ== X-Received: by 2002:a2e:b543:: with SMTP id a3mr11879754ljn.19.1599531105278; Mon, 07 Sep 2020 19:11:45 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:44 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 11/35] i2c: tegra: Use platform_get_irq() Date: Tue, 8 Sep 2020 05:09:57 +0300 Message-Id: <20200908021021.9123-12-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Use common helper for retrieval of the interrupt number in order to make code cleaner. Note that platform_get_irq() prints error message by itself. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index c2bbdf92b11f..505b5d37077d 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1684,12 +1684,9 @@ static int tegra_i2c_probe(struct platform_device *pdev) base_phys = res->start; - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (!res) { - dev_err(&pdev->dev, "no irq resource\n"); - return -EINVAL; - } - irq = res->start; + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; div_clk = devm_clk_get(&pdev->dev, "div-clk"); if (IS_ERR(div_clk)) { From patchwork Tue Sep 8 02:09:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359395 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=c+BPUPuo; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpfl5VkQz9sTK for ; Tue, 8 Sep 2020 12:16:15 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728481AbgIHCP4 (ORCPT ); Mon, 7 Sep 2020 22:15:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728283AbgIHCLu (ORCPT ); Mon, 7 Sep 2020 22:11:50 -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 C9BB4C061797; Mon, 7 Sep 2020 19:11:47 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id k25so5443563ljk.0; Mon, 07 Sep 2020 19:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YHZBmS//DKgloRMzbyQpmnOh0K1tBY6VABjMBXpbtz0=; b=c+BPUPuotzOcWSghINHQROv9//BUwlSfg5E4UeJlptTZEh9SnBmZLgPzQX59mQShrH uhjEQovZ8ypxEXG1Mb+g+PN8CeauwvnunQJ9j4Kwx7Pb7I/H7qRlvWgYYsKX1WEkO8M4 1xbwBFhAZVXpBGk+cdu9imD0hfZCIvRj1PJ6rCrdGBox4rQ7XcvWCRfHbkiklVCKhw73 KnmMDyw5Cm4Ttoqj6O/vAvfCcbDXQv6TZ5TI6e6A1tZ2UOCMVUlSkeh/06xqG5jBh2CJ u5b78N1AkIXcJtxmqlYe2TOWVIcMciw6LV8ahTlpC7iwYs+nnLBzI3Nswq3P4ZHVlVom /9SQ== 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=YHZBmS//DKgloRMzbyQpmnOh0K1tBY6VABjMBXpbtz0=; b=DMMKB5KjGJ865yfrruKIlLaDzGNTk24JZX/NqSF81Y32enRP/54qDAKjnI7BIB+hIH P6cQExDFLJQ5rOA+xvNHFnBlvn/nG65/xGXGWJ8IHXAjRAxKrl73tUB1ew3RPsJ5ObM9 c+8IXDq2V7R4f42/TcG6LlZA8WuC4iZ+uWrPn3NWGXLKZAX1vIQt1mBlXKvciiKZNqq8 OsrcWIsIK5PVa/2/RJAz0RehGyWUOgwUoShkHljkLfoPBn9fmDFrVcdUNqS2eDj1SCN1 awRNbXMYkpQrVdFyYS9KywgfL1okngKhaLl4FWXgQhOeG6oAL0jmCtPZ83kEShtrpXzx jUYA== X-Gm-Message-State: AOAM533F/KYo9YhNjxl0Y4wtl29EL776GgdS0s6FAeLDnbT6V17eKEXx uK9srSHm5Dlam++tCvi3gYPMAWrTcd4= X-Google-Smtp-Source: ABdhPJzBzcEIEpdkOEfHlOJ8q4Ps09yizoo7jOjiNehX3qMjfy8wVVFzLVkqHPsX7IDEBdhW4U2EGw== X-Received: by 2002:a05:651c:1056:: with SMTP id x22mr12559913ljm.81.1599531106221; Mon, 07 Sep 2020 19:11:46 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:45 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 12/35] i2c: tegra: Use clk-bulk helpers Date: Tue, 8 Sep 2020 05:09:58 +0300 Message-Id: <20200908021021.9123-13-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Use clk-bulk helpers and factor out clocks initialization into separate function in order to make code cleaner. The clocks initialization now performed after reset-control initialization in order to avoid a noisy -PROBE_DEFER errors on T186+ from the clk-bulk helper which doesn't silence this error code. Hence reset_control_get() now may return -EPROBE_DEFER on newer Tegra SoCs because they use BPMP driver that provides reset controls and BPMP doesn't come up early during boot. Previously rst was protected by the clocks retrieval and now this patch makes dev_err_probe() to be used for the rst error handling. Suggested-by: Andy Shevchenko Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 187 ++++++++++++--------------------- 1 file changed, 67 insertions(+), 120 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 505b5d37077d..d2fe0f1704a5 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -165,9 +165,6 @@ enum msg_end_type { * @has_continue_xfer_support: Continue transfer supports. * @has_per_pkt_xfer_complete_irq: Has enable/disable capability for transfer * complete interrupt per packet basis. - * @has_single_clk_source: The I2C controller has single clock source. Tegra30 - * and earlier SoCs have two clock sources i.e. div-clk and - * fast-clk. * @has_config_load_reg: Has the config load register to load the new * configuration. * @clk_divisor_hs_mode: Clock divisor in HS mode. @@ -208,7 +205,6 @@ enum msg_end_type { struct tegra_i2c_hw_feature { bool has_continue_xfer_support; bool has_per_pkt_xfer_complete_irq; - bool has_single_clk_source; bool has_config_load_reg; int clk_divisor_hs_mode; int clk_divisor_std_mode; @@ -236,7 +232,8 @@ struct tegra_i2c_hw_feature { * @hw: Tegra I2C HW feature * @adapter: core I2C layer adapter information * @div_clk: clock reference for div clock of I2C controller - * @fast_clk: clock reference for fast clock of I2C controller + * @clocks: array of I2C controller clocks + * @nclocks: number of clocks in the array * @rst: reset control for the I2C controller * @base: ioremapped registers cookie * @base_phys: physical base address of the I2C controller @@ -265,8 +262,8 @@ struct tegra_i2c_dev { const struct tegra_i2c_hw_feature *hw; struct i2c_adapter adapter; struct clk *div_clk; - struct clk *fast_clk; - struct clk *slow_clk; + struct clk_bulk_data *clocks; + unsigned int nclocks; struct reset_control *rst; void __iomem *base; phys_addr_t base_phys; @@ -662,25 +659,9 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) if (ret) return ret; - ret = clk_enable(i2c_dev->fast_clk); - if (ret < 0) { - dev_err(i2c_dev->dev, - "Enabling fast clk failed, err %d\n", ret); + ret = clk_bulk_enable(i2c_dev->nclocks, i2c_dev->clocks); + if (ret) return ret; - } - - ret = clk_enable(i2c_dev->slow_clk); - if (ret < 0) { - dev_err(dev, "failed to enable slow clock: %d\n", ret); - goto disable_fast_clk; - } - - ret = clk_enable(i2c_dev->div_clk); - if (ret < 0) { - dev_err(i2c_dev->dev, - "Enabling div clk failed, err %d\n", ret); - goto disable_slow_clk; - } /* * VI I2C device is attached to VE power domain which goes through @@ -691,17 +672,14 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) if (i2c_dev->is_vi) { ret = tegra_i2c_init(i2c_dev); if (ret) - goto disable_div_clk; + goto disable_clocks; } return 0; -disable_div_clk: - clk_disable(i2c_dev->div_clk); -disable_slow_clk: - clk_disable(i2c_dev->slow_clk); -disable_fast_clk: - clk_disable(i2c_dev->fast_clk); +disable_clocks: + clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); + return ret; } @@ -709,9 +687,7 @@ static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev) { struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); - clk_disable(i2c_dev->div_clk); - clk_disable(i2c_dev->slow_clk); - clk_disable(i2c_dev->fast_clk); + clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); return pinctrl_pm_select_idle_state(i2c_dev->dev); } @@ -1479,7 +1455,6 @@ static struct i2c_bus_recovery_info tegra_i2c_recovery_info = { static const struct tegra_i2c_hw_feature tegra20_i2c_hw = { .has_continue_xfer_support = false, .has_per_pkt_xfer_complete_irq = false, - .has_single_clk_source = false, .clk_divisor_hs_mode = 3, .clk_divisor_std_mode = 0, .clk_divisor_fast_mode = 0, @@ -1504,7 +1479,6 @@ static const struct tegra_i2c_hw_feature tegra20_i2c_hw = { static const struct tegra_i2c_hw_feature tegra30_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = false, - .has_single_clk_source = false, .clk_divisor_hs_mode = 3, .clk_divisor_std_mode = 0, .clk_divisor_fast_mode = 0, @@ -1529,7 +1503,6 @@ static const struct tegra_i2c_hw_feature tegra30_i2c_hw = { static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = true, - .has_single_clk_source = true, .clk_divisor_hs_mode = 1, .clk_divisor_std_mode = 0x19, .clk_divisor_fast_mode = 0x19, @@ -1554,7 +1527,6 @@ static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { static const struct tegra_i2c_hw_feature tegra124_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = true, - .has_single_clk_source = true, .clk_divisor_hs_mode = 1, .clk_divisor_std_mode = 0x19, .clk_divisor_fast_mode = 0x19, @@ -1579,7 +1551,6 @@ static const struct tegra_i2c_hw_feature tegra124_i2c_hw = { static const struct tegra_i2c_hw_feature tegra210_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = true, - .has_single_clk_source = true, .clk_divisor_hs_mode = 1, .clk_divisor_std_mode = 0x19, .clk_divisor_fast_mode = 0x19, @@ -1604,7 +1575,6 @@ static const struct tegra_i2c_hw_feature tegra210_i2c_hw = { static const struct tegra_i2c_hw_feature tegra186_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = true, - .has_single_clk_source = true, .clk_divisor_hs_mode = 1, .clk_divisor_std_mode = 0x16, .clk_divisor_fast_mode = 0x19, @@ -1629,7 +1599,6 @@ static const struct tegra_i2c_hw_feature tegra186_i2c_hw = { static const struct tegra_i2c_hw_feature tegra194_i2c_hw = { .has_continue_xfer_support = true, .has_per_pkt_xfer_complete_irq = true, - .has_single_clk_source = true, .clk_divisor_hs_mode = 1, .clk_divisor_std_mode = 0x4f, .clk_divisor_fast_mode = 0x3c, @@ -1666,13 +1635,58 @@ static const struct of_device_id tegra_i2c_of_match[] = { }; MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); +static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev) +{ + unsigned int i; + int err; + + err = devm_clk_bulk_get_all(i2c_dev->dev, &i2c_dev->clocks); + if (err < 0) + return err; + + i2c_dev->nclocks = err; + + err = clk_bulk_prepare(i2c_dev->nclocks, i2c_dev->clocks); + if (err) + return err; + + for (i = 0; i < i2c_dev->nclocks; i++) { + if (!strcmp(i2c_dev->clocks[i].id, "div-clk")) { + i2c_dev->div_clk = i2c_dev->clocks[i].clk; + break; + } + } + + if (!i2c_dev->is_multimaster_mode) + return 0; + + err = clk_enable(i2c_dev->div_clk); + if (err) { + dev_err(i2c_dev->dev, "failed to enable div-clk: %d\n", err); + goto unprepare_clocks; + } + + return 0; + +unprepare_clocks: + clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks); + + return err; +} + +static void tegra_i2c_release_clocks(struct tegra_i2c_dev *i2c_dev) +{ + if (i2c_dev->is_multimaster_mode) + clk_disable(i2c_dev->div_clk); + + clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks); +} + static int tegra_i2c_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct tegra_i2c_dev *i2c_dev; struct resource *res; - struct clk *div_clk; - struct clk *fast_clk; void __iomem *base; phys_addr_t base_phys; int irq; @@ -1688,21 +1702,12 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (irq < 0) return irq; - div_clk = devm_clk_get(&pdev->dev, "div-clk"); - if (IS_ERR(div_clk)) { - if (PTR_ERR(div_clk) != -EPROBE_DEFER) - dev_err(&pdev->dev, "missing controller clock\n"); - - return PTR_ERR(div_clk); - } - i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); if (!i2c_dev) return -ENOMEM; i2c_dev->base = base; i2c_dev->base_phys = base_phys; - i2c_dev->div_clk = div_clk; i2c_dev->adapter.algo = &tegra_i2c_algo; i2c_dev->adapter.retries = 1; i2c_dev->adapter.timeout = 6 * HZ; @@ -1712,12 +1717,17 @@ static int tegra_i2c_probe(struct platform_device *pdev) i2c_dev->rst = devm_reset_control_get_exclusive(&pdev->dev, "i2c"); if (IS_ERR(i2c_dev->rst)) { - dev_err(&pdev->dev, "missing controller reset\n"); + dev_err_probe(i2c_dev->dev, PTR_ERR(i2c_dev->rst), + "failed to get reset control\n"); return PTR_ERR(i2c_dev->rst); } tegra_i2c_parse_dt(i2c_dev); + ret = tegra_i2c_init_clocks(i2c_dev); + if (ret) + return ret; + i2c_dev->hw = of_device_get_match_data(&pdev->dev); i2c_dev->is_dvc = of_device_is_compatible(pdev->dev.of_node, "nvidia,tegra20-i2c-dvc"); @@ -1729,46 +1739,8 @@ static int tegra_i2c_probe(struct platform_device *pdev) init_completion(&i2c_dev->msg_complete); init_completion(&i2c_dev->dma_complete); - if (!i2c_dev->hw->has_single_clk_source) { - fast_clk = devm_clk_get(&pdev->dev, "fast-clk"); - if (IS_ERR(fast_clk)) { - dev_err(&pdev->dev, "missing fast clock\n"); - return PTR_ERR(fast_clk); - } - i2c_dev->fast_clk = fast_clk; - } - - if (i2c_dev->is_vi) { - i2c_dev->slow_clk = devm_clk_get(dev, "slow"); - if (IS_ERR(i2c_dev->slow_clk)) { - if (PTR_ERR(i2c_dev->slow_clk) != -EPROBE_DEFER) - dev_err(dev, "failed to get slow clock: %ld\n", - PTR_ERR(i2c_dev->slow_clk)); - - return PTR_ERR(i2c_dev->slow_clk); - } - } - platform_set_drvdata(pdev, i2c_dev); - ret = clk_prepare(i2c_dev->fast_clk); - if (ret < 0) { - dev_err(i2c_dev->dev, "Clock prepare failed %d\n", ret); - return ret; - } - - ret = clk_prepare(i2c_dev->slow_clk); - if (ret < 0) { - dev_err(dev, "failed to prepare slow clock: %d\n", ret); - goto unprepare_fast_clk; - } - - ret = clk_prepare(i2c_dev->div_clk); - if (ret < 0) { - dev_err(i2c_dev->dev, "Clock prepare failed %d\n", ret); - goto unprepare_slow_clk; - } - /* * VI I2C is in VE power domain which is not always on and not * an IRQ safe. So, IRQ safe device can't be attached to a non-IRQ @@ -1785,21 +1757,12 @@ static int tegra_i2c_probe(struct platform_device *pdev) goto put_rpm; } - if (i2c_dev->is_multimaster_mode) { - ret = clk_enable(i2c_dev->div_clk); - if (ret < 0) { - dev_err(i2c_dev->dev, "div_clk enable failed %d\n", - ret); - goto put_rpm; - } - } - if (i2c_dev->hw->supports_bus_clear) i2c_dev->adapter.bus_recovery_info = &tegra_i2c_recovery_info; ret = tegra_i2c_init_dma(i2c_dev); if (ret < 0) - goto disable_div_clk; + goto put_rpm; ret = tegra_i2c_init(i2c_dev); if (ret) { @@ -1834,20 +1797,10 @@ static int tegra_i2c_probe(struct platform_device *pdev) release_dma: tegra_i2c_release_dma(i2c_dev); -disable_div_clk: - if (i2c_dev->is_multimaster_mode) - clk_disable(i2c_dev->div_clk); - put_rpm: pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); - clk_unprepare(i2c_dev->div_clk); - -unprepare_slow_clk: - clk_unprepare(i2c_dev->slow_clk); - -unprepare_fast_clk: - clk_unprepare(i2c_dev->fast_clk); + tegra_i2c_release_clocks(i2c_dev); return ret; } @@ -1858,16 +1811,10 @@ static int tegra_i2c_remove(struct platform_device *pdev) i2c_del_adapter(&i2c_dev->adapter); - if (i2c_dev->is_multimaster_mode) - clk_disable(i2c_dev->div_clk); - pm_runtime_disable(&pdev->dev); - clk_unprepare(i2c_dev->div_clk); - clk_unprepare(i2c_dev->slow_clk); - clk_unprepare(i2c_dev->fast_clk); - tegra_i2c_release_dma(i2c_dev); + tegra_i2c_release_clocks(i2c_dev); return 0; } From patchwork Tue Sep 8 02:09:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359384 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=GoPm2t9o; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BlpfG6hrkz9sR4 for ; Tue, 8 Sep 2020 12:15:50 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728932AbgIHCP0 (ORCPT ); Mon, 7 Sep 2020 22:15:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728303AbgIHCMA (ORCPT ); Mon, 7 Sep 2020 22:12:00 -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 9E391C061798; Mon, 7 Sep 2020 19:11:48 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id w3so18002631ljo.5; Mon, 07 Sep 2020 19:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n78f/w7+YRlV7g2j4BSWVO0kVbFgpBSvXgYlEUTKsGI=; b=GoPm2t9ozB8lqVKv6t/xeiGfy8YhpTLYGgt0Kcc4cHVqZhhW+kSuG2PGad9yZ/hP90 G9tEJCcRKmBaTyKe/ec4x0X2vH42LBE77Z8JL1D9WzvCaeicnxmBPOVRllQ0SnqV7y4l h2Kfm5iv3b5M12wogJFJn5TJHLvOBYOw+yXZjdUsAWH4KbXiH1LcHxLN4ehLb7h3+wW6 R9aY4tjpMg5TsW/TSW0OUo5QHOTU85gU76UhET/DL/uoADU2p6LdxsSlJVL+9TqGj/QI 4zkouuu0jwu5+5Pd9AQDs0mEoZ3Gf2PO+YBtWhybBKMNxBok9UVnLfCHFf+iIzGjD0ZG 5m2g== 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=n78f/w7+YRlV7g2j4BSWVO0kVbFgpBSvXgYlEUTKsGI=; b=jDkT9L2X+f8HWtS7X0eabQY0VBNYJVU0RkpxK5BOmHf/1kgVMsizO+24hvHBnAnY5r qjzMdxyPwevSPt+p3Allej0stqkUDlDzdQGrDYv9ABVjQEBRVGG/EBIwSiuuyWS+Kp52 yi9E6T+Xp6uLM9Rz6wSbI0wHPWIB3kB7HEGsG4ATweQAEBnBNw29JSIhxzlbtAxIHdzG SB7ub4PDp8+Uau6Nmt28vOvXlFrgowXENHQWqac/HpUlulnppPviI1CkvrCJSLRu/0pz dABPJrpUyhAubCcwcF5GanD6FVn2+nACD51EZOD7QnX8uhDPMjrIu+pjW/n8100vX8ft JKvw== X-Gm-Message-State: AOAM533GqE7xqAmhxCc/33G8Vno7i6N/08lckv6/fvCCRR4ygp4aRowY TFxumqwgjv68/YUCxpiiQcmMPJVX0p8= X-Google-Smtp-Source: ABdhPJwAzGn2vY0SMWNE5xX/vh0LxiNC1OBOIgRrRXCf1ALdEL4SOn1JSdjboMWrH1XAwBv20cD/5w== X-Received: by 2002:a2e:918f:: with SMTP id f15mr11835357ljg.435.1599531107062; Mon, 07 Sep 2020 19:11:47 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:46 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 13/35] i2c: tegra: Move out all device-tree parsing into tegra_i2c_parse_dt() Date: Tue, 8 Sep 2020 05:09:59 +0300 Message-Id: <20200908021021.9123-14-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Move out code related to device-tree parsing from the probe function into tegra_i2c_parse_dt() in order to make code more consistent. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index d2fe0f1704a5..e20937041504 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1428,6 +1428,12 @@ static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) multi_mode = of_property_read_bool(np, "multi-master"); i2c_dev->is_multimaster_mode = multi_mode; + + if (of_device_is_compatible(np, "nvidia,tegra20-i2c-dvc")) + i2c_dev->is_dvc = true; + + if (of_device_is_compatible(np, "nvidia,tegra210-i2c-vi")) + i2c_dev->is_vi = true; } static const struct i2c_algorithm tegra_i2c_algo = { @@ -1729,10 +1735,6 @@ static int tegra_i2c_probe(struct platform_device *pdev) return ret; i2c_dev->hw = of_device_get_match_data(&pdev->dev); - i2c_dev->is_dvc = of_device_is_compatible(pdev->dev.of_node, - "nvidia,tegra20-i2c-dvc"); - i2c_dev->is_vi = of_device_is_compatible(dev->of_node, - "nvidia,tegra210-i2c-vi"); i2c_dev->adapter.quirks = i2c_dev->hw->quirks; i2c_dev->dma_buf_size = i2c_dev->adapter.quirks->max_write_len + I2C_PACKET_HEADER_SIZE; From patchwork Tue Sep 8 02:10:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359382 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=lTWhurnF; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BlpfF2gSKz9sR4 for ; Tue, 8 Sep 2020 12:15:49 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729023AbgIHCP0 (ORCPT ); Mon, 7 Sep 2020 22:15:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728304AbgIHCMA (ORCPT ); Mon, 7 Sep 2020 22:12:00 -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 9E111C061799; Mon, 7 Sep 2020 19:11:49 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id z17so8278147lfi.12; Mon, 07 Sep 2020 19:11:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kCyEsKR0un5niH6gxtptQbiMsjxv3WuucENMOeiVIdo=; b=lTWhurnFIjL3s22RvrWf+mATezimZRnvwTBABxHtYlhJHg01vKS5B0IVzV7BiAqV7P dpCQ6qlYu5wN3ihCWyudv8oAc7PouWvX927jdFBNh+e/pZTM0yLh+hTdD4tKboh0bnNs iF7OkdvIodaz6fs7vjoVHAGfWwLXky/OkIRnkioMUpElJ5G/ma1Bx7/W+xVpkcWiUilh KnxrL8Rpax6waN8Ww4+FrQY6xemeLDtfIMaaQUVzA7y1Gs7FhLGUMWAlnwBw3Ve7SVNh 0RELBrudfBcu3WB3xb2R53klEsFzFiznxY9PB0MdztfM4KgaoBB9MLn1rOCJ/45+z1ib 003g== 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=kCyEsKR0un5niH6gxtptQbiMsjxv3WuucENMOeiVIdo=; b=APNr8CqrZDkEado8zZWyYAw7uehe175lcUqjK9BO7mLu27Rkf5hy0905RYfUZSvGCP +npa+eeWhRRKM7HaYgCLRNuMZXpnN8JtDP8pa3FHM8hI1Nc7Bw6vdCwX65k0ry/tOEz4 IiJJiXADlfcYWM2P6qQ4s1PORWkQFVSgVwxBBzSH5HVkvKhzgdbFCqjcsrOhm3439UgO D0wfJh3kW/EOoVk/DikpV0b+sla26zgygDtGWPXiWEjvvu+tCryqqhyhkjc0lj2i/QS8 cPH7BB83cqV83cFz0R95sJaGAF8/kyjDvlph55vdHirgapvGfK51Ie9gqqgdUzDLs94y lNIQ== X-Gm-Message-State: AOAM533KhFSGoNZjto025Z7fiJLGS++HU6kVRobCO8TVQG+/Jjao8EUd qhaokOLvKuzTuAhrEzuUbWo= X-Google-Smtp-Source: ABdhPJzClpLCo4Ht4G/uPEbOf+KJSXede6woAFncTWfr32pa+8azWbEqnniF5jczfO4RW6WNmfPR0w== X-Received: by 2002:a05:6512:10d1:: with SMTP id k17mr11388832lfg.179.1599531108041; Mon, 07 Sep 2020 19:11:48 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:47 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 14/35] i2c: tegra: Clean up probe function Date: Tue, 8 Sep 2020 05:10:00 +0300 Message-Id: <20200908021021.9123-15-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The driver's probe function code is a bit difficult to read. This patch reorders code of the probe function, forming groups of code that are easy to work with. The probe tear-down order now matches the driver-removal order. All dev/&pdev->dev are replaced with i2c_dev->dev in order to have uniform code style across the driver. The "ret" variable renamed to "err" since it only carries error code and the new name clearly shows that. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 141 +++++++++++++++++---------------- 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index e20937041504..01637e1fccde 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -440,6 +440,9 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) i2c_dev->tx_dma_chan = chan; + i2c_dev->dma_buf_size = i2c_dev->hw->quirks->max_write_len + + I2C_PACKET_HEADER_SIZE; + dma_buf = dma_alloc_coherent(i2c_dev->dev, i2c_dev->dma_buf_size, &dma_phys, GFP_KERNEL | __GFP_NOWARN); if (!dma_buf) { @@ -1690,38 +1693,45 @@ static void tegra_i2c_release_clocks(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_probe(struct platform_device *pdev) { - struct device *dev = &pdev->dev; struct tegra_i2c_dev *i2c_dev; struct resource *res; - void __iomem *base; - phys_addr_t base_phys; - int irq; - int ret; - - base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); - if (IS_ERR(base)) - return PTR_ERR(base); - - base_phys = res->start; - - irq = platform_get_irq(pdev, 0); - if (irq < 0) - return irq; + int err; i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); if (!i2c_dev) return -ENOMEM; - i2c_dev->base = base; - i2c_dev->base_phys = base_phys; - i2c_dev->adapter.algo = &tegra_i2c_algo; - i2c_dev->adapter.retries = 1; - i2c_dev->adapter.timeout = 6 * HZ; - i2c_dev->irq = irq; + platform_set_drvdata(pdev, i2c_dev); + + init_completion(&i2c_dev->msg_complete); + init_completion(&i2c_dev->dma_complete); + + i2c_dev->hw = of_device_get_match_data(&pdev->dev); i2c_dev->cont_id = pdev->id; i2c_dev->dev = &pdev->dev; - i2c_dev->rst = devm_reset_control_get_exclusive(&pdev->dev, "i2c"); + i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); + if (IS_ERR(i2c_dev->base)) + return PTR_ERR(i2c_dev->base); + + i2c_dev->base_phys = res->start; + + 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); + + 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; + + 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"); @@ -1730,18 +1740,13 @@ static int tegra_i2c_probe(struct platform_device *pdev) tegra_i2c_parse_dt(i2c_dev); - ret = tegra_i2c_init_clocks(i2c_dev); - if (ret) - return ret; - - i2c_dev->hw = of_device_get_match_data(&pdev->dev); - i2c_dev->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); + err = tegra_i2c_init_clocks(i2c_dev); + if (err) + return err; - platform_set_drvdata(pdev, i2c_dev); + err = tegra_i2c_init_dma(i2c_dev); + if (err) + goto release_clocks; /* * VI I2C is in VE power domain which is not always on and not @@ -1751,60 +1756,56 @@ static int tegra_i2c_probe(struct platform_device *pdev) * not be used for atomic transfers. */ if (!i2c_dev->is_vi) - pm_runtime_irq_safe(&pdev->dev); - pm_runtime_enable(&pdev->dev); - ret = pm_runtime_get_sync(i2c_dev->dev); - if (ret < 0) { - dev_err(dev, "runtime resume failed\n"); - goto put_rpm; - } + pm_runtime_irq_safe(i2c_dev->dev); - if (i2c_dev->hw->supports_bus_clear) - i2c_dev->adapter.bus_recovery_info = &tegra_i2c_recovery_info; + pm_runtime_enable(i2c_dev->dev); - ret = tegra_i2c_init_dma(i2c_dev); - if (ret < 0) + err = pm_runtime_get_sync(i2c_dev->dev); + if (err < 0) { + dev_err(i2c_dev->dev, "runtime resume failed: %d\n", err); goto put_rpm; - - ret = tegra_i2c_init(i2c_dev); - if (ret) { - dev_err(&pdev->dev, "Failed to initialize i2c controller\n"); - goto release_dma; } - irq_set_status_flags(i2c_dev->irq, IRQ_NOAUTOEN); - - ret = devm_request_irq(&pdev->dev, i2c_dev->irq, tegra_i2c_isr, - IRQF_NO_SUSPEND, dev_name(&pdev->dev), i2c_dev); - if (ret) - goto release_dma; + /* initialize hardware state */ + err = tegra_i2c_init(i2c_dev); + if (err) + goto put_rpm; - i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); + i2c_dev->adapter.dev.of_node = i2c_dev->dev->of_node; + i2c_dev->adapter.dev.parent = i2c_dev->dev; + i2c_dev->adapter.retries = 1; + i2c_dev->adapter.timeout = 6 * HZ; + i2c_dev->adapter.quirks = i2c_dev->hw->quirks; 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 put_rpm; - return 0; + pm_runtime_put(i2c_dev->dev); -release_dma: - tegra_i2c_release_dma(i2c_dev); + return 0; put_rpm: - pm_runtime_put_sync(&pdev->dev); - pm_runtime_disable(&pdev->dev); + pm_runtime_put(i2c_dev->dev); + pm_runtime_disable(i2c_dev->dev); + + tegra_i2c_release_dma(i2c_dev); +release_clocks: tegra_i2c_release_clocks(i2c_dev); - return ret; + return err; } static int tegra_i2c_remove(struct platform_device *pdev) From patchwork Tue Sep 8 02:10:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=XXPY1nb/; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpdq29Tgz9sR4 for ; Tue, 8 Sep 2020 12:15:27 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729010AbgIHCP0 (ORCPT ); Mon, 7 Sep 2020 22:15:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728305AbgIHCMA (ORCPT ); Mon, 7 Sep 2020 22:12:00 -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 03D4EC061756; Mon, 7 Sep 2020 19:11:51 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id c2so17973363ljj.12; Mon, 07 Sep 2020 19:11:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nnCEXogDxtK7hntlv9V/OnoOYZ3tQL0WnuA892WUn2E=; b=XXPY1nb/YzMDEPH88wBqjwnc8Lx90+vYwkcikpRo7f51G72fpUjQV2ZjbZiFfvAigz b4lnxzpdKBwFfZ/K7nX6Tts99XtrKTUg8KtKUAA7XmVurpp8rgXXrG/gwkVhm4Q2EiCQ 87jnDhPbjp9/Q2vgpOZ3NdrpspDJi2XXocvXs3t79s/pXrHIP1F9H02g7QUccMCzqBj1 kz32VtXYbDswBv6pKdFM5k33OY1/4A2Uuw7ejHRjTCe/OkDQMma9Y0lGq7Xfj4jYOzUp 53c58dX6Auur/qsz3ZMp/D5C4jeIroh16AVe8M1SF6zmfMBQMWZlUtQM0FmMMCvHRWaT Vm8w== 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=nnCEXogDxtK7hntlv9V/OnoOYZ3tQL0WnuA892WUn2E=; b=ZSCRs1O5Nyw78zGLgGMkHrTREV6UmWNoVgH0PQS10nOY9iXqLP+cWnttbJhDVo6oYi Icvg7RHYaHt7d6N64P4PGoLKv2IHuofTqqUEXAQvDWC5iT9lE6fa+Zi9wn8Ilzp4UQ8C F5XbRjGe7l3NjFxwKwe95bDChd7M+jTWZ22c6RjwVu+WHLE78I3XPFG4FSvcnVSh9XYh sU7L7tbFe1/FzpJUW/v8CcX+E2Z6OFxphZOOFuucmvjhNkndIN2PHd4vUiKilRzXF4KO IOn2rYtmVfh22OyA+3gL/Fa2NdUukBrnNkMeTdZfFeUBDos1VTUU8Cn35JT2NC6PYK3z mYJQ== X-Gm-Message-State: AOAM5331JnoalHbfRtuhNyEzl5PFxxU7lSdYuPbX2U3Rhc9V6cwNWoJU D2jGx/IMorkkHjKUoU402OU= X-Google-Smtp-Source: ABdhPJwayapKA0enyxcQDqxpj9flYu8iQAbzeP1/WSJOBQfD5bs+mZSC0uECelLUW/nCqWY3+lAd9A== X-Received: by 2002:a05:651c:124b:: with SMTP id h11mr12241468ljh.172.1599531109504; Mon, 07 Sep 2020 19:11:49 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:48 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 15/35] i2c: tegra: Clean up variable types Date: Tue, 8 Sep 2020 05:10:01 +0300 Message-Id: <20200908021021.9123-16-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Don't use signed types for unsigned values and use consistent types for sibling variables. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 01637e1fccde..8ab31f8100a8 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -206,20 +206,20 @@ struct tegra_i2c_hw_feature { bool has_continue_xfer_support; bool has_per_pkt_xfer_complete_irq; bool has_config_load_reg; - int clk_divisor_hs_mode; - int clk_divisor_std_mode; - int clk_divisor_fast_mode; - u16 clk_divisor_fast_plus_mode; + u32 clk_divisor_hs_mode; + u32 clk_divisor_std_mode; + u32 clk_divisor_fast_mode; + u32 clk_divisor_fast_plus_mode; bool has_multi_master_mode; bool has_slcg_override_reg; bool has_mst_fifo; const struct i2c_adapter_quirks *quirks; bool supports_bus_clear; bool has_apb_dma; - u8 tlow_std_mode; - u8 thigh_std_mode; - u8 tlow_fast_fastplus_mode; - u8 thigh_fast_fastplus_mode; + u32 tlow_std_mode; + u32 thigh_std_mode; + u32 tlow_fast_fastplus_mode; + u32 thigh_fast_fastplus_mode; u32 setup_hold_time_std_mode; u32 setup_hold_time_fast_fast_plus_mode; u32 setup_hold_time_hs_mode; @@ -267,15 +267,15 @@ struct tegra_i2c_dev { struct reset_control *rst; void __iomem *base; phys_addr_t base_phys; - int cont_id; - int irq; - int is_dvc; + unsigned int cont_id; + unsigned int irq; + bool is_dvc; bool is_vi; struct completion msg_complete; int msg_err; u8 *msg_buf; size_t msg_buf_remaining; - int msg_read; + bool msg_read; u32 bus_clk_rate; bool is_multimaster_mode; struct dma_chan *tx_dma_chan; @@ -331,13 +331,13 @@ static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) } static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data, - unsigned long reg, int len) + unsigned long reg, unsigned int len) { writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); } static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data, - unsigned long reg, int len) + unsigned long reg, unsigned int len) { readsl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); } @@ -506,10 +506,10 @@ 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; + unsigned int rx_fifo_avail; u8 *buf = i2c_dev->msg_buf; size_t buf_remaining = i2c_dev->msg_buf_remaining; - int words_to_transfer; + unsigned int words_to_transfer; /* * Catch overflow due to message fully sent @@ -567,10 +567,10 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) { u32 val; - int tx_fifo_avail; + unsigned int tx_fifo_avail; u8 *buf = i2c_dev->msg_buf; size_t buf_remaining = i2c_dev->msg_buf_remaining; - int words_to_transfer; + unsigned int words_to_transfer; if (i2c_dev->hw->has_mst_fifo) { val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); @@ -1178,7 +1178,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->msg_buf = msg->buf; i2c_dev->msg_buf_remaining = msg->len; i2c_dev->msg_err = I2C_ERR_NONE; - i2c_dev->msg_read = (msg->flags & I2C_M_RD); + i2c_dev->msg_read = !!(msg->flags & I2C_M_RD); reinit_completion(&i2c_dev->msg_complete); if (i2c_dev->msg_read) From patchwork Tue Sep 8 02:10:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359344 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=gDpYuigX; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BlpZx3klYz9sTK for ; Tue, 8 Sep 2020 12:12:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728210AbgIHCMp (ORCPT ); Mon, 7 Sep 2020 22:12:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728307AbgIHCMA (ORCPT ); Mon, 7 Sep 2020 22:12:00 -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 19D04C06179A; Mon, 7 Sep 2020 19:11:52 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id d15so7418450lfq.11; Mon, 07 Sep 2020 19:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M6ZLkoHlcSCDifvVCVlDKrSGw2O9flrYXIfshk6+Wt8=; b=gDpYuigXrn+iEY6E2yFlb1apV4/793dm2Wy30xgsJeH/aI6RUQOTkvXpHluNhL5GT3 4S0hnrhWG8kQtcIoOnp+aBb+33TMV0KFeKm9rud4brXZHoIsmWIsSJxK0ziqWYI0Xx0c mqKiNWsFt5agHGK+rZqlgQewiLSd/aPtNO5bMH5SFelMh3bFl1HE4JIJTfps5pvxAmhx mnQEe7eytDbGN7chBs7IieWbGCIQ+bj2wZw6mDEF8xIgohs/yxmgL0jR2+kHevZuvcDK euEOCSD8oHtC3BgxAOUynORdza7jEBzIY4bt/8zGESY2inefAu6SauhvLqyHKd0gxwJ5 WZEA== 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=M6ZLkoHlcSCDifvVCVlDKrSGw2O9flrYXIfshk6+Wt8=; b=q1n+2EY1Y4KfBqKE0K/CR/lNC9YJEoDyd1+NLzmKpOgT+D58Z98Si7kVbfLQqBodXf i6Rw4pt+L1Y6mD2T65pPLQLiQKYlLN9R02a0hZ18/mwaMnE27+CIvFRpvhWGR/ibWTBc jV9074jZikmgLb9RKWO0r7/b+xzZKp9XRBHgyFQkpyYUoYoeO2g3hrYE/Bslxwfcr8iA ltRE8bY/LKdn7C9QGyOH6WmdCHGGmnAk3mU8iK7C7FYkHYZrzV6hYV5kR3DDaYkd3KfU /Uc1ta7WhkdkhULo0QQE5A6XLrbA3ZB8B7dtGg0hX8U0kVsoFQj4so9H1kZDPxT0y83c iFQw== X-Gm-Message-State: AOAM531DAYR60VRAUun2ePCPRHCBy3pqju+ITOTLE/5VeVNcNjgzEwtd KMwdBdGX42vlFUuqFY1KlYw= X-Google-Smtp-Source: ABdhPJxDp1cNZ5FeYoQrtWsioxZFjuOqSt0XLQHApSIN3hRrFZhvh/qBkGfux7qU4EKgnBe7O2h1cg== X-Received: by 2002:a19:7d8b:: with SMTP id y133mr2575409lfc.152.1599531110419; Mon, 07 Sep 2020 19:11:50 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:49 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 16/35] i2c: tegra: Reorder location of functions in the code Date: Tue, 8 Sep 2020 05:10:02 +0300 Message-Id: <20200908021021.9123-17-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Reorder location of functions in the code in order to have definition of functions closer to the place of the invocation. This change makes easier to navigate around the code and removes the need to have a prototype for tegra_i2c_init(). Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 486 ++++++++++++++++----------------- 1 file changed, 242 insertions(+), 244 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 8ab31f8100a8..542436cb7823 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -288,8 +288,6 @@ struct tegra_i2c_dev { bool is_curr_atomic_xfer; }; -static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev); - static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned long reg) { @@ -466,6 +464,56 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) return err; } +/* + * One of the Tegra I2C blocks is inside the DVC (Digital Voltage Controller) + * block. This block is identical to the rest of the I2C blocks, except that + * it only supports master mode, it has registers moved around, and it needs + * some extra init to get it into I2C mode. The register moves are handled + * by i2c_readl and i2c_writel + */ +static void tegra_dvc_init(struct tegra_i2c_dev *i2c_dev) +{ + u32 val; + + val = dvc_readl(i2c_dev, DVC_CTRL_REG3); + val |= DVC_CTRL_REG3_SW_PROG; + val |= DVC_CTRL_REG3_I2C_DONE_INTR_EN; + dvc_writel(i2c_dev, val, DVC_CTRL_REG3); + + val = dvc_readl(i2c_dev, DVC_CTRL_REG1); + val |= DVC_CTRL_REG1_INTR_EN; + dvc_writel(i2c_dev, val, DVC_CTRL_REG1); +} + +static void tegra_i2c_vi_init(struct tegra_i2c_dev *i2c_dev) +{ + u32 value; + + value = FIELD_PREP(I2C_INTERFACE_TIMING_THIGH, 2) | + FIELD_PREP(I2C_INTERFACE_TIMING_TLOW, 4); + i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_0); + + value = FIELD_PREP(I2C_INTERFACE_TIMING_TBUF, 4) | + FIELD_PREP(I2C_INTERFACE_TIMING_TSU_STO, 7) | + FIELD_PREP(I2C_INTERFACE_TIMING_THD_STA, 4) | + FIELD_PREP(I2C_INTERFACE_TIMING_TSU_STA, 4); + i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_1); + + value = FIELD_PREP(I2C_HS_INTERFACE_TIMING_THIGH, 3) | + FIELD_PREP(I2C_HS_INTERFACE_TIMING_TLOW, 8); + i2c_writel(i2c_dev, value, I2C_HS_INTERFACE_TIMING_0); + + value = FIELD_PREP(I2C_HS_INTERFACE_TIMING_TSU_STO, 11) | + FIELD_PREP(I2C_HS_INTERFACE_TIMING_THD_STA, 11) | + FIELD_PREP(I2C_HS_INTERFACE_TIMING_TSU_STA, 11); + i2c_writel(i2c_dev, value, I2C_HS_INTERFACE_TIMING_1); + + value = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND; + i2c_writel(i2c_dev, value, I2C_BUS_CLEAR_CNFG); + + i2c_writel(i2c_dev, 0x0, I2C_TLOW_SEXT); +} + static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) { u32 mask, val, offset, reg_offset; @@ -503,198 +551,6 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) return 0; } -static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) -{ - u32 val; - unsigned int rx_fifo_avail; - u8 *buf = i2c_dev->msg_buf; - size_t buf_remaining = i2c_dev->msg_buf_remaining; - unsigned int words_to_transfer; - - /* - * Catch overflow due to message fully sent - * before the check for RX FIFO availability. - */ - if (WARN_ON_ONCE(!(i2c_dev->msg_buf_remaining))) - return -EINVAL; - - if (i2c_dev->hw->has_mst_fifo) { - val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); - rx_fifo_avail = FIELD_GET(I2C_MST_FIFO_STATUS_RX, val); - } else { - val = i2c_readl(i2c_dev, I2C_FIFO_STATUS); - rx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_RX, val); - } - - /* Rounds down to not include partial word at the end of buf */ - words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; - if (words_to_transfer > rx_fifo_avail) - words_to_transfer = rx_fifo_avail; - - i2c_readsl(i2c_dev, buf, I2C_RX_FIFO, words_to_transfer); - - buf += words_to_transfer * BYTES_PER_FIFO_WORD; - buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; - rx_fifo_avail -= words_to_transfer; - - /* - * If there is a partial word at the end of buf, handle it manually to - * prevent overwriting past the end of buf - */ - if (rx_fifo_avail > 0 && buf_remaining > 0) { - /* - * buf_remaining > 3 check not needed as rx_fifo_avail == 0 - * when (words_to_transfer was > rx_fifo_avail) earlier - * in this function. - */ - val = i2c_readl(i2c_dev, I2C_RX_FIFO); - val = cpu_to_le32(val); - memcpy(buf, &val, buf_remaining); - buf_remaining = 0; - rx_fifo_avail--; - } - - /* RX FIFO must be drained, otherwise it's an Overflow case. */ - if (WARN_ON_ONCE(rx_fifo_avail)) - return -EINVAL; - - i2c_dev->msg_buf_remaining = buf_remaining; - i2c_dev->msg_buf = buf; - - return 0; -} - -static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) -{ - u32 val; - unsigned int tx_fifo_avail; - u8 *buf = i2c_dev->msg_buf; - size_t buf_remaining = i2c_dev->msg_buf_remaining; - unsigned int words_to_transfer; - - if (i2c_dev->hw->has_mst_fifo) { - val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); - tx_fifo_avail = FIELD_GET(I2C_MST_FIFO_STATUS_TX, val); - } else { - val = i2c_readl(i2c_dev, I2C_FIFO_STATUS); - tx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_TX, val); - } - - /* Rounds down to not include partial word at the end of buf */ - words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; - - /* It's very common to have < 4 bytes, so optimize that case. */ - if (words_to_transfer) { - if (words_to_transfer > tx_fifo_avail) - words_to_transfer = tx_fifo_avail; - - /* - * Update state before writing to FIFO. If this casues us - * to finish writing all bytes (AKA buf_remaining goes to 0) we - * have a potential for an interrupt (PACKET_XFER_COMPLETE is - * not maskable). We need to make sure that the isr sees - * buf_remaining as 0 and doesn't call us back re-entrantly. - */ - buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; - tx_fifo_avail -= words_to_transfer; - i2c_dev->msg_buf_remaining = buf_remaining; - i2c_dev->msg_buf = buf + - words_to_transfer * BYTES_PER_FIFO_WORD; - barrier(); - - i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer); - - buf += words_to_transfer * BYTES_PER_FIFO_WORD; - } - - /* - * If there is a partial word at the end of buf, handle it manually to - * prevent reading past the end of buf, which could cross a page - * boundary and fault. - */ - if (tx_fifo_avail > 0 && buf_remaining > 0) { - /* - * buf_remaining > 3 check not needed as tx_fifo_avail == 0 - * when (words_to_transfer was > tx_fifo_avail) earlier - * in this function for non-zero words_to_transfer. - */ - memcpy(&val, buf, buf_remaining); - val = le32_to_cpu(val); - - /* Again update before writing to FIFO to make sure isr sees. */ - i2c_dev->msg_buf_remaining = 0; - i2c_dev->msg_buf = NULL; - barrier(); - - i2c_writel(i2c_dev, val, I2C_TX_FIFO); - } - - return 0; -} - -/* - * One of the Tegra I2C blocks is inside the DVC (Digital Voltage Controller) - * block. This block is identical to the rest of the I2C blocks, except that - * it only supports master mode, it has registers moved around, and it needs - * some extra init to get it into I2C mode. The register moves are handled - * by i2c_readl and i2c_writel - */ -static void tegra_dvc_init(struct tegra_i2c_dev *i2c_dev) -{ - u32 val; - - val = dvc_readl(i2c_dev, DVC_CTRL_REG3); - val |= DVC_CTRL_REG3_SW_PROG; - val |= DVC_CTRL_REG3_I2C_DONE_INTR_EN; - dvc_writel(i2c_dev, val, DVC_CTRL_REG3); - - val = dvc_readl(i2c_dev, DVC_CTRL_REG1); - val |= DVC_CTRL_REG1_INTR_EN; - dvc_writel(i2c_dev, val, DVC_CTRL_REG1); -} - -static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) -{ - struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); - int ret; - - ret = pinctrl_pm_select_default_state(i2c_dev->dev); - if (ret) - return ret; - - ret = clk_bulk_enable(i2c_dev->nclocks, i2c_dev->clocks); - if (ret) - return ret; - - /* - * VI I2C device is attached to VE power domain which goes through - * power ON/OFF during PM runtime resume/suspend. So, controller - * should go through reset and need to re-initialize after power - * domain ON. - */ - if (i2c_dev->is_vi) { - ret = tegra_i2c_init(i2c_dev); - if (ret) - goto disable_clocks; - } - - return 0; - -disable_clocks: - clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); - - return ret; -} - -static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev) -{ - struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); - - clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); - - return pinctrl_pm_select_idle_state(i2c_dev->dev); -} - static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) { unsigned long reg_offset; @@ -726,35 +582,6 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) return 0; } -static void tegra_i2c_vi_init(struct tegra_i2c_dev *i2c_dev) -{ - u32 value; - - value = FIELD_PREP(I2C_INTERFACE_TIMING_THIGH, 2) | - FIELD_PREP(I2C_INTERFACE_TIMING_TLOW, 4); - i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_0); - - value = FIELD_PREP(I2C_INTERFACE_TIMING_TBUF, 4) | - FIELD_PREP(I2C_INTERFACE_TIMING_TSU_STO, 7) | - FIELD_PREP(I2C_INTERFACE_TIMING_THD_STA, 4) | - FIELD_PREP(I2C_INTERFACE_TIMING_TSU_STA, 4); - i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_1); - - value = FIELD_PREP(I2C_HS_INTERFACE_TIMING_THIGH, 3) | - FIELD_PREP(I2C_HS_INTERFACE_TIMING_TLOW, 8); - i2c_writel(i2c_dev, value, I2C_HS_INTERFACE_TIMING_0); - - value = FIELD_PREP(I2C_HS_INTERFACE_TIMING_TSU_STO, 11) | - FIELD_PREP(I2C_HS_INTERFACE_TIMING_THD_STA, 11) | - FIELD_PREP(I2C_HS_INTERFACE_TIMING_TSU_STA, 11); - i2c_writel(i2c_dev, value, I2C_HS_INTERFACE_TIMING_1); - - value = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND; - i2c_writel(i2c_dev, value, I2C_BUS_CLEAR_CNFG); - - i2c_writel(i2c_dev, 0x0, I2C_TLOW_SEXT); -} - static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) { u32 val; @@ -882,6 +709,135 @@ static int tegra_i2c_disable_packet_mode(struct tegra_i2c_dev *i2c_dev) return tegra_i2c_wait_for_config_load(i2c_dev); } +static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) +{ + u32 val; + unsigned int rx_fifo_avail; + u8 *buf = i2c_dev->msg_buf; + size_t buf_remaining = i2c_dev->msg_buf_remaining; + unsigned int words_to_transfer; + + /* + * Catch overflow due to message fully sent + * before the check for RX FIFO availability. + */ + if (WARN_ON_ONCE(!(i2c_dev->msg_buf_remaining))) + return -EINVAL; + + if (i2c_dev->hw->has_mst_fifo) { + val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); + rx_fifo_avail = FIELD_GET(I2C_MST_FIFO_STATUS_RX, val); + } else { + val = i2c_readl(i2c_dev, I2C_FIFO_STATUS); + rx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_RX, val); + } + + /* Rounds down to not include partial word at the end of buf */ + words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; + if (words_to_transfer > rx_fifo_avail) + words_to_transfer = rx_fifo_avail; + + i2c_readsl(i2c_dev, buf, I2C_RX_FIFO, words_to_transfer); + + buf += words_to_transfer * BYTES_PER_FIFO_WORD; + buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; + rx_fifo_avail -= words_to_transfer; + + /* + * If there is a partial word at the end of buf, handle it manually to + * prevent overwriting past the end of buf + */ + if (rx_fifo_avail > 0 && buf_remaining > 0) { + /* + * buf_remaining > 3 check not needed as rx_fifo_avail == 0 + * when (words_to_transfer was > rx_fifo_avail) earlier + * in this function. + */ + val = i2c_readl(i2c_dev, I2C_RX_FIFO); + val = cpu_to_le32(val); + memcpy(buf, &val, buf_remaining); + buf_remaining = 0; + rx_fifo_avail--; + } + + /* RX FIFO must be drained, otherwise it's an Overflow case. */ + if (WARN_ON_ONCE(rx_fifo_avail)) + return -EINVAL; + + i2c_dev->msg_buf_remaining = buf_remaining; + i2c_dev->msg_buf = buf; + + return 0; +} + +static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) +{ + u32 val; + unsigned int tx_fifo_avail; + u8 *buf = i2c_dev->msg_buf; + size_t buf_remaining = i2c_dev->msg_buf_remaining; + unsigned int words_to_transfer; + + if (i2c_dev->hw->has_mst_fifo) { + val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); + tx_fifo_avail = FIELD_GET(I2C_MST_FIFO_STATUS_TX, val); + } else { + val = i2c_readl(i2c_dev, I2C_FIFO_STATUS); + tx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_TX, val); + } + + /* Rounds down to not include partial word at the end of buf */ + words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; + + /* It's very common to have < 4 bytes, so optimize that case. */ + if (words_to_transfer) { + if (words_to_transfer > tx_fifo_avail) + words_to_transfer = tx_fifo_avail; + + /* + * Update state before writing to FIFO. If this casues us + * to finish writing all bytes (AKA buf_remaining goes to 0) we + * have a potential for an interrupt (PACKET_XFER_COMPLETE is + * not maskable). We need to make sure that the isr sees + * buf_remaining as 0 and doesn't call us back re-entrantly. + */ + buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; + tx_fifo_avail -= words_to_transfer; + i2c_dev->msg_buf_remaining = buf_remaining; + i2c_dev->msg_buf = buf + + words_to_transfer * BYTES_PER_FIFO_WORD; + barrier(); + + i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer); + + buf += words_to_transfer * BYTES_PER_FIFO_WORD; + } + + /* + * If there is a partial word at the end of buf, handle it manually to + * prevent reading past the end of buf, which could cross a page + * boundary and fault. + */ + if (tx_fifo_avail > 0 && buf_remaining > 0) { + /* + * buf_remaining > 3 check not needed as tx_fifo_avail == 0 + * when (words_to_transfer was > tx_fifo_avail) earlier + * in this function for non-zero words_to_transfer. + */ + memcpy(&val, buf, buf_remaining); + val = le32_to_cpu(val); + + /* Again update before writing to FIFO to make sure isr sees. */ + i2c_dev->msg_buf_remaining = 0; + i2c_dev->msg_buf = NULL; + barrier(); + + i2c_writel(i2c_dev, val, I2C_TX_FIFO); + } + + return 0; +} + static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) { u32 status; @@ -1418,27 +1374,6 @@ static u32 tegra_i2c_func(struct i2c_adapter *adap) return ret; } -static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) -{ - struct device_node *np = i2c_dev->dev->of_node; - int ret; - bool multi_mode; - - ret = of_property_read_u32(np, "clock-frequency", - &i2c_dev->bus_clk_rate); - if (ret) - i2c_dev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */ - - multi_mode = of_property_read_bool(np, "multi-master"); - i2c_dev->is_multimaster_mode = multi_mode; - - if (of_device_is_compatible(np, "nvidia,tegra20-i2c-dvc")) - i2c_dev->is_dvc = true; - - if (of_device_is_compatible(np, "nvidia,tegra210-i2c-vi")) - i2c_dev->is_vi = true; -} - static const struct i2c_algorithm tegra_i2c_algo = { .master_xfer = tegra_i2c_xfer, .master_xfer_atomic = tegra_i2c_xfer_atomic, @@ -1644,6 +1579,27 @@ static const struct of_device_id tegra_i2c_of_match[] = { }; MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); +static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) +{ + struct device_node *np = i2c_dev->dev->of_node; + int ret; + bool multi_mode; + + ret = of_property_read_u32(np, "clock-frequency", + &i2c_dev->bus_clk_rate); + if (ret) + i2c_dev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */ + + multi_mode = of_property_read_bool(np, "multi-master"); + i2c_dev->is_multimaster_mode = multi_mode; + + if (of_device_is_compatible(np, "nvidia,tegra20-i2c-dvc")) + i2c_dev->is_dvc = true; + + if (of_device_is_compatible(np, "nvidia,tegra210-i2c-vi")) + i2c_dev->is_vi = true; +} + static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev) { unsigned int i; @@ -1821,6 +1777,48 @@ static int tegra_i2c_remove(struct platform_device *pdev) return 0; } +static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) +{ + struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); + int ret; + + ret = pinctrl_pm_select_default_state(i2c_dev->dev); + if (ret) + return ret; + + ret = clk_bulk_enable(i2c_dev->nclocks, i2c_dev->clocks); + if (ret) + return ret; + + /* + * VI I2C device is attached to VE power domain which goes through + * power ON/OFF during PM runtime resume/suspend. So, controller + * should go through reset and need to re-initialize after power + * domain ON. + */ + if (i2c_dev->is_vi) { + ret = tegra_i2c_init(i2c_dev); + if (ret) + goto disable_clocks; + } + + return 0; + +disable_clocks: + clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); + + return ret; +} + +static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev) +{ + struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); + + clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); + + return pinctrl_pm_select_idle_state(i2c_dev->dev); +} + static int __maybe_unused tegra_i2c_suspend(struct device *dev) { struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); From patchwork Tue Sep 8 02:10:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=F4UHz9Yu; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpd013k7z9sTK for ; Tue, 8 Sep 2020 12:14:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728893AbgIHCOl (ORCPT ); Mon, 7 Sep 2020 22:14:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728317AbgIHCMA (ORCPT ); Mon, 7 Sep 2020 22:12:00 -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 BE0C8C06179B; Mon, 7 Sep 2020 19:11:52 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id k25so5443725ljk.0; Mon, 07 Sep 2020 19:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0/NnRDH2LzHZtHYBLKcTqzIuFvCSK+MGSMEdMNw6Vd0=; b=F4UHz9YufeNsgNIZM5zZWVtIsnbC/wQroXA08ZVOmJnCfhCtxcBpTwH4ipSdIt5D6W 9QHMbYibFkiN1732pYbvrl1XuEoY9NeRTACGybj8vzjpH1UPGu1vfDmVh9bCdoGWrH9s EZyU6J9wM9rRAeDorjvqTchN/8thqg/473Jrd54CvBvP1FzBIMIj/YzkaiT5EeYrkKF7 XVgFGa1ReInEFWlZzuhJP/alDc3xuZeAT/HY3v/r8Wgtz0OGfZD7xImCtKc7koym3WoO aXC7E4OZUf35CEpgifjzUariciayuFsy4u8Djj7G7WpO5RwoWiW9xxE7yULEKTJKmtB9 KD+g== 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=0/NnRDH2LzHZtHYBLKcTqzIuFvCSK+MGSMEdMNw6Vd0=; b=mInAX16dw/Kg+z29MbRxwwMe6C98flMxsNPVpeBem7bvzCrmYRou0TRb3cPG9wB66u c/h1dW03jmTmkXdlVtp7bSVF9JHzNQW9+gkaeSoHB3KHxtJN2R6lv4yZlC1/G4OBR0+A YMKxKxigq6c0FsYUA4KBV4QFDONIwf2XcLaJWRBSLfIgh5oxNiXWdvs070bZQJHtNMxz kMC6kyxXA26R1OB0/Ip5y1uPTQQHkKi0R1pzDZfo7HzLKgMHD9L+6Eavokl+ZhfJf0jT 1zqwJSLAJeF31m391n1SfDFDQrLKQqPduPqsVAJCCjIigyhXzBL8mgBXeUeb+Jyl9h2P xIEw== X-Gm-Message-State: AOAM532Uu0uhpKJpQt6OCC4/SEiF6IpZaGJ9mg7S/Dy0xj8LxUry4DHp cgkvIezfjJSlXelYRCW+Lmw= X-Google-Smtp-Source: ABdhPJwjb54BtcpgW7PspIyMAVq41mNQvz3+yVewoLGPs3L4TublroMk788MJgMSgtyz/s3+KvVjvw== X-Received: by 2002:a2e:92cd:: with SMTP id k13mr11960861ljh.441.1599531111250; Mon, 07 Sep 2020 19:11:51 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:50 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 17/35] i2c: tegra: Remove likely/unlikely from the code Date: Tue, 8 Sep 2020 05:10:03 +0300 Message-Id: <20200908021021.9123-18-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The likely/unlikely annotations should be used only in a hot paths of performance-critical code. The I2C driver doesn't have such paths, and thus, there is no justification for usage of likely/unlikely annotations in the code. Hence remove them. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 542436cb7823..29e096422b95 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -855,7 +855,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) goto err; } - if (unlikely(status & status_err)) { + if (status & status_err) { tegra_i2c_disable_packet_mode(i2c_dev); if (status & I2C_INT_NO_ACK) i2c_dev->msg_err |= I2C_ERR_NO_ACK; @@ -1297,7 +1297,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->msg_err); i2c_dev->is_curr_dma_xfer = false; - if (likely(i2c_dev->msg_err == I2C_ERR_NONE)) + if (i2c_dev->msg_err == I2C_ERR_NONE) return 0; tegra_i2c_init(i2c_dev); From patchwork Tue Sep 8 02:10:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359378 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=QRYnJvB2; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpdp5SHyz9sTK for ; Tue, 8 Sep 2020 12:15:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728995AbgIHCP0 (ORCPT ); Mon, 7 Sep 2020 22:15:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728318AbgIHCMA (ORCPT ); Mon, 7 Sep 2020 22:12:00 -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 9AABFC06179E; Mon, 7 Sep 2020 19:11:53 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id k25so5443756ljk.0; Mon, 07 Sep 2020 19:11:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZD78APQi2tl+Q5v9LPhVtkKJ+nkgMadC4O/adVR437Y=; b=QRYnJvB2Xk4lEuxhbrvoRgLEa8EJBATNxek0RSWfb4bvuk4aSpU2P3l2ouyHTA8Oxt SLn9rT5W86DbaVMwOOjilIMKT8LvaSw21PK527ZVCYdSf3bnBf7GA+DNZlyxQK5zrkQe U3BrMkrRfWkUvHmyl3Iq4uJEXTVeKTTUVzB2XRCVflh3yHcYMDOQy9tiF4ernZMojBKu +PxLoSo3cDwqu/m6CQXgsq3lRlZ3qTL9Dol5yo04Esqlii9fnGq+eGmpRDtnJ6VdtcwF n87TtCFRihXHnKZZDFay7rOFRfTwOW9B5FVty8o21MBTfla0+J/Ht4vMj4rUS+kQ12cz EXug== 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=ZD78APQi2tl+Q5v9LPhVtkKJ+nkgMadC4O/adVR437Y=; b=RxYb/PnCPKvce3VSQM358O8lmwWlb2d4U9VZnwSVJS7iE77FR28OaP3neXcdh4qz1J OX3hjVFEUAJ9YJEvqFwvDh9rAfvXMvSqaNzQWLIvC8L6WqnGM0RU6Cq87+51Wsugemog DXXgCTkB/EbpUuH4iQQ869zZYjN+b2kmERETsjinKcu3ucfyP6PClaOgFmyZUrC1a6qc Na6uFNQpICzQQvWD8tZKuJ5t2No69Tz9hkDc5aTfWFPyDseBMbql17LuO91NfcBJRx4V +CZyeLA7OMAH0WH2f8DtyHJlK67sJ04xPQ7yxfj5UmtS0YTLcXROiUVpud5N587Jc4U7 Stcw== X-Gm-Message-State: AOAM530bn4DwMfzbnuag96ouASU1fQ8UmqCAQtfZoYMhl4hYEI8gOpYH 3KRT0P+42DHXa5nshNyH2YA= X-Google-Smtp-Source: ABdhPJwB8Q7wMPq+S95EwPVyJUWL+R8o/AXZZuONJzAtJ9YGW8K0CwX9XZvy62lUvkjqFE5Zi62akw== X-Received: by 2002:a2e:8904:: with SMTP id d4mr12454862lji.322.1599531112122; Mon, 07 Sep 2020 19:11: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 j12sm9070085lfj.5.2020.09.07.19.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:51 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 18/35] i2c: tegra: Remove outdated barrier() Date: Tue, 8 Sep 2020 05:10:04 +0300 Message-Id: <20200908021021.9123-19-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The barrier() was intended to reduce possibility of racing with the interrupt handler, but driver's code evolved significantly and today's driver enables interrupt only when it waits for completion notification. Hence barrier() has no good use anymore, let's remove it. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 29e096422b95..2393f52fc584 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -795,18 +795,17 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) words_to_transfer = tx_fifo_avail; /* - * Update state before writing to FIFO. If this casues us - * to finish writing all bytes (AKA buf_remaining goes to 0) we - * have a potential for an interrupt (PACKET_XFER_COMPLETE is - * not maskable). We need to make sure that the isr sees - * buf_remaining as 0 and doesn't call us back re-entrantly. + * Update state before writing to FIFO. Note that this may + * cause us to finish writing all bytes (AKA buf_remaining + * goes to 0), hence we have a potential for an interrupt + * (PACKET_XFER_COMPLETE is not maskable), but GIC interrupt + * is disabled at this point. */ buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; tx_fifo_avail -= words_to_transfer; i2c_dev->msg_buf_remaining = buf_remaining; i2c_dev->msg_buf = buf + words_to_transfer * BYTES_PER_FIFO_WORD; - barrier(); i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer); @@ -827,10 +826,8 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) memcpy(&val, buf, buf_remaining); val = le32_to_cpu(val); - /* Again update before writing to FIFO to make sure isr sees. */ i2c_dev->msg_buf_remaining = 0; i2c_dev->msg_buf = NULL; - barrier(); i2c_writel(i2c_dev, val, I2C_TX_FIFO); } From patchwork Tue Sep 8 02:10:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=tyKhR3OT; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpdp1PRqz9sR4 for ; Tue, 8 Sep 2020 12:15:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728185AbgIHCPX (ORCPT ); Mon, 7 Sep 2020 22:15:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728324AbgIHCMA (ORCPT ); Mon, 7 Sep 2020 22:12:00 -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 7963AC06179F; Mon, 7 Sep 2020 19:11:54 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id s205so18039122lja.7; Mon, 07 Sep 2020 19:11: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=ssXvtmU8WdM4pL4rp/dgR6uSS2Fq2XHwxYSCuPbIYk0=; b=tyKhR3OTV1qz9wjOI40GJJjPDMk7mw338EgTN1MgP/oT1/0yDuBBTWFsgy4FGLnhqD nyUmHYc3QgcUahravEB/ndZ2Z/NNs+g7gcu8e4FJOBqVs6OwTxprL6Ka9dTSaqAf4HLy Mul8PK+Yo943WiHP9IpIUlNqHUKlfdZDu9EHJfBJTxqXLfEH7Q54H+lB6HpiIts9ma8C hpCLyjn8Zbm9JYllguxvBOMT186w/mt3YiQmjnEz53p/oHBmC+IvdLuheF5Bpjvb0OAC fsLt4p0DXeRcKIbJFkjcNqHdls1arsO4NJWXA8C1cEKDLQHOqeYvP9jAy+tg6G+xquX2 +vYg== 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=ssXvtmU8WdM4pL4rp/dgR6uSS2Fq2XHwxYSCuPbIYk0=; b=PgQXcy1aP8n9g3mDFOKcEC76uKj9Jh0tpdcw+3EJfXQgGuoLU5tRp8jckIDqqDXvLy grb6icKJVGBKwwuGs6Q01Sactz9Nfrbqd1irr7jvxjqO7OzChs/Ewd90nTToxTkiTxzA IlqHI03BDttv0LD2xXMu6dNgWeY0j1dl+/y1o8R3L+uE8V+6w7n8dER/9MpMolQdFzfN 7dK7xbtK/gAagOtQJMdZZbo2fCUtw+omOq9j/eBR/cK4SLfpTwweMfbwjohsu9DxwYXw acnyaXWC2emi6G3K/30eZ8XExdOXc0l15I5YJ7zlL9vbucL7WChlsWCOlsXDjtBYjDw+ MO+Q== X-Gm-Message-State: AOAM532caR93oL/5n6QaV3c/gesGqF5N6PsplBVWGTbgt2mY1yz8CrFe gqSBto68/Sh4FIDAeI9NzeYCRocMjO4= X-Google-Smtp-Source: ABdhPJzUue1PWgb38U/8GIweq/QAWNJBnHxQG60y5Dj7MTGmURo6LOJgX1aAbVlcvovKPwK0e8TXwA== X-Received: by 2002:a2e:98cf:: with SMTP id s15mr12646456ljj.446.1599531112986; Mon, 07 Sep 2020 19:11: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 j12sm9070085lfj.5.2020.09.07.19.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11: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 v6 19/35] i2c: tegra: Remove redundant check in tegra_i2c_issue_bus_clear() Date: Tue, 8 Sep 2020 05:10:05 +0300 Message-Id: <20200908021021.9123-20-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The tegra_i2c_wait_for_config_load() checks for 'has_config_load_reg' by itself, hence there is no need to duplicate the check. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 2393f52fc584..4e8514696b0c 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1082,11 +1082,10 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) reg = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND | I2C_BC_TERMINATE; i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); - if (i2c_dev->hw->has_config_load_reg) { - err = tegra_i2c_wait_for_config_load(i2c_dev); - if (err) - return err; - } + + err = tegra_i2c_wait_for_config_load(i2c_dev); + if (err) + return err; reg |= I2C_BC_ENABLE; i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); From patchwork Tue Sep 8 02:10:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359387 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=p3D4215j; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BlpfL1sflz9sTX for ; Tue, 8 Sep 2020 12:15:54 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728529AbgIHCPY (ORCPT ); Mon, 7 Sep 2020 22:15:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728326AbgIHCMA (ORCPT ); Mon, 7 Sep 2020 22:12:00 -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 556A6C0617A0; Mon, 7 Sep 2020 19:11:55 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id t23so18046246ljc.3; Mon, 07 Sep 2020 19:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5uWg/frcUGv1irMtVYv3F8vtSyCUVHwjLNZ6tfcNU5A=; b=p3D4215jRG/tdfVSF9+1z7MKU38MUW5Qr/3WVuAazJwjltPg3lKB0mubI7m/07TEGI Rm2KEZBxxg+4kFr8OjFAsRv37PwJM6G7sCXVX04S3v27qD1BsgyU3ZK/aIZuxzl0fplp +I4bu78WIn/ug6WyKbyfKLNQu8jE6QWqlv0XLmNhL7fNuEoPHbDs9NEWkqLZFg9Ns6JR 8CiRWUJUAF3pAQM57HlTqBahZ7aKMLF+uSWsRPmvxAKJSAhTZunTPQQBejbtYVZ/EifU rTCV8OoWXrAwzP+xYwRuQqewMfDpZ8TeCJfyIn5LoWMgeiSgZFMcF7p94VRv4iDiH+Bk hhSw== 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=5uWg/frcUGv1irMtVYv3F8vtSyCUVHwjLNZ6tfcNU5A=; b=j8bJO1nbD4WmNUbn3u6Wd/0cdYH9zyStP8+y/aBwsh650kI7Ut/GVQCiwXdx+hAG6H s/smau9dflLC4nNlZFKLhIbYwTtqaAeqZ2tn+Ns46/J+tKT72T2X+ZRjGeScdaE3fANs dXm1z8AdMDaxDbzaWu3beIENSM5cxDabXsLlCwGGuqVaFkR9ktb59lHR1WYDAesqCelA yT1M2XPwCjWS3O3WnAuDDXE4X71OuhPLTNpNSy95H8pK4+6GMMSxfTqI/vmt9iraV8r3 WmMNI5AVjH13XDbuBOrFnQbH/UiiAVic1DpwuDuK9k1YTJd6webuCx4k5Zhi1+/IbJRm dweA== X-Gm-Message-State: AOAM533/7H8v4LmvmKSvEueZ3WCxdlwIVlmmMe38jglUVm6GzxOud/fr SvedOlWhzjqPGQwXD7yvkJk= X-Google-Smtp-Source: ABdhPJxAZtjsFzHZ4LtBzLFh11fd2Mzv3GVSw9yDE+gA8B2XoSQ3dgwHGwpdR8Qo2/QISOW+zPqLPw== X-Received: by 2002:a2e:97d3:: with SMTP id m19mr1692959ljj.296.1599531113819; Mon, 07 Sep 2020 19:11:53 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:53 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 20/35] i2c: tegra: Remove "dma" variable from tegra_i2c_xfer_msg() Date: Tue, 8 Sep 2020 05:10:06 +0300 Message-Id: <20200908021021.9123-21-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The "dma" variable of tegra_i2c_xfer_msg() function doesn't bring much in regards to readability and generation of the code. Besides readability, it's also not very nice that the is_curr_dma_xfer is initialized in tegra_i2c_xfer_msg() and then could be overridden by tegra_i2c_config_fifo_trig(). In a result, the "dma" variable creates slight confusion since it's not instantly obvious why it's set after tegra_i2c_config_fifo_trig(). Hence should be better to have the variable removed. This makes code more consistent. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 4e8514696b0c..e94da14d36e2 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1120,7 +1120,6 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, size_t xfer_size; u32 *buffer = NULL; int err = 0; - bool dma; u16 xfer_time = 100; err = tegra_i2c_flush_fifos(i2c_dev); @@ -1143,7 +1142,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->dma_buf && !i2c_dev->is_curr_atomic_xfer; tegra_i2c_config_fifo_trig(i2c_dev, xfer_size); - dma = i2c_dev->is_curr_dma_xfer; + /* * Transfer time in mSec = Total bits / transfer rate * Total bits = 9 bits per byte (including ACK bit) + Start & stop bits @@ -1153,7 +1152,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; tegra_i2c_unmask_irq(i2c_dev, int_mask); - if (dma) { + if (i2c_dev->is_curr_dma_xfer) { if (i2c_dev->msg_read) { dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, @@ -1181,13 +1180,13 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, PACKET_HEADER0_PROTOCOL_I2C) | FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) | FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1); - if (dma && !i2c_dev->msg_read) + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) *buffer++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); packet_header = msg->len - 1; - if (dma && !i2c_dev->msg_read) + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) *buffer++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); @@ -1207,13 +1206,13 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, packet_header |= I2C_HEADER_CONT_ON_NAK; if (msg->flags & I2C_M_RD) packet_header |= I2C_HEADER_READ; - if (dma && !i2c_dev->msg_read) + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) *buffer++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); if (!i2c_dev->msg_read) { - if (dma) { + if (i2c_dev->is_curr_dma_xfer) { memcpy(buffer, msg->buf, msg->len); dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, @@ -1233,7 +1232,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (i2c_dev->hw->has_per_pkt_xfer_complete_irq) int_mask |= I2C_INT_PACKET_XFER_COMPLETE; - if (!dma) { + if (!i2c_dev->is_curr_dma_xfer) { if (msg->flags & I2C_M_RD) int_mask |= I2C_INT_RX_FIFO_DATA_REQ; else if (i2c_dev->msg_buf_remaining) @@ -1244,7 +1243,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, dev_dbg(i2c_dev->dev, "unmasked irq: %02x\n", i2c_readl(i2c_dev, I2C_INT_MASK)); - if (dma) { + if (i2c_dev->is_curr_dma_xfer) { time_left = tegra_i2c_wait_completion_timeout( i2c_dev, &i2c_dev->dma_complete, xfer_time); From patchwork Tue Sep 8 02:10:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=SXIC3Q8S; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpcz3ss6z9sTd for ; Tue, 8 Sep 2020 12:14:43 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728886AbgIHCOl (ORCPT ); Mon, 7 Sep 2020 22:14:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728328AbgIHCMD (ORCPT ); Mon, 7 Sep 2020 22:12: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 36AE9C0617A1; Mon, 7 Sep 2020 19:11:56 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id n25so7106387ljj.4; Mon, 07 Sep 2020 19:11: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=Lxvjtf4dYiAKvgZL7eYwyWdc5H5QauMaAbRRwLy755M=; b=SXIC3Q8SrWUGUeRnAFdu5qYHteMzhNsaoneeeTW6BzfdTaLgKwfRYFtd54IFuDdeki hsgRr4CiEgPwBTb7V1DQgH4etiA2repiRFPY5kz9yH8PSdeFpDzqguwBF3Dr0KS67vKo RbM3Pb4/WUGRCf9cmSqJjnSPpFBu/MV90h3US9j+yX8ZtTdy9TI7VSGFLSE/XvgLIGdA h78sO84zdAJX36lUyA72g31DiMEx/J4KZ8lUM9mWXQWYAX0O1fpWNmRfnzmA7IjW5XQf hkZz7ITkURMfbTdXG5sn7YtsEc6aCf2a/YFzs0/rs/C9hSDkfAAVOCjD4OK8FI7V3foM YpcA== 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=Lxvjtf4dYiAKvgZL7eYwyWdc5H5QauMaAbRRwLy755M=; b=I54f5dhRg5ESHWm8Av65sxe9TGX99Pasc6ia8aYcEAjDXF+LH5m3nRJ/ay82GG2xSh Lg53kZP7btSrxVXCrlQ017tSAVd5OWwjNAdnspgBX9Wz8duqwdvDtOe2720knTFzASf5 kov53p83XPcGgCJ0x8ujJL88wbNnPmTIqTEpnS4CP1ORQc6hzEUxMkHUPBl6Vn5Sq0JE Ncb4YZ8MuMLQ57gYnsj8skWioZp+ruKnrSgkccRU0ePl0TuFXN4BQBRfvrquvolaaFaI 35xVtly+moSCYc5XPMEJSTMNze0bn8WuXUoX7xDQsKreEIca2gHKGS5hUgNMt1J4K2SR CBmA== X-Gm-Message-State: AOAM531EwLyIBv+2PgV3MRVDxRZaWtLniXtCi9LmjDbJXrjw0IbS2GEu e8wpafRchPSKnBuDy7yjXPk= X-Google-Smtp-Source: ABdhPJysiWP28b7t6ydytix6g/oK2T8yL2PpXxcryP+HVlaolLiMbkUYyCwNZykLDQZqU8E1ZOBtIQ== X-Received: by 2002:a2e:a304:: with SMTP id l4mr11810448lje.35.1599531114697; Mon, 07 Sep 2020 19:11: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 j12sm9070085lfj.5.2020.09.07.19.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11: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 v6 21/35] i2c: tegra: Don't fall back to PIO mode if DMA configuration fails Date: Tue, 8 Sep 2020 05:10:07 +0300 Message-Id: <20200908021021.9123-22-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The DMA code path has been tested well enough and the DMA configuration performed by tegra_i2c_config_fifo_trig() shouldn't ever fail in practice. Hence let's remove the obscure transfer-mode switching in order to have a cleaner and simpler code. Now I2C transfer will be failed if DMA configuration fails. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index e94da14d36e2..ba71b64e5e64 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -940,8 +940,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) return IRQ_HANDLED; } -static void tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, - size_t len) +static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) { u32 val, reg; u8 dma_burst; @@ -992,12 +991,10 @@ static void tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, if (ret < 0) { dev_err(i2c_dev->dev, "DMA slave config failed: %d\n", ret); - dev_err(i2c_dev->dev, "falling back to PIO\n"); - tegra_i2c_release_dma(i2c_dev); - i2c_dev->is_curr_dma_xfer = false; - } else { - goto out; + return ret; } + + goto out; } if (i2c_dev->hw->has_mst_fifo) @@ -1008,6 +1005,8 @@ static void tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, I2C_FIFO_CONTROL_RX_TRIG(1); out: i2c_writel(i2c_dev, val, reg); + + return 0; } static unsigned long @@ -1141,7 +1140,10 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->is_curr_dma_xfer = (xfer_size > I2C_PIO_MODE_PREFERRED_LEN) && i2c_dev->dma_buf && !i2c_dev->is_curr_atomic_xfer; - tegra_i2c_config_fifo_trig(i2c_dev, xfer_size); + + err = tegra_i2c_config_fifo_trig(i2c_dev, xfer_size); + if (err) + return err; /* * Transfer time in mSec = Total bits / transfer rate From patchwork Tue Sep 8 02:10:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359345 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=BRL6UYVa; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpbp5xsBz9sTK for ; Tue, 8 Sep 2020 12:13:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728414AbgIHCM5 (ORCPT ); Mon, 7 Sep 2020 22:12:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728327AbgIHCMD (ORCPT ); Mon, 7 Sep 2020 22:12: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 224C6C0617A2; Mon, 7 Sep 2020 19:11:57 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id u4so17130475ljd.10; Mon, 07 Sep 2020 19:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wa9az+ziOuvF1dsROfNY80oLmd37PjHgJIcfq+Dbcps=; b=BRL6UYVaXw0htKJGZQbwn+3TYwz1woyCR4mZXq/eYdoQ/oI70Mlgyi8ejytH2uz1qE gY+3EysaK9cbPpORB19gcAkUSjx+PALQ8Ph4NMtjSvtC6l4BkLmYPq6VEyKVWSY3LvvN TdG+s/gI1DzQ19TVOHeTRVrpdy8nNnGJ9rdaHsxR5kPgi6Z7jtfHUuUEm+q6iR6rzzoI LwiIh2Y9AkVQta7qc5tcgT/oJfb/yZ35Nxwph32gxNCB0nteVTco0z0TY2ZLZOEoYabP yQZRq4gYB5PsIey4kk2Vpqp0WZGFDjF3sDEK7sKGi82Xz9oH9YbrZpPx9bDtO2xglbsL 1GVQ== 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=Wa9az+ziOuvF1dsROfNY80oLmd37PjHgJIcfq+Dbcps=; b=lyRXMmk14tOHqXy1i0Menz0Susm8HiUh5pHxBnXehh3HAAiCE/ZDnF/Oy4Mubg2ng8 LEmtXfexXHZz1BfQ9FdaPWu0u+vZ6jWFERjy6zXIuAZLPpVsbfcwcWagRAwcMBrVhCPz qQaGy8yflqCRRmDKZTGm41DXkCztI6vVUqp9RhnY/mD7zXQpXWJ84vclzqw9G6wj+f9F vqxuujTeN+svpEZLaKPELe5fOGdU3NMuruKTK6G3W+gEuSJNzn/6mYoQKsfuKlJJNamX hvQoPxAqJ1RbQA20l7P+G1KZbcNXw9VEnVSGseVZlY7WVm/fWTdjlln1LkE8p2sT6CS8 Vjpw== X-Gm-Message-State: AOAM531gnMJaBzW6jUQgGjjUPAY/zrvdxZF00AZ061uyBEX7oeTMcwnQ nKuhSgea11YWS1MpYboixRk= X-Google-Smtp-Source: ABdhPJzUviycLv7w8LCrFEMKUG6vh3SR7jS8tpmDUEyUzJ0+kL7soRrrsSrtw94l/x4Iruscg2VbgQ== X-Received: by 2002:a05:651c:554:: with SMTP id q20mr12228879ljp.348.1599531115575; Mon, 07 Sep 2020 19:11:55 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:55 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 22/35] i2c: tegra: Improve formatting of variables Date: Tue, 8 Sep 2020 05:10:08 +0300 Message-Id: <20200908021021.9123-23-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Reorder definition of variables in the code to have them sorted by length and grouped logically, also replace "unsigned long" with "u32". Do this in order to make code easier to read. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 100 +++++++++++++++------------------ 1 file changed, 46 insertions(+), 54 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index ba71b64e5e64..be7a09041871 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -259,42 +259,48 @@ struct tegra_i2c_hw_feature { */ struct tegra_i2c_dev { struct device *dev; - const struct tegra_i2c_hw_feature *hw; struct i2c_adapter adapter; - struct clk *div_clk; - struct clk_bulk_data *clocks; - unsigned int nclocks; + + const struct tegra_i2c_hw_feature *hw; struct reset_control *rst; - void __iomem *base; - phys_addr_t base_phys; unsigned int cont_id; unsigned int irq; - bool is_dvc; - bool is_vi; + + phys_addr_t base_phys; + void __iomem *base; + + struct clk_bulk_data *clocks; + unsigned int nclocks; + + struct clk *div_clk; + u32 bus_clk_rate; + struct completion msg_complete; + size_t msg_buf_remaining; int msg_err; u8 *msg_buf; - size_t msg_buf_remaining; - bool msg_read; - u32 bus_clk_rate; - bool is_multimaster_mode; + + struct completion dma_complete; struct dma_chan *tx_dma_chan; struct dma_chan *rx_dma_chan; + unsigned int dma_buf_size; dma_addr_t dma_phys; u32 *dma_buf; - unsigned int dma_buf_size; - bool is_curr_dma_xfer; - struct completion dma_complete; + + bool is_multimaster_mode; bool is_curr_atomic_xfer; + bool is_curr_dma_xfer; + bool msg_read; + bool is_dvc; + bool is_vi; }; -static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, - unsigned long reg) +static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, u32 reg) { writel_relaxed(val, i2c_dev->base + reg); } -static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) +static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, u32 reg) { return readl_relaxed(i2c_dev->base + reg); } @@ -303,8 +309,7 @@ static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) * i2c_writel and i2c_readl will offset the register if necessary to talk * to the I2C block inside the DVC block */ -static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, - unsigned long reg) +static u32 tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, u32 reg) { if (i2c_dev->is_dvc) reg += (reg >= I2C_TX_FIFO) ? 0x10 : 0x40; @@ -313,8 +318,7 @@ static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, return reg; } -static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, - unsigned long reg) +static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, u32 reg) { writel_relaxed(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); @@ -323,19 +327,19 @@ static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); } -static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) +static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, u32 reg) { return readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); } static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data, - unsigned long reg, unsigned int len) + u32 reg, unsigned int len) { writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); } static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data, - unsigned long reg, unsigned int len) + u32 reg, unsigned int len) { readsl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); } @@ -410,8 +414,8 @@ static void tegra_i2c_release_dma(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) { struct dma_chan *chan; - u32 *dma_buf; dma_addr_t dma_phys; + u32 *dma_buf; int err; if (!i2c_dev->hw->has_apb_dma || i2c_dev->is_vi) @@ -584,12 +588,8 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) { - u32 val; + u32 val, clk_divisor, clk_multiplier, tsu_thd, tlow, thigh, non_hs_mode; int err; - u32 clk_divisor, clk_multiplier; - u32 non_hs_mode; - u32 tsu_thd; - u8 tlow, thigh; /* * The reset shouldn't ever fail in practice. The failure will be a @@ -711,11 +711,10 @@ static int tegra_i2c_disable_packet_mode(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) { - u32 val; - unsigned int rx_fifo_avail; - u8 *buf = i2c_dev->msg_buf; size_t buf_remaining = i2c_dev->msg_buf_remaining; - unsigned int words_to_transfer; + unsigned int words_to_transfer, rx_fifo_avail; + u8 *buf = i2c_dev->msg_buf; + u32 val; /* * Catch overflow due to message fully sent @@ -772,11 +771,10 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) { - u32 val; - unsigned int tx_fifo_avail; - u8 *buf = i2c_dev->msg_buf; size_t buf_remaining = i2c_dev->msg_buf_remaining; - unsigned int words_to_transfer; + unsigned int words_to_transfer, tx_fifo_avail; + u8 *buf = i2c_dev->msg_buf; + u32 val; if (i2c_dev->hw->has_mst_fifo) { val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); @@ -837,9 +835,9 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) { - u32 status; const u32 status_err = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; struct tegra_i2c_dev *i2c_dev = dev_id; + u32 status; status = i2c_readl(i2c_dev, I2C_INT_STATUS); @@ -942,12 +940,10 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) { - u32 val, reg; - u8 dma_burst; struct dma_slave_config slv_config = {0}; + u32 val, reg, dma_burst, reg_offset; struct dma_chan *chan; int ret; - unsigned long reg_offset; if (i2c_dev->hw->has_mst_fifo) reg = I2C_MST_FIFO_CONTROL; @@ -1073,9 +1069,8 @@ 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); + u32 reg, time_left; int err; - unsigned long time_left; - u32 reg; reinit_completion(&i2c_dev->msg_complete); reg = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND | @@ -1113,13 +1108,11 @@ 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; - u16 xfer_time = 100; + size_t xfer_size; + int err; err = tegra_i2c_flush_fifos(i2c_dev); if (err) @@ -1318,8 +1311,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) { @@ -1579,8 +1571,8 @@ MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) { struct device_node *np = i2c_dev->dev->of_node; - int ret; bool multi_mode; + int ret; ret = of_property_read_u32(np, "clock-frequency", &i2c_dev->bus_clk_rate); From patchwork Tue Sep 8 02:10:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359369 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=q7LQSWJo; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpcz0Qysz9sTW for ; Tue, 8 Sep 2020 12:14:43 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728874AbgIHCOk (ORCPT ); Mon, 7 Sep 2020 22:14:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728330AbgIHCMD (ORCPT ); Mon, 7 Sep 2020 22:12:03 -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 32EFCC061757; Mon, 7 Sep 2020 19:11:59 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id t23so18046322ljc.3; Mon, 07 Sep 2020 19:11: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=CH+tGayY3Xii8pDTmAx+Z65LYWNubZeJ2KNGkfprF0o=; b=q7LQSWJoPH17LhpG8Ij5kxBGv1GINCpyByNSRJS2267Vv99bG1eccilS5yxAAPHk1P cEVIarB3wZhH42itbXveTltNS7UF8EXujaixR5BA0pYUYBhseh1usZyXmwLGmUQHcA2g sfBdZ8EbTMrlZJp1MGAh2yAbDmLFap08lqpjRVJVtO82Cb5xtCF5lAjlbAPNi6rTNOGd 9M2d+kMMkAhunnDvTK0uyHaVVHh7kkcyzW8XSU//7zNcqN+VR48sB7GcApeFFdPlvOH2 3cfOoiXepbhpvOXCB8OybV3ewZzytQS0NtXXisT5bux/9PumSQXDLxXOHpySFjOwM8wZ T7ug== 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=CH+tGayY3Xii8pDTmAx+Z65LYWNubZeJ2KNGkfprF0o=; b=OZNLEV53488aZ4tMtRK1lQVdwJpXF3KnS41V22GnJZT9S0rM1LGLMkmo5c+KKEOJEd T61wD0nsRNZ8YAN92BEDfO3O2pzjNdWH7GWs9BRtAXMvAHb7M3yl9Ztk3B4mDoQJsTeF BJZOfAR0nHrPqwpQq4XPD+yqpnRDDM+4TkDI/MUk+IcM04g7KHiwj9jTt9dk2uFo/lhU yavMa1FRevNZ8l+biIglUF1+jKSnmk7EnEXvpwRtmNhjZhsdrAZJXeLhKs0pS1+W+RTJ v2mZm9rRLtSGF1GeTYF5zEZDOZ4NGZh+RNrx0AgnDk9N8WtVKVZyS+8a0CqQBEpuf6RZ G6og== X-Gm-Message-State: AOAM530Iuie91Exl1KkI3aQagQAfDzioWurPlRMnWkbK0buIRsipYIES QFAsitVaHrQY/YMhiZcbbqs= X-Google-Smtp-Source: ABdhPJwKeE4jgVr/H5XobpJ54PIi3/2IyL+WLcE37TDByo0BizuVIollVgNmlCMYEYeVUKZcfCpMlQ== X-Received: by 2002:a2e:808a:: with SMTP id i10mr12109982ljg.313.1599531116440; Mon, 07 Sep 2020 19:11: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 j12sm9070085lfj.5.2020.09.07.19.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:55 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 23/35] i2c: tegra: Improve coding style of tegra_i2c_wait_for_config_load() Date: Tue, 8 Sep 2020 05:10:09 +0300 Message-Id: <20200908021021.9123-24-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Improve coding style of the tegra_i2c_wait_for_config_load() function by removing need to wrap code in order make it more readable and to adhere to the common kernel coding style. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index be7a09041871..c16273c13291 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -562,25 +562,23 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) u32 val; int err; - if (i2c_dev->hw->has_config_load_reg) { - reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_CONFIG_LOAD); - addr = i2c_dev->base + reg_offset; - i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD); - - if (i2c_dev->is_curr_atomic_xfer) - err = readl_relaxed_poll_timeout_atomic( - addr, val, val == 0, 1000, - I2C_CONFIG_LOAD_TIMEOUT); - else - err = readl_relaxed_poll_timeout( - addr, val, val == 0, 1000, - I2C_CONFIG_LOAD_TIMEOUT); + if (!i2c_dev->hw->has_config_load_reg) + return 0; - if (err) { - dev_warn(i2c_dev->dev, - "timeout waiting for config load\n"); - return err; - } + reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_CONFIG_LOAD); + addr = i2c_dev->base + reg_offset; + i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD); + + if (i2c_dev->is_curr_atomic_xfer) + err = readl_relaxed_poll_timeout_atomic(addr, val, val == 0, 1000, + I2C_CONFIG_LOAD_TIMEOUT); + else + err = readl_relaxed_poll_timeout(addr, val, val == 0, 1000, + I2C_CONFIG_LOAD_TIMEOUT); + + if (err) { + dev_warn(i2c_dev->dev, "timeout waiting for config load\n"); + return err; } return 0; From patchwork Tue Sep 8 02:10:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359375 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=je8zVeR4; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpdl1JPCz9sTK for ; Tue, 8 Sep 2020 12:15:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728869AbgIHCOk (ORCPT ); Mon, 7 Sep 2020 22:14:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728332AbgIHCMD (ORCPT ); Mon, 7 Sep 2020 22:12: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 DB0F3C061573; Mon, 7 Sep 2020 19:11:58 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id s205so18039257lja.7; Mon, 07 Sep 2020 19:11: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=JgF3VVU7tFsmkskdQ6viyyo6sIhqDxq3DbAN2Y/3odY=; b=je8zVeR4suUOynWJWNENTG/m1KI6DvGXWoGyQ9aX68bzvcGb1r65VP4glWVyFj8+Ze RizTf7zA1XjS8Z6Kz/lwJJh7f+KQqxnoFCqYx3txqXDeK+DWo6ltwgb1blRDedOnQxX1 +dyIyWno3s7tQbQeIpE3B5Twfe66oBrCgYYEe1h0C9oXX/SruuvLB8l7sf84vRMIJzBj vbkivMI1qj2IA6LNb3Yxnz5x5Tk1iwG4cgYzOq+ePXP8oh5+x/WL2QbUoJL9myl2/tMw J/jbLCYHolVI+9qmew+cikm31UEczKpLRQOaCTANNZkLEfB4sDoWcFUWo0LbTCrM1sGj 3hQQ== 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=JgF3VVU7tFsmkskdQ6viyyo6sIhqDxq3DbAN2Y/3odY=; b=uHdUyGGvQZdHnoD6MVTA9CG7E8hrOYEh0hFsM1rQ+Tm6Zw8/utquGc1iGwsEFvFU+n HuG5cJBnbC6sBnw+iHTkbzBbKD+Gp45uI56HkB8jjo3UeitelAxtxXZHQ1LsRhnYtFpP pSN7YaZe6JBK9oT+pUUBMmiL60yKBQkTyctAKa8KtNTJFysCmVoZJxsUjKSh3hsUUiDV YefCf0xh5W7gCK7zPXMRp3qeq1J7FiKwR92Qg0LwMEzggmnFKyGRH66UliI8FIlQq4ap 93bJN/Hef00+oeey/++Vgoc8Qc5o4kaCYabXAIrnobNc1BIxvNXNc8SsX9bB2PuvYiNl Myzg== X-Gm-Message-State: AOAM5303VSdD5hnLD2Afx/B2TrWlbSgJ2zxpbEVTQ8PvzTIofunsD4o6 cHxW0iftQ6fUXkyk+K1OJds= X-Google-Smtp-Source: ABdhPJzbpCynRifLlKBdg6XyNvORmkifbjjdQQOBwESWVKNdaR50R4AigmKhp7laAx0lfOouqB4DHQ== X-Received: by 2002:a2e:9057:: with SMTP id n23mr9596269ljg.411.1599531117389; Mon, 07 Sep 2020 19:11: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 j12sm9070085lfj.5.2020.09.07.19.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11: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 v6 24/35] i2c: tegra: Rename wait/poll functions Date: Tue, 8 Sep 2020 05:10:10 +0300 Message-Id: <20200908021021.9123-25-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Drop '_timeout' postfix from the wait/poll completion function names in order to make the names shorter, making code cleaner a tad. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index c16273c13291..0d823aae9eaf 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1003,10 +1003,9 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) return 0; } -static unsigned long -tegra_i2c_poll_completion_timeout(struct tegra_i2c_dev *i2c_dev, - struct completion *complete, - unsigned int timeout_ms) +static unsigned long tegra_i2c_poll_completion(struct tegra_i2c_dev *i2c_dev, + struct completion *complete, + unsigned int timeout_ms) { ktime_t ktime = ktime_get(); ktime_t ktimeout = ktime_add_ms(ktime, timeout_ms); @@ -1030,16 +1029,14 @@ tegra_i2c_poll_completion_timeout(struct tegra_i2c_dev *i2c_dev, return 0; } -static unsigned long -tegra_i2c_wait_completion_timeout(struct tegra_i2c_dev *i2c_dev, - struct completion *complete, - unsigned int timeout_ms) +static unsigned long tegra_i2c_wait_completion(struct tegra_i2c_dev *i2c_dev, + struct completion *complete, + unsigned int timeout_ms) { unsigned long ret; if (i2c_dev->is_curr_atomic_xfer) { - ret = tegra_i2c_poll_completion_timeout(i2c_dev, complete, - timeout_ms); + ret = tegra_i2c_poll_completion(i2c_dev, complete, timeout_ms); } else { enable_irq(i2c_dev->irq); ret = wait_for_completion_timeout(complete, @@ -1057,8 +1054,7 @@ tegra_i2c_wait_completion_timeout(struct tegra_i2c_dev *i2c_dev, * needs to be checked after timeout. */ if (ret == 0) - ret = tegra_i2c_poll_completion_timeout(i2c_dev, - complete, 0); + ret = tegra_i2c_poll_completion(i2c_dev, complete, 0); } return ret; @@ -1083,8 +1079,8 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); tegra_i2c_unmask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); - time_left = tegra_i2c_wait_completion_timeout( - i2c_dev, &i2c_dev->msg_complete, 50); + time_left = tegra_i2c_wait_completion(i2c_dev, &i2c_dev->msg_complete, + 50); tegra_i2c_mask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); if (time_left == 0) { @@ -1237,8 +1233,9 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_readl(i2c_dev, I2C_INT_MASK)); if (i2c_dev->is_curr_dma_xfer) { - time_left = tegra_i2c_wait_completion_timeout( - i2c_dev, &i2c_dev->dma_complete, xfer_time); + time_left = tegra_i2c_wait_completion(i2c_dev, + &i2c_dev->dma_complete, + xfer_time); /* * Synchronize DMA first, since dmaengine_terminate_sync() @@ -1269,8 +1266,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, } } - time_left = tegra_i2c_wait_completion_timeout( - i2c_dev, &i2c_dev->msg_complete, xfer_time); + time_left = tegra_i2c_wait_completion(i2c_dev, &i2c_dev->msg_complete, + xfer_time); tegra_i2c_mask_irq(i2c_dev, int_mask); From patchwork Tue Sep 8 02:10:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359367 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=KLQnsVHR; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpcy0Qhgz9sTW for ; Tue, 8 Sep 2020 12:14:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728852AbgIHCOj (ORCPT ); Mon, 7 Sep 2020 22:14:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728338AbgIHCMD (ORCPT ); Mon, 7 Sep 2020 22:12:03 -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 AF1E6C0617A3; Mon, 7 Sep 2020 19:11:59 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id w3so18003000ljo.5; Mon, 07 Sep 2020 19:11: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=CqjfeQNlhTI+BPVPyT/fOr+xJ6iCGpnOYdb93ZFU2yk=; b=KLQnsVHROyCYPOlFK8ssWwNzuMMsbPzPfPyZRDHT6kE1mRHQsHWbFrwgcn4F7P0HSX h45HtJQZfgbc5ZRbs2yMdGabpeOLxjDKtWG+C/Jy6ILrbwPqRRV/0pesA2sH0v0c7PG7 texli1RV4HcYtWGLNkSPJlpT8UmdyTNfvUs6G0Sl9WUiEpENn4v80+cNh7VQO/XloR9y QDrG96KbqZ+JWzeTnJJ+PKsclpI4GkrrzA5EOwNjlNmrIBeUN6VCaLkwmGTCcLpdPvmX niaw2hF9wSeb9VHMOofDbu/mTQwbnVJBpY1HNA0N046hCESbJmtf5JPtjLiR4/iTY4LP ynHQ== 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=CqjfeQNlhTI+BPVPyT/fOr+xJ6iCGpnOYdb93ZFU2yk=; b=VOO+XZF4EtiVaz6p4aRfbo2h5qCGCd13jukQWlyGphjRMoHMMet3bQNyqK5De5Kzez to2NUHpbA0A4QdFfvtr4+MS2Ex8S5wPa8NiLr9jYjOrB9Z3sSTjj3mHfS21tZYbUBBQG kmOxxaN4/+vFmsvN190KyVfDVDIEql6i2lGYxkygthpEzgj54FOHdBkdnv8CZ47c/tbq htUcAsIQZcFHxHqN9Eb0V0X1QoddK3JZNTjjOf4DRO7gYCQWNkqOCcLpU984ONcQuYeX iX6fRtrezhG6yNFmpfpCpcE5C4jVNjnomIloOu3CT8w2lGZKTJHnLn/BzWrCgjrFOAmm 3E8w== X-Gm-Message-State: AOAM531WxN8NdSmGiUb1yNzvASlQkCP7HHGf93DM49JVyhj3g/jnc6wb 88Z4ipg2mtPA2N2DEOHMz1U= X-Google-Smtp-Source: ABdhPJwMEfOulv4bE9nM1fVJG5naXD7d7s3IwKXhN/mDZzEoaYCq1j198LcJ4tT15xhtWFgHfciAgg== X-Received: by 2002:a2e:7a04:: with SMTP id v4mr12094444ljc.128.1599531118224; Mon, 07 Sep 2020 19:11:58 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11: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 v6 25/35] i2c: tegra: Factor out error recovery from tegra_i2c_xfer_msg() Date: Tue, 8 Sep 2020 05:10:11 +0300 Message-Id: <20200908021021.9123-26-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Factor out error recovery code from tegra_i2c_xfer_msg() in order to make this function easier to read and follow. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- 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 0d823aae9eaf..e53334bc3de3 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1098,6 +1098,32 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) return -EAGAIN; } +static int tegra_i2c_error_recover(struct tegra_i2c_dev *i2c_dev, + struct i2c_msg *msg) +{ + if (i2c_dev->msg_err == I2C_ERR_NONE) + return 0; + + tegra_i2c_init(i2c_dev); + + /* start recovery upon arbitration loss in single master mode */ + if (i2c_dev->msg_err == I2C_ERR_ARBITRATION_LOST) { + if (!i2c_dev->is_multimaster_mode) + return i2c_recover_bus(&i2c_dev->adapter); + + return -EAGAIN; + } + + if (i2c_dev->msg_err == I2C_ERR_NO_ACK) { + if (msg->flags & I2C_M_IGNORE_NAK) + return 0; + + return -EREMOTEIO; + } + + return -EIO; +} + static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, struct i2c_msg *msg, enum msg_end_type end_state) @@ -1282,24 +1308,12 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->msg_err); i2c_dev->is_curr_dma_xfer = false; - if (i2c_dev->msg_err == I2C_ERR_NONE) - return 0; - tegra_i2c_init(i2c_dev); - /* start recovery upon arbitration loss in single master mode */ - if (i2c_dev->msg_err == I2C_ERR_ARBITRATION_LOST) { - if (!i2c_dev->is_multimaster_mode) - return i2c_recover_bus(&i2c_dev->adapter); - return -EAGAIN; - } - - if (i2c_dev->msg_err == I2C_ERR_NO_ACK) { - if (msg->flags & I2C_M_IGNORE_NAK) - return 0; - return -EREMOTEIO; - } + err = tegra_i2c_error_recover(i2c_dev, msg); + if (err) + return err; - return -EIO; + return 0; } static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], From patchwork Tue Sep 8 02:10:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359362 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Y3RLBG02; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpcl2m58z9sTK for ; Tue, 8 Sep 2020 12:14:31 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728414AbgIHCO3 (ORCPT ); Mon, 7 Sep 2020 22:14:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728339AbgIHCMD (ORCPT ); Mon, 7 Sep 2020 22:12: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 93E8BC061575; Mon, 7 Sep 2020 19:12:00 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id u21so7781067ljl.6; Mon, 07 Sep 2020 19:12:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7kRCRfMq38wFuNahMZFQYpLZtJc+rzpszwWJYEXvcIo=; b=Y3RLBG02uCrI4hWo9WQndroyDQ2sl27pDQY9jYf9WjDuouGvJ/DzSou67++UsYpWW7 E9aKYyCmx40AHGumtR9fLF4PDRSi+TTPNYjHZLgTYPf6OkTY+DA4ePwn/dkctSWfvmp/ RY5BtvCiiskr2YKel171n6UGD7fAhGh4afv/GRPzHPYH2Iu1af1lbty0razBum3HVYZz 0OAPuVJ7GaR3P3BEDeLqJbrwLss4iGD9ka6D3hNYV92Eok5ye8ZfwYCyP7h8cGY8Z1Kp qs3Hyaewh4HE1ieImZUEw9Ihg4+1gMNxOjBEneD1CwFNH5lX9yi49QGDJ1LfyfpErQx4 PHig== 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=7kRCRfMq38wFuNahMZFQYpLZtJc+rzpszwWJYEXvcIo=; b=A7cEPmhFL3Ik+/odhyPYrjfcb04pus66wohtClfhPKypp4j7+roQZMIgHMeJNwSlAa QNf93bKbnDtB4XKh1I2X8Qx3JfL8XSY/8qu+wtNWTr9ER+UA12UaU3Pu5b/OQ8ywTdxj /esAuyz0D1Vsa3UZb8nl0vAQN5Jw9E5OZQVaNZKS43whQ98k9SiOTgewmtDY9D3ycVXS hAGd9a4TRFWpUcry3i6muQ44Z8o4ty0JA1sNvXbDrNnMc5luKkDUx6IpnXc/+ln0AO3S ZTS8btbf3svimw2tCLVOSwT8vnzPk7Uy2BkRPF/St5JceKw8AIjoTh36+k7ivvLroOlB AK9A== X-Gm-Message-State: AOAM5331Hb4icKKeMS4yO2eI/OEm+aH/ss0NQUjddu+r0w2oCowtxiju QlnkG18j/EzAj9mQ5JcWUL0= X-Google-Smtp-Source: ABdhPJwX5PI+yG79T2fIN2SNOQlBcBW9hsNm5+8s87oJ9TK3M0qONHKvMpxNcU486BulJZP25wrMSA== X-Received: by 2002:a2e:7e0b:: with SMTP id z11mr11828385ljc.133.1599531119063; Mon, 07 Sep 2020 19:11: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 j12sm9070085lfj.5.2020.09.07.19.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11:58 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 26/35] i2c: tegra: Factor out packet header setup from tegra_i2c_xfer_msg() Date: Tue, 8 Sep 2020 05:10:12 +0300 Message-Id: <20200908021021.9123-27-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The code related to packet header setting up is a bit messy and makes tegra_i2c_xfer_msg() more difficult to read than it could be. Let's factor the packet header setup from tegra_i2c_xfer_msg() into separate function in order to make code easier to read and follow. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 93 ++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index e53334bc3de3..7d54b8b3ed9a 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1098,6 +1098,57 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) return -EAGAIN; } +static void tegra_i2c_push_packet_header(struct tegra_i2c_dev *i2c_dev, + struct i2c_msg *msg, + enum msg_end_type end_state) +{ + u32 *dma_buf = i2c_dev->dma_buf; + u32 packet_header; + + packet_header = FIELD_PREP(PACKET_HEADER0_HEADER_SIZE, 0) | + FIELD_PREP(PACKET_HEADER0_PROTOCOL, + PACKET_HEADER0_PROTOCOL_I2C) | + FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) | + FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1); + + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + *dma_buf++ = packet_header; + else + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); + + packet_header = msg->len - 1; + + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + *dma_buf++ = packet_header; + else + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); + + packet_header = I2C_HEADER_IE_ENABLE; + + if (end_state == MSG_END_CONTINUE) + packet_header |= I2C_HEADER_CONTINUE_XFER; + else if (end_state == MSG_END_REPEAT_START) + packet_header |= I2C_HEADER_REPEAT_START; + + if (msg->flags & I2C_M_TEN) { + packet_header |= msg->addr; + packet_header |= I2C_HEADER_10BIT_ADDR; + } else { + packet_header |= msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT; + } + + if (msg->flags & I2C_M_IGNORE_NAK) + packet_header |= I2C_HEADER_CONT_ON_NAK; + + if (msg->flags & I2C_M_RD) + packet_header |= I2C_HEADER_READ; + + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + *dma_buf++ = packet_header; + else + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); +} + static int tegra_i2c_error_recover(struct tegra_i2c_dev *i2c_dev, struct i2c_msg *msg) { @@ -1129,9 +1180,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, enum msg_end_type end_state) { unsigned long time_left, xfer_time = 100; - u32 packet_header, int_mask; - u32 *buffer = NULL; size_t xfer_size; + u32 int_mask; int err; err = tegra_i2c_flush_fifos(i2c_dev); @@ -1186,49 +1236,14 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->dma_phys, xfer_size, DMA_TO_DEVICE); - buffer = i2c_dev->dma_buf; } } - packet_header = FIELD_PREP(PACKET_HEADER0_HEADER_SIZE, 0) | - FIELD_PREP(PACKET_HEADER0_PROTOCOL, - PACKET_HEADER0_PROTOCOL_I2C) | - FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) | - FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1); - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) - *buffer++ = packet_header; - else - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); - - packet_header = msg->len - 1; - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) - *buffer++ = packet_header; - else - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); - - packet_header = I2C_HEADER_IE_ENABLE; - if (end_state == MSG_END_CONTINUE) - packet_header |= I2C_HEADER_CONTINUE_XFER; - else if (end_state == MSG_END_REPEAT_START) - packet_header |= I2C_HEADER_REPEAT_START; - if (msg->flags & I2C_M_TEN) { - packet_header |= msg->addr; - packet_header |= I2C_HEADER_10BIT_ADDR; - } else { - packet_header |= msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT; - } - if (msg->flags & I2C_M_IGNORE_NAK) - packet_header |= I2C_HEADER_CONT_ON_NAK; - if (msg->flags & I2C_M_RD) - packet_header |= I2C_HEADER_READ; - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) - *buffer++ = packet_header; - else - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); + tegra_i2c_push_packet_header(i2c_dev, msg, end_state); if (!i2c_dev->msg_read) { if (i2c_dev->is_curr_dma_xfer) { - memcpy(buffer, msg->buf, msg->len); + memcpy(i2c_dev->dma_buf, msg->buf, msg->len); dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, xfer_size, From patchwork Tue Sep 8 02:10:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ZS2wWUW3; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpcx0Xh7z9sTW for ; Tue, 8 Sep 2020 12:14:41 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728632AbgIHCOj (ORCPT ); Mon, 7 Sep 2020 22:14:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728341AbgIHCMD (ORCPT ); Mon, 7 Sep 2020 22:12:03 -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 675C3C0613ED; Mon, 7 Sep 2020 19:12:01 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id a22so11626101ljp.13; Mon, 07 Sep 2020 19:12: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=cjZeMOpLGKlggQ4Zf1tDxvKw367fZ+lczUYfx0tdRmw=; b=ZS2wWUW3ORmz3Pv/f2ccJqJm93Xc67Hz0iyjcs1eleucmVVxZmL63LDdgzHIvah7js aAe4YHVT1+dxpwKWiuXXMiYmn2FGid9a7gAzTJjpcfJ6RxRQsjroJ7vf/2MV4SadIN48 8bpIzhCHutRgl6Z/3QnWF0VwiXkEY8EqzDMUBRDrDQoKCKzbQ9fw0GwnPh2X0l8vn8Ai cee07Y4DJXQmoK2HSSkn/uQZreK9yTOhYxmql/7H2Qnu0+RAqfGU3BL5dqRxIybjv48b CJwsKajCjUS/g8MGDHokcXfdup85lDuJddMZn/QiJM/emi7sa1rjIK/n8NPF0dhTmbxM FaYg== 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=cjZeMOpLGKlggQ4Zf1tDxvKw367fZ+lczUYfx0tdRmw=; b=sxdVFZiK7p5drNOYpsxihS6VpfyxZ+Q4ayLUgvFeQg6VIW5GY8kw6J2WF2aR1N8FTS xP7Rsoqo2nr5QarI4+pFfZahpi4d07pazltcnVX4fFtxV3LF90uuKAqc8S9XQAvqIwVK 70PPcQnhPzMCT4u8S7Wvl158/mEFafVlrDaWw0NCDbopRfV5JokBZ2g1YnPZkWdGtrhG E6zYQwpuKnXdsKBXpBfv04U985VbAlpdY9qbt0WP9E9eM9Z0voOv1Z9O+AnKJrGba9TF JnAzInvcLJ5ouMNFvRWb0xIAUeEdFh0dsLGn2f/hdRM7AhV/7c5RVWMNr+DCZA7GvFdz U/sQ== X-Gm-Message-State: AOAM530yhOdJ7qq89LTBeK/sJQTvD2/cqOI+W28v3L/4J6iVZtpyStU9 9evpEqIRFnQQJ+FkvW7MrkU7Wx18PIs= X-Google-Smtp-Source: ABdhPJzLpPz57i5QJ2Z0Xg0STz0uvvWopocYTfYuguMnwUOaxzolVsa8KzdbmBGBnL98cfsC9DuaWA== X-Received: by 2002:a2e:9dc7:: with SMTP id x7mr11256502ljj.447.1599531119914; Mon, 07 Sep 2020 19:11: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 j12sm9070085lfj.5.2020.09.07.19.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:11: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 v6 27/35] i2c: tegra: Factor out register polling into separate function Date: Tue, 8 Sep 2020 05:10:13 +0300 Message-Id: <20200908021021.9123-28-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Factor out register polling into a separate function in order to remove boilerplate code and make code cleaner. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 43 +++++++++++++++------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 7d54b8b3ed9a..2e7beadd381f 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -518,10 +518,24 @@ static void tegra_i2c_vi_init(struct tegra_i2c_dev *i2c_dev) i2c_writel(i2c_dev, 0x0, I2C_TLOW_SEXT); } +static int tegra_i2c_poll_register(struct tegra_i2c_dev *i2c_dev, + u32 reg, u32 mask, u32 delay_us, + u32 timeout_us) +{ + void __iomem *addr = i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg); + u32 val; + + if (!i2c_dev->is_curr_atomic_xfer) + return readl_relaxed_poll_timeout(addr, val, !(val & mask), + delay_us, timeout_us); + + return readl_relaxed_poll_timeout_atomic(addr, val, !(val & mask), + delay_us, timeout_us); +} + static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) { - u32 mask, val, offset, reg_offset; - void __iomem *addr; + u32 mask, val, offset; int err; if (i2c_dev->hw->has_mst_fifo) { @@ -538,16 +552,7 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) val |= mask; i2c_writel(i2c_dev, val, offset); - reg_offset = tegra_i2c_reg_addr(i2c_dev, offset); - addr = i2c_dev->base + reg_offset; - - if (i2c_dev->is_curr_atomic_xfer) - err = readl_relaxed_poll_timeout_atomic(addr, val, !(val & mask), - 1000, 1000000); - else - err = readl_relaxed_poll_timeout(addr, val, !(val & mask), - 1000, 1000000); - + err = tegra_i2c_poll_register(i2c_dev, offset, mask, 1000, 1000000); if (err) { dev_err(i2c_dev->dev, "failed to flush FIFO\n"); return err; @@ -557,25 +562,15 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) { - unsigned long reg_offset; - void __iomem *addr; - u32 val; int err; if (!i2c_dev->hw->has_config_load_reg) return 0; - reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_CONFIG_LOAD); - addr = i2c_dev->base + reg_offset; i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD); - if (i2c_dev->is_curr_atomic_xfer) - err = readl_relaxed_poll_timeout_atomic(addr, val, val == 0, 1000, - I2C_CONFIG_LOAD_TIMEOUT); - else - err = readl_relaxed_poll_timeout(addr, val, val == 0, 1000, - I2C_CONFIG_LOAD_TIMEOUT); - + err = tegra_i2c_poll_register(i2c_dev, I2C_CONFIG_LOAD, 0xffffffff, + 1000, I2C_CONFIG_LOAD_TIMEOUT); if (err) { dev_warn(i2c_dev->dev, "timeout waiting for config load\n"); return err; From patchwork Tue Sep 8 02:10:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359351 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=kvtlENgW; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpcc5DZZz9sTK for ; Tue, 8 Sep 2020 12:14:24 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728158AbgIHCNq (ORCPT ); Mon, 7 Sep 2020 22:13:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728382AbgIHCMP (ORCPT ); Mon, 7 Sep 2020 22:12:15 -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 4FB6AC0617A4; Mon, 7 Sep 2020 19:12:02 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id n25so7106580ljj.4; Mon, 07 Sep 2020 19:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+XR0GKh2Rda8u3koZlqMitsrhjsxJys6IV1C/EFC2aI=; b=kvtlENgWUyOmS7mnjfGXld/dNgCfuHuAF9QW6pyeInC++NGhKl05jTPT8wxRtmaFsb tgowznDCxGb/alctR5zAvLwrTbELNpoy7CMbaSIiBJ74zSy7KWKCnhCTVNo9kHO17JQF 58ZfQgD2BpF56fod7yHvU4SkdoRNFwc/WK0ohgpvdnLQ146WHly0mOOeZcrkTraYVffI NF/+XQY7K3jJxa8ZIMSAKbgGLjn+kEfy7Dg02nFZICKqjzj68awom/Fcxt4Hw2qzi+5Z lD7bn+TuVuxmAyEW5F0qdgEIB8N2UOD3+mmxXljP2fZgKKZB2ZE139jKeEpHezzAw/Ba u9Pg== 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=+XR0GKh2Rda8u3koZlqMitsrhjsxJys6IV1C/EFC2aI=; b=qw+q/k3BKyCsaSpQWEZgwV6ZAXerRROLVk2mQ5N50K+xdJhXSvZyVDRQVov8KVOfgi F60NrCRNOARcJfT51rFaEX758iUjda6sW1l+YDbsYOYId+kpoP1tbRtXPbotjZ58dLpx rjHRshWFnlYKauIJzLeiM5yp1wdvXZLBkYyBspR9pTie+OU8JSXRaTUfttuzkZtMeSVa /0eYicZCFlSbjbqSWcKn67V992AozNhbh4P9xPuBMafcpMVaGT+PotbhzgjZNH9IY+ov zDAOIjVfd4nhEoccQbt6EilqMLEqYG9Ge1pQJWEvCxc0oy1TH9PDXiSA7F/Vz9McGnG8 BZiw== X-Gm-Message-State: AOAM530hpRK88rVEKuX1vPAizJgB/DznTJDdEy/+oPvhQrz659wqwcRw d6r9S6BLhibJoQVfsN6C81U= X-Google-Smtp-Source: ABdhPJyB8C20xBu1cW9qmhousT8Rre754g2t6bNUomxbqJx3ISaKMctjo6Lzx41AtHoJQ/2XQemjLA== X-Received: by 2002:a2e:99c4:: with SMTP id l4mr12489968ljj.428.1599531120814; Mon, 07 Sep 2020 19:12:00 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:12:00 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 28/35] i2c: tegra: Factor out hardware initialization into separate function Date: Tue, 8 Sep 2020 05:10:14 +0300 Message-Id: <20200908021021.9123-29-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Factor out hardware initialization into a separate function from the probe function. The only place where runtime PM needs to be resumed during probe is the place of hardware initialization, hence it makes sense to factor out it in order to have a bit cleaner error handling in tegra_i2c_probe(). Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 2e7beadd381f..44a8c7ae8509 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1655,6 +1655,21 @@ static void tegra_i2c_release_clocks(struct tegra_i2c_dev *i2c_dev) clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks); } +static int tegra_i2c_init_hardware(struct tegra_i2c_dev *i2c_dev) +{ + int ret; + + ret = pm_runtime_get_sync(i2c_dev->dev); + if (ret < 0) + dev_err(i2c_dev->dev, "runtime resume failed: %d\n", ret); + else + ret = tegra_i2c_init(i2c_dev); + + pm_runtime_put(i2c_dev->dev); + + return ret; +} + static int tegra_i2c_probe(struct platform_device *pdev) { struct tegra_i2c_dev *i2c_dev; @@ -1724,16 +1739,9 @@ static int tegra_i2c_probe(struct platform_device *pdev) pm_runtime_enable(i2c_dev->dev); - err = pm_runtime_get_sync(i2c_dev->dev); - if (err < 0) { - dev_err(i2c_dev->dev, "runtime resume failed: %d\n", err); - goto put_rpm; - } - - /* initialize hardware state */ - err = tegra_i2c_init(i2c_dev); + err = tegra_i2c_init_hardware(i2c_dev); if (err) - goto put_rpm; + goto release_rpm; i2c_dev->adapter.dev.of_node = i2c_dev->dev->of_node; i2c_dev->adapter.dev.parent = i2c_dev->dev; @@ -1755,14 +1763,11 @@ static int tegra_i2c_probe(struct platform_device *pdev) err = i2c_add_numbered_adapter(&i2c_dev->adapter); if (err) - goto put_rpm; - - pm_runtime_put(i2c_dev->dev); + goto release_rpm; return 0; -put_rpm: - pm_runtime_put(i2c_dev->dev); +release_rpm: pm_runtime_disable(i2c_dev->dev); tegra_i2c_release_dma(i2c_dev); From patchwork Tue Sep 8 02:10:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359361 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=rtm0v+gA; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpck5YPnz9sR4 for ; Tue, 8 Sep 2020 12:14:30 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728149AbgIHCO3 (ORCPT ); Mon, 7 Sep 2020 22:14:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728384AbgIHCMP (ORCPT ); Mon, 7 Sep 2020 22:12:15 -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 4A756C0617A5; Mon, 7 Sep 2020 19:12:03 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id y4so18007832ljk.8; Mon, 07 Sep 2020 19:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bhYXVU5OxtMkVW3XxSZWr/Wz0AEa7WBnTGkvmLBOr6I=; b=rtm0v+gAdEnm932au1tB3Fambj6CK2mvDSkO41G+MXRYrgKpvgZQbe+qo2qQsXM9pa kWpRKCslYyWfiIdlxpDEwCLwtCaXCN3NPtcbh3Nk/SzzuhxMuBq/FvNvkAlTUQULVEu0 PIoSJIZUEEIAkavsKZoYTi6NVYSTluxri29OUE87N7ZFXDZUp8LkNNDMJXLWFblzK1Pa Tf7lgqHPdsXOGJPY8qiwKJtX80U3lk6h/dj/iCbg2XpjUYXa4dKXGOxthGNGQrptVID3 BZJO+kccC3lJd9ORL77C18iESLpBktXup3j0OOU7ffbAe2U3TeAycgnoiJwNS90CVv+W JyTw== 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=bhYXVU5OxtMkVW3XxSZWr/Wz0AEa7WBnTGkvmLBOr6I=; b=CRM/DfpCow23LAwPyACMriQ+I337AZyBWOX+1rMQEQRxpk86O2urR9ZBwFREsKCMG7 /7DFR7bOiTzEFg19CBJ4xczGlafpNPtCClyAq1dsCzrsZpxxnXegZfMJwpTWY6QZ2mTh o/SqlqUl4G2bqWmS8QXxtXnD1BPgU2qCKj8qCxElTlh2NfUu2pkODt0i0n+gXTJsxq1d eJjHRnex+hpXGr6+CaJhZZ+3QydCVW0x+O/sq0t34RBlenc5G6W8re62JDCROOwMeaVT IsKRgysVS2cOhLK+ltD04fWicV8AR3XjUAVrJoalAMJrsrTbwD7dCkgEJ0j8gXvMPKKv K3kw== X-Gm-Message-State: AOAM531iMemLb14S3v3I9mM7y64mj+oadPGcI8lDuBLbD4MapKSzGwLc MrP2JKENUpjWURkTAqyoyoA= X-Google-Smtp-Source: ABdhPJyjrjcqJE86UbUuHCAIy7a2diCuAzo72eXvsYDkgkGJtdepruaA11KcB55rm36Jy1wMiGKR4A== X-Received: by 2002:a2e:9988:: with SMTP id w8mr12365362lji.286.1599531121631; Mon, 07 Sep 2020 19:12:01 -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 j12sm9070085lfj.5.2020.09.07.19.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:12:01 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 29/35] i2c: tegra: Check errors for both positive and negative values Date: Tue, 8 Sep 2020 05:10:15 +0300 Message-Id: <20200908021021.9123-30-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The driver's code is inconsistent in regards to the error values checking. The correct way should be to check both positive and negative values. This patch cleans up the error-checks in the code. Note that the pm_runtime_get_sync() could return positive value on success, hence only relevant parts of the code are changed by this patch. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 44a8c7ae8509..2529d557e0b1 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -977,7 +977,7 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) slv_config.device_fc = true; ret = dmaengine_slave_config(chan, &slv_config); - if (ret < 0) { + if (ret) { dev_err(i2c_dev->dev, "DMA slave config failed: %d\n", ret); return ret; @@ -1219,7 +1219,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size, DMA_FROM_DEVICE); err = tegra_i2c_dma_submit(i2c_dev, xfer_size); - if (err < 0) { + if (err) { dev_err(i2c_dev->dev, "starting RX DMA failed, err %d\n", err); @@ -1244,7 +1244,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size, DMA_TO_DEVICE); err = tegra_i2c_dma_submit(i2c_dev, xfer_size); - if (err < 0) { + if (err) { dev_err(i2c_dev->dev, "starting TX DMA failed, err %d\n", err); From patchwork Tue Sep 8 02:10:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359352 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=c7WSz1Zb; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpcd3jg7z9sTM for ; Tue, 8 Sep 2020 12:14:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728601AbgIHCNp (ORCPT ); Mon, 7 Sep 2020 22:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728386AbgIHCMS (ORCPT ); Mon, 7 Sep 2020 22:12:18 -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 00F02C061755; Mon, 7 Sep 2020 19:12:04 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id s205so18039412lja.7; Mon, 07 Sep 2020 19:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vveidTkc/eu87y/y+4KUyPRX3Pa9/Zje3+4hy4983PA=; b=c7WSz1ZbqVbBub2NvVsjVh1OUH8DlotJWWRh87EUgZSeuvis6PVIcO1w20LsafW/zL bembyoaGFU73S2crS6iFYP5HmiXqU5ZA1fkWjXe2K0h/gpw1CSoD+AEcuBu+Yr5koH1t oU5IY8RozWSV+Y4MpV56BlK2xqVShD+J7LtxJ3hMrk+qqmuQOVh9W+l/mqPiFwhO5KZL Ywc2gahuP0HWf7wpsEcbsIMBVTP/r4QYa4pMjDLUlHlNiH3mhXHWriY4M/I1LKl89ssU XtfMgQ5OLbmRkUslRKwB96BFagMdzk6+7acJVZmLstfsGDMa3+JyeveHM+o5l9UvwtKI 4m1Q== 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=vveidTkc/eu87y/y+4KUyPRX3Pa9/Zje3+4hy4983PA=; b=HhVOz5zPfH/5rZ7su8bujJDKylncbnI1YeduLWQ47/sT7+jltnvFv5YqlQ316OI0U8 GE5MXjUoVo8bxH7+T28tv9G5ZHBITlPeXauXLH+S11TDjFiI0PfnCRHBp7nTZVH6lU6Z skVpeTmyy8hJMVRo1dk/91GqkKkQ5hdrqoXXEgkgfY+zjtTbw70faiOgMeX72/PS2mCa sETg7DqIJkJuJVhP7qwrHWHgQr96m3WcXZhEWvkudDgu1UOxnRDwEi22SJT4liH52Rf2 gisJEL3kc8qANEkpIa84/g2SxJH8dsjdu3DKqUMKmgF1rudPnQBLFtOfD6s/EWr0zAFj 1vNQ== X-Gm-Message-State: AOAM530SSP1zDBteVBaYPIml3OJZzBSayIDwiDpGQaGnOSZ2cEo6xeTn 7miGQlfFfjVIiK8tF4T7b0/DtXWl2Ps= X-Google-Smtp-Source: ABdhPJxnaYx8Wg6tJI8LnT7XBPQ4oR9WOJsNGXXVwFiMCs5UEHRbucij7ZX452B+vZaY0ftGYYNMQw== X-Received: by 2002:a2e:a314:: with SMTP id l20mr12264858lje.213.1599531122515; Mon, 07 Sep 2020 19:12: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 j12sm9070085lfj.5.2020.09.07.19.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:12: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 v6 30/35] i2c: tegra: Consolidate error handling in tegra_i2c_xfer_msg() Date: Tue, 8 Sep 2020 05:10:16 +0300 Message-Id: <20200908021021.9123-31-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Consolidate error handling in tegra_i2c_xfer_msg() into a common code path in order to make code cleaner. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 2529d557e0b1..62c7334fe601 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1288,8 +1288,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (!time_left && !completion_done(&i2c_dev->dma_complete)) { dev_err(i2c_dev->dev, "DMA transfer timeout\n"); - tegra_i2c_init(i2c_dev); - return -ETIMEDOUT; + err = -ETIMEDOUT; + goto reset_hardware; } if (i2c_dev->msg_read && i2c_dev->msg_err == I2C_ERR_NONE) { @@ -1309,8 +1309,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (time_left == 0) { dev_err(i2c_dev->dev, "i2c transfer timed out\n"); - tegra_i2c_init(i2c_dev); - return -ETIMEDOUT; + err = -ETIMEDOUT; + goto reset_hardware; } dev_dbg(i2c_dev->dev, "transfer complete: %lu %d %d\n", @@ -1324,6 +1324,11 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, return err; return 0; + +reset_hardware: + tegra_i2c_init(i2c_dev); + + return err; } static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], From patchwork Tue Sep 8 02:10:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359350 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Bn6Y8gS8; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpbx0HNDz9sTd for ; Tue, 8 Sep 2020 12:13:49 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728632AbgIHCNq (ORCPT ); Mon, 7 Sep 2020 22:13:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728392AbgIHCMS (ORCPT ); Mon, 7 Sep 2020 22:12:18 -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 049C6C061786; Mon, 7 Sep 2020 19:12:05 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id y11so8331317lfl.5; Mon, 07 Sep 2020 19:12: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=pLCqpTt0o9YasuFuanVeohNjbDRhOwjYnUF/dxHNwVo=; b=Bn6Y8gS86P2CIbHMn71b3x/m/8ijNlgo9DYln5gW5lVWp8MxAZSZxvkig5d8mWHdia fYJpQUttzhM627J2Hn2DrbKlRpmwfc/dlJjLWO0bjev69OydZcgSnyYMOC2GW/X1e/CT dfUIzdaZQWkNbQS9FhPgZrUo2/yw1I+6TVQeWUOWm7DZA2wy8td3sEYKtlZJ6TQu6Ktr p8xtHaQdat+FbBNTdBC9PLBCqDNiOyMXSLNr0EvPWJCX4fKFSEqUNC5Cc1Sr4G0hlnZa R6jcQ72EzNbtJf1nLleQaAexc2UmH0DXFaOV5ZqCOiZTXyfLgqDShFC7GFHo//Ie7lpV gGjQ== 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=pLCqpTt0o9YasuFuanVeohNjbDRhOwjYnUF/dxHNwVo=; b=lnxKjci3oB3GHIbG26vjiPM74yGWhNYenwu6bq8dw2qKHfO/5HMrkca8HWoUXEdpzY Px9usxmrkUpOvWU9Gi+koA7lO+ZCKnNFKQOOAQj35wdMdKa+uJyyp8rhujRXrla334yO Xvgv7Edq4iAO5JUiaZCYPR2TxvCztXVIKjKAQrAkF0P0nAMpZaUVNrJY0B88lZN6AkFR wo21+09jyheTADGjgS4p72wF4j7I2RheUXiFumGngAIn3msp8rHZCcAiZkPvQuWeqHoi mMC/21mU25ZPfMGGROI4UtERt4CY5burMqgRTRyOJEof9ICNFcz660bUYBOeENFFuQ57 f51g== X-Gm-Message-State: AOAM5308hqdLgxQ1pW9HL/AShq6X8VykfKAp2akDtmuJ8CTeDwd+fhfP vnjPrB+/HBWMSyKhLu6tu8Q= X-Google-Smtp-Source: ABdhPJxJYr6nz36rfixlnpmmO0qhXJ93b8sUrVG9O/wBh1xEki/MisrenDSdbt9Eg3ToxqHul+bAug== X-Received: by 2002:ac2:592d:: with SMTP id v13mr11566983lfi.124.1599531123369; Mon, 07 Sep 2020 19:12: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 j12sm9070085lfj.5.2020.09.07.19.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:12: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 v6 31/35] i2c: tegra: Clean up variable names Date: Tue, 8 Sep 2020 05:10:17 +0300 Message-Id: <20200908021021.9123-32-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Rename "ret" variables to "err" in order to make code a bit more expressive, emphasizing that the returned value is an error code. Rename variable "reg" to "val" in order to better reflect the actual usage of the variable in the code and to make naming consistent with the rest of the code. Use briefer names for a few members of the tegra_i2c_dev structure in order to improve readability of the code. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 109 ++++++++++++++++----------------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 62c7334fe601..44c75595a173 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -247,15 +247,15 @@ struct tegra_i2c_hw_feature { * @msg_buf_remaining: size of unsent data in the message buffer * @msg_read: identifies read transfers * @bus_clk_rate: current I2C bus clock rate - * @is_multimaster_mode: track if I2C controller is in multi-master mode + * @multimaster_mode: indicates that I2C controller is in multi-master mode * @tx_dma_chan: DMA transmit channel * @rx_dma_chan: DMA receive channel * @dma_phys: handle to DMA resources * @dma_buf: pointer to allocated DMA buffer * @dma_buf_size: DMA buffer size - * @is_curr_dma_xfer: indicates active DMA transfer + * @dma_mode: indicates active DMA transfer * @dma_complete: DMA completion notifier - * @is_curr_atomic_xfer: indicates active atomic transfer + * @atomic_mode: indicates active atomic transfer */ struct tegra_i2c_dev { struct device *dev; @@ -287,9 +287,9 @@ struct tegra_i2c_dev { dma_addr_t dma_phys; u32 *dma_buf; - bool is_multimaster_mode; - bool is_curr_atomic_xfer; - bool is_curr_dma_xfer; + bool multimaster_mode; + bool atomic_mode; + bool dma_mode; bool msg_read; bool is_dvc; bool is_vi; @@ -525,7 +525,7 @@ static int tegra_i2c_poll_register(struct tegra_i2c_dev *i2c_dev, void __iomem *addr = i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg); u32 val; - if (!i2c_dev->is_curr_atomic_xfer) + if (!i2c_dev->atomic_mode) return readl_relaxed_poll_timeout(addr, val, !(val & mask), delay_us, timeout_us); @@ -673,7 +673,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) if (err) return err; - if (i2c_dev->is_multimaster_mode && i2c_dev->hw->has_slcg_override_reg) + if (i2c_dev->multimaster_mode && i2c_dev->hw->has_slcg_override_reg) i2c_writel(i2c_dev, I2C_MST_CORE_CLKEN_OVR, I2C_CLKEN_OVERRIDE); err = tegra_i2c_wait_for_config_load(i2c_dev); @@ -859,7 +859,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) if (i2c_dev->hw->supports_bus_clear && (status & I2C_INT_BUS_CLR_DONE)) goto err; - if (!i2c_dev->is_curr_dma_xfer) { + if (!i2c_dev->dma_mode) { if (i2c_dev->msg_read && (status & I2C_INT_RX_FIFO_DATA_REQ)) { if (tegra_i2c_empty_rx_fifo(i2c_dev)) { /* @@ -893,7 +893,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) * so forcing msg_buf_remaining to 0 in DMA mode. */ if (status & I2C_INT_PACKET_XFER_COMPLETE) { - if (i2c_dev->is_curr_dma_xfer) + if (i2c_dev->dma_mode) i2c_dev->msg_buf_remaining = 0; /* * Underflow error condition: XFER_COMPLETE before message @@ -917,7 +917,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) if (i2c_dev->is_dvc) dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS); - if (i2c_dev->is_curr_dma_xfer) { + if (i2c_dev->dma_mode) { if (i2c_dev->msg_read) dmaengine_terminate_async(i2c_dev->rx_dma_chan); else @@ -936,14 +936,14 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) struct dma_slave_config slv_config = {0}; u32 val, reg, dma_burst, reg_offset; struct dma_chan *chan; - int ret; + int err; if (i2c_dev->hw->has_mst_fifo) reg = I2C_MST_FIFO_CONTROL; else reg = I2C_FIFO_CONTROL; - if (i2c_dev->is_curr_dma_xfer) { + if (i2c_dev->dma_mode) { if (len & 0xF) dma_burst = 1; else if (len & 0x10) @@ -976,11 +976,11 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) } slv_config.device_fc = true; - ret = dmaengine_slave_config(chan, &slv_config); - if (ret) { + err = dmaengine_slave_config(chan, &slv_config); + if (err) { dev_err(i2c_dev->dev, "DMA slave config failed: %d\n", - ret); - return ret; + err); + return err; } goto out; @@ -1030,7 +1030,7 @@ static unsigned long tegra_i2c_wait_completion(struct tegra_i2c_dev *i2c_dev, { unsigned long ret; - if (i2c_dev->is_curr_atomic_xfer) { + if (i2c_dev->atomic_mode) { ret = tegra_i2c_poll_completion(i2c_dev, complete, timeout_ms); } else { enable_irq(i2c_dev->irq); @@ -1058,20 +1058,20 @@ static unsigned long tegra_i2c_wait_completion(struct tegra_i2c_dev *i2c_dev, static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) { struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); - u32 reg, time_left; + u32 val, time_left; int err; reinit_completion(&i2c_dev->msg_complete); - reg = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND | + val = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND | I2C_BC_TERMINATE; - i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); + i2c_writel(i2c_dev, val, I2C_BUS_CLEAR_CNFG); err = tegra_i2c_wait_for_config_load(i2c_dev); if (err) return err; - reg |= I2C_BC_ENABLE; - i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); + val |= I2C_BC_ENABLE; + i2c_writel(i2c_dev, val, I2C_BUS_CLEAR_CNFG); tegra_i2c_unmask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); time_left = tegra_i2c_wait_completion(i2c_dev, &i2c_dev->msg_complete, @@ -1083,8 +1083,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; @@ -1106,14 +1106,14 @@ static void tegra_i2c_push_packet_header(struct tegra_i2c_dev *i2c_dev, FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) | FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1); - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + if (i2c_dev->dma_mode && !i2c_dev->msg_read) *dma_buf++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); packet_header = msg->len - 1; - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + if (i2c_dev->dma_mode && !i2c_dev->msg_read) *dma_buf++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); @@ -1138,7 +1138,7 @@ static void tegra_i2c_push_packet_header(struct tegra_i2c_dev *i2c_dev, if (msg->flags & I2C_M_RD) packet_header |= I2C_HEADER_READ; - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + if (i2c_dev->dma_mode && !i2c_dev->msg_read) *dma_buf++ = packet_header; else i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); @@ -1154,7 +1154,7 @@ static int tegra_i2c_error_recover(struct tegra_i2c_dev *i2c_dev, /* start recovery upon arbitration loss in single master mode */ if (i2c_dev->msg_err == I2C_ERR_ARBITRATION_LOST) { - if (!i2c_dev->is_multimaster_mode) + if (!i2c_dev->multimaster_mode) return i2c_recover_bus(&i2c_dev->adapter); return -EAGAIN; @@ -1195,9 +1195,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size = msg->len + I2C_PACKET_HEADER_SIZE; xfer_size = ALIGN(xfer_size, BYTES_PER_FIFO_WORD); - i2c_dev->is_curr_dma_xfer = (xfer_size > I2C_PIO_MODE_PREFERRED_LEN) && - i2c_dev->dma_buf && - !i2c_dev->is_curr_atomic_xfer; + i2c_dev->dma_mode = (xfer_size > I2C_PIO_MODE_PREFERRED_LEN) && + i2c_dev->dma_buf && !i2c_dev->atomic_mode; err = tegra_i2c_config_fifo_trig(i2c_dev, xfer_size); if (err) @@ -1212,7 +1211,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; tegra_i2c_unmask_irq(i2c_dev, int_mask); - if (i2c_dev->is_curr_dma_xfer) { + if (i2c_dev->dma_mode) { if (i2c_dev->msg_read) { dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, @@ -1237,7 +1236,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, tegra_i2c_push_packet_header(i2c_dev, msg, end_state); if (!i2c_dev->msg_read) { - if (i2c_dev->is_curr_dma_xfer) { + if (i2c_dev->dma_mode) { memcpy(i2c_dev->dma_buf, msg->buf, msg->len); dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, @@ -1257,7 +1256,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (i2c_dev->hw->has_per_pkt_xfer_complete_irq) int_mask |= I2C_INT_PACKET_XFER_COMPLETE; - if (!i2c_dev->is_curr_dma_xfer) { + if (!i2c_dev->dma_mode) { if (msg->flags & I2C_M_RD) int_mask |= I2C_INT_RX_FIFO_DATA_REQ; else if (i2c_dev->msg_buf_remaining) @@ -1268,7 +1267,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, dev_dbg(i2c_dev->dev, "unmasked irq: %02x\n", i2c_readl(i2c_dev, I2C_INT_MASK)); - if (i2c_dev->is_curr_dma_xfer) { + if (i2c_dev->dma_mode) { time_left = tegra_i2c_wait_completion(i2c_dev, &i2c_dev->dma_complete, xfer_time); @@ -1317,7 +1316,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, time_left, completion_done(&i2c_dev->msg_complete), i2c_dev->msg_err); - i2c_dev->is_curr_dma_xfer = false; + i2c_dev->dma_mode = false; err = tegra_i2c_error_recover(i2c_dev, msg); if (err) @@ -1369,9 +1368,9 @@ static int tegra_i2c_xfer_atomic(struct i2c_adapter *adap, struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); int ret; - i2c_dev->is_curr_atomic_xfer = true; + i2c_dev->atomic_mode = true; ret = tegra_i2c_xfer(adap, msgs, num); - i2c_dev->is_curr_atomic_xfer = false; + i2c_dev->atomic_mode = false; return ret; } @@ -1596,15 +1595,15 @@ static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) { struct device_node *np = i2c_dev->dev->of_node; bool multi_mode; - int ret; + int err; - ret = of_property_read_u32(np, "clock-frequency", + err = of_property_read_u32(np, "clock-frequency", &i2c_dev->bus_clk_rate); - if (ret) + if (err) i2c_dev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */ multi_mode = of_property_read_bool(np, "multi-master"); - i2c_dev->is_multimaster_mode = multi_mode; + i2c_dev->multimaster_mode = multi_mode; if (of_device_is_compatible(np, "nvidia,tegra20-i2c-dvc")) i2c_dev->is_dvc = true; @@ -1635,7 +1634,7 @@ static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev) } } - if (!i2c_dev->is_multimaster_mode) + if (!i2c_dev->multimaster_mode) return 0; err = clk_enable(i2c_dev->div_clk); @@ -1654,7 +1653,7 @@ static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev) static void tegra_i2c_release_clocks(struct tegra_i2c_dev *i2c_dev) { - if (i2c_dev->is_multimaster_mode) + if (i2c_dev->multimaster_mode) clk_disable(i2c_dev->div_clk); clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks); @@ -1798,15 +1797,15 @@ static int tegra_i2c_remove(struct platform_device *pdev) static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) { struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); - int ret; + int err; - ret = pinctrl_pm_select_default_state(i2c_dev->dev); - if (ret) - return ret; + err = pinctrl_pm_select_default_state(i2c_dev->dev); + if (err) + return err; - ret = clk_bulk_enable(i2c_dev->nclocks, i2c_dev->clocks); - if (ret) - return ret; + err = clk_bulk_enable(i2c_dev->nclocks, i2c_dev->clocks); + if (err) + return err; /* * VI I2C device is attached to VE power domain which goes through @@ -1815,8 +1814,8 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) * domain ON. */ if (i2c_dev->is_vi) { - ret = tegra_i2c_init(i2c_dev); - if (ret) + err = tegra_i2c_init(i2c_dev); + if (err) goto disable_clocks; } @@ -1825,7 +1824,7 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) disable_clocks: clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks); - return ret; + return err; } static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev) From patchwork Tue Sep 8 02:10:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359354 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=d66VIMLI; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpcf6Vnkz9sTK for ; Tue, 8 Sep 2020 12:14:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728586AbgIHCNp (ORCPT ); Mon, 7 Sep 2020 22:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728395AbgIHCMU (ORCPT ); Mon, 7 Sep 2020 22:12:20 -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 DC3FEC061795; Mon, 7 Sep 2020 19:12:05 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id b19so17987115lji.11; Mon, 07 Sep 2020 19:12: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=m0S/4Np9sPc793jkBRlsI+/R5oCadbPZM3MSvc8MO1k=; b=d66VIMLIdRTu/WczmtN9OLBNrmwlgdh8KQuzEf8jGVtx0jG+zZeEbTJHHHG+C2MAXu 2kU6i4pI0FcGnzSLIpjschNRqdk33JMSXzAt/HWvQjWriV0MYGaYZnpyjcKjNS9JRlNZ FWQykMFFJwJ3A+XJQHfwms5GGDq4/Fi0/AStCA3F7thDJygoHZLMUVHfBTkaqMHJ8zHH A4GiTaP2B0y/3SvGYRli3kJhMbECk616jTTKxXoKxyUhKRowIOPy1zlnUJXu5nSndFiK t+SLykfMFDV4Sf1NYxswcd3fwx2C5d9jtpNv0kGxN7pgo/wfsw4p8LSrHDGKdi75Y8TL siyg== 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=m0S/4Np9sPc793jkBRlsI+/R5oCadbPZM3MSvc8MO1k=; b=a3i9GQwS0Gv6SH0/W4CoLnkPCrd5KmWkjfKPKc7pCVyWEFku+QvPLfTTgMn7K0h+uo f6DDmlL934Zc2a6UwpDHSbKaaQYvYRPsIT1/y1GtN0buWoScFu3GI/9ghnFRkggmNeOT HPe5wkTi+3OJnsEd9Qq6cr4akCtG+yzaWj7mHRCoILue9o3XX+sgsMz2YECflW9jWRHW 6pCRkOMc1euLVux+3CofEyv/d07xvzk1Sv3VN/moEuvvaAlnAF25GruUEDuL8wdZXPS6 67MEtYbwBIV2h02YpS4SlIwaYpq0StWAQlx9vXifjPQmpGC7bAH8wKnmfMuvivgAWj1h j+Hw== X-Gm-Message-State: AOAM531g0vaQQbXj7ilG2lJRWG7uBtGinT+mtufRMTT6Da2+JaK1S4ay OrcJPBKMXwLVH4YRhFaXEPXKnhOCQG0= X-Google-Smtp-Source: ABdhPJx5l2LYH+Ky2qRjckzgavI9WQfVIHJxhjIMkhTXTBFAw5bhHaG1YnHYelB6EWsWBgJb1e5OaA== X-Received: by 2002:a2e:87d9:: with SMTP id v25mr11849428ljj.171.1599531124310; Mon, 07 Sep 2020 19:12:04 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j12sm9070085lfj.5.2020.09.07.19.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:12: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 v6 32/35] i2c: tegra: Clean up printk messages Date: Tue, 8 Sep 2020 05:10:18 +0300 Message-Id: <20200908021021.9123-33-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org This patch unifies style of all messages in the driver by starting them with a lowercase letter and using consistent capitalization and wording for all messages. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 37 +++++++++++++--------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 44c75595a173..56a7f696e425 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -381,7 +381,8 @@ static int tegra_i2c_dma_submit(struct tegra_i2c_dev *i2c_dev, size_t len) len, dir, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); if (!dma_desc) { - dev_err(i2c_dev->dev, "failed to get DMA descriptor\n"); + dev_err(i2c_dev->dev, "failed to get %s DMA descriptor\n", + i2c_dev->msg_read ? "RX" : "TX"); return -EINVAL; } @@ -422,7 +423,7 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) return 0; if (!IS_ENABLED(CONFIG_TEGRA20_APB_DMA)) { - dev_dbg(i2c_dev->dev, "Support for APB DMA not enabled!\n"); + dev_dbg(i2c_dev->dev, "DMA support not enabled\n"); return 0; } @@ -448,7 +449,7 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) dma_buf = dma_alloc_coherent(i2c_dev->dev, i2c_dev->dma_buf_size, &dma_phys, GFP_KERNEL | __GFP_NOWARN); if (!dma_buf) { - dev_err(i2c_dev->dev, "failed to allocate the DMA buffer\n"); + dev_err(i2c_dev->dev, "failed to allocate DMA buffer\n"); err = -ENOMEM; goto err_out; } @@ -572,7 +573,7 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) err = tegra_i2c_poll_register(i2c_dev, I2C_CONFIG_LOAD, 0xffffffff, 1000, I2C_CONFIG_LOAD_TIMEOUT); if (err) { - dev_warn(i2c_dev->dev, "timeout waiting for config load\n"); + dev_err(i2c_dev->dev, "failed to load config\n"); return err; } @@ -835,7 +836,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) status = i2c_readl(i2c_dev, I2C_INT_STATUS); if (status == 0) { - dev_warn(i2c_dev->dev, "irq status 0 %08x %08x %08x\n", + dev_warn(i2c_dev->dev, "IRQ status 0 %08x %08x %08x\n", i2c_readl(i2c_dev, I2C_PACKET_TRANSFER_STATUS), i2c_readl(i2c_dev, I2C_STATUS), i2c_readl(i2c_dev, I2C_CNFG)); @@ -978,8 +979,7 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) slv_config.device_fc = true; err = dmaengine_slave_config(chan, &slv_config); if (err) { - dev_err(i2c_dev->dev, "DMA slave config failed: %d\n", - err); + dev_err(i2c_dev->dev, "DMA config failed: %d\n", err); return err; } @@ -1079,14 +1079,13 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) tegra_i2c_mask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); if (time_left == 0) { - dev_err(i2c_dev->dev, "timed out for bus clear\n"); + dev_err(i2c_dev->dev, "failed to clear bus\n"); return -ETIMEDOUT; } val = i2c_readl(i2c_dev, I2C_BUS_CLEAR_STATUS); if (!(val & I2C_BC_STATUS)) { - dev_err(i2c_dev->dev, - "un-recovered arbitration lost\n"); + dev_err(i2c_dev->dev, "un-recovered arbitration lost\n"); return -EIO; } @@ -1218,12 +1217,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size, DMA_FROM_DEVICE); err = tegra_i2c_dma_submit(i2c_dev, xfer_size); - if (err) { - dev_err(i2c_dev->dev, - "starting RX DMA failed, err %d\n", - err); + if (err) return err; - } } else { dma_sync_single_for_cpu(i2c_dev->dev, @@ -1243,12 +1238,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size, DMA_TO_DEVICE); err = tegra_i2c_dma_submit(i2c_dev, xfer_size); - if (err) { - dev_err(i2c_dev->dev, - "starting TX DMA failed, err %d\n", - err); + if (err) return err; - } } else { tegra_i2c_fill_tx_fifo(i2c_dev); } @@ -1264,7 +1255,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, } tegra_i2c_unmask_irq(i2c_dev, int_mask); - dev_dbg(i2c_dev->dev, "unmasked irq: %02x\n", + dev_dbg(i2c_dev->dev, "unmasked IRQ: %02x\n", i2c_readl(i2c_dev, I2C_INT_MASK)); if (i2c_dev->dma_mode) { @@ -1286,7 +1277,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->tx_dma_chan); if (!time_left && !completion_done(&i2c_dev->dma_complete)) { - dev_err(i2c_dev->dev, "DMA transfer timeout\n"); + dev_err(i2c_dev->dev, "DMA transfer timed out\n"); err = -ETIMEDOUT; goto reset_hardware; } @@ -1307,7 +1298,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, tegra_i2c_mask_irq(i2c_dev, int_mask); if (time_left == 0) { - dev_err(i2c_dev->dev, "i2c transfer timed out\n"); + dev_err(i2c_dev->dev, "I2C transfer timed out\n"); err = -ETIMEDOUT; goto reset_hardware; } From patchwork Tue Sep 8 02:10:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359357 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=l81cf+0H; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpch3Z58z9sR4 for ; Tue, 8 Sep 2020 12:14:28 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728565AbgIHCNo (ORCPT ); Mon, 7 Sep 2020 22:13:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728396AbgIHCMU (ORCPT ); Mon, 7 Sep 2020 22:12:20 -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 E5CA1C061797; Mon, 7 Sep 2020 19:12:06 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id w3so18003237ljo.5; Mon, 07 Sep 2020 19:12:06 -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=s4OxMYUpxrlcvwprS6HxjKIWRXowGXnjPJZcDCzog/A=; b=l81cf+0HznD8alqlUtXXqzHqe7+BbckiDenUb2EZD9Xq4wt0nmTRYVGbDdePbYSmB1 167I/3ko1QV3lHz0BcW7F6OMQnInRquw5n1ow0xdkai0zbq8qsVxWVeg2f9ovzMrg8rj Mn4ej61MXSmRnsjX8Lug/+5rE4Daw9jUKmU46S+6+QUGLYiv0U6ha+j4ygZDF3A0hbts tZujrm6mV0wGAafP6eTczXOcQtmLZySBLHjgn3YX/rMxWaa1rwffzvO3a5ib8bonHND8 l6tNGcqNF2S9KVmSxs2RLMZgOU1zSqwhMJJUp/+weHpr2LKsGeKeXtw7BmfGfcM/vtuA XevQ== 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=s4OxMYUpxrlcvwprS6HxjKIWRXowGXnjPJZcDCzog/A=; b=ag8iYX4KCBubNdpMFY1k5T6kvLE2RXxQopFhN89lxbBeK1Wr5XzgoyK/dnypli0TVb zjubCNJUkaSoKOeYrilMXfPrzSpsbRCQHcosCf2oHBWYLMTwmQ6nN6PfEfV3HjRpdRKn RkvHdH0326iWVehFqhaSIU6vi/4H9a4J6rmymj2+A1Ua4lDEQ7JBLso/hvqu29R/tJ76 tVJyD2WEvQmJy0I6yE/PGwkMVqKZl+m5TTiNxajuTMz02rja9umMTR/0DPWAVQ/Gvr40 MGdwX+/3dRY+Z7/EksHqmJkTH9ivKG3B9hovpgQkwCFDUbNB1aZZOrEMS23ZirRVpPQ9 c3vQ== X-Gm-Message-State: AOAM5337WTrEsQAHMU2nQn+cSKFZCqoREw6mqcOxmljPw6e8bhRhIlJR 4wFnMd7DAyXaxt36iXPa3j4= X-Google-Smtp-Source: ABdhPJx0nfVAgMLqfwSqS3Drn/GW5CfhFfZveTn0FVFYKxwygDNGWLCBG50M+8nEx9+Si9lj4Yn5UA== X-Received: by 2002:a2e:93cd:: with SMTP id p13mr12020958ljh.460.1599531125309; Mon, 07 Sep 2020 19:12:05 -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 j12sm9070085lfj.5.2020.09.07.19.12.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:12:04 -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 v6 33/35] i2c: tegra: Clean up and improve comments Date: Tue, 8 Sep 2020 05:10:19 +0300 Message-Id: <20200908021021.9123-34-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Make all comments to be consistent in regards to capitalization and punctuation, correct spelling and grammar errors, improve wording. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 88 ++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 56a7f696e425..8b2be44cec2f 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -136,7 +136,7 @@ /* configuration load timeout in microseconds */ #define I2C_CONFIG_LOAD_TIMEOUT 1000000 -/* Packet header size in bytes */ +/* packet header size in bytes */ #define I2C_PACKET_HEADER_SIZE 12 /* @@ -148,11 +148,10 @@ #define I2C_PIO_MODE_PREFERRED_LEN 32 /* - * msg_end_type: The bus control which need to be send at end of transfer. - * @MSG_END_STOP: Send stop pulse at end of transfer. - * @MSG_END_REPEAT_START: Send repeat start at end of transfer. - * @MSG_END_CONTINUE: The following on message is coming and so do not send - * stop or repeat start. + * msg_end_type: The bus control which needs to be sent at end of transfer. + * @MSG_END_STOP: Send stop pulse. + * @MSG_END_REPEAT_START: Send repeat-start. + * @MSG_END_CONTINUE: Don't send stop or repeat-start. */ enum msg_end_type { MSG_END_STOP, @@ -161,10 +160,10 @@ enum msg_end_type { }; /** - * struct tegra_i2c_hw_feature : Different HW support on Tegra - * @has_continue_xfer_support: Continue transfer supports. + * struct tegra_i2c_hw_feature : per hardware generation features + * @has_continue_xfer_support: Continue-transfer supported. * @has_per_pkt_xfer_complete_irq: Has enable/disable capability for transfer - * complete interrupt per packet basis. + * completion interrupt on per packet basis. * @has_config_load_reg: Has the config load register to load the new * configuration. * @clk_divisor_hs_mode: Clock divisor in HS mode. @@ -184,7 +183,7 @@ enum msg_end_type { * @has_mst_fifo: The I2C controller contains the new MST FIFO interface that * provides additional features and allows for longer messages to * be transferred in one go. - * @quirks: i2c adapter quirks for limiting write/read transfer size and not + * @quirks: I2C adapter quirks for limiting write/read transfer size and not * allowing 0 length transfers. * @supports_bus_clear: Bus Clear support to recover from bus hang during * SDA stuck low from device for some unknown reasons. @@ -245,7 +244,7 @@ struct tegra_i2c_hw_feature { * @msg_err: error code for completed message * @msg_buf: pointer to current message data * @msg_buf_remaining: size of unsent data in the message buffer - * @msg_read: identifies read transfers + * @msg_read: indicates read direction of a transfer * @bus_clk_rate: current I2C bus clock rate * @multimaster_mode: indicates that I2C controller is in multi-master mode * @tx_dma_chan: DMA transmit channel @@ -306,8 +305,8 @@ static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, u32 reg) } /* - * i2c_writel and i2c_readl will offset the register if necessary to talk - * to the I2C block inside the DVC block + * If necessary, i2c_writel() and i2c_readl() will offset the register + * in order to talk to the I2C block inside the DVC block. */ static u32 tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, u32 reg) { @@ -322,7 +321,7 @@ static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, u32 reg) { writel_relaxed(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); - /* Read back register to make sure that register writes completed */ + /* read back register to make sure that register writes completed */ if (reg != I2C_TX_FIFO) readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); } @@ -474,7 +473,7 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) * block. This block is identical to the rest of the I2C blocks, except that * it only supports master mode, it has registers moved around, and it needs * some extra init to get it into I2C mode. The register moves are handled - * by i2c_readl and i2c_writel + * by i2c_readl() and i2c_writel(). */ static void tegra_dvc_init(struct tegra_i2c_dev *i2c_dev) { @@ -632,7 +631,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) break; } - /* Make sure clock divisor programmed correctly */ + /* make sure clock divisor programmed correctly */ clk_divisor = FIELD_PREP(I2C_CLK_DIVISOR_HSMODE, i2c_dev->hw->clk_divisor_hs_mode) | FIELD_PREP(I2C_CLK_DIVISOR_STD_FAST_MODE, non_hs_mode); @@ -645,8 +644,8 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) } /* - * configure setup and hold times only when tsu_thd is non-zero. - * otherwise, preserve the chip default values + * Configure setup and hold times only when tsu_thd is non-zero. + * Otherwise, preserve the chip default values. */ if (i2c_dev->hw->has_interface_timing_reg && tsu_thd) i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1); @@ -690,7 +689,7 @@ static int tegra_i2c_disable_packet_mode(struct tegra_i2c_dev *i2c_dev) /* * NACK interrupt is generated before the I2C controller generates - * the STOP condition on the bus. So wait for 2 clock periods + * the STOP condition on the bus. So, wait for 2 clock periods * before disabling the controller so that the STOP condition has * been delivered properly. */ @@ -711,8 +710,8 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) u32 val; /* - * Catch overflow due to message fully sent - * before the check for RX FIFO availability. + * Catch overflow due to message fully sent before the check for + * RX FIFO availability. */ if (WARN_ON_ONCE(!(i2c_dev->msg_buf_remaining))) return -EINVAL; @@ -725,7 +724,7 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) rx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_RX, val); } - /* Rounds down to not include partial word at the end of buf */ + /* round down to exclude partial word at the end of buffer */ words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; if (words_to_transfer > rx_fifo_avail) words_to_transfer = rx_fifo_avail; @@ -737,8 +736,8 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) rx_fifo_avail -= words_to_transfer; /* - * If there is a partial word at the end of buf, handle it manually to - * prevent overwriting past the end of buf + * If there is a partial word at the end of buffer, handle it + * manually to prevent overwriting past the end of buffer. */ if (rx_fifo_avail > 0 && buf_remaining > 0) { /* @@ -778,10 +777,15 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) tx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_TX, val); } - /* Rounds down to not include partial word at the end of buf */ + /* round down to exclude partial word at the end of buffer */ words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; - /* It's very common to have < 4 bytes, so optimize that case. */ + /* + * This hunk pushes 4 bytes at a time into the TX FIFO. + * + * It's very common to have < 4 bytes, hence there is no word + * to push if we have less than 4 bytes to transfer. + */ if (words_to_transfer) { if (words_to_transfer > tx_fifo_avail) words_to_transfer = tx_fifo_avail; @@ -805,8 +809,8 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) } /* - * If there is a partial word at the end of buf, handle it manually to - * prevent reading past the end of buf, which could cross a page + * If there is a partial word at the end of buffer, handle it manually + * to prevent reading past the end of buffer, which could cross a page * boundary and fault. */ if (tx_fifo_avail > 0 && buf_remaining > 0) { @@ -854,7 +858,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) } /* - * I2C transfer is terminated during the bus clear so skip + * I2C transfer is terminated during the bus clear, so skip * processing the other interrupts. */ if (i2c_dev->hw->supports_bus_clear && (status & I2C_INT_BUS_CLR_DONE)) @@ -890,7 +894,8 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) * During message read XFER_COMPLETE interrupt is triggered prior to * DMA completion and during message write XFER_COMPLETE interrupt is * triggered after DMA completion. - * PACKETS_XFER_COMPLETE indicates completion of all bytes of transfer. + * + * PACKETS_XFER_COMPLETE indicates completion of all bytes of transfer, * so forcing msg_buf_remaining to 0 in DMA mode. */ if (status & I2C_INT_PACKET_XFER_COMPLETE) { @@ -908,7 +913,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) } goto done; err: - /* An error occurred, mask all interrupts */ + /* mask all interrupts on error */ tegra_i2c_mask_irq(i2c_dev, I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST | I2C_INT_PACKET_XFER_COMPLETE | I2C_INT_TX_FIFO_DATA_REQ | I2C_INT_RX_FIFO_DATA_REQ); @@ -1338,6 +1343,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], enum msg_end_type end_type = MSG_END_STOP; if (i < (num - 1)) { + /* check whether follow up message is coming */ if (msgs[i + 1].flags & I2C_M_NOSTART) end_type = MSG_END_CONTINUE; else @@ -1567,7 +1573,6 @@ static const struct tegra_i2c_hw_feature tegra194_i2c_hw = { .has_interface_timing_reg = true, }; -/* Match table for of_platform binding */ static const struct of_device_id tegra_i2c_of_match[] = { { .compatible = "nvidia,tegra194-i2c", .data = &tegra194_i2c_hw, }, { .compatible = "nvidia,tegra186-i2c", .data = &tegra186_i2c_hw, }, @@ -1591,7 +1596,7 @@ static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) err = of_property_read_u32(np, "clock-frequency", &i2c_dev->bus_clk_rate); if (err) - i2c_dev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */ + i2c_dev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; multi_mode = of_property_read_bool(np, "multi-master"); i2c_dev->multimaster_mode = multi_mode; @@ -1723,11 +1728,13 @@ static int tegra_i2c_probe(struct platform_device *pdev) goto release_clocks; /* - * VI I2C is in VE power domain which is not always on and not - * an IRQ safe. So, IRQ safe device can't be attached to a non-IRQ - * safe domain as it prevents powering off the PM domain. - * Also, VI I2C device don't need to use runtime IRQ safe as it will - * not be used for atomic transfers. + * VI I2C is in VE power domain which is not always ON and not + * IRQ-safe. Thus, IRQ-safe device shouldn't be attached to a + * non IRQ-safe domain because this prevents powering off the power + * domain. + * + * VI I2C device shouldn't be marked as IRQ-safe because VI I2C won't + * be used for atomic transfers. */ if (!i2c_dev->is_vi) pm_runtime_irq_safe(i2c_dev->dev); @@ -1800,9 +1807,8 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev) /* * VI I2C device is attached to VE power domain which goes through - * power ON/OFF during PM runtime resume/suspend. So, controller - * should go through reset and need to re-initialize after power - * domain ON. + * power ON/OFF during of runtime PM resume/suspend, meaning that + * controller needs to be re-initialized after power ON. */ if (i2c_dev->is_vi) { err = tegra_i2c_init(i2c_dev); From patchwork Tue Sep 8 02:10:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359348 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=cdS5U2lW; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpbs3V4cz9sTW for ; Tue, 8 Sep 2020 12:13:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728348AbgIHCNo (ORCPT ); Mon, 7 Sep 2020 22:13:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728213AbgIHCMb (ORCPT ); Mon, 7 Sep 2020 22:12:31 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C45E2C0617A9; Mon, 7 Sep 2020 19:12:07 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id z17so8278365lfi.12; Mon, 07 Sep 2020 19:12: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=DbQyWM7oycl0co92zuB2RA/14+46Ead6WBoTQN24xgA=; b=cdS5U2lWgm9VfIcvb82p6jUCNW8fO5lfhQSI4BMacgyXplBlGCCfxqBhxFGHvm6KBR 3L6LtBgvB7q14vMhuiwSCJnRHgi76qfeGSPc8OotWeVutevKJKuzJywyBVU0w0GpuAMV MrSyfUbYxlCNNJfhgEu8QqyDfPzcSaQmVCzU8oUm1ziqzLcdqqWYtgandqYl5k76X1j+ GIGVOmzHwkH8KLy8PeoyYDqABEVTG4gxQgYlILvEg4uRTLhwKgJrYQj8etj8zwjH0yEu 3c6dYFF419iec3jj2tVt8tXyVADXWdPSO913+z6LeVRnlA0Iwb1ED14m2xHI4H4yndoj XYhA== 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=DbQyWM7oycl0co92zuB2RA/14+46Ead6WBoTQN24xgA=; b=nNuTgY2XnwSL9xZ0bhQ5DMndeAD73eInY/4XGWjqnTQNlfWRHQzr7wNvp/9lpg6QBj uv2vn97gILbdRFD2MmldXxg0hCvKgOsgaTDicEt9q7VMZIgpoPWDFgfhOVvbUr3W3Ico AAoSjTCAAZ298dhEmworPA3DELTRTfglUW32slDilN2KcCeLC09YLE3nSF6fggJ4toUq yV0o5Lu8yq1w4/iNQpngNAzKluD8F+HrWqU65IozBCve4Qop4D6IcaqF9JPWWBik3JGx ZImWRhUUAACXn8a+uKKyw9tyJUKgoxol3NUV/tgS2+9uh/vk7hczMUCL8SqEHXJLuHN5 i7cw== X-Gm-Message-State: AOAM531sBfkMD7OrD/07TezwJAEzHdemtZs6UN7Febqs1w2HiHbncbUn fOc9qY7mwdgHeCTRi7MOuaU= X-Google-Smtp-Source: ABdhPJygSNtBfq/PNPkYIi3pL007WuF16ob5y5CVjJqtBISWpJifx6xmFZi8xq5CYktEzje5w0UVDQ== X-Received: by 2002:a19:7fd8:: with SMTP id a207mr11288005lfd.11.1599531126219; Mon, 07 Sep 2020 19:12: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 j12sm9070085lfj.5.2020.09.07.19.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:12: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 v6 34/35] i2c: tegra: Clean up whitespaces, newlines and indentation Date: Tue, 8 Sep 2020 05:10:20 +0300 Message-Id: <20200908021021.9123-35-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Some places in the code are missing newlines or have unnecessary whitespaces and newlines. This creates inconsistency of the code and hurts readability. This patch removes the unnecessary and adds necessary whitespaces / newlines, clears indentation of the code. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 72 +++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 8b2be44cec2f..179d4bb66ae8 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -314,6 +314,7 @@ static u32 tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, u32 reg) reg += (reg >= I2C_TX_FIFO) ? 0x10 : 0x40; else if (i2c_dev->is_vi) reg = 0xc00 + (reg << 2); + return reg; } @@ -373,9 +374,12 @@ static int tegra_i2c_dma_submit(struct tegra_i2c_dev *i2c_dev, size_t len) struct dma_chan *chan; dev_dbg(i2c_dev->dev, "starting DMA for length: %zu\n", len); + reinit_completion(&i2c_dev->dma_complete); + dir = i2c_dev->msg_read ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV; chan = i2c_dev->msg_read ? i2c_dev->rx_dma_chan : i2c_dev->tx_dma_chan; + dma_desc = dmaengine_prep_slave_single(chan, i2c_dev->dma_phys, len, dir, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); @@ -387,8 +391,10 @@ static int tegra_i2c_dma_submit(struct tegra_i2c_dev *i2c_dev, size_t len) dma_desc->callback = tegra_i2c_dma_complete; dma_desc->callback_param = i2c_dev; + dmaengine_submit(dma_desc); dma_async_issue_pending(chan); + return 0; } @@ -557,6 +563,7 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) dev_err(i2c_dev->dev, "failed to flush FIFO\n"); return err; } + return 0; } @@ -650,8 +657,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) if (i2c_dev->hw->has_interface_timing_reg && tsu_thd) i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1); - clk_multiplier = tlow + thigh + 2; - clk_multiplier *= non_hs_mode + 1; + clk_multiplier = (tlow + thigh + 2) * (non_hs_mode + 1); err = clk_set_rate(i2c_dev->div_clk, i2c_dev->bus_clk_rate * clk_multiplier); @@ -799,9 +805,9 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) */ buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; tx_fifo_avail -= words_to_transfer; + i2c_dev->msg_buf_remaining = buf_remaining; - i2c_dev->msg_buf = buf + - words_to_transfer * BYTES_PER_FIFO_WORD; + i2c_dev->msg_buf = buf + words_to_transfer * BYTES_PER_FIFO_WORD; i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer); @@ -914,12 +920,18 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) goto done; err: /* mask all interrupts on error */ - tegra_i2c_mask_irq(i2c_dev, I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST | - I2C_INT_PACKET_XFER_COMPLETE | I2C_INT_TX_FIFO_DATA_REQ | - I2C_INT_RX_FIFO_DATA_REQ); + tegra_i2c_mask_irq(i2c_dev, + I2C_INT_NO_ACK | + I2C_INT_ARBITRATION_LOST | + I2C_INT_PACKET_XFER_COMPLETE | + I2C_INT_TX_FIFO_DATA_REQ | + I2C_INT_RX_FIFO_DATA_REQ); + if (i2c_dev->hw->supports_bus_clear) tegra_i2c_mask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); + i2c_writel(i2c_dev, status, I2C_INT_STATUS); + if (i2c_dev->is_dvc) dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS); @@ -960,6 +972,7 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) if (i2c_dev->msg_read) { chan = i2c_dev->rx_dma_chan; reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_RX_FIFO); + slv_config.src_addr = i2c_dev->base_phys + reg_offset; slv_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; slv_config.src_maxburst = dma_burst; @@ -971,6 +984,7 @@ static int tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, size_t len) } else { chan = i2c_dev->tx_dma_chan; reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_TX_FIFO); + slv_config.dst_addr = i2c_dev->base_phys + reg_offset; slv_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; slv_config.dst_maxburst = dma_burst; @@ -1067,6 +1081,7 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) int err; reinit_completion(&i2c_dev->msg_complete); + val = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND | I2C_BC_TERMINATE; i2c_writel(i2c_dev, val, I2C_BUS_CLEAR_CNFG); @@ -1199,7 +1214,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size = msg->len + I2C_PACKET_HEADER_SIZE; xfer_size = ALIGN(xfer_size, BYTES_PER_FIFO_WORD); - i2c_dev->dma_mode = (xfer_size > I2C_PIO_MODE_PREFERRED_LEN) && + + i2c_dev->dma_mode = xfer_size > I2C_PIO_MODE_PREFERRED_LEN && i2c_dev->dma_buf && !i2c_dev->atomic_mode; err = tegra_i2c_config_fifo_trig(i2c_dev, xfer_size); @@ -1211,25 +1227,24 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, * Total bits = 9 bits per byte (including ACK bit) + Start & stop bits */ xfer_time += DIV_ROUND_CLOSEST(((xfer_size * 9) + 2) * MSEC_PER_SEC, - i2c_dev->bus_clk_rate); + i2c_dev->bus_clk_rate); int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; tegra_i2c_unmask_irq(i2c_dev, int_mask); + if (i2c_dev->dma_mode) { if (i2c_dev->msg_read) { dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, - xfer_size, - DMA_FROM_DEVICE); + xfer_size, DMA_FROM_DEVICE); + err = tegra_i2c_dma_submit(i2c_dev, xfer_size); if (err) return err; - } else { dma_sync_single_for_cpu(i2c_dev->dev, i2c_dev->dma_phys, - xfer_size, - DMA_TO_DEVICE); + xfer_size, DMA_TO_DEVICE); } } @@ -1238,10 +1253,11 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (!i2c_dev->msg_read) { if (i2c_dev->dma_mode) { memcpy(i2c_dev->dma_buf, msg->buf, msg->len); + dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, - xfer_size, - DMA_TO_DEVICE); + xfer_size, DMA_TO_DEVICE); + err = tegra_i2c_dma_submit(i2c_dev, xfer_size); if (err) return err; @@ -1252,6 +1268,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (i2c_dev->hw->has_per_pkt_xfer_complete_irq) int_mask |= I2C_INT_PACKET_XFER_COMPLETE; + if (!i2c_dev->dma_mode) { if (msg->flags & I2C_M_RD) int_mask |= I2C_INT_RX_FIFO_DATA_REQ; @@ -1290,10 +1307,9 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, if (i2c_dev->msg_read && i2c_dev->msg_err == I2C_ERR_NONE) { dma_sync_single_for_cpu(i2c_dev->dev, i2c_dev->dma_phys, - xfer_size, - DMA_FROM_DEVICE); - memcpy(i2c_dev->msg_buf, i2c_dev->dma_buf, - msg->len); + xfer_size, DMA_FROM_DEVICE); + + memcpy(i2c_dev->msg_buf, i2c_dev->dma_buf, msg->len); } } @@ -1380,6 +1396,7 @@ static u32 tegra_i2c_func(struct i2c_adapter *adap) if (i2c_dev->hw->has_continue_xfer_support) ret |= I2C_FUNC_NOSTART; + return ret; } @@ -1784,11 +1801,11 @@ static int tegra_i2c_remove(struct platform_device *pdev) struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev); i2c_del_adapter(&i2c_dev->adapter); - - pm_runtime_disable(&pdev->dev); + pm_runtime_disable(i2c_dev->dev); tegra_i2c_release_dma(i2c_dev); tegra_i2c_release_clocks(i2c_dev); + return 0; } @@ -1886,15 +1903,14 @@ static const struct dev_pm_ops tegra_i2c_pm = { }; static struct platform_driver tegra_i2c_driver = { - .probe = tegra_i2c_probe, - .remove = tegra_i2c_remove, - .driver = { - .name = "tegra-i2c", + .probe = tegra_i2c_probe, + .remove = tegra_i2c_remove, + .driver = { + .name = "tegra-i2c", .of_match_table = tegra_i2c_of_match, - .pm = &tegra_i2c_pm, + .pm = &tegra_i2c_pm, }, }; - module_platform_driver(tegra_i2c_driver); MODULE_DESCRIPTION("nVidia Tegra2 I2C Bus Controller driver"); From patchwork Tue Sep 8 02:10:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1359358 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=maek0TmK; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Blpcj0VS1z9sTM for ; Tue, 8 Sep 2020 12:14:29 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728537AbgIHCNn (ORCPT ); Mon, 7 Sep 2020 22:13:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728158AbgIHCMb (ORCPT ); Mon, 7 Sep 2020 22:12:31 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93B1DC0617AA; Mon, 7 Sep 2020 19:12:08 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id a22so11626314ljp.13; Mon, 07 Sep 2020 19:12: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=UPDOYzKqS621N5af7uifqlaDWkOlluvKF6+RkvUgMCU=; b=maek0TmKuA7rhalDld3NkXKqhxRaTLx7wRj05LNTOXpneZ1XILD6AiEL/QFw7sHUj4 a6NytJZCjDq5T6k/MmNHdGWoZGsmfORjtNWzlfmJRG3pgdZDTUOvRwwCTy4vtmGUlMz9 m3BsHXBz9d8StOF/PYjqw60GUt+Ei7irBDgReyRYajl0ITsj43nRzRBTbTRXbSRl/CHB wDRj2SRwiNYJXksd8W1ys0606z6RfyVUM2213fD4xgimsBh2a4PAVN5h3L3j+q+6YZKE 3CKrqKxBNcHsOzpycnsHr5oEh8TWWS+0ZPiOw2km2dH3TkRCD+44kiT8uj1ER9Op0jI9 NDGw== 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=UPDOYzKqS621N5af7uifqlaDWkOlluvKF6+RkvUgMCU=; b=OMr/MxERjiFTcp8YgR0Th+SESrGhzC11BLqLJ4YzTWHHscmciuhdmJxvVDPhycgvtg G6xAGbtX/hmadxFfdWKPBauGg2fWZ1VS+3Yd45s/4WAf8mhaVlZYKwEfl11BJa/dLr0A xYHubQDdZ32dbZTjnUvmSlr/AvVIo4DrT/8UnqqTU06up1pMXaAGh5Q5Lr0qoy8N2Vxp nbn2xzldFe/Wd/5+tW7J9ZdztCsXjJVx8yHb4YDOBgLws11Jj6XlSCCmbn5br5eFYS8n N8maoM3Puc/B2buW4TC4L8H4i0uCnqea7QlaJFWBSGGKWxmDpMfWVaDKSK3SE3wXKWAX 8ZpA== X-Gm-Message-State: AOAM530HfF8iJrLaSkRa4UQgM/4aysXIPTf9px71goHWc6obMw6dwhaG x+i7OjStMN55yW4PMHgJykI= X-Google-Smtp-Source: ABdhPJy3VtKROhEMDA00gVM33KriqCJ2racvGAk/Kh4WSLSvCRP/AsATyKnp+OmbLokZ9yYQkgS59Q== X-Received: by 2002:a2e:9785:: with SMTP id y5mr5920472lji.452.1599531127119; Mon, 07 Sep 2020 19:12: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 j12sm9070085lfj.5.2020.09.07.19.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 19:12: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 v6 35/35] i2c: tegra: Improve driver module description Date: Tue, 8 Sep 2020 05:10:21 +0300 Message-Id: <20200908021021.9123-36-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200908021021.9123-1-digetx@gmail.com> References: <20200908021021.9123-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Use proper spelling of "NVIDIA" and don't designate driver as Tegra2-only since newer SoC generations are supported as well. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- 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 179d4bb66ae8..a7ca3eee525c 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1913,6 +1913,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");