Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devices: MIMX8ML8: fixes for clock gating/ungating #229

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions devices/MIMX8ML8/drivers/fsl_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,25 +920,27 @@ void CLOCK_EnableClock(clock_ip_name_t ccmGate)
{
uint32_t clockType = CLOCK_GATE_TYPE(ccmGate);
uint32_t ccgr = CCM_TUPLE_CCGR(ccmGate);
uint32_t rootClk = 0U;
uint32_t rootClk = 0U;
uint32_t rootClkId = 0U;

if (CLOCK_GATE_IN_AUDIOMIX == clockType)
{
uint32_t offset = AUDIOMIX_TUPLE_OFFSET(ccmGate);
uint32_t gate = AUDIOMIX_TUPLE_GATE(ccmGate);
rootClk = AUDIOMIX_TUPLE_ROOT(ccmGate);
rootClkId = AUDIOMIX_TUPLE_ROOT_ID(ccmGate);

*(volatile uint32_t *)((uintptr_t)AUDIOMIX + offset) |= (uint32_t)1U << gate;
}
else
{
CCM_REG_SET(ccgr) = (uint32_t)kCLOCK_ClockNeededAll;
rootClk = CCM_TUPLE_ROOT(ccmGate);
rootClkId = CCM_TUPLE_ROOT_ID(ccmGate);
}

/* if root clock is 0xFFFFU, then skip enable root clock */
if (rootClk != 0xFFFFU)
if (rootClkId != 0xFFFFU)
{
rootClk = CCM_TUPLE_ROOT(rootClkId);
CCM_REG_SET(rootClk) = CCM_TARGET_ROOT_SET_ENABLE_MASK;
}
}
Expand All @@ -957,24 +959,26 @@ void CLOCK_DisableClock(clock_ip_name_t ccmGate)
uint32_t ccgr = CCM_TUPLE_CCGR(ccmGate);
uint32_t clockType = CLOCK_GATE_TYPE(ccmGate);
uint32_t rootClk = 0U;
uint32_t rootClkId = 0U;

if (CLOCK_GATE_IN_AUDIOMIX == clockType)
{
uint32_t offset = AUDIOMIX_TUPLE_OFFSET(ccmGate);
uint32_t gate = AUDIOMIX_TUPLE_GATE(ccmGate);
rootClk = AUDIOMIX_TUPLE_ROOT(ccmGate);
rootClkId = AUDIOMIX_TUPLE_ROOT_ID(ccmGate);

*(volatile uint32_t *)((uintptr_t)AUDIOMIX + offset) &= ~((uint32_t)1U << gate);
}
else
{
CCM_REG(ccgr) = (uint32_t)kCLOCK_ClockNotNeeded;
rootClk = CCM_TUPLE_ROOT(ccmGate);
rootClkId = CCM_TUPLE_ROOT(ccmGate);
}

/* if root clock is 0xFFFFU, then skip disable root clock */
if (rootClk != 0xFFFFU)
if (rootClkId != 0xFFFFU)
{
rootClk = CCM_TUPLE_ROOT(rootClkId);
CCM_REG_CLR(rootClk) = CCM_TARGET_ROOT_CLR_ENABLE_MASK;
}
}
7 changes: 4 additions & 3 deletions devices/MIMX8ML8/drivers/fsl_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,14 @@
#define CLOCK_GATE_TYPE(tuple) ((uint32_t)(tuple) >> 28U)
#define CCM_TUPLE(ccgr, root) ((((ccgr)&0xFFFFU) << 16U) | (root))
#define CCM_TUPLE_CCGR(tuple) ((uintptr_t)(&(CCM)->CCGR[(uint32_t)(tuple) >> 16U].CCGR))
#define CCM_TUPLE_ROOT(tuple) ((uintptr_t)(&(CCM)->ROOT[(uint32_t)(tuple)&0xFFFFU].TARGET_ROOT))
#define CCM_TUPLE_ROOT_ID(tuple) ((uint32_t)(tuple)&0xFFFFU)
#define CCM_TUPLE_ROOT(id) ((uintptr_t)(&(CCM)->ROOT[id].TARGET_ROOT))
/*!@brief audio mix CCGR */
#define AUDIOMIX_TUPLE(offset, gate, root) \
(((CLOCK_GATE_IN_AUDIOMIX) << 28U) | (((offset)&0xFU) << 24U) | (((gate)&0xFFU) << 16U) | ((root)&0xFFFFU))
#define AUDIOMIX_TUPLE_OFFSET(tuple) (((uint32_t)(tuple) >> 24U) & 0xFU)
#define AUDIOMIX_TUPLE_GATE(tuple) (((uint32_t)(tuple) >> 16U) & 0xFFU)
#define AUDIOMIX_TUPLE_ROOT(tuple) ((uint32_t)(tuple)&0xFFFFU)
#define AUDIOMIX_TUPLE_ROOT_ID(tuple) ((uint32_t)(tuple)&0xFFFFU)

/*!
* @brief clock root source
Expand Down Expand Up @@ -635,7 +636,7 @@ typedef enum _clock_ip_name
kCLOCK_Sai3_Mclk3 = AUDIOMIX_TUPLE(0U, 11U, 0xFFFF), /*!< SAI3 MCLK3 clock gate */
kCLOCK_Sai3_Mclk2 = AUDIOMIX_TUPLE(0U, 10U, 0xFFFF), /*!< SAI3 MCLK2 clock gate */
kCLOCK_Sai3_Mclk1 = AUDIOMIX_TUPLE(0U, 9U, 0xFFFF), /*!< SAI3 MCLK1 clock gate */
kCLOCK_Sai3 = AUDIOMIX_TUPLE(0U, 8U, 77U), /*!< SAI3 clock gate */
kCLOCK_Sai3 = AUDIOMIX_TUPLE(0U, 8U, 0xFFFF), /*!< SAI3 clock gate */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Laurentiu,

From RM, sai3's clock root id is 77, any reason to modify it to 0xFFFF? if it's 0xFFFF, it means that sai3 doesn't have clock root.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SAI3 (IPG)'s root is not SAI3_CLK_ROOT, but rather AUDIO_AHB_CLK_ROOT (34) so 77 is wrong.

We're setting it to 0xFFFF because we don't want CLOCK_EnableClock() and CLOCK_DisableClock() to touch AUDIO_AHB_CLK_ROOT as it's used by multiple SAI instances.


kCLOCK_Sai2_Mclk3 = AUDIOMIX_TUPLE(0U, 7U, 0xFFFF), /*!< SAI2 MCLK3 clock gate */
kCLOCK_Sai2_Mclk2 = AUDIOMIX_TUPLE(0U, 6U, 0xFFFF), /*!< SAI2 MCLK2 clock gate */
Expand Down