s3c6400-clock.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /* linux/arch/arm/plat-s3c64xx/s3c6400-clock.c
  2. *
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * S3C6400 based common clock support
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/list.h>
  18. #include <linux/errno.h>
  19. #include <linux/err.h>
  20. #include <linux/clk.h>
  21. #include <linux/sysdev.h>
  22. #include <linux/io.h>
  23. #include <mach/hardware.h>
  24. #include <mach/map.h>
  25. #include <plat/cpu-freq.h>
  26. #include <plat/regs-clock.h>
  27. #include <plat/clock.h>
  28. #include <plat/cpu.h>
  29. #include <plat/pll.h>
  30. /* fin_apll, fin_mpll and fin_epll are all the same clock, which we call
  31. * ext_xtal_mux for want of an actual name from the manual.
  32. */
  33. static struct clk clk_ext_xtal_mux = {
  34. .name = "ext_xtal",
  35. .id = -1,
  36. };
  37. #define clk_fin_apll clk_ext_xtal_mux
  38. #define clk_fin_mpll clk_ext_xtal_mux
  39. #define clk_fin_epll clk_ext_xtal_mux
  40. #define clk_fout_mpll clk_mpll
  41. #define clk_fout_epll clk_epll
  42. struct clk_sources {
  43. unsigned int nr_sources;
  44. struct clk **sources;
  45. };
  46. struct clksrc_clk {
  47. struct clk clk;
  48. unsigned int mask;
  49. unsigned int shift;
  50. struct clk_sources *sources;
  51. unsigned int divider_shift;
  52. void __iomem *reg_divider;
  53. };
  54. static struct clk clk_fout_apll = {
  55. .name = "fout_apll",
  56. .id = -1,
  57. };
  58. static struct clk *clk_src_apll_list[] = {
  59. [0] = &clk_fin_apll,
  60. [1] = &clk_fout_apll,
  61. };
  62. static struct clk_sources clk_src_apll = {
  63. .sources = clk_src_apll_list,
  64. .nr_sources = ARRAY_SIZE(clk_src_apll_list),
  65. };
  66. static struct clksrc_clk clk_mout_apll = {
  67. .clk = {
  68. .name = "mout_apll",
  69. .id = -1,
  70. },
  71. .shift = S3C6400_CLKSRC_APLL_MOUT_SHIFT,
  72. .mask = S3C6400_CLKSRC_APLL_MOUT,
  73. .sources = &clk_src_apll,
  74. };
  75. static struct clk *clk_src_epll_list[] = {
  76. [0] = &clk_fin_epll,
  77. [1] = &clk_fout_epll,
  78. };
  79. static struct clk_sources clk_src_epll = {
  80. .sources = clk_src_epll_list,
  81. .nr_sources = ARRAY_SIZE(clk_src_epll_list),
  82. };
  83. static struct clksrc_clk clk_mout_epll = {
  84. .clk = {
  85. .name = "mout_epll",
  86. .id = -1,
  87. },
  88. .shift = S3C6400_CLKSRC_EPLL_MOUT_SHIFT,
  89. .mask = S3C6400_CLKSRC_EPLL_MOUT,
  90. .sources = &clk_src_epll,
  91. };
  92. static struct clk *clk_src_mpll_list[] = {
  93. [0] = &clk_fin_mpll,
  94. [1] = &clk_fout_mpll,
  95. };
  96. static struct clk_sources clk_src_mpll = {
  97. .sources = clk_src_mpll_list,
  98. .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
  99. };
  100. static struct clksrc_clk clk_mout_mpll = {
  101. .clk = {
  102. .name = "mout_mpll",
  103. .id = -1,
  104. },
  105. .shift = S3C6400_CLKSRC_MPLL_MOUT_SHIFT,
  106. .mask = S3C6400_CLKSRC_MPLL_MOUT,
  107. .sources = &clk_src_mpll,
  108. };
  109. static unsigned int armclk_mask;
  110. static unsigned long s3c64xx_clk_arm_get_rate(struct clk *clk)
  111. {
  112. unsigned long rate = clk_get_rate(clk->parent);
  113. u32 clkdiv;
  114. /* divisor mask starts at bit0, so no need to shift */
  115. clkdiv = __raw_readl(S3C_CLK_DIV0) & armclk_mask;
  116. return rate / (clkdiv + 1);
  117. }
  118. static unsigned long s3c64xx_clk_arm_round_rate(struct clk *clk,
  119. unsigned long rate)
  120. {
  121. unsigned long parent = clk_get_rate(clk->parent);
  122. u32 div;
  123. if (parent < rate)
  124. return parent;
  125. div = (parent / rate) - 1;
  126. if (div > armclk_mask)
  127. div = armclk_mask;
  128. return parent / (div + 1);
  129. }
  130. static int s3c64xx_clk_arm_set_rate(struct clk *clk, unsigned long rate)
  131. {
  132. unsigned long parent = clk_get_rate(clk->parent);
  133. u32 div;
  134. u32 val;
  135. if (rate < parent / (armclk_mask + 1))
  136. return -EINVAL;
  137. rate = clk_round_rate(clk, rate);
  138. div = clk_get_rate(clk->parent) / rate;
  139. val = __raw_readl(S3C_CLK_DIV0);
  140. val &= ~armclk_mask;
  141. val |= (div - 1);
  142. __raw_writel(val, S3C_CLK_DIV0);
  143. return 0;
  144. }
  145. static struct clk clk_arm = {
  146. .name = "armclk",
  147. .id = -1,
  148. .parent = &clk_mout_apll.clk,
  149. .get_rate = s3c64xx_clk_arm_get_rate,
  150. .set_rate = s3c64xx_clk_arm_set_rate,
  151. .round_rate = s3c64xx_clk_arm_round_rate,
  152. };
  153. static unsigned long s3c64xx_clk_doutmpll_get_rate(struct clk *clk)
  154. {
  155. unsigned long rate = clk_get_rate(clk->parent);
  156. printk(KERN_DEBUG "%s: parent is %ld\n", __func__, rate);
  157. if (__raw_readl(S3C_CLK_DIV0) & S3C6400_CLKDIV0_MPLL_MASK)
  158. rate /= 2;
  159. return rate;
  160. }
  161. static struct clk clk_dout_mpll = {
  162. .name = "dout_mpll",
  163. .id = -1,
  164. .parent = &clk_mout_mpll.clk,
  165. .get_rate = s3c64xx_clk_doutmpll_get_rate,
  166. };
  167. static struct clk *clkset_spi_mmc_list[] = {
  168. &clk_mout_epll.clk,
  169. &clk_dout_mpll,
  170. &clk_fin_epll,
  171. &clk_27m,
  172. };
  173. static struct clk_sources clkset_spi_mmc = {
  174. .sources = clkset_spi_mmc_list,
  175. .nr_sources = ARRAY_SIZE(clkset_spi_mmc_list),
  176. };
  177. static struct clk *clkset_irda_list[] = {
  178. &clk_mout_epll.clk,
  179. &clk_dout_mpll,
  180. NULL,
  181. &clk_27m,
  182. };
  183. static struct clk_sources clkset_irda = {
  184. .sources = clkset_irda_list,
  185. .nr_sources = ARRAY_SIZE(clkset_irda_list),
  186. };
  187. static struct clk *clkset_uart_list[] = {
  188. &clk_mout_epll.clk,
  189. &clk_dout_mpll,
  190. NULL,
  191. NULL
  192. };
  193. static struct clk_sources clkset_uart = {
  194. .sources = clkset_uart_list,
  195. .nr_sources = ARRAY_SIZE(clkset_uart_list),
  196. };
  197. static struct clk *clkset_uhost_list[] = {
  198. &clk_48m,
  199. &clk_mout_epll.clk,
  200. &clk_dout_mpll,
  201. &clk_fin_epll,
  202. };
  203. static struct clk_sources clkset_uhost = {
  204. .sources = clkset_uhost_list,
  205. .nr_sources = ARRAY_SIZE(clkset_uhost_list),
  206. };
  207. /* The peripheral clocks are all controlled via clocksource followed
  208. * by an optional divider and gate stage. We currently roll this into
  209. * one clock which hides the intermediate clock from the mux.
  210. *
  211. * Note, the JPEG clock can only be an even divider...
  212. *
  213. * The scaler and LCD clocks depend on the S3C64XX version, and also
  214. * have a common parent divisor so are not included here.
  215. */
  216. static inline struct clksrc_clk *to_clksrc(struct clk *clk)
  217. {
  218. return container_of(clk, struct clksrc_clk, clk);
  219. }
  220. static unsigned long s3c64xx_getrate_clksrc(struct clk *clk)
  221. {
  222. struct clksrc_clk *sclk = to_clksrc(clk);
  223. unsigned long rate = clk_get_rate(clk->parent);
  224. u32 clkdiv = __raw_readl(sclk->reg_divider);
  225. clkdiv >>= sclk->divider_shift;
  226. clkdiv &= 0xf;
  227. clkdiv++;
  228. rate /= clkdiv;
  229. return rate;
  230. }
  231. static int s3c64xx_setrate_clksrc(struct clk *clk, unsigned long rate)
  232. {
  233. struct clksrc_clk *sclk = to_clksrc(clk);
  234. void __iomem *reg = sclk->reg_divider;
  235. unsigned int div;
  236. u32 val;
  237. rate = clk_round_rate(clk, rate);
  238. div = clk_get_rate(clk->parent) / rate;
  239. if (div > 16)
  240. return -EINVAL;
  241. val = __raw_readl(reg);
  242. val &= ~(0xf << sclk->divider_shift);
  243. val |= (div - 1) << sclk->divider_shift;
  244. __raw_writel(val, reg);
  245. return 0;
  246. }
  247. static int s3c64xx_setparent_clksrc(struct clk *clk, struct clk *parent)
  248. {
  249. struct clksrc_clk *sclk = to_clksrc(clk);
  250. struct clk_sources *srcs = sclk->sources;
  251. u32 clksrc = __raw_readl(S3C_CLK_SRC);
  252. int src_nr = -1;
  253. int ptr;
  254. for (ptr = 0; ptr < srcs->nr_sources; ptr++)
  255. if (srcs->sources[ptr] == parent) {
  256. src_nr = ptr;
  257. break;
  258. }
  259. if (src_nr >= 0) {
  260. clksrc &= ~sclk->mask;
  261. clksrc |= src_nr << sclk->shift;
  262. __raw_writel(clksrc, S3C_CLK_SRC);
  263. clk->parent = parent;
  264. return 0;
  265. }
  266. return -EINVAL;
  267. }
  268. static unsigned long s3c64xx_roundrate_clksrc(struct clk *clk,
  269. unsigned long rate)
  270. {
  271. unsigned long parent_rate = clk_get_rate(clk->parent);
  272. int div;
  273. if (rate > parent_rate)
  274. rate = parent_rate;
  275. else {
  276. div = parent_rate / rate;
  277. if (div == 0)
  278. div = 1;
  279. if (div > 16)
  280. div = 16;
  281. rate = parent_rate / div;
  282. }
  283. return rate;
  284. }
  285. static struct clksrc_clk clk_mmc0 = {
  286. .clk = {
  287. .name = "mmc_bus",
  288. .id = 0,
  289. .ctrlbit = S3C_CLKCON_SCLK_MMC0,
  290. .enable = s3c64xx_sclk_ctrl,
  291. .set_parent = s3c64xx_setparent_clksrc,
  292. .get_rate = s3c64xx_getrate_clksrc,
  293. .set_rate = s3c64xx_setrate_clksrc,
  294. .round_rate = s3c64xx_roundrate_clksrc,
  295. },
  296. .shift = S3C6400_CLKSRC_MMC0_SHIFT,
  297. .mask = S3C6400_CLKSRC_MMC0_MASK,
  298. .sources = &clkset_spi_mmc,
  299. .divider_shift = S3C6400_CLKDIV1_MMC0_SHIFT,
  300. .reg_divider = S3C_CLK_DIV1,
  301. };
  302. static struct clksrc_clk clk_mmc1 = {
  303. .clk = {
  304. .name = "mmc_bus",
  305. .id = 1,
  306. .ctrlbit = S3C_CLKCON_SCLK_MMC1,
  307. .enable = s3c64xx_sclk_ctrl,
  308. .get_rate = s3c64xx_getrate_clksrc,
  309. .set_rate = s3c64xx_setrate_clksrc,
  310. .set_parent = s3c64xx_setparent_clksrc,
  311. .round_rate = s3c64xx_roundrate_clksrc,
  312. },
  313. .shift = S3C6400_CLKSRC_MMC1_SHIFT,
  314. .mask = S3C6400_CLKSRC_MMC1_MASK,
  315. .sources = &clkset_spi_mmc,
  316. .divider_shift = S3C6400_CLKDIV1_MMC1_SHIFT,
  317. .reg_divider = S3C_CLK_DIV1,
  318. };
  319. static struct clksrc_clk clk_mmc2 = {
  320. .clk = {
  321. .name = "mmc_bus",
  322. .id = 2,
  323. .ctrlbit = S3C_CLKCON_SCLK_MMC2,
  324. .enable = s3c64xx_sclk_ctrl,
  325. .get_rate = s3c64xx_getrate_clksrc,
  326. .set_rate = s3c64xx_setrate_clksrc,
  327. .set_parent = s3c64xx_setparent_clksrc,
  328. .round_rate = s3c64xx_roundrate_clksrc,
  329. },
  330. .shift = S3C6400_CLKSRC_MMC2_SHIFT,
  331. .mask = S3C6400_CLKSRC_MMC2_MASK,
  332. .sources = &clkset_spi_mmc,
  333. .divider_shift = S3C6400_CLKDIV1_MMC2_SHIFT,
  334. .reg_divider = S3C_CLK_DIV1,
  335. };
  336. static struct clksrc_clk clk_usbhost = {
  337. .clk = {
  338. .name = "usb-bus-host",
  339. .id = -1,
  340. .ctrlbit = S3C_CLKCON_SCLK_UHOST,
  341. .enable = s3c64xx_sclk_ctrl,
  342. .set_parent = s3c64xx_setparent_clksrc,
  343. .get_rate = s3c64xx_getrate_clksrc,
  344. .set_rate = s3c64xx_setrate_clksrc,
  345. .round_rate = s3c64xx_roundrate_clksrc,
  346. },
  347. .shift = S3C6400_CLKSRC_UHOST_SHIFT,
  348. .mask = S3C6400_CLKSRC_UHOST_MASK,
  349. .sources = &clkset_uhost,
  350. .divider_shift = S3C6400_CLKDIV1_UHOST_SHIFT,
  351. .reg_divider = S3C_CLK_DIV1,
  352. };
  353. static struct clksrc_clk clk_uart_uclk1 = {
  354. .clk = {
  355. .name = "uclk1",
  356. .id = -1,
  357. .ctrlbit = S3C_CLKCON_SCLK_UART,
  358. .enable = s3c64xx_sclk_ctrl,
  359. .set_parent = s3c64xx_setparent_clksrc,
  360. .get_rate = s3c64xx_getrate_clksrc,
  361. .set_rate = s3c64xx_setrate_clksrc,
  362. .round_rate = s3c64xx_roundrate_clksrc,
  363. },
  364. .shift = S3C6400_CLKSRC_UART_SHIFT,
  365. .mask = S3C6400_CLKSRC_UART_MASK,
  366. .sources = &clkset_uart,
  367. .divider_shift = S3C6400_CLKDIV2_UART_SHIFT,
  368. .reg_divider = S3C_CLK_DIV2,
  369. };
  370. /* Where does UCLK0 come from? */
  371. static struct clksrc_clk clk_spi0 = {
  372. .clk = {
  373. .name = "spi-bus",
  374. .id = 0,
  375. .ctrlbit = S3C_CLKCON_SCLK_SPI0,
  376. .enable = s3c64xx_sclk_ctrl,
  377. .set_parent = s3c64xx_setparent_clksrc,
  378. .get_rate = s3c64xx_getrate_clksrc,
  379. .set_rate = s3c64xx_setrate_clksrc,
  380. .round_rate = s3c64xx_roundrate_clksrc,
  381. },
  382. .shift = S3C6400_CLKSRC_SPI0_SHIFT,
  383. .mask = S3C6400_CLKSRC_SPI0_MASK,
  384. .sources = &clkset_spi_mmc,
  385. .divider_shift = S3C6400_CLKDIV2_SPI0_SHIFT,
  386. .reg_divider = S3C_CLK_DIV2,
  387. };
  388. static struct clksrc_clk clk_spi1 = {
  389. .clk = {
  390. .name = "spi-bus",
  391. .id = 1,
  392. .ctrlbit = S3C_CLKCON_SCLK_SPI1,
  393. .enable = s3c64xx_sclk_ctrl,
  394. .set_parent = s3c64xx_setparent_clksrc,
  395. .get_rate = s3c64xx_getrate_clksrc,
  396. .set_rate = s3c64xx_setrate_clksrc,
  397. .round_rate = s3c64xx_roundrate_clksrc,
  398. },
  399. .shift = S3C6400_CLKSRC_SPI1_SHIFT,
  400. .mask = S3C6400_CLKSRC_SPI1_MASK,
  401. .sources = &clkset_spi_mmc,
  402. .divider_shift = S3C6400_CLKDIV2_SPI1_SHIFT,
  403. .reg_divider = S3C_CLK_DIV2,
  404. };
  405. static struct clk clk_iis_cd0 = {
  406. .name = "iis_cdclk0",
  407. .id = -1,
  408. };
  409. static struct clk clk_iis_cd1 = {
  410. .name = "iis_cdclk1",
  411. .id = -1,
  412. };
  413. static struct clk clk_pcm_cd = {
  414. .name = "pcm_cdclk",
  415. .id = -1,
  416. };
  417. static struct clk *clkset_audio0_list[] = {
  418. [0] = &clk_mout_epll.clk,
  419. [1] = &clk_dout_mpll,
  420. [2] = &clk_fin_epll,
  421. [3] = &clk_iis_cd0,
  422. [4] = &clk_pcm_cd,
  423. };
  424. static struct clk_sources clkset_audio0 = {
  425. .sources = clkset_audio0_list,
  426. .nr_sources = ARRAY_SIZE(clkset_audio0_list),
  427. };
  428. static struct clksrc_clk clk_audio0 = {
  429. .clk = {
  430. .name = "audio-bus",
  431. .id = 0,
  432. .ctrlbit = S3C_CLKCON_SCLK_AUDIO0,
  433. .enable = s3c64xx_sclk_ctrl,
  434. .set_parent = s3c64xx_setparent_clksrc,
  435. .get_rate = s3c64xx_getrate_clksrc,
  436. .set_rate = s3c64xx_setrate_clksrc,
  437. .round_rate = s3c64xx_roundrate_clksrc,
  438. },
  439. .shift = S3C6400_CLKSRC_AUDIO0_SHIFT,
  440. .mask = S3C6400_CLKSRC_AUDIO0_MASK,
  441. .sources = &clkset_audio0,
  442. .divider_shift = S3C6400_CLKDIV2_AUDIO0_SHIFT,
  443. .reg_divider = S3C_CLK_DIV2,
  444. };
  445. static struct clk *clkset_audio1_list[] = {
  446. [0] = &clk_mout_epll.clk,
  447. [1] = &clk_dout_mpll,
  448. [2] = &clk_fin_epll,
  449. [3] = &clk_iis_cd1,
  450. [4] = &clk_pcm_cd,
  451. };
  452. static struct clk_sources clkset_audio1 = {
  453. .sources = clkset_audio1_list,
  454. .nr_sources = ARRAY_SIZE(clkset_audio1_list),
  455. };
  456. static struct clksrc_clk clk_audio1 = {
  457. .clk = {
  458. .name = "audio-bus",
  459. .id = 1,
  460. .ctrlbit = S3C_CLKCON_SCLK_AUDIO1,
  461. .enable = s3c64xx_sclk_ctrl,
  462. .set_parent = s3c64xx_setparent_clksrc,
  463. .get_rate = s3c64xx_getrate_clksrc,
  464. .set_rate = s3c64xx_setrate_clksrc,
  465. .round_rate = s3c64xx_roundrate_clksrc,
  466. },
  467. .shift = S3C6400_CLKSRC_AUDIO1_SHIFT,
  468. .mask = S3C6400_CLKSRC_AUDIO1_MASK,
  469. .sources = &clkset_audio1,
  470. .divider_shift = S3C6400_CLKDIV2_AUDIO1_SHIFT,
  471. .reg_divider = S3C_CLK_DIV2,
  472. };
  473. static struct clksrc_clk clk_irda = {
  474. .clk = {
  475. .name = "irda-bus",
  476. .id = 0,
  477. .ctrlbit = S3C_CLKCON_SCLK_IRDA,
  478. .enable = s3c64xx_sclk_ctrl,
  479. .set_parent = s3c64xx_setparent_clksrc,
  480. .get_rate = s3c64xx_getrate_clksrc,
  481. .set_rate = s3c64xx_setrate_clksrc,
  482. .round_rate = s3c64xx_roundrate_clksrc,
  483. },
  484. .shift = S3C6400_CLKSRC_IRDA_SHIFT,
  485. .mask = S3C6400_CLKSRC_IRDA_MASK,
  486. .sources = &clkset_irda,
  487. .divider_shift = S3C6400_CLKDIV2_IRDA_SHIFT,
  488. .reg_divider = S3C_CLK_DIV2,
  489. };
  490. static struct clk *clkset_camif_list[] = {
  491. &clk_h2,
  492. };
  493. static struct clk_sources clkset_camif = {
  494. .sources = clkset_camif_list,
  495. .nr_sources = ARRAY_SIZE(clkset_camif_list),
  496. };
  497. static struct clksrc_clk clk_camif = {
  498. .clk = {
  499. .name = "camera",
  500. .id = -1,
  501. .ctrlbit = S3C_CLKCON_SCLK_CAM,
  502. .enable = s3c64xx_sclk_ctrl,
  503. .set_parent = s3c64xx_setparent_clksrc,
  504. .get_rate = s3c64xx_getrate_clksrc,
  505. .set_rate = s3c64xx_setrate_clksrc,
  506. .round_rate = s3c64xx_roundrate_clksrc,
  507. },
  508. .shift = 0,
  509. .mask = 0,
  510. .sources = &clkset_camif,
  511. .divider_shift = S3C6400_CLKDIV0_CAM_SHIFT,
  512. .reg_divider = S3C_CLK_DIV0,
  513. };
  514. /* Clock initialisation code */
  515. static struct clksrc_clk *init_parents[] = {
  516. &clk_mout_apll,
  517. &clk_mout_epll,
  518. &clk_mout_mpll,
  519. &clk_mmc0,
  520. &clk_mmc1,
  521. &clk_mmc2,
  522. &clk_usbhost,
  523. &clk_uart_uclk1,
  524. &clk_spi0,
  525. &clk_spi1,
  526. &clk_audio0,
  527. &clk_audio1,
  528. &clk_irda,
  529. &clk_camif,
  530. };
  531. static void __init_or_cpufreq s3c6400_set_clksrc(struct clksrc_clk *clk)
  532. {
  533. struct clk_sources *srcs = clk->sources;
  534. u32 clksrc = __raw_readl(S3C_CLK_SRC);
  535. clksrc &= clk->mask;
  536. clksrc >>= clk->shift;
  537. if (clksrc > srcs->nr_sources || !srcs->sources[clksrc]) {
  538. printk(KERN_ERR "%s: bad source %d\n",
  539. clk->clk.name, clksrc);
  540. return;
  541. }
  542. clk->clk.parent = srcs->sources[clksrc];
  543. printk(KERN_INFO "%s: source is %s (%d), rate is %ld\n",
  544. clk->clk.name, clk->clk.parent->name, clksrc,
  545. clk_get_rate(&clk->clk));
  546. }
  547. #define GET_DIV(clk, field) ((((clk) & field##_MASK) >> field##_SHIFT) + 1)
  548. void __init_or_cpufreq s3c6400_setup_clocks(void)
  549. {
  550. struct clk *xtal_clk;
  551. unsigned long xtal;
  552. unsigned long fclk;
  553. unsigned long hclk;
  554. unsigned long hclk2;
  555. unsigned long pclk;
  556. unsigned long epll;
  557. unsigned long apll;
  558. unsigned long mpll;
  559. unsigned int ptr;
  560. u32 clkdiv0;
  561. printk(KERN_DEBUG "%s: registering clocks\n", __func__);
  562. clkdiv0 = __raw_readl(S3C_CLK_DIV0);
  563. printk(KERN_DEBUG "%s: clkdiv0 = %08x\n", __func__, clkdiv0);
  564. xtal_clk = clk_get(NULL, "xtal");
  565. BUG_ON(IS_ERR(xtal_clk));
  566. xtal = clk_get_rate(xtal_clk);
  567. clk_put(xtal_clk);
  568. printk(KERN_DEBUG "%s: xtal is %ld\n", __func__, xtal);
  569. /* For now assume the mux always selects the crystal */
  570. clk_ext_xtal_mux.parent = xtal_clk;
  571. epll = s3c6400_get_epll(xtal);
  572. mpll = s3c6400_get_pll(xtal, __raw_readl(S3C_MPLL_CON));
  573. apll = s3c6400_get_pll(xtal, __raw_readl(S3C_APLL_CON));
  574. fclk = mpll;
  575. printk(KERN_INFO "S3C64XX: PLL settings, A=%ld, M=%ld, E=%ld\n",
  576. apll, mpll, epll);
  577. hclk2 = mpll / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK2);
  578. hclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK);
  579. pclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_PCLK);
  580. printk(KERN_INFO "S3C64XX: HCLK2=%ld, HCLK=%ld, PCLK=%ld\n",
  581. hclk2, hclk, pclk);
  582. clk_fout_mpll.rate = mpll;
  583. clk_fout_epll.rate = epll;
  584. clk_fout_apll.rate = apll;
  585. clk_h2.rate = hclk2;
  586. clk_h.rate = hclk;
  587. clk_p.rate = pclk;
  588. clk_f.rate = fclk;
  589. for (ptr = 0; ptr < ARRAY_SIZE(init_parents); ptr++)
  590. s3c6400_set_clksrc(init_parents[ptr]);
  591. }
  592. static struct clk *clks[] __initdata = {
  593. &clk_ext_xtal_mux,
  594. &clk_iis_cd0,
  595. &clk_iis_cd1,
  596. &clk_pcm_cd,
  597. &clk_mout_epll.clk,
  598. &clk_mout_mpll.clk,
  599. &clk_dout_mpll,
  600. &clk_mmc0.clk,
  601. &clk_mmc1.clk,
  602. &clk_mmc2.clk,
  603. &clk_usbhost.clk,
  604. &clk_uart_uclk1.clk,
  605. &clk_spi0.clk,
  606. &clk_spi1.clk,
  607. &clk_audio0.clk,
  608. &clk_audio1.clk,
  609. &clk_irda.clk,
  610. &clk_camif.clk,
  611. &clk_arm,
  612. };
  613. /**
  614. * s3c6400_register_clocks - register clocks for s3c6400 and above
  615. * @armclk_divlimit: Divisor mask for ARMCLK
  616. *
  617. * Register the clocks for the S3C6400 and above SoC range, such
  618. * as ARMCLK and the clocks which have divider chains attached.
  619. *
  620. * This call does not setup the clocks, which is left to the
  621. * s3c6400_setup_clocks() call which may be needed by the cpufreq
  622. * or resume code to re-set the clocks if the bootloader has changed
  623. * them.
  624. */
  625. void __init s3c6400_register_clocks(unsigned armclk_divlimit)
  626. {
  627. struct clk *clkp;
  628. int ret;
  629. int ptr;
  630. armclk_mask = armclk_divlimit;
  631. for (ptr = 0; ptr < ARRAY_SIZE(clks); ptr++) {
  632. clkp = clks[ptr];
  633. ret = s3c24xx_register_clock(clkp);
  634. if (ret < 0) {
  635. printk(KERN_ERR "Failed to register clock %s (%d)\n",
  636. clkp->name, ret);
  637. }
  638. }
  639. }