cpuidle.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * arch/sh/kernel/cpu/shmobile/cpuidle.c
  3. *
  4. * Cpuidle support code for SuperH Mobile
  5. *
  6. * Copyright (C) 2009 Magnus Damm
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/io.h>
  15. #include <linux/suspend.h>
  16. #include <linux/cpuidle.h>
  17. #include <linux/export.h>
  18. #include <asm/suspend.h>
  19. #include <asm/uaccess.h>
  20. static unsigned long cpuidle_mode[] = {
  21. SUSP_SH_SLEEP, /* regular sleep mode */
  22. SUSP_SH_SLEEP | SUSP_SH_SF, /* sleep mode + self refresh */
  23. SUSP_SH_STANDBY | SUSP_SH_SF, /* software standby mode + self refresh */
  24. };
  25. static int cpuidle_sleep_enter(struct cpuidle_device *dev,
  26. struct cpuidle_driver *drv,
  27. int index)
  28. {
  29. unsigned long allowed_mode = SUSP_SH_SLEEP;
  30. int requested_state = index;
  31. int allowed_state;
  32. int k;
  33. /* convert allowed mode to allowed state */
  34. for (k = ARRAY_SIZE(cpuidle_mode) - 1; k > 0; k--)
  35. if (cpuidle_mode[k] == allowed_mode)
  36. break;
  37. allowed_state = k;
  38. /* take the following into account for sleep mode selection:
  39. * - allowed_state: best mode allowed by hardware (clock deps)
  40. * - requested_state: best mode allowed by software (latencies)
  41. */
  42. k = min_t(int, allowed_state, requested_state);
  43. sh_mobile_call_standby(cpuidle_mode[k]);
  44. return k;
  45. }
  46. static struct cpuidle_driver cpuidle_driver = {
  47. .name = "sh_idle",
  48. .owner = THIS_MODULE,
  49. .states = {
  50. {
  51. .exit_latency = 1,
  52. .target_residency = 1 * 2,
  53. .power_usage = 3,
  54. .enter = cpuidle_sleep_enter,
  55. .name = "C1",
  56. .desc = "SuperH Sleep Mode",
  57. },
  58. {
  59. .exit_latency = 100,
  60. .target_residency = 1 * 2,
  61. .power_usage = 1,
  62. .enter = cpuidle_sleep_enter,
  63. .name = "C2",
  64. .desc = "SuperH Sleep Mode [SF]",
  65. .disabled = true,
  66. },
  67. {
  68. .exit_latency = 2300,
  69. .target_residency = 1 * 2,
  70. .power_usage = 1,
  71. .enter = cpuidle_sleep_enter,
  72. .name = "C3",
  73. .desc = "SuperH Mobile Standby Mode [SF]",
  74. .disabled = true,
  75. },
  76. },
  77. .safe_state_index = 0,
  78. .state_count = 3,
  79. };
  80. int __init sh_mobile_setup_cpuidle(void)
  81. {
  82. if (sh_mobile_sleep_supported & SUSP_SH_SF)
  83. cpuidle_driver.states[1].disabled = false;
  84. if (sh_mobile_sleep_supported & SUSP_SH_STANDBY)
  85. cpuidle_driver.states[2].disabled = false;
  86. return cpuidle_register(&cpuidle_driver, NULL);
  87. }