From patchwork Sat Apr 16 18:55:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vishnupatekar X-Patchwork-Id: 8861821 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 CBD569F441 for ; Sat, 16 Apr 2016 18:57:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E60452014A for ; Sat, 16 Apr 2016 18:57:25 +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 8430D20211 for ; Sat, 16 Apr 2016 18:57:24 +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 1arVNg-0005Ly-36; Sat, 16 Apr 2016 18:55:44 +0000 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1arVNa-0005KE-Bv for linux-arm-kernel@lists.infradead.org; Sat, 16 Apr 2016 18:55:39 +0000 Received: by mail-pf0-x243.google.com with SMTP id e190so13044927pfe.0 for ; Sat, 16 Apr 2016 11:55:18 -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=v00dSzIWnH5uQXr99ISKy8ZoqbVKmLKEYXVz3KXiCho=; b=dt2cjmfYeWrq8EQ36lLe3ZtY9PSZ/44IeuUGg6ROb9U1jz1YA6qMDv0VeQXDqYBXvT 4fOWUAGY7bby/dtv1gNg02OdEC68BF2PSDoGdJvUWRxe5CKOIVWcPHxhwyO/ogklwBkz FUFqD8ElhWV+aHHk5ryyPz27wH1pXX5L4/szxsFJaG2Xb3GjGNsgGE0b1f0zs8rvw+Sk Syzr/B2EjmjbMC1VZSOPomiO2+g3BVvr8cj6LjZK70WWDu1Tv47f4EgMDF2VPhWPaQFp nWRcv2H7ifdArf8o3gc2smhOgac/vhS1UZ/mtbrWoQV8m+n4kMr7/KurJMEz2aYClpVx jZhw== 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=v00dSzIWnH5uQXr99ISKy8ZoqbVKmLKEYXVz3KXiCho=; b=VknS/FzG+NE5egQbkrCS0h3weihCxW/ixDEzgqERAUkluDIhrLM8s22+1oeC9m6xe+ NH9XEfXL/tIfT25xh/N1tioPJf8t7/G4mbj1iHrPYBJzExqy5Um8V2+i2L/OERwxc2zW bE4TAkOQCjbsNu0uHKF1/eZkh1gFbgGFVvAS3IkQQuxja/KVlHZP+TOfWMyDixMfkNDt rYrBcctZ8qV12Nk/p6q1wc+6iKHvfdPKwKD+RHed6sguotb6Y0mvIesxaiaYhjvuBqfT 0rx4Ikixa6/C76pVdcfArMqrVifuYKKlW7i3dTHkGeh1jrTBaDgcA/9YIe+7o7CAioMd GxvA== X-Gm-Message-State: AOPr4FV/Pw7vJZsvB/ef6x1HcbzKaS5l/txydPsRyjeoFUM/B9IPJT2kv/y5FN690NA3Lg== X-Received: by 10.98.93.138 with SMTP id n10mr21590500pfj.43.1460832917691; Sat, 16 Apr 2016 11:55:17 -0700 (PDT) Received: from localhost.localdomain (amx-tls3.starhub.net.sg. [203.116.164.13]) by smtp.gmail.com with ESMTPSA id a205sm5365765pfa.6.2016.04.16.11.55.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 16 Apr 2016 11:55:17 -0700 (PDT) From: Vishnu Patekar To: maxime.ripard@free-electrons.com, emilio@elopez.com.ar, wens@csie.org Subject: [PATCH 1/2] clk: sunxi: add predivider handling for factors clock Date: Sun, 17 Apr 2016 02:55:05 +0800 Message-Id: <1460832906-24064-2-git-send-email-vishnupatekar0510@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460832906-24064-1-git-send-email-vishnupatekar0510@gmail.com> References: <1460832906-24064-1-git-send-email-vishnupatekar0510@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160416_115538_460756_71C35990 X-CRM114-Status: GOOD ( 15.96 ) 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. Signed-off-by: Vishnu Patekar --- drivers/clk/sunxi/clk-factors.c | 31 +++++++++++++++---------------- drivers/clk/sunxi/clk-factors.h | 10 +++++++++- 2 files changed, 24 insertions(+), 17 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;