blob: 412a78bb0c9410b3fe592227d6b9b03e534616b7 [file] [log] [blame]
Martin Persson7c1a70e2010-12-08 15:13:42 +01001/*
Martin Persson7c1a70e2010-12-08 15:13:42 +01002 * Copyright (C) STMicroelectronics 2009
Lee Jones0baf0662012-11-28 11:27:44 +01003 * Copyright (C) ST-Ericsson SA 2010-2012
Martin Persson7c1a70e2010-12-08 15:13:42 +01004 *
5 * License Terms: GNU General Public License v2
Martin Persson7c1a70e2010-12-08 15:13:42 +01006 * Author: Sundar Iyer <sundar.iyer@stericsson.com>
7 * Author: Martin Persson <martin.persson@stericsson.com>
8 * Author: Jonas Aaberg <jonas.aberg@stericsson.com>
Martin Persson7c1a70e2010-12-08 15:13:42 +01009 */
Lee Jones0baf0662012-11-28 11:27:44 +010010
Ulf Hanssonb4689442012-10-10 13:42:24 +020011#include <linux/module.h>
Martin Persson7c1a70e2010-12-08 15:13:42 +010012#include <linux/kernel.h>
13#include <linux/cpufreq.h>
14#include <linux/delay.h>
Linus Walleij72b2fd52011-05-15 19:19:51 +020015#include <linux/slab.h>
Ulf Hanssonb4689442012-10-10 13:42:24 +020016#include <linux/platform_device.h>
Ulf Hansson78e30d12012-10-10 13:42:29 +020017#include <linux/clk.h>
Martin Persson7c1a70e2010-12-08 15:13:42 +010018
Ulf Hanssonfdb44462012-10-10 13:42:25 +020019static struct cpufreq_frequency_table *freq_table;
Ulf Hansson78e30d12012-10-10 13:42:29 +020020static struct clk *armss_clk;
Martin Persson7c1a70e2010-12-08 15:13:42 +010021
Lee Jonesedb10c12012-12-10 16:25:38 +010022static int dbx500_cpufreq_target(struct cpufreq_policy *policy,
Viresh Kumar9c0ebcf2013-10-25 19:45:48 +053023 unsigned int index)
Martin Persson7c1a70e2010-12-08 15:13:42 +010024{
Ulf Hansson78e30d12012-10-10 13:42:29 +020025 /* update armss clk frequency */
Viresh Kumard4019f02013-08-14 19:38:24 +053026 return clk_set_rate(armss_clk, freq_table[index].frequency * 1000);
Martin Persson7c1a70e2010-12-08 15:13:42 +010027}
28
Paul Gortmaker27609842013-06-19 13:54:04 -040029static int dbx500_cpufreq_init(struct cpufreq_policy *policy)
Martin Persson7c1a70e2010-12-08 15:13:42 +010030{
Viresh Kumar652ed952014-01-09 20:38:43 +053031 policy->clk = armss_clk;
Viresh Kumar2b3dc762013-10-03 20:29:12 +053032 return cpufreq_generic_init(policy, freq_table, 20 * 1000);
Martin Persson7c1a70e2010-12-08 15:13:42 +010033}
34
Lee Jonesedb10c12012-12-10 16:25:38 +010035static struct cpufreq_driver dbx500_cpufreq_driver = {
Viresh Kumarae6b4272013-12-03 11:20:45 +053036 .flags = CPUFREQ_STICKY | CPUFREQ_CONST_LOOPS |
37 CPUFREQ_NEED_INITIAL_FREQ_CHECK,
Viresh Kumar47150e92013-10-03 20:28:03 +053038 .verify = cpufreq_generic_frequency_table_verify,
Viresh Kumar9c0ebcf2013-10-25 19:45:48 +053039 .target_index = dbx500_cpufreq_target,
Viresh Kumar652ed952014-01-09 20:38:43 +053040 .get = cpufreq_generic_get,
Lee Jonesedb10c12012-12-10 16:25:38 +010041 .init = dbx500_cpufreq_init,
42 .name = "DBX500",
Viresh Kumar47150e92013-10-03 20:28:03 +053043 .attr = cpufreq_generic_attr,
Martin Persson7c1a70e2010-12-08 15:13:42 +010044};
45
Lee Jonesedb10c12012-12-10 16:25:38 +010046static int dbx500_cpufreq_probe(struct platform_device *pdev)
Ulf Hanssonb4689442012-10-10 13:42:24 +020047{
Ulf Hansson3e279962012-12-10 16:25:40 +010048 int i = 0;
Ulf Hanssonfdb44462012-10-10 13:42:25 +020049
Ulf Hansson3e279962012-12-10 16:25:40 +010050 freq_table = dev_get_platdata(&pdev->dev);
Ulf Hanssonfdb44462012-10-10 13:42:25 +020051 if (!freq_table) {
Lee Jonesedb10c12012-12-10 16:25:38 +010052 pr_err("dbx500-cpufreq: Failed to fetch cpufreq table\n");
Ulf Hanssonfdb44462012-10-10 13:42:25 +020053 return -ENODEV;
54 }
55
Ulf Hansson3e279962012-12-10 16:25:40 +010056 armss_clk = clk_get(&pdev->dev, "armss");
57 if (IS_ERR(armss_clk)) {
Jonas Aaberg9291cf92012-11-28 11:27:43 +010058 pr_err("dbx500-cpufreq: Failed to get armss clk\n");
Ulf Hansson3e279962012-12-10 16:25:40 +010059 return PTR_ERR(armss_clk);
60 }
61
Jonas Aaberg9291cf92012-11-28 11:27:43 +010062 pr_info("dbx500-cpufreq: Available frequencies:\n");
Ulf Hansson3e279962012-12-10 16:25:40 +010063 while (freq_table[i].frequency != CPUFREQ_TABLE_END) {
64 pr_info(" %d Mhz\n", freq_table[i].frequency/1000);
65 i++;
66 }
67
Lee Jonesedb10c12012-12-10 16:25:38 +010068 return cpufreq_register_driver(&dbx500_cpufreq_driver);
Ulf Hanssonb4689442012-10-10 13:42:24 +020069}
70
Lee Jonesedb10c12012-12-10 16:25:38 +010071static struct platform_driver dbx500_cpufreq_plat_driver = {
Ulf Hanssonb4689442012-10-10 13:42:24 +020072 .driver = {
Lee Jonesedb10c12012-12-10 16:25:38 +010073 .name = "cpufreq-ux500",
Ulf Hanssonb4689442012-10-10 13:42:24 +020074 .owner = THIS_MODULE,
75 },
Lee Jonesedb10c12012-12-10 16:25:38 +010076 .probe = dbx500_cpufreq_probe,
Ulf Hanssonb4689442012-10-10 13:42:24 +020077};
78
Lee Jonesedb10c12012-12-10 16:25:38 +010079static int __init dbx500_cpufreq_register(void)
Martin Persson7c1a70e2010-12-08 15:13:42 +010080{
Lee Jonesedb10c12012-12-10 16:25:38 +010081 return platform_driver_register(&dbx500_cpufreq_plat_driver);
Martin Persson7c1a70e2010-12-08 15:13:42 +010082}
Lee Jonesedb10c12012-12-10 16:25:38 +010083device_initcall(dbx500_cpufreq_register);
Ulf Hanssonb4689442012-10-10 13:42:24 +020084
85MODULE_LICENSE("GPL v2");
Lee Jonesedb10c12012-12-10 16:25:38 +010086MODULE_DESCRIPTION("cpufreq driver for DBX500");