cminst44xx.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * OMAP4 CM instance functions
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Copyright (C) 2008-2011 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. * This is needed since CM instances can be in the PRM, PRCM_MPU, CM1,
  14. * or CM2 hardware modules. For example, the EMU_CM CM instance is in
  15. * the PRM hardware module. What a mess...
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/types.h>
  19. #include <linux/errno.h>
  20. #include <linux/err.h>
  21. #include <linux/io.h>
  22. #include "iomap.h"
  23. #include "common.h"
  24. #include "clockdomain.h"
  25. #include "cm.h"
  26. #include "cm1_44xx.h"
  27. #include "cm2_44xx.h"
  28. #include "cm44xx.h"
  29. #include "cminst44xx.h"
  30. #include "cm-regbits-34xx.h"
  31. #include "cm-regbits-44xx.h"
  32. #include "prcm44xx.h"
  33. #include "prm44xx.h"
  34. #include "prcm_mpu44xx.h"
  35. #include "prcm-common.h"
  36. /*
  37. * CLKCTRL_IDLEST_*: possible values for the CM_*_CLKCTRL.IDLEST bitfield:
  38. *
  39. * 0x0 func: Module is fully functional, including OCP
  40. * 0x1 trans: Module is performing transition: wakeup, or sleep, or sleep
  41. * abortion
  42. * 0x2 idle: Module is in Idle mode (only OCP part). It is functional if
  43. * using separate functional clock
  44. * 0x3 disabled: Module is disabled and cannot be accessed
  45. *
  46. */
  47. #define CLKCTRL_IDLEST_FUNCTIONAL 0x0
  48. #define CLKCTRL_IDLEST_INTRANSITION 0x1
  49. #define CLKCTRL_IDLEST_INTERFACE_IDLE 0x2
  50. #define CLKCTRL_IDLEST_DISABLED 0x3
  51. static void __iomem *_cm_bases[OMAP4_MAX_PRCM_PARTITIONS];
  52. /**
  53. * omap_cm_base_init - Populates the cm partitions
  54. *
  55. * Populates the base addresses of the _cm_bases
  56. * array used for read/write of cm module registers.
  57. */
  58. void omap_cm_base_init(void)
  59. {
  60. _cm_bases[OMAP4430_PRM_PARTITION] = prm_base;
  61. _cm_bases[OMAP4430_CM1_PARTITION] = cm_base;
  62. _cm_bases[OMAP4430_CM2_PARTITION] = cm2_base;
  63. _cm_bases[OMAP4430_PRCM_MPU_PARTITION] = prcm_mpu_base;
  64. }
  65. /* Private functions */
  66. /**
  67. * _clkctrl_idlest - read a CM_*_CLKCTRL register; mask & shift IDLEST bitfield
  68. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  69. * @inst: CM instance register offset (*_INST macro)
  70. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  71. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  72. *
  73. * Return the IDLEST bitfield of a CM_*_CLKCTRL register, shifted down to
  74. * bit 0.
  75. */
  76. static u32 _clkctrl_idlest(u8 part, u16 inst, s16 cdoffs, u16 clkctrl_offs)
  77. {
  78. u32 v = omap4_cminst_read_inst_reg(part, inst, clkctrl_offs);
  79. v &= OMAP4430_IDLEST_MASK;
  80. v >>= OMAP4430_IDLEST_SHIFT;
  81. return v;
  82. }
  83. /**
  84. * _is_module_ready - can module registers be accessed without causing an abort?
  85. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  86. * @inst: CM instance register offset (*_INST macro)
  87. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  88. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  89. *
  90. * Returns true if the module's CM_*_CLKCTRL.IDLEST bitfield is either
  91. * *FUNCTIONAL or *INTERFACE_IDLE; false otherwise.
  92. */
  93. static bool _is_module_ready(u8 part, u16 inst, s16 cdoffs, u16 clkctrl_offs)
  94. {
  95. u32 v;
  96. v = _clkctrl_idlest(part, inst, cdoffs, clkctrl_offs);
  97. return (v == CLKCTRL_IDLEST_FUNCTIONAL ||
  98. v == CLKCTRL_IDLEST_INTERFACE_IDLE) ? true : false;
  99. }
  100. /* Public functions */
  101. /* Read a register in a CM instance */
  102. u32 omap4_cminst_read_inst_reg(u8 part, s16 inst, u16 idx)
  103. {
  104. BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
  105. part == OMAP4430_INVALID_PRCM_PARTITION ||
  106. !_cm_bases[part]);
  107. return __raw_readl(_cm_bases[part] + inst + idx);
  108. }
  109. /* Write into a register in a CM instance */
  110. void omap4_cminst_write_inst_reg(u32 val, u8 part, s16 inst, u16 idx)
  111. {
  112. BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
  113. part == OMAP4430_INVALID_PRCM_PARTITION ||
  114. !_cm_bases[part]);
  115. __raw_writel(val, _cm_bases[part] + inst + idx);
  116. }
  117. /* Read-modify-write a register in CM1. Caller must lock */
  118. u32 omap4_cminst_rmw_inst_reg_bits(u32 mask, u32 bits, u8 part, s16 inst,
  119. s16 idx)
  120. {
  121. u32 v;
  122. v = omap4_cminst_read_inst_reg(part, inst, idx);
  123. v &= ~mask;
  124. v |= bits;
  125. omap4_cminst_write_inst_reg(v, part, inst, idx);
  126. return v;
  127. }
  128. u32 omap4_cminst_set_inst_reg_bits(u32 bits, u8 part, s16 inst, s16 idx)
  129. {
  130. return omap4_cminst_rmw_inst_reg_bits(bits, bits, part, inst, idx);
  131. }
  132. u32 omap4_cminst_clear_inst_reg_bits(u32 bits, u8 part, s16 inst, s16 idx)
  133. {
  134. return omap4_cminst_rmw_inst_reg_bits(bits, 0x0, part, inst, idx);
  135. }
  136. u32 omap4_cminst_read_inst_reg_bits(u8 part, u16 inst, s16 idx, u32 mask)
  137. {
  138. u32 v;
  139. v = omap4_cminst_read_inst_reg(part, inst, idx);
  140. v &= mask;
  141. v >>= __ffs(mask);
  142. return v;
  143. }
  144. /*
  145. *
  146. */
  147. /**
  148. * _clktrctrl_write - write @c to a CM_CLKSTCTRL.CLKTRCTRL register bitfield
  149. * @c: CLKTRCTRL register bitfield (LSB = bit 0, i.e., unshifted)
  150. * @part: PRCM partition ID that the CM_CLKSTCTRL register exists in
  151. * @inst: CM instance register offset (*_INST macro)
  152. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  153. *
  154. * @c must be the unshifted value for CLKTRCTRL - i.e., this function
  155. * will handle the shift itself.
  156. */
  157. static void _clktrctrl_write(u8 c, u8 part, s16 inst, u16 cdoffs)
  158. {
  159. u32 v;
  160. v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  161. v &= ~OMAP4430_CLKTRCTRL_MASK;
  162. v |= c << OMAP4430_CLKTRCTRL_SHIFT;
  163. omap4_cminst_write_inst_reg(v, part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  164. }
  165. /**
  166. * omap4_cminst_is_clkdm_in_hwsup - is a clockdomain in hwsup idle mode?
  167. * @part: PRCM partition ID that the CM_CLKSTCTRL register exists in
  168. * @inst: CM instance register offset (*_INST macro)
  169. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  170. *
  171. * Returns true if the clockdomain referred to by (@part, @inst, @cdoffs)
  172. * is in hardware-supervised idle mode, or 0 otherwise.
  173. */
  174. bool omap4_cminst_is_clkdm_in_hwsup(u8 part, s16 inst, u16 cdoffs)
  175. {
  176. u32 v;
  177. v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  178. v &= OMAP4430_CLKTRCTRL_MASK;
  179. v >>= OMAP4430_CLKTRCTRL_SHIFT;
  180. return (v == OMAP34XX_CLKSTCTRL_ENABLE_AUTO) ? true : false;
  181. }
  182. /**
  183. * omap4_cminst_clkdm_enable_hwsup - put a clockdomain in hwsup-idle mode
  184. * @part: PRCM partition ID that the clockdomain registers exist in
  185. * @inst: CM instance register offset (*_INST macro)
  186. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  187. *
  188. * Put a clockdomain referred to by (@part, @inst, @cdoffs) into
  189. * hardware-supervised idle mode. No return value.
  190. */
  191. void omap4_cminst_clkdm_enable_hwsup(u8 part, s16 inst, u16 cdoffs)
  192. {
  193. _clktrctrl_write(OMAP34XX_CLKSTCTRL_ENABLE_AUTO, part, inst, cdoffs);
  194. }
  195. /**
  196. * omap4_cminst_clkdm_disable_hwsup - put a clockdomain in swsup-idle mode
  197. * @part: PRCM partition ID that the clockdomain registers exist in
  198. * @inst: CM instance register offset (*_INST macro)
  199. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  200. *
  201. * Put a clockdomain referred to by (@part, @inst, @cdoffs) into
  202. * software-supervised idle mode, i.e., controlled manually by the
  203. * Linux OMAP clockdomain code. No return value.
  204. */
  205. void omap4_cminst_clkdm_disable_hwsup(u8 part, s16 inst, u16 cdoffs)
  206. {
  207. _clktrctrl_write(OMAP34XX_CLKSTCTRL_DISABLE_AUTO, part, inst, cdoffs);
  208. }
  209. /**
  210. * omap4_cminst_clkdm_force_sleep - try to take a clockdomain out of idle
  211. * @part: PRCM partition ID that the clockdomain registers exist in
  212. * @inst: CM instance register offset (*_INST macro)
  213. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  214. *
  215. * Take a clockdomain referred to by (@part, @inst, @cdoffs) out of idle,
  216. * waking it up. No return value.
  217. */
  218. void omap4_cminst_clkdm_force_wakeup(u8 part, s16 inst, u16 cdoffs)
  219. {
  220. _clktrctrl_write(OMAP34XX_CLKSTCTRL_FORCE_WAKEUP, part, inst, cdoffs);
  221. }
  222. /*
  223. *
  224. */
  225. /**
  226. * omap4_cminst_wait_module_ready - wait for a module to be in 'func' state
  227. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  228. * @inst: CM instance register offset (*_INST macro)
  229. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  230. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  231. *
  232. * Wait for the module IDLEST to be functional. If the idle state is in any
  233. * the non functional state (trans, idle or disabled), module and thus the
  234. * sysconfig cannot be accessed and will probably lead to an "imprecise
  235. * external abort"
  236. */
  237. int omap4_cminst_wait_module_ready(u8 part, u16 inst, s16 cdoffs,
  238. u16 clkctrl_offs)
  239. {
  240. int i = 0;
  241. if (!clkctrl_offs)
  242. return 0;
  243. omap_test_timeout(_is_module_ready(part, inst, cdoffs, clkctrl_offs),
  244. MAX_MODULE_READY_TIME, i);
  245. return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
  246. }
  247. /**
  248. * omap4_cminst_wait_module_idle - wait for a module to be in 'disabled'
  249. * state
  250. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  251. * @inst: CM instance register offset (*_INST macro)
  252. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  253. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  254. *
  255. * Wait for the module IDLEST to be disabled. Some PRCM transition,
  256. * like reset assertion or parent clock de-activation must wait the
  257. * module to be fully disabled.
  258. */
  259. int omap4_cminst_wait_module_idle(u8 part, u16 inst, s16 cdoffs, u16 clkctrl_offs)
  260. {
  261. int i = 0;
  262. if (!clkctrl_offs)
  263. return 0;
  264. omap_test_timeout((_clkctrl_idlest(part, inst, cdoffs, clkctrl_offs) ==
  265. CLKCTRL_IDLEST_DISABLED),
  266. MAX_MODULE_DISABLE_TIME, i);
  267. return (i < MAX_MODULE_DISABLE_TIME) ? 0 : -EBUSY;
  268. }
  269. /**
  270. * omap4_cminst_module_enable - Enable the modulemode inside CLKCTRL
  271. * @mode: Module mode (SW or HW)
  272. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  273. * @inst: CM instance register offset (*_INST macro)
  274. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  275. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  276. *
  277. * No return value.
  278. */
  279. void omap4_cminst_module_enable(u8 mode, u8 part, u16 inst, s16 cdoffs,
  280. u16 clkctrl_offs)
  281. {
  282. u32 v;
  283. v = omap4_cminst_read_inst_reg(part, inst, clkctrl_offs);
  284. v &= ~OMAP4430_MODULEMODE_MASK;
  285. v |= mode << OMAP4430_MODULEMODE_SHIFT;
  286. omap4_cminst_write_inst_reg(v, part, inst, clkctrl_offs);
  287. }
  288. /**
  289. * omap4_cminst_module_disable - Disable the module inside CLKCTRL
  290. * @part: PRCM partition ID that the CM_CLKCTRL register exists in
  291. * @inst: CM instance register offset (*_INST macro)
  292. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  293. * @clkctrl_offs: Module clock control register offset (*_CLKCTRL macro)
  294. *
  295. * No return value.
  296. */
  297. void omap4_cminst_module_disable(u8 part, u16 inst, s16 cdoffs,
  298. u16 clkctrl_offs)
  299. {
  300. u32 v;
  301. v = omap4_cminst_read_inst_reg(part, inst, clkctrl_offs);
  302. v &= ~OMAP4430_MODULEMODE_MASK;
  303. omap4_cminst_write_inst_reg(v, part, inst, clkctrl_offs);
  304. }
  305. /*
  306. * Clockdomain low-level functions
  307. */
  308. static int omap4_clkdm_add_wkup_sleep_dep(struct clockdomain *clkdm1,
  309. struct clockdomain *clkdm2)
  310. {
  311. omap4_cminst_set_inst_reg_bits((1 << clkdm2->dep_bit),
  312. clkdm1->prcm_partition,
  313. clkdm1->cm_inst, clkdm1->clkdm_offs +
  314. OMAP4_CM_STATICDEP);
  315. return 0;
  316. }
  317. static int omap4_clkdm_del_wkup_sleep_dep(struct clockdomain *clkdm1,
  318. struct clockdomain *clkdm2)
  319. {
  320. omap4_cminst_clear_inst_reg_bits((1 << clkdm2->dep_bit),
  321. clkdm1->prcm_partition,
  322. clkdm1->cm_inst, clkdm1->clkdm_offs +
  323. OMAP4_CM_STATICDEP);
  324. return 0;
  325. }
  326. static int omap4_clkdm_read_wkup_sleep_dep(struct clockdomain *clkdm1,
  327. struct clockdomain *clkdm2)
  328. {
  329. return omap4_cminst_read_inst_reg_bits(clkdm1->prcm_partition,
  330. clkdm1->cm_inst,
  331. clkdm1->clkdm_offs +
  332. OMAP4_CM_STATICDEP,
  333. (1 << clkdm2->dep_bit));
  334. }
  335. static int omap4_clkdm_clear_all_wkup_sleep_deps(struct clockdomain *clkdm)
  336. {
  337. struct clkdm_dep *cd;
  338. u32 mask = 0;
  339. if (!clkdm->prcm_partition)
  340. return 0;
  341. for (cd = clkdm->wkdep_srcs; cd && cd->clkdm_name; cd++) {
  342. if (!cd->clkdm)
  343. continue; /* only happens if data is erroneous */
  344. mask |= 1 << cd->clkdm->dep_bit;
  345. cd->wkdep_usecount = 0;
  346. }
  347. omap4_cminst_clear_inst_reg_bits(mask, clkdm->prcm_partition,
  348. clkdm->cm_inst, clkdm->clkdm_offs +
  349. OMAP4_CM_STATICDEP);
  350. return 0;
  351. }
  352. static int omap4_clkdm_sleep(struct clockdomain *clkdm)
  353. {
  354. omap4_cminst_clkdm_enable_hwsup(clkdm->prcm_partition,
  355. clkdm->cm_inst, clkdm->clkdm_offs);
  356. return 0;
  357. }
  358. static int omap4_clkdm_wakeup(struct clockdomain *clkdm)
  359. {
  360. omap4_cminst_clkdm_force_wakeup(clkdm->prcm_partition,
  361. clkdm->cm_inst, clkdm->clkdm_offs);
  362. return 0;
  363. }
  364. static void omap4_clkdm_allow_idle(struct clockdomain *clkdm)
  365. {
  366. omap4_cminst_clkdm_enable_hwsup(clkdm->prcm_partition,
  367. clkdm->cm_inst, clkdm->clkdm_offs);
  368. }
  369. static void omap4_clkdm_deny_idle(struct clockdomain *clkdm)
  370. {
  371. if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
  372. omap4_clkdm_wakeup(clkdm);
  373. else
  374. omap4_cminst_clkdm_disable_hwsup(clkdm->prcm_partition,
  375. clkdm->cm_inst,
  376. clkdm->clkdm_offs);
  377. }
  378. static int omap4_clkdm_clk_enable(struct clockdomain *clkdm)
  379. {
  380. if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
  381. return omap4_clkdm_wakeup(clkdm);
  382. return 0;
  383. }
  384. static int omap4_clkdm_clk_disable(struct clockdomain *clkdm)
  385. {
  386. bool hwsup = false;
  387. if (!clkdm->prcm_partition)
  388. return 0;
  389. /*
  390. * The CLKDM_MISSING_IDLE_REPORTING flag documentation has
  391. * more details on the unpleasant problem this is working
  392. * around
  393. */
  394. if (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING &&
  395. !(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) {
  396. omap4_clkdm_allow_idle(clkdm);
  397. return 0;
  398. }
  399. hwsup = omap4_cminst_is_clkdm_in_hwsup(clkdm->prcm_partition,
  400. clkdm->cm_inst, clkdm->clkdm_offs);
  401. if (!hwsup && (clkdm->flags & CLKDM_CAN_FORCE_SLEEP))
  402. omap4_clkdm_sleep(clkdm);
  403. return 0;
  404. }
  405. struct clkdm_ops omap4_clkdm_operations = {
  406. .clkdm_add_wkdep = omap4_clkdm_add_wkup_sleep_dep,
  407. .clkdm_del_wkdep = omap4_clkdm_del_wkup_sleep_dep,
  408. .clkdm_read_wkdep = omap4_clkdm_read_wkup_sleep_dep,
  409. .clkdm_clear_all_wkdeps = omap4_clkdm_clear_all_wkup_sleep_deps,
  410. .clkdm_add_sleepdep = omap4_clkdm_add_wkup_sleep_dep,
  411. .clkdm_del_sleepdep = omap4_clkdm_del_wkup_sleep_dep,
  412. .clkdm_read_sleepdep = omap4_clkdm_read_wkup_sleep_dep,
  413. .clkdm_clear_all_sleepdeps = omap4_clkdm_clear_all_wkup_sleep_deps,
  414. .clkdm_sleep = omap4_clkdm_sleep,
  415. .clkdm_wakeup = omap4_clkdm_wakeup,
  416. .clkdm_allow_idle = omap4_clkdm_allow_idle,
  417. .clkdm_deny_idle = omap4_clkdm_deny_idle,
  418. .clkdm_clk_enable = omap4_clkdm_clk_enable,
  419. .clkdm_clk_disable = omap4_clkdm_clk_disable,
  420. };