hotplug.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2012-2013 Xilinx
  3. *
  4. * based on linux/arch/arm/mach-realview/hotplug.c
  5. *
  6. * Copyright (C) 2002 ARM Ltd.
  7. * All Rights Reserved
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/smp.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/cp15.h>
  18. #include "common.h"
  19. static inline void zynq_cpu_enter_lowpower(void)
  20. {
  21. unsigned int v;
  22. flush_cache_all();
  23. asm volatile(
  24. " mcr p15, 0, %1, c7, c5, 0\n"
  25. " dsb\n"
  26. /*
  27. * Turn off coherency
  28. */
  29. " mrc p15, 0, %0, c1, c0, 1\n"
  30. " bic %0, %0, #0x40\n"
  31. " mcr p15, 0, %0, c1, c0, 1\n"
  32. " mrc p15, 0, %0, c1, c0, 0\n"
  33. " bic %0, %0, %2\n"
  34. " mcr p15, 0, %0, c1, c0, 0\n"
  35. : "=&r" (v)
  36. : "r" (0), "Ir" (CR_C)
  37. : "cc");
  38. }
  39. static inline void zynq_cpu_leave_lowpower(void)
  40. {
  41. unsigned int v;
  42. asm volatile(
  43. " mrc p15, 0, %0, c1, c0, 0\n"
  44. " orr %0, %0, %1\n"
  45. " mcr p15, 0, %0, c1, c0, 0\n"
  46. " mrc p15, 0, %0, c1, c0, 1\n"
  47. " orr %0, %0, #0x40\n"
  48. " mcr p15, 0, %0, c1, c0, 1\n"
  49. : "=&r" (v)
  50. : "Ir" (CR_C)
  51. : "cc");
  52. }
  53. static inline void zynq_platform_do_lowpower(unsigned int cpu, int *spurious)
  54. {
  55. /*
  56. * there is no power-control hardware on this platform, so all
  57. * we can do is put the core into WFI; this is safe as the calling
  58. * code will have already disabled interrupts
  59. */
  60. for (;;) {
  61. dsb();
  62. wfi();
  63. /*
  64. * Getting here, means that we have come out of WFI without
  65. * having been woken up - this shouldn't happen
  66. *
  67. * Just note it happening - when we're woken, we can report
  68. * its occurrence.
  69. */
  70. (*spurious)++;
  71. }
  72. }
  73. /*
  74. * platform-specific code to shutdown a CPU
  75. *
  76. * Called with IRQs disabled
  77. */
  78. void zynq_platform_cpu_die(unsigned int cpu)
  79. {
  80. int spurious = 0;
  81. /*
  82. * we're ready for shutdown now, so do it
  83. */
  84. zynq_cpu_enter_lowpower();
  85. zynq_platform_do_lowpower(cpu, &spurious);
  86. /*
  87. * bring this CPU back into the world of cache
  88. * coherency, and then restore interrupts
  89. */
  90. zynq_cpu_leave_lowpower();
  91. if (spurious)
  92. pr_warn("CPU%u: %u spurious wakeup calls\n", cpu, spurious);
  93. }