mtk_governor.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * mtk_governor.c - the MediaTek idle governor
  3. *
  4. * Copyright (C) 2015 MediaTek Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/cpuidle.h>
  12. #include <linux/pm_qos.h>
  13. #include <linux/time.h>
  14. #include <linux/ktime.h>
  15. #include <linux/hrtimer.h>
  16. #include <linux/tick.h>
  17. #include <linux/sched.h>
  18. #include <linux/math64.h>
  19. #include <linux/module.h>
  20. #include <linux/cpu.h>
  21. struct mtk_idle_device {
  22. unsigned int cpu;
  23. int last_state_idx;
  24. };
  25. static DEFINE_PER_CPU(struct mtk_idle_device, mtk_idle_devices);
  26. int __attribute__((weak)) mt_idle_select(int cpu)
  27. {
  28. /* Default: CPUidle state select failed */
  29. return -1;
  30. }
  31. void __attribute__((weak)) mt_cpuidle_framework_init(void)
  32. {
  33. }
  34. /*
  35. * mtk_governor_select - selects the next idle state to enter
  36. * @drv: cpuidle driver containing state data
  37. * @dev: the CPU
  38. */
  39. static int mtk_governor_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
  40. {
  41. struct mtk_idle_device *data = &__get_cpu_var(mtk_idle_devices);
  42. int state;
  43. state = mt_idle_select(data->cpu);
  44. return state;
  45. }
  46. /*
  47. * mtk_governor_reflect - records that data structures need update
  48. * @dev: the CPU
  49. * @index: the index of actual entered state
  50. *
  51. * NOTE: it's important to be fast here because this operation will add to
  52. * the overall exit latency.
  53. */
  54. static void mtk_governor_reflect(struct cpuidle_device *dev, int index)
  55. {
  56. /* TODO: implement actions for MTK governor & replace it */
  57. }
  58. /*
  59. * mtk_governor_enable_device - scans a CPU's states and does setup
  60. * @drv: cpuidle driver
  61. * @dev: the CPU
  62. */
  63. static int mtk_governor_enable_device(struct cpuidle_driver *drv,
  64. struct cpuidle_device *dev)
  65. {
  66. struct mtk_idle_device *data = &per_cpu(mtk_idle_devices, dev->cpu);
  67. memset(data, 0, sizeof(struct mtk_idle_device));
  68. data->cpu = dev->cpu;
  69. return 0;
  70. }
  71. static struct cpuidle_governor mtk_governor = {
  72. .name = "mtk_governor",
  73. .rating = 100,
  74. .enable = mtk_governor_enable_device,
  75. .select = mtk_governor_select,
  76. .reflect = mtk_governor_reflect,
  77. .owner = THIS_MODULE,
  78. };
  79. /*
  80. * init_mtk_governor - initializes the governor
  81. */
  82. static int __init init_mtk_governor(void)
  83. {
  84. /* TODO: check if debugfs_create_file() failed */
  85. mt_cpuidle_framework_init();
  86. return cpuidle_register_governor(&mtk_governor);
  87. }
  88. MODULE_LICENSE("GPL");
  89. postcore_initcall(init_mtk_governor);