governor_powersave.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * linux/drivers/devfreq/governor_powersave.c
  3. *
  4. * Copyright (C) 2011 Samsung Electronics
  5. * MyungJoo Ham <myungjoo.ham@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/devfreq.h>
  12. #include <linux/module.h>
  13. #include "governor.h"
  14. static int devfreq_powersave_func(struct devfreq *df,
  15. unsigned long *freq,
  16. u32 *flag)
  17. {
  18. /*
  19. * target callback should be able to get ceiling value as
  20. * said in devfreq.h
  21. */
  22. *freq = df->min_freq;
  23. return 0;
  24. }
  25. static int devfreq_powersave_handler(struct devfreq *devfreq,
  26. unsigned int event, void *data)
  27. {
  28. int ret = 0;
  29. if (event == DEVFREQ_GOV_START || event == DEVFREQ_GOV_RESUME) {
  30. mutex_lock(&devfreq->lock);
  31. ret = update_devfreq(devfreq);
  32. mutex_unlock(&devfreq->lock);
  33. }
  34. return ret;
  35. }
  36. static struct devfreq_governor devfreq_powersave = {
  37. .name = "powersave",
  38. .get_target_freq = devfreq_powersave_func,
  39. .event_handler = devfreq_powersave_handler,
  40. };
  41. static int __init devfreq_powersave_init(void)
  42. {
  43. return devfreq_add_governor(&devfreq_powersave);
  44. }
  45. subsys_initcall(devfreq_powersave_init);
  46. static void __exit devfreq_powersave_exit(void)
  47. {
  48. int ret;
  49. ret = devfreq_remove_governor(&devfreq_powersave);
  50. if (ret)
  51. pr_err("%s: failed remove governor %d\n", __func__, ret);
  52. return;
  53. }
  54. module_exit(devfreq_powersave_exit);
  55. MODULE_LICENSE("GPL");