Received: by 10.223.185.116 with SMTP id b49csp635754wrg; Fri, 23 Feb 2018 04:31:21 -0800 (PST) X-Google-Smtp-Source: AH8x226h5PCvAO9GFozTew8Kfghwe5NmwbKgEUTfWiTe8omINo7r/GqtNC+g0Ji1XPttZ1lKxyVJ X-Received: by 10.99.125.8 with SMTP id y8mr1319957pgc.241.1519389081481; Fri, 23 Feb 2018 04:31:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519389081; cv=none; d=google.com; s=arc-20160816; b=ZFwL5+HECN8CJKmBo+LVAaQlM4wvDiKuHKiwDGHaE200PNtoPo5Yrga958wtJm0k4Y 92Fx0Su5Ui2UTOYXrL25gk2XQEOdRE5zJi18U0qDFaeArghISal2z2npqjuAW9kjUr0y bMTmisMjctN1AuyQaNVYQJ9QTUxRENRI45Ra/w26hooGFaYHHyyvn6PDTJlsHSNhxfJo R+maY+h5MkudTJWu+ex2kEg0BKZA9Azp0oKF/s2T7P4qAV4V8WEYZDJIy59JXDtRo5jV TXH/YN3ZiCMiEQ2GECICiIacL0VbwPGegnbRQS9B5AU7g1WLURfy5irrJIbP1W7gs0Ia WsCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=M/kZuMIKFDJg1yw62CYd9dcTsRCekWh45SDdIQ7DVG4=; b=ybWoLLyl4f3icPjh1ceYYBFStKodu1Fu51QpVnRQnLHCCcGtoyzggNgPoNq8Dwg7qD 22SNyHZkzjdZK/LhPb764eLgHqhajaQZnbCpeoIfVo7zW0V3DYLVJfFvmCeMDUAivm7P 2fT9KHAMiDK5nGOUHAvc8nLCPfweXaEbwaV0bDwZV4SeyBqTTnMzNLvdjy9xsiPWKdyW s7Gu5CLWBT0uY+daPqmnlGiAQF68e3F1rz2QlYuA3S55izyYqMXe4hNDrXzeke8ufjGr SQ61t48DLAc9hMLWVyZ4tSWP7Sr4XnOM80gaNLMkxKNHU0G9MYC4PVfSd4soALuUvMxi YdXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c66si1747140pfc.416.2018.02.23.04.31.06; Fri, 23 Feb 2018 04:31:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751634AbeBWM21 (ORCPT + 99 others); Fri, 23 Feb 2018 07:28:27 -0500 Received: from hermes.aosc.io ([199.195.250.187]:51144 "EHLO hermes.aosc.io" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751089AbeBWM2Y (ORCPT ); Fri, 23 Feb 2018 07:28:24 -0500 Received: from localhost (localhost [127.0.0.1]) (Authenticated sender: icenowy@aosc.io) by hermes.aosc.io (Postfix) with ESMTPSA id E8413571E2; Fri, 23 Feb 2018 12:28:20 +0000 (UTC) From: Icenowy Zheng To: Maxime Ripard , Chen-Yu Tsai , Linus Walleij Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-sunxi@googlegroups.com, Icenowy Zheng Subject: [PATCH v3 4/7] clk: sunxi-ng: Support fixed post-dividers on NKMP style clocks Date: Fri, 23 Feb 2018 20:25:49 +0800 Message-Id: <20180223122552.58049-5-icenowy@aosc.io> In-Reply-To: <20180223122552.58049-1-icenowy@aosc.io> References: <20180223122552.58049-1-icenowy@aosc.io> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On the new Allwinner H6 SoC, multiple PLL's are NMP style clocks (modelled as NKMP with no K) and have fixed post-dividers. Add fixed post divider support to the NKMP style clocks. Signed-off-by: Icenowy Zheng --- Changes in v3: - Rebased on newest linux-next/master. No changes in v2. drivers/clk/sunxi-ng/ccu_nkmp.c | 20 +++++++++++++++++--- drivers/clk/sunxi-ng/ccu_nkmp.h | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_nkmp.c b/drivers/clk/sunxi-ng/ccu_nkmp.c index c3f6fe7be565..ebd9436d2c7c 100644 --- a/drivers/clk/sunxi-ng/ccu_nkmp.c +++ b/drivers/clk/sunxi-ng/ccu_nkmp.c @@ -95,7 +95,7 @@ static unsigned long ccu_nkmp_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct ccu_nkmp *nkmp = hw_to_ccu_nkmp(hw); - unsigned long n, m, k, p; + unsigned long n, m, k, p, rate; u32 reg; reg = readl(nkmp->common.base + nkmp->common.reg); @@ -121,7 +121,11 @@ static unsigned long ccu_nkmp_recalc_rate(struct clk_hw *hw, p = reg >> nkmp->p.shift; p &= (1 << nkmp->p.width) - 1; - return ccu_nkmp_calc_rate(parent_rate, n, k, m, 1 << p); + rate = ccu_nkmp_calc_rate(parent_rate, n, k, m, 1 << p); + if (nkmp->common.features & CCU_FEATURE_FIXED_POSTDIV) + rate /= nkmp->fixed_post_div; + + return rate; } static long ccu_nkmp_round_rate(struct clk_hw *hw, unsigned long rate, @@ -130,6 +134,9 @@ static long ccu_nkmp_round_rate(struct clk_hw *hw, unsigned long rate, struct ccu_nkmp *nkmp = hw_to_ccu_nkmp(hw); struct _ccu_nkmp _nkmp; + if (nkmp->common.features & CCU_FEATURE_FIXED_POSTDIV) + rate *= nkmp->fixed_post_div; + _nkmp.min_n = nkmp->n.min ?: 1; _nkmp.max_n = nkmp->n.max ?: 1 << nkmp->n.width; _nkmp.min_k = nkmp->k.min ?: 1; @@ -141,8 +148,12 @@ static long ccu_nkmp_round_rate(struct clk_hw *hw, unsigned long rate, ccu_nkmp_find_best(*parent_rate, rate, &_nkmp); - return ccu_nkmp_calc_rate(*parent_rate, _nkmp.n, _nkmp.k, + rate = ccu_nkmp_calc_rate(*parent_rate, _nkmp.n, _nkmp.k, _nkmp.m, _nkmp.p); + if (nkmp->common.features & CCU_FEATURE_FIXED_POSTDIV) + rate = rate / nkmp->fixed_post_div; + + return rate; } static int ccu_nkmp_set_rate(struct clk_hw *hw, unsigned long rate, @@ -154,6 +165,9 @@ static int ccu_nkmp_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long flags; u32 reg; + if (nkmp->common.features & CCU_FEATURE_FIXED_POSTDIV) + rate = rate * nkmp->fixed_post_div; + _nkmp.min_n = nkmp->n.min ?: 1; _nkmp.max_n = nkmp->n.max ?: 1 << nkmp->n.width; _nkmp.min_k = nkmp->k.min ?: 1; diff --git a/drivers/clk/sunxi-ng/ccu_nkmp.h b/drivers/clk/sunxi-ng/ccu_nkmp.h index a82facbc6144..6940503e7fc4 100644 --- a/drivers/clk/sunxi-ng/ccu_nkmp.h +++ b/drivers/clk/sunxi-ng/ccu_nkmp.h @@ -34,6 +34,8 @@ struct ccu_nkmp { struct ccu_div_internal m; struct ccu_div_internal p; + unsigned int fixed_post_div; + struct ccu_common common; }; -- 2.15.1