cpuidle-imx6q.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <soc/imx/cpuidle.h>
  12. #include "common.h"
  13. #include "cpuidle.h"
  14. #include "hardware.h"
  15. static atomic_t master = ATOMIC_INIT(0);
  16. static DEFINE_SPINLOCK(master_lock);
  17. static int imx6q_enter_wait(struct cpuidle_device *dev,
  18. struct cpuidle_driver *drv, int index)
  19. {
  20. if (atomic_inc_return(&master) == num_online_cpus()) {
  21. /*
  22. * With this lock, we prevent other cpu to exit and enter
  23. * this function again and become the master.
  24. */
  25. if (!spin_trylock(&master_lock))
  26. goto idle;
  27. imx6_set_lpm(WAIT_UNCLOCKED);
  28. cpu_do_idle();
  29. imx6_set_lpm(WAIT_CLOCKED);
  30. spin_unlock(&master_lock);
  31. goto done;
  32. }
  33. idle:
  34. cpu_do_idle();
  35. done:
  36. atomic_dec(&master);
  37. return index;
  38. }
  39. static struct cpuidle_driver imx6q_cpuidle_driver = {
  40. .name = "imx6q_cpuidle",
  41. .owner = THIS_MODULE,
  42. .states = {
  43. /* WFI */
  44. ARM_CPUIDLE_WFI_STATE,
  45. /* WAIT */
  46. {
  47. .exit_latency = 50,
  48. .target_residency = 75,
  49. .flags = 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. /*
  59. * i.MX6 Q/DL has an erratum (ERR006687) that prevents the FEC from waking the
  60. * CPUs when they are in wait(unclocked) state. As the hardware workaround isn't
  61. * applicable to all boards, disable the deeper idle state when the workaround
  62. * isn't present and the FEC is in use.
  63. */
  64. void imx6q_cpuidle_fec_irqs_used(void)
  65. {
  66. imx6q_cpuidle_driver.states[1].disabled = true;
  67. }
  68. EXPORT_SYMBOL_GPL(imx6q_cpuidle_fec_irqs_used);
  69. void imx6q_cpuidle_fec_irqs_unused(void)
  70. {
  71. imx6q_cpuidle_driver.states[1].disabled = false;
  72. }
  73. EXPORT_SYMBOL_GPL(imx6q_cpuidle_fec_irqs_unused);
  74. int __init imx6q_cpuidle_init(void)
  75. {
  76. /* Set INT_MEM_CLK_LPM bit to get a reliable WAIT mode support */
  77. imx6_set_int_mem_clk_lpm(true);
  78. return cpuidle_register(&imx6q_cpuidle_driver, NULL);
  79. }