clock-s3c2412.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. /* linux/arch/arm/mach-s3c2412/clock.c
  2. *
  3. * Copyright (c) 2006 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C2412,S3C2413 Clock control support
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/module.h>
  24. #include <linux/kernel.h>
  25. #include <linux/list.h>
  26. #include <linux/errno.h>
  27. #include <linux/err.h>
  28. #include <linux/device.h>
  29. #include <linux/clk.h>
  30. #include <linux/mutex.h>
  31. #include <linux/delay.h>
  32. #include <linux/serial_core.h>
  33. #include <linux/io.h>
  34. #include <asm/mach/map.h>
  35. #include <mach/hardware.h>
  36. #include <plat/regs-serial.h>
  37. #include <mach/regs-clock.h>
  38. #include <mach/regs-gpio.h>
  39. #include <plat/s3c2412.h>
  40. #include <plat/clock.h>
  41. #include <plat/cpu.h>
  42. /* We currently have to assume that the system is running
  43. * from the XTPll input, and that all ***REFCLKs are being
  44. * fed from it, as we cannot read the state of OM[4] from
  45. * software.
  46. *
  47. * It would be possible for each board initialisation to
  48. * set the correct muxing at initialisation
  49. */
  50. static int s3c2412_clkcon_enable(struct clk *clk, int enable)
  51. {
  52. unsigned int clocks = clk->ctrlbit;
  53. unsigned long clkcon;
  54. clkcon = __raw_readl(S3C2410_CLKCON);
  55. if (enable)
  56. clkcon |= clocks;
  57. else
  58. clkcon &= ~clocks;
  59. __raw_writel(clkcon, S3C2410_CLKCON);
  60. return 0;
  61. }
  62. static int s3c2412_upll_enable(struct clk *clk, int enable)
  63. {
  64. unsigned long upllcon = __raw_readl(S3C2410_UPLLCON);
  65. unsigned long orig = upllcon;
  66. if (!enable)
  67. upllcon |= S3C2412_PLLCON_OFF;
  68. else
  69. upllcon &= ~S3C2412_PLLCON_OFF;
  70. __raw_writel(upllcon, S3C2410_UPLLCON);
  71. /* allow ~150uS for the PLL to settle and lock */
  72. if (enable && (orig & S3C2412_PLLCON_OFF))
  73. udelay(150);
  74. return 0;
  75. }
  76. /* clock selections */
  77. static struct clk clk_erefclk = {
  78. .name = "erefclk",
  79. };
  80. static struct clk clk_urefclk = {
  81. .name = "urefclk",
  82. };
  83. static int s3c2412_setparent_usysclk(struct clk *clk, struct clk *parent)
  84. {
  85. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  86. if (parent == &clk_urefclk)
  87. clksrc &= ~S3C2412_CLKSRC_USYSCLK_UPLL;
  88. else if (parent == &clk_upll)
  89. clksrc |= S3C2412_CLKSRC_USYSCLK_UPLL;
  90. else
  91. return -EINVAL;
  92. clk->parent = parent;
  93. __raw_writel(clksrc, S3C2412_CLKSRC);
  94. return 0;
  95. }
  96. static struct clk clk_usysclk = {
  97. .name = "usysclk",
  98. .parent = &clk_xtal,
  99. .ops = &(struct clk_ops) {
  100. .set_parent = s3c2412_setparent_usysclk,
  101. },
  102. };
  103. static struct clk clk_mrefclk = {
  104. .name = "mrefclk",
  105. .parent = &clk_xtal,
  106. };
  107. static struct clk clk_mdivclk = {
  108. .name = "mdivclk",
  109. .parent = &clk_xtal,
  110. };
  111. static int s3c2412_setparent_usbsrc(struct clk *clk, struct clk *parent)
  112. {
  113. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  114. if (parent == &clk_usysclk)
  115. clksrc &= ~S3C2412_CLKSRC_USBCLK_HCLK;
  116. else if (parent == &clk_h)
  117. clksrc |= S3C2412_CLKSRC_USBCLK_HCLK;
  118. else
  119. return -EINVAL;
  120. clk->parent = parent;
  121. __raw_writel(clksrc, S3C2412_CLKSRC);
  122. return 0;
  123. }
  124. static unsigned long s3c2412_roundrate_usbsrc(struct clk *clk,
  125. unsigned long rate)
  126. {
  127. unsigned long parent_rate = clk_get_rate(clk->parent);
  128. int div;
  129. if (rate > parent_rate)
  130. return parent_rate;
  131. div = parent_rate / rate;
  132. if (div > 2)
  133. div = 2;
  134. return parent_rate / div;
  135. }
  136. static unsigned long s3c2412_getrate_usbsrc(struct clk *clk)
  137. {
  138. unsigned long parent_rate = clk_get_rate(clk->parent);
  139. unsigned long div = __raw_readl(S3C2410_CLKDIVN);
  140. return parent_rate / ((div & S3C2412_CLKDIVN_USB48DIV) ? 2 : 1);
  141. }
  142. static int s3c2412_setrate_usbsrc(struct clk *clk, unsigned long rate)
  143. {
  144. unsigned long parent_rate = clk_get_rate(clk->parent);
  145. unsigned long clkdivn = __raw_readl(S3C2410_CLKDIVN);
  146. rate = s3c2412_roundrate_usbsrc(clk, rate);
  147. if ((parent_rate / rate) == 2)
  148. clkdivn |= S3C2412_CLKDIVN_USB48DIV;
  149. else
  150. clkdivn &= ~S3C2412_CLKDIVN_USB48DIV;
  151. __raw_writel(clkdivn, S3C2410_CLKDIVN);
  152. return 0;
  153. }
  154. static struct clk clk_usbsrc = {
  155. .name = "usbsrc",
  156. .ops = &(struct clk_ops) {
  157. .get_rate = s3c2412_getrate_usbsrc,
  158. .set_rate = s3c2412_setrate_usbsrc,
  159. .round_rate = s3c2412_roundrate_usbsrc,
  160. .set_parent = s3c2412_setparent_usbsrc,
  161. },
  162. };
  163. static int s3c2412_setparent_msysclk(struct clk *clk, struct clk *parent)
  164. {
  165. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  166. if (parent == &clk_mdivclk)
  167. clksrc &= ~S3C2412_CLKSRC_MSYSCLK_MPLL;
  168. else if (parent == &clk_mpll)
  169. clksrc |= S3C2412_CLKSRC_MSYSCLK_MPLL;
  170. else
  171. return -EINVAL;
  172. clk->parent = parent;
  173. __raw_writel(clksrc, S3C2412_CLKSRC);
  174. return 0;
  175. }
  176. static struct clk clk_msysclk = {
  177. .name = "msysclk",
  178. .ops = &(struct clk_ops) {
  179. .set_parent = s3c2412_setparent_msysclk,
  180. },
  181. };
  182. static int s3c2412_setparent_armclk(struct clk *clk, struct clk *parent)
  183. {
  184. unsigned long flags;
  185. unsigned long clkdiv;
  186. unsigned long dvs;
  187. /* Note, we current equate fclk andf msysclk for S3C2412 */
  188. if (parent == &clk_msysclk || parent == &clk_f)
  189. dvs = 0;
  190. else if (parent == &clk_h)
  191. dvs = S3C2412_CLKDIVN_DVSEN;
  192. else
  193. return -EINVAL;
  194. clk->parent = parent;
  195. /* update this under irq lockdown, clkdivn is not protected
  196. * by the clock system. */
  197. local_irq_save(flags);
  198. clkdiv = __raw_readl(S3C2410_CLKDIVN);
  199. clkdiv &= ~S3C2412_CLKDIVN_DVSEN;
  200. clkdiv |= dvs;
  201. __raw_writel(clkdiv, S3C2410_CLKDIVN);
  202. local_irq_restore(flags);
  203. return 0;
  204. }
  205. static struct clk clk_armclk = {
  206. .name = "armclk",
  207. .parent = &clk_msysclk,
  208. .ops = &(struct clk_ops) {
  209. .set_parent = s3c2412_setparent_armclk,
  210. },
  211. };
  212. /* these next clocks have an divider immediately after them,
  213. * so we can register them with their divider and leave out the
  214. * intermediate clock stage
  215. */
  216. static unsigned long s3c2412_roundrate_clksrc(struct clk *clk,
  217. unsigned long rate)
  218. {
  219. unsigned long parent_rate = clk_get_rate(clk->parent);
  220. int div;
  221. if (rate > parent_rate)
  222. return parent_rate;
  223. /* note, we remove the +/- 1 calculations as they cancel out */
  224. div = (rate / parent_rate);
  225. if (div < 1)
  226. div = 1;
  227. else if (div > 16)
  228. div = 16;
  229. return parent_rate / div;
  230. }
  231. static int s3c2412_setparent_uart(struct clk *clk, struct clk *parent)
  232. {
  233. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  234. if (parent == &clk_erefclk)
  235. clksrc &= ~S3C2412_CLKSRC_UARTCLK_MPLL;
  236. else if (parent == &clk_mpll)
  237. clksrc |= S3C2412_CLKSRC_UARTCLK_MPLL;
  238. else
  239. return -EINVAL;
  240. clk->parent = parent;
  241. __raw_writel(clksrc, S3C2412_CLKSRC);
  242. return 0;
  243. }
  244. static unsigned long s3c2412_getrate_uart(struct clk *clk)
  245. {
  246. unsigned long parent_rate = clk_get_rate(clk->parent);
  247. unsigned long div = __raw_readl(S3C2410_CLKDIVN);
  248. div &= S3C2412_CLKDIVN_UARTDIV_MASK;
  249. div >>= S3C2412_CLKDIVN_UARTDIV_SHIFT;
  250. return parent_rate / (div + 1);
  251. }
  252. static int s3c2412_setrate_uart(struct clk *clk, unsigned long rate)
  253. {
  254. unsigned long parent_rate = clk_get_rate(clk->parent);
  255. unsigned long clkdivn = __raw_readl(S3C2410_CLKDIVN);
  256. rate = s3c2412_roundrate_clksrc(clk, rate);
  257. clkdivn &= ~S3C2412_CLKDIVN_UARTDIV_MASK;
  258. clkdivn |= ((parent_rate / rate) - 1) << S3C2412_CLKDIVN_UARTDIV_SHIFT;
  259. __raw_writel(clkdivn, S3C2410_CLKDIVN);
  260. return 0;
  261. }
  262. static struct clk clk_uart = {
  263. .name = "uartclk",
  264. .ops = &(struct clk_ops) {
  265. .get_rate = s3c2412_getrate_uart,
  266. .set_rate = s3c2412_setrate_uart,
  267. .set_parent = s3c2412_setparent_uart,
  268. .round_rate = s3c2412_roundrate_clksrc,
  269. },
  270. };
  271. static int s3c2412_setparent_i2s(struct clk *clk, struct clk *parent)
  272. {
  273. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  274. if (parent == &clk_erefclk)
  275. clksrc &= ~S3C2412_CLKSRC_I2SCLK_MPLL;
  276. else if (parent == &clk_mpll)
  277. clksrc |= S3C2412_CLKSRC_I2SCLK_MPLL;
  278. else
  279. return -EINVAL;
  280. clk->parent = parent;
  281. __raw_writel(clksrc, S3C2412_CLKSRC);
  282. return 0;
  283. }
  284. static unsigned long s3c2412_getrate_i2s(struct clk *clk)
  285. {
  286. unsigned long parent_rate = clk_get_rate(clk->parent);
  287. unsigned long div = __raw_readl(S3C2410_CLKDIVN);
  288. div &= S3C2412_CLKDIVN_I2SDIV_MASK;
  289. div >>= S3C2412_CLKDIVN_I2SDIV_SHIFT;
  290. return parent_rate / (div + 1);
  291. }
  292. static int s3c2412_setrate_i2s(struct clk *clk, unsigned long rate)
  293. {
  294. unsigned long parent_rate = clk_get_rate(clk->parent);
  295. unsigned long clkdivn = __raw_readl(S3C2410_CLKDIVN);
  296. rate = s3c2412_roundrate_clksrc(clk, rate);
  297. clkdivn &= ~S3C2412_CLKDIVN_I2SDIV_MASK;
  298. clkdivn |= ((parent_rate / rate) - 1) << S3C2412_CLKDIVN_I2SDIV_SHIFT;
  299. __raw_writel(clkdivn, S3C2410_CLKDIVN);
  300. return 0;
  301. }
  302. static struct clk clk_i2s = {
  303. .name = "i2sclk",
  304. .ops = &(struct clk_ops) {
  305. .get_rate = s3c2412_getrate_i2s,
  306. .set_rate = s3c2412_setrate_i2s,
  307. .set_parent = s3c2412_setparent_i2s,
  308. .round_rate = s3c2412_roundrate_clksrc,
  309. },
  310. };
  311. static int s3c2412_setparent_cam(struct clk *clk, struct clk *parent)
  312. {
  313. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  314. if (parent == &clk_usysclk)
  315. clksrc &= ~S3C2412_CLKSRC_CAMCLK_HCLK;
  316. else if (parent == &clk_h)
  317. clksrc |= S3C2412_CLKSRC_CAMCLK_HCLK;
  318. else
  319. return -EINVAL;
  320. clk->parent = parent;
  321. __raw_writel(clksrc, S3C2412_CLKSRC);
  322. return 0;
  323. }
  324. static unsigned long s3c2412_getrate_cam(struct clk *clk)
  325. {
  326. unsigned long parent_rate = clk_get_rate(clk->parent);
  327. unsigned long div = __raw_readl(S3C2410_CLKDIVN);
  328. div &= S3C2412_CLKDIVN_CAMDIV_MASK;
  329. div >>= S3C2412_CLKDIVN_CAMDIV_SHIFT;
  330. return parent_rate / (div + 1);
  331. }
  332. static int s3c2412_setrate_cam(struct clk *clk, unsigned long rate)
  333. {
  334. unsigned long parent_rate = clk_get_rate(clk->parent);
  335. unsigned long clkdivn = __raw_readl(S3C2410_CLKDIVN);
  336. rate = s3c2412_roundrate_clksrc(clk, rate);
  337. clkdivn &= ~S3C2412_CLKDIVN_CAMDIV_MASK;
  338. clkdivn |= ((parent_rate / rate) - 1) << S3C2412_CLKDIVN_CAMDIV_SHIFT;
  339. __raw_writel(clkdivn, S3C2410_CLKDIVN);
  340. return 0;
  341. }
  342. static struct clk clk_cam = {
  343. .name = "camif-upll", /* same as 2440 name */
  344. .ops = &(struct clk_ops) {
  345. .get_rate = s3c2412_getrate_cam,
  346. .set_rate = s3c2412_setrate_cam,
  347. .set_parent = s3c2412_setparent_cam,
  348. .round_rate = s3c2412_roundrate_clksrc,
  349. },
  350. };
  351. /* standard clock definitions */
  352. static struct clk init_clocks_disable[] = {
  353. {
  354. .name = "nand",
  355. .parent = &clk_h,
  356. .enable = s3c2412_clkcon_enable,
  357. .ctrlbit = S3C2412_CLKCON_NAND,
  358. }, {
  359. .name = "sdi",
  360. .parent = &clk_p,
  361. .enable = s3c2412_clkcon_enable,
  362. .ctrlbit = S3C2412_CLKCON_SDI,
  363. }, {
  364. .name = "adc",
  365. .parent = &clk_p,
  366. .enable = s3c2412_clkcon_enable,
  367. .ctrlbit = S3C2412_CLKCON_ADC,
  368. }, {
  369. .name = "i2c",
  370. .parent = &clk_p,
  371. .enable = s3c2412_clkcon_enable,
  372. .ctrlbit = S3C2412_CLKCON_IIC,
  373. }, {
  374. .name = "iis",
  375. .parent = &clk_p,
  376. .enable = s3c2412_clkcon_enable,
  377. .ctrlbit = S3C2412_CLKCON_IIS,
  378. }, {
  379. .name = "spi",
  380. .parent = &clk_p,
  381. .enable = s3c2412_clkcon_enable,
  382. .ctrlbit = S3C2412_CLKCON_SPI,
  383. }
  384. };
  385. static struct clk init_clocks[] = {
  386. {
  387. .name = "dma",
  388. .parent = &clk_h,
  389. .enable = s3c2412_clkcon_enable,
  390. .ctrlbit = S3C2412_CLKCON_DMA0,
  391. }, {
  392. .name = "dma",
  393. .parent = &clk_h,
  394. .enable = s3c2412_clkcon_enable,
  395. .ctrlbit = S3C2412_CLKCON_DMA1,
  396. }, {
  397. .name = "dma",
  398. .parent = &clk_h,
  399. .enable = s3c2412_clkcon_enable,
  400. .ctrlbit = S3C2412_CLKCON_DMA2,
  401. }, {
  402. .name = "dma",
  403. .parent = &clk_h,
  404. .enable = s3c2412_clkcon_enable,
  405. .ctrlbit = S3C2412_CLKCON_DMA3,
  406. }, {
  407. .name = "lcd",
  408. .parent = &clk_h,
  409. .enable = s3c2412_clkcon_enable,
  410. .ctrlbit = S3C2412_CLKCON_LCDC,
  411. }, {
  412. .name = "gpio",
  413. .parent = &clk_p,
  414. .enable = s3c2412_clkcon_enable,
  415. .ctrlbit = S3C2412_CLKCON_GPIO,
  416. }, {
  417. .name = "usb-host",
  418. .parent = &clk_h,
  419. .enable = s3c2412_clkcon_enable,
  420. .ctrlbit = S3C2412_CLKCON_USBH,
  421. }, {
  422. .name = "usb-device",
  423. .parent = &clk_h,
  424. .enable = s3c2412_clkcon_enable,
  425. .ctrlbit = S3C2412_CLKCON_USBD,
  426. }, {
  427. .name = "timers",
  428. .parent = &clk_p,
  429. .enable = s3c2412_clkcon_enable,
  430. .ctrlbit = S3C2412_CLKCON_PWMT,
  431. }, {
  432. .name = "uart",
  433. .devname = "s3c2412-uart.0",
  434. .parent = &clk_p,
  435. .enable = s3c2412_clkcon_enable,
  436. .ctrlbit = S3C2412_CLKCON_UART0,
  437. }, {
  438. .name = "uart",
  439. .devname = "s3c2412-uart.1",
  440. .parent = &clk_p,
  441. .enable = s3c2412_clkcon_enable,
  442. .ctrlbit = S3C2412_CLKCON_UART1,
  443. }, {
  444. .name = "uart",
  445. .devname = "s3c2412-uart.2",
  446. .parent = &clk_p,
  447. .enable = s3c2412_clkcon_enable,
  448. .ctrlbit = S3C2412_CLKCON_UART2,
  449. }, {
  450. .name = "rtc",
  451. .parent = &clk_p,
  452. .enable = s3c2412_clkcon_enable,
  453. .ctrlbit = S3C2412_CLKCON_RTC,
  454. }, {
  455. .name = "watchdog",
  456. .parent = &clk_p,
  457. .ctrlbit = 0,
  458. }, {
  459. .name = "usb-bus-gadget",
  460. .parent = &clk_usb_bus,
  461. .enable = s3c2412_clkcon_enable,
  462. .ctrlbit = S3C2412_CLKCON_USB_DEV48,
  463. }, {
  464. .name = "usb-bus-host",
  465. .parent = &clk_usb_bus,
  466. .enable = s3c2412_clkcon_enable,
  467. .ctrlbit = S3C2412_CLKCON_USB_HOST48,
  468. }
  469. };
  470. /* clocks to add where we need to check their parentage */
  471. struct clk_init {
  472. struct clk *clk;
  473. unsigned int bit;
  474. struct clk *src_0;
  475. struct clk *src_1;
  476. };
  477. static struct clk_init clks_src[] __initdata = {
  478. {
  479. .clk = &clk_usysclk,
  480. .bit = S3C2412_CLKSRC_USBCLK_HCLK,
  481. .src_0 = &clk_urefclk,
  482. .src_1 = &clk_upll,
  483. }, {
  484. .clk = &clk_i2s,
  485. .bit = S3C2412_CLKSRC_I2SCLK_MPLL,
  486. .src_0 = &clk_erefclk,
  487. .src_1 = &clk_mpll,
  488. }, {
  489. .clk = &clk_cam,
  490. .bit = S3C2412_CLKSRC_CAMCLK_HCLK,
  491. .src_0 = &clk_usysclk,
  492. .src_1 = &clk_h,
  493. }, {
  494. .clk = &clk_msysclk,
  495. .bit = S3C2412_CLKSRC_MSYSCLK_MPLL,
  496. .src_0 = &clk_mdivclk,
  497. .src_1 = &clk_mpll,
  498. }, {
  499. .clk = &clk_uart,
  500. .bit = S3C2412_CLKSRC_UARTCLK_MPLL,
  501. .src_0 = &clk_erefclk,
  502. .src_1 = &clk_mpll,
  503. }, {
  504. .clk = &clk_usbsrc,
  505. .bit = S3C2412_CLKSRC_USBCLK_HCLK,
  506. .src_0 = &clk_usysclk,
  507. .src_1 = &clk_h,
  508. /* here we assume OM[4] select xtal */
  509. }, {
  510. .clk = &clk_erefclk,
  511. .bit = S3C2412_CLKSRC_EREFCLK_EXTCLK,
  512. .src_0 = &clk_xtal,
  513. .src_1 = &clk_ext,
  514. }, {
  515. .clk = &clk_urefclk,
  516. .bit = S3C2412_CLKSRC_UREFCLK_EXTCLK,
  517. .src_0 = &clk_xtal,
  518. .src_1 = &clk_ext,
  519. },
  520. };
  521. /* s3c2412_clk_initparents
  522. *
  523. * Initialise the parents for the clocks that we get at start-time
  524. */
  525. static void __init s3c2412_clk_initparents(void)
  526. {
  527. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  528. struct clk_init *cip = clks_src;
  529. struct clk *src;
  530. int ptr;
  531. int ret;
  532. for (ptr = 0; ptr < ARRAY_SIZE(clks_src); ptr++, cip++) {
  533. ret = s3c24xx_register_clock(cip->clk);
  534. if (ret < 0) {
  535. printk(KERN_ERR "Failed to register clock %s (%d)\n",
  536. cip->clk->name, ret);
  537. }
  538. src = (clksrc & cip->bit) ? cip->src_1 : cip->src_0;
  539. printk(KERN_INFO "%s: parent %s\n", cip->clk->name, src->name);
  540. clk_set_parent(cip->clk, src);
  541. }
  542. }
  543. /* clocks to add straight away */
  544. static struct clk *clks[] __initdata = {
  545. &clk_ext,
  546. &clk_usb_bus,
  547. &clk_mrefclk,
  548. &clk_armclk,
  549. };
  550. static struct clk_lookup s3c2412_clk_lookup[] = {
  551. CLKDEV_INIT(NULL, "clk_uart_baud1", &s3c24xx_uclk),
  552. CLKDEV_INIT(NULL, "clk_uart_baud2", &clk_p),
  553. CLKDEV_INIT(NULL, "clk_uart_baud3", &clk_usysclk),
  554. };
  555. int __init s3c2412_baseclk_add(void)
  556. {
  557. unsigned long clkcon = __raw_readl(S3C2410_CLKCON);
  558. unsigned int dvs;
  559. struct clk *clkp;
  560. int ret;
  561. int ptr;
  562. clk_upll.enable = s3c2412_upll_enable;
  563. clk_usb_bus.parent = &clk_usbsrc;
  564. clk_usb_bus.rate = 0x0;
  565. clk_f.parent = &clk_msysclk;
  566. s3c2412_clk_initparents();
  567. for (ptr = 0; ptr < ARRAY_SIZE(clks); ptr++) {
  568. clkp = clks[ptr];
  569. ret = s3c24xx_register_clock(clkp);
  570. if (ret < 0) {
  571. printk(KERN_ERR "Failed to register clock %s (%d)\n",
  572. clkp->name, ret);
  573. }
  574. }
  575. /* set the dvs state according to what we got at boot time */
  576. dvs = __raw_readl(S3C2410_CLKDIVN) & S3C2412_CLKDIVN_DVSEN;
  577. if (dvs)
  578. clk_armclk.parent = &clk_h;
  579. printk(KERN_INFO "S3C2412: DVS is %s\n", dvs ? "on" : "off");
  580. /* ensure usb bus clock is within correct rate of 48MHz */
  581. if (clk_get_rate(&clk_usb_bus) != (48 * 1000 * 1000)) {
  582. printk(KERN_INFO "Warning: USB bus clock not at 48MHz\n");
  583. /* for the moment, let's use the UPLL, and see if we can
  584. * get 48MHz */
  585. clk_set_parent(&clk_usysclk, &clk_upll);
  586. clk_set_parent(&clk_usbsrc, &clk_usysclk);
  587. clk_set_rate(&clk_usbsrc, 48*1000*1000);
  588. }
  589. printk("S3C2412: upll %s, %ld.%03ld MHz, usb-bus %ld.%03ld MHz\n",
  590. (__raw_readl(S3C2410_UPLLCON) & S3C2412_PLLCON_OFF) ? "off":"on",
  591. print_mhz(clk_get_rate(&clk_upll)),
  592. print_mhz(clk_get_rate(&clk_usb_bus)));
  593. /* register clocks from clock array */
  594. clkp = init_clocks;
  595. for (ptr = 0; ptr < ARRAY_SIZE(init_clocks); ptr++, clkp++) {
  596. /* ensure that we note the clock state */
  597. clkp->usage = clkcon & clkp->ctrlbit ? 1 : 0;
  598. ret = s3c24xx_register_clock(clkp);
  599. if (ret < 0) {
  600. printk(KERN_ERR "Failed to register clock %s (%d)\n",
  601. clkp->name, ret);
  602. }
  603. }
  604. /* We must be careful disabling the clocks we are not intending to
  605. * be using at boot time, as subsystems such as the LCD which do
  606. * their own DMA requests to the bus can cause the system to lockup
  607. * if they where in the middle of requesting bus access.
  608. *
  609. * Disabling the LCD clock if the LCD is active is very dangerous,
  610. * and therefore the bootloader should be careful to not enable
  611. * the LCD clock if it is not needed.
  612. */
  613. /* install (and disable) the clocks we do not need immediately */
  614. clkp = init_clocks_disable;
  615. for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
  616. ret = s3c24xx_register_clock(clkp);
  617. if (ret < 0) {
  618. printk(KERN_ERR "Failed to register clock %s (%d)\n",
  619. clkp->name, ret);
  620. }
  621. s3c2412_clkcon_enable(clkp, 0);
  622. }
  623. clkdev_add_table(s3c2412_clk_lookup, ARRAY_SIZE(s3c2412_clk_lookup));
  624. s3c_pwmclk_init();
  625. return 0;
  626. }