cpuidle-calxeda.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright 2012 Calxeda, Inc.
  3. *
  4. * Based on arch/arm/plat-mxc/cpuidle.c: #v3.7
  5. * Copyright 2012 Freescale Semiconductor, Inc.
  6. * Copyright 2012 Linaro Ltd.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * Maintainer: Rob Herring <rob.herring@calxeda.com>
  21. */
  22. #include <linux/cpuidle.h>
  23. #include <linux/init.h>
  24. #include <linux/io.h>
  25. #include <linux/of.h>
  26. #include <linux/time.h>
  27. #include <linux/delay.h>
  28. #include <linux/suspend.h>
  29. #include <asm/cpuidle.h>
  30. #include <asm/proc-fns.h>
  31. #include <asm/smp_scu.h>
  32. #include <asm/suspend.h>
  33. #include <asm/cacheflush.h>
  34. #include <asm/cp15.h>
  35. extern void highbank_set_cpu_jump(int cpu, void *jump_addr);
  36. extern void __iomem *scu_base_addr;
  37. static noinline void calxeda_idle_restore(void)
  38. {
  39. set_cr(get_cr() | CR_C);
  40. set_auxcr(get_auxcr() | 0x40);
  41. scu_power_mode(scu_base_addr, SCU_PM_NORMAL);
  42. }
  43. static int calxeda_idle_finish(unsigned long val)
  44. {
  45. /* Already flushed cache, but do it again as the outer cache functions
  46. * dirty the cache with spinlocks */
  47. flush_cache_all();
  48. set_auxcr(get_auxcr() & ~0x40);
  49. set_cr(get_cr() & ~CR_C);
  50. scu_power_mode(scu_base_addr, SCU_PM_DORMANT);
  51. cpu_do_idle();
  52. /* Restore things if we didn't enter power-gating */
  53. calxeda_idle_restore();
  54. return 1;
  55. }
  56. static int calxeda_pwrdown_idle(struct cpuidle_device *dev,
  57. struct cpuidle_driver *drv,
  58. int index)
  59. {
  60. highbank_set_cpu_jump(smp_processor_id(), cpu_resume);
  61. cpu_suspend(0, calxeda_idle_finish);
  62. return index;
  63. }
  64. static struct cpuidle_driver calxeda_idle_driver = {
  65. .name = "calxeda_idle",
  66. .states = {
  67. ARM_CPUIDLE_WFI_STATE,
  68. {
  69. .name = "PG",
  70. .desc = "Power Gate",
  71. .flags = CPUIDLE_FLAG_TIME_VALID,
  72. .exit_latency = 30,
  73. .power_usage = 50,
  74. .target_residency = 200,
  75. .enter = calxeda_pwrdown_idle,
  76. },
  77. },
  78. .state_count = 2,
  79. };
  80. static int __init calxeda_cpuidle_init(void)
  81. {
  82. if (!of_machine_is_compatible("calxeda,highbank"))
  83. return -ENODEV;
  84. return cpuidle_register(&calxeda_idle_driver, NULL);
  85. }
  86. module_init(calxeda_cpuidle_init);