1 // SPDX-License-Identifier: GPL-2.0
2 /* apc - Driver implementation for power management functions
3 * of Aurora Personality Chip (APC) on SPARCstation-4/5 and
6 * Copyright (c) 2002 Eric Brower (ebrower@usa.net)
9 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/init.h>
13 #include <linux/miscdevice.h>
16 #include <linux/of_device.h>
17 #include <linux/module.h>
20 #include <asm/oplib.h>
21 #include <linux/uaccess.h>
22 #include <asm/auxio.h>
24 #include <asm/processor.h>
28 * #define APC_DEBUG_LED
31 #define APC_MINOR MISC_DYNAMIC_MINOR
32 #define APC_OBPNAME "power-management"
33 #define APC_DEVNAME "apc"
35 static u8 __iomem *regs;
36 static int apc_no_idle = 0;
38 #define apc_readb(offs) (sbus_readb(regs+offs))
39 #define apc_writeb(val, offs) (sbus_writeb(val, regs+offs))
41 /* Specify "apc=noidle" on the kernel command line to
42 * disable APC CPU standby support. Certain prototype
43 * systems (SPARCstation-Fox) do not play well with APC
44 * CPU idle, so disable this if your system has APC and
47 static int __init apc_setup(char *str)
49 if(!strncmp(str, "noidle", strlen("noidle"))) {
55 __setup("apc=", apc_setup);
58 * CPU idle callback function
59 * See .../arch/sparc/kernel/process.c
61 static void apc_swift_idle(void)
64 set_auxio(0x00, AUXIO_LED);
67 apc_writeb(apc_readb(APC_IDLE_REG) | APC_IDLE_ON, APC_IDLE_REG);
70 set_auxio(AUXIO_LED, 0x00);
74 static inline void apc_free(struct platform_device *op)
76 of_iounmap(&op->resource[0], regs, resource_size(&op->resource[0]));
79 static int apc_open(struct inode *inode, struct file *f)
84 static int apc_release(struct inode *inode, struct file *f)
89 static long apc_ioctl(struct file *f, unsigned int cmd, unsigned long __arg)
91 __u8 inarg, __user *arg = (__u8 __user *) __arg;
95 if (put_user(apc_readb(APC_FANCTL_REG) & APC_REGMASK, arg))
100 if (put_user(apc_readb(APC_CPOWER_REG) & APC_REGMASK, arg))
105 if (put_user(apc_readb(APC_BPORT_REG) & APC_BPMASK, arg))
110 if (get_user(inarg, arg))
112 apc_writeb(inarg & APC_REGMASK, APC_FANCTL_REG);
116 if (get_user(inarg, arg))
118 apc_writeb(inarg & APC_REGMASK, APC_CPOWER_REG);
122 if (get_user(inarg, arg))
124 apc_writeb(inarg & APC_BPMASK, APC_BPORT_REG);
134 static const struct file_operations apc_fops = {
135 .unlocked_ioctl = apc_ioctl,
137 .release = apc_release,
138 .llseek = noop_llseek,
141 static struct miscdevice apc_miscdev = { APC_MINOR, APC_DEVNAME, &apc_fops };
143 static int apc_probe(struct platform_device *op)
147 regs = of_ioremap(&op->resource[0], 0,
148 resource_size(&op->resource[0]), APC_OBPNAME);
150 printk(KERN_ERR "%s: unable to map registers\n", APC_DEVNAME);
154 err = misc_register(&apc_miscdev);
156 printk(KERN_ERR "%s: unable to register device\n", APC_DEVNAME);
161 /* Assign power management IDLE handler */
163 sparc_idle = apc_swift_idle;
165 printk(KERN_INFO "%s: power management initialized%s\n",
166 APC_DEVNAME, apc_no_idle ? " (CPU idle disabled)" : "");
171 static const struct of_device_id apc_match[] = {
177 MODULE_DEVICE_TABLE(of, apc_match);
179 static struct platform_driver apc_driver = {
182 .of_match_table = apc_match,
187 static int __init apc_init(void)
189 return platform_driver_register(&apc_driver);
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:
196 __initcall(apc_init);