cpuidle.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* linux/arch/arm/mach-exynos4/cpuidle.c
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/cpuidle.h>
  13. #include <linux/io.h>
  14. #include <asm/proc-fns.h>
  15. static int exynos4_enter_idle(struct cpuidle_device *dev,
  16. struct cpuidle_driver *drv,
  17. int index);
  18. static struct cpuidle_state exynos4_cpuidle_set[] = {
  19. [0] = {
  20. .enter = exynos4_enter_idle,
  21. .exit_latency = 1,
  22. .target_residency = 100000,
  23. .flags = CPUIDLE_FLAG_TIME_VALID,
  24. .name = "IDLE",
  25. .desc = "ARM clock gating(WFI)",
  26. },
  27. };
  28. static DEFINE_PER_CPU(struct cpuidle_device, exynos4_cpuidle_device);
  29. static struct cpuidle_driver exynos4_idle_driver = {
  30. .name = "exynos4_idle",
  31. .owner = THIS_MODULE,
  32. };
  33. static int exynos4_enter_idle(struct cpuidle_device *dev,
  34. struct cpuidle_driver *drv,
  35. int index)
  36. {
  37. struct timeval before, after;
  38. int idle_time;
  39. local_irq_disable();
  40. do_gettimeofday(&before);
  41. cpu_do_idle();
  42. do_gettimeofday(&after);
  43. local_irq_enable();
  44. idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
  45. (after.tv_usec - before.tv_usec);
  46. dev->last_residency = idle_time;
  47. return index;
  48. }
  49. static int __init exynos4_init_cpuidle(void)
  50. {
  51. int i, max_cpuidle_state, cpu_id;
  52. struct cpuidle_device *device;
  53. struct cpuidle_driver *drv = &exynos4_idle_driver;
  54. /* Setup cpuidle driver */
  55. drv->state_count = (sizeof(exynos4_cpuidle_set) /
  56. sizeof(struct cpuidle_state));
  57. max_cpuidle_state = drv->state_count;
  58. for (i = 0; i < max_cpuidle_state; i++) {
  59. memcpy(&drv->states[i], &exynos4_cpuidle_set[i],
  60. sizeof(struct cpuidle_state));
  61. }
  62. cpuidle_register_driver(&exynos4_idle_driver);
  63. for_each_cpu(cpu_id, cpu_online_mask) {
  64. device = &per_cpu(exynos4_cpuidle_device, cpu_id);
  65. device->cpu = cpu_id;
  66. device->state_count = drv->state_count;
  67. if (cpuidle_register_device(device)) {
  68. printk(KERN_ERR "CPUidle register device failed\n,");
  69. return -EIO;
  70. }
  71. }
  72. return 0;
  73. }
  74. device_initcall(exynos4_init_cpuidle);