db8500_cpufreq_cooling.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * db8500_cpufreq_cooling.c - DB8500 cpufreq works as cooling device.
  3. *
  4. * Copyright (C) 2012 ST-Ericsson
  5. * Copyright (C) 2012 Linaro Ltd.
  6. *
  7. * Author: Hongbo Zhang <hongbo.zhang@linaro.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #include <linux/cpu_cooling.h>
  20. #include <linux/cpufreq.h>
  21. #include <linux/err.h>
  22. #include <linux/module.h>
  23. #include <linux/of.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/slab.h>
  26. static int db8500_cpufreq_cooling_probe(struct platform_device *pdev)
  27. {
  28. struct thermal_cooling_device *cdev;
  29. struct cpumask mask_val;
  30. /* make sure cpufreq driver has been initialized */
  31. if (!cpufreq_frequency_get_table(0))
  32. return -EPROBE_DEFER;
  33. cpumask_set_cpu(0, &mask_val);
  34. cdev = cpufreq_cooling_register(&mask_val);
  35. if (IS_ERR_OR_NULL(cdev)) {
  36. dev_err(&pdev->dev, "Failed to register cooling device\n");
  37. return PTR_ERR(cdev);
  38. }
  39. platform_set_drvdata(pdev, cdev);
  40. dev_info(&pdev->dev, "Cooling device registered: %s\n", cdev->type);
  41. return 0;
  42. }
  43. static int db8500_cpufreq_cooling_remove(struct platform_device *pdev)
  44. {
  45. struct thermal_cooling_device *cdev = platform_get_drvdata(pdev);
  46. cpufreq_cooling_unregister(cdev);
  47. return 0;
  48. }
  49. static int db8500_cpufreq_cooling_suspend(struct platform_device *pdev,
  50. pm_message_t state)
  51. {
  52. return -ENOSYS;
  53. }
  54. static int db8500_cpufreq_cooling_resume(struct platform_device *pdev)
  55. {
  56. return -ENOSYS;
  57. }
  58. #ifdef CONFIG_OF
  59. static const struct of_device_id db8500_cpufreq_cooling_match[] = {
  60. { .compatible = "stericsson,db8500-cpufreq-cooling" },
  61. {},
  62. };
  63. #endif
  64. static struct platform_driver db8500_cpufreq_cooling_driver = {
  65. .driver = {
  66. .owner = THIS_MODULE,
  67. .name = "db8500-cpufreq-cooling",
  68. .of_match_table = of_match_ptr(db8500_cpufreq_cooling_match),
  69. },
  70. .probe = db8500_cpufreq_cooling_probe,
  71. .suspend = db8500_cpufreq_cooling_suspend,
  72. .resume = db8500_cpufreq_cooling_resume,
  73. .remove = db8500_cpufreq_cooling_remove,
  74. };
  75. static int __init db8500_cpufreq_cooling_init(void)
  76. {
  77. return platform_driver_register(&db8500_cpufreq_cooling_driver);
  78. }
  79. static void __exit db8500_cpufreq_cooling_exit(void)
  80. {
  81. platform_driver_unregister(&db8500_cpufreq_cooling_driver);
  82. }
  83. /* Should be later than db8500_cpufreq_register */
  84. late_initcall(db8500_cpufreq_cooling_init);
  85. module_exit(db8500_cpufreq_cooling_exit);
  86. MODULE_AUTHOR("Hongbo Zhang <hongbo.zhang@stericsson.com>");
  87. MODULE_DESCRIPTION("DB8500 cpufreq cooling driver");
  88. MODULE_LICENSE("GPL");