Skip to contentSkip to conversation

common clk support for mxs

PATCH New Shawn Guo 4 participants 22 messages Apr 21, 2012 – Apr 25, 2012

Subsystems (4)
lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

cover common clk support for mxs

The mxs clock porting to common clk framework has been ready for a while. I was planning to post it after Mike's -next branch is published. Since the ETA of the branch is still uncertain while the series needs to take some time to go through the review process, I can not hold it for any longer, so here it is.

It's based on v3.4-rc3 plus various fixup/cleanup patches that Mike confirmed pick-up on his -next branch and the clkdev one below.

CLKDEV: Add helper routines to allocate and add clkdevs for given struct clk *

The series originally kept the code in arch/arm/mach-mxs. With Arnd's comment taken, I reworked it a bit to put it into drivers/clk/mxs in the same way that spear clock moves.

Shawn Guo (8):
clk: mxs: add mxs specific clocks
clk: mxs: add clock support for imx23
clk: mxs: add clock support for imx28
ARM: mxs: request clock for timer
ARM: mxs: change the lookup name for fec phy clock
ARM: mxs: switch to common clk framework
ARM: mxs: remove old clock support
ARM: mxs: remove now unused timer_clk argument from mxs_timer_init

 arch/arm/Kconfig                        |    1 +
 arch/arm/mach-mxs/Makefile              |    5 +-
 arch/arm/mach-mxs/clock-mx23.c          |  536 ---------------------
 arch/arm/mach-mxs/clock-mx28.c          |  803 -------------------------------
 arch/arm/mach-mxs/clock.c               |  211 --------
 arch/arm/mach-mxs/include/mach/clock.h  |   62 ---
 arch/arm/mach-mxs/include/mach/common.h |    6 +-
 arch/arm/mach-mxs/mach-mx28evk.c        |    2 +-
 arch/arm/mach-mxs/regs-clkctrl-mx23.h   |  331 -------------
 arch/arm/mach-mxs/regs-clkctrl-mx28.h   |  486 -------------------
 arch/arm/mach-mxs/system.c              |   16 -
 arch/arm/mach-mxs/timer.c               |   11 +-
 drivers/clk/Makefile                    |    2 +
 drivers/clk/mxs/Makefile                |    8 +
 drivers/clk/mxs/clk-div.c               |  102 ++++
 drivers/clk/mxs/clk-frac.c              |  127 +++++
 drivers/clk/mxs/clk-imx23.c             |  195 ++++++++
 drivers/clk/mxs/clk-imx28.c             |  318 ++++++++++++
 drivers/clk/mxs/clk-pll.c               |  123 +++++
 drivers/clk/mxs/clk-ref.c               |  139 ++++++
 drivers/clk/mxs/clk.h                   |   95 ++++
 21 files changed, 1123 insertions(+), 2456 deletions(-)
author
#1 lore raw

PATCH 1/8 clk: mxs: add mxs specific clocks

Add mxs specific clocks, pll, reference clock (PFD), integer divider and fractional divider.

---
 drivers/clk/mxs/Makefile   |    5 ++
 drivers/clk/mxs/clk-div.c  |  102 ++++++++++++++++++++++++++++++++
 drivers/clk/mxs/clk-frac.c |  127 ++++++++++++++++++++++++++++++++++++++++
 drivers/clk/mxs/clk-pll.c  |  123 +++++++++++++++++++++++++++++++++++++++
 drivers/clk/mxs/clk-ref.c  |  139 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/mxs/clk.h      |   75 ++++++++++++++++++++++++
 6 files changed, 571 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mxs/Makefile
 create mode 100644 drivers/clk/mxs/clk-div.c
 create mode 100644 drivers/clk/mxs/clk-frac.c
 create mode 100644 drivers/clk/mxs/clk-pll.c
 create mode 100644 drivers/clk/mxs/clk-ref.c
 create mode 100644 drivers/clk/mxs/clk.h
drivers/clk/mxs/Makefile new file +5 -0
new file mode 100644
index 0000000..067c231
@@ -0,0 +1,5 @@
+#
+# Makefile for mxs specific clk
+#
+
+obj-y += clk-pll.o clk-ref.o clk-div.o clk-frac.o
drivers/clk/mxs/clk-div.c new file +102 -0

102 lines not on this page · raw message

drivers/clk/mxs/clk-frac.c new file +127 -0

127 lines not on this page · raw message

drivers/clk/mxs/clk-pll.c new file +123 -0

123 lines not on this page · raw message

drivers/clk/mxs/clk-ref.c new file +139 -0

139 lines not on this page · raw message

drivers/clk/mxs/clk.h new file +75 -0

75 lines not on this page · raw message

Signature · 1 line
1.7.5.4
author
#2 lore raw

PATCH 2/8 clk: mxs: add clock support for imx23

In reply to Shawn Guo

Add imx23 clock support based on common clk framework.

---
 drivers/clk/mxs/Makefile    |    2 +
 drivers/clk/mxs/clk-imx23.c |  195 +++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/mxs/clk.h       |   20 +++++
 3 files changed, 217 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mxs/clk-imx23.c
drivers/clk/mxs/Makefile +2 -0
index 067c231..21ec6ca 100644
@@ -3,3 +3,5 @@
 #
 
 obj-y += clk-pll.o clk-ref.o clk-div.o clk-frac.o
+
+obj-$(CONFIG_SOC_IMX23) += clk-imx23.o
drivers/clk/mxs/clk-imx23.c new file +195 -0

195 lines not on this page · raw message

drivers/clk/mxs/clk.h +20 -0
index deb5c23..fb5937d 100644
@@ -12,6 +12,8 @@
 #ifndef __MXS_CLK_H
 #define __MXS_CLK_H
 
+#include <linux/clk.h>
+#include <linux/clkdev.h>
 #include <linux/clk-provider.h>
 #include <linux/err.h>
 #include <linux/io.h>
@@ -72,4 +74,22 @@ static inline int mxs_clk_wait(void __iomem *reg, u8 shift)
 	return 0;
 }
 
+static inline int mxs_clk_init_on(char **clks_init_on, int num)
+{
+	struct clk *clk;
+	int i;
+
+	for (i = 0; i < num; i++) {
+		clk = clk_get_sys(clks_init_on[i], NULL);
+		if (IS_ERR(clk)) {
+			pr_err("%s: failed to get clk %s", __func__,
+			       clks_init_on[i]);
+			return PTR_ERR(clk);
+		}
+		clk_prepare_enable(clk);
+	}
+
+	return 0;
+}
+
 #endif /* __MXS_CLK_H */
Signature · 1 line
1.7.5.4
#3 lore raw

PATCH 2/8 clk: mxs: add clock support for imx23

Quoted 4 lines · Shawn Guo

Add imx23 clock support based on common clk framework.

---

...

drivers/clk/mxs/clk-imx23.c

Quoted 8 lines
drivers/clk/mxs/clk-imx23.c new file +8 -0
+int __init mx23_clocks_init(void)
+{
+ ? ? ? struct clk *clk;
+ ? ? ? int ret;
+
+ ? ? ? clk_misc_init();
+
+ ? ? ? mxs_clk_fixed("ref_xtal", 24000000);

There is no error checking at all?

Quoted 24 lines
drivers/clk/mxs/clk.h +0 -0
index deb5c23..fb5937d 100644
@@ -12,6 +12,8 @@

?#ifndef __MXS_CLK_H
?#define __MXS_CLK_H

drivers/clk/mxs/clk.h +2 -0
+#include <linux/clk.h>
+#include <linux/clkdev.h>

?#include <linux/clk-provider.h>
?#include <linux/err.h>
?#include <linux/io.h>

drivers/clk/mxs/clk.h +7 -0
@@ -72,4 +74,22 @@ static inline int mxs_clk_wait(void __iomem *reg, u8 shift)
 ? ? ? ?return 0;
 ?}
 
+static inline int mxs_clk_init_on(char **clks_init_on, int num)
+{
+ ? ? ? struct clk *clk;
+ ? ? ? int i;
+
+ ? ? ? for (i = 0; i < num; i++) {
+ ? ? ? ? ? ? ? clk = clk_get_sys(clks_init_on[i], NULL);

drivers/clk/mxs/clk.h static inline int mxs_clk_wait(void __iomem *reg, u8 shift) · line 93

Quoted 10 lines
drivers/clk/mxs/clk.h +10 -0
+ ? ? ? ? ? ? ? if (IS_ERR(clk)) {
+ ? ? ? ? ? ? ? ? ? ? ? pr_err("%s: failed to get clk %s", __func__,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?clks_init_on[i]);
+ ? ? ? ? ? ? ? ? ? ? ? return PTR_ERR(clk);
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? clk_prepare_enable(clk);
+ ? ? ? }
+
+ ? ? ? return 0;
+}

Any good reason for this code to live in the header as static inline?

Do you call this code any time other than at boot? Why not __init?

Thanks,
Mike

author
#4 lore raw

PATCH 2/8 clk: mxs: add clock support for imx23

Quoted 6 lines · Mike
Quoted 4 lines · Shawn Guo

Add imx23 clock support based on common clk framework.

---

...

Quoted 11 lines

drivers/clk/mxs/clk-imx23.c

Quoted 8 lines
drivers/clk/mxs/clk-imx23.c new file +8 -0
+int __init mx23_clocks_init(void)
+{
+ ? ? ? struct clk *clk;
+ ? ? ? int ret;
+
+ ? ? ? clk_misc_init();
+
+ ? ? ? mxs_clk_fixed("ref_xtal", 24000000);

There is no error checking at all?

Right now, the only possible reason that the registration function could fail is -ENOMEM. I thought it's not worth checking tens of function returns for the same error which is unlikely to happen.

But if you're strong on this, I can add a check.

Quoted 28 lines
Quoted 28 lines
drivers/clk/mxs/clk.h +0 -0
index deb5c23..fb5937d 100644
@@ -12,6 +12,8 @@

?#ifndef __MXS_CLK_H
?#define __MXS_CLK_H

drivers/clk/mxs/clk.h +2 -0
+#include <linux/clk.h>
+#include <linux/clkdev.h>

?#include <linux/clk-provider.h>
?#include <linux/err.h>
?#include <linux/io.h>

drivers/clk/mxs/clk.h +11 -0
@@ -72,4 +74,22 @@ static inline int mxs_clk_wait(void __iomem *reg, u8 shift)
 ? ? ? ?return 0;
 ?}
 
+static inline int mxs_clk_init_on(char **clks_init_on, int num)
+{
+ ? ? ? struct clk *clk;
+ ? ? ? int i;
+
+ ? ? ? for (i = 0; i < num; i++) {
+ ? ? ? ? ? ? ? clk = clk_get_sys(clks_init_on[i], NULL);
+ ? ? ? ? ? ? ? if (IS_ERR(clk)) {
+ ? ? ? ? ? ? ? ? ? ? ? pr_err("%s: failed to get clk %s", __func__,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?clks_init_on[i]);
+ ? ? ? ? ? ? ? ? ? ? ? return PTR_ERR(clk);
Quoted 9 lines

drivers/clk/mxs/clk.h static inline int mxs_clk_wait(void __iomem *reg, u8 shift) · line 93

Quoted 6 lines
drivers/clk/mxs/clk.h +6 -0
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? clk_prepare_enable(clk);
+ ? ? ? }
+
+ ? ? ? return 0;
+}

Any good reason for this code to live in the header as static inline?

It's a small function which is used by both clk-imx23.c and clk-imx28.c.

Quoted 2 lines

Do you call this code any time other than at boot? Why not __init?

Eh, __init for inline function?

Signature · 2 lines
Regards,
Shawn
#5 lore raw

PATCH 2/8 clk: mxs: add clock support for imx23

Quoted 18 lines · Shawn Guo
Quoted 6 lines · Mike
Quoted 4 lines · Shawn Guo

Add imx23 clock support based on common clk framework.

---

...

Quoted 11 lines

drivers/clk/mxs/clk-imx23.c

Quoted 8 lines
drivers/clk/mxs/clk-imx23.c new file +8 -0
+int __init mx23_clocks_init(void)
+{
+ ? ? ? struct clk *clk;
+ ? ? ? int ret;
+
+ ? ? ? clk_misc_init();
+
+ ? ? ? mxs_clk_fixed("ref_xtal", 24000000);

There is no error checking at all?

Quoted 5 lines

Right now, the only possible reason that the registration function could fail is -ENOMEM. ?I thought it's not worth checking tens of function returns for the same error which is unlikely to happen.

But if you're strong on this, I can add a check.

The error codes were added in for a good reason and should be honored.

Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
drivers/clk/mxs/clk.h +0 -0
index deb5c23..fb5937d 100644
@@ -12,6 +12,8 @@

?#ifndef __MXS_CLK_H
?#define __MXS_CLK_H

drivers/clk/mxs/clk.h +2 -0
+#include <linux/clk.h>
+#include <linux/clkdev.h>

?#include <linux/clk-provider.h>
?#include <linux/err.h>
?#include <linux/io.h>

drivers/clk/mxs/clk.h +11 -0
@@ -72,4 +74,22 @@ static inline int mxs_clk_wait(void __iomem *reg, u8 shift)
 ? ? ? ?return 0;
 ?}
 
+static inline int mxs_clk_init_on(char **clks_init_on, int num)
+{
+ ? ? ? struct clk *clk;
+ ? ? ? int i;
+
+ ? ? ? for (i = 0; i < num; i++) {
+ ? ? ? ? ? ? ? clk = clk_get_sys(clks_init_on[i], NULL);
+ ? ? ? ? ? ? ? if (IS_ERR(clk)) {
+ ? ? ? ? ? ? ? ? ? ? ? pr_err("%s: failed to get clk %s", __func__,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?clks_init_on[i]);
+ ? ? ? ? ? ? ? ? ? ? ? return PTR_ERR(clk);
Quoted 9 lines

drivers/clk/mxs/clk.h static inline int mxs_clk_wait(void __iomem *reg, u8 shift) · line 93

Quoted 6 lines
drivers/clk/mxs/clk.h +6 -0
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? clk_prepare_enable(clk);
+ ? ? ? }
+
+ ? ? ? return 0;
+}

Any good reason for this code to live in the header as static inline?

Quoted 5 lines

It's a small function which is used by both clk-imx23.c and clk-imx28.c.

Quoted 2 lines

Do you call this code any time other than at boot? ?Why not __init?

Eh, __init for inline function?

__init for a non-lined function. If this code is only called at boot then you can move it into a C file and __init it.

This issue isn't worth blocking the series, but you could just as easily put the definition in the clock code for the oldest SoC that uses it (imx23 in this case) and declare it in your local clk.h

Regards,
Mike

author
#6 lore raw

PATCH 2/8 clk: mxs: add clock support for imx23

Quoted 43 lines · Mike

The error codes were added in for a good reason and should be honored.

Quoted 41 lines
Quoted 28 lines
Quoted 28 lines
drivers/clk/mxs/clk.h +0 -0
index deb5c23..fb5937d 100644
@@ -12,6 +12,8 @@

?#ifndef __MXS_CLK_H
?#define __MXS_CLK_H

drivers/clk/mxs/clk.h +2 -0
+#include <linux/clk.h>
+#include <linux/clkdev.h>

?#include <linux/clk-provider.h>
?#include <linux/err.h>
?#include <linux/io.h>

drivers/clk/mxs/clk.h +11 -0
@@ -72,4 +74,22 @@ static inline int mxs_clk_wait(void __iomem *reg, u8 shift)
 ? ? ? ?return 0;
 ?}
 
+static inline int mxs_clk_init_on(char **clks_init_on, int num)
+{
+ ? ? ? struct clk *clk;
+ ? ? ? int i;
+
+ ? ? ? for (i = 0; i < num; i++) {
+ ? ? ? ? ? ? ? clk = clk_get_sys(clks_init_on[i], NULL);
+ ? ? ? ? ? ? ? if (IS_ERR(clk)) {
+ ? ? ? ? ? ? ? ? ? ? ? pr_err("%s: failed to get clk %s", __func__,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?clks_init_on[i]);
+ ? ? ? ? ? ? ? ? ? ? ? return PTR_ERR(clk);
Quoted 9 lines

drivers/clk/mxs/clk.h static inline int mxs_clk_wait(void __iomem *reg, u8 shift) · line 93

Quoted 6 lines
drivers/clk/mxs/clk.h +6 -0
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? clk_prepare_enable(clk);
+ ? ? ? }
+
+ ? ? ? return 0;
+}

Any good reason for this code to live in the header as static inline?

It's a small function which is used by both clk-imx23.c and clk-imx28.c.

Quoted 2 lines

Do you call this code any time other than at boot? ?Why not __init?

Quoted 9 lines
Quoted 1 line

Eh, __init for inline function?

__init for a non-lined function. If this code is only called at boot then you can move it into a C file and __init it.

This issue isn't worth blocking the series, but you could just as easily put the definition in the clock code for the oldest SoC that uses it (imx23 in this case) and declare it in your local clk.h

Ok, if you are strong on this, I would prefer to the current way. After all, it's a small function and the callers to it have already been __init.

Should I respin the series to have those registration returns checked?

Signature · 2 lines
Regards,
Shawn
#7 lore raw

PATCH 2/8 clk: mxs: add clock support for imx23

Quoted 49 lines · Shawn Guo
Quoted 48 lines · Mike

The error codes were added in for a good reason and should be honored.

Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
drivers/clk/mxs/clk.h +0 -0
index deb5c23..fb5937d 100644
@@ -12,6 +12,8 @@

?#ifndef __MXS_CLK_H
?#define __MXS_CLK_H

drivers/clk/mxs/clk.h +2 -0
+#include <linux/clk.h>
+#include <linux/clkdev.h>

?#include <linux/clk-provider.h>
?#include <linux/err.h>
?#include <linux/io.h>

drivers/clk/mxs/clk.h +11 -0
@@ -72,4 +74,22 @@ static inline int mxs_clk_wait(void __iomem *reg, u8 shift)
 ? ? ? ?return 0;
 ?}
 
+static inline int mxs_clk_init_on(char **clks_init_on, int num)
+{
+ ? ? ? struct clk *clk;
+ ? ? ? int i;
+
+ ? ? ? for (i = 0; i < num; i++) {
+ ? ? ? ? ? ? ? clk = clk_get_sys(clks_init_on[i], NULL);
+ ? ? ? ? ? ? ? if (IS_ERR(clk)) {
+ ? ? ? ? ? ? ? ? ? ? ? pr_err("%s: failed to get clk %s", __func__,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?clks_init_on[i]);
+ ? ? ? ? ? ? ? ? ? ? ? return PTR_ERR(clk);
Quoted 9 lines

drivers/clk/mxs/clk.h static inline int mxs_clk_wait(void __iomem *reg, u8 shift) · line 93

Quoted 6 lines
drivers/clk/mxs/clk.h +6 -0
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? clk_prepare_enable(clk);
+ ? ? ? }
+
+ ? ? ? return 0;
+}

Any good reason for this code to live in the header as static inline?

Quoted 5 lines

It's a small function which is used by both clk-imx23.c and clk-imx28.c.

Quoted 2 lines

Do you call this code any time other than at boot? ?Why not __init?

Eh, __init for inline function?

__init for a non-lined function. ?If this code is only called at boot then you can move it into a C file and __init it.

Quoted 7 lines
Quoted 4 lines

This issue isn't worth blocking the series, but you could just as easily put the definition in the clock code for the oldest SoC that uses it (imx23 in this case) and declare it in your local clk.h

Ok, if you are strong on this, I would prefer to the current way. After all, it's a small function and the callers to it have already been __init.

I'm OK if you leave it as it is. It is not a blocking issue for me.

Quoted 1 line

Should I respin the series to have those registration returns checked?

Yes, please do. Once the checks are in then I will take this into my -next branch.

Regards,
Mike

Quoted 3 lines

--
Regards,
Shawn

author
#8 lore raw

PATCH 2/8 clk: mxs: add clock support for imx23

Quoted 3 lines · Mike

Yes, please do. Once the checks are in then I will take this into my -next branch.

Just reminded by Sascha, the error return of basic clk registrations have not been unified. Can you publish your -next branch, so that I can have a good base to respin the series?

Signature · 2 lines
Regards,
Shawn
author
#9 lore raw

PATCH 3/8 clk: mxs: add clock support for imx28

In reply to Shawn Guo

Add imx28 clock support based on common clk framework.

---
 drivers/clk/mxs/Makefile    |    1 +
 drivers/clk/mxs/clk-imx28.c |  318 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 319 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mxs/clk-imx28.c
drivers/clk/mxs/Makefile +1 -0
index 21ec6ca..3554916 100644
@@ -5,3 +5,4 @@
 obj-y += clk-pll.o clk-ref.o clk-div.o clk-frac.o
 
 obj-$(CONFIG_SOC_IMX23) += clk-imx23.o
+obj-$(CONFIG_SOC_IMX28) += clk-imx28.o
drivers/clk/mxs/clk-imx28.c new file +318 -0

318 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#10 lore raw

PATCH 3/8 clk: mxs: add clock support for imx28

Quoted 4 lines · Shawn Guo

Add imx28 clock support based on common clk framework.

---

...

drivers/clk/mxs/clk-imx28.c

Quoted 8 lines
drivers/clk/mxs/clk-imx28.c new file +8 -0
+int __init mx28_clocks_init(void)
+{
+ ? ? ? struct clk *clk;
+ ? ? ? int ret;
+
+ ? ? ? clk_misc_init();
+
+ ? ? ? mxs_clk_fixed("ref_xtal", 24000000);

Hi Shawn,

My comment here is the same as patch 2/8. There is zero error handling here. Registration functions _should_ be returning -EERROR.

Regards,
Mike

maintainer
#11 lore raw

PATCH 3/8 clk: mxs: add clock support for imx28

In reply to Shawn Guo

Hi Shawn,

I realized that you have no register lock which means that you rely on the locking of the clock framework. This may not be sufficient, see the following example:

drivers/clk/mxs/clk-imx28.c line 279

Quoted 2 lines
drivers/clk/mxs/clk-imx28.c new file +2 -0
+	mxs_clk_div("ssp0_div", "ssp0_sel", SSP0, 0, 9, 29);
+	clk = mxs_clk_gate("ssp0", "ssp0_div", SSP0, 31);

You have both a divider and a gate in the same register here. The gate implements clk_enable which is protected by a spinlock in the clock framework. The divider implements clk_set_rate which is protected by a mutex in the clock framework. This means that during a read-modify-write operation for a rate change the clk_enable call can come in between.

Ok, here we have two clocks which are both handled by a single driver, so there probably won't be any real problems, but do you want to rely on this?

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#12 lore raw

PATCH 3/8 clk: mxs: add clock support for imx28

Quoted 6 lines · Sascha Hauer

Hi Shawn,

I realized that you have no register lock which means that you rely on the locking of the clock framework. This may not be sufficient, see the following example:

Quoted 8 lines

drivers/clk/mxs/clk-imx28.c line 279

Quoted 2 lines
drivers/clk/mxs/clk-imx28.c new file +2 -0
+	mxs_clk_div("ssp0_div", "ssp0_sel", SSP0, 0, 9, 29);
+	clk = mxs_clk_gate("ssp0", "ssp0_div", SSP0, 31);

You have both a divider and a gate in the same register here. The gate implements clk_enable which is protected by a spinlock in the clock framework. The divider implements clk_set_rate which is protected by a mutex in the clock framework. This means that during a read-modify-write operation for a rate change the clk_enable call can come in between.

We have SET and CLR register on mxs clocks, so do not really have to go through read-modify-write sequence.

Regards,
Shawn

Quoted 5 lines

Ok, here we have two clocks which are both handled by a single driver, so there probably won't be any real problems, but do you want to rely on this?

maintainer
#13 lore raw

PATCH 3/8 clk: mxs: add clock support for imx28

Quoted 16 lines · Shawn Guo
Quoted 6 lines · Sascha Hauer

Hi Shawn,

I realized that you have no register lock which means that you rely on the locking of the clock framework. This may not be sufficient, see the following example:

Quoted 8 lines

drivers/clk/mxs/clk-imx28.c line 279

Quoted 2 lines
drivers/clk/mxs/clk-imx28.c new file +2 -0
+	mxs_clk_div("ssp0_div", "ssp0_sel", SSP0, 0, 9, 29);
+	clk = mxs_clk_gate("ssp0", "ssp0_div", SSP0, 31);

You have both a divider and a gate in the same register here. The gate implements clk_enable which is protected by a spinlock in the clock framework. The divider implements clk_set_rate which is protected by a mutex in the clock framework. This means that during a read-modify-write operation for a rate change the clk_enable call can come in between.

Quoted 2 lines

We have SET and CLR register on mxs clocks, so do not really have to go through read-modify-write sequence.

You have the SET and CLR registers but you don't use them. You could use SET/CLR in the gate, but even then:

- clk_set_rate starts and reads the divider register
- clk_enable comes in and writes to SET/CLR for the same register
- clk_set_rate continues and writes to the divider register not knowing that it has been modified in between.

You could try and clear all divider bits in the divider using the CLR register and then set the wanted bits using the SET register, but this would mean writing reserved values to the divider in between.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#14 lore raw

PATCH 3/8 clk: mxs: add clock support for imx28

Quoted 17 lines · Sascha Hauer
Quoted 16 lines · Shawn Guo
Quoted 14 lines · Sascha Hauer

Hi Shawn,

I realized that you have no register lock which means that you rely on the locking of the clock framework. This may not be sufficient, see the following example:

drivers/clk/mxs/clk-imx28.c line 279

Quoted 2 lines
drivers/clk/mxs/clk-imx28.c new file +2 -0
+	mxs_clk_div("ssp0_div", "ssp0_sel", SSP0, 0, 9, 29);
+	clk = mxs_clk_gate("ssp0", "ssp0_div", SSP0, 31);

You have both a divider and a gate in the same register here. The gate implements clk_enable which is protected by a spinlock in the clock framework. The divider implements clk_set_rate which is protected by a mutex in the clock framework. This means that during a read-modify-write operation for a rate change the clk_enable call can come in between.

Quoted 4 lines
Quoted 2 lines

We have SET and CLR register on mxs clocks, so do not really have to go through read-modify-write sequence.

You have the SET and CLR registers but you don't use them.

Doh! I forgot I'm running with basic clocks.

Quoted 12 lines

You could use
SET/CLR in the gate, but even then:

- clk_set_rate starts and reads the divider register
- clk_enable comes in and writes to SET/CLR for the same register
- clk_set_rate continues and writes to the divider register not knowing that it has been modified in between.

You could try and clear all divider bits in the divider using the CLR register and then set the wanted bits using the SET register, but this would mean writing reserved values to the divider in between.

Ok, will add register locking. Thanks, Sascha.

Signature · 2 lines
Regards,
Shawn
author
#15 lore raw

PATCH 4/8 ARM: mxs: request clock for timer

In reply to Shawn Guo

When mxs_timer_init() does not have a timer_clk passed in, it should try to request clock from clkdev system.

---
 arch/arm/mach-mxs/timer.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
arch/arm/mach-mxs/timer.c +9 -0
index 564a632..575e8fd 100644
@@ -20,6 +20,7 @@
  * MA 02110-1301, USA.
  */
 
+#include <linux/err.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/clockchips.h>
@@ -245,6 +246,14 @@ static int __init mxs_clocksource_init(struct clk *timer_clk)
 
 void __init mxs_timer_init(struct clk *timer_clk, int irq)
 {
+	if (!timer_clk) {
+		timer_clk = clk_get_sys("timrot", NULL);
+		if (IS_ERR(timer_clk)) {
+			pr_err("%s: failed to get clk\n", __func__);
+			return;
+		}
+	}
+
 	clk_prepare_enable(timer_clk);
 
 	/*
Signature · 1 line
1.7.5.4
author
#16 lore raw

PATCH 5/8 ARM: mxs: change the lookup name for fec phy clock

In reply to Shawn Guo

Change the fec phy clock lookup name to be more accurate.

---
 arch/arm/mach-mxs/clock-mx28.c   |    2 +-
 arch/arm/mach-mxs/mach-mx28evk.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-mxs/clock-mx28.c +1 -1
index cea29c9..5a832ad 100644
@@ -624,7 +624,7 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("mxs-auart.3", NULL, uart_clk)
 	_REGISTER_CLOCK("mxs-auart.4", NULL, uart_clk)
 	_REGISTER_CLOCK("rtc", NULL, rtc_clk)
-	_REGISTER_CLOCK("pll2", NULL, pll2_clk)
+	_REGISTER_CLOCK("enet_out", NULL, pll2_clk)
 	_REGISTER_CLOCK("mxs-dma-apbh", NULL, hbus_clk)
 	_REGISTER_CLOCK("mxs-dma-apbx", NULL, xbus_clk)
 	_REGISTER_CLOCK("mxs-mmc.0", NULL, ssp0_clk)
arch/arm/mach-mxs/mach-mx28evk.c +1 -1
index e386c14..9596940 100644
@@ -226,7 +226,7 @@ static void __init mx28evk_fec_reset(void)
 	struct clk *clk;
 
 	/* Enable fec phy clock */
-	clk = clk_get_sys("pll2", NULL);
+	clk = clk_get_sys("enet_out", NULL);
 	if (!IS_ERR(clk))
 		clk_prepare_enable(clk);
 
Signature · 1 line
1.7.5.4
author
#17 lore raw

PATCH 6/8 ARM: mxs: switch to common clk framework

In reply to Shawn Guo

It switches mxs clock support to common clk framework based drivers.

---
 arch/arm/Kconfig           |    1 +
 arch/arm/mach-mxs/Makefile |    5 +----
 drivers/clk/Makefile       |    2 ++
 3 files changed, 4 insertions(+), 4 deletions(-)
arch/arm/Kconfig +1 -0
index cf006d4..60bdec7 100644
@@ -468,6 +468,7 @@ config ARCH_MXS
 	select ARCH_REQUIRE_GPIOLIB
 	select CLKDEV_LOOKUP
 	select CLKSRC_MMIO
+	select COMMON_CLK
 	select HAVE_CLK_PREPARE
 	help
 	  Support for Freescale MXS-based family of processors
arch/arm/mach-mxs/Makefile +1 -4
index 908bf9a..6ce21a2 100644
@@ -1,12 +1,9 @@
 # Common support
-obj-y := clock.o devices.o icoll.o iomux.o system.o timer.o mm.o
+obj-y := devices.o icoll.o iomux.o system.o timer.o mm.o
 
 obj-$(CONFIG_MXS_OCOTP) += ocotp.o
 obj-$(CONFIG_PM) += pm.o
 
-obj-$(CONFIG_SOC_IMX23) += clock-mx23.o
-obj-$(CONFIG_SOC_IMX28) += clock-mx28.o
-
 obj-$(CONFIG_MACH_STMP378X_DEVB) += mach-stmp378x_devb.o
 obj-$(CONFIG_MACH_MX23EVK) += mach-mx23evk.o
 obj-$(CONFIG_MACH_MX28EVK) += mach-mx28evk.o
drivers/clk/Makefile +2 -0
index 24aa714..4a5bdbc 100644
@@ -2,3 +2,5 @@
 obj-$(CONFIG_CLKDEV_LOOKUP)	+= clkdev.o
 obj-$(CONFIG_COMMON_CLK)	+= clk.o clk-fixed-rate.o clk-gate.o \
 				   clk-mux.o clk-divider.o clk-fixed-factor.o
+
+obj-$(CONFIG_ARCH_MXS)		+= mxs/
Signature · 1 line
1.7.5.4
author
#18 lore raw

PATCH 7/8 ARM: mxs: remove old clock support

In reply to Shawn Guo

The mxs clock has been switched to common clock framework, so the old clock support can be removed now.

---
 arch/arm/mach-mxs/clock-mx23.c          |  536 ---------------------
 arch/arm/mach-mxs/clock-mx28.c          |  803 -------------------------------
 arch/arm/mach-mxs/clock.c               |  211 --------
 arch/arm/mach-mxs/include/mach/clock.h  |   62 ---
 arch/arm/mach-mxs/include/mach/common.h |    2 -
 arch/arm/mach-mxs/regs-clkctrl-mx23.h   |  331 -------------
 arch/arm/mach-mxs/regs-clkctrl-mx28.h   |  486 -------------------
 arch/arm/mach-mxs/system.c              |   16 -
 8 files changed, 0 insertions(+), 2447 deletions(-)
 delete mode 100644 arch/arm/mach-mxs/clock-mx23.c
 delete mode 100644 arch/arm/mach-mxs/clock-mx28.c
 delete mode 100644 arch/arm/mach-mxs/clock.c
 delete mode 100644 arch/arm/mach-mxs/include/mach/clock.h
 delete mode 100644 arch/arm/mach-mxs/regs-clkctrl-mx23.h
 delete mode 100644 arch/arm/mach-mxs/regs-clkctrl-mx28.h
arch/arm/mach-mxs/clock-mx23.c deleted +0 -536
deleted file mode 100644
index e3ac52c..0000000
@@ -1,536 +0,0 @@
-/*
- * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <linux/mm.h>
-#include <linux/delay.h>
-#include <linux/clk.h>
-#include <linux/io.h>
-#include <linux/jiffies.h>
-#include <linux/clkdev.h>
-
-#include <asm/clkdev.h>
-#include <asm/div64.h>
-
-#include <mach/mx23.h>
-#include <mach/common.h>
-#include <mach/clock.h>
-
-#include "regs-clkctrl-mx23.h"
-
-#define CLKCTRL_BASE_ADDR	MX23_IO_ADDRESS(MX23_CLKCTRL_BASE_ADDR)
-#define DIGCTRL_BASE_ADDR	MX23_IO_ADDRESS(MX23_DIGCTL_BASE_ADDR)
-
-#define PARENT_RATE_SHIFT	8
-
-static int _raw_clk_enable(struct clk *clk)
-{
-	u32 reg;
-
-	if (clk->enable_reg) {
-		reg = __raw_readl(clk->enable_reg);
-		reg &= ~(1 << clk->enable_shift);
-		__raw_writel(reg, clk->enable_reg);
-	}
-
-	return 0;
-}
-
-static void _raw_clk_disable(struct clk *clk)
-{
-	u32 reg;
-
-	if (clk->enable_reg) {
-		reg = __raw_readl(clk->enable_reg);
-		reg |= 1 << clk->enable_shift;
-		__raw_writel(reg, clk->enable_reg);
-	}
-}
-
-/*
- * ref_xtal_clk
- */
-static unsigned long ref_xtal_clk_get_rate(struct clk *clk)
-{
-	return 24000000;
-}
-
-static struct clk ref_xtal_clk = {
-	.get_rate = ref_xtal_clk_get_rate,
-};
-
-/*
- * pll_clk
- */
-static unsigned long pll_clk_get_rate(struct clk *clk)
-{
-	return 480000000;
-}
-
-static int pll_clk_enable(struct clk *clk)
-{
-	__raw_writel(BM_CLKCTRL_PLLCTRL0_POWER |
-			BM_CLKCTRL_PLLCTRL0_EN_USB_CLKS,
-			CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLLCTRL0_SET);
-
-	/* Only a 10us delay is need. PLLCTRL1 LOCK bitfied is only a timer
-	 * and is incorrect (excessive). Per definition of the PLLCTRL0
-	 * POWER field, waiting at least 10us.
-	 */
-	udelay(10);
-
-	return 0;
-}
-
-static void pll_clk_disable(struct clk *clk)
-{
-	__raw_writel(BM_CLKCTRL_PLLCTRL0_POWER |
-			BM_CLKCTRL_PLLCTRL0_EN_USB_CLKS,
-			CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLLCTRL0_CLR);
-}
-
-static struct clk pll_clk = {
-	 .get_rate = pll_clk_get_rate,
-	 .enable = pll_clk_enable,
-	 .disable = pll_clk_disable,
-	 .parent = &ref_xtal_clk,
-};
-
-/*
- * ref_clk
- */
-#define _CLK_GET_RATE_REF(name, sr, ss)					\
-static unsigned long name##_get_rate(struct clk *clk)			\
-{									\
-	unsigned long parent_rate;					\
-	u32 reg, div;							\
-									\
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##sr);		\
-	div = (reg >> BP_CLKCTRL_##sr##_##ss##FRAC) & 0x3f;		\
-	parent_rate = clk_get_rate(clk->parent);			\
-									\
-	return SH_DIV((parent_rate >> PARENT_RATE_SHIFT) * 18,		\
-			div, PARENT_RATE_SHIFT);			\
-}
-
-_CLK_GET_RATE_REF(ref_cpu_clk, FRAC, CPU)
-_CLK_GET_RATE_REF(ref_emi_clk, FRAC, EMI)
-_CLK_GET_RATE_REF(ref_pix_clk, FRAC, PIX)
-_CLK_GET_RATE_REF(ref_io_clk, FRAC, IO)
-
-#define _DEFINE_CLOCK_REF(name, er, es)					\
-	static struct clk name = {					\
-		.enable_reg	= CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er,	\
-		.enable_shift	= BP_CLKCTRL_##er##_CLKGATE##es,	\
-		.get_rate	= name##_get_rate,			\
-		.enable		= _raw_clk_enable,			\
-		.disable	= _raw_clk_disable,			\
-		.parent		= &pll_clk,				\
-	}
-
-_DEFINE_CLOCK_REF(ref_cpu_clk, FRAC, CPU);
-_DEFINE_CLOCK_REF(ref_emi_clk, FRAC, EMI);
-_DEFINE_CLOCK_REF(ref_pix_clk, FRAC, PIX);
-_DEFINE_CLOCK_REF(ref_io_clk, FRAC, IO);
-
-/*
- * General clocks
- *
- * clk_get_rate
- */
-static unsigned long rtc_clk_get_rate(struct clk *clk)
-{
-	/* ref_xtal_clk is implemented as the only parent */
-	return clk_get_rate(clk->parent) / 768;
-}
-
-static unsigned long clk32k_clk_get_rate(struct clk *clk)
-{
-	return clk->parent->get_rate(clk->parent) / 750;
-}
-
-#define _CLK_GET_RATE(name, rs)						\
-static unsigned long name##_get_rate(struct clk *clk)			\
-{									\
-	u32 reg, div;							\
-									\
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##rs);		\
-									\
-	if (clk->parent == &ref_xtal_clk)				\
-		div = (reg & BM_CLKCTRL_##rs##_DIV_XTAL) >>		\
-			BP_CLKCTRL_##rs##_DIV_XTAL;			\
-	else								\
-		div = (reg & BM_CLKCTRL_##rs##_DIV_##rs) >>		\
-			BP_CLKCTRL_##rs##_DIV_##rs;			\
-									\
-	if (!div)							\
-		return -EINVAL;						\
-									\
-	return clk_get_rate(clk->parent) / div;				\
-}
-
-_CLK_GET_RATE(cpu_clk, CPU)
-_CLK_GET_RATE(emi_clk, EMI)
-
-#define _CLK_GET_RATE1(name, rs)					\
-static unsigned long name##_get_rate(struct clk *clk)			\
-{									\
-	u32 reg, div;							\
-									\
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##rs);		\
-	div = (reg & BM_CLKCTRL_##rs##_DIV) >> BP_CLKCTRL_##rs##_DIV;	\
-									\
-	if (!div)							\
-		return -EINVAL;						\
-									\
-	return clk_get_rate(clk->parent) / div;				\
-}
-
-_CLK_GET_RATE1(hbus_clk, HBUS)
-_CLK_GET_RATE1(xbus_clk, XBUS)
-_CLK_GET_RATE1(ssp_clk, SSP)
-_CLK_GET_RATE1(gpmi_clk, GPMI)
-_CLK_GET_RATE1(lcdif_clk, PIX)
-
-#define _CLK_GET_RATE_STUB(name)					\
-static unsigned long name##_get_rate(struct clk *clk)			\
-{									\
-	return clk_get_rate(clk->parent);				\
-}
-
-_CLK_GET_RATE_STUB(uart_clk)
-_CLK_GET_RATE_STUB(audio_clk)
-_CLK_GET_RATE_STUB(pwm_clk)
-
-/*
- * clk_set_rate
- */
-static int cpu_clk_set_rate(struct clk *clk, unsigned long rate)
-{
-	u32 reg, bm_busy, div_max, d, f, div, frac;
-	unsigned long diff, parent_rate, calc_rate;
-
-	parent_rate = clk_get_rate(clk->parent);
-
-	if (clk->parent == &ref_xtal_clk) {
-		div_max = BM_CLKCTRL_CPU_DIV_XTAL >> BP_CLKCTRL_CPU_DIV_XTAL;
-		bm_busy = BM_CLKCTRL_CPU_BUSY_REF_XTAL;
-		div = DIV_ROUND_UP(parent_rate, rate);
-		if (div == 0 || div > div_max)
-			return -EINVAL;
-	} else {
-		div_max = BM_CLKCTRL_CPU_DIV_CPU >> BP_CLKCTRL_CPU_DIV_CPU;
-		bm_busy = BM_CLKCTRL_CPU_BUSY_REF_CPU;
-		rate >>= PARENT_RATE_SHIFT;
-		parent_rate >>= PARENT_RATE_SHIFT;
-		diff = parent_rate;
-		div = frac = 1;
-		for (d = 1; d <= div_max; d++) {
-			f = parent_rate * 18 / d / rate;
-			if ((parent_rate * 18 / d) % rate)
-				f++;
-			if (f < 18 || f > 35)
-				continue;
-
-			calc_rate = parent_rate * 18 / f / d;
-			if (calc_rate > rate)
-				continue;
-
-			if (rate - calc_rate < diff) {
-				frac = f;
-				div = d;
-				diff = rate - calc_rate;
-			}
-
-			if (diff == 0)
-				break;
-		}
-
-		if (diff == parent_rate)
-			return -EINVAL;
-
-		reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_FRAC);
-		reg &= ~BM_CLKCTRL_FRAC_CPUFRAC;
-		reg |= frac;
-		__raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_FRAC);
-	}
-
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_CPU);
-	reg &= ~BM_CLKCTRL_CPU_DIV_CPU;
-	reg |= div << BP_CLKCTRL_CPU_DIV_CPU;
-	__raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_CPU);
-
-	mxs_clkctrl_timeout(HW_CLKCTRL_CPU, bm_busy);
-
-	return 0;
-}
-
-#define _CLK_SET_RATE(name, dr)						\
-static int name##_set_rate(struct clk *clk, unsigned long rate)		\
-{									\
-	u32 reg, div_max, div;						\
-	unsigned long parent_rate;					\
-									\
-	parent_rate = clk_get_rate(clk->parent);			\
-	div_max = BM_CLKCTRL_##dr##_DIV >> BP_CLKCTRL_##dr##_DIV;	\
-									\
-	div = DIV_ROUND_UP(parent_rate, rate);				\
-	if (div == 0 || div > div_max)					\
-		return -EINVAL;						\
-									\
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_##dr);		\
-	reg &= ~BM_CLKCTRL_##dr##_DIV;					\
-	reg |= div << BP_CLKCTRL_##dr##_DIV;				\
-	if (reg & (1 << clk->enable_shift)) {				\
-		pr_err("%s: clock is gated\n", __func__);		\
-		return -EINVAL;						\
-	}								\
-	__raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_##dr);		\
-									\
-	mxs_clkctrl_timeout(HW_CLKCTRL_##dr, BM_CLKCTRL_##dr##_BUSY);	\
-	return 0;							\
-}
-
-_CLK_SET_RATE(xbus_clk, XBUS)
-_CLK_SET_RATE(ssp_clk, SSP)
-_CLK_SET_RATE(gpmi_clk, GPMI)
-_CLK_SET_RATE(lcdif_clk, PIX)
-
-#define _CLK_SET_RATE_STUB(name)					\
-static int name##_set_rate(struct clk *clk, unsigned long rate)		\
-{									\
-	return -EINVAL;							\
-}
-
-_CLK_SET_RATE_STUB(emi_clk)
-_CLK_SET_RATE_STUB(uart_clk)
-_CLK_SET_RATE_STUB(audio_clk)
-_CLK_SET_RATE_STUB(pwm_clk)
-_CLK_SET_RATE_STUB(clk32k_clk)
-
-/*
- * clk_set_parent
- */
-#define _CLK_SET_PARENT(name, bit)					\
-static int name##_set_parent(struct clk *clk, struct clk *parent)	\
-{									\
-	if (parent != clk->parent) {					\
-		__raw_writel(BM_CLKCTRL_CLKSEQ_BYPASS_##bit,		\
-			 CLKCTRL_BASE_ADDR + HW_CLKCTRL_CLKSEQ_TOG);	\
-		clk->parent = parent;					\
-	}								\
-									\
-	return 0;							\
-}
-
-_CLK_SET_PARENT(cpu_clk, CPU)
-_CLK_SET_PARENT(emi_clk, EMI)
-_CLK_SET_PARENT(ssp_clk, SSP)
-_CLK_SET_PARENT(gpmi_clk, GPMI)
-_CLK_SET_PARENT(lcdif_clk, PIX)
-
-#define _CLK_SET_PARENT_STUB(name)					\
-static int name##_set_parent(struct clk *clk, struct clk *parent)	\
-{									\
-	if (parent != clk->parent)					\
-		return -EINVAL;						\
-	else								\
-		return 0;						\
-}
-
-_CLK_SET_PARENT_STUB(uart_clk)
-_CLK_SET_PARENT_STUB(audio_clk)
-_CLK_SET_PARENT_STUB(pwm_clk)
-_CLK_SET_PARENT_STUB(clk32k_clk)
-
-/*
- * clk definition
- */
-static struct clk cpu_clk = {
-	.get_rate = cpu_clk_get_rate,
-	.set_rate = cpu_clk_set_rate,
-	.set_parent = cpu_clk_set_parent,
-	.parent = &ref_cpu_clk,
-};
-
-static struct clk hbus_clk = {
-	.get_rate = hbus_clk_get_rate,
-	.parent = &cpu_clk,
-};
-
-static struct clk xbus_clk = {
-	.get_rate = xbus_clk_get_rate,
-	.set_rate = xbus_clk_set_rate,
-	.parent = &ref_xtal_clk,
-};
-
-static struct clk rtc_clk = {
-	.get_rate = rtc_clk_get_rate,
-	.parent = &ref_xtal_clk,
-};
-
-/* usb_clk gate is controlled in DIGCTRL other than CLKCTRL */
-static struct clk usb_clk = {
-	.enable_reg = DIGCTRL_BASE_ADDR,
-	.enable_shift = 2,
-	.enable = _raw_clk_enable,
-	.disable = _raw_clk_disable,
-	.parent = &pll_clk,
-};
-
-#define _DEFINE_CLOCK(name, er, es, p)					\
-	static struct clk name = {					\
-		.enable_reg	= CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er,	\
-		.enable_shift	= BP_CLKCTRL_##er##_##es,		\
-		.get_rate	= name##_get_rate,			\
-		.set_rate	= name##_set_rate,			\
-		.set_parent	= name##_set_parent,			\
-		.enable		= _raw_clk_enable,			\
-		.disable	= _raw_clk_disable,			\
-		.parent		= p,					\
-	}
-
-_DEFINE_CLOCK(emi_clk, EMI, CLKGATE, &ref_xtal_clk);
-_DEFINE_CLOCK(ssp_clk, SSP, CLKGATE, &ref_xtal_clk);
-_DEFINE_CLOCK(gpmi_clk, GPMI, CLKGATE, &ref_xtal_clk);
-_DEFINE_CLOCK(lcdif_clk, PIX, CLKGATE, &ref_xtal_clk);
-_DEFINE_CLOCK(uart_clk, XTAL, UART_CLK_GATE, &ref_xtal_clk);
-_DEFINE_CLOCK(audio_clk, XTAL, FILT_CLK24M_GATE, &ref_xtal_clk);
-_DEFINE_CLOCK(pwm_clk, XTAL, PWM_CLK24M_GATE, &ref_xtal_clk);
-_DEFINE_CLOCK(clk32k_clk, XTAL, TIMROT_CLK32K_GATE, &ref_xtal_clk);
-
-#define _REGISTER_CLOCK(d, n, c) \
-	{ \
-		.dev_id = d, \
-		.con_id = n, \
-		.clk = &c, \
-	},
-
-static struct clk_lookup lookups[] = {
-	/* for amba bus driver */
-	_REGISTER_CLOCK("duart", "apb_pclk", xbus_clk)
-	/* for amba-pl011 driver */
-	_REGISTER_CLOCK("duart", NULL, uart_clk)
-	_REGISTER_CLOCK("mxs-auart.0", NULL, uart_clk)
-	_REGISTER_CLOCK("rtc", NULL, rtc_clk)
-	_REGISTER_CLOCK("mxs-dma-apbh", NULL, hbus_clk)
-	_REGISTER_CLOCK("mxs-dma-apbx", NULL, xbus_clk)
-	_REGISTER_CLOCK("mxs-mmc.0", NULL, ssp_clk)
-	_REGISTER_CLOCK("mxs-mmc.1", NULL, ssp_clk)
-	_REGISTER_CLOCK(NULL, "usb", usb_clk)
-	_REGISTER_CLOCK(NULL, "audio", audio_clk)
-	_REGISTER_CLOCK("mxs-pwm.0", NULL, pwm_clk)
-	_REGISTER_CLOCK("mxs-pwm.1", NULL, pwm_clk)
-	_REGISTER_CLOCK("mxs-pwm.2", NULL, pwm_clk)
-	_REGISTER_CLOCK("mxs-pwm.3", NULL, pwm_clk)
-	_REGISTER_CLOCK("mxs-pwm.4", NULL, pwm_clk)
-	_REGISTER_CLOCK("imx23-fb", NULL, lcdif_clk)
-	_REGISTER_CLOCK("imx23-gpmi-nand", NULL, gpmi_clk)
-};
-
-static int clk_misc_init(void)
-{
-	u32 reg;
-	int ret;
-
-	/* Fix up parent per register setting */
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_CLKSEQ);
-	cpu_clk.parent = (reg & BM_CLKCTRL_CLKSEQ_BYPASS_CPU) ?
-			&ref_xtal_clk : &ref_cpu_clk;
-	emi_clk.parent = (reg & BM_CLKCTRL_CLKSEQ_BYPASS_EMI) ?
-			&ref_xtal_clk : &ref_emi_clk;
-	ssp_clk.parent = (reg & BM_CLKCTRL_CLKSEQ_BYPASS_SSP) ?
-			&ref_xtal_clk : &ref_io_clk;
-	gpmi_clk.parent = (reg & BM_CLKCTRL_CLKSEQ_BYPASS_GPMI) ?
-			&ref_xtal_clk : &ref_io_clk;
-	lcdif_clk.parent = (reg & BM_CLKCTRL_CLKSEQ_BYPASS_PIX) ?
-			&ref_xtal_clk : &ref_pix_clk;
-
-	/* Use int div over frac when both are available */
-	__raw_writel(BM_CLKCTRL_CPU_DIV_XTAL_FRAC_EN,
-			CLKCTRL_BASE_ADDR + HW_CLKCTRL_CPU_CLR);
-	__raw_writel(BM_CLKCTRL_CPU_DIV_CPU_FRAC_EN,
-			CLKCTRL_BASE_ADDR + HW_CLKCTRL_CPU_CLR);
-	__raw_writel(BM_CLKCTRL_HBUS_DIV_FRAC_EN,
-			CLKCTRL_BASE_ADDR + HW_CLKCTRL_HBUS_CLR);
-
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_XBUS);
-	reg &= ~BM_CLKCTRL_XBUS_DIV_FRAC_EN;
-	__raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_XBUS);
-
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_SSP);
-	reg &= ~BM_CLKCTRL_SSP_DIV_FRAC_EN;
-	__raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_SSP);
-
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_GPMI);
-	reg &= ~BM_CLKCTRL_GPMI_DIV_FRAC_EN;
-	__raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_GPMI);
-
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_PIX);
-	reg &= ~BM_CLKCTRL_PIX_DIV_FRAC_EN;
-	__raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_PIX);
-
-	/*
-	 * Set safe hbus clock divider. A divider of 3 ensure that
-	 * the Vddd voltage required for the cpu clock is sufficiently
-	 * high for the hbus clock.
-	 */
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_HBUS);
-	reg &= BM_CLKCTRL_HBUS_DIV;
-	reg |= 3 << BP_CLKCTRL_HBUS_DIV;
-	__raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_HBUS);
-
-	ret = mxs_clkctrl_timeout(HW_CLKCTRL_HBUS, BM_CLKCTRL_HBUS_BUSY);
-
-	/* Gate off cpu clock in WFI for power saving */
-	__raw_writel(BM_CLKCTRL_CPU_INTERRUPT_WAIT,
-			CLKCTRL_BASE_ADDR + HW_CLKCTRL_CPU_SET);
-
-	/*
-	 * 480 MHz seems too high to be ssp clock source directly,
-	 * so set frac to get a 288 MHz ref_io.
-	 */
-	reg = __raw_readl(CLKCTRL_BASE_ADDR + HW_CLKCTRL_FRAC);
-	reg &= ~BM_CLKCTRL_FRAC_IOFRAC;
-	reg |= 30 << BP_CLKCTRL_FRAC_IOFRAC;
-	__raw_writel(reg, CLKCTRL_BASE_ADDR + HW_CLKCTRL_FRAC);
-
-	return ret;
-}
-
-int __init mx23_clocks_init(void)
-{
-	clk_misc_init();
-
-	/*
-	 * source ssp clock from ref_io than ref_xtal,
-	 * as ref_xtal only provides 24 MHz as maximum.
-	 */
-	clk_set_parent(&ssp_clk, &ref_io_clk);
-
-	clk_prepare_enable(&cpu_clk);
-	clk_prepare_enable(&hbus_clk);
-	clk_prepare_enable(&xbus_clk);
-	clk_prepare_enable(&emi_clk);
-	clk_prepare_enable(&uart_clk);
-
-	clkdev_add_table(lookups, ARRAY_SIZE(lookups));
-
-	mxs_timer_init(&clk32k_clk, MX23_INT_TIMER0);
-
-	return 0;
-}
arch/arm/mach-mxs/clock-mx28.c deleted +0 -803

803 lines not on this page · raw message

arch/arm/mach-mxs/clock.c deleted +0 -211

211 lines not on this page · raw message

arch/arm/mach-mxs/include/mach/clock.h deleted +0 -62

62 lines not on this page · raw message

arch/arm/mach-mxs/include/mach/common.h +0 -2
index c50c3ea..e1237ab 100644
@@ -31,6 +31,4 @@ extern void mx28_init_irq(void);
 
 extern void icoll_init_irq(void);
 
-extern int mxs_clkctrl_timeout(unsigned int reg_offset, unsigned int mask);
-
 #endif /* __MACH_MXS_COMMON_H__ */
arch/arm/mach-mxs/regs-clkctrl-mx23.h deleted +0 -331

331 lines not on this page · raw message

arch/arm/mach-mxs/regs-clkctrl-mx28.h deleted +0 -486

486 lines not on this page · raw message

arch/arm/mach-mxs/system.c +0 -16
index 80ac1fc..30042e2 100644
@@ -37,8 +37,6 @@
 #define MXS_MODULE_CLKGATE		(1 << 30)
 #define MXS_MODULE_SFTRST		(1 << 31)
 
-#define CLKCTRL_TIMEOUT		10	/* 10 ms */
-
 static void __iomem *mxs_clkctrl_reset_addr;
 
 /*
@@ -139,17 +137,3 @@ error:
 	return -ETIMEDOUT;
 }
 EXPORT_SYMBOL(mxs_reset_block);
-
-int mxs_clkctrl_timeout(unsigned int reg_offset, unsigned int mask)
-{
-	unsigned long timeout = jiffies + msecs_to_jiffies(CLKCTRL_TIMEOUT);
-	while (readl_relaxed(MXS_IO_ADDRESS(MXS_CLKCTRL_BASE_ADDR)
-						+ reg_offset) & mask) {
-		if (time_after(jiffies, timeout)) {
-			pr_err("Timeout@CLKCTRL + 0x%x\n", reg_offset);
-			return -ETIMEDOUT;
-		}
-	}
-
-	return 0;
-}
Signature · 1 line
1.7.5.4
author
#19 lore raw

PATCH 8/8 ARM: mxs: remove now unused timer_clk argument from mxs_timer_init

In reply to Shawn Guo

With old mxs clock support removed, the timer_clk argument of mxs_timer_init is unused now, so remove it.

---
 arch/arm/mach-mxs/include/mach/common.h |    4 +---
 arch/arm/mach-mxs/timer.c               |   14 +++++++-------
 drivers/clk/mxs/clk-imx23.c             |    2 +-
 drivers/clk/mxs/clk-imx28.c             |    2 +-
 4 files changed, 10 insertions(+), 12 deletions(-)
arch/arm/mach-mxs/include/mach/common.h +1 -3
index e1237ab..9bdc953 100644
@@ -11,11 +11,9 @@
 #ifndef __MACH_MXS_COMMON_H__
 #define __MACH_MXS_COMMON_H__
 
-struct clk;
-
 extern const u32 *mxs_get_ocotp(void);
 extern int mxs_reset_block(void __iomem *);
-extern void mxs_timer_init(struct clk *, int);
+extern void mxs_timer_init(int);
 extern void mxs_restart(char, const char *);
 extern int mxs_saif_clkmux_select(unsigned int clkmux);
 
arch/arm/mach-mxs/timer.c +7 -7
index 575e8fd..02d36de 100644
@@ -244,14 +244,14 @@ static int __init mxs_clocksource_init(struct clk *timer_clk)
 	return 0;
 }
 
-void __init mxs_timer_init(struct clk *timer_clk, int irq)
+void __init mxs_timer_init(int irq)
 {
-	if (!timer_clk) {
-		timer_clk = clk_get_sys("timrot", NULL);
-		if (IS_ERR(timer_clk)) {
-			pr_err("%s: failed to get clk\n", __func__);
-			return;
-		}
+	struct clk *timer_clk;
+
+	timer_clk = clk_get_sys("timrot", NULL);
+	if (IS_ERR(timer_clk)) {
+		pr_err("%s: failed to get clk\n", __func__);
+		return;
 	}
 
 	clk_prepare_enable(timer_clk);
drivers/clk/mxs/clk-imx23.c +1 -1
index 6cce512..ef9c3cf 100644
@@ -189,7 +189,7 @@ int __init mx23_clocks_init(void)
 	if (ret)
 		return ret;
 
-	mxs_timer_init(NULL, MX23_INT_TIMER0);
+	mxs_timer_init(MX23_INT_TIMER0);
 
 	return 0;
 }
drivers/clk/mxs/clk-imx28.c +1 -1
index 0837f1d..70108cb 100644
@@ -312,7 +312,7 @@ int __init mx28_clocks_init(void)
 	if (ret)
 		return ret;
 
-	mxs_timer_init(NULL, MX28_INT_TIMER0);
+	mxs_timer_init(MX28_INT_TIMER0);
 
 	return 0;
 }
Signature · 1 line
1.7.5.4
#20 lore raw

cover common clk support for mxs

In reply to Shawn Guo
Quoted 5 lines · Shawn Guo

The mxs clock porting to common clk framework has been ready for a while. ?I was planning to post it after Mike's -next branch is published. ?Since the ETA of the branch is still uncertain while the series needs to take some time to go through the review process, I can not hold it for any longer, so here it is.

I have been waiting a bit on Saravana's changes to struct clk_hw, however I don't think that such a patch will break this series too badly. Your clk code doesn't rely too heavily on __clk_internal_function() too much, so you shouldn't be adversely affected.

Quoted 8 lines

It's based on v3.4-rc3 plus various fixup/cleanup patches that Mike confirmed pick-up on his -next branch and the clkdev one below.

?CLKDEV: Add helper routines to allocate and add clkdevs for given struct clk *

The series originally kept the code in arch/arm/mach-mxs. ?With Arnd's comment taken, I reworked it a bit to put it into drivers/clk/mxs in the same way that spear clock moves.

Most of the series looks good except for the minor issues I pointed out in the first three patches.

Which tree are you targeting this for? clk-next or arm-soc?

Thanks,
Mike

Quoted 37 lines

Shawn Guo (8):
? ? ?clk: mxs: add mxs specific clocks
? ? ?clk: mxs: add clock support for imx23
? ? ?clk: mxs: add clock support for imx28
? ? ?ARM: mxs: request clock for timer
? ? ?ARM: mxs: change the lookup name for fec phy clock
? ? ?ARM: mxs: switch to common clk framework
? ? ?ARM: mxs: remove old clock support
? ? ?ARM: mxs: remove now unused timer_clk argument from mxs_timer_init

?arch/arm/Kconfig ? ? ? ? ? ? ? ? ? ? ? ?| ? ?1 +
?arch/arm/mach-mxs/Makefile ? ? ? ? ? ? ?| ? ?5 +-
?arch/arm/mach-mxs/clock-mx23.c ? ? ? ? ?| ?536 ---------------------
?arch/arm/mach-mxs/clock-mx28.c ? ? ? ? ?| ?803 -------------------------------
?arch/arm/mach-mxs/clock.c ? ? ? ? ? ? ? | ?211 --------
?arch/arm/mach-mxs/include/mach/clock.h ?| ? 62 ---
?arch/arm/mach-mxs/include/mach/common.h | ? ?6 +-
?arch/arm/mach-mxs/mach-mx28evk.c ? ? ? ?| ? ?2 +-
?arch/arm/mach-mxs/regs-clkctrl-mx23.h ? | ?331 -------------
?arch/arm/mach-mxs/regs-clkctrl-mx28.h ? | ?486 -------------------
?arch/arm/mach-mxs/system.c ? ? ? ? ? ? ?| ? 16 -
?arch/arm/mach-mxs/timer.c ? ? ? ? ? ? ? | ? 11 +-
?drivers/clk/Makefile ? ? ? ? ? ? ? ? ? ?| ? ?2 +
?drivers/clk/mxs/Makefile ? ? ? ? ? ? ? ?| ? ?8 +
?drivers/clk/mxs/clk-div.c ? ? ? ? ? ? ? | ?102 ++++
?drivers/clk/mxs/clk-frac.c ? ? ? ? ? ? ?| ?127 +++++
?drivers/clk/mxs/clk-imx23.c ? ? ? ? ? ? | ?195 ++++++++
?drivers/clk/mxs/clk-imx28.c ? ? ? ? ? ? | ?318 ++++++++++++
?drivers/clk/mxs/clk-pll.c ? ? ? ? ? ? ? | ?123 +++++
?drivers/clk/mxs/clk-ref.c ? ? ? ? ? ? ? | ?139 ++++++
?drivers/clk/mxs/clk.h ? ? ? ? ? ? ? ? ? | ? 95 ++++

?21 files changed, 1123 insertions(+), 2456 deletions(-)

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#21 lore raw

cover common clk support for mxs

Quoted 5 lines · Mike

Most of the series looks good except for the minor issues I pointed out in the first three patches.

Which tree are you targeting this for? clk-next or arm-soc?

As Arnd is pushing us to move clock into drivers/clk, I would expect clk-next is the target tree.

Signature · 2 lines
Regards,
Shawn