10 #include <linux/kernel.h>
11 #include <linux/module.h>
15 #include <linux/pci.h>
18 #define NFORCE2_XTAL 25
19 #define NFORCE2_BOOTFSB 0x48
20 #define NFORCE2_PLLENABLE 0xa8
21 #define NFORCE2_PLLREG 0xa4
22 #define NFORCE2_PLLADR 0xa0
23 #define NFORCE2_PLL(mul, div) (0x100000 | (mul << 8) | div)
25 #define NFORCE2_MIN_FSB 50
26 #define NFORCE2_SAFE_DISTANCE 50
35 static struct pci_dev *nforce2_dev;
57 "Minimum FSB to use, if not defined: current FSB - 50");
59 #define PFX "cpufreq-nforce2: "
67 static int nforce2_calc_fsb(
int pll)
69 unsigned char mul,
div;
71 mul = (pll >> 8) & 0xff;
86 static int nforce2_calc_pll(
unsigned int fsb)
88 unsigned char xmul, xdiv;
89 unsigned char mul = 0,
div = 0;
93 while (((mul == 0) || (
div == 0)) && (tried <= 3)) {
94 for (xdiv = 2; xdiv <= 0x80; xdiv++)
95 for (xmul = 1; xmul <= 0xfe; xmul++)
104 if ((mul == 0) || (
div == 0))
116 static void nforce2_write_pll(
int pll)
124 for (temp = 0; temp <= 0x3f; temp++)
136 static unsigned int nforce2_fsb_read(
int bootfsb)
153 if (bootfsb || !temp)
158 fsb = nforce2_calc_fsb(temp);
169 static int nforce2_set_fsb(
unsigned int fsb)
181 tfsb = nforce2_fsb_read(0);
190 pll = nforce2_calc_pll(tfsb);
195 nforce2_write_pll(pll);
207 while ((tfsb != fsb) && (tfsb <= max_fsb) && (tfsb >= min_fsb)) {
214 pll = nforce2_calc_pll(tfsb);
218 nforce2_write_pll(pll);
236 static unsigned int nforce2_get(
unsigned int cpu)
240 return nforce2_fsb_read(0) *
fid * 100;
253 unsigned int target_freq,
unsigned int relation)
257 unsigned int target_fsb;
259 if ((target_freq > policy->
max) || (target_freq < policy->
min))
262 target_fsb = target_freq / (
fid * 100);
264 freqs.old = nforce2_get(policy->
cpu);
265 freqs.new = target_fsb *
fid * 100;
268 if (freqs.old == freqs.new)
271 pr_debug(
"Old CPU frequency %d kHz, new %d kHz\n",
272 freqs.old, freqs.new);
279 if (nforce2_set_fsb(target_fsb) < 0)
283 pr_debug(
"Changed FSB successfully to %d\n",
300 unsigned int fsb_pol_max;
302 fsb_pol_max = policy->
max / (fid * 100);
304 if (policy->
min < (fsb_pol_max * fid * 100))
305 policy->
max = (fsb_pol_max + 1) * fid * 100;
307 cpufreq_verify_within_limits(policy,
319 if (policy->
cpu != 0)
323 fsb = nforce2_fsb_read(0);
332 "cpu_khz not set, can't calculate multiplier!\n");
351 max_fsb = nforce2_fsb_read(1);
363 policy->
cpuinfo.min_freq = min_fsb * fid * 100;
364 policy->
cpuinfo.max_freq = max_fsb * fid * 100;
366 policy->
cur = nforce2_get(policy->
cpu);
380 .verify = nforce2_verify,
381 .target = nforce2_target,
383 .init = nforce2_cpu_init,
384 .exit = nforce2_cpu_exit,
402 static int nforce2_detect_chipset(
void)
408 if (nforce2_dev ==
NULL)
414 "FSB changing is maybe unstable and can lead to "
415 "crashes and data loss.\n");
427 static int __init nforce2_init(
void)
432 if (nforce2_detect_chipset()) {
445 static void __exit nforce2_exit(
void)