omap4pwr.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. omap4pwr.c
  5. Abstract:
  6. This module implements power and clock domain services for the TI OMAP4.
  7. Author:
  8. Evan Green 4-Nov-2012
  9. Environment:
  10. Kernel
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. //
  16. // Include kernel.h, but be cautious about which APIs are used. Most of the
  17. // system depends on the hardware modules. Limit use to HL, RTL and AR routines.
  18. //
  19. #include <minoca/kernel/kernel.h>
  20. #include "omap4.h"
  21. //
  22. // --------------------------------------------------------------------- Macros
  23. //
  24. //
  25. // This macro reads from an OMAP4 PRCM Register. _Base should be a pointer, and
  26. // _Register should be a register offset in ULONGs.
  27. //
  28. #define READ_PRCM_REGISTER(_Base, _Register) \
  29. HlReadRegister32((PULONG)(_Base) + (_Register))
  30. //
  31. // This macro writes to an OMAP4 PRCM Register. _Base should be a pointer,
  32. // _Register should be register offset in ULONGs, and _Value should be a ULONG.
  33. //
  34. #define WRITE_PRCM_REGISTER(_Base, _Register, _Value) \
  35. HlWriteRegister32((PULONG)(_Base) + (_Register), (_Value))
  36. //
  37. // ---------------------------------------------------------------- Definitions
  38. //
  39. //
  40. // This bit is set to select the always on 32kHz clock source to drive the
  41. // timer counter.
  42. //
  43. #define GPTIMER_SELECT_32KHZ_CLOCK 0x01000000
  44. #define GPTIMER_SELECT_SYSTEM_CLOCK 0x00000000
  45. //
  46. // These bits define the operating mode of the functional clock.
  47. //
  48. #define GPTIMER_CLOCK_MODE_MASK 0x03
  49. #define GPTIMER_ENABLE_CLOCK 0x02
  50. //
  51. // Define the clock control bits for the Audio backend control.
  52. //
  53. #define AUDIO_CLOCK_CONTROL_MODE_MASK 0x3
  54. #define AUDIO_CLOCK_CONTROL_NO_SLEEP 0x0
  55. //
  56. // ----------------------------------------------- Internal Function Prototypes
  57. //
  58. //
  59. // ------------------------------------------------------ Data Type Definitions
  60. //
  61. //
  62. // Register offsets for the Wakeup Clock Management interface (WKUP_CM). All
  63. // offsets are in ULONGs.
  64. //
  65. typedef enum _WKUP_CM_REGISTER {
  66. WakeupClockControl = 0x00, // CM_WKUP_CLKSTCTRL
  67. WakeupClockGpTimer1Control = 0x10, // CM_WKUP_GPTIMER1_CLKCTRL
  68. } WKUP_CM_REGISTER, *PWKUP_CM_REGISTER;
  69. //
  70. // Register offsets for the L4 Interconnect Clock Managment interface
  71. // (L4PER_CM). All offsets are in ULONGs.
  72. //
  73. typedef enum _L4PER_CM_REGISTER {
  74. L4ClockControl = 0x00, // CM_L4PER_CLKSTCTRL
  75. L4ClockGpTimer10Control = 0x0A, // CM_L4PER_GPTIMER10_CLKCTRL
  76. L4ClockGpTimer11Control = 0x0C, // CM_L4PER_GPTIMER11_CLKCTRL
  77. L4ClockGpTimer2Control = 0x0E, // CM_L4PER_GPTIMER2_CLKCTRL
  78. L4ClockGpTimer3Control = 0x10, // CM_L4PER_GPTIMER3_CLKCTRL
  79. L4ClockGpTimer4Control = 0x12, // CM_L4PER_GPTIMER4_CLKCTRL
  80. L4ClockGpTimer9Control = 0x14, // CM_L4PER_GPTIMER9_CLKCTRL
  81. } L4PER_CM_REGISTER, *PL4PER_CM_REGISTER;
  82. //
  83. // Register offsets for the Audio Back-End Clock Management interface (ABE_CM1).
  84. // All offsets are in ULONGs.
  85. //
  86. typedef enum _ABE_CM1_REGISTER {
  87. AudioClockControl = 0x00, // CM1_ABE_CLKSTCTRL
  88. AudioClockGpTimer5Control = 0x1A, // CM1_ABE_GPTIMER5_CLKCTRL
  89. AudioClockGpTimer6Control = 0x1C, // CM1_ABE_GPTIMER6_CLKCTRL
  90. AudioClockGpTimer7Control = 0x1E, // CM1_ABE_GPTIMER7_CLKCTRL
  91. AudioClockGpTimer8Control = 0x20, // CM1_ABE_GPTIMER8_CLKCTRL
  92. } ABE_CM1_REGISTER, *PABE_CM1_REGISTER;
  93. //
  94. // -------------------------------------------------------------------- Globals
  95. //
  96. //
  97. // Store pointers to pieces of the PRCM.
  98. //
  99. PVOID HlOmap4WakeupClockControl = NULL;
  100. PVOID HlOmap4L4ClockControl = NULL;
  101. PVOID HlOmap4AudioClockControl = NULL;
  102. //
  103. // ------------------------------------------------------------------ Functions
  104. //
  105. KSTATUS
  106. HlpOmap4InitializePowerAndClocks (
  107. VOID
  108. )
  109. /*++
  110. Routine Description:
  111. This routine initializes the PRCM and turns on clocks and power domains
  112. needed by the system.
  113. Arguments:
  114. None.
  115. Return Value:
  116. Status code.
  117. --*/
  118. {
  119. KSTATUS Status;
  120. ULONG Value;
  121. //
  122. // Map each of the PRCM sections if needed.
  123. //
  124. if (HlOmap4WakeupClockControl == NULL) {
  125. HlOmap4WakeupClockControl = HlMapPhysicalAddress(
  126. HlOmap4Table->WakeupClockPhysicalAddress,
  127. 0x800,
  128. TRUE);
  129. if (HlOmap4WakeupClockControl == NULL) {
  130. Status = STATUS_INSUFFICIENT_RESOURCES;
  131. goto InitializePowerAndClocksEnd;
  132. }
  133. }
  134. if (HlOmap4L4ClockControl == NULL) {
  135. HlOmap4L4ClockControl = HlMapPhysicalAddress(
  136. HlOmap4Table->L4ClockPhysicalAddress,
  137. 0xC00,
  138. TRUE);
  139. if (HlOmap4L4ClockControl == NULL) {
  140. Status = STATUS_INSUFFICIENT_RESOURCES;
  141. goto InitializePowerAndClocksEnd;
  142. }
  143. }
  144. if (HlOmap4AudioClockControl == NULL) {
  145. HlOmap4AudioClockControl = HlMapPhysicalAddress(
  146. HlOmap4Table->AudioClockPhysicalAddress,
  147. 0xB00,
  148. TRUE);
  149. if (HlOmap4AudioClockControl == NULL) {
  150. Status = STATUS_INSUFFICIENT_RESOURCES;
  151. goto InitializePowerAndClocksEnd;
  152. }
  153. }
  154. //
  155. // Enable GP Timer 1, and set it to run at the system clock frequency.
  156. //
  157. Value = GPTIMER_SELECT_SYSTEM_CLOCK | GPTIMER_ENABLE_CLOCK;
  158. WRITE_PRCM_REGISTER(HlOmap4WakeupClockControl,
  159. WakeupClockGpTimer1Control,
  160. Value);
  161. //
  162. // Enable GP Timers 2-4 and 9-11 to run at the 32kHz clock speed.
  163. //
  164. Value = GPTIMER_SELECT_32KHZ_CLOCK | GPTIMER_ENABLE_CLOCK;
  165. WRITE_PRCM_REGISTER(HlOmap4L4ClockControl,
  166. L4ClockGpTimer2Control,
  167. Value);
  168. WRITE_PRCM_REGISTER(HlOmap4L4ClockControl,
  169. L4ClockGpTimer3Control,
  170. Value);
  171. WRITE_PRCM_REGISTER(HlOmap4L4ClockControl,
  172. L4ClockGpTimer4Control,
  173. Value);
  174. WRITE_PRCM_REGISTER(HlOmap4L4ClockControl,
  175. L4ClockGpTimer9Control,
  176. Value);
  177. WRITE_PRCM_REGISTER(HlOmap4L4ClockControl,
  178. L4ClockGpTimer10Control,
  179. Value);
  180. WRITE_PRCM_REGISTER(HlOmap4L4ClockControl,
  181. L4ClockGpTimer11Control,
  182. Value);
  183. //
  184. // Enable the Audio Back-End clock.
  185. //
  186. Value = READ_PRCM_REGISTER(HlOmap4AudioClockControl, AudioClockControl);
  187. Value &= ~AUDIO_CLOCK_CONTROL_MODE_MASK;
  188. Value |= AUDIO_CLOCK_CONTROL_NO_SLEEP;
  189. WRITE_PRCM_REGISTER(HlOmap4AudioClockControl, AudioClockControl, Value);
  190. //
  191. // Enable GP Timers 5-8 to run at the 32kHz always on clock rate.
  192. //
  193. Value = GPTIMER_SELECT_32KHZ_CLOCK | GPTIMER_ENABLE_CLOCK;
  194. WRITE_PRCM_REGISTER(HlOmap4AudioClockControl,
  195. AudioClockGpTimer5Control,
  196. Value);
  197. WRITE_PRCM_REGISTER(HlOmap4AudioClockControl,
  198. AudioClockGpTimer6Control,
  199. Value);
  200. WRITE_PRCM_REGISTER(HlOmap4AudioClockControl,
  201. AudioClockGpTimer7Control,
  202. Value);
  203. WRITE_PRCM_REGISTER(HlOmap4AudioClockControl,
  204. AudioClockGpTimer8Control,
  205. Value);
  206. Status = STATUS_SUCCESS;
  207. InitializePowerAndClocksEnd:
  208. return Status;
  209. }
  210. //
  211. // --------------------------------------------------------- Internal Functions
  212. //