SYLIXOS 龙芯2K1000 LCD屏参配置(2)

这篇博客介绍了龙芯平台的时钟寄存器配置方法,包括`__ls2xCalFreq`函数用于计算时钟寄存器的值以及`__ls2xConfigPll`函数进行配置。通过遍历不同的分频因子、环路频率和时钟频率组合,找到最佳配置,并最终写入时钟寄存器。
摘要由CSDN通过智能技术生成

龙芯显控手册:

注意事项:

 操作的时钟寄存器:

 

#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);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值