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. /* Debug
  19. *
  20. * #define PMC_DEBUG_LED
  21. * #define PMC_NO_IDLE
  22. */
  23. #define PMC_OBPNAME "SUNW,pmc"
  24. #define PMC_DEVNAME "pmc"
  25. #define PMC_IDLE_REG 0x00
  26. #define PMC_IDLE_ON 0x01
  27. static u8 __iomem *regs;
  28. #define pmc_readb(offs) (sbus_readb(regs+offs))
  29. #define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs))
  30. /*
  31. * CPU idle callback function
  32. * See .../arch/sparc/kernel/process.c
  33. */
  34. static void pmc_swift_idle(void)
  35. {
  36. #ifdef PMC_DEBUG_LED
  37. set_auxio(0x00, AUXIO_LED);
  38. #endif
  39. pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);
  40. #ifdef PMC_DEBUG_LED
  41. set_auxio(AUXIO_LED, 0x00);
  42. #endif
  43. }
  44. static int __devinit pmc_probe(struct platform_device *op)
  45. {
  46. regs = of_ioremap(&op->resource[0], 0,
  47. resource_size(&op->resource[0]), PMC_OBPNAME);
  48. if (!regs) {
  49. printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME);
  50. return -ENODEV;
  51. }
  52. #ifndef PMC_NO_IDLE
  53. /* Assign power management IDLE handler */
  54. pm_idle = pmc_swift_idle;
  55. #endif
  56. printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
  57. return 0;
  58. }
  59. static struct of_device_id pmc_match[] = {
  60. {
  61. .name = PMC_OBPNAME,
  62. },
  63. {},
  64. };
  65. MODULE_DEVICE_TABLE(of, pmc_match);
  66. static struct platform_driver pmc_driver = {
  67. .driver = {
  68. .name = "pmc",
  69. .owner = THIS_MODULE,
  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);