Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Freescale Semiconductor, Inc. |
| 3 | * |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 4 | * CPU Frequency Scaling driver for Freescale QorIQ SoCs. |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 12 | |
| 13 | #include <linux/clk.h> |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 14 | #include <linux/clk-provider.h> |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 15 | #include <linux/cpufreq.h> |
Hongtao Jia | 8ae1702 | 2015-11-26 17:21:11 +0800 | [diff] [blame] | 16 | #include <linux/cpu_cooling.h> |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 17 | #include <linux/errno.h> |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 18 | #include <linux/init.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/mutex.h> |
| 22 | #include <linux/of.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/smp.h> |
| 25 | |
| 26 | /** |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 27 | * struct cpu_data |
Tang Yuantian | 8a95c14 | 2015-06-04 14:25:42 +0800 | [diff] [blame] | 28 | * @pclk: the parent clock of cpu |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 29 | * @table: frequency table |
| 30 | */ |
| 31 | struct cpu_data { |
Tang Yuantian | 8a95c14 | 2015-06-04 14:25:42 +0800 | [diff] [blame] | 32 | struct clk **pclk; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 33 | struct cpufreq_frequency_table *table; |
Hongtao Jia | 8ae1702 | 2015-11-26 17:21:11 +0800 | [diff] [blame] | 34 | struct thermal_cooling_device *cdev; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 37 | /* |
| 38 | * Don't use cpufreq on this SoC -- used when the SoC would have otherwise |
| 39 | * matched a more generic compatible. |
| 40 | */ |
| 41 | #define SOC_BLACKLIST 1 |
| 42 | |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 43 | /** |
| 44 | * struct soc_data - SoC specific data |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 45 | * @flags: SOC_xxx |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 46 | */ |
| 47 | struct soc_data { |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 48 | u32 flags; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 51 | static u32 get_bus_freq(void) |
| 52 | { |
| 53 | struct device_node *soc; |
| 54 | u32 sysfreq; |
| 55 | |
| 56 | soc = of_find_node_by_type(NULL, "soc"); |
| 57 | if (!soc) |
| 58 | return 0; |
| 59 | |
| 60 | if (of_property_read_u32(soc, "bus-frequency", &sysfreq)) |
| 61 | sysfreq = 0; |
| 62 | |
| 63 | of_node_put(soc); |
| 64 | |
| 65 | return sysfreq; |
| 66 | } |
| 67 | |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 68 | static struct clk *cpu_to_clk(int cpu) |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 69 | { |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 70 | struct device_node *np; |
| 71 | struct clk *clk; |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 72 | |
| 73 | if (!cpu_present(cpu)) |
| 74 | return NULL; |
| 75 | |
| 76 | np = of_get_cpu_node(cpu, NULL); |
| 77 | if (!np) |
| 78 | return NULL; |
| 79 | |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 80 | clk = of_clk_get(np, 0); |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 81 | of_node_put(np); |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 82 | return clk; |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /* traverse cpu nodes to get cpu mask of sharing clock wire */ |
| 86 | static void set_affected_cpus(struct cpufreq_policy *policy) |
| 87 | { |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 88 | struct cpumask *dstp = policy->cpus; |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 89 | struct clk *clk; |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 90 | int i; |
| 91 | |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 92 | for_each_present_cpu(i) { |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 93 | clk = cpu_to_clk(i); |
| 94 | if (IS_ERR(clk)) { |
| 95 | pr_err("%s: no clock for cpu %d\n", __func__, i); |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 96 | continue; |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 97 | } |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 98 | |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 99 | if (clk_is_match(policy->clk, clk)) |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 100 | cpumask_set_cpu(i, dstp); |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 101 | } |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 102 | } |
| 103 | |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 104 | /* reduce the duplicated frequencies in frequency table */ |
| 105 | static void freq_table_redup(struct cpufreq_frequency_table *freq_table, |
| 106 | int count) |
| 107 | { |
| 108 | int i, j; |
| 109 | |
| 110 | for (i = 1; i < count; i++) { |
| 111 | for (j = 0; j < i; j++) { |
| 112 | if (freq_table[j].frequency == CPUFREQ_ENTRY_INVALID || |
| 113 | freq_table[j].frequency != |
| 114 | freq_table[i].frequency) |
| 115 | continue; |
| 116 | |
| 117 | freq_table[i].frequency = CPUFREQ_ENTRY_INVALID; |
| 118 | break; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /* sort the frequencies in frequency table in descenting order */ |
| 124 | static void freq_table_sort(struct cpufreq_frequency_table *freq_table, |
| 125 | int count) |
| 126 | { |
| 127 | int i, j, ind; |
| 128 | unsigned int freq, max_freq; |
| 129 | struct cpufreq_frequency_table table; |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 130 | |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 131 | for (i = 0; i < count - 1; i++) { |
| 132 | max_freq = freq_table[i].frequency; |
| 133 | ind = i; |
| 134 | for (j = i + 1; j < count; j++) { |
| 135 | freq = freq_table[j].frequency; |
| 136 | if (freq == CPUFREQ_ENTRY_INVALID || |
| 137 | freq <= max_freq) |
| 138 | continue; |
| 139 | ind = j; |
| 140 | max_freq = freq; |
| 141 | } |
| 142 | |
| 143 | if (ind != i) { |
| 144 | /* exchange the frequencies */ |
| 145 | table.driver_data = freq_table[i].driver_data; |
| 146 | table.frequency = freq_table[i].frequency; |
| 147 | freq_table[i].driver_data = freq_table[ind].driver_data; |
| 148 | freq_table[i].frequency = freq_table[ind].frequency; |
| 149 | freq_table[ind].driver_data = table.driver_data; |
| 150 | freq_table[ind].frequency = table.frequency; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 155 | static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy) |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 156 | { |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 157 | struct device_node *np; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 158 | int i, count, ret; |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 159 | u32 freq; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 160 | struct clk *clk; |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 161 | const struct clk_hw *hwclk; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 162 | struct cpufreq_frequency_table *table; |
| 163 | struct cpu_data *data; |
| 164 | unsigned int cpu = policy->cpu; |
Ed Swarthout | 906fe03 | 2014-06-05 18:56:17 -0500 | [diff] [blame] | 165 | u64 u64temp; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 166 | |
| 167 | np = of_get_cpu_node(cpu, NULL); |
| 168 | if (!np) |
| 169 | return -ENODEV; |
| 170 | |
| 171 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 172 | if (!data) |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 173 | goto err_np; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 174 | |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 175 | policy->clk = of_clk_get(np, 0); |
| 176 | if (IS_ERR(policy->clk)) { |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 177 | pr_err("%s: no clock information\n", __func__); |
| 178 | goto err_nomem2; |
| 179 | } |
| 180 | |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 181 | hwclk = __clk_get_hw(policy->clk); |
| 182 | count = clk_hw_get_num_parents(hwclk); |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 183 | |
Tang Yuantian | 8a95c14 | 2015-06-04 14:25:42 +0800 | [diff] [blame] | 184 | data->pclk = kcalloc(count, sizeof(struct clk *), GFP_KERNEL); |
| 185 | if (!data->pclk) { |
| 186 | pr_err("%s: no memory\n", __func__); |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 187 | goto err_nomem2; |
Tang Yuantian | 8a95c14 | 2015-06-04 14:25:42 +0800 | [diff] [blame] | 188 | } |
| 189 | |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 190 | table = kcalloc(count + 1, sizeof(*table), GFP_KERNEL); |
| 191 | if (!table) { |
| 192 | pr_err("%s: no memory\n", __func__); |
Tang Yuantian | 8a95c14 | 2015-06-04 14:25:42 +0800 | [diff] [blame] | 193 | goto err_pclk; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 196 | for (i = 0; i < count; i++) { |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 197 | clk = clk_hw_get_parent_by_index(hwclk, i)->clk; |
Tang Yuantian | 8a95c14 | 2015-06-04 14:25:42 +0800 | [diff] [blame] | 198 | data->pclk[i] = clk; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 199 | freq = clk_get_rate(clk); |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 200 | table[i].frequency = freq / 1000; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 201 | table[i].driver_data = i; |
| 202 | } |
| 203 | freq_table_redup(table, count); |
| 204 | freq_table_sort(table, count); |
| 205 | table[i].frequency = CPUFREQ_TABLE_END; |
| 206 | |
| 207 | /* set the min and max frequency properly */ |
Viresh Kumar | 6b4147d | 2013-09-16 18:56:28 +0530 | [diff] [blame] | 208 | ret = cpufreq_table_validate_and_show(policy, table); |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 209 | if (ret) { |
| 210 | pr_err("invalid frequency table: %d\n", ret); |
| 211 | goto err_nomem1; |
| 212 | } |
| 213 | |
| 214 | data->table = table; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 215 | |
| 216 | /* update ->cpus if we have cluster, no harm if not */ |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 217 | set_affected_cpus(policy); |
| 218 | policy->driver_data = data; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 219 | |
Ed Swarthout | 906fe03 | 2014-06-05 18:56:17 -0500 | [diff] [blame] | 220 | /* Minimum transition latency is 12 platform clocks */ |
| 221 | u64temp = 12ULL * NSEC_PER_SEC; |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 222 | do_div(u64temp, get_bus_freq()); |
Ed Swarthout | 906fe03 | 2014-06-05 18:56:17 -0500 | [diff] [blame] | 223 | policy->cpuinfo.transition_latency = u64temp + 1; |
Tim Gardner | 6712d29 | 2014-04-28 10:18:18 -0600 | [diff] [blame] | 224 | |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 225 | of_node_put(np); |
| 226 | |
| 227 | return 0; |
| 228 | |
| 229 | err_nomem1: |
| 230 | kfree(table); |
Tang Yuantian | 8a95c14 | 2015-06-04 14:25:42 +0800 | [diff] [blame] | 231 | err_pclk: |
| 232 | kfree(data->pclk); |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 233 | err_nomem2: |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 234 | kfree(data); |
| 235 | err_np: |
| 236 | of_node_put(np); |
| 237 | |
| 238 | return -ENODEV; |
| 239 | } |
| 240 | |
Jia Hongtao | 495c716 | 2016-04-19 17:00:06 +0800 | [diff] [blame] | 241 | static int qoriq_cpufreq_cpu_exit(struct cpufreq_policy *policy) |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 242 | { |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 243 | struct cpu_data *data = policy->driver_data; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 244 | |
Jia Hongtao | 394cb83 | 2016-04-19 17:00:07 +0800 | [diff] [blame] | 245 | cpufreq_cooling_unregister(data->cdev); |
Tang Yuantian | 8a95c14 | 2015-06-04 14:25:42 +0800 | [diff] [blame] | 246 | kfree(data->pclk); |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 247 | kfree(data->table); |
| 248 | kfree(data); |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 249 | policy->driver_data = NULL; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 254 | static int qoriq_cpufreq_target(struct cpufreq_policy *policy, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 255 | unsigned int index) |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 256 | { |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 257 | struct clk *parent; |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 258 | struct cpu_data *data = policy->driver_data; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 259 | |
Tang Yuantian | 8a95c14 | 2015-06-04 14:25:42 +0800 | [diff] [blame] | 260 | parent = data->pclk[data->table[index].driver_data]; |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 261 | return clk_set_parent(policy->clk, parent); |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Hongtao Jia | 8ae1702 | 2015-11-26 17:21:11 +0800 | [diff] [blame] | 264 | |
| 265 | static void qoriq_cpufreq_ready(struct cpufreq_policy *policy) |
| 266 | { |
| 267 | struct cpu_data *cpud = policy->driver_data; |
| 268 | struct device_node *np = of_get_cpu_node(policy->cpu, NULL); |
| 269 | |
| 270 | if (of_find_property(np, "#cooling-cells", NULL)) { |
| 271 | cpud->cdev = of_cpufreq_cooling_register(np, |
| 272 | policy->related_cpus); |
| 273 | |
Jia Hongtao | 27b8fe8 | 2016-04-18 15:59:32 +0800 | [diff] [blame] | 274 | if (IS_ERR(cpud->cdev) && PTR_ERR(cpud->cdev) != -ENOSYS) { |
| 275 | pr_err("cpu%d is not running as cooling device: %ld\n", |
Hongtao Jia | 8ae1702 | 2015-11-26 17:21:11 +0800 | [diff] [blame] | 276 | policy->cpu, PTR_ERR(cpud->cdev)); |
| 277 | |
| 278 | cpud->cdev = NULL; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | of_node_put(np); |
| 283 | } |
| 284 | |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 285 | static struct cpufreq_driver qoriq_cpufreq_driver = { |
| 286 | .name = "qoriq_cpufreq", |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 287 | .flags = CPUFREQ_CONST_LOOPS, |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 288 | .init = qoriq_cpufreq_cpu_init, |
Jia Hongtao | 495c716 | 2016-04-19 17:00:06 +0800 | [diff] [blame] | 289 | .exit = qoriq_cpufreq_cpu_exit, |
Viresh Kumar | dc2398d | 2013-10-03 20:28:18 +0530 | [diff] [blame] | 290 | .verify = cpufreq_generic_frequency_table_verify, |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 291 | .target_index = qoriq_cpufreq_target, |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 292 | .get = cpufreq_generic_get, |
Hongtao Jia | 8ae1702 | 2015-11-26 17:21:11 +0800 | [diff] [blame] | 293 | .ready = qoriq_cpufreq_ready, |
Viresh Kumar | dc2398d | 2013-10-03 20:28:18 +0530 | [diff] [blame] | 294 | .attr = cpufreq_generic_attr, |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 295 | }; |
| 296 | |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 297 | static const struct soc_data blacklist = { |
| 298 | .flags = SOC_BLACKLIST, |
| 299 | }; |
| 300 | |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 301 | static const struct of_device_id node_matches[] __initconst = { |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 302 | /* e6500 cannot use cpufreq due to erratum A-008083 */ |
| 303 | { .compatible = "fsl,b4420-clockgen", &blacklist }, |
| 304 | { .compatible = "fsl,b4860-clockgen", &blacklist }, |
| 305 | { .compatible = "fsl,t2080-clockgen", &blacklist }, |
| 306 | { .compatible = "fsl,t4240-clockgen", &blacklist }, |
| 307 | |
| 308 | { .compatible = "fsl,ls1012a-clockgen", }, |
| 309 | { .compatible = "fsl,ls1021a-clockgen", }, |
| 310 | { .compatible = "fsl,ls1043a-clockgen", }, |
| 311 | { .compatible = "fsl,ls1046a-clockgen", }, |
| 312 | { .compatible = "fsl,ls1088a-clockgen", }, |
| 313 | { .compatible = "fsl,ls2080a-clockgen", }, |
| 314 | { .compatible = "fsl,p4080-clockgen", }, |
| 315 | { .compatible = "fsl,qoriq-clockgen-1.0", }, |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 316 | { .compatible = "fsl,qoriq-clockgen-2.0", }, |
| 317 | {} |
| 318 | }; |
| 319 | |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 320 | static int __init qoriq_cpufreq_init(void) |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 321 | { |
| 322 | int ret; |
| 323 | struct device_node *np; |
| 324 | const struct of_device_id *match; |
| 325 | const struct soc_data *data; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 326 | |
| 327 | np = of_find_matching_node(NULL, node_matches); |
| 328 | if (!np) |
| 329 | return -ENODEV; |
| 330 | |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 331 | match = of_match_node(node_matches, np); |
| 332 | data = match->data; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 333 | |
| 334 | of_node_put(np); |
| 335 | |
Tang Yuantian | b1e9a64 | 2017-02-09 10:33:02 +0800 | [diff] [blame] | 336 | if (data && data->flags & SOC_BLACKLIST) |
| 337 | return -ENODEV; |
| 338 | |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 339 | ret = cpufreq_register_driver(&qoriq_cpufreq_driver); |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 340 | if (!ret) |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 341 | pr_info("Freescale QorIQ CPU frequency scaling driver\n"); |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 342 | |
| 343 | return ret; |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 344 | } |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 345 | module_init(qoriq_cpufreq_init); |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 346 | |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 347 | static void __exit qoriq_cpufreq_exit(void) |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 348 | { |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 349 | cpufreq_unregister_driver(&qoriq_cpufreq_driver); |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 350 | } |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 351 | module_exit(qoriq_cpufreq_exit); |
Tang Yuantian | defa4c7 | 2013-06-05 09:30:48 +0000 | [diff] [blame] | 352 | |
| 353 | MODULE_LICENSE("GPL"); |
| 354 | MODULE_AUTHOR("Tang Yuantian <Yuantian.Tang@freescale.com>"); |
Tang Yuantian | a4f2074 | 2015-03-13 12:39:01 +0800 | [diff] [blame] | 355 | MODULE_DESCRIPTION("cpufreq driver for Freescale QorIQ series SoCs"); |