cpuidle-imx6q.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. int cpu = dev->cpu;
  21. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
  22. if (atomic_inc_return(&master) == num_online_cpus()) {
  23. /*
  24. * With this lock, we prevent other cpu to exit and enter
  25. * this function again and become the master.
  26. */
  27. if (!spin_trylock(&master_lock))
  28. goto idle;
  29. imx6q_set_lpm(WAIT_UNCLOCKED);
  30. cpu_do_idle();
  31. imx6q_set_lpm(WAIT_CLOCKED);
  32. spin_unlock(&master_lock);
  33. goto done;
  34. }
  35. idle:
  36. cpu_do_idle();
  37. done:
  38. atomic_dec(&master);
  39. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
  40. return index;
  41. }
  42. /*
  43. * For each cpu, setup the broadcast timer because local timer
  44. * stops for the states other than WFI.
  45. */
  46. static void imx6q_setup_broadcast_timer(void *arg)
  47. {
  48. int cpu = smp_processor_id();
  49. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &cpu);
  50. }
  51. static struct cpuidle_driver imx6q_cpuidle_driver = {
  52. .name = "imx6q_cpuidle",
  53. .owner = THIS_MODULE,
  54. .en_core_tk_irqen = 1,
  55. .states = {
  56. /* WFI */
  57. ARM_CPUIDLE_WFI_STATE,
  58. /* WAIT */
  59. {
  60. .exit_latency = 50,
  61. .target_residency = 75,
  62. .flags = CPUIDLE_FLAG_TIME_VALID,
  63. .enter = imx6q_enter_wait,
  64. .name = "WAIT",
  65. .desc = "Clock off",
  66. },
  67. },
  68. .state_count = 2,
  69. .safe_state_index = 0,
  70. };
  71. int __init imx6q_cpuidle_init(void)
  72. {
  73. /* Need to enable SCU standby for entering WAIT modes */
  74. imx_scu_standby_enable();
  75. /* Set chicken bit to get a reliable WAIT mode support */
  76. imx6q_set_chicken_bit();
  77. /* Configure the broadcast timer on each cpu */
  78. on_each_cpu(imx6q_setup_broadcast_timer, NULL, 1);
  79. return imx_cpuidle_init(&imx6q_cpuidle_driver);
  80. }