From patchwork Sat Jul 31 19:14:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12412657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20320C4320A for ; Sat, 31 Jul 2021 19:15:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F143761050 for ; Sat, 31 Jul 2021 19:15:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230303AbhGaTPb (ORCPT ); Sat, 31 Jul 2021 15:15:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbhGaTPa (ORCPT ); Sat, 31 Jul 2021 15:15:30 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FF0EC0613CF; Sat, 31 Jul 2021 12:15:24 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id r26so25348899lfp.5; Sat, 31 Jul 2021 12:15:24 -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:mime-version :content-transfer-encoding; bh=O6HizKYjgpTKrJ3jzl7u6TzRt2edy1/wCW+GDPbwhfc=; b=fdoVfL84CyiznnmBfdYdjkMQ6j45YNWXp8MpxPFW1uE1yoyJIJGGRw7IcSycSG9Jo4 mANN3z34Sqtzt5LYu9OVPblxviUfwwcjZIIyZxeypk62d7cmcZHVrWrE3xJMag7NDW1/ nKpKe910717Re8y/817xnAMyYyE/oEZ1phXQcObuuf9Y6SqX/7KY+2/qMDEcOgPgoQtJ Bi9GlmZTd+TOcjfyU+xJ+jJyMVLAAIrul2oboyn9HnJTuBksyguCiMEIcmsCU9MGt5oj dqliy9XxRIKz747BmTtiOSzecblxwJPHH4+QwYfYFiIJdU/Ej8SASAgEAf+i6H3vBGB+ I+gA== 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:mime-version :content-transfer-encoding; bh=O6HizKYjgpTKrJ3jzl7u6TzRt2edy1/wCW+GDPbwhfc=; b=S7wtC+SEdFsEBcmlkp5sVXAvDt2ZozJVttKNVBmfXjKPCwLYemiNv/Jb/8O8YJ85Pc JR5CYHjz/axiRx8MTU1PuWIRtAEZgtMsPKxkxQI0BYFL7Mfjw6QxVQPBELC1bG4tRtLN KYo14h6estAWrdJWAcnTzcVGa3b/USzm8DNqsC5xf+yClp4TyxprTjUQRFmNOqLQ9pBH OHIvJ41Zbp8f5J2SlMbZWgTjW5w2A9Osr5t59cudwS3sQsIPwGY6cfaDC7HQoTiqnZsz tmINTA0fRRt5mG7nzFYtSqP4SdMkr1+pa05fiGG/Nfa5+9kzCwYyVYjHZt0iPtHl/PBr +IQA== X-Gm-Message-State: AOAM533iJGeqgMeNxCAikyWxLoJb9BFvYFP/KwxuyRNBteLXqMxucOj8 uIKn8lOUekSJJ/uao2AhUnY= X-Google-Smtp-Source: ABdhPJzTt7Uh80Ab4qfr7a5+r5WHylnUr0O7FG0DBD8AboWV7mqfsOMHg9CciPNr1T50Ah8IZs3C/w== X-Received: by 2002:a05:6512:3f18:: with SMTP id y24mr2052427lfa.531.1627758922581; Sat, 31 Jul 2021 12:15:22 -0700 (PDT) Received: from localhost.localdomain (94-29-22-96.dynamic.spd-mgts.ru. [94.29.22.96]) by smtp.gmail.com with ESMTPSA id g17sm424259ljm.28.2021.07.31.12.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jul 2021 12:15:22 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Laxman Dewangan Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 1/2] spi: tegra20-slink: Improve runtime PM usage Date: Sat, 31 Jul 2021 22:14:57 +0300 Message-Id: <20210731191458.30535-1-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The Tegra SPI driver supports runtime PM, which controls the clock enable state, but the clk is also enabled separately from the RPM at the driver probe time, and thus, stays always on. Fix it. Runtime PM now is always available on Tegra, hence there is no need to check the RPM presence in the driver anymore. Remove these checks. Signed-off-by: Dmitry Osipenko --- drivers/spi/spi-tegra20-slink.c | 73 +++++++++++---------------------- 1 file changed, 25 insertions(+), 48 deletions(-) diff --git a/drivers/spi/spi-tegra20-slink.c b/drivers/spi/spi-tegra20-slink.c index 6a726c95ac7a..501eca1d0f89 100644 --- a/drivers/spi/spi-tegra20-slink.c +++ b/drivers/spi/spi-tegra20-slink.c @@ -1061,33 +1061,12 @@ static int tegra_slink_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Can not get clock %d\n", ret); goto exit_free_master; } - ret = clk_prepare(tspi->clk); - if (ret < 0) { - dev_err(&pdev->dev, "Clock prepare failed %d\n", ret); - goto exit_free_master; - } - ret = clk_enable(tspi->clk); - if (ret < 0) { - dev_err(&pdev->dev, "Clock enable failed %d\n", ret); - goto exit_clk_unprepare; - } - - spi_irq = platform_get_irq(pdev, 0); - tspi->irq = spi_irq; - ret = request_threaded_irq(tspi->irq, tegra_slink_isr, - tegra_slink_isr_thread, IRQF_ONESHOT, - dev_name(&pdev->dev), tspi); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n", - tspi->irq); - goto exit_clk_disable; - } tspi->rst = devm_reset_control_get_exclusive(&pdev->dev, "spi"); if (IS_ERR(tspi->rst)) { dev_err(&pdev->dev, "can not get reset\n"); ret = PTR_ERR(tspi->rst); - goto exit_free_irq; + goto exit_free_master; } tspi->max_buf_size = SLINK_FIFO_DEPTH << 2; @@ -1095,7 +1074,7 @@ static int tegra_slink_probe(struct platform_device *pdev) ret = tegra_slink_init_dma_param(tspi, true); if (ret < 0) - goto exit_free_irq; + goto exit_free_master; ret = tegra_slink_init_dma_param(tspi, false); if (ret < 0) goto exit_rx_dma_free; @@ -1106,16 +1085,9 @@ static int tegra_slink_probe(struct platform_device *pdev) init_completion(&tspi->xfer_completion); pm_runtime_enable(&pdev->dev); - if (!pm_runtime_enabled(&pdev->dev)) { - ret = tegra_slink_runtime_resume(&pdev->dev); - if (ret) - goto exit_pm_disable; - } - - ret = pm_runtime_get_sync(&pdev->dev); - if (ret < 0) { + ret = pm_runtime_resume_and_get(&pdev->dev); + if (ret) { dev_err(&pdev->dev, "pm runtime get failed, e = %d\n", ret); - pm_runtime_put_noidle(&pdev->dev); goto exit_pm_disable; } @@ -1123,33 +1095,43 @@ static int tegra_slink_probe(struct platform_device *pdev) udelay(2); reset_control_deassert(tspi->rst); + spi_irq = platform_get_irq(pdev, 0); + tspi->irq = spi_irq; + ret = request_threaded_irq(tspi->irq, tegra_slink_isr, + tegra_slink_isr_thread, IRQF_ONESHOT, + dev_name(&pdev->dev), tspi); + if (ret < 0) { + dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n", + tspi->irq); + goto exit_pm_put; + } + tspi->def_command_reg = SLINK_M_S; tspi->def_command2_reg = SLINK_CS_ACTIVE_BETWEEN; tegra_slink_writel(tspi, tspi->def_command_reg, SLINK_COMMAND); tegra_slink_writel(tspi, tspi->def_command2_reg, SLINK_COMMAND2); - pm_runtime_put(&pdev->dev); master->dev.of_node = pdev->dev.of_node; ret = devm_spi_register_master(&pdev->dev, master); if (ret < 0) { dev_err(&pdev->dev, "can not register to master err %d\n", ret); - goto exit_pm_disable; + goto exit_free_irq; } + + pm_runtime_put(&pdev->dev); + return ret; +exit_free_irq: + free_irq(spi_irq, tspi); +exit_pm_put: + pm_runtime_put(&pdev->dev); exit_pm_disable: pm_runtime_disable(&pdev->dev); - if (!pm_runtime_status_suspended(&pdev->dev)) - tegra_slink_runtime_suspend(&pdev->dev); + tegra_slink_deinit_dma_param(tspi, false); exit_rx_dma_free: tegra_slink_deinit_dma_param(tspi, true); -exit_free_irq: - free_irq(spi_irq, tspi); -exit_clk_disable: - clk_disable(tspi->clk); -exit_clk_unprepare: - clk_unprepare(tspi->clk); exit_free_master: spi_master_put(master); return ret; @@ -1162,8 +1144,7 @@ static int tegra_slink_remove(struct platform_device *pdev) free_irq(tspi->irq, tspi); - clk_disable(tspi->clk); - clk_unprepare(tspi->clk); + pm_runtime_disable(&pdev->dev); if (tspi->tx_dma_chan) tegra_slink_deinit_dma_param(tspi, false); @@ -1171,10 +1152,6 @@ static int tegra_slink_remove(struct platform_device *pdev) if (tspi->rx_dma_chan) tegra_slink_deinit_dma_param(tspi, true); - pm_runtime_disable(&pdev->dev); - if (!pm_runtime_status_suspended(&pdev->dev)) - tegra_slink_runtime_suspend(&pdev->dev); - return 0; } From patchwork Sat Jul 31 19:14:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12412659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1EB2C432BE for ; Sat, 31 Jul 2021 19:15:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 89F6A61042 for ; Sat, 31 Jul 2021 19:15:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230398AbhGaTPc (ORCPT ); Sat, 31 Jul 2021 15:15:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbhGaTPb (ORCPT ); Sat, 31 Jul 2021 15:15:31 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD737C06175F; Sat, 31 Jul 2021 12:15:24 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id r26so25348938lfp.5; Sat, 31 Jul 2021 12:15:24 -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=z6RHlFVIPwschZyiy2o4/m4eOut9h9ogqnj+c4ljJ80=; b=f0WZEultHTpR23gI+ODq7vUmGqoi4oqTaCTpSwCTQmIaMtikaYta7syVgOELeYXid6 Flg4CX4xrO0q9zE+exJKnV0rwd1BBnfOo/PmSrtHWDWULi6HCR/JYjBYx7qb8rtLqU1V 6iMlGQ+sS1GOaiUDMqKJxl6HO1PtCfQ+Ra2h7/ZN7p6c3L1v2qe8V7BaH5VsixafkK+P 6pQGGpMRo8wXEmd50n0NmvR4UHzyqwb1TEwwC0Zm667zKcVB3eLJ/Rdaro6+iogbwZny ldz+yt1qVB2iyuxL7kFU9aDno4vfar/DvKAUXNBsiW0IMW7q5cyzlvQC+LEFKREbUrIc 2SEg== 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=z6RHlFVIPwschZyiy2o4/m4eOut9h9ogqnj+c4ljJ80=; b=OJXNsxqjN9Y46Fc/mkM36oDj/K3B7SBYsenx6knycPdj7UyyBALh+Mj3sF0V9Q97UI lJ64D3LTIavXbXpWaQ39z7R+1YW2bOL+VpzRBpcfiw+kIYb0cqVhG+NsmqIMFGi3LmeD ilhaB4QQ/OnxzTwQJUUcjGRi1JgKzHq2THDd3vmMjhSuFVCAuyX8aicAtj5JMDVNZRhv NL4WeduJ1sHNrfnNezNIWQENFUfvNIyQtiu7bVLpPUXeukrjsIuGqvRFt70PF7mqDF7C fXx525OS6v13ymydGOnBPLYWkAooLR5APEPjWJX4YsC/tAde54MMCeLqodLSbJC//NLQ ZKkA== X-Gm-Message-State: AOAM530EO9mZddwN3PhQwFkNoqRkkuzMG49ztfVjuyfBy/gU1m6mBWPq YQ3clYk7qjfT9FO9Im9uV0U= X-Google-Smtp-Source: ABdhPJyCb6FoAGaCIy27//id4QlbypzqGHXAwu6+z79NK48DMSa8k59/KsmJhYfi563svgoPC+XApw== X-Received: by 2002:ac2:4310:: with SMTP id l16mr6471813lfh.481.1627758923247; Sat, 31 Jul 2021 12:15:23 -0700 (PDT) Received: from localhost.localdomain (94-29-22-96.dynamic.spd-mgts.ru. [94.29.22.96]) by smtp.gmail.com with ESMTPSA id g17sm424259ljm.28.2021.07.31.12.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jul 2021 12:15:22 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Laxman Dewangan Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v1 2/2] spi: tegra20-slink: Don't use resource-managed spi_register helper Date: Sat, 31 Jul 2021 22:14:58 +0300 Message-Id: <20210731191458.30535-2-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210731191458.30535-1-digetx@gmail.com> References: <20210731191458.30535-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Don't use resource-managed spi_register helper to correct the driver removal order and fix memory leak of spi_master that is never released. Signed-off-by: Dmitry Osipenko --- drivers/spi/spi-tegra20-slink.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-tegra20-slink.c b/drivers/spi/spi-tegra20-slink.c index 501eca1d0f89..deff16ba6d58 100644 --- a/drivers/spi/spi-tegra20-slink.c +++ b/drivers/spi/spi-tegra20-slink.c @@ -1112,7 +1112,7 @@ static int tegra_slink_probe(struct platform_device *pdev) tegra_slink_writel(tspi, tspi->def_command2_reg, SLINK_COMMAND2); master->dev.of_node = pdev->dev.of_node; - ret = devm_spi_register_master(&pdev->dev, master); + ret = spi_register_master(master); if (ret < 0) { dev_err(&pdev->dev, "can not register to master err %d\n", ret); goto exit_free_irq; @@ -1142,6 +1142,8 @@ static int tegra_slink_remove(struct platform_device *pdev) struct spi_master *master = platform_get_drvdata(pdev); struct tegra_slink_data *tspi = spi_master_get_devdata(master); + spi_unregister_master(master); + free_irq(tspi->irq, tspi); pm_runtime_disable(&pdev->dev); @@ -1152,6 +1154,8 @@ static int tegra_slink_remove(struct platform_device *pdev) if (tspi->rx_dma_chan) tegra_slink_deinit_dma_param(tspi, true); + spi_master_put(master); + return 0; }