hotplug.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * linux/arch/arm/mach-spear13xx/hotplug.c
  3. *
  4. * Copyright (C) 2012 ST Microelectronics Ltd.
  5. * Deepak Sikri <deepak.sikri@st.com>
  6. *
  7. * based upon linux/arch/arm/mach-realview/hotplug.c
  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 <asm/smp_plat.h>
  19. static inline void 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, #0x20\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", "memory");
  38. }
  39. static inline void cpu_leave_lowpower(void)
  40. {
  41. unsigned int v;
  42. asm volatile("mrc p15, 0, %0, c1, c0, 0\n"
  43. " orr %0, %0, %1\n"
  44. " mcr p15, 0, %0, c1, c0, 0\n"
  45. " mrc p15, 0, %0, c1, c0, 1\n"
  46. " orr %0, %0, #0x20\n"
  47. " mcr p15, 0, %0, c1, c0, 1\n"
  48. : "=&r" (v)
  49. : "Ir" (CR_C)
  50. : "cc");
  51. }
  52. static inline void spear13xx_do_lowpower(unsigned int cpu, int *spurious)
  53. {
  54. for (;;) {
  55. wfi();
  56. if (pen_release == cpu) {
  57. /*
  58. * OK, proper wakeup, we're done
  59. */
  60. break;
  61. }
  62. /*
  63. * Getting here, means that we have come out of WFI without
  64. * having been woken up - this shouldn't happen
  65. *
  66. * Just note it happening - when we're woken, we can report
  67. * its occurrence.
  68. */
  69. (*spurious)++;
  70. }
  71. }
  72. /*
  73. * platform-specific code to shutdown a CPU
  74. *
  75. * Called with IRQs disabled
  76. */
  77. void __ref spear13xx_cpu_die(unsigned int cpu)
  78. {
  79. int spurious = 0;
  80. /*
  81. * we're ready for shutdown now, so do it
  82. */
  83. cpu_enter_lowpower();
  84. spear13xx_do_lowpower(cpu, &spurious);
  85. /*
  86. * bring this CPU back into the world of cache
  87. * coherency, and then restore interrupts
  88. */
  89. cpu_leave_lowpower();
  90. if (spurious)
  91. pr_warn("CPU%u: %u spurious wakeup calls\n", cpu, spurious);
  92. }