[<prev] [next>] [day] [month] [year] [list]
Message-ID: <8447d6730901080150r3f51c758l4d4b74cdaaf9d09c@mail.gmail.com>
Date: Thu, 8 Jan 2009 10:50:56 +0100
From: "Davide Rizzo" <elpa.rizzo@...il.com>
To: linux-kernel@...r.kernel.org, hjk@...utronix.de, gregkh@...e.de,
ben-linux@...ff.org
Subject: [PATCH 3/3] Driver for user access to internal clocks
This is a proposal for adding 2 functions to clk interface to allow higher
level drivers to enumerate and list all clocks.
There is also the implementation for Samsung S3C24xx platform.
Signed-off-by: Davide Rizzo <elpa-rizzo@...il.com>
---
diff -urNp linux-2.6.28/arch/arm/plat-s3c24xx/clock.c
linux-2.6.28.elpa/arch/arm/plat-s3c24xx/clock.c
--- linux-2.6.28/arch/arm/plat-s3c24xx/clock.c 2008-12-25
00:26:37.000000000 +0100
+++ linux-2.6.28.elpa/arch/arm/plat-s3c24xx/clock.c 2009-01-07
19:25:07.000000000 +0100
@@ -422,6 +433,42 @@ static int s3c24xx_clkout_setparent(stru
return 0;
}
+int clk_for_each(int(*fn)(struct clk *, void *), void *data)
+{
+ struct clk *clk;
+ int ret = 0;
+
+ list_for_each_entry(clk, &clocks, list)
+ {
+ ret = fn(clk, data);
+ if (ret)
+ break;
+ }
+ return ret;
+}
+EXPORT_SYMBOL(clk_for_each);
+
+/* Must be deallocated with kfree() */
+const char *clk_get_name(struct clk *clk)
+{
+ char *s;
+ int len;
+
+ if (IS_ERR(clk))
+ return ERR_PTR(-EINVAL);
+
+ len = strlen(clk->name) + 8;
+ s = kmalloc(len, GFP_KERNEL);
+ if (!s)
+ return ERR_PTR(-ENOMEM);
+ if (clk->id == -1)
+ strlcpy(s, clk->name, len);
+ else if (snprintf(s, len, "%s.%d", clk->name, clk->id) > len)
+ s[len - 1] = '\0';
+ return s;
+}
+EXPORT_SYMBOL(clk_get_name);
+
/* external clock definitions */
struct clk s3c24xx_dclk0 = {
diff -urNp linux-2.6.28/include/linux/clk.h
linux-2.6.28.elpa/include/linux/clk.h
--- linux-2.6.28/include/linux/clk.h 2008-12-25 00:26:37.000000000 +0100
+++ linux-2.6.28.elpa/include/linux/clk.h 2009-01-07 19:06:46.000000000 +0100
@@ -125,4 +125,22 @@ int clk_set_parent(struct clk *clk, stru
*/
struct clk *clk_get_parent(struct clk *clk);
+/**
+ * clk_for_each - calls fn, iterating between registered clocks
+ * @fn: function to be called, passing each clk structure in 1st argument
+ * @data: 2nd argument to pass to fn function
+ *
+ * Returns 0 or the called fn return code if != 0
+ */
+int clk_for_each(int(*fn)(struct clk *, void *), void *data);
+
+/**
+ * clk_name - get clock name
+ * @clk: clock source
+ *
+ * Returns clock's name that must be deallocated with kfree(), or valid
+ * IS_ERR() condition containing errno.
+ */
+const char *clk_get_name(struct clk *clk);
+
#endif
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists