2005-04-17 05:20:36 +07:00
|
|
|
/*
|
2008-04-02 11:42:42 +07:00
|
|
|
* LoCoMo keyboard driver for Linux-based ARM PDAs:
|
|
|
|
* - SHARP Zaurus Collie (SL-5500)
|
|
|
|
* - SHARP Zaurus Poodle (SL-5600)
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2008-04-02 11:42:42 +07:00
|
|
|
* Copyright (c) 2005 John Lenz
|
2005-04-17 05:20:36 +07:00
|
|
|
* Based on from xtkbd.c
|
2008-04-02 11:42:42 +07:00
|
|
|
*
|
|
|
|
*
|
2005-04-17 05:20:36 +07:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
|
|
|
|
#include <asm/hardware/locomo.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
|
|
|
|
MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
|
|
|
|
MODULE_DESCRIPTION("LoCoMo keyboard driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2005-05-29 14:28:42 +07:00
|
|
|
#define LOCOMOKBD_NUMKEYS 128
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#define KEY_ACTIVITY KEY_F16
|
|
|
|
#define KEY_CONTACT KEY_F18
|
|
|
|
#define KEY_CENTER KEY_F15
|
|
|
|
|
2008-04-02 11:42:42 +07:00
|
|
|
static const unsigned char
|
2012-11-24 12:31:00 +07:00
|
|
|
locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
|
2005-04-17 05:20:36 +07:00
|
|
|
0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0, /* 0 - 9 */
|
|
|
|
0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT, /* 10 - 19 */
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 29 */
|
|
|
|
0, 0, 0, KEY_CENTER, 0, KEY_MAIL, 0, 0, 0, 0, /* 30 - 39 */
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RIGHT, /* 40 - 49 */
|
|
|
|
KEY_UP, KEY_LEFT, 0, 0, KEY_P, 0, KEY_O, KEY_I, KEY_Y, KEY_T, /* 50 - 59 */
|
|
|
|
KEY_E, KEY_W, 0, 0, 0, 0, KEY_DOWN, KEY_ENTER, 0, 0, /* 60 - 69 */
|
|
|
|
KEY_BACKSPACE, 0, KEY_L, KEY_U, KEY_H, KEY_R, KEY_D, KEY_Q, 0, 0, /* 70 - 79 */
|
|
|
|
0, 0, 0, 0, 0, 0, KEY_ENTER, KEY_RIGHTSHIFT, KEY_K, KEY_J, /* 80 - 89 */
|
|
|
|
KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0, /* 90 - 99 */
|
|
|
|
0, 0, KEY_DOT, 0, KEY_COMMA, KEY_N, KEY_B, KEY_C, KEY_Z, KEY_A, /* 100 - 109 */
|
|
|
|
KEY_LEFTSHIFT, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0, 0, 0, 0, 0, /* 110 - 119 */
|
2005-05-29 14:28:42 +07:00
|
|
|
KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0 /* 120 - 128 */
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define KB_ROWS 16
|
|
|
|
#define KB_COLS 8
|
|
|
|
#define KB_ROWMASK(r) (1 << (r))
|
|
|
|
#define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 )
|
|
|
|
|
|
|
|
#define KB_DELAY 8
|
|
|
|
#define SCAN_INTERVAL (HZ/10)
|
|
|
|
|
|
|
|
struct locomokbd {
|
|
|
|
unsigned char keycode[LOCOMOKBD_NUMKEYS];
|
2005-11-03 10:49:53 +07:00
|
|
|
struct input_dev *input;
|
2005-04-17 05:20:36 +07:00
|
|
|
char phys[32];
|
|
|
|
|
|
|
|
unsigned long base;
|
|
|
|
spinlock_t lock;
|
2005-05-29 14:28:42 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
struct timer_list timer;
|
2008-04-02 11:42:42 +07:00
|
|
|
unsigned long suspend_jiffies;
|
|
|
|
unsigned int count_cancel;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* helper functions for reading the keyboard matrix */
|
|
|
|
static inline void locomokbd_charge_all(unsigned long membase)
|
|
|
|
{
|
|
|
|
locomo_writel(0x00FF, membase + LOCOMO_KSC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void locomokbd_activate_all(unsigned long membase)
|
|
|
|
{
|
|
|
|
unsigned long r;
|
2005-05-29 14:28:42 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
locomo_writel(0, membase + LOCOMO_KSC);
|
|
|
|
r = locomo_readl(membase + LOCOMO_KIC);
|
|
|
|
r &= 0xFEFF;
|
|
|
|
locomo_writel(r, membase + LOCOMO_KIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void locomokbd_activate_col(unsigned long membase, int col)
|
|
|
|
{
|
|
|
|
unsigned short nset;
|
|
|
|
unsigned short nbset;
|
|
|
|
|
|
|
|
nset = 0xFF & ~(1 << col);
|
|
|
|
nbset = (nset << 8) + nset;
|
|
|
|
locomo_writel(nbset, membase + LOCOMO_KSC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void locomokbd_reset_col(unsigned long membase, int col)
|
|
|
|
{
|
|
|
|
unsigned short nbset;
|
|
|
|
|
|
|
|
nbset = ((0xFF & ~(1 << col)) << 8) + 0xFF;
|
|
|
|
locomo_writel(nbset, membase + LOCOMO_KSC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The LoCoMo keyboard only generates interrupts when a key is pressed.
|
|
|
|
* So when a key is pressed, we enable a timer. This timer scans the
|
|
|
|
* keyboard, and this is how we detect when the key is released.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Scan the hardware keyboard and push any changes up through the input layer */
|
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 20:55:46 +07:00
|
|
|
static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-04-02 11:42:42 +07:00
|
|
|
unsigned int row, col, rowd;
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned int num_pressed;
|
|
|
|
unsigned long membase = locomokbd->base;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&locomokbd->lock, flags);
|
|
|
|
|
|
|
|
locomokbd_charge_all(membase);
|
|
|
|
|
|
|
|
num_pressed = 0;
|
|
|
|
for (col = 0; col < KB_COLS; col++) {
|
|
|
|
|
|
|
|
locomokbd_activate_col(membase, col);
|
|
|
|
udelay(KB_DELAY);
|
2005-05-29 14:28:42 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
rowd = ~locomo_readl(membase + LOCOMO_KIB);
|
2005-05-29 14:28:42 +07:00
|
|
|
for (row = 0; row < KB_ROWS; row++) {
|
2008-04-02 11:42:42 +07:00
|
|
|
unsigned int scancode, pressed, key;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
scancode = SCANCODE(col, row);
|
2008-04-02 11:42:42 +07:00
|
|
|
pressed = rowd & KB_ROWMASK(row);
|
|
|
|
key = locomokbd->keycode[scancode];
|
|
|
|
|
|
|
|
input_report_key(locomokbd->input, key, pressed);
|
|
|
|
if (likely(!pressed))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
num_pressed++;
|
|
|
|
|
|
|
|
/* The "Cancel/ESC" key is labeled "On/Off" on
|
|
|
|
* Collie and Poodle and should suspend the device
|
|
|
|
* if it was pressed for more than a second. */
|
|
|
|
if (unlikely(key == KEY_ESC)) {
|
|
|
|
if (!time_after(jiffies,
|
|
|
|
locomokbd->suspend_jiffies + HZ))
|
|
|
|
continue;
|
|
|
|
if (locomokbd->count_cancel++
|
|
|
|
!= (HZ/SCAN_INTERVAL + 1))
|
|
|
|
continue;
|
|
|
|
input_event(locomokbd->input, EV_PWR,
|
|
|
|
KEY_SUSPEND, 1);
|
|
|
|
locomokbd->suspend_jiffies = jiffies;
|
|
|
|
} else
|
|
|
|
locomokbd->count_cancel = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
locomokbd_reset_col(membase, col);
|
|
|
|
}
|
|
|
|
locomokbd_activate_all(membase);
|
|
|
|
|
2005-11-03 10:49:53 +07:00
|
|
|
input_sync(locomokbd->input);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* if any keys are pressed, enable the timer */
|
|
|
|
if (num_pressed)
|
|
|
|
mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL);
|
2008-04-02 11:42:42 +07:00
|
|
|
else
|
|
|
|
locomokbd->count_cancel = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&locomokbd->lock, flags);
|
|
|
|
}
|
|
|
|
|
2005-05-29 14:28:42 +07:00
|
|
|
/*
|
2005-04-17 05:20:36 +07:00
|
|
|
* LoCoMo keyboard interrupt handler.
|
|
|
|
*/
|
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 20:55:46 +07:00
|
|
|
static irqreturn_t locomokbd_interrupt(int irq, void *dev_id)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct locomokbd *locomokbd = dev_id;
|
2010-02-05 08:13:55 +07:00
|
|
|
u16 r;
|
|
|
|
|
|
|
|
r = locomo_readl(locomokbd->base + LOCOMO_KIC);
|
|
|
|
if ((r & 0x0001) == 0)
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
|
|
|
locomo_writel(r & ~0x0100, locomokbd->base + LOCOMO_KIC); /* Ack */
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/** wait chattering delay **/
|
|
|
|
udelay(100);
|
|
|
|
|
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 20:55:46 +07:00
|
|
|
locomokbd_scankeyboard(locomokbd);
|
2005-04-17 05:20:36 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LoCoMo timer checking for released keys
|
|
|
|
*/
|
|
|
|
static void locomokbd_timer_callback(unsigned long data)
|
|
|
|
{
|
|
|
|
struct locomokbd *locomokbd = (struct locomokbd *) data;
|
2008-04-02 11:42:42 +07:00
|
|
|
|
2006-10-15 19:50:02 +07:00
|
|
|
locomokbd_scankeyboard(locomokbd);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2010-02-05 08:13:55 +07:00
|
|
|
static int locomokbd_open(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct locomokbd *locomokbd = input_get_drvdata(dev);
|
|
|
|
u16 r;
|
|
|
|
|
|
|
|
r = locomo_readl(locomokbd->base + LOCOMO_KIC) | 0x0010;
|
|
|
|
locomo_writel(r, locomokbd->base + LOCOMO_KIC);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void locomokbd_close(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct locomokbd *locomokbd = input_get_drvdata(dev);
|
|
|
|
u16 r;
|
|
|
|
|
|
|
|
r = locomo_readl(locomokbd->base + LOCOMO_KIC) & ~0x0010;
|
|
|
|
locomo_writel(r, locomokbd->base + LOCOMO_KIC);
|
|
|
|
}
|
|
|
|
|
2012-11-24 12:38:25 +07:00
|
|
|
static int locomokbd_probe(struct locomo_dev *dev)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct locomokbd *locomokbd;
|
2005-11-03 10:49:53 +07:00
|
|
|
struct input_dev *input_dev;
|
2006-11-06 10:39:56 +07:00
|
|
|
int i, err;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-11-03 10:49:53 +07:00
|
|
|
locomokbd = kzalloc(sizeof(struct locomokbd), GFP_KERNEL);
|
|
|
|
input_dev = input_allocate_device();
|
|
|
|
if (!locomokbd || !input_dev) {
|
2006-11-06 10:39:56 +07:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_free_mem;
|
2005-11-03 10:49:53 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* try and claim memory region */
|
2005-05-29 14:28:42 +07:00
|
|
|
if (!request_mem_region((unsigned long) dev->mapbase,
|
|
|
|
dev->length,
|
2005-04-17 05:20:36 +07:00
|
|
|
LOCOMO_DRIVER_NAME(dev))) {
|
2006-11-06 10:39:56 +07:00
|
|
|
err = -EBUSY;
|
2005-04-17 05:20:36 +07:00
|
|
|
printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n");
|
2006-11-06 10:39:56 +07:00
|
|
|
goto err_free_mem;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
locomo_set_drvdata(dev, locomokbd);
|
|
|
|
|
|
|
|
locomokbd->base = (unsigned long) dev->mapbase;
|
|
|
|
|
|
|
|
spin_lock_init(&locomokbd->lock);
|
|
|
|
|
|
|
|
init_timer(&locomokbd->timer);
|
|
|
|
locomokbd->timer.function = locomokbd_timer_callback;
|
|
|
|
locomokbd->timer.data = (unsigned long) locomokbd;
|
|
|
|
|
2008-04-02 11:42:42 +07:00
|
|
|
locomokbd->suspend_jiffies = jiffies;
|
|
|
|
|
2005-11-03 10:49:53 +07:00
|
|
|
locomokbd->input = input_dev;
|
|
|
|
strcpy(locomokbd->phys, "locomokbd/input0");
|
|
|
|
|
|
|
|
input_dev->name = "LoCoMo keyboard";
|
|
|
|
input_dev->phys = locomokbd->phys;
|
2005-11-03 10:52:33 +07:00
|
|
|
input_dev->id.bustype = BUS_HOST;
|
2005-11-03 10:49:53 +07:00
|
|
|
input_dev->id.vendor = 0x0001;
|
|
|
|
input_dev->id.product = 0x0001;
|
|
|
|
input_dev->id.version = 0x0100;
|
2010-02-05 08:13:55 +07:00
|
|
|
input_dev->open = locomokbd_open;
|
|
|
|
input_dev->close = locomokbd_close;
|
2007-04-12 12:34:58 +07:00
|
|
|
input_dev->dev.parent = &dev->dev;
|
2005-05-29 14:28:42 +07:00
|
|
|
|
2008-04-02 11:42:42 +07:00
|
|
|
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
|
|
|
|
BIT_MASK(EV_PWR);
|
2005-11-03 10:49:53 +07:00
|
|
|
input_dev->keycode = locomokbd->keycode;
|
2008-04-02 11:42:42 +07:00
|
|
|
input_dev->keycodesize = sizeof(locomokbd_keycode[0]);
|
2005-11-03 10:49:53 +07:00
|
|
|
input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-02-05 08:13:55 +07:00
|
|
|
input_set_drvdata(input_dev, locomokbd);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode));
|
|
|
|
for (i = 0; i < LOCOMOKBD_NUMKEYS; i++)
|
2005-11-03 10:49:53 +07:00
|
|
|
set_bit(locomokbd->keycode[i], input_dev->keybit);
|
|
|
|
clear_bit(0, input_dev->keybit);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* attempt to get the interrupt */
|
2006-11-06 10:39:56 +07:00
|
|
|
err = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd);
|
|
|
|
if (err) {
|
2005-04-17 05:20:36 +07:00
|
|
|
printk(KERN_ERR "locomokbd: Can't get irq for keyboard\n");
|
2006-11-06 10:39:56 +07:00
|
|
|
goto err_release_region;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2006-11-06 10:39:56 +07:00
|
|
|
err = input_register_device(locomokbd->input);
|
|
|
|
if (err)
|
|
|
|
goto err_free_irq;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2006-11-06 10:39:56 +07:00
|
|
|
err_free_irq:
|
|
|
|
free_irq(dev->irq[0], locomokbd);
|
|
|
|
err_release_region:
|
2005-04-17 05:20:36 +07:00
|
|
|
release_mem_region((unsigned long) dev->mapbase, dev->length);
|
|
|
|
locomo_set_drvdata(dev, NULL);
|
2006-11-06 10:39:56 +07:00
|
|
|
err_free_mem:
|
2005-11-03 10:49:53 +07:00
|
|
|
input_free_device(input_dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
kfree(locomokbd);
|
|
|
|
|
2006-11-06 10:39:56 +07:00
|
|
|
return err;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2012-11-24 12:50:47 +07:00
|
|
|
static int locomokbd_remove(struct locomo_dev *dev)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct locomokbd *locomokbd = locomo_get_drvdata(dev);
|
2005-05-29 14:28:42 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
free_irq(dev->irq[0], locomokbd);
|
|
|
|
|
|
|
|
del_timer_sync(&locomokbd->timer);
|
2005-05-29 14:28:42 +07:00
|
|
|
|
2005-11-03 10:49:53 +07:00
|
|
|
input_unregister_device(locomokbd->input);
|
2005-04-17 05:20:36 +07:00
|
|
|
locomo_set_drvdata(dev, NULL);
|
|
|
|
|
|
|
|
release_mem_region((unsigned long) dev->mapbase, dev->length);
|
|
|
|
|
|
|
|
kfree(locomokbd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct locomo_driver keyboard_driver = {
|
|
|
|
.drv = {
|
|
|
|
.name = "locomokbd"
|
|
|
|
},
|
|
|
|
.devid = LOCOMO_DEVID_KEYBOARD,
|
|
|
|
.probe = locomokbd_probe,
|
2012-11-24 12:27:39 +07:00
|
|
|
.remove = locomokbd_remove,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init locomokbd_init(void)
|
|
|
|
{
|
|
|
|
return locomo_driver_register(&keyboard_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit locomokbd_exit(void)
|
|
|
|
{
|
|
|
|
locomo_driver_unregister(&keyboard_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(locomokbd_init);
|
|
|
|
module_exit(locomokbd_exit);
|