Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 1 | /* |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 2 | * Copyright (C) STMicroelectronics 2009 |
Lee Jones | 0baf066 | 2012-11-28 11:27:44 +0100 | [diff] [blame] | 3 | * Copyright (C) ST-Ericsson SA 2010-2012 |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 4 | * |
| 5 | * License Terms: GNU General Public License v2 |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 6 | * Author: Sundar Iyer <sundar.iyer@stericsson.com> |
| 7 | * Author: Martin Persson <martin.persson@stericsson.com> |
| 8 | * Author: Jonas Aaberg <jonas.aberg@stericsson.com> |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 9 | */ |
Lee Jones | 0baf066 | 2012-11-28 11:27:44 +0100 | [diff] [blame] | 10 | |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 11 | #include <linux/module.h> |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/cpufreq.h> |
Viresh Kumar | 19678ff | 2017-03-14 10:48:31 +0530 | [diff] [blame] | 14 | #include <linux/cpu_cooling.h> |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 15 | #include <linux/delay.h> |
Linus Walleij | 72b2fd5 | 2011-05-15 19:19:51 +0200 | [diff] [blame] | 16 | #include <linux/slab.h> |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Ulf Hansson | 78e30d1 | 2012-10-10 13:42:29 +0200 | [diff] [blame] | 18 | #include <linux/clk.h> |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 19 | |
Ulf Hansson | fdb4446 | 2012-10-10 13:42:25 +0200 | [diff] [blame] | 20 | static struct cpufreq_frequency_table *freq_table; |
Ulf Hansson | 78e30d1 | 2012-10-10 13:42:29 +0200 | [diff] [blame] | 21 | static struct clk *armss_clk; |
Viresh Kumar | 19678ff | 2017-03-14 10:48:31 +0530 | [diff] [blame] | 22 | static struct thermal_cooling_device *cdev; |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 23 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 24 | static int dbx500_cpufreq_target(struct cpufreq_policy *policy, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 25 | unsigned int index) |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 26 | { |
Ulf Hansson | 78e30d1 | 2012-10-10 13:42:29 +0200 | [diff] [blame] | 27 | /* update armss clk frequency */ |
Viresh Kumar | d4019f0 | 2013-08-14 19:38:24 +0530 | [diff] [blame] | 28 | return clk_set_rate(armss_clk, freq_table[index].frequency * 1000); |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 29 | } |
| 30 | |
Paul Gortmaker | 2760984 | 2013-06-19 13:54:04 -0400 | [diff] [blame] | 31 | static int dbx500_cpufreq_init(struct cpufreq_policy *policy) |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 32 | { |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 33 | policy->clk = armss_clk; |
Viresh Kumar | 2b3dc76 | 2013-10-03 20:29:12 +0530 | [diff] [blame] | 34 | return cpufreq_generic_init(policy, freq_table, 20 * 1000); |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Viresh Kumar | 19678ff | 2017-03-14 10:48:31 +0530 | [diff] [blame] | 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 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 53 | static struct cpufreq_driver dbx500_cpufreq_driver = { |
Viresh Kumar | ae6b427 | 2013-12-03 11:20:45 +0530 | [diff] [blame] | 54 | .flags = CPUFREQ_STICKY | CPUFREQ_CONST_LOOPS | |
| 55 | CPUFREQ_NEED_INITIAL_FREQ_CHECK, |
Viresh Kumar | 47150e9 | 2013-10-03 20:28:03 +0530 | [diff] [blame] | 56 | .verify = cpufreq_generic_frequency_table_verify, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 57 | .target_index = dbx500_cpufreq_target, |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 58 | .get = cpufreq_generic_get, |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 59 | .init = dbx500_cpufreq_init, |
Viresh Kumar | 19678ff | 2017-03-14 10:48:31 +0530 | [diff] [blame] | 60 | .exit = dbx500_cpufreq_exit, |
| 61 | .ready = dbx500_cpufreq_ready, |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 62 | .name = "DBX500", |
Viresh Kumar | 47150e9 | 2013-10-03 20:28:03 +0530 | [diff] [blame] | 63 | .attr = cpufreq_generic_attr, |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 64 | }; |
| 65 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 66 | static int dbx500_cpufreq_probe(struct platform_device *pdev) |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 67 | { |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 68 | struct cpufreq_frequency_table *pos; |
Ulf Hansson | fdb4446 | 2012-10-10 13:42:25 +0200 | [diff] [blame] | 69 | |
Ulf Hansson | 3e27996 | 2012-12-10 16:25:40 +0100 | [diff] [blame] | 70 | freq_table = dev_get_platdata(&pdev->dev); |
Ulf Hansson | fdb4446 | 2012-10-10 13:42:25 +0200 | [diff] [blame] | 71 | if (!freq_table) { |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 72 | pr_err("dbx500-cpufreq: Failed to fetch cpufreq table\n"); |
Ulf Hansson | fdb4446 | 2012-10-10 13:42:25 +0200 | [diff] [blame] | 73 | return -ENODEV; |
| 74 | } |
| 75 | |
Ulf Hansson | 3e27996 | 2012-12-10 16:25:40 +0100 | [diff] [blame] | 76 | armss_clk = clk_get(&pdev->dev, "armss"); |
| 77 | if (IS_ERR(armss_clk)) { |
Jonas Aaberg | 9291cf9 | 2012-11-28 11:27:43 +0100 | [diff] [blame] | 78 | pr_err("dbx500-cpufreq: Failed to get armss clk\n"); |
Ulf Hansson | 3e27996 | 2012-12-10 16:25:40 +0100 | [diff] [blame] | 79 | return PTR_ERR(armss_clk); |
| 80 | } |
| 81 | |
Jonas Aaberg | 9291cf9 | 2012-11-28 11:27:43 +0100 | [diff] [blame] | 82 | pr_info("dbx500-cpufreq: Available frequencies:\n"); |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 83 | cpufreq_for_each_entry(pos, freq_table) |
| 84 | pr_info(" %d Mhz\n", pos->frequency / 1000); |
Ulf Hansson | 3e27996 | 2012-12-10 16:25:40 +0100 | [diff] [blame] | 85 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 86 | return cpufreq_register_driver(&dbx500_cpufreq_driver); |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 89 | static struct platform_driver dbx500_cpufreq_plat_driver = { |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 90 | .driver = { |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 91 | .name = "cpufreq-ux500", |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 92 | }, |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 93 | .probe = dbx500_cpufreq_probe, |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 94 | }; |
| 95 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 96 | static int __init dbx500_cpufreq_register(void) |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 97 | { |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 98 | return platform_driver_register(&dbx500_cpufreq_plat_driver); |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 99 | } |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 100 | device_initcall(dbx500_cpufreq_register); |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 101 | |
| 102 | MODULE_LICENSE("GPL v2"); |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 103 | MODULE_DESCRIPTION("cpufreq driver for DBX500"); |