cpuidle-exynos.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* linux/arch/arm/mach-exynos/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/cpuidle.h>
  11. #include <linux/cpu_pm.h>
  12. #include <linux/export.h>
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <asm/proc-fns.h>
  16. #include <asm/suspend.h>
  17. #include <asm/cpuidle.h>
  18. static void (*exynos_enter_aftr)(void);
  19. static int idle_finisher(unsigned long flags)
  20. {
  21. exynos_enter_aftr();
  22. cpu_do_idle();
  23. return 1;
  24. }
  25. static int exynos_enter_core0_aftr(struct cpuidle_device *dev,
  26. struct cpuidle_driver *drv,
  27. int index)
  28. {
  29. cpu_pm_enter();
  30. cpu_suspend(0, idle_finisher);
  31. cpu_pm_exit();
  32. return index;
  33. }
  34. static int exynos_enter_lowpower(struct cpuidle_device *dev,
  35. struct cpuidle_driver *drv,
  36. int index)
  37. {
  38. int new_index = index;
  39. /* AFTR can only be entered when cores other than CPU0 are offline */
  40. if (num_online_cpus() > 1 || dev->cpu != 0)
  41. new_index = drv->safe_state_index;
  42. if (new_index == 0)
  43. return arm_cpuidle_simple_enter(dev, drv, new_index);
  44. else
  45. return exynos_enter_core0_aftr(dev, drv, new_index);
  46. }
  47. static struct cpuidle_driver exynos_idle_driver = {
  48. .name = "exynos_idle",
  49. .owner = THIS_MODULE,
  50. .states = {
  51. [0] = ARM_CPUIDLE_WFI_STATE,
  52. [1] = {
  53. .enter = exynos_enter_lowpower,
  54. .exit_latency = 300,
  55. .target_residency = 100000,
  56. .flags = CPUIDLE_FLAG_TIME_VALID,
  57. .name = "C1",
  58. .desc = "ARM power down",
  59. },
  60. },
  61. .state_count = 2,
  62. .safe_state_index = 0,
  63. };
  64. static int exynos_cpuidle_probe(struct platform_device *pdev)
  65. {
  66. int ret;
  67. exynos_enter_aftr = (void *)(pdev->dev.platform_data);
  68. ret = cpuidle_register(&exynos_idle_driver, NULL);
  69. if (ret) {
  70. dev_err(&pdev->dev, "failed to register cpuidle driver\n");
  71. return ret;
  72. }
  73. return 0;
  74. }
  75. static struct platform_driver exynos_cpuidle_driver = {
  76. .probe = exynos_cpuidle_probe,
  77. .driver = {
  78. .name = "exynos_cpuidle",
  79. .owner = THIS_MODULE,
  80. },
  81. };
  82. module_platform_driver(exynos_cpuidle_driver);