mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Davide Rizzo <elpa.rizzo@gmail.com>
To: Greg KH <gregkh@suse.de>
Cc: "Hans J. Koch" <hjk@linutronix.de>,
	linux-kernel@vger.kernel.org, ben-linux@fluff.org
Subject: Re: [PATCH 1/3] Driver for user access to internal clocks
Date: Wed, 28 Jan 2009 20:17:06 +0100	[thread overview]
Message-ID: <8447d6730901281117g3a8b7ddfp26e937111b6b6304@mail.gmail.com> (raw)
In-Reply-To: <20090108163024.GB26413@suse.de>

> Same comments here as for your "timer.c" file:
>        - too generic of a name
>        - needs proper documentation
>        - send any kernel api changes also to linux-api@vger.kernel.org
>
> thanks,
>
> greg k-h
>

This is the modified Samsung S3c implementation for user mode clock driver.

This is a proposal for adding 2 functions to clk interface to allow higher
 level drivers to enumerate and list all clocks, and to modify clk_get
 to accept device specific clk names in the form "name.id"
There is also the implementation for Samsung S3C24xx platform.

Signed-off-by: Davide Rizzo <elpa.rizzo@gmail.com>
---diff -urpN linux-2.6.29-rc2/arch/arm/plat-s3c/clock.c
linux-2.6.29-rc2.elpa/arch/arm/plat-s3c/clock.c
--- linux-2.6.29-rc2/arch/arm/plat-s3c/clock.c	2009-01-17
11:32:38.000000000 +0100
+++ linux-2.6.29-rc2.elpa/arch/arm/plat-s3c/clock.c	2009-01-28
19:32:08.000000000 +0100
@@ -69,11 +69,19 @@ static int clk_null_enable(struct clk *c

 struct clk *clk_get(struct device *dev, const char *id)
 {
+	long idno;
+	char *name = (char *)id;
+	char *dotpos = strrchr(id, '.');
 	struct clk *p;
 	struct clk *clk = ERR_PTR(-ENOENT);
-	int idno;

-	if (dev == NULL || dev->bus != &platform_bus_type)
+	if (dotpos) {
+		int err = strict_strtol(dotpos + 1, 10, &idno);
+		if (err)
+				return ERR_PTR(err);
+		name = kstrdup(id, GFP_KERNEL);
+		name[dotpos - id] = '\0';
+	} else if (dev == NULL || dev->bus != &platform_bus_type)
 		idno = -1;
 	else
 		idno = to_platform_device(dev)->id;
@@ -82,7 +90,7 @@ struct clk *clk_get(struct device *dev,

 	list_for_each_entry(p, &clocks, list) {
 		if (p->id == idno &&
-		    strcmp(id, p->name) == 0 &&
+		    strcmp(name, p->name) == 0 &&
 		    try_module_get(p->owner)) {
 			clk = p;
 			break;
@@ -94,7 +102,7 @@ struct clk *clk_get(struct device *dev,

 	if (IS_ERR(clk)) {
 		list_for_each_entry(p, &clocks, list) {
-			if (p->id == -1 && strcmp(id, p->name) == 0 &&
+			if (p->id == -1 && strcmp(name, p->name) == 0 &&
 			    try_module_get(p->owner)) {
 				clk = p;
 				break;
@@ -103,6 +111,8 @@ struct clk *clk_get(struct device *dev,
 	}

 	spin_unlock(&clocks_lock);
+	if (dotpos)
+		kfree(name);
 	return clk;
 }

@@ -222,6 +232,42 @@ EXPORT_SYMBOL(clk_set_rate);
 EXPORT_SYMBOL(clk_get_parent);
 EXPORT_SYMBOL(clk_set_parent);

+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);
+
+/* Returned pointer 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);
+
 /* base clocks */

 static int clk_default_setrate(struct clk *clk, unsigned long rate)
diff -urpN linux-2.6.29-rc2/include/linux/clk.h
linux-2.6.29-rc2.elpa/include/linux/clk.h
--- linux-2.6.29-rc2/include/linux/clk.h	2008-12-25 00:26:37.000000000 +0100
+++ linux-2.6.29-rc2.elpa/include/linux/clk.h	2009-01-28
19:21:43.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

  reply	other threads:[~2009-01-28 19:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-08  9:49 Davide Rizzo
2009-01-08 11:27 ` Hans J. Koch
2009-01-08 16:06   ` Davide Rizzo
2009-01-08 16:30     ` Greg KH
2009-01-28 19:17       ` Davide Rizzo [this message]
2009-02-09 17:54         ` [PATCH 2/2] " Davide Rizzo
2009-01-28 19:20       ` [PATCH 1/3] " Davide Rizzo

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=8447d6730901281117g3a8b7ddfp26e937111b6b6304@mail.gmail.com \
    --to=elpa.rizzo@gmail.com \
    --cc=ben-linux@fluff.org \
    --cc=gregkh@suse.de \
    --cc=hjk@linutronix.de \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®