From patchwork Sat Sep 13 22:13:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 4900411 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 8BBAABEEA5 for ; Sat, 13 Sep 2014 22:17:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 785232021B for ; Sat, 13 Sep 2014 22:17:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D7AF520200 for ; Sat, 13 Sep 2014 22:17:09 +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 1XSvas-0003cu-Ao; Sat, 13 Sep 2014 22:14:58 +0000 Received: from mout.gmx.net ([212.227.17.20]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XSvaO-0002vN-3k for linux-arm-kernel@lists.infradead.org; Sat, 13 Sep 2014 22:14:29 +0000 Received: from zwerg.lan ([79.222.204.61]) by mail.gmx.com (mrgmx101) with ESMTPSA (Nemesis) id 0MJGFi-1XVgjd0t0k-002qnh; Sun, 14 Sep 2014 00:13:59 +0200 From: Oleksij Rempel To: linux-arm-kernel@lists.infradead.org, tglx@linutronix.de, mturquette@linaro.org Subject: [PATCH 4/7] clk: add clk-asm9260 driver Date: Sun, 14 Sep 2014 00:13:25 +0200 Message-Id: <1410646408-28901-5-git-send-email-linux@rempel-privat.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1410646408-28901-1-git-send-email-linux@rempel-privat.de> References: <1410646408-28901-1-git-send-email-linux@rempel-privat.de> X-Provags-ID: V03:K0:7M5pgMbM+31MX9gQgXp9UHmFWf2pQ3MBoKWrpOP+3f0UHjAJcSx n+zhg5vslVDPqnMKhzQdfrc68UBN4dZGB+qcWBZk87AAsr9nB0JQStgqqwCD8EjYtphXCFF 8upIbZtRc5LJwhuHQg8vaUwLm401T+prhkzl1ktdg93Ps+zINAqUBIc4G8TzvDwQfRr+tm5 jcTdcd7EUlYdwfQYXDNKg== X-UI-Out-Filterresults: notjunk:1; X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140913_151428_529575_DD7FB77D X-CRM114-Status: GOOD ( 12.55 ) X-Spam-Score: -1.8 (-) Cc: Oleksij Rempel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham 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 Signed-off-by: Oleksij Rempel --- drivers/clk/Makefile | 1 + drivers/clk/clk-asm9260.c | 159 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 drivers/clk/clk-asm9260.c diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index 567f102..351dd48 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_ARCH_HI3xxx) += hisilicon/ obj-$(CONFIG_ARCH_HIP04) += hisilicon/ obj-$(CONFIG_ARCH_HIX5HD2) += hisilicon/ obj-$(CONFIG_COMMON_CLK_KEYSTONE) += keystone/ +obj-$(CONFIG_MACH_ASM9260) += clk-asm9260.o ifeq ($(CONFIG_COMMON_CLK), y) obj-$(CONFIG_ARCH_MMP) += mmp/ endif diff --git a/drivers/clk/clk-asm9260.c b/drivers/clk/clk-asm9260.c new file mode 100644 index 0000000..396cc09 --- /dev/null +++ b/drivers/clk/clk-asm9260.c @@ -0,0 +1,159 @@ +/* + * U300 clock implementation + * Copyright (C) 2007-2012 ST-Ericsson AB + * License terms: GNU General Public License (GPL) version 2 + * Author: Linus Walleij + * Author: Jonas Aaberg + */ +#include +#include +#include +#include +#include +#include +#include +#include + +static DEFINE_SPINLOCK(asm9260_clk_lock); + +struct asm9260_clk { + void __iomem *reg; + char *parent_name; +}; + +static void __iomem *asm9260_get_sreg(struct device_node *node) +{ + u32 reg; + void __iomem *iomem; + struct device_node *srnp; + int ret; + + ret = of_property_read_u32(node, "reg", ®); + if (WARN_ON(ret)) + return NULL; + + srnp = of_find_compatible_node(NULL, NULL, "alpscale,asm9260-sregs"); + iomem = of_iomap(srnp, 0); + iomem += reg; + + return iomem; +} + +/* + * On this chip gate used to disable or to update clock + * after new source was selected + */ + +static void __init asm9260_gate_init(struct device_node *node) +{ + struct clk *clk; + const char *clk_name = node->name; + void __iomem *iomem; + const char *parent_name; + u32 bit; + int ret; + + iomem = asm9260_get_sreg(node); + parent_name = of_clk_get_parent_name(node, 0); + + ret = of_property_read_u32(node, "bit-index", &bit); + if (WARN_ON(ret)) + return; + + clk = clk_register_gate(NULL, clk_name, parent_name, + CLK_SET_RATE_PARENT, iomem, bit, 0, + &asm9260_clk_lock); + + if (!IS_ERR(clk)) + of_clk_add_provider(node, of_clk_src_simple_get, clk); +} +CLK_OF_DECLARE(asm9260_gate, "alpscale,asm9260-gate-clock", asm9260_gate_init); + + +static void __init asm9260_div_init(struct device_node *node) +{ + struct clk *clk; + const char *clk_name = node->name; + void __iomem *iomem; + const char *parent_name; + + iomem = asm9260_get_sreg(node); + + parent_name = of_clk_get_parent_name(node, 0); + clk = clk_register_divider(NULL, clk_name, parent_name, + CLK_SET_RATE_PARENT, iomem, 0, 8, CLK_DIVIDER_ONE_BASED, + &asm9260_clk_lock); + + if (!IS_ERR(clk)) + of_clk_add_provider(node, of_clk_src_simple_get, clk); +} +CLK_OF_DECLARE(asm9260_div, "alpscale,asm9260-div-clock", asm9260_div_init); + +/* + * Simple one bit MUX for two sources + */ +static void __init asm9260_bimux_init(struct device_node *node) +{ + struct clk *clk; + const char *clk_name = node->name; + u8 num_parents; + void __iomem *iomem; + const char **parent_names; + int ret, i; + u32 *table; + + iomem = asm9260_get_sreg(node); + if (!iomem) + return; + + num_parents = of_clk_get_parent_count(node); + if (WARN_ON(!num_parents || num_parents > 2)) + return; + + parent_names = kzalloc(sizeof(char *) * num_parents, GFP_KERNEL); + if (WARN_ON(!parent_names)) + return; + + table = kzalloc(sizeof(u32) * num_parents, GFP_KERNEL); + if (WARN_ON(!table)) + return; + + ret = of_property_read_u32_array(node, "mux-table", table, + num_parents); + if (WARN_ON(ret)) + return; + + for (i = 0; i < num_parents; i++) + parent_names[i] = of_clk_get_parent_name(node, i); + + clk = clk_register_mux_table(NULL, clk_name, parent_names, + num_parents, 0, iomem, 0, 1, 0, table, + &asm9260_clk_lock); + + if (!IS_ERR(clk)) + of_clk_add_provider(node, of_clk_src_simple_get, clk); +} +CLK_OF_DECLARE(asm9260_bimux, "alpscale,asm9260-bimux-clock", asm9260_bimux_init); + +static void __init asm9260_pll_init(struct device_node *node) +{ + struct clk *clk; + const char *clk_name = node->name; + u32 rate; + void __iomem *iomem; + const char *parent_name; + u32 accuracy = 0; + + iomem = asm9260_get_sreg(node); + rate = (ioread32(iomem) & 0xffff) * 1000000; + + parent_name = of_clk_get_parent_name(node, 0); + accuracy = clk_get_accuracy(__clk_lookup(parent_name)); + clk = clk_register_fixed_rate_with_accuracy(NULL, clk_name, parent_name, + 0, rate, + accuracy); + + if (!IS_ERR(clk)) + of_clk_add_provider(node, of_clk_src_simple_get, clk); +} +CLK_OF_DECLARE(asm9260_pll, "alpscale,asm9260-pll-clock", asm9260_pll_init);