governor_msm_cpufreq.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2013, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/devfreq.h>
  14. #include <mach/cpufreq.h>
  15. #include "governor.h"
  16. DEFINE_MUTEX(df_lock);
  17. static struct devfreq *df;
  18. static int devfreq_msm_cpufreq_get_freq(struct devfreq *df,
  19. unsigned long *freq,
  20. u32 *flag)
  21. {
  22. *freq = msm_cpufreq_get_bw();
  23. return 0;
  24. }
  25. int devfreq_msm_cpufreq_update_bw(void)
  26. {
  27. int ret = 0;
  28. mutex_lock(&df_lock);
  29. if (df) {
  30. mutex_lock(&df->lock);
  31. ret = update_devfreq(df);
  32. mutex_unlock(&df->lock);
  33. }
  34. mutex_unlock(&df_lock);
  35. return ret;
  36. }
  37. static int devfreq_msm_cpufreq_ev_handler(struct devfreq *devfreq,
  38. unsigned int event, void *data)
  39. {
  40. int ret;
  41. switch (event) {
  42. case DEVFREQ_GOV_START:
  43. mutex_lock(&df_lock);
  44. df = devfreq;
  45. mutex_unlock(&df_lock);
  46. ret = devfreq_msm_cpufreq_update_bw();
  47. if (ret) {
  48. pr_err("Unable to update BW! Gov start failed!\n");
  49. return ret;
  50. }
  51. devfreq_monitor_stop(df);
  52. pr_debug("Enabled MSM CPUfreq governor\n");
  53. break;
  54. case DEVFREQ_GOV_STOP:
  55. mutex_lock(&df_lock);
  56. df = NULL;
  57. mutex_unlock(&df_lock);
  58. pr_debug("Disabled MSM CPUfreq governor\n");
  59. break;
  60. }
  61. return 0;
  62. }
  63. static struct devfreq_governor devfreq_msm_cpufreq = {
  64. .name = "msm_cpufreq",
  65. .get_target_freq = devfreq_msm_cpufreq_get_freq,
  66. .event_handler = devfreq_msm_cpufreq_ev_handler,
  67. };
  68. int register_devfreq_msm_cpufreq(void)
  69. {
  70. return devfreq_add_governor(&devfreq_msm_cpufreq);
  71. }