cpuidle.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * arch/arm/mach-kirkwood/cpuidle.c
  3. *
  4. * CPU idle Marvell Kirkwood SoCs
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. *
  10. * The cpu idle uses wait-for-interrupt and DDR self refresh in order
  11. * to implement two idle states -
  12. * #1 wait-for-interrupt
  13. * #2 wait-for-interrupt and DDR self refresh
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/cpuidle.h>
  19. #include <linux/io.h>
  20. #include <linux/export.h>
  21. #include <asm/proc-fns.h>
  22. #include <mach/kirkwood.h>
  23. #define KIRKWOOD_MAX_STATES 2
  24. static struct cpuidle_driver kirkwood_idle_driver = {
  25. .name = "kirkwood_idle",
  26. .owner = THIS_MODULE,
  27. };
  28. static DEFINE_PER_CPU(struct cpuidle_device, kirkwood_cpuidle_device);
  29. /* Actual code that puts the SoC in different idle states */
  30. static int kirkwood_enter_idle(struct cpuidle_device *dev,
  31. struct cpuidle_driver *drv,
  32. int index)
  33. {
  34. struct timeval before, after;
  35. int idle_time;
  36. local_irq_disable();
  37. do_gettimeofday(&before);
  38. if (index == 0)
  39. /* Wait for interrupt state */
  40. cpu_do_idle();
  41. else if (index == 1) {
  42. /*
  43. * Following write will put DDR in self refresh.
  44. * Note that we have 256 cycles before DDR puts it
  45. * self in self-refresh, so the wait-for-interrupt
  46. * call afterwards won't get the DDR from self refresh
  47. * mode.
  48. */
  49. writel(0x7, DDR_OPERATION_BASE);
  50. cpu_do_idle();
  51. }
  52. do_gettimeofday(&after);
  53. local_irq_enable();
  54. idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
  55. (after.tv_usec - before.tv_usec);
  56. /* Update last residency */
  57. dev->last_residency = idle_time;
  58. return index;
  59. }
  60. /* Initialize CPU idle by registering the idle states */
  61. static int kirkwood_init_cpuidle(void)
  62. {
  63. struct cpuidle_device *device;
  64. struct cpuidle_driver *driver = &kirkwood_idle_driver;
  65. device = &per_cpu(kirkwood_cpuidle_device, smp_processor_id());
  66. device->state_count = KIRKWOOD_MAX_STATES;
  67. driver->state_count = KIRKWOOD_MAX_STATES;
  68. /* Wait for interrupt state */
  69. driver->states[0].enter = kirkwood_enter_idle;
  70. driver->states[0].exit_latency = 1;
  71. driver->states[0].target_residency = 10000;
  72. driver->states[0].flags = CPUIDLE_FLAG_TIME_VALID;
  73. strcpy(driver->states[0].name, "WFI");
  74. strcpy(driver->states[0].desc, "Wait for interrupt");
  75. /* Wait for interrupt and DDR self refresh state */
  76. driver->states[1].enter = kirkwood_enter_idle;
  77. driver->states[1].exit_latency = 10;
  78. driver->states[1].target_residency = 10000;
  79. driver->states[1].flags = CPUIDLE_FLAG_TIME_VALID;
  80. strcpy(driver->states[1].name, "DDR SR");
  81. strcpy(driver->states[1].desc, "WFI and DDR Self Refresh");
  82. cpuidle_register_driver(&kirkwood_idle_driver);
  83. if (cpuidle_register_device(device)) {
  84. printk(KERN_ERR "kirkwood_init_cpuidle: Failed registering\n");
  85. return -EIO;
  86. }
  87. return 0;
  88. }
  89. device_initcall(kirkwood_init_cpuidle);