1 /* apc - Driver implementation for power management functions
2 * of Aurora Personality Chip (APC) on SPARCstation-4/5 and
5 * Copyright (c) 2002 Eric Brower (ebrower@usa.net)
8 #include <linux/kernel.h>
10 #include <linux/errno.h>
11 #include <linux/init.h>
12 #include <linux/miscdevice.h>
13 #include <linux/smp_lock.h>
18 #include <asm/oplib.h>
19 #include <asm/uaccess.h>
20 #include <asm/auxio.h>
25 * #define APC_DEBUG_LED
28 #define APC_MINOR MISC_DYNAMIC_MINOR
29 #define APC_OBPNAME "power-management"
30 #define APC_DEVNAME "apc"
32 volatile static u8 __iomem
*regs
;
33 static int apc_regsize
;
34 static int apc_no_idle __initdata
= 0;
36 #define apc_readb(offs) (sbus_readb(regs+offs))
37 #define apc_writeb(val, offs) (sbus_writeb(val, regs+offs))
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
45 static int __init
apc_setup(char *str
)
47 if(!strncmp(str
, "noidle", strlen("noidle"))) {
53 __setup("apc=", apc_setup
);
56 * CPU idle callback function
57 * See .../arch/sparc/kernel/process.c
59 static void apc_swift_idle(void)
62 set_auxio(0x00, AUXIO_LED
);
65 apc_writeb(apc_readb(APC_IDLE_REG
) | APC_IDLE_ON
, APC_IDLE_REG
);
68 set_auxio(AUXIO_LED
, 0x00);
72 static inline void apc_free(void)
74 sbus_iounmap(regs
, apc_regsize
);
77 static int apc_open(struct inode
*inode
, struct file
*f
)
83 static int apc_release(struct inode
*inode
, struct file
*f
)
88 static long apc_ioctl(struct file
*f
, unsigned int cmd
, unsigned long __arg
)
90 __u8 inarg
, __user
*arg
;
92 arg
= (__u8 __user
*) __arg
;
98 if (put_user(apc_readb(APC_FANCTL_REG
) & APC_REGMASK
, arg
)) {
105 if (put_user(apc_readb(APC_CPOWER_REG
) & APC_REGMASK
, arg
)) {
112 if (put_user(apc_readb(APC_BPORT_REG
) & APC_BPMASK
, arg
)) {
119 if (get_user(inarg
, arg
)) {
123 apc_writeb(inarg
& APC_REGMASK
, APC_FANCTL_REG
);
126 if (get_user(inarg
, arg
)) {
130 apc_writeb(inarg
& APC_REGMASK
, APC_CPOWER_REG
);
133 if (get_user(inarg
, arg
)) {
137 apc_writeb(inarg
& APC_BPMASK
, APC_BPORT_REG
);
148 static const struct file_operations apc_fops
= {
149 .unlocked_ioctl
= apc_ioctl
,
151 .release
= apc_release
,
154 static struct miscdevice apc_miscdev
= { APC_MINOR
, APC_DEVNAME
, &apc_fops
};
156 static int __init
apc_probe(void)
158 struct sbus_bus
*sbus
= NULL
;
159 struct sbus_dev
*sdev
= NULL
;
162 for_each_sbus(sbus
) {
163 for_each_sbusdev(sdev
, sbus
) {
164 if (!strcmp(sdev
->prom_name
, APC_OBPNAME
)) {
175 apc_regsize
= sdev
->reg_addrs
[0].reg_size
;
176 regs
= sbus_ioremap(&sdev
->resource
[0], 0,
177 apc_regsize
, APC_OBPNAME
);
179 printk(KERN_ERR
"%s: unable to map registers\n", APC_DEVNAME
);
183 iTmp
= misc_register(&apc_miscdev
);
185 printk(KERN_ERR
"%s: unable to register device\n", APC_DEVNAME
);
190 /* Assign power management IDLE handler */
192 pm_idle
= apc_swift_idle
;
194 printk(KERN_INFO
"%s: power management initialized%s\n",
195 APC_DEVNAME
, apc_no_idle
? " (CPU idle disabled)" : "");
199 /* This driver is not critical to the boot process
200 * and is easiest to ioremap when SBus is already
201 * initialized, so we install ourselves thusly:
203 __initcall(apc_probe
);