Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / sparc / kernel / apc.c
blobd06a405ca718eb6f0067c9d80ca16d606486d4a3
1 /* apc - Driver implementation for power management functions
2 * of Aurora Personality Chip (APC) on SPARCstation-4/5 and
3 * derivatives.
5 * Copyright (c) 2002 Eric Brower (ebrower@usa.net)
6 */
8 #include <linux/kernel.h>
9 #include <linux/fs.h>
10 #include <linux/errno.h>
11 #include <linux/init.h>
12 #include <linux/miscdevice.h>
13 #include <linux/pm.h>
15 #include <asm/io.h>
16 #include <asm/sbus.h>
17 #include <asm/oplib.h>
18 #include <asm/uaccess.h>
19 #include <asm/auxio.h>
20 #include <asm/apc.h>
22 /* Debugging
24 * #define APC_DEBUG_LED
27 #define APC_MINOR MISC_DYNAMIC_MINOR
28 #define APC_OBPNAME "power-management"
29 #define APC_DEVNAME "apc"
31 volatile static u8 __iomem *regs;
32 static int apc_regsize;
33 static int apc_no_idle __initdata = 0;
35 #define apc_readb(offs) (sbus_readb(regs+offs))
36 #define apc_writeb(val, offs) (sbus_writeb(val, regs+offs))
38 /* Specify "apc=noidle" on the kernel command line to
39 * disable APC CPU standby support. Certain prototype
40 * systems (SPARCstation-Fox) do not play well with APC
41 * CPU idle, so disable this if your system has APC and
42 * crashes randomly.
44 static int __init apc_setup(char *str)
46 if(!strncmp(str, "noidle", strlen("noidle"))) {
47 apc_no_idle = 1;
48 return 1;
50 return 0;
52 __setup("apc=", apc_setup);
54 /*
55 * CPU idle callback function
56 * See .../arch/sparc/kernel/process.c
58 void apc_swift_idle(void)
60 #ifdef APC_DEBUG_LED
61 set_auxio(0x00, AUXIO_LED);
62 #endif
64 apc_writeb(apc_readb(APC_IDLE_REG) | APC_IDLE_ON, APC_IDLE_REG);
66 #ifdef APC_DEBUG_LED
67 set_auxio(AUXIO_LED, 0x00);
68 #endif
71 static inline void apc_free(void)
73 sbus_iounmap(regs, apc_regsize);
76 static int apc_open(struct inode *inode, struct file *f)
78 return 0;
81 static int apc_release(struct inode *inode, struct file *f)
83 return 0;
86 static int apc_ioctl(struct inode *inode, struct file *f,
87 unsigned int cmd, unsigned long __arg)
89 __u8 inarg, __user *arg;
91 arg = (__u8 __user *) __arg;
92 switch (cmd) {
93 case APCIOCGFANCTL:
94 if (put_user(apc_readb(APC_FANCTL_REG) & APC_REGMASK, arg))
95 return -EFAULT;
96 break;
98 case APCIOCGCPWR:
99 if (put_user(apc_readb(APC_CPOWER_REG) & APC_REGMASK, arg))
100 return -EFAULT;
101 break;
103 case APCIOCGBPORT:
104 if (put_user(apc_readb(APC_BPORT_REG) & APC_BPMASK, arg))
105 return -EFAULT;
106 break;
108 case APCIOCSFANCTL:
109 if (get_user(inarg, arg))
110 return -EFAULT;
111 apc_writeb(inarg & APC_REGMASK, APC_FANCTL_REG);
112 break;
113 case APCIOCSCPWR:
114 if (get_user(inarg, arg))
115 return -EFAULT;
116 apc_writeb(inarg & APC_REGMASK, APC_CPOWER_REG);
117 break;
118 case APCIOCSBPORT:
119 if (get_user(inarg, arg))
120 return -EFAULT;
121 apc_writeb(inarg & APC_BPMASK, APC_BPORT_REG);
122 break;
123 default:
124 return -EINVAL;
127 return 0;
130 static const struct file_operations apc_fops = {
131 .ioctl = apc_ioctl,
132 .open = apc_open,
133 .release = apc_release,
136 static struct miscdevice apc_miscdev = { APC_MINOR, APC_DEVNAME, &apc_fops };
138 static int __init apc_probe(void)
140 struct sbus_bus *sbus = NULL;
141 struct sbus_dev *sdev = NULL;
142 int iTmp = 0;
144 for_each_sbus(sbus) {
145 for_each_sbusdev(sdev, sbus) {
146 if (!strcmp(sdev->prom_name, APC_OBPNAME)) {
147 goto sbus_done;
152 sbus_done:
153 if (!sdev) {
154 return -ENODEV;
157 apc_regsize = sdev->reg_addrs[0].reg_size;
158 regs = sbus_ioremap(&sdev->resource[0], 0,
159 apc_regsize, APC_OBPNAME);
160 if(!regs) {
161 printk(KERN_ERR "%s: unable to map registers\n", APC_DEVNAME);
162 return -ENODEV;
165 iTmp = misc_register(&apc_miscdev);
166 if (iTmp != 0) {
167 printk(KERN_ERR "%s: unable to register device\n", APC_DEVNAME);
168 apc_free();
169 return -ENODEV;
172 /* Assign power management IDLE handler */
173 if(!apc_no_idle)
174 pm_idle = apc_swift_idle;
176 printk(KERN_INFO "%s: power management initialized%s\n",
177 APC_DEVNAME, apc_no_idle ? " (CPU idle disabled)" : "");
178 return 0;
181 /* This driver is not critical to the boot process
182 * and is easiest to ioremap when SBus is already
183 * initialized, so we install ourselves thusly:
185 __initcall(apc_probe);