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>
15 #include <linux/of_device.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 static u8 __iomem
*regs
;
33 static int apc_no_idle __devinitdata
= 0;
35 #define apc_readb(offs) (sbus_readb(regs+offs))
36 #define apc_writeb(val, offs) (sbus_writeb(val, regs+offs))
38 /* Specify "apc=noidle" on the kernel command line to
39 * disable APC CPU standby support. Certain prototype
40 * systems (SPARCstation-Fox) do not play well with APC
41 * CPU idle, so disable this if your system has APC and
44 static int __init
apc_setup(char *str
)
46 if(!strncmp(str
, "noidle", strlen("noidle"))) {
52 __setup("apc=", apc_setup
);
55 * CPU idle callback function
56 * See .../arch/sparc/kernel/process.c
58 static void apc_swift_idle(void)
61 set_auxio(0x00, AUXIO_LED
);
64 apc_writeb(apc_readb(APC_IDLE_REG
) | APC_IDLE_ON
, APC_IDLE_REG
);
67 set_auxio(AUXIO_LED
, 0x00);
71 static inline void apc_free(struct platform_device
*op
)
73 of_iounmap(&op
->resource
[0], regs
, resource_size(&op
->resource
[0]));
76 static int apc_open(struct inode
*inode
, struct file
*f
)
81 static int apc_release(struct inode
*inode
, struct file
*f
)
86 static long apc_ioctl(struct file
*f
, unsigned int cmd
, unsigned long __arg
)
88 __u8 inarg
, __user
*arg
= (__u8 __user
*) __arg
;
92 if (put_user(apc_readb(APC_FANCTL_REG
) & APC_REGMASK
, arg
))
97 if (put_user(apc_readb(APC_CPOWER_REG
) & APC_REGMASK
, arg
))
102 if (put_user(apc_readb(APC_BPORT_REG
) & APC_BPMASK
, arg
))
107 if (get_user(inarg
, arg
))
109 apc_writeb(inarg
& APC_REGMASK
, APC_FANCTL_REG
);
113 if (get_user(inarg
, arg
))
115 apc_writeb(inarg
& APC_REGMASK
, APC_CPOWER_REG
);
119 if (get_user(inarg
, arg
))
121 apc_writeb(inarg
& APC_BPMASK
, APC_BPORT_REG
);
131 static const struct file_operations apc_fops
= {
132 .unlocked_ioctl
= apc_ioctl
,
134 .release
= apc_release
,
135 .llseek
= noop_llseek
,
138 static struct miscdevice apc_miscdev
= { APC_MINOR
, APC_DEVNAME
, &apc_fops
};
140 static int __devinit
apc_probe(struct platform_device
*op
)
144 regs
= of_ioremap(&op
->resource
[0], 0,
145 resource_size(&op
->resource
[0]), APC_OBPNAME
);
147 printk(KERN_ERR
"%s: unable to map registers\n", APC_DEVNAME
);
151 err
= misc_register(&apc_miscdev
);
153 printk(KERN_ERR
"%s: unable to register device\n", APC_DEVNAME
);
158 /* Assign power management IDLE handler */
160 pm_idle
= apc_swift_idle
;
162 printk(KERN_INFO
"%s: power management initialized%s\n",
163 APC_DEVNAME
, apc_no_idle
? " (CPU idle disabled)" : "");
168 static struct of_device_id apc_match
[] = {
174 MODULE_DEVICE_TABLE(of
, apc_match
);
176 static struct platform_driver apc_driver
= {
179 .owner
= THIS_MODULE
,
180 .of_match_table
= apc_match
,
185 static int __init
apc_init(void)
187 return platform_driver_register(&apc_driver
);
190 /* This driver is not critical to the boot process
191 * and is easiest to ioremap when SBus is already
192 * initialized, so we install ourselves thusly:
194 __initcall(apc_init
);