Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de> |
| 3 | * |
| 4 | * Licensed under the terms of the GNU GPL License version 2. |
| 5 | */ |
| 6 | |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <errno.h> |
| 10 | #include <stdlib.h> |
| 11 | #include <string.h> |
| 12 | |
| 13 | #include "cpufreq.h" |
| 14 | #include "sysfs.h" |
| 15 | |
| 16 | int cpufreq_cpu_exists(unsigned int cpu) |
| 17 | { |
| 18 | return sysfs_cpu_exists(cpu); |
| 19 | } |
| 20 | |
| 21 | unsigned long cpufreq_get_freq_kernel(unsigned int cpu) |
| 22 | { |
| 23 | return sysfs_get_freq_kernel(cpu); |
| 24 | } |
| 25 | |
| 26 | unsigned long cpufreq_get_freq_hardware(unsigned int cpu) |
| 27 | { |
| 28 | return sysfs_get_freq_hardware(cpu); |
| 29 | } |
| 30 | |
| 31 | unsigned long cpufreq_get_transition_latency(unsigned int cpu) |
| 32 | { |
| 33 | return sysfs_get_freq_transition_latency(cpu); |
| 34 | } |
| 35 | |
| 36 | int cpufreq_get_hardware_limits(unsigned int cpu, |
| 37 | unsigned long *min, |
| 38 | unsigned long *max) |
| 39 | { |
| 40 | if ((!min) || (!max)) |
| 41 | return -EINVAL; |
| 42 | return sysfs_get_freq_hardware_limits(cpu, min, max); |
| 43 | } |
| 44 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 45 | char *cpufreq_get_driver(unsigned int cpu) |
| 46 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 47 | return sysfs_get_freq_driver(cpu); |
| 48 | } |
| 49 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 50 | void cpufreq_put_driver(char *ptr) |
| 51 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 52 | if (!ptr) |
| 53 | return; |
| 54 | free(ptr); |
| 55 | } |
| 56 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 57 | struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu) |
| 58 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 59 | return sysfs_get_freq_policy(cpu); |
| 60 | } |
| 61 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 62 | void cpufreq_put_policy(struct cpufreq_policy *policy) |
| 63 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 64 | if ((!policy) || (!policy->governor)) |
| 65 | return; |
| 66 | |
| 67 | free(policy->governor); |
| 68 | policy->governor = NULL; |
| 69 | free(policy); |
| 70 | } |
| 71 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 72 | struct cpufreq_available_governors *cpufreq_get_available_governors(unsigned |
| 73 | int cpu) |
| 74 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 75 | return sysfs_get_freq_available_governors(cpu); |
| 76 | } |
| 77 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 78 | void cpufreq_put_available_governors(struct cpufreq_available_governors *any) |
| 79 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 80 | struct cpufreq_available_governors *tmp, *next; |
| 81 | |
| 82 | if (!any) |
| 83 | return; |
| 84 | |
| 85 | tmp = any->first; |
| 86 | while (tmp) { |
| 87 | next = tmp->next; |
| 88 | if (tmp->governor) |
| 89 | free(tmp->governor); |
| 90 | free(tmp); |
| 91 | tmp = next; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 96 | struct cpufreq_available_frequencies |
| 97 | *cpufreq_get_available_frequencies(unsigned int cpu) |
| 98 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 99 | return sysfs_get_available_frequencies(cpu); |
| 100 | } |
| 101 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 102 | void cpufreq_put_available_frequencies(struct cpufreq_available_frequencies |
| 103 | *any) { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 104 | struct cpufreq_available_frequencies *tmp, *next; |
| 105 | |
| 106 | if (!any) |
| 107 | return; |
| 108 | |
| 109 | tmp = any->first; |
| 110 | while (tmp) { |
| 111 | next = tmp->next; |
| 112 | free(tmp); |
| 113 | tmp = next; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 118 | struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned int cpu) |
| 119 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 120 | return sysfs_get_freq_affected_cpus(cpu); |
| 121 | } |
| 122 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 123 | void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *any) |
| 124 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 125 | struct cpufreq_affected_cpus *tmp, *next; |
| 126 | |
| 127 | if (!any) |
| 128 | return; |
| 129 | |
| 130 | tmp = any->first; |
| 131 | while (tmp) { |
| 132 | next = tmp->next; |
| 133 | free(tmp); |
| 134 | tmp = next; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 139 | struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned int cpu) |
| 140 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 141 | return sysfs_get_freq_related_cpus(cpu); |
| 142 | } |
| 143 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 144 | void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *any) |
| 145 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 146 | cpufreq_put_affected_cpus(any); |
| 147 | } |
| 148 | |
| 149 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 150 | int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy) |
| 151 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 152 | if (!policy || !(policy->governor)) |
| 153 | return -EINVAL; |
| 154 | |
| 155 | return sysfs_set_freq_policy(cpu, policy); |
| 156 | } |
| 157 | |
| 158 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 159 | int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq) |
| 160 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 161 | return sysfs_modify_freq_policy_min(cpu, min_freq); |
| 162 | } |
| 163 | |
| 164 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 165 | int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq) |
| 166 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 167 | return sysfs_modify_freq_policy_max(cpu, max_freq); |
| 168 | } |
| 169 | |
| 170 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 171 | int cpufreq_modify_policy_governor(unsigned int cpu, char *governor) |
| 172 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 173 | if ((!governor) || (strlen(governor) > 19)) |
| 174 | return -EINVAL; |
| 175 | |
| 176 | return sysfs_modify_freq_policy_governor(cpu, governor); |
| 177 | } |
| 178 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 179 | int cpufreq_set_frequency(unsigned int cpu, unsigned long target_frequency) |
| 180 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 181 | return sysfs_set_frequency(cpu, target_frequency); |
| 182 | } |
| 183 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 184 | struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu, |
| 185 | unsigned long long *total_time) |
| 186 | { |
| 187 | return sysfs_get_freq_stats(cpu, total_time); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 190 | void cpufreq_put_stats(struct cpufreq_stats *any) |
| 191 | { |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 192 | struct cpufreq_stats *tmp, *next; |
| 193 | |
| 194 | if (!any) |
| 195 | return; |
| 196 | |
| 197 | tmp = any->first; |
| 198 | while (tmp) { |
| 199 | next = tmp->next; |
| 200 | free(tmp); |
| 201 | tmp = next; |
| 202 | } |
| 203 | } |
| 204 | |
Dominik Brodowski | 6c2b818 | 2011-04-19 19:42:33 +0200 | [diff] [blame] | 205 | unsigned long cpufreq_get_transitions(unsigned int cpu) |
| 206 | { |
| 207 | return sysfs_get_freq_transitions(cpu); |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 208 | } |