clock34xx.c 35 KB

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