apc.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* apc - Driver implementation for power management functions
  2. * of Aurora Personality Chip (APC) on SPARCstation-4/5 and
  3. * derivatives.
  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/miscdevice.h>
  12. #include <linux/pm.h>
  13. #include <asm/io.h>
  14. #include <asm/sbus.h>
  15. #include <asm/oplib.h>
  16. #include <asm/uaccess.h>
  17. #include <asm/auxio.h>
  18. #include <asm/apc.h>
  19. /* Debugging
  20. *
  21. * #define APC_DEBUG_LED
  22. */
  23. #define APC_MINOR MISC_DYNAMIC_MINOR
  24. #define APC_OBPNAME "power-management"
  25. #define APC_DEVNAME "apc"
  26. volatile static u8 __iomem *regs;
  27. static int apc_regsize;
  28. static int apc_no_idle __initdata = 0;
  29. #define apc_readb(offs) (sbus_readb(regs+offs))
  30. #define apc_writeb(val, offs) (sbus_writeb(val, regs+offs))
  31. /* Specify "apc=noidle" on the kernel command line to
  32. * disable APC CPU standby support. Certain prototype
  33. * systems (SPARCstation-Fox) do not play well with APC
  34. * CPU idle, so disable this if your system has APC and
  35. * crashes randomly.
  36. */
  37. static int __init apc_setup(char *str)
  38. {
  39. if(!strncmp(str, "noidle", strlen("noidle"))) {
  40. apc_no_idle = 1;
  41. return 1;
  42. }
  43. return 0;
  44. }
  45. __setup("apc=", apc_setup);
  46. /*
  47. * CPU idle callback function
  48. * See .../arch/sparc/kernel/process.c
  49. */
  50. void apc_swift_idle(void)
  51. {
  52. #ifdef APC_DEBUG_LED
  53. set_auxio(0x00, AUXIO_LED);
  54. #endif
  55. apc_writeb(apc_readb(APC_IDLE_REG) | APC_IDLE_ON, APC_IDLE_REG);
  56. #ifdef APC_DEBUG_LED
  57. set_auxio(AUXIO_LED, 0x00);
  58. #endif
  59. }
  60. static inline void apc_free(void)
  61. {
  62. sbus_iounmap(regs, apc_regsize);
  63. }
  64. static int apc_open(struct inode *inode, struct file *f)
  65. {
  66. return 0;
  67. }
  68. static int apc_release(struct inode *inode, struct file *f)
  69. {
  70. return 0;
  71. }
  72. static int apc_ioctl(struct inode *inode, struct file *f,
  73. unsigned int cmd, unsigned long __arg)
  74. {
  75. __u8 inarg, __user *arg;
  76. arg = (__u8 __user *) __arg;
  77. switch (cmd) {
  78. case APCIOCGFANCTL:
  79. if (put_user(apc_readb(APC_FANCTL_REG) & APC_REGMASK, arg))
  80. return -EFAULT;
  81. break;
  82. case APCIOCGCPWR:
  83. if (put_user(apc_readb(APC_CPOWER_REG) & APC_REGMASK, arg))
  84. return -EFAULT;
  85. break;
  86. case APCIOCGBPORT:
  87. if (put_user(apc_readb(APC_BPORT_REG) & APC_BPMASK, arg))
  88. return -EFAULT;
  89. break;
  90. case APCIOCSFANCTL:
  91. if (get_user(inarg, arg))
  92. return -EFAULT;
  93. apc_writeb(inarg & APC_REGMASK, APC_FANCTL_REG);
  94. break;
  95. case APCIOCSCPWR:
  96. if (get_user(inarg, arg))
  97. return -EFAULT;
  98. apc_writeb(inarg & APC_REGMASK, APC_CPOWER_REG);
  99. break;
  100. case APCIOCSBPORT:
  101. if (get_user(inarg, arg))
  102. return -EFAULT;
  103. apc_writeb(inarg & APC_BPMASK, APC_BPORT_REG);
  104. break;
  105. default:
  106. return -EINVAL;
  107. };
  108. return 0;
  109. }
  110. static struct file_operations apc_fops = {
  111. .ioctl = apc_ioctl,
  112. .open = apc_open,
  113. .release = apc_release,
  114. };
  115. static struct miscdevice apc_miscdev = { APC_MINOR, APC_DEVNAME, &apc_fops };
  116. static int __init apc_probe(void)
  117. {
  118. struct sbus_bus *sbus = NULL;
  119. struct sbus_dev *sdev = NULL;
  120. int iTmp = 0;
  121. for_each_sbus(sbus) {
  122. for_each_sbusdev(sdev, sbus) {
  123. if (!strcmp(sdev->prom_name, APC_OBPNAME)) {
  124. goto sbus_done;
  125. }
  126. }
  127. }
  128. sbus_done:
  129. if (!sdev) {
  130. return -ENODEV;
  131. }
  132. apc_regsize = sdev->reg_addrs[0].reg_size;
  133. regs = sbus_ioremap(&sdev->resource[0], 0,
  134. apc_regsize, APC_OBPNAME);
  135. if(!regs) {
  136. printk(KERN_ERR "%s: unable to map registers\n", APC_DEVNAME);
  137. return -ENODEV;
  138. }
  139. iTmp = misc_register(&apc_miscdev);
  140. if (iTmp != 0) {
  141. printk(KERN_ERR "%s: unable to register device\n", APC_DEVNAME);
  142. apc_free();
  143. return -ENODEV;
  144. }
  145. /* Assign power management IDLE handler */
  146. if(!apc_no_idle)
  147. pm_idle = apc_swift_idle;
  148. printk(KERN_INFO "%s: power management initialized%s\n",
  149. APC_DEVNAME, apc_no_idle ? " (CPU idle disabled)" : "");
  150. return 0;
  151. }
  152. /* This driver is not critical to the boot process
  153. * and is easiest to ioremap when SBus is already
  154. * initialized, so we install ourselves thusly:
  155. */
  156. __initcall(apc_probe);