cpuidle.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_state *state)
  32. {
  33. struct timeval before, after;
  34. int idle_time;
  35. u32 saved_lpr;
  36. local_irq_disable();
  37. do_gettimeofday(&before);
  38. if (state == &dev->states[0])
  39. /* Wait for interrupt state */
  40. cpu_do_idle();
  41. else if (state == &dev->states[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. return idle_time;
  53. }
  54. /* Initialize CPU idle by registering the idle states */
  55. static int at91_init_cpuidle(void)
  56. {
  57. struct cpuidle_device *device;
  58. cpuidle_register_driver(&at91_idle_driver);
  59. device = &per_cpu(at91_cpuidle_device, smp_processor_id());
  60. device->state_count = AT91_MAX_STATES;
  61. /* Wait for interrupt state */
  62. device->states[0].enter = at91_enter_idle;
  63. device->states[0].exit_latency = 1;
  64. device->states[0].target_residency = 10000;
  65. device->states[0].flags = CPUIDLE_FLAG_TIME_VALID;
  66. strcpy(device->states[0].name, "WFI");
  67. strcpy(device->states[0].desc, "Wait for interrupt");
  68. /* Wait for interrupt and RAM self refresh state */
  69. device->states[1].enter = at91_enter_idle;
  70. device->states[1].exit_latency = 10;
  71. device->states[1].target_residency = 10000;
  72. device->states[1].flags = CPUIDLE_FLAG_TIME_VALID;
  73. strcpy(device->states[1].name, "RAM_SR");
  74. strcpy(device->states[1].desc, "WFI and RAM Self Refresh");
  75. if (cpuidle_register_device(device)) {
  76. printk(KERN_ERR "at91_init_cpuidle: Failed registering\n");
  77. return -EIO;
  78. }
  79. return 0;
  80. }
  81. device_initcall(at91_init_cpuidle);