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> |
| 14 | #include <linux/delay.h> |
Linus Walleij | 72b2fd5 | 2011-05-15 19:19:51 +0200 | [diff] [blame] | 15 | #include <linux/slab.h> |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
Ulf Hansson | 78e30d1 | 2012-10-10 13:42:29 +0200 | [diff] [blame] | 17 | #include <linux/clk.h> |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 18 | |
Ulf Hansson | fdb4446 | 2012-10-10 13:42:25 +0200 | [diff] [blame] | 19 | static struct cpufreq_frequency_table *freq_table; |
Ulf Hansson | 78e30d1 | 2012-10-10 13:42:29 +0200 | [diff] [blame] | 20 | static struct clk *armss_clk; |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 21 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 22 | static int dbx500_cpufreq_target(struct cpufreq_policy *policy, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 23 | unsigned int index) |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 24 | { |
Ulf Hansson | 78e30d1 | 2012-10-10 13:42:29 +0200 | [diff] [blame] | 25 | /* update armss clk frequency */ |
Viresh Kumar | d4019f0 | 2013-08-14 19:38:24 +0530 | [diff] [blame] | 26 | return clk_set_rate(armss_clk, freq_table[index].frequency * 1000); |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 27 | } |
| 28 | |
Paul Gortmaker | 2760984 | 2013-06-19 13:54:04 -0400 | [diff] [blame] | 29 | static int dbx500_cpufreq_init(struct cpufreq_policy *policy) |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 30 | { |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 31 | policy->clk = armss_clk; |
Viresh Kumar | 2b3dc76 | 2013-10-03 20:29:12 +0530 | [diff] [blame] | 32 | return cpufreq_generic_init(policy, freq_table, 20 * 1000); |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 33 | } |
| 34 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 35 | static struct cpufreq_driver dbx500_cpufreq_driver = { |
Viresh Kumar | ae6b427 | 2013-12-03 11:20:45 +0530 | [diff] [blame] | 36 | .flags = CPUFREQ_STICKY | CPUFREQ_CONST_LOOPS | |
| 37 | CPUFREQ_NEED_INITIAL_FREQ_CHECK, |
Viresh Kumar | 47150e9 | 2013-10-03 20:28:03 +0530 | [diff] [blame] | 38 | .verify = cpufreq_generic_frequency_table_verify, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 39 | .target_index = dbx500_cpufreq_target, |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 40 | .get = cpufreq_generic_get, |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 41 | .init = dbx500_cpufreq_init, |
| 42 | .name = "DBX500", |
Viresh Kumar | 47150e9 | 2013-10-03 20:28:03 +0530 | [diff] [blame] | 43 | .attr = cpufreq_generic_attr, |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 44 | }; |
| 45 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 46 | static int dbx500_cpufreq_probe(struct platform_device *pdev) |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 47 | { |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 48 | struct cpufreq_frequency_table *pos; |
Ulf Hansson | fdb4446 | 2012-10-10 13:42:25 +0200 | [diff] [blame] | 49 | |
Ulf Hansson | 3e27996 | 2012-12-10 16:25:40 +0100 | [diff] [blame] | 50 | freq_table = dev_get_platdata(&pdev->dev); |
Ulf Hansson | fdb4446 | 2012-10-10 13:42:25 +0200 | [diff] [blame] | 51 | if (!freq_table) { |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 52 | pr_err("dbx500-cpufreq: Failed to fetch cpufreq table\n"); |
Ulf Hansson | fdb4446 | 2012-10-10 13:42:25 +0200 | [diff] [blame] | 53 | return -ENODEV; |
| 54 | } |
| 55 | |
Ulf Hansson | 3e27996 | 2012-12-10 16:25:40 +0100 | [diff] [blame] | 56 | armss_clk = clk_get(&pdev->dev, "armss"); |
| 57 | if (IS_ERR(armss_clk)) { |
Jonas Aaberg | 9291cf9 | 2012-11-28 11:27:43 +0100 | [diff] [blame] | 58 | pr_err("dbx500-cpufreq: Failed to get armss clk\n"); |
Ulf Hansson | 3e27996 | 2012-12-10 16:25:40 +0100 | [diff] [blame] | 59 | return PTR_ERR(armss_clk); |
| 60 | } |
| 61 | |
Jonas Aaberg | 9291cf9 | 2012-11-28 11:27:43 +0100 | [diff] [blame] | 62 | pr_info("dbx500-cpufreq: Available frequencies:\n"); |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 63 | cpufreq_for_each_entry(pos, freq_table) |
| 64 | pr_info(" %d Mhz\n", pos->frequency / 1000); |
Ulf Hansson | 3e27996 | 2012-12-10 16:25:40 +0100 | [diff] [blame] | 65 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 66 | return cpufreq_register_driver(&dbx500_cpufreq_driver); |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 67 | } |
| 68 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 69 | static struct platform_driver dbx500_cpufreq_plat_driver = { |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 70 | .driver = { |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 71 | .name = "cpufreq-ux500", |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 72 | }, |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 73 | .probe = dbx500_cpufreq_probe, |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 76 | static int __init dbx500_cpufreq_register(void) |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 77 | { |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 78 | return platform_driver_register(&dbx500_cpufreq_plat_driver); |
Martin Persson | 7c1a70e | 2010-12-08 15:13:42 +0100 | [diff] [blame] | 79 | } |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 80 | device_initcall(dbx500_cpufreq_register); |
Ulf Hansson | b468944 | 2012-10-10 13:42:24 +0200 | [diff] [blame] | 81 | |
| 82 | MODULE_LICENSE("GPL v2"); |
Lee Jones | edb10c1 | 2012-12-10 16:25:38 +0100 | [diff] [blame] | 83 | MODULE_DESCRIPTION("cpufreq driver for DBX500"); |