Merge branch 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa...
[deliverable/linux.git] / arch / sparc / kernel / apc.c
CommitLineData
1da177e4
LT
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
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>
7e7e2f03
DM
14#include <linux/of.h>
15#include <linux/of_device.h>
f060ac54 16#include <linux/module.h>
1da177e4
LT
17
18#include <asm/io.h>
1da177e4
LT
19#include <asm/oplib.h>
20#include <asm/uaccess.h>
21#include <asm/auxio.h>
22#include <asm/apc.h>
d472ba84 23#include <asm/processor.h>
1da177e4
LT
24
25/* Debugging
26 *
27 * #define APC_DEBUG_LED
28 */
29
30#define APC_MINOR MISC_DYNAMIC_MINOR
31#define APC_OBPNAME "power-management"
32#define APC_DEVNAME "apc"
33
7e7e2f03 34static u8 __iomem *regs;
7c9503b8 35static int apc_no_idle = 0;
1da177e4 36
7e7e2f03 37#define apc_readb(offs) (sbus_readb(regs+offs))
1da177e4
LT
38#define apc_writeb(val, offs) (sbus_writeb(val, regs+offs))
39
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.
45 */
46static int __init apc_setup(char *str)
47{
48 if(!strncmp(str, "noidle", strlen("noidle"))) {
49 apc_no_idle = 1;
50 return 1;
51 }
52 return 0;
53}
54__setup("apc=", apc_setup);
55
56/*
57 * CPU idle callback function
58 * See .../arch/sparc/kernel/process.c
59 */
c61c65cd 60static void apc_swift_idle(void)
1da177e4
LT
61{
62#ifdef APC_DEBUG_LED
63 set_auxio(0x00, AUXIO_LED);
64#endif
65
66 apc_writeb(apc_readb(APC_IDLE_REG) | APC_IDLE_ON, APC_IDLE_REG);
67
68#ifdef APC_DEBUG_LED
69 set_auxio(AUXIO_LED, 0x00);
70#endif
71}
72
cd4cd730 73static inline void apc_free(struct platform_device *op)
1da177e4 74{
7e7e2f03 75 of_iounmap(&op->resource[0], regs, resource_size(&op->resource[0]));
1da177e4
LT
76}
77
78static int apc_open(struct inode *inode, struct file *f)
79{
80 return 0;
81}
82
83static int apc_release(struct inode *inode, struct file *f)
84{
85 return 0;
86}
87
ab772027 88static long apc_ioctl(struct file *f, unsigned int cmd, unsigned long __arg)
1da177e4 89{
49ab972a 90 __u8 inarg, __user *arg = (__u8 __user *) __arg;
ab772027 91
1da177e4
LT
92 switch (cmd) {
93 case APCIOCGFANCTL:
49ab972a 94 if (put_user(apc_readb(APC_FANCTL_REG) & APC_REGMASK, arg))
ab772027 95 return -EFAULT;
1da177e4
LT
96 break;
97
98 case APCIOCGCPWR:
49ab972a 99 if (put_user(apc_readb(APC_CPOWER_REG) & APC_REGMASK, arg))
1da177e4
LT
100 return -EFAULT;
101 break;
102
103 case APCIOCGBPORT:
49ab972a 104 if (put_user(apc_readb(APC_BPORT_REG) & APC_BPMASK, arg))
1da177e4
LT
105 return -EFAULT;
106 break;
107
108 case APCIOCSFANCTL:
49ab972a 109 if (get_user(inarg, arg))
1da177e4
LT
110 return -EFAULT;
111 apc_writeb(inarg & APC_REGMASK, APC_FANCTL_REG);
112 break;
49ab972a 113
1da177e4 114 case APCIOCSCPWR:
49ab972a 115 if (get_user(inarg, arg))
1da177e4
LT
116 return -EFAULT;
117 apc_writeb(inarg & APC_REGMASK, APC_CPOWER_REG);
118 break;
49ab972a 119
1da177e4 120 case APCIOCSBPORT:
49ab972a 121 if (get_user(inarg, arg))
1da177e4
LT
122 return -EFAULT;
123 apc_writeb(inarg & APC_BPMASK, APC_BPORT_REG);
124 break;
49ab972a 125
1da177e4
LT
126 default:
127 return -EINVAL;
6cb79b3f 128 }
1da177e4
LT
129
130 return 0;
131}
132
5dfe4c96 133static const struct file_operations apc_fops = {
ab772027
SG
134 .unlocked_ioctl = apc_ioctl,
135 .open = apc_open,
136 .release = apc_release,
6038f373 137 .llseek = noop_llseek,
1da177e4
LT
138};
139
140static struct miscdevice apc_miscdev = { APC_MINOR, APC_DEVNAME, &apc_fops };
141
7c9503b8 142static int apc_probe(struct platform_device *op)
1da177e4 143{
7e7e2f03 144 int err;
1da177e4 145
7e7e2f03
DM
146 regs = of_ioremap(&op->resource[0], 0,
147 resource_size(&op->resource[0]), APC_OBPNAME);
148 if (!regs) {
1da177e4
LT
149 printk(KERN_ERR "%s: unable to map registers\n", APC_DEVNAME);
150 return -ENODEV;
151 }
152
7e7e2f03
DM
153 err = misc_register(&apc_miscdev);
154 if (err) {
1da177e4 155 printk(KERN_ERR "%s: unable to register device\n", APC_DEVNAME);
7e7e2f03 156 apc_free(op);
1da177e4
LT
157 return -ENODEV;
158 }
159
160 /* Assign power management IDLE handler */
7e7e2f03 161 if (!apc_no_idle)
d472ba84 162 sparc_idle = apc_swift_idle;
1da177e4
LT
163
164 printk(KERN_INFO "%s: power management initialized%s\n",
7e7e2f03
DM
165 APC_DEVNAME, apc_no_idle ? " (CPU idle disabled)" : "");
166
1da177e4
LT
167 return 0;
168}
169
505d9147 170static struct of_device_id apc_match[] = {
7e7e2f03
DM
171 {
172 .name = APC_OBPNAME,
173 },
174 {},
175};
176MODULE_DEVICE_TABLE(of, apc_match);
177
4ebb24f7 178static struct platform_driver apc_driver = {
4018294b
GL
179 .driver = {
180 .name = "apc",
181 .owner = THIS_MODULE,
182 .of_match_table = apc_match,
183 },
7e7e2f03
DM
184 .probe = apc_probe,
185};
186
187static int __init apc_init(void)
188{
4ebb24f7 189 return platform_driver_register(&apc_driver);
7e7e2f03
DM
190}
191
1da177e4
LT
192/* This driver is not critical to the boot process
193 * and is easiest to ioremap when SBus is already
194 * initialized, so we install ourselves thusly:
195 */
7e7e2f03 196__initcall(apc_init);
This page took 0.668511 seconds and 5 git commands to generate.