am335pwr.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*++
  2. Copyright (c) 2015 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. am335pwr.c
  5. Abstract:
  6. This module implements clock and power support for AM335x SoCs.
  7. Author:
  8. Evan Green 6-Jan-2015
  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 <minoca/soc/am335x.h>
  21. #include "am335.h"
  22. //
  23. // --------------------------------------------------------------------- Macros
  24. //
  25. #define AM335_CM_DPLL_READ(_Register) \
  26. HlReadRegister32(HlAm335Prcm + AM335_CM_DPLL_OFFSET + (_Register))
  27. #define AM335_CM_DPLL_WRITE(_Register, _Value) \
  28. HlWriteRegister32(HlAm335Prcm + AM335_CM_DPLL_OFFSET + (_Register), \
  29. (_Value))
  30. #define AM335_CM_PER_READ(_Register) \
  31. HlReadRegister32(HlAm335Prcm + AM335_CM_PER_OFFSET + (_Register))
  32. #define AM335_CM_PER_WRITE(_Register, _Value) \
  33. HlWriteRegister32(HlAm335Prcm + AM335_CM_PER_OFFSET + (_Register), \
  34. (_Value))
  35. #define AM335_CM_WAKEUP_READ(_Register) \
  36. HlReadRegister32(HlAm335Prcm + AM335_CM_WAKEUP_OFFSET + (_Register))
  37. #define AM335_CM_WAKEUP_WRITE(_Register, _Value) \
  38. HlWriteRegister32(HlAm335Prcm + AM335_CM_WAKEUP_OFFSET + (_Register), \
  39. (_Value))
  40. //
  41. // ---------------------------------------------------------------- Definitions
  42. //
  43. //
  44. // ------------------------------------------------------ Data Type Definitions
  45. //
  46. //
  47. // ----------------------------------------------- Internal Function Prototypes
  48. //
  49. //
  50. // -------------------------------------------------------------------- Globals
  51. //
  52. //
  53. // Store virtual address register bases.
  54. //
  55. PVOID HlAm335Prcm;
  56. //
  57. // ------------------------------------------------------------------ Functions
  58. //
  59. KSTATUS
  60. HlpAm335InitializePowerAndClocks (
  61. VOID
  62. )
  63. /*++
  64. Routine Description:
  65. This routine initializes the PRCM and turns on clocks and power domains
  66. needed by the system.
  67. Arguments:
  68. None.
  69. Return Value:
  70. Status code.
  71. --*/
  72. {
  73. KSTATUS Status;
  74. ULONG Value;
  75. if (HlAm335Prcm == NULL) {
  76. HlAm335Prcm = HlMapPhysicalAddress(HlAm335Table->PrcmBase,
  77. AM335_PRCM_SIZE,
  78. TRUE);
  79. if (HlAm335Prcm == NULL) {
  80. Status = STATUS_INSUFFICIENT_RESOURCES;
  81. goto InitializePowerAndClocksEnd;
  82. }
  83. }
  84. //
  85. // Select the 32kHz source for timer 1. Timer 0 is fixed at 32kHz.
  86. //
  87. Value = AM335_CM_DPLL_CLOCK_SELECT_TIMER1_32KHZ;
  88. AM335_CM_DPLL_WRITE(AM335_CM_DPLL_CLOCK_SELECT_TIMER1, Value);
  89. //
  90. // Select the system clock source for all the other timers.
  91. //
  92. Value = AM335_CM_DPLL_CLOCK_SELECT_TIMER_SYSTEM_CLOCK;
  93. AM335_CM_DPLL_WRITE(AM335_CM_DPLL_CLOCK_SELECT_TIMER2, Value);
  94. AM335_CM_DPLL_WRITE(AM335_CM_DPLL_CLOCK_SELECT_TIMER3, Value);
  95. AM335_CM_DPLL_WRITE(AM335_CM_DPLL_CLOCK_SELECT_TIMER4, Value);
  96. AM335_CM_DPLL_WRITE(AM335_CM_DPLL_CLOCK_SELECT_TIMER5, Value);
  97. AM335_CM_DPLL_WRITE(AM335_CM_DPLL_CLOCK_SELECT_TIMER6, Value);
  98. AM335_CM_DPLL_WRITE(AM335_CM_DPLL_CLOCK_SELECT_TIMER7, Value);
  99. //
  100. // Enable all timers.
  101. //
  102. Value = AM335_CM_WAKEUP_TIMER0_CLOCK_ENABLE;
  103. AM335_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_TIMER0_CLOCK_CONTROL, Value);
  104. AM335_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_TIMER1_CLOCK_CONTROL, Value);
  105. Value = AM335_CM_PER_TIMER2_CLOCK_ENABLE;
  106. AM335_CM_PER_WRITE(AM335_CM_PER_TIMER2_CLOCK_CONTROL, Value);
  107. AM335_CM_PER_WRITE(AM335_CM_PER_TIMER3_CLOCK_CONTROL, Value);
  108. AM335_CM_PER_WRITE(AM335_CM_PER_TIMER4_CLOCK_CONTROL, Value);
  109. AM335_CM_PER_WRITE(AM335_CM_PER_TIMER5_CLOCK_CONTROL, Value);
  110. AM335_CM_PER_WRITE(AM335_CM_PER_TIMER6_CLOCK_CONTROL, Value);
  111. AM335_CM_PER_WRITE(AM335_CM_PER_TIMER7_CLOCK_CONTROL, Value);
  112. Status = STATUS_SUCCESS;
  113. InitializePowerAndClocksEnd:
  114. return Status;
  115. }
  116. //
  117. // --------------------------------------------------------- Internal Functions
  118. //