cminst44xx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * OMAP4 CM instance functions
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Copyright (C) 2011 Texas Instruments, Inc.
  6. * Paul Walmsley
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This is needed since CM instances can be in the PRM, PRCM_MPU, CM1,
  13. * or CM2 hardware modules. For example, the EMU_CM CM instance is in
  14. * the PRM hardware module. What a mess...
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/types.h>
  18. #include <linux/errno.h>
  19. #include <linux/err.h>
  20. #include <linux/io.h>
  21. #include <plat/common.h>
  22. #include "cm.h"
  23. #include "cm1_44xx.h"
  24. #include "cm2_44xx.h"
  25. #include "cm44xx.h"
  26. #include "cminst44xx.h"
  27. #include "cm-regbits-34xx.h"
  28. #include "cm-regbits-44xx.h"
  29. #include "prcm44xx.h"
  30. #include "prm44xx.h"
  31. #include "prcm_mpu44xx.h"
  32. /*
  33. * CLKCTRL_IDLEST_*: possible values for the CM_*_CLKCTRL.IDLEST bitfield:
  34. *
  35. * 0x0 func: Module is fully functional, including OCP
  36. * 0x1 trans: Module is performing transition: wakeup, or sleep, or sleep
  37. * abortion
  38. * 0x2 idle: Module is in Idle mode (only OCP part). It is functional if
  39. * using separate functional clock
  40. * 0x3 disabled: Module is disabled and cannot be accessed
  41. *
  42. */
  43. #define CLKCTRL_IDLEST_FUNCTIONAL 0x0
  44. #define CLKCTRL_IDLEST_INTRANSITION 0x1
  45. #define CLKCTRL_IDLEST_INTERFACE_IDLE 0x2
  46. #define CLKCTRL_IDLEST_DISABLED 0x3
  47. static u32 _cm_bases[OMAP4_MAX_PRCM_PARTITIONS] = {
  48. [OMAP4430_INVALID_PRCM_PARTITION] = 0,
  49. [OMAP4430_PRM_PARTITION] = OMAP4430_PRM_BASE,
  50. [OMAP4430_CM1_PARTITION] = OMAP4430_CM1_BASE,
  51. [OMAP4430_CM2_PARTITION] = OMAP4430_CM2_BASE,
  52. [OMAP4430_SCRM_PARTITION] = 0,
  53. [OMAP4430_PRCM_MPU_PARTITION] = OMAP4430_PRCM_MPU_BASE,
  54. };
  55. /* Private functions */
  56. /**
  57. * _clkctrl_idlest - read a CM_*_CLKCTRL register; mask & shift IDLEST bitfield
  58. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  59. * @inst: CM instance register offset (*_INST macro)
  60. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  61. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  62. *
  63. * Return the IDLEST bitfield of a CM_*_CLKCTRL register, shifted down to
  64. * bit 0.
  65. */
  66. static u32 _clkctrl_idlest(u8 part, u16 inst, s16 cdoffs, u16 clkctrl_offs)
  67. {
  68. u32 v = omap4_cminst_read_inst_reg(part, inst, clkctrl_offs);
  69. v &= OMAP4430_IDLEST_MASK;
  70. v >>= OMAP4430_IDLEST_SHIFT;
  71. return v;
  72. }
  73. /**
  74. * _is_module_ready - can module registers be accessed without causing an abort?
  75. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  76. * @inst: CM instance register offset (*_INST macro)
  77. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  78. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  79. *
  80. * Returns true if the module's CM_*_CLKCTRL.IDLEST bitfield is either
  81. * *FUNCTIONAL or *INTERFACE_IDLE; false otherwise.
  82. */
  83. static bool _is_module_ready(u8 part, u16 inst, s16 cdoffs, u16 clkctrl_offs)
  84. {
  85. u32 v;
  86. v = _clkctrl_idlest(part, inst, cdoffs, clkctrl_offs);
  87. return (v == CLKCTRL_IDLEST_FUNCTIONAL ||
  88. v == CLKCTRL_IDLEST_INTERFACE_IDLE) ? true : false;
  89. }
  90. /* Public functions */
  91. /* Read a register in a CM instance */
  92. u32 omap4_cminst_read_inst_reg(u8 part, s16 inst, u16 idx)
  93. {
  94. BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
  95. part == OMAP4430_INVALID_PRCM_PARTITION ||
  96. !_cm_bases[part]);
  97. return __raw_readl(OMAP2_L4_IO_ADDRESS(_cm_bases[part] + inst + idx));
  98. }
  99. /* Write into a register in a CM instance */
  100. void omap4_cminst_write_inst_reg(u32 val, u8 part, s16 inst, u16 idx)
  101. {
  102. BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
  103. part == OMAP4430_INVALID_PRCM_PARTITION ||
  104. !_cm_bases[part]);
  105. __raw_writel(val, OMAP2_L4_IO_ADDRESS(_cm_bases[part] + inst + idx));
  106. }
  107. /* Read-modify-write a register in CM1. Caller must lock */
  108. u32 omap4_cminst_rmw_inst_reg_bits(u32 mask, u32 bits, u8 part, s16 inst,
  109. s16 idx)
  110. {
  111. u32 v;
  112. v = omap4_cminst_read_inst_reg(part, inst, idx);
  113. v &= ~mask;
  114. v |= bits;
  115. omap4_cminst_write_inst_reg(v, part, inst, idx);
  116. return v;
  117. }
  118. u32 omap4_cminst_set_inst_reg_bits(u32 bits, u8 part, s16 inst, s16 idx)
  119. {
  120. return omap4_cminst_rmw_inst_reg_bits(bits, bits, part, inst, idx);
  121. }
  122. u32 omap4_cminst_clear_inst_reg_bits(u32 bits, u8 part, s16 inst, s16 idx)
  123. {
  124. return omap4_cminst_rmw_inst_reg_bits(bits, 0x0, part, inst, idx);
  125. }
  126. u32 omap4_cminst_read_inst_reg_bits(u8 part, u16 inst, s16 idx, u32 mask)
  127. {
  128. u32 v;
  129. v = omap4_cminst_read_inst_reg(part, inst, idx);
  130. v &= mask;
  131. v >>= __ffs(mask);
  132. return v;
  133. }
  134. /*
  135. *
  136. */
  137. /**
  138. * _clktrctrl_write - write @c to a CM_CLKSTCTRL.CLKTRCTRL register bitfield
  139. * @c: CLKTRCTRL register bitfield (LSB = bit 0, i.e., unshifted)
  140. * @part: PRCM partition ID that the CM_CLKSTCTRL register exists in
  141. * @inst: CM instance register offset (*_INST macro)
  142. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  143. *
  144. * @c must be the unshifted value for CLKTRCTRL - i.e., this function
  145. * will handle the shift itself.
  146. */
  147. static void _clktrctrl_write(u8 c, u8 part, s16 inst, u16 cdoffs)
  148. {
  149. u32 v;
  150. v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  151. v &= ~OMAP4430_CLKTRCTRL_MASK;
  152. v |= c << OMAP4430_CLKTRCTRL_SHIFT;
  153. omap4_cminst_write_inst_reg(v, part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  154. }
  155. /**
  156. * omap4_cminst_is_clkdm_in_hwsup - is a clockdomain in hwsup idle mode?
  157. * @part: PRCM partition ID that the CM_CLKSTCTRL register exists in
  158. * @inst: CM instance register offset (*_INST macro)
  159. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  160. *
  161. * Returns true if the clockdomain referred to by (@part, @inst, @cdoffs)
  162. * is in hardware-supervised idle mode, or 0 otherwise.
  163. */
  164. bool omap4_cminst_is_clkdm_in_hwsup(u8 part, s16 inst, u16 cdoffs)
  165. {
  166. u32 v;
  167. v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  168. v &= OMAP4430_CLKTRCTRL_MASK;
  169. v >>= OMAP4430_CLKTRCTRL_SHIFT;
  170. return (v == OMAP34XX_CLKSTCTRL_ENABLE_AUTO) ? true : false;
  171. }
  172. /**
  173. * omap4_cminst_clkdm_enable_hwsup - put a clockdomain in hwsup-idle mode
  174. * @part: PRCM partition ID that the clockdomain registers exist in
  175. * @inst: CM instance register offset (*_INST macro)
  176. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  177. *
  178. * Put a clockdomain referred to by (@part, @inst, @cdoffs) into
  179. * hardware-supervised idle mode. No return value.
  180. */
  181. void omap4_cminst_clkdm_enable_hwsup(u8 part, s16 inst, u16 cdoffs)
  182. {
  183. _clktrctrl_write(OMAP34XX_CLKSTCTRL_ENABLE_AUTO, part, inst, cdoffs);
  184. }
  185. /**
  186. * omap4_cminst_clkdm_disable_hwsup - put a clockdomain in swsup-idle mode
  187. * @part: PRCM partition ID that the clockdomain registers exist in
  188. * @inst: CM instance register offset (*_INST macro)
  189. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  190. *
  191. * Put a clockdomain referred to by (@part, @inst, @cdoffs) into
  192. * software-supervised idle mode, i.e., controlled manually by the
  193. * Linux OMAP clockdomain code. No return value.
  194. */
  195. void omap4_cminst_clkdm_disable_hwsup(u8 part, s16 inst, u16 cdoffs)
  196. {
  197. _clktrctrl_write(OMAP34XX_CLKSTCTRL_DISABLE_AUTO, part, inst, cdoffs);
  198. }
  199. /**
  200. * omap4_cminst_clkdm_force_sleep - try to put a clockdomain into idle
  201. * @part: PRCM partition ID that the clockdomain registers exist in
  202. * @inst: CM instance register offset (*_INST macro)
  203. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  204. *
  205. * Put a clockdomain referred to by (@part, @inst, @cdoffs) into idle
  206. * No return value.
  207. */
  208. void omap4_cminst_clkdm_force_sleep(u8 part, s16 inst, u16 cdoffs)
  209. {
  210. _clktrctrl_write(OMAP34XX_CLKSTCTRL_FORCE_SLEEP, part, inst, cdoffs);
  211. }
  212. /**
  213. * omap4_cminst_clkdm_force_sleep - try to take a clockdomain out of idle
  214. * @part: PRCM partition ID that the clockdomain registers exist in
  215. * @inst: CM instance register offset (*_INST macro)
  216. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  217. *
  218. * Take a clockdomain referred to by (@part, @inst, @cdoffs) out of idle,
  219. * waking it up. No return value.
  220. */
  221. void omap4_cminst_clkdm_force_wakeup(u8 part, s16 inst, u16 cdoffs)
  222. {
  223. _clktrctrl_write(OMAP34XX_CLKSTCTRL_FORCE_WAKEUP, part, inst, cdoffs);
  224. }
  225. /*
  226. *
  227. */
  228. /**
  229. * omap4_cminst_wait_module_ready - wait for a module to be in 'func' state
  230. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  231. * @inst: CM instance register offset (*_INST macro)
  232. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  233. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  234. *
  235. * Wait for the module IDLEST to be functional. If the idle state is in any
  236. * the non functional state (trans, idle or disabled), module and thus the
  237. * sysconfig cannot be accessed and will probably lead to an "imprecise
  238. * external abort"
  239. */
  240. int omap4_cminst_wait_module_ready(u8 part, u16 inst, s16 cdoffs,
  241. u16 clkctrl_offs)
  242. {
  243. int i = 0;
  244. if (!clkctrl_offs)
  245. return 0;
  246. omap_test_timeout(_is_module_ready(part, inst, cdoffs, clkctrl_offs),
  247. MAX_MODULE_READY_TIME, i);
  248. return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
  249. }
  250. /**
  251. * omap4_cminst_wait_module_idle - wait for a module to be in 'disabled'
  252. * state
  253. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  254. * @inst: CM instance register offset (*_INST macro)
  255. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  256. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  257. *
  258. * Wait for the module IDLEST to be disabled. Some PRCM transition,
  259. * like reset assertion or parent clock de-activation must wait the
  260. * module to be fully disabled.
  261. */
  262. int omap4_cminst_wait_module_idle(u8 part, u16 inst, s16 cdoffs, u16 clkctrl_offs)
  263. {
  264. int i = 0;
  265. if (!clkctrl_offs)
  266. return 0;
  267. omap_test_timeout((_clkctrl_idlest(part, inst, cdoffs, clkctrl_offs) ==
  268. CLKCTRL_IDLEST_DISABLED),
  269. MAX_MODULE_READY_TIME, i);
  270. return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
  271. }
  272. /**
  273. * omap4_cminst_module_enable - Enable the modulemode inside CLKCTRL
  274. * @mode: Module mode (SW or HW)
  275. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  276. * @inst: CM instance register offset (*_INST macro)
  277. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  278. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  279. *
  280. * No return value.
  281. */
  282. void omap4_cminst_module_enable(u8 mode, u8 part, u16 inst, s16 cdoffs,
  283. u16 clkctrl_offs)
  284. {
  285. u32 v;
  286. v = omap4_cminst_read_inst_reg(part, inst, clkctrl_offs);
  287. v &= ~OMAP4430_MODULEMODE_MASK;
  288. v |= mode << OMAP4430_MODULEMODE_SHIFT;
  289. omap4_cminst_write_inst_reg(v, part, inst, clkctrl_offs);
  290. }
  291. /**
  292. * omap4_cminst_module_disable - Disable the module inside CLKCTRL
  293. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  294. * @inst: CM instance register offset (*_INST macro)
  295. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  296. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  297. *
  298. * No return value.
  299. */
  300. void omap4_cminst_module_disable(u8 part, u16 inst, s16 cdoffs,
  301. u16 clkctrl_offs)
  302. {
  303. u32 v;
  304. v = omap4_cminst_read_inst_reg(part, inst, clkctrl_offs);
  305. v &= ~OMAP4430_MODULEMODE_MASK;
  306. omap4_cminst_write_inst_reg(v, part, inst, clkctrl_offs);
  307. }