clock34xx.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. /*
  2. * OMAP3-specific clock framework functions
  3. *
  4. * Copyright (C) 2007-2008 Texas Instruments, Inc.
  5. * Copyright (C) 2007-2009 Nokia Corporation
  6. *
  7. * Written by Paul Walmsley
  8. * Testing and integration fixes by Jouni Högander
  9. *
  10. * Parts of this code are based on code written by
  11. * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. */
  17. #undef DEBUG
  18. #include <linux/module.h>
  19. #include <linux/kernel.h>
  20. #include <linux/device.h>
  21. #include <linux/list.h>
  22. #include <linux/errno.h>
  23. #include <linux/delay.h>
  24. #include <linux/clk.h>
  25. #include <linux/io.h>
  26. #include <linux/limits.h>
  27. #include <linux/bitops.h>
  28. #include <mach/clock.h>
  29. #include <mach/sram.h>
  30. #include <asm/div64.h>
  31. #include <asm/clkdev.h>
  32. #include <mach/sdrc.h>
  33. #include "clock.h"
  34. #include "prm.h"
  35. #include "prm-regbits-34xx.h"
  36. #include "cm.h"
  37. #include "cm-regbits-34xx.h"
  38. static const struct clkops clkops_noncore_dpll_ops;
  39. static void omap3430es2_clk_ssi_find_idlest(struct clk *clk,
  40. void __iomem **idlest_reg,
  41. u8 *idlest_bit);
  42. static void omap3430es2_clk_hsotgusb_find_idlest(struct clk *clk,
  43. void __iomem **idlest_reg,
  44. u8 *idlest_bit);
  45. static void omap3430es2_clk_dss_usbhost_find_idlest(struct clk *clk,
  46. void __iomem **idlest_reg,
  47. u8 *idlest_bit);
  48. static const struct clkops clkops_omap3430es2_ssi_wait = {
  49. .enable = omap2_dflt_clk_enable,
  50. .disable = omap2_dflt_clk_disable,
  51. .find_idlest = omap3430es2_clk_ssi_find_idlest,
  52. .find_companion = omap2_clk_dflt_find_companion,
  53. };
  54. static const struct clkops clkops_omap3430es2_hsotgusb_wait = {
  55. .enable = omap2_dflt_clk_enable,
  56. .disable = omap2_dflt_clk_disable,
  57. .find_idlest = omap3430es2_clk_hsotgusb_find_idlest,
  58. .find_companion = omap2_clk_dflt_find_companion,
  59. };
  60. static const struct clkops clkops_omap3430es2_dss_usbhost_wait = {
  61. .enable = omap2_dflt_clk_enable,
  62. .disable = omap2_dflt_clk_disable,
  63. .find_idlest = omap3430es2_clk_dss_usbhost_find_idlest,
  64. .find_companion = omap2_clk_dflt_find_companion,
  65. };
  66. #include "clock34xx.h"
  67. struct omap_clk {
  68. u32 cpu;
  69. struct clk_lookup lk;
  70. };
  71. #define CLK(dev, con, ck, cp) \
  72. { \
  73. .cpu = cp, \
  74. .lk = { \
  75. .dev_id = dev, \
  76. .con_id = con, \
  77. .clk = ck, \
  78. }, \
  79. }
  80. #define CK_343X (1 << 0)
  81. #define CK_3430ES1 (1 << 1)
  82. #define CK_3430ES2 (1 << 2)
  83. static struct omap_clk omap34xx_clks[] = {
  84. CLK(NULL, "omap_32k_fck", &omap_32k_fck, CK_343X),
  85. CLK(NULL, "virt_12m_ck", &virt_12m_ck, CK_343X),
  86. CLK(NULL, "virt_13m_ck", &virt_13m_ck, CK_343X),
  87. CLK(NULL, "virt_16_8m_ck", &virt_16_8m_ck, CK_3430ES2),
  88. CLK(NULL, "virt_19_2m_ck", &virt_19_2m_ck, CK_343X),
  89. CLK(NULL, "virt_26m_ck", &virt_26m_ck, CK_343X),
  90. CLK(NULL, "virt_38_4m_ck", &virt_38_4m_ck, CK_343X),
  91. CLK(NULL, "osc_sys_ck", &osc_sys_ck, CK_343X),
  92. CLK(NULL, "sys_ck", &sys_ck, CK_343X),
  93. CLK(NULL, "sys_altclk", &sys_altclk, CK_343X),
  94. CLK(NULL, "mcbsp_clks", &mcbsp_clks, CK_343X),
  95. CLK(NULL, "sys_clkout1", &sys_clkout1, CK_343X),
  96. CLK(NULL, "dpll1_ck", &dpll1_ck, CK_343X),
  97. CLK(NULL, "dpll1_x2_ck", &dpll1_x2_ck, CK_343X),
  98. CLK(NULL, "dpll1_x2m2_ck", &dpll1_x2m2_ck, CK_343X),
  99. CLK(NULL, "dpll2_ck", &dpll2_ck, CK_343X),
  100. CLK(NULL, "dpll2_m2_ck", &dpll2_m2_ck, CK_343X),
  101. CLK(NULL, "dpll3_ck", &dpll3_ck, CK_343X),
  102. CLK(NULL, "core_ck", &core_ck, CK_343X),
  103. CLK(NULL, "dpll3_x2_ck", &dpll3_x2_ck, CK_343X),
  104. CLK(NULL, "dpll3_m2_ck", &dpll3_m2_ck, CK_343X),
  105. CLK(NULL, "dpll3_m2x2_ck", &dpll3_m2x2_ck, CK_343X),
  106. CLK(NULL, "dpll3_m3_ck", &dpll3_m3_ck, CK_343X),
  107. CLK(NULL, "dpll3_m3x2_ck", &dpll3_m3x2_ck, CK_343X),
  108. CLK(NULL, "emu_core_alwon_ck", &emu_core_alwon_ck, CK_343X),
  109. CLK(NULL, "dpll4_ck", &dpll4_ck, CK_343X),
  110. CLK(NULL, "dpll4_x2_ck", &dpll4_x2_ck, CK_343X),
  111. CLK(NULL, "omap_96m_alwon_fck", &omap_96m_alwon_fck, CK_343X),
  112. CLK(NULL, "omap_96m_fck", &omap_96m_fck, CK_343X),
  113. CLK(NULL, "cm_96m_fck", &cm_96m_fck, CK_343X),
  114. CLK(NULL, "omap_54m_fck", &omap_54m_fck, CK_343X),
  115. CLK(NULL, "omap_48m_fck", &omap_48m_fck, CK_343X),
  116. CLK(NULL, "omap_12m_fck", &omap_12m_fck, CK_343X),
  117. CLK(NULL, "dpll4_m2_ck", &dpll4_m2_ck, CK_343X),
  118. CLK(NULL, "dpll4_m2x2_ck", &dpll4_m2x2_ck, CK_343X),
  119. CLK(NULL, "dpll4_m3_ck", &dpll4_m3_ck, CK_343X),
  120. CLK(NULL, "dpll4_m3x2_ck", &dpll4_m3x2_ck, CK_343X),
  121. CLK(NULL, "dpll4_m4_ck", &dpll4_m4_ck, CK_343X),
  122. CLK(NULL, "dpll4_m4x2_ck", &dpll4_m4x2_ck, CK_343X),
  123. CLK(NULL, "dpll4_m5_ck", &dpll4_m5_ck, CK_343X),
  124. CLK(NULL, "dpll4_m5x2_ck", &dpll4_m5x2_ck, CK_343X),
  125. CLK(NULL, "dpll4_m6_ck", &dpll4_m6_ck, CK_343X),
  126. CLK(NULL, "dpll4_m6x2_ck", &dpll4_m6x2_ck, CK_343X),
  127. CLK(NULL, "emu_per_alwon_ck", &emu_per_alwon_ck, CK_343X),
  128. CLK(NULL, "dpll5_ck", &dpll5_ck, CK_3430ES2),
  129. CLK(NULL, "dpll5_m2_ck", &dpll5_m2_ck, CK_3430ES2),
  130. CLK(NULL, "clkout2_src_ck", &clkout2_src_ck, CK_343X),
  131. CLK(NULL, "sys_clkout2", &sys_clkout2, CK_343X),
  132. CLK(NULL, "corex2_fck", &corex2_fck, CK_343X),
  133. CLK(NULL, "dpll1_fck", &dpll1_fck, CK_343X),
  134. CLK(NULL, "mpu_ck", &mpu_ck, CK_343X),
  135. CLK(NULL, "arm_fck", &arm_fck, CK_343X),
  136. CLK(NULL, "emu_mpu_alwon_ck", &emu_mpu_alwon_ck, CK_343X),
  137. CLK(NULL, "dpll2_fck", &dpll2_fck, CK_343X),
  138. CLK(NULL, "iva2_ck", &iva2_ck, CK_343X),
  139. CLK(NULL, "l3_ick", &l3_ick, CK_343X),
  140. CLK(NULL, "l4_ick", &l4_ick, CK_343X),
  141. CLK(NULL, "rm_ick", &rm_ick, CK_343X),
  142. CLK(NULL, "gfx_l3_ck", &gfx_l3_ck, CK_3430ES1),
  143. CLK(NULL, "gfx_l3_fck", &gfx_l3_fck, CK_3430ES1),
  144. CLK(NULL, "gfx_l3_ick", &gfx_l3_ick, CK_3430ES1),
  145. CLK(NULL, "gfx_cg1_ck", &gfx_cg1_ck, CK_3430ES1),
  146. CLK(NULL, "gfx_cg2_ck", &gfx_cg2_ck, CK_3430ES1),
  147. CLK(NULL, "sgx_fck", &sgx_fck, CK_3430ES2),
  148. CLK(NULL, "sgx_ick", &sgx_ick, CK_3430ES2),
  149. CLK(NULL, "d2d_26m_fck", &d2d_26m_fck, CK_3430ES1),
  150. CLK(NULL, "modem_fck", &modem_fck, CK_343X),
  151. CLK(NULL, "sad2d_ick", &sad2d_ick, CK_343X),
  152. CLK(NULL, "mad2d_ick", &mad2d_ick, CK_343X),
  153. CLK(NULL, "gpt10_fck", &gpt10_fck, CK_343X),
  154. CLK(NULL, "gpt11_fck", &gpt11_fck, CK_343X),
  155. CLK(NULL, "cpefuse_fck", &cpefuse_fck, CK_3430ES2),
  156. CLK(NULL, "ts_fck", &ts_fck, CK_3430ES2),
  157. CLK(NULL, "usbtll_fck", &usbtll_fck, CK_3430ES2),
  158. CLK(NULL, "core_96m_fck", &core_96m_fck, CK_343X),
  159. CLK("mmci-omap-hs.2", "fck", &mmchs3_fck, CK_3430ES2),
  160. CLK("mmci-omap-hs.1", "fck", &mmchs2_fck, CK_343X),
  161. CLK(NULL, "mspro_fck", &mspro_fck, CK_343X),
  162. CLK("mmci-omap-hs.0", "fck", &mmchs1_fck, CK_343X),
  163. CLK("i2c_omap.3", "fck", &i2c3_fck, CK_343X),
  164. CLK("i2c_omap.2", "fck", &i2c2_fck, CK_343X),
  165. CLK("i2c_omap.1", "fck", &i2c1_fck, CK_343X),
  166. CLK("omap-mcbsp.5", "fck", &mcbsp5_fck, CK_343X),
  167. CLK("omap-mcbsp.1", "fck", &mcbsp1_fck, CK_343X),
  168. CLK(NULL, "core_48m_fck", &core_48m_fck, CK_343X),
  169. CLK("omap2_mcspi.4", "fck", &mcspi4_fck, CK_343X),
  170. CLK("omap2_mcspi.3", "fck", &mcspi3_fck, CK_343X),
  171. CLK("omap2_mcspi.2", "fck", &mcspi2_fck, CK_343X),
  172. CLK("omap2_mcspi.1", "fck", &mcspi1_fck, CK_343X),
  173. CLK(NULL, "uart2_fck", &uart2_fck, CK_343X),
  174. CLK(NULL, "uart1_fck", &uart1_fck, CK_343X),
  175. CLK(NULL, "fshostusb_fck", &fshostusb_fck, CK_3430ES1),
  176. CLK(NULL, "core_12m_fck", &core_12m_fck, CK_343X),
  177. CLK("omap_hdq.0", "fck", &hdq_fck, CK_343X),
  178. CLK(NULL, "ssi_ssr_fck", &ssi_ssr_fck_3430es1, CK_3430ES1),
  179. CLK(NULL, "ssi_ssr_fck", &ssi_ssr_fck_3430es2, CK_3430ES2),
  180. CLK(NULL, "ssi_sst_fck", &ssi_sst_fck_3430es1, CK_3430ES1),
  181. CLK(NULL, "ssi_sst_fck", &ssi_sst_fck_3430es2, CK_3430ES2),
  182. CLK(NULL, "core_l3_ick", &core_l3_ick, CK_343X),
  183. CLK("musb_hdrc", "ick", &hsotgusb_ick_3430es1, CK_3430ES1),
  184. CLK("musb_hdrc", "ick", &hsotgusb_ick_3430es2, CK_3430ES2),
  185. CLK(NULL, "sdrc_ick", &sdrc_ick, CK_343X),
  186. CLK(NULL, "gpmc_fck", &gpmc_fck, CK_343X),
  187. CLK(NULL, "security_l3_ick", &security_l3_ick, CK_343X),
  188. CLK(NULL, "pka_ick", &pka_ick, CK_343X),
  189. CLK(NULL, "core_l4_ick", &core_l4_ick, CK_343X),
  190. CLK(NULL, "usbtll_ick", &usbtll_ick, CK_3430ES2),
  191. CLK("mmci-omap-hs.2", "ick", &mmchs3_ick, CK_3430ES2),
  192. CLK(NULL, "icr_ick", &icr_ick, CK_343X),
  193. CLK(NULL, "aes2_ick", &aes2_ick, CK_343X),
  194. CLK(NULL, "sha12_ick", &sha12_ick, CK_343X),
  195. CLK(NULL, "des2_ick", &des2_ick, CK_343X),
  196. CLK("mmci-omap-hs.1", "ick", &mmchs2_ick, CK_343X),
  197. CLK("mmci-omap-hs.0", "ick", &mmchs1_ick, CK_343X),
  198. CLK(NULL, "mspro_ick", &mspro_ick, CK_343X),
  199. CLK("omap_hdq.0", "ick", &hdq_ick, CK_343X),
  200. CLK("omap2_mcspi.4", "ick", &mcspi4_ick, CK_343X),
  201. CLK("omap2_mcspi.3", "ick", &mcspi3_ick, CK_343X),
  202. CLK("omap2_mcspi.2", "ick", &mcspi2_ick, CK_343X),
  203. CLK("omap2_mcspi.1", "ick", &mcspi1_ick, CK_343X),
  204. CLK("i2c_omap.3", "ick", &i2c3_ick, CK_343X),
  205. CLK("i2c_omap.2", "ick", &i2c2_ick, CK_343X),
  206. CLK("i2c_omap.1", "ick", &i2c1_ick, CK_343X),
  207. CLK(NULL, "uart2_ick", &uart2_ick, CK_343X),
  208. CLK(NULL, "uart1_ick", &uart1_ick, CK_343X),
  209. CLK(NULL, "gpt11_ick", &gpt11_ick, CK_343X),
  210. CLK(NULL, "gpt10_ick", &gpt10_ick, CK_343X),
  211. CLK("omap-mcbsp.5", "ick", &mcbsp5_ick, CK_343X),
  212. CLK("omap-mcbsp.1", "ick", &mcbsp1_ick, CK_343X),
  213. CLK(NULL, "fac_ick", &fac_ick, CK_3430ES1),
  214. CLK(NULL, "mailboxes_ick", &mailboxes_ick, CK_343X),
  215. CLK(NULL, "omapctrl_ick", &omapctrl_ick, CK_343X),
  216. CLK(NULL, "ssi_l4_ick", &ssi_l4_ick, CK_343X),
  217. CLK(NULL, "ssi_ick", &ssi_ick_3430es1, CK_3430ES1),
  218. CLK(NULL, "ssi_ick", &ssi_ick_3430es2, CK_3430ES2),
  219. CLK(NULL, "usb_l4_ick", &usb_l4_ick, CK_3430ES1),
  220. CLK(NULL, "security_l4_ick2", &security_l4_ick2, CK_343X),
  221. CLK(NULL, "aes1_ick", &aes1_ick, CK_343X),
  222. CLK("omap_rng", "ick", &rng_ick, CK_343X),
  223. CLK(NULL, "sha11_ick", &sha11_ick, CK_343X),
  224. CLK(NULL, "des1_ick", &des1_ick, CK_343X),
  225. CLK("omapfb", "dss1_fck", &dss1_alwon_fck_3430es1, CK_3430ES1),
  226. CLK("omapfb", "dss1_fck", &dss1_alwon_fck_3430es2, CK_3430ES2),
  227. CLK("omapfb", "tv_fck", &dss_tv_fck, CK_343X),
  228. CLK("omapfb", "video_fck", &dss_96m_fck, CK_343X),
  229. CLK("omapfb", "dss2_fck", &dss2_alwon_fck, CK_343X),
  230. CLK("omapfb", "ick", &dss_ick_3430es1, CK_3430ES1),
  231. CLK("omapfb", "ick", &dss_ick_3430es2, CK_3430ES2),
  232. CLK(NULL, "cam_mclk", &cam_mclk, CK_343X),
  233. CLK(NULL, "cam_ick", &cam_ick, CK_343X),
  234. CLK(NULL, "csi2_96m_fck", &csi2_96m_fck, CK_343X),
  235. CLK(NULL, "usbhost_120m_fck", &usbhost_120m_fck, CK_3430ES2),
  236. CLK(NULL, "usbhost_48m_fck", &usbhost_48m_fck, CK_3430ES2),
  237. CLK(NULL, "usbhost_ick", &usbhost_ick, CK_3430ES2),
  238. CLK(NULL, "usim_fck", &usim_fck, CK_3430ES2),
  239. CLK(NULL, "gpt1_fck", &gpt1_fck, CK_343X),
  240. CLK(NULL, "wkup_32k_fck", &wkup_32k_fck, CK_343X),
  241. CLK(NULL, "gpio1_dbck", &gpio1_dbck, CK_343X),
  242. CLK("omap_wdt", "fck", &wdt2_fck, CK_343X),
  243. CLK(NULL, "wkup_l4_ick", &wkup_l4_ick, CK_343X),
  244. CLK(NULL, "usim_ick", &usim_ick, CK_3430ES2),
  245. CLK("omap_wdt", "ick", &wdt2_ick, CK_343X),
  246. CLK(NULL, "wdt1_ick", &wdt1_ick, CK_343X),
  247. CLK(NULL, "gpio1_ick", &gpio1_ick, CK_343X),
  248. CLK(NULL, "omap_32ksync_ick", &omap_32ksync_ick, CK_343X),
  249. CLK(NULL, "gpt12_ick", &gpt12_ick, CK_343X),
  250. CLK(NULL, "gpt1_ick", &gpt1_ick, CK_343X),
  251. CLK(NULL, "per_96m_fck", &per_96m_fck, CK_343X),
  252. CLK(NULL, "per_48m_fck", &per_48m_fck, CK_343X),
  253. CLK(NULL, "uart3_fck", &uart3_fck, CK_343X),
  254. CLK(NULL, "gpt2_fck", &gpt2_fck, CK_343X),
  255. CLK(NULL, "gpt3_fck", &gpt3_fck, CK_343X),
  256. CLK(NULL, "gpt4_fck", &gpt4_fck, CK_343X),
  257. CLK(NULL, "gpt5_fck", &gpt5_fck, CK_343X),
  258. CLK(NULL, "gpt6_fck", &gpt6_fck, CK_343X),
  259. CLK(NULL, "gpt7_fck", &gpt7_fck, CK_343X),
  260. CLK(NULL, "gpt8_fck", &gpt8_fck, CK_343X),
  261. CLK(NULL, "gpt9_fck", &gpt9_fck, CK_343X),
  262. CLK(NULL, "per_32k_alwon_fck", &per_32k_alwon_fck, CK_343X),
  263. CLK(NULL, "gpio6_dbck", &gpio6_dbck, CK_343X),
  264. CLK(NULL, "gpio5_dbck", &gpio5_dbck, CK_343X),
  265. CLK(NULL, "gpio4_dbck", &gpio4_dbck, CK_343X),
  266. CLK(NULL, "gpio3_dbck", &gpio3_dbck, CK_343X),
  267. CLK(NULL, "gpio2_dbck", &gpio2_dbck, CK_343X),
  268. CLK(NULL, "wdt3_fck", &wdt3_fck, CK_343X),
  269. CLK(NULL, "per_l4_ick", &per_l4_ick, CK_343X),
  270. CLK(NULL, "gpio6_ick", &gpio6_ick, CK_343X),
  271. CLK(NULL, "gpio5_ick", &gpio5_ick, CK_343X),
  272. CLK(NULL, "gpio4_ick", &gpio4_ick, CK_343X),
  273. CLK(NULL, "gpio3_ick", &gpio3_ick, CK_343X),
  274. CLK(NULL, "gpio2_ick", &gpio2_ick, CK_343X),
  275. CLK(NULL, "wdt3_ick", &wdt3_ick, CK_343X),
  276. CLK(NULL, "uart3_ick", &uart3_ick, CK_343X),
  277. CLK(NULL, "gpt9_ick", &gpt9_ick, CK_343X),
  278. CLK(NULL, "gpt8_ick", &gpt8_ick, CK_343X),
  279. CLK(NULL, "gpt7_ick", &gpt7_ick, CK_343X),
  280. CLK(NULL, "gpt6_ick", &gpt6_ick, CK_343X),
  281. CLK(NULL, "gpt5_ick", &gpt5_ick, CK_343X),
  282. CLK(NULL, "gpt4_ick", &gpt4_ick, CK_343X),
  283. CLK(NULL, "gpt3_ick", &gpt3_ick, CK_343X),
  284. CLK(NULL, "gpt2_ick", &gpt2_ick, CK_343X),
  285. CLK("omap-mcbsp.2", "ick", &mcbsp2_ick, CK_343X),
  286. CLK("omap-mcbsp.3", "ick", &mcbsp3_ick, CK_343X),
  287. CLK("omap-mcbsp.4", "ick", &mcbsp4_ick, CK_343X),
  288. CLK("omap-mcbsp.2", "fck", &mcbsp2_fck, CK_343X),
  289. CLK("omap-mcbsp.3", "fck", &mcbsp3_fck, CK_343X),
  290. CLK("omap-mcbsp.4", "fck", &mcbsp4_fck, CK_343X),
  291. CLK(NULL, "emu_src_ck", &emu_src_ck, CK_343X),
  292. CLK(NULL, "pclk_fck", &pclk_fck, CK_343X),
  293. CLK(NULL, "pclkx2_fck", &pclkx2_fck, CK_343X),
  294. CLK(NULL, "atclk_fck", &atclk_fck, CK_343X),
  295. CLK(NULL, "traceclk_src_fck", &traceclk_src_fck, CK_343X),
  296. CLK(NULL, "traceclk_fck", &traceclk_fck, CK_343X),
  297. CLK(NULL, "sr1_fck", &sr1_fck, CK_343X),
  298. CLK(NULL, "sr2_fck", &sr2_fck, CK_343X),
  299. CLK(NULL, "sr_l4_ick", &sr_l4_ick, CK_343X),
  300. CLK(NULL, "secure_32k_fck", &secure_32k_fck, CK_343X),
  301. CLK(NULL, "gpt12_fck", &gpt12_fck, CK_343X),
  302. CLK(NULL, "wdt1_fck", &wdt1_fck, CK_343X),
  303. };
  304. /* CM_AUTOIDLE_PLL*.AUTO_* bit values */
  305. #define DPLL_AUTOIDLE_DISABLE 0x0
  306. #define DPLL_AUTOIDLE_LOW_POWER_STOP 0x1
  307. #define MAX_DPLL_WAIT_TRIES 1000000
  308. #define MIN_SDRC_DLL_LOCK_FREQ 83000000
  309. #define CYCLES_PER_MHZ 1000000
  310. /* Scale factor for fixed-point arith in omap3_core_dpll_m2_set_rate() */
  311. #define SDRC_MPURATE_SCALE 8
  312. /* 2^SDRC_MPURATE_BASE_SHIFT: MPU MHz that SDRC_MPURATE_LOOPS is defined for */
  313. #define SDRC_MPURATE_BASE_SHIFT 9
  314. /*
  315. * SDRC_MPURATE_LOOPS: Number of MPU loops to execute at
  316. * 2^MPURATE_BASE_SHIFT MHz for SDRC to stabilize
  317. */
  318. #define SDRC_MPURATE_LOOPS 96
  319. /**
  320. * omap3430es2_clk_ssi_find_idlest - return CM_IDLEST info for SSI
  321. * @clk: struct clk * being enabled
  322. * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
  323. * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
  324. *
  325. * The OMAP3430ES2 SSI target CM_IDLEST bit is at a different shift
  326. * from the CM_{I,F}CLKEN bit. Pass back the correct info via
  327. * @idlest_reg and @idlest_bit. No return value.
  328. */
  329. static void omap3430es2_clk_ssi_find_idlest(struct clk *clk,
  330. void __iomem **idlest_reg,
  331. u8 *idlest_bit)
  332. {
  333. u32 r;
  334. r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
  335. *idlest_reg = (__force void __iomem *)r;
  336. *idlest_bit = OMAP3430ES2_ST_SSI_IDLE_SHIFT;
  337. }
  338. /**
  339. * omap3430es2_clk_dss_usbhost_find_idlest - CM_IDLEST info for DSS, USBHOST
  340. * @clk: struct clk * being enabled
  341. * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
  342. * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
  343. *
  344. * Some OMAP modules on OMAP3 ES2+ chips have both initiator and
  345. * target IDLEST bits. For our purposes, we are concerned with the
  346. * target IDLEST bits, which exist at a different bit position than
  347. * the *CLKEN bit position for these modules (DSS and USBHOST) (The
  348. * default find_idlest code assumes that they are at the same
  349. * position.) No return value.
  350. */
  351. static void omap3430es2_clk_dss_usbhost_find_idlest(struct clk *clk,
  352. void __iomem **idlest_reg,
  353. u8 *idlest_bit)
  354. {
  355. u32 r;
  356. r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
  357. *idlest_reg = (__force void __iomem *)r;
  358. /* USBHOST_IDLE has same shift */
  359. *idlest_bit = OMAP3430ES2_ST_DSS_IDLE_SHIFT;
  360. }
  361. /**
  362. * omap3430es2_clk_hsotgusb_find_idlest - return CM_IDLEST info for HSOTGUSB
  363. * @clk: struct clk * being enabled
  364. * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
  365. * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
  366. *
  367. * The OMAP3430ES2 HSOTGUSB target CM_IDLEST bit is at a different
  368. * shift from the CM_{I,F}CLKEN bit. Pass back the correct info via
  369. * @idlest_reg and @idlest_bit. No return value.
  370. */
  371. static void omap3430es2_clk_hsotgusb_find_idlest(struct clk *clk,
  372. void __iomem **idlest_reg,
  373. u8 *idlest_bit)
  374. {
  375. u32 r;
  376. r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
  377. *idlest_reg = (__force void __iomem *)r;
  378. *idlest_bit = OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT;
  379. }
  380. /**
  381. * omap3_dpll_recalc - recalculate DPLL rate
  382. * @clk: DPLL struct clk
  383. *
  384. * Recalculate and propagate the DPLL rate.
  385. */
  386. static unsigned long omap3_dpll_recalc(struct clk *clk)
  387. {
  388. return omap2_get_dpll_rate(clk);
  389. }
  390. /* _omap3_dpll_write_clken - write clken_bits arg to a DPLL's enable bits */
  391. static void _omap3_dpll_write_clken(struct clk *clk, u8 clken_bits)
  392. {
  393. const struct dpll_data *dd;
  394. u32 v;
  395. dd = clk->dpll_data;
  396. v = __raw_readl(dd->control_reg);
  397. v &= ~dd->enable_mask;
  398. v |= clken_bits << __ffs(dd->enable_mask);
  399. __raw_writel(v, dd->control_reg);
  400. }
  401. /* _omap3_wait_dpll_status: wait for a DPLL to enter a specific state */
  402. static int _omap3_wait_dpll_status(struct clk *clk, u8 state)
  403. {
  404. const struct dpll_data *dd;
  405. int i = 0;
  406. int ret = -EINVAL;
  407. dd = clk->dpll_data;
  408. state <<= __ffs(dd->idlest_mask);
  409. while (((__raw_readl(dd->idlest_reg) & dd->idlest_mask) != state) &&
  410. i < MAX_DPLL_WAIT_TRIES) {
  411. i++;
  412. udelay(1);
  413. }
  414. if (i == MAX_DPLL_WAIT_TRIES) {
  415. printk(KERN_ERR "clock: %s failed transition to '%s'\n",
  416. clk->name, (state) ? "locked" : "bypassed");
  417. } else {
  418. pr_debug("clock: %s transition to '%s' in %d loops\n",
  419. clk->name, (state) ? "locked" : "bypassed", i);
  420. ret = 0;
  421. }
  422. return ret;
  423. }
  424. /* From 3430 TRM ES2 4.7.6.2 */
  425. static u16 _omap3_dpll_compute_freqsel(struct clk *clk, u8 n)
  426. {
  427. unsigned long fint;
  428. u16 f = 0;
  429. fint = clk->dpll_data->clk_ref->rate / (n + 1);
  430. pr_debug("clock: fint is %lu\n", fint);
  431. if (fint >= 750000 && fint <= 1000000)
  432. f = 0x3;
  433. else if (fint > 1000000 && fint <= 1250000)
  434. f = 0x4;
  435. else if (fint > 1250000 && fint <= 1500000)
  436. f = 0x5;
  437. else if (fint > 1500000 && fint <= 1750000)
  438. f = 0x6;
  439. else if (fint > 1750000 && fint <= 2100000)
  440. f = 0x7;
  441. else if (fint > 7500000 && fint <= 10000000)
  442. f = 0xB;
  443. else if (fint > 10000000 && fint <= 12500000)
  444. f = 0xC;
  445. else if (fint > 12500000 && fint <= 15000000)
  446. f = 0xD;
  447. else if (fint > 15000000 && fint <= 17500000)
  448. f = 0xE;
  449. else if (fint > 17500000 && fint <= 21000000)
  450. f = 0xF;
  451. else
  452. pr_debug("clock: unknown freqsel setting for %d\n", n);
  453. return f;
  454. }
  455. /* Non-CORE DPLL (e.g., DPLLs that do not control SDRC) clock functions */
  456. /*
  457. * _omap3_noncore_dpll_lock - instruct a DPLL to lock and wait for readiness
  458. * @clk: pointer to a DPLL struct clk
  459. *
  460. * Instructs a non-CORE DPLL to lock. Waits for the DPLL to report
  461. * readiness before returning. Will save and restore the DPLL's
  462. * autoidle state across the enable, per the CDP code. If the DPLL
  463. * locked successfully, return 0; if the DPLL did not lock in the time
  464. * allotted, or DPLL3 was passed in, return -EINVAL.
  465. */
  466. static int _omap3_noncore_dpll_lock(struct clk *clk)
  467. {
  468. u8 ai;
  469. int r;
  470. if (clk == &dpll3_ck)
  471. return -EINVAL;
  472. pr_debug("clock: locking DPLL %s\n", clk->name);
  473. ai = omap3_dpll_autoidle_read(clk);
  474. omap3_dpll_deny_idle(clk);
  475. _omap3_dpll_write_clken(clk, DPLL_LOCKED);
  476. r = _omap3_wait_dpll_status(clk, 1);
  477. if (ai)
  478. omap3_dpll_allow_idle(clk);
  479. return r;
  480. }
  481. /*
  482. * _omap3_noncore_dpll_bypass - instruct a DPLL to bypass and wait for readiness
  483. * @clk: pointer to a DPLL struct clk
  484. *
  485. * Instructs a non-CORE DPLL to enter low-power bypass mode. In
  486. * bypass mode, the DPLL's rate is set equal to its parent clock's
  487. * rate. Waits for the DPLL to report readiness before returning.
  488. * Will save and restore the DPLL's autoidle state across the enable,
  489. * per the CDP code. If the DPLL entered bypass mode successfully,
  490. * return 0; if the DPLL did not enter bypass in the time allotted, or
  491. * DPLL3 was passed in, or the DPLL does not support low-power bypass,
  492. * return -EINVAL.
  493. */
  494. static int _omap3_noncore_dpll_bypass(struct clk *clk)
  495. {
  496. int r;
  497. u8 ai;
  498. if (clk == &dpll3_ck)
  499. return -EINVAL;
  500. if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_BYPASS)))
  501. return -EINVAL;
  502. pr_debug("clock: configuring DPLL %s for low-power bypass\n",
  503. clk->name);
  504. ai = omap3_dpll_autoidle_read(clk);
  505. _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_BYPASS);
  506. r = _omap3_wait_dpll_status(clk, 0);
  507. if (ai)
  508. omap3_dpll_allow_idle(clk);
  509. else
  510. omap3_dpll_deny_idle(clk);
  511. return r;
  512. }
  513. /*
  514. * _omap3_noncore_dpll_stop - instruct a DPLL to stop
  515. * @clk: pointer to a DPLL struct clk
  516. *
  517. * Instructs a non-CORE DPLL to enter low-power stop. Will save and
  518. * restore the DPLL's autoidle state across the stop, per the CDP
  519. * code. If DPLL3 was passed in, or the DPLL does not support
  520. * low-power stop, return -EINVAL; otherwise, return 0.
  521. */
  522. static int _omap3_noncore_dpll_stop(struct clk *clk)
  523. {
  524. u8 ai;
  525. if (clk == &dpll3_ck)
  526. return -EINVAL;
  527. if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_STOP)))
  528. return -EINVAL;
  529. pr_debug("clock: stopping DPLL %s\n", clk->name);
  530. ai = omap3_dpll_autoidle_read(clk);
  531. _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_STOP);
  532. if (ai)
  533. omap3_dpll_allow_idle(clk);
  534. else
  535. omap3_dpll_deny_idle(clk);
  536. return 0;
  537. }
  538. /**
  539. * omap3_noncore_dpll_enable - instruct a DPLL to enter bypass or lock mode
  540. * @clk: pointer to a DPLL struct clk
  541. *
  542. * Instructs a non-CORE DPLL to enable, e.g., to enter bypass or lock.
  543. * The choice of modes depends on the DPLL's programmed rate: if it is
  544. * the same as the DPLL's parent clock, it will enter bypass;
  545. * otherwise, it will enter lock. This code will wait for the DPLL to
  546. * indicate readiness before returning, unless the DPLL takes too long
  547. * to enter the target state. Intended to be used as the struct clk's
  548. * enable function. If DPLL3 was passed in, or the DPLL does not
  549. * support low-power stop, or if the DPLL took too long to enter
  550. * bypass or lock, return -EINVAL; otherwise, return 0.
  551. */
  552. static int omap3_noncore_dpll_enable(struct clk *clk)
  553. {
  554. int r;
  555. struct dpll_data *dd;
  556. if (clk == &dpll3_ck)
  557. return -EINVAL;
  558. dd = clk->dpll_data;
  559. if (!dd)
  560. return -EINVAL;
  561. if (clk->rate == dd->clk_bypass->rate) {
  562. WARN_ON(clk->parent != dd->clk_bypass);
  563. r = _omap3_noncore_dpll_bypass(clk);
  564. } else {
  565. WARN_ON(clk->parent != dd->clk_ref);
  566. r = _omap3_noncore_dpll_lock(clk);
  567. }
  568. /* FIXME: this is dubious - if clk->rate has changed, what about propagating? */
  569. if (!r)
  570. clk->rate = omap2_get_dpll_rate(clk);
  571. return r;
  572. }
  573. /**
  574. * omap3_noncore_dpll_enable - instruct a DPLL to enter bypass or lock mode
  575. * @clk: pointer to a DPLL struct clk
  576. *
  577. * Instructs a non-CORE DPLL to enable, e.g., to enter bypass or lock.
  578. * The choice of modes depends on the DPLL's programmed rate: if it is
  579. * the same as the DPLL's parent clock, it will enter bypass;
  580. * otherwise, it will enter lock. This code will wait for the DPLL to
  581. * indicate readiness before returning, unless the DPLL takes too long
  582. * to enter the target state. Intended to be used as the struct clk's
  583. * enable function. If DPLL3 was passed in, or the DPLL does not
  584. * support low-power stop, or if the DPLL took too long to enter
  585. * bypass or lock, return -EINVAL; otherwise, return 0.
  586. */
  587. static void omap3_noncore_dpll_disable(struct clk *clk)
  588. {
  589. if (clk == &dpll3_ck)
  590. return;
  591. _omap3_noncore_dpll_stop(clk);
  592. }
  593. /* Non-CORE DPLL rate set code */
  594. /*
  595. * omap3_noncore_dpll_program - set non-core DPLL M,N values directly
  596. * @clk: struct clk * of DPLL to set
  597. * @m: DPLL multiplier to set
  598. * @n: DPLL divider to set
  599. * @freqsel: FREQSEL value to set
  600. *
  601. * Program the DPLL with the supplied M, N values, and wait for the DPLL to
  602. * lock.. Returns -EINVAL upon error, or 0 upon success.
  603. */
  604. static int omap3_noncore_dpll_program(struct clk *clk, u16 m, u8 n, u16 freqsel)
  605. {
  606. struct dpll_data *dd = clk->dpll_data;
  607. u32 v;
  608. /* 3430 ES2 TRM: 4.7.6.9 DPLL Programming Sequence */
  609. _omap3_noncore_dpll_bypass(clk);
  610. /* Set jitter correction */
  611. v = __raw_readl(dd->control_reg);
  612. v &= ~dd->freqsel_mask;
  613. v |= freqsel << __ffs(dd->freqsel_mask);
  614. __raw_writel(v, dd->control_reg);
  615. /* Set DPLL multiplier, divider */
  616. v = __raw_readl(dd->mult_div1_reg);
  617. v &= ~(dd->mult_mask | dd->div1_mask);
  618. v |= m << __ffs(dd->mult_mask);
  619. v |= (n - 1) << __ffs(dd->div1_mask);
  620. __raw_writel(v, dd->mult_div1_reg);
  621. /* We let the clock framework set the other output dividers later */
  622. /* REVISIT: Set ramp-up delay? */
  623. _omap3_noncore_dpll_lock(clk);
  624. return 0;
  625. }
  626. /**
  627. * omap3_noncore_dpll_set_rate - set non-core DPLL rate
  628. * @clk: struct clk * of DPLL to set
  629. * @rate: rounded target rate
  630. *
  631. * Set the DPLL CLKOUT to the target rate. If the DPLL can enter
  632. * low-power bypass, and the target rate is the bypass source clock
  633. * rate, then configure the DPLL for bypass. Otherwise, round the
  634. * target rate if it hasn't been done already, then program and lock
  635. * the DPLL. Returns -EINVAL upon error, or 0 upon success.
  636. */
  637. static int omap3_noncore_dpll_set_rate(struct clk *clk, unsigned long rate)
  638. {
  639. struct clk *new_parent = NULL;
  640. u16 freqsel;
  641. struct dpll_data *dd;
  642. int ret;
  643. if (!clk || !rate)
  644. return -EINVAL;
  645. dd = clk->dpll_data;
  646. if (!dd)
  647. return -EINVAL;
  648. if (rate == omap2_get_dpll_rate(clk))
  649. return 0;
  650. /*
  651. * Ensure both the bypass and ref clocks are enabled prior to
  652. * doing anything; we need the bypass clock running to reprogram
  653. * the DPLL.
  654. */
  655. omap2_clk_enable(dd->clk_bypass);
  656. omap2_clk_enable(dd->clk_ref);
  657. if (dd->clk_bypass->rate == rate &&
  658. (clk->dpll_data->modes & (1 << DPLL_LOW_POWER_BYPASS))) {
  659. pr_debug("clock: %s: set rate: entering bypass.\n", clk->name);
  660. ret = _omap3_noncore_dpll_bypass(clk);
  661. if (!ret)
  662. new_parent = dd->clk_bypass;
  663. } else {
  664. if (dd->last_rounded_rate != rate)
  665. omap2_dpll_round_rate(clk, rate);
  666. if (dd->last_rounded_rate == 0)
  667. return -EINVAL;
  668. freqsel = _omap3_dpll_compute_freqsel(clk, dd->last_rounded_n);
  669. if (!freqsel)
  670. WARN_ON(1);
  671. pr_debug("clock: %s: set rate: locking rate to %lu.\n",
  672. clk->name, rate);
  673. ret = omap3_noncore_dpll_program(clk, dd->last_rounded_m,
  674. dd->last_rounded_n, freqsel);
  675. if (!ret)
  676. new_parent = dd->clk_ref;
  677. }
  678. if (!ret) {
  679. /*
  680. * Switch the parent clock in the heirarchy, and make sure
  681. * that the new parent's usecount is correct. Note: we
  682. * enable the new parent before disabling the old to avoid
  683. * any unnecessary hardware disable->enable transitions.
  684. */
  685. if (clk->usecount) {
  686. omap2_clk_enable(new_parent);
  687. omap2_clk_disable(clk->parent);
  688. }
  689. clk_reparent(clk, new_parent);
  690. clk->rate = rate;
  691. }
  692. omap2_clk_disable(dd->clk_ref);
  693. omap2_clk_disable(dd->clk_bypass);
  694. return 0;
  695. }
  696. static int omap3_dpll4_set_rate(struct clk *clk, unsigned long rate)
  697. {
  698. /*
  699. * According to the 12-5 CDP code from TI, "Limitation 2.5"
  700. * on 3430ES1 prevents us from changing DPLL multipliers or dividers
  701. * on DPLL4.
  702. */
  703. if (omap_rev() == OMAP3430_REV_ES1_0) {
  704. printk(KERN_ERR "clock: DPLL4 cannot change rate due to "
  705. "silicon 'Limitation 2.5' on 3430ES1.\n");
  706. return -EINVAL;
  707. }
  708. return omap3_noncore_dpll_set_rate(clk, rate);
  709. }
  710. /*
  711. * CORE DPLL (DPLL3) rate programming functions
  712. *
  713. * These call into SRAM code to do the actual CM writes, since the SDRAM
  714. * is clocked from DPLL3.
  715. */
  716. /**
  717. * omap3_core_dpll_m2_set_rate - set CORE DPLL M2 divider
  718. * @clk: struct clk * of DPLL to set
  719. * @rate: rounded target rate
  720. *
  721. * Program the DPLL M2 divider with the rounded target rate. Returns
  722. * -EINVAL upon error, or 0 upon success.
  723. */
  724. static int omap3_core_dpll_m2_set_rate(struct clk *clk, unsigned long rate)
  725. {
  726. u32 new_div = 0;
  727. u32 unlock_dll = 0;
  728. u32 c;
  729. unsigned long validrate, sdrcrate, mpurate;
  730. struct omap_sdrc_params *sdrc_cs0;
  731. struct omap_sdrc_params *sdrc_cs1;
  732. int ret;
  733. if (!clk || !rate)
  734. return -EINVAL;
  735. if (clk != &dpll3_m2_ck)
  736. return -EINVAL;
  737. validrate = omap2_clksel_round_rate_div(clk, rate, &new_div);
  738. if (validrate != rate)
  739. return -EINVAL;
  740. sdrcrate = sdrc_ick.rate;
  741. if (rate > clk->rate)
  742. sdrcrate <<= ((rate / clk->rate) >> 1);
  743. else
  744. sdrcrate >>= ((clk->rate / rate) >> 1);
  745. ret = omap2_sdrc_get_params(sdrcrate, &sdrc_cs0, &sdrc_cs1);
  746. if (ret)
  747. return -EINVAL;
  748. if (sdrcrate < MIN_SDRC_DLL_LOCK_FREQ) {
  749. pr_debug("clock: will unlock SDRC DLL\n");
  750. unlock_dll = 1;
  751. }
  752. /*
  753. * XXX This only needs to be done when the CPU frequency changes
  754. */
  755. mpurate = arm_fck.rate / CYCLES_PER_MHZ;
  756. c = (mpurate << SDRC_MPURATE_SCALE) >> SDRC_MPURATE_BASE_SHIFT;
  757. c += 1; /* for safety */
  758. c *= SDRC_MPURATE_LOOPS;
  759. c >>= SDRC_MPURATE_SCALE;
  760. if (c == 0)
  761. c = 1;
  762. pr_debug("clock: changing CORE DPLL rate from %lu to %lu\n", clk->rate,
  763. validrate);
  764. pr_debug("clock: SDRC CS0 timing params used:"
  765. " RFR %08x CTRLA %08x CTRLB %08x MR %08x\n",
  766. sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,
  767. sdrc_cs0->actim_ctrlb, sdrc_cs0->mr);
  768. if (sdrc_cs1)
  769. pr_debug("clock: SDRC CS1 timing params used: "
  770. " RFR %08x CTRLA %08x CTRLB %08x MR %08x\n",
  771. sdrc_cs1->rfr_ctrl, sdrc_cs1->actim_ctrla,
  772. sdrc_cs1->actim_ctrlb, sdrc_cs1->mr);
  773. if (sdrc_cs1)
  774. omap3_configure_core_dpll(
  775. new_div, unlock_dll, c, rate > clk->rate,
  776. sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,
  777. sdrc_cs0->actim_ctrlb, sdrc_cs0->mr,
  778. sdrc_cs1->rfr_ctrl, sdrc_cs1->actim_ctrla,
  779. sdrc_cs1->actim_ctrlb, sdrc_cs1->mr);
  780. else
  781. omap3_configure_core_dpll(
  782. new_div, unlock_dll, c, rate > clk->rate,
  783. sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,
  784. sdrc_cs0->actim_ctrlb, sdrc_cs0->mr,
  785. 0, 0, 0, 0);
  786. return 0;
  787. }
  788. static const struct clkops clkops_noncore_dpll_ops = {
  789. .enable = &omap3_noncore_dpll_enable,
  790. .disable = &omap3_noncore_dpll_disable,
  791. };
  792. /* DPLL autoidle read/set code */
  793. /**
  794. * omap3_dpll_autoidle_read - read a DPLL's autoidle bits
  795. * @clk: struct clk * of the DPLL to read
  796. *
  797. * Return the DPLL's autoidle bits, shifted down to bit 0. Returns
  798. * -EINVAL if passed a null pointer or if the struct clk does not
  799. * appear to refer to a DPLL.
  800. */
  801. static u32 omap3_dpll_autoidle_read(struct clk *clk)
  802. {
  803. const struct dpll_data *dd;
  804. u32 v;
  805. if (!clk || !clk->dpll_data)
  806. return -EINVAL;
  807. dd = clk->dpll_data;
  808. v = __raw_readl(dd->autoidle_reg);
  809. v &= dd->autoidle_mask;
  810. v >>= __ffs(dd->autoidle_mask);
  811. return v;
  812. }
  813. /**
  814. * omap3_dpll_allow_idle - enable DPLL autoidle bits
  815. * @clk: struct clk * of the DPLL to operate on
  816. *
  817. * Enable DPLL automatic idle control. This automatic idle mode
  818. * switching takes effect only when the DPLL is locked, at least on
  819. * OMAP3430. The DPLL will enter low-power stop when its downstream
  820. * clocks are gated. No return value.
  821. */
  822. static void omap3_dpll_allow_idle(struct clk *clk)
  823. {
  824. const struct dpll_data *dd;
  825. u32 v;
  826. if (!clk || !clk->dpll_data)
  827. return;
  828. dd = clk->dpll_data;
  829. /*
  830. * REVISIT: CORE DPLL can optionally enter low-power bypass
  831. * by writing 0x5 instead of 0x1. Add some mechanism to
  832. * optionally enter this mode.
  833. */
  834. v = __raw_readl(dd->autoidle_reg);
  835. v &= ~dd->autoidle_mask;
  836. v |= DPLL_AUTOIDLE_LOW_POWER_STOP << __ffs(dd->autoidle_mask);
  837. __raw_writel(v, dd->autoidle_reg);
  838. }
  839. /**
  840. * omap3_dpll_deny_idle - prevent DPLL from automatically idling
  841. * @clk: struct clk * of the DPLL to operate on
  842. *
  843. * Disable DPLL automatic idle control. No return value.
  844. */
  845. static void omap3_dpll_deny_idle(struct clk *clk)
  846. {
  847. const struct dpll_data *dd;
  848. u32 v;
  849. if (!clk || !clk->dpll_data)
  850. return;
  851. dd = clk->dpll_data;
  852. v = __raw_readl(dd->autoidle_reg);
  853. v &= ~dd->autoidle_mask;
  854. v |= DPLL_AUTOIDLE_DISABLE << __ffs(dd->autoidle_mask);
  855. __raw_writel(v, dd->autoidle_reg);
  856. }
  857. /* Clock control for DPLL outputs */
  858. /**
  859. * omap3_clkoutx2_recalc - recalculate DPLL X2 output virtual clock rate
  860. * @clk: DPLL output struct clk
  861. *
  862. * Using parent clock DPLL data, look up DPLL state. If locked, set our
  863. * rate to the dpll_clk * 2; otherwise, just use dpll_clk.
  864. */
  865. static unsigned long omap3_clkoutx2_recalc(struct clk *clk)
  866. {
  867. const struct dpll_data *dd;
  868. unsigned long rate;
  869. u32 v;
  870. struct clk *pclk;
  871. /* Walk up the parents of clk, looking for a DPLL */
  872. pclk = clk->parent;
  873. while (pclk && !pclk->dpll_data)
  874. pclk = pclk->parent;
  875. /* clk does not have a DPLL as a parent? */
  876. WARN_ON(!pclk);
  877. dd = pclk->dpll_data;
  878. WARN_ON(!dd->enable_mask);
  879. v = __raw_readl(dd->control_reg) & dd->enable_mask;
  880. v >>= __ffs(dd->enable_mask);
  881. if (v != OMAP3XXX_EN_DPLL_LOCKED)
  882. rate = clk->parent->rate;
  883. else
  884. rate = clk->parent->rate * 2;
  885. return rate;
  886. }
  887. /* Common clock code */
  888. /*
  889. * As it is structured now, this will prevent an OMAP2/3 multiboot
  890. * kernel from compiling. This will need further attention.
  891. */
  892. #if defined(CONFIG_ARCH_OMAP3)
  893. static struct clk_functions omap2_clk_functions = {
  894. .clk_enable = omap2_clk_enable,
  895. .clk_disable = omap2_clk_disable,
  896. .clk_round_rate = omap2_clk_round_rate,
  897. .clk_set_rate = omap2_clk_set_rate,
  898. .clk_set_parent = omap2_clk_set_parent,
  899. .clk_disable_unused = omap2_clk_disable_unused,
  900. };
  901. /*
  902. * Set clocks for bypass mode for reboot to work.
  903. */
  904. void omap2_clk_prepare_for_reboot(void)
  905. {
  906. /* REVISIT: Not ready for 343x */
  907. #if 0
  908. u32 rate;
  909. if (vclk == NULL || sclk == NULL)
  910. return;
  911. rate = clk_get_rate(sclk);
  912. clk_set_rate(vclk, rate);
  913. #endif
  914. }
  915. /* REVISIT: Move this init stuff out into clock.c */
  916. /*
  917. * Switch the MPU rate if specified on cmdline.
  918. * We cannot do this early until cmdline is parsed.
  919. */
  920. static int __init omap2_clk_arch_init(void)
  921. {
  922. if (!mpurate)
  923. return -EINVAL;
  924. /* REVISIT: not yet ready for 343x */
  925. #if 0
  926. if (clk_set_rate(&virt_prcm_set, mpurate))
  927. printk(KERN_ERR "Could not find matching MPU rate\n");
  928. #endif
  929. recalculate_root_clocks();
  930. printk(KERN_INFO "Switched to new clocking rate (Crystal/DPLL3/MPU): "
  931. "%ld.%01ld/%ld/%ld MHz\n",
  932. (osc_sys_ck.rate / 1000000), (osc_sys_ck.rate / 100000) % 10,
  933. (core_ck.rate / 1000000), (dpll1_fck.rate / 1000000)) ;
  934. return 0;
  935. }
  936. arch_initcall(omap2_clk_arch_init);
  937. int __init omap2_clk_init(void)
  938. {
  939. /* struct prcm_config *prcm; */
  940. struct omap_clk *c;
  941. /* u32 clkrate; */
  942. u32 cpu_clkflg;
  943. if (cpu_is_omap34xx()) {
  944. cpu_mask = RATE_IN_343X;
  945. cpu_clkflg = CK_343X;
  946. /*
  947. * Update this if there are further clock changes between ES2
  948. * and production parts
  949. */
  950. if (omap_rev() == OMAP3430_REV_ES1_0) {
  951. /* No 3430ES1-only rates exist, so no RATE_IN_3430ES1 */
  952. cpu_clkflg |= CK_3430ES1;
  953. } else {
  954. cpu_mask |= RATE_IN_3430ES2;
  955. cpu_clkflg |= CK_3430ES2;
  956. }
  957. }
  958. clk_init(&omap2_clk_functions);
  959. for (c = omap34xx_clks; c < omap34xx_clks + ARRAY_SIZE(omap34xx_clks); c++)
  960. clk_preinit(c->lk.clk);
  961. for (c = omap34xx_clks; c < omap34xx_clks + ARRAY_SIZE(omap34xx_clks); c++)
  962. if (c->cpu & cpu_clkflg) {
  963. clkdev_add(&c->lk);
  964. clk_register(c->lk.clk);
  965. omap2_init_clk_clkdm(c->lk.clk);
  966. }
  967. /* REVISIT: Not yet ready for OMAP3 */
  968. #if 0
  969. /* Check the MPU rate set by bootloader */
  970. clkrate = omap2_get_dpll_rate_24xx(&dpll_ck);
  971. for (prcm = rate_table; prcm->mpu_speed; prcm++) {
  972. if (!(prcm->flags & cpu_mask))
  973. continue;
  974. if (prcm->xtal_speed != sys_ck.rate)
  975. continue;
  976. if (prcm->dpll_speed <= clkrate)
  977. break;
  978. }
  979. curr_prcm_set = prcm;
  980. #endif
  981. recalculate_root_clocks();
  982. printk(KERN_INFO "Clocking rate (Crystal/DPLL/ARM core): "
  983. "%ld.%01ld/%ld/%ld MHz\n",
  984. (osc_sys_ck.rate / 1000000), (osc_sys_ck.rate / 100000) % 10,
  985. (core_ck.rate / 1000000), (arm_fck.rate / 1000000));
  986. /*
  987. * Only enable those clocks we will need, let the drivers
  988. * enable other clocks as necessary
  989. */
  990. clk_enable_init_clocks();
  991. /* Avoid sleeping during omap2_clk_prepare_for_reboot() */
  992. /* REVISIT: not yet ready for 343x */
  993. #if 0
  994. vclk = clk_get(NULL, "virt_prcm_set");
  995. sclk = clk_get(NULL, "sys_ck");
  996. #endif
  997. return 0;
  998. }
  999. #endif