spear1340_clock.c 38.8 KB
Newer Older
1 2 3 4 5 6
/*
 * arch/arm/mach-spear13xx/spear1340_clock.c
 *
 * SPEAr1340 machine clock framework source file
 *
 * Copyright (C) 2012 ST Microelectronics
V
Viresh Kumar 已提交
7
 * Viresh Kumar <viresh.linux@gmail.com>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This file is licensed under the terms of the GNU General Public
 * License version 2. This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 */

#include <linux/clk.h>
#include <linux/clkdev.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/of_platform.h>
#include <linux/spinlock_types.h>
#include "clk.h"

/* Clock Configuration Registers */
23
#define SPEAR1340_SYS_CLK_CTRL			(misc_base + 0x200)
24 25 26 27 28 29
	#define SPEAR1340_HCLK_SRC_SEL_SHIFT	27
	#define SPEAR1340_HCLK_SRC_SEL_MASK	1
	#define SPEAR1340_SCLK_SRC_SEL_SHIFT	23
	#define SPEAR1340_SCLK_SRC_SEL_MASK	3

/* PLL related registers and bit values */
30
#define SPEAR1340_PLL_CFG			(misc_base + 0x210)
31 32 33 34 35 36 37 38 39 40 41
	/* PLL_CFG bit values */
	#define SPEAR1340_CLCD_SYNT_CLK_MASK		1
	#define SPEAR1340_CLCD_SYNT_CLK_SHIFT		31
	#define SPEAR1340_GEN_SYNT2_3_CLK_SHIFT		29
	#define SPEAR1340_GEN_SYNT_CLK_MASK		2
	#define SPEAR1340_GEN_SYNT0_1_CLK_SHIFT		27
	#define SPEAR1340_PLL_CLK_MASK			2
	#define SPEAR1340_PLL3_CLK_SHIFT		24
	#define SPEAR1340_PLL2_CLK_SHIFT		22
	#define SPEAR1340_PLL1_CLK_SHIFT		20

42 43 44 45 46 47 48 49 50
#define SPEAR1340_PLL1_CTR			(misc_base + 0x214)
#define SPEAR1340_PLL1_FRQ			(misc_base + 0x218)
#define SPEAR1340_PLL2_CTR			(misc_base + 0x220)
#define SPEAR1340_PLL2_FRQ			(misc_base + 0x224)
#define SPEAR1340_PLL3_CTR			(misc_base + 0x22C)
#define SPEAR1340_PLL3_FRQ			(misc_base + 0x230)
#define SPEAR1340_PLL4_CTR			(misc_base + 0x238)
#define SPEAR1340_PLL4_FRQ			(misc_base + 0x23C)
#define SPEAR1340_PERIP_CLK_CFG			(misc_base + 0x244)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
	/* PERIP_CLK_CFG bit values */
	#define SPEAR1340_SPDIF_CLK_MASK		1
	#define SPEAR1340_SPDIF_OUT_CLK_SHIFT		15
	#define SPEAR1340_SPDIF_IN_CLK_SHIFT		14
	#define SPEAR1340_GPT3_CLK_SHIFT		13
	#define SPEAR1340_GPT2_CLK_SHIFT		12
	#define SPEAR1340_GPT_CLK_MASK			1
	#define SPEAR1340_GPT1_CLK_SHIFT		9
	#define SPEAR1340_GPT0_CLK_SHIFT		8
	#define SPEAR1340_UART_CLK_MASK			2
	#define SPEAR1340_UART1_CLK_SHIFT		6
	#define SPEAR1340_UART0_CLK_SHIFT		4
	#define SPEAR1340_CLCD_CLK_MASK			2
	#define SPEAR1340_CLCD_CLK_SHIFT		2
	#define SPEAR1340_C3_CLK_MASK			1
	#define SPEAR1340_C3_CLK_SHIFT			1

68
#define SPEAR1340_GMAC_CLK_CFG			(misc_base + 0x248)
69 70 71 72 73
	#define SPEAR1340_GMAC_PHY_CLK_MASK		1
	#define SPEAR1340_GMAC_PHY_CLK_SHIFT		2
	#define SPEAR1340_GMAC_PHY_INPUT_CLK_MASK	2
	#define SPEAR1340_GMAC_PHY_INPUT_CLK_SHIFT	0

74
#define SPEAR1340_I2S_CLK_CFG			(misc_base + 0x24C)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
	/* I2S_CLK_CFG register mask */
	#define SPEAR1340_I2S_SCLK_X_MASK		0x1F
	#define SPEAR1340_I2S_SCLK_X_SHIFT		27
	#define SPEAR1340_I2S_SCLK_Y_MASK		0x1F
	#define SPEAR1340_I2S_SCLK_Y_SHIFT		22
	#define SPEAR1340_I2S_SCLK_EQ_SEL_SHIFT		21
	#define SPEAR1340_I2S_SCLK_SYNTH_ENB		20
	#define SPEAR1340_I2S_PRS1_CLK_X_MASK		0xFF
	#define SPEAR1340_I2S_PRS1_CLK_X_SHIFT		12
	#define SPEAR1340_I2S_PRS1_CLK_Y_MASK		0xFF
	#define SPEAR1340_I2S_PRS1_CLK_Y_SHIFT		4
	#define SPEAR1340_I2S_PRS1_EQ_SEL_SHIFT		3
	#define SPEAR1340_I2S_REF_SEL_MASK		1
	#define SPEAR1340_I2S_REF_SHIFT			2
	#define SPEAR1340_I2S_SRC_CLK_MASK		2
	#define SPEAR1340_I2S_SRC_CLK_SHIFT		0

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
#define SPEAR1340_C3_CLK_SYNT			(misc_base + 0x250)
#define SPEAR1340_UART0_CLK_SYNT		(misc_base + 0x254)
#define SPEAR1340_UART1_CLK_SYNT		(misc_base + 0x258)
#define SPEAR1340_GMAC_CLK_SYNT			(misc_base + 0x25C)
#define SPEAR1340_SDHCI_CLK_SYNT		(misc_base + 0x260)
#define SPEAR1340_CFXD_CLK_SYNT			(misc_base + 0x264)
#define SPEAR1340_ADC_CLK_SYNT			(misc_base + 0x270)
#define SPEAR1340_AMBA_CLK_SYNT			(misc_base + 0x274)
#define SPEAR1340_CLCD_CLK_SYNT			(misc_base + 0x27C)
#define SPEAR1340_SYS_CLK_SYNT			(misc_base + 0x284)
#define SPEAR1340_GEN_CLK_SYNT0			(misc_base + 0x28C)
#define SPEAR1340_GEN_CLK_SYNT1			(misc_base + 0x294)
#define SPEAR1340_GEN_CLK_SYNT2			(misc_base + 0x29C)
#define SPEAR1340_GEN_CLK_SYNT3			(misc_base + 0x304)
#define SPEAR1340_PERIP1_CLK_ENB		(misc_base + 0x30C)
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
	#define SPEAR1340_RTC_CLK_ENB			31
	#define SPEAR1340_ADC_CLK_ENB			30
	#define SPEAR1340_C3_CLK_ENB			29
	#define SPEAR1340_CLCD_CLK_ENB			27
	#define SPEAR1340_DMA_CLK_ENB			25
	#define SPEAR1340_GPIO1_CLK_ENB			24
	#define SPEAR1340_GPIO0_CLK_ENB			23
	#define SPEAR1340_GPT1_CLK_ENB			22
	#define SPEAR1340_GPT0_CLK_ENB			21
	#define SPEAR1340_I2S_PLAY_CLK_ENB		20
	#define SPEAR1340_I2S_REC_CLK_ENB		19
	#define SPEAR1340_I2C0_CLK_ENB			18
	#define SPEAR1340_SSP_CLK_ENB			17
	#define SPEAR1340_UART0_CLK_ENB			15
	#define SPEAR1340_PCIE_SATA_CLK_ENB		12
	#define SPEAR1340_UOC_CLK_ENB			11
	#define SPEAR1340_UHC1_CLK_ENB			10
	#define SPEAR1340_UHC0_CLK_ENB			9
	#define SPEAR1340_GMAC_CLK_ENB			8
	#define SPEAR1340_CFXD_CLK_ENB			7
	#define SPEAR1340_SDHCI_CLK_ENB			6
	#define SPEAR1340_SMI_CLK_ENB			5
	#define SPEAR1340_FSMC_CLK_ENB			4
	#define SPEAR1340_SYSRAM0_CLK_ENB		3
	#define SPEAR1340_SYSRAM1_CLK_ENB		2
	#define SPEAR1340_SYSROM_CLK_ENB		1
	#define SPEAR1340_BUS_CLK_ENB			0

135
#define SPEAR1340_PERIP2_CLK_ENB		(misc_base + 0x310)
136 137 138 139 140 141 142 143 144 145
	#define SPEAR1340_THSENS_CLK_ENB		8
	#define SPEAR1340_I2S_REF_PAD_CLK_ENB		7
	#define SPEAR1340_ACP_CLK_ENB			6
	#define SPEAR1340_GPT3_CLK_ENB			5
	#define SPEAR1340_GPT2_CLK_ENB			4
	#define SPEAR1340_KBD_CLK_ENB			3
	#define SPEAR1340_CPU_DBG_CLK_ENB		2
	#define SPEAR1340_DDR_CORE_CLK_ENB		1
	#define SPEAR1340_DDR_CTRL_CLK_ENB		0

146
#define SPEAR1340_PERIP3_CLK_ENB		(misc_base + 0x314)
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
	#define SPEAR1340_PLGPIO_CLK_ENB		18
	#define SPEAR1340_VIDEO_DEC_CLK_ENB		16
	#define SPEAR1340_VIDEO_ENC_CLK_ENB		15
	#define SPEAR1340_SPDIF_OUT_CLK_ENB		13
	#define SPEAR1340_SPDIF_IN_CLK_ENB		12
	#define SPEAR1340_VIDEO_IN_CLK_ENB		11
	#define SPEAR1340_CAM0_CLK_ENB			10
	#define SPEAR1340_CAM1_CLK_ENB			9
	#define SPEAR1340_CAM2_CLK_ENB			8
	#define SPEAR1340_CAM3_CLK_ENB			7
	#define SPEAR1340_MALI_CLK_ENB			6
	#define SPEAR1340_CEC0_CLK_ENB			5
	#define SPEAR1340_CEC1_CLK_ENB			4
	#define SPEAR1340_PWM_CLK_ENB			3
	#define SPEAR1340_I2C1_CLK_ENB			2
	#define SPEAR1340_UART1_CLK_ENB			1

static DEFINE_SPINLOCK(_lock);

/* pll rate configuration table, in ascending order of rates */
static struct pll_rate_tbl pll_rtbl[] = {
	/* PCLK 24MHz */
	{.mode = 0, .m = 0x83, .n = 0x04, .p = 0x5}, /* vco 1572, pll 49.125 MHz */
	{.mode = 0, .m = 0x7D, .n = 0x06, .p = 0x3}, /* vco 1000, pll 125 MHz */
	{.mode = 0, .m = 0x64, .n = 0x06, .p = 0x1}, /* vco 800, pll 400 MHz */
	{.mode = 0, .m = 0x7D, .n = 0x06, .p = 0x1}, /* vco 1000, pll 500 MHz */
	{.mode = 0, .m = 0xA6, .n = 0x06, .p = 0x1}, /* vco 1328, pll 664 MHz */
	{.mode = 0, .m = 0xC8, .n = 0x06, .p = 0x1}, /* vco 1600, pll 800 MHz */
	{.mode = 0, .m = 0x7D, .n = 0x06, .p = 0x0}, /* vco 1, pll 1 GHz */
	{.mode = 0, .m = 0x96, .n = 0x06, .p = 0x0}, /* vco 1200, pll 1200 MHz */
};

/* vco-pll4 rate configuration table, in ascending order of rates */
static struct pll_rate_tbl pll4_rtbl[] = {
	{.mode = 0, .m = 0x7D, .n = 0x06, .p = 0x2}, /* vco 1000, pll 250 MHz */
	{.mode = 0, .m = 0xA6, .n = 0x06, .p = 0x2}, /* vco 1328, pll 332 MHz */
	{.mode = 0, .m = 0xC8, .n = 0x06, .p = 0x2}, /* vco 1600, pll 400 MHz */
	{.mode = 0, .m = 0x7D, .n = 0x06, .p = 0x0}, /* vco 1, pll 1 GHz */
};

/*
 * All below entries generate 166 MHz for
 * different values of vco1div2
 */
static struct frac_rate_tbl amba_synth_rtbl[] = {
D
Deepak Sikri 已提交
192
	{.div = 0x073A8}, /* for vco1div2 = 600 MHz */
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
	{.div = 0x06062}, /* for vco1div2 = 500 MHz */
	{.div = 0x04D1B}, /* for vco1div2 = 400 MHz */
	{.div = 0x04000}, /* for vco1div2 = 332 MHz */
	{.div = 0x03031}, /* for vco1div2 = 250 MHz */
	{.div = 0x0268D}, /* for vco1div2 = 200 MHz */
};

/*
 * Synthesizer Clock derived from vcodiv2. This clock is one of the
 * possible clocks to feed cpu directly.
 * We can program this synthesizer to make cpu run on different clock
 * frequencies.
 * Following table provides configuration values to let cpu run on 200,
 * 250, 332, 400 or 500 MHz considering different possibilites of input
 * (vco1div2) clock.
 *
 * --------------------------------------------------------------------
 * vco1div2(Mhz)	fout(Mhz)	cpuclk = fout/2		div
 * --------------------------------------------------------------------
 * 400			200		100			0x04000
 * 400			250		125			0x03333
 * 400			332		166			0x0268D
 * 400			400		200			0x02000
 * --------------------------------------------------------------------
 * 500			200		100			0x05000
 * 500			250		125			0x04000
 * 500			332		166			0x03031
 * 500			400		200			0x02800
 * 500			500		250			0x02000
 * --------------------------------------------------------------------
D
Deepak Sikri 已提交
223 224 225 226 227 228
 * 600			200		100			0x06000
 * 600			250		125			0x04CCE
 * 600			332		166			0x039D5
 * 600			400		200			0x03000
 * 600			500		250			0x02666
 * --------------------------------------------------------------------
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
 * 664			200		100			0x06a38
 * 664			250		125			0x054FD
 * 664			332		166			0x04000
 * 664			400		200			0x0351E
 * 664			500		250			0x02A7E
 * --------------------------------------------------------------------
 * 800			200		100			0x08000
 * 800			250		125			0x06666
 * 800			332		166			0x04D18
 * 800			400		200			0x04000
 * 800			500		250			0x03333
 * --------------------------------------------------------------------
 * sys rate configuration table is in descending order of divisor.
 */
static struct frac_rate_tbl sys_synth_rtbl[] = {
	{.div = 0x08000},
	{.div = 0x06a38},
	{.div = 0x06666},
D
Deepak Sikri 已提交
247
	{.div = 0x06000},
248 249 250
	{.div = 0x054FD},
	{.div = 0x05000},
	{.div = 0x04D18},
D
Deepak Sikri 已提交
251
	{.div = 0x04CCE},
252
	{.div = 0x04000},
D
Deepak Sikri 已提交
253
	{.div = 0x039D5},
254 255 256
	{.div = 0x0351E},
	{.div = 0x03333},
	{.div = 0x03031},
D
Deepak Sikri 已提交
257
	{.div = 0x03000},
258 259 260
	{.div = 0x02A7E},
	{.div = 0x02800},
	{.div = 0x0268D},
D
Deepak Sikri 已提交
261
	{.div = 0x02666},
262 263 264 265 266
	{.div = 0x02000},
};

/* aux rate configuration table, in ascending order of rates */
static struct aux_rate_tbl aux_rtbl[] = {
D
Deepak Sikri 已提交
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
	/* 12.29MHz for vic1div2=600MHz and 10.24MHz for VCO1div2=500MHz */
	{.xscale = 5, .yscale = 122, .eq = 0},
	/* 14.70MHz for vic1div2=600MHz and 12.29MHz for VCO1div2=500MHz */
	{.xscale = 10, .yscale = 204, .eq = 0},
	/* 48MHz for vic1div2=600MHz and 40 MHz for VCO1div2=500MHz */
	{.xscale = 4, .yscale = 25, .eq = 0},
	/* 57.14MHz for vic1div2=600MHz and 48 MHz for VCO1div2=500MHz */
	{.xscale = 4, .yscale = 21, .eq = 0},
	/* 83.33MHz for vic1div2=600MHz and 69.44MHz for VCO1div2=500MHz */
	{.xscale = 5, .yscale = 18, .eq = 0},
	/* 100MHz for vic1div2=600MHz and 83.33 MHz for VCO1div2=500MHz */
	{.xscale = 2, .yscale = 6, .eq = 0},
	/* 125MHz for vic1div2=600MHz and 104.1MHz for VCO1div2=500MHz */
	{.xscale = 5, .yscale = 12, .eq = 0},
	/* 150MHz for vic1div2=600MHz and 125MHz for VCO1div2=500MHz */
	{.xscale = 2, .yscale = 4, .eq = 0},
	/* 166MHz for vic1div2=600MHz and 138.88MHz for VCO1div2=500MHz */
	{.xscale = 5, .yscale = 18, .eq = 1},
	/* 200MHz for vic1div2=600MHz and 166MHz for VCO1div2=500MHz */
	{.xscale = 1, .yscale = 3, .eq = 1},
	/* 250MHz for vic1div2=600MHz and 208.33MHz for VCO1div2=500MHz */
	{.xscale = 5, .yscale = 12, .eq = 1},
	/* 300MHz for vic1div2=600MHz and 250MHz for VCO1div2=500MHz */
	{.xscale = 1, .yscale = 2, .eq = 1},
291 292 293 294 295 296 297 298 299 300 301 302 303
};

/* gmac rate configuration table, in ascending order of rates */
static struct aux_rate_tbl gmac_rtbl[] = {
	/* For gmac phy input clk */
	{.xscale = 2, .yscale = 6, .eq = 0}, /* divided by 6 */
	{.xscale = 2, .yscale = 4, .eq = 0}, /* divided by 4 */
	{.xscale = 1, .yscale = 3, .eq = 1}, /* divided by 3 */
	{.xscale = 1, .yscale = 2, .eq = 1}, /* divided by 2 */
};

/* clcd rate configuration table, in ascending order of rates */
static struct frac_rate_tbl clcd_rtbl[] = {
D
Deepak Sikri 已提交
304 305
	{.div = 0x18000}, /* 25 Mhz , for vc01div4 = 300 MHz*/
	{.div = 0x1638E}, /* 27 Mhz , for vc01div4 = 300 MHz*/
306 307 308 309
	{.div = 0x14000}, /* 25 Mhz , for vc01div4 = 250 MHz*/
	{.div = 0x1284B}, /* 27 Mhz , for vc01div4 = 250 MHz*/
	{.div = 0x0D8D3}, /* 58 Mhz , for vco1div4 = 393 MHz */
	{.div = 0x0B72C}, /* 58 Mhz , for vco1div4 = 332 MHz */
D
Deepak Sikri 已提交
310 311
	{.div = 0x0A584}, /* 58 Mhz , for vco1div4 = 300 MHz */
	{.div = 0x093B1}, /* 65 Mhz , for vc01div4 = 300 MHz*/
312
	{.div = 0x089EE}, /* 58 Mhz , for vc01div4 = 250 MHz*/
D
Deepak Sikri 已提交
313
	{.div = 0x081BA}, /* 74 Mhz , for vc01div4 = 300 MHz*/
314 315 316 317
	{.div = 0x07BA0}, /* 65 Mhz , for vc01div4 = 250 MHz*/
	{.div = 0x06f1C}, /* 72 Mhz , for vc01div4 = 250 MHz*/
	{.div = 0x06E58}, /* 58 Mhz , for vco1div4 = 200 MHz */
	{.div = 0x06c1B}, /* 74 Mhz , for vc01div4 = 250 MHz*/
D
Deepak Sikri 已提交
318
	{.div = 0x058E3}, /* 108 Mhz , for vc01div4 = 300 MHz*/
319
	{.div = 0x04A12}, /* 108 Mhz , for vc01div4 = 250 MHz*/
D
Deepak Sikri 已提交
320
	{.div = 0x040A5}, /* 148.5 Mhz , for vc01div4 = 300 MHz*/
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
	{.div = 0x0378E}, /* 144 Mhz , for vc01div4 = 250 MHz*/
	{.div = 0x0360D}, /* 148 Mhz , for vc01div4 = 250 MHz*/
	{.div = 0x035E0}, /* 148.5 MHz, for vc01div4 = 250 MHz*/
};

/* i2s prescaler1 masks */
static struct aux_clk_masks i2s_prs1_masks = {
	.eq_sel_mask = AUX_EQ_SEL_MASK,
	.eq_sel_shift = SPEAR1340_I2S_PRS1_EQ_SEL_SHIFT,
	.eq1_mask = AUX_EQ1_SEL,
	.eq2_mask = AUX_EQ2_SEL,
	.xscale_sel_mask = SPEAR1340_I2S_PRS1_CLK_X_MASK,
	.xscale_sel_shift = SPEAR1340_I2S_PRS1_CLK_X_SHIFT,
	.yscale_sel_mask = SPEAR1340_I2S_PRS1_CLK_Y_MASK,
	.yscale_sel_shift = SPEAR1340_I2S_PRS1_CLK_Y_SHIFT,
};

/* i2s sclk (bit clock) syynthesizers masks */
static struct aux_clk_masks i2s_sclk_masks = {
	.eq_sel_mask = AUX_EQ_SEL_MASK,
	.eq_sel_shift = SPEAR1340_I2S_SCLK_EQ_SEL_SHIFT,
	.eq1_mask = AUX_EQ1_SEL,
	.eq2_mask = AUX_EQ2_SEL,
	.xscale_sel_mask = SPEAR1340_I2S_SCLK_X_MASK,
	.xscale_sel_shift = SPEAR1340_I2S_SCLK_X_SHIFT,
	.yscale_sel_mask = SPEAR1340_I2S_SCLK_Y_MASK,
	.yscale_sel_shift = SPEAR1340_I2S_SCLK_Y_SHIFT,
	.enable_bit = SPEAR1340_I2S_SCLK_SYNTH_ENB,
};

/* i2s prs1 aux rate configuration table, in ascending order of rates */
static struct aux_rate_tbl i2s_prs1_rtbl[] = {
	/* For parent clk = 49.152 MHz */
	{.xscale = 1, .yscale = 12, .eq = 0}, /* 2.048 MHz, smp freq = 8Khz */
	{.xscale = 11, .yscale = 96, .eq = 0}, /* 2.816 MHz, smp freq = 11Khz */
	{.xscale = 1, .yscale = 6, .eq = 0}, /* 4.096 MHz, smp freq = 16Khz */
	{.xscale = 11, .yscale = 48, .eq = 0}, /* 5.632 MHz, smp freq = 22Khz */

	/*
	 * with parent clk = 49.152, freq gen is 8.192 MHz, smp freq = 32Khz
	 * with parent clk = 12.288, freq gen is 2.048 MHz, smp freq = 8Khz
	 */
	{.xscale = 1, .yscale = 3, .eq = 0},

	/* For parent clk = 49.152 MHz */
	{.xscale = 17, .yscale = 37, .eq = 0}, /* 11.289 MHz, smp freq = 44Khz*/
	{.xscale = 1, .yscale = 2, .eq = 0}, /* 12.288 MHz, smp freq = 48Khz*/
};

/* i2s sclk aux rate configuration table, in ascending order of rates */
static struct aux_rate_tbl i2s_sclk_rtbl[] = {
	/* For sclk = ref_clk * x/2/y */
	{.xscale = 1, .yscale = 4, .eq = 0},
	{.xscale = 1, .yscale = 2, .eq = 0},
};

/* adc rate configuration table, in ascending order of rates */
/* possible adc range is 2.5 MHz to 20 MHz. */
static struct aux_rate_tbl adc_rtbl[] = {
	/* For ahb = 166.67 MHz */
	{.xscale = 1, .yscale = 31, .eq = 0}, /* 2.68 MHz */
	{.xscale = 2, .yscale = 21, .eq = 0}, /* 7.94 MHz */
	{.xscale = 4, .yscale = 21, .eq = 0}, /* 15.87 MHz */
	{.xscale = 10, .yscale = 42, .eq = 0}, /* 19.84 MHz */
};

/* General synth rate configuration table, in ascending order of rates */
static struct frac_rate_tbl gen_rtbl[] = {
D
Deepak Sikri 已提交
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
	{.div = 0x1A92B}, /* 22.5792 MHz for vco1div4=300 MHz*/
	{.div = 0x186A0}, /* 24.576 MHz for vco1div4=300 MHz*/
	{.div = 0x18000}, /* 25 MHz for vco1div4=300 MHz*/
	{.div = 0x1624E}, /* 22.5792 MHz for vco1div4=250 MHz*/
	{.div = 0x14585}, /* 24.576 MHz for vco1div4=250 MHz*/
	{.div = 0x14000}, /* 25 MHz for vco1div4=250 MHz*/
	{.div = 0x0D495}, /* 45.1584 MHz for vco1div4=300 MHz*/
	{.div = 0x0C000}, /* 50 MHz for vco1div4=300 MHz*/
	{.div = 0x0B127}, /* 45.1584 MHz for vco1div4=250 MHz*/
	{.div = 0x0A000}, /* 50 MHz for vco1div4=250 MHz*/
	{.div = 0x07530}, /* 81.92 MHz for vco1div4=300 MHz*/
	{.div = 0x061A8}, /* 81.92 MHz for vco1div4=250 MHz*/
	{.div = 0x06000}, /* 100 MHz for vco1div4=300 MHz*/
	{.div = 0x05000}, /* 100 MHz for vco1div4=250 MHz*/
	{.div = 0x03000}, /* 200 MHz for vco1div4=300 MHz*/
	{.div = 0x02DB6}, /* 210 MHz for vco1div4=300 MHz*/
	{.div = 0x02BA2}, /* 220 MHz for vco1div4=300 MHz*/
	{.div = 0x029BD}, /* 230 MHz for vco1div4=300 MHz*/
	{.div = 0x02800}, /* 200 MHz for vco1div4=250 MHz*/
	{.div = 0x02666}, /* 250 MHz for vco1div4=300 MHz*/
	{.div = 0x02620}, /* 210 MHz for vco1div4=250 MHz*/
	{.div = 0x02460}, /* 220 MHz for vco1div4=250 MHz*/
	{.div = 0x022C0}, /* 230 MHz for vco1div4=250 MHz*/
	{.div = 0x02160}, /* 240 MHz for vco1div4=250 MHz*/
	{.div = 0x02000}, /* 250 MHz for vco1div4=250 MHz*/
414 415 416 417
};

/* clock parents */
static const char *vco_parents[] = { "osc_24m_clk", "osc_25m_clk", };
418
static const char *sys_parents[] = { "pll1_clk", "pll1_clk", "pll1_clk",
419
	"pll1_clk", "sys_syn_clk", "sys_syn_clk", "pll2_clk", "pll3_clk", };
420
static const char *ahb_parents[] = { "cpu_div3_clk", "amba_syn_clk", };
421 422
static const char *gpt_parents[] = { "osc_24m_clk", "apb_clk", };
static const char *uart0_parents[] = { "pll5_clk", "osc_24m_clk",
423
	"uart0_syn_gclk", };
424
static const char *uart1_parents[] = { "pll5_clk", "osc_24m_clk",
425 426 427
	"uart1_syn_gclk", };
static const char *c3_parents[] = { "pll5_clk", "c3_syn_gclk", };
static const char *gmac_phy_input_parents[] = { "gmii_pad_clk", "pll2_clk",
428
	"osc_25m_clk", };
429
static const char *gmac_phy_parents[] = { "phy_input_mclk", "phy_syn_gclk", };
430
static const char *clcd_synth_parents[] = { "vco1div4_clk", "pll2_clk", };
431
static const char *clcd_pixel_parents[] = { "pll5_clk", "clcd_syn_clk", };
432 433
static const char *i2s_src_parents[] = { "vco1div2_clk", "pll2_clk", "pll3_clk",
	"i2s_src_pad_clk", };
434 435 436
static const char *i2s_ref_parents[] = { "i2s_src_mclk", "i2s_prs1_clk", };
static const char *spdif_out_parents[] = { "i2s_src_pad_clk", "gen_syn2_clk", };
static const char *spdif_in_parents[] = { "pll2_clk", "gen_syn3_clk", };
437 438 439

static const char *gen_synth0_1_parents[] = { "vco1div4_clk", "vco3div2_clk",
	"pll3_clk", };
440
static const char *gen_synth2_3_parents[] = { "vco1div4_clk", "vco2div2_clk",
441 442
	"pll2_clk", };

443
void __init spear1340_clk_init(void __iomem *misc_base)
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
{
	struct clk *clk, *clk1;

	clk = clk_register_fixed_rate(NULL, "osc_32k_clk", NULL, CLK_IS_ROOT,
			32000);
	clk_register_clkdev(clk, "osc_32k_clk", NULL);

	clk = clk_register_fixed_rate(NULL, "osc_24m_clk", NULL, CLK_IS_ROOT,
			24000000);
	clk_register_clkdev(clk, "osc_24m_clk", NULL);

	clk = clk_register_fixed_rate(NULL, "osc_25m_clk", NULL, CLK_IS_ROOT,
			25000000);
	clk_register_clkdev(clk, "osc_25m_clk", NULL);

459 460 461
	clk = clk_register_fixed_rate(NULL, "gmii_pad_clk", NULL, CLK_IS_ROOT,
			125000000);
	clk_register_clkdev(clk, "gmii_pad_clk", NULL);
462 463 464 465 466 467 468 469 470

	clk = clk_register_fixed_rate(NULL, "i2s_src_pad_clk", NULL,
			CLK_IS_ROOT, 12288000);
	clk_register_clkdev(clk, "i2s_src_pad_clk", NULL);

	/* clock derived from 32 KHz osc clk */
	clk = clk_register_gate(NULL, "rtc-spear", "osc_32k_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_RTC_CLK_ENB, 0,
			&_lock);
471
	clk_register_clkdev(clk, NULL, "e0580000.rtc");
472 473 474

	/* clock derived from 24 or 25 MHz osc clk */
	/* vco-pll */
475
	clk = clk_register_mux(NULL, "vco1_mclk", vco_parents,
476 477 478
			ARRAY_SIZE(vco_parents), 0, SPEAR1340_PLL_CFG,
			SPEAR1340_PLL1_CLK_SHIFT, SPEAR1340_PLL_CLK_MASK, 0,
			&_lock);
479 480 481
	clk_register_clkdev(clk, "vco1_mclk", NULL);
	clk = clk_register_vco_pll("vco1_clk", "pll1_clk", NULL, "vco1_mclk", 0,
			SPEAR1340_PLL1_CTR, SPEAR1340_PLL1_FRQ, pll_rtbl,
482 483 484 485
			ARRAY_SIZE(pll_rtbl), &_lock, &clk1, NULL);
	clk_register_clkdev(clk, "vco1_clk", NULL);
	clk_register_clkdev(clk1, "pll1_clk", NULL);

486
	clk = clk_register_mux(NULL, "vco2_mclk", vco_parents,
487 488 489
			ARRAY_SIZE(vco_parents), 0, SPEAR1340_PLL_CFG,
			SPEAR1340_PLL2_CLK_SHIFT, SPEAR1340_PLL_CLK_MASK, 0,
			&_lock);
490 491 492
	clk_register_clkdev(clk, "vco2_mclk", NULL);
	clk = clk_register_vco_pll("vco2_clk", "pll2_clk", NULL, "vco2_mclk", 0,
			SPEAR1340_PLL2_CTR, SPEAR1340_PLL2_FRQ, pll_rtbl,
493 494 495 496
			ARRAY_SIZE(pll_rtbl), &_lock, &clk1, NULL);
	clk_register_clkdev(clk, "vco2_clk", NULL);
	clk_register_clkdev(clk1, "pll2_clk", NULL);

497
	clk = clk_register_mux(NULL, "vco3_mclk", vco_parents,
498 499 500
			ARRAY_SIZE(vco_parents), 0, SPEAR1340_PLL_CFG,
			SPEAR1340_PLL3_CLK_SHIFT, SPEAR1340_PLL_CLK_MASK, 0,
			&_lock);
501 502 503
	clk_register_clkdev(clk, "vco3_mclk", NULL);
	clk = clk_register_vco_pll("vco3_clk", "pll3_clk", NULL, "vco3_mclk", 0,
			SPEAR1340_PLL3_CTR, SPEAR1340_PLL3_FRQ, pll_rtbl,
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
			ARRAY_SIZE(pll_rtbl), &_lock, &clk1, NULL);
	clk_register_clkdev(clk, "vco3_clk", NULL);
	clk_register_clkdev(clk1, "pll3_clk", NULL);

	clk = clk_register_vco_pll("vco4_clk", "pll4_clk", NULL, "osc_24m_clk",
			0, SPEAR1340_PLL4_CTR, SPEAR1340_PLL4_FRQ, pll4_rtbl,
			ARRAY_SIZE(pll4_rtbl), &_lock, &clk1, NULL);
	clk_register_clkdev(clk, "vco4_clk", NULL);
	clk_register_clkdev(clk1, "pll4_clk", NULL);

	clk = clk_register_fixed_rate(NULL, "pll5_clk", "osc_24m_clk", 0,
			48000000);
	clk_register_clkdev(clk, "pll5_clk", NULL);

	clk = clk_register_fixed_rate(NULL, "pll6_clk", "osc_25m_clk", 0,
			25000000);
	clk_register_clkdev(clk, "pll6_clk", NULL);

	/* vco div n clocks */
	clk = clk_register_fixed_factor(NULL, "vco1div2_clk", "vco1_clk", 0, 1,
			2);
	clk_register_clkdev(clk, "vco1div2_clk", NULL);

	clk = clk_register_fixed_factor(NULL, "vco1div4_clk", "vco1_clk", 0, 1,
			4);
	clk_register_clkdev(clk, "vco1div4_clk", NULL);

	clk = clk_register_fixed_factor(NULL, "vco2div2_clk", "vco2_clk", 0, 1,
			2);
	clk_register_clkdev(clk, "vco2div2_clk", NULL);

	clk = clk_register_fixed_factor(NULL, "vco3div2_clk", "vco3_clk", 0, 1,
			2);
	clk_register_clkdev(clk, "vco3div2_clk", NULL);

	/* peripherals */
	clk_register_fixed_factor(NULL, "thermal_clk", "osc_24m_clk", 0, 1,
			128);
542
	clk = clk_register_gate(NULL, "thermal_gclk", "thermal_clk", 0,
543 544
			SPEAR1340_PERIP2_CLK_ENB, SPEAR1340_THSENS_CLK_ENB, 0,
			&_lock);
545
	clk_register_clkdev(clk, NULL, "e07008c4.thermal");
546 547 548 549 550 551 552

	/* clock derived from pll4 clk */
	clk = clk_register_fixed_factor(NULL, "ddr_clk", "pll4_clk", 0, 1,
			1);
	clk_register_clkdev(clk, "ddr_clk", NULL);

	/* clock derived from pll1 clk */
553
	clk = clk_register_frac("sys_syn_clk", "vco1div2_clk", 0,
554 555
			SPEAR1340_SYS_CLK_SYNT, sys_synth_rtbl,
			ARRAY_SIZE(sys_synth_rtbl), &_lock);
556
	clk_register_clkdev(clk, "sys_syn_clk", NULL);
557

558
	clk = clk_register_frac("amba_syn_clk", "vco1div2_clk", 0,
559 560
			SPEAR1340_AMBA_CLK_SYNT, amba_synth_rtbl,
			ARRAY_SIZE(amba_synth_rtbl), &_lock);
561
	clk_register_clkdev(clk, "amba_syn_clk", NULL);
562

563
	clk = clk_register_mux(NULL, "sys_mclk", sys_parents,
564 565 566
			ARRAY_SIZE(sys_parents), 0, SPEAR1340_SYS_CLK_CTRL,
			SPEAR1340_SCLK_SRC_SEL_SHIFT,
			SPEAR1340_SCLK_SRC_SEL_MASK, 0, &_lock);
567
	clk_register_clkdev(clk, "sys_mclk", NULL);
568

569
	clk = clk_register_fixed_factor(NULL, "cpu_clk", "sys_mclk", 0, 1,
570 571 572 573 574 575 576 577 578 579 580
			2);
	clk_register_clkdev(clk, "cpu_clk", NULL);

	clk = clk_register_fixed_factor(NULL, "cpu_div3_clk", "cpu_clk", 0, 1,
			3);
	clk_register_clkdev(clk, "cpu_div3_clk", NULL);

	clk = clk_register_fixed_factor(NULL, "wdt_clk", "cpu_clk", 0, 1,
			2);
	clk_register_clkdev(clk, NULL, "ec800620.wdt");

V
Vipul Kumar Samar 已提交
581 582 583 584
	clk = clk_register_fixed_factor(NULL, "smp_twd_clk", "cpu_clk", 0, 1,
			2);
	clk_register_clkdev(clk, NULL, "smp_twd");

585 586 587 588 589 590 591 592 593 594 595
	clk = clk_register_mux(NULL, "ahb_clk", ahb_parents,
			ARRAY_SIZE(ahb_parents), 0, SPEAR1340_SYS_CLK_CTRL,
			SPEAR1340_HCLK_SRC_SEL_SHIFT,
			SPEAR1340_HCLK_SRC_SEL_MASK, 0, &_lock);
	clk_register_clkdev(clk, "ahb_clk", NULL);

	clk = clk_register_fixed_factor(NULL, "apb_clk", "ahb_clk", 0, 1,
			2);
	clk_register_clkdev(clk, "apb_clk", NULL);

	/* gpt clocks */
596
	clk = clk_register_mux(NULL, "gpt0_mclk", gpt_parents,
597 598 599
			ARRAY_SIZE(gpt_parents), 0, SPEAR1340_PERIP_CLK_CFG,
			SPEAR1340_GPT0_CLK_SHIFT, SPEAR1340_GPT_CLK_MASK, 0,
			&_lock);
600 601
	clk_register_clkdev(clk, "gpt0_mclk", NULL);
	clk = clk_register_gate(NULL, "gpt0_clk", "gpt0_mclk", 0,
602 603 604 605
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_GPT0_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "gpt0");

606
	clk = clk_register_mux(NULL, "gpt1_mclk", gpt_parents,
607 608 609
			ARRAY_SIZE(gpt_parents), 0, SPEAR1340_PERIP_CLK_CFG,
			SPEAR1340_GPT1_CLK_SHIFT, SPEAR1340_GPT_CLK_MASK, 0,
			&_lock);
610 611
	clk_register_clkdev(clk, "gpt1_mclk", NULL);
	clk = clk_register_gate(NULL, "gpt1_clk", "gpt1_mclk", 0,
612 613 614 615
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_GPT1_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "gpt1");

616
	clk = clk_register_mux(NULL, "gpt2_mclk", gpt_parents,
617 618 619
			ARRAY_SIZE(gpt_parents), 0, SPEAR1340_PERIP_CLK_CFG,
			SPEAR1340_GPT2_CLK_SHIFT, SPEAR1340_GPT_CLK_MASK, 0,
			&_lock);
620 621
	clk_register_clkdev(clk, "gpt2_mclk", NULL);
	clk = clk_register_gate(NULL, "gpt2_clk", "gpt2_mclk", 0,
622 623 624 625
			SPEAR1340_PERIP2_CLK_ENB, SPEAR1340_GPT2_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "gpt2");

626
	clk = clk_register_mux(NULL, "gpt3_mclk", gpt_parents,
627 628 629
			ARRAY_SIZE(gpt_parents), 0, SPEAR1340_PERIP_CLK_CFG,
			SPEAR1340_GPT3_CLK_SHIFT, SPEAR1340_GPT_CLK_MASK, 0,
			&_lock);
630 631
	clk_register_clkdev(clk, "gpt3_mclk", NULL);
	clk = clk_register_gate(NULL, "gpt3_clk", "gpt3_mclk", 0,
632 633 634 635 636
			SPEAR1340_PERIP2_CLK_ENB, SPEAR1340_GPT3_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "gpt3");

	/* others */
637
	clk = clk_register_aux("uart0_syn_clk", "uart0_syn_gclk",
638 639
			"vco1div2_clk", 0, SPEAR1340_UART0_CLK_SYNT, NULL,
			aux_rtbl, ARRAY_SIZE(aux_rtbl), &_lock, &clk1);
640 641
	clk_register_clkdev(clk, "uart0_syn_clk", NULL);
	clk_register_clkdev(clk1, "uart0_syn_gclk", NULL);
642

643
	clk = clk_register_mux(NULL, "uart0_mclk", uart0_parents,
644 645 646
			ARRAY_SIZE(uart0_parents), CLK_SET_RATE_PARENT,
			SPEAR1340_PERIP_CLK_CFG, SPEAR1340_UART0_CLK_SHIFT,
			SPEAR1340_UART_CLK_MASK, 0, &_lock);
647
	clk_register_clkdev(clk, "uart0_mclk", NULL);
648

649 650 651
	clk = clk_register_gate(NULL, "uart0_clk", "uart0_mclk",
			CLK_SET_RATE_PARENT, SPEAR1340_PERIP1_CLK_ENB,
			SPEAR1340_UART0_CLK_ENB, 0, &_lock);
652 653
	clk_register_clkdev(clk, NULL, "e0000000.serial");

654
	clk = clk_register_aux("uart1_syn_clk", "uart1_syn_gclk",
655 656
			"vco1div2_clk", 0, SPEAR1340_UART1_CLK_SYNT, NULL,
			aux_rtbl, ARRAY_SIZE(aux_rtbl), &_lock, &clk1);
657 658
	clk_register_clkdev(clk, "uart1_syn_clk", NULL);
	clk_register_clkdev(clk1, "uart1_syn_gclk", NULL);
659

660
	clk = clk_register_mux(NULL, "uart1_mclk", uart1_parents,
661 662 663
			ARRAY_SIZE(uart1_parents), 0, SPEAR1340_PERIP_CLK_CFG,
			SPEAR1340_UART1_CLK_SHIFT, SPEAR1340_UART_CLK_MASK, 0,
			&_lock);
664
	clk_register_clkdev(clk, "uart1_mclk", NULL);
665

666
	clk = clk_register_gate(NULL, "uart1_clk", "uart1_mclk", 0,
667
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_UART1_CLK_ENB, 0,
668 669 670
			&_lock);
	clk_register_clkdev(clk, NULL, "b4100000.serial");

671
	clk = clk_register_aux("sdhci_syn_clk", "sdhci_syn_gclk",
672 673
			"vco1div2_clk", 0, SPEAR1340_SDHCI_CLK_SYNT, NULL,
			aux_rtbl, ARRAY_SIZE(aux_rtbl), &_lock, &clk1);
674 675
	clk_register_clkdev(clk, "sdhci_syn_clk", NULL);
	clk_register_clkdev(clk1, "sdhci_syn_gclk", NULL);
676

677 678 679
	clk = clk_register_gate(NULL, "sdhci_clk", "sdhci_syn_gclk",
			CLK_SET_RATE_PARENT, SPEAR1340_PERIP1_CLK_ENB,
			SPEAR1340_SDHCI_CLK_ENB, 0, &_lock);
680 681
	clk_register_clkdev(clk, NULL, "b3000000.sdhci");

682 683 684 685 686
	clk = clk_register_aux("cfxd_syn_clk", "cfxd_syn_gclk", "vco1div2_clk",
			0, SPEAR1340_CFXD_CLK_SYNT, NULL, aux_rtbl,
			ARRAY_SIZE(aux_rtbl), &_lock, &clk1);
	clk_register_clkdev(clk, "cfxd_syn_clk", NULL);
	clk_register_clkdev(clk1, "cfxd_syn_gclk", NULL);
687

688 689 690
	clk = clk_register_gate(NULL, "cfxd_clk", "cfxd_syn_gclk",
			CLK_SET_RATE_PARENT, SPEAR1340_PERIP1_CLK_ENB,
			SPEAR1340_CFXD_CLK_ENB, 0, &_lock);
691 692 693
	clk_register_clkdev(clk, NULL, "b2800000.cf");
	clk_register_clkdev(clk, NULL, "arasan_xd");

694 695 696 697 698
	clk = clk_register_aux("c3_syn_clk", "c3_syn_gclk", "vco1div2_clk", 0,
			SPEAR1340_C3_CLK_SYNT, NULL, aux_rtbl,
			ARRAY_SIZE(aux_rtbl), &_lock, &clk1);
	clk_register_clkdev(clk, "c3_syn_clk", NULL);
	clk_register_clkdev(clk1, "c3_syn_gclk", NULL);
699

700
	clk = clk_register_mux(NULL, "c3_mclk", c3_parents,
701 702 703
			ARRAY_SIZE(c3_parents), CLK_SET_RATE_PARENT,
			SPEAR1340_PERIP_CLK_CFG, SPEAR1340_C3_CLK_SHIFT,
			SPEAR1340_C3_CLK_MASK, 0, &_lock);
704
	clk_register_clkdev(clk, "c3_mclk", NULL);
705

706
	clk = clk_register_gate(NULL, "c3_clk", "c3_mclk", CLK_SET_RATE_PARENT,
707 708
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_C3_CLK_ENB, 0,
			&_lock);
709
	clk_register_clkdev(clk, NULL, "e1800000.c3");
710 711

	/* gmac */
712
	clk = clk_register_mux(NULL, "phy_input_mclk", gmac_phy_input_parents,
713 714 715 716
			ARRAY_SIZE(gmac_phy_input_parents), 0,
			SPEAR1340_GMAC_CLK_CFG,
			SPEAR1340_GMAC_PHY_INPUT_CLK_SHIFT,
			SPEAR1340_GMAC_PHY_INPUT_CLK_MASK, 0, &_lock);
717
	clk_register_clkdev(clk, "phy_input_mclk", NULL);
718

719 720 721 722 723
	clk = clk_register_aux("phy_syn_clk", "phy_syn_gclk", "phy_input_mclk",
			0, SPEAR1340_GMAC_CLK_SYNT, NULL, gmac_rtbl,
			ARRAY_SIZE(gmac_rtbl), &_lock, &clk1);
	clk_register_clkdev(clk, "phy_syn_clk", NULL);
	clk_register_clkdev(clk1, "phy_syn_gclk", NULL);
724

725
	clk = clk_register_mux(NULL, "phy_mclk", gmac_phy_parents,
726 727 728
			ARRAY_SIZE(gmac_phy_parents), 0,
			SPEAR1340_PERIP_CLK_CFG, SPEAR1340_GMAC_PHY_CLK_SHIFT,
			SPEAR1340_GMAC_PHY_CLK_MASK, 0, &_lock);
729
	clk_register_clkdev(clk, "stmmacphy.0", NULL);
730 731

	/* clcd */
732
	clk = clk_register_mux(NULL, "clcd_syn_mclk", clcd_synth_parents,
733 734 735
			ARRAY_SIZE(clcd_synth_parents), 0,
			SPEAR1340_CLCD_CLK_SYNT, SPEAR1340_CLCD_SYNT_CLK_SHIFT,
			SPEAR1340_CLCD_SYNT_CLK_MASK, 0, &_lock);
736
	clk_register_clkdev(clk, "clcd_syn_mclk", NULL);
737

738
	clk = clk_register_frac("clcd_syn_clk", "clcd_syn_mclk", 0,
739 740
			SPEAR1340_CLCD_CLK_SYNT, clcd_rtbl,
			ARRAY_SIZE(clcd_rtbl), &_lock);
741
	clk_register_clkdev(clk, "clcd_syn_clk", NULL);
742

743
	clk = clk_register_mux(NULL, "clcd_pixel_mclk", clcd_pixel_parents,
744
			ARRAY_SIZE(clcd_pixel_parents), CLK_SET_RATE_PARENT,
745 746
			SPEAR1340_PERIP_CLK_CFG, SPEAR1340_CLCD_CLK_SHIFT,
			SPEAR1340_CLCD_CLK_MASK, 0, &_lock);
747
	clk_register_clkdev(clk, "clcd_pixel_mclk", NULL);
748

749
	clk = clk_register_gate(NULL, "clcd_clk", "clcd_pixel_mclk", 0,
750 751
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_CLCD_CLK_ENB, 0,
			&_lock);
752
	clk_register_clkdev(clk, NULL, "e1000000.clcd");
753 754

	/* i2s */
755
	clk = clk_register_mux(NULL, "i2s_src_mclk", i2s_src_parents,
756 757 758
			ARRAY_SIZE(i2s_src_parents), 0, SPEAR1340_I2S_CLK_CFG,
			SPEAR1340_I2S_SRC_CLK_SHIFT, SPEAR1340_I2S_SRC_CLK_MASK,
			0, &_lock);
759
	clk_register_clkdev(clk, "i2s_src_mclk", NULL);
760

761 762 763
	clk = clk_register_aux("i2s_prs1_clk", NULL, "i2s_src_mclk",
			CLK_SET_RATE_PARENT, SPEAR1340_I2S_CLK_CFG,
			&i2s_prs1_masks, i2s_prs1_rtbl,
764 765 766
			ARRAY_SIZE(i2s_prs1_rtbl), &_lock, NULL);
	clk_register_clkdev(clk, "i2s_prs1_clk", NULL);

767
	clk = clk_register_mux(NULL, "i2s_ref_mclk", i2s_ref_parents,
768 769 770
			ARRAY_SIZE(i2s_ref_parents), CLK_SET_RATE_PARENT,
			SPEAR1340_I2S_CLK_CFG, SPEAR1340_I2S_REF_SHIFT,
			SPEAR1340_I2S_REF_SEL_MASK, 0, &_lock);
771
	clk_register_clkdev(clk, "i2s_ref_mclk", NULL);
772

773
	clk = clk_register_gate(NULL, "i2s_ref_pad_clk", "i2s_ref_mclk", 0,
774 775 776 777
			SPEAR1340_PERIP2_CLK_ENB, SPEAR1340_I2S_REF_PAD_CLK_ENB,
			0, &_lock);
	clk_register_clkdev(clk, "i2s_ref_pad_clk", NULL);

778 779 780 781
	clk = clk_register_aux("i2s_sclk_clk", "i2s_sclk_gclk", "i2s_ref_mclk",
			0, SPEAR1340_I2S_CLK_CFG, &i2s_sclk_masks,
			i2s_sclk_rtbl, ARRAY_SIZE(i2s_sclk_rtbl), &_lock,
			&clk1);
782
	clk_register_clkdev(clk, "i2s_sclk_clk", NULL);
783
	clk_register_clkdev(clk1, "i2s_sclk_gclk", NULL);
784 785 786 787 788 789 790 791

	/* clock derived from ahb clk */
	clk = clk_register_gate(NULL, "i2c0_clk", "ahb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_I2C0_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "e0280000.i2c");

	clk = clk_register_gate(NULL, "i2c1_clk", "ahb_clk", 0,
792
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_I2C1_CLK_ENB, 0,
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
			&_lock);
	clk_register_clkdev(clk, NULL, "b4000000.i2c");

	clk = clk_register_gate(NULL, "dma_clk", "ahb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_DMA_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "ea800000.dma");
	clk_register_clkdev(clk, NULL, "eb000000.dma");

	clk = clk_register_gate(NULL, "gmac_clk", "ahb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_GMAC_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "e2000000.eth");

	clk = clk_register_gate(NULL, "fsmc_clk", "ahb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_FSMC_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "b0000000.flash");

	clk = clk_register_gate(NULL, "smi_clk", "ahb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_SMI_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "ea000000.flash");

	clk = clk_register_gate(NULL, "usbh0_clk", "ahb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_UHC0_CLK_ENB, 0,
			&_lock);
820 821
	clk_register_clkdev(clk, NULL, "e4000000.ohci");
	clk_register_clkdev(clk, NULL, "e4800000.ehci");
822 823 824 825

	clk = clk_register_gate(NULL, "usbh1_clk", "ahb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_UHC1_CLK_ENB, 0,
			&_lock);
826 827
	clk_register_clkdev(clk, NULL, "e5000000.ohci");
	clk_register_clkdev(clk, NULL, "e5800000.ehci");
828 829 830 831

	clk = clk_register_gate(NULL, "uoc_clk", "ahb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_UOC_CLK_ENB, 0,
			&_lock);
832
	clk_register_clkdev(clk, NULL, "e3800000.otg");
833 834 835 836 837

	clk = clk_register_gate(NULL, "pcie_sata_clk", "ahb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_PCIE_SATA_CLK_ENB,
			0, &_lock);
	clk_register_clkdev(clk, NULL, "dw_pcie");
838
	clk_register_clkdev(clk, NULL, "b1000000.ahci");
839 840 841 842 843 844 845 846 847 848 849

	clk = clk_register_gate(NULL, "sysram0_clk", "ahb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_SYSRAM0_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, "sysram0_clk", NULL);

	clk = clk_register_gate(NULL, "sysram1_clk", "ahb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_SYSRAM1_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, "sysram1_clk", NULL);

850
	clk = clk_register_aux("adc_syn_clk", "adc_syn_gclk", "ahb_clk",
851 852
			0, SPEAR1340_ADC_CLK_SYNT, NULL, adc_rtbl,
			ARRAY_SIZE(adc_rtbl), &_lock, &clk1);
853 854
	clk_register_clkdev(clk, "adc_syn_clk", NULL);
	clk_register_clkdev(clk1, "adc_syn_gclk", NULL);
855

856 857 858
	clk = clk_register_gate(NULL, "adc_clk", "adc_syn_gclk",
			CLK_SET_RATE_PARENT, SPEAR1340_PERIP1_CLK_ENB,
			SPEAR1340_ADC_CLK_ENB, 0, &_lock);
859
	clk_register_clkdev(clk, NULL, "e0080000.adc");
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879

	/* clock derived from apb clk */
	clk = clk_register_gate(NULL, "ssp_clk", "apb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_SSP_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "e0100000.spi");

	clk = clk_register_gate(NULL, "gpio0_clk", "apb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_GPIO0_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "e0600000.gpio");

	clk = clk_register_gate(NULL, "gpio1_clk", "apb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_GPIO1_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "e0680000.gpio");

	clk = clk_register_gate(NULL, "i2s_play_clk", "apb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_I2S_PLAY_CLK_ENB, 0,
			&_lock);
880
	clk_register_clkdev(clk, NULL, "b2400000.i2s-play");
881 882 883 884

	clk = clk_register_gate(NULL, "i2s_rec_clk", "apb_clk", 0,
			SPEAR1340_PERIP1_CLK_ENB, SPEAR1340_I2S_REC_CLK_ENB, 0,
			&_lock);
885
	clk_register_clkdev(clk, NULL, "b2000000.i2s-rec");
886 887 888 889 890 891 892

	clk = clk_register_gate(NULL, "kbd_clk", "apb_clk", 0,
			SPEAR1340_PERIP2_CLK_ENB, SPEAR1340_KBD_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "e0300000.kbd");

	/* RAS clks */
893 894 895
	clk = clk_register_mux(NULL, "gen_syn0_1_mclk", gen_synth0_1_parents,
			ARRAY_SIZE(gen_synth0_1_parents), 0, SPEAR1340_PLL_CFG,
			SPEAR1340_GEN_SYNT0_1_CLK_SHIFT,
896
			SPEAR1340_GEN_SYNT_CLK_MASK, 0, &_lock);
897
	clk_register_clkdev(clk, "gen_syn0_1_mclk", NULL);
898

899 900 901
	clk = clk_register_mux(NULL, "gen_syn2_3_mclk", gen_synth2_3_parents,
			ARRAY_SIZE(gen_synth2_3_parents), 0, SPEAR1340_PLL_CFG,
			SPEAR1340_GEN_SYNT2_3_CLK_SHIFT,
902
			SPEAR1340_GEN_SYNT_CLK_MASK, 0, &_lock);
903
	clk_register_clkdev(clk, "gen_syn2_3_mclk", NULL);
904

905
	clk = clk_register_frac("gen_syn0_clk", "gen_syn0_1_mclk", 0,
906 907
			SPEAR1340_GEN_CLK_SYNT0, gen_rtbl, ARRAY_SIZE(gen_rtbl),
			&_lock);
908
	clk_register_clkdev(clk, "gen_syn0_clk", NULL);
909

910
	clk = clk_register_frac("gen_syn1_clk", "gen_syn0_1_mclk", 0,
911 912
			SPEAR1340_GEN_CLK_SYNT1, gen_rtbl, ARRAY_SIZE(gen_rtbl),
			&_lock);
913
	clk_register_clkdev(clk, "gen_syn1_clk", NULL);
914

915
	clk = clk_register_frac("gen_syn2_clk", "gen_syn2_3_mclk", 0,
916 917
			SPEAR1340_GEN_CLK_SYNT2, gen_rtbl, ARRAY_SIZE(gen_rtbl),
			&_lock);
918
	clk_register_clkdev(clk, "gen_syn2_clk", NULL);
919

920
	clk = clk_register_frac("gen_syn3_clk", "gen_syn2_3_mclk", 0,
921 922
			SPEAR1340_GEN_CLK_SYNT3, gen_rtbl, ARRAY_SIZE(gen_rtbl),
			&_lock);
923
	clk_register_clkdev(clk, "gen_syn3_clk", NULL);
924

925 926 927
	clk = clk_register_gate(NULL, "mali_clk", "gen_syn3_clk",
			CLK_SET_RATE_PARENT, SPEAR1340_PERIP3_CLK_ENB,
			SPEAR1340_MALI_CLK_ENB, 0, &_lock);
928 929 930 931 932 933 934 935 936 937 938 939
	clk_register_clkdev(clk, NULL, "mali");

	clk = clk_register_gate(NULL, "cec0_clk", "ahb_clk", 0,
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CEC0_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "spear_cec.0");

	clk = clk_register_gate(NULL, "cec1_clk", "ahb_clk", 0,
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CEC1_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "spear_cec.1");

940
	clk = clk_register_mux(NULL, "spdif_out_mclk", spdif_out_parents,
941
			ARRAY_SIZE(spdif_out_parents), CLK_SET_RATE_PARENT,
942 943
			SPEAR1340_PERIP_CLK_CFG, SPEAR1340_SPDIF_OUT_CLK_SHIFT,
			SPEAR1340_SPDIF_CLK_MASK, 0, &_lock);
944
	clk_register_clkdev(clk, "spdif_out_mclk", NULL);
945

946 947 948
	clk = clk_register_gate(NULL, "spdif_out_clk", "spdif_out_mclk",
			CLK_SET_RATE_PARENT, SPEAR1340_PERIP3_CLK_ENB,
			SPEAR1340_SPDIF_OUT_CLK_ENB, 0, &_lock);
949
	clk_register_clkdev(clk, NULL, "d0000000.spdif-out");
950

951
	clk = clk_register_mux(NULL, "spdif_in_mclk", spdif_in_parents,
952
			ARRAY_SIZE(spdif_in_parents), CLK_SET_RATE_PARENT,
953 954
			SPEAR1340_PERIP_CLK_CFG, SPEAR1340_SPDIF_IN_CLK_SHIFT,
			SPEAR1340_SPDIF_CLK_MASK, 0, &_lock);
955
	clk_register_clkdev(clk, "spdif_in_mclk", NULL);
956

957 958 959
	clk = clk_register_gate(NULL, "spdif_in_clk", "spdif_in_mclk",
			CLK_SET_RATE_PARENT, SPEAR1340_PERIP3_CLK_ENB,
			SPEAR1340_SPDIF_IN_CLK_ENB, 0, &_lock);
960
	clk_register_clkdev(clk, NULL, "d0100000.spdif-in");
961

962
	clk = clk_register_gate(NULL, "acp_clk", "acp_mclk", 0,
963 964 965 966
			SPEAR1340_PERIP2_CLK_ENB, SPEAR1340_ACP_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "acp_clk");

967
	clk = clk_register_gate(NULL, "plgpio_clk", "plgpio_mclk", 0,
968 969
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_PLGPIO_CLK_ENB, 0,
			&_lock);
970
	clk_register_clkdev(clk, NULL, "e2800000.gpio");
971

972
	clk = clk_register_gate(NULL, "video_dec_clk", "video_dec_mclk", 0,
973 974 975 976
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_VIDEO_DEC_CLK_ENB,
			0, &_lock);
	clk_register_clkdev(clk, NULL, "video_dec");

977
	clk = clk_register_gate(NULL, "video_enc_clk", "video_enc_mclk", 0,
978 979 980 981
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_VIDEO_ENC_CLK_ENB,
			0, &_lock);
	clk_register_clkdev(clk, NULL, "video_enc");

982
	clk = clk_register_gate(NULL, "video_in_clk", "video_in_mclk", 0,
983 984 985 986
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_VIDEO_IN_CLK_ENB, 0,
			&_lock);
	clk_register_clkdev(clk, NULL, "spear_vip");

987
	clk = clk_register_gate(NULL, "cam0_clk", "cam0_mclk", 0,
988 989
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM0_CLK_ENB, 0,
			&_lock);
990
	clk_register_clkdev(clk, NULL, "d0200000.cam0");
991

992
	clk = clk_register_gate(NULL, "cam1_clk", "cam1_mclk", 0,
993 994
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM1_CLK_ENB, 0,
			&_lock);
995
	clk_register_clkdev(clk, NULL, "d0300000.cam1");
996

997
	clk = clk_register_gate(NULL, "cam2_clk", "cam2_mclk", 0,
998 999
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM2_CLK_ENB, 0,
			&_lock);
1000
	clk_register_clkdev(clk, NULL, "d0400000.cam2");
1001

1002
	clk = clk_register_gate(NULL, "cam3_clk", "cam3_mclk", 0,
1003 1004
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM3_CLK_ENB, 0,
			&_lock);
1005
	clk_register_clkdev(clk, NULL, "d0500000.cam3");
1006

1007
	clk = clk_register_gate(NULL, "pwm_clk", "ahb_clk", 0,
1008 1009
			SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_PWM_CLK_ENB, 0,
			&_lock);
1010
	clk_register_clkdev(clk, NULL, "e0180000.pwm");
1011
}