2015-09-22 09:01:17 +00:00
|
|
|
#include <linux/sizes.h>
|
|
|
|
|
2015-03-03 10:51:06 +00:00
|
|
|
#include "ddk750_help.h"
|
|
|
|
#include "ddk750_reg.h"
|
|
|
|
#include "ddk750_chip.h"
|
|
|
|
#include "ddk750_power.h"
|
2015-03-26 17:09:13 +00:00
|
|
|
typedef struct _pllcalparam {
|
2015-03-03 10:51:06 +00:00
|
|
|
unsigned char power;/* d : 0~ 6*/
|
|
|
|
unsigned char pod;
|
|
|
|
unsigned char od;
|
|
|
|
unsigned char value;/* value of 2 power d (2^d) */
|
|
|
|
}
|
|
|
|
pllcalparam;
|
|
|
|
|
2015-03-11 16:11:00 +00:00
|
|
|
logical_chip_type_t getChipType(void)
|
2015-03-03 10:51:06 +00:00
|
|
|
{
|
|
|
|
unsigned short physicalID;
|
|
|
|
char physicalRev;
|
|
|
|
logical_chip_type_t chip;
|
|
|
|
|
2015-06-12 10:17:22 +00:00
|
|
|
physicalID = devId750; /* either 0x718 or 0x750 */
|
2015-03-03 10:51:06 +00:00
|
|
|
physicalRev = revId750;
|
|
|
|
|
2015-03-18 09:37:42 +00:00
|
|
|
if (physicalID == 0x718)
|
|
|
|
chip = SM718;
|
2015-03-26 17:09:14 +00:00
|
|
|
else if (physicalID == 0x750) {
|
2015-03-18 09:37:42 +00:00
|
|
|
chip = SM750;
|
2015-03-03 10:51:06 +00:00
|
|
|
/* SM750 and SM750LE are different in their revision ID only. */
|
2015-03-26 17:09:14 +00:00
|
|
|
if (physicalRev == SM750LE_REVISION_ID)
|
2015-03-03 10:51:06 +00:00
|
|
|
chip = SM750LE;
|
2015-03-26 17:09:14 +00:00
|
|
|
} else
|
2015-03-18 09:37:42 +00:00
|
|
|
chip = SM_UNKNOWN;
|
2015-03-03 10:51:06 +00:00
|
|
|
|
|
|
|
return chip;
|
|
|
|
}
|
|
|
|
|
2015-10-13 06:26:45 +00:00
|
|
|
static unsigned int get_mxclk_freq(void)
|
2015-03-03 10:51:06 +00:00
|
|
|
{
|
2015-10-13 06:26:44 +00:00
|
|
|
unsigned int pll_reg;
|
|
|
|
unsigned int M, N, OD, POD;
|
|
|
|
|
2015-03-26 17:09:16 +00:00
|
|
|
if (getChipType() == SM750LE)
|
2015-03-03 10:51:06 +00:00
|
|
|
return MHz(130);
|
|
|
|
|
2015-10-13 06:26:44 +00:00
|
|
|
pll_reg = PEEK32(MXCLK_PLL_CTRL);
|
|
|
|
M = FIELD_GET(pll_reg, PANEL_PLL_CTRL, M);
|
|
|
|
N = FIELD_GET(pll_reg, PANEL_PLL_CTRL, N);
|
|
|
|
OD = FIELD_GET(pll_reg, PANEL_PLL_CTRL, OD);
|
|
|
|
POD = FIELD_GET(pll_reg, PANEL_PLL_CTRL, POD);
|
|
|
|
|
|
|
|
return DEFAULT_INPUT_CLOCK * M / N / (1 << OD) / (1 << POD);
|
2015-03-03 10:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function set up the main chip clock.
|
|
|
|
*
|
|
|
|
* Input: Frequency to be set.
|
|
|
|
*/
|
2015-09-30 05:24:54 +00:00
|
|
|
static void setChipClock(unsigned int frequency)
|
2015-03-03 10:51:06 +00:00
|
|
|
{
|
2015-03-18 09:37:42 +00:00
|
|
|
pll_value_t pll;
|
|
|
|
unsigned int ulActualMxClk;
|
2015-03-03 10:51:06 +00:00
|
|
|
#if 1
|
2015-03-18 09:37:42 +00:00
|
|
|
/* Cheok_0509: For SM750LE, the chip clock is fixed. Nothing to set. */
|
|
|
|
if (getChipType() == SM750LE)
|
|
|
|
return;
|
2015-03-03 10:51:06 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-02 17:31:04 +00:00
|
|
|
if (frequency) {
|
2015-03-18 09:37:42 +00:00
|
|
|
/*
|
|
|
|
* Set up PLL, a structure to hold the value to be set in clocks.
|
|
|
|
*/
|
|
|
|
pll.inputFreq = DEFAULT_INPUT_CLOCK; /* Defined in CLOCK.H */
|
|
|
|
pll.clockType = MXCLK_PLL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call calcPllValue() to fill up the other fields for PLL structure.
|
|
|
|
* Sometime, the chip cannot set up the exact clock required by User.
|
|
|
|
* Return value from calcPllValue() gives the actual possible clock.
|
|
|
|
*/
|
|
|
|
ulActualMxClk = calcPllValue(frequency, &pll);
|
|
|
|
|
|
|
|
/* Master Clock Control: MXCLK_PLL */
|
|
|
|
POKE32(MXCLK_PLL_CTRL, formatPllReg(&pll));
|
|
|
|
}
|
2015-03-03 10:51:06 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 05:24:54 +00:00
|
|
|
static void setMemoryClock(unsigned int frequency)
|
2015-03-03 10:51:06 +00:00
|
|
|
{
|
2015-03-18 09:37:42 +00:00
|
|
|
unsigned int ulReg, divisor;
|
2015-03-03 10:51:06 +00:00
|
|
|
#if 1
|
|
|
|
/* Cheok_0509: For SM750LE, the memory clock is fixed. Nothing to set. */
|
|
|
|
if (getChipType() == SM750LE)
|
|
|
|
return;
|
|
|
|
#endif
|
2015-04-02 17:31:04 +00:00
|
|
|
if (frequency) {
|
2015-03-18 09:37:42 +00:00
|
|
|
/* Set the frequency to the maximum frequency that the DDR Memory can take
|
|
|
|
which is 336MHz. */
|
|
|
|
if (frequency > MHz(336))
|
|
|
|
frequency = MHz(336);
|
|
|
|
|
|
|
|
/* Calculate the divisor */
|
2015-10-13 06:26:45 +00:00
|
|
|
divisor = (unsigned int)roundedDiv(get_mxclk_freq(), frequency);
|
2015-03-18 09:37:42 +00:00
|
|
|
|
|
|
|
/* Set the corresponding divisor in the register. */
|
|
|
|
ulReg = PEEK32(CURRENT_GATE);
|
2015-03-26 17:09:17 +00:00
|
|
|
switch (divisor) {
|
2015-03-18 09:37:42 +00:00
|
|
|
default:
|
|
|
|
case 1:
|
|
|
|
ulReg = FIELD_SET(ulReg, CURRENT_GATE, M2XCLK, DIV_1);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ulReg = FIELD_SET(ulReg, CURRENT_GATE, M2XCLK, DIV_2);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ulReg = FIELD_SET(ulReg, CURRENT_GATE, M2XCLK, DIV_3);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
ulReg = FIELD_SET(ulReg, CURRENT_GATE, M2XCLK, DIV_4);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setCurrentGate(ulReg);
|
|
|
|
}
|
2015-03-03 10:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function set up the master clock (MCLK).
|
|
|
|
*
|
|
|
|
* Input: Frequency to be set.
|
|
|
|
*
|
|
|
|
* NOTE:
|
|
|
|
* The maximum frequency the engine can run is 168MHz.
|
|
|
|
*/
|
2015-09-30 05:24:54 +00:00
|
|
|
static void setMasterClock(unsigned int frequency)
|
2015-03-03 10:51:06 +00:00
|
|
|
{
|
2015-03-18 09:37:42 +00:00
|
|
|
unsigned int ulReg, divisor;
|
|
|
|
#if 1
|
2015-03-03 10:51:06 +00:00
|
|
|
/* Cheok_0509: For SM750LE, the memory clock is fixed. Nothing to set. */
|
|
|
|
if (getChipType() == SM750LE)
|
|
|
|
return;
|
|
|
|
#endif
|
2015-04-02 17:31:04 +00:00
|
|
|
if (frequency) {
|
2015-03-18 09:37:42 +00:00
|
|
|
/* Set the frequency to the maximum frequency that the SM750 engine can
|
|
|
|
run, which is about 190 MHz. */
|
|
|
|
if (frequency > MHz(190))
|
|
|
|
frequency = MHz(190);
|
|
|
|
|
|
|
|
/* Calculate the divisor */
|
2015-10-13 06:26:45 +00:00
|
|
|
divisor = (unsigned int)roundedDiv(get_mxclk_freq(), frequency);
|
2015-03-18 09:37:42 +00:00
|
|
|
|
|
|
|
/* Set the corresponding divisor in the register. */
|
|
|
|
ulReg = PEEK32(CURRENT_GATE);
|
2015-03-26 17:09:17 +00:00
|
|
|
switch (divisor) {
|
2015-03-18 09:37:42 +00:00
|
|
|
default:
|
|
|
|
case 3:
|
|
|
|
ulReg = FIELD_SET(ulReg, CURRENT_GATE, MCLK, DIV_3);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
ulReg = FIELD_SET(ulReg, CURRENT_GATE, MCLK, DIV_4);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
ulReg = FIELD_SET(ulReg, CURRENT_GATE, MCLK, DIV_6);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
ulReg = FIELD_SET(ulReg, CURRENT_GATE, MCLK, DIV_8);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setCurrentGate(ulReg);
|
|
|
|
}
|
2015-03-03 10:51:06 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 16:11:00 +00:00
|
|
|
unsigned int ddk750_getVMSize(void)
|
2015-03-03 10:51:06 +00:00
|
|
|
{
|
|
|
|
unsigned int reg;
|
|
|
|
unsigned int data;
|
|
|
|
|
|
|
|
/* sm750le only use 64 mb memory*/
|
2015-03-26 17:09:16 +00:00
|
|
|
if (getChipType() == SM750LE)
|
2015-09-22 09:01:17 +00:00
|
|
|
return SZ_64M;
|
2015-03-03 10:51:06 +00:00
|
|
|
|
|
|
|
/* for 750,always use power mode0*/
|
|
|
|
reg = PEEK32(MODE0_GATE);
|
2015-03-26 17:09:18 +00:00
|
|
|
reg = FIELD_SET(reg, MODE0_GATE, GPIO, ON);
|
|
|
|
POKE32(MODE0_GATE, reg);
|
2015-03-03 10:51:06 +00:00
|
|
|
|
|
|
|
/* get frame buffer size from GPIO */
|
2015-03-26 17:09:18 +00:00
|
|
|
reg = FIELD_GET(PEEK32(MISC_CTRL), MISC_CTRL, LOCALMEM_SIZE);
|
2015-03-26 17:09:17 +00:00
|
|
|
switch (reg) {
|
2015-03-26 17:09:19 +00:00
|
|
|
case MISC_CTRL_LOCALMEM_SIZE_8M:
|
2015-09-22 09:01:17 +00:00
|
|
|
data = SZ_8M; break; /* 8 Mega byte */
|
2015-03-26 17:09:19 +00:00
|
|
|
case MISC_CTRL_LOCALMEM_SIZE_16M:
|
2015-09-22 09:01:17 +00:00
|
|
|
data = SZ_16M; break; /* 16 Mega byte */
|
2015-03-26 17:09:19 +00:00
|
|
|
case MISC_CTRL_LOCALMEM_SIZE_32M:
|
2015-09-22 09:01:17 +00:00
|
|
|
data = SZ_32M; break; /* 32 Mega byte */
|
2015-03-26 17:09:19 +00:00
|
|
|
case MISC_CTRL_LOCALMEM_SIZE_64M:
|
2015-09-22 09:01:17 +00:00
|
|
|
data = SZ_64M; break; /* 64 Mega byte */
|
2015-03-26 17:09:19 +00:00
|
|
|
default:
|
2015-04-02 17:27:55 +00:00
|
|
|
data = 0;
|
|
|
|
break;
|
2015-03-03 10:51:06 +00:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2015-03-26 17:09:20 +00:00
|
|
|
int ddk750_initHw(initchip_param_t *pInitParam)
|
2015-03-03 10:51:06 +00:00
|
|
|
{
|
|
|
|
unsigned int ulReg;
|
|
|
|
|
2015-07-15 04:14:32 +00:00
|
|
|
if (pInitParam->powerMode != 0)
|
2015-03-03 10:51:06 +00:00
|
|
|
pInitParam->powerMode = 0;
|
|
|
|
setPowerMode(pInitParam->powerMode);
|
|
|
|
|
|
|
|
/* Enable display power gate & LOCALMEM power gate*/
|
|
|
|
ulReg = PEEK32(CURRENT_GATE);
|
|
|
|
ulReg = FIELD_SET(ulReg, CURRENT_GATE, DISPLAY, ON);
|
2015-03-26 17:09:18 +00:00
|
|
|
ulReg = FIELD_SET(ulReg, CURRENT_GATE, LOCALMEM, ON);
|
2015-03-03 10:51:06 +00:00
|
|
|
setCurrentGate(ulReg);
|
|
|
|
|
2015-03-26 17:09:16 +00:00
|
|
|
if (getChipType() != SM750LE) {
|
2015-03-03 10:51:06 +00:00
|
|
|
/* set panel pll and graphic mode via mmio_88 */
|
|
|
|
ulReg = PEEK32(VGA_CONFIGURATION);
|
2015-03-26 17:09:18 +00:00
|
|
|
ulReg = FIELD_SET(ulReg, VGA_CONFIGURATION, PLL, PANEL);
|
|
|
|
ulReg = FIELD_SET(ulReg, VGA_CONFIGURATION, MODE, GRAPHIC);
|
|
|
|
POKE32(VGA_CONFIGURATION, ulReg);
|
2015-03-26 17:09:14 +00:00
|
|
|
} else {
|
2015-04-08 16:55:06 +00:00
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
2015-03-03 10:51:06 +00:00
|
|
|
/* set graphic mode via IO method */
|
2015-03-26 17:09:18 +00:00
|
|
|
outb_p(0x88, 0x3d4);
|
|
|
|
outb_p(0x06, 0x3d5);
|
2015-03-03 10:51:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the Main Chip Clock */
|
|
|
|
setChipClock(MHz((unsigned int)pInitParam->chipClock));
|
|
|
|
|
|
|
|
/* Set up memory clock. */
|
|
|
|
setMemoryClock(MHz(pInitParam->memClock));
|
|
|
|
|
|
|
|
/* Set up master clock */
|
|
|
|
setMasterClock(MHz(pInitParam->masterClock));
|
|
|
|
|
|
|
|
|
|
|
|
/* Reset the memory controller. If the memory controller is not reset in SM750,
|
|
|
|
the system might hang when sw accesses the memory.
|
|
|
|
The memory should be resetted after changing the MXCLK.
|
|
|
|
*/
|
2015-03-26 17:09:14 +00:00
|
|
|
if (pInitParam->resetMemory == 1) {
|
2015-03-03 10:51:06 +00:00
|
|
|
ulReg = PEEK32(MISC_CTRL);
|
|
|
|
ulReg = FIELD_SET(ulReg, MISC_CTRL, LOCALMEM_RESET, RESET);
|
|
|
|
POKE32(MISC_CTRL, ulReg);
|
|
|
|
|
|
|
|
ulReg = FIELD_SET(ulReg, MISC_CTRL, LOCALMEM_RESET, NORMAL);
|
|
|
|
POKE32(MISC_CTRL, ulReg);
|
|
|
|
}
|
|
|
|
|
2015-03-26 17:09:14 +00:00
|
|
|
if (pInitParam->setAllEngOff == 1) {
|
2015-03-03 10:51:06 +00:00
|
|
|
enable2DEngine(0);
|
|
|
|
|
|
|
|
/* Disable Overlay, if a former application left it on */
|
|
|
|
ulReg = PEEK32(VIDEO_DISPLAY_CTRL);
|
|
|
|
ulReg = FIELD_SET(ulReg, VIDEO_DISPLAY_CTRL, PLANE, DISABLE);
|
|
|
|
POKE32(VIDEO_DISPLAY_CTRL, ulReg);
|
|
|
|
|
|
|
|
/* Disable video alpha, if a former application left it on */
|
|
|
|
ulReg = PEEK32(VIDEO_ALPHA_DISPLAY_CTRL);
|
|
|
|
ulReg = FIELD_SET(ulReg, VIDEO_ALPHA_DISPLAY_CTRL, PLANE, DISABLE);
|
|
|
|
POKE32(VIDEO_ALPHA_DISPLAY_CTRL, ulReg);
|
|
|
|
|
|
|
|
/* Disable alpha plane, if a former application left it on */
|
|
|
|
ulReg = PEEK32(ALPHA_DISPLAY_CTRL);
|
|
|
|
ulReg = FIELD_SET(ulReg, ALPHA_DISPLAY_CTRL, PLANE, DISABLE);
|
|
|
|
POKE32(ALPHA_DISPLAY_CTRL, ulReg);
|
|
|
|
|
|
|
|
/* Disable DMA Channel, if a former application left it on */
|
|
|
|
ulReg = PEEK32(DMA_ABORT_INTERRUPT);
|
|
|
|
ulReg = FIELD_SET(ulReg, DMA_ABORT_INTERRUPT, ABORT_1, ABORT);
|
|
|
|
POKE32(DMA_ABORT_INTERRUPT, ulReg);
|
|
|
|
|
|
|
|
/* Disable DMA Power, if a former application left it on */
|
|
|
|
enableDMA(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can add more initialization as needed. */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
monk liu @ 4/6/2011:
|
|
|
|
re-write the calculatePLL function of ddk750.
|
|
|
|
the original version function does not use some mathematics tricks and shortcut
|
|
|
|
when it doing the calculation of the best N,M,D combination
|
|
|
|
I think this version gives a little upgrade in speed
|
|
|
|
|
|
|
|
750 pll clock formular:
|
|
|
|
Request Clock = (Input Clock * M )/(N * X)
|
|
|
|
|
|
|
|
Input Clock = 14318181 hz
|
|
|
|
X = 2 power D
|
|
|
|
D ={0,1,2,3,4,5,6}
|
|
|
|
M = {1,...,255}
|
|
|
|
N = {2,...,15}
|
|
|
|
*/
|
2015-03-26 17:09:18 +00:00
|
|
|
unsigned int calcPllValue(unsigned int request_orig, pll_value_t *pll)
|
2015-03-03 10:51:06 +00:00
|
|
|
{
|
|
|
|
/* used for primary and secondary channel pixel clock pll */
|
|
|
|
static pllcalparam xparm_PIXEL[] = {
|
2015-03-26 17:09:18 +00:00
|
|
|
/* 2^0 = 1*/ {0, 0, 0, 1},
|
|
|
|
/* 2^ 1 =2*/ {1, 0, 1, 2},
|
|
|
|
/* 2^ 2 = 4*/ {2, 0, 2, 4},
|
|
|
|
{3, 0, 3, 8},
|
|
|
|
{4, 1, 3, 16},
|
|
|
|
{5, 2, 3, 32},
|
|
|
|
/* 2^6 = 64 */ {6, 3, 3, 64},
|
2015-03-03 10:51:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* used for MXCLK (chip clock) */
|
|
|
|
static pllcalparam xparm_MXCLK[] = {
|
2015-03-26 17:09:18 +00:00
|
|
|
/* 2^0 = 1*/ {0, 0, 0, 1},
|
|
|
|
/* 2^ 1 =2*/ {1, 0, 1, 2},
|
|
|
|
/* 2^ 2 = 4*/ {2, 0, 2, 4},
|
|
|
|
{3, 0, 3, 8},
|
2015-03-03 10:51:06 +00:00
|
|
|
};
|
|
|
|
|
2015-03-18 09:37:42 +00:00
|
|
|
/* as sm750 register definition, N located in 2,15 and M located in 1,255 */
|
2015-03-26 17:09:18 +00:00
|
|
|
int N, M, X, d;
|
2015-03-03 10:51:06 +00:00
|
|
|
int xcnt;
|
2015-10-09 20:44:27 +00:00
|
|
|
int mini_diff;
|
2015-03-26 17:09:18 +00:00
|
|
|
unsigned int RN, quo, rem, fl_quo;
|
|
|
|
unsigned int input, request;
|
|
|
|
unsigned int tmpClock, ret;
|
2015-06-18 20:06:56 +00:00
|
|
|
pllcalparam *xparm;
|
2015-03-03 10:51:06 +00:00
|
|
|
|
|
|
|
#if 1
|
2015-03-26 17:09:14 +00:00
|
|
|
if (getChipType() == SM750LE) {
|
2015-03-18 09:37:42 +00:00
|
|
|
/* SM750LE don't have prgrammable PLL and M/N values to work on.
|
|
|
|
Just return the requested clock. */
|
|
|
|
return request_orig;
|
|
|
|
}
|
2015-03-03 10:51:06 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ret = 0;
|
2015-10-09 20:44:27 +00:00
|
|
|
mini_diff = ~0;
|
2015-03-03 10:51:06 +00:00
|
|
|
request = request_orig / 1000;
|
|
|
|
input = pll->inputFreq / 1000;
|
|
|
|
|
|
|
|
/* for MXCLK register , no POD provided, so need be treated differently */
|
|
|
|
|
2015-03-26 17:09:16 +00:00
|
|
|
if (pll->clockType != MXCLK_PLL) {
|
2015-03-03 10:51:06 +00:00
|
|
|
xparm = &xparm_PIXEL[0];
|
2015-10-08 19:25:17 +00:00
|
|
|
xcnt = ARRAY_SIZE(xparm_PIXEL);
|
2015-03-26 17:09:14 +00:00
|
|
|
} else {
|
2015-03-03 10:51:06 +00:00
|
|
|
xparm = &xparm_MXCLK[0];
|
2015-10-08 19:25:17 +00:00
|
|
|
xcnt = ARRAY_SIZE(xparm_MXCLK);
|
2015-03-03 10:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-26 17:09:15 +00:00
|
|
|
for (N = 15; N > 1; N--) {
|
2015-03-03 10:51:06 +00:00
|
|
|
/* RN will not exceed maximum long if @request <= 285 MHZ (for 32bit cpu) */
|
|
|
|
RN = N * request;
|
|
|
|
quo = RN / input;
|
|
|
|
rem = RN % input;/* rem always small than 14318181 */
|
2015-07-15 04:14:40 +00:00
|
|
|
fl_quo = (rem * 10000 / input);
|
2015-03-03 10:51:06 +00:00
|
|
|
|
2015-03-26 17:09:15 +00:00
|
|
|
for (d = xcnt - 1; d >= 0; d--) {
|
2015-03-03 10:51:06 +00:00
|
|
|
X = xparm[d].value;
|
2015-10-04 14:42:30 +00:00
|
|
|
M = quo * X;
|
2015-03-03 10:51:06 +00:00
|
|
|
M += fl_quo * X / 10000;
|
|
|
|
/* round step */
|
2015-10-04 14:48:32 +00:00
|
|
|
M += (fl_quo * X % 10000) > 5000 ? 1 : 0;
|
2015-03-26 17:09:16 +00:00
|
|
|
if (M < 256 && M > 0) {
|
2015-03-03 10:51:06 +00:00
|
|
|
unsigned int diff;
|
2015-07-15 04:14:48 +00:00
|
|
|
|
2015-07-15 04:14:40 +00:00
|
|
|
tmpClock = pll->inputFreq * M / N / X;
|
2015-03-26 17:09:18 +00:00
|
|
|
diff = absDiff(tmpClock, request_orig);
|
2015-10-09 20:44:27 +00:00
|
|
|
if (diff < mini_diff) {
|
2015-03-03 10:51:06 +00:00
|
|
|
pll->M = M;
|
|
|
|
pll->N = N;
|
|
|
|
pll->OD = xparm[d].od;
|
|
|
|
pll->POD = xparm[d].pod;
|
2015-10-09 20:44:27 +00:00
|
|
|
mini_diff = diff;
|
2015-03-03 10:51:06 +00:00
|
|
|
ret = tmpClock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int formatPllReg(pll_value_t *pPLL)
|
|
|
|
{
|
2015-03-18 09:37:42 +00:00
|
|
|
unsigned int ulPllReg = 0;
|
2015-03-03 10:51:06 +00:00
|
|
|
|
|
|
|
/* Note that all PLL's have the same format. Here, we just use Panel PLL parameter
|
|
|
|
to work out the bit fields in the register.
|
|
|
|
On returning a 32 bit number, the value can be applied to any PLL in the calling function.
|
|
|
|
*/
|
2015-03-18 09:37:42 +00:00
|
|
|
ulPllReg =
|
2015-07-15 04:14:31 +00:00
|
|
|
FIELD_SET(0, PANEL_PLL_CTRL, BYPASS, OFF)
|
|
|
|
| FIELD_SET(0, PANEL_PLL_CTRL, POWER, ON)
|
|
|
|
| FIELD_SET(0, PANEL_PLL_CTRL, INPUT, OSC)
|
2015-03-03 10:51:06 +00:00
|
|
|
#ifndef VALIDATION_CHIP
|
2015-03-18 09:37:42 +00:00
|
|
|
| FIELD_VALUE(0, PANEL_PLL_CTRL, POD, pPLL->POD)
|
2015-03-03 10:51:06 +00:00
|
|
|
#endif
|
2015-03-18 09:37:42 +00:00
|
|
|
| FIELD_VALUE(0, PANEL_PLL_CTRL, OD, pPLL->OD)
|
|
|
|
| FIELD_VALUE(0, PANEL_PLL_CTRL, N, pPLL->N)
|
|
|
|
| FIELD_VALUE(0, PANEL_PLL_CTRL, M, pPLL->M);
|
2015-03-03 10:51:06 +00:00
|
|
|
|
2015-05-25 05:48:42 +00:00
|
|
|
return ulPllReg;
|
2015-03-03 10:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|