From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 02/23] clk clkdev: Add clkdev matching based on physbase
Date: Mon, 24 Sep 2012 13:04:31 +0200 [thread overview]
Message-ID: <1348484692-24993-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1348484692-24993-1-git-send-email-s.hauer@pengutronix.de>
Most clock/device associations can be done based on the physical
base address of the corresponding device. So instead of depending
on string matching add an optional possibility to associate a clock
lookups with physical addresses. This also has the advantage that
the lookups for devicetree based devices can be identical to the
platform based devices.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/clk/clkdev.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
include/linux/clkdev.h | 3 +++
2 files changed, 50 insertions(+)
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 717fea5..40bc006 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -62,6 +62,32 @@ static struct clk *clk_find(const char *dev_id, const char *con_id)
return clk;
}
+static struct clk *clk_find_physbase(struct device_d *dev, const char *con_id)
+{
+ struct clk_lookup *p;
+ unsigned long start;
+
+ if (!dev || !dev->resource)
+ return ERR_PTR(-ENOSYS);
+
+ start = dev->resource[0].start;
+
+ list_for_each_entry(p, &clocks, node) {
+ if (!p->physbase)
+ continue;
+ if (p->physbase != start)
+ continue;
+ if (p->con_id) {
+ if (!con_id || strcmp(p->con_id, con_id))
+ continue;
+ return p->clk;
+ }
+ return p->clk;
+ }
+ return ERR_PTR(-ENOSYS);
+
+}
+
struct clk *clk_get_sys(const char *dev_id, const char *con_id)
{
struct clk *clk;
@@ -77,6 +103,11 @@ EXPORT_SYMBOL(clk_get_sys);
struct clk *clk_get(struct device_d *dev, const char *con_id)
{
const char *dev_id = dev ? dev_name(dev) : NULL;
+ struct clk *clk;
+
+ clk = clk_find_physbase(dev, con_id);
+ if (!IS_ERR(clk))
+ return clk;
return clk_get_sys(dev_id, con_id);
}
@@ -166,3 +197,19 @@ void clkdev_drop(struct clk_lookup *cl)
kfree(cl);
}
EXPORT_SYMBOL(clkdev_drop);
+
+int clkdev_add_physbase(struct clk *clk, unsigned long base, const char *id)
+{
+ struct clk_lookup *cl;
+
+ cl = xzalloc(sizeof(*cl));
+
+ cl->clk = clk;
+ cl->con_id = id;
+ cl->physbase = base;
+
+ clkdev_add(cl);
+
+ return 0;
+}
+EXPORT_SYMBOL(clkdev_add_physbase);
diff --git a/include/linux/clkdev.h b/include/linux/clkdev.h
index d2eca99..d2f0d89 100644
--- a/include/linux/clkdev.h
+++ b/include/linux/clkdev.h
@@ -19,6 +19,7 @@ struct device_d;
struct clk_lookup {
struct list_head node;
+ unsigned long physbase;
const char *dev_id;
const char *con_id;
struct clk *clk;
@@ -33,6 +34,8 @@ void clkdev_drop(struct clk_lookup *cl);
void clkdev_add_table(struct clk_lookup *, size_t);
int clk_add_alias(const char *, const char *, char *, struct device_d *);
+int clkdev_add_physbase(struct clk *clk, unsigned long base, const char *id);
+
#define CLKDEV_DEV_ID(_id, _clk) \
{ \
.dev_id = _id, \
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-09-24 11:04 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-24 11:04 [PATCH] common clk support Sascha Hauer
2012-09-24 11:04 ` [PATCH 01/23] err.h: introduce IS_ERR_OR_NULL Sascha Hauer
2012-09-24 11:04 ` Sascha Hauer [this message]
2012-09-26 16:02 ` [PATCH 02/23] clk clkdev: Add clkdev matching based on physbase Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 17:25 ` Sascha Hauer
2012-09-26 18:53 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 19:09 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 19:08 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-26 21:31 ` Sascha Hauer
2012-09-24 11:04 ` [PATCH 03/23] clk: initial common clk support Sascha Hauer
2012-09-24 11:04 ` [PATCH 04/23] commands: Add clk commands Sascha Hauer
2012-09-24 11:04 ` [PATCH 05/23] ARM i.MX: initial clk support Sascha Hauer
2012-09-24 11:04 ` [PATCH 06/23] ARM i.MX27: implement " Sascha Hauer
2012-09-24 11:04 ` [PATCH 07/23] ARM i.MX25: Switch to common " Sascha Hauer
2012-09-24 11:04 ` [PATCH 08/23] ARM i.MX5: " Sascha Hauer
2012-09-24 11:36 ` Sascha Hauer
2012-09-24 11:04 ` [PATCH 09/23] ARM i.MX1: " Sascha Hauer
2012-09-24 11:04 ` [PATCH 10/23] ARM i.MX31: Switch to common clk Sascha Hauer
2012-09-24 11:04 ` [PATCH 11/23] ARM i.MX6: " Sascha Hauer
2012-09-24 11:04 ` [PATCH 12/23] ARM i.MX21: " Sascha Hauer
2012-09-24 11:04 ` [PATCH 13/23] ARM i.MX35: " Sascha Hauer
2012-09-24 11:04 ` [PATCH 14/23] net fec: Switch to clk support Sascha Hauer
2012-09-26 16:07 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-24 11:04 ` [PATCH 15/23] serial i.MX: " Sascha Hauer
2012-09-26 16:08 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-24 11:04 ` [PATCH 16/23] spi " Sascha Hauer
2012-09-24 11:04 ` [PATCH 17/23] ARM i.MX: Switch clocksource to clk_get Sascha Hauer
2012-09-24 11:04 ` [PATCH 18/23] mci i.MX ESDHC: Switch to clock support Sascha Hauer
2012-09-24 11:04 ` [PATCH 19/23] mci i.MX: " Sascha Hauer
2012-09-24 11:04 ` [PATCH 20/23] i2c " Sascha Hauer
2012-09-26 16:10 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-24 11:04 ` [PATCH 21/23] video " Sascha Hauer
2012-09-24 11:04 ` [PATCH 22/23] video i.MX IPU: " Sascha Hauer
2012-09-24 11:04 ` [PATCH 23/23] ARM i.MX: Remove old " Sascha Hauer
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=1348484692-24993-3-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@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