clock.c 21 KB

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