Patchwork [U-Boot] da8xx: add support for multiple PLL controllers

login
register
mail settings
Submitter nagabhushana.netagunte@ti.com
Date July 28, 2011, 4:25 p.m.
Message ID <1311870338-18950-14-git-send-email-nagabhushana.netagunte@ti.com>
Download mbox | patch
Permalink /patch/107284/
State Changes Requested
Headers show

Comments

nagabhushana.netagunte@ti.com - July 28, 2011, 4:25 p.m.
From: Sudhakar Rajashekhara <sudhakar.raj@ti.com>

Add support for multiple PLL controllers  and in the process,
modify the clk_get() to work for multiple PLL controllers.

Signed-off-by: Sudhakar Rajashekhara <sudhakar.raj@ti.com>
Signed-off-by: Nagabhushana Netagunte <nagabhushana.netagunte@ti.com>
---
 arch/arm/cpu/arm926ejs/davinci/cpu.c         |   27 +++++++++++++++----------
 arch/arm/include/asm/arch-davinci/hardware.h |    1 +
 2 files changed, 17 insertions(+), 11 deletions(-)
Detlev Zundel - July 29, 2011, 8:41 a.m.
Hi,

[...]

> -	pre_div = (readl(&davinci_pllc_regs->prediv) &
> -		   DAVINCI_PLLC_DIV_MASK) + 1;
> -	pllm = readl(&davinci_pllc_regs->pllm) + 1;
> +	pre_div = (REG(pll_base + PLLC_PREDIV) & 0xff) + 1;
> +	pllm = REG(pll_base + PLLC_PLLM) + 1;

Nack - do not change "common" accessors into local macros.  We should
really strive to have a common base here.  See also

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/104428

Cheers
  Detlev
nagabhushana.netagunte@ti.com - Aug. 1, 2011, 9:47 a.m.
Detlev,
Thanks for your comments.
I will make appropriate changes to the patch.

-Nag
On Fri, Jul 29, 2011 at 14:11:41, Detlev Zundel wrote:
> Hi,
> 
> [...]
> 
> > -	pre_div = (readl(&davinci_pllc_regs->prediv) &
> > -		   DAVINCI_PLLC_DIV_MASK) + 1;
> > -	pllm = readl(&davinci_pllc_regs->pllm) + 1;
> > +	pre_div = (REG(pll_base + PLLC_PREDIV) & 0xff) + 1;
> > +	pllm = REG(pll_base + PLLC_PLLM) + 1;
> 
> Nack - do not change "common" accessors into local macros.  We should really strive to have a common base here.  See also
> 
> http://article.gmane.org/gmane.comp.boot-loaders.u-boot/104428
> 
> Cheers
>   Detlev
> 
> --
> He thinks he's really smooth, but he's only C^1.
> --
> DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu@denx.de
>

Patch

diff --git a/arch/arm/cpu/arm926ejs/davinci/cpu.c b/arch/arm/cpu/arm926ejs/davinci/cpu.c
index 8b57205..3ab56c7 100644
--- a/arch/arm/cpu/arm926ejs/davinci/cpu.c
+++ b/arch/arm/cpu/arm926ejs/davinci/cpu.c
@@ -37,6 +37,7 @@ 
 #define PLLC_PLLDIV4	0x160
 #define PLLC_PLLDIV5	0x164
 #define PLLC_PLLDIV6	0x168
+#define PLLC_PLLDIV7	0x16c
 #define PLLC_PLLDIV8	0x170
 #define PLLC_PLLDIV9	0x174
 
@@ -61,11 +62,9 @@ 
 #endif
 
 #ifdef CONFIG_SOC_DA8XX
-const dv_reg * const sysdiv[7] = {
-	&davinci_pllc_regs->plldiv1, &davinci_pllc_regs->plldiv2,
-	&davinci_pllc_regs->plldiv3, &davinci_pllc_regs->plldiv4,
-	&davinci_pllc_regs->plldiv5, &davinci_pllc_regs->plldiv6,
-	&davinci_pllc_regs->plldiv7
+unsigned int sysdiv[9] = {
+	PLLC_PLLDIV1, PLLC_PLLDIV2, PLLC_PLLDIV3, PLLC_PLLDIV4, PLLC_PLLDIV5,
+	PLLC_PLLDIV6, PLLC_PLLDIV7, PLLC_PLLDIV8, PLLC_PLLDIV9
 };
 
 int clk_get(enum davinci_clk_ids id)
@@ -74,19 +73,26 @@  int clk_get(enum davinci_clk_ids id)
 	int pllm;
 	int post_div;
 	int pll_out;
+	volatile unsigned int pll_base;
 
 	pll_out = CONFIG_SYS_OSCIN_FREQ;
 
 	if (id == DAVINCI_AUXCLK_CLKID)
 		goto out;
 
+	if ((id >> 16) == 1)
+		pll_base = DAVINCI_PLL_CNTRL1_BASE;
+	else
+		pll_base = DAVINCI_PLL_CNTRL0_BASE;
+
+	id &= 0xFFFF;
+
 	/*
 	 * Lets keep this simple. Combining operations can result in
 	 * unexpected approximations
 	 */
-	pre_div = (readl(&davinci_pllc_regs->prediv) &
-		   DAVINCI_PLLC_DIV_MASK) + 1;
-	pllm = readl(&davinci_pllc_regs->pllm) + 1;
+	pre_div = (REG(pll_base + PLLC_PREDIV) & 0xff) + 1;
+	pllm = REG(pll_base + PLLC_PLLM) + 1;
 
 	pll_out /= pre_div;
 	pll_out *= pllm;
@@ -94,15 +100,14 @@  int clk_get(enum davinci_clk_ids id)
 	if (id == DAVINCI_PLLM_CLKID)
 		goto out;
 
-	post_div = (readl(&davinci_pllc_regs->postdiv) &
-		    DAVINCI_PLLC_DIV_MASK) + 1;
+	post_div = (REG(pll_base + PLLC_POSTDIV) & 0xff) + 1;
 
 	pll_out /= post_div;
 
 	if (id == DAVINCI_PLLC_CLKID)
 		goto out;
 
-	pll_out /= (readl(sysdiv[id - 1]) & DAVINCI_PLLC_DIV_MASK) + 1;
+	pll_out /= (REG(pll_base + sysdiv[id - 1]) & 0xff) + 1;
 
 out:
 	return pll_out;
diff --git a/arch/arm/include/asm/arch-davinci/hardware.h b/arch/arm/include/asm/arch-davinci/hardware.h
index df3f549..d2b2989 100644
--- a/arch/arm/include/asm/arch-davinci/hardware.h
+++ b/arch/arm/include/asm/arch-davinci/hardware.h
@@ -129,6 +129,7 @@  typedef volatile unsigned int *	dv_reg_p;
 #define DAVINCI_TIMER1_BASE			0x01c21000
 #define DAVINCI_WDOG_BASE			0x01c21000
 #define DAVINCI_PLL_CNTRL0_BASE			0x01c11000
+#define DAVINCI_PLL_CNTRL1_BASE			0x01e1a000
 #define DAVINCI_PSC0_BASE			0x01c10000
 #define DAVINCI_PSC1_BASE			0x01e27000
 #define DAVINCI_SPI0_BASE			0x01c41000