Merge tag 'samsung-fixes-4.12' of git://git.kernel.org/pub/scm/linux/kernel/git/krzk...
[sfrench/cifs-2.6.git] / drivers / cpufreq / dbx500-cpufreq.c
1 /*
2  * Copyright (C) STMicroelectronics 2009
3  * Copyright (C) ST-Ericsson SA 2010-2012
4  *
5  * License Terms: GNU General Public License v2
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
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/cpufreq.h>
14 #include <linux/cpu_cooling.h>
15 #include <linux/delay.h>
16 #include <linux/slab.h>
17 #include <linux/platform_device.h>
18 #include <linux/clk.h>
19
20 static struct cpufreq_frequency_table *freq_table;
21 static struct clk *armss_clk;
22 static struct thermal_cooling_device *cdev;
23
24 static int dbx500_cpufreq_target(struct cpufreq_policy *policy,
25                                 unsigned int index)
26 {
27         /* update armss clk frequency */
28         return clk_set_rate(armss_clk, freq_table[index].frequency * 1000);
29 }
30
31 static int dbx500_cpufreq_init(struct cpufreq_policy *policy)
32 {
33         policy->clk = armss_clk;
34         return cpufreq_generic_init(policy, freq_table, 20 * 1000);
35 }
36
37 static int dbx500_cpufreq_exit(struct cpufreq_policy *policy)
38 {
39         if (!IS_ERR(cdev))
40                 cpufreq_cooling_unregister(cdev);
41         return 0;
42 }
43
44 static void dbx500_cpufreq_ready(struct cpufreq_policy *policy)
45 {
46         cdev = cpufreq_cooling_register(policy->cpus);
47         if (IS_ERR(cdev))
48                 pr_err("Failed to register cooling device %ld\n", PTR_ERR(cdev));
49         else
50                 pr_info("Cooling device registered: %s\n", cdev->type);
51 }
52
53 static struct cpufreq_driver dbx500_cpufreq_driver = {
54         .flags  = CPUFREQ_STICKY | CPUFREQ_CONST_LOOPS |
55                         CPUFREQ_NEED_INITIAL_FREQ_CHECK,
56         .verify = cpufreq_generic_frequency_table_verify,
57         .target_index = dbx500_cpufreq_target,
58         .get    = cpufreq_generic_get,
59         .init   = dbx500_cpufreq_init,
60         .exit  = dbx500_cpufreq_exit,
61         .ready  = dbx500_cpufreq_ready,
62         .name   = "DBX500",
63         .attr   = cpufreq_generic_attr,
64 };
65
66 static int dbx500_cpufreq_probe(struct platform_device *pdev)
67 {
68         struct cpufreq_frequency_table *pos;
69
70         freq_table = dev_get_platdata(&pdev->dev);
71         if (!freq_table) {
72                 pr_err("dbx500-cpufreq: Failed to fetch cpufreq table\n");
73                 return -ENODEV;
74         }
75
76         armss_clk = clk_get(&pdev->dev, "armss");
77         if (IS_ERR(armss_clk)) {
78                 pr_err("dbx500-cpufreq: Failed to get armss clk\n");
79                 return PTR_ERR(armss_clk);
80         }
81
82         pr_info("dbx500-cpufreq: Available frequencies:\n");
83         cpufreq_for_each_entry(pos, freq_table)
84                 pr_info("  %d Mhz\n", pos->frequency / 1000);
85
86         return cpufreq_register_driver(&dbx500_cpufreq_driver);
87 }
88
89 static struct platform_driver dbx500_cpufreq_plat_driver = {
90         .driver = {
91                 .name = "cpufreq-ux500",
92         },
93         .probe = dbx500_cpufreq_probe,
94 };
95
96 static int __init dbx500_cpufreq_register(void)
97 {
98         return platform_driver_register(&dbx500_cpufreq_plat_driver);
99 }
100 device_initcall(dbx500_cpufreq_register);
101
102 MODULE_LICENSE("GPL v2");
103 MODULE_DESCRIPTION("cpufreq driver for DBX500");