From patchwork Tue Mar 12 11:51:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pin-yen Lin X-Patchwork-Id: 13589878 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 8852DC54E66 for ; Tue, 12 Mar 2024 11:53:18 +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: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:In-Reply-To:References: List-Owner; bh=guVe1KaJjY7NTffMV9OQ9a8DQHi58tcnUCcOO0oa+5E=; b=X/bQ9XlcsfsnDp MUl+1y75M1NrDGinCh85Nun0psBfC+d9eE4IESSUma0N46cBI7RC9N0ouSmQSjCXLsI0+IrA5ZJWt l9oCD9ReAa0oNfkHIDkMMzJolJGwwxbJNy4LNeeJ7LMCUUQ224uAZS1mpz019GzJS5BBw5LHdIvRR 6SANx6axyHlzlCh19FQ6HAdjXx1sJDS1gbBhdeuMseb2N0L43WvVQGacHxZOUHCSg2m0WvmF3RudY fvO2EryKT4NgeQhkgSo+bz/TGFuI/j8pDiOZxhop1VNDDdEQv86mVHe/pd3kZp81wwtT9mgBcIcxH ChjG2PU3fwqFOB8TxvEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rk0gm-00000005aUv-3Tbm; Tue, 12 Mar 2024 11:53:00 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rk0gi-00000005aTZ-4B27 for linux-arm-kernel@lists.infradead.org; Tue, 12 Mar 2024 11:52:58 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6e6b22af648so16761b3a.0 for ; Tue, 12 Mar 2024 04:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1710244376; x=1710849176; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=32L7EdHAuQ4WnOqivRSfbIvHEBBAYz+hzKyLr7KyYy4=; b=KkBeyKuoV7I6cRsMn1UdOxYZAtzqs8/qSBYavSocTgQZeVp3szgMYESL1L8pWhU36Q TgptGFrdZcPoSIElCIfnASFxugn50z68er9gwOmJrwziLbRlSpxX+HCWO1Gn8f9H/WxM dgll4+c0ySLq2lHbaXK7X1LCfGgu9TKZKZGig= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710244376; x=1710849176; 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=32L7EdHAuQ4WnOqivRSfbIvHEBBAYz+hzKyLr7KyYy4=; b=QSr0xUt8v8CqUdsYtPkOyCjKEzAPwnnXQwpGLbBvkis8Z4JzbUYPWPe/e9ZuA9FPcJ N7k1elBjrZtuux1lzNDtJImVxDFWdjXmn6B/Dt0jZhFMHIakTLBfhACQYegDry+8+ow6 QTRmBz7wLRYv+xp4tVXiw9gPiUxfeFpbhuZrwt4ObejajjRfURQcM/1zWIrfX3akmgsP lEAAR50b6Dji7w3tg4UyPcVYAXX+isqNTvC8Z2ZPrB4oXAzNkFbeSMrZ78GNX4TBQ2PC 9DXfok3wI73ZzVSbMsr7YPzWV45Rq2FxPriWmpGbu+6k/PnbRWvcTN+mPJWrZaVskuiY JrlA== X-Forwarded-Encrypted: i=1; AJvYcCUb6jZC0LJDiMbeF7ITDyjSBqtrgHS4282RA9xoMjQ4Euk0s7JS/14ZTuI2kJo11rzFC7YHumz7yzIue8ZI7+VIJk4TUGBwFY0fsp8Whz4GEB+UFzQ= X-Gm-Message-State: AOJu0YxsPwg6scGmD7fEAXbVPEwpgYR/xUB8Q2+CB++CQ1FXYX0IOOHK BN+E+/2EN60/NFdfD0AEQmWIDyFhEJX58acz3fqj9Y46fPO9GneKGC5QnnPTpIf5GWadX0RylTA = X-Google-Smtp-Source: AGHT+IFHW7gNc8FGsMt9K1fDNHiUJ5TT/QPfRrLz4t4aGJMOagv8xqOkZuJYIn0TiohOgI7RjlfCgg== X-Received: by 2002:a17:902:d2d2:b0:1dd:c227:4175 with SMTP id n18-20020a170902d2d200b001ddc2274175mr813268plc.8.1710244375852; Tue, 12 Mar 2024 04:52:55 -0700 (PDT) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:bae3:7b5f:7434:812e]) by smtp.gmail.com with ESMTPSA id b15-20020a170903228f00b001dd1bdee6d9sm6500179plh.31.2024.03.12.04.52.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 04:52:55 -0700 (PDT) From: Pin-yen Lin To: Michael Turquette , Stephen Boyd , Matthias Brugger , AngeloGioacchino Del Regno Cc: Chen-Yu Tsai , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Pin-yen Lin , Weiyi Lu , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Bosi Zhang , Nicolas Boichat , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Subject: [PATCH v4] clk: mediatek: Do a runtime PM get on controllers during probe Date: Tue, 12 Mar 2024 19:51:55 +0800 Message-ID: <20240312115249.3341654-1-treapking@chromium.org> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240312_045257_089891_86DA76AC X-CRM114-Status: GOOD ( 16.04 ) 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 mt8183-mfgcfg has a mutual dependency with genpd during the probing stage, which leads to a deadlock in the following call stack: CPU0: genpd_lock --> clk_prepare_lock genpd_power_off_work_fn() genpd_lock() generic_pm_domain::power_off() clk_unprepare() clk_prepare_lock() CPU1: clk_prepare_lock --> genpd_lock clk_register() __clk_core_init() clk_prepare_lock() clk_pm_runtime_get() genpd_lock() Do a runtime PM get at the probe function to make sure clk_register() won't acquire the genpd lock. Instead of only modifying mt8183-mfgcfg, do this on all mediatek clock controller probings because we don't believe this would cause any regression. Verified on MT8183 and MT8192 Chromebooks. Fixes: acddfc2c261b ("clk: mediatek: Add MT8183 clock support") Signed-off-by: Pin-yen Lin Tested-by: AngeloGioacchino Del Regno Reviewed-by: AngeloGioacchino Del Regno --- v3: https://lore.kernel.org/all/20240108081834.408403-1-treapking@chromium.org/ Changes in v4: - Remove the need_runtime_pm flag and apply this to all mtk controllers Changes in v3: - Update the commit message and the comments before runtime PM call Changes in v2: - Fix the order of error handling - Update the commit message and add a comment before the runtime PM call drivers/clk/mediatek/clk-mtk.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 2e55368dc4d8..bd37ab4d1a9b 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "clk-mtk.h" @@ -494,6 +495,16 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev, return IS_ERR(base) ? PTR_ERR(base) : -ENOMEM; } + + devm_pm_runtime_enable(&pdev->dev); + /* + * Do a pm_runtime_resume_and_get() to workaround a possible + * deadlock between clk_register() and the genpd framework. + */ + r = pm_runtime_resume_and_get(&pdev->dev); + if (r) + return r; + /* Calculate how many clk_hw_onecell_data entries to allocate */ num_clks = mcd->num_clks + mcd->num_composite_clks; num_clks += mcd->num_fixed_clks + mcd->num_factor_clks; @@ -574,6 +585,8 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev, goto unregister_clks; } + pm_runtime_put(&pdev->dev); + return r; unregister_clks: @@ -604,6 +617,8 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev, free_base: if (mcd->shared_io && base) iounmap(base); + + pm_runtime_put(&pdev->dev); return r; }