cpuidle-imx6q.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/clockchips.h>
  9. #include <linux/cpuidle.h>
  10. #include <linux/module.h>
  11. #include <asm/cpuidle.h>
  12. #include <asm/proc-fns.h>
  13. #include "common.h"
  14. #include "cpuidle.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. imx6q_set_lpm(WAIT_UNCLOCKED);
  28. cpu_do_idle();
  29. imx6q_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. /*
  40. * For each cpu, setup the broadcast timer because local timer
  41. * stops for the states other than WFI.
  42. */
  43. static void imx6q_setup_broadcast_timer(void *arg)
  44. {
  45. int cpu = smp_processor_id();
  46. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &cpu);
  47. }
  48. static struct cpuidle_driver imx6q_cpuidle_driver = {
  49. .name = "imx6q_cpuidle",
  50. .owner = THIS_MODULE,
  51. .en_core_tk_irqen = 1,
  52. .states = {
  53. /* WFI */
  54. ARM_CPUIDLE_WFI_STATE,
  55. /* WAIT */
  56. {
  57. .exit_latency = 50,
  58. .target_residency = 75,
  59. .flags = CPUIDLE_FLAG_TIME_VALID |
  60. CPUIDLE_FLAG_TIMER_STOP,
  61. .enter = imx6q_enter_wait,
  62. .name = "WAIT",
  63. .desc = "Clock off",
  64. },
  65. },
  66. .state_count = 2,
  67. .safe_state_index = 0,
  68. };
  69. int __init imx6q_cpuidle_init(void)
  70. {
  71. /* Need to enable SCU standby for entering WAIT modes */
  72. imx_scu_standby_enable();
  73. /* Set chicken bit to get a reliable WAIT mode support */
  74. imx6q_set_chicken_bit();
  75. /* Configure the broadcast timer on each cpu */
  76. on_each_cpu(imx6q_setup_broadcast_timer, NULL, 1);
  77. return imx_cpuidle_init(&imx6q_cpuidle_driver);
  78. }