Re: [PATCH 0/3] Clocklib: generic framework for clocks managing [v3]

Previous thread: none

Next thread: [PATCH] Remove experimental status of kdump on IA64 by Bernhard Walle on Thursday, June 26, 2008 - 8:53 am. (1 message)
To: <linux-kernel@...>
Cc: <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, pHilipp Zabel <philipp.zabel@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Thursday, June 26, 2008 - 8:50 am

Hi,

This is again a set of patches to unify the management of clocks and
allow easy registration and unregistration of them. This is neccessary
to cleanly support such devices as toshiba mobile companion chips,
sa1111 companion, etc. Also it brings code unification, especially for a
lot of arm sub-arches which share nearly the same code, etc.

This is the "version 3" approach. Given the negative response to
kobjects, I've redesigned it to use plain krefs.

Debugfs support is merged into main clocklib patch. Documentation
for it's interface will come later. For now it provides tree structure
with single file per each clock directory.

--
With best wishes
Dmitry

--

To: Dmitry Baryshkov <dbaryshkov@...>
Cc: <linux-kernel@...>, <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, pHilipp Zabel <philipp.zabel@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Thursday, July 3, 2008 - 4:22 pm

I'd prefer not to see this called clocklib, it isn't of any use
outside of the kernel, and once it is in there's little point in
anyone not using it.

--
Ben (ben@fluff.org, http://www.fluff.org/)

'a smiley only costs 4 bytes'
--

To: Ben Dooks <ben-linux@...>
Cc: <linux-kernel@...>, <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, pHilipp Zabel <philipp.zabel@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Friday, July 4, 2008 - 5:05 am

--
With best wishes
Dmitry

--

To: <linux-kernel@...>
Cc: <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, pHilipp Zabel <philipp.zabel@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Thursday, June 26, 2008 - 8:52 am

Make SA-1100 use clocklib for clocks support.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
---
arch/arm/Kconfig | 1 +
arch/arm/mach-sa1100/clock.c | 114 ++++++------------------------------------
2 files changed, 17 insertions(+), 98 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index e7d0343..fffd99a 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -421,6 +421,7 @@ config ARCH_SA1100
select GENERIC_CLOCKEVENTS
select TICK_ONESHOT
select HAVE_GPIO_LIB
+ select HAVE_CLOCKLIB
help
Support for StrongARM 11x0 based boards.

diff --git a/arch/arm/mach-sa1100/clock.c b/arch/arm/mach-sa1100/clock.c
index fc97fe5..61760b7 100644
--- a/arch/arm/mach-sa1100/clock.c
+++ b/arch/arm/mach-sa1100/clock.c
@@ -3,88 +3,12 @@
*/
#include <linux/module.h>
#include <linux/kernel.h>
-#include <linux/list.h>
-#include <linux/errno.h>
-#include <linux/err.h>
-#include <linux/string.h>
#include <linux/clk.h>
-#include <linux/spinlock.h>
-#include <linux/mutex.h>
+#include <linux/clocklib.h>

#include <asm/hardware.h>

-/*
- * Very simple clock implementation - we only have one clock to
- * deal with at the moment, so we only match using the "name".
- */
-struct clk {
- struct list_head node;
- unsigned long rate;
- const char *name;
- unsigned int enabled;
- void (*enable)(void);
- void (*disable)(void);
-};
-
-static LIST_HEAD(clocks);
-static DEFINE_MUTEX(clocks_mutex);
-static DEFINE_SPINLOCK(clocks_lock);
-
-struct clk *clk_get(struct device *dev, const char *id)
-{
- struct clk *p, *clk = ERR_PTR(-ENOENT);
-
- mutex_lock(&clocks_mutex);
- list_for_each_entry(p, &clocks, node) {
- if (strcmp(id, p->name) == 0) {
- clk = p;
- break;
- }
- }
- mutex_unlock(&clocks_mutex);
-
- return clk;
-}
-EXPORT_SYMBOL(clk_get);
-
-void clk_put(struct clk *clk)
-{
-}
-EXPORT_SYMBOL(clk_put);
-
-int cl...

To: <linux-kernel@...>
Cc: <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, pHilipp Zabel <philipp.zabel@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Thursday, June 26, 2008 - 8:51 am

Make PXA use clocklib for clocks support.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
---
arch/arm/Kconfig | 1 +
arch/arm/mach-pxa/clock.c | 157 ++++++++++++++++++--------------------------
arch/arm/mach-pxa/clock.h | 89 ++++++++++++++++---------
arch/arm/mach-pxa/pxa25x.c | 69 ++++++++++++-------
arch/arm/mach-pxa/pxa27x.c | 78 +++++++++++++---------
arch/arm/mach-pxa/pxa3xx.c | 154 ++++++++++++++++++++++++++----------------
6 files changed, 307 insertions(+), 241 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index fe1455e..e7d0343 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -393,6 +393,7 @@ config ARCH_PXA
select GENERIC_TIME
select GENERIC_CLOCKEVENTS
select TICK_ONESHOT
+ select HAVE_CLOCKLIB
help
Support for Intel/Marvell's PXA2xx/PXA3xx processor line.

diff --git a/arch/arm/mach-pxa/clock.c b/arch/arm/mach-pxa/clock.c
index 180c8bb..f326b80 100644
--- a/arch/arm/mach-pxa/clock.c
+++ b/arch/arm/mach-pxa/clock.c
@@ -3,152 +3,121 @@
*/
#include <linux/module.h>
#include <linux/kernel.h>
-#include <linux/list.h>
-#include <linux/errno.h>
-#include <linux/err.h>
-#include <linux/string.h>
#include <linux/clk.h>
-#include <linux/spinlock.h>
-#include <linux/platform_device.h>
+#include <linux/clocklib.h>
#include <linux/delay.h>

#include <asm/arch/pxa2xx-regs.h>
#include <asm/arch/pxa2xx-gpio.h>
#include <asm/hardware.h>

-#include "devices.h"
-#include "generic.h"
+//#include "devices.h"
+//#include "generic.h"
#include "clock.h"

-static LIST_HEAD(clocks);
-static DEFINE_MUTEX(clocks_mutex);
-static DEFINE_SPINLOCK(clocks_lock);
-
-static struct clk *clk_lookup(struct device *dev, const char *id)
+static int clk_gpio11_enable(struct clk *clk)
{
- struct clk *p;
-
- list_for_each_entry(p, &clocks, node)
- if (strcmp(id, p->name) == 0 && p->dev ==...

To: Dmitry Baryshkov <dbaryshkov@...>
Cc: <linux-kernel@...>, <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Thursday, June 26, 2008 - 11:02 am

regards
Philipp
--

To: <linux-kernel@...>
Cc: <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, pHilipp Zabel <philipp.zabel@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Thursday, June 26, 2008 - 8:51 am

Provide a generic framework that platform may choose
to support clocks api. In particular this provides
platform-independant struct clk definition, a full
implementation of clocks api and a set of functions
for registering and unregistering clocks in a safe way.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
---
include/linux/clocklib.h | 58 ++++++++
lib/Kconfig | 3 +
lib/Makefile | 1 +
lib/clocklib.c | 353 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 415 insertions(+), 0 deletions(-)
create mode 100644 include/linux/clocklib.h
create mode 100644 lib/clocklib.c

diff --git a/include/linux/clocklib.h b/include/linux/clocklib.h
new file mode 100644
index 0000000..cf2b41e
--- /dev/null
+++ b/include/linux/clocklib.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2008 Dmitry Baryshkov
+ *
+ * This file is released under the GPL v2.
+ */
+
+#ifndef CLKLIB_H
+#define CLKLIB_H
+
+#include <linux/spinlock.h>
+#include <linux/kref.h>
+
+struct clk;
+
+/**
+ * struct clk_ops - generic clock management operations
+ * @can_get: checks whether passed device can get this clock
+ * @set_parent: reconfigures the clock to use specified parent
+ * @set_mode: enable or disable specified clock
+ * @get_rate: obtain the current clock rate of a specified clock
+ * @set_rate: set the clock rate for a specified clock
+ * @round_rate: adjust a reate to the exact rate a clock can provide
+ *
+ * This structure specifies clock operations that are used to configure
+ * specific clock.
+ */
+struct clk_ops {
+ int (*can_get)(struct clk *clk, struct device *dev);
+ int (*set_parent)(struct clk *clk, struct clk *parent);
+ int (*enable)(struct clk *clk);
+ void (*disable)(struct clk *clk);
+ unsigned long (*get_rate)(struct clk *clk);
+ long (*round_rate)(struct clk *clk, unsigned long hz, bool apply);
+};
+
+
+struct clk {
+ struct list_head node;
+ spinlock_t *lock;
+ struct kref ref;
+ int us...

To: Dmitry Baryshkov <dbaryshkov@...>
Cc: <linux-kernel@...>, <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, pHilipp Zabel <philipp.zabel@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Thursday, July 3, 2008 - 4:31 pm

I'd much prefer to see the following changes:

1) enable and disable merged into one, and pass an enable
parameter, ie:

int (*set_enable)(struct clk *clk, bool on);

as most code I see is of the following:

int myclk_enable(struct clk *clk, bool on)
{
clkbit = bit_for_clk(clk);
reg = read_reg(reg_for_clk(clk));

if (on)
reg |= clkbit;
else
reg &= ~clkbit;

write_reg(reg, reg_for_clk(clk));
return 0;
}

whereas if you have seperate enable and disable methods you
end up duplicating quite a lot of that code, as so:

int myclk_enable(struct clk *clk)
{
clkbit = bit_for_clk(clk);
reg = read_reg(reg_for_clk(clk));

reg |= clkbit;

write_reg(reg, reg_for_clk(clk));
return 0;
}

int myclk_disable(struct clk *clk)
{
clkbit = bit_for_clk(clk);
reg = read_reg(reg_for_clk(clk));

reg &= ~clkbit;

write_reg(reg, reg_for_clk(clk));
return 0;

Can't you hide this in the code, say by wrappering the

clk->usage = 0; is the same, maybe also easier to encase
the whole lot in the same if block:

if (clk->usage == 1) {
rc = clk->ops->enable(clk);

if (rc)
clk->usage = 0;

--
Ben (ben@fluff.org, http://www.fluff.org/)

'a smiley only costs 4 bytes'
--

To: Ben Dooks <ben-linux@...>
Cc: Dmitry Baryshkov <dbaryshkov@...>, <linux-kernel@...>, <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, pHilipp Zabel <philipp.zabel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Friday, July 4, 2008 - 4:44 am

This does not belong into lib/, really. drivers/clk seems ok.
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--

To: Ben Dooks <ben-linux@...>
Cc: <linux-kernel@...>, <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, pHilipp Zabel <philipp.zabel@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Friday, July 4, 2008 - 5:04 am

Because there will be probably no "clock only" drivers. Probably it

It was discussed before. Andrew Morton specifically said, that he

It is allocated dynamically by drivers. I can move this to
struct clk_private to specify that it's private, but it should be

--
With best wishes
Dmitry

--

To: Dmitry Baryshkov <dbaryshkov@...>
Cc: Ben Dooks <ben-linux@...>, <linux-kernel@...>, <akpm@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, pHilipp Zabel <philipp.zabel@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Friday, July 4, 2008 - 5:12 am

Actually, I don't think it _should_ be private. Low-level clock drivers
might want to provide debugfs nodes on their own, and those nodes
naturally belong in the same directory as the clklib ones. So the
debugfs root node must be exposed somehow.

You can get rid of the "info" field if you apply this patch:

http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/...

Haavard
--

To: Dmitry Baryshkov <dbaryshkov@...>
Cc: <linux-kernel@...>, <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Thursday, June 26, 2008 - 11:00 am

regards
Philipp
--

To: pHilipp Zabel <philipp.zabel@...>
Cc: <linux-kernel@...>, <akpm@...>, Haavard Skinnemoen <haavard.skinnemoen@...>, Russell King <rmk+lkml@...>, Paul Mundt <lethal@...>, Pavel Machek <pavel@...>, <tony@...>, <paul@...>, David Brownell <david-b@...>, Mark Brown <broonie@...>, ian <spyro@...>
Date: Thursday, June 26, 2008 - 11:03 am

That was an idea to be able to supply some additional info from a clock.

--
With best wishes
Dmitry

--

Previous thread: none

Next thread: [PATCH] Remove experimental status of kdump on IA64 by Bernhard Walle on Thursday, June 26, 2008 - 8:53 am. (1 message)