2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/drivers/input/serio/sa1111ps2.c
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/serio.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
#include <asm/hardware/sa1111.h>
|
|
|
|
|
2012-01-16 19:29:43 +08:00
|
|
|
#define PS2CR 0x0000
|
|
|
|
#define PS2STAT 0x0004
|
|
|
|
#define PS2DATA 0x0008
|
|
|
|
#define PS2CLKDIV 0x000c
|
|
|
|
#define PS2PRECNT 0x0010
|
|
|
|
|
|
|
|
#define PS2CR_ENA 0x08
|
|
|
|
#define PS2CR_FKD 0x02
|
|
|
|
#define PS2CR_FKC 0x01
|
|
|
|
|
|
|
|
#define PS2STAT_STP 0x0100
|
|
|
|
#define PS2STAT_TXE 0x0080
|
|
|
|
#define PS2STAT_TXB 0x0040
|
|
|
|
#define PS2STAT_RXF 0x0020
|
|
|
|
#define PS2STAT_RXB 0x0010
|
|
|
|
#define PS2STAT_ENA 0x0008
|
|
|
|
#define PS2STAT_RXP 0x0004
|
|
|
|
#define PS2STAT_KBD 0x0002
|
|
|
|
#define PS2STAT_KBC 0x0001
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ps2if {
|
|
|
|
struct serio *io;
|
|
|
|
struct sa1111_dev *dev;
|
|
|
|
void __iomem *base;
|
2017-09-27 00:56:23 +08:00
|
|
|
int rx_irq;
|
|
|
|
int tx_irq;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int open;
|
|
|
|
spinlock_t lock;
|
|
|
|
unsigned int head;
|
|
|
|
unsigned int tail;
|
|
|
|
unsigned char buf[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read all bytes waiting in the PS2 port. There should be
|
|
|
|
* at the most one, but we loop for safety. If there was a
|
|
|
|
* framing error, we have to manually clear the status.
|
|
|
|
*/
|
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 ps2_rxint(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ps2if *ps2if = dev_id;
|
|
|
|
unsigned int scancode, flag, status;
|
|
|
|
|
2017-09-27 00:56:56 +08:00
|
|
|
status = readl_relaxed(ps2if->base + PS2STAT);
|
2005-04-17 06:20:36 +08:00
|
|
|
while (status & PS2STAT_RXF) {
|
|
|
|
if (status & PS2STAT_STP)
|
2017-09-27 00:56:56 +08:00
|
|
|
writel_relaxed(PS2STAT_STP, ps2if->base + PS2STAT);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
flag = (status & PS2STAT_STP ? SERIO_FRAME : 0) |
|
|
|
|
(status & PS2STAT_RXP ? 0 : SERIO_PARITY);
|
|
|
|
|
2017-09-27 00:56:56 +08:00
|
|
|
scancode = readl_relaxed(ps2if->base + PS2DATA) & 0xff;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
serio_interrupt(ps2if->io, scancode, flag);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-09-27 00:56:56 +08:00
|
|
|
status = readl_relaxed(ps2if->base + PS2STAT);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Completion of ps2 write
|
|
|
|
*/
|
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 ps2_txint(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ps2if *ps2if = dev_id;
|
|
|
|
unsigned int status;
|
|
|
|
|
|
|
|
spin_lock(&ps2if->lock);
|
2017-09-27 00:56:56 +08:00
|
|
|
status = readl_relaxed(ps2if->base + PS2STAT);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ps2if->head == ps2if->tail) {
|
2009-04-18 11:35:57 +08:00
|
|
|
disable_irq_nosync(irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* done */
|
|
|
|
} else if (status & PS2STAT_TXE) {
|
2017-09-27 00:56:56 +08:00
|
|
|
writel_relaxed(ps2if->buf[ps2if->tail], ps2if->base + PS2DATA);
|
2005-04-17 06:20:36 +08:00
|
|
|
ps2if->tail = (ps2if->tail + 1) & (sizeof(ps2if->buf) - 1);
|
|
|
|
}
|
|
|
|
spin_unlock(&ps2if->lock);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write a byte to the PS2 port. We have to wait for the
|
|
|
|
* port to indicate that the transmitter is empty.
|
|
|
|
*/
|
|
|
|
static int ps2_write(struct serio *io, unsigned char val)
|
|
|
|
{
|
|
|
|
struct ps2if *ps2if = io->port_data;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int head;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ps2if->lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the TX register is empty, we can go straight out.
|
|
|
|
*/
|
2017-09-27 00:56:56 +08:00
|
|
|
if (readl_relaxed(ps2if->base + PS2STAT) & PS2STAT_TXE) {
|
|
|
|
writel_relaxed(val, ps2if->base + PS2DATA);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
if (ps2if->head == ps2if->tail)
|
2017-09-27 00:56:23 +08:00
|
|
|
enable_irq(ps2if->tx_irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
head = (ps2if->head + 1) & (sizeof(ps2if->buf) - 1);
|
|
|
|
if (head != ps2if->tail) {
|
|
|
|
ps2if->buf[ps2if->head] = val;
|
|
|
|
ps2if->head = head;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&ps2if->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ps2_open(struct serio *io)
|
|
|
|
{
|
|
|
|
struct ps2if *ps2if = io->port_data;
|
|
|
|
int ret;
|
|
|
|
|
2012-01-26 21:25:47 +08:00
|
|
|
ret = sa1111_enable_device(ps2if->dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-09-27 00:56:23 +08:00
|
|
|
ret = request_irq(ps2if->rx_irq, ps2_rxint, 0,
|
2005-04-17 06:20:36 +08:00
|
|
|
SA1111_DRIVER_NAME(ps2if->dev), ps2if);
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_ERR "sa1111ps2: could not allocate IRQ%d: %d\n",
|
2017-09-27 00:56:23 +08:00
|
|
|
ps2if->rx_irq, ret);
|
2012-01-26 21:25:47 +08:00
|
|
|
sa1111_disable_device(ps2if->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-27 00:56:23 +08:00
|
|
|
ret = request_irq(ps2if->tx_irq, ps2_txint, 0,
|
2005-04-17 06:20:36 +08:00
|
|
|
SA1111_DRIVER_NAME(ps2if->dev), ps2if);
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_ERR "sa1111ps2: could not allocate IRQ%d: %d\n",
|
2017-09-27 00:56:23 +08:00
|
|
|
ps2if->tx_irq, ret);
|
|
|
|
free_irq(ps2if->rx_irq, ps2if);
|
2012-01-26 21:25:47 +08:00
|
|
|
sa1111_disable_device(ps2if->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps2if->open = 1;
|
|
|
|
|
2017-09-27 00:56:23 +08:00
|
|
|
enable_irq_wake(ps2if->rx_irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-09-27 00:56:56 +08:00
|
|
|
writel_relaxed(PS2CR_ENA, ps2if->base + PS2CR);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ps2_close(struct serio *io)
|
|
|
|
{
|
|
|
|
struct ps2if *ps2if = io->port_data;
|
|
|
|
|
2017-09-27 00:56:56 +08:00
|
|
|
writel_relaxed(0, ps2if->base + PS2CR);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-09-27 00:56:23 +08:00
|
|
|
disable_irq_wake(ps2if->rx_irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ps2if->open = 0;
|
|
|
|
|
2017-09-27 00:56:23 +08:00
|
|
|
free_irq(ps2if->tx_irq, ps2if);
|
|
|
|
free_irq(ps2if->rx_irq, ps2if);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
sa1111_disable_device(ps2if->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the input buffer.
|
|
|
|
*/
|
2012-11-24 13:38:25 +08:00
|
|
|
static void ps2_clear_input(struct ps2if *ps2if)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int maxread = 100;
|
|
|
|
|
|
|
|
while (maxread--) {
|
2017-09-27 00:56:56 +08:00
|
|
|
if ((readl_relaxed(ps2if->base + PS2DATA) & 0xff) == 0xff)
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-24 13:38:25 +08:00
|
|
|
static unsigned int ps2_test_one(struct ps2if *ps2if,
|
2009-12-12 13:57:04 +08:00
|
|
|
unsigned int mask)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
|
2017-09-27 00:56:56 +08:00
|
|
|
writel_relaxed(PS2CR_ENA | mask, ps2if->base + PS2CR);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-09-27 00:57:12 +08:00
|
|
|
udelay(10);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-09-27 00:56:56 +08:00
|
|
|
val = readl_relaxed(ps2if->base + PS2STAT);
|
2005-04-17 06:20:36 +08:00
|
|
|
return val & (PS2STAT_KBC | PS2STAT_KBD);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the keyboard interface. We basically check to make sure that
|
|
|
|
* we can drive each line to the keyboard independently of each other.
|
|
|
|
*/
|
2012-11-24 13:38:25 +08:00
|
|
|
static int ps2_test(struct ps2if *ps2if)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned int stat;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
stat = ps2_test_one(ps2if, PS2CR_FKC);
|
|
|
|
if (stat != PS2STAT_KBD) {
|
|
|
|
printk("PS/2 interface test failed[1]: %02x\n", stat);
|
|
|
|
ret = -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
stat = ps2_test_one(ps2if, 0);
|
|
|
|
if (stat != (PS2STAT_KBC | PS2STAT_KBD)) {
|
|
|
|
printk("PS/2 interface test failed[2]: %02x\n", stat);
|
|
|
|
ret = -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
stat = ps2_test_one(ps2if, PS2CR_FKD);
|
|
|
|
if (stat != PS2STAT_KBC) {
|
|
|
|
printk("PS/2 interface test failed[3]: %02x\n", stat);
|
|
|
|
ret = -ENODEV;
|
|
|
|
}
|
|
|
|
|
2017-09-27 00:56:56 +08:00
|
|
|
writel_relaxed(0, ps2if->base + PS2CR);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add one device to this driver.
|
|
|
|
*/
|
2012-11-24 13:38:25 +08:00
|
|
|
static int ps2_probe(struct sa1111_dev *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ps2if *ps2if;
|
|
|
|
struct serio *serio;
|
|
|
|
int 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
|
|
|
ps2if = kzalloc(sizeof(struct ps2if), GFP_KERNEL);
|
|
|
|
serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ps2if || !serio) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
|
|
|
serio->id.type = SERIO_8042;
|
|
|
|
serio->write = ps2_write;
|
|
|
|
serio->open = ps2_open;
|
|
|
|
serio->close = ps2_close;
|
2009-01-30 14:56:08 +08:00
|
|
|
strlcpy(serio->name, dev_name(&dev->dev), sizeof(serio->name));
|
|
|
|
strlcpy(serio->phys, dev_name(&dev->dev), sizeof(serio->phys));
|
2005-04-17 06:20:36 +08:00
|
|
|
serio->port_data = ps2if;
|
|
|
|
serio->dev.parent = &dev->dev;
|
|
|
|
ps2if->io = serio;
|
|
|
|
ps2if->dev = dev;
|
|
|
|
sa1111_set_drvdata(dev, ps2if);
|
|
|
|
|
|
|
|
spin_lock_init(&ps2if->lock);
|
|
|
|
|
2017-09-27 00:56:23 +08:00
|
|
|
ps2if->rx_irq = sa1111_get_irq(dev, 0);
|
|
|
|
if (ps2if->rx_irq <= 0) {
|
|
|
|
ret = ps2if->rx_irq ? : -ENXIO;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps2if->tx_irq = sa1111_get_irq(dev, 1);
|
|
|
|
if (ps2if->tx_irq <= 0) {
|
|
|
|
ret = ps2if->tx_irq ? : -ENXIO;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Request the physical region for this PS2 port.
|
|
|
|
*/
|
|
|
|
if (!request_mem_region(dev->res.start,
|
|
|
|
dev->res.end - dev->res.start + 1,
|
|
|
|
SA1111_DRIVER_NAME(dev))) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our parent device has already mapped the region.
|
|
|
|
*/
|
|
|
|
ps2if->base = dev->mapbase;
|
|
|
|
|
|
|
|
sa1111_enable_device(ps2if->dev);
|
|
|
|
|
|
|
|
/* Incoming clock is 8MHz */
|
2017-09-27 00:56:56 +08:00
|
|
|
writel_relaxed(0, ps2if->base + PS2CLKDIV);
|
|
|
|
writel_relaxed(127, ps2if->base + PS2PRECNT);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush any pending input.
|
|
|
|
*/
|
|
|
|
ps2_clear_input(ps2if);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the keyboard interface.
|
|
|
|
*/
|
|
|
|
ret = ps2_test(ps2if);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush any pending input.
|
|
|
|
*/
|
|
|
|
ps2_clear_input(ps2if);
|
|
|
|
|
|
|
|
sa1111_disable_device(ps2if->dev);
|
|
|
|
serio_register_port(ps2if->io);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
sa1111_disable_device(ps2if->dev);
|
2011-06-10 00:13:32 +08:00
|
|
|
release_mem_region(dev->res.start, resource_size(&dev->res));
|
2005-04-17 06:20:36 +08:00
|
|
|
free:
|
|
|
|
sa1111_set_drvdata(dev, NULL);
|
|
|
|
kfree(ps2if);
|
|
|
|
kfree(serio);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove one device from this driver.
|
|
|
|
*/
|
2012-11-24 13:50:47 +08:00
|
|
|
static int ps2_remove(struct sa1111_dev *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ps2if *ps2if = sa1111_get_drvdata(dev);
|
|
|
|
|
|
|
|
serio_unregister_port(ps2if->io);
|
2011-06-10 00:13:32 +08:00
|
|
|
release_mem_region(dev->res.start, resource_size(&dev->res));
|
2005-04-17 06:20:36 +08:00
|
|
|
sa1111_set_drvdata(dev, NULL);
|
|
|
|
|
|
|
|
kfree(ps2if);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our device driver structure
|
|
|
|
*/
|
|
|
|
static struct sa1111_driver ps2_driver = {
|
|
|
|
.drv = {
|
|
|
|
.name = "sa1111-ps2",
|
2012-01-26 19:19:48 +08:00
|
|
|
.owner = THIS_MODULE,
|
2005-04-17 06:20:36 +08:00
|
|
|
},
|
|
|
|
.devid = SA1111_DEVID_PS2,
|
|
|
|
.probe = ps2_probe,
|
2012-11-24 13:27:39 +08:00
|
|
|
.remove = ps2_remove,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ps2_init(void)
|
|
|
|
{
|
|
|
|
return sa1111_driver_register(&ps2_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit ps2_exit(void)
|
|
|
|
{
|
|
|
|
sa1111_driver_unregister(&ps2_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ps2_init);
|
|
|
|
module_exit(ps2_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
|
|
|
|
MODULE_DESCRIPTION("SA1111 PS2 controller driver");
|
|
|
|
MODULE_LICENSE("GPL");
|