cpuidle.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * arch/arm/mach-tegra/cpuidle.c
  3. *
  4. * CPU idle driver for Tegra CPUs
  5. *
  6. * Copyright (c) 2010-2012, NVIDIA Corporation.
  7. * Copyright (c) 2011 Google, Inc.
  8. * Author: Colin Cross <ccross@android.com>
  9. * Gary King <gking@nvidia.com>
  10. *
  11. * Rework for 3.3 by Peter De Schrijver <pdeschrijver@nvidia.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful, but WITHOUT
  19. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  20. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  21. * more details.
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/cpu.h>
  26. #include <linux/cpuidle.h>
  27. #include <linux/hrtimer.h>
  28. #include <mach/iomap.h>
  29. extern void tegra_cpu_wfi(void);
  30. static int tegra_idle_enter_lp3(struct cpuidle_device *dev,
  31. struct cpuidle_driver *drv, int index);
  32. struct cpuidle_driver tegra_idle_driver = {
  33. .name = "tegra_idle",
  34. .owner = THIS_MODULE,
  35. .state_count = 1,
  36. .states = {
  37. [0] = {
  38. .enter = tegra_idle_enter_lp3,
  39. .exit_latency = 10,
  40. .target_residency = 10,
  41. .power_usage = 600,
  42. .flags = CPUIDLE_FLAG_TIME_VALID,
  43. .name = "LP3",
  44. .desc = "CPU flow-controlled",
  45. },
  46. },
  47. };
  48. static DEFINE_PER_CPU(struct cpuidle_device, tegra_idle_device);
  49. static int tegra_idle_enter_lp3(struct cpuidle_device *dev,
  50. struct cpuidle_driver *drv, int index)
  51. {
  52. ktime_t enter, exit;
  53. s64 us;
  54. local_irq_disable();
  55. local_fiq_disable();
  56. enter = ktime_get();
  57. tegra_cpu_wfi();
  58. exit = ktime_sub(ktime_get(), enter);
  59. us = ktime_to_us(exit);
  60. local_fiq_enable();
  61. local_irq_enable();
  62. dev->last_residency = us;
  63. return index;
  64. }
  65. static int __init tegra_cpuidle_init(void)
  66. {
  67. int ret;
  68. unsigned int cpu;
  69. struct cpuidle_device *dev;
  70. struct cpuidle_driver *drv = &tegra_idle_driver;
  71. ret = cpuidle_register_driver(&tegra_idle_driver);
  72. if (ret) {
  73. pr_err("CPUidle driver registration failed\n");
  74. return ret;
  75. }
  76. for_each_possible_cpu(cpu) {
  77. dev = &per_cpu(tegra_idle_device, cpu);
  78. dev->cpu = cpu;
  79. dev->state_count = drv->state_count;
  80. ret = cpuidle_register_device(dev);
  81. if (ret) {
  82. pr_err("CPU%u: CPUidle device registration failed\n",
  83. cpu);
  84. return ret;
  85. }
  86. }
  87. return 0;
  88. }
  89. device_initcall(tegra_cpuidle_init);