2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* $Id: amikbd.c,v 1.13 2002/02/01 16:02:24 vojtech Exp $
|
|
|
|
*
|
|
|
|
* Copyright (c) 2000-2001 Vojtech Pavlik
|
|
|
|
*
|
|
|
|
* Based on the work of:
|
|
|
|
* Hamish Macdonald
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Amiga keyboard driver for Linux/m68k
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* Should you need to contact me, the author, you can do so either by
|
|
|
|
* e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
|
|
|
|
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/interrupt.h>
|
2006-06-23 11:04:56 +02:00
|
|
|
#include <linux/keyboard.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
#include <asm/amigaints.h>
|
|
|
|
#include <asm/amigahw.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
|
|
|
|
MODULE_DESCRIPTION("Amiga keyboard driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2006-06-23 11:04:56 +02:00
|
|
|
static unsigned char amikbd_keycode[0x78] __initdata = {
|
2005-04-17 00:20:36 +02:00
|
|
|
[0] = KEY_GRAVE,
|
|
|
|
[1] = KEY_1,
|
|
|
|
[2] = KEY_2,
|
|
|
|
[3] = KEY_3,
|
|
|
|
[4] = KEY_4,
|
|
|
|
[5] = KEY_5,
|
|
|
|
[6] = KEY_6,
|
|
|
|
[7] = KEY_7,
|
|
|
|
[8] = KEY_8,
|
|
|
|
[9] = KEY_9,
|
|
|
|
[10] = KEY_0,
|
|
|
|
[11] = KEY_MINUS,
|
|
|
|
[12] = KEY_EQUAL,
|
|
|
|
[13] = KEY_BACKSLASH,
|
|
|
|
[15] = KEY_KP0,
|
|
|
|
[16] = KEY_Q,
|
|
|
|
[17] = KEY_W,
|
|
|
|
[18] = KEY_E,
|
|
|
|
[19] = KEY_R,
|
|
|
|
[20] = KEY_T,
|
|
|
|
[21] = KEY_Y,
|
|
|
|
[22] = KEY_U,
|
|
|
|
[23] = KEY_I,
|
|
|
|
[24] = KEY_O,
|
|
|
|
[25] = KEY_P,
|
|
|
|
[26] = KEY_LEFTBRACE,
|
|
|
|
[27] = KEY_RIGHTBRACE,
|
|
|
|
[29] = KEY_KP1,
|
|
|
|
[30] = KEY_KP2,
|
|
|
|
[31] = KEY_KP3,
|
|
|
|
[32] = KEY_A,
|
|
|
|
[33] = KEY_S,
|
|
|
|
[34] = KEY_D,
|
|
|
|
[35] = KEY_F,
|
|
|
|
[36] = KEY_G,
|
|
|
|
[37] = KEY_H,
|
|
|
|
[38] = KEY_J,
|
|
|
|
[39] = KEY_K,
|
|
|
|
[40] = KEY_L,
|
|
|
|
[41] = KEY_SEMICOLON,
|
|
|
|
[42] = KEY_APOSTROPHE,
|
|
|
|
[43] = KEY_BACKSLASH,
|
|
|
|
[45] = KEY_KP4,
|
|
|
|
[46] = KEY_KP5,
|
|
|
|
[47] = KEY_KP6,
|
|
|
|
[48] = KEY_102ND,
|
|
|
|
[49] = KEY_Z,
|
|
|
|
[50] = KEY_X,
|
|
|
|
[51] = KEY_C,
|
|
|
|
[52] = KEY_V,
|
|
|
|
[53] = KEY_B,
|
|
|
|
[54] = KEY_N,
|
|
|
|
[55] = KEY_M,
|
|
|
|
[56] = KEY_COMMA,
|
|
|
|
[57] = KEY_DOT,
|
|
|
|
[58] = KEY_SLASH,
|
|
|
|
[60] = KEY_KPDOT,
|
|
|
|
[61] = KEY_KP7,
|
|
|
|
[62] = KEY_KP8,
|
|
|
|
[63] = KEY_KP9,
|
|
|
|
[64] = KEY_SPACE,
|
|
|
|
[65] = KEY_BACKSPACE,
|
|
|
|
[66] = KEY_TAB,
|
|
|
|
[67] = KEY_KPENTER,
|
|
|
|
[68] = KEY_ENTER,
|
|
|
|
[69] = KEY_ESC,
|
|
|
|
[70] = KEY_DELETE,
|
|
|
|
[74] = KEY_KPMINUS,
|
|
|
|
[76] = KEY_UP,
|
|
|
|
[77] = KEY_DOWN,
|
|
|
|
[78] = KEY_RIGHT,
|
|
|
|
[79] = KEY_LEFT,
|
|
|
|
[80] = KEY_F1,
|
|
|
|
[81] = KEY_F2,
|
|
|
|
[82] = KEY_F3,
|
|
|
|
[83] = KEY_F4,
|
|
|
|
[84] = KEY_F5,
|
|
|
|
[85] = KEY_F6,
|
|
|
|
[86] = KEY_F7,
|
|
|
|
[87] = KEY_F8,
|
|
|
|
[88] = KEY_F9,
|
|
|
|
[89] = KEY_F10,
|
|
|
|
[90] = KEY_KPLEFTPAREN,
|
|
|
|
[91] = KEY_KPRIGHTPAREN,
|
|
|
|
[92] = KEY_KPSLASH,
|
|
|
|
[93] = KEY_KPASTERISK,
|
|
|
|
[94] = KEY_KPPLUS,
|
|
|
|
[95] = KEY_HELP,
|
|
|
|
[96] = KEY_LEFTSHIFT,
|
|
|
|
[97] = KEY_RIGHTSHIFT,
|
|
|
|
[98] = KEY_CAPSLOCK,
|
|
|
|
[99] = KEY_LEFTCTRL,
|
|
|
|
[100] = KEY_LEFTALT,
|
|
|
|
[101] = KEY_RIGHTALT,
|
|
|
|
[102] = KEY_LEFTMETA,
|
|
|
|
[103] = KEY_RIGHTMETA
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *amikbd_messages[8] = {
|
|
|
|
[0] = KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
|
|
|
|
[1] = KERN_WARNING "amikbd: keyboard lost sync\n",
|
|
|
|
[2] = KERN_WARNING "amikbd: keyboard buffer overflow\n",
|
|
|
|
[3] = KERN_WARNING "amikbd: keyboard controller failure\n",
|
|
|
|
[4] = KERN_ERR "amikbd: keyboard selftest failure\n",
|
|
|
|
[5] = KERN_INFO "amikbd: initiate power-up key stream\n",
|
|
|
|
[6] = KERN_INFO "amikbd: terminate power-up key stream\n",
|
|
|
|
[7] = KERN_WARNING "amikbd: keyboard interrupt\n"
|
|
|
|
};
|
|
|
|
|
2005-09-15 09:01:45 +02:00
|
|
|
static struct input_dev *amikbd_dev;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
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 15:55:46 +02:00
|
|
|
static irqreturn_t amikbd_interrupt(int irq, void *dummy)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
unsigned char scancode, down;
|
|
|
|
|
|
|
|
scancode = ~ciaa.sdr; /* get and invert scancode (keyboard is active low) */
|
|
|
|
ciaa.cra |= 0x40; /* switch SP pin to output for handshake */
|
|
|
|
udelay(85); /* wait until 85 us have expired */
|
|
|
|
ciaa.cra &= ~0x40; /* switch CIA serial port to input mode */
|
|
|
|
|
|
|
|
down = !(scancode & 1); /* lowest bit is release bit */
|
|
|
|
scancode >>= 1;
|
|
|
|
|
|
|
|
if (scancode < 0x78) { /* scancodes < 0x78 are keys */
|
2006-06-23 11:04:56 +02:00
|
|
|
if (scancode == 98) { /* CapsLock is a toggle switch key on Amiga */
|
2005-09-15 09:01:45 +02:00
|
|
|
input_report_key(amikbd_dev, scancode, 1);
|
|
|
|
input_report_key(amikbd_dev, scancode, 0);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else {
|
2005-09-15 09:01:45 +02:00
|
|
|
input_report_key(amikbd_dev, scancode, down);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2005-09-15 09:01:45 +02:00
|
|
|
|
|
|
|
input_sync(amikbd_dev);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else /* scancodes >= 0x78 are error codes */
|
|
|
|
printk(amikbd_messages[scancode - 0x78]);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init amikbd_init(void)
|
|
|
|
{
|
2006-06-23 11:04:56 +02:00
|
|
|
int i, j;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
|
2006-11-06 04:39:56 +01:00
|
|
|
return -ENODEV;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb"))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2005-10-29 12:49:33 +02:00
|
|
|
amikbd_dev = input_allocate_device();
|
2005-09-15 09:01:45 +02:00
|
|
|
if (!amikbd_dev) {
|
|
|
|
printk(KERN_ERR "amikbd: not enough memory for input device\n");
|
2006-11-06 04:39:56 +01:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto fail1;
|
2005-09-15 09:01:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
amikbd_dev->name = "Amiga Keyboard";
|
|
|
|
amikbd_dev->phys = "amikbd/input0";
|
|
|
|
amikbd_dev->id.bustype = BUS_AMIGA;
|
|
|
|
amikbd_dev->id.vendor = 0x0001;
|
|
|
|
amikbd_dev->id.product = 0x0001;
|
|
|
|
amikbd_dev->id.version = 0x0100;
|
|
|
|
|
|
|
|
amikbd_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 0x78; i++)
|
2006-06-23 11:04:56 +02:00
|
|
|
set_bit(i, amikbd_dev->keybit);
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
|
|
|
static u_short temp_map[NR_KEYS] __initdata;
|
|
|
|
if (!key_maps[i])
|
|
|
|
continue;
|
|
|
|
memset(temp_map, 0, sizeof(temp_map));
|
|
|
|
for (j = 0; j < 0x78; j++) {
|
|
|
|
if (!amikbd_keycode[j])
|
|
|
|
continue;
|
|
|
|
temp_map[j] = key_maps[i][amikbd_keycode[j]];
|
|
|
|
}
|
|
|
|
for (j = 0; j < NR_KEYS; j++) {
|
|
|
|
if (!temp_map[j])
|
|
|
|
temp_map[j] = 0xf200;
|
|
|
|
}
|
|
|
|
memcpy(key_maps[i], temp_map, sizeof(temp_map));
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
ciaa.cra &= ~0x41; /* serial data in, turn off TA */
|
2006-11-06 04:39:56 +01:00
|
|
|
if (request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
|
|
|
|
amikbd_interrupt)) {
|
|
|
|
err = -EBUSY;
|
|
|
|
goto fail2;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = input_register_device(amikbd_dev);
|
|
|
|
if (err)
|
|
|
|
goto fail3;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return 0;
|
2006-11-06 04:39:56 +01:00
|
|
|
|
|
|
|
fail3: free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
|
|
|
|
fail2: input_free_device(amikbd_dev);
|
|
|
|
fail1: release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
|
|
|
|
return err;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit amikbd_exit(void)
|
|
|
|
{
|
|
|
|
free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
|
2005-09-15 09:01:45 +02:00
|
|
|
input_unregister_device(amikbd_dev);
|
|
|
|
release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(amikbd_init);
|
|
|
|
module_exit(amikbd_exit);
|