From patchwork Sat Mar 5 15:42:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vishnupatekar X-Patchwork-Id: 8510721 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ACDA9C0553 for ; Sat, 5 Mar 2016 15:45:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C49FE201CE for ; Sat, 5 Mar 2016 15:45:51 +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 CED73201EF for ; Sat, 5 Mar 2016 15:45:50 +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 1acEND-0003Ss-3C; Sat, 05 Mar 2016 15:44:07 +0000 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1acEN0-0003NH-QT for linux-arm-kernel@lists.infradead.org; Sat, 05 Mar 2016 15:43:56 +0000 Received: by mail-pf0-x241.google.com with SMTP id 184so5056683pff.1 for ; Sat, 05 Mar 2016 07:43:34 -0800 (PST) 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=dncoK8FuNv0TamO2uwJhpcH/KszhYXUe39N7N4JOtps=; b=P6HGuxD3MzAxgAPcC5DFEhsU5YTx4jC1rueugWVKb+tA3CQVZugPigs+dlXfudBB2C N6HLLTXodnEztsTlz++0jNyomzWrap28VIYk3IZm+oSUxqdEv2Y6bs1xpxft2X5ajcPP ZZMWOcWk2PjKpTpS2rDt/X+MliPmUa5G3R3pDptu6/2R2wPLJtmfx3e/6vVnW+WK/7Dr 6UgKC6ci3BbmMDmgFB4m/So00F6da2hLJcATn+gEcDBHAXNV1wYJH4uqKMk3x5UL0X+m CEEhk2nQvVotEPrdZ3q/Nw1PMNrrHhp2re+UiXELadlJHmSZ68D/GiymJtNLPdHSXZXy n/EA== 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=dncoK8FuNv0TamO2uwJhpcH/KszhYXUe39N7N4JOtps=; b=epefwA/P5q318FGU/Q5CiGHDORi0eedyECTArMuCpLM31LMlY7972lWb8rdbc3j1CP QRRlH0qkiqbj/5PuCVqb/HFLAEQygLdc8l6X/MXOHp9llE+FrfC+ehcidzUEd3dq0bYR DL3Ocx5TciJxt/nB6UFjBKTXUWQAsnzjMu4pqnw/lEwN0vY4MPD/GDd7kuHVEK1Q9wBZ WfBBlr25FI+2u/dl+vm2fBJ9VpTakaXaFq7L1c/PXwK3q5xZjHz9zCsGrzDQSSlhpqdk XWe4QTOfI8bpOsgODJbQktMe20md8wjjxjhsJtJDSIg9NOeCUdoPPCJ+CRTMSVjGlX7T nyGg== X-Gm-Message-State: AD7BkJILO6Odjy0UqXMzYGWPV1ag61IKWHGUnS+YTb7EKs6somdXSkPJ5oSgPTKPwLZlAg== X-Received: by 10.98.79.205 with SMTP id f74mr20716365pfj.68.1457192614667; Sat, 05 Mar 2016 07:43:34 -0800 (PST) Received: from localhost.localdomain ([101.127.161.160]) by smtp.gmail.com with ESMTPSA id ah10sm13230527pad.23.2016.03.05.07.43.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 05 Mar 2016 07:43:34 -0800 (PST) From: Vishnu Patekar To: robh+dt@kernel.org, corbet@lwn.net, pawel.moll@arm.com, mark.rutland@arm.com, ijc+devicetree@hellion.org.uk, galak@codeaurora.org, maxime.ripard@free-electrons.com, linux@arm.linux.org.uk, emilio@elopez.com.ar Subject: [PATCH v3 02/13] clk: sunxi: add ahb1 clock for A83T Date: Sat, 5 Mar 2016 23:42:55 +0800 Message-Id: <1457192586-25596-3-git-send-email-vishnupatekar0510@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1457192586-25596-1-git-send-email-vishnupatekar0510@gmail.com> References: <1457192586-25596-1-git-send-email-vishnupatekar0510@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160305_074355_085881_0D9AAF13 X-CRM114-Status: GOOD ( 13.68 ) 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: devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, linux-sunxi@googlegroups.com, patchesrdh@mveas.com, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, hdegoede@redhat.com, wens@csie.org, mturquette@baylibre.com, jenskuske@gmail.com, linus.walleij@linaro.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=-4.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 AHB1 on A83T is similar to ahb1 on A31, except parents are different. clock index 0b1x is PLL6. Signed-off-by: Vishnu Patekar Acked-by: Chen-Yu Tsai Acked-by: Rob Herring --- Documentation/devicetree/bindings/clock/sunxi.txt | 1 + drivers/clk/sunxi/clk-sunxi.c | 76 +++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/Documentation/devicetree/bindings/clock/sunxi.txt b/Documentation/devicetree/bindings/clock/sunxi.txt index c09f59b..2ee7841 100644 --- a/Documentation/devicetree/bindings/clock/sunxi.txt +++ b/Documentation/devicetree/bindings/clock/sunxi.txt @@ -29,6 +29,7 @@ Required properties: "allwinner,sun6i-a31-ar100-clk" - for the AR100 on A31 "allwinner,sun9i-a80-cpus-clk" - for the CPUS on A80 "allwinner,sun6i-a31-ahb1-clk" - for the AHB1 clock on A31 + "allwinner,sun8i-a83t-ahb1-clk" - for the AHB1 clock on A83T "allwinner,sun8i-h3-ahb2-clk" - for the AHB2 clock on H3 "allwinner,sun6i-a31-ahb1-gates-clk" - for the AHB1 gates on A31 "allwinner,sun8i-a23-ahb1-gates-clk" - for the AHB1 gates on A23 diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c index 99f60ef..0ae1f09 100644 --- a/drivers/clk/sunxi/clk-sunxi.c +++ b/drivers/clk/sunxi/clk-sunxi.c @@ -344,6 +344,67 @@ static void sun6i_ahb1_recalc(struct factors_request *req) req->rate >>= req->p; } +#define SUN8I_A83T_AHB1_PARENT_PLL6 2 +/** + * sun8i_a83t_get_ahb_factors() - calculates m, p factors for AHB + * AHB rate is calculated as follows + * rate = parent_rate >> p + * + * if parent is pll6, then + * parent_rate = pll6 rate / (m + 1) + */ + +static void sun8i_a83t_get_ahb1_factors(struct factors_request *req) +{ + u8 div, calcp, calcm = 1; + + /* + * clock can only divide, so we will never be able to achieve + * frequencies higher than the parent frequency + */ + if (req->parent_rate && req->rate > req->parent_rate) + req->rate = req->parent_rate; + + div = DIV_ROUND_UP(req->parent_rate, req->rate); + + /* calculate pre-divider if parent is pll6 */ + if (req->parent_index >= SUN8I_A83T_AHB1_PARENT_PLL6) { + if (div < 4) + calcp = 0; + else if (div / 2 < 4) + calcp = 1; + else if (div / 4 < 4) + calcp = 2; + else + calcp = 3; + + calcm = DIV_ROUND_UP(div, 1 << calcp); + } else { + calcp = __roundup_pow_of_two(div); + calcp = calcp > 3 ? 3 : calcp; +} + + req->rate = (req->parent_rate / calcm) >> calcp; + req->p = calcp; + req->m = calcm - 1; +} + +/** +* sun8i_a83t_ahb1_recalc() - calculates AHB clock rate from m, p factors and +* parent index +*/ +static void sun8i_a83t_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 @@ -555,6 +616,14 @@ static const struct factors_data sun6i_ahb1_data __initconst = { .recalc = sun6i_ahb1_recalc, }; +static const struct factors_data sun8i_a83t_ahb1_data __initconst = { + .mux = 12, + .muxmask = BIT(1) | BIT(0), + .table = &sun6i_ahb1_config, + .getter = sun8i_a83t_get_ahb1_factors, + .recalc = sun8i_a83t_ahb1_recalc, +}; + static const struct factors_data sun4i_apb1_data __initconst = { .mux = 24, .muxmask = BIT(1) | BIT(0), @@ -627,6 +696,13 @@ static void __init sun6i_ahb1_clk_setup(struct device_node *node) CLK_OF_DECLARE(sun6i_a31_ahb1, "allwinner,sun6i-a31-ahb1-clk", sun6i_ahb1_clk_setup); +static void __init sun8i_a83t_ahb1_clk_setup(struct device_node *node) +{ + sunxi_factors_clk_setup(node, &sun8i_a83t_ahb1_data); +} +CLK_OF_DECLARE(sun8i_a83t_ahb1, "allwinner,sun8i-a83t-ahb1-clk", + sun8i_a83t_ahb1_clk_setup); + static void __init sun4i_apb1_clk_setup(struct device_node *node) { sunxi_factors_clk_setup(node, &sun4i_apb1_data);