clock.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  1. /*
  2. * linux/arch/arm/plat-omap/clock.c
  3. *
  4. * Copyright (C) 2004 Nokia corporation
  5. * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/list.h>
  14. #include <linux/errno.h>
  15. #include <linux/err.h>
  16. #include <asm/io.h>
  17. #include <asm/semaphore.h>
  18. #include <asm/hardware/clock.h>
  19. #include <asm/arch/board.h>
  20. #include <asm/arch/usb.h>
  21. #include "clock.h"
  22. #include "sram.h"
  23. static LIST_HEAD(clocks);
  24. static DECLARE_MUTEX(clocks_sem);
  25. static DEFINE_SPINLOCK(clockfw_lock);
  26. static void propagate_rate(struct clk * clk);
  27. /* UART clock function */
  28. static int set_uart_rate(struct clk * clk, unsigned long rate);
  29. /* External clock (MCLK & BCLK) functions */
  30. static int set_ext_clk_rate(struct clk * clk, unsigned long rate);
  31. static long round_ext_clk_rate(struct clk * clk, unsigned long rate);
  32. static void init_ext_clk(struct clk * clk);
  33. /* MPU virtual clock functions */
  34. static int select_table_rate(struct clk * clk, unsigned long rate);
  35. static long round_to_table_rate(struct clk * clk, unsigned long rate);
  36. void clk_setdpll(__u16, __u16);
  37. static struct mpu_rate rate_table[] = {
  38. /* MPU MHz, xtal MHz, dpll1 MHz, CKCTL, DPLL_CTL
  39. * armdiv, dspdiv, dspmmu, tcdiv, perdiv, lcddiv
  40. */
  41. #if defined(CONFIG_OMAP_ARM_216MHZ)
  42. { 216000000, 12000000, 216000000, 0x050d, 0x2910 }, /* 1/1/2/2/2/8 */
  43. #endif
  44. #if defined(CONFIG_OMAP_ARM_195MHZ)
  45. { 195000000, 13000000, 195000000, 0x050e, 0x2790 }, /* 1/1/2/2/4/8 */
  46. #endif
  47. #if defined(CONFIG_OMAP_ARM_192MHZ)
  48. { 192000000, 19200000, 192000000, 0x050f, 0x2510 }, /* 1/1/2/2/8/8 */
  49. { 192000000, 12000000, 192000000, 0x050f, 0x2810 }, /* 1/1/2/2/8/8 */
  50. { 96000000, 12000000, 192000000, 0x055f, 0x2810 }, /* 2/2/2/2/8/8 */
  51. { 48000000, 12000000, 192000000, 0x0baf, 0x2810 }, /* 4/8/4/4/8/8 */
  52. { 24000000, 12000000, 192000000, 0x0fff, 0x2810 }, /* 8/8/8/8/8/8 */
  53. #endif
  54. #if defined(CONFIG_OMAP_ARM_182MHZ)
  55. { 182000000, 13000000, 182000000, 0x050e, 0x2710 }, /* 1/1/2/2/4/8 */
  56. #endif
  57. #if defined(CONFIG_OMAP_ARM_168MHZ)
  58. { 168000000, 12000000, 168000000, 0x010f, 0x2710 }, /* 1/1/1/2/8/8 */
  59. #endif
  60. #if defined(CONFIG_OMAP_ARM_150MHZ)
  61. { 150000000, 12000000, 150000000, 0x010a, 0x2cb0 }, /* 1/1/1/2/4/4 */
  62. #endif
  63. #if defined(CONFIG_OMAP_ARM_120MHZ)
  64. { 120000000, 12000000, 120000000, 0x010a, 0x2510 }, /* 1/1/1/2/4/4 */
  65. #endif
  66. #if defined(CONFIG_OMAP_ARM_96MHZ)
  67. { 96000000, 12000000, 96000000, 0x0005, 0x2410 }, /* 1/1/1/1/2/2 */
  68. #endif
  69. #if defined(CONFIG_OMAP_ARM_60MHZ)
  70. { 60000000, 12000000, 60000000, 0x0005, 0x2290 }, /* 1/1/1/1/2/2 */
  71. #endif
  72. #if defined(CONFIG_OMAP_ARM_30MHZ)
  73. { 30000000, 12000000, 60000000, 0x0555, 0x2290 }, /* 2/2/2/2/2/2 */
  74. #endif
  75. { 0, 0, 0, 0, 0 },
  76. };
  77. static void ckctl_recalc(struct clk * clk);
  78. int __clk_enable(struct clk *clk);
  79. void __clk_disable(struct clk *clk);
  80. void __clk_unuse(struct clk *clk);
  81. int __clk_use(struct clk *clk);
  82. static void followparent_recalc(struct clk * clk)
  83. {
  84. clk->rate = clk->parent->rate;
  85. }
  86. static void watchdog_recalc(struct clk * clk)
  87. {
  88. clk->rate = clk->parent->rate / 14;
  89. }
  90. static void uart_recalc(struct clk * clk)
  91. {
  92. unsigned int val = omap_readl(clk->enable_reg);
  93. if (val & clk->enable_bit)
  94. clk->rate = 48000000;
  95. else
  96. clk->rate = 12000000;
  97. }
  98. static struct clk ck_ref = {
  99. .name = "ck_ref",
  100. .rate = 12000000,
  101. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  102. ALWAYS_ENABLED,
  103. };
  104. static struct clk ck_dpll1 = {
  105. .name = "ck_dpll1",
  106. .parent = &ck_ref,
  107. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  108. RATE_PROPAGATES | ALWAYS_ENABLED,
  109. };
  110. static struct clk ck_dpll1out = {
  111. .name = "ck_dpll1out",
  112. .parent = &ck_dpll1,
  113. .flags = CLOCK_IN_OMAP16XX,
  114. .enable_reg = ARM_IDLECT2,
  115. .enable_bit = EN_CKOUT_ARM,
  116. .recalc = &followparent_recalc,
  117. };
  118. static struct clk arm_ck = {
  119. .name = "arm_ck",
  120. .parent = &ck_dpll1,
  121. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  122. RATE_CKCTL | RATE_PROPAGATES | ALWAYS_ENABLED,
  123. .rate_offset = CKCTL_ARMDIV_OFFSET,
  124. .recalc = &ckctl_recalc,
  125. };
  126. static struct clk armper_ck = {
  127. .name = "armper_ck",
  128. .parent = &ck_dpll1,
  129. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  130. RATE_CKCTL,
  131. .enable_reg = ARM_IDLECT2,
  132. .enable_bit = EN_PERCK,
  133. .rate_offset = CKCTL_PERDIV_OFFSET,
  134. .recalc = &ckctl_recalc,
  135. };
  136. static struct clk arm_gpio_ck = {
  137. .name = "arm_gpio_ck",
  138. .parent = &ck_dpll1,
  139. .flags = CLOCK_IN_OMAP1510,
  140. .enable_reg = ARM_IDLECT2,
  141. .enable_bit = EN_GPIOCK,
  142. .recalc = &followparent_recalc,
  143. };
  144. static struct clk armxor_ck = {
  145. .name = "armxor_ck",
  146. .parent = &ck_ref,
  147. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
  148. .enable_reg = ARM_IDLECT2,
  149. .enable_bit = EN_XORPCK,
  150. .recalc = &followparent_recalc,
  151. };
  152. static struct clk armtim_ck = {
  153. .name = "armtim_ck",
  154. .parent = &ck_ref,
  155. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
  156. .enable_reg = ARM_IDLECT2,
  157. .enable_bit = EN_TIMCK,
  158. .recalc = &followparent_recalc,
  159. };
  160. static struct clk armwdt_ck = {
  161. .name = "armwdt_ck",
  162. .parent = &ck_ref,
  163. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
  164. .enable_reg = ARM_IDLECT2,
  165. .enable_bit = EN_WDTCK,
  166. .recalc = &watchdog_recalc,
  167. };
  168. static struct clk arminth_ck16xx = {
  169. .name = "arminth_ck",
  170. .parent = &arm_ck,
  171. .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
  172. .recalc = &followparent_recalc,
  173. /* Note: On 16xx the frequency can be divided by 2 by programming
  174. * ARM_CKCTL:ARM_INTHCK_SEL(14) to 1
  175. *
  176. * 1510 version is in TC clocks.
  177. */
  178. };
  179. static struct clk dsp_ck = {
  180. .name = "dsp_ck",
  181. .parent = &ck_dpll1,
  182. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  183. RATE_CKCTL,
  184. .enable_reg = ARM_CKCTL,
  185. .enable_bit = EN_DSPCK,
  186. .rate_offset = CKCTL_DSPDIV_OFFSET,
  187. .recalc = &ckctl_recalc,
  188. };
  189. static struct clk dspmmu_ck = {
  190. .name = "dspmmu_ck",
  191. .parent = &ck_dpll1,
  192. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  193. RATE_CKCTL | ALWAYS_ENABLED,
  194. .rate_offset = CKCTL_DSPMMUDIV_OFFSET,
  195. .recalc = &ckctl_recalc,
  196. };
  197. static struct clk dspper_ck = {
  198. .name = "dspper_ck",
  199. .parent = &ck_dpll1,
  200. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  201. RATE_CKCTL | DSP_DOMAIN_CLOCK | VIRTUAL_IO_ADDRESS,
  202. .enable_reg = DSP_IDLECT2,
  203. .enable_bit = EN_PERCK,
  204. .rate_offset = CKCTL_PERDIV_OFFSET,
  205. .recalc = &followparent_recalc,
  206. //.recalc = &ckctl_recalc,
  207. };
  208. static struct clk dspxor_ck = {
  209. .name = "dspxor_ck",
  210. .parent = &ck_ref,
  211. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  212. DSP_DOMAIN_CLOCK | VIRTUAL_IO_ADDRESS,
  213. .enable_reg = DSP_IDLECT2,
  214. .enable_bit = EN_XORPCK,
  215. .recalc = &followparent_recalc,
  216. };
  217. static struct clk dsptim_ck = {
  218. .name = "dsptim_ck",
  219. .parent = &ck_ref,
  220. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  221. DSP_DOMAIN_CLOCK | VIRTUAL_IO_ADDRESS,
  222. .enable_reg = DSP_IDLECT2,
  223. .enable_bit = EN_DSPTIMCK,
  224. .recalc = &followparent_recalc,
  225. };
  226. static struct clk tc_ck = {
  227. .name = "tc_ck",
  228. .parent = &ck_dpll1,
  229. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP730 |
  230. RATE_CKCTL | RATE_PROPAGATES | ALWAYS_ENABLED,
  231. .rate_offset = CKCTL_TCDIV_OFFSET,
  232. .recalc = &ckctl_recalc,
  233. };
  234. static struct clk arminth_ck1510 = {
  235. .name = "arminth_ck",
  236. .parent = &tc_ck,
  237. .flags = CLOCK_IN_OMAP1510 | ALWAYS_ENABLED,
  238. .recalc = &followparent_recalc,
  239. /* Note: On 1510 the frequency follows TC_CK
  240. *
  241. * 16xx version is in MPU clocks.
  242. */
  243. };
  244. static struct clk tipb_ck = {
  245. .name = "tibp_ck",
  246. .parent = &tc_ck,
  247. .flags = CLOCK_IN_OMAP1510 | ALWAYS_ENABLED,
  248. .recalc = &followparent_recalc,
  249. };
  250. static struct clk l3_ocpi_ck = {
  251. .name = "l3_ocpi_ck",
  252. .parent = &tc_ck,
  253. .flags = CLOCK_IN_OMAP16XX,
  254. .enable_reg = ARM_IDLECT3,
  255. .enable_bit = EN_OCPI_CK,
  256. .recalc = &followparent_recalc,
  257. };
  258. static struct clk tc1_ck = {
  259. .name = "tc1_ck",
  260. .parent = &tc_ck,
  261. .flags = CLOCK_IN_OMAP16XX,
  262. .enable_reg = ARM_IDLECT3,
  263. .enable_bit = EN_TC1_CK,
  264. .recalc = &followparent_recalc,
  265. };
  266. static struct clk tc2_ck = {
  267. .name = "tc2_ck",
  268. .parent = &tc_ck,
  269. .flags = CLOCK_IN_OMAP16XX,
  270. .enable_reg = ARM_IDLECT3,
  271. .enable_bit = EN_TC2_CK,
  272. .recalc = &followparent_recalc,
  273. };
  274. static struct clk dma_ck = {
  275. .name = "dma_ck",
  276. .parent = &tc_ck,
  277. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  278. ALWAYS_ENABLED,
  279. .recalc = &followparent_recalc,
  280. };
  281. static struct clk dma_lcdfree_ck = {
  282. .name = "dma_lcdfree_ck",
  283. .parent = &tc_ck,
  284. .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
  285. .recalc = &followparent_recalc,
  286. };
  287. static struct clk api_ck = {
  288. .name = "api_ck",
  289. .parent = &tc_ck,
  290. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX,
  291. .enable_reg = ARM_IDLECT2,
  292. .enable_bit = EN_APICK,
  293. .recalc = &followparent_recalc,
  294. };
  295. static struct clk lb_ck = {
  296. .name = "lb_ck",
  297. .parent = &tc_ck,
  298. .flags = CLOCK_IN_OMAP1510,
  299. .enable_reg = ARM_IDLECT2,
  300. .enable_bit = EN_LBCK,
  301. .recalc = &followparent_recalc,
  302. };
  303. static struct clk rhea1_ck = {
  304. .name = "rhea1_ck",
  305. .parent = &tc_ck,
  306. .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
  307. .recalc = &followparent_recalc,
  308. };
  309. static struct clk rhea2_ck = {
  310. .name = "rhea2_ck",
  311. .parent = &tc_ck,
  312. .flags = CLOCK_IN_OMAP16XX | ALWAYS_ENABLED,
  313. .recalc = &followparent_recalc,
  314. };
  315. static struct clk lcd_ck = {
  316. .name = "lcd_ck",
  317. .parent = &ck_dpll1,
  318. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | CLOCK_IN_OMAP730 |
  319. RATE_CKCTL,
  320. .enable_reg = ARM_IDLECT2,
  321. .enable_bit = EN_LCDCK,
  322. .rate_offset = CKCTL_LCDDIV_OFFSET,
  323. .recalc = &ckctl_recalc,
  324. };
  325. static struct clk uart1_1510 = {
  326. .name = "uart1_ck",
  327. /* Direct from ULPD, no parent */
  328. .rate = 12000000,
  329. .flags = CLOCK_IN_OMAP1510 | ENABLE_REG_32BIT | ALWAYS_ENABLED,
  330. .enable_reg = MOD_CONF_CTRL_0,
  331. .enable_bit = 29, /* Chooses between 12MHz and 48MHz */
  332. .set_rate = &set_uart_rate,
  333. .recalc = &uart_recalc,
  334. };
  335. static struct clk uart1_16xx = {
  336. .name = "uart1_ck",
  337. /* Direct from ULPD, no parent */
  338. .rate = 48000000,
  339. .flags = CLOCK_IN_OMAP16XX | RATE_FIXED | ENABLE_REG_32BIT,
  340. .enable_reg = MOD_CONF_CTRL_0,
  341. .enable_bit = 29,
  342. };
  343. static struct clk uart2_ck = {
  344. .name = "uart2_ck",
  345. /* Direct from ULPD, no parent */
  346. .rate = 12000000,
  347. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX | ENABLE_REG_32BIT |
  348. ALWAYS_ENABLED,
  349. .enable_reg = MOD_CONF_CTRL_0,
  350. .enable_bit = 30, /* Chooses between 12MHz and 48MHz */
  351. .set_rate = &set_uart_rate,
  352. .recalc = &uart_recalc,
  353. };
  354. static struct clk uart3_1510 = {
  355. .name = "uart3_ck",
  356. /* Direct from ULPD, no parent */
  357. .rate = 12000000,
  358. .flags = CLOCK_IN_OMAP1510 | ENABLE_REG_32BIT | ALWAYS_ENABLED,
  359. .enable_reg = MOD_CONF_CTRL_0,
  360. .enable_bit = 31, /* Chooses between 12MHz and 48MHz */
  361. .set_rate = &set_uart_rate,
  362. .recalc = &uart_recalc,
  363. };
  364. static struct clk uart3_16xx = {
  365. .name = "uart3_ck",
  366. /* Direct from ULPD, no parent */
  367. .rate = 48000000,
  368. .flags = CLOCK_IN_OMAP16XX | RATE_FIXED | ENABLE_REG_32BIT,
  369. .enable_reg = MOD_CONF_CTRL_0,
  370. .enable_bit = 31,
  371. };
  372. static struct clk usb_clko = { /* 6 MHz output on W4_USB_CLKO */
  373. .name = "usb_clko",
  374. /* Direct from ULPD, no parent */
  375. .rate = 6000000,
  376. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  377. RATE_FIXED | ENABLE_REG_32BIT,
  378. .enable_reg = ULPD_CLOCK_CTRL,
  379. .enable_bit = USB_MCLK_EN_BIT,
  380. };
  381. static struct clk usb_hhc_ck1510 = {
  382. .name = "usb_hhc_ck",
  383. /* Direct from ULPD, no parent */
  384. .rate = 48000000, /* Actually 2 clocks, 12MHz and 48MHz */
  385. .flags = CLOCK_IN_OMAP1510 |
  386. RATE_FIXED | ENABLE_REG_32BIT,
  387. .enable_reg = MOD_CONF_CTRL_0,
  388. .enable_bit = USB_HOST_HHC_UHOST_EN,
  389. };
  390. static struct clk usb_hhc_ck16xx = {
  391. .name = "usb_hhc_ck",
  392. /* Direct from ULPD, no parent */
  393. .rate = 48000000,
  394. /* OTG_SYSCON_2.OTG_PADEN == 0 (not 1510-compatible) */
  395. .flags = CLOCK_IN_OMAP16XX |
  396. RATE_FIXED | ENABLE_REG_32BIT,
  397. .enable_reg = OTG_BASE + 0x08 /* OTG_SYSCON_2 */,
  398. .enable_bit = 8 /* UHOST_EN */,
  399. };
  400. static struct clk usb_dc_ck = {
  401. .name = "usb_dc_ck",
  402. /* Direct from ULPD, no parent */
  403. .rate = 48000000,
  404. .flags = CLOCK_IN_OMAP16XX | RATE_FIXED,
  405. .enable_reg = SOFT_REQ_REG,
  406. .enable_bit = 4,
  407. };
  408. static struct clk mclk_1510 = {
  409. .name = "mclk",
  410. /* Direct from ULPD, no parent. May be enabled by ext hardware. */
  411. .rate = 12000000,
  412. .flags = CLOCK_IN_OMAP1510 | RATE_FIXED,
  413. };
  414. static struct clk mclk_16xx = {
  415. .name = "mclk",
  416. /* Direct from ULPD, no parent. May be enabled by ext hardware. */
  417. .flags = CLOCK_IN_OMAP16XX,
  418. .enable_reg = COM_CLK_DIV_CTRL_SEL,
  419. .enable_bit = COM_ULPD_PLL_CLK_REQ,
  420. .set_rate = &set_ext_clk_rate,
  421. .round_rate = &round_ext_clk_rate,
  422. .init = &init_ext_clk,
  423. };
  424. static struct clk bclk_1510 = {
  425. .name = "bclk",
  426. /* Direct from ULPD, no parent. May be enabled by ext hardware. */
  427. .rate = 12000000,
  428. .flags = CLOCK_IN_OMAP1510 | RATE_FIXED,
  429. };
  430. static struct clk bclk_16xx = {
  431. .name = "bclk",
  432. /* Direct from ULPD, no parent. May be enabled by ext hardware. */
  433. .flags = CLOCK_IN_OMAP16XX,
  434. .enable_reg = SWD_CLK_DIV_CTRL_SEL,
  435. .enable_bit = SWD_ULPD_PLL_CLK_REQ,
  436. .set_rate = &set_ext_clk_rate,
  437. .round_rate = &round_ext_clk_rate,
  438. .init = &init_ext_clk,
  439. };
  440. static struct clk mmc1_ck = {
  441. .name = "mmc1_ck",
  442. /* Functional clock is direct from ULPD, interface clock is ARMPER */
  443. .parent = &armper_ck,
  444. .rate = 48000000,
  445. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  446. RATE_FIXED | ENABLE_REG_32BIT,
  447. .enable_reg = MOD_CONF_CTRL_0,
  448. .enable_bit = 23,
  449. };
  450. static struct clk mmc2_ck = {
  451. .name = "mmc2_ck",
  452. /* Functional clock is direct from ULPD, interface clock is ARMPER */
  453. .parent = &armper_ck,
  454. .rate = 48000000,
  455. .flags = CLOCK_IN_OMAP16XX |
  456. RATE_FIXED | ENABLE_REG_32BIT,
  457. .enable_reg = MOD_CONF_CTRL_0,
  458. .enable_bit = 20,
  459. };
  460. static struct clk virtual_ck_mpu = {
  461. .name = "mpu",
  462. .flags = CLOCK_IN_OMAP1510 | CLOCK_IN_OMAP16XX |
  463. VIRTUAL_CLOCK | ALWAYS_ENABLED,
  464. .parent = &arm_ck, /* Is smarter alias for */
  465. .recalc = &followparent_recalc,
  466. .set_rate = &select_table_rate,
  467. .round_rate = &round_to_table_rate,
  468. };
  469. static struct clk * onchip_clks[] = {
  470. /* non-ULPD clocks */
  471. &ck_ref,
  472. &ck_dpll1,
  473. /* CK_GEN1 clocks */
  474. &ck_dpll1out,
  475. &arm_ck,
  476. &armper_ck,
  477. &arm_gpio_ck,
  478. &armxor_ck,
  479. &armtim_ck,
  480. &armwdt_ck,
  481. &arminth_ck1510, &arminth_ck16xx,
  482. /* CK_GEN2 clocks */
  483. &dsp_ck,
  484. &dspmmu_ck,
  485. &dspper_ck,
  486. &dspxor_ck,
  487. &dsptim_ck,
  488. /* CK_GEN3 clocks */
  489. &tc_ck,
  490. &tipb_ck,
  491. &l3_ocpi_ck,
  492. &tc1_ck,
  493. &tc2_ck,
  494. &dma_ck,
  495. &dma_lcdfree_ck,
  496. &api_ck,
  497. &lb_ck,
  498. &rhea1_ck,
  499. &rhea2_ck,
  500. &lcd_ck,
  501. /* ULPD clocks */
  502. &uart1_1510,
  503. &uart1_16xx,
  504. &uart2_ck,
  505. &uart3_1510,
  506. &uart3_16xx,
  507. &usb_clko,
  508. &usb_hhc_ck1510, &usb_hhc_ck16xx,
  509. &usb_dc_ck,
  510. &mclk_1510, &mclk_16xx,
  511. &bclk_1510, &bclk_16xx,
  512. &mmc1_ck,
  513. &mmc2_ck,
  514. /* Virtual clocks */
  515. &virtual_ck_mpu,
  516. };
  517. struct clk *clk_get(struct device *dev, const char *id)
  518. {
  519. struct clk *p, *clk = ERR_PTR(-ENOENT);
  520. down(&clocks_sem);
  521. list_for_each_entry(p, &clocks, node) {
  522. if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
  523. clk = p;
  524. break;
  525. }
  526. }
  527. up(&clocks_sem);
  528. return clk;
  529. }
  530. EXPORT_SYMBOL(clk_get);
  531. void clk_put(struct clk *clk)
  532. {
  533. if (clk && !IS_ERR(clk))
  534. module_put(clk->owner);
  535. }
  536. EXPORT_SYMBOL(clk_put);
  537. int __clk_enable(struct clk *clk)
  538. {
  539. __u16 regval16;
  540. __u32 regval32;
  541. if (clk->flags & ALWAYS_ENABLED)
  542. return 0;
  543. if (unlikely(clk->enable_reg == 0)) {
  544. printk(KERN_ERR "clock.c: Enable for %s without enable code\n",
  545. clk->name);
  546. return 0;
  547. }
  548. if (clk->flags & DSP_DOMAIN_CLOCK) {
  549. __clk_use(&api_ck);
  550. }
  551. if (clk->flags & ENABLE_REG_32BIT) {
  552. if (clk->flags & VIRTUAL_IO_ADDRESS) {
  553. regval32 = __raw_readl(clk->enable_reg);
  554. regval32 |= (1 << clk->enable_bit);
  555. __raw_writel(regval32, clk->enable_reg);
  556. } else {
  557. regval32 = omap_readl(clk->enable_reg);
  558. regval32 |= (1 << clk->enable_bit);
  559. omap_writel(regval32, clk->enable_reg);
  560. }
  561. } else {
  562. if (clk->flags & VIRTUAL_IO_ADDRESS) {
  563. regval16 = __raw_readw(clk->enable_reg);
  564. regval16 |= (1 << clk->enable_bit);
  565. __raw_writew(regval16, clk->enable_reg);
  566. } else {
  567. regval16 = omap_readw(clk->enable_reg);
  568. regval16 |= (1 << clk->enable_bit);
  569. omap_writew(regval16, clk->enable_reg);
  570. }
  571. }
  572. if (clk->flags & DSP_DOMAIN_CLOCK) {
  573. __clk_unuse(&api_ck);
  574. }
  575. return 0;
  576. }
  577. void __clk_disable(struct clk *clk)
  578. {
  579. __u16 regval16;
  580. __u32 regval32;
  581. if (clk->enable_reg == 0)
  582. return;
  583. if (clk->flags & DSP_DOMAIN_CLOCK) {
  584. __clk_use(&api_ck);
  585. }
  586. if (clk->flags & ENABLE_REG_32BIT) {
  587. if (clk->flags & VIRTUAL_IO_ADDRESS) {
  588. regval32 = __raw_readl(clk->enable_reg);
  589. regval32 &= ~(1 << clk->enable_bit);
  590. __raw_writel(regval32, clk->enable_reg);
  591. } else {
  592. regval32 = omap_readl(clk->enable_reg);
  593. regval32 &= ~(1 << clk->enable_bit);
  594. omap_writel(regval32, clk->enable_reg);
  595. }
  596. } else {
  597. if (clk->flags & VIRTUAL_IO_ADDRESS) {
  598. regval16 = __raw_readw(clk->enable_reg);
  599. regval16 &= ~(1 << clk->enable_bit);
  600. __raw_writew(regval16, clk->enable_reg);
  601. } else {
  602. regval16 = omap_readw(clk->enable_reg);
  603. regval16 &= ~(1 << clk->enable_bit);
  604. omap_writew(regval16, clk->enable_reg);
  605. }
  606. }
  607. if (clk->flags & DSP_DOMAIN_CLOCK) {
  608. __clk_unuse(&api_ck);
  609. }
  610. }
  611. void __clk_unuse(struct clk *clk)
  612. {
  613. if (clk->usecount > 0 && !(--clk->usecount)) {
  614. __clk_disable(clk);
  615. if (likely(clk->parent))
  616. __clk_unuse(clk->parent);
  617. }
  618. }
  619. int __clk_use(struct clk *clk)
  620. {
  621. int ret = 0;
  622. if (clk->usecount++ == 0) {
  623. if (likely(clk->parent))
  624. ret = __clk_use(clk->parent);
  625. if (unlikely(ret != 0)) {
  626. clk->usecount--;
  627. return ret;
  628. }
  629. ret = __clk_enable(clk);
  630. if (unlikely(ret != 0) && clk->parent) {
  631. __clk_unuse(clk->parent);
  632. clk->usecount--;
  633. }
  634. }
  635. return ret;
  636. }
  637. int clk_enable(struct clk *clk)
  638. {
  639. unsigned long flags;
  640. int ret;
  641. spin_lock_irqsave(&clockfw_lock, flags);
  642. ret = __clk_enable(clk);
  643. spin_unlock_irqrestore(&clockfw_lock, flags);
  644. return ret;
  645. }
  646. EXPORT_SYMBOL(clk_enable);
  647. void clk_disable(struct clk *clk)
  648. {
  649. unsigned long flags;
  650. spin_lock_irqsave(&clockfw_lock, flags);
  651. __clk_disable(clk);
  652. spin_unlock_irqrestore(&clockfw_lock, flags);
  653. }
  654. EXPORT_SYMBOL(clk_disable);
  655. int clk_use(struct clk *clk)
  656. {
  657. unsigned long flags;
  658. int ret = 0;
  659. spin_lock_irqsave(&clockfw_lock, flags);
  660. ret = __clk_use(clk);
  661. spin_unlock_irqrestore(&clockfw_lock, flags);
  662. return ret;
  663. }
  664. EXPORT_SYMBOL(clk_use);
  665. void clk_unuse(struct clk *clk)
  666. {
  667. unsigned long flags;
  668. spin_lock_irqsave(&clockfw_lock, flags);
  669. __clk_unuse(clk);
  670. spin_unlock_irqrestore(&clockfw_lock, flags);
  671. }
  672. EXPORT_SYMBOL(clk_unuse);
  673. int clk_get_usecount(struct clk *clk)
  674. {
  675. return clk->usecount;
  676. }
  677. EXPORT_SYMBOL(clk_get_usecount);
  678. unsigned long clk_get_rate(struct clk *clk)
  679. {
  680. return clk->rate;
  681. }
  682. EXPORT_SYMBOL(clk_get_rate);
  683. static __u16 verify_ckctl_value(__u16 newval)
  684. {
  685. /* This function checks for following limitations set
  686. * by the hardware (all conditions must be true):
  687. * DSPMMU_CK == DSP_CK or DSPMMU_CK == DSP_CK/2
  688. * ARM_CK >= TC_CK
  689. * DSP_CK >= TC_CK
  690. * DSPMMU_CK >= TC_CK
  691. *
  692. * In addition following rules are enforced:
  693. * LCD_CK <= TC_CK
  694. * ARMPER_CK <= TC_CK
  695. *
  696. * However, maximum frequencies are not checked for!
  697. */
  698. __u8 per_exp;
  699. __u8 lcd_exp;
  700. __u8 arm_exp;
  701. __u8 dsp_exp;
  702. __u8 tc_exp;
  703. __u8 dspmmu_exp;
  704. per_exp = (newval >> CKCTL_PERDIV_OFFSET) & 3;
  705. lcd_exp = (newval >> CKCTL_LCDDIV_OFFSET) & 3;
  706. arm_exp = (newval >> CKCTL_ARMDIV_OFFSET) & 3;
  707. dsp_exp = (newval >> CKCTL_DSPDIV_OFFSET) & 3;
  708. tc_exp = (newval >> CKCTL_TCDIV_OFFSET) & 3;
  709. dspmmu_exp = (newval >> CKCTL_DSPMMUDIV_OFFSET) & 3;
  710. if (dspmmu_exp < dsp_exp)
  711. dspmmu_exp = dsp_exp;
  712. if (dspmmu_exp > dsp_exp+1)
  713. dspmmu_exp = dsp_exp+1;
  714. if (tc_exp < arm_exp)
  715. tc_exp = arm_exp;
  716. if (tc_exp < dspmmu_exp)
  717. tc_exp = dspmmu_exp;
  718. if (tc_exp > lcd_exp)
  719. lcd_exp = tc_exp;
  720. if (tc_exp > per_exp)
  721. per_exp = tc_exp;
  722. newval &= 0xf000;
  723. newval |= per_exp << CKCTL_PERDIV_OFFSET;
  724. newval |= lcd_exp << CKCTL_LCDDIV_OFFSET;
  725. newval |= arm_exp << CKCTL_ARMDIV_OFFSET;
  726. newval |= dsp_exp << CKCTL_DSPDIV_OFFSET;
  727. newval |= tc_exp << CKCTL_TCDIV_OFFSET;
  728. newval |= dspmmu_exp << CKCTL_DSPMMUDIV_OFFSET;
  729. return newval;
  730. }
  731. static int calc_dsor_exp(struct clk *clk, unsigned long rate)
  732. {
  733. /* Note: If target frequency is too low, this function will return 4,
  734. * which is invalid value. Caller must check for this value and act
  735. * accordingly.
  736. *
  737. * Note: This function does not check for following limitations set
  738. * by the hardware (all conditions must be true):
  739. * DSPMMU_CK == DSP_CK or DSPMMU_CK == DSP_CK/2
  740. * ARM_CK >= TC_CK
  741. * DSP_CK >= TC_CK
  742. * DSPMMU_CK >= TC_CK
  743. */
  744. unsigned long realrate;
  745. struct clk * parent;
  746. unsigned dsor_exp;
  747. if (unlikely(!(clk->flags & RATE_CKCTL)))
  748. return -EINVAL;
  749. parent = clk->parent;
  750. if (unlikely(parent == 0))
  751. return -EIO;
  752. realrate = parent->rate;
  753. for (dsor_exp=0; dsor_exp<4; dsor_exp++) {
  754. if (realrate <= rate)
  755. break;
  756. realrate /= 2;
  757. }
  758. return dsor_exp;
  759. }
  760. static void ckctl_recalc(struct clk * clk)
  761. {
  762. int dsor;
  763. /* Calculate divisor encoded as 2-bit exponent */
  764. if (clk->flags & DSP_DOMAIN_CLOCK) {
  765. /* The clock control bits are in DSP domain,
  766. * so api_ck is needed for access.
  767. * Note that DSP_CKCTL virt addr = phys addr, so
  768. * we must use __raw_readw() instead of omap_readw().
  769. */
  770. __clk_use(&api_ck);
  771. dsor = 1 << (3 & (__raw_readw(DSP_CKCTL) >> clk->rate_offset));
  772. __clk_unuse(&api_ck);
  773. } else {
  774. dsor = 1 << (3 & (omap_readw(ARM_CKCTL) >> clk->rate_offset));
  775. }
  776. if (unlikely(clk->rate == clk->parent->rate / dsor))
  777. return; /* No change, quick exit */
  778. clk->rate = clk->parent->rate / dsor;
  779. if (unlikely(clk->flags & RATE_PROPAGATES))
  780. propagate_rate(clk);
  781. }
  782. long clk_round_rate(struct clk *clk, unsigned long rate)
  783. {
  784. int dsor_exp;
  785. if (clk->flags & RATE_FIXED)
  786. return clk->rate;
  787. if (clk->flags & RATE_CKCTL) {
  788. dsor_exp = calc_dsor_exp(clk, rate);
  789. if (dsor_exp < 0)
  790. return dsor_exp;
  791. if (dsor_exp > 3)
  792. dsor_exp = 3;
  793. return clk->parent->rate / (1 << dsor_exp);
  794. }
  795. if(clk->round_rate != 0)
  796. return clk->round_rate(clk, rate);
  797. return clk->rate;
  798. }
  799. EXPORT_SYMBOL(clk_round_rate);
  800. static void propagate_rate(struct clk * clk)
  801. {
  802. struct clk ** clkp;
  803. for (clkp = onchip_clks; clkp < onchip_clks+ARRAY_SIZE(onchip_clks); clkp++) {
  804. if (likely((*clkp)->parent != clk)) continue;
  805. if (likely((*clkp)->recalc))
  806. (*clkp)->recalc(*clkp);
  807. }
  808. }
  809. static int select_table_rate(struct clk * clk, unsigned long rate)
  810. {
  811. /* Find the highest supported frequency <= rate and switch to it */
  812. struct mpu_rate * ptr;
  813. if (clk != &virtual_ck_mpu)
  814. return -EINVAL;
  815. for (ptr = rate_table; ptr->rate; ptr++) {
  816. if (ptr->xtal != ck_ref.rate)
  817. continue;
  818. /* DPLL1 cannot be reprogrammed without risking system crash */
  819. if (likely(ck_dpll1.rate!=0) && ptr->pll_rate != ck_dpll1.rate)
  820. continue;
  821. /* Can check only after xtal frequency check */
  822. if (ptr->rate <= rate)
  823. break;
  824. }
  825. if (!ptr->rate)
  826. return -EINVAL;
  827. /*
  828. * In most cases we should not need to reprogram DPLL.
  829. * Reprogramming the DPLL is tricky, it must be done from SRAM.
  830. */
  831. omap_sram_reprogram_clock(ptr->dpllctl_val, ptr->ckctl_val);
  832. ck_dpll1.rate = ptr->pll_rate;
  833. propagate_rate(&ck_dpll1);
  834. return 0;
  835. }
  836. static long round_to_table_rate(struct clk * clk, unsigned long rate)
  837. {
  838. /* Find the highest supported frequency <= rate */
  839. struct mpu_rate * ptr;
  840. long highest_rate;
  841. if (clk != &virtual_ck_mpu)
  842. return -EINVAL;
  843. highest_rate = -EINVAL;
  844. for (ptr = rate_table; ptr->rate; ptr++) {
  845. if (ptr->xtal != ck_ref.rate)
  846. continue;
  847. highest_rate = ptr->rate;
  848. /* Can check only after xtal frequency check */
  849. if (ptr->rate <= rate)
  850. break;
  851. }
  852. return highest_rate;
  853. }
  854. int clk_set_rate(struct clk *clk, unsigned long rate)
  855. {
  856. int ret = -EINVAL;
  857. int dsor_exp;
  858. __u16 regval;
  859. unsigned long flags;
  860. if (clk->flags & RATE_CKCTL) {
  861. dsor_exp = calc_dsor_exp(clk, rate);
  862. if (dsor_exp > 3)
  863. dsor_exp = -EINVAL;
  864. if (dsor_exp < 0)
  865. return dsor_exp;
  866. spin_lock_irqsave(&clockfw_lock, flags);
  867. regval = omap_readw(ARM_CKCTL);
  868. regval &= ~(3 << clk->rate_offset);
  869. regval |= dsor_exp << clk->rate_offset;
  870. regval = verify_ckctl_value(regval);
  871. omap_writew(regval, ARM_CKCTL);
  872. clk->rate = clk->parent->rate / (1 << dsor_exp);
  873. spin_unlock_irqrestore(&clockfw_lock, flags);
  874. ret = 0;
  875. } else if(clk->set_rate != 0) {
  876. spin_lock_irqsave(&clockfw_lock, flags);
  877. ret = clk->set_rate(clk, rate);
  878. spin_unlock_irqrestore(&clockfw_lock, flags);
  879. }
  880. if (unlikely(ret == 0 && (clk->flags & RATE_PROPAGATES)))
  881. propagate_rate(clk);
  882. return ret;
  883. }
  884. EXPORT_SYMBOL(clk_set_rate);
  885. static unsigned calc_ext_dsor(unsigned long rate)
  886. {
  887. unsigned dsor;
  888. /* MCLK and BCLK divisor selection is not linear:
  889. * freq = 96MHz / dsor
  890. *
  891. * RATIO_SEL range: dsor <-> RATIO_SEL
  892. * 0..6: (RATIO_SEL+2) <-> (dsor-2)
  893. * 6..48: (8+(RATIO_SEL-6)*2) <-> ((dsor-8)/2+6)
  894. * Minimum dsor is 2 and maximum is 96. Odd divisors starting from 9
  895. * can not be used.
  896. */
  897. for (dsor = 2; dsor < 96; ++dsor) {
  898. if ((dsor & 1) && dsor > 8)
  899. continue;
  900. if (rate >= 96000000 / dsor)
  901. break;
  902. }
  903. return dsor;
  904. }
  905. /* Only needed on 1510 */
  906. static int set_uart_rate(struct clk * clk, unsigned long rate)
  907. {
  908. unsigned int val;
  909. val = omap_readl(clk->enable_reg);
  910. if (rate == 12000000)
  911. val &= ~(1 << clk->enable_bit);
  912. else if (rate == 48000000)
  913. val |= (1 << clk->enable_bit);
  914. else
  915. return -EINVAL;
  916. omap_writel(val, clk->enable_reg);
  917. clk->rate = rate;
  918. return 0;
  919. }
  920. static int set_ext_clk_rate(struct clk * clk, unsigned long rate)
  921. {
  922. unsigned dsor;
  923. __u16 ratio_bits;
  924. dsor = calc_ext_dsor(rate);
  925. clk->rate = 96000000 / dsor;
  926. if (dsor > 8)
  927. ratio_bits = ((dsor - 8) / 2 + 6) << 2;
  928. else
  929. ratio_bits = (dsor - 2) << 2;
  930. ratio_bits |= omap_readw(clk->enable_reg) & ~0xfd;
  931. omap_writew(ratio_bits, clk->enable_reg);
  932. return 0;
  933. }
  934. static long round_ext_clk_rate(struct clk * clk, unsigned long rate)
  935. {
  936. return 96000000 / calc_ext_dsor(rate);
  937. }
  938. static void init_ext_clk(struct clk * clk)
  939. {
  940. unsigned dsor;
  941. __u16 ratio_bits;
  942. /* Determine current rate and ensure clock is based on 96MHz APLL */
  943. ratio_bits = omap_readw(clk->enable_reg) & ~1;
  944. omap_writew(ratio_bits, clk->enable_reg);
  945. ratio_bits = (ratio_bits & 0xfc) >> 2;
  946. if (ratio_bits > 6)
  947. dsor = (ratio_bits - 6) * 2 + 8;
  948. else
  949. dsor = ratio_bits + 2;
  950. clk-> rate = 96000000 / dsor;
  951. }
  952. int clk_register(struct clk *clk)
  953. {
  954. down(&clocks_sem);
  955. list_add(&clk->node, &clocks);
  956. if (clk->init)
  957. clk->init(clk);
  958. up(&clocks_sem);
  959. return 0;
  960. }
  961. EXPORT_SYMBOL(clk_register);
  962. void clk_unregister(struct clk *clk)
  963. {
  964. down(&clocks_sem);
  965. list_del(&clk->node);
  966. up(&clocks_sem);
  967. }
  968. EXPORT_SYMBOL(clk_unregister);
  969. #ifdef CONFIG_OMAP_RESET_CLOCKS
  970. /*
  971. * Resets some clocks that may be left on from bootloader,
  972. * but leaves serial clocks on. See also omap_late_clk_reset().
  973. */
  974. static inline void omap_early_clk_reset(void)
  975. {
  976. //omap_writel(0x3 << 29, MOD_CONF_CTRL_0);
  977. }
  978. #else
  979. #define omap_early_clk_reset() {}
  980. #endif
  981. int __init clk_init(void)
  982. {
  983. struct clk ** clkp;
  984. const struct omap_clock_config *info;
  985. int crystal_type = 0; /* Default 12 MHz */
  986. omap_early_clk_reset();
  987. for (clkp = onchip_clks; clkp < onchip_clks+ARRAY_SIZE(onchip_clks); clkp++) {
  988. if (((*clkp)->flags &CLOCK_IN_OMAP1510) && cpu_is_omap1510()) {
  989. clk_register(*clkp);
  990. continue;
  991. }
  992. if (((*clkp)->flags &CLOCK_IN_OMAP16XX) && cpu_is_omap16xx()) {
  993. clk_register(*clkp);
  994. continue;
  995. }
  996. if (((*clkp)->flags &CLOCK_IN_OMAP730) && cpu_is_omap730()) {
  997. clk_register(*clkp);
  998. continue;
  999. }
  1000. }
  1001. info = omap_get_config(OMAP_TAG_CLOCK, struct omap_clock_config);
  1002. if (info != NULL) {
  1003. if (!cpu_is_omap1510())
  1004. crystal_type = info->system_clock_type;
  1005. }
  1006. #if defined(CONFIG_ARCH_OMAP730)
  1007. ck_ref.rate = 13000000;
  1008. #elif defined(CONFIG_ARCH_OMAP16XX)
  1009. if (crystal_type == 2)
  1010. ck_ref.rate = 19200000;
  1011. #endif
  1012. printk("Clocks: ARM_SYSST: 0x%04x DPLL_CTL: 0x%04x ARM_CKCTL: 0x%04x\n",
  1013. omap_readw(ARM_SYSST), omap_readw(DPLL_CTL),
  1014. omap_readw(ARM_CKCTL));
  1015. /* We want to be in syncronous scalable mode */
  1016. omap_writew(0x1000, ARM_SYSST);
  1017. #ifdef CONFIG_OMAP_CLOCKS_SET_BY_BOOTLOADER
  1018. /* Use values set by bootloader. Determine PLL rate and recalculate
  1019. * dependent clocks as if kernel had changed PLL or divisors.
  1020. */
  1021. {
  1022. unsigned pll_ctl_val = omap_readw(DPLL_CTL);
  1023. ck_dpll1.rate = ck_ref.rate; /* Base xtal rate */
  1024. if (pll_ctl_val & 0x10) {
  1025. /* PLL enabled, apply multiplier and divisor */
  1026. if (pll_ctl_val & 0xf80)
  1027. ck_dpll1.rate *= (pll_ctl_val & 0xf80) >> 7;
  1028. ck_dpll1.rate /= ((pll_ctl_val & 0x60) >> 5) + 1;
  1029. } else {
  1030. /* PLL disabled, apply bypass divisor */
  1031. switch (pll_ctl_val & 0xc) {
  1032. case 0:
  1033. break;
  1034. case 0x4:
  1035. ck_dpll1.rate /= 2;
  1036. break;
  1037. default:
  1038. ck_dpll1.rate /= 4;
  1039. break;
  1040. }
  1041. }
  1042. }
  1043. propagate_rate(&ck_dpll1);
  1044. #else
  1045. /* Find the highest supported frequency and enable it */
  1046. if (select_table_rate(&virtual_ck_mpu, ~0)) {
  1047. printk(KERN_ERR "System frequencies not set. Check your config.\n");
  1048. /* Guess sane values (60MHz) */
  1049. omap_writew(0x2290, DPLL_CTL);
  1050. omap_writew(0x1005, ARM_CKCTL);
  1051. ck_dpll1.rate = 60000000;
  1052. propagate_rate(&ck_dpll1);
  1053. }
  1054. #endif
  1055. /* Cache rates for clocks connected to ck_ref (not dpll1) */
  1056. propagate_rate(&ck_ref);
  1057. printk(KERN_INFO "Clocking rate (xtal/DPLL1/MPU): "
  1058. "%ld.%01ld/%ld.%01ld/%ld.%01ld MHz\n",
  1059. ck_ref.rate / 1000000, (ck_ref.rate / 100000) % 10,
  1060. ck_dpll1.rate / 1000000, (ck_dpll1.rate / 100000) % 10,
  1061. arm_ck.rate / 1000000, (arm_ck.rate / 100000) % 10);
  1062. #ifdef CONFIG_MACH_OMAP_PERSEUS2
  1063. /* Select slicer output as OMAP input clock */
  1064. omap_writew(omap_readw(OMAP730_PCC_UPLD_CTRL) & ~0x1, OMAP730_PCC_UPLD_CTRL);
  1065. #endif
  1066. /* Turn off DSP and ARM_TIMXO. Make sure ARM_INTHCK is not divided */
  1067. omap_writew(omap_readw(ARM_CKCTL) & 0x0fff, ARM_CKCTL);
  1068. /* Put DSP/MPUI into reset until needed */
  1069. omap_writew(0, ARM_RSTCT1);
  1070. omap_writew(1, ARM_RSTCT2);
  1071. omap_writew(0x400, ARM_IDLECT1);
  1072. /*
  1073. * According to OMAP5910 Erratum SYS_DMA_1, bit DMACK_REQ (bit 8)
  1074. * of the ARM_IDLECT2 register must be set to zero. The power-on
  1075. * default value of this bit is one.
  1076. */
  1077. omap_writew(0x0000, ARM_IDLECT2); /* Turn LCD clock off also */
  1078. /*
  1079. * Only enable those clocks we will need, let the drivers
  1080. * enable other clocks as necessary
  1081. */
  1082. clk_use(&armper_ck);
  1083. clk_use(&armxor_ck);
  1084. clk_use(&armtim_ck);
  1085. if (cpu_is_omap1510())
  1086. clk_enable(&arm_gpio_ck);
  1087. return 0;
  1088. }
  1089. #ifdef CONFIG_OMAP_RESET_CLOCKS
  1090. static int __init omap_late_clk_reset(void)
  1091. {
  1092. /* Turn off all unused clocks */
  1093. struct clk *p;
  1094. __u32 regval32;
  1095. /* USB_REQ_EN will be disabled later if necessary (usb_dc_ck) */
  1096. regval32 = omap_readw(SOFT_REQ_REG) & (1 << 4);
  1097. omap_writew(regval32, SOFT_REQ_REG);
  1098. omap_writew(0, SOFT_REQ_REG2);
  1099. list_for_each_entry(p, &clocks, node) {
  1100. if (p->usecount > 0 || (p->flags & ALWAYS_ENABLED) ||
  1101. p->enable_reg == 0)
  1102. continue;
  1103. /* Assume no DSP clocks have been activated by bootloader */
  1104. if (p->flags & DSP_DOMAIN_CLOCK)
  1105. continue;
  1106. /* Is the clock already disabled? */
  1107. if (p->flags & ENABLE_REG_32BIT) {
  1108. if (p->flags & VIRTUAL_IO_ADDRESS)
  1109. regval32 = __raw_readl(p->enable_reg);
  1110. else
  1111. regval32 = omap_readl(p->enable_reg);
  1112. } else {
  1113. if (p->flags & VIRTUAL_IO_ADDRESS)
  1114. regval32 = __raw_readw(p->enable_reg);
  1115. else
  1116. regval32 = omap_readw(p->enable_reg);
  1117. }
  1118. if ((regval32 & (1 << p->enable_bit)) == 0)
  1119. continue;
  1120. /* FIXME: This clock seems to be necessary but no-one
  1121. * has asked for its activation. */
  1122. if (p == &tc2_ck // FIX: pm.c (SRAM), CCP, Camera
  1123. || p == &ck_dpll1out // FIX: SoSSI, SSR
  1124. || p == &arm_gpio_ck // FIX: GPIO code for 1510
  1125. ) {
  1126. printk(KERN_INFO "FIXME: Clock \"%s\" seems unused\n",
  1127. p->name);
  1128. continue;
  1129. }
  1130. printk(KERN_INFO "Disabling unused clock \"%s\"... ", p->name);
  1131. __clk_disable(p);
  1132. printk(" done\n");
  1133. }
  1134. return 0;
  1135. }
  1136. late_initcall(omap_late_clk_reset);
  1137. #endif