clock.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. /* linux/arch/arm/plat-s3c64xx/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. * S3C64XX Base 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/interrupt.h>
  17. #include <linux/ioport.h>
  18. #include <linux/clk.h>
  19. #include <linux/err.h>
  20. #include <linux/io.h>
  21. #include <mach/hardware.h>
  22. #include <mach/map.h>
  23. #include <mach/regs-sys.h>
  24. #include <mach/regs-clock.h>
  25. #include <mach/pll.h>
  26. #include <plat/cpu.h>
  27. #include <plat/devs.h>
  28. #include <plat/cpu-freq.h>
  29. #include <plat/clock.h>
  30. #include <plat/clock-clksrc.h>
  31. /* fin_apll, fin_mpll and fin_epll are all the same clock, which we call
  32. * ext_xtal_mux for want of an actual name from the manual.
  33. */
  34. static struct clk clk_ext_xtal_mux = {
  35. .name = "ext_xtal",
  36. .id = -1,
  37. };
  38. #define clk_fin_apll clk_ext_xtal_mux
  39. #define clk_fin_mpll clk_ext_xtal_mux
  40. #define clk_fin_epll clk_ext_xtal_mux
  41. #define clk_fout_mpll clk_mpll
  42. #define clk_fout_epll clk_epll
  43. struct clk clk_h2 = {
  44. .name = "hclk2",
  45. .id = -1,
  46. .rate = 0,
  47. };
  48. struct clk clk_27m = {
  49. .name = "clk_27m",
  50. .id = -1,
  51. .rate = 27000000,
  52. };
  53. static int clk_48m_ctrl(struct clk *clk, int enable)
  54. {
  55. unsigned long flags;
  56. u32 val;
  57. /* can't rely on clock lock, this register has other usages */
  58. local_irq_save(flags);
  59. val = __raw_readl(S3C64XX_OTHERS);
  60. if (enable)
  61. val |= S3C64XX_OTHERS_USBMASK;
  62. else
  63. val &= ~S3C64XX_OTHERS_USBMASK;
  64. __raw_writel(val, S3C64XX_OTHERS);
  65. local_irq_restore(flags);
  66. return 0;
  67. }
  68. struct clk clk_48m = {
  69. .name = "clk_48m",
  70. .id = -1,
  71. .rate = 48000000,
  72. .enable = clk_48m_ctrl,
  73. };
  74. struct clk clk_xusbxti = {
  75. .name = "xusbxti",
  76. .id = -1,
  77. .rate = 48000000,
  78. };
  79. static int inline s3c64xx_gate(void __iomem *reg,
  80. struct clk *clk,
  81. int enable)
  82. {
  83. unsigned int ctrlbit = clk->ctrlbit;
  84. u32 con;
  85. con = __raw_readl(reg);
  86. if (enable)
  87. con |= ctrlbit;
  88. else
  89. con &= ~ctrlbit;
  90. __raw_writel(con, reg);
  91. return 0;
  92. }
  93. static int s3c64xx_pclk_ctrl(struct clk *clk, int enable)
  94. {
  95. return s3c64xx_gate(S3C_PCLK_GATE, clk, enable);
  96. }
  97. static int s3c64xx_hclk_ctrl(struct clk *clk, int enable)
  98. {
  99. return s3c64xx_gate(S3C_HCLK_GATE, clk, enable);
  100. }
  101. int s3c64xx_sclk_ctrl(struct clk *clk, int enable)
  102. {
  103. return s3c64xx_gate(S3C_SCLK_GATE, clk, enable);
  104. }
  105. static struct clk init_clocks_off[] = {
  106. {
  107. .name = "nand",
  108. .id = -1,
  109. .parent = &clk_h,
  110. }, {
  111. .name = "rtc",
  112. .id = -1,
  113. .parent = &clk_p,
  114. .enable = s3c64xx_pclk_ctrl,
  115. .ctrlbit = S3C_CLKCON_PCLK_RTC,
  116. }, {
  117. .name = "adc",
  118. .id = -1,
  119. .parent = &clk_p,
  120. .enable = s3c64xx_pclk_ctrl,
  121. .ctrlbit = S3C_CLKCON_PCLK_TSADC,
  122. }, {
  123. .name = "i2c",
  124. .id = -1,
  125. .parent = &clk_p,
  126. .enable = s3c64xx_pclk_ctrl,
  127. .ctrlbit = S3C_CLKCON_PCLK_IIC,
  128. }, {
  129. .name = "i2c",
  130. .id = 1,
  131. .parent = &clk_p,
  132. .enable = s3c64xx_pclk_ctrl,
  133. .ctrlbit = S3C6410_CLKCON_PCLK_I2C1,
  134. }, {
  135. .name = "iis",
  136. .id = 0,
  137. .parent = &clk_p,
  138. .enable = s3c64xx_pclk_ctrl,
  139. .ctrlbit = S3C_CLKCON_PCLK_IIS0,
  140. }, {
  141. .name = "iis",
  142. .id = 1,
  143. .parent = &clk_p,
  144. .enable = s3c64xx_pclk_ctrl,
  145. .ctrlbit = S3C_CLKCON_PCLK_IIS1,
  146. }, {
  147. #ifdef CONFIG_CPU_S3C6410
  148. .name = "iis",
  149. .id = -1, /* There's only one IISv4 port */
  150. .parent = &clk_p,
  151. .enable = s3c64xx_pclk_ctrl,
  152. .ctrlbit = S3C6410_CLKCON_PCLK_IIS2,
  153. }, {
  154. #endif
  155. .name = "keypad",
  156. .id = -1,
  157. .parent = &clk_p,
  158. .enable = s3c64xx_pclk_ctrl,
  159. .ctrlbit = S3C_CLKCON_PCLK_KEYPAD,
  160. }, {
  161. .name = "spi",
  162. .id = 0,
  163. .parent = &clk_p,
  164. .enable = s3c64xx_pclk_ctrl,
  165. .ctrlbit = S3C_CLKCON_PCLK_SPI0,
  166. }, {
  167. .name = "spi",
  168. .id = 1,
  169. .parent = &clk_p,
  170. .enable = s3c64xx_pclk_ctrl,
  171. .ctrlbit = S3C_CLKCON_PCLK_SPI1,
  172. }, {
  173. .name = "spi_48m",
  174. .id = 0,
  175. .parent = &clk_48m,
  176. .enable = s3c64xx_sclk_ctrl,
  177. .ctrlbit = S3C_CLKCON_SCLK_SPI0_48,
  178. }, {
  179. .name = "spi_48m",
  180. .id = 1,
  181. .parent = &clk_48m,
  182. .enable = s3c64xx_sclk_ctrl,
  183. .ctrlbit = S3C_CLKCON_SCLK_SPI1_48,
  184. }, {
  185. .name = "48m",
  186. .id = 0,
  187. .parent = &clk_48m,
  188. .enable = s3c64xx_sclk_ctrl,
  189. .ctrlbit = S3C_CLKCON_SCLK_MMC0_48,
  190. }, {
  191. .name = "48m",
  192. .id = 1,
  193. .parent = &clk_48m,
  194. .enable = s3c64xx_sclk_ctrl,
  195. .ctrlbit = S3C_CLKCON_SCLK_MMC1_48,
  196. }, {
  197. .name = "48m",
  198. .id = 2,
  199. .parent = &clk_48m,
  200. .enable = s3c64xx_sclk_ctrl,
  201. .ctrlbit = S3C_CLKCON_SCLK_MMC2_48,
  202. }, {
  203. .name = "dma0",
  204. .id = -1,
  205. .parent = &clk_h,
  206. .enable = s3c64xx_hclk_ctrl,
  207. .ctrlbit = S3C_CLKCON_HCLK_DMA0,
  208. }, {
  209. .name = "dma1",
  210. .id = -1,
  211. .parent = &clk_h,
  212. .enable = s3c64xx_hclk_ctrl,
  213. .ctrlbit = S3C_CLKCON_HCLK_DMA1,
  214. },
  215. };
  216. static struct clk init_clocks[] = {
  217. {
  218. .name = "lcd",
  219. .id = -1,
  220. .parent = &clk_h,
  221. .enable = s3c64xx_hclk_ctrl,
  222. .ctrlbit = S3C_CLKCON_HCLK_LCD,
  223. }, {
  224. .name = "gpio",
  225. .id = -1,
  226. .parent = &clk_p,
  227. .enable = s3c64xx_pclk_ctrl,
  228. .ctrlbit = S3C_CLKCON_PCLK_GPIO,
  229. }, {
  230. .name = "usb-host",
  231. .id = -1,
  232. .parent = &clk_h,
  233. .enable = s3c64xx_hclk_ctrl,
  234. .ctrlbit = S3C_CLKCON_HCLK_UHOST,
  235. }, {
  236. .name = "hsmmc",
  237. .id = 0,
  238. .parent = &clk_h,
  239. .enable = s3c64xx_hclk_ctrl,
  240. .ctrlbit = S3C_CLKCON_HCLK_HSMMC0,
  241. }, {
  242. .name = "hsmmc",
  243. .id = 1,
  244. .parent = &clk_h,
  245. .enable = s3c64xx_hclk_ctrl,
  246. .ctrlbit = S3C_CLKCON_HCLK_HSMMC1,
  247. }, {
  248. .name = "hsmmc",
  249. .id = 2,
  250. .parent = &clk_h,
  251. .enable = s3c64xx_hclk_ctrl,
  252. .ctrlbit = S3C_CLKCON_HCLK_HSMMC2,
  253. }, {
  254. .name = "otg",
  255. .id = -1,
  256. .parent = &clk_h,
  257. .enable = s3c64xx_hclk_ctrl,
  258. .ctrlbit = S3C_CLKCON_HCLK_USB,
  259. }, {
  260. .name = "timers",
  261. .id = -1,
  262. .parent = &clk_p,
  263. .enable = s3c64xx_pclk_ctrl,
  264. .ctrlbit = S3C_CLKCON_PCLK_PWM,
  265. }, {
  266. .name = "uart",
  267. .id = 0,
  268. .parent = &clk_p,
  269. .enable = s3c64xx_pclk_ctrl,
  270. .ctrlbit = S3C_CLKCON_PCLK_UART0,
  271. }, {
  272. .name = "uart",
  273. .id = 1,
  274. .parent = &clk_p,
  275. .enable = s3c64xx_pclk_ctrl,
  276. .ctrlbit = S3C_CLKCON_PCLK_UART1,
  277. }, {
  278. .name = "uart",
  279. .id = 2,
  280. .parent = &clk_p,
  281. .enable = s3c64xx_pclk_ctrl,
  282. .ctrlbit = S3C_CLKCON_PCLK_UART2,
  283. }, {
  284. .name = "uart",
  285. .id = 3,
  286. .parent = &clk_p,
  287. .enable = s3c64xx_pclk_ctrl,
  288. .ctrlbit = S3C_CLKCON_PCLK_UART3,
  289. }, {
  290. .name = "watchdog",
  291. .id = -1,
  292. .parent = &clk_p,
  293. .ctrlbit = S3C_CLKCON_PCLK_WDT,
  294. }, {
  295. .name = "ac97",
  296. .id = -1,
  297. .parent = &clk_p,
  298. .ctrlbit = S3C_CLKCON_PCLK_AC97,
  299. }, {
  300. .name = "cfcon",
  301. .id = -1,
  302. .parent = &clk_h,
  303. .enable = s3c64xx_hclk_ctrl,
  304. .ctrlbit = S3C_CLKCON_HCLK_IHOST,
  305. }
  306. };
  307. static struct clk clk_fout_apll = {
  308. .name = "fout_apll",
  309. .id = -1,
  310. };
  311. static struct clk *clk_src_apll_list[] = {
  312. [0] = &clk_fin_apll,
  313. [1] = &clk_fout_apll,
  314. };
  315. static struct clksrc_sources clk_src_apll = {
  316. .sources = clk_src_apll_list,
  317. .nr_sources = ARRAY_SIZE(clk_src_apll_list),
  318. };
  319. static struct clksrc_clk clk_mout_apll = {
  320. .clk = {
  321. .name = "mout_apll",
  322. .id = -1,
  323. },
  324. .reg_src = { .reg = S3C_CLK_SRC, .shift = 0, .size = 1 },
  325. .sources = &clk_src_apll,
  326. };
  327. static struct clk *clk_src_epll_list[] = {
  328. [0] = &clk_fin_epll,
  329. [1] = &clk_fout_epll,
  330. };
  331. static struct clksrc_sources clk_src_epll = {
  332. .sources = clk_src_epll_list,
  333. .nr_sources = ARRAY_SIZE(clk_src_epll_list),
  334. };
  335. static struct clksrc_clk clk_mout_epll = {
  336. .clk = {
  337. .name = "mout_epll",
  338. .id = -1,
  339. },
  340. .reg_src = { .reg = S3C_CLK_SRC, .shift = 2, .size = 1 },
  341. .sources = &clk_src_epll,
  342. };
  343. static struct clk *clk_src_mpll_list[] = {
  344. [0] = &clk_fin_mpll,
  345. [1] = &clk_fout_mpll,
  346. };
  347. static struct clksrc_sources clk_src_mpll = {
  348. .sources = clk_src_mpll_list,
  349. .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
  350. };
  351. static struct clksrc_clk clk_mout_mpll = {
  352. .clk = {
  353. .name = "mout_mpll",
  354. .id = -1,
  355. },
  356. .reg_src = { .reg = S3C_CLK_SRC, .shift = 1, .size = 1 },
  357. .sources = &clk_src_mpll,
  358. };
  359. static unsigned int armclk_mask;
  360. static unsigned long s3c64xx_clk_arm_get_rate(struct clk *clk)
  361. {
  362. unsigned long rate = clk_get_rate(clk->parent);
  363. u32 clkdiv;
  364. /* divisor mask starts at bit0, so no need to shift */
  365. clkdiv = __raw_readl(S3C_CLK_DIV0) & armclk_mask;
  366. return rate / (clkdiv + 1);
  367. }
  368. static unsigned long s3c64xx_clk_arm_round_rate(struct clk *clk,
  369. unsigned long rate)
  370. {
  371. unsigned long parent = clk_get_rate(clk->parent);
  372. u32 div;
  373. if (parent < rate)
  374. return parent;
  375. div = (parent / rate) - 1;
  376. if (div > armclk_mask)
  377. div = armclk_mask;
  378. return parent / (div + 1);
  379. }
  380. static int s3c64xx_clk_arm_set_rate(struct clk *clk, unsigned long rate)
  381. {
  382. unsigned long parent = clk_get_rate(clk->parent);
  383. u32 div;
  384. u32 val;
  385. if (rate < parent / (armclk_mask + 1))
  386. return -EINVAL;
  387. rate = clk_round_rate(clk, rate);
  388. div = clk_get_rate(clk->parent) / rate;
  389. val = __raw_readl(S3C_CLK_DIV0);
  390. val &= ~armclk_mask;
  391. val |= (div - 1);
  392. __raw_writel(val, S3C_CLK_DIV0);
  393. return 0;
  394. }
  395. static struct clk clk_arm = {
  396. .name = "armclk",
  397. .id = -1,
  398. .parent = &clk_mout_apll.clk,
  399. .ops = &(struct clk_ops) {
  400. .get_rate = s3c64xx_clk_arm_get_rate,
  401. .set_rate = s3c64xx_clk_arm_set_rate,
  402. .round_rate = s3c64xx_clk_arm_round_rate,
  403. },
  404. };
  405. static unsigned long s3c64xx_clk_doutmpll_get_rate(struct clk *clk)
  406. {
  407. unsigned long rate = clk_get_rate(clk->parent);
  408. printk(KERN_DEBUG "%s: parent is %ld\n", __func__, rate);
  409. if (__raw_readl(S3C_CLK_DIV0) & S3C6400_CLKDIV0_MPLL_MASK)
  410. rate /= 2;
  411. return rate;
  412. }
  413. static struct clk_ops clk_dout_ops = {
  414. .get_rate = s3c64xx_clk_doutmpll_get_rate,
  415. };
  416. static struct clk clk_dout_mpll = {
  417. .name = "dout_mpll",
  418. .id = -1,
  419. .parent = &clk_mout_mpll.clk,
  420. .ops = &clk_dout_ops,
  421. };
  422. static struct clk *clkset_spi_mmc_list[] = {
  423. &clk_mout_epll.clk,
  424. &clk_dout_mpll,
  425. &clk_fin_epll,
  426. &clk_27m,
  427. };
  428. static struct clksrc_sources clkset_spi_mmc = {
  429. .sources = clkset_spi_mmc_list,
  430. .nr_sources = ARRAY_SIZE(clkset_spi_mmc_list),
  431. };
  432. static struct clk *clkset_irda_list[] = {
  433. &clk_mout_epll.clk,
  434. &clk_dout_mpll,
  435. NULL,
  436. &clk_27m,
  437. };
  438. static struct clksrc_sources clkset_irda = {
  439. .sources = clkset_irda_list,
  440. .nr_sources = ARRAY_SIZE(clkset_irda_list),
  441. };
  442. static struct clk *clkset_uart_list[] = {
  443. &clk_mout_epll.clk,
  444. &clk_dout_mpll,
  445. NULL,
  446. NULL
  447. };
  448. static struct clksrc_sources clkset_uart = {
  449. .sources = clkset_uart_list,
  450. .nr_sources = ARRAY_SIZE(clkset_uart_list),
  451. };
  452. static struct clk *clkset_uhost_list[] = {
  453. &clk_48m,
  454. &clk_mout_epll.clk,
  455. &clk_dout_mpll,
  456. &clk_fin_epll,
  457. };
  458. static struct clksrc_sources clkset_uhost = {
  459. .sources = clkset_uhost_list,
  460. .nr_sources = ARRAY_SIZE(clkset_uhost_list),
  461. };
  462. /* The peripheral clocks are all controlled via clocksource followed
  463. * by an optional divider and gate stage. We currently roll this into
  464. * one clock which hides the intermediate clock from the mux.
  465. *
  466. * Note, the JPEG clock can only be an even divider...
  467. *
  468. * The scaler and LCD clocks depend on the S3C64XX version, and also
  469. * have a common parent divisor so are not included here.
  470. */
  471. /* clocks that feed other parts of the clock source tree */
  472. static struct clk clk_iis_cd0 = {
  473. .name = "iis_cdclk0",
  474. .id = -1,
  475. };
  476. static struct clk clk_iis_cd1 = {
  477. .name = "iis_cdclk1",
  478. .id = -1,
  479. };
  480. static struct clk clk_iisv4_cd = {
  481. .name = "iis_cdclk_v4",
  482. .id = -1,
  483. };
  484. static struct clk clk_pcm_cd = {
  485. .name = "pcm_cdclk",
  486. .id = -1,
  487. };
  488. static struct clk *clkset_audio0_list[] = {
  489. [0] = &clk_mout_epll.clk,
  490. [1] = &clk_dout_mpll,
  491. [2] = &clk_fin_epll,
  492. [3] = &clk_iis_cd0,
  493. [4] = &clk_pcm_cd,
  494. };
  495. static struct clksrc_sources clkset_audio0 = {
  496. .sources = clkset_audio0_list,
  497. .nr_sources = ARRAY_SIZE(clkset_audio0_list),
  498. };
  499. static struct clk *clkset_audio1_list[] = {
  500. [0] = &clk_mout_epll.clk,
  501. [1] = &clk_dout_mpll,
  502. [2] = &clk_fin_epll,
  503. [3] = &clk_iis_cd1,
  504. [4] = &clk_pcm_cd,
  505. };
  506. static struct clksrc_sources clkset_audio1 = {
  507. .sources = clkset_audio1_list,
  508. .nr_sources = ARRAY_SIZE(clkset_audio1_list),
  509. };
  510. static struct clk *clkset_audio2_list[] = {
  511. [0] = &clk_mout_epll.clk,
  512. [1] = &clk_dout_mpll,
  513. [2] = &clk_fin_epll,
  514. [3] = &clk_iisv4_cd,
  515. [4] = &clk_pcm_cd,
  516. };
  517. static struct clksrc_sources clkset_audio2 = {
  518. .sources = clkset_audio2_list,
  519. .nr_sources = ARRAY_SIZE(clkset_audio2_list),
  520. };
  521. static struct clk *clkset_camif_list[] = {
  522. &clk_h2,
  523. };
  524. static struct clksrc_sources clkset_camif = {
  525. .sources = clkset_camif_list,
  526. .nr_sources = ARRAY_SIZE(clkset_camif_list),
  527. };
  528. static struct clksrc_clk clksrcs[] = {
  529. {
  530. .clk = {
  531. .name = "mmc_bus",
  532. .id = 0,
  533. .ctrlbit = S3C_CLKCON_SCLK_MMC0,
  534. .enable = s3c64xx_sclk_ctrl,
  535. },
  536. .reg_src = { .reg = S3C_CLK_SRC, .shift = 18, .size = 2 },
  537. .reg_div = { .reg = S3C_CLK_DIV1, .shift = 0, .size = 4 },
  538. .sources = &clkset_spi_mmc,
  539. }, {
  540. .clk = {
  541. .name = "mmc_bus",
  542. .id = 1,
  543. .ctrlbit = S3C_CLKCON_SCLK_MMC1,
  544. .enable = s3c64xx_sclk_ctrl,
  545. },
  546. .reg_src = { .reg = S3C_CLK_SRC, .shift = 20, .size = 2 },
  547. .reg_div = { .reg = S3C_CLK_DIV1, .shift = 4, .size = 4 },
  548. .sources = &clkset_spi_mmc,
  549. }, {
  550. .clk = {
  551. .name = "mmc_bus",
  552. .id = 2,
  553. .ctrlbit = S3C_CLKCON_SCLK_MMC2,
  554. .enable = s3c64xx_sclk_ctrl,
  555. },
  556. .reg_src = { .reg = S3C_CLK_SRC, .shift = 22, .size = 2 },
  557. .reg_div = { .reg = S3C_CLK_DIV1, .shift = 8, .size = 4 },
  558. .sources = &clkset_spi_mmc,
  559. }, {
  560. .clk = {
  561. .name = "usb-bus-host",
  562. .id = -1,
  563. .ctrlbit = S3C_CLKCON_SCLK_UHOST,
  564. .enable = s3c64xx_sclk_ctrl,
  565. },
  566. .reg_src = { .reg = S3C_CLK_SRC, .shift = 5, .size = 2 },
  567. .reg_div = { .reg = S3C_CLK_DIV1, .shift = 20, .size = 4 },
  568. .sources = &clkset_uhost,
  569. }, {
  570. .clk = {
  571. .name = "uclk1",
  572. .id = -1,
  573. .ctrlbit = S3C_CLKCON_SCLK_UART,
  574. .enable = s3c64xx_sclk_ctrl,
  575. },
  576. .reg_src = { .reg = S3C_CLK_SRC, .shift = 13, .size = 1 },
  577. .reg_div = { .reg = S3C_CLK_DIV2, .shift = 16, .size = 4 },
  578. .sources = &clkset_uart,
  579. }, {
  580. /* Where does UCLK0 come from? */
  581. .clk = {
  582. .name = "spi-bus",
  583. .id = 0,
  584. .ctrlbit = S3C_CLKCON_SCLK_SPI0,
  585. .enable = s3c64xx_sclk_ctrl,
  586. },
  587. .reg_src = { .reg = S3C_CLK_SRC, .shift = 14, .size = 2 },
  588. .reg_div = { .reg = S3C_CLK_DIV2, .shift = 0, .size = 4 },
  589. .sources = &clkset_spi_mmc,
  590. }, {
  591. .clk = {
  592. .name = "spi-bus",
  593. .id = 1,
  594. .ctrlbit = S3C_CLKCON_SCLK_SPI1,
  595. .enable = s3c64xx_sclk_ctrl,
  596. },
  597. .reg_src = { .reg = S3C_CLK_SRC, .shift = 16, .size = 2 },
  598. .reg_div = { .reg = S3C_CLK_DIV2, .shift = 4, .size = 4 },
  599. .sources = &clkset_spi_mmc,
  600. }, {
  601. .clk = {
  602. .name = "audio-bus",
  603. .id = 0,
  604. .ctrlbit = S3C_CLKCON_SCLK_AUDIO0,
  605. .enable = s3c64xx_sclk_ctrl,
  606. },
  607. .reg_src = { .reg = S3C_CLK_SRC, .shift = 7, .size = 3 },
  608. .reg_div = { .reg = S3C_CLK_DIV2, .shift = 8, .size = 4 },
  609. .sources = &clkset_audio0,
  610. }, {
  611. .clk = {
  612. .name = "audio-bus",
  613. .id = 1,
  614. .ctrlbit = S3C_CLKCON_SCLK_AUDIO1,
  615. .enable = s3c64xx_sclk_ctrl,
  616. },
  617. .reg_src = { .reg = S3C_CLK_SRC, .shift = 10, .size = 3 },
  618. .reg_div = { .reg = S3C_CLK_DIV2, .shift = 12, .size = 4 },
  619. .sources = &clkset_audio1,
  620. }, {
  621. .clk = {
  622. .name = "audio-bus",
  623. .id = 2,
  624. .ctrlbit = S3C6410_CLKCON_SCLK_AUDIO2,
  625. .enable = s3c64xx_sclk_ctrl,
  626. },
  627. .reg_src = { .reg = S3C6410_CLK_SRC2, .shift = 0, .size = 3 },
  628. .reg_div = { .reg = S3C_CLK_DIV2, .shift = 24, .size = 4 },
  629. .sources = &clkset_audio2,
  630. }, {
  631. .clk = {
  632. .name = "irda-bus",
  633. .id = 0,
  634. .ctrlbit = S3C_CLKCON_SCLK_IRDA,
  635. .enable = s3c64xx_sclk_ctrl,
  636. },
  637. .reg_src = { .reg = S3C_CLK_SRC, .shift = 24, .size = 2 },
  638. .reg_div = { .reg = S3C_CLK_DIV2, .shift = 20, .size = 4 },
  639. .sources = &clkset_irda,
  640. }, {
  641. .clk = {
  642. .name = "camera",
  643. .id = -1,
  644. .ctrlbit = S3C_CLKCON_SCLK_CAM,
  645. .enable = s3c64xx_sclk_ctrl,
  646. },
  647. .reg_div = { .reg = S3C_CLK_DIV0, .shift = 20, .size = 4 },
  648. .reg_src = { .reg = NULL, .shift = 0, .size = 0 },
  649. .sources = &clkset_camif,
  650. },
  651. };
  652. /* Clock initialisation code */
  653. static struct clksrc_clk *init_parents[] = {
  654. &clk_mout_apll,
  655. &clk_mout_epll,
  656. &clk_mout_mpll,
  657. };
  658. #define GET_DIV(clk, field) ((((clk) & field##_MASK) >> field##_SHIFT) + 1)
  659. void __init_or_cpufreq s3c6400_setup_clocks(void)
  660. {
  661. struct clk *xtal_clk;
  662. unsigned long xtal;
  663. unsigned long fclk;
  664. unsigned long hclk;
  665. unsigned long hclk2;
  666. unsigned long pclk;
  667. unsigned long epll;
  668. unsigned long apll;
  669. unsigned long mpll;
  670. unsigned int ptr;
  671. u32 clkdiv0;
  672. printk(KERN_DEBUG "%s: registering clocks\n", __func__);
  673. clkdiv0 = __raw_readl(S3C_CLK_DIV0);
  674. printk(KERN_DEBUG "%s: clkdiv0 = %08x\n", __func__, clkdiv0);
  675. xtal_clk = clk_get(NULL, "xtal");
  676. BUG_ON(IS_ERR(xtal_clk));
  677. xtal = clk_get_rate(xtal_clk);
  678. clk_put(xtal_clk);
  679. printk(KERN_DEBUG "%s: xtal is %ld\n", __func__, xtal);
  680. /* For now assume the mux always selects the crystal */
  681. clk_ext_xtal_mux.parent = xtal_clk;
  682. epll = s3c6400_get_epll(xtal);
  683. mpll = s3c6400_get_pll(xtal, __raw_readl(S3C_MPLL_CON));
  684. apll = s3c6400_get_pll(xtal, __raw_readl(S3C_APLL_CON));
  685. fclk = mpll;
  686. printk(KERN_INFO "S3C64XX: PLL settings, A=%ld, M=%ld, E=%ld\n",
  687. apll, mpll, epll);
  688. hclk2 = mpll / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK2);
  689. hclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK);
  690. pclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_PCLK);
  691. printk(KERN_INFO "S3C64XX: HCLK2=%ld, HCLK=%ld, PCLK=%ld\n",
  692. hclk2, hclk, pclk);
  693. clk_fout_mpll.rate = mpll;
  694. clk_fout_epll.rate = epll;
  695. clk_fout_apll.rate = apll;
  696. clk_h2.rate = hclk2;
  697. clk_h.rate = hclk;
  698. clk_p.rate = pclk;
  699. clk_f.rate = fclk;
  700. for (ptr = 0; ptr < ARRAY_SIZE(init_parents); ptr++)
  701. s3c_set_clksrc(init_parents[ptr], true);
  702. for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
  703. s3c_set_clksrc(&clksrcs[ptr], true);
  704. }
  705. static struct clk *clks1[] __initdata = {
  706. &clk_ext_xtal_mux,
  707. &clk_iis_cd0,
  708. &clk_iis_cd1,
  709. &clk_iisv4_cd,
  710. &clk_pcm_cd,
  711. &clk_mout_epll.clk,
  712. &clk_mout_mpll.clk,
  713. &clk_dout_mpll,
  714. &clk_arm,
  715. };
  716. static struct clk *clks[] __initdata = {
  717. &clk_ext,
  718. &clk_epll,
  719. &clk_27m,
  720. &clk_48m,
  721. &clk_h2,
  722. &clk_xusbxti,
  723. };
  724. /**
  725. * s3c64xx_register_clocks - register clocks for s3c6400 and s3c6410
  726. * @xtal: The rate for the clock crystal feeding the PLLs.
  727. * @armclk_divlimit: Divisor mask for ARMCLK.
  728. *
  729. * Register the clocks for the S3C6400 and S3C6410 SoC range, such
  730. * as ARMCLK as well as the necessary parent clocks.
  731. *
  732. * This call does not setup the clocks, which is left to the
  733. * s3c6400_setup_clocks() call which may be needed by the cpufreq
  734. * or resume code to re-set the clocks if the bootloader has changed
  735. * them.
  736. */
  737. void __init s3c64xx_register_clocks(unsigned long xtal,
  738. unsigned armclk_divlimit)
  739. {
  740. armclk_mask = armclk_divlimit;
  741. s3c24xx_register_baseclocks(xtal);
  742. s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
  743. s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
  744. s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
  745. s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
  746. s3c24xx_register_clocks(clks1, ARRAY_SIZE(clks1));
  747. s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));
  748. s3c_pwmclk_init();
  749. }