龙芯显控手册:
注意事项:
操作的时钟寄存器:
#define LS2K_PIX0_PLL (0xffffffffbfe104b0)
#define LS2K_PIX1_PLL (0xffffffffbfe104c0)
/*********************************************************************************************************
** 函数名称: __ls2xCalFreq
** 功能描述: 计算时钟寄存器的值
** 输 入 : uiPixClock 刷新频率
** pllConfig pll配置值
** 输 出 : ERROR CODE
** 全局变量:
** 调用模块:
*********************************************************************************************************/
static UINT __ls2xCalFreq (UINT uiPixClock, __LS2X_PIX_PLL_HANDLE hPllCfg)
{
UINT uiDiv, uiLoop, uiFre;
UINT uiTa, uiTb, uiTc;
UINT uiMin = 1000;
for (uiDiv = 1; uiDiv < 64; uiDiv++) {
uiTa = (UINT)uiPixClock * uiDiv;
for (uiFre = 3; uiFre < 6; uiFre++) {
for (uiLoop = 24; uiLoop < 161; uiLoop++) {
if ((uiLoop < 12 * uiFre) || (uiLoop > 32 * uiFre)) {
continue;
}
uiTb = 100000L * uiLoop / uiFre;
uiTc = (uiTa > uiTb) ? (uiTa - uiTb) : (uiTb - uiTa);
if (uiTc < uiMin) {
hPllCfg->LS2XPIXPLL_uiDiv = uiDiv;
hPllCfg->LS2XPIXPLL_uiLoop = uiLoop;
hPllCfg->LS2XPIXPLL_uiFre = uiFre;
return (PX_ERROR);
}
}
}
}
return (ERROR_NONE);
}
/*********************************************************************************************************
** 函数名称: __ls2xConfigPll
** 功能描述: 配置时钟寄存器
** 输 入 : ullPllBase 时钟寄存器基址
** pllCfg 配置值
** 输 出 : NONE
** 全局变量:
** 调用模块:
*********************************************************************************************************/
static VOID __ls2xConfigPll (UINT64 ullPllBase, __LS2X_PIX_PLL_HANDLE hPllCfg)
{
UINT64 ui64out;
UINT64 ui64Loop;
UINT64 ui64Fre;
UINT64 ui64Tmp = 1;
#define __LS2X_LO_OFF (0)
#define __LS2X_HI_OFF (8)
ui64Loop = hPllCfg->LS2XPIXPLL_uiLoop;
ui64Fre = hPllCfg->LS2XPIXPLL_uiFre;
ui64out = (1 << 7) | (ui64Tmp << 42) | (3 << 10) |
((UINT64)(ui64Loop) << 32) |
((UINT64)(ui64Fre) << 26);
write64(0, ullPllBase + __LS2X_LO_OFF);
write64(1 << 19, ullPllBase + __LS2X_LO_OFF);
write64(ui64out, ullPllBase + __LS2X_LO_OFF);
write64(hPllCfg->LS2XPIXPLL_uiDiv, ullPllBase + __LS2X_HI_OFF);
ui64out = (ui64out | (1 << 2));
write64(ui64out, ullPllBase + __LS2X_LO_OFF);
while (!(read64(ullPllBase + __LS2X_LO_OFF) & 0x10000)) ;
write64((ui64out | 1), ullPllBase + __LS2X_LO_OFF);
}
uiPixFreq = __LS2X_PICOS2KHZ(hLcdPanel->uiPixelClk);
uiRet = __ls2xCalFreq(uiPixFreq, &hPllCfg);
if (uiRet) {
__ls2xConfigPll(LS2K_PIX0_PLL, &hPllCfg);
__ls2xConfigPll(LS2K_PIX1_PLL, &hPllCfg);
}