clock-s3c2412.c 18 KB

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