hotplug.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/cp15.h>
  17. #include <asm/smp_plat.h>
  18. static inline void cpu_enter_lowpower(void)
  19. {
  20. unsigned int v;
  21. asm volatile(
  22. " mcr p15, 0, %1, c7, c5, 0\n"
  23. " dsb\n"
  24. /*
  25. * Turn off coherency
  26. */
  27. " mrc p15, 0, %0, c1, c0, 1\n"
  28. " bic %0, %0, #0x20\n"
  29. " mcr p15, 0, %0, c1, c0, 1\n"
  30. " mrc p15, 0, %0, c1, c0, 0\n"
  31. " bic %0, %0, %2\n"
  32. " mcr p15, 0, %0, c1, c0, 0\n"
  33. : "=&r" (v)
  34. : "r" (0), "Ir" (CR_C)
  35. : "cc", "memory");
  36. }
  37. static inline void cpu_leave_lowpower(void)
  38. {
  39. unsigned int v;
  40. asm volatile("mrc p15, 0, %0, c1, c0, 0\n"
  41. " orr %0, %0, %1\n"
  42. " mcr p15, 0, %0, c1, c0, 0\n"
  43. " mrc p15, 0, %0, c1, c0, 1\n"
  44. " orr %0, %0, #0x20\n"
  45. " mcr p15, 0, %0, c1, c0, 1\n"
  46. : "=&r" (v)
  47. : "Ir" (CR_C)
  48. : "cc");
  49. }
  50. static inline void spear13xx_do_lowpower(unsigned int cpu, int *spurious)
  51. {
  52. for (;;) {
  53. wfi();
  54. if (pen_release == cpu) {
  55. /*
  56. * OK, proper wakeup, we're done
  57. */
  58. break;
  59. }
  60. /*
  61. * Getting here, means that we have come out of WFI without
  62. * having been woken up - this shouldn't happen
  63. *
  64. * Just note it happening - when we're woken, we can report
  65. * its occurrence.
  66. */
  67. (*spurious)++;
  68. }
  69. }
  70. /*
  71. * platform-specific code to shutdown a CPU
  72. *
  73. * Called with IRQs disabled
  74. */
  75. void spear13xx_cpu_die(unsigned int cpu)
  76. {
  77. int spurious = 0;
  78. /*
  79. * we're ready for shutdown now, so do it
  80. */
  81. cpu_enter_lowpower();
  82. spear13xx_do_lowpower(cpu, &spurious);
  83. /*
  84. * bring this CPU back into the world of cache
  85. * coherency, and then restore interrupts
  86. */
  87. cpu_leave_lowpower();
  88. if (spurious)
  89. pr_warn("CPU%u: %u spurious wakeup calls\n", cpu, spurious);
  90. }