]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/cpufreq/db8500-cpufreq.c
clk: ux500: Add armss clk and fixup smp_twd clk for u8500
[mirror_ubuntu-zesty-kernel.git] / drivers / cpufreq / db8500-cpufreq.c
CommitLineData
7c1a70e9 1/*
7c1a70e9
MP
2 * Copyright (C) STMicroelectronics 2009
3 * Copyright (C) ST-Ericsson SA 2010
4 *
5 * License Terms: GNU General Public License v2
7c1a70e9
MP
6 * Author: Sundar Iyer <sundar.iyer@stericsson.com>
7 * Author: Martin Persson <martin.persson@stericsson.com>
8 * Author: Jonas Aaberg <jonas.aberg@stericsson.com>
9 *
10 */
b4689444 11#include <linux/module.h>
7c1a70e9
MP
12#include <linux/kernel.h>
13#include <linux/cpufreq.h>
14#include <linux/delay.h>
72b2fd5c 15#include <linux/slab.h>
b4689444 16#include <linux/platform_device.h>
73180f85 17#include <linux/mfd/dbx500-prcmu.h>
72b2fd5c 18#include <mach/id.h>
7c1a70e9 19
fdb44464 20static struct cpufreq_frequency_table *freq_table;
72b2fd5c
LW
21
22static struct freq_attr *db8500_cpufreq_attr[] = {
23 &cpufreq_freq_attr_scaling_available_freqs,
24 NULL,
7c1a70e9
MP
25};
26
72b2fd5c 27static int db8500_cpufreq_verify_speed(struct cpufreq_policy *policy)
7c1a70e9
MP
28{
29 return cpufreq_frequency_table_verify(policy, freq_table);
30}
31
72b2fd5c 32static int db8500_cpufreq_target(struct cpufreq_policy *policy,
7c1a70e9
MP
33 unsigned int target_freq,
34 unsigned int relation)
35{
36 struct cpufreq_freqs freqs;
72b2fd5c 37 unsigned int idx;
7c1a70e9 38
72b2fd5c 39 /* scale the target frequency to one of the extremes supported */
7c1a70e9
MP
40 if (target_freq < policy->cpuinfo.min_freq)
41 target_freq = policy->cpuinfo.min_freq;
42 if (target_freq > policy->cpuinfo.max_freq)
43 target_freq = policy->cpuinfo.max_freq;
44
72b2fd5c
LW
45 /* Lookup the next frequency */
46 if (cpufreq_frequency_table_target
47 (policy, freq_table, target_freq, relation, &idx)) {
48 return -EINVAL;
7c1a70e9
MP
49 }
50
51 freqs.old = policy->cur;
72b2fd5c 52 freqs.new = freq_table[idx].frequency;
7c1a70e9 53
72b2fd5c 54 if (freqs.old == freqs.new)
7c1a70e9 55 return 0;
7c1a70e9 56
72b2fd5c 57 /* pre-change notification */
8efd072b
VG
58 for_each_cpu(freqs.cpu, policy->cpus)
59 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
7c1a70e9 60
72b2fd5c 61 /* request the PRCM unit for opp change */
fdb44464 62 if (prcmu_set_arm_opp(freq_table[idx].index)) {
72b2fd5c
LW
63 pr_err("db8500-cpufreq: Failed to set OPP level\n");
64 return -EINVAL;
7c1a70e9
MP
65 }
66
72b2fd5c 67 /* post change notification */
8efd072b
VG
68 for_each_cpu(freqs.cpu, policy->cpus)
69 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
7c1a70e9 70
72b2fd5c 71 return 0;
7c1a70e9
MP
72}
73
72b2fd5c 74static unsigned int db8500_cpufreq_getspeed(unsigned int cpu)
7c1a70e9 75{
fdb44464 76 int i = 0;
72b2fd5c 77 /* request the prcm to get the current ARM opp */
fdb44464
UH
78 int opp = prcmu_get_arm_opp();
79
80 while (freq_table[i].frequency != CPUFREQ_TABLE_END) {
81 if (opp == freq_table[i].index)
82 return freq_table[i].frequency;
83 i++;
84 }
85
86 /* We could not find a corresponding opp frequency. */
87 return 0;
7c1a70e9
MP
88}
89
72b2fd5c 90static int __cpuinit db8500_cpufreq_init(struct cpufreq_policy *policy)
7c1a70e9 91{
fdb44464
UH
92 int i = 0;
93 int res;
c72fe851 94
6283e328 95 pr_info("db8500-cpufreq : Available frequencies:\n");
fdb44464 96 while (freq_table[i].frequency != CPUFREQ_TABLE_END) {
eb0b38a5 97 pr_info(" %d Mhz\n", freq_table[i].frequency/1000);
fdb44464
UH
98 i++;
99 }
7c1a70e9
MP
100
101 /* get policy fields based on the table */
102 res = cpufreq_frequency_table_cpuinfo(policy, freq_table);
103 if (!res)
104 cpufreq_frequency_table_get_attr(freq_table, policy->cpu);
105 else {
72b2fd5c 106 pr_err("db8500-cpufreq : Failed to read policy table\n");
7c1a70e9
MP
107 return res;
108 }
109
110 policy->min = policy->cpuinfo.min_freq;
111 policy->max = policy->cpuinfo.max_freq;
72b2fd5c 112 policy->cur = db8500_cpufreq_getspeed(policy->cpu);
7c1a70e9
MP
113 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
114
115 /*
116 * FIXME : Need to take time measurement across the target()
117 * function with no/some/all drivers in the notification
118 * list.
119 */
72b2fd5c 120 policy->cpuinfo.transition_latency = 20 * 1000; /* in ns */
7c1a70e9
MP
121
122 /* policy sharing between dual CPUs */
88d8cd52 123 cpumask_copy(policy->cpus, cpu_present_mask);
7c1a70e9
MP
124
125 policy->shared_type = CPUFREQ_SHARED_TYPE_ALL;
126
7c1a70e9
MP
127 return 0;
128}
129
72b2fd5c
LW
130static struct cpufreq_driver db8500_cpufreq_driver = {
131 .flags = CPUFREQ_STICKY,
132 .verify = db8500_cpufreq_verify_speed,
133 .target = db8500_cpufreq_target,
134 .get = db8500_cpufreq_getspeed,
135 .init = db8500_cpufreq_init,
136 .name = "DB8500",
137 .attr = db8500_cpufreq_attr,
7c1a70e9
MP
138};
139
b4689444
UH
140static int db8500_cpufreq_probe(struct platform_device *pdev)
141{
fdb44464
UH
142 freq_table = dev_get_platdata(&pdev->dev);
143
144 if (!freq_table) {
145 pr_err("db8500-cpufreq: Failed to fetch cpufreq table\n");
146 return -ENODEV;
147 }
148
b4689444
UH
149 return cpufreq_register_driver(&db8500_cpufreq_driver);
150}
151
152static struct platform_driver db8500_cpufreq_plat_driver = {
153 .driver = {
154 .name = "cpufreq-u8500",
155 .owner = THIS_MODULE,
156 },
157 .probe = db8500_cpufreq_probe,
158};
159
72b2fd5c 160static int __init db8500_cpufreq_register(void)
7c1a70e9 161{
bc71c096 162 if (!cpu_is_u8500_family())
72b2fd5c 163 return -ENODEV;
7c1a70e9 164
72b2fd5c 165 pr_info("cpufreq for DB8500 started\n");
b4689444 166 return platform_driver_register(&db8500_cpufreq_plat_driver);
7c1a70e9 167}
72b2fd5c 168device_initcall(db8500_cpufreq_register);
b4689444
UH
169
170MODULE_LICENSE("GPL v2");
171MODULE_DESCRIPTION("cpufreq driver for DB8500");