2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/drivers/input/serio/ambakmi.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000-2003 Deep Blue Solutions Ltd.
|
|
|
|
* Copyright (C) 2002 Russell King.
|
|
|
|
*
|
|
|
|
* 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, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/serio.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/err.h>
|
2006-01-07 21:52:45 +08:00
|
|
|
#include <linux/amba/bus.h>
|
|
|
|
#include <linux/amba/kmi.h>
|
2006-01-08 00:15:52 +08:00
|
|
|
#include <linux/clk.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
|
|
|
|
#define KMI_BASE (kmi->base)
|
|
|
|
|
|
|
|
struct amba_kmi_port {
|
|
|
|
struct serio *io;
|
|
|
|
struct clk *clk;
|
|
|
|
void __iomem *base;
|
|
|
|
unsigned int irq;
|
|
|
|
unsigned int divisor;
|
|
|
|
unsigned int open;
|
|
|
|
};
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static irqreturn_t amba_kmi_int(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct amba_kmi_port *kmi = dev_id;
|
|
|
|
unsigned int status = readb(KMIIR);
|
|
|
|
int handled = IRQ_NONE;
|
|
|
|
|
|
|
|
while (status & KMIIR_RXINTR) {
|
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 21:55:46 +08:00
|
|
|
serio_interrupt(kmi->io, readb(KMIDATA), 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
status = readb(KMIIR);
|
|
|
|
handled = IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int amba_kmi_write(struct serio *io, unsigned char val)
|
|
|
|
{
|
|
|
|
struct amba_kmi_port *kmi = io->port_data;
|
|
|
|
unsigned int timeleft = 10000; /* timeout in 100ms */
|
|
|
|
|
2009-02-02 08:55:45 +08:00
|
|
|
while ((readb(KMISTAT) & KMISTAT_TXEMPTY) == 0 && --timeleft)
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(10);
|
|
|
|
|
|
|
|
if (timeleft)
|
|
|
|
writeb(val, KMIDATA);
|
|
|
|
|
|
|
|
return timeleft ? 0 : SERIO_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int amba_kmi_open(struct serio *io)
|
|
|
|
{
|
|
|
|
struct amba_kmi_port *kmi = io->port_data;
|
|
|
|
unsigned int divisor;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = clk_enable(kmi->clk);
|
|
|
|
if (ret)
|
2006-01-04 02:41:37 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
divisor = clk_get_rate(kmi->clk) / 8000000 - 1;
|
|
|
|
writeb(divisor, KMICLKDIV);
|
|
|
|
writeb(KMICR_EN, KMICR);
|
|
|
|
|
|
|
|
ret = request_irq(kmi->irq, amba_kmi_int, 0, "kmi-pl050", kmi);
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_ERR "kmi: failed to claim IRQ%d\n", kmi->irq);
|
|
|
|
writeb(0, KMICR);
|
|
|
|
goto clk_disable;
|
|
|
|
}
|
|
|
|
|
|
|
|
writeb(KMICR_EN | KMICR_RXINTREN, KMICR);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
clk_disable:
|
|
|
|
clk_disable(kmi->clk);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void amba_kmi_close(struct serio *io)
|
|
|
|
{
|
|
|
|
struct amba_kmi_port *kmi = io->port_data;
|
|
|
|
|
|
|
|
writeb(0, KMICR);
|
|
|
|
|
|
|
|
free_irq(kmi->irq, kmi);
|
|
|
|
clk_disable(kmi->clk);
|
|
|
|
}
|
|
|
|
|
2011-02-19 23:55:00 +08:00
|
|
|
static int __devinit amba_kmi_probe(struct amba_device *dev,
|
|
|
|
const struct amba_id *id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct amba_kmi_port *kmi;
|
|
|
|
struct serio *io;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = amba_request_regions(dev, NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
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 16:49:03 +08:00
|
|
|
kmi = kzalloc(sizeof(struct amba_kmi_port), GFP_KERNEL);
|
|
|
|
io = kzalloc(sizeof(struct serio), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!kmi || !io) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
io->id.type = SERIO_8042;
|
|
|
|
io->write = amba_kmi_write;
|
|
|
|
io->open = amba_kmi_open;
|
|
|
|
io->close = amba_kmi_close;
|
2009-01-30 14:56:08 +08:00
|
|
|
strlcpy(io->name, dev_name(&dev->dev), sizeof(io->name));
|
|
|
|
strlcpy(io->phys, dev_name(&dev->dev), sizeof(io->phys));
|
2005-04-17 06:20:36 +08:00
|
|
|
io->port_data = kmi;
|
|
|
|
io->dev.parent = &dev->dev;
|
|
|
|
|
2009-12-12 13:50:47 +08:00
|
|
|
kmi->io = io;
|
2009-06-08 06:27:31 +08:00
|
|
|
kmi->base = ioremap(dev->res.start, resource_size(&dev->res));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!kmi->base) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
kmi->clk = clk_get(&dev->dev, "KMIREFCLK");
|
|
|
|
if (IS_ERR(kmi->clk)) {
|
|
|
|
ret = PTR_ERR(kmi->clk);
|
|
|
|
goto unmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
kmi->irq = dev->irq[0];
|
|
|
|
amba_set_drvdata(dev, kmi);
|
|
|
|
|
|
|
|
serio_register_port(kmi->io);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unmap:
|
|
|
|
iounmap(kmi->base);
|
|
|
|
out:
|
|
|
|
kfree(kmi);
|
|
|
|
kfree(io);
|
|
|
|
amba_release_regions(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-12 13:50:47 +08:00
|
|
|
static int __devexit amba_kmi_remove(struct amba_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct amba_kmi_port *kmi = amba_get_drvdata(dev);
|
|
|
|
|
|
|
|
amba_set_drvdata(dev, NULL);
|
|
|
|
|
|
|
|
serio_unregister_port(kmi->io);
|
|
|
|
clk_put(kmi->clk);
|
|
|
|
iounmap(kmi->base);
|
|
|
|
kfree(kmi);
|
|
|
|
amba_release_regions(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int amba_kmi_resume(struct amba_device *dev)
|
|
|
|
{
|
|
|
|
struct amba_kmi_port *kmi = amba_get_drvdata(dev);
|
|
|
|
|
|
|
|
/* kick the serio layer to rescan this port */
|
|
|
|
serio_reconnect(kmi->io);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct amba_id amba_kmi_idtable[] = {
|
|
|
|
{
|
|
|
|
.id = 0x00041050,
|
|
|
|
.mask = 0x000fffff,
|
|
|
|
},
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
2011-10-05 22:15:21 +08:00
|
|
|
MODULE_DEVICE_TABLE(amba, amba_kmi_idtable);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct amba_driver ambakmi_driver = {
|
|
|
|
.drv = {
|
|
|
|
.name = "kmi-pl050",
|
2009-12-12 13:10:18 +08:00
|
|
|
.owner = THIS_MODULE,
|
2005-04-17 06:20:36 +08:00
|
|
|
},
|
|
|
|
.id_table = amba_kmi_idtable,
|
|
|
|
.probe = amba_kmi_probe,
|
2009-12-12 13:50:47 +08:00
|
|
|
.remove = __devexit_p(amba_kmi_remove),
|
2005-04-17 06:20:36 +08:00
|
|
|
.resume = amba_kmi_resume,
|
|
|
|
};
|
|
|
|
|
2012-03-15 17:40:38 +08:00
|
|
|
module_amba_driver(ambakmi_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
|
|
|
|
MODULE_DESCRIPTION("AMBA KMI controller driver");
|
|
|
|
MODULE_LICENSE("GPL");
|