From patchwork Thu Feb 8 13:43:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 10207159 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2BE64603EE for ; Thu, 8 Feb 2018 13:43:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DF2F294CC for ; Thu, 8 Feb 2018 13:43:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 127B7294D4; Thu, 8 Feb 2018 13:43:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C94F294D1 for ; Thu, 8 Feb 2018 13:43:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752010AbeBHNnu (ORCPT ); Thu, 8 Feb 2018 08:43:50 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:44344 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751878AbeBHNnr (ORCPT ); Thu, 8 Feb 2018 08:43:47 -0500 Received: by mail.free-electrons.com (Postfix, from userid 110) id 373092071B; Thu, 8 Feb 2018 14:43:46 +0100 (CET) Received: from bbrezillon.lan (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id CE74B2061A; Thu, 8 Feb 2018 14:43:45 +0100 (CET) From: Boris Brezillon To: Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Stephen Warren , Lee Jones , Eric Anholt , linux-rpi-kernel@lists.infradead.org, Mike Turquette , Stephen Boyd , linux-clk@vger.kernel.org Cc: Boris Brezillon , stable@vger.kernel.org Subject: [PATCH 4/4] clk: bcm2835: Make sure the PLL is gated before changing its rate Date: Thu, 8 Feb 2018 14:43:38 +0100 Message-Id: <20180208134338.24590-4-boris.brezillon@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180208134338.24590-1-boris.brezillon@bootlin.com> References: <20180208134338.24590-1-boris.brezillon@bootlin.com> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP All bcm2835 PLLs should be gated before their rate can be changed. Setting CLK_SET_RATE_GATE will let the core enforce that, but this is not enough to make the code work in all situations. Indeed, the CLK_SET_RATE_GATE flag prevents a user from changing the rate while the clock is enabled, but this check only guarantees there's no Linux users. In our case, the clock might have been enabled by the bootloader/FW, and, because we have CLK_IGNORE_UNUSED set, Linux never disables the PLL. So we have to make sure the PLL is actually disabled before changing the rate. Fixes: 41691b8862e2 ("clk: bcm2835: Add support for programming the audio domain clocks") Cc: Signed-off-by: Boris Brezillon --- drivers/clk/bcm/clk-bcm2835.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c index 6c5d4a8e426c..051ce769c109 100644 --- a/drivers/clk/bcm/clk-bcm2835.c +++ b/drivers/clk/bcm/clk-bcm2835.c @@ -678,6 +678,18 @@ static int bcm2835_pll_set_rate(struct clk_hw *hw, u32 ana[4]; int i; + /* + * Normally, the CLK_SET_RATE_GATE flag prevents a user from changing + * the rate while the clock is enabled, but this check only makes sure + * there's no Linux users. + * In our case, the clock might have been enabled by the bootloader/FW, + * and, since CLK_IGNORE_UNUSED flag is set, Linux never disables it. + * So we have to make sure the clk is actually disabled before changing + * the rate. + */ + if (bcm2835_pll_is_on(hw)) + bcm2835_pll_off(hw); + if (rate > data->max_fb_rate) { use_fb_prediv = true; rate /= 2; @@ -1318,7 +1330,7 @@ static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman, init.num_parents = 1; init.name = data->name; init.ops = &bcm2835_pll_clk_ops; - init.flags = CLK_IGNORE_UNUSED; + init.flags = CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE; pll = kzalloc(sizeof(*pll), GFP_KERNEL); if (!pll)