12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/types.h>
15 #include <linux/pci.h>
21 #define SDRAM_CFG_0 0x49A1
22 #define SDRAM_CFG_1 0xA732
23 #define SDRAM_CFG_2 0x31
24 #define SDRAM_ARB_CFG 0xA0
25 #define SDRAM_REFRESH 0x20
28 #define PMX2_SOFTRESET_DAC_RST 0x0001
29 #define PMX2_SOFTRESET_C1_RST 0x0004
30 #define PMX2_SOFTRESET_C2_RST 0x0008
31 #define PMX2_SOFTRESET_3D_RST 0x0010
32 #define PMX2_SOFTRESET_VIDIN_RST 0x0020
33 #define PMX2_SOFTRESET_TLB_RST 0x0040
34 #define PMX2_SOFTRESET_SD_RST 0x0080
35 #define PMX2_SOFTRESET_VGA_RST 0x0100
36 #define PMX2_SOFTRESET_ROM_RST 0x0200
37 #define PMX2_SOFTRESET_TA_RST 0x0400
38 #define PMX2_SOFTRESET_REG_RST 0x4000
39 #define PMX2_SOFTRESET_ALL 0x7fff
42 #define CORE_PLL_FREQ 1000000
45 #define REF_FREQ 14318
48 static u16 CorePllControl = 0x70;
50 #define PCI_CONFIG_SUBSYS_ID 0x2e
53 #define CORE_PLL_MODE_REG_0_7 3
54 #define CORE_PLL_MODE_REG_8_15 2
55 #define CORE_PLL_MODE_CONFIG_REG 1
56 #define DAC_PLL_CONFIG_REG 0
58 #define STG_MAX_VCO 500000
59 #define STG_MIN_VCO 100000
62 #define STG4K3_PLL_SCALER 8
63 #define STG4K3_PLL_MIN_R 2
64 #define STG4K3_PLL_MAX_R 33
65 #define STG4K3_PLL_MIN_F 2
66 #define STG4K3_PLL_MAX_F 513
67 #define STG4K3_PLL_MIN_OD 0
68 #define STG4K3_PLL_MAX_OD 2
69 #define STG4K3_PLL_MIN_VCO_SC (100000000 >> STG4K3_PLL_SCALER)
70 #define STG4K3_PLL_MAX_VCO_SC (500000000 >> STG4K3_PLL_SCALER)
71 #define STG4K3_PLL_MINR_VCO_SC (100000000 >> STG4K3_PLL_SCALER)
72 #define STG4K3_PLL_MAXR_VCO_SC (500000000 >> STG4K3_PLL_SCALER)
73 #define STG4K3_PLL_MINR_VCO 100000000
74 #define STG4K3_PLL_MAX_VCO 500000000
75 #define STG4K3_PLL_MAXR_VCO 500000000
79 volatile u32 i,count=0; \
80 for(i=0;i<X;i++) count++; \
84 u32 dwSubSysID,
u32 dwRevID)
86 u32 adwSDRAMArgCfg0[] = { 0xa0, 0x80, 0xa0, 0xa0, 0xa0 };
87 u32 adwSDRAMCfg1[] = { 0x8732, 0x8732, 0xa732, 0xa732, 0x8732 };
88 u32 adwSDRAMCfg2[] = { 0x87d2, 0x87d2, 0xa7d2, 0x87d2, 0xa7d2 };
89 u32 adwSDRAMRsh[] = { 36, 39, 40 };
90 u32 adwChipSpeed[] = { 110, 120, 125 };
95 dwMemTypeIdx = (dwSubSysID & 0x70) >> 4;
96 dwChipSpeedIdx = (dwSubSysID & 0x180) >> 7;
98 if (dwMemTypeIdx > 4 || dwChipSpeedIdx > 2)
102 STG_WRITE_REG(SDRAMArbiterConf, adwSDRAMArgCfg0[dwMemTypeIdx]);
114 return adwChipSpeed[dwChipSpeedIdx] * 10000;
121 u32 R = 0,
F = 0,
OD = 0, ODIndex = 0;
122 u32 ulBestR = 0, ulBestF = 0, ulBestOD = 0;
123 u32 ulBestVCO = 0, ulBestClk = 0, ulBestScore = 0;
124 u32 ulScore, ulPhaseScore, ulVcoScore;
125 u32 ulTmp = 0, ulVCO;
126 u32 ulScaleClockReq, ulMinClock, ulMaxClock;
127 u32 ODValues[] = { 1, 2, 0 };
136 ulMinClock = coreClock - (coreClock >> 8);
137 ulMaxClock = coreClock + (coreClock >> 8);
143 for (ODIndex = 0; ODIndex < 3; ODIndex++) {
144 OD = ODValues[ODIndex];
150 ulTmp = R * (ulScaleClockReq <<
OD);
153 F = (
u32)(ulTmp / (refClock >> STG4K3_PLL_SCALER));
168 ulVCO = refClock /
R;
181 ulTmp = (ulVCO >>
OD);
184 if ((ulTmp >= ulMinClock)
185 && (ulTmp <= ulMaxClock)) {
189 ulScore = ulPhaseScore + ulVcoScore;
208 if ((ulScore >= ulBestScore) && (
OD > 0)) {
233 if ((ulBestOD == 2) || (ulBestOD == 3)) {
246 u16 core_pll = 0, sub;
279 ulChipSpeed = InitSDRAMRegisters(pSTGReg, (
u32)sub,
282 if (ulChipSpeed == 0)
287 core_pll |= ((
P) | ((F - 2) << 2) | ((R - 2) << 11));
293 pci_write_config_word(pDev, CorePllControl, tmp);
300 pci_write_config_word(pDev, CorePllControl, tmp);
305 ((CORE_PLL_MODE_REG_8_15 << 8) | ((core_pll & 0xFF00) >> 8));
306 pci_write_config_word(pDev, CorePllControl, tmp);
310 pci_write_config_word(pDev, CorePllControl, tmp);