cpuidle.c 2.3 KB

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