]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - arch/arm/cpu/armv7/omap-common/clocks-common.c
Merge branch 'master' of git://git.denx.de/u-boot-usb
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / omap-common / clocks-common.c
index d36fcccafe03d0083bd0723a50386038cb92bc54..9ed18995ead3f1b4b8cff20b88f672b32807423c 100644 (file)
 #define puts(s)
 #endif
 
+const u32 sys_clk_array[8] = {
+       12000000,              /* 12 MHz */
+       13000000,              /* 13 MHz */
+       16800000,              /* 16.8 MHz */
+       19200000,              /* 19.2 MHz */
+       26000000,              /* 26 MHz */
+       27000000,              /* 27 MHz */
+       38400000,              /* 38.4 MHz */
+       20000000,               /* 20 MHz */
+};
+
 static inline u32 __get_sys_clk_index(void)
 {
-       u32 ind;
+       s8 ind;
        /*
         * For ES1 the ROM code calibration of sys clock is not reliable
         * due to hw issue. So, use hard-coded value. If this value is not
@@ -63,6 +74,13 @@ static inline u32 __get_sys_clk_index(void)
                /* SYS_CLKSEL - 1 to match the dpll param array indices */
                ind = (readl((*prcm)->cm_sys_clksel) &
                        CM_SYS_CLKSEL_SYS_CLKSEL_MASK) - 1;
+               /*
+                * SYS_CLKSEL value for 20MHz is 0. This is introduced newly
+                * in DRA7XX socs. SYS_CLKSEL -1 will be greater than
+                * NUM_SYS_CLK. So considering the last 3 bits as the index
+                * for the dpll param array.
+                */
+               ind &= CM_SYS_CLKSEL_SYS_CLKSEL_MASK;
        }
        return ind;
 }
@@ -76,6 +94,33 @@ u32 get_sys_clk_freq(void)
        return sys_clk_array[index];
 }
 
+void setup_post_dividers(u32 const base, const struct dpll_params *params)
+{
+       struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
+
+       /* Setup post-dividers */
+       if (params->m2 >= 0)
+               writel(params->m2, &dpll_regs->cm_div_m2_dpll);
+       if (params->m3 >= 0)
+               writel(params->m3, &dpll_regs->cm_div_m3_dpll);
+       if (params->m4_h11 >= 0)
+               writel(params->m4_h11, &dpll_regs->cm_div_m4_h11_dpll);
+       if (params->m5_h12 >= 0)
+               writel(params->m5_h12, &dpll_regs->cm_div_m5_h12_dpll);
+       if (params->m6_h13 >= 0)
+               writel(params->m6_h13, &dpll_regs->cm_div_m6_h13_dpll);
+       if (params->m7_h14 >= 0)
+               writel(params->m7_h14, &dpll_regs->cm_div_m7_h14_dpll);
+       if (params->h21 >= 0)
+               writel(params->h21, &dpll_regs->cm_div_h21_dpll);
+       if (params->h22 >= 0)
+               writel(params->h22, &dpll_regs->cm_div_h22_dpll);
+       if (params->h23 >= 0)
+               writel(params->h23, &dpll_regs->cm_div_h23_dpll);
+       if (params->h24 >= 0)
+               writel(params->h24, &dpll_regs->cm_div_h24_dpll);
+}
+
 static inline void do_bypass_dpll(u32 const base)
 {
        struct dpll_regs *dpll_regs = (struct dpll_regs *)base;
@@ -124,12 +169,65 @@ inline u32 check_for_lock(u32 const base)
        return lock;
 }
 
+const struct dpll_params *get_mpu_dpll_params(struct dplls const *dpll_data)
+{
+       u32 sysclk_ind = get_sys_clk_index();
+       return &dpll_data->mpu[sysclk_ind];
+}
+
+const struct dpll_params *get_core_dpll_params(struct dplls const *dpll_data)
+{
+       u32 sysclk_ind = get_sys_clk_index();
+       return &dpll_data->core[sysclk_ind];
+}
+
+const struct dpll_params *get_per_dpll_params(struct dplls const *dpll_data)
+{
+       u32 sysclk_ind = get_sys_clk_index();
+       return &dpll_data->per[sysclk_ind];
+}
+
+const struct dpll_params *get_iva_dpll_params(struct dplls const *dpll_data)
+{
+       u32 sysclk_ind = get_sys_clk_index();
+       return &dpll_data->iva[sysclk_ind];
+}
+
+const struct dpll_params *get_usb_dpll_params(struct dplls const *dpll_data)
+{
+       u32 sysclk_ind = get_sys_clk_index();
+       return &dpll_data->usb[sysclk_ind];
+}
+
+const struct dpll_params *get_abe_dpll_params(struct dplls const *dpll_data)
+{
+#ifdef CONFIG_SYS_OMAP_ABE_SYSCK
+       u32 sysclk_ind = get_sys_clk_index();
+       return &dpll_data->abe[sysclk_ind];
+#else
+       return dpll_data->abe;
+#endif
+}
+
+static const struct dpll_params *get_ddr_dpll_params
+                       (struct dplls const *dpll_data)
+{
+       u32 sysclk_ind = get_sys_clk_index();
+
+       if (!dpll_data->ddr)
+               return NULL;
+       return &dpll_data->ddr[sysclk_ind];
+}
+
 static void do_setup_dpll(u32 const base, const struct dpll_params *params,
                                u8 lock, char *dpll)
 {
        u32 temp, M, N;
        struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
 
+       if (!params)
+               return;
+
        temp = readl(&dpll_regs->cm_clksel_dpll);
 
        if (check_for_lock(base)) {
@@ -184,7 +282,7 @@ u32 omap_ddr_clk(void)
        omap_rev = omap_revision();
        sys_clk_khz = get_sys_clk_freq() / 1000;
 
-       core_dpll_params = get_core_dpll_params();
+       core_dpll_params = get_core_dpll_params(*dplls_data);
 
        debug("sys_clk %d\n ", sys_clk_khz * 1000);
 
@@ -246,12 +344,7 @@ void configure_mpu_dpll(void)
                        CM_CLKSEL_DCC_EN_MASK);
        }
 
-       setbits_le32((*prcm)->cm_mpu_mpu_clkctrl,
-               MPU_CLKCTRL_CLKSEL_EMIF_DIV_MODE_MASK);
-       setbits_le32((*prcm)->cm_mpu_mpu_clkctrl,
-               MPU_CLKCTRL_CLKSEL_ABE_DIV_MODE_MASK);
-
-       params = get_mpu_dpll_params();
+       params = get_mpu_dpll_params(*dplls_data);
 
        do_setup_dpll((*prcm)->cm_clkmode_dpll_mpu, params, DPLL_LOCK, "mpu");
        debug("MPU DPLL locked\n");
@@ -272,7 +365,7 @@ static void setup_usb_dpll(void)
         * Use CLKINP in KHz and adjust the denominator accordingly so
         * that we have enough accuracy and at the same time no overflow
         */
-       params = get_usb_dpll_params();
+       params = get_usb_dpll_params(*dplls_data);
        num = params->m * sys_clk_khz;
        den = (params->n + 1) * 250 * 1000;
        num += den - 1;
@@ -294,7 +387,7 @@ static void setup_dplls(void)
        debug("setup_dplls\n");
 
        /* CORE dpll */
-       params = get_core_dpll_params();        /* default - safest */
+       params = get_core_dpll_params(*dplls_data);     /* default - safest */
        /*
         * Do not lock the core DPLL now. Just set it up.
         * Core DPLL will be locked after setting up EMIF
@@ -314,7 +407,7 @@ static void setup_dplls(void)
        debug("Core DPLL configured\n");
 
        /* lock PER dpll */
-       params = get_per_dpll_params();
+       params = get_per_dpll_params(*dplls_data);
        do_setup_dpll((*prcm)->cm_clkmode_dpll_per,
                        params, DPLL_LOCK, "per");
        debug("PER DPLL locked\n");
@@ -325,6 +418,9 @@ static void setup_dplls(void)
 #ifdef CONFIG_USB_EHCI_OMAP
        setup_usb_dpll();
 #endif
+       params = get_ddr_dpll_params(*dplls_data);
+       do_setup_dpll((*prcm)->cm_clkmode_dpll_ddrphy,
+                     params, DPLL_LOCK, "ddr");
 }
 
 #ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL
@@ -337,11 +433,11 @@ static void setup_non_essential_dplls(void)
        clrsetbits_le32((*prcm)->cm_bypclk_dpll_iva,
                CM_BYPCLK_DPLL_IVA_CLKSEL_MASK, DPLL_IVA_CLKSEL_CORE_X2_DIV_2);
 
-       params = get_iva_dpll_params();
+       params = get_iva_dpll_params(*dplls_data);
        do_setup_dpll((*prcm)->cm_clkmode_dpll_iva, params, DPLL_LOCK, "iva");
 
        /* Configure ABE dpll */
-       params = get_abe_dpll_params();
+       params = get_abe_dpll_params(*dplls_data);
 #ifdef CONFIG_SYS_OMAP_ABE_SYSCK
        abe_ref_clk = CM_ABE_PLL_REF_CLKSEL_CLKSEL_SYSCLK;
 #else
@@ -370,44 +466,45 @@ static void setup_non_essential_dplls(void)
 }
 #endif
 
-void do_scale_tps62361(int gpio, u32 reg, u32 volt_mv)
+u32 get_offset_code(u32 volt_offset, struct pmic_data *pmic)
 {
-       u32 step;
-       int ret = 0;
-
-       /* See if we can first get the GPIO if needed */
-       if (gpio >= 0)
-               ret = gpio_request(gpio, "TPS62361_VSEL0_GPIO");
-       if (ret < 0) {
-               printf("%s: gpio %d request failed %d\n", __func__, gpio, ret);
-               gpio = -1;
-       }
-
-       /* Pull the GPIO low to select SET0 register, while we program SET1 */
-       if (gpio >= 0)
-               gpio_direction_output(gpio, 0);
+       u32 offset_code;
 
-       step = volt_mv - TPS62361_BASE_VOLT_MV;
-       step /= 10;
+       volt_offset -= pmic->base_offset;
 
-       debug("do_scale_tps62361: volt - %d step - 0x%x\n", volt_mv, step);
-       if (omap_vc_bypass_send_value(TPS62361_I2C_SLAVE_ADDR, reg, step))
-               puts("Scaling voltage failed for vdd_mpu from TPS\n");
+       offset_code = (volt_offset + pmic->step - 1) / pmic->step;
 
-       /* Pull the GPIO high to select SET1 register */
-       if (gpio >= 0)
-               gpio_direction_output(gpio, 1);
+       /*
+        * Offset codes 1-6 all give the base voltage in Palmas
+        * Offset code 0 switches OFF the SMPS
+        */
+       return offset_code + pmic->start_code;
 }
 
-void do_scale_vcore(u32 vcore_reg, u32 volt_mv)
+void do_scale_vcore(u32 vcore_reg, u32 volt_mv, struct pmic_data *pmic)
 {
        u32 offset_code;
        u32 offset = volt_mv;
+       int ret = 0;
+
+       /* See if we can first get the GPIO if needed */
+       if (pmic->gpio_en)
+               ret = gpio_request(pmic->gpio, "PMIC_GPIO");
+
+       if (ret < 0) {
+               printf("%s: gpio %d request failed %d\n", __func__,
+                                                       pmic->gpio, ret);
+               return;
+       }
+
+       /* Pull the GPIO low to select SET0 register, while we program SET1 */
+       if (pmic->gpio_en)
+               gpio_direction_output(pmic->gpio, 0);
 
        /* convert to uV for better accuracy in the calculations */
        offset *= 1000;
 
-       offset_code = get_offset_code(offset);
+       offset_code = get_offset_code(offset, pmic);
 
        debug("do_scale_vcore: volt - %d offset_code - 0x%x\n", volt_mv,
                offset_code);
@@ -415,6 +512,36 @@ void do_scale_vcore(u32 vcore_reg, u32 volt_mv)
        if (omap_vc_bypass_send_value(SMPS_I2C_SLAVE_ADDR,
                                vcore_reg, offset_code))
                printf("Scaling voltage failed for 0x%x\n", vcore_reg);
+
+       if (pmic->gpio_en)
+               gpio_direction_output(pmic->gpio, 1);
+}
+
+/*
+ * Setup the voltages for vdd_mpu, vdd_core, and vdd_iva
+ * We set the maximum voltages allowed here because Smart-Reflex is not
+ * enabled in bootloader. Voltage initialization in the kernel will set
+ * these to the nominal values after enabling Smart-Reflex
+ */
+void scale_vcores(struct vcores_data const *vcores)
+{
+       omap_vc_init(PRM_VC_I2C_CHANNEL_FREQ_KHZ);
+
+       do_scale_vcore(vcores->core.addr, vcores->core.value,
+                                         vcores->core.pmic);
+
+       do_scale_vcore(vcores->mpu.addr, vcores->mpu.value,
+                                         vcores->mpu.pmic);
+
+       do_scale_vcore(vcores->mm.addr, vcores->mm.value,
+                                         vcores->mm.pmic);
+
+        if (emif_sdram_type() == EMIF_SDRAM_TYPE_DDR3) {
+               /* Configure LDO SRAM "magic" bits */
+               writel(2, (*prcm)->prm_sldo_core_setup);
+               writel(2, (*prcm)->prm_sldo_mpu_setup);
+               writel(2, (*prcm)->prm_sldo_mm_setup);
+       }
 }
 
 static inline void enable_clock_domain(u32 const clkctrl_reg, u32 enable_mode)
@@ -459,7 +586,7 @@ void freq_update_core(void)
        const struct dpll_params *core_dpll_params;
        u32 omap_rev = omap_revision();
 
-       core_dpll_params = get_core_dpll_params();
+       core_dpll_params = get_core_dpll_params(*dplls_data);
        /* Put EMIF clock domain in sw wakeup mode */
        enable_clock_domain((*prcm)->cm_memif_clkstctrl,
                                CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
@@ -583,7 +710,7 @@ void prcm_init(void)
        case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
        case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
                enable_basic_clocks();
-               scale_vcores();
+               scale_vcores(*omap_vcores);
                setup_dplls();
 #ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL
                setup_non_essential_dplls();