Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4611208pxj; Wed, 12 May 2021 09:12:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWaoBUsZqtfsidkj6sqXItJ21Wdgjlwntg+b2lw4zPNg+4JXyCrOX/n4tOAGLRrCwylJ3S X-Received: by 2002:aa7:d4d5:: with SMTP id t21mr30996298edr.95.1620835966797; Wed, 12 May 2021 09:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835966; cv=none; d=google.com; s=arc-20160816; b=uqzBuNhBrVvSjIhPYyrYAiKCwBiCYJkfwT6wYBJz2YGzX3V9hTk20iOocJYKdUuRfY p/GAt8gmDkwBLMzc+U6PR2PWdfe7CoyuedgS1H4kGiQwnOumh5xDFp7UF5oM+SFC7Nv0 nMpPP0ZdPgxVLzzAF+PHzdcmMyHXnI0BmwgtcP1srrXCPG7MJUh58AOmYSYBTPjQEMOZ OUSFgfhsBRQnuHQANdZxCZD3t2KziU2s6/hrb8wVxnWApzlXd3MPEjWqpFxxVHOQMbsy QFHDPFVehOllTaUCK7qk/pdQktDGd50pdMxGhl6pfmJPq83ov9vLfph6ClED9gj1on4/ 0Kmw== 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=oXte6/+E4ecQlEgMdq+AM+132i+j+/E6OTOUaH9vAwz7vpVakTsDvZZcUFSeWRd6Yb 4oGZXT37yliGV6JFbr3x2mzDkgNc7VaJN7dG2PzVmuLtIkQc7+Ds6o1EKXH9o2RLSUqd eldmngYMv/USGkcXjpv6var23S1cBiY41Na9zdSFogjDZMbQ3wWqUpPIcaOtv4wvluZ0 a2s2kK7gXaUVkfZ+eGuqpM5Bk6nXYvOPawdNzRmP8LL+0x3l0Tk8R029o/+8bjEZzKdh K/apxkSNSmuZ0d34yDyRN7UVevMA4f49oNspfuSPZTjU5JJhn2KV5HsGb0OrKfrGw0Ag WR7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wR+UKZaA; 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 g14si283885ejx.307.2021.05.12.09.12.03; Wed, 12 May 2021 09:12:46 -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=wR+UKZaA; 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 S239200AbhELQHf (ORCPT + 99 others); Wed, 12 May 2021 12:07:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:40502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235687AbhELP2q (ORCPT ); Wed, 12 May 2021 11:28:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DC1F861C2F; Wed, 12 May 2021 15:14:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832481; bh=JsJiWstIsSPp/unCPBmaU/bOK5cDK9cuN3cHAiuLIM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wR+UKZaA8n987ksZCicYvBMLSwl8cwGwRAAzZdh1CdwZ1hG/reoOabVRFDNDDwI0P HLi7sNJnMFPa6rI0SZElCfv65LLI7bTizc0weViRlia/68pK5a8YT0jfyf/Se0tEZR 0ghUPWVQdB88z+cSeuU0J18F6V6d7+DKvHxjh8Kg= 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.10 262/530] spi: spi-zynqmp-gqspi: fix clk_enable/disable imbalance issue Date: Wed, 12 May 2021 16:46:12 +0200 Message-Id: <20210512144828.439652984@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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