pmc.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <linux/of.h>
  13. #include <linux/of_device.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_MINOR MISC_DYNAMIC_MINOR
  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. 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 __devinit pmc_probe(struct of_device *op,
  46. const struct of_device_id *match)
  47. {
  48. regs = of_ioremap(&op->resource[0], 0,
  49. resource_size(&op->resource[0]), PMC_OBPNAME);
  50. if (!regs) {
  51. printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME);
  52. return -ENODEV;
  53. }
  54. #ifndef PMC_NO_IDLE
  55. /* Assign power management IDLE handler */
  56. pm_idle = pmc_swift_idle;
  57. #endif
  58. printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
  59. return 0;
  60. }
  61. static struct of_device_id __initdata pmc_match[] = {
  62. {
  63. .name = PMC_OBPNAME,
  64. },
  65. {},
  66. };
  67. MODULE_DEVICE_TABLE(of, pmc_match);
  68. static struct of_platform_driver pmc_driver = {
  69. .name = "pmc",
  70. .match_table = pmc_match,
  71. .probe = pmc_probe,
  72. };
  73. static int __init pmc_init(void)
  74. {
  75. return of_register_driver(&pmc_driver, &of_bus_type);
  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);