clock.c 19 KB

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