dbx500-cpufreq.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/cpufreq.h>
  13. #include <linux/delay.h>
  14. #include <linux/slab.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/clk.h>
  17. static struct cpufreq_frequency_table *freq_table;
  18. static struct clk *armss_clk;
  19. static int dbx500_cpufreq_target(struct cpufreq_policy *policy,
  20. unsigned int index)
  21. {
  22. /* update armss clk frequency */
  23. return clk_set_rate(armss_clk, freq_table[index].frequency * 1000);
  24. }
  25. static int dbx500_cpufreq_init(struct cpufreq_policy *policy)
  26. {
  27. policy->clk = armss_clk;
  28. return cpufreq_generic_init(policy, freq_table, 20 * 1000);
  29. }
  30. static struct cpufreq_driver dbx500_cpufreq_driver = {
  31. .flags = CPUFREQ_STICKY | CPUFREQ_CONST_LOOPS |
  32. CPUFREQ_NEED_INITIAL_FREQ_CHECK,
  33. .verify = cpufreq_generic_frequency_table_verify,
  34. .target_index = dbx500_cpufreq_target,
  35. .get = cpufreq_generic_get,
  36. .init = dbx500_cpufreq_init,
  37. .name = "DBX500",
  38. .attr = cpufreq_generic_attr,
  39. };
  40. static int dbx500_cpufreq_probe(struct platform_device *pdev)
  41. {
  42. struct cpufreq_frequency_table *pos;
  43. freq_table = dev_get_platdata(&pdev->dev);
  44. if (!freq_table) {
  45. pr_err("dbx500-cpufreq: Failed to fetch cpufreq table\n");
  46. return -ENODEV;
  47. }
  48. armss_clk = clk_get(&pdev->dev, "armss");
  49. if (IS_ERR(armss_clk)) {
  50. pr_err("dbx500-cpufreq: Failed to get armss clk\n");
  51. return PTR_ERR(armss_clk);
  52. }
  53. pr_info("dbx500-cpufreq: Available frequencies:\n");
  54. cpufreq_for_each_entry(pos, freq_table)
  55. pr_info(" %d Mhz\n", pos->frequency / 1000);
  56. return cpufreq_register_driver(&dbx500_cpufreq_driver);
  57. }
  58. static struct platform_driver dbx500_cpufreq_plat_driver = {
  59. .driver = {
  60. .name = "cpufreq-ux500",
  61. },
  62. .probe = dbx500_cpufreq_probe,
  63. };
  64. static int __init dbx500_cpufreq_register(void)
  65. {
  66. return platform_driver_register(&dbx500_cpufreq_plat_driver);
  67. }
  68. device_initcall(dbx500_cpufreq_register);
  69. MODULE_LICENSE("GPL v2");
  70. MODULE_DESCRIPTION("cpufreq driver for DBX500");