2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Keyboard driver for Sharp Corgi models (SL-C7xx)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004-2005 Richard Purdie
|
|
|
|
*
|
|
|
|
* Based on xtkbd.c/locomkbd.c
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/delay.h>
|
2005-10-30 02:07:23 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/interrupt.h>
|
2005-09-07 06:18:59 +08:00
|
|
|
#include <linux/jiffies.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
#include <asm/arch/corgi.h>
|
|
|
|
#include <asm/arch/hardware.h>
|
|
|
|
#include <asm/arch/pxa-regs.h>
|
|
|
|
#include <asm/hardware/scoop.h>
|
|
|
|
|
|
|
|
#define KB_ROWS 8
|
|
|
|
#define KB_COLS 12
|
|
|
|
#define KB_ROWMASK(r) (1 << (r))
|
|
|
|
#define SCANCODE(r,c) ( ((r)<<4) + (c) + 1 )
|
2006-03-14 13:12:32 +08:00
|
|
|
/* zero code, 124 scancodes */
|
|
|
|
#define NR_SCANCODES ( SCANCODE(KB_ROWS-1,KB_COLS-1) +1 +1 )
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-14 13:12:32 +08:00
|
|
|
#define SCAN_INTERVAL (50) /* ms */
|
|
|
|
#define HINGE_SCAN_INTERVAL (250) /* ms */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define CORGI_KEY_CALENDER KEY_F1
|
|
|
|
#define CORGI_KEY_ADDRESS KEY_F2
|
|
|
|
#define CORGI_KEY_FN KEY_F3
|
2005-05-29 15:27:06 +08:00
|
|
|
#define CORGI_KEY_CANCEL KEY_F4
|
2005-04-17 06:20:36 +08:00
|
|
|
#define CORGI_KEY_OFF KEY_SUSPEND
|
|
|
|
#define CORGI_KEY_EXOK KEY_F5
|
|
|
|
#define CORGI_KEY_EXCANCEL KEY_F6
|
|
|
|
#define CORGI_KEY_EXJOGDOWN KEY_F7
|
|
|
|
#define CORGI_KEY_EXJOGUP KEY_F8
|
|
|
|
#define CORGI_KEY_JAP1 KEY_LEFTCTRL
|
|
|
|
#define CORGI_KEY_JAP2 KEY_LEFTALT
|
2005-05-29 15:27:06 +08:00
|
|
|
#define CORGI_KEY_MAIL KEY_F10
|
2005-04-17 06:20:36 +08:00
|
|
|
#define CORGI_KEY_OK KEY_F11
|
|
|
|
#define CORGI_KEY_MENU KEY_F12
|
|
|
|
|
|
|
|
static unsigned char corgikbd_keycode[NR_SCANCODES] = {
|
|
|
|
0, /* 0 */
|
|
|
|
0, KEY_1, KEY_3, KEY_5, KEY_6, KEY_7, KEY_9, KEY_0, KEY_BACKSPACE, 0, 0, 0, 0, 0, 0, 0, /* 1-16 */
|
|
|
|
0, KEY_2, KEY_4, KEY_R, KEY_Y, KEY_8, KEY_I, KEY_O, KEY_P, 0, 0, 0, 0, 0, 0, 0, /* 17-32 */
|
|
|
|
KEY_TAB, KEY_Q, KEY_E, KEY_T, KEY_G, KEY_U, KEY_J, KEY_K, 0, 0, 0, 0, 0, 0, 0, 0, /* 33-48 */
|
|
|
|
CORGI_KEY_CALENDER, KEY_W, KEY_S, KEY_F, KEY_V, KEY_H, KEY_M, KEY_L, 0, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0, 0, /* 49-64 */
|
|
|
|
CORGI_KEY_ADDRESS, KEY_A, KEY_D, KEY_C, KEY_B, KEY_N, KEY_DOT, 0, KEY_ENTER, 0, KEY_LEFTSHIFT, 0, 0, 0, 0, 0, /* 65-80 */
|
2005-05-29 15:27:06 +08:00
|
|
|
CORGI_KEY_MAIL, KEY_Z, KEY_X, KEY_MINUS, KEY_SPACE, KEY_COMMA, 0, KEY_UP, 0, 0, 0, CORGI_KEY_FN, 0, 0, 0, 0, /* 81-96 */
|
|
|
|
KEY_SYSRQ, CORGI_KEY_JAP1, CORGI_KEY_JAP2, CORGI_KEY_CANCEL, CORGI_KEY_OK, CORGI_KEY_MENU, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0, 0, /* 97-112 */
|
2005-04-17 06:20:36 +08:00
|
|
|
CORGI_KEY_OFF, CORGI_KEY_EXOK, CORGI_KEY_EXCANCEL, CORGI_KEY_EXJOGDOWN, CORGI_KEY_EXJOGUP, 0, 0, 0, 0, 0, 0, 0, /* 113-124 */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct corgikbd {
|
|
|
|
unsigned char keycode[ARRAY_SIZE(corgikbd_keycode)];
|
2005-09-15 15:01:45 +08:00
|
|
|
struct input_dev *input;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spinlock_t lock;
|
|
|
|
struct timer_list timer;
|
|
|
|
struct timer_list htimer;
|
2005-09-07 06:18:59 +08:00
|
|
|
|
|
|
|
unsigned int suspended;
|
|
|
|
unsigned long suspend_jiffies;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define KB_DISCHARGE_DELAY 10
|
|
|
|
#define KB_ACTIVATE_DELAY 10
|
|
|
|
|
|
|
|
/* Helper functions for reading the keyboard matrix
|
|
|
|
* Note: We should really be using pxa_gpio_mode to alter GPDR but it
|
|
|
|
* requires a function call per GPIO bit which is excessive
|
|
|
|
* when we need to access 12 bits at once multiple times.
|
|
|
|
* These functions must be called within local_irq_save()/local_irq_restore()
|
|
|
|
* or similar.
|
|
|
|
*/
|
|
|
|
static inline void corgikbd_discharge_all(void)
|
|
|
|
{
|
2005-09-07 06:19:00 +08:00
|
|
|
/* STROBE All HiZ */
|
2005-04-17 06:20:36 +08:00
|
|
|
GPCR2 = CORGI_GPIO_ALL_STROBE_BIT;
|
|
|
|
GPDR2 &= ~CORGI_GPIO_ALL_STROBE_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void corgikbd_activate_all(void)
|
|
|
|
{
|
2005-09-07 06:19:00 +08:00
|
|
|
/* STROBE ALL -> High */
|
2005-04-17 06:20:36 +08:00
|
|
|
GPSR2 = CORGI_GPIO_ALL_STROBE_BIT;
|
|
|
|
GPDR2 |= CORGI_GPIO_ALL_STROBE_BIT;
|
|
|
|
|
|
|
|
udelay(KB_DISCHARGE_DELAY);
|
|
|
|
|
2005-09-07 06:19:00 +08:00
|
|
|
/* Clear any interrupts we may have triggered when altering the GPIO lines */
|
2005-04-17 06:20:36 +08:00
|
|
|
GEDR1 = CORGI_GPIO_HIGH_SENSE_BIT;
|
|
|
|
GEDR2 = CORGI_GPIO_LOW_SENSE_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void corgikbd_activate_col(int col)
|
|
|
|
{
|
2005-09-07 06:19:00 +08:00
|
|
|
/* STROBE col -> High, not col -> HiZ */
|
2005-04-17 06:20:36 +08:00
|
|
|
GPSR2 = CORGI_GPIO_STROBE_BIT(col);
|
|
|
|
GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void corgikbd_reset_col(int col)
|
|
|
|
{
|
2005-09-07 06:19:00 +08:00
|
|
|
/* STROBE col -> Low */
|
2005-04-17 06:20:36 +08:00
|
|
|
GPCR2 = CORGI_GPIO_STROBE_BIT(col);
|
2005-09-07 06:19:00 +08:00
|
|
|
/* STROBE col -> out, not col -> HiZ */
|
2005-04-17 06:20:36 +08:00
|
|
|
GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_ROWS_STATUS(c) (((GPLR1 & CORGI_GPIO_HIGH_SENSE_BIT) >> CORGI_GPIO_HIGH_SENSE_RSHIFT) | ((GPLR2 & CORGI_GPIO_LOW_SENSE_BIT) << CORGI_GPIO_LOW_SENSE_LSHIFT))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The corgi keyboard only generates interrupts when a key is pressed.
|
|
|
|
* When a key is pressed, we enable a timer which then scans the
|
|
|
|
* keyboard to 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 21:55:46 +08:00
|
|
|
static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-07 06:19:00 +08:00
|
|
|
unsigned int row, col, rowd;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned int num_pressed;
|
|
|
|
|
2005-09-07 06:18:59 +08:00
|
|
|
if (corgikbd_data->suspended)
|
|
|
|
return;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irqsave(&corgikbd_data->lock, flags);
|
|
|
|
|
|
|
|
num_pressed = 0;
|
|
|
|
for (col = 0; col < KB_COLS; col++) {
|
|
|
|
/*
|
|
|
|
* Discharge the output driver capacitatance
|
|
|
|
* in the keyboard matrix. (Yes it is significant..)
|
|
|
|
*/
|
|
|
|
|
|
|
|
corgikbd_discharge_all();
|
|
|
|
udelay(KB_DISCHARGE_DELAY);
|
|
|
|
|
|
|
|
corgikbd_activate_col(col);
|
|
|
|
udelay(KB_ACTIVATE_DELAY);
|
|
|
|
|
|
|
|
rowd = GET_ROWS_STATUS(col);
|
|
|
|
for (row = 0; row < KB_ROWS; row++) {
|
2005-09-07 06:19:00 +08:00
|
|
|
unsigned int scancode, pressed;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
scancode = SCANCODE(row, col);
|
2005-09-07 06:19:00 +08:00
|
|
|
pressed = rowd & KB_ROWMASK(row);
|
|
|
|
|
2005-09-15 15:01:45 +08:00
|
|
|
input_report_key(corgikbd_data->input, corgikbd_data->keycode[scancode], pressed);
|
2005-09-07 06:19:00 +08:00
|
|
|
|
|
|
|
if (pressed)
|
2005-04-17 06:20:36 +08:00
|
|
|
num_pressed++;
|
2005-09-07 06:19:00 +08:00
|
|
|
|
|
|
|
if (pressed && (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF)
|
|
|
|
&& time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) {
|
2005-09-15 15:01:45 +08:00
|
|
|
input_event(corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1);
|
2005-09-07 06:19:00 +08:00
|
|
|
corgikbd_data->suspend_jiffies=jiffies;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
corgikbd_reset_col(col);
|
|
|
|
}
|
|
|
|
|
|
|
|
corgikbd_activate_all();
|
|
|
|
|
2005-09-15 15:01:45 +08:00
|
|
|
input_sync(corgikbd_data->input);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* if any keys are pressed, enable the timer */
|
|
|
|
if (num_pressed)
|
2006-03-14 13:12:32 +08:00
|
|
|
mod_timer(&corgikbd_data->timer, jiffies + msecs_to_jiffies(SCAN_INTERVAL));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&corgikbd_data->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* corgi 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 21:55:46 +08:00
|
|
|
static irqreturn_t corgikbd_interrupt(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct corgikbd *corgikbd_data = dev_id;
|
|
|
|
|
|
|
|
if (!timer_pending(&corgikbd_data->timer)) {
|
|
|
|
/** wait chattering delay **/
|
|
|
|
udelay(20);
|
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
|
|
|
corgikbd_scankeyboard(corgikbd_data);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* corgi timer checking for released keys
|
|
|
|
*/
|
|
|
|
static void corgikbd_timer_callback(unsigned long data)
|
|
|
|
{
|
|
|
|
struct corgikbd *corgikbd_data = (struct corgikbd *) data;
|
2006-10-15 20:50:02 +08:00
|
|
|
corgikbd_scankeyboard(corgikbd_data);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The hinge switches generate no interrupt so they need to be
|
|
|
|
* monitored by a timer.
|
|
|
|
*
|
2005-09-07 06:19:00 +08:00
|
|
|
* We debounce the switches and pass them to the input system.
|
|
|
|
*
|
|
|
|
* gprr == 0x00 - Keyboard with Landscape Screen
|
|
|
|
* 0x08 - No Keyboard with Portrait Screen
|
|
|
|
* 0x0c - Keyboard and Screen Closed
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2006-03-14 13:12:32 +08:00
|
|
|
#define READ_GPIO_BIT(x) (GPLR(x) & GPIO_bit(x))
|
2005-04-17 06:20:36 +08:00
|
|
|
#define HINGE_STABLE_COUNT 2
|
|
|
|
static int sharpsl_hinge_state;
|
|
|
|
static int hinge_count;
|
|
|
|
|
|
|
|
static void corgikbd_hinge_timer(unsigned long data)
|
|
|
|
{
|
|
|
|
struct corgikbd *corgikbd_data = (struct corgikbd *) data;
|
|
|
|
unsigned long gprr;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2005-09-07 06:18:59 +08:00
|
|
|
gprr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_GPRR) & (CORGI_SCP_SWA | CORGI_SCP_SWB);
|
2006-03-14 13:12:32 +08:00
|
|
|
gprr |= (READ_GPIO_BIT(CORGI_GPIO_AK_INT) != 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (gprr != sharpsl_hinge_state) {
|
|
|
|
hinge_count = 0;
|
|
|
|
sharpsl_hinge_state = gprr;
|
|
|
|
} else if (hinge_count < HINGE_STABLE_COUNT) {
|
|
|
|
hinge_count++;
|
|
|
|
if (hinge_count >= HINGE_STABLE_COUNT) {
|
|
|
|
spin_lock_irqsave(&corgikbd_data->lock, flags);
|
|
|
|
|
2006-05-30 11:31:03 +08:00
|
|
|
input_report_switch(corgikbd_data->input, SW_LID, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0));
|
|
|
|
input_report_switch(corgikbd_data->input, SW_TABLET_MODE, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0));
|
|
|
|
input_report_switch(corgikbd_data->input, SW_HEADPHONE_INSERT, (READ_GPIO_BIT(CORGI_GPIO_AK_INT) != 0));
|
2005-09-15 15:01:45 +08:00
|
|
|
input_sync(corgikbd_data->input);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&corgikbd_data->lock, flags);
|
|
|
|
}
|
|
|
|
}
|
2006-03-14 13:12:32 +08:00
|
|
|
mod_timer(&corgikbd_data->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-09-07 06:18:59 +08:00
|
|
|
#ifdef CONFIG_PM
|
2005-11-10 06:32:44 +08:00
|
|
|
static int corgikbd_suspend(struct platform_device *dev, pm_message_t state)
|
2005-09-07 06:18:59 +08:00
|
|
|
{
|
2006-03-14 13:12:32 +08:00
|
|
|
int i;
|
2005-11-10 06:32:44 +08:00
|
|
|
struct corgikbd *corgikbd = platform_get_drvdata(dev);
|
2006-03-14 13:12:32 +08:00
|
|
|
|
2005-10-29 00:52:56 +08:00
|
|
|
corgikbd->suspended = 1;
|
2006-03-14 13:12:32 +08:00
|
|
|
/* strobe 0 is the power key so this can't be made an input for
|
|
|
|
powersaving therefore i = 1 */
|
|
|
|
for (i = 1; i < CORGI_KEY_STROBE_NUM; i++)
|
|
|
|
pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_IN);
|
2005-10-29 00:52:56 +08:00
|
|
|
|
2005-09-07 06:18:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int corgikbd_resume(struct platform_device *dev)
|
2005-09-07 06:18:59 +08:00
|
|
|
{
|
2006-03-14 13:12:32 +08:00
|
|
|
int i;
|
2005-11-10 06:32:44 +08:00
|
|
|
struct corgikbd *corgikbd = platform_get_drvdata(dev);
|
2005-10-29 00:52:56 +08:00
|
|
|
|
2006-03-14 13:12:32 +08:00
|
|
|
for (i = 1; i < CORGI_KEY_STROBE_NUM; i++)
|
|
|
|
pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH);
|
|
|
|
|
2005-10-29 00:52:56 +08:00
|
|
|
/* Upon resume, ignore the suspend key for a short while */
|
|
|
|
corgikbd->suspend_jiffies=jiffies;
|
|
|
|
corgikbd->suspended = 0;
|
2005-09-07 06:18:59 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define corgikbd_suspend NULL
|
|
|
|
#define corgikbd_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int __init corgikbd_probe(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct corgikbd *corgikbd;
|
2005-09-15 15:01:45 +08:00
|
|
|
struct input_dev *input_dev;
|
2006-11-06 11:39:56 +08:00
|
|
|
int i, err = -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-07 06:18:33 +08:00
|
|
|
corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL);
|
2005-09-15 15:01:45 +08:00
|
|
|
input_dev = input_allocate_device();
|
2006-11-06 11:39:56 +08:00
|
|
|
if (!corgikbd || !input_dev)
|
|
|
|
goto fail;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_set_drvdata(pdev, corgikbd);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-15 15:01:45 +08:00
|
|
|
corgikbd->input = input_dev;
|
2005-09-07 06:18:59 +08:00
|
|
|
spin_lock_init(&corgikbd->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Init Keyboard rescan timer */
|
|
|
|
init_timer(&corgikbd->timer);
|
|
|
|
corgikbd->timer.function = corgikbd_timer_callback;
|
|
|
|
corgikbd->timer.data = (unsigned long) corgikbd;
|
|
|
|
|
|
|
|
/* Init Hinge Timer */
|
|
|
|
init_timer(&corgikbd->htimer);
|
|
|
|
corgikbd->htimer.function = corgikbd_hinge_timer;
|
|
|
|
corgikbd->htimer.data = (unsigned long) corgikbd;
|
|
|
|
|
2005-09-07 06:18:59 +08:00
|
|
|
corgikbd->suspend_jiffies=jiffies;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
memcpy(corgikbd->keycode, corgikbd_keycode, sizeof(corgikbd->keycode));
|
2005-09-15 15:01:45 +08:00
|
|
|
|
|
|
|
input_dev->name = "Corgi Keyboard";
|
|
|
|
input_dev->phys = "corgikbd/input0";
|
|
|
|
input_dev->id.bustype = BUS_HOST;
|
|
|
|
input_dev->id.vendor = 0x0001;
|
|
|
|
input_dev->id.product = 0x0001;
|
|
|
|
input_dev->id.version = 0x0100;
|
2007-04-12 13:34:58 +08:00
|
|
|
input_dev->dev.parent = &pdev->dev;
|
2005-09-15 15:01:45 +08:00
|
|
|
|
2007-10-19 14:40:32 +08:00
|
|
|
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
|
|
|
|
BIT_MASK(EV_PWR) | BIT_MASK(EV_SW);
|
2005-09-15 15:01:45 +08:00
|
|
|
input_dev->keycode = corgikbd->keycode;
|
|
|
|
input_dev->keycodesize = sizeof(unsigned char);
|
|
|
|
input_dev->keycodemax = ARRAY_SIZE(corgikbd_keycode);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++)
|
2005-09-15 15:01:45 +08:00
|
|
|
set_bit(corgikbd->keycode[i], input_dev->keybit);
|
|
|
|
clear_bit(0, input_dev->keybit);
|
2006-05-30 11:31:03 +08:00
|
|
|
set_bit(SW_LID, input_dev->swbit);
|
|
|
|
set_bit(SW_TABLET_MODE, input_dev->swbit);
|
|
|
|
set_bit(SW_HEADPHONE_INSERT, input_dev->swbit);
|
2005-09-15 15:01:45 +08:00
|
|
|
|
2006-11-06 11:39:56 +08:00
|
|
|
err = input_register_device(corgikbd->input);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-14 13:12:32 +08:00
|
|
|
mod_timer(&corgikbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */
|
|
|
|
for (i = 0; i < CORGI_KEY_SENSE_NUM; i++) {
|
|
|
|
pxa_gpio_mode(CORGI_GPIO_KEY_SENSE(i) | GPIO_IN);
|
|
|
|
if (request_irq(CORGI_IRQ_GPIO_KEY_SENSE(i), corgikbd_interrupt,
|
2006-07-02 10:29:38 +08:00
|
|
|
IRQF_DISABLED | IRQF_TRIGGER_RISING,
|
[PATCH] IRQ type flags
Some ARM platforms have the ability to program the interrupt controller to
detect various interrupt edges and/or levels. For some platforms, this is
critical to setup correctly, particularly those which the setting is dependent
on the device.
Currently, ARM drivers do (eg) the following:
err = request_irq(irq, ...);
set_irq_type(irq, IRQT_RISING);
However, if the interrupt has previously been programmed to be level sensitive
(for whatever reason) then this will cause an interrupt storm.
Hence, if we combine set_irq_type() with request_irq(), we can then safely set
the type prior to unmasking the interrupt. The unfortunate problem is that in
order to support this, these flags need to be visible outside of the ARM
architecture - drivers such as smc91x need these flags and they're
cross-architecture.
Finally, the SA_TRIGGER_* flag passed to request_irq() should reflect the
property that the device would like. The IRQ controller code should do its
best to select the most appropriate supported mode.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-08 17:02:07 +08:00
|
|
|
"corgikbd", corgikbd))
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_WARNING "corgikbd: Can't get IRQ: %d!\n", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Strobe lines as outputs - set high */
|
|
|
|
for (i = 0; i < CORGI_KEY_STROBE_NUM; i++)
|
|
|
|
pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH);
|
|
|
|
|
2006-03-14 13:12:32 +08:00
|
|
|
/* Setup the headphone jack as an input */
|
|
|
|
pxa_gpio_mode(CORGI_GPIO_AK_INT | GPIO_IN);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2006-11-06 11:39:56 +08:00
|
|
|
|
|
|
|
fail: input_free_device(input_dev);
|
|
|
|
kfree(corgikbd);
|
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int corgikbd_remove(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
2005-11-10 06:32:44 +08:00
|
|
|
struct corgikbd *corgikbd = platform_get_drvdata(pdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < CORGI_KEY_SENSE_NUM; i++)
|
|
|
|
free_irq(CORGI_IRQ_GPIO_KEY_SENSE(i), corgikbd);
|
|
|
|
|
|
|
|
del_timer_sync(&corgikbd->htimer);
|
|
|
|
del_timer_sync(&corgikbd->timer);
|
|
|
|
|
2005-09-15 15:01:45 +08:00
|
|
|
input_unregister_device(corgikbd->input);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
kfree(corgikbd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static struct platform_driver corgikbd_driver = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.probe = corgikbd_probe,
|
|
|
|
.remove = corgikbd_remove,
|
2005-09-07 06:18:59 +08:00
|
|
|
.suspend = corgikbd_suspend,
|
|
|
|
.resume = corgikbd_resume,
|
2005-11-10 06:32:44 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "corgi-keyboard",
|
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __devinit corgikbd_init(void)
|
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
return platform_driver_register(&corgikbd_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit corgikbd_exit(void)
|
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_driver_unregister(&corgikbd_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(corgikbd_init);
|
|
|
|
module_exit(corgikbd_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
|
|
|
|
MODULE_DESCRIPTION("Corgi Keyboard Driver");
|
|
|
|
MODULE_LICENSE("GPLv2");
|