From patchwork Sat Mar 2 14:00:36 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: 209222 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp490179dyc; Sat, 2 Mar 2024 06:03:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVZ290IJccQOg0+0JwggVjF9ufSWckE+9QVYNoOikeEhNk0j7Oz87DMKvM72NZj67LHmoMm6ir4tNHolL9AbZHSOTmV4A== X-Google-Smtp-Source: AGHT+IHCVPAc/y/bgplsrvYnz87X1LXcJ9qGx9PVALPicsHIC3N9/7XjeJ1EX0EfBHLmglBFKwPn X-Received: by 2002:a17:90a:7e12:b0:29b:1c89:3770 with SMTP id i18-20020a17090a7e1200b0029b1c893770mr3787633pjl.4.1709388196896; Sat, 02 Mar 2024 06:03:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709388196; cv=pass; d=google.com; s=arc-20160816; b=TaSuOhpUEclzVgmBmcqvdJLXX9+eEJ405L38kwQjwGy22TKid5nQUBJtlwqIikgnz4 glVRfeIYv53T/PaYchHejJZcRd83JgNeW/4Lx575MDEsTMHtokGM+jqzTIJ42eWQR+73 3E3EWuZX7TDrXwKwJItMpIIrEDa42pa2DqBlo0PRsU1sxJ8IoMt6kmcHmxgGJ8HJoNqf 6TrBo9jc7iyEHjav+l8WsZH3BJJVpGtLW1UXi55TPiXupM+5Tn5ktT4e0uH3DHoi9zYS 7ZPy6RAxJe8YCqs2W+IHoWwN7V++dFLO3WeY3Z9Vpv2pvu25wUK5/FTx3rUomgQYJrf+ uiKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tZHBDvfrrAGtmB+/fidIX0U2hsjiIAxtdQ1EvOJidU4=; fh=QGdVBqYg4q7jIiN9KcNXeuSkybNfaLt8K5LfUlN67/I=; b=OUqh3qgp+tcvdLtGT80LZWMq6DJv4pM9Kh9lo9O+L1/8SW1TOs+GNhcISGBGo+2jCs 5/7OZS9/tUvmd6tthOz4bmq6DREclGfwGWZSG9y4Dtu3N61PH2oiN6grusALumHCeQvM O46hC/9vVrUQj0MzmEtjVSAXxoGf6Nqm5lpjc/WRAV3SoCcAq8yvSAe9oUJxlhKnHfWi dxbRuEbbHKpH7MWR6/a8PvmMLEh6G2QXy5cklHybkv+0NgwlI9H/iKYie8wjwZ+OvgCU sN1wBpe+j2/yX0tcsnMZy85R1mpXcLZEz2gVM9l3OYYijoV5XHYHhX4G1E7K/aBHkk4s LW7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=nqNlJMLp; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-89458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89458-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a10-20020a17090a688a00b0029b02c294f6si5526561pjd.0.2024.03.02.06.03.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Mar 2024 06:03:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=nqNlJMLp; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-89458-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89458-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C1CE1B20F09 for ; Sat, 2 Mar 2024 14:01:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8057E21370; Sat, 2 Mar 2024 14:00:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b="nqNlJMLp" Received: from vps.xff.cz (vps.xff.cz [195.181.215.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD3BE17BB2; Sat, 2 Mar 2024 14:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.181.215.36 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709388052; cv=none; b=oZAHjjzA+/KXMw7p5vaDwizvqnnBTc8E/lD/mnBLQs1r7PE7GvyzqbqAvyYMEaZnVHUud2yXqIjrMvzMSBhiuBSKRp3egTZu9DxtyxQFqtDOJbTNUL+6eW4kX0mqYGZ3WFKDHOAwi3outm+W2LraUMSUkN+R88R64NrNZOj/EpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709388052; c=relaxed/simple; bh=r6weZvhYPX/wRF91u8nn22GC5bL37LloOCbH075rviA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ALjaNrQ5tR6+seLI/p2rUGXZFuiKgoCXgUI96ZW+BJWvmoziXUXvsOaTIPU8aVMTSoei8Q8vEPigHVW3EVKQgiacG9bapsiwtsfiuRdGeJzuYy5vOvI37GemP7i/u4jPX1+KaIDQ4Y+qg+z1nZLUww9bFxuKNKuHAvgykUzV8iE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz; spf=pass smtp.mailfrom=xff.cz; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b=nqNlJMLp; arc=none smtp.client-ip=195.181.215.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xff.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xff.cz; s=mail; t=1709388046; bh=r6weZvhYPX/wRF91u8nn22GC5bL37LloOCbH075rviA=; h=From:To:Cc:Subject:Date:References:From; b=nqNlJMLpQsjxq+vcHWEdWxRRo0BfU/Stbv995wm/amMCZmEv0BuX9dz+HSF18MMNX EiHSn4A9od7qYj0wb07RuT5N5n3ugRUeTQB6n/KwznkKr5p2ari4b/YoworsL9fYd9 BeiQ1WQRcohZpOMvFM6zUzQya0Oj4ylK22oZHoIQ= From: =?utf-8?q?Ond=C5=99ej_Jirman?= To: linux-kernel@vger.kernel.org, Liam Girdwood , 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, linux-sunxi@lists.linux.dev Subject: [PATCH v3 2/4] ASoC: sun8i-codec: Enable bus clock at STANDBY and higher bias Date: Sat, 2 Mar 2024 15:00:36 +0100 Message-ID: <20240302140042.1990256-3-megi@xff.cz> In-Reply-To: <20240302140042.1990256-1-megi@xff.cz> References: <20240302140042.1990256-1-megi@xff.cz> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792423438335291712 X-GMAIL-MSGID: 1792423438335291712 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[] = {