pmc.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* pmc - Driver implementation for power management functions
  3. * of Power Management Controller (PMC) on SPARCstation-Voyager.
  4. *
  5. * Copyright (c) 2002 Eric Brower (ebrower@usa.net)
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/fs.h>
  9. #include <linux/errno.h>
  10. #include <linux/init.h>
  11. #include <linux/pm.h>
  12. #include <linux/of.h>
  13. #include <linux/of_device.h>
  14. #include <linux/module.h>
  15. #include <asm/io.h>
  16. #include <asm/oplib.h>
  17. #include <linux/uaccess.h>
  18. #include <asm/auxio.h>
  19. #include <asm/processor.h>
  20. /* Debug
  21. *
  22. * #define PMC_DEBUG_LED
  23. * #define PMC_NO_IDLE
  24. */
  25. #define PMC_OBPNAME "SUNW,pmc"
  26. #define PMC_DEVNAME "pmc"
  27. #define PMC_IDLE_REG 0x00
  28. #define PMC_IDLE_ON 0x01
  29. static u8 __iomem *regs;
  30. #define pmc_readb(offs) (sbus_readb(regs+offs))
  31. #define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs))
  32. /*
  33. * CPU idle callback function
  34. * See .../arch/sparc/kernel/process.c
  35. */
  36. static void pmc_swift_idle(void)
  37. {
  38. #ifdef PMC_DEBUG_LED
  39. set_auxio(0x00, AUXIO_LED);
  40. #endif
  41. pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG);
  42. #ifdef PMC_DEBUG_LED
  43. set_auxio(AUXIO_LED, 0x00);
  44. #endif
  45. }
  46. static int pmc_probe(struct platform_device *op)
  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. sparc_idle = pmc_swift_idle;
  57. #endif
  58. printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
  59. return 0;
  60. }
  61. static const struct of_device_id pmc_match[] = {
  62. {
  63. .name = PMC_OBPNAME,
  64. },
  65. {},
  66. };
  67. MODULE_DEVICE_TABLE(of, pmc_match);
  68. static struct platform_driver pmc_driver = {
  69. .driver = {
  70. .name = "pmc",
  71. .of_match_table = pmc_match,
  72. },
  73. .probe = pmc_probe,
  74. };
  75. static int __init pmc_init(void)
  76. {
  77. return platform_driver_register(&pmc_driver);
  78. }
  79. /* This driver is not critical to the boot process
  80. * and is easiest to ioremap when SBus is already
  81. * initialized, so we install ourselves thusly:
  82. */
  83. __initcall(pmc_init);