cpuidle.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * CPUIdle support code for SH-Mobile ARM
  3. *
  4. * Copyright (C) 2011 Magnus Damm
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/pm.h>
  11. #include <linux/cpuidle.h>
  12. #include <linux/suspend.h>
  13. #include <linux/module.h>
  14. #include <linux/err.h>
  15. #include <asm/system.h>
  16. #include <asm/io.h>
  17. static void shmobile_enter_wfi(void)
  18. {
  19. cpu_do_idle();
  20. }
  21. void (*shmobile_cpuidle_modes[CPUIDLE_STATE_MAX])(void) = {
  22. shmobile_enter_wfi, /* regular sleep mode */
  23. };
  24. static int shmobile_cpuidle_enter(struct cpuidle_device *dev,
  25. struct cpuidle_driver *drv,
  26. int index)
  27. {
  28. ktime_t before, after;
  29. before = ktime_get();
  30. local_irq_disable();
  31. local_fiq_disable();
  32. shmobile_cpuidle_modes[index]();
  33. local_irq_enable();
  34. local_fiq_enable();
  35. after = ktime_get();
  36. dev->last_residency = ktime_to_ns(ktime_sub(after, before)) >> 10;
  37. return index;
  38. }
  39. static struct cpuidle_device shmobile_cpuidle_dev;
  40. static struct cpuidle_driver shmobile_cpuidle_driver = {
  41. .name = "shmobile_cpuidle",
  42. .owner = THIS_MODULE,
  43. .states[0] = {
  44. .name = "C1",
  45. .desc = "WFI",
  46. .exit_latency = 1,
  47. .target_residency = 1 * 2,
  48. .flags = CPUIDLE_FLAG_TIME_VALID,
  49. },
  50. .safe_state_index = 0, /* C1 */
  51. .state_count = 1,
  52. };
  53. void (*shmobile_cpuidle_setup)(struct cpuidle_driver *drv);
  54. static int shmobile_cpuidle_init(void)
  55. {
  56. struct cpuidle_device *dev = &shmobile_cpuidle_dev;
  57. struct cpuidle_driver *drv = &shmobile_cpuidle_driver;
  58. int i;
  59. for (i = 0; i < CPUIDLE_STATE_MAX; i++)
  60. drv->states[i].enter = shmobile_cpuidle_enter;
  61. if (shmobile_cpuidle_setup)
  62. shmobile_cpuidle_setup(drv);
  63. cpuidle_register_driver(drv);
  64. dev->state_count = drv->state_count;
  65. cpuidle_register_device(dev);
  66. return 0;
  67. }
  68. late_initcall(shmobile_cpuidle_init);