cm3xxx.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * OMAP3xxx CM module functions
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Copyright (C) 2008-2010, 2012 Texas Instruments, Inc.
  6. * Paul Walmsley
  7. * Rajendra Nayak <rnayak@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/delay.h>
  16. #include <linux/errno.h>
  17. #include <linux/err.h>
  18. #include <linux/io.h>
  19. #include "prm2xxx_3xxx.h"
  20. #include "cm.h"
  21. #include "cm3xxx.h"
  22. #include "cm-regbits-34xx.h"
  23. #include "clockdomain.h"
  24. static const u8 omap3xxx_cm_idlest_offs[] = {
  25. CM_IDLEST1, CM_IDLEST2, OMAP2430_CM_IDLEST3
  26. };
  27. /*
  28. *
  29. */
  30. static void _write_clktrctrl(u8 c, s16 module, u32 mask)
  31. {
  32. u32 v;
  33. v = omap2_cm_read_mod_reg(module, OMAP2_CM_CLKSTCTRL);
  34. v &= ~mask;
  35. v |= c << __ffs(mask);
  36. omap2_cm_write_mod_reg(v, module, OMAP2_CM_CLKSTCTRL);
  37. }
  38. static bool omap3xxx_cm_is_clkdm_in_hwsup(s16 module, u32 mask)
  39. {
  40. u32 v;
  41. v = omap2_cm_read_mod_reg(module, OMAP2_CM_CLKSTCTRL);
  42. v &= mask;
  43. v >>= __ffs(mask);
  44. return (v == OMAP34XX_CLKSTCTRL_ENABLE_AUTO) ? 1 : 0;
  45. }
  46. static void omap3xxx_cm_clkdm_enable_hwsup(s16 module, u32 mask)
  47. {
  48. _write_clktrctrl(OMAP34XX_CLKSTCTRL_ENABLE_AUTO, module, mask);
  49. }
  50. static void omap3xxx_cm_clkdm_disable_hwsup(s16 module, u32 mask)
  51. {
  52. _write_clktrctrl(OMAP34XX_CLKSTCTRL_DISABLE_AUTO, module, mask);
  53. }
  54. static void omap3xxx_cm_clkdm_force_sleep(s16 module, u32 mask)
  55. {
  56. _write_clktrctrl(OMAP34XX_CLKSTCTRL_FORCE_SLEEP, module, mask);
  57. }
  58. static void omap3xxx_cm_clkdm_force_wakeup(s16 module, u32 mask)
  59. {
  60. _write_clktrctrl(OMAP34XX_CLKSTCTRL_FORCE_WAKEUP, module, mask);
  61. }
  62. /*
  63. *
  64. */
  65. /**
  66. * omap3xxx_cm_wait_module_ready - wait for a module to leave idle or standby
  67. * @part: PRCM partition, ignored for OMAP3
  68. * @prcm_mod: PRCM module offset
  69. * @idlest_id: CM_IDLESTx register ID (i.e., x = 1, 2, 3)
  70. * @idlest_shift: shift of the bit in the CM_IDLEST* register to check
  71. *
  72. * Wait for the PRCM to indicate that the module identified by
  73. * (@prcm_mod, @idlest_id, @idlest_shift) is clocked. Return 0 upon
  74. * success or -EBUSY if the module doesn't enable in time.
  75. */
  76. static int omap3xxx_cm_wait_module_ready(u8 part, s16 prcm_mod, u16 idlest_id,
  77. u8 idlest_shift)
  78. {
  79. int ena = 0, i = 0;
  80. u8 cm_idlest_reg;
  81. u32 mask;
  82. if (!idlest_id || (idlest_id > ARRAY_SIZE(omap3xxx_cm_idlest_offs)))
  83. return -EINVAL;
  84. cm_idlest_reg = omap3xxx_cm_idlest_offs[idlest_id - 1];
  85. mask = 1 << idlest_shift;
  86. ena = 0;
  87. omap_test_timeout(((omap2_cm_read_mod_reg(prcm_mod, cm_idlest_reg) &
  88. mask) == ena), MAX_MODULE_READY_TIME, i);
  89. return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
  90. }
  91. /**
  92. * omap3xxx_cm_split_idlest_reg - split CM_IDLEST reg addr into its components
  93. * @idlest_reg: CM_IDLEST* virtual address
  94. * @prcm_inst: pointer to an s16 to return the PRCM instance offset
  95. * @idlest_reg_id: pointer to a u8 to return the CM_IDLESTx register ID
  96. *
  97. * XXX This function is only needed until absolute register addresses are
  98. * removed from the OMAP struct clk records.
  99. */
  100. static int omap3xxx_cm_split_idlest_reg(void __iomem *idlest_reg,
  101. s16 *prcm_inst,
  102. u8 *idlest_reg_id)
  103. {
  104. unsigned long offs;
  105. u8 idlest_offs;
  106. int i;
  107. if (idlest_reg < (cm_base + OMAP3430_IVA2_MOD) ||
  108. idlest_reg > (cm_base + 0x1ffff))
  109. return -EINVAL;
  110. idlest_offs = (unsigned long)idlest_reg & 0xff;
  111. for (i = 0; i < ARRAY_SIZE(omap3xxx_cm_idlest_offs); i++) {
  112. if (idlest_offs == omap3xxx_cm_idlest_offs[i]) {
  113. *idlest_reg_id = i + 1;
  114. break;
  115. }
  116. }
  117. if (i == ARRAY_SIZE(omap3xxx_cm_idlest_offs))
  118. return -EINVAL;
  119. offs = idlest_reg - cm_base;
  120. offs &= 0xff00;
  121. *prcm_inst = offs;
  122. return 0;
  123. }
  124. /* Clockdomain low-level operations */
  125. static int omap3xxx_clkdm_add_sleepdep(struct clockdomain *clkdm1,
  126. struct clockdomain *clkdm2)
  127. {
  128. omap2_cm_set_mod_reg_bits((1 << clkdm2->dep_bit),
  129. clkdm1->pwrdm.ptr->prcm_offs,
  130. OMAP3430_CM_SLEEPDEP);
  131. return 0;
  132. }
  133. static int omap3xxx_clkdm_del_sleepdep(struct clockdomain *clkdm1,
  134. struct clockdomain *clkdm2)
  135. {
  136. omap2_cm_clear_mod_reg_bits((1 << clkdm2->dep_bit),
  137. clkdm1->pwrdm.ptr->prcm_offs,
  138. OMAP3430_CM_SLEEPDEP);
  139. return 0;
  140. }
  141. static int omap3xxx_clkdm_read_sleepdep(struct clockdomain *clkdm1,
  142. struct clockdomain *clkdm2)
  143. {
  144. return omap2_cm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs,
  145. OMAP3430_CM_SLEEPDEP,
  146. (1 << clkdm2->dep_bit));
  147. }
  148. static int omap3xxx_clkdm_clear_all_sleepdeps(struct clockdomain *clkdm)
  149. {
  150. struct clkdm_dep *cd;
  151. u32 mask = 0;
  152. for (cd = clkdm->sleepdep_srcs; cd && cd->clkdm_name; cd++) {
  153. if (!cd->clkdm)
  154. continue; /* only happens if data is erroneous */
  155. mask |= 1 << cd->clkdm->dep_bit;
  156. cd->sleepdep_usecount = 0;
  157. }
  158. omap2_cm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs,
  159. OMAP3430_CM_SLEEPDEP);
  160. return 0;
  161. }
  162. static int omap3xxx_clkdm_sleep(struct clockdomain *clkdm)
  163. {
  164. omap3xxx_cm_clkdm_force_sleep(clkdm->pwrdm.ptr->prcm_offs,
  165. clkdm->clktrctrl_mask);
  166. return 0;
  167. }
  168. static int omap3xxx_clkdm_wakeup(struct clockdomain *clkdm)
  169. {
  170. omap3xxx_cm_clkdm_force_wakeup(clkdm->pwrdm.ptr->prcm_offs,
  171. clkdm->clktrctrl_mask);
  172. return 0;
  173. }
  174. static void omap3xxx_clkdm_allow_idle(struct clockdomain *clkdm)
  175. {
  176. if (clkdm->usecount > 0)
  177. clkdm_add_autodeps(clkdm);
  178. omap3xxx_cm_clkdm_enable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
  179. clkdm->clktrctrl_mask);
  180. }
  181. static void omap3xxx_clkdm_deny_idle(struct clockdomain *clkdm)
  182. {
  183. omap3xxx_cm_clkdm_disable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
  184. clkdm->clktrctrl_mask);
  185. if (clkdm->usecount > 0)
  186. clkdm_del_autodeps(clkdm);
  187. }
  188. static int omap3xxx_clkdm_clk_enable(struct clockdomain *clkdm)
  189. {
  190. bool hwsup = false;
  191. if (!clkdm->clktrctrl_mask)
  192. return 0;
  193. /*
  194. * The CLKDM_MISSING_IDLE_REPORTING flag documentation has
  195. * more details on the unpleasant problem this is working
  196. * around
  197. */
  198. if ((clkdm->flags & CLKDM_MISSING_IDLE_REPORTING) &&
  199. (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)) {
  200. omap3xxx_clkdm_wakeup(clkdm);
  201. return 0;
  202. }
  203. hwsup = omap3xxx_cm_is_clkdm_in_hwsup(clkdm->pwrdm.ptr->prcm_offs,
  204. clkdm->clktrctrl_mask);
  205. if (hwsup) {
  206. /* Disable HW transitions when we are changing deps */
  207. omap3xxx_cm_clkdm_disable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
  208. clkdm->clktrctrl_mask);
  209. clkdm_add_autodeps(clkdm);
  210. omap3xxx_cm_clkdm_enable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
  211. clkdm->clktrctrl_mask);
  212. } else {
  213. if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
  214. omap3xxx_clkdm_wakeup(clkdm);
  215. }
  216. return 0;
  217. }
  218. static int omap3xxx_clkdm_clk_disable(struct clockdomain *clkdm)
  219. {
  220. bool hwsup = false;
  221. if (!clkdm->clktrctrl_mask)
  222. return 0;
  223. /*
  224. * The CLKDM_MISSING_IDLE_REPORTING flag documentation has
  225. * more details on the unpleasant problem this is working
  226. * around
  227. */
  228. if (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING &&
  229. !(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) {
  230. omap3xxx_cm_clkdm_enable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
  231. clkdm->clktrctrl_mask);
  232. return 0;
  233. }
  234. hwsup = omap3xxx_cm_is_clkdm_in_hwsup(clkdm->pwrdm.ptr->prcm_offs,
  235. clkdm->clktrctrl_mask);
  236. if (hwsup) {
  237. /* Disable HW transitions when we are changing deps */
  238. omap3xxx_cm_clkdm_disable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
  239. clkdm->clktrctrl_mask);
  240. clkdm_del_autodeps(clkdm);
  241. omap3xxx_cm_clkdm_enable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
  242. clkdm->clktrctrl_mask);
  243. } else {
  244. if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP)
  245. omap3xxx_clkdm_sleep(clkdm);
  246. }
  247. return 0;
  248. }
  249. struct clkdm_ops omap3_clkdm_operations = {
  250. .clkdm_add_wkdep = omap2_clkdm_add_wkdep,
  251. .clkdm_del_wkdep = omap2_clkdm_del_wkdep,
  252. .clkdm_read_wkdep = omap2_clkdm_read_wkdep,
  253. .clkdm_clear_all_wkdeps = omap2_clkdm_clear_all_wkdeps,
  254. .clkdm_add_sleepdep = omap3xxx_clkdm_add_sleepdep,
  255. .clkdm_del_sleepdep = omap3xxx_clkdm_del_sleepdep,
  256. .clkdm_read_sleepdep = omap3xxx_clkdm_read_sleepdep,
  257. .clkdm_clear_all_sleepdeps = omap3xxx_clkdm_clear_all_sleepdeps,
  258. .clkdm_sleep = omap3xxx_clkdm_sleep,
  259. .clkdm_wakeup = omap3xxx_clkdm_wakeup,
  260. .clkdm_allow_idle = omap3xxx_clkdm_allow_idle,
  261. .clkdm_deny_idle = omap3xxx_clkdm_deny_idle,
  262. .clkdm_clk_enable = omap3xxx_clkdm_clk_enable,
  263. .clkdm_clk_disable = omap3xxx_clkdm_clk_disable,
  264. };
  265. /*
  266. * Context save/restore code - OMAP3 only
  267. */
  268. struct omap3_cm_regs {
  269. u32 iva2_cm_clksel1;
  270. u32 iva2_cm_clksel2;
  271. u32 cm_sysconfig;
  272. u32 sgx_cm_clksel;
  273. u32 dss_cm_clksel;
  274. u32 cam_cm_clksel;
  275. u32 per_cm_clksel;
  276. u32 emu_cm_clksel;
  277. u32 emu_cm_clkstctrl;
  278. u32 pll_cm_autoidle;
  279. u32 pll_cm_autoidle2;
  280. u32 pll_cm_clksel4;
  281. u32 pll_cm_clksel5;
  282. u32 pll_cm_clken2;
  283. u32 cm_polctrl;
  284. u32 iva2_cm_fclken;
  285. u32 iva2_cm_clken_pll;
  286. u32 core_cm_fclken1;
  287. u32 core_cm_fclken3;
  288. u32 sgx_cm_fclken;
  289. u32 wkup_cm_fclken;
  290. u32 dss_cm_fclken;
  291. u32 cam_cm_fclken;
  292. u32 per_cm_fclken;
  293. u32 usbhost_cm_fclken;
  294. u32 core_cm_iclken1;
  295. u32 core_cm_iclken2;
  296. u32 core_cm_iclken3;
  297. u32 sgx_cm_iclken;
  298. u32 wkup_cm_iclken;
  299. u32 dss_cm_iclken;
  300. u32 cam_cm_iclken;
  301. u32 per_cm_iclken;
  302. u32 usbhost_cm_iclken;
  303. u32 iva2_cm_autoidle2;
  304. u32 mpu_cm_autoidle2;
  305. u32 iva2_cm_clkstctrl;
  306. u32 mpu_cm_clkstctrl;
  307. u32 core_cm_clkstctrl;
  308. u32 sgx_cm_clkstctrl;
  309. u32 dss_cm_clkstctrl;
  310. u32 cam_cm_clkstctrl;
  311. u32 per_cm_clkstctrl;
  312. u32 neon_cm_clkstctrl;
  313. u32 usbhost_cm_clkstctrl;
  314. u32 core_cm_autoidle1;
  315. u32 core_cm_autoidle2;
  316. u32 core_cm_autoidle3;
  317. u32 wkup_cm_autoidle;
  318. u32 dss_cm_autoidle;
  319. u32 cam_cm_autoidle;
  320. u32 per_cm_autoidle;
  321. u32 usbhost_cm_autoidle;
  322. u32 sgx_cm_sleepdep;
  323. u32 dss_cm_sleepdep;
  324. u32 cam_cm_sleepdep;
  325. u32 per_cm_sleepdep;
  326. u32 usbhost_cm_sleepdep;
  327. u32 cm_clkout_ctrl;
  328. };
  329. static struct omap3_cm_regs cm_context;
  330. void omap3_cm_save_context(void)
  331. {
  332. cm_context.iva2_cm_clksel1 =
  333. omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, CM_CLKSEL1);
  334. cm_context.iva2_cm_clksel2 =
  335. omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, CM_CLKSEL2);
  336. cm_context.cm_sysconfig =
  337. omap2_cm_read_mod_reg(OCP_MOD, OMAP3430_CM_SYSCONFIG);
  338. cm_context.sgx_cm_clksel =
  339. omap2_cm_read_mod_reg(OMAP3430ES2_SGX_MOD, CM_CLKSEL);
  340. cm_context.dss_cm_clksel =
  341. omap2_cm_read_mod_reg(OMAP3430_DSS_MOD, CM_CLKSEL);
  342. cm_context.cam_cm_clksel =
  343. omap2_cm_read_mod_reg(OMAP3430_CAM_MOD, CM_CLKSEL);
  344. cm_context.per_cm_clksel =
  345. omap2_cm_read_mod_reg(OMAP3430_PER_MOD, CM_CLKSEL);
  346. cm_context.emu_cm_clksel =
  347. omap2_cm_read_mod_reg(OMAP3430_EMU_MOD, CM_CLKSEL1);
  348. cm_context.emu_cm_clkstctrl =
  349. omap2_cm_read_mod_reg(OMAP3430_EMU_MOD, OMAP2_CM_CLKSTCTRL);
  350. /*
  351. * As per erratum i671, ROM code does not respect the PER DPLL
  352. * programming scheme if CM_AUTOIDLE_PLL.AUTO_PERIPH_DPLL == 1.
  353. * In this case, even though this register has been saved in
  354. * scratchpad contents, we need to restore AUTO_PERIPH_DPLL
  355. * by ourselves. So, we need to save it anyway.
  356. */
  357. cm_context.pll_cm_autoidle =
  358. omap2_cm_read_mod_reg(PLL_MOD, CM_AUTOIDLE);
  359. cm_context.pll_cm_autoidle2 =
  360. omap2_cm_read_mod_reg(PLL_MOD, CM_AUTOIDLE2);
  361. cm_context.pll_cm_clksel4 =
  362. omap2_cm_read_mod_reg(PLL_MOD, OMAP3430ES2_CM_CLKSEL4);
  363. cm_context.pll_cm_clksel5 =
  364. omap2_cm_read_mod_reg(PLL_MOD, OMAP3430ES2_CM_CLKSEL5);
  365. cm_context.pll_cm_clken2 =
  366. omap2_cm_read_mod_reg(PLL_MOD, OMAP3430ES2_CM_CLKEN2);
  367. cm_context.cm_polctrl =
  368. omap2_cm_read_mod_reg(OCP_MOD, OMAP3430_CM_POLCTRL);
  369. cm_context.iva2_cm_fclken =
  370. omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, CM_FCLKEN);
  371. cm_context.iva2_cm_clken_pll =
  372. omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKEN_PLL);
  373. cm_context.core_cm_fclken1 =
  374. omap2_cm_read_mod_reg(CORE_MOD, CM_FCLKEN1);
  375. cm_context.core_cm_fclken3 =
  376. omap2_cm_read_mod_reg(CORE_MOD, OMAP3430ES2_CM_FCLKEN3);
  377. cm_context.sgx_cm_fclken =
  378. omap2_cm_read_mod_reg(OMAP3430ES2_SGX_MOD, CM_FCLKEN);
  379. cm_context.wkup_cm_fclken =
  380. omap2_cm_read_mod_reg(WKUP_MOD, CM_FCLKEN);
  381. cm_context.dss_cm_fclken =
  382. omap2_cm_read_mod_reg(OMAP3430_DSS_MOD, CM_FCLKEN);
  383. cm_context.cam_cm_fclken =
  384. omap2_cm_read_mod_reg(OMAP3430_CAM_MOD, CM_FCLKEN);
  385. cm_context.per_cm_fclken =
  386. omap2_cm_read_mod_reg(OMAP3430_PER_MOD, CM_FCLKEN);
  387. cm_context.usbhost_cm_fclken =
  388. omap2_cm_read_mod_reg(OMAP3430ES2_USBHOST_MOD, CM_FCLKEN);
  389. cm_context.core_cm_iclken1 =
  390. omap2_cm_read_mod_reg(CORE_MOD, CM_ICLKEN1);
  391. cm_context.core_cm_iclken2 =
  392. omap2_cm_read_mod_reg(CORE_MOD, CM_ICLKEN2);
  393. cm_context.core_cm_iclken3 =
  394. omap2_cm_read_mod_reg(CORE_MOD, CM_ICLKEN3);
  395. cm_context.sgx_cm_iclken =
  396. omap2_cm_read_mod_reg(OMAP3430ES2_SGX_MOD, CM_ICLKEN);
  397. cm_context.wkup_cm_iclken =
  398. omap2_cm_read_mod_reg(WKUP_MOD, CM_ICLKEN);
  399. cm_context.dss_cm_iclken =
  400. omap2_cm_read_mod_reg(OMAP3430_DSS_MOD, CM_ICLKEN);
  401. cm_context.cam_cm_iclken =
  402. omap2_cm_read_mod_reg(OMAP3430_CAM_MOD, CM_ICLKEN);
  403. cm_context.per_cm_iclken =
  404. omap2_cm_read_mod_reg(OMAP3430_PER_MOD, CM_ICLKEN);
  405. cm_context.usbhost_cm_iclken =
  406. omap2_cm_read_mod_reg(OMAP3430ES2_USBHOST_MOD, CM_ICLKEN);
  407. cm_context.iva2_cm_autoidle2 =
  408. omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, CM_AUTOIDLE2);
  409. cm_context.mpu_cm_autoidle2 =
  410. omap2_cm_read_mod_reg(MPU_MOD, CM_AUTOIDLE2);
  411. cm_context.iva2_cm_clkstctrl =
  412. omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP2_CM_CLKSTCTRL);
  413. cm_context.mpu_cm_clkstctrl =
  414. omap2_cm_read_mod_reg(MPU_MOD, OMAP2_CM_CLKSTCTRL);
  415. cm_context.core_cm_clkstctrl =
  416. omap2_cm_read_mod_reg(CORE_MOD, OMAP2_CM_CLKSTCTRL);
  417. cm_context.sgx_cm_clkstctrl =
  418. omap2_cm_read_mod_reg(OMAP3430ES2_SGX_MOD, OMAP2_CM_CLKSTCTRL);
  419. cm_context.dss_cm_clkstctrl =
  420. omap2_cm_read_mod_reg(OMAP3430_DSS_MOD, OMAP2_CM_CLKSTCTRL);
  421. cm_context.cam_cm_clkstctrl =
  422. omap2_cm_read_mod_reg(OMAP3430_CAM_MOD, OMAP2_CM_CLKSTCTRL);
  423. cm_context.per_cm_clkstctrl =
  424. omap2_cm_read_mod_reg(OMAP3430_PER_MOD, OMAP2_CM_CLKSTCTRL);
  425. cm_context.neon_cm_clkstctrl =
  426. omap2_cm_read_mod_reg(OMAP3430_NEON_MOD, OMAP2_CM_CLKSTCTRL);
  427. cm_context.usbhost_cm_clkstctrl =
  428. omap2_cm_read_mod_reg(OMAP3430ES2_USBHOST_MOD,
  429. OMAP2_CM_CLKSTCTRL);
  430. cm_context.core_cm_autoidle1 =
  431. omap2_cm_read_mod_reg(CORE_MOD, CM_AUTOIDLE1);
  432. cm_context.core_cm_autoidle2 =
  433. omap2_cm_read_mod_reg(CORE_MOD, CM_AUTOIDLE2);
  434. cm_context.core_cm_autoidle3 =
  435. omap2_cm_read_mod_reg(CORE_MOD, CM_AUTOIDLE3);
  436. cm_context.wkup_cm_autoidle =
  437. omap2_cm_read_mod_reg(WKUP_MOD, CM_AUTOIDLE);
  438. cm_context.dss_cm_autoidle =
  439. omap2_cm_read_mod_reg(OMAP3430_DSS_MOD, CM_AUTOIDLE);
  440. cm_context.cam_cm_autoidle =
  441. omap2_cm_read_mod_reg(OMAP3430_CAM_MOD, CM_AUTOIDLE);
  442. cm_context.per_cm_autoidle =
  443. omap2_cm_read_mod_reg(OMAP3430_PER_MOD, CM_AUTOIDLE);
  444. cm_context.usbhost_cm_autoidle =
  445. omap2_cm_read_mod_reg(OMAP3430ES2_USBHOST_MOD, CM_AUTOIDLE);
  446. cm_context.sgx_cm_sleepdep =
  447. omap2_cm_read_mod_reg(OMAP3430ES2_SGX_MOD,
  448. OMAP3430_CM_SLEEPDEP);
  449. cm_context.dss_cm_sleepdep =
  450. omap2_cm_read_mod_reg(OMAP3430_DSS_MOD, OMAP3430_CM_SLEEPDEP);
  451. cm_context.cam_cm_sleepdep =
  452. omap2_cm_read_mod_reg(OMAP3430_CAM_MOD, OMAP3430_CM_SLEEPDEP);
  453. cm_context.per_cm_sleepdep =
  454. omap2_cm_read_mod_reg(OMAP3430_PER_MOD, OMAP3430_CM_SLEEPDEP);
  455. cm_context.usbhost_cm_sleepdep =
  456. omap2_cm_read_mod_reg(OMAP3430ES2_USBHOST_MOD,
  457. OMAP3430_CM_SLEEPDEP);
  458. cm_context.cm_clkout_ctrl =
  459. omap2_cm_read_mod_reg(OMAP3430_CCR_MOD,
  460. OMAP3_CM_CLKOUT_CTRL_OFFSET);
  461. }
  462. void omap3_cm_restore_context(void)
  463. {
  464. omap2_cm_write_mod_reg(cm_context.iva2_cm_clksel1, OMAP3430_IVA2_MOD,
  465. CM_CLKSEL1);
  466. omap2_cm_write_mod_reg(cm_context.iva2_cm_clksel2, OMAP3430_IVA2_MOD,
  467. CM_CLKSEL2);
  468. omap2_cm_write_mod_reg(cm_context.cm_sysconfig, OCP_MOD,
  469. OMAP3430_CM_SYSCONFIG);
  470. omap2_cm_write_mod_reg(cm_context.sgx_cm_clksel, OMAP3430ES2_SGX_MOD,
  471. CM_CLKSEL);
  472. omap2_cm_write_mod_reg(cm_context.dss_cm_clksel, OMAP3430_DSS_MOD,
  473. CM_CLKSEL);
  474. omap2_cm_write_mod_reg(cm_context.cam_cm_clksel, OMAP3430_CAM_MOD,
  475. CM_CLKSEL);
  476. omap2_cm_write_mod_reg(cm_context.per_cm_clksel, OMAP3430_PER_MOD,
  477. CM_CLKSEL);
  478. omap2_cm_write_mod_reg(cm_context.emu_cm_clksel, OMAP3430_EMU_MOD,
  479. CM_CLKSEL1);
  480. omap2_cm_write_mod_reg(cm_context.emu_cm_clkstctrl, OMAP3430_EMU_MOD,
  481. OMAP2_CM_CLKSTCTRL);
  482. /*
  483. * As per erratum i671, ROM code does not respect the PER DPLL
  484. * programming scheme if CM_AUTOIDLE_PLL.AUTO_PERIPH_DPLL == 1.
  485. * In this case, we need to restore AUTO_PERIPH_DPLL by ourselves.
  486. */
  487. omap2_cm_write_mod_reg(cm_context.pll_cm_autoidle, PLL_MOD,
  488. CM_AUTOIDLE);
  489. omap2_cm_write_mod_reg(cm_context.pll_cm_autoidle2, PLL_MOD,
  490. CM_AUTOIDLE2);
  491. omap2_cm_write_mod_reg(cm_context.pll_cm_clksel4, PLL_MOD,
  492. OMAP3430ES2_CM_CLKSEL4);
  493. omap2_cm_write_mod_reg(cm_context.pll_cm_clksel5, PLL_MOD,
  494. OMAP3430ES2_CM_CLKSEL5);
  495. omap2_cm_write_mod_reg(cm_context.pll_cm_clken2, PLL_MOD,
  496. OMAP3430ES2_CM_CLKEN2);
  497. omap2_cm_write_mod_reg(cm_context.cm_polctrl, OCP_MOD,
  498. OMAP3430_CM_POLCTRL);
  499. omap2_cm_write_mod_reg(cm_context.iva2_cm_fclken, OMAP3430_IVA2_MOD,
  500. CM_FCLKEN);
  501. omap2_cm_write_mod_reg(cm_context.iva2_cm_clken_pll, OMAP3430_IVA2_MOD,
  502. OMAP3430_CM_CLKEN_PLL);
  503. omap2_cm_write_mod_reg(cm_context.core_cm_fclken1, CORE_MOD,
  504. CM_FCLKEN1);
  505. omap2_cm_write_mod_reg(cm_context.core_cm_fclken3, CORE_MOD,
  506. OMAP3430ES2_CM_FCLKEN3);
  507. omap2_cm_write_mod_reg(cm_context.sgx_cm_fclken, OMAP3430ES2_SGX_MOD,
  508. CM_FCLKEN);
  509. omap2_cm_write_mod_reg(cm_context.wkup_cm_fclken, WKUP_MOD, CM_FCLKEN);
  510. omap2_cm_write_mod_reg(cm_context.dss_cm_fclken, OMAP3430_DSS_MOD,
  511. CM_FCLKEN);
  512. omap2_cm_write_mod_reg(cm_context.cam_cm_fclken, OMAP3430_CAM_MOD,
  513. CM_FCLKEN);
  514. omap2_cm_write_mod_reg(cm_context.per_cm_fclken, OMAP3430_PER_MOD,
  515. CM_FCLKEN);
  516. omap2_cm_write_mod_reg(cm_context.usbhost_cm_fclken,
  517. OMAP3430ES2_USBHOST_MOD, CM_FCLKEN);
  518. omap2_cm_write_mod_reg(cm_context.core_cm_iclken1, CORE_MOD,
  519. CM_ICLKEN1);
  520. omap2_cm_write_mod_reg(cm_context.core_cm_iclken2, CORE_MOD,
  521. CM_ICLKEN2);
  522. omap2_cm_write_mod_reg(cm_context.core_cm_iclken3, CORE_MOD,
  523. CM_ICLKEN3);
  524. omap2_cm_write_mod_reg(cm_context.sgx_cm_iclken, OMAP3430ES2_SGX_MOD,
  525. CM_ICLKEN);
  526. omap2_cm_write_mod_reg(cm_context.wkup_cm_iclken, WKUP_MOD, CM_ICLKEN);
  527. omap2_cm_write_mod_reg(cm_context.dss_cm_iclken, OMAP3430_DSS_MOD,
  528. CM_ICLKEN);
  529. omap2_cm_write_mod_reg(cm_context.cam_cm_iclken, OMAP3430_CAM_MOD,
  530. CM_ICLKEN);
  531. omap2_cm_write_mod_reg(cm_context.per_cm_iclken, OMAP3430_PER_MOD,
  532. CM_ICLKEN);
  533. omap2_cm_write_mod_reg(cm_context.usbhost_cm_iclken,
  534. OMAP3430ES2_USBHOST_MOD, CM_ICLKEN);
  535. omap2_cm_write_mod_reg(cm_context.iva2_cm_autoidle2, OMAP3430_IVA2_MOD,
  536. CM_AUTOIDLE2);
  537. omap2_cm_write_mod_reg(cm_context.mpu_cm_autoidle2, MPU_MOD,
  538. CM_AUTOIDLE2);
  539. omap2_cm_write_mod_reg(cm_context.iva2_cm_clkstctrl, OMAP3430_IVA2_MOD,
  540. OMAP2_CM_CLKSTCTRL);
  541. omap2_cm_write_mod_reg(cm_context.mpu_cm_clkstctrl, MPU_MOD,
  542. OMAP2_CM_CLKSTCTRL);
  543. omap2_cm_write_mod_reg(cm_context.core_cm_clkstctrl, CORE_MOD,
  544. OMAP2_CM_CLKSTCTRL);
  545. omap2_cm_write_mod_reg(cm_context.sgx_cm_clkstctrl, OMAP3430ES2_SGX_MOD,
  546. OMAP2_CM_CLKSTCTRL);
  547. omap2_cm_write_mod_reg(cm_context.dss_cm_clkstctrl, OMAP3430_DSS_MOD,
  548. OMAP2_CM_CLKSTCTRL);
  549. omap2_cm_write_mod_reg(cm_context.cam_cm_clkstctrl, OMAP3430_CAM_MOD,
  550. OMAP2_CM_CLKSTCTRL);
  551. omap2_cm_write_mod_reg(cm_context.per_cm_clkstctrl, OMAP3430_PER_MOD,
  552. OMAP2_CM_CLKSTCTRL);
  553. omap2_cm_write_mod_reg(cm_context.neon_cm_clkstctrl, OMAP3430_NEON_MOD,
  554. OMAP2_CM_CLKSTCTRL);
  555. omap2_cm_write_mod_reg(cm_context.usbhost_cm_clkstctrl,
  556. OMAP3430ES2_USBHOST_MOD, OMAP2_CM_CLKSTCTRL);
  557. omap2_cm_write_mod_reg(cm_context.core_cm_autoidle1, CORE_MOD,
  558. CM_AUTOIDLE1);
  559. omap2_cm_write_mod_reg(cm_context.core_cm_autoidle2, CORE_MOD,
  560. CM_AUTOIDLE2);
  561. omap2_cm_write_mod_reg(cm_context.core_cm_autoidle3, CORE_MOD,
  562. CM_AUTOIDLE3);
  563. omap2_cm_write_mod_reg(cm_context.wkup_cm_autoidle, WKUP_MOD,
  564. CM_AUTOIDLE);
  565. omap2_cm_write_mod_reg(cm_context.dss_cm_autoidle, OMAP3430_DSS_MOD,
  566. CM_AUTOIDLE);
  567. omap2_cm_write_mod_reg(cm_context.cam_cm_autoidle, OMAP3430_CAM_MOD,
  568. CM_AUTOIDLE);
  569. omap2_cm_write_mod_reg(cm_context.per_cm_autoidle, OMAP3430_PER_MOD,
  570. CM_AUTOIDLE);
  571. omap2_cm_write_mod_reg(cm_context.usbhost_cm_autoidle,
  572. OMAP3430ES2_USBHOST_MOD, CM_AUTOIDLE);
  573. omap2_cm_write_mod_reg(cm_context.sgx_cm_sleepdep, OMAP3430ES2_SGX_MOD,
  574. OMAP3430_CM_SLEEPDEP);
  575. omap2_cm_write_mod_reg(cm_context.dss_cm_sleepdep, OMAP3430_DSS_MOD,
  576. OMAP3430_CM_SLEEPDEP);
  577. omap2_cm_write_mod_reg(cm_context.cam_cm_sleepdep, OMAP3430_CAM_MOD,
  578. OMAP3430_CM_SLEEPDEP);
  579. omap2_cm_write_mod_reg(cm_context.per_cm_sleepdep, OMAP3430_PER_MOD,
  580. OMAP3430_CM_SLEEPDEP);
  581. omap2_cm_write_mod_reg(cm_context.usbhost_cm_sleepdep,
  582. OMAP3430ES2_USBHOST_MOD, OMAP3430_CM_SLEEPDEP);
  583. omap2_cm_write_mod_reg(cm_context.cm_clkout_ctrl, OMAP3430_CCR_MOD,
  584. OMAP3_CM_CLKOUT_CTRL_OFFSET);
  585. }
  586. void omap3_cm_save_scratchpad_contents(u32 *ptr)
  587. {
  588. *ptr++ = omap2_cm_read_mod_reg(CORE_MOD, CM_CLKSEL);
  589. *ptr++ = omap2_cm_read_mod_reg(WKUP_MOD, CM_CLKSEL);
  590. *ptr++ = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKEN);
  591. /*
  592. * As per erratum i671, ROM code does not respect the PER DPLL
  593. * programming scheme if CM_AUTOIDLE_PLL..AUTO_PERIPH_DPLL == 1.
  594. * Then, in any case, clear these bits to avoid extra latencies.
  595. */
  596. *ptr++ = omap2_cm_read_mod_reg(PLL_MOD, CM_AUTOIDLE) &
  597. ~OMAP3430_AUTO_PERIPH_DPLL_MASK;
  598. *ptr++ = omap2_cm_read_mod_reg(PLL_MOD, OMAP3430_CM_CLKSEL1_PLL);
  599. *ptr++ = omap2_cm_read_mod_reg(PLL_MOD, OMAP3430_CM_CLKSEL2_PLL);
  600. *ptr++ = omap2_cm_read_mod_reg(PLL_MOD, OMAP3430_CM_CLKSEL3);
  601. *ptr++ = omap2_cm_read_mod_reg(MPU_MOD, OMAP3430_CM_CLKEN_PLL);
  602. *ptr++ = omap2_cm_read_mod_reg(MPU_MOD, OMAP3430_CM_AUTOIDLE_PLL);
  603. *ptr++ = omap2_cm_read_mod_reg(MPU_MOD, OMAP3430_CM_CLKSEL1_PLL);
  604. *ptr++ = omap2_cm_read_mod_reg(MPU_MOD, OMAP3430_CM_CLKSEL2_PLL);
  605. }
  606. /*
  607. *
  608. */
  609. static struct cm_ll_data omap3xxx_cm_ll_data = {
  610. .split_idlest_reg = &omap3xxx_cm_split_idlest_reg,
  611. .wait_module_ready = &omap3xxx_cm_wait_module_ready,
  612. };
  613. int __init omap3xxx_cm_init(const struct omap_prcm_init_data *data)
  614. {
  615. omap2_clk_legacy_provider_init(TI_CLKM_CM, cm_base + OMAP3430_IVA2_MOD);
  616. return cm_register(&omap3xxx_cm_ll_data);
  617. }
  618. static void __exit omap3xxx_cm_exit(void)
  619. {
  620. cm_unregister(&omap3xxx_cm_ll_data);
  621. }
  622. __exitcall(omap3xxx_cm_exit);