uboot/arch/arm/cpu/armv7/exynos/clock_init_exynos5.c
<<
>>
Prefs
   1/*
   2 * Clock setup for SMDK5250 board based on EXYNOS5
   3 *
   4 * Copyright (C) 2012 Samsung Electronics
   5 *
   6 * SPDX-License-Identifier:     GPL-2.0+
   7 */
   8
   9#include <common.h>
  10#include <config.h>
  11#include <asm/io.h>
  12#include <asm/arch/clk.h>
  13#include <asm/arch/clock.h>
  14#include <asm/arch/spl.h>
  15#include <asm/arch/dwmmc.h>
  16
  17#include "clock_init.h"
  18#include "common_setup.h"
  19#include "exynos5_setup.h"
  20
  21#define FSYS1_MMC0_DIV_MASK     0xff0f
  22#define FSYS1_MMC0_DIV_VAL      0x0701
  23
  24DECLARE_GLOBAL_DATA_PTR;
  25
  26struct arm_clk_ratios arm_clk_ratios[] = {
  27#ifdef CONFIG_EXYNOS5420
  28        {
  29                .arm_freq_mhz = 900,
  30
  31                .apll_mdiv = 0x96,
  32                .apll_pdiv = 0x2,
  33                .apll_sdiv = 0x1,
  34
  35                .arm2_ratio = 0x0,
  36                .apll_ratio = 0x3,
  37                .pclk_dbg_ratio = 0x6,
  38                .atb_ratio = 0x6,
  39                .periph_ratio = 0x7,
  40                .acp_ratio = 0x0,
  41                .cpud_ratio = 0x2,
  42                .arm_ratio = 0x0,
  43        }
  44#else
  45        {
  46                .arm_freq_mhz = 600,
  47
  48                .apll_mdiv = 0xc8,
  49                .apll_pdiv = 0x4,
  50                .apll_sdiv = 0x1,
  51
  52                .arm2_ratio = 0x0,
  53                .apll_ratio = 0x1,
  54                .pclk_dbg_ratio = 0x1,
  55                .atb_ratio = 0x2,
  56                .periph_ratio = 0x7,
  57                .acp_ratio = 0x7,
  58                .cpud_ratio = 0x1,
  59                .arm_ratio = 0x0,
  60        }, {
  61                .arm_freq_mhz = 800,
  62
  63                .apll_mdiv = 0x64,
  64                .apll_pdiv = 0x3,
  65                .apll_sdiv = 0x0,
  66
  67                .arm2_ratio = 0x0,
  68                .apll_ratio = 0x1,
  69                .pclk_dbg_ratio = 0x1,
  70                .atb_ratio = 0x3,
  71                .periph_ratio = 0x7,
  72                .acp_ratio = 0x7,
  73                .cpud_ratio = 0x2,
  74                .arm_ratio = 0x0,
  75        }, {
  76                .arm_freq_mhz = 1000,
  77
  78                .apll_mdiv = 0x7d,
  79                .apll_pdiv = 0x3,
  80                .apll_sdiv = 0x0,
  81
  82                .arm2_ratio = 0x0,
  83                .apll_ratio = 0x1,
  84                .pclk_dbg_ratio = 0x1,
  85                .atb_ratio = 0x4,
  86                .periph_ratio = 0x7,
  87                .acp_ratio = 0x7,
  88                .cpud_ratio = 0x2,
  89                .arm_ratio = 0x0,
  90        }, {
  91                .arm_freq_mhz = 1200,
  92
  93                .apll_mdiv = 0x96,
  94                .apll_pdiv = 0x3,
  95                .apll_sdiv = 0x0,
  96
  97                .arm2_ratio = 0x0,
  98                .apll_ratio = 0x3,
  99                .pclk_dbg_ratio = 0x1,
 100                .atb_ratio = 0x5,
 101                .periph_ratio = 0x7,
 102                .acp_ratio = 0x7,
 103                .cpud_ratio = 0x3,
 104                .arm_ratio = 0x0,
 105        }, {
 106                .arm_freq_mhz = 1400,
 107
 108                .apll_mdiv = 0xaf,
 109                .apll_pdiv = 0x3,
 110                .apll_sdiv = 0x0,
 111
 112                .arm2_ratio = 0x0,
 113                .apll_ratio = 0x3,
 114                .pclk_dbg_ratio = 0x1,
 115                .atb_ratio = 0x6,
 116                .periph_ratio = 0x7,
 117                .acp_ratio = 0x7,
 118                .cpud_ratio = 0x3,
 119                .arm_ratio = 0x0,
 120        }, {
 121                .arm_freq_mhz = 1700,
 122
 123                .apll_mdiv = 0x1a9,
 124                .apll_pdiv = 0x6,
 125                .apll_sdiv = 0x0,
 126
 127                .arm2_ratio = 0x0,
 128                .apll_ratio = 0x3,
 129                .pclk_dbg_ratio = 0x1,
 130                .atb_ratio = 0x6,
 131                .periph_ratio = 0x7,
 132                .acp_ratio = 0x7,
 133                .cpud_ratio = 0x3,
 134                .arm_ratio = 0x0,
 135        }
 136#endif
 137};
 138
 139struct mem_timings mem_timings[] = {
 140#ifdef CONFIG_EXYNOS5420
 141        {
 142                .mem_manuf = MEM_MANUF_SAMSUNG,
 143                .mem_type = DDR_MODE_DDR3,
 144                .frequency_mhz = 800,
 145
 146                /* MPLL @800MHz*/
 147                .mpll_mdiv = 0xc8,
 148                .mpll_pdiv = 0x3,
 149                .mpll_sdiv = 0x1,
 150                /* CPLL @666MHz */
 151                .cpll_mdiv = 0xde,
 152                .cpll_pdiv = 0x4,
 153                .cpll_sdiv = 0x1,
 154                /* EPLL @600MHz */
 155                .epll_mdiv = 0x64,
 156                .epll_pdiv = 0x2,
 157                .epll_sdiv = 0x1,
 158                /* VPLL @430MHz */
 159                .vpll_mdiv = 0xd7,
 160                .vpll_pdiv = 0x3,
 161                .vpll_sdiv = 0x2,
 162                /* BPLL @800MHz */
 163                .bpll_mdiv = 0xc8,
 164                .bpll_pdiv = 0x3,
 165                .bpll_sdiv = 0x1,
 166                /* KPLL @600MHz */
 167                .kpll_mdiv = 0x190,
 168                .kpll_pdiv = 0x4,
 169                .kpll_sdiv = 0x2,
 170                /* DPLL @600MHz */
 171                .dpll_mdiv = 0x190,
 172                .dpll_pdiv = 0x4,
 173                .dpll_sdiv = 0x2,
 174                /* IPLL @370MHz */
 175                .ipll_mdiv = 0xb9,
 176                .ipll_pdiv = 0x3,
 177                .ipll_sdiv = 0x2,
 178                /* SPLL @400MHz */
 179                .spll_mdiv = 0xc8,
 180                .spll_pdiv = 0x3,
 181                .spll_sdiv = 0x2,
 182
 183                .direct_cmd_msr = {
 184                        0x00020018, 0x00030000, 0x00010046, 0x00000d70,
 185                        0x00000c70
 186                },
 187                .timing_ref = 0x000000bb,
 188                .timing_row = 0x6836650f,
 189                .timing_data = 0x3630580b,
 190                .timing_power = 0x41000a26,
 191                .phy0_dqs = 0x08080808,
 192                .phy1_dqs = 0x08080808,
 193                .phy0_dq = 0x08080808,
 194                .phy1_dq = 0x08080808,
 195                .phy0_tFS = 0x8,
 196                .phy1_tFS = 0x8,
 197                .phy0_pulld_dqs = 0xf,
 198                .phy1_pulld_dqs = 0xf,
 199
 200                .lpddr3_ctrl_phy_reset = 0x1,
 201                .ctrl_start_point = 0x10,
 202                .ctrl_inc = 0x10,
 203                .ctrl_start = 0x1,
 204                .ctrl_dll_on = 0x1,
 205                .ctrl_ref = 0x8,
 206
 207                .ctrl_force = 0x1a,
 208                .ctrl_rdlat = 0x0b,
 209                .ctrl_bstlen = 0x08,
 210
 211                .fp_resync = 0x8,
 212                .iv_size = 0x7,
 213                .dfi_init_start = 1,
 214                .aref_en = 1,
 215
 216                .rd_fetch = 0x3,
 217
 218                .zq_mode_dds = 0x7,
 219                .zq_mode_term = 0x1,
 220                .zq_mode_noterm = 1,
 221
 222                /*
 223                * Dynamic Clock: Always Running
 224                * Memory Burst length: 8
 225                * Number of chips: 1
 226                * Memory Bus width: 32 bit
 227                * Memory Type: DDR3
 228                * Additional Latancy for PLL: 0 Cycle
 229                */
 230                .memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
 231                        DMC_MEMCONTROL_DPWRDN_DISABLE |
 232                        DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
 233                        DMC_MEMCONTROL_TP_DISABLE |
 234                        DMC_MEMCONTROL_DSREF_DISABLE |
 235                        DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
 236                        DMC_MEMCONTROL_MEM_TYPE_DDR3 |
 237                        DMC_MEMCONTROL_MEM_WIDTH_32BIT |
 238                        DMC_MEMCONTROL_NUM_CHIP_1 |
 239                        DMC_MEMCONTROL_BL_8 |
 240                        DMC_MEMCONTROL_PZQ_DISABLE |
 241                        DMC_MEMCONTROL_MRR_BYTE_7_0,
 242                .memconfig = DMC_MEMCONFIG_CHIP_MAP_SPLIT |
 243                        DMC_MEMCONFIGX_CHIP_COL_10 |
 244                        DMC_MEMCONFIGX_CHIP_ROW_15 |
 245                        DMC_MEMCONFIGX_CHIP_BANK_8,
 246                .prechconfig_tp_cnt = 0xff,
 247                .dpwrdn_cyc = 0xff,
 248                .dsref_cyc = 0xffff,
 249                .concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
 250                        DMC_CONCONTROL_TIMEOUT_LEVEL0 |
 251                        DMC_CONCONTROL_RD_FETCH_DISABLE |
 252                        DMC_CONCONTROL_EMPTY_DISABLE |
 253                        DMC_CONCONTROL_AREF_EN_DISABLE |
 254                        DMC_CONCONTROL_IO_PD_CON_DISABLE,
 255                .dmc_channels = 1,
 256                .chips_per_channel = 1,
 257                .chips_to_configure = 1,
 258                .send_zq_init = 1,
 259                .gate_leveling_enable = 1,
 260                .read_leveling_enable = 0,
 261        }
 262#else
 263        {
 264                .mem_manuf = MEM_MANUF_ELPIDA,
 265                .mem_type = DDR_MODE_DDR3,
 266                .frequency_mhz = 800,
 267                .mpll_mdiv = 0xc8,
 268                .mpll_pdiv = 0x3,
 269                .mpll_sdiv = 0x0,
 270                .cpll_mdiv = 0xde,
 271                .cpll_pdiv = 0x4,
 272                .cpll_sdiv = 0x2,
 273                .gpll_mdiv = 0x215,
 274                .gpll_pdiv = 0xc,
 275                .gpll_sdiv = 0x1,
 276                .epll_mdiv = 0x60,
 277                .epll_pdiv = 0x3,
 278                .epll_sdiv = 0x3,
 279                .vpll_mdiv = 0x96,
 280                .vpll_pdiv = 0x3,
 281                .vpll_sdiv = 0x2,
 282
 283                .bpll_mdiv = 0x64,
 284                .bpll_pdiv = 0x3,
 285                .bpll_sdiv = 0x0,
 286                .pclk_cdrex_ratio = 0x5,
 287                .direct_cmd_msr = {
 288                        0x00020018, 0x00030000, 0x00010042, 0x00000d70
 289                },
 290                .timing_ref = 0x000000bb,
 291                .timing_row = 0x8c36650e,
 292                .timing_data = 0x3630580b,
 293                .timing_power = 0x41000a44,
 294                .phy0_dqs = 0x08080808,
 295                .phy1_dqs = 0x08080808,
 296                .phy0_dq = 0x08080808,
 297                .phy1_dq = 0x08080808,
 298                .phy0_tFS = 0x4,
 299                .phy1_tFS = 0x4,
 300                .phy0_pulld_dqs = 0xf,
 301                .phy1_pulld_dqs = 0xf,
 302
 303                .lpddr3_ctrl_phy_reset = 0x1,
 304                .ctrl_start_point = 0x10,
 305                .ctrl_inc = 0x10,
 306                .ctrl_start = 0x1,
 307                .ctrl_dll_on = 0x1,
 308                .ctrl_ref = 0x8,
 309
 310                .ctrl_force = 0x1a,
 311                .ctrl_rdlat = 0x0b,
 312                .ctrl_bstlen = 0x08,
 313
 314                .fp_resync = 0x8,
 315                .iv_size = 0x7,
 316                .dfi_init_start = 1,
 317                .aref_en = 1,
 318
 319                .rd_fetch = 0x3,
 320
 321                .zq_mode_dds = 0x7,
 322                .zq_mode_term = 0x1,
 323                .zq_mode_noterm = 0,
 324
 325                /*
 326                * Dynamic Clock: Always Running
 327                * Memory Burst length: 8
 328                * Number of chips: 1
 329                * Memory Bus width: 32 bit
 330                * Memory Type: DDR3
 331                * Additional Latancy for PLL: 0 Cycle
 332                */
 333                .memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
 334                        DMC_MEMCONTROL_DPWRDN_DISABLE |
 335                        DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
 336                        DMC_MEMCONTROL_TP_DISABLE |
 337                        DMC_MEMCONTROL_DSREF_ENABLE |
 338                        DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
 339                        DMC_MEMCONTROL_MEM_TYPE_DDR3 |
 340                        DMC_MEMCONTROL_MEM_WIDTH_32BIT |
 341                        DMC_MEMCONTROL_NUM_CHIP_1 |
 342                        DMC_MEMCONTROL_BL_8 |
 343                        DMC_MEMCONTROL_PZQ_DISABLE |
 344                        DMC_MEMCONTROL_MRR_BYTE_7_0,
 345                .memconfig = DMC_MEMCONFIGX_CHIP_MAP_INTERLEAVED |
 346                        DMC_MEMCONFIGX_CHIP_COL_10 |
 347                        DMC_MEMCONFIGX_CHIP_ROW_15 |
 348                        DMC_MEMCONFIGX_CHIP_BANK_8,
 349                .membaseconfig0 = DMC_MEMBASECONFIG_VAL(0x40),
 350                .membaseconfig1 = DMC_MEMBASECONFIG_VAL(0x80),
 351                .prechconfig_tp_cnt = 0xff,
 352                .dpwrdn_cyc = 0xff,
 353                .dsref_cyc = 0xffff,
 354                .concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
 355                        DMC_CONCONTROL_TIMEOUT_LEVEL0 |
 356                        DMC_CONCONTROL_RD_FETCH_DISABLE |
 357                        DMC_CONCONTROL_EMPTY_DISABLE |
 358                        DMC_CONCONTROL_AREF_EN_DISABLE |
 359                        DMC_CONCONTROL_IO_PD_CON_DISABLE,
 360                .dmc_channels = 2,
 361                .chips_per_channel = 2,
 362                .chips_to_configure = 1,
 363                .send_zq_init = 1,
 364                .impedance = IMP_OUTPUT_DRV_30_OHM,
 365                .gate_leveling_enable = 0,
 366        }, {
 367                .mem_manuf = MEM_MANUF_SAMSUNG,
 368                .mem_type = DDR_MODE_DDR3,
 369                .frequency_mhz = 800,
 370                .mpll_mdiv = 0xc8,
 371                .mpll_pdiv = 0x3,
 372                .mpll_sdiv = 0x0,
 373                .cpll_mdiv = 0xde,
 374                .cpll_pdiv = 0x4,
 375                .cpll_sdiv = 0x2,
 376                .gpll_mdiv = 0x215,
 377                .gpll_pdiv = 0xc,
 378                .gpll_sdiv = 0x1,
 379                .epll_mdiv = 0x60,
 380                .epll_pdiv = 0x3,
 381                .epll_sdiv = 0x3,
 382                .vpll_mdiv = 0x96,
 383                .vpll_pdiv = 0x3,
 384                .vpll_sdiv = 0x2,
 385
 386                .bpll_mdiv = 0x64,
 387                .bpll_pdiv = 0x3,
 388                .bpll_sdiv = 0x0,
 389                .pclk_cdrex_ratio = 0x5,
 390                .direct_cmd_msr = {
 391                        0x00020018, 0x00030000, 0x00010000, 0x00000d70
 392                },
 393                .timing_ref = 0x000000bb,
 394                .timing_row = 0x8c36650e,
 395                .timing_data = 0x3630580b,
 396                .timing_power = 0x41000a44,
 397                .phy0_dqs = 0x08080808,
 398                .phy1_dqs = 0x08080808,
 399                .phy0_dq = 0x08080808,
 400                .phy1_dq = 0x08080808,
 401                .phy0_tFS = 0x8,
 402                .phy1_tFS = 0x8,
 403                .phy0_pulld_dqs = 0xf,
 404                .phy1_pulld_dqs = 0xf,
 405
 406                .lpddr3_ctrl_phy_reset = 0x1,
 407                .ctrl_start_point = 0x10,
 408                .ctrl_inc = 0x10,
 409                .ctrl_start = 0x1,
 410                .ctrl_dll_on = 0x1,
 411                .ctrl_ref = 0x8,
 412
 413                .ctrl_force = 0x1a,
 414                .ctrl_rdlat = 0x0b,
 415                .ctrl_bstlen = 0x08,
 416
 417                .fp_resync = 0x8,
 418                .iv_size = 0x7,
 419                .dfi_init_start = 1,
 420                .aref_en = 1,
 421
 422                .rd_fetch = 0x3,
 423
 424                .zq_mode_dds = 0x5,
 425                .zq_mode_term = 0x1,
 426                .zq_mode_noterm = 1,
 427
 428                /*
 429                * Dynamic Clock: Always Running
 430                * Memory Burst length: 8
 431                * Number of chips: 1
 432                * Memory Bus width: 32 bit
 433                * Memory Type: DDR3
 434                * Additional Latancy for PLL: 0 Cycle
 435                */
 436                .memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
 437                        DMC_MEMCONTROL_DPWRDN_DISABLE |
 438                        DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
 439                        DMC_MEMCONTROL_TP_DISABLE |
 440                        DMC_MEMCONTROL_DSREF_ENABLE |
 441                        DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
 442                        DMC_MEMCONTROL_MEM_TYPE_DDR3 |
 443                        DMC_MEMCONTROL_MEM_WIDTH_32BIT |
 444                        DMC_MEMCONTROL_NUM_CHIP_1 |
 445                        DMC_MEMCONTROL_BL_8 |
 446                        DMC_MEMCONTROL_PZQ_DISABLE |
 447                        DMC_MEMCONTROL_MRR_BYTE_7_0,
 448                .memconfig = DMC_MEMCONFIGX_CHIP_MAP_INTERLEAVED |
 449                        DMC_MEMCONFIGX_CHIP_COL_10 |
 450                        DMC_MEMCONFIGX_CHIP_ROW_15 |
 451                        DMC_MEMCONFIGX_CHIP_BANK_8,
 452                .membaseconfig0 = DMC_MEMBASECONFIG_VAL(0x40),
 453                .membaseconfig1 = DMC_MEMBASECONFIG_VAL(0x80),
 454                .prechconfig_tp_cnt = 0xff,
 455                .dpwrdn_cyc = 0xff,
 456                .dsref_cyc = 0xffff,
 457                .concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
 458                        DMC_CONCONTROL_TIMEOUT_LEVEL0 |
 459                        DMC_CONCONTROL_RD_FETCH_DISABLE |
 460                        DMC_CONCONTROL_EMPTY_DISABLE |
 461                        DMC_CONCONTROL_AREF_EN_DISABLE |
 462                        DMC_CONCONTROL_IO_PD_CON_DISABLE,
 463                .dmc_channels = 2,
 464                .chips_per_channel = 2,
 465                .chips_to_configure = 1,
 466                .send_zq_init = 1,
 467                .impedance = IMP_OUTPUT_DRV_40_OHM,
 468                .gate_leveling_enable = 1,
 469        }
 470#endif
 471};
 472
 473/**
 474 * Get the required memory type and speed (SPL version).
 475 *
 476 * In SPL we have no device tree, so we use the machine parameters
 477 *
 478 * @param mem_type      Returns memory type
 479 * @param frequency_mhz Returns memory speed in MHz
 480 * @param arm_freq      Returns ARM clock speed in MHz
 481 * @param mem_manuf     Return Memory Manufacturer name
 482 */
 483static void clock_get_mem_selection(enum ddr_mode *mem_type,
 484                unsigned *frequency_mhz, unsigned *arm_freq,
 485                enum mem_manuf *mem_manuf)
 486{
 487        struct spl_machine_param *params;
 488
 489        params = spl_get_machine_params();
 490        *mem_type = params->mem_type;
 491        *frequency_mhz = params->frequency_mhz;
 492        *arm_freq = params->arm_freq_mhz;
 493        *mem_manuf = params->mem_manuf;
 494}
 495
 496/* Get the ratios for setting ARM clock */
 497struct arm_clk_ratios *get_arm_ratios(void)
 498{
 499        struct arm_clk_ratios *arm_ratio;
 500        enum ddr_mode mem_type;
 501        enum mem_manuf mem_manuf;
 502        unsigned frequency_mhz, arm_freq;
 503        int i;
 504
 505        clock_get_mem_selection(&mem_type, &frequency_mhz,
 506                                &arm_freq, &mem_manuf);
 507
 508        for (i = 0, arm_ratio = arm_clk_ratios; i < ARRAY_SIZE(arm_clk_ratios);
 509                i++, arm_ratio++) {
 510                if (arm_ratio->arm_freq_mhz == arm_freq)
 511                        return arm_ratio;
 512        }
 513
 514        /* will hang if failed to find clock ratio */
 515        while (1)
 516                ;
 517
 518        return NULL;
 519}
 520
 521struct mem_timings *clock_get_mem_timings(void)
 522{
 523        struct mem_timings *mem;
 524        enum ddr_mode mem_type;
 525        enum mem_manuf mem_manuf;
 526        unsigned frequency_mhz, arm_freq;
 527        int i;
 528
 529        clock_get_mem_selection(&mem_type, &frequency_mhz,
 530                                &arm_freq, &mem_manuf);
 531        for (i = 0, mem = mem_timings; i < ARRAY_SIZE(mem_timings);
 532             i++, mem++) {
 533                if (mem->mem_type == mem_type &&
 534                    mem->frequency_mhz == frequency_mhz &&
 535                    mem->mem_manuf == mem_manuf)
 536                        return mem;
 537        }
 538
 539        /* will hang if failed to find memory timings */
 540        while (1)
 541                ;
 542
 543        return NULL;
 544}
 545
 546static void exynos5250_system_clock_init(void)
 547{
 548        struct exynos5_clock *clk =
 549                (struct exynos5_clock *)samsung_get_base_clock();
 550        struct mem_timings *mem;
 551        struct arm_clk_ratios *arm_clk_ratio;
 552        u32 val, tmp;
 553
 554        mem = clock_get_mem_timings();
 555        arm_clk_ratio = get_arm_ratios();
 556
 557        clrbits_le32(&clk->src_cpu, MUX_APLL_SEL_MASK);
 558        do {
 559                val = readl(&clk->mux_stat_cpu);
 560        } while ((val | MUX_APLL_SEL_MASK) != val);
 561
 562        clrbits_le32(&clk->src_core1, MUX_MPLL_SEL_MASK);
 563        do {
 564                val = readl(&clk->mux_stat_core1);
 565        } while ((val | MUX_MPLL_SEL_MASK) != val);
 566
 567        clrbits_le32(&clk->src_top2, MUX_CPLL_SEL_MASK);
 568        clrbits_le32(&clk->src_top2, MUX_EPLL_SEL_MASK);
 569        clrbits_le32(&clk->src_top2, MUX_VPLL_SEL_MASK);
 570        clrbits_le32(&clk->src_top2, MUX_GPLL_SEL_MASK);
 571        tmp = MUX_CPLL_SEL_MASK | MUX_EPLL_SEL_MASK | MUX_VPLL_SEL_MASK
 572                | MUX_GPLL_SEL_MASK;
 573        do {
 574                val = readl(&clk->mux_stat_top2);
 575        } while ((val | tmp) != val);
 576
 577        clrbits_le32(&clk->src_cdrex, MUX_BPLL_SEL_MASK);
 578        do {
 579                val = readl(&clk->mux_stat_cdrex);
 580        } while ((val | MUX_BPLL_SEL_MASK) != val);
 581
 582        /* PLL locktime */
 583        writel(mem->apll_pdiv * PLL_LOCK_FACTOR, &clk->apll_lock);
 584        writel(mem->mpll_pdiv * PLL_LOCK_FACTOR, &clk->mpll_lock);
 585        writel(mem->bpll_pdiv * PLL_LOCK_FACTOR, &clk->bpll_lock);
 586        writel(mem->cpll_pdiv * PLL_LOCK_FACTOR, &clk->cpll_lock);
 587        writel(mem->gpll_pdiv * PLL_X_LOCK_FACTOR, &clk->gpll_lock);
 588        writel(mem->epll_pdiv * PLL_X_LOCK_FACTOR, &clk->epll_lock);
 589        writel(mem->vpll_pdiv * PLL_X_LOCK_FACTOR, &clk->vpll_lock);
 590
 591        writel(CLK_REG_DISABLE, &clk->pll_div2_sel);
 592
 593        writel(MUX_HPM_SEL_MASK, &clk->src_cpu);
 594        do {
 595                val = readl(&clk->mux_stat_cpu);
 596        } while ((val | HPM_SEL_SCLK_MPLL) != val);
 597
 598        val = arm_clk_ratio->arm2_ratio << 28
 599                | arm_clk_ratio->apll_ratio << 24
 600                | arm_clk_ratio->pclk_dbg_ratio << 20
 601                | arm_clk_ratio->atb_ratio << 16
 602                | arm_clk_ratio->periph_ratio << 12
 603                | arm_clk_ratio->acp_ratio << 8
 604                | arm_clk_ratio->cpud_ratio << 4
 605                | arm_clk_ratio->arm_ratio;
 606        writel(val, &clk->div_cpu0);
 607        do {
 608                val = readl(&clk->div_stat_cpu0);
 609        } while (0 != val);
 610
 611        writel(CLK_DIV_CPU1_VAL, &clk->div_cpu1);
 612        do {
 613                val = readl(&clk->div_stat_cpu1);
 614        } while (0 != val);
 615
 616        /* Set APLL */
 617        writel(APLL_CON1_VAL, &clk->apll_con1);
 618        val = set_pll(arm_clk_ratio->apll_mdiv, arm_clk_ratio->apll_pdiv,
 619                        arm_clk_ratio->apll_sdiv);
 620        writel(val, &clk->apll_con0);
 621        while ((readl(&clk->apll_con0) & APLL_CON0_LOCKED) == 0)
 622                ;
 623
 624        /* Set MPLL */
 625        writel(MPLL_CON1_VAL, &clk->mpll_con1);
 626        val = set_pll(mem->mpll_mdiv, mem->mpll_pdiv, mem->mpll_sdiv);
 627        writel(val, &clk->mpll_con0);
 628        while ((readl(&clk->mpll_con0) & MPLL_CON0_LOCKED) == 0)
 629                ;
 630
 631        /* Set BPLL */
 632        writel(BPLL_CON1_VAL, &clk->bpll_con1);
 633        val = set_pll(mem->bpll_mdiv, mem->bpll_pdiv, mem->bpll_sdiv);
 634        writel(val, &clk->bpll_con0);
 635        while ((readl(&clk->bpll_con0) & BPLL_CON0_LOCKED) == 0)
 636                ;
 637
 638        /* Set CPLL */
 639        writel(CPLL_CON1_VAL, &clk->cpll_con1);
 640        val = set_pll(mem->cpll_mdiv, mem->cpll_pdiv, mem->cpll_sdiv);
 641        writel(val, &clk->cpll_con0);
 642        while ((readl(&clk->cpll_con0) & CPLL_CON0_LOCKED) == 0)
 643                ;
 644
 645        /* Set GPLL */
 646        writel(GPLL_CON1_VAL, &clk->gpll_con1);
 647        val = set_pll(mem->gpll_mdiv, mem->gpll_pdiv, mem->gpll_sdiv);
 648        writel(val, &clk->gpll_con0);
 649        while ((readl(&clk->gpll_con0) & GPLL_CON0_LOCKED) == 0)
 650                ;
 651
 652        /* Set EPLL */
 653        writel(EPLL_CON2_VAL, &clk->epll_con2);
 654        writel(EPLL_CON1_VAL, &clk->epll_con1);
 655        val = set_pll(mem->epll_mdiv, mem->epll_pdiv, mem->epll_sdiv);
 656        writel(val, &clk->epll_con0);
 657        while ((readl(&clk->epll_con0) & EPLL_CON0_LOCKED) == 0)
 658                ;
 659
 660        /* Set VPLL */
 661        writel(VPLL_CON2_VAL, &clk->vpll_con2);
 662        writel(VPLL_CON1_VAL, &clk->vpll_con1);
 663        val = set_pll(mem->vpll_mdiv, mem->vpll_pdiv, mem->vpll_sdiv);
 664        writel(val, &clk->vpll_con0);
 665        while ((readl(&clk->vpll_con0) & VPLL_CON0_LOCKED) == 0)
 666                ;
 667
 668        writel(CLK_SRC_CORE0_VAL, &clk->src_core0);
 669        writel(CLK_DIV_CORE0_VAL, &clk->div_core0);
 670        while (readl(&clk->div_stat_core0) != 0)
 671                ;
 672
 673        writel(CLK_DIV_CORE1_VAL, &clk->div_core1);
 674        while (readl(&clk->div_stat_core1) != 0)
 675                ;
 676
 677        writel(CLK_DIV_SYSRGT_VAL, &clk->div_sysrgt);
 678        while (readl(&clk->div_stat_sysrgt) != 0)
 679                ;
 680
 681        writel(CLK_DIV_ACP_VAL, &clk->div_acp);
 682        while (readl(&clk->div_stat_acp) != 0)
 683                ;
 684
 685        writel(CLK_DIV_SYSLFT_VAL, &clk->div_syslft);
 686        while (readl(&clk->div_stat_syslft) != 0)
 687                ;
 688
 689        writel(CLK_SRC_TOP0_VAL, &clk->src_top0);
 690        writel(CLK_SRC_TOP1_VAL, &clk->src_top1);
 691        writel(TOP2_VAL, &clk->src_top2);
 692        writel(CLK_SRC_TOP3_VAL, &clk->src_top3);
 693
 694        writel(CLK_DIV_TOP0_VAL, &clk->div_top0);
 695        while (readl(&clk->div_stat_top0))
 696                ;
 697
 698        writel(CLK_DIV_TOP1_VAL, &clk->div_top1);
 699        while (readl(&clk->div_stat_top1))
 700                ;
 701
 702        writel(CLK_SRC_LEX_VAL, &clk->src_lex);
 703        while (1) {
 704                val = readl(&clk->mux_stat_lex);
 705                if (val == (val | 1))
 706                        break;
 707        }
 708
 709        writel(CLK_DIV_LEX_VAL, &clk->div_lex);
 710        while (readl(&clk->div_stat_lex))
 711                ;
 712
 713        writel(CLK_DIV_R0X_VAL, &clk->div_r0x);
 714        while (readl(&clk->div_stat_r0x))
 715                ;
 716
 717        writel(CLK_DIV_R0X_VAL, &clk->div_r0x);
 718        while (readl(&clk->div_stat_r0x))
 719                ;
 720
 721        writel(CLK_DIV_R1X_VAL, &clk->div_r1x);
 722        while (readl(&clk->div_stat_r1x))
 723                ;
 724
 725        writel(CLK_REG_DISABLE, &clk->src_cdrex);
 726
 727        writel(CLK_DIV_CDREX_VAL, &clk->div_cdrex);
 728        while (readl(&clk->div_stat_cdrex))
 729                ;
 730
 731        val = readl(&clk->src_cpu);
 732        val |= CLK_SRC_CPU_VAL;
 733        writel(val, &clk->src_cpu);
 734
 735        val = readl(&clk->src_top2);
 736        val |= CLK_SRC_TOP2_VAL;
 737        writel(val, &clk->src_top2);
 738
 739        val = readl(&clk->src_core1);
 740        val |= CLK_SRC_CORE1_VAL;
 741        writel(val, &clk->src_core1);
 742
 743        writel(CLK_SRC_FSYS0_VAL, &clk->src_fsys);
 744        writel(CLK_DIV_FSYS0_VAL, &clk->div_fsys0);
 745        while (readl(&clk->div_stat_fsys0))
 746                ;
 747
 748        writel(CLK_REG_DISABLE, &clk->clkout_cmu_cpu);
 749        writel(CLK_REG_DISABLE, &clk->clkout_cmu_core);
 750        writel(CLK_REG_DISABLE, &clk->clkout_cmu_acp);
 751        writel(CLK_REG_DISABLE, &clk->clkout_cmu_top);
 752        writel(CLK_REG_DISABLE, &clk->clkout_cmu_lex);
 753        writel(CLK_REG_DISABLE, &clk->clkout_cmu_r0x);
 754        writel(CLK_REG_DISABLE, &clk->clkout_cmu_r1x);
 755        writel(CLK_REG_DISABLE, &clk->clkout_cmu_cdrex);
 756
 757        writel(CLK_SRC_PERIC0_VAL, &clk->src_peric0);
 758        writel(CLK_DIV_PERIC0_VAL, &clk->div_peric0);
 759
 760        writel(CLK_SRC_PERIC1_VAL, &clk->src_peric1);
 761        writel(CLK_DIV_PERIC1_VAL, &clk->div_peric1);
 762        writel(CLK_DIV_PERIC2_VAL, &clk->div_peric2);
 763        writel(CLK_DIV_PERIC3_VAL, &clk->div_peric3);
 764
 765        writel(SCLK_SRC_ISP_VAL, &clk->sclk_src_isp);
 766        writel(SCLK_DIV_ISP_VAL, &clk->sclk_div_isp);
 767        writel(CLK_DIV_ISP0_VAL, &clk->div_isp0);
 768        writel(CLK_DIV_ISP1_VAL, &clk->div_isp1);
 769        writel(CLK_DIV_ISP2_VAL, &clk->div_isp2);
 770
 771        /* FIMD1 SRC CLK SELECTION */
 772        writel(CLK_SRC_DISP1_0_VAL, &clk->src_disp1_0);
 773
 774        val = MMC2_PRE_RATIO_VAL << MMC2_PRE_RATIO_OFFSET
 775                | MMC2_RATIO_VAL << MMC2_RATIO_OFFSET
 776                | MMC3_PRE_RATIO_VAL << MMC3_PRE_RATIO_OFFSET
 777                | MMC3_RATIO_VAL << MMC3_RATIO_OFFSET;
 778        writel(val, &clk->div_fsys2);
 779}
 780
 781static void exynos5420_system_clock_init(void)
 782{
 783        struct exynos5420_clock *clk =
 784                (struct exynos5420_clock *)samsung_get_base_clock();
 785        struct mem_timings *mem;
 786        struct arm_clk_ratios *arm_clk_ratio;
 787        u32 val;
 788
 789        mem = clock_get_mem_timings();
 790        arm_clk_ratio = get_arm_ratios();
 791
 792        /* PLL locktime */
 793        writel(arm_clk_ratio->apll_pdiv * PLL_LOCK_FACTOR, &clk->apll_lock);
 794        writel(mem->mpll_pdiv * PLL_LOCK_FACTOR, &clk->mpll_lock);
 795        writel(mem->bpll_pdiv * PLL_LOCK_FACTOR, &clk->bpll_lock);
 796        writel(mem->cpll_pdiv * PLL_LOCK_FACTOR, &clk->cpll_lock);
 797        writel(mem->dpll_pdiv * PLL_LOCK_FACTOR, &clk->dpll_lock);
 798        writel(mem->epll_pdiv * PLL_X_LOCK_FACTOR, &clk->epll_lock);
 799        writel(mem->vpll_pdiv * PLL_LOCK_FACTOR, &clk->vpll_lock);
 800        writel(mem->ipll_pdiv * PLL_LOCK_FACTOR, &clk->ipll_lock);
 801        writel(mem->spll_pdiv * PLL_LOCK_FACTOR, &clk->spll_lock);
 802        writel(mem->kpll_pdiv * PLL_LOCK_FACTOR, &clk->kpll_lock);
 803
 804        setbits_le32(&clk->src_cpu, MUX_HPM_SEL_MASK);
 805
 806        writel(0, &clk->src_top6);
 807
 808        writel(0, &clk->src_cdrex);
 809        writel(SRC_KFC_HPM_SEL, &clk->src_kfc);
 810        writel(HPM_RATIO,  &clk->div_cpu1);
 811        writel(CLK_DIV_CPU0_VAL,  &clk->div_cpu0);
 812
 813        /* switch A15 clock source to OSC clock before changing APLL */
 814        clrbits_le32(&clk->src_cpu, APLL_FOUT);
 815
 816        /* Set APLL */
 817        writel(APLL_CON1_VAL, &clk->apll_con1);
 818        val = set_pll(arm_clk_ratio->apll_mdiv,
 819                      arm_clk_ratio->apll_pdiv,
 820                      arm_clk_ratio->apll_sdiv);
 821        writel(val, &clk->apll_con0);
 822        while ((readl(&clk->apll_con0) & PLL_LOCKED) == 0)
 823                ;
 824
 825        /* now it is safe to switch to APLL */
 826        setbits_le32(&clk->src_cpu, APLL_FOUT);
 827
 828        writel(SRC_KFC_HPM_SEL, &clk->src_kfc);
 829        writel(CLK_DIV_KFC_VAL, &clk->div_kfc0);
 830
 831        /* switch A7 clock source to OSC clock before changing KPLL */
 832        clrbits_le32(&clk->src_kfc, KPLL_FOUT);
 833
 834        /* Set KPLL*/
 835        writel(KPLL_CON1_VAL, &clk->kpll_con1);
 836        val = set_pll(mem->kpll_mdiv, mem->kpll_pdiv, mem->kpll_sdiv);
 837        writel(val, &clk->kpll_con0);
 838        while ((readl(&clk->kpll_con0) & PLL_LOCKED) == 0)
 839                ;
 840
 841        /* now it is safe to switch to KPLL */
 842        setbits_le32(&clk->src_kfc, KPLL_FOUT);
 843
 844        /* Set MPLL */
 845        writel(MPLL_CON1_VAL, &clk->mpll_con1);
 846        val = set_pll(mem->mpll_mdiv, mem->mpll_pdiv, mem->mpll_sdiv);
 847        writel(val, &clk->mpll_con0);
 848        while ((readl(&clk->mpll_con0) & PLL_LOCKED) == 0)
 849                ;
 850
 851        /* Set DPLL */
 852        writel(DPLL_CON1_VAL, &clk->dpll_con1);
 853        val = set_pll(mem->dpll_mdiv, mem->dpll_pdiv, mem->dpll_sdiv);
 854        writel(val, &clk->dpll_con0);
 855        while ((readl(&clk->dpll_con0) & PLL_LOCKED) == 0)
 856                ;
 857
 858        /* Set EPLL */
 859        writel(EPLL_CON2_VAL, &clk->epll_con2);
 860        writel(EPLL_CON1_VAL, &clk->epll_con1);
 861        val = set_pll(mem->epll_mdiv, mem->epll_pdiv, mem->epll_sdiv);
 862        writel(val, &clk->epll_con0);
 863        while ((readl(&clk->epll_con0) & PLL_LOCKED) == 0)
 864                ;
 865
 866        /* Set CPLL */
 867        writel(CPLL_CON1_VAL, &clk->cpll_con1);
 868        val = set_pll(mem->cpll_mdiv, mem->cpll_pdiv, mem->cpll_sdiv);
 869        writel(val, &clk->cpll_con0);
 870        while ((readl(&clk->cpll_con0) & PLL_LOCKED) == 0)
 871                ;
 872
 873        /* Set IPLL */
 874        writel(IPLL_CON1_VAL, &clk->ipll_con1);
 875        val = set_pll(mem->ipll_mdiv, mem->ipll_pdiv, mem->ipll_sdiv);
 876        writel(val, &clk->ipll_con0);
 877        while ((readl(&clk->ipll_con0) & PLL_LOCKED) == 0)
 878                ;
 879
 880        /* Set VPLL */
 881        writel(VPLL_CON1_VAL, &clk->vpll_con1);
 882        val = set_pll(mem->vpll_mdiv, mem->vpll_pdiv, mem->vpll_sdiv);
 883        writel(val, &clk->vpll_con0);
 884        while ((readl(&clk->vpll_con0) & PLL_LOCKED) == 0)
 885                ;
 886
 887        /* Set BPLL */
 888        writel(BPLL_CON1_VAL, &clk->bpll_con1);
 889        val = set_pll(mem->bpll_mdiv, mem->bpll_pdiv, mem->bpll_sdiv);
 890        writel(val, &clk->bpll_con0);
 891        while ((readl(&clk->bpll_con0) & PLL_LOCKED) == 0)
 892                ;
 893
 894        /* Set SPLL */
 895        writel(SPLL_CON1_VAL, &clk->spll_con1);
 896        val = set_pll(mem->spll_mdiv, mem->spll_pdiv, mem->spll_sdiv);
 897        writel(val, &clk->spll_con0);
 898        while ((readl(&clk->spll_con0) & PLL_LOCKED) == 0)
 899                ;
 900
 901        writel(CLK_DIV_CDREX0_VAL, &clk->div_cdrex0);
 902        writel(CLK_DIV_CDREX1_VAL, &clk->div_cdrex1);
 903
 904        writel(CLK_SRC_TOP0_VAL, &clk->src_top0);
 905        writel(CLK_SRC_TOP1_VAL, &clk->src_top1);
 906        writel(CLK_SRC_TOP2_VAL, &clk->src_top2);
 907        writel(CLK_SRC_TOP7_VAL, &clk->src_top7);
 908
 909        writel(CLK_DIV_TOP0_VAL, &clk->div_top0);
 910        writel(CLK_DIV_TOP1_VAL, &clk->div_top1);
 911        writel(CLK_DIV_TOP2_VAL, &clk->div_top2);
 912
 913        writel(0, &clk->src_top10);
 914        writel(0, &clk->src_top11);
 915        writel(0, &clk->src_top12);
 916
 917        writel(CLK_SRC_TOP3_VAL, &clk->src_top3);
 918        writel(CLK_SRC_TOP4_VAL, &clk->src_top4);
 919        writel(CLK_SRC_TOP5_VAL, &clk->src_top5);
 920
 921        /* DISP1 BLK CLK SELECTION */
 922        writel(CLK_SRC_DISP1_0_VAL, &clk->src_disp10);
 923        writel(CLK_DIV_DISP1_0_VAL, &clk->div_disp10);
 924
 925        /* AUDIO BLK */
 926        writel(AUDIO0_SEL_EPLL, &clk->src_mau);
 927        writel(DIV_MAU_VAL, &clk->div_mau);
 928
 929        /* FSYS */
 930        writel(CLK_SRC_FSYS0_VAL, &clk->src_fsys);
 931        writel(CLK_DIV_FSYS0_VAL, &clk->div_fsys0);
 932        writel(CLK_DIV_FSYS1_VAL, &clk->div_fsys1);
 933        writel(CLK_DIV_FSYS2_VAL, &clk->div_fsys2);
 934
 935        writel(CLK_SRC_ISP_VAL, &clk->src_isp);
 936        writel(CLK_DIV_ISP0_VAL, &clk->div_isp0);
 937        writel(CLK_DIV_ISP1_VAL, &clk->div_isp1);
 938
 939        writel(CLK_SRC_PERIC0_VAL, &clk->src_peric0);
 940        writel(CLK_SRC_PERIC1_VAL, &clk->src_peric1);
 941
 942        writel(CLK_DIV_PERIC0_VAL, &clk->div_peric0);
 943        writel(CLK_DIV_PERIC1_VAL, &clk->div_peric1);
 944        writel(CLK_DIV_PERIC2_VAL, &clk->div_peric2);
 945        writel(CLK_DIV_PERIC3_VAL, &clk->div_peric3);
 946        writel(CLK_DIV_PERIC4_VAL, &clk->div_peric4);
 947
 948        writel(CLK_DIV_CPERI1_VAL, &clk->div_cperi1);
 949
 950        writel(CLK_DIV2_RATIO, &clk->clkdiv2_ratio);
 951        writel(CLK_DIV4_RATIO, &clk->clkdiv4_ratio);
 952        writel(CLK_DIV_G2D, &clk->div_g2d);
 953
 954        writel(CLK_SRC_TOP6_VAL, &clk->src_top6);
 955        writel(CLK_SRC_CDREX_VAL, &clk->src_cdrex);
 956        writel(CLK_SRC_KFC_VAL, &clk->src_kfc);
 957}
 958
 959void system_clock_init(void)
 960{
 961        if (proid_is_exynos5420())
 962                exynos5420_system_clock_init();
 963        else
 964                exynos5250_system_clock_init();
 965}
 966
 967void clock_init_dp_clock(void)
 968{
 969        struct exynos5_clock *clk =
 970                (struct exynos5_clock *)samsung_get_base_clock();
 971
 972        /* DP clock enable */
 973        setbits_le32(&clk->gate_ip_disp1, CLK_GATE_DP1_ALLOW);
 974
 975        /* We run DP at 267 Mhz */
 976        setbits_le32(&clk->div_disp1_0, CLK_DIV_DISP1_0_FIMD1);
 977}
 978
 979/*
 980 * Set clock divisor value for booting from EMMC.
 981 * Set DWMMC channel-0 clk div to operate mmc0 device at 50MHz.
 982 */
 983void emmc_boot_clk_div_set(void)
 984{
 985        struct exynos5_clock *clk =
 986                (struct exynos5_clock *)samsung_get_base_clock();
 987        unsigned int div_mmc;
 988
 989        div_mmc = readl((unsigned int) &clk->div_fsys1) & ~FSYS1_MMC0_DIV_MASK;
 990        div_mmc |= FSYS1_MMC0_DIV_VAL;
 991        writel(div_mmc, (unsigned int) &clk->div_fsys1);
 992}
 993