public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@suse.cz>
To: Tom Hughes <tom@compton.nu>
Cc: Matthew Garrett <mjg@redhat.com>,
	Thomas Renninger <trenn@suse.de>,
	Cristiano Prisciandaro <cristiano.p@solnet.ch>,
	Dave Jones <davej@redhat.com>,
	cpufreq@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] cpufreq: eeepc 900 frequency scaling driver
Date: Tue, 9 Dec 2008 13:36:10 +0100	[thread overview]
Message-ID: <20081209123607.GA1683@ucw.cz> (raw)
In-Reply-To: <493BF1D4.7090602@compton.nu>

On Sun 2008-12-07 15:55:00, Tom Hughes wrote:
> Matthew Garrett wrote:
>
>> It appears to be implemented in the 900 and 901 BIOSes as well, so some 
>> kind of limitation is probably needed. The best approach would probably 
>> to check whether the CPU has the EST flag. Just do something like:
>>
>> struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu);
>>
>> if (cpu->x86_vendor != X86_VENDOR_INTEL || cpu_has(cpu, X86_FEATURE_EST))
>> 	return -ENODEV
>>
>> at the top of the cpufreq init code. That way you'll refuse to bind on  
>> anything that implements speedstep and acpi-cpufreq can be used 
>> instead.
>
> Sounds like a good idea - here's a new version with that check added:

Whitespace damaged and needs signed-off-by; otherwise looks ok to me.

> --- kmod-eeepc-laptop-2.6.28rc5/eeepc-laptop.c	2008-11-20 09:24:41.000000000 +0000
> +++ kmod-eeepc-laptop-cpufreq/eeepc-laptop.c	2008-12-07 15:54:07.000000000 +0000
> @@ -25,6 +25,7 @@
> #include <linux/fb.h>
> #include <linux/hwmon.h>
> #include <linux/hwmon-sysfs.h>
> +#include <linux/cpufreq.h>
> #include <acpi/acpi_drivers.h>
> #include <acpi/acpi_bus.h>
> #include <linux/uaccess.h>
> @@ -731,6 +732,118 @@
> };
>
> /*
> + * Cpufreq
> + *
> + * Based on work by Cristiano P. <cris69@solnet.ch>
> + */
> +static struct cpufreq_frequency_table eeepc_cpufreq_table[] = {
> +       {0, 630000},
> +       {1, 900000},
> +       {0, CPUFREQ_TABLE_END}
> +};
> +
> +static unsigned int eeepc_cpufreq_get(unsigned int cpu)
> +{
> +	switch (get_acpi(CM_ASL_CPUFV)) {
> +	case 0x200:
> +		return 900000;
> +	case 0x201:
> +		return 630000;
> +	}
> +
> +	return 0;
> +}
> +
> +static void eeepc_cpufreq_set(unsigned int frequency)
> +{
> +	struct cpufreq_freqs freqs;
> +
> +	freqs.cpu = 0;
> +	freqs.old = eeepc_cpufreq_get(0);
> +	freqs.new = frequency;
> +
> +	cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
> +
> +	switch (frequency) {
> +	case 900000:
> +		set_acpi(CM_ASL_CPUFV, 0);
> +		break;
> +	case 630000:
> +		set_acpi(CM_ASL_CPUFV, 1);
> +		break;
> +	}
> +
> +	cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
> +
> +	return;
> +}
> +
> +static int eeepc_cpufreq_verify(struct cpufreq_policy *policy)
> +{
> +	return cpufreq_frequency_table_verify(policy, eeepc_cpufreq_table);
> +}
> +
> +static int eeepc_cpufreq_target (struct cpufreq_policy *policy,
> +				 unsigned int target_freq,
> +				 unsigned int relation)
> +{
> +	unsigned int newstate = 0;
> +
> +	if (cpufreq_frequency_table_target(policy, eeepc_cpufreq_table,
> +					   target_freq, relation, &newstate))
> +		return -EINVAL;
> +
> +	eeepc_cpufreq_set(eeepc_cpufreq_table[newstate].frequency);
> +
> +	return 0;
> +}
> +
> +static int eeepc_cpufreq_cpu_init(struct cpufreq_policy *policy)
> +{
> +	struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu);
> +
> +	/* Defer to acpi-cpufreq if this CPU has SpeedStep support */
> +	if (cpu->x86_vendor != X86_VENDOR_INTEL || cpu_has(cpu, X86_FEATURE_EST))
> +		return -ENODEV;
> +
> +	if (get_acpi(CM_ASL_CPUFV) < 0)
> +		return -ENODEV;
> +
> +	policy->cpuinfo.transition_latency = 1000000;
> +	policy->cur = eeepc_cpufreq_get(policy->cpu);
> +
> +	if (cpufreq_frequency_table_cpuinfo(policy, eeepc_cpufreq_table))
> +		return -EINVAL;
> +
> +	cpufreq_frequency_table_get_attr(eeepc_cpufreq_table, policy->cpu);
> +
> +	return 0;
> +}
> +
> +static int eeepc_cpufreq_cpu_exit(struct cpufreq_policy *policy)
> +{
> +	cpufreq_frequency_table_put_attr(policy->cpu);
> +
> +	return 0;
> +}
> +
> +static struct freq_attr *eeepc_cpufreq_attr[] = {
> +	&cpufreq_freq_attr_scaling_available_freqs,
> +	NULL,
> +};
> +
> +static struct cpufreq_driver eeepc_cpufreq_driver = {
> +	.verify         = eeepc_cpufreq_verify,
> +	.target         = eeepc_cpufreq_target,
> +	.init           = eeepc_cpufreq_cpu_init,
> +	.exit           = eeepc_cpufreq_cpu_exit,
> +	.get            = eeepc_cpufreq_get,
> +	.name           = "eeepc",
> +	.owner          = THIS_MODULE,
> +	.attr           = eeepc_cpufreq_attr,
> +};
> +
> +/*
>  * exit/init
>  */
> static void eeepc_backlight_exit(void)
> @@ -759,10 +872,16 @@
> 	eeepc_hwmon_device = NULL;
> }
>
> +static void eeepc_cpufreq_exit(void)
> +{
> +	cpufreq_unregister_driver(&eeepc_cpufreq_driver);
> +}
> +
> static void __exit eeepc_laptop_exit(void)
> {
> 	eeepc_backlight_exit();
> 	eeepc_hwmon_exit();
> +	eeepc_cpufreq_exit();
> 	acpi_bus_unregister_driver(&eeepc_hotk_driver);
> 	sysfs_remove_group(&platform_device->dev.kobj,
> 			   &platform_attribute_group);
> @@ -810,6 +929,11 @@
> 	return result;
> }
>
> +static int eeepc_cpufreq_init(struct device *dev)
> +{
> +	return cpufreq_register_driver(&eeepc_cpufreq_driver);
> +}
> +
> static int __init eeepc_laptop_init(void)
> {
> 	struct device *dev;
> @@ -837,6 +961,9 @@
> 	result = eeepc_hwmon_init(dev);
> 	if (result)
> 		goto fail_hwmon;
> +	result = eeepc_cpufreq_init(dev);
> +	if (result)
> +		goto fail_cpufreq;
> 	/* Register platform stuff */
> 	result = platform_driver_register(&platform_driver);
> 	if (result)
> @@ -861,6 +988,8 @@
> fail_platform_device1:
> 	platform_driver_unregister(&platform_driver);
> fail_platform_driver:
> +	eeepc_cpufreq_exit();
> +fail_cpufreq:
> 	eeepc_hwmon_exit();
> fail_hwmon:
> 	eeepc_backlight_exit();
>
>
> Tom
>

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

      reply	other threads:[~2008-12-09 12:36 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-23 15:27 [PATCH 1/1] cpufreq: eeepc 900 frequency scaling driver Cristiano Prisciandaro
2008-11-23 18:04 ` Pavel Machek
2008-12-02 16:15   ` Matthew Garrett
2008-12-02 20:14     ` Pavel Machek
2009-03-16  4:24       ` Len Brown
2009-03-16  8:29         ` Pavel Machek
2009-03-17  8:30           ` Fabio Comolli
2009-03-17  8:59             ` Fabio Comolli
2008-11-24  9:38 ` Tom Hughes
2008-11-24 15:13   ` Thomas Renninger
2008-11-24 16:36     ` Thomas Renninger
2008-11-24 16:41       ` [Acpi4asus-user] " Corentin Chary
2008-11-24 16:48         ` Tom Hughes
2008-11-24 16:58           ` Corentin Chary
2008-11-24 17:07             ` Tom Hughes
2008-11-24 16:46       ` Tom Hughes
2008-11-24 23:02       ` Cristiano Prisciandaro
2009-04-05  7:43         ` [Acpi4asus-user] " Corentin Chary
2009-04-05 10:20           ` Matthew Garrett
2009-04-05 11:39             ` Grigori Goronzy
2008-11-24 16:39     ` Tom Hughes
2008-11-24 19:09   ` Cristiano Prisciandaro
2008-12-03 19:26   ` Tom Hughes
2008-12-04  1:57     ` Thomas Renninger
2008-12-05 23:05       ` Tom Hughes
2008-12-06 16:35         ` Matthew Garrett
2008-12-07 15:55           ` Tom Hughes
2008-12-09 12:36             ` Pavel Machek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081209123607.GA1683@ucw.cz \
    --to=pavel@suse.cz \
    --cc=cpufreq@vger.kernel.org \
    --cc=cristiano.p@solnet.ch \
    --cc=davej@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjg@redhat.com \
    --cc=tom@compton.nu \
    --cc=trenn@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox