From patchwork Tue Apr 19 16:47:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vishnupatekar X-Patchwork-Id: 8881681 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 21CE79F39A for ; Tue, 19 Apr 2016 16:50:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DBA82202B8 for ; Tue, 19 Apr 2016 16:50:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D1DCB20279 for ; Tue, 19 Apr 2016 16:50:43 +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 1asYq3-0004Tq-V3; Tue, 19 Apr 2016 16:49:23 +0000 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1asYpu-0004K0-3r for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2016 16:49:15 +0000 Received: by mail-pf0-x244.google.com with SMTP id e190so2183960pfe.0 for ; Tue, 19 Apr 2016 09:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UALnRR0dKTZsPR/Nu8tlFCRltA6z7bSZiGahKT4AHic=; b=dwMfLA9b4USSOPYPUpVLmD4eAn5L1UWBnjgUBsQg3Y16o0zbalD4r1IgWOGNDaBYmm YPH70hyJfZHfSufW3PY9o5KVu5+YCJTTvGhunk0V3OCZ8Nk3agUPyB8lEUQZgg96H4Zz 6TcUsWnrjXqLlEuNF4lswT3KDC0GFNZLUR9cec5w9iiETlXpp9MBxi+/XYzu1aJikwiS eO3/DyDzc1Xj++v6czfbY81VYrFsh2lcDjZWor+92GMyQF7FTyY3W2QIO8MWTkDql/KJ G1KPG1zUKyogVZB6w7bY+EEz3BU2/2EhOiWF6gAYs5jnJ5SSq0WOPIx4tsjrzTE+L5rf 0CIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UALnRR0dKTZsPR/Nu8tlFCRltA6z7bSZiGahKT4AHic=; b=XeggxqMPOQmr9YDi1sZ3DLDnmEB0EMa6NdW0XMQjJoLYYCqSNSk4aGXvVIS9/vrMtH 500kYHPcuRPRgarHcXnJCuB/do77PVFmy/VuEHXAg5eMhkMy438/syvYKJyFslj12W9Y ncCd1x7W9gmaT1YI+GxjraFjANoBmG1RWDGNIiX2glfKizm9I87UXZvG2hg8MPPeI5kb fPrbXuYGjwQ+74/FBJsnAUKrJQGxwsqBsiP8oFQV6hy7wISCc62PwotwS+edHY7bprga aXuo5RsiJ3ce0EjB1c0P3zWp87fW9MWBCxp24Wv2ownf/i367sCDAElu2tYvEw9Adt3T MDMA== X-Gm-Message-State: AOPr4FW55bxFsNtQICBJcDwsO5seZUAJ5MJHaSaWGKyJSrQrduLWz3u0f4PZF7EqWmMdFQ== X-Received: by 10.98.20.150 with SMTP id 144mr5476822pfu.144.1461084536714; Tue, 19 Apr 2016 09:48:56 -0700 (PDT) Received: from localhost.localdomain (amx-tls3.starhub.net.sg. [203.116.164.13]) by smtp.gmail.com with ESMTPSA id p78sm32502219pfa.75.2016.04.19.09.48.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Apr 2016 09:48:55 -0700 (PDT) From: Vishnu Patekar To: maxime.ripard@free-electrons.com, emilio@elopez.com.ar, wens@csie.org Subject: [PATCH v2] clk: sunxi: predivider handling for factors clock Date: Wed, 20 Apr 2016 00:47:46 +0800 Message-Id: <1461084466-20889-2-git-send-email-vishnupatekar0510@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461084466-20889-1-git-send-email-vishnupatekar0510@gmail.com> References: <1461084466-20889-1-git-send-email-vishnupatekar0510@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160419_094914_234023_A8FFDA89 X-CRM114-Status: GOOD ( 19.48 ) X-Spam-Score: -2.5 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-sunxi@googlegroups.com, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 For A31 ahb1 and a83t ahb1 clocks have predivider for certain parent. To handle this, this patch adds predivider table with parent index, prediv shift and width, parents with predivider will have nonzero width. Rate adjustment is moved from clock specific recalc function to generic factors recalc. Also, adds prediv table for a31. Signed-off-by: Vishnu Patekar --- drivers/clk/sunxi/clk-factors.c | 31 +++++++++++++++---------------- drivers/clk/sunxi/clk-factors.h | 10 +++++++++- drivers/clk/sunxi/clk-sunxi.c | 31 +++++++++---------------------- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/drivers/clk/sunxi/clk-factors.c b/drivers/clk/sunxi/clk-factors.c index ddefe96..8f3b637 100644 --- a/drivers/clk/sunxi/clk-factors.c +++ b/drivers/clk/sunxi/clk-factors.c @@ -45,10 +45,12 @@ static unsigned long clk_factors_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { u8 n = 1, k = 0, p = 0, m = 0; + u8 par_index = 0; u32 reg; unsigned long rate; struct clk_factors *factors = to_clk_factors(hw); const struct clk_factors_config *config = factors->config; + const struct clk_factors_prediv *prediv = factors->prediv_config; /* Fetch the register value */ reg = readl(factors->reg); @@ -63,24 +65,16 @@ static unsigned long clk_factors_recalc_rate(struct clk_hw *hw, if (config->pwidth != SUNXI_FACTORS_NOT_APPLICABLE) p = FACTOR_GET(config->pshift, config->pwidth, reg); - if (factors->recalc) { - struct factors_request factors_req = { - .parent_rate = parent_rate, - .n = n, - .k = k, - .m = m, - .p = p, - }; - + if (prediv) { /* get mux details from mux clk structure */ if (factors->mux) - factors_req.parent_index = - (reg >> factors->mux->shift) & - factors->mux->mask; - - factors->recalc(&factors_req); + par_index = (reg >> factors->mux->shift) & + factors->mux->mask; - return factors_req.rate; + if (prediv[par_index].width != SUNXI_FACTORS_NOT_APPLICABLE) { + m = FACTOR_GET(prediv[par_index].shift, + prediv[par_index].width, reg); + } } /* Calculate the rate */ @@ -102,8 +96,12 @@ static int clk_factors_determine_rate(struct clk_hw *hw, for (i = 0; i < num_parents; i++) { struct factors_request factors_req = { .rate = req->rate, - .parent_index = i, }; + + if (factors->prediv_config) + factors_req.prediv_width = + factors->prediv_config[i].width; + parent = clk_hw_get_parent_by_index(hw, i); if (!parent) continue; @@ -211,6 +209,7 @@ struct clk *sunxi_factors_register(struct device_node *node, /* set up factors properties */ factors->reg = reg; factors->config = data->table; + factors->prediv_config = data->prediv_table; factors->get_factors = data->getter; factors->recalc = data->recalc; factors->lock = lock; diff --git a/drivers/clk/sunxi/clk-factors.h b/drivers/clk/sunxi/clk-factors.h index 1e63c5b..b1b7745 100644 --- a/drivers/clk/sunxi/clk-factors.h +++ b/drivers/clk/sunxi/clk-factors.h @@ -18,10 +18,16 @@ struct clk_factors_config { u8 n_start; }; +struct clk_factors_prediv { + u8 parent_index; + u8 shift; + u8 width; +}; + struct factors_request { unsigned long rate; unsigned long parent_rate; - u8 parent_index; + u8 prediv_width; u8 n; u8 k; u8 m; @@ -33,6 +39,7 @@ struct factors_data { int mux; int muxmask; const struct clk_factors_config *table; + const struct clk_factors_prediv *prediv_table; void (*getter)(struct factors_request *req); void (*recalc)(struct factors_request *req); const char *name; @@ -42,6 +49,7 @@ struct clk_factors { struct clk_hw hw; void __iomem *reg; const struct clk_factors_config *config; + const struct clk_factors_prediv *prediv_config; void (*get_factors)(struct factors_request *req); void (*recalc)(struct factors_request *req); spinlock_t *lock; diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c index 91de0a0..5a5f26b 100644 --- a/drivers/clk/sunxi/clk-sunxi.c +++ b/drivers/clk/sunxi/clk-sunxi.c @@ -282,8 +282,6 @@ static void sun5i_a13_get_ahb_factors(struct factors_request *req) req->p = div; } -#define SUN6I_AHB1_PARENT_PLL6 3 - /** * sun6i_a31_get_ahb_factors() - calculates m, p factors for AHB * AHB rate is calculated as follows @@ -307,7 +305,7 @@ static void sun6i_get_ahb1_factors(struct factors_request *req) div = DIV_ROUND_UP(req->parent_rate, req->rate); /* calculate pre-divider if parent is pll6 */ - if (req->parent_index == SUN6I_AHB1_PARENT_PLL6) { + if (req->prediv_width) { if (div < 4) calcp = 0; else if (div / 2 < 4) @@ -329,22 +327,6 @@ static void sun6i_get_ahb1_factors(struct factors_request *req) } /** - * sun6i_ahb1_recalc() - calculates AHB clock rate from m, p factors and - * parent index - */ -static void sun6i_ahb1_recalc(struct factors_request *req) -{ - req->rate = req->parent_rate; - - /* apply pre-divider first if parent is pll6 */ - if (req->parent_index == SUN6I_AHB1_PARENT_PLL6) - req->rate /= req->m + 1; - - /* clk divider */ - req->rate >>= req->p; -} - -/** * sun4i_get_apb1_factors() - calculates m, p factors for APB1 * APB1 rate is calculated as follows * rate = (parent_rate >> p) / (m + 1); @@ -474,12 +456,17 @@ static const struct clk_factors_config sun5i_a13_ahb_config = { }; static const struct clk_factors_config sun6i_ahb1_config = { - .mshift = 6, - .mwidth = 2, .pshift = 4, .pwidth = 2, }; +static const struct clk_factors_prediv sun6i_ahb1_prediv[] = { + {.parent_index = 0, .shift = 0, .width = 0 }, /* LOSC */ + {.parent_index = 1, .shift = 0, .width = 0 }, /* OSC24MHz */ + {.parent_index = 2, .shift = 0, .width = 0 }, /* AXI */ + {.parent_index = 3, .shift = 6, .width = 2 } /* PLL6/Pre_div */ +}; + static const struct clk_factors_config sun4i_apb1_config = { .mshift = 0, .mwidth = 5, @@ -551,8 +538,8 @@ static const struct factors_data sun6i_ahb1_data __initconst = { .mux = 12, .muxmask = BIT(1) | BIT(0), .table = &sun6i_ahb1_config, + .prediv_table = sun6i_ahb1_prediv, .getter = sun6i_get_ahb1_factors, - .recalc = sun6i_ahb1_recalc, }; static const struct factors_data sun4i_apb1_data __initconst = {