clock.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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/sysdev.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. .id = -1,
  80. };
  81. static struct clk clk_urefclk = {
  82. .name = "urefclk",
  83. .id = -1,
  84. };
  85. static int s3c2412_setparent_usysclk(struct clk *clk, struct clk *parent)
  86. {
  87. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  88. if (parent == &clk_urefclk)
  89. clksrc &= ~S3C2412_CLKSRC_USYSCLK_UPLL;
  90. else if (parent == &clk_upll)
  91. clksrc |= S3C2412_CLKSRC_USYSCLK_UPLL;
  92. else
  93. return -EINVAL;
  94. clk->parent = parent;
  95. __raw_writel(clksrc, S3C2412_CLKSRC);
  96. return 0;
  97. }
  98. static struct clk clk_usysclk = {
  99. .name = "usysclk",
  100. .id = -1,
  101. .parent = &clk_xtal,
  102. .set_parent = s3c2412_setparent_usysclk,
  103. };
  104. static struct clk clk_mrefclk = {
  105. .name = "mrefclk",
  106. .parent = &clk_xtal,
  107. .id = -1,
  108. };
  109. static struct clk clk_mdivclk = {
  110. .name = "mdivclk",
  111. .parent = &clk_xtal,
  112. .id = -1,
  113. };
  114. static int s3c2412_setparent_usbsrc(struct clk *clk, struct clk *parent)
  115. {
  116. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  117. if (parent == &clk_usysclk)
  118. clksrc &= ~S3C2412_CLKSRC_USBCLK_HCLK;
  119. else if (parent == &clk_h)
  120. clksrc |= S3C2412_CLKSRC_USBCLK_HCLK;
  121. else
  122. return -EINVAL;
  123. clk->parent = parent;
  124. __raw_writel(clksrc, S3C2412_CLKSRC);
  125. return 0;
  126. }
  127. static unsigned long s3c2412_roundrate_usbsrc(struct clk *clk,
  128. unsigned long rate)
  129. {
  130. unsigned long parent_rate = clk_get_rate(clk->parent);
  131. int div;
  132. if (rate > parent_rate)
  133. return parent_rate;
  134. div = parent_rate / rate;
  135. if (div > 2)
  136. div = 2;
  137. return parent_rate / div;
  138. }
  139. static unsigned long s3c2412_getrate_usbsrc(struct clk *clk)
  140. {
  141. unsigned long parent_rate = clk_get_rate(clk->parent);
  142. unsigned long div = __raw_readl(S3C2410_CLKDIVN);
  143. return parent_rate / ((div & S3C2412_CLKDIVN_USB48DIV) ? 2 : 1);
  144. }
  145. static int s3c2412_setrate_usbsrc(struct clk *clk, unsigned long rate)
  146. {
  147. unsigned long parent_rate = clk_get_rate(clk->parent);
  148. unsigned long clkdivn = __raw_readl(S3C2410_CLKDIVN);
  149. rate = s3c2412_roundrate_usbsrc(clk, rate);
  150. if ((parent_rate / rate) == 2)
  151. clkdivn |= S3C2412_CLKDIVN_USB48DIV;
  152. else
  153. clkdivn &= ~S3C2412_CLKDIVN_USB48DIV;
  154. __raw_writel(clkdivn, S3C2410_CLKDIVN);
  155. return 0;
  156. }
  157. static struct clk clk_usbsrc = {
  158. .name = "usbsrc",
  159. .id = -1,
  160. .get_rate = s3c2412_getrate_usbsrc,
  161. .set_rate = s3c2412_setrate_usbsrc,
  162. .round_rate = s3c2412_roundrate_usbsrc,
  163. .set_parent = s3c2412_setparent_usbsrc,
  164. };
  165. static int s3c2412_setparent_msysclk(struct clk *clk, struct clk *parent)
  166. {
  167. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  168. if (parent == &clk_mdivclk)
  169. clksrc &= ~S3C2412_CLKSRC_MSYSCLK_MPLL;
  170. else if (parent == &clk_mpll)
  171. clksrc |= S3C2412_CLKSRC_MSYSCLK_MPLL;
  172. else
  173. return -EINVAL;
  174. clk->parent = parent;
  175. __raw_writel(clksrc, S3C2412_CLKSRC);
  176. return 0;
  177. }
  178. static struct clk clk_msysclk = {
  179. .name = "msysclk",
  180. .id = -1,
  181. .set_parent = s3c2412_setparent_msysclk,
  182. };
  183. static int s3c2412_setparent_armclk(struct clk *clk, struct clk *parent)
  184. {
  185. unsigned long flags;
  186. unsigned long clkdiv;
  187. unsigned long dvs;
  188. /* Note, we current equate fclk andf msysclk for S3C2412 */
  189. if (parent == &clk_msysclk || parent == &clk_f)
  190. dvs = 0;
  191. else if (parent == &clk_h)
  192. dvs = S3C2412_CLKDIVN_DVSEN;
  193. else
  194. return -EINVAL;
  195. clk->parent = parent;
  196. /* update this under irq lockdown, clkdivn is not protected
  197. * by the clock system. */
  198. local_irq_save(flags);
  199. clkdiv = __raw_readl(S3C2410_CLKDIVN);
  200. clkdiv &= ~S3C2412_CLKDIVN_DVSEN;
  201. clkdiv |= dvs;
  202. __raw_writel(clkdiv, S3C2410_CLKDIVN);
  203. local_irq_restore(flags);
  204. return 0;
  205. }
  206. static struct clk clk_armclk = {
  207. .name = "armclk",
  208. .id = -1,
  209. .parent = &clk_msysclk,
  210. .set_parent = s3c2412_setparent_armclk,
  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. .id = -1,
  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. 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. .id = -1,
  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. static int s3c2412_setparent_cam(struct clk *clk, struct clk *parent)
  310. {
  311. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  312. if (parent == &clk_usysclk)
  313. clksrc &= ~S3C2412_CLKSRC_CAMCLK_HCLK;
  314. else if (parent == &clk_h)
  315. clksrc |= S3C2412_CLKSRC_CAMCLK_HCLK;
  316. else
  317. return -EINVAL;
  318. clk->parent = parent;
  319. __raw_writel(clksrc, S3C2412_CLKSRC);
  320. return 0;
  321. }
  322. static unsigned long s3c2412_getrate_cam(struct clk *clk)
  323. {
  324. unsigned long parent_rate = clk_get_rate(clk->parent);
  325. unsigned long div = __raw_readl(S3C2410_CLKDIVN);
  326. div &= S3C2412_CLKDIVN_CAMDIV_MASK;
  327. div >>= S3C2412_CLKDIVN_CAMDIV_SHIFT;
  328. return parent_rate / (div + 1);
  329. }
  330. static int s3c2412_setrate_cam(struct clk *clk, unsigned long rate)
  331. {
  332. unsigned long parent_rate = clk_get_rate(clk->parent);
  333. unsigned long clkdivn = __raw_readl(S3C2410_CLKDIVN);
  334. rate = s3c2412_roundrate_clksrc(clk, rate);
  335. clkdivn &= ~S3C2412_CLKDIVN_CAMDIV_MASK;
  336. clkdivn |= ((parent_rate / rate) - 1) << S3C2412_CLKDIVN_CAMDIV_SHIFT;
  337. __raw_writel(clkdivn, S3C2410_CLKDIVN);
  338. return 0;
  339. }
  340. static struct clk clk_cam = {
  341. .name = "camif-upll", /* same as 2440 name */
  342. .id = -1,
  343. .get_rate = s3c2412_getrate_cam,
  344. .set_rate = s3c2412_setrate_cam,
  345. .set_parent = s3c2412_setparent_cam,
  346. .round_rate = s3c2412_roundrate_clksrc,
  347. };
  348. /* standard clock definitions */
  349. static struct clk init_clocks_disable[] = {
  350. {
  351. .name = "nand",
  352. .id = -1,
  353. .parent = &clk_h,
  354. .enable = s3c2412_clkcon_enable,
  355. .ctrlbit = S3C2412_CLKCON_NAND,
  356. }, {
  357. .name = "sdi",
  358. .id = -1,
  359. .parent = &clk_p,
  360. .enable = s3c2412_clkcon_enable,
  361. .ctrlbit = S3C2412_CLKCON_SDI,
  362. }, {
  363. .name = "adc",
  364. .id = -1,
  365. .parent = &clk_p,
  366. .enable = s3c2412_clkcon_enable,
  367. .ctrlbit = S3C2412_CLKCON_ADC,
  368. }, {
  369. .name = "i2c",
  370. .id = -1,
  371. .parent = &clk_p,
  372. .enable = s3c2412_clkcon_enable,
  373. .ctrlbit = S3C2412_CLKCON_IIC,
  374. }, {
  375. .name = "iis",
  376. .id = -1,
  377. .parent = &clk_p,
  378. .enable = s3c2412_clkcon_enable,
  379. .ctrlbit = S3C2412_CLKCON_IIS,
  380. }, {
  381. .name = "spi",
  382. .id = -1,
  383. .parent = &clk_p,
  384. .enable = s3c2412_clkcon_enable,
  385. .ctrlbit = S3C2412_CLKCON_SPI,
  386. }
  387. };
  388. static struct clk init_clocks[] = {
  389. {
  390. .name = "dma",
  391. .id = 0,
  392. .parent = &clk_h,
  393. .enable = s3c2412_clkcon_enable,
  394. .ctrlbit = S3C2412_CLKCON_DMA0,
  395. }, {
  396. .name = "dma",
  397. .id = 1,
  398. .parent = &clk_h,
  399. .enable = s3c2412_clkcon_enable,
  400. .ctrlbit = S3C2412_CLKCON_DMA1,
  401. }, {
  402. .name = "dma",
  403. .id = 2,
  404. .parent = &clk_h,
  405. .enable = s3c2412_clkcon_enable,
  406. .ctrlbit = S3C2412_CLKCON_DMA2,
  407. }, {
  408. .name = "dma",
  409. .id = 3,
  410. .parent = &clk_h,
  411. .enable = s3c2412_clkcon_enable,
  412. .ctrlbit = S3C2412_CLKCON_DMA3,
  413. }, {
  414. .name = "lcd",
  415. .id = -1,
  416. .parent = &clk_h,
  417. .enable = s3c2412_clkcon_enable,
  418. .ctrlbit = S3C2412_CLKCON_LCDC,
  419. }, {
  420. .name = "gpio",
  421. .id = -1,
  422. .parent = &clk_p,
  423. .enable = s3c2412_clkcon_enable,
  424. .ctrlbit = S3C2412_CLKCON_GPIO,
  425. }, {
  426. .name = "usb-host",
  427. .id = -1,
  428. .parent = &clk_h,
  429. .enable = s3c2412_clkcon_enable,
  430. .ctrlbit = S3C2412_CLKCON_USBH,
  431. }, {
  432. .name = "usb-device",
  433. .id = -1,
  434. .parent = &clk_h,
  435. .enable = s3c2412_clkcon_enable,
  436. .ctrlbit = S3C2412_CLKCON_USBD,
  437. }, {
  438. .name = "timers",
  439. .id = -1,
  440. .parent = &clk_p,
  441. .enable = s3c2412_clkcon_enable,
  442. .ctrlbit = S3C2412_CLKCON_PWMT,
  443. }, {
  444. .name = "uart",
  445. .id = 0,
  446. .parent = &clk_p,
  447. .enable = s3c2412_clkcon_enable,
  448. .ctrlbit = S3C2412_CLKCON_UART0,
  449. }, {
  450. .name = "uart",
  451. .id = 1,
  452. .parent = &clk_p,
  453. .enable = s3c2412_clkcon_enable,
  454. .ctrlbit = S3C2412_CLKCON_UART1,
  455. }, {
  456. .name = "uart",
  457. .id = 2,
  458. .parent = &clk_p,
  459. .enable = s3c2412_clkcon_enable,
  460. .ctrlbit = S3C2412_CLKCON_UART2,
  461. }, {
  462. .name = "rtc",
  463. .id = -1,
  464. .parent = &clk_p,
  465. .enable = s3c2412_clkcon_enable,
  466. .ctrlbit = S3C2412_CLKCON_RTC,
  467. }, {
  468. .name = "watchdog",
  469. .id = -1,
  470. .parent = &clk_p,
  471. .ctrlbit = 0,
  472. }, {
  473. .name = "usb-bus-gadget",
  474. .id = -1,
  475. .parent = &clk_usb_bus,
  476. .enable = s3c2412_clkcon_enable,
  477. .ctrlbit = S3C2412_CLKCON_USB_DEV48,
  478. }, {
  479. .name = "usb-bus-host",
  480. .id = -1,
  481. .parent = &clk_usb_bus,
  482. .enable = s3c2412_clkcon_enable,
  483. .ctrlbit = S3C2412_CLKCON_USB_HOST48,
  484. }
  485. };
  486. /* clocks to add where we need to check their parentage */
  487. struct clk_init {
  488. struct clk *clk;
  489. unsigned int bit;
  490. struct clk *src_0;
  491. struct clk *src_1;
  492. };
  493. static struct clk_init clks_src[] __initdata = {
  494. {
  495. .clk = &clk_usysclk,
  496. .bit = S3C2412_CLKSRC_USBCLK_HCLK,
  497. .src_0 = &clk_urefclk,
  498. .src_1 = &clk_upll,
  499. }, {
  500. .clk = &clk_i2s,
  501. .bit = S3C2412_CLKSRC_I2SCLK_MPLL,
  502. .src_0 = &clk_erefclk,
  503. .src_1 = &clk_mpll,
  504. }, {
  505. .clk = &clk_cam,
  506. .bit = S3C2412_CLKSRC_CAMCLK_HCLK,
  507. .src_0 = &clk_usysclk,
  508. .src_1 = &clk_h,
  509. }, {
  510. .clk = &clk_msysclk,
  511. .bit = S3C2412_CLKSRC_MSYSCLK_MPLL,
  512. .src_0 = &clk_mdivclk,
  513. .src_1 = &clk_mpll,
  514. }, {
  515. .clk = &clk_uart,
  516. .bit = S3C2412_CLKSRC_UARTCLK_MPLL,
  517. .src_0 = &clk_erefclk,
  518. .src_1 = &clk_mpll,
  519. }, {
  520. .clk = &clk_usbsrc,
  521. .bit = S3C2412_CLKSRC_USBCLK_HCLK,
  522. .src_0 = &clk_usysclk,
  523. .src_1 = &clk_h,
  524. /* here we assume OM[4] select xtal */
  525. }, {
  526. .clk = &clk_erefclk,
  527. .bit = S3C2412_CLKSRC_EREFCLK_EXTCLK,
  528. .src_0 = &clk_xtal,
  529. .src_1 = &clk_ext,
  530. }, {
  531. .clk = &clk_urefclk,
  532. .bit = S3C2412_CLKSRC_UREFCLK_EXTCLK,
  533. .src_0 = &clk_xtal,
  534. .src_1 = &clk_ext,
  535. },
  536. };
  537. /* s3c2412_clk_initparents
  538. *
  539. * Initialise the parents for the clocks that we get at start-time
  540. */
  541. static void __init s3c2412_clk_initparents(void)
  542. {
  543. unsigned long clksrc = __raw_readl(S3C2412_CLKSRC);
  544. struct clk_init *cip = clks_src;
  545. struct clk *src;
  546. int ptr;
  547. int ret;
  548. for (ptr = 0; ptr < ARRAY_SIZE(clks_src); ptr++, cip++) {
  549. ret = s3c24xx_register_clock(cip->clk);
  550. if (ret < 0) {
  551. printk(KERN_ERR "Failed to register clock %s (%d)\n",
  552. cip->clk->name, ret);
  553. }
  554. src = (clksrc & cip->bit) ? cip->src_1 : cip->src_0;
  555. printk(KERN_INFO "%s: parent %s\n", cip->clk->name, src->name);
  556. clk_set_parent(cip->clk, src);
  557. }
  558. }
  559. /* clocks to add straight away */
  560. static struct clk *clks[] __initdata = {
  561. &clk_ext,
  562. &clk_usb_bus,
  563. &clk_mrefclk,
  564. &clk_armclk,
  565. };
  566. int __init s3c2412_baseclk_add(void)
  567. {
  568. unsigned long clkcon = __raw_readl(S3C2410_CLKCON);
  569. unsigned int dvs;
  570. struct clk *clkp;
  571. int ret;
  572. int ptr;
  573. clk_upll.enable = s3c2412_upll_enable;
  574. clk_usb_bus.parent = &clk_usbsrc;
  575. clk_usb_bus.rate = 0x0;
  576. clk_f.parent = &clk_msysclk;
  577. s3c2412_clk_initparents();
  578. for (ptr = 0; ptr < ARRAY_SIZE(clks); ptr++) {
  579. clkp = clks[ptr];
  580. ret = s3c24xx_register_clock(clkp);
  581. if (ret < 0) {
  582. printk(KERN_ERR "Failed to register clock %s (%d)\n",
  583. clkp->name, ret);
  584. }
  585. }
  586. /* set the dvs state according to what we got at boot time */
  587. dvs = __raw_readl(S3C2410_CLKDIVN) & S3C2412_CLKDIVN_DVSEN;
  588. if (dvs)
  589. clk_armclk.parent = &clk_h;
  590. printk(KERN_INFO "S3C2412: DVS is %s\n", dvs ? "on" : "off");
  591. /* ensure usb bus clock is within correct rate of 48MHz */
  592. if (clk_get_rate(&clk_usb_bus) != (48 * 1000 * 1000)) {
  593. printk(KERN_INFO "Warning: USB bus clock not at 48MHz\n");
  594. /* for the moment, let's use the UPLL, and see if we can
  595. * get 48MHz */
  596. clk_set_parent(&clk_usysclk, &clk_upll);
  597. clk_set_parent(&clk_usbsrc, &clk_usysclk);
  598. clk_set_rate(&clk_usbsrc, 48*1000*1000);
  599. }
  600. printk("S3C2412: upll %s, %ld.%03ld MHz, usb-bus %ld.%03ld MHz\n",
  601. (__raw_readl(S3C2410_UPLLCON) & S3C2412_PLLCON_OFF) ? "off":"on",
  602. print_mhz(clk_get_rate(&clk_upll)),
  603. print_mhz(clk_get_rate(&clk_usb_bus)));
  604. /* register clocks from clock array */
  605. clkp = init_clocks;
  606. for (ptr = 0; ptr < ARRAY_SIZE(init_clocks); ptr++, clkp++) {
  607. /* ensure that we note the clock state */
  608. clkp->usage = clkcon & clkp->ctrlbit ? 1 : 0;
  609. ret = s3c24xx_register_clock(clkp);
  610. if (ret < 0) {
  611. printk(KERN_ERR "Failed to register clock %s (%d)\n",
  612. clkp->name, ret);
  613. }
  614. }
  615. /* We must be careful disabling the clocks we are not intending to
  616. * be using at boot time, as subsystems such as the LCD which do
  617. * their own DMA requests to the bus can cause the system to lockup
  618. * if they where in the middle of requesting bus access.
  619. *
  620. * Disabling the LCD clock if the LCD is active is very dangerous,
  621. * and therefore the bootloader should be careful to not enable
  622. * the LCD clock if it is not needed.
  623. */
  624. /* install (and disable) the clocks we do not need immediately */
  625. clkp = init_clocks_disable;
  626. for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
  627. ret = s3c24xx_register_clock(clkp);
  628. if (ret < 0) {
  629. printk(KERN_ERR "Failed to register clock %s (%d)\n",
  630. clkp->name, ret);
  631. }
  632. s3c2412_clkcon_enable(clkp, 0);
  633. }
  634. s3c_pwmclk_init();
  635. return 0;
  636. }