Skip to contentSkip to conversation

Add common clock setting routine mpc52xx_psc_set_clkdiv()

PATCH Superseded Grant Likely 2 participants 2 messages Jan 9, 2008

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add common clock setting routine mpc52xx_psc_set_clkdiv()

From: Grant Likely <[email protected]>

PSC drivers should not access the CDM registers directly. Instead provide a common routine for setting the PSC clock parameters with the required locking.

---

 arch/powerpc/platforms/52xx/efika.c          |    3 +
 arch/powerpc/platforms/52xx/lite5200.c       |   10 +--
 arch/powerpc/platforms/52xx/mpc5200_simple.c |    6 +-
 arch/powerpc/platforms/52xx/mpc52xx_common.c |   90 +++++++++++++++++++++++---
 arch/ppc/syslib/mpc52xx_setup.c              |   36 ++++++++++
 include/asm-powerpc/mpc52xx.h                |   13 ++--
 6 files changed, 134 insertions(+), 24 deletions(-)
arch/powerpc/platforms/52xx/efika.c +3 -0
index a0da70c..a2068fa 100644
@@ -180,6 +180,9 @@ static void __init efika_setup_arch(void)
 {
 	rtas_initialize();
 
+	/* Map important registers from the internal memory map */
+	mpc52xx_map_common_devices();
+
 	efika_pcisetup();
 
 #ifdef CONFIG_PM
arch/powerpc/platforms/52xx/lite5200.c +5 -5
index f8ba5f2..42e87b6 100644
@@ -150,15 +150,15 @@ static void __init lite5200_setup_arch(void)
 	if (ppc_md.progress)
 		ppc_md.progress("lite5200_setup_arch()", 0);
 
-	/* Fix things that firmware should have done. */
-	lite5200_fix_clock_config();
-	lite5200_fix_port_config();
+	/* Map important registers from the internal memory map */
+	mpc52xx_map_common_devices();
 
 	/* Some mpc5200 & mpc5200b related configuration */
 	mpc5200_setup_xlb_arbiter();
 
-	/* Map wdt for mpc52xx_restart() */
-	mpc52xx_map_wdt();
+	/* Fix things that firmware should have done. */
+	lite5200_fix_clock_config();
+	lite5200_fix_port_config();
 
 #ifdef CONFIG_PM
 	mpc52xx_suspend.board_suspend_prepare = lite5200_suspend_prepare;
arch/powerpc/platforms/52xx/mpc5200_simple.c +3 -3
index 754aa93..c48b82b 100644
@@ -39,12 +39,12 @@ static void __init mpc5200_simple_setup_arch(void)
 	if (ppc_md.progress)
 		ppc_md.progress("mpc5200_simple_setup_arch()", 0);
 
+	/* Map important registers from the internal memory map */
+	mpc52xx_map_common_devices();
+
 	/* Some mpc5200 & mpc5200b related configuration */
 	mpc5200_setup_xlb_arbiter();
 
-	/* Map wdt for mpc52xx_restart() */
-	mpc52xx_map_wdt();
-
 	mpc52xx_setup_pci();
 }
 
arch/powerpc/platforms/52xx/mpc52xx_common.c +79 -11

138 lines not on this page · raw message

arch/ppc/syslib/mpc52xx_setup.c +36 -0
index ecfa2c0..57c9c87 100644
@@ -16,6 +16,7 @@
  */
 
 
+#include <linux/spinlock.h>
 #include <asm/io.h>
 #include <asm/time.h>
 #include <asm/mpc52xx.h>
@@ -275,3 +276,38 @@ int mpc52xx_match_psc_function(int psc_idx, const char *func)
 
 	return 0;
 }
+
+int mpc52xx_set_psc_clkdiv(int psc_id, int clkdiv)
+{
+	static spinlock_t lock = SPIN_LOCK_UNLOCKED;
+	struct mpc52xx_cdm __iomem *cdm;
+	unsigned long flags;
+	u16 mclken_div;
+	u16 __iomem *reg;
+	u32 mask;
+
+	cdm = ioremap(MPC52xx_PA(MPC52xx_CDM_OFFSET), MPC52xx_CDM_SIZE);
+	if (!cdm) {
+		printk(KERN_ERR __FILE__ ": Error mapping CDM\n");
+		return -ENODEV;
+	}
+
+	mclken_div = 0x8000 | (clkdiv & 0x1FF);
+	switch (psc_id) {
+	  case 1: reg = &cdm->mclken_div_psc1; mask = 0x20; break;
+	  case 2: reg = &cdm->mclken_div_psc2; mask = 0x40; break;
+	  case 3: reg = &cdm->mclken_div_psc3; mask = 0x80; break;
+	  case 6: reg = &cdm->mclken_div_psc6; mask = 0x10; break;
+	  default:
+	  	return -ENODEV;
+	}
+
+	/* Set the rate and enable the clock */
+	spin_lock_irqsave(&lock, flags);
+	out_be16(reg, mclken_div);
+	out_be32(&cdm->clk_enables, in_be32(&cdm->clk_enables) | mask);
+	spin_unlock_irqrestore(&lock, flags);
+
+	iounmap(cdm);
+	return 0;
+}
include/asm-powerpc/mpc52xx.h +8 -5
index 1c48c6d..c7a0710 100644
@@ -248,13 +248,19 @@ struct mpc52xx_cdm {
 
 #ifndef __ASSEMBLY__
 
+/* mpc52xx_common.c */
 extern unsigned int mpc52xx_find_ipb_freq(struct device_node *node);
-extern void mpc5200_setup_xlb_arbiter(void);
-extern void mpc52xx_declare_of_platform_devices(void);
+extern void __init mpc5200_setup_xlb_arbiter(void);
+extern void __init mpc52xx_declare_of_platform_devices(void);
+extern void __init mpc52xx_map_common_devices(void);
+extern int mpc52xx_set_psc_clkdiv(int psc_id, int clkdiv);
+extern void mpc52xx_restart(char *cmd);
 
+/* mpc52xx_pic.c */
 extern void mpc52xx_init_irq(void);
 extern unsigned int mpc52xx_get_irq(void);
 
+/* mpc52xx_pci.c */
 #ifdef CONFIG_PCI
 extern int __init mpc52xx_add_bridge(struct device_node *node);
 extern void __init mpc52xx_setup_pci(void);
@@ -262,9 +268,6 @@ extern void __init mpc52xx_setup_pci(void);
 static inline void mpc52xx_setup_pci(void) { }
 #endif
 
-extern void __init mpc52xx_map_wdt(void);
-extern void mpc52xx_restart(char *cmd);
-
 #endif /* __ASSEMBLY__ */
 
 #ifdef CONFIG_PM
#1 lore raw

Hi Grant,

Just a couple of trivial things.

arch/powerpc/platforms/52xx/mpc52xx_common.c mpc52xx_declare_of_platform_devices(void) · line 192

Quoted 11 lines · On Tue, 08 Jan 2008 22:09:50 -0700 Grant Likely <[email protected]>…
arch/powerpc/platforms/52xx/mpc52xx_common.c +9 -0
+int mpc52xx_set_psc_clkdiv(int psc_id, int clkdiv)
 
+	switch (psc_id) {
+	  case 1: reg = &mpc52xx_cdm->mclken_div_psc1; mask = 0x20; break;
+	  case 2: reg = &mpc52xx_cdm->mclken_div_psc2; mask = 0x40; break;
+	  case 3: reg = &mpc52xx_cdm->mclken_div_psc3; mask = 0x80; break;
+	  case 6: reg = &mpc52xx_cdm->mclken_div_psc6; mask = 0x10; break;
+	  default:
+		return -ENODEV;
+	}

We line up case labels with the switch statement itself.

arch/ppc/syslib/mpc52xx_setup.c int mpc52xx_match_psc_function(int psc_idx, const char *func) · line 303

Quoted 10 lines
arch/ppc/syslib/mpc52xx_setup.c +9 -0
+int mpc52xx_set_psc_clkdiv(int psc_id, int clkdiv)
 
+	switch (psc_id) {
+	  case 1: reg = &cdm->mclken_div_psc1; mask = 0x20; break;
+	  case 2: reg = &cdm->mclken_div_psc2; mask = 0x40; break;
+	  case 3: reg = &cdm->mclken_div_psc3; mask = 0x80; break;
+	  case 6: reg = &cdm->mclken_div_psc6; mask = 0x10; break;
+	  default:
+	  	return -ENODEV;
+	}

Here as well.

include/asm-powerpc/mpc52xx.h struct mpc52xx_cdm { · line 255

Quoted 6 lines

+++ b/include/asm-powerpc/mpc52xx.h

include/asm-powerpc/mpc52xx.h +3 -2
-extern void mpc5200_setup_xlb_arbiter(void);
-extern void mpc52xx_declare_of_platform_devices(void);
+extern void __init mpc5200_setup_xlb_arbiter(void);
+extern void __init mpc52xx_declare_of_platform_devices(void);
+extern void __init mpc52xx_map_common_devices(void);

We don't mark things __init in header files. It is unnecessary and can get out of sync - which causes unexpected results.

Quoted 4 lines

+/* mpc52xx_pci.c */
#ifdef CONFIG_PCI
extern int __init mpc52xx_add_bridge(struct device_node *node); extern void __init mpc52xx_setup_pci(void);

I see where yours above came from ...

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/