Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp867031ybh; Mon, 13 Jul 2020 03:29:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK083EcEHwpAryIGOqztzzrInD6Ru5aIEIOTbyFI1tgr5SGxP3pfkmfvIfa2kp5j9mjJVt X-Received: by 2002:a05:6402:22f0:: with SMTP id dn16mr91446302edb.83.1594636139851; Mon, 13 Jul 2020 03:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594636139; cv=none; d=google.com; s=arc-20160816; b=RmwW5R0WcboIy3obQYYAnEln4dbFZdni51oQL2dUXL6DInjf0RsxfQ1PmoPRDUnhrp arG+0nee0YWtR4vzlcDYPvMYtBmxLFL288mafz9aWiFAvNCCesTlw6wUlODnRQyVOpJY JC+k7JP0aNILZ3UaBC7ipinHMpG5rvZb21qqCv1fuVtGyHEAElMeiCoiDbko7jOruetl 8zx/FvYWhTYSMISLt5aFJdNlbRzCpuJPHXSbznd826KbFGl4hgZvuK/qBQXJsRTLdKX7 fXIJt2CnQBFhEJPV2tfo/H1IjaTfyHQ9iSH3mFqgujwmGZ/eD05J7ciyIvIzJUZVUIUT xhgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=HceS+e+EY7Y5m+BcwBxP8OEYiiYWT7Qocyz8QbV9MPI=; b=gvnK9r4SsZT9fhHHXl7NJd9zBwikH7s/p9wdAWuCxryVpaF9NRepOaR36fsQoK9U8j reCXm4aKdn0u1MFI3puC3vRlFPJBnO97pXzQnrRIVwROJ8R68Yy+EEaSGYKEYMMi7mbI tVpXEG9X/S/Z+ST3PwluVTKpckWJriPnFBHIJap0xRu1ybXj5O0mhPULncD8X8JLk9tN L1yoJAK1uLlynSF+WuQoRLC4PGrNKm6kmJ/Aa1Qxi3fyPzGynIdhilqYVcgddXswCA1S O09NM7OjPpzbjsOj3ZCBJC2Hur4o0KL/cdpry91XqIJ+OS8x1sKIUHkoXKyi99789tYH 74Tg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y16si5173071edv.476.2020.07.13.03.28.36; Mon, 13 Jul 2020 03:28:59 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729412AbgGMK0R (ORCPT + 99 others); Mon, 13 Jul 2020 06:26:17 -0400 Received: from lucky1.263xmail.com ([211.157.147.130]:53630 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729390AbgGMK0Q (ORCPT ); Mon, 13 Jul 2020 06:26:16 -0400 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 Cc: linux-rockchip@lists.infradead.org, Sugar Zhang , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Heiko Stuebner , alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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; } -- 2.7.4