From patchwork Wed Jul 13 08:21:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12916244 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 CF768C43334 for ; Wed, 13 Jul 2022 08:22:50 +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=Jj7iWvxoRaTrrvscctSFLXqJ5P7f11NHmI+9NxuTN4A=; b=IKpo9UiBldOcKa e/NNnisaqlxKyUgbqMGAyQnmcFRDvRvQ9a8UxK4wpVrAAqNG1P87LqhJI9AImMQS5YbdzUp+5cGu4 v1ZPdSBv9cQIM9HHeRt4SfWhkMACRdAPd1y+9aau5NQG+uLtjo8yjtbDyIrzseMyZos8neF9V0KIL WhCi9pJnpFJZY8oZrjsAP+m3FnmNfRjwJsMl+a8fek00btr2hGOdMzWFCX02IzbDY9tfVK0JcRZah mC+bJ7u7VWm8KzHmw/GsrCItvYP/5dAApUit+Ik5cL9SrczZY2zZCPP8F7a+vc3Ncn2LP1PKeKIfD Ay1BtvqJCzIR67sbIK2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oBXcu-001bSi-Sl; Wed, 13 Jul 2022 08:21:45 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oBXcY-001bFg-0G for linux-arm-kernel@lists.infradead.org; Wed, 13 Jul 2022 08:21:23 +0000 Received: by mail-pg1-x531.google.com with SMTP id f65so549485pgc.12 for ; Wed, 13 Jul 2022 01:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OZzK5y0eIxncPQQ3hhM9CtKDdXTROOL9hGvuVufD4R0=; b=LVI7afIdx9YSScvsEUrrMCzTkjoehM3oIiQd60Ag7fskFqaUqKhz59wT/5iO31iaAQ ISJkReGxxe8n7SMMi+PSUi2U8QN/QnaJ6OC15vnwjpMlv7UF27CCtQEBPf/eR87Ns0wF yS/CI1F71Aftmnf8Z4VRjx/9AP5po0GUnxw/M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OZzK5y0eIxncPQQ3hhM9CtKDdXTROOL9hGvuVufD4R0=; b=HOE2d5pSoAmm8hoDbGtS6ZrzeqZbVRcaaG+J1F6uPrSzUESpLBeR6Z5ydHaetBYq1k DueKRXYmwQAALVKMvsFp1xlITCqUUmCC/F1gdRjIEqN9yoKeNd/5OtNrOTbGRX9NmK50 mPRbdMkDnLQApXHOg4f6YAV6NiOudL7QQ9HNwbn7+K2Xzj3GJ/cN1xtNLfOEjryk7TB2 cYR3xjtDdTYtW2FdBIQ4hfwQAC7hKg9CCAa18yAtkkmoNTFZPrpdCa7yF7RSGbpan9sd NxhayNWUb8IX2eA32DnT4YjskbVNBFNqnCKwQKRHlEZdBI9zaYGTj+MfQCriXvCRJGk/ LW+g== X-Gm-Message-State: AJIora9O61pMDrk9zIrPzP8my+xMjiWTdX9LkU6BJwJ6ODacbGWyl0A4 xFPLIjSa/nfIt4+dVeu6nxYVxg== X-Google-Smtp-Source: AGRyM1tvbTHGQRx2DcT1j1U+cdRg2iAmTleWHqHp1zVByPK8suxmR9yVUKvda5Yb1GsU3pIIGbZ8Cg== X-Received: by 2002:a63:27c3:0:b0:412:99f2:e483 with SMTP id n186-20020a6327c3000000b0041299f2e483mr1915203pgn.483.1657700479028; Wed, 13 Jul 2022 01:21:19 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:d1a9:ca7d:e86f:cf6f]) by smtp.gmail.com with ESMTPSA id k11-20020aa7972b000000b005281d926733sm8220461pfg.199.2022.07.13.01.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:21:18 -0700 (PDT) From: Chen-Yu Tsai To: Michael Turquette , Stephen Boyd Cc: Chen-Yu Tsai , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, AngeloGioacchino Del Regno , =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Subject: [PATCH v2 1/2] clk: core: Honor CLK_OPS_PARENT_ENABLE for clk gate ops Date: Wed, 13 Jul 2022 16:21:10 +0800 Message-Id: <20220713082111.2233016-2-wenst@chromium.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220713082111.2233016-1-wenst@chromium.org> References: <20220713082111.2233016-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220713_012122_080251_C4B94DEC X-CRM114-Status: GOOD ( 15.52 ) 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 In the previous commits that added CLK_OPS_PARENT_ENABLE, support for this flag was only added to rate change operations (rate setting and reparent) and disabling unused subtree. It was not added to the clock gate related operations. Any hardware driver that needs it for these operations will either see bogus results, or worse, hang. This has been seen on MT8192 and MT8195, where the imp_ii2_* clk drivers set this, but dumping debugfs clk_summary would cause it to hang. Fixes: fc8726a2c021 ("clk: core: support clocks which requires parents enable (part 2)") Fixes: a4b3518d146f ("clk: core: support clocks which requires parents enable (part 1)") Signed-off-by: Chen-Yu Tsai Reviewed-by: Nícolas F. R. A. Prado Tested-by: Nícolas F. R. A. Prado --- drivers/clk/clk.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 7fc191c15507..9b365cd6d14b 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -196,6 +196,9 @@ static bool clk_core_rate_is_protected(struct clk_core *core) return core->protect_count; } +static int clk_core_prepare_enable(struct clk_core *core); +static void clk_core_disable_unprepare(struct clk_core *core); + static bool clk_core_is_prepared(struct clk_core *core) { bool ret = false; @@ -208,7 +211,11 @@ static bool clk_core_is_prepared(struct clk_core *core) return core->prepare_count; if (!clk_pm_runtime_get(core)) { + if (core->flags & CLK_OPS_PARENT_ENABLE) + clk_core_prepare_enable(core->parent); ret = core->ops->is_prepared(core->hw); + if (core->flags & CLK_OPS_PARENT_ENABLE) + clk_core_disable_unprepare(core->parent); clk_pm_runtime_put(core); } @@ -244,7 +251,13 @@ static bool clk_core_is_enabled(struct clk_core *core) } } + if (core->flags & CLK_OPS_PARENT_ENABLE) + clk_core_prepare_enable(core->parent); + ret = core->ops->is_enabled(core->hw); + + if (core->flags & CLK_OPS_PARENT_ENABLE) + clk_core_disable_unprepare(core->parent); done: if (core->rpm_enabled) pm_runtime_put(core->dev); @@ -812,6 +825,9 @@ int clk_rate_exclusive_get(struct clk *clk) } EXPORT_SYMBOL_GPL(clk_rate_exclusive_get); +static int clk_core_enable_lock(struct clk_core *core); +static void clk_core_disable_lock(struct clk_core *core); + static void clk_core_unprepare(struct clk_core *core) { lockdep_assert_held(&prepare_lock); @@ -835,6 +851,9 @@ static void clk_core_unprepare(struct clk_core *core) WARN(core->enable_count > 0, "Unpreparing enabled %s\n", core->name); + if (core->flags & CLK_OPS_PARENT_ENABLE) + clk_core_enable_lock(core->parent); + trace_clk_unprepare(core); if (core->ops->unprepare) @@ -843,6 +862,9 @@ static void clk_core_unprepare(struct clk_core *core) clk_pm_runtime_put(core); trace_clk_unprepare_complete(core); + + if (core->flags & CLK_OPS_PARENT_ENABLE) + clk_core_disable_lock(core->parent); clk_core_unprepare(core->parent); } @@ -891,6 +913,9 @@ static int clk_core_prepare(struct clk_core *core) if (ret) goto runtime_put; + if (core->flags & CLK_OPS_PARENT_ENABLE) + clk_core_enable_lock(core->parent); + trace_clk_prepare(core); if (core->ops->prepare) @@ -898,6 +923,9 @@ static int clk_core_prepare(struct clk_core *core) trace_clk_prepare_complete(core); + if (core->flags & CLK_OPS_PARENT_ENABLE) + clk_core_disable_lock(core->parent); + if (ret) goto unprepare; } From patchwork Wed Jul 13 08:21:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12916245 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 2DF16C433EF for ; Wed, 13 Jul 2022 08:23: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: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=2gpqhYYDx5kE0XxDEHrslNOAmGewsToYs7lLy6Sk1wc=; b=b5WF14dkdWNRUL 2c7w2bRfHHrA+mezGCxmpXSIbCG4H1rG/f285EY7dPuDxO8bb3ObTXR1MWi0e43OGDrUR9gSZ4000 /qb11QC6BIw5PfkDvebHkV/cZ1X3GJc19LjNCqEFjg+TyzJEwYKl2DZPc/JN6/5bSxzgFMFDcneWW M1FHgdggOOpucv/+Dcf/Rd7FH2/tFpAsLyFl8xbvEmrGNloDtLbLx+/ntXfNsiAHnFhblYwOLc5F8 5tR+jW9RQFKOQH//HYIZ02dK+hJluEFKqIYtgpbuZdUKjbxMRIxamJLohz2SG/eMcwIPtEH0qsVsS gWXF1LblCfMEjckpFNhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oBXdE-001bdw-Bn; Wed, 13 Jul 2022 08:22:04 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oBXcZ-001bGu-VQ for linux-arm-kernel@lists.infradead.org; Wed, 13 Jul 2022 08:21:25 +0000 Received: by mail-pf1-x42b.google.com with SMTP id y141so9611975pfb.7 for ; Wed, 13 Jul 2022 01:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mHyeUQJdYIKoGxaGh8GhuqJCqLId0c4uymSzWL5ah+k=; b=DOrORcUIpO3bIcq5mvbqgBwsoGpPNo8J5EQp4QRXgfAWhrd6BtDAXS/8u/JFee+tPn spKJNC7hu9wllOFfzrO6vyeRE6XQzZ6K6R0VoyPaa0Mi/Imd3X1QDgtvoidaPXLbCykb y4gAahfqffsMc54O+yutFBdUx6LgSi2ggp4e8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mHyeUQJdYIKoGxaGh8GhuqJCqLId0c4uymSzWL5ah+k=; b=oZSXNj+ZY2jcpJLoRT1Z7X7nY5mSvcehpxvgRMfjf/xPyggwxbnhiwvU9rjlrXJHwm Cb+wBOjrshqZkRWsoXhh5FETY7DECKPJYdXKKdlf+BeCv9bq+C5HcAP0RIYY4DfpttAy mNpEWM5bgl4uqkV+/Y/Vbr7US0hxNJiNdqSB+tcHxKauA8JccSfUdpR7r7cmI7Nk1osb 1yzezIGllS22tHA6q3/YwoGt1q3mXDpP1PFwL8W5VCymTVUWNoVXN5/d09tP2v0n7gsK xE3VLqHdu9uPPhsoa3etu5iCNY7Ml3AZ/w5swh2Izvczc9HRPD/0t14hBR6d6+s7b6dU 87Fg== X-Gm-Message-State: AJIora/n6OjyBxWpZ7IfSvgCL2Mr9uQrr1lWxb7z/8h+Jd8zuhBTER2L ATBAulyDPI6SstlS2EkEfjnVcQ== X-Google-Smtp-Source: AGRyM1tS7JahWvLt1w8JAVRW4I4+Aa0EiNeuGUU4qnjy10lqhxel9oniuebbxHptr3VTQIgz92RGHw== X-Received: by 2002:a62:ea18:0:b0:52a:c12b:9313 with SMTP id t24-20020a62ea18000000b0052ac12b9313mr2173174pfh.49.1657700480832; Wed, 13 Jul 2022 01:21:20 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:d1a9:ca7d:e86f:cf6f]) by smtp.gmail.com with ESMTPSA id k11-20020aa7972b000000b005281d926733sm8220461pfg.199.2022.07.13.01.21.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:21:20 -0700 (PDT) From: Chen-Yu Tsai To: Michael Turquette , Stephen Boyd Cc: Chen-Yu Tsai , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, AngeloGioacchino Del Regno , =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Subject: [PATCH v2 2/2] clk: core: Fix runtime PM sequence in clk_core_unprepare() Date: Wed, 13 Jul 2022 16:21:11 +0800 Message-Id: <20220713082111.2233016-3-wenst@chromium.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220713082111.2233016-1-wenst@chromium.org> References: <20220713082111.2233016-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220713_012124_061602_B6FB6FA4 X-CRM114-Status: GOOD ( 13.56 ) 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 In the original commit 9a34b45397e5 ("clk: Add support for runtime PM"), the commit message mentioned that pm_runtime_put_sync() would be done at the end of clk_core_unprepare(). This mirrors the operations in clk_core_prepare() in the opposite order. However, the actual code that was added wasn't in the order the commit message described. Move clk_pm_runtime_put() to the end of clk_core_unprepare() so that it is in the correct order. Fixes: 9a34b45397e5 ("clk: Add support for runtime PM") Signed-off-by: Chen-Yu Tsai Reviewed-by: Nícolas F. R. A. Prado --- drivers/clk/clk.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 9b365cd6d14b..2e29a72c68e1 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -859,13 +859,12 @@ static void clk_core_unprepare(struct clk_core *core) if (core->ops->unprepare) core->ops->unprepare(core->hw); - clk_pm_runtime_put(core); - trace_clk_unprepare_complete(core); if (core->flags & CLK_OPS_PARENT_ENABLE) clk_core_disable_lock(core->parent); clk_core_unprepare(core->parent); + clk_pm_runtime_put(core); } static void clk_core_unprepare_lock(struct clk_core *core)