Linux Audio

Check our new training course

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