From patchwork Mon Jul 13 10:26:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sugar Zhang X-Patchwork-Id: 11659311 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CDB2D60D for ; Mon, 13 Jul 2020 10:26:30 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 80321206F4 for ; Mon, 13 Jul 2020 10:26:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Cm96FGVs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80321206F4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=rock-chips.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=JU4Sy4QKN8hnqAbRCrkwCdtOqXAOBqkGhn2+gfe6eV4=; b=Cm96FGVsjZSeLIan2O4OR2ni4C J3Tv/whleVCfFuycNoAwIFUIKT8hRcmUdPMWU8AMLv5CCv3dWweIQwgqZnpQOG9P3kFhoCkRA1mD0 SRCN2AGLQ1vZlHAWtZoQEhWBV00fEcU7Jo55zpKKtz7/bf/2pT2kFEPel4xP7q0/4yqxi0oF8b5Gp l9gLqB29vI+f1RmgYUa9nvRN9iPRjuCu2ZDvH5TUdMLHWYuo3BHx9zm6WGOc9/4L6FfuRchH69pwf iCfS5b+T3jQzPp/2AasXO7Vt58DZslp5yFId6O4NqIRYdXnShpQlFy5QV+72V1O7q0s3KvhsSMwTi 20oqdKBA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1juvfF-0007nR-3T; Mon, 13 Jul 2020 10:26:25 +0000 Received: from lucky1.263xmail.com ([211.157.147.130]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1juvfA-0007mC-58; Mon, 13 Jul 2020 10:26:22 +0000 Received: from localhost (unknown [192.168.167.69]) by lucky1.263xmail.com (Postfix) with ESMTP id BCE20CA52C; Mon, 13 Jul 2020 18:26:09 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P8591T140098829747968S1594635967092824_; Mon, 13 Jul 2020 18:26:08 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: X-RL-SENDER: sugar.zhang@rock-chips.com X-SENDER: zxg@rock-chips.com X-LOGIN-NAME: sugar.zhang@rock-chips.com X-FST-TO: broonie@kernel.org X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 X-System-Flag: 0 From: Sugar Zhang To: broonie@kernel.org Subject: [PATCH] ASoC: rockchip: spdif: Handle clk by pm runtime Date: Mon, 13 Jul 2020 18:26:00 +0800 Message-Id: <1594635960-67855-1-git-send-email-sugar.zhang@rock-chips.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200713_062620_679991_658B5B4C X-CRM114-Status: GOOD ( 13.04 ) X-Spam-Score: 1.5 (+) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (1.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- 1.5 RCVD_IN_SORBS_WEB RBL: SORBS: sender is an abusable web server [58.22.7.114 listed in dnsbl.sorbs.net] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [211.157.147.130 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [211.157.147.130 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, Heiko Stuebner , linux-kernel@vger.kernel.org, Takashi Iwai , Liam Girdwood , Sugar Zhang , linux-rockchip@lists.infradead.org, Jaroslav Kysela , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org This patch handle the clk by pm runtime mechanism to simplify the clk management. Signed-off-by: Sugar Zhang --- sound/soc/rockchip/rockchip_spdif.c | 59 +++++++++++-------------------------- 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/sound/soc/rockchip/rockchip_spdif.c b/sound/soc/rockchip/rockchip_spdif.c index 6635145..6748108 100644 --- a/sound/soc/rockchip/rockchip_spdif.c +++ b/sound/soc/rockchip/rockchip_spdif.c @@ -306,44 +306,22 @@ static int rk_spdif_probe(struct platform_device *pdev) return -ENOMEM; spdif->hclk = devm_clk_get(&pdev->dev, "hclk"); - if (IS_ERR(spdif->hclk)) { - dev_err(&pdev->dev, "Can't retrieve rk_spdif bus clock\n"); + if (IS_ERR(spdif->hclk)) return PTR_ERR(spdif->hclk); - } - ret = clk_prepare_enable(spdif->hclk); - if (ret) { - dev_err(spdif->dev, "hclock enable failed %d\n", ret); - return ret; - } spdif->mclk = devm_clk_get(&pdev->dev, "mclk"); - if (IS_ERR(spdif->mclk)) { - dev_err(&pdev->dev, "Can't retrieve rk_spdif master clock\n"); - ret = PTR_ERR(spdif->mclk); - goto err_disable_hclk; - } - - ret = clk_prepare_enable(spdif->mclk); - if (ret) { - dev_err(spdif->dev, "clock enable failed %d\n", ret); - goto err_disable_clocks; - } + if (IS_ERR(spdif->mclk)) + return PTR_ERR(spdif->mclk); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); regs = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(regs)) { - ret = PTR_ERR(regs); - goto err_disable_clocks; - } + if (IS_ERR(regs)) + return PTR_ERR(regs); spdif->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "hclk", regs, &rk_spdif_regmap_config); - if (IS_ERR(spdif->regmap)) { - dev_err(&pdev->dev, - "Failed to initialise managed register map\n"); - ret = PTR_ERR(spdif->regmap); - goto err_disable_clocks; - } + if (IS_ERR(spdif->regmap)) + return PTR_ERR(spdif->regmap); spdif->playback_dma_data.addr = res->start + SPDIF_SMPDR; spdif->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; @@ -352,47 +330,44 @@ static int rk_spdif_probe(struct platform_device *pdev) spdif->dev = &pdev->dev; dev_set_drvdata(&pdev->dev, spdif); - pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); - pm_request_idle(&pdev->dev); + if (!pm_runtime_enabled(&pdev->dev)) { + ret = rk_spdif_runtime_resume(&pdev->dev); + if (ret) + goto err_pm_runtime; + } ret = devm_snd_soc_register_component(&pdev->dev, &rk_spdif_component, &rk_spdif_dai, 1); if (ret) { dev_err(&pdev->dev, "Could not register DAI\n"); - goto err_pm_runtime; + goto err_pm_suspend; } ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); if (ret) { dev_err(&pdev->dev, "Could not register PCM\n"); - goto err_pm_runtime; + goto err_pm_suspend; } return 0; +err_pm_suspend: + if (!pm_runtime_status_suspended(&pdev->dev)) + rk_spdif_runtime_suspend(&pdev->dev); err_pm_runtime: pm_runtime_disable(&pdev->dev); -err_disable_clocks: - clk_disable_unprepare(spdif->mclk); -err_disable_hclk: - clk_disable_unprepare(spdif->hclk); return ret; } static int rk_spdif_remove(struct platform_device *pdev) { - struct rk_spdif_dev *spdif = dev_get_drvdata(&pdev->dev); - pm_runtime_disable(&pdev->dev); if (!pm_runtime_status_suspended(&pdev->dev)) rk_spdif_runtime_suspend(&pdev->dev); - clk_disable_unprepare(spdif->mclk); - clk_disable_unprepare(spdif->hclk); - return 0; }