Skip to content

Commit edb23d4

Browse files
author
Joy Cho
committed
ODROID-XU4: add a command, 'dmc' to set lpddr3 frequency on u-boot stage
Change-Id: Ieb49575c1e8c93553495b30368ef68827bb0bf2f
1 parent 8952a12 commit edb23d4

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

cmd/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ config CMD_MEMINFO
373373
help
374374
Display memory information.
375375

376+
config CMD_DMC
377+
bool "dmc - ddr_freq"
378+
help
379+
Set DDR clock
380+
376381
config CMD_UNZIP
377382
bool "unzip"
378383
help

cmd/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ obj-$(CONFIG_LOGBUFFER) += log.o
8383
obj-$(CONFIG_ID_EEPROM) += mac.o
8484
obj-$(CONFIG_CMD_MD5SUM) += md5sum.o
8585
obj-$(CONFIG_CMD_MEMORY) += mem.o
86+
obj-$(CONFIG_CMD_DMC) += dmc.o
8687
obj-$(CONFIG_CMD_IO) += io.o
8788
obj-$(CONFIG_CMD_MFSL) += mfsl.o
8889
obj-$(CONFIG_CMD_MII) += mii.o

cmd/dmc.c

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Set LPDDR3 frequency and DMC for Exynos5422
3+
*
4+
* Copyright (C) 2017 Joy Cho <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*/
16+
17+
#include <common.h>
18+
#include <asm/io.h>
19+
#include <asm/arch/clock.h>
20+
21+
#define DREXI_0 0x10C20000
22+
#define DREXI_1 0x10C30000
23+
24+
static int set_cmu(int freq)
25+
{
26+
struct exynos5420_clock *clk =
27+
(struct exynos5420_clock *)EXYNOS5_CLOCK_BASE;
28+
29+
/* set BPLL_LOCK, BPLL_CON1 and BPLL_CON0 */
30+
switch (freq) {
31+
case 933:
32+
writel(0x00000320, &clk->bpll_lock);
33+
writel(0x0020F300, &clk->bpll_con1);
34+
writel(0x81370401, &clk->bpll_con0);
35+
break;
36+
case 825:
37+
writel(0x00000320, &clk->bpll_lock);
38+
writel(0x0020F300, &clk->bpll_con1);
39+
writel(0x81130401, &clk->bpll_con0);
40+
break;
41+
case 728:
42+
writel(0x00000258, &clk->bpll_lock);
43+
writel(0x0020F300, &clk->bpll_con1);
44+
writel(0x80B60301, &clk->bpll_con0);
45+
break;
46+
case 633:
47+
writel(0x00000320, &clk->bpll_lock);
48+
writel(0x0020F300, &clk->bpll_con1);
49+
writel(0x80D30401, &clk->bpll_con0);
50+
break;
51+
default:
52+
printf("no available frequency - %dMHz\n", freq);
53+
return 0;
54+
}
55+
56+
/* check the 29th bit (LOCKED) to confirm PLL locking */
57+
while(!(readl(&clk->bpll_con0) & (0x1 << 29)));
58+
59+
return 1;
60+
}
61+
62+
static void set_dmc(int freq, u32 drex_addr)
63+
{
64+
/* set TIMINGROW0, TIMINGDATA0 and TIMINGPOWER0 */
65+
switch (freq) {
66+
case 933:
67+
writel(0x3D6BA816, drex_addr+0x0034);
68+
writel(0x4742086E, drex_addr+0x0038);
69+
writel(0x60670447, drex_addr+0x003C);
70+
break;
71+
case 825:
72+
writel(0x365A9713, drex_addr+0x0034);
73+
writel(0x4740085E, drex_addr+0x0038);
74+
writel(0x543A0446, drex_addr+0x003C);
75+
break;
76+
case 728:
77+
writel(0x30598651, drex_addr+0x0034);
78+
writel(0x3730085E, drex_addr+0x0038);
79+
writel(0x4C330336, drex_addr+0x003C);
80+
break;
81+
case 633:
82+
writel(0x2A48758F, drex_addr+0x0034);
83+
writel(0x3730085E, drex_addr+0x0038);
84+
writel(0x402D0335, drex_addr+0x003C);
85+
break;
86+
default:
87+
printf("no available frequency - %dMHz\n", freq);
88+
break;
89+
}
90+
}
91+
92+
static int do_dmc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
93+
{
94+
int freq;
95+
96+
if (argc != 2)
97+
return cmd_usage(cmdtp);
98+
else
99+
freq = simple_strtoul(argv[1], NULL, 10);
100+
101+
if (!set_cmu(freq))
102+
return cmd_usage(cmdtp);
103+
104+
set_dmc(freq, DREXI_0);
105+
set_dmc(freq, DREXI_1);
106+
107+
return 0;
108+
}
109+
110+
U_BOOT_CMD(
111+
dmc, 2, 0, do_dmc,
112+
"Set LPDDR3 clock",
113+
"dmc <lpddr3 frequency>\n"
114+
"ex) dmc 933\n"
115+
"lpddr3 frequency list - 933/825/728/633\n");

configs/odroid-xu4_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ CONFIG_CMD_MEMTEST=y
337337
CONFIG_CMD_MEMINFO=y
338338
# CONFIG_CMD_UNZIP is not set
339339
# CONFIG_CMD_ZIP is not set
340+
CONFIG_CMD_DMC=y
340341

341342
#
342343
# Device access commands

0 commit comments

Comments
 (0)