summaryrefslogtreecommitdiff
path: root/packages/uboot/u-boot-mkimage-gta01-native/uboot-cmd_s3c2410.patch
blob: 993ef4f6f23a0f4bb98b8ca64ec2cf12f7035fcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
This patch adds a new 's3c2410' command which currently supports 's3c2410 speed
{set,get,list} and thus allows dynamic change of the CPU clock.

Signed-off-by: Harald Welte <laforge@openmoko.org>

Index: u-boot/cpu/arm920t/s3c24x0/Makefile
===================================================================
--- u-boot.orig/cpu/arm920t/s3c24x0/Makefile	2007-02-24 15:14:00.000000000 +0100
+++ u-boot/cpu/arm920t/s3c24x0/Makefile	2007-02-24 15:21:02.000000000 +0100
@@ -26,7 +26,7 @@
 LIB	= $(obj)lib$(SOC).a
 
 COBJS	= i2c.o interrupts.o serial.o speed.o \
-	  usb_ohci.o nand_read.o nand.o
+	  usb_ohci.o nand_read.o nand.o cmd_s3c2410.o
 
 SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
Index: u-boot/cpu/arm920t/s3c24x0/cmd_s3c2410.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ u-boot/cpu/arm920t/s3c24x0/cmd_s3c2410.c	2007-02-24 15:22:17.000000000 +0100
@@ -0,0 +1,152 @@
+/*
+ * (C) Copyright 2006 by OpenMoko, Inc.
+ * Author: Harald Welte <laforge@openmoko.org>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/*
+ * Boot support
+ */
+#include <common.h>
+#include <command.h>
+#include <net.h>		/* for print_IPaddr */
+#include <s3c2410.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if (CONFIG_COMMANDS & CFG_CMD_BDI)
+
+#define ARRAY_SIZE(x)           (sizeof(x) / sizeof((x)[0]))
+#define MHZ	1000000
+
+static void print_cpu_speed(void)
+{
+	printf("FCLK = %u MHz, HCLK = %u MHz, PCLK = %u MHz\n",
+		get_FCLK()/MHZ, get_HCLK()/MHZ, get_PCLK()/MHZ);
+}
+
+struct s3c2410_pll_speed {
+	u_int16_t	mhz;
+	u_int32_t	mpllcon;
+	u_int32_t	clkdivn;
+};
+
+#define CLKDIVN_1_1_1	0x00
+#define CLKDIVN_1_2_2	0x02
+#define CLKDIVN_1_2_4	0x03
+#define CLKDIVN_1_4_4	0x04
+
+static const struct s3c2410_pll_speed pll_configs[] = {
+	{
+		.mhz = 50,
+		.mpllcon = ((0x5c << 12) + (0x4 << 4) + 0x2),
+		.clkdivn = CLKDIVN_1_1_1,
+	},
+	{
+		.mhz = 101,
+		.mpllcon = ((0x7f << 12) + (0x2 << 4) + 0x2),
+		.clkdivn = CLKDIVN_1_2_2,
+	},
+	{
+		.mhz = 202,
+		.mpllcon = ((0x90 << 12) + (0x7 << 4) + 0x0),
+		.clkdivn = CLKDIVN_1_2_4,
+	},
+	{
+		.mhz = 266,
+		.mpllcon = ((0x7d << 12) + (0x1 << 4) + 0x1),
+		.clkdivn = CLKDIVN_1_2_4,
+	},
+};
+
+static void list_cpu_speeds(void)
+{
+	int i;
+	for (i = 0; i < ARRAY_SIZE(pll_configs); i++)
+		printf("%u MHz\n", pll_configs[i].mhz);
+}
+
+static int reconfig_mpll(u_int16_t mhz)
+{
+	S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(pll_configs); i++) {
+		if (pll_configs[i].mhz == mhz) {
+			/* to reduce PLL lock time, adjust the LOCKTIME register */
+			clk_power->LOCKTIME = 0xFFFFFF;
+
+			/* configure MPLL */
+			clk_power->MPLLCON = pll_configs[i].mpllcon;
+			clk_power->UPLLCON = ((0x78 << 12) + (0x2 << 4) + 0x3),
+			clk_power->CLKDIVN = pll_configs[i].clkdivn;
+
+			/* If we changed the speed, we need to re-configure
+			 * the serial baud rate generator */
+			serial_setbrg();
+			return 0;
+		}
+	}
+	return -1;
+}
+
+int do_s3c2410 ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+	if (!strcmp(argv[1], "speed")) {
+		if (argc < 2)
+			goto out_help;
+		if (!strcmp(argv[2], "get"))
+			print_cpu_speed();
+		else if (!strcmp(argv[2], "list"))
+			list_cpu_speeds();
+		else if (!strcmp(argv[2], "set")) {
+			unsigned long mhz;
+			if (argc < 3)
+				goto out_help;
+
+			mhz = simple_strtoul(argv[3], NULL, 10);
+
+			if (reconfig_mpll(mhz) < 0)
+				printf("error, speed %uMHz unknown\n", mhz);
+			else
+				print_cpu_speed();
+		} else
+			goto out_help;
+	} else {
+out_help:
+		printf("Usage:\n%s\n", cmdtp->usage);
+		return 1;
+	}
+
+	return 0;
+}
+
+/* -------------------------------------------------------------------- */
+
+
+U_BOOT_CMD(
+	s3c2410,	4,	1,	do_s3c2410,
+	"s3c2410 - SoC  specific commands\n",
+	"speed get - display current PLL speed config\n"
+	"s3c2410 speed list - display supporte PLL speed configs\n"
+	"s3c2410 speed set - set PLL speed\n"
+);
+
+#endif