cpuidle.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <linux/io.h>
  20. #include <linux/export.h>
  21. #include <asm/proc-fns.h>
  22. #include <asm/cpuidle.h>
  23. #include <mach/cpu.h>
  24. #include "pm.h"
  25. #define AT91_MAX_STATES 2
  26. static DEFINE_PER_CPU(struct cpuidle_device, at91_cpuidle_device);
  27. /* Actual code that puts the SoC in different idle states */
  28. static int at91_enter_idle(struct cpuidle_device *dev,
  29. struct cpuidle_driver *drv,
  30. int index)
  31. {
  32. if (cpu_is_at91rm9200())
  33. at91rm9200_standby();
  34. else if (cpu_is_at91sam9g45())
  35. at91sam9g45_standby();
  36. else
  37. at91sam9_standby();
  38. return index;
  39. }
  40. static struct cpuidle_driver at91_idle_driver = {
  41. .name = "at91_idle",
  42. .owner = THIS_MODULE,
  43. .en_core_tk_irqen = 1,
  44. .states[0] = ARM_CPUIDLE_WFI_STATE,
  45. .states[1] = {
  46. .enter = at91_enter_idle,
  47. .exit_latency = 10,
  48. .target_residency = 100000,
  49. .flags = CPUIDLE_FLAG_TIME_VALID,
  50. .name = "RAM_SR",
  51. .desc = "WFI and DDR Self Refresh",
  52. },
  53. .state_count = AT91_MAX_STATES,
  54. };
  55. /* Initialize CPU idle by registering the idle states */
  56. static int at91_init_cpuidle(void)
  57. {
  58. struct cpuidle_device *device;
  59. device = &per_cpu(at91_cpuidle_device, smp_processor_id());
  60. device->state_count = AT91_MAX_STATES;
  61. cpuidle_register_driver(&at91_idle_driver);
  62. if (cpuidle_register_device(device)) {
  63. printk(KERN_ERR "at91_init_cpuidle: Failed registering\n");
  64. return -EIO;
  65. }
  66. return 0;
  67. }
  68. device_initcall(at91_init_cpuidle);