cpuidle-imx6q.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2012 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/cpuidle.h>
  9. #include <linux/module.h>
  10. #include <asm/cpuidle.h>
  11. #include <asm/proc-fns.h>
  12. #include "common.h"
  13. #include "cpuidle.h"
  14. static atomic_t master = ATOMIC_INIT(0);
  15. static DEFINE_SPINLOCK(master_lock);
  16. static int imx6q_enter_wait(struct cpuidle_device *dev,
  17. struct cpuidle_driver *drv, int index)
  18. {
  19. if (atomic_inc_return(&master) == num_online_cpus()) {
  20. /*
  21. * With this lock, we prevent other cpu to exit and enter
  22. * this function again and become the master.
  23. */
  24. if (!spin_trylock(&master_lock))
  25. goto idle;
  26. imx6q_set_lpm(WAIT_UNCLOCKED);
  27. cpu_do_idle();
  28. imx6q_set_lpm(WAIT_CLOCKED);
  29. spin_unlock(&master_lock);
  30. goto done;
  31. }
  32. idle:
  33. cpu_do_idle();
  34. done:
  35. atomic_dec(&master);
  36. return index;
  37. }
  38. static struct cpuidle_driver imx6q_cpuidle_driver = {
  39. .name = "imx6q_cpuidle",
  40. .owner = THIS_MODULE,
  41. .states = {
  42. /* WFI */
  43. ARM_CPUIDLE_WFI_STATE,
  44. /* WAIT */
  45. {
  46. .exit_latency = 50,
  47. .target_residency = 75,
  48. .flags = CPUIDLE_FLAG_TIME_VALID |
  49. CPUIDLE_FLAG_TIMER_STOP,
  50. .enter = imx6q_enter_wait,
  51. .name = "WAIT",
  52. .desc = "Clock off",
  53. },
  54. },
  55. .state_count = 2,
  56. .safe_state_index = 0,
  57. };
  58. int __init imx6q_cpuidle_init(void)
  59. {
  60. /* Need to enable SCU standby for entering WAIT modes */
  61. imx_scu_standby_enable();
  62. /* Set chicken bit to get a reliable WAIT mode support */
  63. imx6q_set_chicken_bit();
  64. return cpuidle_register(&imx6q_cpuidle_driver, NULL);
  65. }