123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997 |
- /*++
- Copyright (c) 2014 Minoca Corp. All Rights Reserved
- Module Name:
- clock.c
- Abstract:
- This module implements clock management for the TI AM335x first stage
- loader.
- Author:
- Evan Green 18-Dec-2014
- Environment:
- Firmware
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <uefifw.h>
- #include "init.h"
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- VOID
- EfipAm335InitializeMpuPll (
- UINTN Multiplier
- );
- VOID
- EfipAm335InitializeCorePll (
- VOID
- );
- VOID
- EfipAm335InitializePerPll (
- VOID
- );
- VOID
- EfipAm335InitializeDdrPll (
- UINTN Multiplier
- );
- VOID
- EfipAm335InitializeDisplayPll (
- VOID
- );
- VOID
- EfipAm335InitializeInterfaceClocks (
- VOID
- );
- VOID
- EfipAm335InitializePowerDomainTransition (
- VOID
- );
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // ------------------------------------------------------------------ Functions
- //
- VOID
- EfipAm335InitializeClocks (
- VOID
- )
- /*++
- Routine Description:
- This routine initializes functional clocks for needed modules and domains.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- {
- UINT32 Value;
- //
- // Enable the L3 clock.
- //
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_CLOCK_CONTROL);
- Value |= AM335_CM_PER_L3_CLOCK_ENABLE;
- AM3_CM_PER_WRITE(AM335_CM_PER_L3_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_CLOCK_CONTROL);
- } while ((Value & AM335_CM_PER_L3_CLOCK_MODE_MASK) !=
- AM335_CM_PER_L3_CLOCK_ENABLE);
- //
- // Enable the L3 instr clock.
- //
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_INSTR_CLOCK_CONTROL);
- Value |= AM335_CM_PER_L3_INSTR_CLOCK_ENABLE;
- AM3_CM_PER_WRITE(AM335_CM_PER_L3_INSTR_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_INSTR_CLOCK_CONTROL);
- } while ((Value & AM335_CM_PER_L3_INSTR_CLOCK_MODE_MASK) !=
- AM335_CM_PER_L3_INSTR_CLOCK_ENABLE);
- //
- // Force a software wakeup of the L3 clock.
- //
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_CLOCK_STATE_CONTROL);
- Value |= AM335_CM_PER_L3_CLOCK_STATE_SOFTWARE_WAKEUP;
- AM3_CM_PER_WRITE(AM335_CM_PER_L3_CLOCK_STATE_CONTROL, Value);
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_PER_L3_CLOCK_STATE_TRANSITION_MASK) !=
- AM335_CM_PER_L3_CLOCK_STATE_SOFTWARE_WAKEUP);
- //
- // Force a software wakeup of the OCPWP L3 clock.
- //
- Value = AM3_CM_PER_READ(AM335_CM_PER_OCPWP_L3_CLOCK_STATE_CONTROL);
- Value |= AM335_CM_PER_OCPWP_L3_CLOCK_STATE_SOFTWARE_WAKEUP;
- AM3_CM_PER_WRITE(AM335_CM_PER_OCPWP_L3_CLOCK_STATE_CONTROL, Value);
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_OCPWP_L3_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_PER_OCPWP_L3_CLOCK_STATE_TRANSITION_MASK) !=
- AM335_CM_PER_OCPWP_L3_CLOCK_STATE_SOFTWARE_WAKEUP);
- //
- // Force a software wakeup of the L3S clock.
- //
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3S_CLOCK_STATE_CONTROL);
- Value |= AM335_CM_PER_L3S_CLOCK_STATE_SOFTWARE_WAKEUP;
- AM3_CM_PER_WRITE(AM335_CM_PER_L3S_CLOCK_STATE_CONTROL, Value);
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3S_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_PER_L3S_CLOCK_STATE_TRANSITION_MASK) !=
- AM335_CM_PER_L3S_CLOCK_STATE_SOFTWARE_WAKEUP);
- //
- // Wait for the idle state in the L3 clock control.
- //
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_CLOCK_CONTROL);
- } while ((Value & AM335_CM_PER_L3_CLOCK_IDLE_STATE_MASK) !=
- AM335_CM_PER_L3_CLOCK_IDLE_STATE_FUNCTIONAL);
- //
- // Wait for the idle state in the L3 instr clock control.
- //
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_INSTR_CLOCK_CONTROL);
- } while ((Value & AM335_CM_PER_L3_INSTR_CLOCK_IDLE_STATE_MASK) !=
- AM335_CM_PER_L3_INSTR_CLOCK_IDLE_STATE_FUNCTIONAL);
- //
- // Wait for the L3 clock to become active.
- //
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_PER_L3_CLOCK_STATE_ACTIVE) == 0);
- //
- // Wait for the OCPWP L3 clock to become active.
- //
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_OCPWP_L3_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_PER_OCPWP_L3_CLOCK_STATE_ACTIVE) == 0);
- //
- // Wait for the L3S clock to become active.
- //
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3S_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_PER_L3S_CLOCK_STATE_ACTIVE) == 0);
- //
- // Enable the wakeup region.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CONTROL_CLOCK_CONTROL);
- Value |= AM335_CM_WAKEUP_CONTROL_CLOCK_ENABLE;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CONTROL_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CONTROL_CLOCK_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_CONTROL_CLOCK_MODE_MASK) !=
- AM335_CM_WAKEUP_CONTROL_CLOCK_ENABLE);
- //
- // Force a software wakeup of the CM wakeup clock.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_STATE_CONTROL);
- Value |= AM335_CM_WAKEUP_CLOCK_STATE_SOFTWARE_WAKEUP;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_STATE_CONTROL, Value);
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_CLOCK_STATE_TRANSITION_MASK) !=
- AM335_CM_WAKEUP_CLOCK_STATE_SOFTWARE_WAKEUP);
- //
- // Force a software wakeup of the CM L3 Always On clock.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_L3_AON_CLOCK_STATE_CONTROL);
- Value |= AM335_CM_WAKEUP_L3_AON_CLOCK_STATE_SOFTWARE_WAKEUP;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_L3_AON_CLOCK_STATE_CONTROL, Value);
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_L3_AON_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_L3_AON_CLOCK_STATE_TRANSITION_MASK) !=
- AM335_CM_WAKEUP_L3_AON_CLOCK_STATE_SOFTWARE_WAKEUP);
- //
- // Enable UART0.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_UART0_CLOCK_CONTROL);
- Value |= AM335_CM_WAKEUP_UART0_CONTROL_CLOCK_ENABLE;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_UART0_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_UART0_CLOCK_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_UART0_CLOCK_MODE_MASK) !=
- AM335_CM_WAKEUP_UART0_CONTROL_CLOCK_ENABLE);
- //
- // Enable I2C0.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_I2C0_CLOCK_CONTROL);
- Value |= AM335_CM_WAKEUP_I2C0_CONTROL_CLOCK_ENABLE;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_I2C0_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_I2C0_CLOCK_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_I2C0_CLOCK_MODE_MASK) !=
- AM335_CM_WAKEUP_I2C0_CONTROL_CLOCK_ENABLE);
- //
- // Wait for the idle state in the CM wakeup control clock.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CONTROL_CLOCK_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_CONTROL_CLOCK_IDLE_STATE_MASK) !=
- AM335_CM_WAKEUP_CONTROL_CLOCK_IDLE_STATE_FUNCTIONAL);
- //
- // Wait for the L3 Always On clock to become active.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_L3_AON_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_L3_AON_CLOCK_STATE_ACTIVE) == 0);
- //
- // Wait for the L4 wakeup clock transition to become idle.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_L4WKUP_CLOCK_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_L4WKUP_CLOCK_IDLE_STATE_MASK) !=
- AM335_CM_WAKEUP_L4WKUP_CLOCK_IDLE_STATE_FUNCTIONAL);
- //
- // Wait for the L4 wakeup clock to become active.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_CLOCK_STATE_L4WAKEUP_ACTIVE) == 0);
- //
- // Wait for the L4 wakeup always on clock to become active.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(
- AM335_CM_WAKEUP_L4WKUP_AON_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_L4WKUP_AON_CLOCK_STATE_ACTIVE) == 0);
- //
- // Wait for the UART0 clock to become enabled.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_CLOCK_STATE_UART0_ACTIVE) == 0);
- //
- // Wait for the I2C0 clock to become enabled.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_STATE_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_CLOCK_STATE_I2C0_ACTIVE) == 0);
- //
- // Wait for the UART clock to become idle.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_UART0_CLOCK_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_UART0_CLOCK_IDLE_STATE_MASK) !=
- AM335_CM_WAKEUP_UART0_CLOCK_IDLE_STATE_FUNCTIONAL);
- //
- // Wait for the I2C clock to become idle.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_I2C0_CLOCK_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_I2C0_CLOCK_IDLE_STATE_MASK) !=
- AM335_CM_WAKEUP_I2C0_CLOCK_IDLE_STATE_FUNCTIONAL);
- return;
- }
- VOID
- EfipAm335InitializePlls (
- UINT32 OppIndex,
- UINT32 DdrFrequencyMultiplier
- )
- /*++
- Routine Description:
- This routine initializes the PLLs for the AM335x.
- Arguments:
- OppIndex - Supplies the index into the operating conditions table that the
- PLLs should be configured for.
- DdrFrequencyMultiplier - Supplies the multiplier value to initialize the
- DDR PLL with (depends on whether DDR2 or DDR3 is in use).
- Return Value:
- None.
- --*/
- {
- EfipAm335InitializeMpuPll(EfiAm335OppTable[OppIndex].PllMultiplier);
- EfipAm335InitializeCorePll();
- EfipAm335InitializePerPll();
- EfipAm335InitializeDdrPll(DdrFrequencyMultiplier);
- EfipAm335InitializeInterfaceClocks();
- EfipAm335InitializeDisplayPll();
- return;
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
- VOID
- EfipAm335InitializeMpuPll (
- UINTN Multiplier
- )
- /*++
- Routine Description:
- This routine initializes the MPU PLL.
- Arguments:
- Multiplier - Supplies the multiplier value for the PLL.
- Return Value:
- None.
- --*/
- {
- UINT32 Value;
- //
- // Put the PLL in bypass mode.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_MPU) &
- ~AM335_CM_WAKEUP_CLOCK_MODE_DPLL_MPU_ENABLE;
- Value |= AM335_CM_WAKEUP_CLOCK_MODE_DPLL_MPU_ENABLE_MN_BYPASS;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_MPU, Value);
- //
- // Wait for the PLL to go into bypass mode.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_IDLE_STATUS_DPLL_MPU);
- } while ((Value & AM335_CM_WAKEUP_IDLE_STATUS_DPLL_MPU_MN_BYPASS) == 0);
- //
- // Clear the multiplier and divisor fields.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_MPU);
- Value &= ~(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_MPU_MULT_MASK |
- AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_MPU_DIV_MASK);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_MPU, Value);
- //
- // Set the new multiplier and divisor.
- //
- Value |= (Multiplier << AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_MPU_MULT_SHIFT) |
- (AM335_MPU_PLL_N <<
- AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_MPU_DIV_SHIFT);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_MPU, Value);
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_DIV_M2_DPLL_MPU);
- Value &= ~(AM335_CM_WAKEUP_DIV_M2_DPLL_MPU_CLOCK_OUT_MASK);
- Value |= AM335_MPU_PLL_M2;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_DIV_M2_DPLL_MPU, Value);
- //
- // Enable and lock the PLL.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_MPU);
- Value |= AM335_CM_WAKEUP_CLOCK_MODE_DPLL_MPU_ENABLE;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_MPU, Value);
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_IDLE_STATUS_DPLL_MPU);
- } while ((Value & AM335_CM_WAKEUP_IDLE_STATUS_DPLL_MPU_CLOCK) == 0);
- return;
- }
- VOID
- EfipAm335InitializeCorePll (
- VOID
- )
- /*++
- Routine Description:
- This routine initializes the Core PLL.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- {
- UINT32 Value;
- //
- // Put the PLL in bypass mode.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_CORE) &
- ~AM335_CM_WAKEUP_CLOCK_MODE_DPLL_CORE_ENABLE;
- Value |= AM335_CM_WAKEUP_CLOCK_MODE_DPLL_CORE_ENABLE_MN_BYPASS;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_CORE, Value);
- //
- // Wait for the PLL to go into bypass mode.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_IDLE_STATUS_DPLL_CORE);
- } while ((Value & AM335_CM_WAKEUP_IDLE_STATUS_DPLL_CORE_MN_BYPASS) == 0);
- //
- // Set the multiplier and divisor.
- //
- Value = (AM335_CORE_PLL_M <<
- AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_CORE_MULT_SHIFT) |
- (AM335_CORE_PLL_N <<
- AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_CORE_DIV_SHIFT);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_CORE, Value);
- //
- // Configure the high speed divisors. Start with the M4 divisor.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_DIV_M4_DPLL_CORE);
- Value &= ~AM335_CM_WAKEUP_DIV_M4_DPLL_CORE_HSDIVIDER_CLOCK_OUT1_DIV_MASK;
- Value |= (AM335_CORE_PLL_HSDIVIDER_M4 <<
- AM335_CM_WAKEUP_DIV_M4_DPLL_CORE_HSDIVIDER_CLOCK_OUT1_DIV_SHIFT);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_DIV_M4_DPLL_CORE, Value);
- //
- // Set the M5 divisor.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_DIV_M5_DPLL_CORE);
- Value &= ~AM335_CM_WAKEUP_DIV_M5_DPLL_CORE_HSDIVIDER_CLOCK_OUT2_DIV_MASK;
- Value |= (AM335_CORE_PLL_HSDIVIDER_M5 <<
- AM335_CM_WAKEUP_DIV_M5_DPLL_CORE_HSDIVIDER_CLOCK_OUT2_DIV_SHIFT);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_DIV_M5_DPLL_CORE, Value);
- //
- // Set the M6 divisor.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_DIV_M6_DPLL_CORE);
- Value &= ~AM335_CM_WAKEUP_DIV_M6_DPLL_CORE_HSDIVIDER_CLOCK_OUT3_DIV_MASK;
- Value |= (AM335_CORE_PLL_HSDIVIDER_M6 <<
- AM335_CM_WAKEUP_DIV_M6_DPLL_CORE_HSDIVIDER_CLOCK_OUT3_DIV_SHIFT);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_DIV_M6_DPLL_CORE, Value);
- //
- // Enable and lock the PLL.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_CORE);
- Value |= AM335_CM_WAKEUP_CLOCK_MODE_DPLL_CORE_ENABLE;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_CORE, Value);
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_IDLE_STATUS_DPLL_CORE);
- } while ((Value & AM335_CM_WAKEUP_IDLE_STATUS_DPLL_CORE_CLOCK) == 0);
- return;
- }
- VOID
- EfipAm335InitializePerPll (
- VOID
- )
- /*++
- Routine Description:
- This routine initializes the Peripheral PLL.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- {
- UINT32 Value;
- //
- // Put the PLL in bypass mode.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_PER) &
- ~AM335_CM_WAKEUP_CLOCK_MODE_DPLL_PER_ENABLE;
- Value |= AM335_CM_WAKEUP_CLOCK_MODE_DPLL_PER_ENABLE_MN_BYPASS;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_PER, Value);
- //
- // Wait for the PLL to go into bypass mode.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_IDLE_STATUS_DPLL_PER);
- } while ((Value & AM335_CM_WAKEUP_IDLE_STATUS_DPLL_PER_MN_BYPASS) == 0);
- //
- // Set the multiplier and divisor.
- //
- Value = (AM335_PER_PLL_M <<
- AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_PER_MULT_SHIFT) |
- (AM335_PER_PLL_N <<
- AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_PER_DIV_SHIFT);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_PER, Value);
- //
- // Set the M2 divisor.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_DIV_M2_DPLL_PER);
- Value &= ~AM335_CM_WAKEUP_DIV_M2_DPLL_PER_CLOCK_OUT_DIV_MASK;
- Value |= (AM335_PER_PLL_M2 <<
- AM335_CM_WAKEUP_DIV_M2_DPLL_PER_CLOCK_OUT_DIV_SHIFT);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_DIV_M2_DPLL_PER, Value);
- //
- // Enable and lock the PLL.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_PER);
- Value |= AM335_CM_WAKEUP_CLOCK_MODE_DPLL_PER_ENABLE;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_PER, Value);
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_IDLE_STATUS_DPLL_PER);
- } while ((Value & AM335_CM_WAKEUP_IDLE_STATUS_DPLL_PER_CLOCK) == 0);
- return;
- }
- VOID
- EfipAm335InitializeDdrPll (
- UINTN Multiplier
- )
- /*++
- Routine Description:
- This routine initializes the DDR PLL.
- Arguments:
- Multiplier - Supplies the multiplier value for the PLL.
- Return Value:
- None.
- --*/
- {
- UINT32 Value;
- //
- // Put the PLL in bypass mode.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DDR) &
- ~AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DDR_ENABLE;
- Value |= AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DDR_ENABLE_MN_BYPASS;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DDR, Value);
- //
- // Wait for the PLL to go into bypass mode.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_IDLE_STATUS_DPLL_DDR);
- } while ((Value & AM335_CM_WAKEUP_IDLE_STATUS_DPLL_DDR_MN_BYPASS) == 0);
- //
- // Clear the multiplier and divisor fields.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DDR);
- Value &= ~(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DDR_MULT_MASK |
- AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DDR_DIV_MASK);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DDR, Value);
- //
- // Set the new multiplier and divisor.
- //
- Value |= (Multiplier << AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DDR_MULT_SHIFT) |
- (AM335_DDR_PLL_N <<
- AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DDR_DIV_SHIFT);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DDR, Value);
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_DIV_M2_DPLL_DDR);
- Value &= ~(AM335_CM_WAKEUP_DIV_M2_DPLL_DDR_CLOCK_OUT_MASK);
- Value |= AM335_DDR_PLL_M2;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_DIV_M2_DPLL_DDR, Value);
- //
- // Enable and lock the PLL.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DDR);
- Value |= AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DDR_ENABLE;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DDR, Value);
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_IDLE_STATUS_DPLL_DDR);
- } while ((Value & AM335_CM_WAKEUP_IDLE_STATUS_DPLL_DDR_CLOCK) == 0);
- return;
- }
- VOID
- EfipAm335InitializeDisplayPll (
- VOID
- )
- /*++
- Routine Description:
- This routine initializes the Display PLL.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- {
- UINT32 Value;
- //
- // Put the PLL in bypass mode.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DISP) &
- ~AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DISP_ENABLE;
- Value |= AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DISP_ENABLE_MN_BYPASS;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DISP, Value);
- //
- // Wait for the PLL to go into bypass mode.
- //
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_IDLE_STATUS_DPLL_DISP);
- } while ((Value & AM335_CM_WAKEUP_IDLE_STATUS_DPLL_DISP_MN_BYPASS) == 0);
- //
- // Clear the multiplier and divisor fields.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DISP);
- Value &= ~(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DISP_MULT_MASK |
- AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DISP_DIV_MASK);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DISP, Value);
- //
- // Set the new multiplier and divisor.
- //
- Value |= (AM335_DISP_PLL_M <<
- AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DISP_MULT_SHIFT) |
- (AM335_DISP_PLL_N <<
- AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DISP_DIV_SHIFT);
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_SELECT_DPLL_DISP, Value);
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_DIV_M2_DPLL_DISP);
- Value &= ~(AM335_CM_WAKEUP_DIV_M2_DPLL_DISP_CLOCK_OUT_MASK);
- Value |= AM335_DISP_PLL_M2;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_DIV_M2_DPLL_DISP, Value);
- //
- // Enable and lock the PLL.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DISP);
- Value |= AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DISP_ENABLE;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_MODE_DPLL_DISP, Value);
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_IDLE_STATUS_DPLL_DISP);
- } while ((Value & AM335_CM_WAKEUP_IDLE_STATUS_DPLL_DISP_CLOCK) == 0);
- return;
- }
- VOID
- EfipAm335InitializeInterfaceClocks (
- VOID
- )
- /*++
- Routine Description:
- This routine fires up the needed interface clocks around the SoC.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- {
- UINT32 Value;
- //
- // Some of these interfaces have already been initialized getting the UART
- // and LEDs running, but it's nice to have these all in once place.
- //
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_CLOCK_CONTROL);
- Value |= AM335_CM_PER_L3_CLOCK_ENABLE;
- AM3_CM_PER_WRITE(AM335_CM_PER_L3_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_CLOCK_CONTROL);
- } while ((Value & AM335_CM_PER_L3_CLOCK_MODE_MASK) !=
- AM335_CM_PER_L3_CLOCK_ENABLE);
- Value = AM3_CM_PER_READ(AM335_CM_PER_L4LS_CLOCK_CONTROL);
- Value |= AM335_CM_PER_L4LS_CLOCK_ENABLE;
- AM3_CM_PER_WRITE(AM335_CM_PER_L4LS_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L4LS_CLOCK_CONTROL);
- } while ((Value & AM335_CM_PER_L4LS_CLOCK_MODE_MASK) !=
- AM335_CM_PER_L4LS_CLOCK_ENABLE);
- Value = AM3_CM_PER_READ(AM335_CM_PER_L4FW_CLOCK_CONTROL);
- Value |= AM335_CM_PER_L4FW_CLOCK_ENABLE;
- AM3_CM_PER_WRITE(AM335_CM_PER_L4FW_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L4FW_CLOCK_CONTROL);
- } while ((Value & AM335_CM_PER_L4FW_CLOCK_MODE_MASK) !=
- AM335_CM_PER_L4FW_CLOCK_ENABLE);
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_L4WKUP_CLOCK_CONTROL);
- Value |= AM335_CM_WAKEUP_L4FW_CLOCK_ENABLE;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_L4WKUP_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_L4WKUP_CLOCK_CONTROL);
- } while ((Value & AM335_CM_WAKEUP_L4FW_CLOCK_MODE_MASK) !=
- AM335_CM_WAKEUP_L4FW_CLOCK_ENABLE);
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_INSTR_CLOCK_CONTROL);
- Value |= AM335_CM_PER_L3_INSTR_CLOCK_ENABLE;
- AM3_CM_PER_WRITE(AM335_CM_PER_L3_INSTR_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_INSTR_CLOCK_CONTROL);
- } while ((Value & AM335_CM_PER_L3_INSTR_CLOCK_MODE_MASK) !=
- AM335_CM_PER_L3_INSTR_CLOCK_ENABLE);
- Value = AM3_CM_PER_READ(AM335_CM_PER_L4HS_CLOCK_CONTROL);
- Value |= AM335_CM_PER_L4HS_CLOCK_ENABLE;
- AM3_CM_PER_WRITE(AM335_CM_PER_L4HS_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_L4HS_CLOCK_CONTROL);
- } while ((Value & AM335_CM_PER_L4HS_CLOCK_MODE_MASK) !=
- AM335_CM_PER_L4FW_CLOCK_ENABLE);
- //
- // Enable USB clocks.
- //
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_DCO_LDO_DPLL_PER);
- Value |= AM335_CM_WAKEUP_DCO_LDO_PER_DPLL_GATE_CONTROL;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_DCO_LDO_DPLL_PER, Value);
- Value = AM3_CM_PER_READ(AM335_CM_PER_USB0_CLOCK_CONTROL);
- Value |= AM335_CM_PER_USB0_CLOCK_ENABLE;
- AM3_CM_PER_WRITE(AM335_CM_PER_USB0_CLOCK_CONTROL, Value);
- do {
- Value = AM3_CM_PER_READ(AM335_CM_PER_USB0_CLOCK_CONTROL);
- } while ((Value & AM335_CM_PER_USB0_CLOCK_MODE_MASK) !=
- AM335_CM_PER_USB0_CLOCK_ENABLE);
- return;
- }
- VOID
- EfipAm335InitializePowerDomainTransition (
- VOID
- )
- /*++
- Routine Description:
- This routine performs clock wakeups for needed modules.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- {
- UINT32 Value;
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3_CLOCK_STATE_CONTROL);
- Value |= AM335_CM_PER_L3_CLOCK_STATE_SOFTWARE_WAKEUP;
- AM3_CM_PER_WRITE(AM335_CM_PER_L3_CLOCK_STATE_CONTROL, Value);
- Value = AM3_CM_PER_READ(AM335_CM_PER_L4LS_CLOCK_STATE_CONTROL);
- Value |= AM335_CM_PER_L4LS_CLOCK_STATE_SOFTWARE_WAKEUP;
- AM3_CM_PER_WRITE(AM335_CM_PER_L4LS_CLOCK_STATE_CONTROL, Value);
- Value = AM3_CM_WAKEUP_READ(AM335_CM_WAKEUP_CLOCK_STATE_CONTROL);
- Value |= AM335_CM_WAKEUP_CLOCK_STATE_SOFTWARE_WAKEUP;
- AM3_CM_WAKEUP_WRITE(AM335_CM_WAKEUP_CLOCK_STATE_CONTROL, Value);
- Value = AM3_CM_PER_READ(AM335_CM_PER_L4FW_CLOCK_STATE_CONTROL);
- Value |= AM335_CM_PER_L4FW_CLOCK_STATE_SOFTWARE_WAKEUP;
- AM3_CM_PER_WRITE(AM335_CM_PER_L4FW_CLOCK_STATE_CONTROL, Value);
- Value = AM3_CM_PER_READ(AM335_CM_PER_L3S_CLOCK_STATE_CONTROL);
- Value |= AM335_CM_PER_L3S_CLOCK_STATE_SOFTWARE_WAKEUP;
- AM3_CM_PER_WRITE(AM335_CM_PER_L3S_CLOCK_STATE_CONTROL, Value);
- return;
- }
|