cpuidle.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * based on arch/arm/mach-kirkwood/cpuidle.c
  3. *
  4. * CPU idle support for AT91 SoC
  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 RAM self refresh in order
  11. * to implement two idle states -
  12. * #1 wait-for-interrupt
  13. * #2 wait-for-interrupt and RAM 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 <asm/proc-fns.h>
  20. #include <linux/io.h>
  21. #include "pm.h"
  22. #define AT91_MAX_STATES 2
  23. static DEFINE_PER_CPU(struct cpuidle_device, at91_cpuidle_device);
  24. static struct cpuidle_driver at91_idle_driver = {
  25. .name = "at91_idle",
  26. .owner = THIS_MODULE,
  27. };
  28. /* Actual code that puts the SoC in different idle states */
  29. static int at91_enter_idle(struct cpuidle_device *dev,
  30. struct cpuidle_driver *drv,
  31. int index)
  32. {
  33. struct timeval before, after;
  34. int idle_time;
  35. u32 saved_lpr;
  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. asm("b 1f; .align 5; 1:");
  43. asm("mcr p15, 0, r0, c7, c10, 4"); /* drain write buffer */
  44. saved_lpr = sdram_selfrefresh_enable();
  45. cpu_do_idle();
  46. sdram_selfrefresh_disable(saved_lpr);
  47. }
  48. do_gettimeofday(&after);
  49. local_irq_enable();
  50. idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
  51. (after.tv_usec - before.tv_usec);
  52. dev->last_residency = idle_time;
  53. return index;
  54. }
  55. /* Initialize CPU idle by registering the idle states */
  56. static int at91_init_cpuidle(void)
  57. {
  58. struct cpuidle_device *device;
  59. struct cpuidle_driver *driver = &at91_idle_driver;
  60. device = &per_cpu(at91_cpuidle_device, smp_processor_id());
  61. device->state_count = AT91_MAX_STATES;
  62. driver->state_count = AT91_MAX_STATES;
  63. /* Wait for interrupt state */
  64. driver->states[0].enter = at91_enter_idle;
  65. driver->states[0].exit_latency = 1;
  66. driver->states[0].target_residency = 10000;
  67. driver->states[0].flags = CPUIDLE_FLAG_TIME_VALID;
  68. strcpy(driver->states[0].name, "WFI");
  69. strcpy(driver->states[0].desc, "Wait for interrupt");
  70. /* Wait for interrupt and RAM self refresh state */
  71. driver->states[1].enter = at91_enter_idle;
  72. driver->states[1].exit_latency = 10;
  73. driver->states[1].target_residency = 10000;
  74. driver->states[1].flags = CPUIDLE_FLAG_TIME_VALID;
  75. strcpy(driver->states[1].name, "RAM_SR");
  76. strcpy(driver->states[1].desc, "WFI and RAM Self Refresh");
  77. cpuidle_register_driver(&at91_idle_driver);
  78. if (cpuidle_register_device(device)) {
  79. printk(KERN_ERR "at91_init_cpuidle: Failed registering\n");
  80. return -EIO;
  81. }
  82. return 0;
  83. }
  84. device_initcall(at91_init_cpuidle);