tizen 2.3.1 release
[platform/kernel/u-boot.git] / arch / arm / cpu / arm926ejs / davinci / cpu.c
index ff61147..8b57205 100644 (file)
@@ -2,7 +2,22 @@
  * Copyright (C) 2004 Texas Instruments.
  * Copyright (C) 2009 David Brownell
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <common.h>
@@ -10,8 +25,6 @@
 #include <asm/arch/hardware.h>
 #include <asm/io.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 /* offsets from PLL controller base */
 #define PLLC_PLLCTL    0x100
 #define PLLC_PLLM      0x110
@@ -24,7 +37,6 @@ DECLARE_GLOBAL_DATA_PTR;
 #define PLLC_PLLDIV4   0x160
 #define PLLC_PLLDIV5   0x164
 #define PLLC_PLLDIV6   0x168
-#define PLLC_PLLDIV7   0x16c
 #define PLLC_PLLDIV8   0x170
 #define PLLC_PLLDIV9   0x174
 
@@ -49,9 +61,11 @@ DECLARE_GLOBAL_DATA_PTR;
 #endif
 
 #ifdef CONFIG_SOC_DA8XX
-unsigned int sysdiv[9] = {
-       PLLC_PLLDIV1, PLLC_PLLDIV2, PLLC_PLLDIV3, PLLC_PLLDIV4, PLLC_PLLDIV5,
-       PLLC_PLLDIV6, PLLC_PLLDIV7, PLLC_PLLDIV8, PLLC_PLLDIV9
+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
 };
 
 int clk_get(enum davinci_clk_ids id)
@@ -60,27 +74,19 @@ int clk_get(enum davinci_clk_ids id)
        int pllm;
        int post_div;
        int pll_out;
-       unsigned int pll_base;
 
        pll_out = CONFIG_SYS_OSCIN_FREQ;
 
        if (id == DAVINCI_AUXCLK_CLKID)
                goto out;
 
-       if ((id >> 16) == 1)
-               pll_base = (unsigned int)davinci_pllc1_regs;
-       else
-               pll_base = (unsigned int)davinci_pllc0_regs;
-
-       id &= 0xFFFF;
-
        /*
         * Lets keep this simple. Combining operations can result in
         * unexpected approximations
         */
-       pre_div = (readl(pll_base + PLLC_PREDIV) &
-               DAVINCI_PLLC_DIV_MASK) + 1;
-       pllm = readl(pll_base + PLLC_PLLM) + 1;
+       pre_div = (readl(&davinci_pllc_regs->prediv) &
+                  DAVINCI_PLLC_DIV_MASK) + 1;
+       pllm = readl(&davinci_pllc_regs->pllm) + 1;
 
        pll_out /= pre_div;
        pll_out *= pllm;
@@ -88,32 +94,22 @@ int clk_get(enum davinci_clk_ids id)
        if (id == DAVINCI_PLLM_CLKID)
                goto out;
 
-       post_div = (readl(pll_base + PLLC_POSTDIV) &
-               DAVINCI_PLLC_DIV_MASK) + 1;
+       post_div = (readl(&davinci_pllc_regs->postdiv) &
+                   DAVINCI_PLLC_DIV_MASK) + 1;
 
        pll_out /= post_div;
 
        if (id == DAVINCI_PLLC_CLKID)
                goto out;
 
-       pll_out /= (readl(pll_base + sysdiv[id - 1]) &
-               DAVINCI_PLLC_DIV_MASK) + 1;
+       pll_out /= (readl(sysdiv[id - 1]) & DAVINCI_PLLC_DIV_MASK) + 1;
 
 out:
        return pll_out;
 }
+#endif /* CONFIG_SOC_DA8XX */
 
-int set_cpu_clk_info(void)
-{
-       gd->bd->bi_arm_freq = clk_get(DAVINCI_ARM_CLKID) / 1000000;
-       /* DDR PHY uses an x2 input clock */
-       gd->bd->bi_ddr_freq = cpu_is_da830() ? 0 :
-                               (clk_get(DAVINCI_DDR_CLKID) / 1000000);
-       gd->bd->bi_dsp_freq = 0;
-       return 0;
-}
-
-#else /* CONFIG_SOC_DA8XX */
+#ifdef CONFIG_DISPLAY_CPUINFO
 
 static unsigned pll_div(volatile void *pllbase, unsigned offset)
 {
@@ -131,15 +127,13 @@ static inline unsigned pll_prediv(volatile void *pllbase)
                return 8;
        else
                return pll_div(pllbase, PLLC_PREDIV);
-#elif defined(CONFIG_SOC_DM365)
-       return pll_div(pllbase, PLLC_PREDIV);
 #endif
        return 1;
 }
 
 static inline unsigned pll_postdiv(volatile void *pllbase)
 {
-#if defined(CONFIG_SOC_DM355) || defined(CONFIG_SOC_DM365)
+#ifdef CONFIG_SOC_DM355
        return pll_div(pllbase, PLLC_POSTDIV);
 #elif defined(CONFIG_SOC_DM6446)
        if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
@@ -152,63 +146,47 @@ static unsigned pll_sysclk_mhz(unsigned pll_addr, unsigned div)
 {
        volatile void   *pllbase = (volatile void *) pll_addr;
 #ifdef CONFIG_SOC_DM646X
-       unsigned        base = CONFIG_REFCLK_FREQ / 1000;
+       unsigned        base = CFG_REFCLK_FREQ / 1000;
 #else
        unsigned        base = CONFIG_SYS_HZ_CLOCK / 1000;
 #endif
 
        /* the PLL might be bypassed */
-       if (readl(pllbase + PLLC_PLLCTL) & BIT(0)) {
+       if (REG(pllbase + PLLC_PLLCTL) & BIT(0)) {
                base /= pll_prediv(pllbase);
-#if defined(CONFIG_SOC_DM365)
-               base *=  2 * (readl(pllbase + PLLC_PLLM) & 0x0ff);
-#else
                base *= 1 + (REG(pllbase + PLLC_PLLM) & 0x0ff);
-#endif
                base /= pll_postdiv(pllbase);
        }
        return DIV_ROUND_UP(base, 1000 * pll_div(pllbase, div));
 }
 
-#ifdef DAVINCI_DM6467EVM
-unsigned int davinci_arm_clk_get()
+int print_cpuinfo(void)
 {
-       return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV) * 1000000;
-}
-#endif
-
-#if defined(CONFIG_SOC_DM365)
-unsigned int davinci_clk_get(unsigned int div)
-{
-       return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, div) * 1000000;
-}
-#endif
-
-int set_cpu_clk_info(void)
-{
-       unsigned int pllbase = DAVINCI_PLL_CNTRL0_BASE;
-#if defined(CONFIG_SOC_DM365)
-       pllbase = DAVINCI_PLL_CNTRL1_BASE;
-#endif
-       gd->bd->bi_arm_freq = pll_sysclk_mhz(pllbase, ARM_PLLDIV);
+       /* REVISIT fetch and display CPU ID and revision information
+        * too ... that will matter as more revisions appear.
+        */
+       printf("Cores: ARM %d MHz",
+                       pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV));
 
 #ifdef DSP_PLLDIV
-       gd->bd->bi_dsp_freq =
-               pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DSP_PLLDIV);
-#else
-       gd->bd->bi_dsp_freq = 0;
+       printf(", DSP %d MHz",
+                       pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DSP_PLLDIV));
 #endif
 
-       pllbase = DAVINCI_PLL_CNTRL1_BASE;
-#if defined(CONFIG_SOC_DM365)
-       pllbase = DAVINCI_PLL_CNTRL0_BASE;
-#endif
-       gd->bd->bi_ddr_freq = pll_sysclk_mhz(pllbase, DDR_PLLDIV) / 2;
-
+       printf("\nDDR:   %d MHz\n",
+                       /* DDR PHY uses an x2 input clock */
+                       pll_sysclk_mhz(DAVINCI_PLL_CNTRL1_BASE, DDR_PLLDIV)
+                               / 2);
        return 0;
 }
 
-#endif /* !CONFIG_SOC_DA8XX */
+#ifdef DAVINCI_DM6467EVM
+unsigned int davinci_arm_clk_get()
+{
+       return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV) * 1000000;
+}
+#endif
+#endif
 
 /*
  * Initializes on-chip ethernet controllers.