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