clock.c 31 KB

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