clock.c 21 KB

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