Linux Audio

Check our new training course

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