From patchwork Tue Jul 23 01:01:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Emilio_L=C3=B3pez?= X-Patchwork-Id: 2831654 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B346AC0319 for ; Tue, 23 Jul 2013 01:07:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B6E022017E for ; Tue, 23 Jul 2013 01:07:54 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EA2C0200FE for ; Tue, 23 Jul 2013 01:07:50 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V1R2A-0002kP-ON; Tue, 23 Jul 2013 01:05:02 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V1R1X-0002rY-AK; Tue, 23 Jul 2013 01:04:19 +0000 Received: from [2606:3f00:60:21c:d00d:c0de:4:f00d] (helo=zetta.elopez.com.ar) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V1R0U-0002kC-81 for linux-arm-kernel@lists.infradead.org; Tue, 23 Jul 2013 01:03:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=elopez.com.ar; s=mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=oEH9dqO0mjg+/RfNpvRArJAzmLjsSb9oz5XWzVdqW9M=; b=QtL/7BQEg0lruOyI0zIHdlw7FCvbdSbQQdfosqMdgCc84c487bIL1C+h5+12wdXROppOpgto1ilpX2AzAhTPDckAPrLHB7FpIhiYIzUuJTzJP4wZ2nR5wHP/qwo/r4O53YGJ42pc6lbdbbjJmOpt41aRdNL+NIKWZmzzGV8wY1K0WuQQC0uq27DcbvGHeXl448Llp4EOza2HWK/NQCAyVW7krw4Ri6+q/uVfMuaL5UVx37i9aZJtOTQMKILu8XGBAfGw9BTgjHNrScrK6yPZFqr3DdzQWznLyFV+m35hy302/yZDmQOFSKKJllPjRS0eKvhl0JkU55fXW08BvPd0zQ==; Received: from 201-212-128-222.cab.prima.net.ar ([201.212.128.222] helo=desktop.lan) by zetta.elopez.com.ar with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) id 1V1R06-0004KE-8p; Mon, 22 Jul 2013 22:02:50 -0300 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= To: Mike Turquette Subject: [PATCH RFC 7/8] clk: sunxi: mod0 support Date: Mon, 22 Jul 2013 22:01:11 -0300 Message-Id: <1374541272-32173-8-git-send-email-emilio@elopez.com.ar> X-Mailer: git-send-email 1.8.3.3 In-Reply-To: <1374541272-32173-1-git-send-email-emilio@elopez.com.ar> References: <1374541272-32173-1-git-send-email-emilio@elopez.com.ar> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130722_210314_685224_509E2535 X-CRM114-Status: GOOD ( 13.82 ) X-Spam-Score: -1.2 (-) Cc: Gregory CLEMENT , =?UTF-8?q?Emilio=20L=C3=B3pez?= , Maxime Ripard , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, 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 This commit implements support for the "module 0" type of clocks, as used by MMC, IR, NAND, SATA and other components. Signed-off-by: Emilio López Acked-by: Maxime Ripard --- Documentation/devicetree/bindings/clock/sunxi.txt | 1 + drivers/clk/sunxi/clk-sunxi.c | 54 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Documentation/devicetree/bindings/clock/sunxi.txt b/Documentation/devicetree/bindings/clock/sunxi.txt index 6634eac..74c8f2e 100644 --- a/Documentation/devicetree/bindings/clock/sunxi.txt +++ b/Documentation/devicetree/bindings/clock/sunxi.txt @@ -23,6 +23,7 @@ Required properties: "allwinner,sun4i-apb1-mux-clk" - for the APB1 clock muxing "allwinner,sun4i-apb1-gates-clk" - for the APB1 gates on A10 "allwinner,sun5i-a13-apb1-gates-clk" - for the APB1 gates on A13 + "allwinner,sun4i-mod0-clk" - for the module 0 family of clocks Required properties for all clocks: - reg : shall be the control register address for the clock. diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c index 743c2c2..28bf36f 100644 --- a/drivers/clk/sunxi/clk-sunxi.c +++ b/drivers/clk/sunxi/clk-sunxi.c @@ -202,6 +202,44 @@ static void sunxi_get_apb1_factors(u32 *freq, u32 parent_rate, /** + * sunxi_get_mod0_factors() - calculates m, n factors for MOD0-style clocks + * MMC rate is calculated as follows + * rate = (parent_rate >> p) / (m + 1); + */ + +static void sunxi_get_mod0_factors(u32 *freq, u32 parent_rate, + u8 *n, u8 *k, u8 *m, u8 *p) +{ + u8 div, calcm, calcp; + + /* Normalize value to a division of the parent */ + div = parent_rate / *freq; + *freq = parent_rate / div; + + if (div < 16) + calcp = 0; + else if (div / 2 < 16) + calcp = 1; + else if (div / 4 < 16) + calcp = 2; + else + calcp = 3; + + calcm = DIV_ROUND_UP(div, 1 << calcp); + + *freq = (parent_rate >> calcp) / calcm; + + /* we were called to round the frequency, we can now return */ + if (n == NULL) + return; + + *m = calcm - 1; + *p = calcp; +} + + + +/** * sunxi_factors_clk_setup() - Setup function for factor clocks */ @@ -239,6 +277,14 @@ static struct clk_factors_config apb1_config = { .pwidth = 2, }; +/* user manual says "n" but it's really "p" */ +static struct clk_factors_config mod0_config = { + .mshift = 0, + .mwidth = 4, + .pshift = 16, + .pwidth = 2, +}; + static const __initconst struct factors_data pll1_data = { .enable = 31, .table = &pll1_config, @@ -256,6 +302,13 @@ static const __initconst struct factors_data apb1_data = { .getter = sunxi_get_apb1_factors, }; +static const __initconst struct factors_data mod0_data = { + .enable = 31, + .mux = 24, + .table = &mod0_config, + .getter = sunxi_get_mod0_factors, +}; + static void __init sunxi_factors_clk_setup(struct device_node *node, struct factors_data *data) { @@ -621,6 +674,7 @@ CLK_OF_DECLARE(sunxi_osc, "allwinner,sun4i-osc-clk", sunxi_osc_clk_setup); static const __initconst struct of_device_id clk_factors_match[] = { {.compatible = "allwinner,sun4i-pll1-clk", .data = &pll1_data,}, {.compatible = "allwinner,sun4i-apb1-clk", .data = &apb1_data,}, + {.compatible = "allwinner,sun4i-mod0-clk", .data = &mod0_data,}, {} };