leon_pmc.c 1.9 KB

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