Received: by 10.213.65.68 with SMTP id h4csp415237imn; Fri, 16 Mar 2018 07:07:54 -0700 (PDT) X-Google-Smtp-Source: AG47ELuAmAuo32UgJbfuN8e64xya7B81n60QMcx3tHAJpw8hQu41OqGbZpC0bjUYjfCUWx7/SYaW X-Received: by 2002:a17:902:8a94:: with SMTP id p20-v6mr2359442plo.74.1521209274059; Fri, 16 Mar 2018 07:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521209274; cv=none; d=google.com; s=arc-20160816; b=YmhklHJZA/mE4eN+VftgPCy4oOVtxKbh9wN5Yb7NVkUeN1FqWH8rg/6YpWV5YL2CUv SRW0PMaw+OWyuKZj1gMScjZV8Wrc1OwQQUsHlymmc3id+k5o7/gTiMlQu/rO85PZ3AWP EB8lcn9WLz93YO09BCs0gof+N0qz5jwJpellQuQN5RD8Qc3DD5QIa3BuApLLej1CwI9S CRag34DjUX9yvNqpR41htcRgQuyfi5IYBS71mimLQTbzm2d2gy32vj6Dqa4PHisXCNG0 4auUecUxKhtMzLQSn8aqgc0Og8MRJeosTjZNEU57dkcbDo23d/j50Je2aZvhRgeL3RLE 0ZYw== 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=3ZqCiqTL6b4/wVC+DDajcuJ2iiB9ZdwjR0QhC9Xo+zY=; b=cPqGcbnRGiGJNtViZ6RETaplhJWWLy6W0rZx8v1HojnBPPmC1paPEvFcTE/gruLU7y 7Y4CXh9LLb4Ts5OLG+1+p4XY9tjPw3jDOHa5KvwsndjSEOuEziHrA2MSWoDylZYGsOLY NFToAV5Sz50PmtdyFgEkpJMnNEgTnz3y/xeRQW+OszelR2+WDSyu1WwYTs62aPziJyst /WLSpvejqqMJb9TTDPxeDT2O0wwd5vY6fCs79JAJAC4ZuhFDMBUpq2ZVJqrSh4o52PX1 lWwEvhaAcqXSnjrMiTjvPdvnIz8M8z3B7ydaCtm7+ZO/QXDUgc2+d2Uql0qR+fwtyVHV a+Yg== 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 z13si5474091pfh.217.2018.03.16.07.07.25; Fri, 16 Mar 2018 07:07:54 -0700 (PDT) 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 S1752979AbeCPOFK (ORCPT + 99 others); Fri, 16 Mar 2018 10:05:10 -0400 Received: from hermes.aosc.io ([199.195.250.187]:44117 "EHLO hermes.aosc.io" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752339AbeCPOFH (ORCPT ); Fri, 16 Mar 2018 10:05:07 -0400 Received: from localhost (localhost [127.0.0.1]) (Authenticated sender: icenowy@aosc.io) by hermes.aosc.io (Postfix) with ESMTPSA id B654F59788; Fri, 16 Mar 2018 14:05:01 +0000 (UTC) From: Icenowy Zheng To: Rob Herring , 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 v4 5/9] clk: sunxi-ng: Support fixed post-dividers on NKMP style clocks Date: Fri, 16 Mar 2018 22:02:11 +0800 Message-Id: <20180316140215.28663-6-icenowy@aosc.io> In-Reply-To: <20180316140215.28663-1-icenowy@aosc.io> References: <20180316140215.28663-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 --- No changes in v4. 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