cpuidle.c 2.8 KB

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