2005-04-17 06:20:36 +08:00
|
|
|
/* apc - Driver implementation for power management functions
|
|
|
|
* of Aurora Personality Chip (APC) on SPARCstation-4/5 and
|
|
|
|
* derivatives.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002 Eric Brower (ebrower@usa.net)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/pm.h>
|
2008-08-27 17:45:36 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2011-07-31 13:50:31 +08:00
|
|
|
#include <linux/module.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/oplib.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/auxio.h>
|
|
|
|
#include <asm/apc.h>
|
2013-02-10 12:27:26 +08:00
|
|
|
#include <asm/processor.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Debugging
|
|
|
|
*
|
|
|
|
* #define APC_DEBUG_LED
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define APC_MINOR MISC_DYNAMIC_MINOR
|
|
|
|
#define APC_OBPNAME "power-management"
|
|
|
|
#define APC_DEVNAME "apc"
|
|
|
|
|
2008-08-27 17:45:36 +08:00
|
|
|
static u8 __iomem *regs;
|
2012-12-22 06:03:26 +08:00
|
|
|
static int apc_no_idle = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-27 17:45:36 +08:00
|
|
|
#define apc_readb(offs) (sbus_readb(regs+offs))
|
2005-04-17 06:20:36 +08:00
|
|
|
#define apc_writeb(val, offs) (sbus_writeb(val, regs+offs))
|
|
|
|
|
|
|
|
/* Specify "apc=noidle" on the kernel command line to
|
|
|
|
* disable APC CPU standby support. Certain prototype
|
|
|
|
* systems (SPARCstation-Fox) do not play well with APC
|
|
|
|
* CPU idle, so disable this if your system has APC and
|
|
|
|
* crashes randomly.
|
|
|
|
*/
|
|
|
|
static int __init apc_setup(char *str)
|
|
|
|
{
|
|
|
|
if(!strncmp(str, "noidle", strlen("noidle"))) {
|
|
|
|
apc_no_idle = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
__setup("apc=", apc_setup);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CPU idle callback function
|
|
|
|
* See .../arch/sparc/kernel/process.c
|
|
|
|
*/
|
2008-06-06 02:40:58 +08:00
|
|
|
static void apc_swift_idle(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
#ifdef APC_DEBUG_LED
|
|
|
|
set_auxio(0x00, AUXIO_LED);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
apc_writeb(apc_readb(APC_IDLE_REG) | APC_IDLE_ON, APC_IDLE_REG);
|
|
|
|
|
|
|
|
#ifdef APC_DEBUG_LED
|
|
|
|
set_auxio(AUXIO_LED, 0x00);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-07-23 06:04:30 +08:00
|
|
|
static inline void apc_free(struct platform_device *op)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-08-27 17:45:36 +08:00
|
|
|
of_iounmap(&op->resource[0], regs, resource_size(&op->resource[0]));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int apc_open(struct inode *inode, struct file *f)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int apc_release(struct inode *inode, struct file *f)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-15 13:12:29 +08:00
|
|
|
static long apc_ioctl(struct file *f, unsigned int cmd, unsigned long __arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-11-03 13:15:59 +08:00
|
|
|
__u8 inarg, __user *arg = (__u8 __user *) __arg;
|
2008-07-15 13:12:29 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case APCIOCGFANCTL:
|
2009-11-03 13:15:59 +08:00
|
|
|
if (put_user(apc_readb(APC_FANCTL_REG) & APC_REGMASK, arg))
|
2008-07-15 13:12:29 +08:00
|
|
|
return -EFAULT;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case APCIOCGCPWR:
|
2009-11-03 13:15:59 +08:00
|
|
|
if (put_user(apc_readb(APC_CPOWER_REG) & APC_REGMASK, arg))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EFAULT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APCIOCGBPORT:
|
2009-11-03 13:15:59 +08:00
|
|
|
if (put_user(apc_readb(APC_BPORT_REG) & APC_BPMASK, arg))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EFAULT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APCIOCSFANCTL:
|
2009-11-03 13:15:59 +08:00
|
|
|
if (get_user(inarg, arg))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EFAULT;
|
|
|
|
apc_writeb(inarg & APC_REGMASK, APC_FANCTL_REG);
|
|
|
|
break;
|
2009-11-03 13:15:59 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
case APCIOCSCPWR:
|
2009-11-03 13:15:59 +08:00
|
|
|
if (get_user(inarg, arg))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EFAULT;
|
|
|
|
apc_writeb(inarg & APC_REGMASK, APC_CPOWER_REG);
|
|
|
|
break;
|
2009-11-03 13:15:59 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
case APCIOCSBPORT:
|
2009-11-03 13:15:59 +08:00
|
|
|
if (get_user(inarg, arg))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EFAULT;
|
|
|
|
apc_writeb(inarg & APC_BPMASK, APC_BPORT_REG);
|
|
|
|
break;
|
2009-11-03 13:15:59 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2011-06-03 22:45:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-12 16:55:31 +08:00
|
|
|
static const struct file_operations apc_fops = {
|
2008-07-15 13:12:29 +08:00
|
|
|
.unlocked_ioctl = apc_ioctl,
|
|
|
|
.open = apc_open,
|
|
|
|
.release = apc_release,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-16 00:52:59 +08:00
|
|
|
.llseek = noop_llseek,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice apc_miscdev = { APC_MINOR, APC_DEVNAME, &apc_fops };
|
|
|
|
|
2012-12-22 06:03:26 +08:00
|
|
|
static int apc_probe(struct platform_device *op)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-08-27 17:45:36 +08:00
|
|
|
int err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-27 17:45:36 +08:00
|
|
|
regs = of_ioremap(&op->resource[0], 0,
|
|
|
|
resource_size(&op->resource[0]), APC_OBPNAME);
|
|
|
|
if (!regs) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "%s: unable to map registers\n", APC_DEVNAME);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2008-08-27 17:45:36 +08:00
|
|
|
err = misc_register(&apc_miscdev);
|
|
|
|
if (err) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "%s: unable to register device\n", APC_DEVNAME);
|
2008-08-27 17:45:36 +08:00
|
|
|
apc_free(op);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assign power management IDLE handler */
|
2008-08-27 17:45:36 +08:00
|
|
|
if (!apc_no_idle)
|
2013-02-10 12:27:26 +08:00
|
|
|
sparc_idle = apc_swift_idle;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
printk(KERN_INFO "%s: power management initialized%s\n",
|
2008-08-27 17:45:36 +08:00
|
|
|
APC_DEVNAME, apc_no_idle ? " (CPU idle disabled)" : "");
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
sparc32: fix section mismatch warnings in apc, pmc and time_32
In all cases there were a struct of_device_id variable defined __initdata.
But it was referenced from struct platform_driver.of_match_table
which is not guaranteed to be used during init only.
So drop the __initdata annotation.
This fixes following warnings:
WARNING: arch/sparc/kernel/built-in.o(.data+0x810): Section mismatch in reference from the variable clock_driver to the variable .init.data:clock_match
The variable clock_driver references
the variable __initdata clock_match
If the reference is valid then annotate the
variable with __init* or __refdata (see linux/init.h) or name the variable:
*_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console
WARNING: arch/sparc/kernel/built-in.o(.data+0xcec): Section mismatch in reference from the variable apc_driver to the variable .init.data:apc_match
The variable apc_driver references
the variable __initdata apc_match
If the reference is valid then annotate the
variable with __init* or __refdata (see linux/init.h) or name the variable:
*_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console
WARNING: arch/sparc/kernel/built-in.o(.data+0xd60): Section mismatch in reference from the variable pmc_driver to the variable .init.data:pmc_match
The variable pmc_driver references
the variable __initdata pmc_match
If the reference is valid then annotate the
variable with __init* or __refdata (see linux/init.h) or name the variable:
*_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-04-22 06:37:20 +08:00
|
|
|
static struct of_device_id apc_match[] = {
|
2008-08-27 17:45:36 +08:00
|
|
|
{
|
|
|
|
.name = APC_OBPNAME,
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, apc_match);
|
|
|
|
|
2011-02-23 11:01:33 +08:00
|
|
|
static struct platform_driver apc_driver = {
|
2010-04-14 07:13:02 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "apc",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.of_match_table = apc_match,
|
|
|
|
},
|
2008-08-27 17:45:36 +08:00
|
|
|
.probe = apc_probe,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init apc_init(void)
|
|
|
|
{
|
2011-02-23 11:01:33 +08:00
|
|
|
return platform_driver_register(&apc_driver);
|
2008-08-27 17:45:36 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* This driver is not critical to the boot process
|
|
|
|
* and is easiest to ioremap when SBus is already
|
|
|
|
* initialized, so we install ourselves thusly:
|
|
|
|
*/
|
2008-08-27 17:45:36 +08:00
|
|
|
__initcall(apc_init);
|