clock.c 18 KB

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