All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] clk: add ICST307 driver
@ 2012-06-11 15:39 ` Linus Walleij
  0 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2012-06-11 15:39 UTC (permalink / raw)
  To: linux-arm-kernel, arm, linux-kernel
  Cc: Linus Walleij, Russell King, Mike Turquette

The ICST307 VCO clock has a shared driver in the ARM
architecture. This patch provides a wrapper into the common
clock framework so we can use the implementation in the
ARM architecture without duplicating the code until all
ARM platforms using this VCO are moved over. At that point
we can merge the driver from the ARM platform into the
generic file altogether.

Cc: Russell King <linux@arm.linux.org.uk>
Cc: Mike Turquette <mturquette@ti.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/clk/Kconfig    |    5 ++
 drivers/clk/Makefile   |    1 +
 drivers/clk/clk-icst.c |   99 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/clk-icst.h |   10 +++++
 4 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/clk-icst.c
 create mode 100644 drivers/clk/clk-icst.h

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 4864407..32e745e 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -34,4 +34,9 @@ config COMMON_CLK_DEBUG
 	  clk_flags, clk_prepare_count, clk_enable_count &
 	  clk_notifier_count.
 
+config CLK_ICST
+	bool "ICST307 VCO clock driver"
+	depends on COMMON_CLK
+	depends on ICST
+
 endmenu
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index b9a5158..a7a7cf8 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_COMMON_CLK)	+= clk.o clk-fixed-rate.o clk-gate.o \
 # SoCs specific
 obj-$(CONFIG_ARCH_MXS)		+= mxs/
 obj-$(CONFIG_PLAT_SPEAR)	+= spear/
+obj-$(CONFIG_CLK_ICST)		+= clk-icst.o
diff --git a/drivers/clk/clk-icst.c b/drivers/clk/clk-icst.c
new file mode 100644
index 0000000..ba003de
--- /dev/null
+++ b/drivers/clk/clk-icst.c
@@ -0,0 +1,99 @@
+/*
+ * Driver for the ICST307 VCO clock found in the ARM Reference designs.
+ * We wrap the custom interface from <asm/hardware/icst.h> into the generic
+ * clock framework.
+ *
+ * TODO: when all ARM reference designs are migrated to generic clocks, the
+ * ICST clock code from the ARM tree should probably be merged into this
+ * file.
+ */
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/err.h>
+#include <linux/clk-provider.h>
+
+#include "clk-icst.h"
+
+/**
+ * struct clk_icst - ICST VCO clock wrapper
+ * @hw: corresponding clock hardware entry
+ * @params: parameters for this ICST instance
+ * @rate: current rate
+ * @setvco: function to commit ICST settings to hardware
+ */
+struct clk_icst {
+	struct clk_hw hw;
+	const struct icst_params *params;
+	unsigned long rate;
+	struct icst_vco (*getvco)(void);
+	void (*setvco)(struct icst_vco);
+};
+
+#define to_icst(_hw) container_of(_hw, struct clk_icst, hw)
+
+static unsigned long icst_recalc_rate(struct clk_hw *hw,
+				      unsigned long parent_rate)
+{
+	struct clk_icst *icst = to_icst(hw);
+	struct icst_vco vco;
+
+	vco = icst->getvco();
+	icst->rate = icst_hz(icst->params, vco);
+	return icst->rate;
+}
+
+static long icst_round_rate(struct clk_hw *hw, unsigned long rate,
+			    unsigned long *prate)
+{
+	struct clk_icst *icst = to_icst(hw);
+	struct icst_vco vco;
+
+	vco = icst_hz_to_vco(icst->params, rate);
+	return icst_hz(icst->params, vco);
+}
+
+static int icst_set_rate(struct clk_hw *hw, unsigned long rate,
+			 unsigned long parent_rate)
+{
+	struct clk_icst *icst = to_icst(hw);
+	struct icst_vco vco;
+
+	vco = icst_hz_to_vco(icst->params, rate);
+	icst->rate = icst_hz(icst->params, vco);
+	icst->setvco(vco);
+	return 0;
+}
+
+static const struct clk_ops icst_ops = {
+	.recalc_rate = icst_recalc_rate,
+	.round_rate = icst_round_rate,
+	.set_rate = icst_set_rate,
+};
+
+struct clk * __init icst_clk_init(struct device *dev, const struct clk_icst_desc *desc)
+{
+	struct clk *clk;
+	struct clk_icst *icst;
+	struct clk_init_data init;
+
+	icst = kzalloc(sizeof(struct clk_icst), GFP_KERNEL);
+	if (!icst) {
+		pr_err("could not allocate ICST clock!\n");
+		return ERR_PTR(-ENOMEM);
+	}
+	init.name = "icst";
+	init.ops = &icst_ops;
+	init.flags = CLK_IS_ROOT;
+	init.parent_names = NULL;
+	init.num_parents = 0;
+	icst->hw.init = &init;
+	icst->params = desc->params;
+	icst->getvco = desc->getvco;
+	icst->setvco = desc->setvco;
+
+	clk = clk_register(dev, &icst->hw);
+	if (IS_ERR(clk))
+		kfree(icst);
+
+	return clk;
+}
diff --git a/drivers/clk/clk-icst.h b/drivers/clk/clk-icst.h
new file mode 100644
index 0000000..1deaa86
--- /dev/null
+++ b/drivers/clk/clk-icst.h
@@ -0,0 +1,10 @@
+#include <asm/hardware/icst.h>
+
+struct clk_icst_desc {
+	const struct icst_params *params;
+	struct icst_vco (*getvco)(void);
+	void (*setvco)(struct icst_vco);
+};
+
+struct clk *icst_clk_init(struct device *dev,
+			  const struct clk_icst_desc *desc);
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] clk: add ICST307 driver
@ 2012-06-11 15:39 ` Linus Walleij
  0 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2012-06-11 15:39 UTC (permalink / raw)
  To: linux-arm-kernel

The ICST307 VCO clock has a shared driver in the ARM
architecture. This patch provides a wrapper into the common
clock framework so we can use the implementation in the
ARM architecture without duplicating the code until all
ARM platforms using this VCO are moved over. At that point
we can merge the driver from the ARM platform into the
generic file altogether.

Cc: Russell King <linux@arm.linux.org.uk>
Cc: Mike Turquette <mturquette@ti.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/clk/Kconfig    |    5 ++
 drivers/clk/Makefile   |    1 +
 drivers/clk/clk-icst.c |   99 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/clk-icst.h |   10 +++++
 4 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/clk-icst.c
 create mode 100644 drivers/clk/clk-icst.h

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 4864407..32e745e 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -34,4 +34,9 @@ config COMMON_CLK_DEBUG
 	  clk_flags, clk_prepare_count, clk_enable_count &
 	  clk_notifier_count.
 
+config CLK_ICST
+	bool "ICST307 VCO clock driver"
+	depends on COMMON_CLK
+	depends on ICST
+
 endmenu
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index b9a5158..a7a7cf8 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_COMMON_CLK)	+= clk.o clk-fixed-rate.o clk-gate.o \
 # SoCs specific
 obj-$(CONFIG_ARCH_MXS)		+= mxs/
 obj-$(CONFIG_PLAT_SPEAR)	+= spear/
+obj-$(CONFIG_CLK_ICST)		+= clk-icst.o
diff --git a/drivers/clk/clk-icst.c b/drivers/clk/clk-icst.c
new file mode 100644
index 0000000..ba003de
--- /dev/null
+++ b/drivers/clk/clk-icst.c
@@ -0,0 +1,99 @@
+/*
+ * Driver for the ICST307 VCO clock found in the ARM Reference designs.
+ * We wrap the custom interface from <asm/hardware/icst.h> into the generic
+ * clock framework.
+ *
+ * TODO: when all ARM reference designs are migrated to generic clocks, the
+ * ICST clock code from the ARM tree should probably be merged into this
+ * file.
+ */
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/err.h>
+#include <linux/clk-provider.h>
+
+#include "clk-icst.h"
+
+/**
+ * struct clk_icst - ICST VCO clock wrapper
+ * @hw: corresponding clock hardware entry
+ * @params: parameters for this ICST instance
+ * @rate: current rate
+ * @setvco: function to commit ICST settings to hardware
+ */
+struct clk_icst {
+	struct clk_hw hw;
+	const struct icst_params *params;
+	unsigned long rate;
+	struct icst_vco (*getvco)(void);
+	void (*setvco)(struct icst_vco);
+};
+
+#define to_icst(_hw) container_of(_hw, struct clk_icst, hw)
+
+static unsigned long icst_recalc_rate(struct clk_hw *hw,
+				      unsigned long parent_rate)
+{
+	struct clk_icst *icst = to_icst(hw);
+	struct icst_vco vco;
+
+	vco = icst->getvco();
+	icst->rate = icst_hz(icst->params, vco);
+	return icst->rate;
+}
+
+static long icst_round_rate(struct clk_hw *hw, unsigned long rate,
+			    unsigned long *prate)
+{
+	struct clk_icst *icst = to_icst(hw);
+	struct icst_vco vco;
+
+	vco = icst_hz_to_vco(icst->params, rate);
+	return icst_hz(icst->params, vco);
+}
+
+static int icst_set_rate(struct clk_hw *hw, unsigned long rate,
+			 unsigned long parent_rate)
+{
+	struct clk_icst *icst = to_icst(hw);
+	struct icst_vco vco;
+
+	vco = icst_hz_to_vco(icst->params, rate);
+	icst->rate = icst_hz(icst->params, vco);
+	icst->setvco(vco);
+	return 0;
+}
+
+static const struct clk_ops icst_ops = {
+	.recalc_rate = icst_recalc_rate,
+	.round_rate = icst_round_rate,
+	.set_rate = icst_set_rate,
+};
+
+struct clk * __init icst_clk_init(struct device *dev, const struct clk_icst_desc *desc)
+{
+	struct clk *clk;
+	struct clk_icst *icst;
+	struct clk_init_data init;
+
+	icst = kzalloc(sizeof(struct clk_icst), GFP_KERNEL);
+	if (!icst) {
+		pr_err("could not allocate ICST clock!\n");
+		return ERR_PTR(-ENOMEM);
+	}
+	init.name = "icst";
+	init.ops = &icst_ops;
+	init.flags = CLK_IS_ROOT;
+	init.parent_names = NULL;
+	init.num_parents = 0;
+	icst->hw.init = &init;
+	icst->params = desc->params;
+	icst->getvco = desc->getvco;
+	icst->setvco = desc->setvco;
+
+	clk = clk_register(dev, &icst->hw);
+	if (IS_ERR(clk))
+		kfree(icst);
+
+	return clk;
+}
diff --git a/drivers/clk/clk-icst.h b/drivers/clk/clk-icst.h
new file mode 100644
index 0000000..1deaa86
--- /dev/null
+++ b/drivers/clk/clk-icst.h
@@ -0,0 +1,10 @@
+#include <asm/hardware/icst.h>
+
+struct clk_icst_desc {
+	const struct icst_params *params;
+	struct icst_vco (*getvco)(void);
+	void (*setvco)(struct icst_vco);
+};
+
+struct clk *icst_clk_init(struct device *dev,
+			  const struct clk_icst_desc *desc);
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] clk: add ICST307 driver
  2012-06-11 15:39 ` Linus Walleij
@ 2012-06-12 23:06   ` Mike Turquette
  -1 siblings, 0 replies; 8+ messages in thread
From: Mike Turquette @ 2012-06-12 23:06 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-arm-kernel, arm, linux-kernel, Russell King

On 20120611-17:39, Linus Walleij wrote:
> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> index b9a5158..a7a7cf8 100644
> --- a/drivers/clk/Makefile
> +++ b/drivers/clk/Makefile
> @@ -5,3 +5,4 @@ obj-$(CONFIG_COMMON_CLK)	+= clk.o clk-fixed-rate.o clk-gate.o \
>  # SoCs specific
>  obj-$(CONFIG_ARCH_MXS)		+= mxs/
>  obj-$(CONFIG_PLAT_SPEAR)	+= spear/
> +obj-$(CONFIG_CLK_ICST)		+= clk-icst.o

Is there a better place to put this than the top-level directory?

> +struct clk * __init icst_clk_init(struct device *dev, const struct clk_icst_desc *desc)

Nitpick: icst_clk_init should be renamed icst_clk_register to more
closely resemble other clock registration functions which allocate
memory dynamically.

So far the "_init" suffix has been used by functions which operate on
statically initialized data.

Regards,
Mike

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/3] clk: add ICST307 driver
@ 2012-06-12 23:06   ` Mike Turquette
  0 siblings, 0 replies; 8+ messages in thread
From: Mike Turquette @ 2012-06-12 23:06 UTC (permalink / raw)
  To: linux-arm-kernel

On 20120611-17:39, Linus Walleij wrote:
> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> index b9a5158..a7a7cf8 100644
> --- a/drivers/clk/Makefile
> +++ b/drivers/clk/Makefile
> @@ -5,3 +5,4 @@ obj-$(CONFIG_COMMON_CLK)	+= clk.o clk-fixed-rate.o clk-gate.o \
>  # SoCs specific
>  obj-$(CONFIG_ARCH_MXS)		+= mxs/
>  obj-$(CONFIG_PLAT_SPEAR)	+= spear/
> +obj-$(CONFIG_CLK_ICST)		+= clk-icst.o

Is there a better place to put this than the top-level directory?

> +struct clk * __init icst_clk_init(struct device *dev, const struct clk_icst_desc *desc)

Nitpick: icst_clk_init should be renamed icst_clk_register to more
closely resemble other clock registration functions which allocate
memory dynamically.

So far the "_init" suffix has been used by functions which operate on
statically initialized data.

Regards,
Mike

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] clk: add ICST307 driver
  2012-06-12 23:06   ` Mike Turquette
@ 2012-06-13  8:38     ` Linus Walleij
  -1 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2012-06-13  8:38 UTC (permalink / raw)
  To: Mike Turquette; +Cc: linux-arm-kernel, arm, linux-kernel, Russell King

On Wed, Jun 13, 2012 at 1:06 AM, Mike Turquette <mturquette@ti.com> wrote:
> On 20120611-17:39, Linus Walleij wrote:

>> +obj-$(CONFIG_CLK_ICST)               += clk-icst.o
>
> Is there a better place to put this than the top-level directory?

I can put it alone in a subdirectory if you want to... It is used only
by the ARM reference designs AFAICT, shall I put these Integrator
things into clk/versatile as we use the "versatile" name to refer to all
ARM reference designs (i.e. arch/arm/plat-versatile).

>> +struct clk * __init icst_clk_init(struct device *dev, const struct clk_icst_desc *desc)
>
> Nitpick: icst_clk_init should be renamed icst_clk_register to more
> closely resemble other clock registration functions which allocate
> memory dynamically.

I'll fix!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/3] clk: add ICST307 driver
@ 2012-06-13  8:38     ` Linus Walleij
  0 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2012-06-13  8:38 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Jun 13, 2012 at 1:06 AM, Mike Turquette <mturquette@ti.com> wrote:
> On 20120611-17:39, Linus Walleij wrote:

>> +obj-$(CONFIG_CLK_ICST) ? ? ? ? ? ? ? += clk-icst.o
>
> Is there a better place to put this than the top-level directory?

I can put it alone in a subdirectory if you want to... It is used only
by the ARM reference designs AFAICT, shall I put these Integrator
things into clk/versatile as we use the "versatile" name to refer to all
ARM reference designs (i.e. arch/arm/plat-versatile).

>> +struct clk * __init icst_clk_init(struct device *dev, const struct clk_icst_desc *desc)
>
> Nitpick: icst_clk_init should be renamed icst_clk_register to more
> closely resemble other clock registration functions which allocate
> memory dynamically.

I'll fix!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] clk: add ICST307 driver
  2012-06-13  8:38     ` Linus Walleij
@ 2012-06-13 14:42       ` Turquette, Mike
  -1 siblings, 0 replies; 8+ messages in thread
From: Turquette, Mike @ 2012-06-13 14:42 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-arm-kernel, arm, linux-kernel, Russell King

On Wed, Jun 13, 2012 at 1:38 AM, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Wed, Jun 13, 2012 at 1:06 AM, Mike Turquette <mturquette@ti.com> wrote:
>> On 20120611-17:39, Linus Walleij wrote:
>
>>> +obj-$(CONFIG_CLK_ICST)               += clk-icst.o
>>
>> Is there a better place to put this than the top-level directory?
>
> I can put it alone in a subdirectory if you want to... It is used only
> by the ARM reference designs AFAICT, shall I put these Integrator
> things into clk/versatile as we use the "versatile" name to refer to all
> ARM reference designs (i.e. arch/arm/plat-versatile).
>

drivers/clk/versatile seems sensible.  I am just trying to prevent
drivers/clk/ becoming very messy.  If other platforms are going to use
this code then the top-level location makes sense, otherwise lets use
drivers/clk/versatile.

>>> +struct clk * __init icst_clk_init(struct device *dev, const struct clk_icst_desc *desc)
>>
>> Nitpick: icst_clk_init should be renamed icst_clk_register to more
>> closely resemble other clock registration functions which allocate
>> memory dynamically.
>
> I'll fix!
>

Thanks!
Mike

> Yours,
> Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/3] clk: add ICST307 driver
@ 2012-06-13 14:42       ` Turquette, Mike
  0 siblings, 0 replies; 8+ messages in thread
From: Turquette, Mike @ 2012-06-13 14:42 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Jun 13, 2012 at 1:38 AM, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Wed, Jun 13, 2012 at 1:06 AM, Mike Turquette <mturquette@ti.com> wrote:
>> On 20120611-17:39, Linus Walleij wrote:
>
>>> +obj-$(CONFIG_CLK_ICST) ? ? ? ? ? ? ? += clk-icst.o
>>
>> Is there a better place to put this than the top-level directory?
>
> I can put it alone in a subdirectory if you want to... It is used only
> by the ARM reference designs AFAICT, shall I put these Integrator
> things into clk/versatile as we use the "versatile" name to refer to all
> ARM reference designs (i.e. arch/arm/plat-versatile).
>

drivers/clk/versatile seems sensible.  I am just trying to prevent
drivers/clk/ becoming very messy.  If other platforms are going to use
this code then the top-level location makes sense, otherwise lets use
drivers/clk/versatile.

>>> +struct clk * __init icst_clk_init(struct device *dev, const struct clk_icst_desc *desc)
>>
>> Nitpick: icst_clk_init should be renamed icst_clk_register to more
>> closely resemble other clock registration functions which allocate
>> memory dynamically.
>
> I'll fix!
>

Thanks!
Mike

> Yours,
> Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-06-13 14:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-11 15:39 [PATCH 2/3] clk: add ICST307 driver Linus Walleij
2012-06-11 15:39 ` Linus Walleij
2012-06-12 23:06 ` Mike Turquette
2012-06-12 23:06   ` Mike Turquette
2012-06-13  8:38   ` Linus Walleij
2012-06-13  8:38     ` Linus Walleij
2012-06-13 14:42     ` Turquette, Mike
2012-06-13 14:42       ` Turquette, Mike

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.