cpuidle-imx6q.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. .en_core_tk_irqen = 1,
  42. .states = {
  43. /* WFI */
  44. ARM_CPUIDLE_WFI_STATE,
  45. /* WAIT */
  46. {
  47. .exit_latency = 50,
  48. .target_residency = 75,
  49. .flags = CPUIDLE_FLAG_TIME_VALID |
  50. CPUIDLE_FLAG_TIMER_STOP,
  51. .enter = imx6q_enter_wait,
  52. .name = "WAIT",
  53. .desc = "Clock off",
  54. },
  55. },
  56. .state_count = 2,
  57. .safe_state_index = 0,
  58. };
  59. int __init imx6q_cpuidle_init(void)
  60. {
  61. /* Need to enable SCU standby for entering WAIT modes */
  62. imx_scu_standby_enable();
  63. /* Set chicken bit to get a reliable WAIT mode support */
  64. imx6q_set_chicken_bit();
  65. return imx_cpuidle_init(&imx6q_cpuidle_driver);
  66. }