preliminaryDataProcessing.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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);