From patchwork Fri Nov 14 18:06:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Heiko_St=C3=BCbner?= X-Patchwork-Id: 5308671 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4D13BC11AC for ; Fri, 14 Nov 2014 18:03:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4AA38201C8 for ; Fri, 14 Nov 2014 18:03:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 09BD020149 for ; Fri, 14 Nov 2014 18:03:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XpLDm-0005ux-OX; Fri, 14 Nov 2014 18:03:46 +0000 Received: from gloria.sntech.de ([95.129.55.99]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XpLDl-0005rB-5A for linux-rockchip@lists.infradead.org; Fri, 14 Nov 2014 18:03:46 +0000 Received: from ip92344056.dynamic.kabel-deutschland.de ([146.52.64.86] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XpLDF-0002Ak-6o; Fri, 14 Nov 2014 19:03:13 +0100 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: Mike Turquette Subject: Re: [RFC PATCH 1/2] clk: add property for force to update clock setting Date: Fri, 14 Nov 2014 19:06:47 +0100 Message-ID: <6053586.L6Ix8HgKpA@diego> User-Agent: KMail/4.14.1 (Linux/3.16-3-amd64; KDE/4.14.2; x86_64; ; ) In-Reply-To: <20141114014102.25314.77218@quantum> References: <1415884826-7877-1-git-send-email-kever.yang@rock-chips.com> <20141114014102.25314.77218@quantum> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141114_100345_372955_F06FC4B6 X-CRM114-Status: GOOD ( 14.48 ) X-Spam-Score: -0.0 (/) Cc: Tao Huang , Addy Ke , linux-kernel@vger.kernel.org, Doug Anderson , Kever Yang , linux-rockchip@lists.infradead.org, Eddie Cai , Sonny Rao X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Mike, Am Donnerstag, 13. November 2014, 17:41:02 schrieb Mike Turquette: > Quoting Doug Anderson (2014-11-13 15:27:32) [...] > All of the above is to say that perhaps the solution to this problem > belongs in the driver. In the end we're talking about details for > correctly programming hardware, which sounds an awful lot like what > drivers are supposed to do. > > Let me know if the ->init() callback holds any promise for you. If not > we can figure something out. From my theoretical musings, ->init() sounds like a nice idea - but of course it comes with a "but". I guess the general idea would be to have the pll clk-type simply reset to the same rate but forcing it to use the parameters from its parameter table - when the rate params differ [0]. The only problem would be the apll supplying the cpu cores. After all clocks are registered, our armclk makes sure that the core clock gets reparented before changing the underlying apll [dpll is safe, as it is read-only currently]. At the moment the order would be clk_register(apll) apll->init() clk_register(armclk); I'm currently unsure if simply exchanging the register-order of armclk and the plls would help, but as the orphan handling is done before the ->init call I guess it might help. Heiko [0] (compile-tested only) diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c index a3e886a..7f59579 100644 --- a/drivers/clk/rockchip/clk-pll.c +++ b/drivers/clk/rockchip/clk-pll.c @@ -257,6 +257,40 @@ static int rockchip_rk3066_pll_is_enabled(struct clk_hw *hw) return !(pllcon & RK3066_PLLCON3_PWRDOWN); } +static void rockchip_rk3066_pll_init(struct clk_hw *hw) +{ + struct rockchip_clk_pll *pll = to_rockchip_clk_pll(hw); + const struct rockchip_pll_rate_table *rate; + unsigned int nf, nr, no, bwadj; + unsigned long drate; + u32 pllcon; + + drate = __clk_get_rate(hw->clk); + rate = rockchip_get_pll_settings(pll, drate); + + /* when no rate setting for the current rate, rely on clk_set_rate */ + if (!rate) + return; + + pllcon = readl_relaxed(pll->reg_base + RK3066_PLLCON(0)); + nr = ((pllcon >> RK3066_PLLCON0_NR_SHIFT) & RK3066_PLLCON0_NR_MASK) + 1; + no = ((pllcon >> RK3066_PLLCON0_OD_SHIFT) & RK3066_PLLCON0_OD_MASK) + 1; + + pllcon = readl_relaxed(pll->reg_base + RK3066_PLLCON(1)); + nf = ((pllcon >> RK3066_PLLCON1_NF_SHIFT) & RK3066_PLLCON1_NF_MASK) + 1; + + pllcon = readl_relaxed(pll->reg_base + RK3066_PLLCON(2)); + bwadj = (pllcon >> RK3066_PLLCON2_BWADJ_SHIFT) & RK3066_PLLCON2_BWADJ_MASK; + + if (rate->nr != nr || rate->no != no || rate->nf != nf + || rate->bwadj != bwadj) { + struct clk *parent = __clk_get_parent(hw->clk); + unsigned long prate = __clk_get_rate(parent); + + rockchip_rk3066_pll_set_rate(hw, drate, prate); + } +} + static const struct clk_ops rockchip_rk3066_pll_clk_norate_ops = { .recalc_rate = rockchip_rk3066_pll_recalc_rate, .enable = rockchip_rk3066_pll_enable, @@ -271,6 +305,7 @@ static const struct clk_ops rockchip_rk3066_pll_clk_ops = { .enable = rockchip_rk3066_pll_enable, .disable = rockchip_rk3066_pll_disable, .is_enabled = rockchip_rk3066_pll_is_enabled, + .init = rockchip_rk3066_pll_init, }; /*