cminst44xx.c 11 KB

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