From patchwork Tue Mar 25 19:29:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 3890341 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 8E139BF540 for ; Tue, 25 Mar 2014 19:31:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5E60F20160 for ; Tue, 25 Mar 2014 19:31:02 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (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 0F0A520138 for ; Tue, 25 Mar 2014 19:31:01 +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 1WSX3L-0000w5-7P; Tue, 25 Mar 2014 19:30:27 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSX3B-0007pJ-4s; Tue, 25 Mar 2014 19:30:17 +0000 Received: from top.free-electrons.com ([176.31.233.9] helo=mail.free-electrons.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSX37-0007nG-W9 for linux-arm-kernel@lists.infradead.org; Tue, 25 Mar 2014 19:30:15 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id BA2A6927; Tue, 25 Mar 2014 20:29:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost (128-79-216-6.hfc.dyn.abo.bbox.fr [128.79.216.6]) by mail.free-electrons.com (Postfix) with ESMTPSA id 60CA9813; Tue, 25 Mar 2014 20:29:37 +0100 (CET) From: Alexandre Belloni To: Sebastian Hesselbarth , Mike Turquette Subject: [PATCH v3] clk: berlin: add support for berlin plls Date: Tue, 25 Mar 2014 20:29:32 +0100 Message-Id: <1395775772-19685-1-git-send-email-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 1.8.3.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140325_153014_223056_95B4A7E8 X-CRM114-Status: GOOD ( 19.90 ) X-Spam-Score: -1.6 (-) Cc: Jimmy Xu , Jisheng Zhang , linux-doc@vger.kernel.org, =?UTF-8?q?Antoine=20T=C3=A9nart?= , linux-kernel@vger.kernel.org, Alexandre Belloni , 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This drivers allows to provide DT clocks for the cpu and system PLLs found on Marvell Berlin SoCs. Signed-off-by: Alexandre Belloni Acked-by: Sebastian Hesselbarth --- Changes in v3: - removed empty lines a the end of the files - vcodiv are now arrays filled with zeros by default - use an u64 temporary variable to calculate the rate - warn when refdiv or vcodiv are zero --- drivers/clk/Makefile | 1 + drivers/clk/berlin/Makefile | 4 ++ drivers/clk/berlin/common.h | 35 ++++++++++++ drivers/clk/berlin/pll-berlin2.c | 40 +++++++++++++ drivers/clk/berlin/pll-berlin2q.c | 40 +++++++++++++ drivers/clk/berlin/pll.c | 114 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 234 insertions(+) create mode 100644 drivers/clk/berlin/Makefile create mode 100644 drivers/clk/berlin/common.h create mode 100644 drivers/clk/berlin/pll-berlin2.c create mode 100644 drivers/clk/berlin/pll-berlin2q.c create mode 100644 drivers/clk/berlin/pll.c diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index a367a9831717..4a2602737c27 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o obj-$(CONFIG_COMMON_CLK_XGENE) += clk-xgene.o obj-$(CONFIG_COMMON_CLK_AT91) += at91/ +obj-$(CONFIG_ARCH_BERLIN) += berlin/ obj-$(CONFIG_ARCH_HI3xxx) += hisilicon/ obj-$(CONFIG_COMMON_CLK_KEYSTONE) += keystone/ ifeq ($(CONFIG_COMMON_CLK), y) diff --git a/drivers/clk/berlin/Makefile b/drivers/clk/berlin/Makefile new file mode 100644 index 000000000000..94859513de90 --- /dev/null +++ b/drivers/clk/berlin/Makefile @@ -0,0 +1,4 @@ +obj-y += pll.o +obj-$(CONFIG_MACH_BERLIN_BG2) += pll-berlin2.o +obj-$(CONFIG_MACH_BERLIN_BG2CD) += pll-berlin2.o +obj-$(CONFIG_MACH_BERLIN_BG2Q) += pll-berlin2q.o diff --git a/drivers/clk/berlin/common.h b/drivers/clk/berlin/common.h new file mode 100644 index 000000000000..8eb8a9f9aa30 --- /dev/null +++ b/drivers/clk/berlin/common.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014 Marvell Technology Group Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +#ifndef __BERLIN_CLK_H +#define __BERLIN_CLK_H + +struct device_node; + +struct berlin_pllmap { + const u8 *vcodiv; + u32 fbdiv_mask; + u32 rfdiv_mask; + u32 divsel_mask; + u8 fbdiv_shift; + u8 rfdiv_shift; + u8 divsel_shift; + u8 mult; +}; + +extern void __init berlin_pll_setup(struct device_node *np, + struct berlin_pllmap *map); + +#endif /* BERLIN_CLK_H */ diff --git a/drivers/clk/berlin/pll-berlin2.c b/drivers/clk/berlin/pll-berlin2.c new file mode 100644 index 000000000000..bf5704f6ebc5 --- /dev/null +++ b/drivers/clk/berlin/pll-berlin2.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014 Marvell Technology Group Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +#include +#include +#include +#include + +#include "common.h" + +static const u8 vcodiv_berlin2[16] = {10, 15, 20, 25, 30, 40, 50, 60, 80}; + +static struct berlin_pllmap berlin_pll_map = { + .vcodiv = vcodiv_berlin2, + .fbdiv_mask = 0x1FF, + .fbdiv_shift = 6, + .rfdiv_mask = 0x1F, + .rfdiv_shift = 1, + .divsel_mask = 0xF, + .divsel_shift = 7, + .mult = 10, +}; + +static void __init berlin2_pll_setup(struct device_node *np) +{ + berlin_pll_setup(np, &berlin_pll_map); +} +CLK_OF_DECLARE(berlin2_pll, "marvell,berlin2-pll", berlin2_pll_setup); diff --git a/drivers/clk/berlin/pll-berlin2q.c b/drivers/clk/berlin/pll-berlin2q.c new file mode 100644 index 000000000000..4d0e3614c073 --- /dev/null +++ b/drivers/clk/berlin/pll-berlin2q.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014 Marvell Technology Group Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +#include +#include +#include +#include + +#include "common.h" + +static const u8 vcodiv_berlin2q[16] = {1, 0, 2, 0, 3, 4, 0, 6, 8}; + +static struct berlin_pllmap berlin2q_pll_map = { + .vcodiv = vcodiv_berlin2q, + .fbdiv_mask = 0x1FF, + .fbdiv_shift = 7, + .rfdiv_mask = 0x1F, + .rfdiv_shift = 2, + .divsel_mask = 0xF, + .divsel_shift = 9, + .mult = 1, +}; + +static void __init berlin2q_pll_setup(struct device_node *np) +{ + berlin_pll_setup(np, &berlin2q_pll_map); +} +CLK_OF_DECLARE(berlin2q_pll, "marvell,berlin2q-pll", berlin2q_pll_setup); diff --git a/drivers/clk/berlin/pll.c b/drivers/clk/berlin/pll.c new file mode 100644 index 000000000000..fd820ba484bb --- /dev/null +++ b/drivers/clk/berlin/pll.c @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2014 Marvell Technology Group Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" + +struct berlin_pll { + struct clk_hw hw; + void __iomem *base; + struct berlin_pllmap *map; +}; + +#define to_berlin_pll(hw) container_of(hw, struct berlin_pll, hw) + +#define PLL_CTRL0 0x00 +#define PLL_CTRL1 0x04 + +static inline u32 berlin_pll_read(struct berlin_pll *pll, unsigned long offset) +{ + return readl_relaxed(pll->base + offset); +} + +/* + * The output frequency formula for the pll is: + * clkout = fbdiv / refdiv * parent / vcodiv + */ +static unsigned long berlin_pll_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct berlin_pll *pll = to_berlin_pll(hw); + struct berlin_pllmap *map = pll->map; + u32 val, fbdiv, rfdiv, vcodivsel, vcodiv; + u64 rate = parent_rate; + + val = berlin_pll_read(pll, PLL_CTRL0); + fbdiv = (val >> map->fbdiv_shift) & map->fbdiv_mask; + rfdiv = (val >> map->rfdiv_shift) & map->rfdiv_mask; + if (rfdiv == 0) { + pr_warn("%s has zero rfdiv\n", __clk_get_name(hw->clk)); + rfdiv = 1; + } + + val = berlin_pll_read(pll, PLL_CTRL1); + vcodivsel = (val >> map->divsel_shift) & map->divsel_mask; + vcodiv = map->vcodiv[vcodivsel]; + if (vcodiv == 0) { + pr_warn("%s has zero vcodiv (index %d)\n", + __clk_get_name(hw->clk), vcodivsel); + vcodiv = 1; + } + + rate *= fbdiv * map->mult; + do_div(rate, rfdiv * vcodiv); + return (unsigned long)rate; +} + +static const struct clk_ops berlin_pll_ops = { + .recalc_rate = berlin_pll_recalc_rate, +}; + +void __init berlin_pll_setup(struct device_node *np, + struct berlin_pllmap *map) +{ + struct clk_init_data init; + struct berlin_pll *pll; + const char *parent_name; + struct clk *clk; + int ret; + + pll = kzalloc(sizeof(*pll), GFP_KERNEL); + if (WARN_ON(!pll)) + return; + + pll->base = of_iomap(np, 0); + if (WARN_ON(!pll->base)) + return; + + pll->map = map; + + init.name = np->name; + init.ops = &berlin_pll_ops; + parent_name = of_clk_get_parent_name(np, 0); + init.parent_names = &parent_name; + init.num_parents = 1; + + pll->hw.init = &init; + + clk = clk_register(NULL, &pll->hw); + if (WARN_ON(IS_ERR(clk))) + return; + + ret = of_clk_add_provider(np, of_clk_src_simple_get, clk); + if (WARN_ON(ret)) + return; +}