blob: 3575b82210ba056cfd7f39b81da2dd06cc0fd4f2 [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>
Viresh Kumar19678ff2017-03-14 10:48:31 +053014#include <linux/cpu_cooling.h>
Martin Persson7c1a70e2010-12-08 15:13:42 +010015#include <linux/delay.h>
Linus Walleij72b2fd52011-05-15 19:19:51 +020016#include <linux/slab.h>
Ulf Hanssonb4689442012-10-10 13:42:24 +020017#include <linux/platform_device.h>
Ulf Hansson78e30d12012-10-10 13:42:29 +020018#include <linux/clk.h>
Martin Persson7c1a70e2010-12-08 15:13:42 +010019
Ulf Hanssonfdb44462012-10-10 13:42:25 +020020static struct cpufreq_frequency_table *freq_table;
Ulf Hansson78e30d12012-10-10 13:42:29 +020021static struct clk *armss_clk;
Viresh Kumar19678ff2017-03-14 10:48:31 +053022static struct thermal_cooling_device *cdev;
Martin Persson7c1a70e2010-12-08 15:13:42 +010023
Lee Jonesedb10c12012-12-10 16:25:38 +010024static int dbx500_cpufreq_target(struct cpufreq_policy *policy,
Viresh Kumar9c0ebcf2013-10-25 19:45:48 +053025 unsigned int index)
Martin Persson7c1a70e2010-12-08 15:13:42 +010026{
Ulf Hansson78e30d12012-10-10 13:42:29 +020027 /* update armss clk frequency */
Viresh Kumard4019f02013-08-14 19:38:24 +053028 return clk_set_rate(armss_clk, freq_table[index].frequency * 1000);
Martin Persson7c1a70e2010-12-08 15:13:42 +010029}
30
Paul Gortmaker27609842013-06-19 13:54:04 -040031static int dbx500_cpufreq_init(struct cpufreq_policy *policy)
Martin Persson7c1a70e2010-12-08 15:13:42 +010032{
Viresh Kumar652ed952014-01-09 20:38:43 +053033 policy->clk = armss_clk;
Viresh Kumar2b3dc762013-10-03 20:29:12 +053034 return cpufreq_generic_init(policy, freq_table, 20 * 1000);
Martin Persson7c1a70e2010-12-08 15:13:42 +010035}
36
Viresh Kumar19678ff2017-03-14 10:48:31 +053037static int dbx500_cpufreq_exit(struct cpufreq_policy *policy)
38{
39 if (!IS_ERR(cdev))
40 cpufreq_cooling_unregister(cdev);
41 return 0;
42}
43
44static 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 Jonesedb10c12012-12-10 16:25:38 +010053static struct cpufreq_driver dbx500_cpufreq_driver = {
Viresh Kumarae6b4272013-12-03 11:20:45 +053054 .flags = CPUFREQ_STICKY | CPUFREQ_CONST_LOOPS |
55 CPUFREQ_NEED_INITIAL_FREQ_CHECK,
Viresh Kumar47150e92013-10-03 20:28:03 +053056 .verify = cpufreq_generic_frequency_table_verify,
Viresh Kumar9c0ebcf2013-10-25 19:45:48 +053057 .target_index = dbx500_cpufreq_target,
Viresh Kumar652ed952014-01-09 20:38:43 +053058 .get = cpufreq_generic_get,
Lee Jonesedb10c12012-12-10 16:25:38 +010059 .init = dbx500_cpufreq_init,
Viresh Kumar19678ff2017-03-14 10:48:31 +053060 .exit = dbx500_cpufreq_exit,
61 .ready = dbx500_cpufreq_ready,
Lee Jonesedb10c12012-12-10 16:25:38 +010062 .name = "DBX500",
Viresh Kumar47150e92013-10-03 20:28:03 +053063 .attr = cpufreq_generic_attr,
Martin Persson7c1a70e2010-12-08 15:13:42 +010064};
65
Lee Jonesedb10c12012-12-10 16:25:38 +010066static int dbx500_cpufreq_probe(struct platform_device *pdev)
Ulf Hanssonb4689442012-10-10 13:42:24 +020067{
Stratos Karafotis041526f2014-04-25 23:15:38 +030068 struct cpufreq_frequency_table *pos;
Ulf Hanssonfdb44462012-10-10 13:42:25 +020069
Ulf Hansson3e279962012-12-10 16:25:40 +010070 freq_table = dev_get_platdata(&pdev->dev);
Ulf Hanssonfdb44462012-10-10 13:42:25 +020071 if (!freq_table) {
Lee Jonesedb10c12012-12-10 16:25:38 +010072 pr_err("dbx500-cpufreq: Failed to fetch cpufreq table\n");
Ulf Hanssonfdb44462012-10-10 13:42:25 +020073 return -ENODEV;
74 }
75
Ulf Hansson3e279962012-12-10 16:25:40 +010076 armss_clk = clk_get(&pdev->dev, "armss");
77 if (IS_ERR(armss_clk)) {
Jonas Aaberg9291cf92012-11-28 11:27:43 +010078 pr_err("dbx500-cpufreq: Failed to get armss clk\n");
Ulf Hansson3e279962012-12-10 16:25:40 +010079 return PTR_ERR(armss_clk);
80 }
81
Jonas Aaberg9291cf92012-11-28 11:27:43 +010082 pr_info("dbx500-cpufreq: Available frequencies:\n");
Stratos Karafotis041526f2014-04-25 23:15:38 +030083 cpufreq_for_each_entry(pos, freq_table)
84 pr_info(" %d Mhz\n", pos->frequency / 1000);
Ulf Hansson3e279962012-12-10 16:25:40 +010085
Lee Jonesedb10c12012-12-10 16:25:38 +010086 return cpufreq_register_driver(&dbx500_cpufreq_driver);
Ulf Hanssonb4689442012-10-10 13:42:24 +020087}
88
Lee Jonesedb10c12012-12-10 16:25:38 +010089static struct platform_driver dbx500_cpufreq_plat_driver = {
Ulf Hanssonb4689442012-10-10 13:42:24 +020090 .driver = {
Lee Jonesedb10c12012-12-10 16:25:38 +010091 .name = "cpufreq-ux500",
Ulf Hanssonb4689442012-10-10 13:42:24 +020092 },
Lee Jonesedb10c12012-12-10 16:25:38 +010093 .probe = dbx500_cpufreq_probe,
Ulf Hanssonb4689442012-10-10 13:42:24 +020094};
95
Lee Jonesedb10c12012-12-10 16:25:38 +010096static int __init dbx500_cpufreq_register(void)
Martin Persson7c1a70e2010-12-08 15:13:42 +010097{
Lee Jonesedb10c12012-12-10 16:25:38 +010098 return platform_driver_register(&dbx500_cpufreq_plat_driver);
Martin Persson7c1a70e2010-12-08 15:13:42 +010099}
Lee Jonesedb10c12012-12-10 16:25:38 +0100100device_initcall(dbx500_cpufreq_register);
Ulf Hanssonb4689442012-10-10 13:42:24 +0200101
102MODULE_LICENSE("GPL v2");
Lee Jonesedb10c12012-12-10 16:25:38 +0100103MODULE_DESCRIPTION("cpufreq driver for DBX500");