clock.c 8.8 KB
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
/* linux/arch/arm/mach-s5p6442/clock.c
 *
 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com/
 *
 * S5P6442 - Clock support
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
*/

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/err.h>
#include <linux/clk.h>
#include <linux/io.h>

#include <mach/map.h>

#include <plat/cpu-freq.h>
#include <mach/regs-clock.h>
#include <plat/clock.h>
#include <plat/cpu.h>
#include <plat/pll.h>
#include <plat/s5p-clock.h>
#include <plat/clock-clksrc.h>
#include <plat/s5p6442.h>

static struct clksrc_clk clk_mout_apll = {
	.clk	= {
		.name		= "mout_apll",
		.id		= -1,
	},
	.sources	= &clk_src_apll,
	.reg_src	= { .reg = S5P_CLK_SRC0, .shift = 0, .size = 1 },
};

static struct clksrc_clk clk_mout_mpll = {
	.clk = {
		.name		= "mout_mpll",
		.id		= -1,
	},
	.sources	= &clk_src_mpll,
	.reg_src	= { .reg = S5P_CLK_SRC0, .shift = 4, .size = 1 },
};

static struct clksrc_clk clk_mout_epll = {
	.clk	= {
		.name		= "mout_epll",
		.id		= -1,
	},
	.sources	= &clk_src_epll,
	.reg_src	= { .reg = S5P_CLK_SRC0, .shift = 8, .size = 1 },
};

/* Possible clock sources for ARM Mux */
static struct clk *clk_src_arm_list[] = {
	[1] = &clk_mout_apll.clk,
	[2] = &clk_mout_mpll.clk,
};

static struct clksrc_sources clk_src_arm = {
	.sources	= clk_src_arm_list,
	.nr_sources	= ARRAY_SIZE(clk_src_arm_list),
};

static struct clksrc_clk clk_mout_arm = {
	.clk	= {
		.name		= "mout_arm",
		.id		= -1,
	},
	.sources	= &clk_src_arm,
	.reg_src	= { .reg = S5P_CLK_MUX_STAT0, .shift = 16, .size = 3 },
};

static struct clk clk_dout_a2m = {
	.name		= "dout_a2m",
	.id		= -1,
	.parent		= &clk_mout_apll.clk,
};

/* Possible clock sources for D0 Mux */
static struct clk *clk_src_d0_list[] = {
	[1] = &clk_mout_mpll.clk,
	[2] = &clk_dout_a2m,
};

static struct clksrc_sources clk_src_d0 = {
	.sources	= clk_src_d0_list,
	.nr_sources	= ARRAY_SIZE(clk_src_d0_list),
};

static struct clksrc_clk clk_mout_d0 = {
	.clk = {
		.name		= "mout_d0",
		.id		= -1,
	},
	.sources	= &clk_src_d0,
	.reg_src	= { .reg = S5P_CLK_MUX_STAT0, .shift = 20, .size = 3 },
};

static struct clk clk_dout_apll = {
	.name		= "dout_apll",
	.id		= -1,
	.parent		= &clk_mout_arm.clk,
};

/* Possible clock sources for D0SYNC Mux */
static struct clk *clk_src_d0sync_list[] = {
	[1] = &clk_mout_d0.clk,
	[2] = &clk_dout_apll,
};

static struct clksrc_sources clk_src_d0sync = {
	.sources	= clk_src_d0sync_list,
	.nr_sources	= ARRAY_SIZE(clk_src_d0sync_list),
};

static struct clksrc_clk clk_mout_d0sync = {
	.clk	= {
		.name		= "mout_d0sync",
		.id		= -1,
	},
	.sources	= &clk_src_d0sync,
	.reg_src	= { .reg = S5P_CLK_MUX_STAT1, .shift = 28, .size = 3 },
};

/* Possible clock sources for D1 Mux */
static struct clk *clk_src_d1_list[] = {
	[1] = &clk_mout_mpll.clk,
	[2] = &clk_dout_a2m,
};

static struct clksrc_sources clk_src_d1 = {
	.sources	= clk_src_d1_list,
	.nr_sources	= ARRAY_SIZE(clk_src_d1_list),
};

static struct clksrc_clk clk_mout_d1 = {
	.clk	= {
		.name		= "mout_d1",
		.id		= -1,
	},
	.sources	= &clk_src_d1,
	.reg_src	= { .reg = S5P_CLK_MUX_STAT0, .shift = 24, .size = 3 },
};

/* Possible clock sources for D1SYNC Mux */
static struct clk *clk_src_d1sync_list[] = {
	[1] = &clk_mout_d1.clk,
	[2] = &clk_dout_apll,
};

static struct clksrc_sources clk_src_d1sync = {
	.sources	= clk_src_d1sync_list,
	.nr_sources	= ARRAY_SIZE(clk_src_d1sync_list),
};

static struct clksrc_clk clk_mout_d1sync = {
	.clk	= {
		.name		= "mout_d1sync",
		.id		= -1,
	},
	.sources	= &clk_src_d1sync,
	.reg_src	= { .reg = S5P_CLK_MUX_STAT1, .shift = 24, .size = 3 },
};

static struct clk clk_hclkd0 = {
	.name		= "hclkd0",
	.id		= -1,
	.parent		= &clk_mout_d0sync.clk,
};

static struct clk clk_hclkd1 = {
	.name		= "hclkd1",
	.id		= -1,
	.parent		= &clk_mout_d1sync.clk,
};

static struct clk clk_pclkd0 = {
	.name		= "pclkd0",
	.id		= -1,
	.parent		= &clk_hclkd0,
};

static struct clk clk_pclkd1 = {
	.name		= "pclkd1",
	.id		= -1,
	.parent		= &clk_hclkd1,
};

int s5p6442_clk_ip3_ctrl(struct clk *clk, int enable)
{
	return s5p_gatectrl(S5P_CLKGATE_IP3, clk, enable);
}

static struct clksrc_clk clksrcs[] = {
	{
		.clk	= {
			.name		= "dout_a2m",
			.id		= -1,
			.parent		= &clk_mout_apll.clk,
		},
		.sources = &clk_src_apll,
		.reg_src = { .reg = S5P_CLK_SRC0, .shift = 0, .size = 1 },
		.reg_div = { .reg = S5P_CLK_DIV0, .shift = 4, .size = 3 },
	}, {
		.clk	= {
			.name		= "dout_apll",
			.id		= -1,
			.parent		= &clk_mout_arm.clk,
		},
		.sources = &clk_src_arm,
		.reg_src = { .reg = S5P_CLK_MUX_STAT0, .shift = 16, .size = 3 },
		.reg_div = { .reg = S5P_CLK_DIV0, .shift = 0, .size = 3 },
	}, {
		.clk	= {
			.name		= "hclkd1",
			.id		= -1,
			.parent		= &clk_mout_d1sync.clk,
		},
		.sources = &clk_src_d1sync,
		.reg_src = { .reg = S5P_CLK_MUX_STAT1, .shift = 24, .size = 3 },
		.reg_div = { .reg = S5P_CLK_DIV0, .shift = 24, .size = 4 },
	}, {
		.clk	= {
			.name		= "hclkd0",
			.id		= -1,
			.parent		= &clk_mout_d0sync.clk,
		},
		.sources = &clk_src_d0sync,
		.reg_src = { .reg = S5P_CLK_MUX_STAT1, .shift = 28, .size = 3 },
		.reg_div = { .reg = S5P_CLK_DIV0, .shift = 16, .size = 4 },
	}, {
		.clk	= {
			.name		= "pclkd0",
			.id		= -1,
			.parent		= &clk_hclkd0,
		},
		.sources = &clk_src_d0sync,
		.reg_src = { .reg = S5P_CLK_MUX_STAT1, .shift = 28, .size = 3 },
		.reg_div = { .reg = S5P_CLK_DIV0, .shift = 20, .size = 3 },
	}, {
		.clk	= {
			.name		= "pclkd1",
			.id		= -1,
			.parent		= &clk_hclkd1,
		},
		.sources = &clk_src_d1sync,
		.reg_src = { .reg = S5P_CLK_MUX_STAT1, .shift = 24, .size = 3 },
		.reg_div = { .reg = S5P_CLK_DIV0, .shift = 28, .size = 3 },
	}
};

/* Clock initialisation code */
static struct clksrc_clk *init_parents[] = {
	&clk_mout_apll,
	&clk_mout_mpll,
	&clk_mout_epll,
	&clk_mout_arm,
	&clk_mout_d0,
	&clk_mout_d0sync,
	&clk_mout_d1,
	&clk_mout_d1sync,
};

void __init_or_cpufreq s5p6442_setup_clocks(void)
{
	struct clk *pclkd0_clk;
	struct clk *pclkd1_clk;

	unsigned long xtal;
	unsigned long arm;
	unsigned long hclkd0 = 0;
	unsigned long hclkd1 = 0;
	unsigned long pclkd0 = 0;
	unsigned long pclkd1 = 0;

	unsigned long apll;
	unsigned long mpll;
	unsigned long epll;
	unsigned int ptr;

	printk(KERN_DEBUG "%s: registering clocks\n", __func__);

	xtal = clk_get_rate(&clk_xtal);

	printk(KERN_DEBUG "%s: xtal is %ld\n", __func__, xtal);

	apll = s5p_get_pll45xx(xtal, __raw_readl(S5P_APLL_CON), pll_4508);
	mpll = s5p_get_pll45xx(xtal, __raw_readl(S5P_MPLL_CON), pll_4502);
	epll = s5p_get_pll45xx(xtal, __raw_readl(S5P_EPLL_CON), pll_4500);

	printk(KERN_INFO "S5P6442: PLL settings, A=%ld, M=%ld, E=%ld",
			apll, mpll, epll);

	clk_fout_apll.rate = apll;
	clk_fout_mpll.rate = mpll;
	clk_fout_epll.rate = epll;

	for (ptr = 0; ptr < ARRAY_SIZE(init_parents); ptr++)
		s3c_set_clksrc(init_parents[ptr], true);

	for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
		s3c_set_clksrc(&clksrcs[ptr], true);

	arm = clk_get_rate(&clk_dout_apll);
	hclkd0 = clk_get_rate(&clk_hclkd0);
	hclkd1 = clk_get_rate(&clk_hclkd1);

	pclkd0_clk = clk_get(NULL, "pclkd0");
	BUG_ON(IS_ERR(pclkd0_clk));

	pclkd0 = clk_get_rate(pclkd0_clk);
	clk_put(pclkd0_clk);

	pclkd1_clk = clk_get(NULL, "pclkd1");
	BUG_ON(IS_ERR(pclkd1_clk));

	pclkd1 = clk_get_rate(pclkd1_clk);
	clk_put(pclkd1_clk);

	printk(KERN_INFO "S5P6442: HCLKD0=%ld, HCLKD1=%ld, PCLKD0=%ld, PCLKD1=%ld\n",
			hclkd0, hclkd1, pclkd0, pclkd1);

	/* For backward compatibility */
	clk_f.rate = arm;
	clk_h.rate = hclkd1;
	clk_p.rate = pclkd1;

	clk_pclkd0.rate = pclkd0;
	clk_pclkd1.rate = pclkd1;
}

static struct clk init_clocks[] = {
	{
		.name		= "systimer",
		.id		= -1,
		.parent		= &clk_pclkd1,
		.enable		= s5p6442_clk_ip3_ctrl,
		.ctrlbit	= (1<<16),
	}, {
		.name		= "uart",
		.id		= 0,
		.parent		= &clk_pclkd1,
		.enable		= s5p6442_clk_ip3_ctrl,
		.ctrlbit	= (1<<17),
	}, {
		.name		= "uart",
		.id		= 1,
		.parent		= &clk_pclkd1,
		.enable		= s5p6442_clk_ip3_ctrl,
		.ctrlbit	= (1<<18),
	}, {
		.name		= "uart",
		.id		= 2,
		.parent		= &clk_pclkd1,
		.enable		= s5p6442_clk_ip3_ctrl,
		.ctrlbit	= (1<<19),
	}, {
		.name		= "watchdog",
		.id		= -1,
		.parent		= &clk_pclkd1,
		.enable		= s5p6442_clk_ip3_ctrl,
		.ctrlbit	= (1 << 22),
	}, {
		.name		= "timers",
		.id		= -1,
		.parent		= &clk_pclkd1,
		.enable		= s5p6442_clk_ip3_ctrl,
		.ctrlbit	= (1<<23),
	},
};

static struct clk *clks[] __initdata = {
	&clk_ext,
	&clk_epll,
	&clk_mout_apll.clk,
	&clk_mout_mpll.clk,
	&clk_mout_epll.clk,
	&clk_mout_d0.clk,
	&clk_mout_d0sync.clk,
	&clk_mout_d1.clk,
	&clk_mout_d1sync.clk,
	&clk_hclkd0,
	&clk_pclkd0,
	&clk_hclkd1,
	&clk_pclkd1,
};

void __init s5p6442_register_clocks(void)
{
	s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));

	s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));
	s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));

	s3c_pwmclk_init();
}