s3c2412-clock.c 16 KB

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