2005-04-16 18:20:36 -04:00
|
|
|
/*
|
|
|
|
* linux/drivers/input/serio/pcips2.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Russell King, All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License.
|
|
|
|
*
|
|
|
|
* I'm not sure if this is a generic PS/2 PCI interface or specific to
|
|
|
|
* the Mobility Electronics docking station.
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/pci.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 04:04:11 -04:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/serio.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
#define PS2_CTRL (0)
|
|
|
|
#define PS2_STATUS (1)
|
|
|
|
#define PS2_DATA (2)
|
|
|
|
|
|
|
|
#define PS2_CTRL_CLK (1<<0)
|
|
|
|
#define PS2_CTRL_DAT (1<<1)
|
|
|
|
#define PS2_CTRL_TXIRQ (1<<2)
|
|
|
|
#define PS2_CTRL_ENABLE (1<<3)
|
|
|
|
#define PS2_CTRL_RXIRQ (1<<4)
|
|
|
|
|
|
|
|
#define PS2_STAT_CLK (1<<0)
|
|
|
|
#define PS2_STAT_DAT (1<<1)
|
|
|
|
#define PS2_STAT_PARITY (1<<2)
|
|
|
|
#define PS2_STAT_RXFULL (1<<5)
|
|
|
|
#define PS2_STAT_TXBUSY (1<<6)
|
|
|
|
#define PS2_STAT_TXEMPTY (1<<7)
|
|
|
|
|
|
|
|
struct pcips2_data {
|
|
|
|
struct serio *io;
|
|
|
|
unsigned int base;
|
|
|
|
struct pci_dev *dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int pcips2_write(struct serio *io, unsigned char val)
|
|
|
|
{
|
|
|
|
struct pcips2_data *ps2if = io->port_data;
|
|
|
|
unsigned int stat;
|
|
|
|
|
|
|
|
do {
|
|
|
|
stat = inb(ps2if->base + PS2_STATUS);
|
|
|
|
cpu_relax();
|
|
|
|
} while (!(stat & PS2_STAT_TXEMPTY));
|
|
|
|
|
|
|
|
outb(val, ps2if->base + PS2_DATA);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 09:55:46 -04:00
|
|
|
static irqreturn_t pcips2_interrupt(int irq, void *devid)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
struct pcips2_data *ps2if = devid;
|
|
|
|
unsigned char status, scancode;
|
|
|
|
int handled = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
unsigned int flag;
|
|
|
|
|
|
|
|
status = inb(ps2if->base + PS2_STATUS);
|
|
|
|
if (!(status & PS2_STAT_RXFULL))
|
|
|
|
break;
|
|
|
|
handled = 1;
|
|
|
|
scancode = inb(ps2if->base + PS2_DATA);
|
|
|
|
if (status == 0xff && scancode == 0xff)
|
|
|
|
break;
|
|
|
|
|
|
|
|
flag = (status & PS2_STAT_PARITY) ? 0 : SERIO_PARITY;
|
|
|
|
|
|
|
|
if (hweight8(scancode) & 1)
|
|
|
|
flag ^= SERIO_PARITY;
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 09:55:46 -04:00
|
|
|
serio_interrupt(ps2if->io, scancode, flag);
|
2005-04-16 18:20:36 -04:00
|
|
|
} while (1);
|
|
|
|
return IRQ_RETVAL(handled);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcips2_flush_input(struct pcips2_data *ps2if)
|
|
|
|
{
|
|
|
|
unsigned char status, scancode;
|
|
|
|
|
|
|
|
do {
|
|
|
|
status = inb(ps2if->base + PS2_STATUS);
|
|
|
|
if (!(status & PS2_STAT_RXFULL))
|
|
|
|
break;
|
|
|
|
scancode = inb(ps2if->base + PS2_DATA);
|
|
|
|
if (status == 0xff && scancode == 0xff)
|
|
|
|
break;
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcips2_open(struct serio *io)
|
|
|
|
{
|
|
|
|
struct pcips2_data *ps2if = io->port_data;
|
|
|
|
int ret, val = 0;
|
|
|
|
|
|
|
|
outb(PS2_CTRL_ENABLE, ps2if->base);
|
|
|
|
pcips2_flush_input(ps2if);
|
|
|
|
|
2006-07-01 22:29:38 -04:00
|
|
|
ret = request_irq(ps2if->dev->irq, pcips2_interrupt, IRQF_SHARED,
|
2005-04-16 18:20:36 -04:00
|
|
|
"pcips2", ps2if);
|
|
|
|
if (ret == 0)
|
|
|
|
val = PS2_CTRL_ENABLE | PS2_CTRL_RXIRQ;
|
|
|
|
|
|
|
|
outb(val, ps2if->base);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcips2_close(struct serio *io)
|
|
|
|
{
|
|
|
|
struct pcips2_data *ps2if = io->port_data;
|
|
|
|
|
|
|
|
outb(0, ps2if->base);
|
|
|
|
|
|
|
|
free_irq(ps2if->dev->irq, ps2if);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devinit pcips2_probe(struct pci_dev *dev, const struct pci_device_id *id)
|
|
|
|
{
|
|
|
|
struct pcips2_data *ps2if;
|
|
|
|
struct serio *serio;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pci_enable_device(dev);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = pci_request_regions(dev, "pcips2");
|
|
|
|
if (ret)
|
|
|
|
goto disable;
|
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 04:49:03 -04:00
|
|
|
ps2if = kzalloc(sizeof(struct pcips2_data), GFP_KERNEL);
|
|
|
|
serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
|
2005-04-16 18:20:36 -04:00
|
|
|
if (!ps2if || !serio) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
serio->id.type = SERIO_8042;
|
|
|
|
serio->write = pcips2_write;
|
|
|
|
serio->open = pcips2_open;
|
|
|
|
serio->close = pcips2_close;
|
|
|
|
strlcpy(serio->name, pci_name(dev), sizeof(serio->name));
|
2008-10-30 00:07:50 -04:00
|
|
|
strlcpy(serio->phys, dev_name(&dev->dev), sizeof(serio->phys));
|
2005-04-16 18:20:36 -04:00
|
|
|
serio->port_data = ps2if;
|
|
|
|
serio->dev.parent = &dev->dev;
|
|
|
|
ps2if->io = serio;
|
|
|
|
ps2if->dev = dev;
|
|
|
|
ps2if->base = pci_resource_start(dev, 0);
|
|
|
|
|
|
|
|
pci_set_drvdata(dev, ps2if);
|
|
|
|
|
|
|
|
serio_register_port(ps2if->io);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
release:
|
|
|
|
kfree(ps2if);
|
|
|
|
kfree(serio);
|
|
|
|
pci_release_regions(dev);
|
|
|
|
disable:
|
|
|
|
pci_disable_device(dev);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __devexit pcips2_remove(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
struct pcips2_data *ps2if = pci_get_drvdata(dev);
|
|
|
|
|
|
|
|
serio_unregister_port(ps2if->io);
|
|
|
|
pci_set_drvdata(dev, NULL);
|
|
|
|
kfree(ps2if);
|
|
|
|
pci_release_regions(dev);
|
|
|
|
pci_disable_device(dev);
|
|
|
|
}
|
|
|
|
|
2010-01-10 02:23:58 -05:00
|
|
|
static const struct pci_device_id pcips2_ids[] = {
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
.vendor = 0x14f2, /* MOBILITY */
|
|
|
|
.device = 0x0123, /* Keyboard */
|
|
|
|
.subvendor = PCI_ANY_ID,
|
|
|
|
.subdevice = PCI_ANY_ID,
|
|
|
|
.class = PCI_CLASS_INPUT_KEYBOARD << 8,
|
|
|
|
.class_mask = 0xffff00,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.vendor = 0x14f2, /* MOBILITY */
|
|
|
|
.device = 0x0124, /* Mouse */
|
|
|
|
.subvendor = PCI_ANY_ID,
|
|
|
|
.subdevice = PCI_ANY_ID,
|
|
|
|
.class = PCI_CLASS_INPUT_MOUSE << 8,
|
|
|
|
.class_mask = 0xffff00,
|
|
|
|
},
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_driver pcips2_driver = {
|
|
|
|
.name = "pcips2",
|
|
|
|
.id_table = pcips2_ids,
|
|
|
|
.probe = pcips2_probe,
|
|
|
|
.remove = __devexit_p(pcips2_remove),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init pcips2_init(void)
|
|
|
|
{
|
|
|
|
return pci_register_driver(&pcips2_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit pcips2_exit(void)
|
|
|
|
{
|
|
|
|
pci_unregister_driver(&pcips2_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(pcips2_init);
|
|
|
|
module_exit(pcips2_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
|
|
|
|
MODULE_DESCRIPTION("PCI PS/2 keyboard/mouse driver");
|
|
|
|
MODULE_DEVICE_TABLE(pci, pcips2_ids);
|