pmc.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/pm.h>
  11. #include <linux/of.h>
  12. #include <linux/of_device.h>
  13. #include <linux/module.h>
  14. #include <asm/io.h>
  15. #include <asm/oplib.h>
  16. #include <asm/uaccess.h>
  17. #include <asm/auxio.h>
  18. #include <asm/processor.h>
  19. /* Debug
  20. *
  21. * #define PMC_DEBUG_LED
  22. * #define PMC_NO_IDLE
  23. */
  24. #define PMC_OBPNAME "SUNW,pmc"
  25. #define PMC_DEVNAME "pmc"
  26. #define PMC_IDLE_REG 0x00
  27. #define PMC_IDLE_ON 0x01
  28. static u8 __iomem *regs;
  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. static 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 int pmc_probe(struct platform_device *op)
  46. {
  47. regs = of_ioremap(&op->resource[0], 0,
  48. resource_size(&op->resource[0]), PMC_OBPNAME);
  49. if (!regs) {
  50. printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME);
  51. return -ENODEV;
  52. }
  53. #ifndef PMC_NO_IDLE
  54. /* Assign power management IDLE handler */
  55. sparc_idle = pmc_swift_idle;
  56. #endif
  57. printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
  58. return 0;
  59. }
  60. static struct of_device_id pmc_match[] = {
  61. {
  62. .name = PMC_OBPNAME,
  63. },
  64. {},
  65. };
  66. MODULE_DEVICE_TABLE(of, pmc_match);
  67. static struct platform_driver pmc_driver = {
  68. .driver = {
  69. .name = "pmc",
  70. .of_match_table = pmc_match,
  71. },
  72. .probe = pmc_probe,
  73. };
  74. static int __init pmc_init(void)
  75. {
  76. return platform_driver_register(&pmc_driver);
  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_init);