pmc.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* pmc - Driver implementation for power management functions
  2. * of Power Management Controller (PMC) on SPARCstation-Voyager.
  3. *
  4. * Copyright (c) 2002 Eric Brower (ebrower@usa.net)
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/fs.h>
  8. #include <linux/errno.h>
  9. #include <linux/init.h>
  10. #include <linux/miscdevice.h>
  11. #include <linux/pm.h>
  12. #include <asm/io.h>
  13. #include <asm/sbus.h>
  14. #include <asm/oplib.h>
  15. #include <asm/uaccess.h>
  16. #include <asm/auxio.h>
  17. /* Debug
  18. *
  19. * #define PMC_DEBUG_LED
  20. * #define PMC_NO_IDLE
  21. */
  22. #define PMC_MINOR MISC_DYNAMIC_MINOR
  23. #define PMC_OBPNAME "SUNW,pmc"
  24. #define PMC_DEVNAME "pmc"
  25. #define PMC_IDLE_REG 0x00
  26. #define PMC_IDLE_ON 0x01
  27. volatile static u8 __iomem *regs;
  28. static int pmc_regsize;
  29. #define pmc_readb(offs) (sbus_readb(regs+offs))
  30. #define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs))
  31. /*
  32. * CPU idle callback function
  33. * See .../arch/sparc/kernel/process.c
  34. */
  35. void pmc_swift_idle(void)
  36. {
  37. #ifdef PMC_DEBUG_LED
  38. set_auxio(0x00, AUXIO_LED);
  39. #endif
  40. pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);
  41. #ifdef PMC_DEBUG_LED
  42. set_auxio(AUXIO_LED, 0x00);
  43. #endif
  44. }
  45. static inline void pmc_free(void)
  46. {
  47. sbus_iounmap(regs, pmc_regsize);
  48. }
  49. static int __init pmc_probe(void)
  50. {
  51. struct sbus_bus *sbus = NULL;
  52. struct sbus_dev *sdev = NULL;
  53. for_each_sbus(sbus) {
  54. for_each_sbusdev(sdev, sbus) {
  55. if (!strcmp(sdev->prom_name, PMC_OBPNAME)) {
  56. goto sbus_done;
  57. }
  58. }
  59. }
  60. sbus_done:
  61. if (!sdev) {
  62. return -ENODEV;
  63. }
  64. pmc_regsize = sdev->reg_addrs[0].reg_size;
  65. regs = sbus_ioremap(&sdev->resource[0], 0,
  66. pmc_regsize, PMC_OBPNAME);
  67. if (!regs) {
  68. printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME);
  69. return -ENODEV;
  70. }
  71. #ifndef PMC_NO_IDLE
  72. /* Assign power management IDLE handler */
  73. pm_idle = pmc_swift_idle;
  74. #endif
  75. printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
  76. return 0;
  77. }
  78. /* This driver is not critical to the boot process
  79. * and is easiest to ioremap when SBus is already
  80. * initialized, so we install ourselves thusly:
  81. */
  82. __initcall(pmc_probe);