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/pm.h>
  11. #include <linux/of.h>
  12. #include <linux/of_device.h>
  13. #include <asm/io.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_OBPNAME "SUNW,pmc"
  23. #define PMC_DEVNAME "pmc"
  24. #define PMC_IDLE_REG 0x00
  25. #define PMC_IDLE_ON 0x01
  26. static u8 __iomem *regs;
  27. #define pmc_readb(offs) (sbus_readb(regs+offs))
  28. #define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs))
  29. /*
  30. * CPU idle callback function
  31. * See .../arch/sparc/kernel/process.c
  32. */
  33. static void pmc_swift_idle(void)
  34. {
  35. #ifdef PMC_DEBUG_LED
  36. set_auxio(0x00, AUXIO_LED);
  37. #endif
  38. pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);
  39. #ifdef PMC_DEBUG_LED
  40. set_auxio(AUXIO_LED, 0x00);
  41. #endif
  42. }
  43. static int __devinit pmc_probe(struct platform_device *op)
  44. {
  45. regs = of_ioremap(&op->resource[0], 0,
  46. resource_size(&op->resource[0]), PMC_OBPNAME);
  47. if (!regs) {
  48. printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME);
  49. return -ENODEV;
  50. }
  51. #ifndef PMC_NO_IDLE
  52. /* Assign power management IDLE handler */
  53. pm_idle = pmc_swift_idle;
  54. #endif
  55. printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
  56. return 0;
  57. }
  58. static struct of_device_id pmc_match[] = {
  59. {
  60. .name = PMC_OBPNAME,
  61. },
  62. {},
  63. };
  64. MODULE_DEVICE_TABLE(of, pmc_match);
  65. static struct platform_driver pmc_driver = {
  66. .driver = {
  67. .name = "pmc",
  68. .owner = THIS_MODULE,
  69. .of_match_table = pmc_match,
  70. },
  71. .probe = pmc_probe,
  72. };
  73. static int __init pmc_init(void)
  74. {
  75. return platform_driver_register(&pmc_driver);
  76. }
  77. /* This driver is not critical to the boot process
  78. * and is easiest to ioremap when SBus is already
  79. * initialized, so we install ourselves thusly:
  80. */
  81. __initcall(pmc_init);