diff options
author | Srinidhi Kasagar <srinidhi.kasagar@intel.com> | 2014-12-19 12:43:51 -0500 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2014-12-20 13:37:37 -0500 |
commit | e7ddf4b7b3c5fe64902c4fb9edac92532c87cd75 (patch) | |
tree | f89bacb2cba6e874d3d5f7c5ecf456bbdfb5261f /drivers/cpufreq | |
parent | 108cc2e7d212c7d52694fb400423da807e1e5fe4 (diff) |
cpufreq: Add SFI based cpufreq driver support
This adds the SFI based cpu freq driver for some of the Intel's
Silvermont based Atom architectures like Z34xx and Z35xx.
Signed-off-by: Rudramuni, Vishwesh M <vishwesh.m.rudramuni@intel.com>
Signed-off-by: Srinidhi Kasagar <srinidhi.kasagar@intel.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r-- | drivers/cpufreq/Kconfig.x86 | 10 | ||||
-rw-r--r-- | drivers/cpufreq/Makefile | 1 | ||||
-rw-r--r-- | drivers/cpufreq/sfi-cpufreq.c | 136 |
3 files changed, 147 insertions, 0 deletions
diff --git a/drivers/cpufreq/Kconfig.x86 b/drivers/cpufreq/Kconfig.x86 index 89ae88f91895..c59bdcb83217 100644 --- a/drivers/cpufreq/Kconfig.x86 +++ b/drivers/cpufreq/Kconfig.x86 | |||
@@ -57,6 +57,16 @@ config X86_ACPI_CPUFREQ_CPB | |||
57 | By enabling this option the acpi_cpufreq driver provides the old | 57 | By enabling this option the acpi_cpufreq driver provides the old |
58 | entry in addition to the new boost ones, for compatibility reasons. | 58 | entry in addition to the new boost ones, for compatibility reasons. |
59 | 59 | ||
60 | config X86_SFI_CPUFREQ | ||
61 | tristate "SFI Performance-States driver" | ||
62 | depends on X86_INTEL_MID && SFI | ||
63 | help | ||
64 | This adds a CPUFreq driver for some Silvermont based Intel Atom | ||
65 | architectures like Z34xx and Z35xx which enumerate processor | ||
66 | performance states through SFI. | ||
67 | |||
68 | If in doubt, say N. | ||
69 | |||
60 | config ELAN_CPUFREQ | 70 | config ELAN_CPUFREQ |
61 | tristate "AMD Elan SC400 and SC410" | 71 | tristate "AMD Elan SC400 and SC410" |
62 | depends on MELAN | 72 | depends on MELAN |
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile index 40c53dc1937e..2e50f55e14d3 100644 --- a/drivers/cpufreq/Makefile +++ b/drivers/cpufreq/Makefile | |||
@@ -41,6 +41,7 @@ obj-$(CONFIG_X86_P4_CLOCKMOD) += p4-clockmod.o | |||
41 | obj-$(CONFIG_X86_CPUFREQ_NFORCE2) += cpufreq-nforce2.o | 41 | obj-$(CONFIG_X86_CPUFREQ_NFORCE2) += cpufreq-nforce2.o |
42 | obj-$(CONFIG_X86_INTEL_PSTATE) += intel_pstate.o | 42 | obj-$(CONFIG_X86_INTEL_PSTATE) += intel_pstate.o |
43 | obj-$(CONFIG_X86_AMD_FREQ_SENSITIVITY) += amd_freq_sensitivity.o | 43 | obj-$(CONFIG_X86_AMD_FREQ_SENSITIVITY) += amd_freq_sensitivity.o |
44 | obj-$(CONFIG_X86_SFI_CPUFREQ) += sfi-cpufreq.o | ||
44 | 45 | ||
45 | ################################################################################## | 46 | ################################################################################## |
46 | # ARM SoC drivers | 47 | # ARM SoC drivers |
diff --git a/drivers/cpufreq/sfi-cpufreq.c b/drivers/cpufreq/sfi-cpufreq.c new file mode 100644 index 000000000000..ffa3389e535b --- /dev/null +++ b/drivers/cpufreq/sfi-cpufreq.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | * SFI Performance States Driver | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, but | ||
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | * General Public License for more details. | ||
12 | * | ||
13 | * Author: Vishwesh M Rudramuni <vishwesh.m.rudramuni@intel.com> | ||
14 | * Author: Srinidhi Kasagar <srinidhi.kasagar@intel.com> | ||
15 | */ | ||
16 | |||
17 | #include <linux/cpufreq.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/sfi.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/smp.h> | ||
24 | |||
25 | #include <asm/msr.h> | ||
26 | |||
27 | struct cpufreq_frequency_table *freq_table; | ||
28 | static struct sfi_freq_table_entry *sfi_cpufreq_array; | ||
29 | static int num_freq_table_entries; | ||
30 | |||
31 | static int sfi_parse_freq(struct sfi_table_header *table) | ||
32 | { | ||
33 | struct sfi_table_simple *sb; | ||
34 | struct sfi_freq_table_entry *pentry; | ||
35 | int totallen; | ||
36 | |||
37 | sb = (struct sfi_table_simple *)table; | ||
38 | num_freq_table_entries = SFI_GET_NUM_ENTRIES(sb, | ||
39 | struct sfi_freq_table_entry); | ||
40 | if (num_freq_table_entries <= 1) { | ||
41 | pr_err("No p-states discovered\n"); | ||
42 | return -ENODEV; | ||
43 | } | ||
44 | |||
45 | pentry = (struct sfi_freq_table_entry *)sb->pentry; | ||
46 | totallen = num_freq_table_entries * sizeof(*pentry); | ||
47 | |||
48 | sfi_cpufreq_array = kzalloc(totallen, GFP_KERNEL); | ||
49 | if (!sfi_cpufreq_array) | ||
50 | return -ENOMEM; | ||
51 | |||
52 | memcpy(sfi_cpufreq_array, pentry, totallen); | ||
53 | |||
54 | return 0; | ||
55 | } | ||
56 | |||
57 | static int sfi_cpufreq_target(struct cpufreq_policy *policy, unsigned int index) | ||
58 | { | ||
59 | unsigned int next_perf_state = 0; /* Index into perf table */ | ||
60 | u32 lo, hi; | ||
61 | |||
62 | next_perf_state = policy->freq_table[index].driver_data; | ||
63 | |||
64 | rdmsr_on_cpu(policy->cpu, MSR_IA32_PERF_CTL, &lo, &hi); | ||
65 | lo = (lo & ~INTEL_PERF_CTL_MASK) | | ||
66 | ((u32) sfi_cpufreq_array[next_perf_state].ctrl_val & | ||
67 | INTEL_PERF_CTL_MASK); | ||
68 | wrmsr_on_cpu(policy->cpu, MSR_IA32_PERF_CTL, lo, hi); | ||
69 | |||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static int sfi_cpufreq_cpu_init(struct cpufreq_policy *policy) | ||
74 | { | ||
75 | policy->shared_type = CPUFREQ_SHARED_TYPE_HW; | ||
76 | policy->cpuinfo.transition_latency = 100000; /* 100us */ | ||
77 | |||
78 | return cpufreq_table_validate_and_show(policy, freq_table); | ||
79 | } | ||
80 | |||
81 | static struct cpufreq_driver sfi_cpufreq_driver = { | ||
82 | .flags = CPUFREQ_CONST_LOOPS, | ||
83 | .verify = cpufreq_generic_frequency_table_verify, | ||
84 | .target_index = sfi_cpufreq_target, | ||
85 | .init = sfi_cpufreq_cpu_init, | ||
86 | .name = "sfi-cpufreq", | ||
87 | .attr = cpufreq_generic_attr, | ||
88 | }; | ||
89 | |||
90 | static int __init sfi_cpufreq_init(void) | ||
91 | { | ||
92 | int ret, i; | ||
93 | |||
94 | /* parse the freq table from SFI */ | ||
95 | ret = sfi_table_parse(SFI_SIG_FREQ, NULL, NULL, sfi_parse_freq); | ||
96 | if (ret) | ||
97 | return ret; | ||
98 | |||
99 | freq_table = kzalloc(sizeof(*freq_table) * | ||
100 | (num_freq_table_entries + 1), GFP_KERNEL); | ||
101 | if (!freq_table) { | ||
102 | ret = -ENOMEM; | ||
103 | goto err_free_array; | ||
104 | } | ||
105 | |||
106 | for (i = 0; i < num_freq_table_entries; i++) { | ||
107 | freq_table[i].driver_data = i; | ||
108 | freq_table[i].frequency = sfi_cpufreq_array[i].freq_mhz * 1000; | ||
109 | } | ||
110 | freq_table[i].frequency = CPUFREQ_TABLE_END; | ||
111 | |||
112 | ret = cpufreq_register_driver(&sfi_cpufreq_driver); | ||
113 | if (ret) | ||
114 | goto err_free_tbl; | ||
115 | |||
116 | return ret; | ||
117 | |||
118 | err_free_tbl: | ||
119 | kfree(freq_table); | ||
120 | err_free_array: | ||
121 | kfree(sfi_cpufreq_array); | ||
122 | return ret; | ||
123 | } | ||
124 | late_initcall(sfi_cpufreq_init); | ||
125 | |||
126 | static void __exit sfi_cpufreq_exit(void) | ||
127 | { | ||
128 | cpufreq_unregister_driver(&sfi_cpufreq_driver); | ||
129 | kfree(freq_table); | ||
130 | kfree(sfi_cpufreq_array); | ||
131 | } | ||
132 | module_exit(sfi_cpufreq_exit); | ||
133 | |||
134 | MODULE_AUTHOR("Vishwesh M Rudramuni <vishwesh.m.rudramuni@intel.com>"); | ||
135 | MODULE_DESCRIPTION("SFI Performance-States Driver"); | ||
136 | MODULE_LICENSE("GPL"); | ||