Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4671872pxj; Wed, 12 May 2021 10:32:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxx1XsvsmQ4v4sDbU7jOwfXOf+7u7LJ/tv2X7ZyrS62sbrBo4rR7JaSqsqNiHj3VJuvJXon X-Received: by 2002:aa7:c9cb:: with SMTP id i11mr45317723edt.331.1620840750754; Wed, 12 May 2021 10:32:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620840750; cv=none; d=google.com; s=arc-20160816; b=Ou8/DOQtgMtbRlfqxgzMHdp7o1eo+opNaXgdCI8tKmIVC3wuBcFShzAiXXTZp1+pKS 0vPHA2/3S8l7XEdm28PGV/qte83XwCKVrpQFUhKfqYlk9SonkU1h/5CEEMXHgikFz6I2 TJqq/XzhOmj+CU9R8B3ixrR9qJVqTLXXo1Dsjw5PjiU7qQ+KLdjpxwLuMOLnqAU+soko j1Ln3hftZ7i2hLEVyHbhoudXt4p5cMF9oUkm1/5JnCrpelbllH4oi40fFaiMUk0wSMPq lsdk8V6HljxzdR0jd3OrdKZOkB0UddypqPJgUSXOI21j5uJwqa07RCYIYmbJc8+UyTmV QWRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e03ycXAhSm93WP8WWiR/lTTmomKA9p7hO7gxK5a0u4M=; b=Z0zw1DGYNaemkGT17QFVT8hwkfSMXTm1RdAcQqvi0PIBYAoSycWkNAC+yACw1BVCMD PsPLd6GGGxNZXKHy9EAmkfGKFTxUhBQfO8CHeGMU476FXVnHcITQs4VSrh4ld9a3buCA baOsG83nMJhkSMCLfeD7y8QWDF5LpUHJXhp5FSxstZEuLRv9kqYEXax6wiTKQfmlCZ+J uSrbuvCnD+YGX313vg4LAORZsF3ooqPBPHrXZRj1iQ+IRd765ZQHGpAbtHb+fmG1qQhA CoxYITYnRsjRqO17I2PeAqyrzfqZvWP6furHJAjJMuoNn3Cx1kfgBBQ10EP8VgVHSiOd 88xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fnZJc+os; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kk28si464623ejc.668.2021.05.12.10.32.05; Wed, 12 May 2021 10:32:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fnZJc+os; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347227AbhELR1o (ORCPT + 99 others); Wed, 12 May 2021 13:27:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:34634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239235AbhELQHh (ORCPT ); Wed, 12 May 2021 12:07:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EF8E761D16; Wed, 12 May 2021 15:36:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833814; bh=JsJiWstIsSPp/unCPBmaU/bOK5cDK9cuN3cHAiuLIM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fnZJc+oszutxpXJ0Oya/jL6F9xykpGGLVyOrAhM8L8MVnPxfLwE2GdpNojxojg0TI 4W2nHaTtzcK5Sqc9eFteRoB0x2BXi8ogmijmCnTSf5oTKDP0euwYsR6dTlp1FJgvu+ LuIGaMTEJIDjZsgnDKj/tllFC4cqXrLxECP6nrN4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Quanyang Wang , Mark Brown , Sasha Levin Subject: [PATCH 5.11 292/601] spi: spi-zynqmp-gqspi: fix clk_enable/disable imbalance issue Date: Wed, 12 May 2021 16:46:09 +0200 Message-Id: <20210512144837.424029123@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quanyang Wang [ Upstream commit c6bdae08012b2ca3e94f3a41ef4ca8cfe7c9ab6f ] The clks "pclk" and "ref_clk" are enabled twice during the probe. The first time is in the function zynqmp_qspi_probe and the second time is in zynqmp_qspi_setup_op which is called by devm_spi_register_controller. Then calling zynqmp_qspi_remove (rmmod this module) to disable these clks will trigger a warning as below: [ 309.124604] Unpreparing enabled qspi_ref [ 309.128641] WARNING: CPU: 1 PID: 537 at drivers/clk/clk.c:824 clk_core_unprepare+0x108/0x110 Since pm_runtime works now, clks can be enabled/disabled by calling zynqmp_runtime_suspend/resume. So we don't need to enable these clks explicitly in zynqmp_qspi_setup_op. Remove them to fix this issue. And remove clk enabling/disabling in zynqmp_qspi_resume because there is no spi transfer operation so enabling ref_clk is redundant meanwhile pclk is not disabled for it is shared with other peripherals. Furthermore replace clk_enable/disable with clk_prepare_enable and clk_disable_unprepare in runtime_suspend/resume functions. Fixes: 1c26372e5aa9 ("spi: spi-zynqmp-gqspi: Update driver to use spi-mem framework") Signed-off-by: Quanyang Wang Link: https://lore.kernel.org/r/20210416004652.2975446-2-quanyang.wang@windriver.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-zynqmp-gqspi.c | 47 ++++++---------------------------- 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index 408e348382c5..31d266cfbb4c 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -487,24 +487,10 @@ static int zynqmp_qspi_setup_op(struct spi_device *qspi) { struct spi_controller *ctlr = qspi->master; struct zynqmp_qspi *xqspi = spi_controller_get_devdata(ctlr); - struct device *dev = &ctlr->dev; - int ret; if (ctlr->busy) return -EBUSY; - ret = clk_enable(xqspi->refclk); - if (ret) { - dev_err(dev, "Cannot enable device clock.\n"); - return ret; - } - - ret = clk_enable(xqspi->pclk); - if (ret) { - dev_err(dev, "Cannot enable APB clock.\n"); - clk_disable(xqspi->refclk); - return ret; - } zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, GQSPI_EN_MASK); return 0; @@ -863,26 +849,9 @@ static int __maybe_unused zynqmp_qspi_suspend(struct device *dev) static int __maybe_unused zynqmp_qspi_resume(struct device *dev) { struct spi_controller *ctlr = dev_get_drvdata(dev); - struct zynqmp_qspi *xqspi = spi_controller_get_devdata(ctlr); - int ret = 0; - - ret = clk_enable(xqspi->pclk); - if (ret) { - dev_err(dev, "Cannot enable APB clock.\n"); - return ret; - } - - ret = clk_enable(xqspi->refclk); - if (ret) { - dev_err(dev, "Cannot enable device clock.\n"); - clk_disable(xqspi->pclk); - return ret; - } spi_controller_resume(ctlr); - clk_disable(xqspi->refclk); - clk_disable(xqspi->pclk); return 0; } @@ -898,8 +867,8 @@ static int __maybe_unused zynqmp_runtime_suspend(struct device *dev) { struct zynqmp_qspi *xqspi = (struct zynqmp_qspi *)dev_get_drvdata(dev); - clk_disable(xqspi->refclk); - clk_disable(xqspi->pclk); + clk_disable_unprepare(xqspi->refclk); + clk_disable_unprepare(xqspi->pclk); return 0; } @@ -917,16 +886,16 @@ static int __maybe_unused zynqmp_runtime_resume(struct device *dev) struct zynqmp_qspi *xqspi = (struct zynqmp_qspi *)dev_get_drvdata(dev); int ret; - ret = clk_enable(xqspi->pclk); + ret = clk_prepare_enable(xqspi->pclk); if (ret) { dev_err(dev, "Cannot enable APB clock.\n"); return ret; } - ret = clk_enable(xqspi->refclk); + ret = clk_prepare_enable(xqspi->refclk); if (ret) { dev_err(dev, "Cannot enable device clock.\n"); - clk_disable(xqspi->pclk); + clk_disable_unprepare(xqspi->pclk); return ret; } @@ -1136,13 +1105,11 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) goto remove_master; } - init_completion(&xqspi->data_completion); - xqspi->refclk = devm_clk_get(&pdev->dev, "ref_clk"); if (IS_ERR(xqspi->refclk)) { dev_err(dev, "ref_clk clock not found.\n"); ret = PTR_ERR(xqspi->refclk); - goto clk_dis_pclk; + goto remove_master; } ret = clk_prepare_enable(xqspi->pclk); @@ -1157,6 +1124,8 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) goto clk_dis_pclk; } + init_completion(&xqspi->data_completion); + mutex_init(&xqspi->op_lock); pm_runtime_use_autosuspend(&pdev->dev); -- 2.30.2