From patchwork Sat Feb 24 13:54:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ond=C5=99ej_Jirman?= X-Patchwork-Id: 13570494 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 884FDC5478C for ; Sat, 24 Feb 2024 13:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=krFsRYIAolpDLEqOC97ZRZXaF1ZxVYiAeAazSNfWopA=; b=gcIKaT7bFTigg5 XGluCF4Q1zuG4aC1GhUYTH/8wcpkZrg33Uxkca+4tqBczZz0ef6E1fd4jrdnliZm6D7rjHU/R/z8D ZGaEEesOvBTG0aipvNxT7hBPzR74q2ctpY4WAhDWnN+Wd8Aj5FZJEp+4tt4wzpQjxPOQd6LVroRxt y5gyNR31MBFqVLXso2a0QN+26yVQHx2m0wGbfEXESLOxabWXTIzeDnKC/Pmm7k+/KlBrov//6YjZW IaSYYT2Gr/7y70RtpMvX4f/46XXF13aoPzD4T70JNJOwpQAdU/D0k7VdSUdPMs2sIYok98zjYdgTz O0A9k99qL92Ya7gjOBhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdsV0-0000000D06e-2G3I; Sat, 24 Feb 2024 13:55:30 +0000 Received: from vps.xff.cz ([195.181.215.36]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdsUg-0000000Czx5-3tJ2 for linux-arm-kernel@lists.infradead.org; Sat, 24 Feb 2024 13:55:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xff.cz; s=mail; t=1708782909; bh=Yqk0ASm3qdzudKQuluB7RYak2VVWIt+QMV2iJnIWwSI=; h=From:To:Cc:Subject:Date:References:From; b=YGQyERaXkCKyDWPMH36QpBpzqFlYB0fHMSVwd4U1y0yg34s7GsIleYaR7PkvMwJ6Y KDkmGOHRr6XiE6IXTnQLEDXf+q9VjEMM9GilmfDu4R3J2AgtX8m/v+pk703FZWjJ/C ShXBIIfOEALtX+a4dwac1i0slhy9/LItwhiiSUbQ= From: =?utf-8?q?Ond=C5=99ej_Jirman?= To: linux-kernel@vger.kernel.org, Liam Girdwood , Rob Herring , Conor Dooley , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Samuel Holland , Chen-Yu Tsai , Jernej Skrabec , Ondrej Jirman , Arnaud Ferraris , linux-sound@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: [RESEND PATCH v2 3/5] ASoC: sun8i-codec: Enable bus clock at STANDBY and higher bias Date: Sat, 24 Feb 2024 14:54:56 +0100 Message-ID: <20240224135501.3822390-4-megi@xff.cz> In-Reply-To: <20240224135501.3822390-1-megi@xff.cz> References: <20240224135501.3822390-1-megi@xff.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240224_055511_190361_357EF0C9 X-CRM114-Status: GOOD ( 17.62 ) 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: Samuel Holland For codec variants that have a bus clock, that clock must be running to receive interrupts. Since jack and mic accessory detection should work even when no audio is playing, that means the bus clock should be enabled any time the system is on. Accomplish that by tying the bus clock to the runtime PM state, which is then tied to the bias level not being OFF. Since the codec sets idle_bias_on, bias will generally never be OFF. However, we can set suspend_bias_off to maintain the power savings of gating the bus clock during suspend, when we don't expect jack/accessory detection to work. Signed-off-by: Samuel Holland Signed-off-by: Ondřej Jirman --- sound/soc/sunxi/sun8i-codec.c | 41 ++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/sound/soc/sunxi/sun8i-codec.c b/sound/soc/sunxi/sun8i-codec.c index 7b45ddffe990..2a46b96b03cc 100644 --- a/sound/soc/sunxi/sun8i-codec.c +++ b/sound/soc/sunxi/sun8i-codec.c @@ -177,12 +177,14 @@ struct sun8i_codec_aif { }; struct sun8i_codec_quirks { - bool legacy_widgets : 1; - bool lrck_inversion : 1; + bool bus_clock : 1; + bool legacy_widgets : 1; + bool lrck_inversion : 1; }; struct sun8i_codec { struct regmap *regmap; + struct clk *clk_bus; struct clk *clk_module; const struct sun8i_codec_quirks *quirks; struct sun8i_codec_aif aifs[SUN8I_CODEC_NAIFS]; @@ -197,6 +199,14 @@ static int sun8i_codec_runtime_resume(struct device *dev) struct sun8i_codec *scodec = dev_get_drvdata(dev); int ret; + if (scodec->clk_bus) { + ret = clk_prepare_enable(scodec->clk_bus); + if (ret) { + dev_err(dev, "Failed to enable the bus clock\n"); + return ret; + } + } + regcache_cache_only(scodec->regmap, false); ret = regcache_sync(scodec->regmap); @@ -215,6 +225,9 @@ static int sun8i_codec_runtime_suspend(struct device *dev) regcache_cache_only(scodec->regmap, true); regcache_mark_dirty(scodec->regmap); + if (scodec->clk_bus) + clk_disable_unprepare(scodec->clk_bus); + return 0; } @@ -1277,6 +1290,7 @@ static const struct snd_soc_component_driver sun8i_soc_component = { .num_dapm_routes = ARRAY_SIZE(sun8i_codec_dapm_routes), .probe = sun8i_codec_component_probe, .idle_bias_on = 1, + .suspend_bias_off = 1, .endianness = 1, }; @@ -1299,6 +1313,18 @@ static int sun8i_codec_probe(struct platform_device *pdev) if (!scodec) return -ENOMEM; + scodec->quirks = of_device_get_match_data(&pdev->dev); + + platform_set_drvdata(pdev, scodec); + + if (scodec->quirks->bus_clock) { + scodec->clk_bus = devm_clk_get(&pdev->dev, "bus"); + if (IS_ERR(scodec->clk_bus)) { + dev_err(&pdev->dev, "Failed to get the bus clock\n"); + return PTR_ERR(scodec->clk_bus); + } + } + scodec->clk_module = devm_clk_get(&pdev->dev, "mod"); if (IS_ERR(scodec->clk_module)) { dev_err(&pdev->dev, "Failed to get the module clock\n"); @@ -1311,17 +1337,14 @@ static int sun8i_codec_probe(struct platform_device *pdev) return PTR_ERR(base); } - scodec->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "bus", base, - &sun8i_codec_regmap_config); + scodec->regmap = devm_regmap_init_mmio(&pdev->dev, base, + &sun8i_codec_regmap_config); if (IS_ERR(scodec->regmap)) { dev_err(&pdev->dev, "Failed to create our regmap\n"); return PTR_ERR(scodec->regmap); } - scodec->quirks = of_device_get_match_data(&pdev->dev); - - platform_set_drvdata(pdev, scodec); - + regcache_cache_only(scodec->regmap, true); pm_runtime_enable(&pdev->dev); if (!pm_runtime_enabled(&pdev->dev)) { ret = sun8i_codec_runtime_resume(&pdev->dev); @@ -1357,11 +1380,13 @@ static void sun8i_codec_remove(struct platform_device *pdev) } static const struct sun8i_codec_quirks sun8i_a33_quirks = { + .bus_clock = true, .legacy_widgets = true, .lrck_inversion = true, }; static const struct sun8i_codec_quirks sun50i_a64_quirks = { + .bus_clock = true, }; static const struct of_device_id sun8i_codec_of_match[] = {