clock.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*++
  2. Copyright (c) 2014 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. clock.c
  9. Abstract:
  10. This module manages power and clocks for TI OMAP4 devices.
  11. Author:
  12. Evan Green 3-Mar-2014
  13. Environment:
  14. Firmware
  15. --*/
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. #include <uefifw.h>
  20. #include "dev/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. EfiReadRegister32((UINT32 *)(_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. EfiWriteRegister32((UINT32 *)(_Base) + (_Register), (_Value))
  36. //
  37. // ---------------------------------------------------------------- Definitions
  38. //
  39. //
  40. // Define clock/reset base addresses for OMAP4 SoCs.
  41. //
  42. #define OMAP4_WAKEUP_CLOCK_BASE 0x4A307800
  43. #define OMAP4_L4_CLOCK_BASE 0x4A009400
  44. #define OMAP4_AUDIO_CLOCK_BASE 0x4A004500
  45. //
  46. // This bit is set to select the always on 32kHz clock source to drive the
  47. // timer counter.
  48. //
  49. #define GPTIMER_SELECT_32KHZ_CLOCK 0x01000000
  50. #define GPTIMER_SELECT_SYSTEM_CLOCK 0x00000000
  51. //
  52. // These bits define the operating mode of the functional clock.
  53. //
  54. #define GPTIMER_CLOCK_MODE_MASK 0x03
  55. #define GPTIMER_ENABLE_CLOCK 0x02
  56. //
  57. // Define the clock control bits for the Audio backend control.
  58. //
  59. #define AUDIO_CLOCK_CONTROL_MODE_MASK 0x3
  60. #define AUDIO_CLOCK_CONTROL_NO_SLEEP 0x0
  61. //
  62. // ----------------------------------------------- Internal Function Prototypes
  63. //
  64. //
  65. // ------------------------------------------------------ Data Type Definitions
  66. //
  67. //
  68. // Register offsets for the Wakeup Clock Management interface (WKUP_CM). All
  69. // offsets are in UINT32s.
  70. //
  71. typedef enum _WKUP_CM_REGISTER {
  72. WakeupClockControl = 0x00, // CM_WKUP_CLKSTCTRL
  73. WakeupClockGpTimer1Control = 0x10, // CM_WKUP_GPTIMER1_CLKCTRL
  74. } WKUP_CM_REGISTER, *PWKUP_CM_REGISTER;
  75. //
  76. // Register offsets for the L4 Interconnect Clock Managment interface
  77. // (L4PER_CM). All offsets are in UINT32s.
  78. //
  79. typedef enum _L4PER_CM_REGISTER {
  80. L4ClockControl = 0x00, // CM_L4PER_CLKSTCTRL
  81. L4ClockGpTimer10Control = 0x0A, // CM_L4PER_GPTIMER10_CLKCTRL
  82. L4ClockGpTimer11Control = 0x0C, // CM_L4PER_GPTIMER11_CLKCTRL
  83. L4ClockGpTimer2Control = 0x0E, // CM_L4PER_GPTIMER2_CLKCTRL
  84. L4ClockGpTimer3Control = 0x10, // CM_L4PER_GPTIMER3_CLKCTRL
  85. L4ClockGpTimer4Control = 0x12, // CM_L4PER_GPTIMER4_CLKCTRL
  86. L4ClockGpTimer9Control = 0x14, // CM_L4PER_GPTIMER9_CLKCTRL
  87. } L4PER_CM_REGISTER, *PL4PER_CM_REGISTER;
  88. //
  89. // Register offsets for the Audio Back-End Clock Management interface (ABE_CM1).
  90. // All offsets are in UINT32s.
  91. //
  92. typedef enum _ABE_CM1_REGISTER {
  93. AudioClockControl = 0x00, // CM1_ABE_CLKSTCTRL
  94. AudioClockGpTimer5Control = 0x1A, // CM1_ABE_GPTIMER5_CLKCTRL
  95. AudioClockGpTimer6Control = 0x1C, // CM1_ABE_GPTIMER6_CLKCTRL
  96. AudioClockGpTimer7Control = 0x1E, // CM1_ABE_GPTIMER7_CLKCTRL
  97. AudioClockGpTimer8Control = 0x20, // CM1_ABE_GPTIMER8_CLKCTRL
  98. } ABE_CM1_REGISTER, *PABE_CM1_REGISTER;
  99. //
  100. // -------------------------------------------------------------------- Globals
  101. //
  102. //
  103. // Store pointers to pieces of the PRCM.
  104. //
  105. VOID *EfiOmap4WakeupClockControl = (VOID *)OMAP4_WAKEUP_CLOCK_BASE;
  106. VOID *EfiOmap4L4ClockControl = (VOID *)OMAP4_L4_CLOCK_BASE;
  107. VOID *EfiOmap4AudioClockControl = (VOID *)OMAP4_AUDIO_CLOCK_BASE;
  108. //
  109. // ------------------------------------------------------------------ Functions
  110. //
  111. VOID
  112. EfipOmap4InitializePowerAndClocks (
  113. VOID
  114. )
  115. /*++
  116. Routine Description:
  117. This routine initializes the PRCM and turns on clocks and power domains
  118. needed by the system.
  119. Arguments:
  120. None.
  121. Return Value:
  122. Status code.
  123. --*/
  124. {
  125. UINT32 Value;
  126. //
  127. // Enable GP Timer 1, and set it to run at the system clock frequency.
  128. //
  129. Value = GPTIMER_SELECT_SYSTEM_CLOCK | GPTIMER_ENABLE_CLOCK;
  130. WRITE_PRCM_REGISTER(EfiOmap4WakeupClockControl,
  131. WakeupClockGpTimer1Control,
  132. Value);
  133. //
  134. // Enable GP Timers 2-4 and 9-11 to run at the 32kHz clock speed.
  135. //
  136. Value = GPTIMER_SELECT_32KHZ_CLOCK | GPTIMER_ENABLE_CLOCK;
  137. WRITE_PRCM_REGISTER(EfiOmap4L4ClockControl,
  138. L4ClockGpTimer2Control,
  139. Value);
  140. WRITE_PRCM_REGISTER(EfiOmap4L4ClockControl,
  141. L4ClockGpTimer3Control,
  142. Value);
  143. WRITE_PRCM_REGISTER(EfiOmap4L4ClockControl,
  144. L4ClockGpTimer4Control,
  145. Value);
  146. WRITE_PRCM_REGISTER(EfiOmap4L4ClockControl,
  147. L4ClockGpTimer9Control,
  148. Value);
  149. WRITE_PRCM_REGISTER(EfiOmap4L4ClockControl,
  150. L4ClockGpTimer10Control,
  151. Value);
  152. WRITE_PRCM_REGISTER(EfiOmap4L4ClockControl,
  153. L4ClockGpTimer11Control,
  154. Value);
  155. //
  156. // Enable the Audio Back-End clock.
  157. //
  158. Value = READ_PRCM_REGISTER(EfiOmap4AudioClockControl, AudioClockControl);
  159. Value &= ~AUDIO_CLOCK_CONTROL_MODE_MASK;
  160. Value |= AUDIO_CLOCK_CONTROL_NO_SLEEP;
  161. WRITE_PRCM_REGISTER(EfiOmap4AudioClockControl, AudioClockControl, Value);
  162. //
  163. // Enable GP Timers 5-8 to run at the 32kHz always on clock rate.
  164. //
  165. Value = GPTIMER_SELECT_32KHZ_CLOCK | GPTIMER_ENABLE_CLOCK;
  166. WRITE_PRCM_REGISTER(EfiOmap4AudioClockControl,
  167. AudioClockGpTimer5Control,
  168. Value);
  169. WRITE_PRCM_REGISTER(EfiOmap4AudioClockControl,
  170. AudioClockGpTimer6Control,
  171. Value);
  172. WRITE_PRCM_REGISTER(EfiOmap4AudioClockControl,
  173. AudioClockGpTimer7Control,
  174. Value);
  175. WRITE_PRCM_REGISTER(EfiOmap4AudioClockControl,
  176. AudioClockGpTimer8Control,
  177. Value);
  178. return;
  179. }
  180. //
  181. // --------------------------------------------------------- Internal Functions
  182. //