From patchwork Sat Dec 28 22:16:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1215962 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; 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.b="kYYx9FZx"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47ldNp16cdz9sPh for ; Sun, 29 Dec 2019 09:17:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726425AbfL1WRX (ORCPT ); Sat, 28 Dec 2019 17:17:23 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:40399 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726132AbfL1WRW (ORCPT ); Sat, 28 Dec 2019 17:17:22 -0500 Received: by mail-lj1-f194.google.com with SMTP id u1so29973002ljk.7; Sat, 28 Dec 2019 14:17:20 -0800 (PST) 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=0wDGXuY18A0/+zgWOUGjS7EoingM7KoaMm0Na+dcu9U=; b=kYYx9FZxeN72Vkix7fn42y+fx6VD9koyBQKVPBVJNxi4E4a/4cGXB7/urmcky01/5o 6KTud2TjDqGlBz/B/uN94R4CmJ4EELR+yeOlX+wY/RaHuABSePMD4yDMIhz/GHl2gG1y Z8pai+0ym9waVnqDZ0V8BpIcJW3BYmfxbzyI615y9LVziVLkZneMomsdndCdZzAjZvTV dQt+J5GUz7Z3N3A13HuxDho4m7xuzhuDvRUFc1uyfu5svhlGN93ViY/9vztKeXykN1cB ilMOCrPAelXTvX36q6V/YRPGb0W1TuhHHCoTq1Za7ohk/JPHjGP5GrIPTdhyL1hcHyBH hWew== 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=0wDGXuY18A0/+zgWOUGjS7EoingM7KoaMm0Na+dcu9U=; b=XjbIVjxVi5aDwE8SkwZGPfttBH+SiVFft7sipo43xjJjktazGXPzzTTaSXmzQvUFWl tTp26+p65pI9CrOOHtnEsOMS9CaCvjk4qY4mkeUMB5irwL+sO8tOeQwgNLgAE7DmsRwW PEjMhKstOg316/fD9/H30Rupvv5lS18yfeC0Pkk8/FOj7gU6Fh3+7RMcf9YoyixoDQmA RzfAAzctGNETxJsott6pyrhjNo7cYpyWDAHRX3X4mQADqMsuZEK2RGzolz/6igyZoCJ8 dv/DuTwz+TeBeFMSFinrcJmGDkj314hj//GBUnL6/y0Nh/EOcUIBxyyatYZ+Hrj+s/wL zptA== X-Gm-Message-State: APjAAAVh5F4v/jzKka8lZyi5FUouG0GBHonKIokPALwKrp/Fq32MElR3 icAjqOc/frQJZoZqx0IKF2Q= X-Google-Smtp-Source: APXvYqxps+Uo2YCxjkG2qDWaRiB1uO9CTn0y+Cu94BMp4r0e4BTp8sAR342uHdgyvUWNR4OxvweOYQ== X-Received: by 2002:a2e:b4ef:: with SMTP id s15mr24877542ljm.20.1577571440065; Sat, 28 Dec 2019 14:17:20 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id y10sm15209584ljm.93.2019.12.28.14.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 14:17:19 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Mikko Perttunen , Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/6] i2c: tegra: Fix suspending in active runtime PM state Date: Sun, 29 Dec 2019 01:16:49 +0300 Message-Id: <20191228221654.28842-2-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228221654.28842-1-digetx@gmail.com> References: <20191228221654.28842-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 I noticed that sometime I2C clock is kept enabled during suspend-resume. This happens because runtime PM defers dynamic suspension and thus it may happen that runtime PM is in active state when system enters into suspend. In particular I2C controller that is used for CPU's DVFS is often kept ON during suspend because CPU's voltage scaling happens quite often. Fixes: 8ebf15e9c869 ("i2c: tegra: Move suspend handling to NOIRQ phase") Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index a98bf31d0e5c..79d19f6ce94e 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1710,9 +1710,14 @@ static int tegra_i2c_remove(struct platform_device *pdev) static int __maybe_unused tegra_i2c_suspend(struct device *dev) { struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); + int err; i2c_mark_adapter_suspended(&i2c_dev->adapter); + err = pm_runtime_force_suspend(dev); + if (err < 0) + return err; + return 0; } @@ -1733,6 +1738,10 @@ static int __maybe_unused tegra_i2c_resume(struct device *dev) if (err) return err; + err = pm_runtime_force_resume(dev); + if (err < 0) + return err; + i2c_mark_adapter_resumed(&i2c_dev->adapter); return 0; From patchwork Sat Dec 28 22:16:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1215960 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; 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.b="j8SItEMS"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47ldNm4Gbnz9sPh for ; Sun, 29 Dec 2019 09:17:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726573AbfL1WRX (ORCPT ); Sat, 28 Dec 2019 17:17:23 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:42231 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726187AbfL1WRX (ORCPT ); Sat, 28 Dec 2019 17:17:23 -0500 Received: by mail-lj1-f194.google.com with SMTP id y4so15634624ljj.9; Sat, 28 Dec 2019 14:17:21 -0800 (PST) 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=MxLj3sMjbJSVDQh/qIpP3HDKKCaIdKkelMGqwQ8Ieqs=; b=j8SItEMSnkuexrk3ygept1Ikflg2UCy4z3shNl1sOyCbLaQXEKyoVKCTUbNrbVDu4b u9soOKcWDTMVl1fXrmtcbbc0Pd7Bf1MnQzvxY/EvqMPnEFan2FcT6fjtW0+ehzBi9qBn w3vuoycPYVJ6qRoF3L1blkTsXpEFjMaNFLOWcDTToqTmX9gfyOEjPTPmLUQlv8tqrr1d YI9L/LN1UZW6Urv53bbKL8B/6jQc1+EXvEE40f7kD5y1EwpOpVOFsxnhiCsWgV8W2jDO kETmbyaCkwAo0sYCR+ITk9zo7uKARJSLeubzLQ+jl+0gXST0tgdlrsVxMDmkeK5pK8+G 8SBQ== 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=MxLj3sMjbJSVDQh/qIpP3HDKKCaIdKkelMGqwQ8Ieqs=; b=a6hJIQINeBsfJgMBM6WgcHy+2vxbJtLkOCX5EGptC77rr5UhcAxN6BsfddyIIjtXZN /VPqZEOiCWsdclOFEV2YVF82dVKV4cpl1vKkr1TrAyQSl6LjFxqoA1FWS0BNYii8+Yzb 5BIEEv3aJFIqCHzjHng8GaDIXcxkMiJ21ag0FdyjFMz3K7daye9QSZy222mqxdR3Ie91 A3UvCTDEx9WtJUCsBri0HSka69adbrWopL0OnDdmmoHXAAUHgXoZQPQza9MfCwtMfv1S PPvbgRD2hME7V2KxC/PZlA3orU3V6ADUdlLxLqJ0RiXdyShpsK+wQR/oyMZRcJtc2awj nNFw== X-Gm-Message-State: APjAAAWFbpUoxrYC2TR/y4qTV5wIRMcwQLK6eAboWfHkAoTJsurqDGaI DWV29/uEFBsi+V7nLIRWnvw= X-Google-Smtp-Source: APXvYqz2UYufujkccZrYCSW4CQDkHD7h1MJivFIobvUU0taFhuMlKquz1RYI6G3KhPSCnICcREImSw== X-Received: by 2002:a2e:b054:: with SMTP id d20mr18985619ljl.190.1577571440874; Sat, 28 Dec 2019 14:17:20 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id y10sm15209584ljm.93.2019.12.28.14.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 14:17:20 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Mikko Perttunen , Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] i2c: tegra: Properly disable runtime PM on driver's probe error Date: Sun, 29 Dec 2019 01:16:50 +0300 Message-Id: <20191228221654.28842-3-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228221654.28842-1-digetx@gmail.com> References: <20191228221654.28842-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 One of the recent Tegra I2C commits made a change that resumes runtime PM during driver's probe, but it missed to put the RPM in a case of error. Note that it's not correct to use pm_runtime_status_suspended because it breaks RPM refcounting. Fixes: 8ebf15e9c869 ("i2c: tegra: Move suspend handling to NOIRQ phase") Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 79d19f6ce94e..61339c665ebd 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1608,14 +1608,18 @@ static int tegra_i2c_probe(struct platform_device *pdev) } pm_runtime_enable(&pdev->dev); - if (!pm_runtime_enabled(&pdev->dev)) + if (!pm_runtime_enabled(&pdev->dev)) { ret = tegra_i2c_runtime_resume(&pdev->dev); - else + 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 unprepare_div_clk; + if (ret < 0) { + dev_err(&pdev->dev, "runtime resume failed\n"); + goto disable_rpm; + } } if (i2c_dev->is_multimaster_mode) { @@ -1623,7 +1627,7 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (ret < 0) { dev_err(i2c_dev->dev, "div_clk enable failed %d\n", ret); - goto disable_rpm; + goto put_rpm; } } @@ -1671,11 +1675,16 @@ static int tegra_i2c_probe(struct platform_device *pdev) if (i2c_dev->is_multimaster_mode) clk_disable(i2c_dev->div_clk); -disable_rpm: - pm_runtime_disable(&pdev->dev); - if (!pm_runtime_status_suspended(&pdev->dev)) +put_rpm: + if (pm_runtime_enabled(&pdev->dev)) + pm_runtime_put_sync(&pdev->dev); + else tegra_i2c_runtime_suspend(&pdev->dev); +disable_rpm: + if (pm_runtime_enabled(&pdev->dev)) + pm_runtime_disable(&pdev->dev); + unprepare_div_clk: clk_unprepare(i2c_dev->div_clk); From patchwork Sat Dec 28 22:16:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1215958 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; 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.b="rr17o3pt"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47ldNl1sP2z9sR8 for ; Sun, 29 Dec 2019 09:17:43 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726635AbfL1WRZ (ORCPT ); Sat, 28 Dec 2019 17:17:25 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:34044 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726377AbfL1WRY (ORCPT ); Sat, 28 Dec 2019 17:17:24 -0500 Received: by mail-lj1-f194.google.com with SMTP id z22so25176583ljg.1; Sat, 28 Dec 2019 14:17:22 -0800 (PST) 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=8PkL5bnd0pmXf+lkKaCySAWexDYLt7K2/IiWjav9yI0=; b=rr17o3ptdySlIAOsSTUAFPlvdeiBy6sHxiENcbpcn+8e81kTpCwI3IGkT96irGP+Ox IEDMlfJeaUPEgrcYbAN46SN1ZCa5mI2zIISXWUBrSuTUknAjrCfQmxhH5mmLrqZ00hI7 gqQVGuM+eWkpGa+R62DtE17HcIXxILoL7q45jtP0zbpPGFJBH5krcr6rg1dgeUwSWg4u Q8v3xMYyDf0CGxz1/aYQFoU2NmAKzd6ic93bzYsTV53t9fOualOrXdHTwNU80/LYZDlZ lOHyjTjC/kMK+k8cg2OVS4IABfIt3HCD2848Bj1eBtJ9VYsAdXaOKO6UTDN7oCXkCNgc BZlg== 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=8PkL5bnd0pmXf+lkKaCySAWexDYLt7K2/IiWjav9yI0=; b=X/JM4YeUFvSEyAtDps5ibalm2LitxITTOzxWKKiSlHt7dQhPVtmBbjpJLig8wNaMWk SnDITIDOOBYDHIXZh8gA5Q5iCUdIfzlNzlqN3zo2kwUWyHUkK2zGyrDmWU2bZ84xVPZY SG9Ie5ZUePCwO5yaUubXko19uHX5wZ+Bs13b/5b8x14rq5eG2jUfwOMf+D6uptmGZ/4N E48eRuz/yx7hUhrtHbbdZor8/QnNwQeSgnA+0xOiXLIcBpN19j/ZSEZEmlbJR0L/5QZ0 pnyexNd+iiYt5yHQFdMenejkPdSNvI6QrWVhsLBT2we1b9+84qlw0XHKOJx6LWejKqjG DHTg== X-Gm-Message-State: APjAAAWuUqwR8nZkPNK6rwjftxRFk+ydqsqFhc6dQwDTUh/t8IdXT3iT PmLhkuA+0oJ/6LVT6Uur3WA= X-Google-Smtp-Source: APXvYqx+oQBWsr9XHvS9ZdI3Ub6LoFmOe9gRcE32B7j5yZPmQ3A+73pmuaUXmO1Yxakku2E8/LT7gg== X-Received: by 2002:a2e:800b:: with SMTP id j11mr29205171ljg.126.1577571441808; Sat, 28 Dec 2019 14:17:21 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id y10sm15209584ljm.93.2019.12.28.14.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 14:17:21 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Mikko Perttunen , Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] i2c: tegra: Prevent interrupt triggering after transfer timeout Date: Sun, 29 Dec 2019 01:16:51 +0300 Message-Id: <20191228221654.28842-4-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228221654.28842-1-digetx@gmail.com> References: <20191228221654.28842-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 Potentially it is possible that interrupt may fire after transfer timeout. That may not end up well for the next transfer because interrupt handling may race with hardware resetting. This is very unlikely to happen in practice, but anyway let's prevent the potential problem by enabling interrupt only at the moments when it is actually necessary to get some interrupt event. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 69 +++++++++++++++++----------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 61339c665ebd..3016fd3eb064 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -230,7 +231,6 @@ struct tegra_i2c_hw_feature { * @base_phys: physical base address of the I2C controller * @cont_id: I2C controller ID, used for packet header * @irq: IRQ number of transfer complete interrupt - * @irq_disabled: used to track whether or not the interrupt is enabled * @is_dvc: identifies the DVC I2C controller, has a different register layout * @msg_complete: transfer completion notifier * @msg_err: error code for completed message @@ -240,7 +240,6 @@ struct tegra_i2c_hw_feature { * @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 - * @xfer_lock: lock to serialize transfer submission and processing * @tx_dma_chan: DMA transmit channel * @rx_dma_chan: DMA receive channel * @dma_phys: handle to DMA resources @@ -260,7 +259,6 @@ struct tegra_i2c_dev { phys_addr_t base_phys; int cont_id; int irq; - bool irq_disabled; int is_dvc; struct completion msg_complete; int msg_err; @@ -270,8 +268,6 @@ struct tegra_i2c_dev { u32 bus_clk_rate; u16 clk_divisor_non_hs_mode; bool is_multimaster_mode; - /* xfer_lock: lock to serialize transfer submission and processing */ - spinlock_t xfer_lock; struct dma_chan *tx_dma_chan; struct dma_chan *rx_dma_chan; dma_addr_t dma_phys; @@ -790,11 +786,6 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit) if (err) return err; - if (i2c_dev->irq_disabled) { - i2c_dev->irq_disabled = false; - enable_irq(i2c_dev->irq); - } - return 0; } @@ -825,18 +816,12 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) status = i2c_readl(i2c_dev, I2C_INT_STATUS); - spin_lock(&i2c_dev->xfer_lock); if (status == 0) { 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)); i2c_dev->msg_err |= I2C_ERR_UNKNOWN_INTERRUPT; - - if (!i2c_dev->irq_disabled) { - disable_irq_nosync(i2c_dev->irq); - i2c_dev->irq_disabled = true; - } goto err; } @@ -925,7 +910,6 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) complete(&i2c_dev->msg_complete); done: - spin_unlock(&i2c_dev->xfer_lock); return IRQ_HANDLED; } @@ -999,6 +983,21 @@ static void tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, i2c_writel(i2c_dev, val, reg); } +static unsigned long +tegra_i2c_wait_completion_timeout(struct tegra_i2c_dev *i2c_dev, + struct completion *complete, + unsigned int timeout_ms) +{ + unsigned long timeout = msecs_to_jiffies(timeout_ms); + unsigned long ret; + + enable_irq(i2c_dev->irq); + ret = wait_for_completion_timeout(complete, timeout); + disable_irq(i2c_dev->irq); + + return ret; +} + static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) { struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); @@ -1020,8 +1019,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 = wait_for_completion_timeout(&i2c_dev->msg_complete, - msecs_to_jiffies(50)); + time_left = tegra_i2c_wait_completion_timeout( + i2c_dev, &i2c_dev->msg_complete, 50); if (time_left == 0) { dev_err(i2c_dev->dev, "timed out for bus clear\n"); return -ETIMEDOUT; @@ -1044,7 +1043,6 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, u32 packet_header; u32 int_mask; unsigned long time_left; - unsigned long flags; size_t xfer_size; u32 *buffer = NULL; int err = 0; @@ -1075,7 +1073,6 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, */ xfer_time += DIV_ROUND_CLOSEST(((xfer_size * 9) + 2) * MSEC_PER_SEC, i2c_dev->bus_clk_rate); - spin_lock_irqsave(&i2c_dev->xfer_lock, flags); int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; tegra_i2c_unmask_irq(i2c_dev, int_mask); @@ -1090,7 +1087,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, dev_err(i2c_dev->dev, "starting RX DMA failed, err %d\n", err); - goto unlock; + return err; } } else { @@ -1149,7 +1146,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, dev_err(i2c_dev->dev, "starting TX DMA failed, err %d\n", err); - goto unlock; + return err; } } else { tegra_i2c_fill_tx_fifo(i2c_dev); @@ -1169,15 +1166,10 @@ 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)); -unlock: - spin_unlock_irqrestore(&i2c_dev->xfer_lock, flags); - if (dma) { - if (err) - return err; + time_left = tegra_i2c_wait_completion_timeout( + i2c_dev, &i2c_dev->dma_complete, xfer_time); - time_left = wait_for_completion_timeout(&i2c_dev->dma_complete, - msecs_to_jiffies(xfer_time)); if (time_left == 0) { dev_err(i2c_dev->dev, "DMA transfer timeout\n"); dmaengine_terminate_sync(i2c_dev->msg_read ? @@ -1202,15 +1194,21 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->tx_dma_chan); } - time_left = wait_for_completion_timeout(&i2c_dev->msg_complete, - msecs_to_jiffies(xfer_time)); + time_left = tegra_i2c_wait_completion_timeout( + i2c_dev, &i2c_dev->msg_complete, xfer_time); + tegra_i2c_mask_irq(i2c_dev, int_mask); if (time_left == 0) { dev_err(i2c_dev->dev, "i2c transfer timed out\n"); - tegra_i2c_init(i2c_dev, true); - return -ETIMEDOUT; + if (completion_done(&i2c_dev->msg_complete)) { + dev_err(i2c_dev->dev, + "i2c transfer completed after time out\n"); + } else { + tegra_i2c_init(i2c_dev, true); + return -ETIMEDOUT; + } } dev_dbg(i2c_dev->dev, "transfer complete: %lu %d %d\n", @@ -1568,7 +1566,6 @@ static int tegra_i2c_probe(struct platform_device *pdev) I2C_PACKET_HEADER_SIZE; init_completion(&i2c_dev->msg_complete); init_completion(&i2c_dev->dma_complete); - spin_lock_init(&i2c_dev->xfer_lock); if (!i2c_dev->hw->has_single_clk_source) { fast_clk = devm_clk_get(&pdev->dev, "fast-clk"); @@ -1644,6 +1641,8 @@ static int tegra_i2c_probe(struct platform_device *pdev) goto release_dma; } + irq_set_status_flags(i2c_dev->irq, IRQ_NOAUTOEN); + ret = devm_request_irq(&pdev->dev, i2c_dev->irq, tegra_i2c_isr, 0, dev_name(&pdev->dev), i2c_dev); if (ret) { From patchwork Sat Dec 28 22:16:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1215954 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; 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.b="GgH/cF2Z"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47ldNh2Y6rz9sRQ for ; Sun, 29 Dec 2019 09:17:40 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726744AbfL1WR1 (ORCPT ); Sat, 28 Dec 2019 17:17:27 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:42233 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726080AbfL1WR0 (ORCPT ); Sat, 28 Dec 2019 17:17:26 -0500 Received: by mail-lj1-f193.google.com with SMTP id y4so15634662ljj.9; Sat, 28 Dec 2019 14:17:23 -0800 (PST) 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=CA3YysOV48ZQEIFKJbrKCjOeXv6vJ029j2x+Bkp1Iz8=; b=GgH/cF2ZHO67JAknsvltrNV1nmeTrYTFgnfETMHu1DtIKf9ECsJsP3p4KvSaX0rOYN P5+pyNhHFqDLRcX8StQZ50GGXQs0bOuXVaD9LPC3AfRNWEHPyG/5idIgQ1oruopoCOX3 +mG4/ukcPw24F+I0MUUNHXNUI1K+gSN5LRJk46ampjz5QpW1yq+shx/wwHrI5Jjr/4d5 kD9595rA33LCdfgr5XTx9eXzC4E9pCLtIFSJqtkTnaoFkHpDOmqOzBFQiguHr0lGtFfF L9/Xfk5jI4BZzXRjVblLDJHqX7MH/tOuv9Bi1tIf/efY3eS+n9BjS1GqbG0TvMtxbzP6 P14A== 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=CA3YysOV48ZQEIFKJbrKCjOeXv6vJ029j2x+Bkp1Iz8=; b=QDy6Src3pcayiYM2/Od6V5k0ht2Qq90KaofEtnwnlBn2OgjoRAykC99jx+tMQyryDf Ho0zxzsA7xujwahY5kYm5cJ59DeGELzMpNyr7OphsH/zziLxnKE+r0pIJIH6c2W4MFvO psMw+5J0yFjuCjcv16ytwAO3EIh0qFvFTjInxE0G7OrHyW5nbb8sv0RqvpMWTsV/qnNH 1yLbFQQEZEBBbxPGA/bBKNvRurWpVvq1+hAKlv8xA4bb++do+vwd6lt9vFgFz+YK+TYa Iq+DgdDdCjpg1bHkQnaLrk8gyCectK0vVVRHbhCMaEzICLavdhjPxp6Z5lpswmEyqQFj Rmtg== X-Gm-Message-State: APjAAAXXVIXDkS6v3eKNtzotg0VVXFnBGjmW1OD1+UNcYxCkPMZiPzSM w35cIhQeEqZI4S0G4CwAUMxv2LCB X-Google-Smtp-Source: APXvYqxFx6TkX7V6bvogF1jX6EcnXXWVWGcsXNHUMrrx7qIo068YjYCP2hvHf0+Rwbje+Yflw+onGw== X-Received: by 2002:a05:651c:111a:: with SMTP id d26mr29051094ljo.153.1577571442604; Sat, 28 Dec 2019 14:17:22 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id y10sm15209584ljm.93.2019.12.28.14.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 14:17:22 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Mikko Perttunen , Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/6] i2c: tegra: Support atomic transfers Date: Sun, 29 Dec 2019 01:16:52 +0300 Message-Id: <20191228221654.28842-5-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228221654.28842-1-digetx@gmail.com> References: <20191228221654.28842-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 System shutdown may happen with interrupts being disabled and in this case I2C core rejects transfers if atomic transfer isn't supported by driver. There were several occurrences where I found my Nexus 7 completely discharged despite of being turned off and then one day I spotted this in the log: reboot: Power down ------------[ cut here ]------------ WARNING: CPU: 0 PID: 1 at drivers/i2c/i2c-core.h:40 i2c_transfer+0x95/0x9c No atomic I2C transfer handler for 'i2c-1' Modules linked in: tegra30_devfreq CPU: 0 PID: 1 Comm: systemd-shutdow Not tainted 5.4.0-next-20191202-00120-gf7ecd80fb803-dirty #3195 Hardware name: NVIDIA Tegra SoC (Flattened Device Tree) [] (unwind_backtrace) from [] (show_stack+0x11/0x14) [] (show_stack) from [] (dump_stack+0x85/0x94) [] (dump_stack) from [] (__warn+0xc1/0xc4) [] (__warn) from [] (warn_slowpath_fmt+0x61/0x78) [] (warn_slowpath_fmt) from [] (i2c_transfer+0x95/0x9c) [] (i2c_transfer) from [] (regmap_i2c_read+0x4d/0x6c) [] (regmap_i2c_read) from [] (_regmap_raw_read+0x99/0x1cc) [] (_regmap_raw_read) from [] (_regmap_bus_read+0x23/0x38) [] (_regmap_bus_read) from [] (_regmap_read+0x3d/0xfc) [] (_regmap_read) from [] (_regmap_update_bits+0x87/0xc4) [] (_regmap_update_bits) from [] (regmap_update_bits_base+0x39/0x50) [] (regmap_update_bits_base) from [] (max77620_pm_power_off+0x29/0x2c) [] (max77620_pm_power_off) from [] (__do_sys_reboot+0xe9/0x170) [] (__do_sys_reboot) from [] (ret_fast_syscall+0x1/0x28) Exception stack(0xde907fa8 to 0xde907ff0) 7fa0: 00000000 00000000 fee1dead 28121969 4321fedc 00000000 7fc0: 00000000 00000000 00000000 00000058 00000000 00000000 00000000 00000000 7fe0: 0045adf0 bed9abb8 004444a0 b6c666d0 ---[ end trace bdd18f87595b1a5e ]--- The atomic transferring is implemented by enforcing PIO mode for the transfer and by polling interrupt status until transfer is completed or failed. Now system shuts down properly every time. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 65 ++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 3016fd3eb064..a61aea5845d4 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -247,6 +248,7 @@ struct tegra_i2c_hw_feature { * @dma_buf_size: DMA buffer size * @is_curr_dma_xfer: indicates active DMA transfer * @dma_complete: DMA completion notifier + * @is_curr_atomic_xfer: indicates active atomic transfer */ struct tegra_i2c_dev { struct device *dev; @@ -275,6 +277,7 @@ struct tegra_i2c_dev { unsigned int dma_buf_size; bool is_curr_dma_xfer; struct completion dma_complete; + bool is_curr_atomic_xfer; }; static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, @@ -683,7 +686,8 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) 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 (in_interrupt()) + + if (i2c_dev->is_curr_atomic_xfer) err = readl_poll_timeout_atomic(addr, val, val == 0, 1000, I2C_CONFIG_LOAD_TIMEOUT); @@ -983,6 +987,33 @@ static void tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, i2c_writel(i2c_dev, val, reg); } +static unsigned long +tegra_i2c_poll_completion_timeout(struct tegra_i2c_dev *i2c_dev, + unsigned int timeout_ms) +{ + ktime_t ktime = ktime_get(); + ktime_t ktimeout = ktime_add_ms(ktime, timeout_ms); + + do { + u32 status = i2c_readl(i2c_dev, I2C_INT_STATUS); + + if (status) { + tegra_i2c_isr(i2c_dev->irq, i2c_dev); + + if (completion_done(&i2c_dev->msg_complete)) { + s64 delta = ktime_ms_delta(ktimeout, ktime); + + return msecs_to_jiffies(delta) ?: 1; + } + } + + ktime = ktime_get(); + + } while (ktime_before(ktime, ktimeout)); + + return 0; +} + static unsigned long tegra_i2c_wait_completion_timeout(struct tegra_i2c_dev *i2c_dev, struct completion *complete, @@ -991,9 +1022,13 @@ tegra_i2c_wait_completion_timeout(struct tegra_i2c_dev *i2c_dev, unsigned long timeout = msecs_to_jiffies(timeout_ms); unsigned long ret; - enable_irq(i2c_dev->irq); - ret = wait_for_completion_timeout(complete, timeout); - disable_irq(i2c_dev->irq); + if (i2c_dev->is_curr_atomic_xfer) { + ret = tegra_i2c_poll_completion_timeout(i2c_dev, timeout_ms); + } else { + enable_irq(i2c_dev->irq); + ret = wait_for_completion_timeout(complete, timeout); + disable_irq(i2c_dev->irq); + } return ret; } @@ -1064,7 +1099,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, xfer_size = ALIGN(xfer_size, BYTES_PER_FIFO_WORD); i2c_dev->is_curr_dma_xfer = (xfer_size > I2C_PIO_MODE_MAX_LEN) && - i2c_dev->dma_buf; + 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; /* @@ -1268,6 +1304,19 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], return ret ?: i; } +static int tegra_i2c_xfer_atomic(struct i2c_adapter *adap, + struct i2c_msg msgs[], int num) +{ + struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); + int ret; + + i2c_dev->is_curr_atomic_xfer = true; + ret = tegra_i2c_xfer(adap, msgs, num); + i2c_dev->is_curr_atomic_xfer = false; + + return ret; +} + static u32 tegra_i2c_func(struct i2c_adapter *adap) { struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); @@ -1295,8 +1344,9 @@ static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev) } static const struct i2c_algorithm tegra_i2c_algo = { - .master_xfer = tegra_i2c_xfer, - .functionality = tegra_i2c_func, + .master_xfer = tegra_i2c_xfer, + .master_xfer_atomic = tegra_i2c_xfer_atomic, + .functionality = tegra_i2c_func, }; /* payload size is only 12 bit */ @@ -1604,6 +1654,7 @@ static int tegra_i2c_probe(struct platform_device *pdev) goto unprepare_fast_clk; } + pm_runtime_irq_safe(&pdev->dev); pm_runtime_enable(&pdev->dev); if (!pm_runtime_enabled(&pdev->dev)) { ret = tegra_i2c_runtime_resume(&pdev->dev); From patchwork Sat Dec 28 22:16:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1215953 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; 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.b="B10v1fX4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47ldNg1clCz9sR8 for ; Sun, 29 Dec 2019 09:17:39 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726816AbfL1WR1 (ORCPT ); Sat, 28 Dec 2019 17:17:27 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:40403 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbfL1WRZ (ORCPT ); Sat, 28 Dec 2019 17:17:25 -0500 Received: by mail-lj1-f195.google.com with SMTP id u1so29973069ljk.7; Sat, 28 Dec 2019 14:17:24 -0800 (PST) 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=XooarHYfJfZshBGzPfhpSIkO10pFZYvOSKKStqb1xs4=; b=B10v1fX4z5rogdu7DoVXV/gHZXGGsG+KAMlbrXkU7rI5ZgM49eExWBK6Vnn7wO1D0C gXKesFyNjrCz7vnn38mMdD9VuIAchFkeAOIMso01fjaUmZOHQ5gZU5uxycDqV9EkadUx Yy+uscs1/O8ONF39yfqB7fC8BvRBzblnt0HJcc5IvJHqv2hgFTlvs8/jV9VBitqxOxl5 ek5gAzgT+z6CRxQo5t7pAoeD4Ta7oRWStJ5eijnzCdAoc5fqthqbwxOvhG0c9S8BGY3v DLB65reMyoJJX0ZGEiV1s2b15uh7USwin8NWrNrRWKf2+Bg3X52J5JXEb+mgiYia4o2i YxEg== 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=XooarHYfJfZshBGzPfhpSIkO10pFZYvOSKKStqb1xs4=; b=j6v1WS9OBRzPKkixp3GrZPppoP4NLS2ij6kowssiDCn1BAhtuQD92zqEBwwuL0iUUr feqVPyiv5BZtgsYVx8GXFhmtKsQ7PWptS2jEJH9RSqn+B35HH+XrAs5ixbfcr+LYxNlm s/mgCMnhYgnH8HGYahKJ8m9ac5cOlJxj0Y9jpw4yTsXiVZXdaSnxFQv6pTQkU156Kr7O xW1W3U2pH/vwbepC6Yx55AWlnhHkee13+F1Wu8Hqf0jJz046lH9u5xqc8bOwSTRJziCb URRc6gF4SI8Vtytk1okR/z3BTRKMC8cNc/NS0JS3PWtHojsv7dpE2KF5orYlOd47yURr VT4g== X-Gm-Message-State: APjAAAUe2jdA+UdhIAulax8Gd8aymE9Kj0D9Xnu+i5ZVDwIg0LEJGixJ v0ryyCBErhvyMiBVp6foWSA= X-Google-Smtp-Source: APXvYqwF4NyqCXTQdsAv5BiSUqI7k75II5fxqUAbKyKiq1ulVl9jTG5HYy1qq/W/06EYVvIucW8LAg== X-Received: by 2002:a2e:854b:: with SMTP id u11mr16062701ljj.90.1577571443424; Sat, 28 Dec 2019 14:17:23 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id y10sm15209584ljm.93.2019.12.28.14.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 14:17:23 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Mikko Perttunen , Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] i2c: tegra: Rename I2C_PIO_MODE_MAX_LEN to I2C_PIO_MODE_PREFERRED_LEN Date: Sun, 29 Dec 2019 01:16:53 +0300 Message-Id: <20191228221654.28842-6-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228221654.28842-1-digetx@gmail.com> References: <20191228221654.28842-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 DMA is preferred for a larger transfers, while PIO is preferred for a smaller transfers to avoid unnecessary DMA overhead. There is no strict size limitations for the PIO-mode transfers, so let's rename the constant for clarity. Tested-by: Thierry Reding Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index a61aea5845d4..0e88c7aa7cd5 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -131,11 +131,12 @@ #define I2C_PACKET_HEADER_SIZE 12 /* - * Upto I2C_PIO_MODE_MAX_LEN bytes, controller will use PIO mode, - * above this, controller will use DMA to fill FIFO. - * MAX PIO len is 20 bytes excluding packet header. + * I2C Controller will use PIO mode for transfers up to 32 bytes in order to + * avoid DMA overhead, otherwise external APB DMA controller will be used. + * Note that the actual MAX PIO length is 20 bytes because 32 bytes include + * I2C_PACKET_HEADER_SIZE. */ -#define I2C_PIO_MODE_MAX_LEN 32 +#define I2C_PIO_MODE_PREFERRED_LEN 32 /* * msg_end_type: The bus control which need to be send at end of transfer. @@ -1098,7 +1099,7 @@ 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_MAX_LEN) && + 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); From patchwork Sat Dec 28 22:16:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1215956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; 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.b="F+JDMOlP"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47ldNj2cc3z9sRW for ; Sun, 29 Dec 2019 09:17:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbfL1WR0 (ORCPT ); Sat, 28 Dec 2019 17:17:26 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:38206 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726187AbfL1WR0 (ORCPT ); Sat, 28 Dec 2019 17:17:26 -0500 Received: by mail-lj1-f194.google.com with SMTP id w1so8001236ljh.5; Sat, 28 Dec 2019 14:17:24 -0800 (PST) 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=PiNNr9K9qIQQnPJ6yZ/V1JmcG7noCNBTXNqtHbq6dTk=; b=F+JDMOlP2X3eFRRcURDvQX83S7gq7aV3tR5j/dAe2MVbdwz3hcXg05rEdZl1uWBCUZ SHqXf/4kRfxBZqKIsaUywdeF2U1kjCJjFzeXh9iy9Y/DEg8uw9Vn0MbGve28AcAzlhsZ yn5Nj/K+r3KvTG1STPRrfIDvJEbFPSwcDV7cEXPiETlR/5kWi39qPjzcvkRFN1ZKne6D VID6jrDXWW2GvVWwMuoLbsIhD37FPRAowx2xyw1xqjbNuXi9x1gmeABHXrTsZDZmNKL+ 3MchmnXstIQ3RW8+XjMRpvPIo4XZaLPVJR1J6iSASLvW7dZVhfq913iQ68VcaGjJlBA6 XK+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=PiNNr9K9qIQQnPJ6yZ/V1JmcG7noCNBTXNqtHbq6dTk=; b=ekOvDA3s0iETD5jyfwdUZi+akVp1pRv2hwxPciKf9kF9Y1qOXsrpA7Z7dS8k8+EuoP zPL58uyyYatmA2QWy8LaHTtH2Ps37FaXFdT7DYRtXhhLHaUtjS9U85XLzRdXe4KynVqG qWtHYRfCs7tliVGy9f9QVWRiCI31x5GH8DVOI59c+5qEY2ulHuTaGNkVX36fWcZxW7pT QJSpkcRCMbJopJHKBqSpzLqvUCDWTACM1qiUboPLNLQhuRQSSj7AuCe26TrGUkqKqK4r W+D2OFK5O9WRhyrZDebgQiBA6zsX7UGjNWWmTAZZbgH7lBNhGjNEr398aCtpkb97FJi/ oqWQ== X-Gm-Message-State: APjAAAXyTRGN/AmFwVjFG8K6yam2Eqqeqj75zsyfs1rEfertsdaBjP5X HBoov93+AXzUN5Vj6gAFs2g= X-Google-Smtp-Source: APXvYqwe6eRGb0lzPDGmWiVte7AMHiY7SA5qKagpCMQ/3OvM0RD+ONdohmoLYCzKP90k2d88sFkDuA== X-Received: by 2002:a2e:9ad8:: with SMTP id p24mr32131220ljj.148.1577571444214; Sat, 28 Dec 2019 14:17:24 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id y10sm15209584ljm.93.2019.12.28.14.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 14:17:23 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Mikko Perttunen , Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] i2c: tegra: Use relaxed versions of readl/writel Date: Sun, 29 Dec 2019 01:16:54 +0300 Message-Id: <20191228221654.28842-7-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228221654.28842-1-digetx@gmail.com> References: <20191228221654.28842-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 There is nothing to synchronize in regards to memory accesses for PIO transfers and for DMA transfers the DMA API takes care of the syncing. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 0e88c7aa7cd5..a39de5012128 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -284,12 +284,12 @@ struct tegra_i2c_dev { static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned long reg) { - writel(val, i2c_dev->base + reg); + writel_relaxed(val, i2c_dev->base + reg); } static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) { - return readl(i2c_dev->base + reg); + return readl_relaxed(i2c_dev->base + reg); } /* @@ -307,16 +307,16 @@ static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned long reg) { - writel(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); + writel_relaxed(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); /* Read back register to make sure that register writes completed */ if (reg != I2C_TX_FIFO) - readl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); + 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) { - return readl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, 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, @@ -689,12 +689,13 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev) i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD); if (i2c_dev->is_curr_atomic_xfer) - err = readl_poll_timeout_atomic(addr, val, val == 0, - 1000, - I2C_CONFIG_LOAD_TIMEOUT); + err = readl_relaxed_poll_timeout_atomic( + addr, val, val == 0, 1000, + I2C_CONFIG_LOAD_TIMEOUT); else - err = readl_poll_timeout(addr, val, val == 0, 1000, - I2C_CONFIG_LOAD_TIMEOUT); + err = readl_relaxed_poll_timeout( + addr, val, val == 0, 1000, + I2C_CONFIG_LOAD_TIMEOUT); if (err) { dev_warn(i2c_dev->dev,