diff mbox

[v6,1/2] clk: shmobile: r8a7779: Add clocks support

Message ID 1397775951-30992-2-git-send-email-horms+renesas@verge.net.au
State Superseded, archived
Headers show

Commit Message

Simon Horman April 17, 2014, 11:05 p.m. UTC
The R8A7779 SoC has several clocks that are too custom to be supported in a
generic driver. Those clocks are all fixed rate clocks with multiplier and
divisor set according to boot mode configuration.

Based on work for R-Car Gen2 SoCs by Laurent Pinchart.

Cc: devicetree@vger.kernel.org
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>

---

v6
* Added Ack from Laurent Pinchart

v5
* Rebase
* As suggested by Laurent Pinchart
  - Do not print an error if kzalloc() fails,
    kzalloc() will print OOM message to the kernel log in such cases
v4
* As suggested by Geert Uytterhoeven
  - Remove double and from bindings documentation
  - Remove unused CPG_PLL_CONFIG_INDEX and struct cpg_pll_config
  - Correct order of cpg_clk_configs entries
* As suggested by Laurent Pinchart
  - Update copyright to include 2014
  - Remove reference to non-existent divider clocks in changelog
  - Do not map cpg->reg as it is not accessed
  - Return an error for unknown name values in r8a7779_cpg_register_clock()
  - Expose clkb in binding
  - Do not include MSPT registers in register range in binding example
* Write (BIT(2)|BIT(1)) instead of (BIT(1)|BIT(2)) as it is less confusing
  (to me)
v3
* As suggested by Laurent Pinchart
  - Added external clock input
  - Use PLLA ratio set bu MD11 and MD12
  - Add _div suffixes of fields of struct cpt_clk_config
  - Register PLLA as a fixed factor clock
  - Use sizeof() instead of sizeof
  - Use num_clks instead of CPG_NUM_CLOCKS in r8a7779_cpg_clocks_init()

  - I kept this as r8a7779 binding rather than moving to a R-Car Gen1
    binding which could be shared with other SoCs as I do not believe that
    the SoCs is are sufficiently similar.
---
 .../bindings/clock/renesas,r8a7779-cpg-clocks.txt  |  27 ++++
 drivers/clk/shmobile/Makefile                      |   1 +
 drivers/clk/shmobile/clk-r8a7779.c                 | 180 +++++++++++++++++++++
 include/linux/clk/shmobile.h                       |   3 +
 4 files changed, 211 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/renesas,r8a7779-cpg-clocks.txt
 create mode 100644 drivers/clk/shmobile/clk-r8a7779.c

Comments

Arnd Bergmann May 27, 2014, 9:31 a.m. UTC | #1
On Friday 18 April 2014, Simon Horman wrote:
> diff --git a/drivers/clk/shmobile/clk-r8a7779.c b/drivers/clk/shmobile/clk-r8a7779.c
> new file mode 100644
> index 0000000..652ecac
> --- /dev/null
> +++ b/drivers/clk/shmobile/clk-r8a7779.c
> @@ -0,0 +1,180 @@
> +/*
> + * r8a7779 Core CPG Clocks
> + *
> + * Copyright (C) 2013, 2014 Horms Solutions Ltd.
> + *
> + * Contact: Simon Horman <horms@verge.net.au>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; version 2 of the License.
> + */
> +
> +#include <linux/clk-provider.h>
> +#include <linux/clkdev.h>
> +#include <linux/clk/shmobile.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/spinlock.h>
> +
> +#include <dt-bindings/clock/r8a7779-clock.h>

This currently causes a build error in Linux-next, since the header file has not
been merged along with the driver.

	Arnd
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mike Turquette May 28, 2014, 1:32 a.m. UTC | #2
Quoting Simon Horman (2014-05-27 18:08:50)
> On Tue, May 27, 2014 at 11:31:42AM +0200, Arnd Bergmann wrote:
> > On Friday 18 April 2014, Simon Horman wrote:
> > > diff --git a/drivers/clk/shmobile/clk-r8a7779.c b/drivers/clk/shmobile/clk-r8a7779.c
> > > new file mode 100644
> > > index 0000000..652ecac
> > > --- /dev/null
> > > +++ b/drivers/clk/shmobile/clk-r8a7779.c
> > > @@ -0,0 +1,180 @@
> > > +/*
> > > + * r8a7779 Core CPG Clocks
> > > + *
> > > + * Copyright (C) 2013, 2014 Horms Solutions Ltd.
> > > + *
> > > + * Contact: Simon Horman <horms@verge.net.au>
> > > + *
> > > + * This program is free software; you can redistribute it and/or modify
> > > + * it under the terms of the GNU General Public License as published by
> > > + * the Free Software Foundation; version 2 of the License.
> > > + */
> > > +
> > > +#include <linux/clk-provider.h>
> > > +#include <linux/clkdev.h>
> > > +#include <linux/clk/shmobile.h>
> > > +#include <linux/init.h>
> > > +#include <linux/kernel.h>
> > > +#include <linux/of.h>
> > > +#include <linux/of_address.h>
> > > +#include <linux/spinlock.h>
> > > +
> > > +#include <dt-bindings/clock/r8a7779-clock.h>
> > 
> > This currently causes a build error in Linux-next, since the header file
> > has not been merged along with the driver.
> 
> Hi Arnd,
> 
> I'm a little unsure what combination of Kernel config options you
> are using to compile this driver in linux-next but I do agree
> that the header is missing and that would cause the compile to fail.
> I apologise for that oversight.
> 
> I believe that a good fix is to add the header, which I already have queued-up
> in the renesas tree for v3.17. I wonder if Mike would consider taking
> the following patch for v3.16. Alternatively I would be happy to send
> it it to arm-soc as a fix for v3.16.

I'm happy to take it for 3.16. I can't squash/rebase my tree so there
will still be the potential for bisect badness, but that's just the way
it goes.

Can you send the patch separately after testing it against the current
clk-next tree?

Thanks,
Mike

> 
> Naturally I will drop it from my v3.17 queue if it its accepted for v3.16
> one way or another.
> 
> From: Simon Horman <horms+renesas@verge.net.au>
> 
> [PATCH] ARM: shmobile: r8a7779: Add clock index macros for DT sources
> 
> Add macros usable by device tree sources to reference r8a7779 clocks by
> index.
> 
> Based on work for the r8a7791 SoC by Laurent Pinchart.
> 
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
> ---
>  include/dt-bindings/clock/r8a7779-clock.h | 64 +++++++++++++++++++++++++++++++
>  1 file changed, 64 insertions(+)
>  create mode 100644 include/dt-bindings/clock/r8a7779-clock.h
> 
> diff --git a/include/dt-bindings/clock/r8a7779-clock.h b/include/dt-bindings/clock/r8a7779-clock.h
> new file mode 100644
> index 0000000..381a611
> --- /dev/null
> +++ b/include/dt-bindings/clock/r8a7779-clock.h
> @@ -0,0 +1,64 @@
> +/*
> + * Copyright (C) 2013  Horms Solutions Ltd.
> + *
> + * Contact: Simon Horman <horms@verge.net.au>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + */
> +
> +#ifndef __DT_BINDINGS_CLOCK_R8A7779_H__
> +#define __DT_BINDINGS_CLOCK_R8A7779_H__
> +
> +/* CPG */
> +#define R8A7779_CLK_PLLA       0
> +#define R8A7779_CLK_Z          1
> +#define R8A7779_CLK_ZS         2
> +#define R8A7779_CLK_S          3
> +#define R8A7779_CLK_S1         4
> +#define R8A7779_CLK_P          5
> +#define R8A7779_CLK_B          6
> +#define R8A7779_CLK_OUT                7
> +
> +/* MSTP 0 */
> +#define R8A7779_CLK_HSPI       7
> +#define R8A7779_CLK_TMU2       14
> +#define R8A7779_CLK_TMU1       15
> +#define R8A7779_CLK_TMU0       16
> +#define R8A7779_CLK_HSCIF1     18
> +#define R8A7779_CLK_HSCIF0     19
> +#define R8A7779_CLK_SCIF5      21
> +#define R8A7779_CLK_SCIF4      22
> +#define R8A7779_CLK_SCIF3      23
> +#define R8A7779_CLK_SCIF2      24
> +#define R8A7779_CLK_SCIF1      25
> +#define R8A7779_CLK_SCIF0      26
> +#define R8A7779_CLK_I2C3       27
> +#define R8A7779_CLK_I2C2       28
> +#define R8A7779_CLK_I2C1       29
> +#define R8A7779_CLK_I2C0       30
> +
> +/* MSTP 1 */
> +#define R8A7779_CLK_USB01      0
> +#define R8A7779_CLK_USB2       1
> +#define R8A7779_CLK_DU         3
> +#define R8A7779_CLK_VIN2       8
> +#define R8A7779_CLK_VIN1       9
> +#define R8A7779_CLK_VIN0       10
> +#define R8A7779_CLK_ETHER      14
> +#define R8A7779_CLK_SATA       15
> +#define R8A7779_CLK_PCIE       16
> +#define R8A7779_CLK_VIN3       20
> +
> +/* MSTP 3 */
> +#define R8A7779_CLK_SDHI3      20
> +#define R8A7779_CLK_SDHI2      21
> +#define R8A7779_CLK_SDHI1      22
> +#define R8A7779_CLK_SDHI0      23
> +#define R8A7779_CLK_MMC1       30
> +#define R8A7779_CLK_MMC0       31
> +
> +
> +#endif /* __DT_BINDINGS_CLOCK_R8A7779_H__ */
> -- 
> 1.8.5.2
> 
> 
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Simon Horman May 28, 2014, 1:34 a.m. UTC | #3
On Tue, May 27, 2014 at 06:32:39PM -0700, Mike Turquette wrote:
> Quoting Simon Horman (2014-05-27 18:08:50)
> > On Tue, May 27, 2014 at 11:31:42AM +0200, Arnd Bergmann wrote:
> > > On Friday 18 April 2014, Simon Horman wrote:
> > > > diff --git a/drivers/clk/shmobile/clk-r8a7779.c b/drivers/clk/shmobile/clk-r8a7779.c
> > > > new file mode 100644
> > > > index 0000000..652ecac
> > > > --- /dev/null
> > > > +++ b/drivers/clk/shmobile/clk-r8a7779.c
> > > > @@ -0,0 +1,180 @@
> > > > +/*
> > > > + * r8a7779 Core CPG Clocks
> > > > + *
> > > > + * Copyright (C) 2013, 2014 Horms Solutions Ltd.
> > > > + *
> > > > + * Contact: Simon Horman <horms@verge.net.au>
> > > > + *
> > > > + * This program is free software; you can redistribute it and/or modify
> > > > + * it under the terms of the GNU General Public License as published by
> > > > + * the Free Software Foundation; version 2 of the License.
> > > > + */
> > > > +
> > > > +#include <linux/clk-provider.h>
> > > > +#include <linux/clkdev.h>
> > > > +#include <linux/clk/shmobile.h>
> > > > +#include <linux/init.h>
> > > > +#include <linux/kernel.h>
> > > > +#include <linux/of.h>
> > > > +#include <linux/of_address.h>
> > > > +#include <linux/spinlock.h>
> > > > +
> > > > +#include <dt-bindings/clock/r8a7779-clock.h>
> > > 
> > > This currently causes a build error in Linux-next, since the header file
> > > has not been merged along with the driver.
> > 
> > Hi Arnd,
> > 
> > I'm a little unsure what combination of Kernel config options you
> > are using to compile this driver in linux-next but I do agree
> > that the header is missing and that would cause the compile to fail.
> > I apologise for that oversight.
> > 
> > I believe that a good fix is to add the header, which I already have queued-up
> > in the renesas tree for v3.17. I wonder if Mike would consider taking
> > the following patch for v3.16. Alternatively I would be happy to send
> > it it to arm-soc as a fix for v3.16.
> 
> I'm happy to take it for 3.16. I can't squash/rebase my tree so there
> will still be the potential for bisect badness, but that's just the way
> it goes.
> 
> Can you send the patch separately after testing it against the current
> clk-next tree?

Sure, will do.

> Thanks,
> Mike
> 
> > 
> > Naturally I will drop it from my v3.17 queue if it its accepted for v3.16
> > one way or another.
> > 
> > From: Simon Horman <horms+renesas@verge.net.au>
> > 
> > [PATCH] ARM: shmobile: r8a7779: Add clock index macros for DT sources
> > 
> > Add macros usable by device tree sources to reference r8a7779 clocks by
> > index.
> > 
> > Based on work for the r8a7791 SoC by Laurent Pinchart.
> > 
> > Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
> > ---
> >  include/dt-bindings/clock/r8a7779-clock.h | 64 +++++++++++++++++++++++++++++++
> >  1 file changed, 64 insertions(+)
> >  create mode 100644 include/dt-bindings/clock/r8a7779-clock.h
> > 
> > diff --git a/include/dt-bindings/clock/r8a7779-clock.h b/include/dt-bindings/clock/r8a7779-clock.h
> > new file mode 100644
> > index 0000000..381a611
> > --- /dev/null
> > +++ b/include/dt-bindings/clock/r8a7779-clock.h
> > @@ -0,0 +1,64 @@
> > +/*
> > + * Copyright (C) 2013  Horms Solutions Ltd.
> > + *
> > + * Contact: Simon Horman <horms@verge.net.au>
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License as published by
> > + * the Free Software Foundation; either version 2 of the License, or
> > + * (at your option) any later version.
> > + */
> > +
> > +#ifndef __DT_BINDINGS_CLOCK_R8A7779_H__
> > +#define __DT_BINDINGS_CLOCK_R8A7779_H__
> > +
> > +/* CPG */
> > +#define R8A7779_CLK_PLLA       0
> > +#define R8A7779_CLK_Z          1
> > +#define R8A7779_CLK_ZS         2
> > +#define R8A7779_CLK_S          3
> > +#define R8A7779_CLK_S1         4
> > +#define R8A7779_CLK_P          5
> > +#define R8A7779_CLK_B          6
> > +#define R8A7779_CLK_OUT                7
> > +
> > +/* MSTP 0 */
> > +#define R8A7779_CLK_HSPI       7
> > +#define R8A7779_CLK_TMU2       14
> > +#define R8A7779_CLK_TMU1       15
> > +#define R8A7779_CLK_TMU0       16
> > +#define R8A7779_CLK_HSCIF1     18
> > +#define R8A7779_CLK_HSCIF0     19
> > +#define R8A7779_CLK_SCIF5      21
> > +#define R8A7779_CLK_SCIF4      22
> > +#define R8A7779_CLK_SCIF3      23
> > +#define R8A7779_CLK_SCIF2      24
> > +#define R8A7779_CLK_SCIF1      25
> > +#define R8A7779_CLK_SCIF0      26
> > +#define R8A7779_CLK_I2C3       27
> > +#define R8A7779_CLK_I2C2       28
> > +#define R8A7779_CLK_I2C1       29
> > +#define R8A7779_CLK_I2C0       30
> > +
> > +/* MSTP 1 */
> > +#define R8A7779_CLK_USB01      0
> > +#define R8A7779_CLK_USB2       1
> > +#define R8A7779_CLK_DU         3
> > +#define R8A7779_CLK_VIN2       8
> > +#define R8A7779_CLK_VIN1       9
> > +#define R8A7779_CLK_VIN0       10
> > +#define R8A7779_CLK_ETHER      14
> > +#define R8A7779_CLK_SATA       15
> > +#define R8A7779_CLK_PCIE       16
> > +#define R8A7779_CLK_VIN3       20
> > +
> > +/* MSTP 3 */
> > +#define R8A7779_CLK_SDHI3      20
> > +#define R8A7779_CLK_SDHI2      21
> > +#define R8A7779_CLK_SDHI1      22
> > +#define R8A7779_CLK_SDHI0      23
> > +#define R8A7779_CLK_MMC1       30
> > +#define R8A7779_CLK_MMC0       31
> > +
> > +
> > +#endif /* __DT_BINDINGS_CLOCK_R8A7779_H__ */
> > -- 
> > 1.8.5.2
> > 
> > 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sh" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Geert Uytterhoeven May 28, 2014, 8:42 a.m. UTC | #4
Hi Simon,

On Wed, May 28, 2014 at 3:08 AM, Simon Horman <horms@verge.net.au> wrote:
>> > +#include <dt-bindings/clock/r8a7779-clock.h>
>>
>> This currently causes a build error in Linux-next, since the header file
>> has not been merged along with the driver.
>
> Hi Arnd,
>
> I'm a little unsure what combination of Kernel config options you
> are using to compile this driver in linux-next but I do agree
> that the header is missing and that would cause the compile to fail.
> I apologise for that oversight.
>
> I believe that a good fix is to add the header, which I already have queued-up
> in the renesas tree for v3.17. I wonder if Mike would consider taking
> the following patch for v3.16. Alternatively I would be happy to send
> it it to arm-soc as a fix for v3.16.

IIUIC, the only reason the driver source needs the header file is:

#define CPG_NUM_CLOCKS                  (R8A7779_CLK_OUT + 1)

Why not

#define CPG_NUM_CLOCKS                  8

and drop the include?

Or better, use "num_clks" (from of_property_count_strings(np,
"clock-output-names")), like the other R-Car drivers do.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Simon Horman May 28, 2014, 8:50 a.m. UTC | #5
On Wed, May 28, 2014 at 10:42:05AM +0200, Geert Uytterhoeven wrote:
> Hi Simon,
> 
> On Wed, May 28, 2014 at 3:08 AM, Simon Horman <horms@verge.net.au> wrote:
> >> > +#include <dt-bindings/clock/r8a7779-clock.h>
> >>
> >> This currently causes a build error in Linux-next, since the header file
> >> has not been merged along with the driver.
> >
> > Hi Arnd,
> >
> > I'm a little unsure what combination of Kernel config options you
> > are using to compile this driver in linux-next but I do agree
> > that the header is missing and that would cause the compile to fail.
> > I apologise for that oversight.
> >
> > I believe that a good fix is to add the header, which I already have queued-up
> > in the renesas tree for v3.17. I wonder if Mike would consider taking
> > the following patch for v3.16. Alternatively I would be happy to send
> > it it to arm-soc as a fix for v3.16.
> 
> IIUIC, the only reason the driver source needs the header file is:
> 
> #define CPG_NUM_CLOCKS                  (R8A7779_CLK_OUT + 1)
> 
> Why not
> 
> #define CPG_NUM_CLOCKS                  8
> 
> and drop the include?
> 
> Or better, use "num_clks" (from of_property_count_strings(np,
> "clock-output-names")), like the other R-Car drivers do.

The latter I like. But I don't see any harm in fixing
the immediate problem using a patch that has already been reviewed.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/clock/renesas,r8a7779-cpg-clocks.txt b/Documentation/devicetree/bindings/clock/renesas,r8a7779-cpg-clocks.txt
new file mode 100644
index 0000000..ed3c8cb
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/renesas,r8a7779-cpg-clocks.txt
@@ -0,0 +1,27 @@ 
+* Renesas R8A7779 Clock Pulse Generator (CPG)
+
+The CPG generates core clocks for the R8A7779. It includes one PLL and
+several fixed ratio dividers
+
+Required Properties:
+
+  - compatible: Must be "renesas,r8a7779-cpg-clocks"
+  - reg: Base address and length of the memory resource used by the CPG
+
+  - clocks: Reference to the parent clock
+  - #clock-cells: Must be 1
+  - clock-output-names: The names of the clocks. Supported clocks are "plla",
+    "z", "zs", "s", "s1", "p", "b", "out".
+
+
+Example
+-------
+
+	cpg_clocks: cpg_clocks@ffc80000 {
+		compatible = "renesas,r8a7779-cpg-clocks";
+		reg = <0 0xffc80000 0 0x30>;
+		clocks = <&extal_clk>;
+		#clock-cells = <1>;
+		clock-output-names = "plla", "z", "zs", "s", "s1", "p",
+		                     "b", "out";
+	};
diff --git a/drivers/clk/shmobile/Makefile b/drivers/clk/shmobile/Makefile
index 5404cb9..bdf342d 100644
--- a/drivers/clk/shmobile/Makefile
+++ b/drivers/clk/shmobile/Makefile
@@ -1,5 +1,6 @@ 
 obj-$(CONFIG_ARCH_EMEV2)		+= clk-emev2.o
 obj-$(CONFIG_ARCH_R7S72100)		+= clk-rz.o
+obj-$(CONFIG_ARCH_R8A7779)		+= clk-r8a7779.o
 obj-$(CONFIG_ARCH_R8A7790)		+= clk-rcar-gen2.o
 obj-$(CONFIG_ARCH_R8A7791)		+= clk-rcar-gen2.o
 obj-$(CONFIG_ARCH_SHMOBILE_MULTI)	+= clk-div6.o
diff --git a/drivers/clk/shmobile/clk-r8a7779.c b/drivers/clk/shmobile/clk-r8a7779.c
new file mode 100644
index 0000000..652ecac
--- /dev/null
+++ b/drivers/clk/shmobile/clk-r8a7779.c
@@ -0,0 +1,180 @@ 
+/*
+ * r8a7779 Core CPG Clocks
+ *
+ * Copyright (C) 2013, 2014 Horms Solutions Ltd.
+ *
+ * Contact: Simon Horman <horms@verge.net.au>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/clkdev.h>
+#include <linux/clk/shmobile.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/spinlock.h>
+
+#include <dt-bindings/clock/r8a7779-clock.h>
+
+#define CPG_NUM_CLOCKS			(R8A7779_CLK_OUT + 1)
+
+struct r8a7779_cpg {
+	struct clk_onecell_data data;
+	spinlock_t lock;
+	void __iomem *reg;
+};
+
+/* -----------------------------------------------------------------------------
+ * CPG Clock Data
+ */
+
+/*
+ *		MD1 = 1			MD1 = 0
+ *		(PLLA = 1500)		(PLLA = 1600)
+ *		(MHz)			(MHz)
+ *------------------------------------------------+--------------------
+ * clkz		1000   (2/3)		800   (1/2)
+ * clkzs	 250   (1/6)		200   (1/8)
+ * clki		 750   (1/2)		800   (1/2)
+ * clks		 250   (1/6)		200   (1/8)
+ * clks1	 125   (1/12)		100   (1/16)
+ * clks3	 187.5 (1/8)		200   (1/8)
+ * clks4	  93.7 (1/16)		100   (1/16)
+ * clkp		  62.5 (1/24)		 50   (1/32)
+ * clkg		  62.5 (1/24)		 66.6 (1/24)
+ * clkb, CLKOUT
+ * (MD2 = 0)	  62.5 (1/24)		 66.6 (1/24)
+ * (MD2 = 1)	  41.6 (1/36)		 50   (1/32)
+ */
+
+#define CPG_CLK_CONFIG_INDEX(md)	(((md) & (BIT(2)|BIT(1))) >> 1)
+
+struct cpg_clk_config {
+	unsigned int z_mult;
+	unsigned int z_div;
+	unsigned int zs_and_s_div;
+	unsigned int s1_div;
+	unsigned int p_div;
+	unsigned int b_and_out_div;
+};
+
+static const struct cpg_clk_config cpg_clk_configs[4] __initconst = {
+	{ 1, 2, 8, 16, 32, 24 },
+	{ 2, 3, 6, 12, 24, 24 },
+	{ 1, 2, 8, 16, 32, 32 },
+	{ 2, 3, 6, 12, 24, 36 },
+};
+
+/*
+ *   MD		PLLA Ratio
+ * 12 11
+ *------------------------
+ * 0  0		x42
+ * 0  1		x48
+ * 1  0		x56
+ * 1  1		x64
+ */
+
+#define CPG_PLLA_MULT_INDEX(md)	(((md) & (BIT(12)|BIT(11))) >> 11)
+
+static const unsigned int cpg_plla_mult[4] __initconst = { 42, 48, 56, 64 };
+
+/* -----------------------------------------------------------------------------
+ * Initialization
+ */
+
+static u32 cpg_mode __initdata;
+
+static struct clk * __init
+r8a7779_cpg_register_clock(struct device_node *np, struct r8a7779_cpg *cpg,
+			   const struct cpg_clk_config *config,
+			   unsigned int plla_mult, const char *name)
+{
+	const char *parent_name = "plla";
+	unsigned int mult = 1;
+	unsigned int div = 1;
+
+	if (!strcmp(name, "plla")) {
+		parent_name = of_clk_get_parent_name(np, 0);
+		mult = plla_mult;
+	} else if (!strcmp(name, "z")) {
+		div = config->z_div;
+		mult = config->z_mult;
+	} else if (!strcmp(name, "zs") || !strcmp(name, "s")) {
+		div = config->zs_and_s_div;
+	} else if (!strcmp(name, "s1")) {
+		div = config->s1_div;
+	} else if (!strcmp(name, "p")) {
+		div = config->p_div;
+	} else if (!strcmp(name, "b") || !strcmp(name, "out")) {
+		div = config->b_and_out_div;
+	} else {
+		return ERR_PTR(-EINVAL);
+	}
+
+	return clk_register_fixed_factor(NULL, name, parent_name, 0, mult, div);
+}
+
+static void __init r8a7779_cpg_clocks_init(struct device_node *np)
+{
+	const struct cpg_clk_config *config;
+	struct r8a7779_cpg *cpg;
+	struct clk **clks;
+	unsigned int i, plla_mult;
+	int num_clks;
+
+	num_clks = of_property_count_strings(np, "clock-output-names");
+	if (num_clks < 0) {
+		pr_err("%s: failed to count clocks\n", __func__);
+		return;
+	}
+
+	cpg = kzalloc(sizeof(*cpg), GFP_KERNEL);
+	clks = kzalloc(CPG_NUM_CLOCKS * sizeof(*clks), GFP_KERNEL);
+	if (cpg == NULL || clks == NULL) {
+		/* We're leaking memory on purpose, there's no point in cleaning
+		 * up as the system won't boot anyway.
+		 */
+		return;
+	}
+
+	spin_lock_init(&cpg->lock);
+
+	cpg->data.clks = clks;
+	cpg->data.clk_num = num_clks;
+
+	config = &cpg_clk_configs[CPG_CLK_CONFIG_INDEX(cpg_mode)];
+	plla_mult = cpg_plla_mult[CPG_PLLA_MULT_INDEX(cpg_mode)];
+
+	for (i = 0; i < num_clks; ++i) {
+		const char *name;
+		struct clk *clk;
+
+		of_property_read_string_index(np, "clock-output-names", i,
+					      &name);
+
+		clk = r8a7779_cpg_register_clock(np, cpg, config,
+						 plla_mult, name);
+		if (IS_ERR(clk))
+			pr_err("%s: failed to register %s %s clock (%ld)\n",
+			       __func__, np->name, name, PTR_ERR(clk));
+		else
+			cpg->data.clks[i] = clk;
+	}
+
+	of_clk_add_provider(np, of_clk_src_onecell_get, &cpg->data);
+}
+CLK_OF_DECLARE(r8a7779_cpg_clks, "renesas,r8a7779-cpg-clocks",
+	       r8a7779_cpg_clocks_init);
+
+void __init r8a7779_clocks_init(u32 mode)
+{
+	cpg_mode = mode;
+
+	of_clk_init(NULL);
+}
diff --git a/include/linux/clk/shmobile.h b/include/linux/clk/shmobile.h
index f9bf080..9f8a140 100644
--- a/include/linux/clk/shmobile.h
+++ b/include/linux/clk/shmobile.h
@@ -1,7 +1,9 @@ 
 /*
  * Copyright 2013 Ideas On Board SPRL
+ * Copyright 2013, 2014 Horms Solutions Ltd.
  *
  * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ * Contact: Simon Horman <horms@verge.net.au>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -14,6 +16,7 @@ 
 
 #include <linux/types.h>
 
+void r8a7779_clocks_init(u32 mode);
 void rcar_gen2_clocks_init(u32 mode);
 
 #endif