From patchwork Fri Apr 16 14:20:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quanyang Wang X-Patchwork-Id: 12207807 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=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 28558C433ED for ; Fri, 16 Apr 2021 14:24:38 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6DBEE6113D for ; Fri, 16 Apr 2021 14:24:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6DBEE6113D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=windriver.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hGx0+rPhhQjISO44tk748PjeSrRTZ8XjUZWzZVVUDzE=; b=PhJgKhV1Lemf+/EW4c4uQUQ0E Szi9Do2MesyNFO3HNBthJHk3blz3tgDIQQLLJkIAH6kQty0NrETeBrTy3G2rfGSy7gzo7m4I7i56g sRALv0xiryuowoUvG1FZmtY1D+/OBVbHyy/B2WsBoZUCo7R9JoH+LGpMZlOF+7XeTH2EUuu1kT+zP BJtR31sgQEWn+g18TJ0uC7QbpIY5/Gt14Q7fSbI8qzPUnEptabIusoa7ItTHhseerQg1ikWMlAh+1 HMk2Ce/S9DCxBXb/AV5S6RS9iwgmgAeovo/ILrD0/QHjWVHlcaSeJ4gn0tbD1rnfvKVqicsv7tTVS cr+cXE+Rg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lXPMi-002Nac-GF; Fri, 16 Apr 2021 14:22:36 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lXPMY-002NZ6-Et for linux-arm-kernel@desiato.infradead.org; Fri, 16 Apr 2021 14:22:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=M/VHzESPyjV8fkVOcutFrKHaOw4oAKVGuUsCnUXpXpE=; b=gwxperPjvSY2Y4FmkMmfUsfPEx XBk4UUvmrT2B3DiaKyXL+hCapgG2pM2wAI+ftvi756IYJcH70PMpdZItlYAqxMJPJLn+mvEM0vVTS WxsOfclGeXbBx18HKdcMONBmWpdsEY4s1oqk3ZtaQppXvAPEC0pqZa1SzDf6q6tQjR4ZyNGoHkHlx kOptme4/tjEpRgI9rYI8DbhL7bQbrRmwiwf1Eaej6KMOHT8DG8Xt749DFxZg4HJe/BL6gc9rjnPeK fUHeITes0aD6BAC5aTcJPfNZ27eQWtw9v7M+ricbUP/b19uxoSCuuO+pyHOg86w1lpTifBjVOlBLd coeyXs+Q==; Received: from mail-dm6nam12on2060.outbound.protection.outlook.com ([40.107.243.60] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lXPMT-009R9y-26 for linux-arm-kernel@lists.infradead.org; Fri, 16 Apr 2021 14:22:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A0VDfuBk9ij7v4Sx3k6GqhXc8MwlzNzGRcB/xbVq7fkUmgGB8psiVDwlOp9p2BkythrY7x6Q6oPPLvzYOv8Caaa10nn6MtoL4bEeSjmLG6z8d8MpUGJg9fqHFY6KJDptPw2qjVkF4PJWdlL/Ljfe/GlXMivE/ANvQ1ZIOI/XMD8/Zrc7Q5WXoU+1m6R/veA0h9kxY5Osegcg40XD28F7EcV+XNeEQ4SZegWi0A5fOj4NPc7C9ewal/kN2eq0F+SWBOBcIbSRSflhMk3s/h5CVi+lm2MS+9DZYA+Y0oIbamddl7SneB1klEanMgQqLSUyPELSDx2OpEMDy4ihdd3OuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M/VHzESPyjV8fkVOcutFrKHaOw4oAKVGuUsCnUXpXpE=; b=ZwsGmtiBrm3ssBlu+IvsfdwN/KfsWh8s2xMNMm8IoG3Jz/z/ygSaC5DsMXdYAVMMPIUyIu3If9uHYQQ9BVrP4eK1cqQMfzLf5FgMUIJ/PlgcmRn+5T5VzPX2HNQa2y8Iol0lG3yFAUok50JY6gzXWfnQSBk8igXf544EALKeR7rGb9sjRn/N9E1Ngeh/TJPk9Aafme0Fz9HMfsM9SqTpQ4uZFYYraC4Gnve0EAGGtjiyxnbCrDtLUlOFNvK/lHLLD7L5+eU9nt5ueCI81Lj5rScQ/C75Q2OQUZ39CCda07u1Msvj6QE1Vb25hYVucAdOSWe427tnvYFIm2oKzBJd0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M/VHzESPyjV8fkVOcutFrKHaOw4oAKVGuUsCnUXpXpE=; b=dcGJthAb6n4Rf2SlZY9nIrw9Sa1ULkGVnR/KI016HbRmNqe3BpjutcXvWYVR7KnnJLnA3zSMNsOipnWAA1t9op3N5s5u8t82hBNMRRmRTY/D8dGgDtbPEInHYRxwb9/gY1h8/NDIu9tGOthEKD0+o71thpo/v9zrrisM/A4VdEk= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=windriver.com; Received: from CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) by CY4PR1101MB2264.namprd11.prod.outlook.com (2603:10b6:910:24::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Fri, 16 Apr 2021 14:22:15 +0000 Received: from CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725]) by CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725%6]) with mapi id 15.20.3999.037; Fri, 16 Apr 2021 14:22:15 +0000 From: quanyang.wang@windriver.com To: Mark Brown , Michal Simek , Amit Kumar Mahapatra Cc: linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Quanyang Wang Subject: [V2][PATCH 1/5] spi: spi-zynqmp-gqspi: fix clk_enable/disable imbalance issue Date: Fri, 16 Apr 2021 22:20:43 +0800 Message-Id: <20210416142047.6349-2-quanyang.wang@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210416142047.6349-1-quanyang.wang@windriver.com> References: <20210416142047.6349-1-quanyang.wang@windriver.com> X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) To CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-qwang2-d1.wrs.com (60.247.85.82) by HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Fri, 16 Apr 2021 14:22:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0d17bedf-974b-40ed-c739-08d900e30894 X-MS-TrafficTypeDiagnostic: CY4PR1101MB2264: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Otln4KfR/aNvWIEsCTU9hfAd2M45mzPiie2tfmAUZI2YGu8u4z8uchLlgxTFDUfl9S8a1zBDj6EbbzlOfrcxsjEFITQlNmLnh0gJ8wtB3LiCdKMtGNX7RelP3fj7ZhIcTRtGEkNHr0FqvKmdI4wvbEs6S69NJH8wc8CSjO3dOacTcI6C94TcrC3ahUp62fXco6j++43c4RCKWH8f72YyRAusdnnSfmiTfsboadH2zRD1z+ZBe6m2u4yAExBgpsVjG62wfqtF4GLyrbg2O0i1pGT8S4UBBwCVG/boke+O2id3sx2BMdpP/8zri7SiOoEm3p+KcEXeY8QpfKl/MAe6FkC9dYt/ZuOmXmnVU+KYxq7i1K8xVSmm77VJ9VccKvpRONjTqFyHnjpyv/pQhz4lbDbBkTezeCNn9oD5JAtrIJMUF3F4K80F8Z99RUuaWBJ0i++iZ5hZjUE4T2vK+OhkPR9Rz5uw5X8GV/3TGWgpSraP7XwSYiTu0s2NqEv7hIXkBAqk6SGlEE5bCh6u80iRRLLkHd/oexWHKciomyao1M12YBeT2AUbvVlR2Ee6jcyOTCs+M2RUaIndF9y6GLhy9V+OUOaiQAb7715DdrKMyqYLiYFkNXbMMqsc152UQGBdeOKgJSHtlCEYzXnbX2Uwy6fhDUjCvl7DJn2qEr0X4NI= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CY4PR11MB0071.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(376002)(366004)(396003)(39850400004)(346002)(86362001)(186003)(2906002)(38350700002)(38100700002)(316002)(6506007)(9686003)(6486002)(83380400001)(66946007)(8676002)(66556008)(66476007)(478600001)(16526019)(5660300002)(4326008)(26005)(6512007)(1076003)(52116002)(110136005)(956004)(6666004)(8936002)(107886003)(2616005)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 9JbiplKsAlJ3FDtIyTbAudCFLGIvTAgyAr4+O4E5XuL2ShKSuA7g9n3ry3wg3fJYQdNTmmjTh3mMjqJCSNCahjcZP101Ty98kn7BPjCAb5+9SUoFaGej36yUkVYfxCMtXUKJKzuTKex/kLfs5TAU8eH+JQehGzrRiwhckAWOa419Fdnn+mmQXRtrcMNrSRgPvF1UYqY5iHgToxN9QhQjNnlS6LFJeXUoX0ensatYZt1uBRtIjBtZzaEoAICiQC1ToFjd2WZzlW14hQYNbg9x5sgkPR2P5DP+zV/TH+ofmpFzm/Tw6zAh0CraKL8Z9pwHzO23igmbmli5PwGTPDxkinQAPhHrfBcm66f+9Z5Y2EZuOnA3vO4HMZlxdTTcQ0gG2Khb2SUtrKCJoOq/6Zgi089ALEXhB65R42voaYtG+m5z9+q4iGeRH/kzTPV9nfVpGpUAG2qixw+xLkgbHeI8MMsgf86X+Fr6okmCbEbyUEdmQcHzJNUFaK7Aj6OnMH3f1LWRN6IBymldHvHdIib/gUerGp4olchQK5EDkXpuEOdm9gGYWS8HOJhJaEhu2Fzf9P/J+hfoWLWjjR1IIjyUKAeXQmRJaPrLBo31YmqKdGR0O5tGPkKCv3LXEB68wfMOhJTER5b675afBie8eHiYmk4/NGDP4m/hLnosR2fIUEdjLhuKDXhDM6hVfvjBZFiva3gw5vbD40Y3adFXXQ27Lg/iKG9Bphw1RQVbNL9TAVYJAAK4tQswHyTqGsrYL9QDnXYKBjidga2IJudUwLS3fjx6OOqyoy3ZfnCFRpb0wpjvN1ysPvZgAJp2H9u+5M5V+siuoVTaFiIc/2K/21hEglE2QdEZ0+EBwn4aEgoDwYk0IXFqDlCqzb88lAFrvJttNGAuQaB9YMG1dQ6oUqjajA7sVxv0sIimENe+ApBJWT5uN/MQlCUOLbFGQQuws8OOG69J2TB8tZZwck1/30lKcHANMIL5nEaZWDbf3KNPRIVb1wK0/pK0XpXZ7OOKLUuQ5vdLR08qBVFHQ3ODfgiQ464OoAClApisz+e36e3O2qLGmB0OuLLUjE+EC6Rh3CWAxmWDMnpAdEmn5jZynQHjFZtOFBMB970P9AA/1L4VVw+rkNIZPBkMIzTgZzsyenuvJ1Sk2/glsXn79Ckbui4E77hPDdiFhVaxbHQKoGp1WZBbxN9Izs1cNunZa3oSf5kZMaKGko6XtCYHkH0crTVai+0mH71/LwteEjRFpk25DReMulJxJKhH7QftxD+XB4yJWHZMxblGA/KBZYU60Pt+gKZeRODRDSqvTg7/PQa+VRWb8mEcpHQfIeujzwcO96GL X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d17bedf-974b-40ed-c739-08d900e30894 X-MS-Exchange-CrossTenant-AuthSource: CY4PR11MB0071.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2021 14:22:15.3079 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NDg+vQdM5JhzM6cuUV5PdfjC0b5yUUdm3U/CgiSDIFq7nwrnmCmS8Gxqak7v/sHKOFwAjMqsZ2k0F1dExVWPaAK9S8oI2gnwtICsMR0D33M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1101MB2264 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210416_072221_135710_96183FE0 X-CRM114-Status: GOOD ( 15.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Quanyang Wang 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. Signed-off-by: Quanyang Wang --- 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 32e53f379e9b..f9056f0a480c 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);