From patchwork Mon Jun 11 15:39:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 9208 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 9A45F23EB4 for ; Mon, 11 Jun 2012 15:40:02 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 42D9CA186A7 for ; Mon, 11 Jun 2012 15:40:02 +0000 (UTC) Received: by ghbz12 with SMTP id z12so2845678ghb.11 for ; Mon, 11 Jun 2012 08:40:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=0S5Pjqi3lVYyF8KsoK2nt6SKLGnHmM2OVhDmsod/PDM=; b=aftMN1wx0lMk9BcjHSnuN6yAtWdrUrWd/CrjBAyFzx2eMAfHscOCoyuFNgkr1sFFF6 ZetgSdgxY/pUV9BLy6BXnYgxdBV9UJ+7Uc74cf0aFDxy8EueKotH9Z6uK3+p4Luhv5Wn MqfzjutNEybh3BrsPmAEgXfYhrOrYptjHmZqGB5AtRfy4/m5up1vACAIzZgO/KRfxaup jwYCpnHrLM7ywKn9LuApSV2sq41De5WUwrY+4YJrLSqRkNVYVHOBXS8RZuIha34omVZP CzZT1P/VcnYVOhn6kry6hIuuNKB0jf1BEiWLhaYM4DatYX3UxOn9DJmPcFIrsd3qGqKa vKqw== Received: by 10.50.163.99 with SMTP id yh3mr6536495igb.53.1339429201371; Mon, 11 Jun 2012 08:40:01 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.24.148 with SMTP id v20csp116648ibb; Mon, 11 Jun 2012 08:40:00 -0700 (PDT) Received: by 10.152.122.9 with SMTP id lo9mr17726500lab.41.1339429199823; Mon, 11 Jun 2012 08:39:59 -0700 (PDT) Received: from mail.df.lth.se (mail.df.lth.se. [194.47.250.12]) by mx.google.com with ESMTPS id oq4si15342592lab.36.2012.06.11.08.39.59 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 11 Jun 2012 08:39:59 -0700 (PDT) Received-SPF: pass (google.com: domain of triad@df.lth.se designates 194.47.250.12 as permitted sender) client-ip=194.47.250.12; Authentication-Results: mx.google.com; spf=pass (google.com: domain of triad@df.lth.se designates 194.47.250.12 as permitted sender) smtp.mail=triad@df.lth.se Received: from mer.df.lth.se (mer.df.lth.se [194.47.250.37]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.df.lth.se (Postfix) with ESMTPS id 0564D65D8E; Mon, 11 Jun 2012 17:39:59 +0200 (CEST) Received: from mer.df.lth.se (triad@localhost.localdomain [127.0.0.1]) by mer.df.lth.se (8.14.3/8.14.3/Debian-9.4) with ESMTP id q5BFdwFl032612; Mon, 11 Jun 2012 17:39:58 +0200 Received: (from triad@localhost) by mer.df.lth.se (8.14.3/8.14.3/Submit) id q5BFdwZj032611; Mon, 11 Jun 2012 17:39:58 +0200 From: Linus Walleij To: linux-arm-kernel@lists.infradead.org, arm@kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Russell King , Mike Turquette Subject: [PATCH 2/3] clk: add ICST307 driver Date: Mon, 11 Jun 2012 17:39:56 +0200 Message-Id: <1339429196-32584-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQnFqwQHdnyJ4g1YiuGDX/aSn/rUU2IjM4/ezM0Aras7S+Lg8YDa153Ih3KVefX+46WjAYQ7 The ICST307 VCO clock has a shared driver in the ARM architecture. This patch provides a wrapper into the common clock framework so we can use the implementation in the ARM architecture without duplicating the code until all ARM platforms using this VCO are moved over. At that point we can merge the driver from the ARM platform into the generic file altogether. Cc: Russell King Cc: Mike Turquette Signed-off-by: Linus Walleij --- drivers/clk/Kconfig | 5 ++ drivers/clk/Makefile | 1 + drivers/clk/clk-icst.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/clk/clk-icst.h | 10 +++++ 4 files changed, 115 insertions(+), 0 deletions(-) create mode 100644 drivers/clk/clk-icst.c create mode 100644 drivers/clk/clk-icst.h diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index 4864407..32e745e 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -34,4 +34,9 @@ config COMMON_CLK_DEBUG clk_flags, clk_prepare_count, clk_enable_count & clk_notifier_count. +config CLK_ICST + bool "ICST307 VCO clock driver" + depends on COMMON_CLK + depends on ICST + endmenu diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index b9a5158..a7a7cf8 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed-rate.o clk-gate.o \ # SoCs specific obj-$(CONFIG_ARCH_MXS) += mxs/ obj-$(CONFIG_PLAT_SPEAR) += spear/ +obj-$(CONFIG_CLK_ICST) += clk-icst.o diff --git a/drivers/clk/clk-icst.c b/drivers/clk/clk-icst.c new file mode 100644 index 0000000..ba003de --- /dev/null +++ b/drivers/clk/clk-icst.c @@ -0,0 +1,99 @@ +/* + * Driver for the ICST307 VCO clock found in the ARM Reference designs. + * We wrap the custom interface from into the generic + * clock framework. + * + * TODO: when all ARM reference designs are migrated to generic clocks, the + * ICST clock code from the ARM tree should probably be merged into this + * file. + */ +#include +#include +#include +#include + +#include "clk-icst.h" + +/** + * struct clk_icst - ICST VCO clock wrapper + * @hw: corresponding clock hardware entry + * @params: parameters for this ICST instance + * @rate: current rate + * @setvco: function to commit ICST settings to hardware + */ +struct clk_icst { + struct clk_hw hw; + const struct icst_params *params; + unsigned long rate; + struct icst_vco (*getvco)(void); + void (*setvco)(struct icst_vco); +}; + +#define to_icst(_hw) container_of(_hw, struct clk_icst, hw) + +static unsigned long icst_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct clk_icst *icst = to_icst(hw); + struct icst_vco vco; + + vco = icst->getvco(); + icst->rate = icst_hz(icst->params, vco); + return icst->rate; +} + +static long icst_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *prate) +{ + struct clk_icst *icst = to_icst(hw); + struct icst_vco vco; + + vco = icst_hz_to_vco(icst->params, rate); + return icst_hz(icst->params, vco); +} + +static int icst_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct clk_icst *icst = to_icst(hw); + struct icst_vco vco; + + vco = icst_hz_to_vco(icst->params, rate); + icst->rate = icst_hz(icst->params, vco); + icst->setvco(vco); + return 0; +} + +static const struct clk_ops icst_ops = { + .recalc_rate = icst_recalc_rate, + .round_rate = icst_round_rate, + .set_rate = icst_set_rate, +}; + +struct clk * __init icst_clk_init(struct device *dev, const struct clk_icst_desc *desc) +{ + struct clk *clk; + struct clk_icst *icst; + struct clk_init_data init; + + icst = kzalloc(sizeof(struct clk_icst), GFP_KERNEL); + if (!icst) { + pr_err("could not allocate ICST clock!\n"); + return ERR_PTR(-ENOMEM); + } + init.name = "icst"; + init.ops = &icst_ops; + init.flags = CLK_IS_ROOT; + init.parent_names = NULL; + init.num_parents = 0; + icst->hw.init = &init; + icst->params = desc->params; + icst->getvco = desc->getvco; + icst->setvco = desc->setvco; + + clk = clk_register(dev, &icst->hw); + if (IS_ERR(clk)) + kfree(icst); + + return clk; +} diff --git a/drivers/clk/clk-icst.h b/drivers/clk/clk-icst.h new file mode 100644 index 0000000..1deaa86 --- /dev/null +++ b/drivers/clk/clk-icst.h @@ -0,0 +1,10 @@ +#include + +struct clk_icst_desc { + const struct icst_params *params; + struct icst_vco (*getvco)(void); + void (*setvco)(struct icst_vco); +}; + +struct clk *icst_clk_init(struct device *dev, + const struct clk_icst_desc *desc);