cpuidle.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_state *state)
  26. {
  27. ktime_t before, after;
  28. int requested_state = state - &dev->states[0];
  29. dev->last_state = &dev->states[requested_state];
  30. before = ktime_get();
  31. local_irq_disable();
  32. local_fiq_disable();
  33. shmobile_cpuidle_modes[requested_state]();
  34. local_irq_enable();
  35. local_fiq_enable();
  36. after = ktime_get();
  37. return ktime_to_ns(ktime_sub(after, before)) >> 10;
  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. };
  44. void (*shmobile_cpuidle_setup)(struct cpuidle_device *dev);
  45. static int shmobile_cpuidle_init(void)
  46. {
  47. struct cpuidle_device *dev = &shmobile_cpuidle_dev;
  48. struct cpuidle_state *state;
  49. int i;
  50. cpuidle_register_driver(&shmobile_cpuidle_driver);
  51. for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
  52. dev->states[i].name[0] = '\0';
  53. dev->states[i].desc[0] = '\0';
  54. dev->states[i].enter = shmobile_cpuidle_enter;
  55. }
  56. i = CPUIDLE_DRIVER_STATE_START;
  57. state = &dev->states[i++];
  58. snprintf(state->name, CPUIDLE_NAME_LEN, "C1");
  59. strncpy(state->desc, "WFI", CPUIDLE_DESC_LEN);
  60. state->exit_latency = 1;
  61. state->target_residency = 1 * 2;
  62. state->power_usage = 3;
  63. state->flags = 0;
  64. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  65. dev->safe_state = state;
  66. dev->state_count = i;
  67. if (shmobile_cpuidle_setup)
  68. shmobile_cpuidle_setup(dev);
  69. cpuidle_register_device(dev);
  70. return 0;
  71. }
  72. late_initcall(shmobile_cpuidle_init);