cpuidle.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_device cpuidle_dev;
  47. static struct cpuidle_driver cpuidle_driver = {
  48. .name = "sh_idle",
  49. .owner = THIS_MODULE,
  50. .en_core_tk_irqen = 1,
  51. };
  52. void sh_mobile_setup_cpuidle(void)
  53. {
  54. struct cpuidle_device *dev = &cpuidle_dev;
  55. struct cpuidle_driver *drv = &cpuidle_driver;
  56. struct cpuidle_state *state;
  57. int i;
  58. for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
  59. drv->states[i].name[0] = '\0';
  60. drv->states[i].desc[0] = '\0';
  61. }
  62. i = CPUIDLE_DRIVER_STATE_START;
  63. state = &drv->states[i++];
  64. snprintf(state->name, CPUIDLE_NAME_LEN, "C1");
  65. strncpy(state->desc, "SuperH Sleep Mode", CPUIDLE_DESC_LEN);
  66. state->exit_latency = 1;
  67. state->target_residency = 1 * 2;
  68. state->power_usage = 3;
  69. state->flags = 0;
  70. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  71. state->enter = cpuidle_sleep_enter;
  72. drv->safe_state_index = i-1;
  73. if (sh_mobile_sleep_supported & SUSP_SH_SF) {
  74. state = &drv->states[i++];
  75. snprintf(state->name, CPUIDLE_NAME_LEN, "C2");
  76. strncpy(state->desc, "SuperH Sleep Mode [SF]",
  77. CPUIDLE_DESC_LEN);
  78. state->exit_latency = 100;
  79. state->target_residency = 1 * 2;
  80. state->power_usage = 1;
  81. state->flags = 0;
  82. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  83. state->enter = cpuidle_sleep_enter;
  84. }
  85. if (sh_mobile_sleep_supported & SUSP_SH_STANDBY) {
  86. state = &drv->states[i++];
  87. snprintf(state->name, CPUIDLE_NAME_LEN, "C3");
  88. strncpy(state->desc, "SuperH Mobile Standby Mode [SF]",
  89. CPUIDLE_DESC_LEN);
  90. state->exit_latency = 2300;
  91. state->target_residency = 1 * 2;
  92. state->power_usage = 1;
  93. state->flags = 0;
  94. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  95. state->enter = cpuidle_sleep_enter;
  96. }
  97. drv->state_count = i;
  98. dev->state_count = i;
  99. cpuidle_register_driver(&cpuidle_driver);
  100. cpuidle_register_device(dev);
  101. }