cpuidle.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_state *state);
  17. static struct cpuidle_state exynos4_cpuidle_set[] = {
  18. [0] = {
  19. .enter = exynos4_enter_idle,
  20. .exit_latency = 1,
  21. .target_residency = 100000,
  22. .flags = CPUIDLE_FLAG_TIME_VALID,
  23. .name = "IDLE",
  24. .desc = "ARM clock gating(WFI)",
  25. },
  26. };
  27. static DEFINE_PER_CPU(struct cpuidle_device, exynos4_cpuidle_device);
  28. static struct cpuidle_driver exynos4_idle_driver = {
  29. .name = "exynos4_idle",
  30. .owner = THIS_MODULE,
  31. };
  32. static int exynos4_enter_idle(struct cpuidle_device *dev,
  33. struct cpuidle_state *state)
  34. {
  35. struct timeval before, after;
  36. int idle_time;
  37. local_irq_disable();
  38. do_gettimeofday(&before);
  39. cpu_do_idle();
  40. do_gettimeofday(&after);
  41. local_irq_enable();
  42. idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
  43. (after.tv_usec - before.tv_usec);
  44. return idle_time;
  45. }
  46. static int __init exynos4_init_cpuidle(void)
  47. {
  48. int i, max_cpuidle_state, cpu_id;
  49. struct cpuidle_device *device;
  50. cpuidle_register_driver(&exynos4_idle_driver);
  51. for_each_cpu(cpu_id, cpu_online_mask) {
  52. device = &per_cpu(exynos4_cpuidle_device, cpu_id);
  53. device->cpu = cpu_id;
  54. device->state_count = (sizeof(exynos4_cpuidle_set) /
  55. sizeof(struct cpuidle_state));
  56. max_cpuidle_state = device->state_count;
  57. for (i = 0; i < max_cpuidle_state; i++) {
  58. memcpy(&device->states[i], &exynos4_cpuidle_set[i],
  59. sizeof(struct cpuidle_state));
  60. }
  61. if (cpuidle_register_device(device)) {
  62. printk(KERN_ERR "CPUidle register device failed\n,");
  63. return -EIO;
  64. }
  65. }
  66. return 0;
  67. }
  68. device_initcall(exynos4_init_cpuidle);