dm thin metadata: fix __udivdi3 undefined on 32-bit
[linux/fpc-iii.git] / drivers / cpufreq / cpufreq_userspace.c
blob9cc8abd3d116e218d6dd5bb7f6344496652865b5
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>
20 #include <linux/slab.h>
22 static DEFINE_PER_CPU(unsigned int, cpu_is_managed);
23 static DEFINE_MUTEX(userspace_mutex);
25 /**
26 * cpufreq_set - set the CPU frequency
27 * @policy: pointer to policy struct where freq is being set
28 * @freq: target frequency in kHz
30 * Sets the CPU frequency to freq.
32 static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
34 int ret = -EINVAL;
35 unsigned int *setspeed = policy->governor_data;
37 pr_debug("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq);
39 mutex_lock(&userspace_mutex);
40 if (!per_cpu(cpu_is_managed, policy->cpu))
41 goto err;
43 *setspeed = freq;
45 ret = __cpufreq_driver_target(policy, freq, CPUFREQ_RELATION_L);
46 err:
47 mutex_unlock(&userspace_mutex);
48 return ret;
51 static ssize_t show_speed(struct cpufreq_policy *policy, char *buf)
53 return sprintf(buf, "%u\n", policy->cur);
56 static int cpufreq_userspace_policy_init(struct cpufreq_policy *policy)
58 unsigned int *setspeed;
60 setspeed = kzalloc(sizeof(*setspeed), GFP_KERNEL);
61 if (!setspeed)
62 return -ENOMEM;
64 policy->governor_data = setspeed;
65 return 0;
68 static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
69 unsigned int event)
71 unsigned int *setspeed = policy->governor_data;
72 unsigned int cpu = policy->cpu;
73 int rc = 0;
75 if (event == CPUFREQ_GOV_POLICY_INIT)
76 return cpufreq_userspace_policy_init(policy);
78 if (!setspeed)
79 return -EINVAL;
81 switch (event) {
82 case CPUFREQ_GOV_POLICY_EXIT:
83 mutex_lock(&userspace_mutex);
84 policy->governor_data = NULL;
85 kfree(setspeed);
86 mutex_unlock(&userspace_mutex);
87 break;
88 case CPUFREQ_GOV_START:
89 BUG_ON(!policy->cur);
90 pr_debug("started managing cpu %u\n", cpu);
92 mutex_lock(&userspace_mutex);
93 per_cpu(cpu_is_managed, cpu) = 1;
94 *setspeed = policy->cur;
95 mutex_unlock(&userspace_mutex);
96 break;
97 case CPUFREQ_GOV_STOP:
98 pr_debug("managing cpu %u stopped\n", cpu);
100 mutex_lock(&userspace_mutex);
101 per_cpu(cpu_is_managed, cpu) = 0;
102 *setspeed = 0;
103 mutex_unlock(&userspace_mutex);
104 break;
105 case CPUFREQ_GOV_LIMITS:
106 mutex_lock(&userspace_mutex);
107 pr_debug("limit event for cpu %u: %u - %u kHz, currently %u kHz, last set to %u kHz\n",
108 cpu, policy->min, policy->max, policy->cur, *setspeed);
110 if (policy->max < *setspeed)
111 __cpufreq_driver_target(policy, policy->max,
112 CPUFREQ_RELATION_H);
113 else if (policy->min > *setspeed)
114 __cpufreq_driver_target(policy, policy->min,
115 CPUFREQ_RELATION_L);
116 else
117 __cpufreq_driver_target(policy, *setspeed,
118 CPUFREQ_RELATION_L);
119 mutex_unlock(&userspace_mutex);
120 break;
122 return rc;
125 #ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
126 static
127 #endif
128 struct cpufreq_governor cpufreq_gov_userspace = {
129 .name = "userspace",
130 .governor = cpufreq_governor_userspace,
131 .store_setspeed = cpufreq_set,
132 .show_setspeed = show_speed,
133 .owner = THIS_MODULE,
136 static int __init cpufreq_gov_userspace_init(void)
138 return cpufreq_register_governor(&cpufreq_gov_userspace);
141 static void __exit cpufreq_gov_userspace_exit(void)
143 cpufreq_unregister_governor(&cpufreq_gov_userspace);
146 MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>, "
147 "Russell King <rmk@arm.linux.org.uk>");
148 MODULE_DESCRIPTION("CPUfreq policy governor 'userspace'");
149 MODULE_LICENSE("GPL");
151 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
152 fs_initcall(cpufreq_gov_userspace_init);
153 #else
154 module_init(cpufreq_gov_userspace_init);
155 #endif
156 module_exit(cpufreq_gov_userspace_exit);