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