x86/vdso: Fix 'make bzImage' on older distros
[linux/fpc-iii.git] / arch / sparc / kernel / apc.c
blob742f6c4436bf2a9397ce9eb20b073f70d26b044e
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>
14 #include <linux/of.h>
15 #include <linux/of_device.h>
16 #include <linux/module.h>
18 #include <asm/io.h>
19 #include <asm/oplib.h>
20 #include <asm/uaccess.h>
21 #include <asm/auxio.h>
22 #include <asm/apc.h>
23 #include <asm/processor.h>
25 /* Debugging
27 * #define APC_DEBUG_LED
30 #define APC_MINOR MISC_DYNAMIC_MINOR
31 #define APC_OBPNAME "power-management"
32 #define APC_DEVNAME "apc"
34 static u8 __iomem *regs;
35 static int apc_no_idle = 0;
37 #define apc_readb(offs) (sbus_readb(regs+offs))
38 #define apc_writeb(val, offs) (sbus_writeb(val, regs+offs))
40 /* Specify "apc=noidle" on the kernel command line to
41 * disable APC CPU standby support. Certain prototype
42 * systems (SPARCstation-Fox) do not play well with APC
43 * CPU idle, so disable this if your system has APC and
44 * crashes randomly.
46 static int __init apc_setup(char *str)
48 if(!strncmp(str, "noidle", strlen("noidle"))) {
49 apc_no_idle = 1;
50 return 1;
52 return 0;
54 __setup("apc=", apc_setup);
56 /*
57 * CPU idle callback function
58 * See .../arch/sparc/kernel/process.c
60 static void apc_swift_idle(void)
62 #ifdef APC_DEBUG_LED
63 set_auxio(0x00, AUXIO_LED);
64 #endif
66 apc_writeb(apc_readb(APC_IDLE_REG) | APC_IDLE_ON, APC_IDLE_REG);
68 #ifdef APC_DEBUG_LED
69 set_auxio(AUXIO_LED, 0x00);
70 #endif
73 static inline void apc_free(struct platform_device *op)
75 of_iounmap(&op->resource[0], regs, resource_size(&op->resource[0]));
78 static int apc_open(struct inode *inode, struct file *f)
80 return 0;
83 static int apc_release(struct inode *inode, struct file *f)
85 return 0;
88 static long apc_ioctl(struct file *f, unsigned int cmd, unsigned long __arg)
90 __u8 inarg, __user *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;
114 case APCIOCSCPWR:
115 if (get_user(inarg, arg))
116 return -EFAULT;
117 apc_writeb(inarg & APC_REGMASK, APC_CPOWER_REG);
118 break;
120 case APCIOCSBPORT:
121 if (get_user(inarg, arg))
122 return -EFAULT;
123 apc_writeb(inarg & APC_BPMASK, APC_BPORT_REG);
124 break;
126 default:
127 return -EINVAL;
130 return 0;
133 static const struct file_operations apc_fops = {
134 .unlocked_ioctl = apc_ioctl,
135 .open = apc_open,
136 .release = apc_release,
137 .llseek = noop_llseek,
140 static struct miscdevice apc_miscdev = { APC_MINOR, APC_DEVNAME, &apc_fops };
142 static int apc_probe(struct platform_device *op)
144 int err;
146 regs = of_ioremap(&op->resource[0], 0,
147 resource_size(&op->resource[0]), APC_OBPNAME);
148 if (!regs) {
149 printk(KERN_ERR "%s: unable to map registers\n", APC_DEVNAME);
150 return -ENODEV;
153 err = misc_register(&apc_miscdev);
154 if (err) {
155 printk(KERN_ERR "%s: unable to register device\n", APC_DEVNAME);
156 apc_free(op);
157 return -ENODEV;
160 /* Assign power management IDLE handler */
161 if (!apc_no_idle)
162 sparc_idle = apc_swift_idle;
164 printk(KERN_INFO "%s: power management initialized%s\n",
165 APC_DEVNAME, apc_no_idle ? " (CPU idle disabled)" : "");
167 return 0;
170 static struct of_device_id apc_match[] = {
172 .name = APC_OBPNAME,
176 MODULE_DEVICE_TABLE(of, apc_match);
178 static struct platform_driver apc_driver = {
179 .driver = {
180 .name = "apc",
181 .of_match_table = apc_match,
183 .probe = apc_probe,
186 static int __init apc_init(void)
188 return platform_driver_register(&apc_driver);
191 /* This driver is not critical to the boot process
192 * and is easiest to ioremap when SBus is already
193 * initialized, so we install ourselves thusly:
195 __initcall(apc_init);