Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 2 | /* |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 3 | * Copyright (C) 2002,2003 Intrinsyc Software |
| 4 | * |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 5 | * History: |
| 6 | * 31-Jul-2002 : Initial version [FB] |
| 7 | * 29-Jan-2003 : added PXA255 support [FB] |
| 8 | * 20-Apr-2003 : ported to v2.5 (Dustin McIntire, Sensoria Corp.) |
| 9 | * |
| 10 | * Note: |
| 11 | * This driver may change the memory bus clock rate, but will not do any |
| 12 | * platform specific access timing changes... for example if you have flash |
| 13 | * memory connected to CS0, you will need to register a platform specific |
| 14 | * notifier which will adjust the memory access strobes to maintain a |
| 15 | * minimum strobe width. |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 18 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 19 | |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 20 | #include <linux/kernel.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/sched.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/cpufreq.h> |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 25 | #include <linux/err.h> |
| 26 | #include <linux/regulator/consumer.h> |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 27 | #include <linux/io.h> |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 28 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 29 | #include <mach/pxa2xx-regs.h> |
Marek Vasut | ad68bb9 | 2010-11-03 16:29:35 +0100 | [diff] [blame] | 30 | #include <mach/smemc.h> |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 31 | |
| 32 | #ifdef DEBUG |
| 33 | static unsigned int freq_debug; |
Randy Dunlap | c710e39 | 2008-02-27 12:11:16 -0800 | [diff] [blame] | 34 | module_param(freq_debug, uint, 0); |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 35 | MODULE_PARM_DESC(freq_debug, "Set the debug messages to on=1/off=0"); |
| 36 | #else |
| 37 | #define freq_debug 0 |
| 38 | #endif |
| 39 | |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 40 | static struct regulator *vcc_core; |
| 41 | |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 42 | static unsigned int pxa27x_maxfreq; |
| 43 | module_param(pxa27x_maxfreq, uint, 0); |
| 44 | MODULE_PARM_DESC(pxa27x_maxfreq, "Set the pxa27x maxfreq in MHz" |
| 45 | "(typically 624=>pxa270, 416=>pxa271, 520=>pxa272)"); |
| 46 | |
Robert Jarzmik | d927807 | 2017-10-14 23:51:02 +0200 | [diff] [blame] | 47 | struct pxa_cpufreq_data { |
| 48 | struct clk *clk_core; |
| 49 | }; |
| 50 | static struct pxa_cpufreq_data pxa_cpufreq_data; |
| 51 | |
Fabian Frederick | 5235255 | 2015-05-01 10:34:00 +0200 | [diff] [blame] | 52 | struct pxa_freqs { |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 53 | unsigned int khz; |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 54 | int vmin; |
| 55 | int vmax; |
Fabian Frederick | 5235255 | 2015-05-01 10:34:00 +0200 | [diff] [blame] | 56 | }; |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 57 | |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 58 | /* |
| 59 | * PXA255 definitions |
| 60 | */ |
Fabian Frederick | 03c2299 | 2015-05-01 10:34:01 +0200 | [diff] [blame] | 61 | static const struct pxa_freqs pxa255_run_freqs[] = |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 62 | { |
Robert Jarzmik | d927807 | 2017-10-14 23:51:02 +0200 | [diff] [blame] | 63 | /* CPU MEMBUS run turbo PXbus SDRAM */ |
| 64 | { 99500, -1, -1}, /* 99, 99, 50, 50 */ |
| 65 | {132700, -1, -1}, /* 133, 133, 66, 66 */ |
| 66 | {199100, -1, -1}, /* 199, 199, 99, 99 */ |
| 67 | {265400, -1, -1}, /* 265, 265, 133, 66 */ |
| 68 | {331800, -1, -1}, /* 331, 331, 166, 83 */ |
| 69 | {398100, -1, -1}, /* 398, 398, 196, 99 */ |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 70 | }; |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 71 | |
| 72 | /* Use the turbo mode frequencies for the CPUFREQ_POLICY_POWERSAVE policy */ |
Fabian Frederick | 03c2299 | 2015-05-01 10:34:01 +0200 | [diff] [blame] | 73 | static const struct pxa_freqs pxa255_turbo_freqs[] = |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 74 | { |
Robert Jarzmik | d927807 | 2017-10-14 23:51:02 +0200 | [diff] [blame] | 75 | /* CPU run turbo PXbus SDRAM */ |
| 76 | { 99500, -1, -1}, /* 99, 99, 50, 50 */ |
| 77 | {199100, -1, -1}, /* 99, 199, 50, 99 */ |
| 78 | {298500, -1, -1}, /* 99, 287, 50, 99 */ |
| 79 | {298600, -1, -1}, /* 199, 287, 99, 99 */ |
| 80 | {398100, -1, -1}, /* 199, 398, 99, 99 */ |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 81 | }; |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 82 | |
| 83 | #define NUM_PXA25x_RUN_FREQS ARRAY_SIZE(pxa255_run_freqs) |
| 84 | #define NUM_PXA25x_TURBO_FREQS ARRAY_SIZE(pxa255_turbo_freqs) |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 85 | |
Robert Jarzmik | 3679389 | 2008-05-07 20:36:34 +0100 | [diff] [blame] | 86 | static struct cpufreq_frequency_table |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 87 | pxa255_run_freq_table[NUM_PXA25x_RUN_FREQS+1]; |
| 88 | static struct cpufreq_frequency_table |
| 89 | pxa255_turbo_freq_table[NUM_PXA25x_TURBO_FREQS+1]; |
| 90 | |
Marc Zyngier | 65587f7 | 2008-11-04 13:33:25 +0100 | [diff] [blame] | 91 | static unsigned int pxa255_turbo_table; |
| 92 | module_param(pxa255_turbo_table, uint, 0); |
| 93 | MODULE_PARM_DESC(pxa255_turbo_table, "Selects the frequency table (0 = run table, !0 = turbo table)"); |
| 94 | |
Fabian Frederick | 5235255 | 2015-05-01 10:34:00 +0200 | [diff] [blame] | 95 | static struct pxa_freqs pxa27x_freqs[] = { |
Robert Jarzmik | d927807 | 2017-10-14 23:51:02 +0200 | [diff] [blame] | 96 | {104000, 900000, 1705000 }, |
| 97 | {156000, 1000000, 1705000 }, |
| 98 | {208000, 1180000, 1705000 }, |
| 99 | {312000, 1250000, 1705000 }, |
| 100 | {416000, 1350000, 1705000 }, |
| 101 | {520000, 1450000, 1705000 }, |
| 102 | {624000, 1550000, 1705000 } |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | #define NUM_PXA27x_FREQS ARRAY_SIZE(pxa27x_freqs) |
| 106 | static struct cpufreq_frequency_table |
| 107 | pxa27x_freq_table[NUM_PXA27x_FREQS+1]; |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 108 | |
| 109 | extern unsigned get_clk_frequency_khz(int info); |
| 110 | |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 111 | #ifdef CONFIG_REGULATOR |
| 112 | |
Fabian Frederick | 03c2299 | 2015-05-01 10:34:01 +0200 | [diff] [blame] | 113 | static int pxa_cpufreq_change_voltage(const struct pxa_freqs *pxa_freq) |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 114 | { |
| 115 | int ret = 0; |
| 116 | int vmin, vmax; |
| 117 | |
| 118 | if (!cpu_is_pxa27x()) |
| 119 | return 0; |
| 120 | |
| 121 | vmin = pxa_freq->vmin; |
| 122 | vmax = pxa_freq->vmax; |
| 123 | if ((vmin == -1) || (vmax == -1)) |
| 124 | return 0; |
| 125 | |
| 126 | ret = regulator_set_voltage(vcc_core, vmin, vmax); |
| 127 | if (ret) |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 128 | pr_err("Failed to set vcc_core in [%dmV..%dmV]\n", vmin, vmax); |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 129 | return ret; |
| 130 | } |
| 131 | |
Arnd Bergmann | 9505b98 | 2019-03-07 11:22:41 +0100 | [diff] [blame] | 132 | static void pxa_cpufreq_init_voltages(void) |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 133 | { |
| 134 | vcc_core = regulator_get(NULL, "vcc_core"); |
| 135 | if (IS_ERR(vcc_core)) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 136 | pr_info("Didn't find vcc_core regulator\n"); |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 137 | vcc_core = NULL; |
| 138 | } else { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 139 | pr_info("Found vcc_core regulator\n"); |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | #else |
Arnd Bergmann | fb2a24a | 2016-01-25 16:44:38 +0100 | [diff] [blame] | 143 | static int pxa_cpufreq_change_voltage(const struct pxa_freqs *pxa_freq) |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 144 | { |
| 145 | return 0; |
| 146 | } |
| 147 | |
Arnd Bergmann | 9505b98 | 2019-03-07 11:22:41 +0100 | [diff] [blame] | 148 | static void pxa_cpufreq_init_voltages(void) { } |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 149 | #endif |
| 150 | |
Marc Zyngier | 65587f7 | 2008-11-04 13:33:25 +0100 | [diff] [blame] | 151 | static void find_freq_tables(struct cpufreq_frequency_table **freq_table, |
Fabian Frederick | 03c2299 | 2015-05-01 10:34:01 +0200 | [diff] [blame] | 152 | const struct pxa_freqs **pxa_freqs) |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 153 | { |
| 154 | if (cpu_is_pxa25x()) { |
Marc Zyngier | 65587f7 | 2008-11-04 13:33:25 +0100 | [diff] [blame] | 155 | if (!pxa255_turbo_table) { |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 156 | *pxa_freqs = pxa255_run_freqs; |
| 157 | *freq_table = pxa255_run_freq_table; |
Marc Zyngier | 65587f7 | 2008-11-04 13:33:25 +0100 | [diff] [blame] | 158 | } else { |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 159 | *pxa_freqs = pxa255_turbo_freqs; |
| 160 | *freq_table = pxa255_turbo_freq_table; |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 161 | } |
Arnd Bergmann | 7264a2b | 2013-04-25 19:28:57 +0200 | [diff] [blame] | 162 | } else if (cpu_is_pxa27x()) { |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 163 | *pxa_freqs = pxa27x_freqs; |
| 164 | *freq_table = pxa27x_freq_table; |
Arnd Bergmann | 7264a2b | 2013-04-25 19:28:57 +0200 | [diff] [blame] | 165 | } else { |
| 166 | BUG(); |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
| 170 | static void pxa27x_guess_max_freq(void) |
| 171 | { |
| 172 | if (!pxa27x_maxfreq) { |
| 173 | pxa27x_maxfreq = 416000; |
Joe Perches | b49c22a | 2016-04-05 13:28:24 -0700 | [diff] [blame] | 174 | pr_info("PXA CPU 27x max frequency not defined (pxa27x_maxfreq), assuming pxa271 with %dkHz maxfreq\n", |
| 175 | pxa27x_maxfreq); |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 176 | } else { |
| 177 | pxa27x_maxfreq *= 1000; |
| 178 | } |
| 179 | } |
| 180 | |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 181 | static unsigned int pxa_cpufreq_get(unsigned int cpu) |
| 182 | { |
Robert Jarzmik | d927807 | 2017-10-14 23:51:02 +0200 | [diff] [blame] | 183 | struct pxa_cpufreq_data *data = cpufreq_get_driver_data(); |
| 184 | |
| 185 | return (unsigned int) clk_get_rate(data->clk_core) / 1000; |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 186 | } |
| 187 | |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 188 | static int pxa_set_target(struct cpufreq_policy *policy, unsigned int idx) |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 189 | { |
| 190 | struct cpufreq_frequency_table *pxa_freqs_table; |
Fabian Frederick | 03c2299 | 2015-05-01 10:34:01 +0200 | [diff] [blame] | 191 | const struct pxa_freqs *pxa_freq_settings; |
Robert Jarzmik | d927807 | 2017-10-14 23:51:02 +0200 | [diff] [blame] | 192 | struct pxa_cpufreq_data *data = cpufreq_get_driver_data(); |
| 193 | unsigned int new_freq_cpu; |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 194 | int ret = 0; |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 195 | |
| 196 | /* Get the current policy */ |
Marc Zyngier | 65587f7 | 2008-11-04 13:33:25 +0100 | [diff] [blame] | 197 | find_freq_tables(&pxa_freqs_table, &pxa_freq_settings); |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 198 | |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 199 | new_freq_cpu = pxa_freq_settings[idx].khz; |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 200 | |
| 201 | if (freq_debug) |
Robert Jarzmik | d927807 | 2017-10-14 23:51:02 +0200 | [diff] [blame] | 202 | pr_debug("Changing CPU frequency from %d Mhz to %d Mhz\n", |
| 203 | policy->cur / 1000, new_freq_cpu / 1000); |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 204 | |
Viresh Kumar | d4019f0 | 2013-08-14 19:38:24 +0530 | [diff] [blame] | 205 | if (vcc_core && new_freq_cpu > policy->cur) { |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 206 | ret = pxa_cpufreq_change_voltage(&pxa_freq_settings[idx]); |
Viresh Kumar | d4019f0 | 2013-08-14 19:38:24 +0530 | [diff] [blame] | 207 | if (ret) |
| 208 | return ret; |
| 209 | } |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 210 | |
Robert Jarzmik | d927807 | 2017-10-14 23:51:02 +0200 | [diff] [blame] | 211 | clk_set_rate(data->clk_core, new_freq_cpu * 1000); |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 212 | |
| 213 | /* |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 214 | * Even if voltage setting fails, we don't report it, as the frequency |
| 215 | * change succeeded. The voltage reduction is not a critical failure, |
| 216 | * only power savings will suffer from this. |
| 217 | * |
| 218 | * Note: if the voltage change fails, and a return value is returned, a |
| 219 | * bug is triggered (seems a deadlock). Should anybody find out where, |
| 220 | * the "return 0" should become a "return ret". |
| 221 | */ |
Viresh Kumar | d4019f0 | 2013-08-14 19:38:24 +0530 | [diff] [blame] | 222 | if (vcc_core && new_freq_cpu < policy->cur) |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 223 | ret = pxa_cpufreq_change_voltage(&pxa_freq_settings[idx]); |
| 224 | |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
Eric Miao | 50e77fc | 2010-08-18 11:51:13 +0800 | [diff] [blame] | 228 | static int pxa_cpufreq_init(struct cpufreq_policy *policy) |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 229 | { |
| 230 | int i; |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 231 | unsigned int freq; |
Marc Zyngier | 65587f7 | 2008-11-04 13:33:25 +0100 | [diff] [blame] | 232 | struct cpufreq_frequency_table *pxa255_freq_table; |
Fabian Frederick | 03c2299 | 2015-05-01 10:34:01 +0200 | [diff] [blame] | 233 | const struct pxa_freqs *pxa255_freqs; |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 234 | |
| 235 | /* try to guess pxa27x cpu */ |
| 236 | if (cpu_is_pxa27x()) |
| 237 | pxa27x_guess_max_freq(); |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 238 | |
Robert Jarzmik | 3dbeef2 | 2009-05-17 23:03:55 +0200 | [diff] [blame] | 239 | pxa_cpufreq_init_voltages(); |
| 240 | |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 241 | /* set default policy and cpuinfo */ |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 242 | policy->cpuinfo.transition_latency = 1000; /* FIXME: 1 ms, assumed */ |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 243 | |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 244 | /* Generate pxa25x the run cpufreq_frequency_table struct */ |
| 245 | for (i = 0; i < NUM_PXA25x_RUN_FREQS; i++) { |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 246 | pxa255_run_freq_table[i].frequency = pxa255_run_freqs[i].khz; |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 247 | pxa255_run_freq_table[i].driver_data = i; |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 248 | } |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 249 | pxa255_run_freq_table[i].frequency = CPUFREQ_TABLE_END; |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 250 | |
| 251 | /* Generate pxa25x the turbo cpufreq_frequency_table struct */ |
| 252 | for (i = 0; i < NUM_PXA25x_TURBO_FREQS; i++) { |
Robert Jarzmik | 3679389 | 2008-05-07 20:36:34 +0100 | [diff] [blame] | 253 | pxa255_turbo_freq_table[i].frequency = |
| 254 | pxa255_turbo_freqs[i].khz; |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 255 | pxa255_turbo_freq_table[i].driver_data = i; |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 256 | } |
| 257 | pxa255_turbo_freq_table[i].frequency = CPUFREQ_TABLE_END; |
| 258 | |
Marc Zyngier | 65587f7 | 2008-11-04 13:33:25 +0100 | [diff] [blame] | 259 | pxa255_turbo_table = !!pxa255_turbo_table; |
| 260 | |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 261 | /* Generate the pxa27x cpufreq_frequency_table struct */ |
| 262 | for (i = 0; i < NUM_PXA27x_FREQS; i++) { |
| 263 | freq = pxa27x_freqs[i].khz; |
| 264 | if (freq > pxa27x_maxfreq) |
| 265 | break; |
| 266 | pxa27x_freq_table[i].frequency = freq; |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 267 | pxa27x_freq_table[i].driver_data = i; |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 268 | } |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 269 | pxa27x_freq_table[i].driver_data = i; |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 270 | pxa27x_freq_table[i].frequency = CPUFREQ_TABLE_END; |
| 271 | |
| 272 | /* |
| 273 | * Set the policy's minimum and maximum frequencies from the tables |
| 274 | * just constructed. This sets cpuinfo.mxx_freq, min and max. |
| 275 | */ |
Marc Zyngier | 65587f7 | 2008-11-04 13:33:25 +0100 | [diff] [blame] | 276 | if (cpu_is_pxa25x()) { |
| 277 | find_freq_tables(&pxa255_freq_table, &pxa255_freqs); |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 278 | pr_info("using %s frequency table\n", |
Marc Zyngier | 65587f7 | 2008-11-04 13:33:25 +0100 | [diff] [blame] | 279 | pxa255_turbo_table ? "turbo" : "run"); |
Viresh Kumar | 6a77a1e | 2013-09-16 18:56:04 +0530 | [diff] [blame] | 280 | |
Viresh Kumar | 8ed5a21 | 2018-02-26 10:39:00 +0530 | [diff] [blame] | 281 | policy->freq_table = pxa255_freq_table; |
Marc Zyngier | 65587f7 | 2008-11-04 13:33:25 +0100 | [diff] [blame] | 282 | } |
Viresh Kumar | 6a77a1e | 2013-09-16 18:56:04 +0530 | [diff] [blame] | 283 | else if (cpu_is_pxa27x()) { |
Viresh Kumar | 8ed5a21 | 2018-02-26 10:39:00 +0530 | [diff] [blame] | 284 | policy->freq_table = pxa27x_freq_table; |
Viresh Kumar | 6a77a1e | 2013-09-16 18:56:04 +0530 | [diff] [blame] | 285 | } |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 286 | |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 287 | pr_info("frequency change support initialized\n"); |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | static struct cpufreq_driver pxa_cpufreq_driver = { |
Viresh Kumar | ae6b427 | 2013-12-03 11:20:45 +0530 | [diff] [blame] | 293 | .flags = CPUFREQ_NEED_INITIAL_FREQ_CHECK, |
Viresh Kumar | bf36e48 | 2013-10-03 20:28:20 +0530 | [diff] [blame] | 294 | .verify = cpufreq_generic_frequency_table_verify, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 295 | .target_index = pxa_set_target, |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 296 | .init = pxa_cpufreq_init, |
Holger Schurig | ea833f0 | 2008-02-11 16:53:15 +0100 | [diff] [blame] | 297 | .get = pxa_cpufreq_get, |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 298 | .name = "PXA2xx", |
Robert Jarzmik | d927807 | 2017-10-14 23:51:02 +0200 | [diff] [blame] | 299 | .driver_data = &pxa_cpufreq_data, |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | static int __init pxa_cpu_init(void) |
| 303 | { |
| 304 | int ret = -ENODEV; |
Robert Jarzmik | d927807 | 2017-10-14 23:51:02 +0200 | [diff] [blame] | 305 | |
| 306 | pxa_cpufreq_data.clk_core = clk_get_sys(NULL, "core"); |
| 307 | if (IS_ERR(pxa_cpufreq_data.clk_core)) |
| 308 | return PTR_ERR(pxa_cpufreq_data.clk_core); |
| 309 | |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 310 | if (cpu_is_pxa25x() || cpu_is_pxa27x()) |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 311 | ret = cpufreq_register_driver(&pxa_cpufreq_driver); |
| 312 | return ret; |
| 313 | } |
| 314 | |
| 315 | static void __exit pxa_cpu_exit(void) |
| 316 | { |
Robert Jarzmik | 592eb99 | 2008-05-07 20:39:06 +0100 | [diff] [blame] | 317 | cpufreq_unregister_driver(&pxa_cpufreq_driver); |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | |
Robert Jarzmik | 3679389 | 2008-05-07 20:36:34 +0100 | [diff] [blame] | 321 | MODULE_AUTHOR("Intrinsyc Software Inc."); |
| 322 | MODULE_DESCRIPTION("CPU frequency changing driver for the PXA architecture"); |
Russell King | 9e2697f | 2007-12-14 13:30:14 +0000 | [diff] [blame] | 323 | MODULE_LICENSE("GPL"); |
| 324 | module_init(pxa_cpu_init); |
| 325 | module_exit(pxa_cpu_exit); |