[CPUFREQ] checkpatch cleanups for powernow-k7

The asm/timer.h warning can be ignored, it's needed for
recalibrate_cpu_khz()

Signed-off-by: Dave Jones <davej@redhat.com>
This commit is contained in:
Dave Jones 2009-01-18 00:32:26 -05:00
parent bbfebd6655
commit b9e7638a30
1 changed files with 137 additions and 100 deletions

View File

@ -6,9 +6,11 @@
* Licensed under the terms of the GNU GPL License version 2. * Licensed under the terms of the GNU GPL License version 2.
* Based upon datasheets & sample CPUs kindly provided by AMD. * Based upon datasheets & sample CPUs kindly provided by AMD.
* *
* Errata 5: Processor may fail to execute a FID/VID change in presence of interrupt. * Errata 5:
* CPU may fail to execute a FID/VID change in presence of interrupt.
* - We cli/sti on stepping A0 CPUs around the FID/VID transition. * - We cli/sti on stepping A0 CPUs around the FID/VID transition.
* Errata 15: Processors with half frequency multipliers may hang upon wakeup from disconnect. * Errata 15:
* CPU with half frequency multipliers may hang upon wakeup from disconnect.
* - We disable half multipliers if ACPI is used on A0 stepping CPUs. * - We disable half multipliers if ACPI is used on A0 stepping CPUs.
*/ */
@ -20,11 +22,11 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/dmi.h> #include <linux/dmi.h>
#include <linux/timex.h>
#include <linux/io.h>
#include <asm/timer.h> /* Needed for recalibrate_cpu_khz() */
#include <asm/msr.h> #include <asm/msr.h>
#include <asm/timer.h>
#include <asm/timex.h>
#include <asm/io.h>
#include <asm/system.h> #include <asm/system.h>
#ifdef CONFIG_X86_POWERNOW_K7_ACPI #ifdef CONFIG_X86_POWERNOW_K7_ACPI
@ -101,7 +103,8 @@ static unsigned int fsb;
static unsigned int latency; static unsigned int latency;
static char have_a0; static char have_a0;
#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "powernow-k7", msg) #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
"powernow-k7", msg)
static int check_fsb(unsigned int fsbspeed) static int check_fsb(unsigned int fsbspeed)
{ {
@ -109,7 +112,7 @@ static int check_fsb(unsigned int fsbspeed)
unsigned int f = fsb / 1000; unsigned int f = fsb / 1000;
delta = (fsbspeed > f) ? fsbspeed - f : f - fsbspeed; delta = (fsbspeed > f) ? fsbspeed - f : f - fsbspeed;
return (delta < 5); return delta < 5;
} }
static int check_powernow(void) static int check_powernow(void)
@ -119,7 +122,8 @@ static int check_powernow(void)
if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 6)) { if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 6)) {
#ifdef MODULE #ifdef MODULE
printk (KERN_INFO PFX "This module only works with AMD K7 CPUs\n"); printk(KERN_INFO PFX "This module only works with "
"AMD K7 CPUs\n");
#endif #endif
return 0; return 0;
} }
@ -134,7 +138,8 @@ static int check_powernow(void)
} }
if ((c->x86_model == 6) && (c->x86_mask == 0)) { if ((c->x86_model == 6) && (c->x86_mask == 0)) {
printk (KERN_INFO PFX "K7 660[A0] core detected, enabling errata workarounds\n"); printk(KERN_INFO PFX "K7 660[A0] core detected, "
"enabling errata workarounds\n");
have_a0 = 1; have_a0 = 1;
} }
@ -163,6 +168,10 @@ static int check_powernow(void)
return 1; return 1;
} }
static void invalidate_entry(unsigned int entry)
{
powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID;
}
static int get_ranges(unsigned char *pst) static int get_ranges(unsigned char *pst)
{ {
@ -170,7 +179,8 @@ static int get_ranges (unsigned char *pst)
unsigned int speed; unsigned int speed;
u8 fid, vid; u8 fid, vid;
powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * (number_scales + 1)), GFP_KERNEL); powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) *
(number_scales + 1)), GFP_KERNEL);
if (!powernow_table) if (!powernow_table)
return -ENOMEM; return -ENOMEM;
@ -185,7 +195,7 @@ static int get_ranges (unsigned char *pst)
if ((fid_codes[fid] % 10) == 5) { if ((fid_codes[fid] % 10) == 5) {
#ifdef CONFIG_X86_POWERNOW_K7_ACPI #ifdef CONFIG_X86_POWERNOW_K7_ACPI
if (have_a0 == 1) if (have_a0 == 1)
powernow_table[j].frequency = CPUFREQ_ENTRY_INVALID; invalidate_entry(j);
#endif #endif
} }
@ -321,12 +331,14 @@ static int powernow_acpi_init(void)
goto err1; goto err1;
} }
if (acpi_processor_perf->control_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) { if (acpi_processor_perf->control_register.space_id !=
ACPI_ADR_SPACE_FIXED_HARDWARE) {
retval = -ENODEV; retval = -ENODEV;
goto err2; goto err2;
} }
if (acpi_processor_perf->status_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) { if (acpi_processor_perf->status_register.space_id !=
ACPI_ADR_SPACE_FIXED_HARDWARE) {
retval = -ENODEV; retval = -ENODEV;
goto err2; goto err2;
} }
@ -338,7 +350,8 @@ static int powernow_acpi_init(void)
goto err2; goto err2;
} }
powernow_table = kzalloc((number_scales + 1) * (sizeof(struct cpufreq_frequency_table)), GFP_KERNEL); powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) *
(number_scales + 1)), GFP_KERNEL);
if (!powernow_table) { if (!powernow_table) {
retval = -ENOMEM; retval = -ENOMEM;
goto err2; goto err2;
@ -383,7 +396,7 @@ static int powernow_acpi_init(void)
if ((fid_codes[fid] % 10) == 5) { if ((fid_codes[fid] % 10) == 5) {
if (have_a0 == 1) if (have_a0 == 1)
powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID; invalidate_entry(i);
} }
dprintk(" FID: 0x%x (%d.%dx [%dMHz]) " dprintk(" FID: 0x%x (%d.%dx [%dMHz]) "
@ -422,7 +435,8 @@ static int powernow_acpi_init(void)
err05: err05:
kfree(acpi_processor_perf); kfree(acpi_processor_perf);
err0: err0:
printk(KERN_WARNING PFX "ACPI perflib can not be used in this platform\n"); printk(KERN_WARNING PFX "ACPI perflib can not be used on "
"this platform\n");
acpi_processor_perf = NULL; acpi_processor_perf = NULL;
return retval; return retval;
} }
@ -435,6 +449,13 @@ static int powernow_acpi_init(void)
} }
#endif #endif
static void print_pst_entry(struct pst_s *pst, unsigned int j)
{
dprintk("PST:%d (@%p)\n", j, pst);
dprintk(" cpuid: 0x%x fsb: %d maxFID: 0x%x startvid: 0x%x\n",
pst->cpuid, pst->fsbspeed, pst->maxfid, pst->startvid);
}
static int powernow_decode_bios(int maxfid, int startvid) static int powernow_decode_bios(int maxfid, int startvid)
{ {
struct psb_s *psb; struct psb_s *psb;
@ -455,25 +476,30 @@ static int powernow_decode_bios (int maxfid, int startvid)
psb = (struct psb_s *) p; psb = (struct psb_s *) p;
dprintk("Table version: 0x%x\n", psb->tableversion); dprintk("Table version: 0x%x\n", psb->tableversion);
if (psb->tableversion != 0x12) { if (psb->tableversion != 0x12) {
printk (KERN_INFO PFX "Sorry, only v1.2 tables supported right now\n"); printk(KERN_INFO PFX "Sorry, only v1.2 tables"
" supported right now\n");
return -ENODEV; return -ENODEV;
} }
dprintk("Flags: 0x%x\n", psb->flags); dprintk("Flags: 0x%x\n", psb->flags);
if ((psb->flags & 1)==0) { if ((psb->flags & 1) == 0)
dprintk("Mobile voltage regulator\n"); dprintk("Mobile voltage regulator\n");
} else { else
dprintk("Desktop voltage regulator\n"); dprintk("Desktop voltage regulator\n");
}
latency = psb->settlingtime; latency = psb->settlingtime;
if (latency < 100) { if (latency < 100) {
printk(KERN_INFO PFX "BIOS set settling time to %d microseconds. " printk(KERN_INFO PFX "BIOS set settling time "
"Should be at least 100. Correcting.\n", latency); "to %d microseconds. "
"Should be at least 100. "
"Correcting.\n", latency);
latency = 100; latency = 100;
} }
dprintk ("Settling Time: %d microseconds.\n", psb->settlingtime); dprintk("Settling Time: %d microseconds.\n",
dprintk ("Has %d PST tables. (Only dumping ones relevant to this CPU).\n", psb->numpst); psb->settlingtime);
dprintk("Has %d PST tables. (Only dumping ones "
"relevant to this CPU).\n",
psb->numpst);
p += sizeof(struct psb_s); p += sizeof(struct psb_s);
@ -483,14 +509,13 @@ static int powernow_decode_bios (int maxfid, int startvid)
pst = (struct pst_s *) p; pst = (struct pst_s *) p;
number_scales = pst->numpstates; number_scales = pst->numpstates;
if ((etuple == pst->cpuid) && check_fsb(pst->fsbspeed) && if ((etuple == pst->cpuid) &&
(maxfid==pst->maxfid) && (startvid==pst->startvid)) check_fsb(pst->fsbspeed) &&
{ (maxfid == pst->maxfid) &&
dprintk ("PST:%d (@%p)\n", j, pst); (startvid == pst->startvid)) {
dprintk (" cpuid: 0x%x fsb: %d maxFID: 0x%x startvid: 0x%x\n", print_pst_entry(pst, j);
pst->cpuid, pst->fsbspeed, pst->maxfid, pst->startvid); p = (char *)pst + sizeof(struct pst_s);
ret = get_ranges(p);
ret = get_ranges ((char *) pst + sizeof (struct pst_s));
return ret; return ret;
} else { } else {
unsigned int k; unsigned int k;
@ -499,8 +524,10 @@ static int powernow_decode_bios (int maxfid, int startvid)
p += 2; p += 2;
} }
} }
printk (KERN_INFO PFX "No PST tables match this cpuid (0x%x)\n", etuple); printk(KERN_INFO PFX "No PST tables match this cpuid "
printk (KERN_INFO PFX "This is indicative of a broken BIOS.\n"); "(0x%x)\n", etuple);
printk(KERN_INFO PFX "This is indicative of a broken "
"BIOS.\n");
return -EINVAL; return -EINVAL;
} }
@ -517,7 +544,8 @@ static int powernow_target (struct cpufreq_policy *policy,
{ {
unsigned int newstate; unsigned int newstate;
if (cpufreq_frequency_table_target(policy, powernow_table, target_freq, relation, &newstate)) if (cpufreq_frequency_table_target(policy, powernow_table, target_freq,
relation, &newstate))
return -EINVAL; return -EINVAL;
change_speed(newstate); change_speed(newstate);
@ -569,15 +597,20 @@ static unsigned int powernow_get(unsigned int cpu)
rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val); rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val);
cfid = fidvidstatus.bits.CFID; cfid = fidvidstatus.bits.CFID;
return (fsb * fid_codes[cfid] / 10); return fsb * fid_codes[cfid] / 10;
} }
static int __init acer_cpufreq_pst(const struct dmi_system_id *d) static int __init acer_cpufreq_pst(const struct dmi_system_id *d)
{ {
printk(KERN_WARNING "%s laptop with broken PST tables in BIOS detected.\n", d->ident); printk(KERN_WARNING PFX
printk(KERN_WARNING "You need to downgrade to 3A21 (09/09/2002), or try a newer BIOS than 3A71 (01/20/2003)\n"); "%s laptop with broken PST tables in BIOS detected.\n",
printk(KERN_WARNING "cpufreq scaling has been disabled as a result of this.\n"); d->ident);
printk(KERN_WARNING PFX
"You need to downgrade to 3A21 (09/09/2002), or try a newer "
"BIOS than 3A71 (01/20/2003)\n");
printk(KERN_WARNING PFX
"cpufreq scaling has been disabled as a result of this.\n");
return 0; return 0;
} }
@ -618,10 +651,12 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
dprintk("FSB: %3dMHz\n", fsb/1000); dprintk("FSB: %3dMHz\n", fsb/1000);
if (dmi_check_system(powernow_dmi_table) || acpi_force) { if (dmi_check_system(powernow_dmi_table) || acpi_force) {
printk (KERN_INFO PFX "PSB/PST known to be broken. Trying ACPI instead\n"); printk(KERN_INFO PFX "PSB/PST known to be broken. "
"Trying ACPI instead\n");
result = powernow_acpi_init(); result = powernow_acpi_init();
} else { } else {
result = powernow_decode_bios(fidvidstatus.bits.MFID, fidvidstatus.bits.SVID); result = powernow_decode_bios(fidvidstatus.bits.MFID,
fidvidstatus.bits.SVID);
if (result) { if (result) {
printk(KERN_INFO PFX "Trying ACPI perflib\n"); printk(KERN_INFO PFX "Trying ACPI perflib\n");
maximum_speed = 0; maximum_speed = 0;
@ -629,8 +664,8 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
latency = 0; latency = 0;
result = powernow_acpi_init(); result = powernow_acpi_init();
if (result) { if (result) {
printk (KERN_INFO PFX "ACPI and legacy methods failed\n"); printk(KERN_INFO PFX
printk (KERN_INFO PFX "See http://www.codemonkey.org.uk/projects/cpufreq/powernow-k7.html\n"); "ACPI and legacy methods failed\n");
} }
} else { } else {
/* SGTC use the bus clock as timer */ /* SGTC use the bus clock as timer */
@ -645,7 +680,8 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
printk(KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n", printk(KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n",
minimum_speed/1000, maximum_speed/1000); minimum_speed/1000, maximum_speed/1000);
policy->cpuinfo.transition_latency = cpufreq_scale(2000000UL, fsb, latency); policy->cpuinfo.transition_latency =
cpufreq_scale(2000000UL, fsb, latency);
policy->cur = powernow_get(0); policy->cur = powernow_get(0);
@ -654,7 +690,8 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
return cpufreq_frequency_table_cpuinfo(policy, powernow_table); return cpufreq_frequency_table_cpuinfo(policy, powernow_table);
} }
static int powernow_cpu_exit (struct cpufreq_policy *policy) { static int powernow_cpu_exit(struct cpufreq_policy *policy)
{
cpufreq_frequency_table_put_attr(policy->cpu); cpufreq_frequency_table_put_attr(policy->cpu);
#ifdef CONFIG_X86_POWERNOW_K7_ACPI #ifdef CONFIG_X86_POWERNOW_K7_ACPI