2002-01-31 15:15:04

by James Simmons

[permalink] [raw]
Subject: [PATCH] amiga input api drivers


Hi!

The amiga mouse and amiga joystick have been already ported over to the
input api. Now for the keyboard. This patch is the input api amiga
keyboard. I wanted people to try it out before I send it off to be
included in the DJ tree. Have fun!!!

. ---
|o_o |
|:_/ | Give Micro$oft the Bird!!!!
// \ \ Use Linux!!!!
(| | )
/'_ _/`\
___)=(___/

diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/arch/m68k/amiga/config.c linux/arch/m68k/amiga/config.c
--- linux-2.5.2-dj7/arch/m68k/amiga/config.c Sat Jan 19 09:34:46 2002
+++ linux/arch/m68k/amiga/config.c Thu Jan 31 07:58:05 2002
@@ -69,11 +69,13 @@
extern char m68k_debug_device[];

static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
+#ifndef CONFIG_KEYBOARD_AMIGA
/* amiga specific keyboard functions */
extern int amiga_keyb_init(void);
extern int amiga_kbdrate (struct kbd_repeat *);
extern int amiga_kbd_translate(unsigned char keycode, unsigned char *keycodep,
char raw_mode);
+#endif
/* amiga specific irq functions */
extern void amiga_init_IRQ (void);
extern void (*amiga_default_handler[]) (int, void *, struct pt_regs *);
@@ -389,9 +391,11 @@
request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);

mach_sched_init = amiga_sched_init;
+#ifndef CONFIG_KEYBOARD_AMIGA
mach_keyb_init = amiga_keyb_init;
mach_kbdrate = amiga_kbdrate;
mach_kbd_translate = amiga_kbd_translate;
+#endif
SYSRQ_KEY = 0xff;
mach_init_IRQ = amiga_init_IRQ;
mach_default_handler = &amiga_default_handler;
diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/arch/ppc/amiga/config.c linux/arch/ppc/amiga/config.c
--- linux-2.5.2-dj7/arch/ppc/amiga/config.c Sat Jan 19 09:34:46 2002
+++ linux/arch/ppc/amiga/config.c Thu Jan 31 07:59:52 2002
@@ -77,9 +77,11 @@
extern char m68k_debug_device[];

static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
+#ifndef CONFIG_KEYBOARD_AMIGA
/* amiga specific keyboard functions */
extern int amiga_keyb_init(void);
extern int amiga_kbdrate (struct kbd_repeat *);
+#endif
/* amiga specific irq functions */
extern void amiga_init_IRQ (void);
extern void (*amiga_default_handler[]) (int, void *, struct pt_regs *);
@@ -409,8 +411,10 @@
request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);

mach_sched_init = amiga_sched_init;
+#ifndef CONFIG_KEYBOARD_AMIGA
mach_keyb_init = amiga_keyb_init;
mach_kbdrate = amiga_kbdrate;
+#endif
mach_init_IRQ = amiga_init_IRQ;
mach_default_handler = &amiga_default_handler;
#ifndef CONFIG_APUS
diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/arch/ppc/kernel/apus_setup.c linux/arch/ppc/kernel/apus_setup.c
--- linux-2.5.2-dj7/arch/ppc/kernel/apus_setup.c Wed Dec 26 10:43:22 2001
+++ linux/arch/ppc/kernel/apus_setup.c Thu Jan 31 08:01:17 2002
@@ -801,9 +801,11 @@
static void apus_kbd_init_hw(void)
{
#ifdef CONFIG_APUS
+#ifndef CONFIG_KEYBOARD_AMIGA
extern int amiga_keyb_init(void);

amiga_keyb_init();
+#endif
#endif
}

diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/drivers/input/keyboard/Config.in linux/drivers/input/keyboard/Config.in
--- linux-2.5.2-dj7/drivers/input/keyboard/Config.in Wed Jan 30 21:07:52 2002
+++ linux/drivers/input/keyboard/Config.in Thu Jan 31 07:49:37 2002
@@ -12,3 +12,7 @@
if [ "$CONFIG_SH_DREAMCAST" = "y" ]; then
dep_tristate ' Maple bus keyboard support' CONFIG_KEYBOARD_MAPLE $CONFIG_INPUT $CONFIG_INPUT_KEYBOARD $CONFIG_MAPLE
fi
+
+if [ "$CONFIG_AMIGA" = "y" ]; then
+ dep_tristate ' Amiga keyboard' CONFIG_KEYBOARD_AMIKBD $CONFIG_INPUT $CONFIG_INPUT_KEYBOARD
+fi
diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/drivers/input/keyboard/Makefile linux/drivers/input/keyboard/Makefile
--- linux-2.5.2-dj7/drivers/input/keyboard/Makefile Wed Jan 30 21:07:52 2002
+++ linux/drivers/input/keyboard/Makefile Thu Jan 31 07:45:52 2002
@@ -13,6 +13,7 @@
obj-$(CONFIG_KEYBOARD_PS2SERKBD) += ps2serkbd.o
obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o
obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o
+obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o

# The global Rules.make.

diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/drivers/input/keyboard/amikbd.c linux/drivers/input/keyboard/amikbd.c
--- linux-2.5.2-dj7/drivers/input/keyboard/amikbd.c Wed Dec 31 16:00:00 1969
+++ linux/drivers/input/keyboard/amikbd.c Thu Jan 31 07:44:05 2002
@@ -0,0 +1,140 @@
+/*
+ * $Id: amikbd.c,v 1.10 2002/01/24 19:22:46 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 <[email protected]>, 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 <asm/amigaints.h>
+#include <asm/amigahw.h>
+#include <asm/irq.h>
+
+MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
+MODULE_DESCRIPTION("Amiga keyboard driver");
+MODULE_LICENSE("GPL");
+
+static unsigned char amikbd_keycode[0x78] = {
+ 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 43, 0, 82,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 0, 79, 80, 81,
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 0, 0, 75, 76, 77,
+ 0, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 0, 83, 71, 72, 73,
+ 57, 14, 15, 96, 28, 1,111, 0, 0, 0, 74, 0,103,108,106,105,
+ 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 98, 55, 78, 87,
+ 42, 54, 58, 29, 56,100
+}
+
+static char *amikbd_messages[] = {
+ KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
+ KERN_WARNING "amikbd: keyboard lost sync\n",
+ KERN_WARNING "amikbd: keyboard buffer overflow\n",
+ KERN_WARNING "amikbd: keyboard controller failure\n",
+ KERN_ERR "amikbd: keyboard selftest failure\n",
+ KERN_INFO "amikbd: initiate power-up key stream\n",
+ KERN_INFO "amikbd: terminate power-up key stream\n",
+ KERN_WARNING "amikbd: keyboard interrupt\n"
+};
+
+static struct input_dev amikbd_dev;
+
+static char *amikbd_name = "Amiga keyboard";
+static char *amikbd_phys = "amikbd/input0";
+
+static void amikbd_interrupt(int irq, void *dummy, struct pt_regs *fp)
+{
+ 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 */
+
+ scancode = scancode >> 1; /* lowest bit is release bit */
+ down = scancode & 1;
+
+ if (scancode < 0x78) { /* scancodes < 0x78 are keys */
+
+ scancode = amikbd_keycode[scancode];
+
+ if (scancode == KEY_CAPS) { /* CapsLock is a toggle switch key on Amiga */
+ input_report_key(&amikbd_dev, scancode, 1);
+ input_report_key(&amikbd_dev, scancode, 0);
+ return;
+ }
+
+ input_report_key(&amikbd_dev, scancode, down);
+
+ return;
+ }
+
+ printk(amikbd_messages[scancode]); /* scancodes >= 0x78 are error codes */
+}
+
+static int __init amikbd_init(void)
+{
+ int i;
+
+ if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
+ return -EIO;
+
+ amikbd_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
+ amikbd_dev.keycode = amikbd_keycode;
+
+ for (i = 0; i < 0x78; i++)
+ if (amikbd_keycode[i])
+ set_bit(amikbd_keycode[i], amikbd_dev.keybit);
+
+ ciaa.cra &= ~0x41; /* serial data in, turn off TA */
+ request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd", NULL);
+
+ amikbd_dev.name = amikbd_name;
+ amikbd_dev.phys = amikbd_phys;
+ amikbd_dev.idbus = BUS_AMIGA;
+ amikbd_dev.idvendor = 0x0001;
+ amikbd_dev.idproduct = 0x0001;
+ amikbd_dev.idversion = 0x0100;
+
+ input_register_device(&amikbd_dev);
+
+ printk(KERN_INFO "input: %s\n", amikbd_name);
+
+ return 0;
+}
+
+static void __exit amikbd_exit(void)
+{
+ input_unregister_device(&amikbd_dev);
+ free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
+}
+
+module_init(amikbd_init);
+module_exit(amikbd_exit);



2002-01-31 20:56:34

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

On Thu, 31 Jan 2002, James Simmons wrote:
> The amiga mouse and amiga joystick have been already ported over to the
> input api. Now for the keyboard. This patch is the input api amiga
> keyboard. I wanted people to try it out before I send it off to be
> included in the DJ tree. Have fun!!!

> diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/drivers/input/keyboard/amikbd.c linux/drivers/input/keyboard/amikbd.c
> --- linux-2.5.2-dj7/drivers/input/keyboard/amikbd.c Wed Dec 31 16:00:00 1969
> +++ linux/drivers/input/keyboard/amikbd.c Thu Jan 31 07:44:05 2002

> +static char *amikbd_messages[] = {
> + KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
> + KERN_WARNING "amikbd: keyboard lost sync\n",
> + KERN_WARNING "amikbd: keyboard buffer overflow\n",
> + KERN_WARNING "amikbd: keyboard controller failure\n",
> + KERN_ERR "amikbd: keyboard selftest failure\n",
> + KERN_INFO "amikbd: initiate power-up key stream\n",
> + KERN_INFO "amikbd: terminate power-up key stream\n",
> + KERN_WARNING "amikbd: keyboard interrupt\n"
> +};

> + if (scancode < 0x78) { /* scancodes < 0x78 are keys */

[...]

> + }
> +
> + printk(amikbd_messages[scancode]); /* scancodes >= 0x78 are error codes */

Oops, amikbd_messages[scancode-0x78]?

Gr{oetje,eeting}s,

Geert (just reading patches)

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2002-01-31 21:19:05

by Simon Richter

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

On Thu, 31 Jan 2002, James Simmons wrote:

> + scancode = scancode >> 1; /* lowest bit is release bit */
> + down = scancode & 1;

Shouldn't that be the other way 'round?

Simon

--
GPG public key available from http://phobos.fs.tum.de/pgp/Simon.Richter.asc
Fingerprint: DC26 EB8D 1F35 4F44 2934 7583 DBB6 F98D 9198 3292
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!

2002-01-31 21:51:23

by Roman Zippel

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

Hi,

James Simmons wrote:

> + printk(amikbd_messages[scancode]); /* scancodes >= 0x78 are error codes */

Damn, Geert was faster with this. :)

> + for (i = 0; i < 0x78; i++)
> + if (amikbd_keycode[i])
> + set_bit(amikbd_keycode[i], amikbd_dev.keybit);

Do I understand it correctly, that amikbd_keycode[i] must have non zero
value for a valid key? If yes, something must be wrong here:

> +static unsigned char amikbd_keycode[0x78] = {
> + 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 43, 0, 82,

0 is a valid keycode on the Amiga, it should be KEY_GRAVE.

bye, Roman

2002-01-31 23:06:07

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers


> > + printk(amikbd_messages[scancode]); /* scancodes >= 0x78 are error codes */
>
> Damn, Geert was faster with this. :)

Fixed.

> > + for (i = 0; i < 0x78; i++)
> > + if (amikbd_keycode[i])
> > + set_bit(amikbd_keycode[i], amikbd_dev.keybit);
>
> Do I understand it correctly, that amikbd_keycode[i] must have non zero
> value for a valid key? If yes, something must be wrong here:

Yes. amikbd_keycode is a map from scancode values to event key values. Now

> > +static unsigned char amikbd_keycode[0x78] = {
> > + 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 43, 0, 82,
>
> 0 is a valid keycode on the Amiga, it should be KEY_GRAVE.

Okay so it should be:

static unsigned char amikbd_keycode[0x78] = {
41, 2, 3, 4, 5, ...

If amikbd_keycode[0] is set 41 then

set_bit(amikbd_keycode[i], amikbd_dev.keybit);

will be called in the above code.



2002-01-31 23:45:37

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers


> > + scancode = scancode >> 1; /* lowest bit is release bit */
> > + down = scancode & 1;
>
> Shouldn't that be the other way 'round?

I don't know. Anyone?

2002-01-31 23:56:47

by Simon Richter

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

On Thu, 31 Jan 2002, James Simmons wrote:

> > > + scancode = scancode >> 1; /* lowest bit is release bit */
> > > + down = scancode & 1;

> > Shouldn't that be the other way 'round?

> I don't know. Anyone?

Me neither, this just looked weird to me, since this code is equivalent to

down = (scancode & 2) >> 1;
scancode = scancode >> 1;

and this is not what I'd expect from the comment. :-)

Simon

--
GPG public key available from http://phobos.fs.tum.de/pgp/Simon.Richter.asc
Fingerprint: DC26 EB8D 1F35 4F44 2934 7583 DBB6 F98D 9198 3292
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!

2002-02-01 00:10:37

by Roman Zippel

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

Hi,

James Simmons wrote:

> > > + scancode = scancode >> 1; /* lowest bit is release bit */
> > > + down = scancode & 1;
> >
> > Shouldn't that be the other way 'round?
>
> I don't know. Anyone?

He's correct, the up/down event is received in the lsb bit, the other 7
bits are the keycode.

bye, Roman

2002-02-01 00:13:47

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers


> > > > + scancode = scancode >> 1; /* lowest bit is release bit */
> > > > + down = scancode & 1;
> > >
> > > Shouldn't that be the other way 'round?
> >
> > I don't know. Anyone?
>
> He's correct, the up/down event is received in the lsb bit, the other 7
> bits are the keycode.

Okay that has been fixed now :-) Another patch is coming your way.


2002-02-01 00:23:47

by James Simmons

[permalink] [raw]
Subject: [PATCH] amiga input api drivers III


Okay. This patch should now work. Give it a try. Remember also the amiga
joystick and mouse are alredy in the Dave Jones tree waiting to be tested
:-)

diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/arch/m68k/amiga/config.c linux/arch/m68k/amiga/config.c
--- linux-2.5.2-dj7/arch/m68k/amiga/config.c Wed Jan 16 10:31:50 2002
+++ linux/arch/m68k/amiga/config.c Thu Jan 31 16:38:00 2002
@@ -69,11 +69,13 @@
extern char m68k_debug_device[];

static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
+#ifndef CONFIG_KEYBOARD_AMIGA
/* amiga specific keyboard functions */
extern int amiga_keyb_init(void);
extern int amiga_kbdrate (struct kbd_repeat *);
extern int amiga_kbd_translate(unsigned char keycode, unsigned char *keycodep,
char raw_mode);
+#endif
/* amiga specific irq functions */
extern void amiga_init_IRQ (void);
extern void (*amiga_default_handler[]) (int, void *, struct pt_regs *);
@@ -389,9 +391,11 @@
request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);

mach_sched_init = amiga_sched_init;
+#ifndef CONFIG_KEYBOARD_AMIGA
mach_keyb_init = amiga_keyb_init;
mach_kbdrate = amiga_kbdrate;
mach_kbd_translate = amiga_kbd_translate;
+#endif
SYSRQ_KEY = 0xff;
mach_init_IRQ = amiga_init_IRQ;
mach_default_handler = &amiga_default_handler;
diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/arch/ppc/amiga/config.c linux/arch/ppc/amiga/config.c
--- linux-2.5.2-dj7/arch/ppc/amiga/config.c Wed Jan 16 10:31:50 2002
+++ linux/arch/ppc/amiga/config.c Thu Jan 31 16:38:00 2002
@@ -77,9 +77,11 @@
extern char m68k_debug_device[];

static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
+#ifndef CONFIG_KEYBOARD_AMIGA
/* amiga specific keyboard functions */
extern int amiga_keyb_init(void);
extern int amiga_kbdrate (struct kbd_repeat *);
+#endif
/* amiga specific irq functions */
extern void amiga_init_IRQ (void);
extern void (*amiga_default_handler[]) (int, void *, struct pt_regs *);
@@ -409,8 +411,10 @@
request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);

mach_sched_init = amiga_sched_init;
+#ifndef CONFIG_KEYBOARD_AMIGA
mach_keyb_init = amiga_keyb_init;
mach_kbdrate = amiga_kbdrate;
+#endif
mach_init_IRQ = amiga_init_IRQ;
mach_default_handler = &amiga_default_handler;
#ifndef CONFIG_APUS
diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/arch/ppc/kernel/apus_setup.c linux/arch/ppc/kernel/apus_setup.c
--- linux-2.5.2-dj7/arch/ppc/kernel/apus_setup.c Mon Dec 17 11:16:56 2001
+++ linux/arch/ppc/kernel/apus_setup.c Thu Jan 31 16:38:00 2002
@@ -801,9 +801,11 @@
static void apus_kbd_init_hw(void)
{
#ifdef CONFIG_APUS
+#ifndef CONFIG_KEYBOARD_AMIGA
extern int amiga_keyb_init(void);

amiga_keyb_init();
+#endif
#endif
}

diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/drivers/input/keyboard/Config.in linux/drivers/input/keyboard/Config.in
--- linux-2.5.2-dj7/drivers/input/keyboard/Config.in Tue Jan 29 17:36:39 2002
+++ linux/drivers/input/keyboard/Config.in Thu Jan 31 16:38:00 2002
@@ -12,3 +12,7 @@
if [ "$CONFIG_SH_DREAMCAST" = "y" ]; then
dep_tristate ' Maple bus keyboard support' CONFIG_KEYBOARD_MAPLE $CONFIG_INPUT $CONFIG_INPUT_KEYBOARD $CONFIG_MAPLE
fi
+
+if [ "$CONFIG_AMIGA" = "y" ]; then
+ dep_tristate ' Amiga keyboard' CONFIG_KEYBOARD_AMIKBD $CONFIG_INPUT $CONFIG_INPUT_KEYBOARD
+fi
diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/drivers/input/keyboard/Makefile linux/drivers/input/keyboard/Makefile
--- linux-2.5.2-dj7/drivers/input/keyboard/Makefile Tue Jan 29 17:36:39 2002
+++ linux/drivers/input/keyboard/Makefile Thu Jan 31 16:38:00 2002
@@ -13,6 +13,7 @@
obj-$(CONFIG_KEYBOARD_PS2SERKBD) += ps2serkbd.o
obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o
obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o
+obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o

# The global Rules.make.

diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/drivers/input/keyboard/amikbd.c linux/drivers/input/keyboard/amikbd.c
--- linux-2.5.2-dj7/drivers/input/keyboard/amikbd.c Wed Dec 31 16:00:00 1969
+++ linux/drivers/input/keyboard/amikbd.c Thu Jan 31 17:11:00 2002
@@ -0,0 +1,140 @@
+/*
+ * $Id: amikbd.c,v 1.12 2002/02/01 00:12:27 jsimmons 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 <[email protected]>, 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 <asm/amigaints.h>
+#include <asm/amigahw.h>
+#include <asm/irq.h>
+
+MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
+MODULE_DESCRIPTION("Amiga keyboard driver");
+MODULE_LICENSE("GPL");
+
+static unsigned char amikbd_keycode[0x78] = {
+ 41, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 43, 0, 82,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 0, 79, 80, 81,
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 0, 0, 75, 76, 77,
+ 0, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 0, 83, 71, 72, 73,
+ 57, 14, 15, 96, 28, 1,111, 0, 0, 0, 74, 0,103,108,106,105,
+ 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 98, 55, 78, 87,
+ 42, 54, 58, 29, 56,100
+}
+
+static char *amikbd_messages[] = {
+ KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
+ KERN_WARNING "amikbd: keyboard lost sync\n",
+ KERN_WARNING "amikbd: keyboard buffer overflow\n",
+ KERN_WARNING "amikbd: keyboard controller failure\n",
+ KERN_ERR "amikbd: keyboard selftest failure\n",
+ KERN_INFO "amikbd: initiate power-up key stream\n",
+ KERN_INFO "amikbd: terminate power-up key stream\n",
+ KERN_WARNING "amikbd: keyboard interrupt\n"
+};
+
+static struct input_dev amikbd_dev;
+
+static char *amikbd_name = "Amiga keyboard";
+static char *amikbd_phys = "amikbd/input0";
+
+static void amikbd_interrupt(int irq, void *dummy, struct pt_regs *fp)
+{
+ 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 = scancode >> 1;
+
+ if (scancode < 0x78) { /* scancodes < 0x78 are keys */
+
+ scancode = amikbd_keycode[scancode];
+
+ if (scancode == KEY_CAPS) { /* CapsLock is a toggle switch key on Amiga */
+ input_report_key(&amikbd_dev, scancode, 1);
+ input_report_key(&amikbd_dev, scancode, 0);
+ return;
+ }
+
+ input_report_key(&amikbd_dev, scancode, down);
+
+ return;
+ }
+
+ printk(amikbd_messages[scancode - 0x78]); /* scancodes >= 0x78 are error codes */
+}
+
+static int __init amikbd_init(void)
+{
+ int i;
+
+ if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
+ return -EIO;
+
+ amikbd_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
+ amikbd_dev.keycode = amikbd_keycode;
+
+ for (i = 0; i < 0x78; i++)
+ if (amikbd_keycode[i])
+ set_bit(amikbd_keycode[i], amikbd_dev.keybit);
+
+ ciaa.cra &= ~0x41; /* serial data in, turn off TA */
+ request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd", NULL);
+
+ amikbd_dev.name = amikbd_name;
+ amikbd_dev.phys = amikbd_phys;
+ amikbd_dev.idbus = BUS_AMIGA;
+ amikbd_dev.idvendor = 0x0001;
+ amikbd_dev.idproduct = 0x0001;
+ amikbd_dev.idversion = 0x0100;
+
+ input_register_device(&amikbd_dev);
+
+ printk(KERN_INFO "input: %s\n", amikbd_name);
+
+ return 0;
+}
+
+static void __exit amikbd_exit(void)
+{
+ input_unregister_device(&amikbd_dev);
+ free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
+}
+
+module_init(amikbd_init);
+module_exit(amikbd_exit);

2002-02-01 00:47:38

by Simon Richter

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

On Fri, 1 Feb 2002, Roman Zippel wrote:

> > > > + scancode = scancode >> 1; /* lowest bit is release bit */
> > > > + down = scancode & 1;

> He's correct, the up/down event is received in the lsb bit, the other 7
> bits are the keycode.

Well, I'm also unsure you mean the LSB here -- The hardware manual says
that bit 7 indicates that the key had been released.

Simon

--
GPG public key available from http://phobos.fs.tum.de/pgp/Simon.Richter.asc
Fingerprint: DC26 EB8D 1F35 4F44 2934 7583 DBB6 F98D 9198 3292
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!

2002-02-01 07:15:08

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

On Thu, Jan 31, 2002 at 09:54:51PM +0100, Geert Uytterhoeven wrote:
> On Thu, 31 Jan 2002, James Simmons wrote:
> > The amiga mouse and amiga joystick have been already ported over to the
> > input api. Now for the keyboard. This patch is the input api amiga
> > keyboard. I wanted people to try it out before I send it off to be
> > included in the DJ tree. Have fun!!!
>
> > diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/drivers/input/keyboard/amikbd.c linux/drivers/input/keyboard/amikbd.c
> > --- linux-2.5.2-dj7/drivers/input/keyboard/amikbd.c Wed Dec 31 16:00:00 1969
> > +++ linux/drivers/input/keyboard/amikbd.c Thu Jan 31 07:44:05 2002
>
> > +static char *amikbd_messages[] = {
> > + KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
> > + KERN_WARNING "amikbd: keyboard lost sync\n",
> > + KERN_WARNING "amikbd: keyboard buffer overflow\n",
> > + KERN_WARNING "amikbd: keyboard controller failure\n",
> > + KERN_ERR "amikbd: keyboard selftest failure\n",
> > + KERN_INFO "amikbd: initiate power-up key stream\n",
> > + KERN_INFO "amikbd: terminate power-up key stream\n",
> > + KERN_WARNING "amikbd: keyboard interrupt\n"
> > +};
>
> > + if (scancode < 0x78) { /* scancodes < 0x78 are keys */
>
> [...]
>
> > + }
> > +
> > + printk(amikbd_messages[scancode]); /* scancodes >= 0x78 are error codes */
>
> Oops, amikbd_messages[scancode-0x78]?

Thanks. And thanks to James for fixing this in the CVS as well.
Does it work otherwise?

--
Vojtech Pavlik
SuSE Labs

2002-02-01 09:14:34

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

On Fri, 1 Feb 2002, Vojtech Pavlik wrote:
> On Thu, Jan 31, 2002 at 09:54:51PM +0100, Geert Uytterhoeven wrote:
> > On Thu, 31 Jan 2002, James Simmons wrote:
> > > The amiga mouse and amiga joystick have been already ported over to the
> > > input api. Now for the keyboard. This patch is the input api amiga
> > > keyboard. I wanted people to try it out before I send it off to be
> > > included in the DJ tree. Have fun!!!

[...]

> > Oops, amikbd_messages[scancode-0x78]?
>
> Thanks. And thanks to James for fixing this in the CVS as well.
> Does it work otherwise?

No idea (yet).

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2002-02-01 09:24:14

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers III

On Thu, 31 Jan 2002, James Simmons wrote:
> Okay. This patch should now work. Give it a try. Remember also the amiga
> joystick and mouse are alredy in the Dave Jones tree waiting to be tested
> :-)
>
> diff -urN -X /home/jsimmons/dontdiff linux-2.5.2-dj7/drivers/input/keyboard/amikbd.c linux/drivers/input/keyboard/amikbd.c
> --- linux-2.5.2-dj7/drivers/input/keyboard/amikbd.c Wed Dec 31 16:00:00 1969
> +++ linux/drivers/input/keyboard/amikbd.c Thu Jan 31 17:11:00 2002

> +static int __init amikbd_init(void)
> +{
> + int i;
> +
> + if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
> + return -EIO;

Please add

if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb"))
return -EBUSY;

here (cfr. drivers/char/amikeyb.c).

> +static void __exit amikbd_exit(void)
> +{
> + input_unregister_device(&amikbd_dev);
> + free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);

And

release_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100);

here.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2002-02-01 09:17:54

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

On Fri, 1 Feb 2002, Simon Richter wrote:
> On Fri, 1 Feb 2002, Roman Zippel wrote:
> > > > > + scancode = scancode >> 1; /* lowest bit is release bit */
> > > > > + down = scancode & 1;
>
> > He's correct, the up/down event is received in the lsb bit, the other 7
> > bits are the keycode.
>
> Well, I'm also unsure you mean the LSB here -- The hardware manual says
> that bit 7 indicates that the key had been released.

Yes, but that's after rotating. The old code did

/* rotate scan code to get up/down bit in proper position */
scancode = ((scancode >> 1) & 0x7f) | ((scancode << 7) & 0x80);

first.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2002-02-13 18:02:16

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers


Another try at the amiga input keyboard driver. Here you go. Please apply

diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/arch/m68k/amiga/config.c linux/arch/m68k/amiga/config.c
--- linux-2.5.4-dj1/arch/m68k/amiga/config.c Wed Jan 16 10:31:50 2002
+++ linux/arch/m68k/amiga/config.c Wed Feb 13 10:26:42 2002
@@ -69,11 +69,13 @@
extern char m68k_debug_device[];

static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
+#ifndef CONFIG_KEYBOARD_AMIGA
/* amiga specific keyboard functions */
extern int amiga_keyb_init(void);
extern int amiga_kbdrate (struct kbd_repeat *);
extern int amiga_kbd_translate(unsigned char keycode, unsigned char *keycodep,
char raw_mode);
+#endif
/* amiga specific irq functions */
extern void amiga_init_IRQ (void);
extern void (*amiga_default_handler[]) (int, void *, struct pt_regs *);
@@ -389,9 +391,11 @@
request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);

mach_sched_init = amiga_sched_init;
+#ifndef CONFIG_KEYBOARD_AMIGA
mach_keyb_init = amiga_keyb_init;
mach_kbdrate = amiga_kbdrate;
mach_kbd_translate = amiga_kbd_translate;
+#endif
SYSRQ_KEY = 0xff;
mach_init_IRQ = amiga_init_IRQ;
mach_default_handler = &amiga_default_handler;
diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/arch/ppc/amiga/config.c linux/arch/ppc/amiga/config.c
--- linux-2.5.4-dj1/arch/ppc/amiga/config.c Wed Jan 16 10:31:50 2002
+++ linux/arch/ppc/amiga/config.c Wed Feb 13 10:26:42 2002
@@ -77,9 +77,11 @@
extern char m68k_debug_device[];

static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
+#ifndef CONFIG_KEYBOARD_AMIGA
/* amiga specific keyboard functions */
extern int amiga_keyb_init(void);
extern int amiga_kbdrate (struct kbd_repeat *);
+#endif
/* amiga specific irq functions */
extern void amiga_init_IRQ (void);
extern void (*amiga_default_handler[]) (int, void *, struct pt_regs *);
@@ -409,8 +411,10 @@
request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);

mach_sched_init = amiga_sched_init;
+#ifndef CONFIG_KEYBOARD_AMIGA
mach_keyb_init = amiga_keyb_init;
mach_kbdrate = amiga_kbdrate;
+#endif
mach_init_IRQ = amiga_init_IRQ;
mach_default_handler = &amiga_default_handler;
#ifndef CONFIG_APUS
diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/arch/ppc/kernel/apus_setup.c linux/arch/ppc/kernel/apus_setup.c
--- linux-2.5.4-dj1/arch/ppc/kernel/apus_setup.c Mon Dec 17 11:16:56 2001
+++ linux/arch/ppc/kernel/apus_setup.c Wed Feb 13 10:26:42 2002
@@ -801,9 +801,11 @@
static void apus_kbd_init_hw(void)
{
#ifdef CONFIG_APUS
+#ifndef CONFIG_KEYBOARD_AMIGA
extern int amiga_keyb_init(void);

amiga_keyb_init();
+#endif
#endif
}

diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/drivers/input/keyboard/Config.help linux/drivers/input/keyboard/Config.help
--- linux-2.5.4-dj1/drivers/input/keyboard/Config.help Tue Feb 12 10:48:06 2002
+++ linux/drivers/input/keyboard/Config.help Wed Feb 13 10:30:17 2002
@@ -55,3 +55,12 @@
The module will be called maple_keyb.o. If you want to compile it as a
module, say M here and read <file:Documentation/modules.txt>.

+CONFIG_KEYBOARD_AMIGA
+ Say Y here if you are running Linux on a m68k amiga and have a keyboard
+ attached.
+
+ This driver is also available as a module ( = code which can be
+ inserted in and removed from the running kernel whenever you want).
+ The module will be called maple_keyb.o. If you want to compile it as a
+ module, say M here and read <file:Documentation/modules.txt>.
+
diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/drivers/input/keyboard/Config.in linux/drivers/input/keyboard/Config.in
--- linux-2.5.4-dj1/drivers/input/keyboard/Config.in Tue Feb 12 10:48:06 2002
+++ linux/drivers/input/keyboard/Config.in Wed Feb 13 10:28:55 2002
@@ -12,3 +12,7 @@
if [ "$CONFIG_SH_DREAMCAST" = "y" ]; then
dep_tristate ' Maple bus keyboard support' CONFIG_KEYBOARD_MAPLE $CONFIG_INPUT $CONFIG_INPUT_KEYBOARD $CONFIG_MAPLE
fi
+
+if [ "$CONFIG_AMIGA" = "y" ]; then
+ dep_tristate ' Amiga keyboard' CONFIG_KEYBOARD_AMIGA $CONFIG_INPUT $CONFIG_INPUT_KEYBOARD
+fi
diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/drivers/input/keyboard/Makefile linux/drivers/input/keyboard/Makefile
--- linux-2.5.4-dj1/drivers/input/keyboard/Makefile Tue Feb 12 10:48:06 2002
+++ linux/drivers/input/keyboard/Makefile Wed Feb 13 10:26:42 2002
@@ -13,6 +13,7 @@
obj-$(CONFIG_KEYBOARD_PS2SERKBD) += ps2serkbd.o
obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o
obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o
+obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o

# The global Rules.make.

diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/drivers/input/keyboard/amikbd.c linux/drivers/input/keyboard/amikbd.c
--- linux-2.5.4-dj1/drivers/input/keyboard/amikbd.c Wed Dec 31 16:00:00 1969
+++ linux/drivers/input/keyboard/amikbd.c Wed Feb 13 10:27:09 2002
@@ -0,0 +1,144 @@
+/*
+ * $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 <[email protected]>, 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 <asm/amigaints.h>
+#include <asm/amigahw.h>
+#include <asm/irq.h>
+
+MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
+MODULE_DESCRIPTION("Amiga keyboard driver");
+MODULE_LICENSE("GPL");
+
+static unsigned char amikbd_keycode[0x78] = {
+ 41, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 43, 0, 82,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 0, 79, 80, 81,
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 0, 0, 75, 76, 77,
+ 0, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 0, 83, 71, 72, 73,
+ 57, 14, 15, 96, 28, 1,111, 0, 0, 0, 74, 0,103,108,106,105,
+ 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 98, 55, 78, 87,
+ 42, 54, 58, 29, 56,100
+}
+
+static char *amikbd_messages[] = {
+ KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
+ KERN_WARNING "amikbd: keyboard lost sync\n",
+ KERN_WARNING "amikbd: keyboard buffer overflow\n",
+ KERN_WARNING "amikbd: keyboard controller failure\n",
+ KERN_ERR "amikbd: keyboard selftest failure\n",
+ KERN_INFO "amikbd: initiate power-up key stream\n",
+ KERN_INFO "amikbd: terminate power-up key stream\n",
+ KERN_WARNING "amikbd: keyboard interrupt\n"
+};
+
+static struct input_dev amikbd_dev;
+
+static char *amikbd_name = "Amiga keyboard";
+static char *amikbd_phys = "amikbd/input0";
+
+static void amikbd_interrupt(int irq, void *dummy, struct pt_regs *fp)
+{
+ 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 = scancode >> 1;
+
+ if (scancode < 0x78) { /* scancodes < 0x78 are keys */
+
+ scancode = amikbd_keycode[scancode];
+
+ if (scancode == KEY_CAPS) { /* CapsLock is a toggle switch key on Amiga */
+ input_report_key(&amikbd_dev, scancode, 1);
+ input_report_key(&amikbd_dev, scancode, 0);
+ return;
+ }
+
+ input_report_key(&amikbd_dev, scancode, down);
+
+ return;
+ }
+
+ printk(amikbd_messages[scancode - 0x78]); /* scancodes >= 0x78 are error codes */
+}
+
+static int __init amikbd_init(void)
+{
+ int i;
+
+ if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
+ return -EIO;
+
+ if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb"))
+ return -EBUSY;
+
+ amikbd_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
+ amikbd_dev.keycode = amikbd_keycode;
+
+ for (i = 0; i < 0x78; i++)
+ if (amikbd_keycode[i])
+ set_bit(amikbd_keycode[i], amikbd_dev.keybit);
+
+ ciaa.cra &= ~0x41; /* serial data in, turn off TA */
+ request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd", NULL);
+
+ amikbd_dev.name = amikbd_name;
+ amikbd_dev.phys = amikbd_phys;
+ amikbd_dev.idbus = BUS_AMIGA;
+ amikbd_dev.idvendor = 0x0001;
+ amikbd_dev.idproduct = 0x0001;
+ amikbd_dev.idversion = 0x0100;
+
+ input_register_device(&amikbd_dev);
+
+ printk(KERN_INFO "input: %s\n", amikbd_name);
+
+ return 0;
+}
+
+static void __exit amikbd_exit(void)
+{
+ input_unregister_device(&amikbd_dev);
+ free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
+ release_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100);
+}
+
+module_init(amikbd_init);
+module_exit(amikbd_exit);


2002-02-13 18:11:33

by Simon Richter

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

On Wed, 13 Feb 2002, James Simmons wrote:

> diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/drivers/input/keyboard/Config.help linux/drivers/input/keyboard/Config.help
> --- linux-2.5.4-dj1/drivers/input/keyboard/Config.help Tue Feb 12 10:48:06 2002
> +++ linux/drivers/input/keyboard/Config.help Wed Feb 13 10:30:17 2002
> @@ -55,3 +55,12 @@
> The module will be called maple_keyb.o. If you want to compile it as a
> module, say M here and read <file:Documentation/modules.txt>.
>
> +CONFIG_KEYBOARD_AMIGA
> + Say Y here if you are running Linux on a m68k amiga and have a keyboard
> + attached.
> +
> + This driver is also available as a module ( = code which can be
> + inserted in and removed from the running kernel whenever you want).
> + The module will be called maple_keyb.o. If you want to compile it as a

Is the module name correct?

Simon

--
GPG public key available from http://phobos.fs.tum.de/pgp/Simon.Richter.asc
Fingerprint: DC26 EB8D 1F35 4F44 2934 7583 DBB6 F98D 9198 3292
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!

2002-02-13 18:19:34

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

On Wed, 13 Feb 2002, James Simmons wrote:
> Another try at the amiga input keyboard driver. Here you go. Please apply
>
> diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/drivers/input/keyboard/Config.help linux/drivers/input/keyboard/Config.help
> --- linux-2.5.4-dj1/drivers/input/keyboard/Config.help Tue Feb 12 10:48:06 2002
> +++ linux/drivers/input/keyboard/Config.help Wed Feb 13 10:30:17 2002
> @@ -55,3 +55,12 @@
> The module will be called maple_keyb.o. If you want to compile it as a
> module, say M here and read <file:Documentation/modules.txt>.
>
> +CONFIG_KEYBOARD_AMIGA
> + Say Y here if you are running Linux on a m68k amiga and have a keyboard
^^^^^^^^^^
> + attached.

I see no reason (assumed it works on the m68k Amigas) why it wouldn't work on
PPC Amigas (that's APUS, i.e. a m68k Amiga with a PPC expansion board).

And please capitalize the word `Amiga' :-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2002-02-13 19:26:07

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers


> Is the module name correct?

Nope. My mistake.

> I see no reason (assumed it works on the m68k Amigas) why it wouldn't
> work on PPC Amigas (that's APUS, i.e. a m68k Amiga with a PPC expansion
> board).
>
> And please capitalize the word `Amiga' :-)

Done. Here is another patch.

diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/arch/m68k/amiga/config.c linux/arch/m68k/amiga/config.c
--- linux-2.5.4-dj1/arch/m68k/amiga/config.c Wed Jan 16 10:31:50 2002
+++ linux/arch/m68k/amiga/config.c Wed Feb 13 10:26:42 2002
@@ -69,11 +69,13 @@
extern char m68k_debug_device[];

static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
+#ifndef CONFIG_KEYBOARD_AMIGA
/* amiga specific keyboard functions */
extern int amiga_keyb_init(void);
extern int amiga_kbdrate (struct kbd_repeat *);
extern int amiga_kbd_translate(unsigned char keycode, unsigned char *keycodep,
char raw_mode);
+#endif
/* amiga specific irq functions */
extern void amiga_init_IRQ (void);
extern void (*amiga_default_handler[]) (int, void *, struct pt_regs *);
@@ -389,9 +391,11 @@
request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);

mach_sched_init = amiga_sched_init;
+#ifndef CONFIG_KEYBOARD_AMIGA
mach_keyb_init = amiga_keyb_init;
mach_kbdrate = amiga_kbdrate;
mach_kbd_translate = amiga_kbd_translate;
+#endif
SYSRQ_KEY = 0xff;
mach_init_IRQ = amiga_init_IRQ;
mach_default_handler = &amiga_default_handler;
diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/arch/ppc/amiga/config.c linux/arch/ppc/amiga/config.c
--- linux-2.5.4-dj1/arch/ppc/amiga/config.c Wed Jan 16 10:31:50 2002
+++ linux/arch/ppc/amiga/config.c Wed Feb 13 10:26:42 2002
@@ -77,9 +77,11 @@
extern char m68k_debug_device[];

static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
+#ifndef CONFIG_KEYBOARD_AMIGA
/* amiga specific keyboard functions */
extern int amiga_keyb_init(void);
extern int amiga_kbdrate (struct kbd_repeat *);
+#endif
/* amiga specific irq functions */
extern void amiga_init_IRQ (void);
extern void (*amiga_default_handler[]) (int, void *, struct pt_regs *);
@@ -409,8 +411,10 @@
request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);

mach_sched_init = amiga_sched_init;
+#ifndef CONFIG_KEYBOARD_AMIGA
mach_keyb_init = amiga_keyb_init;
mach_kbdrate = amiga_kbdrate;
+#endif
mach_init_IRQ = amiga_init_IRQ;
mach_default_handler = &amiga_default_handler;
#ifndef CONFIG_APUS
diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/arch/ppc/kernel/apus_setup.c linux/arch/ppc/kernel/apus_setup.c
--- linux-2.5.4-dj1/arch/ppc/kernel/apus_setup.c Mon Dec 17 11:16:56 2001
+++ linux/arch/ppc/kernel/apus_setup.c Wed Feb 13 10:26:42 2002
@@ -801,9 +801,11 @@
static void apus_kbd_init_hw(void)
{
#ifdef CONFIG_APUS
+#ifndef CONFIG_KEYBOARD_AMIGA
extern int amiga_keyb_init(void);

amiga_keyb_init();
+#endif
#endif
}

diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/drivers/input/keyboard/Config.help linux/drivers/input/keyboard/Config.help
--- linux-2.5.4-dj1/drivers/input/keyboard/Config.help Tue Feb 12 10:48:06 2002
+++ linux/drivers/input/keyboard/Config.help Wed Feb 13 10:30:17 2002
@@ -55,3 +55,12 @@
The module will be called maple_keyb.o. If you want to compile it as a
module, say M here and read <file:Documentation/modules.txt>.

+CONFIG_KEYBOARD_AMIGA
+ Say Y here if you are running Linux on any AMIGA and have a keyboard
+ attached.
+
+ This driver is also available as a module ( = code which can be
+ inserted in and removed from the running kernel whenever you want).
+ The module will be called amikbd.o. If you want to compile it as a
+ module, say M here and read <file:Documentation/modules.txt>.
+
diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/drivers/input/keyboard/Config.in linux/drivers/input/keyboard/Config.in
--- linux-2.5.4-dj1/drivers/input/keyboard/Config.in Tue Feb 12 10:48:06 2002
+++ linux/drivers/input/keyboard/Config.in Wed Feb 13 10:28:55 2002
@@ -12,3 +12,7 @@
if [ "$CONFIG_SH_DREAMCAST" = "y" ]; then
dep_tristate ' Maple bus keyboard support' CONFIG_KEYBOARD_MAPLE $CONFIG_INPUT $CONFIG_INPUT_KEYBOARD $CONFIG_MAPLE
fi
+
+if [ "$CONFIG_AMIGA" = "y" ]; then
+ dep_tristate ' Amiga keyboard' CONFIG_KEYBOARD_AMIGA $CONFIG_INPUT $CONFIG_INPUT_KEYBOARD
+fi
diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/drivers/input/keyboard/Makefile linux/drivers/input/keyboard/Makefile
--- linux-2.5.4-dj1/drivers/input/keyboard/Makefile Tue Feb 12 10:48:06 2002
+++ linux/drivers/input/keyboard/Makefile Wed Feb 13 10:26:42 2002
@@ -13,6 +13,7 @@
obj-$(CONFIG_KEYBOARD_PS2SERKBD) += ps2serkbd.o
obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o
obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o
+obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o

# The global Rules.make.

diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/drivers/input/keyboard/amikbd.c linux/drivers/input/keyboard/amikbd.c
--- linux-2.5.4-dj1/drivers/input/keyboard/amikbd.c Wed Dec 31 16:00:00 1969
+++ linux/drivers/input/keyboard/amikbd.c Wed Feb 13 10:27:09 2002
@@ -0,0 +1,144 @@
+/*
+ * $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 <[email protected]>, 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 <asm/amigaints.h>
+#include <asm/amigahw.h>
+#include <asm/irq.h>
+
+MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
+MODULE_DESCRIPTION("Amiga keyboard driver");
+MODULE_LICENSE("GPL");
+
+static unsigned char amikbd_keycode[0x78] = {
+ 41, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 43, 0, 82,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 0, 79, 80, 81,
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 0, 0, 75, 76, 77,
+ 0, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 0, 83, 71, 72, 73,
+ 57, 14, 15, 96, 28, 1,111, 0, 0, 0, 74, 0,103,108,106,105,
+ 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 98, 55, 78, 87,
+ 42, 54, 58, 29, 56,100
+}
+
+static char *amikbd_messages[] = {
+ KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
+ KERN_WARNING "amikbd: keyboard lost sync\n",
+ KERN_WARNING "amikbd: keyboard buffer overflow\n",
+ KERN_WARNING "amikbd: keyboard controller failure\n",
+ KERN_ERR "amikbd: keyboard selftest failure\n",
+ KERN_INFO "amikbd: initiate power-up key stream\n",
+ KERN_INFO "amikbd: terminate power-up key stream\n",
+ KERN_WARNING "amikbd: keyboard interrupt\n"
+};
+
+static struct input_dev amikbd_dev;
+
+static char *amikbd_name = "Amiga keyboard";
+static char *amikbd_phys = "amikbd/input0";
+
+static void amikbd_interrupt(int irq, void *dummy, struct pt_regs *fp)
+{
+ 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 = scancode >> 1;
+
+ if (scancode < 0x78) { /* scancodes < 0x78 are keys */
+
+ scancode = amikbd_keycode[scancode];
+
+ if (scancode == KEY_CAPS) { /* CapsLock is a toggle switch key on Amiga */
+ input_report_key(&amikbd_dev, scancode, 1);
+ input_report_key(&amikbd_dev, scancode, 0);
+ return;
+ }
+
+ input_report_key(&amikbd_dev, scancode, down);
+
+ return;
+ }
+
+ printk(amikbd_messages[scancode - 0x78]); /* scancodes >= 0x78 are error codes */
+}
+
+static int __init amikbd_init(void)
+{
+ int i;
+
+ if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
+ return -EIO;
+
+ if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb"))
+ return -EBUSY;
+
+ amikbd_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
+ amikbd_dev.keycode = amikbd_keycode;
+
+ for (i = 0; i < 0x78; i++)
+ if (amikbd_keycode[i])
+ set_bit(amikbd_keycode[i], amikbd_dev.keybit);
+
+ ciaa.cra &= ~0x41; /* serial data in, turn off TA */
+ request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd", NULL);
+
+ amikbd_dev.name = amikbd_name;
+ amikbd_dev.phys = amikbd_phys;
+ amikbd_dev.idbus = BUS_AMIGA;
+ amikbd_dev.idvendor = 0x0001;
+ amikbd_dev.idproduct = 0x0001;
+ amikbd_dev.idversion = 0x0100;
+
+ input_register_device(&amikbd_dev);
+
+ printk(KERN_INFO "input: %s\n", amikbd_name);
+
+ return 0;
+}
+
+static void __exit amikbd_exit(void)
+{
+ input_unregister_device(&amikbd_dev);
+ free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
+ release_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100);
+}
+
+module_init(amikbd_init);
+module_exit(amikbd_exit);

2002-02-14 07:11:36

by Horst von Brand

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers

James Simmons <[email protected]> said:

[...]

> Done. Here is another patch.
>
> diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/arch/m68k/amiga/config.c l
> inux/arch/m68k/amiga/config.c
> --- linux-2.5.4-dj1/arch/m68k/amiga/config.c Wed Jan 16 10:31:50 2002
> +++ linux/arch/m68k/amiga/config.c Wed Feb 13 10:26:42 2002
> @@ -69,11 +69,13 @@
> extern char m68k_debug_device[];
>
> static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
> +#ifndef CONFIG_KEYBOARD_AMIGA
> /* amiga specific keyboard functions */
> extern int amiga_keyb_init(void);
> extern int amiga_kbdrate (struct kbd_repeat *);
> extern int amiga_kbd_translate(unsigned char keycode, unsigned char *keycodep,
> char raw_mode);
> +#endif

The #ifdef isn't needed: As long as the functions aren't used, gcc won't
mind them declared if they aren't around.

[...]

> --- linux-2.5.4-dj1/arch/ppc/amiga/config.c Wed Jan 16 10:31:50 2002
> +++ linux/arch/ppc/amiga/config.c Wed Feb 13 10:26:42 2002
> @@ -77,9 +77,11 @@
> extern char m68k_debug_device[];
>
> static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
> +#ifndef CONFIG_KEYBOARD_AMIGA
> /* amiga specific keyboard functions */
> extern int amiga_keyb_init(void);
> extern int amiga_kbdrate (struct kbd_repeat *);
> +#endif

As above.
--
Horst von Brand http://counter.li.org # 22616

2002-02-14 20:29:55

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH] amiga input api drivers


> > diff -urN -X /home/jsimmons/dontdiff linux-2.5.4-dj1/arch/m68k/amiga/config.c l
> > inux/arch/m68k/amiga/config.c
> > --- linux-2.5.4-dj1/arch/m68k/amiga/config.c Wed Jan 16 10:31:50 2002
> > +++ linux/arch/m68k/amiga/config.c Wed Feb 13 10:26:42 2002
> > @@ -69,11 +69,13 @@
> > extern char m68k_debug_device[];
> >
> > static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
> > +#ifndef CONFIG_KEYBOARD_AMIGA
> > /* amiga specific keyboard functions */
> > extern int amiga_keyb_init(void);
> > extern int amiga_kbdrate (struct kbd_repeat *);
> > extern int amiga_kbd_translate(unsigned char keycode, unsigned char *keycodep,
> > char raw_mode);
> > +#endif
>
> The #ifdef isn't needed: As long as the functions aren't used, gcc won't
> mind them declared if they aren't around.

Personally I like to see all the mach_kbd* etc go away.