pm.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * CPU complex suspend & resume functions for Tegra SoCs
  3. *
  4. * Copyright (c) 2009-2012, NVIDIA Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/io.h>
  21. #include <linux/cpumask.h>
  22. #include "iomap.h"
  23. #include "reset.h"
  24. #ifdef CONFIG_PM_SLEEP
  25. static unsigned int g_diag_reg;
  26. static DEFINE_SPINLOCK(tegra_lp2_lock);
  27. void save_cpu_arch_register(void)
  28. {
  29. /* read diagnostic register */
  30. asm("mrc p15, 0, %0, c15, c0, 1" : "=r"(g_diag_reg) : : "cc");
  31. return;
  32. }
  33. void restore_cpu_arch_register(void)
  34. {
  35. /* write diagnostic register */
  36. asm("mcr p15, 0, %0, c15, c0, 1" : : "r"(g_diag_reg) : "cc");
  37. return;
  38. }
  39. void __cpuinit tegra_clear_cpu_in_lp2(int phy_cpu_id)
  40. {
  41. u32 *cpu_in_lp2 = tegra_cpu_lp2_mask;
  42. spin_lock(&tegra_lp2_lock);
  43. BUG_ON(!(*cpu_in_lp2 & BIT(phy_cpu_id)));
  44. *cpu_in_lp2 &= ~BIT(phy_cpu_id);
  45. spin_unlock(&tegra_lp2_lock);
  46. }
  47. bool __cpuinit tegra_set_cpu_in_lp2(int phy_cpu_id)
  48. {
  49. bool last_cpu = false;
  50. cpumask_t *cpu_lp2_mask = tegra_cpu_lp2_mask;
  51. u32 *cpu_in_lp2 = tegra_cpu_lp2_mask;
  52. spin_lock(&tegra_lp2_lock);
  53. BUG_ON((*cpu_in_lp2 & BIT(phy_cpu_id)));
  54. *cpu_in_lp2 |= BIT(phy_cpu_id);
  55. if ((phy_cpu_id == 0) && cpumask_equal(cpu_lp2_mask, cpu_online_mask))
  56. last_cpu = true;
  57. spin_unlock(&tegra_lp2_lock);
  58. return last_cpu;
  59. }
  60. #endif