cpuidle-imx6q.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "common.h"
  12. #include "cpuidle.h"
  13. #include "hardware.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_TIMER_STOP,
  49. .enter = imx6q_enter_wait,
  50. .name = "WAIT",
  51. .desc = "Clock off",
  52. },
  53. },
  54. .state_count = 2,
  55. .safe_state_index = 0,
  56. };
  57. int __init imx6q_cpuidle_init(void)
  58. {
  59. /* Set INT_MEM_CLK_LPM bit to get a reliable WAIT mode support */
  60. imx6q_set_int_mem_clk_lpm(true);
  61. return cpuidle_register(&imx6q_cpuidle_driver, NULL);
  62. }