mfd: bcm590xx: Use devm_mfd_add_devices() for mfd_device registration
[linux/fpc-iii.git] / drivers / cpufreq / cpufreq_userspace.c
blob4d16f45ee1daf3e64e23c97a9cec8b7a4ea0fc0f
2 /*
3 * linux/drivers/cpufreq/cpufreq_userspace.c
5 * Copyright (C) 2001 Russell King
6 * (C) 2002 - 2004 Dominik Brodowski <linux@brodo.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/cpufreq.h>
17 #include <linux/init.h>
18 #include <linux/module.h>
19 #include <linux/mutex.h>
21 static DEFINE_PER_CPU(unsigned int, cpu_is_managed);
22 static DEFINE_MUTEX(userspace_mutex);
24 /**
25 * cpufreq_set - set the CPU frequency
26 * @policy: pointer to policy struct where freq is being set
27 * @freq: target frequency in kHz
29 * Sets the CPU frequency to freq.
31 static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
33 int ret = -EINVAL;
35 pr_debug("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq);
37 mutex_lock(&userspace_mutex);
38 if (!per_cpu(cpu_is_managed, policy->cpu))
39 goto err;
41 ret = __cpufreq_driver_target(policy, freq, CPUFREQ_RELATION_L);
42 err:
43 mutex_unlock(&userspace_mutex);
44 return ret;
47 static ssize_t show_speed(struct cpufreq_policy *policy, char *buf)
49 return sprintf(buf, "%u\n", policy->cur);
52 static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
53 unsigned int event)
55 unsigned int cpu = policy->cpu;
56 int rc = 0;
58 switch (event) {
59 case CPUFREQ_GOV_START:
60 BUG_ON(!policy->cur);
61 pr_debug("started managing cpu %u\n", cpu);
63 mutex_lock(&userspace_mutex);
64 per_cpu(cpu_is_managed, cpu) = 1;
65 mutex_unlock(&userspace_mutex);
66 break;
67 case CPUFREQ_GOV_STOP:
68 pr_debug("managing cpu %u stopped\n", cpu);
70 mutex_lock(&userspace_mutex);
71 per_cpu(cpu_is_managed, cpu) = 0;
72 mutex_unlock(&userspace_mutex);
73 break;
74 case CPUFREQ_GOV_LIMITS:
75 mutex_lock(&userspace_mutex);
76 pr_debug("limit event for cpu %u: %u - %u kHz, currently %u kHz\n",
77 cpu, policy->min, policy->max,
78 policy->cur);
80 if (policy->max < policy->cur)
81 __cpufreq_driver_target(policy, policy->max,
82 CPUFREQ_RELATION_H);
83 else if (policy->min > policy->cur)
84 __cpufreq_driver_target(policy, policy->min,
85 CPUFREQ_RELATION_L);
86 mutex_unlock(&userspace_mutex);
87 break;
89 return rc;
92 static struct cpufreq_governor cpufreq_gov_userspace = {
93 .name = "userspace",
94 .governor = cpufreq_governor_userspace,
95 .store_setspeed = cpufreq_set,
96 .show_setspeed = show_speed,
97 .owner = THIS_MODULE,
100 static int __init cpufreq_gov_userspace_init(void)
102 return cpufreq_register_governor(&cpufreq_gov_userspace);
105 static void __exit cpufreq_gov_userspace_exit(void)
107 cpufreq_unregister_governor(&cpufreq_gov_userspace);
110 MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>, "
111 "Russell King <rmk@arm.linux.org.uk>");
112 MODULE_DESCRIPTION("CPUfreq policy governor 'userspace'");
113 MODULE_LICENSE("GPL");
115 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
116 struct cpufreq_governor *cpufreq_default_governor(void)
118 return &cpufreq_gov_userspace;
121 fs_initcall(cpufreq_gov_userspace_init);
122 #else
123 module_init(cpufreq_gov_userspace_init);
124 #endif
125 module_exit(cpufreq_gov_userspace_exit);