From: pawel.moll@arm.com (Pawel Moll)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 05/11] clk: Versatile Express clock generators ("osc") driver
Date: Mon, 3 Sep 2012 17:25:25 +0100 [thread overview]
Message-ID: <1346689531-7212-6-git-send-email-pawel.moll@arm.com> (raw)
In-Reply-To: <1346689531-7212-1-git-send-email-pawel.moll@arm.com>
This driver provides a common clock framework hardware driver
for Versatile Express clock generators (a.k.a "osc") controlled
via the config bus.
Signed-off-by: Pawel Moll <pawel.moll@arm.com>
Cc: Mike Turquette <mturquette@linaro.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
---
arch/arm/include/asm/hardware/sp810.h | 2 +
drivers/clk/versatile/Makefile | 1 +
drivers/clk/versatile/clk-vexpress-osc.c | 154 ++++++++++++++++++++++++++++++
include/linux/vexpress.h | 9 ++
4 files changed, 166 insertions(+)
create mode 100644 drivers/clk/versatile/clk-vexpress-osc.c
diff --git a/arch/arm/include/asm/hardware/sp810.h b/arch/arm/include/asm/hardware/sp810.h
index 6b9b077..afd7e91 100644
--- a/arch/arm/include/asm/hardware/sp810.h
+++ b/arch/arm/include/asm/hardware/sp810.h
@@ -56,6 +56,8 @@
#define SCCTRL_TIMEREN1SEL_REFCLK (0 << 17)
#define SCCTRL_TIMEREN1SEL_TIMCLK (1 << 17)
+#define SCCTRL_TIMERENnSEL_SHIFT(n) (15 + ((n) * 2))
+
static inline void sysctl_soft_reset(void __iomem *base)
{
/* switch to slow mode */
diff --git a/drivers/clk/versatile/Makefile b/drivers/clk/versatile/Makefile
index c0a0f64..dd32e77 100644
--- a/drivers/clk/versatile/Makefile
+++ b/drivers/clk/versatile/Makefile
@@ -2,3 +2,4 @@
obj-$(CONFIG_ICST) += clk-icst.o
obj-$(CONFIG_ARCH_INTEGRATOR) += clk-integrator.o
obj-$(CONFIG_ARCH_REALVIEW) += clk-realview.o
+obj-$(CONFIG_VEXPRESS_CONFIG_BUS) += clk-vexpress-osc.o
diff --git a/drivers/clk/versatile/clk-vexpress-osc.c b/drivers/clk/versatile/clk-vexpress-osc.c
new file mode 100644
index 0000000..969e03f
--- /dev/null
+++ b/drivers/clk/versatile/clk-vexpress-osc.c
@@ -0,0 +1,154 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ *
+ * Copyright (C) 2012 ARM Limited
+ */
+
+#include <linux/clkdev.h>
+#include <linux/clk-provider.h>
+#include <linux/err.h>
+#include <linux/of.h>
+#include <linux/slab.h>
+#include <linux/vexpress.h>
+
+struct vexpress_osc {
+ struct vexpress_config_device *vecdev;
+ struct clk_hw hw;
+ unsigned long rate_min;
+ unsigned long rate_max;
+};
+
+#define to_vexpress_osc(osc) container_of(osc, struct vexpress_osc, hw)
+
+static unsigned long vexpress_osc_recalc_rate(struct clk_hw *hw,
+ unsigned long parent_rate)
+{
+ struct vexpress_osc *osc = to_vexpress_osc(hw);
+ u32 rate;
+
+ vexpress_config_read(osc->vecdev, 0, &rate);
+
+ return rate;
+}
+
+static long vexpress_osc_round_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long *parent_rate)
+{
+ struct vexpress_osc *osc = to_vexpress_osc(hw);
+
+ if (WARN_ON(rate < osc->rate_min))
+ rate = osc->rate_min;
+
+ if (WARN_ON(rate > osc->rate_max))
+ rate = osc->rate_max;
+
+ return rate;
+}
+
+static int vexpress_osc_set_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long parent_rate)
+{
+ struct vexpress_osc *osc = to_vexpress_osc(hw);
+
+ return vexpress_config_write(osc->vecdev, 0, rate);
+}
+
+static struct clk_ops vexpress_osc_ops = {
+ .recalc_rate = vexpress_osc_recalc_rate,
+ .round_rate = vexpress_osc_round_rate,
+ .set_rate = vexpress_osc_set_rate,
+};
+
+
+static int vexpress_osc_probe(struct vexpress_config_device *vecdev)
+{
+ int err;
+ struct device_node *node = vecdev->dev.of_node;
+ struct vexpress_osc_info *info = vecdev->dev.platform_data;
+ struct clk_init_data init;
+ struct vexpress_osc *osc;
+ struct clk *clk;
+ const char * const *dev_ids = NULL;
+ u32 range[2];
+
+ if (vecdev->status & VEXPRESS_CONFIG_DEVICE_PROBED_EARLY)
+ return 0;
+
+ osc = kzalloc(sizeof(*osc), GFP_KERNEL);
+ if (!osc) {
+ err = -ENOMEM;
+ goto error;
+ }
+ osc->vecdev = vecdev;
+
+ if (info) {
+ init.name = info->clock_name;
+ osc->rate_min = info->rate_min;
+ osc->rate_max = info->rate_max;
+ dev_ids = info->dev_ids;
+ }
+
+ of_property_read_string(node, "clock-output-names", &init.name);
+
+ if (of_property_read_u32_array(node, "freq-range", range,
+ ARRAY_SIZE(range)) == 0) {
+ osc->rate_min = range[0];
+ osc->rate_max = range[1];
+ }
+
+ if (!init.name)
+ init.name = vecdev->name;
+ init.ops = &vexpress_osc_ops;
+ init.flags = CLK_IS_ROOT;
+ init.num_parents = 0;
+
+ osc->hw.init = &init;
+
+ dev_dbg(&vecdev->dev, "New osc %lu-%luHz\n",
+ osc->rate_min, osc->rate_max);
+
+ clk = clk_register(NULL, &osc->hw);
+ if (IS_ERR(clk)) {
+ err = PTR_ERR(clk);
+ goto error;
+ }
+
+ of_clk_add_provider(node, of_clk_src_simple_get, clk);
+
+ while (dev_ids && *dev_ids) {
+ err = clk_register_clkdev(clk, NULL, *dev_ids);
+ if (err)
+ dev_warn(&vecdev->dev, "Failed to register clkdev lookup for '%s'!\n",
+ *dev_ids);
+ dev_ids++;
+ }
+
+ return 0;
+
+error:
+ kfree(osc);
+ return err;
+}
+
+static const unsigned vexpress_osc_funcs[] = {
+ VEXPRESS_CONFIG_FUNC_OSC,
+ 0,
+};
+
+static struct vexpress_config_driver vexpress_osc_driver = {
+ .funcs = vexpress_osc_funcs,
+ .probe = vexpress_osc_probe,
+ .driver.name = "vexpress-osc",
+};
+
+int __init vexpress_osc_driver_register(void)
+{
+ return vexpress_config_driver_register(&vexpress_osc_driver);
+}
diff --git a/include/linux/vexpress.h b/include/linux/vexpress.h
index 7b02341..4768e6e 100644
--- a/include/linux/vexpress.h
+++ b/include/linux/vexpress.h
@@ -121,4 +121,13 @@ int vexpress_config_write(struct vexpress_config_device *vecdev, int offset,
void vexpress_power_off(void);
void vexpress_restart(char str, const char *cmd);
+/* Clock generators */
+struct vexpress_osc_info {
+ const char *clock_name;
+ unsigned long rate_min;
+ unsigned long rate_max;
+ const char * const *dev_ids;
+};
+int vexpress_osc_driver_register(void);
+
#endif
--
1.7.9.5
next prev parent reply other threads:[~2012-09-03 16:25 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-03 16:25 [PATCH 00/11] Versatile Express infrastructure Pawel Moll
2012-09-03 16:25 ` [PATCH 01/11] input: ambakmi: Add missing clk_[un]prepare() calls Pawel Moll
2012-09-04 13:37 ` Thomas Petazzoni
2012-09-04 13:45 ` Pawel Moll
2012-09-03 16:25 ` [PATCH 02/11] misc: Versatile Express config bus infrastructure Pawel Moll
2012-09-03 21:17 ` Arnd Bergmann
2012-09-04 11:53 ` Pawel Moll
2012-09-04 12:45 ` Arnd Bergmann
2012-09-04 16:41 ` Pawel Moll
2012-09-03 16:25 ` [PATCH 03/11] misc: Versatile Express reset driver Pawel Moll
2012-09-03 16:25 ` [PATCH 04/11] misc: Versatile Express display muxer driver Pawel Moll
2012-09-03 21:21 ` Arnd Bergmann
2012-09-04 11:53 ` Pawel Moll
2012-09-03 16:25 ` Pawel Moll [this message]
2012-09-10 19:14 ` [PATCH 05/11] clk: Versatile Express clock generators ("osc") driver Mike Turquette
2012-09-11 16:10 ` Pawel Moll
2012-09-11 18:00 ` Linus Walleij
2012-09-12 16:56 ` Pawel Moll
2012-09-11 18:33 ` Mike Turquette
2012-09-03 16:25 ` [PATCH 06/11] clk: Common clocks implementation for Versatile Express Pawel Moll
2012-09-03 21:24 ` Arnd Bergmann
2012-09-04 11:53 ` Pawel Moll
2012-09-04 12:43 ` Linus Walleij
2012-09-04 17:12 ` Ryan Harkin
2012-09-10 20:10 ` Mike Turquette
2012-09-03 16:25 ` [PATCH 07/11] regulators: Versatile Express regulator driver Pawel Moll
2012-09-03 16:25 ` [PATCH 08/11] hwmon: Versatile Express hwmon driver Pawel Moll
2012-09-03 16:25 ` [PATCH 09/11] misc: Versatile Express system registers driver Pawel Moll
2012-09-03 16:25 ` [PATCH 10/11] ARM: vexpress: Add config bus components and clocks to DTs Pawel Moll
2012-09-04 12:58 ` Rob Herring
2012-09-04 13:05 ` Pawel Moll
2012-09-04 14:31 ` Rob Herring
2012-09-04 15:37 ` Pawel Moll
2012-09-04 17:51 ` Rob Herring
2012-09-19 9:44 ` Pawel Moll
2012-09-03 16:25 ` [PATCH 11/11] ARM: vexpress: Start using new Versatile Express infrastructure Pawel Moll
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1346689531-7212-6-git-send-email-pawel.moll@arm.com \
--to=pawel.moll@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).