leon_pmc.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* leon_pmc.c: LEON Power-down cpu_idle() handler
  3. *
  4. * Copyright (C) 2011 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
  5. */
  6. #include <linux/init.h>
  7. #include <linux/pm.h>
  8. #include <asm/leon_amba.h>
  9. #include <asm/cpu_type.h>
  10. #include <asm/leon.h>
  11. #include <asm/processor.h>
  12. /* List of Systems that need fixup instructions around power-down instruction */
  13. static unsigned int pmc_leon_fixup_ids[] = {
  14. AEROFLEX_UT699,
  15. GAISLER_GR712RC,
  16. LEON4_NEXTREME1,
  17. 0
  18. };
  19. static int pmc_leon_need_fixup(void)
  20. {
  21. unsigned int systemid = amba_system_id >> 16;
  22. unsigned int *id;
  23. id = &pmc_leon_fixup_ids[0];
  24. while (*id != 0) {
  25. if (*id == systemid)
  26. return 1;
  27. id++;
  28. }
  29. return 0;
  30. }
  31. /*
  32. * CPU idle callback function for systems that need some extra handling
  33. * See .../arch/sparc/kernel/process.c
  34. */
  35. static void pmc_leon_idle_fixup(void)
  36. {
  37. /* Prepare an address to a non-cachable region. APB is always
  38. * none-cachable. One instruction is executed after the Sleep
  39. * instruction, we make sure to read the bus and throw away the
  40. * value by accessing a non-cachable area, also we make sure the
  41. * MMU does not get a TLB miss here by using the MMU BYPASS ASI.
  42. */
  43. register unsigned int address = (unsigned int)leon3_irqctrl_regs;
  44. /* Interrupts need to be enabled to not hang the CPU */
  45. raw_local_irq_enable();
  46. __asm__ __volatile__ (
  47. "wr %%g0, %%asr19\n"
  48. "lda [%0] %1, %%g0\n"
  49. :
  50. : "r"(address), "i"(ASI_LEON_BYPASS));
  51. }
  52. /*
  53. * CPU idle callback function
  54. * See .../arch/sparc/kernel/process.c
  55. */
  56. static void pmc_leon_idle(void)
  57. {
  58. /* Interrupts need to be enabled to not hang the CPU */
  59. raw_local_irq_enable();
  60. /* For systems without power-down, this will be no-op */
  61. __asm__ __volatile__ ("wr %g0, %asr19\n\t");
  62. }
  63. /* Install LEON Power Down function */
  64. static int __init leon_pmc_install(void)
  65. {
  66. if (sparc_cpu_model == sparc_leon) {
  67. /* Assign power management IDLE handler */
  68. if (pmc_leon_need_fixup())
  69. sparc_idle = pmc_leon_idle_fixup;
  70. else
  71. sparc_idle = pmc_leon_idle;
  72. printk(KERN_INFO "leon: power management initialized\n");
  73. }
  74. return 0;
  75. }
  76. /* This driver is not critical to the boot process, don't care
  77. * if initialized late.
  78. */
  79. late_initcall(leon_pmc_install);