From patchwork Fri Nov 4 13:56:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 15539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp418946wru; Fri, 4 Nov 2022 07:00:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7z5FhOyrndNPFNaCUiYyuWjSnpFJQ0WvW2Pp4UdfElsR2o8JmE/z4jBzsp70aX3SkWE6sv X-Received: by 2002:a05:6402:1cca:b0:460:7d72:8f2 with SMTP id ds10-20020a0564021cca00b004607d7208f2mr36281159edb.205.1667570437040; Fri, 04 Nov 2022 07:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667570437; cv=none; d=google.com; s=arc-20160816; b=SIt03eIpS9L2Q9vyQ2u1WLpyFBKpvtaw4NhvrC8zTuap8Cex1VbYZRoawKJaKjRhtu TLIcRwXFkWeP9JCXrpUyUQNlJ3fSEB3vc9p5dDP32/hIVDNJqQWWmQfhGnJ4WVx+Te3i GXg0TuR0FKlwiZVBaZajAHFftdKhzyQ/laq3QCAgn2POsJa4/rmO+D0+prHHSU8hgIB9 Hy2Fq5lzMKPXRiNMYymuj2qxjm6SwrsCLK0082ujaOFJo0tOYsAWJPJ9MLY/ka1dDcHq fGVimLXrryJDydRcTl28Q7RiBYRto8cb0eRehJemx6UycKtVDtDxbgVdwEDudMLLgi8s oDNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=XPBXRa9w7YK7/mX5TsWakQgciRU5D3ll2jqB5IqI2G0=; b=dcPQ25nUCjQD3SVH7lJSkg89lwpjJtg/+l53pGECO2ISxcFQWkkCNZoOOuuTpA6T6Z sNAtujf8QG7qTix8h1KC4xlYdLrcpRbEFLSF5hxSo7Qt32EBJ7ce0VhKppWsilLMwzw4 5NMXMuh9Nok3N7PWG+mLpjOyfKRRnuI0t+7UhGRlgibyaqRjGb7Zc11sBRJJiqy8Q4+q VuCE2GQehhLggjJGvyBql+X2s6ToLxq4J6wnXeAeT/7qo56dToi9sm42ygGuqA6+Khh/ sWm/yTxCiHkq8SfzUSIa6cvwrdZQOSM2wVsrazErWdN4zPZnjCm8updzzAB1tRLoxPBe 7Sgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XrWseRGD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt34-20020a1709072da200b0073d710fec77si5733441ejc.251.2022.11.04.07.00.12; Fri, 04 Nov 2022 07:00:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XrWseRGD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231936AbiKDN5Y (ORCPT + 99 others); Fri, 4 Nov 2022 09:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231669AbiKDN5J (ORCPT ); Fri, 4 Nov 2022 09:57:09 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA5592F3A3 for ; Fri, 4 Nov 2022 06:57:02 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id gw22so4571826pjb.3 for ; Fri, 04 Nov 2022 06:57:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XPBXRa9w7YK7/mX5TsWakQgciRU5D3ll2jqB5IqI2G0=; b=XrWseRGDX/666oj7zxpWUZ59i7mlMuNt+zLtA+mT+5ZFDMOrzDCKzoLrCXfYZGut9p HU0xr7K/MflpEV76tvyrBADQftwgoYj2BwchTPnDyg8dKm9l6NjrUXSBhepRU5r1mbvi 38IZfsDxw3QQLlDN+cBVxOwqMpEsurI1C3n5k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XPBXRa9w7YK7/mX5TsWakQgciRU5D3ll2jqB5IqI2G0=; b=RiS1IZOm08GG/XkKapzVAC7F/1Ly8cNMDyqbTwI5fx0ykOtalMT6zyeFkFwtk9btyA oqtU8zka6H4TEJKUgsG4Vv7iQDh0hkfFfmEwHL5rCfvRvCKohOz9EkZcMcqZKs3Gl5qi 0rRa3JYjbpjjBn34+Rs1JfKMpW3X+j7NqF6iSfpSL7EdgRC8Xa2iQrwMLcYzbxDNsM9R lWzQadAf/UddlNqV3+VcFfuRzO0CPgWuXSMPjQm2k+5FPGy3TRaxQlo1k3jSjCwvFPqE 2lmQC00GBvdrP1dqtufmB8Fo2Ym/YtxiZr4H3SB/nJzICujbS5rDKjVcVvX89k5ZFduQ /mqw== X-Gm-Message-State: ACrzQf3S+5/BvCoBZxcMnQvVt/RbAAQJv25m14PXW0D75g4/0WGLsd3K IsGGKZpMjx1HW2wAhPSPuS4n9g== X-Received: by 2002:a17:903:240a:b0:183:6555:7a89 with SMTP id e10-20020a170903240a00b0018365557a89mr35545147plo.68.1667570222142; Fri, 04 Nov 2022 06:57:02 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:5e74:f068:4840:3631]) by smtp.gmail.com with ESMTPSA id m6-20020a62a206000000b0056bf29c9ba3sm2829367pff.146.2022.11.04.06.56.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:57:00 -0700 (PDT) From: Douglas Anderson To: Stephen Boyd , Bjorn Andersson Cc: Taniya Das , Dmitry Baryshkov , Judy Hsiao , Srinivasa Rao Mandadapu , Matthias Kaehlcke , Douglas Anderson , Andy Gross , Konrad Dybcio , Michael Turquette , Stephen Boyd , Taniya Das , linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] clk: qcom: lpass-sc7280: Fix pm_runtime usage Date: Fri, 4 Nov 2022 06:56:28 -0700 Message-Id: <20221104064055.1.I00a0e4564a25489e85328ec41636497775627564@changeid> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog MIME-Version: 1.0 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748574338554345133?= X-GMAIL-MSGID: =?utf-8?q?1748574338554345133?= The pm_runtime usage in lpass-sc7280 was broken in quite a few ways. Specifically: 1. At the end of probe it called "put" twice. This is a no-no and will end us up with a negative usage count. Even worse than calling "put" twice, it never called "get" once. Thus after bootup it could be seen that the runtime usage of the devices managed by this driver was -2. 2. In some error cases it manually called pm_runtime_disable() even though it had previously used devm_add_action_or_reset() to set this up to be called automatically. This meant that in these error cases we'd double-call pm_runtime_disable(). 3. It forgot to call undo pm_runtime_use_autosuspend(), which can sometimes have subtle problems (and the docs specifically mention that you need to undo this function). Overall the above seriously calls into question how this driver is working. It seems like a combination of "it doesn't", "by luck", and "because of the weirdness of runtime_pm". Specifically I put a printout to the serial console every time the runtime suspend/resume was called for the two devices created by this driver (I wrapped the pm_clk calls). When I had serial console enabled, I found that the calls got resumed at bootup (when the clk core probed and before our double-put) and then never touched again. That's no good. [ 0.829997] DOUG: my_pm_clk_resume, usage=1 [ 0.835487] DOUG: my_pm_clk_resume, usage=1 When I disabled serial console (speeding up boot), I got a different pattern, which I guess (?) is better: [ 0.089767] DOUG: my_pm_clk_resume, usage=1 [ 0.090507] DOUG: my_pm_clk_resume, usage=1 [ 0.151885] DOUG: my_pm_clk_suspend, usage=-2 [ 0.151914] DOUG: my_pm_clk_suspend, usage=-2 [ 1.825747] DOUG: my_pm_clk_resume, usage=-1 [ 1.825774] DOUG: my_pm_clk_resume, usage=-1 [ 1.888269] DOUG: my_pm_clk_suspend, usage=-2 [ 1.888282] DOUG: my_pm_clk_suspend, usage=-2 These different patterns have to do with the fact that the core PM Runtime code really isn't designed to be robust to negative usage counts and sometimes may happen to stumble upon a behavior that happens to "work". For instance, you can see that __pm_runtime_suspend() will treat any non-zero value (including negative numbers) as if the device is in use. In any case, let's fix the driver to be correct. We'll hold a pm_runtime reference for the whole probe and then drop it (once!) at the end. We'll get rid of manual pm_runtime_disable() calls in the error handling. We'll also switch to devm_pm_runtime_enable(), which magically handles undoing pm_runtime_use_autosuspend() as of commit b4060db9251f ("PM: runtime: Have devm_pm_runtime_enable() handle pm_runtime_dont_use_autosuspend()"). While we're at this, let's also use devm_pm_clk_create() instead of rolling it ourselves. Note that the above changes make it obvious that lpassaudio_create_pm_clks() was doing more than just creating clocks. It was also setting up pm_runtime parameters. Let's rename it. All of these problems were found by code inspection. I started looking at this driver because it was involved in a deadlock that I reported a while ago [1]. Though I bisected the deadlock to commit 1b771839de05 ("clk: qcom: gdsc: enable optional power domain support"), it was never really clear why that patch affected it other than a luck of timing changes. I'll also note that by fixing the timing (as done in this change) we also seem to aboid the deadlock, which is a nice benefit. Also note that some of the fixes here are much the same type of stuff that Dmitry did in commit 72cfc73f4663 ("clk: qcom: use devm_pm_runtime_enable and devm_pm_clk_create"), but I guess lpassaudiocc-sc7280.c didn't exist then. [1] https://lore.kernel.org/r/20220922154354.2486595-1-dianders@chromium.org Fixes: a9dd26639d05 ("clk: qcom: lpass: Add support for LPASS clock controller for SC7280") Signed-off-by: Douglas Anderson Reviewed-by: Stephen Boyd Reviewed-by: Dmitry Baryshkov --- drivers/clk/qcom/lpassaudiocc-sc7280.c | 55 ++++++++++---------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/drivers/clk/qcom/lpassaudiocc-sc7280.c b/drivers/clk/qcom/lpassaudiocc-sc7280.c index 063e0365f311..1339f9211a14 100644 --- a/drivers/clk/qcom/lpassaudiocc-sc7280.c +++ b/drivers/clk/qcom/lpassaudiocc-sc7280.c @@ -722,33 +722,17 @@ static const struct of_device_id lpass_audio_cc_sc7280_match_table[] = { }; MODULE_DEVICE_TABLE(of, lpass_audio_cc_sc7280_match_table); -static void lpassaudio_pm_runtime_disable(void *data) -{ - pm_runtime_disable(data); -} - -static void lpassaudio_pm_clk_destroy(void *data) -{ - pm_clk_destroy(data); -} - -static int lpassaudio_create_pm_clks(struct platform_device *pdev) +static int lpass_audio_setup_runtime_pm(struct platform_device *pdev) { int ret; pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, 50); - pm_runtime_enable(&pdev->dev); - - ret = devm_add_action_or_reset(&pdev->dev, lpassaudio_pm_runtime_disable, &pdev->dev); - if (ret) - return ret; - - ret = pm_clk_create(&pdev->dev); + ret = devm_pm_runtime_enable(&pdev->dev); if (ret) return ret; - ret = devm_add_action_or_reset(&pdev->dev, lpassaudio_pm_clk_destroy, &pdev->dev); + ret = devm_pm_clk_create(&pdev->dev); if (ret) return ret; @@ -756,7 +740,7 @@ static int lpassaudio_create_pm_clks(struct platform_device *pdev) if (ret < 0) dev_err(&pdev->dev, "failed to acquire iface clock\n"); - return ret; + return pm_runtime_resume_and_get(&pdev->dev); } static int lpass_audio_cc_sc7280_probe(struct platform_device *pdev) @@ -765,7 +749,7 @@ static int lpass_audio_cc_sc7280_probe(struct platform_device *pdev) struct regmap *regmap; int ret; - ret = lpassaudio_create_pm_clks(pdev); + ret = lpass_audio_setup_runtime_pm(pdev); if (ret) return ret; @@ -775,8 +759,8 @@ static int lpass_audio_cc_sc7280_probe(struct platform_device *pdev) regmap = qcom_cc_map(pdev, desc); if (IS_ERR(regmap)) { - pm_runtime_disable(&pdev->dev); - return PTR_ERR(regmap); + ret = PTR_ERR(regmap); + goto exit; } clk_zonda_pll_configure(&lpass_audio_cc_pll, regmap, &lpass_audio_cc_pll_config); @@ -788,20 +772,18 @@ static int lpass_audio_cc_sc7280_probe(struct platform_device *pdev) ret = qcom_cc_really_probe(pdev, &lpass_audio_cc_sc7280_desc, regmap); if (ret) { dev_err(&pdev->dev, "Failed to register LPASS AUDIO CC clocks\n"); - pm_runtime_disable(&pdev->dev); - return ret; + goto exit; } ret = qcom_cc_probe_by_index(pdev, 1, &lpass_audio_cc_reset_sc7280_desc); if (ret) { dev_err(&pdev->dev, "Failed to register LPASS AUDIO CC Resets\n"); - pm_runtime_disable(&pdev->dev); - return ret; + goto exit; } pm_runtime_mark_last_busy(&pdev->dev); +exit: pm_runtime_put_autosuspend(&pdev->dev); - pm_runtime_put_sync(&pdev->dev); return ret; } @@ -839,14 +821,15 @@ static int lpass_aon_cc_sc7280_probe(struct platform_device *pdev) struct regmap *regmap; int ret; - ret = lpassaudio_create_pm_clks(pdev); + ret = lpass_audio_setup_runtime_pm(pdev); if (ret) return ret; if (of_property_read_bool(pdev->dev.of_node, "qcom,adsp-pil-mode")) { lpass_audio_cc_sc7280_regmap_config.name = "cc"; desc = &lpass_cc_sc7280_desc; - return qcom_cc_probe(pdev, desc); + ret = qcom_cc_probe(pdev, desc); + goto exit; } lpass_audio_cc_sc7280_regmap_config.name = "lpasscc_aon"; @@ -854,18 +837,22 @@ static int lpass_aon_cc_sc7280_probe(struct platform_device *pdev) desc = &lpass_aon_cc_sc7280_desc; regmap = qcom_cc_map(pdev, desc); - if (IS_ERR(regmap)) - return PTR_ERR(regmap); + if (IS_ERR(regmap)) { + ret = PTR_ERR(regmap); + goto exit; + } clk_lucid_pll_configure(&lpass_aon_cc_pll, regmap, &lpass_aon_cc_pll_config); ret = qcom_cc_really_probe(pdev, &lpass_aon_cc_sc7280_desc, regmap); - if (ret) + if (ret) { dev_err(&pdev->dev, "Failed to register LPASS AON CC clocks\n"); + goto exit; + } pm_runtime_mark_last_busy(&pdev->dev); +exit: pm_runtime_put_autosuspend(&pdev->dev); - pm_runtime_put_sync(&pdev->dev); return ret; } From patchwork Fri Nov 4 13:56:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 15543 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp420640wru; Fri, 4 Nov 2022 07:02:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4p1PxenLp339R6Ad5OH/56VlYmf9yqzpv9f+Ef9+yN1nc18REja4fiigAkERgpH4B/MAQy X-Received: by 2002:a17:902:c950:b0:187:3da6:37ec with SMTP id i16-20020a170902c95000b001873da637ecmr17027205pla.139.1667570564373; Fri, 04 Nov 2022 07:02:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667570564; cv=none; d=google.com; s=arc-20160816; b=SDymNx9x1PIN8VQXdUBy4iTjQP8i8F2D1Lcl5hk4VmqHZsJbtKYgny3iWGQCCSNSyC dt6XbyXGr+y983UrSh7oCv4FI55keu4tjPDm6xh37F0FPoTDgk8DY87N4su5EYC0o55y Fi6taKBMmL1ng6VUkfPwibP0yksyCevHxORM6wFeL0ANOGbbXoEN/hauqF2pvMzhJrWR HYd7lZ7Prx0V21+HqwK5zvIknEWVz+HQQArBj9BCmdLulz4XXt12CZZU9Pfy9fnE62J7 DYW6haHrpf+kLIs4AmI5MgIRJrm0veFIaIAXVrjNUwwaKnC2eEu65AwFyLGI2wWWp718 MJeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pNFF0xwQukCs3t/Tcp1ZLLt+pMarR7751wvJ6nmpdnw=; b=ZqQrt2mr6vLt4VHIYdnoKwx5k+LbS2/jcAQfKhrCmyDxYD7qPYVCOjS1BeItIX8HyC +gTMf4THZ3OnBF9DemkcpjYD5cZCdUARPi39/BvbCxaUHeA5UkVwbhghOur9qLFF95a1 tMkBo31jeRL1VEjuTtPra7TbkHtcicDxacXjN6JcmdJaFREX3SFzyBH4UbK+6dE2nR0+ JfRHPosOgZMO3ZMKGNj7YY91ET47HxftIhor/ZVVWIDGHfCg2tW9mCfbVVq/CIxiZzby gN9XBIY7u7TQnE1L5RzMzFHG44Sw1D6q1cjXGF7bnXB66QA8NWI9DjsGBNc327QYsmBQ iFMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AvpLIKqz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f13-20020a62380d000000b00563653bc151si4613778pfa.110.2022.11.04.07.02.29; Fri, 04 Nov 2022 07:02:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AvpLIKqz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231754AbiKDN5f (ORCPT + 99 others); Fri, 4 Nov 2022 09:57:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231791AbiKDN5M (ORCPT ); Fri, 4 Nov 2022 09:57:12 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A18442F3B5 for ; Fri, 4 Nov 2022 06:57:04 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id 4so4992863pli.0 for ; Fri, 04 Nov 2022 06:57:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pNFF0xwQukCs3t/Tcp1ZLLt+pMarR7751wvJ6nmpdnw=; b=AvpLIKqzh8Z7IGR1bHjIsdjNzwZeXvEUDsikM0w2+/gdPKQnVWd46Ttee+kJVmN7nu bNYKWXo1aGRU109CG3OssKJFbdvh95q9QvjgCQIdM6qnUkRmvtA+kaUcOoidYsXMQfNS Z1XTJ7WfyzuL2yw+LcPwGmyXhCNAtIzPwMBSU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pNFF0xwQukCs3t/Tcp1ZLLt+pMarR7751wvJ6nmpdnw=; b=V3GSO0ZYiKjAlUZssdF8lNpZqnanG+sBwfTYYHo4mLlGUnU3j0DTeIV/UUqajUIdlf VosRLOHUVQntu6AjkUx106JyHugfYjwwhHB9nwmtmeqvMGto2ETMBxYyRNA2S/8ZmupI +3NmKvhKcQnhchDIxEqvBPu245tJJhRZrAXT1hGY4yqCklmFcWWtmZKBI3qybh7VqE5/ bJGxpZsmvb1phfy5RzfuPg82gJYtorhj/f/n5igmWRzKOQ2Ugnix35DR6IxEMHUyM3dE mXLppDk+BzglGEnpwxOHAX4bIJQIyPG3xpCSRIbt/Wz/tnbcbbSyuV0uMhTA0omUTayR ah1w== X-Gm-Message-State: ACrzQf1TB6iJdyQRXZDWRnthwNAhVJm2Ayqoi0+unpD/rV1lmhpVUCc1 GzQFnN1nHTCKqfOJPf97RirSCQ== X-Received: by 2002:a17:90b:278b:b0:213:c2f2:6ca1 with SMTP id pw11-20020a17090b278b00b00213c2f26ca1mr31733384pjb.103.1667570223871; Fri, 04 Nov 2022 06:57:03 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:5e74:f068:4840:3631]) by smtp.gmail.com with ESMTPSA id m6-20020a62a206000000b0056bf29c9ba3sm2829367pff.146.2022.11.04.06.57.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:57:03 -0700 (PDT) From: Douglas Anderson To: Stephen Boyd , Bjorn Andersson Cc: Taniya Das , Dmitry Baryshkov , Judy Hsiao , Srinivasa Rao Mandadapu , Matthias Kaehlcke , Douglas Anderson , Andy Gross , Konrad Dybcio , Michael Turquette , Stephen Boyd , linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] clk: qcom: lpass-sc7180: Fix pm_runtime usage Date: Fri, 4 Nov 2022 06:56:29 -0700 Message-Id: <20221104064055.2.I49b25b9bda9430fc7ea21e5a708ca5a0aced2798@changeid> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221104064055.1.I00a0e4564a25489e85328ec41636497775627564@changeid> References: <20221104064055.1.I00a0e4564a25489e85328ec41636497775627564@changeid> MIME-Version: 1.0 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748574472184127772?= X-GMAIL-MSGID: =?utf-8?q?1748574472184127772?= The sc7180 lpass clock controller's pm_runtime usage wasn't broken quite as spectacularly as the sc7280's pm_runtime usage, but it was still broken. Putting some printouts in at boot showed me this (with serial console enabled, which makes the prints slow and thus changes timing): [ 3.109951] DOUG: my_pm_clk_resume, usage=1 [ 3.114767] DOUG: my_pm_clk_resume, usage=1 [ 3.664443] DOUG: my_pm_clk_suspend, usage=0 [ 3.897566] DOUG: my_pm_clk_suspend, usage=0 [ 3.910137] DOUG: my_pm_clk_resume, usage=1 [ 3.923217] DOUG: my_pm_clk_resume, usage=0 [ 4.440116] DOUG: my_pm_clk_suspend, usage=-1 [ 4.444982] DOUG: my_pm_clk_suspend, usage=0 [ 14.170501] DOUG: my_pm_clk_resume, usage=1 [ 14.176245] DOUG: my_pm_clk_resume, usage=0 ...or this w/out serial console: [ 0.556139] DOUG: my_pm_clk_resume, usage=1 [ 0.556279] DOUG: my_pm_clk_resume, usage=1 [ 1.058422] DOUG: my_pm_clk_suspend, usage=-1 [ 1.058464] DOUG: my_pm_clk_suspend, usage=0 [ 1.186250] DOUG: my_pm_clk_resume, usage=1 [ 1.186292] DOUG: my_pm_clk_resume, usage=0 [ 1.731536] DOUG: my_pm_clk_suspend, usage=-1 [ 1.731557] DOUG: my_pm_clk_suspend, usage=0 [ 10.288910] DOUG: my_pm_clk_resume, usage=1 [ 10.289496] DOUG: my_pm_clk_resume, usage=0 It seems to be doing roughly the right sequence of calls, but just like with sc7280 this is more by luck than anything. Having a usage of -1 is just not OK. Let's fix this like we did with sc7280. Signed-off-by: Douglas Anderson Reviewed-by: Stephen Boyd --- drivers/clk/qcom/lpasscorecc-sc7180.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/clk/qcom/lpasscorecc-sc7180.c b/drivers/clk/qcom/lpasscorecc-sc7180.c index ac09b7b840ab..a5731994cbed 100644 --- a/drivers/clk/qcom/lpasscorecc-sc7180.c +++ b/drivers/clk/qcom/lpasscorecc-sc7180.c @@ -356,7 +356,7 @@ static const struct qcom_cc_desc lpass_audio_hm_sc7180_desc = { .num_gdscs = ARRAY_SIZE(lpass_audio_hm_sc7180_gdscs), }; -static int lpass_create_pm_clks(struct platform_device *pdev) +static int lpass_setup_runtime_pm(struct platform_device *pdev) { int ret; @@ -375,7 +375,7 @@ static int lpass_create_pm_clks(struct platform_device *pdev) if (ret < 0) dev_err(&pdev->dev, "failed to acquire iface clock\n"); - return ret; + return pm_runtime_resume_and_get(&pdev->dev); } static int lpass_core_cc_sc7180_probe(struct platform_device *pdev) @@ -384,7 +384,7 @@ static int lpass_core_cc_sc7180_probe(struct platform_device *pdev) struct regmap *regmap; int ret; - ret = lpass_create_pm_clks(pdev); + ret = lpass_setup_runtime_pm(pdev); if (ret) return ret; @@ -392,12 +392,14 @@ static int lpass_core_cc_sc7180_probe(struct platform_device *pdev) desc = &lpass_audio_hm_sc7180_desc; ret = qcom_cc_probe_by_index(pdev, 1, desc); if (ret) - return ret; + goto exit; lpass_core_cc_sc7180_regmap_config.name = "lpass_core_cc"; regmap = qcom_cc_map(pdev, &lpass_core_cc_sc7180_desc); - if (IS_ERR(regmap)) - return PTR_ERR(regmap); + if (IS_ERR(regmap)) { + ret = PTR_ERR(regmap); + goto exit; + } /* * Keep the CLK always-ON @@ -415,6 +417,7 @@ static int lpass_core_cc_sc7180_probe(struct platform_device *pdev) ret = qcom_cc_really_probe(pdev, &lpass_core_cc_sc7180_desc, regmap); pm_runtime_mark_last_busy(&pdev->dev); +exit: pm_runtime_put_autosuspend(&pdev->dev); return ret; @@ -425,14 +428,19 @@ static int lpass_hm_core_probe(struct platform_device *pdev) const struct qcom_cc_desc *desc; int ret; - ret = lpass_create_pm_clks(pdev); + ret = lpass_setup_runtime_pm(pdev); if (ret) return ret; lpass_core_cc_sc7180_regmap_config.name = "lpass_hm_core"; desc = &lpass_core_hm_sc7180_desc; - return qcom_cc_probe_by_index(pdev, 0, desc); + ret = qcom_cc_probe_by_index(pdev, 0, desc); + + pm_runtime_mark_last_busy(&pdev->dev); + pm_runtime_put_autosuspend(&pdev->dev); + + return ret; } static const struct of_device_id lpass_hm_sc7180_match_table[] = { From patchwork Fri Nov 4 13:56:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 15548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp421585wru; Fri, 4 Nov 2022 07:03:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5MU2JQAGs6TXcat5dpc9OrPbT0iXMpwK9Lsi59QK/eE5OcK1C2lFOWziI4KcFkwQIvQzXK X-Received: by 2002:a17:906:9414:b0:7ad:bde1:3ccf with SMTP id q20-20020a170906941400b007adbde13ccfmr30981452ejx.543.1667570635427; Fri, 04 Nov 2022 07:03:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667570635; cv=none; d=google.com; s=arc-20160816; b=tQPKY5eEGiqs9BJLvTqo/h8kULCBnuRhNy1aXUoEpdV9dt6RjZWiiFpNgCA2OB9oWJ NNcRsYMQPS5bnRIuT6aVDuCLqHsNzEdRec4K53IepaIe1jvVA2E093dEJsQFCpL/TG+n YjNYKhJ9Cn0irrIQA+Qx2/++RSHdMdByVIEF5rzgUsGt2G8v0dDCEcaAvFK3+MyIvvzA 5/CGqzl0q2+LZjhvY4FEFebK97MmnPma/Q+E9BK3IRGFGf1XFvw5k+YZgfEubfOrAPmA ayyrteRmtaFk4yPDVZvZFCmc6ys5/6hcVHcNY3X4FJb3wn94O8jsfVyO0obtx/83hFKx dlCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aUmqfMirOXscpTm4z7KeYAbRwSxaLS1LCpAqzIugH4o=; b=AxrfAyqH8saW+FCzFdbfcszBz6WdqNDocf3sUZfLvqBrT1xmkjcIU9uJIynh2DyDym 7SffuLK1x1Uh1whdB9rHc9SoVSeq3dQN9jpFzfYu8eLzYHqroD2cFBW7mmzdRNACorsL aSaoybwHxoJY00pH1CnVIsAtKYGLNzL8djvFMVozW2E5aMfYPwVsS70rzTU1V2or3peQ hjArSXJZuA5Nmw7dSjpHBqn7q5pkPSSDXvs5aE3d3Jlvj5vWKLtvqyR6is0De3mqz+eJ 5ZTe1DlaCM/XsoGly+ZLQYThmEOa3jaeu4ha26/Gw/ou/IKLZe/AUi/f1biux6w/Zrsp BPcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="eFXFoY//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm5-20020a170907948500b007ac2daa0b49si5609001ejc.367.2022.11.04.07.03.27; Fri, 04 Nov 2022 07:03:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="eFXFoY//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231653AbiKDN5k (ORCPT + 99 others); Fri, 4 Nov 2022 09:57:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231821AbiKDN5N (ORCPT ); Fri, 4 Nov 2022 09:57:13 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D21312F65B for ; Fri, 4 Nov 2022 06:57:06 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id h14so4565094pjv.4 for ; Fri, 04 Nov 2022 06:57:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aUmqfMirOXscpTm4z7KeYAbRwSxaLS1LCpAqzIugH4o=; b=eFXFoY//OFMqP6HSReO/W8MW+RQMgzamdcVyeG9A7zNIChv+0Da/f6kd5ZBVa+JgOF sqx8QNOHF8Iz3fjRKHGsiVn65gJms5N1Uh6g0EIJTCKtoxXEs6BITwDvAu1GMU0PHQN5 HtdwShla/MTLqVq2kK6sGwV8+WKJNedmFYYQQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aUmqfMirOXscpTm4z7KeYAbRwSxaLS1LCpAqzIugH4o=; b=laak3IYjk0Et8ZvVgX0+WeTch4bFyyRK62csP8eFW2Xj4rOubZGulpO/kRJCLf1tZ6 fMuX1Jynb5JfeHqevBOgPF/BoPveoUvpudTWNbmCykN3bY0BS0RCz06+BZUPL4V1P4l7 Ai89P3C0Ugs+m/LKvqE7he2sqTHMxGEvARJwLzjCJijcfxiqApKrAOrLC5KG+VgHu1mv p+hyW+hNOqPlrfht9WTkAPu5NlK+cZGpQG54clK0t3/A/AbNK/+k5WWut6lUWEz5i4E2 B8w9e8YvAfe7pWOE1d4t+sNVK34CBrEl5kITLLUbF6GyFuB65u/4WWSguYjfyvhhikbo FgkQ== X-Gm-Message-State: ACrzQf2aABQLugW3WS/lF/lDuqP39f4kKIvckhFOHOq5tubJi+NXdBQ8 9OEmthMNTb5HOTQwW53bahUSRw== X-Received: by 2002:a17:903:41c3:b0:186:dfe6:f25 with SMTP id u3-20020a17090341c300b00186dfe60f25mr34810903ple.47.1667570226254; Fri, 04 Nov 2022 06:57:06 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:5e74:f068:4840:3631]) by smtp.gmail.com with ESMTPSA id m6-20020a62a206000000b0056bf29c9ba3sm2829367pff.146.2022.11.04.06.57.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:57:05 -0700 (PDT) From: Douglas Anderson To: Stephen Boyd , Bjorn Andersson Cc: Taniya Das , Dmitry Baryshkov , Judy Hsiao , Srinivasa Rao Mandadapu , Matthias Kaehlcke , Douglas Anderson , Andy Gross , Konrad Dybcio , Michael Turquette , Stephen Boyd , linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] clk: qcom: lpass-sc7180: Avoid an extra "struct dev_pm_ops" Date: Fri, 4 Nov 2022 06:56:30 -0700 Message-Id: <20221104064055.3.I90ba14a47683a484f26531a08f7b46ace7f0a8a9@changeid> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221104064055.1.I00a0e4564a25489e85328ec41636497775627564@changeid> References: <20221104064055.1.I00a0e4564a25489e85328ec41636497775627564@changeid> MIME-Version: 1.0 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748574546951601415?= X-GMAIL-MSGID: =?utf-8?q?1748574546951601415?= The two devices managed by lpasscorecc-sc7180.c each had their own "struct dev_pm_ops". This is not needed. They are exactly the same and the structure is "static const" so it can't possible change. combine the two. This matches what's done for sc7280. This should be a noop other than saving a few bytes. Signed-off-by: Douglas Anderson Reviewed-by: Stephen Boyd --- drivers/clk/qcom/lpasscorecc-sc7180.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/clk/qcom/lpasscorecc-sc7180.c b/drivers/clk/qcom/lpasscorecc-sc7180.c index a5731994cbed..33ed91c67e1c 100644 --- a/drivers/clk/qcom/lpasscorecc-sc7180.c +++ b/drivers/clk/qcom/lpasscorecc-sc7180.c @@ -459,7 +459,7 @@ static const struct of_device_id lpass_core_cc_sc7180_match_table[] = { }; MODULE_DEVICE_TABLE(of, lpass_core_cc_sc7180_match_table); -static const struct dev_pm_ops lpass_core_cc_pm_ops = { +static const struct dev_pm_ops lpass_pm_ops = { SET_RUNTIME_PM_OPS(pm_clk_suspend, pm_clk_resume, NULL) }; @@ -468,20 +468,16 @@ static struct platform_driver lpass_core_cc_sc7180_driver = { .driver = { .name = "lpass_core_cc-sc7180", .of_match_table = lpass_core_cc_sc7180_match_table, - .pm = &lpass_core_cc_pm_ops, + .pm = &lpass_pm_ops, }, }; -static const struct dev_pm_ops lpass_hm_pm_ops = { - SET_RUNTIME_PM_OPS(pm_clk_suspend, pm_clk_resume, NULL) -}; - static struct platform_driver lpass_hm_sc7180_driver = { .probe = lpass_hm_core_probe, .driver = { .name = "lpass_hm-sc7180", .of_match_table = lpass_hm_sc7180_match_table, - .pm = &lpass_hm_pm_ops, + .pm = &lpass_pm_ops, }, };