Skip to contentSkip to conversation

Input issues - key down with no key up

PATCH Neil Brown 8 participants 62 messages Aug 15, 2003 – Sep 8, 2003 Input drivers

lore
Share & tools
lore

Neil Brown

author
#0 lore raw

Hi,

I have a notebook (Dell Latitude D800) which has some keys (actual fn+something combinations) that generate Down events but no Up events (clever, isn't it).

This makes those keys unusable with 2.6.0 as it is because the input layer insists on there being up events. Once it sees a down, it will ignore any future down events until it sees an up event. It will also auto-repeat the key until some other key is pressed. On the whole, not very useful for these keys.

After some thought, the simplest way I could think of to fix it was to have a bitmap of keys that don't generate up events themselves. For these keys the auto-repeat code can then generate an "UP" event (val==0) instead of a "repeat" event (val==2) after the timeout.

The following patch does that and I can now use those keys (after using the relevant ioctl to associate the scan code with a keycode).

This may not be the best way to do it, and I am happy to discuss other approaches, including different ioctls for getting the new status bits into and out-of the kernel.

NeilBrown

----------- Diffstat output ------------

 ./drivers/input/evdev.c |   13 +++++++++++++
 ./drivers/input/input.c |    7 +++++--
 ./include/linux/input.h |    3 +++
 3 files changed, 21 insertions(+), 2 deletions(-)
drivers/input/evdev.c renamed from drivers/input/evdev.c~current~ +13 -0
diff ./drivers/input/evdev.c~current~ ./drivers/input/evdev.c
@@ -246,9 +246,21 @@ static int evdev_ioctl(struct inode *ino
 				if(INPUT_KEYCODE(dev, t) == u) break;
 			if (i == dev->keycodemax) clear_bit(u, dev->keybit);
 			set_bit(INPUT_KEYCODE(dev, t), dev->keybit);
+			clear_bit(INPUT_KEYCODE(dev, t), dev->key);
 
 			return 0;
 
+		case EVIOCSKEYNOUP:
+			if (get_user(t, ((int *) arg) + 0)) return -EFAULT;
+			if (t < 0 || t > dev->keycodemax) return -EINVAL;
+			if (get_user(u, ((int *) arg) + 1)) return -EFAULT;
+			if (u & ~1) return -EINVAL;
+			if (u)
+				set_bit(t, dev->keynoup);
+			else
+				clear_bit(t, dev->keynoup);
+			return 0;
+
 		case EVIOCSFF:
 			if (dev->upload_effect) {
 				struct ff_effect effect;
@@ -303,6 +315,7 @@ static int evdev_ioctl(struct inode *ino
 				switch (_IOC_NR(cmd) & EV_MAX) {
 					case      0: bits = dev->evbit;  len = EV_MAX;  break;
 					case EV_KEY: bits = dev->keybit; len = KEY_MAX; break;
+					case EV_REP: bits = dev->keynoup; len = KEY_MAX; break;
 					case EV_REL: bits = dev->relbit; len = REL_MAX; break;
 					case EV_ABS: bits = dev->absbit; len = ABS_MAX; break;
 					case EV_LED: bits = dev->ledbit; len = LED_MAX; break;
drivers/input/input.c renamed from drivers/input/input.c~current~ +5 -2
diff ./drivers/input/input.c~current~ ./drivers/input/input.c
@@ -191,8 +191,11 @@ static void input_repeat_key(unsigned lo
 
 	if (!test_bit(dev->repeat_key, dev->key))
 		return;
-
-	input_event(dev, EV_KEY, dev->repeat_key, 2);
+	if (test_bit(dev->repeat_key, dev->keynoup))
+		/* don't auto-repeat, just auto-up */
+		input_event(dev, EV_KEY, dev->repeat_key, 0);
+	else
+		input_event(dev, EV_KEY, dev->repeat_key, 2);
 	input_sync(dev);
 
 	mod_timer(&dev->timer, jiffies + dev->rep[REP_PERIOD]);
include/linux/input.h renamed from include/linux/input.h~current~ +3 -0
diff ./include/linux/input.h~current~ ./include/linux/input.h
@@ -60,6 +60,7 @@ struct input_absinfo {
 #define EVIOCSREP		_IOW('E', 0x03, int[2])			/* get repeat settings */
 #define EVIOCGKEYCODE		_IOR('E', 0x04, int[2])			/* get keycode */
 #define EVIOCSKEYCODE		_IOW('E', 0x04, int[2])			/* set keycode */
+#define EVIOCSKEYNOUP		_IOW('E', 0x05, int[2])			/* set 'no-repeat' bit */
 
 #define EVIOCGNAME(len)		_IOC(_IOC_READ, 'E', 0x06, len)		/* get device name */
 #define EVIOCGPHYS(len)		_IOC(_IOC_READ, 'E', 0x07, len)		/* get physical location */
@@ -790,6 +791,8 @@ struct input_dev {
 	int abs[ABS_MAX + 1];
 	int rep[REP_MAX + 1];
 
+	unsigned long keynoup[NBITS(KEY_MAX)]; /* set if key doesn't generate up event */
+
 	unsigned long key[NBITS(KEY_MAX)];
 	unsigned long led[NBITS(LED_MAX)];
 	unsigned long snd[NBITS(SND_MAX)];
#1 lore raw
Quoted 4 lines · Neil Brown

I have a notebook (Dell Latitude D800) which has some keys (actual fn+something combinations) that generate Down events but no Up events (clever, isn't it).

Quoted 8 lines

This makes those keys unusable with 2.6.0 as it is because the input layer insists on there being up events. Once it sees a down, it will ignore any future down events until it sees an up event. It will also auto-repeat the key until some other key is pressed. On the whole, not very useful for these keys.

After some thought, the simplest way I could think of to fix it was to have a bitmap of keys that don't generate up events themselves.

I think we should go for a much simpler fix: only enable the timer-induced repeat when the user asks for that (say, by boot parameter). The keyboard already knows which keys repeat and which don't.

If we forget about the kernel-invented repetition, we solve, I suppose, the problems of those people who see impossibly fast repeat, and also your problem.

Your solution, which involves an ioctl, would force changes to user space. Too inconvenient.

Andries

[By the way, I am a collector of data on strange keyboards - could you on a 2.4 system use showkey -s and tell me about the combinations without Up events? - [email protected]]

#2 lore raw
Quoted 10 lines · Andries Brouwer
Quoted 10 lines

I have a notebook (Dell Latitude D800) which has some keys (actual fn+something combinations) that generate Down events but no Up events (clever, isn't it).

This makes those keys unusable with 2.6.0 as it is because the input layer insists on there being up events. Once it sees a down, it will ignore any future down events until it sees an up event. It will also auto-repeat the key until some other key is pressed. On the whole, not very useful for these keys.

Quoted 6 lines
Quoted 2 lines

After some thought, the simplest way I could think of to fix it was to have a bitmap of keys that don't generate up events themselves.

I think we should go for a much simpler fix: only enable the timer-induced repeat when the user asks for that (say, by boot parameter). The keyboard already knows which keys repeat and which don't.

That won't solve it - the key, while not repeating would be still considered 'down' by the kernel and any more pressing of the key wouldn't do anything.

Quoted 3 lines

If we forget about the kernel-invented repetition, we solve, I suppose, the problems of those people who see impossibly fast repeat, and also your problem.

Only for those with PS/2 keyboards. We still need the kernel repeat for all other kinds of keyboards. And the impossibly fast repeat problem actually needs solving elsewhere - it's a bad interaction betwen ACPI and kernel timer, and that'll cause more trouble than just fast repeat.

Quoted 2 lines

Your solution, which involves an ioctl, would force changes to user space. Too inconvenient.

My proposed solution is to do an input_report_key(pressed) immediately followed by input_report_key(released) for these keys straight in atkbd.c. Possibly based on some flag in the scancode->keycode table for that scancode.

Quoted 3 lines

[By the way, I am a collector of data on strange keyboards - could you on a 2.4 system use showkey -s and tell me about the combinations without Up events? - [email protected]]

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#3 lore raw
Quoted 5 lines · Vojtech Pavlik
Quoted 4 lines
Quoted 4 lines

I have a notebook (Dell Latitude D800) which has some keys (actual fn+something combinations) that generate Down events but no Up events (clever, isn't it).
This makes those keys unusable with 2.6.0 as it is

Quoted 7 lines
Quoted 3 lines

I think we should go for the simple fix: only enable the timer-induced repeat when the user asks for that (say, by boot parameter). The keyboard already knows which keys repeat and which don't.

That won't solve it - the key, while not repeating would be still considered 'down' by the kernel and any more pressing of the key wouldn't do anything.

Yes, it would still be considered down. But that does not imply that pressing it doesnt do anything. It is up to the driver to discard key presses, and I think it shouldnt.
(Unless of course the user asks for that behaviour - it may be required on some broken laptops.)

Just the simple: a keypress generates an interrupt and we see a keystroke.

Use a kernel timer only when we know or the user tells us that it is needed. Not in the default situation.

Quoted 4 lines

My proposed solution is to do an input_report_key(pressed) immediately followed by input_report_key(released) for these keys straight in atkbd.c. Possibly based on some flag in the scancode->keycode table for that scancode.

But that would require users to report on precisely which keys are affected and would give complications where I suppose 2.4 did not have any. This is the way towards an ever more complicated keyboard driver. Not what you would want.

Andries

#4 lore raw
Quoted 21 lines · Andries Brouwer
Quoted 5 lines · Vojtech Pavlik
Quoted 4 lines
Quoted 4 lines

I have a notebook (Dell Latitude D800) which has some keys (actual fn+something combinations) that generate Down events but no Up events (clever, isn't it).
This makes those keys unusable with 2.6.0 as it is

Quoted 7 lines
Quoted 3 lines

I think we should go for the simple fix: only enable the timer-induced repeat when the user asks for that (say, by boot parameter). The keyboard already knows which keys repeat and which don't.

That won't solve it - the key, while not repeating would be still considered 'down' by the kernel and any more pressing of the key wouldn't do anything.

Yes, it would still be considered down. But that does not imply that pressing it doesnt do anything. It is up to the driver to discard key presses, and I think it shouldnt.
(Unless of course the user asks for that behaviour - it may be required on some broken laptops.)

Quoted 4 lines

Just the simple: a keypress generates an interrupt and we see a keystroke.

Use a kernel timer only when we know or the user tells us that it is needed. Not in the default situation.

I'm not very fond of making special exception for the (hopefully soon to be doing) PS/2 genre of keyboards. For USB for example you don't get an interrupt and a scancode per keypress. You get the current keyboard state. So I prefer to keep the keyboard state in the kernel, too, since that is a model that fits more devices. Also not just keyboards.

Quoted 9 lines
Quoted 4 lines

My proposed solution is to do an input_report_key(pressed) immediately followed by input_report_key(released) for these keys straight in atkbd.c. Possibly based on some flag in the scancode->keycode table for that scancode.

But that would require users to report on precisely which keys are affected and would give complications where I suppose 2.4 did not have any. This is the way towards an ever more complicated keyboard driver. Not what you would want.

I definitely want one single driver being more complicated than the core getting more complicated.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#5 lore raw
Quoted 5 lines · Vojtech Pavlik

I'm not very fond of making special exception for the (hopefully soon to be doing) PS/2 genre of keyboards. For USB for example you don't get an interrupt and a scancode per keypress. You get the current keyboard state. So I prefer to keep the keyboard state in the kernel, too, since that is a model that fits more devices. Also not just keyboards.

I think you just have to accept that there are two designs in common use, and neither maps in a predictable way on to the other: keyboards which send the state (USB), and keyboards which never reveal the state (PS/2 with strange mixtures of DOWN+UP, DOWN only, repeating and non-repeating keys).

Anything else is going to do the wrong thing with the other kind of keyboard, until the user does something special, which will be beyond many users to configure themselves.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

My proposed solution is to do an input_report_key(pressed) immediately followed by input_report_key(released) for these keys straight in atkbd.c. Possibly based on some flag in the scancode->keycode table for that scancode.

Quoted 7 lines
Quoted 4 lines

But that would require users to report on precisely which keys are affected and would give complications where I suppose 2.4 did not have any. This is the way towards an ever more complicated keyboard driver. Not what you would want.

I definitely want one single driver being more complicated than the core getting more complicated.

The point is moot if the set of special keys on PS/2 keyboards is the same for all keyboards, though. Then nothing special is required of the user. That would be the best, if it is possible.

But if not
----------

How about the PS/2 driver auto-discovers special (no UP event) keys:

1. The range of known reliable keys, such as letters, can use software mode (repeat, depends on UP reports) from the beginning.

2. Set up _every_ other key to be non-repeating in software, with

(a) consecutive DOWN events causing a synthetic UP just before the second and subsequent DOWNs.
(b) a synthetic UP after a timeout in the DOWN state.

3. Whenever the keyboard sends an UP, change that key (only that key) to be in software mode like 1.

After booting, if the user presses "r", it will behave as expected - it's covered by 1.

If the user presses "Fn+F1" or some other unknown key which doesn't report UP events, it won't repeat and it will report DOWN then UP input events, once each time it is pressed.

If the user presses another unknown key such as "PrevTrack" which does report UP events, that will not repeat the first time it is pressed and released, but subsequently it will.

In all cases, the driver errs on the side of not creating more press events than it knows is safe.

-- Jamie

#6 lore raw
Quoted 5 lines · Jamie Lokier

I think you just have to accept that there are two designs in common use, and neither maps in a predictable way on to the other: keyboards which send the state (USB), and keyboards which never reveal the state (PS/2 with strange mixtures of DOWN+UP, DOWN only, repeating and non-repeating keys).

Well, all keyboards but PS/2 are able to report (or keep track) of the state quite well, and regarding PS/2 only buggy keyboards that deviate from the basic rules of sanity are a problem.

Quoted 3 lines

Anything else is going to do the wrong thing with the other kind of keyboard, until the user does something special, which will be beyond many users to configure themselves.

Maybe.

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

But that would require users to report on precisely which keys are affected and would give complications where I suppose 2.4 did not have any. This is the way towards an ever more complicated keyboard driver. Not what you would want.

I definitely want one single driver being more complicated than the core getting more complicated.

The point is moot if the set of special keys on PS/2 keyboards is the same for all keyboards, though.

It is not. There is only ONE key that is not repeated on normal PS/2 keyboards and that is the Pause key. All other keys (including shift, etc) are repeated. The Pause key, though, sends both Down and Up events on the keypress, so it doesn't confuse the software.

Quoted 2 lines

Then nothing special is required of
the user. That would be the best, if it is possible.

The best is never possible.

Quoted 7 lines

But if not
----------

How about the PS/2 driver auto-discovers special (no UP event) keys:

1. The range of known reliable keys, such as letters, can use software mode (repeat, depends on UP reports) from the beginning.

Ok.

Quoted 4 lines

2. Set up _every_ other key to be non-repeating in software, with

(a) consecutive DOWN events causing a synthetic UP just before the second and subsequent DOWNs.

Won't work on keyboards which send more than one DOWN before an UP. There are a bunch of these, notably the broken notebook keyboards.

Quoted 1 line

(b) a synthetic UP after a timeout in the DOWN state.

That's what I'm planning to implement, with the timeout being the hardware autorepeat delay. This way the sw autorepeat never kicks in unless the hardware one does, too. On the PS/2 keyboards only.

Quoted 9 lines

3. Whenever the keyboard sends an UP, change that key (only that key) to be in software mode like 1.

After booting, if the user presses "r", it will behave as expected - it's covered by 1.

If the user presses "Fn+F1" or some other unknown key which doesn't report UP events, it won't repeat and it will report DOWN then UP input events, once each time it is pressed.

Fn+F1 won't most likely generate a keypress event. It'll just change the contrast via the BIOS or something.

I really believe that keys which generate the same scancode when pressed and released (as per the report which started the thread) usually happen because the keyboard is in some non-native mode.

I have keyboards which report the same scancode for both press and release of several keys (making the keys undistinguishable) unless switched to scancode set 3.

Quoted 8 lines

If the user presses another unknown key such as "PrevTrack" which does report UP events, that will not repeat the first time it is pressed and released, but subsequently it will.

In all cases, the driver errs on the side of not creating more press events than it knows is safe.

-- Jamie

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#7 lore raw
Quoted 7 lines · Vojtech Pavlik
Quoted 4 lines

2. Set up _every_ other key to be non-repeating in software, with

(a) consecutive DOWN events causing a synthetic UP just before the second and subsequent DOWNs.

Won't work on keyboards which send more than one DOWN before an UP. There are a bunch of these, notably the broken notebook keyboards.

I forgot to mention 2b: if subsequent DOWNs appear in rapid succession _soon_ after the first DOWN, it's a buggy laptop. Ignore those subsequent DOWNs.

Quoted 9 lines
Quoted 6 lines

After booting, if the user presses "r", it will behave as expected - it's covered by 1.

If the user presses "Fn+F1" or some other unknown key which doesn't report UP events, it won't repeat and it will report DOWN then UP input events, once each time it is pressed.

Fn+F1 won't most likely generate a keypress event. It'll just change the contrast via the BIOS or something.

I meant the keys which started this thread:

I have a notebook (Dell Latitude D800) which has some keys (actual fn+something combinations) that generate Down events but no Up events (clever, isn't it).

Quoted 7 lines

I really believe that keys which generate the same scancode when pressed and released (as per the report which started the thread) usually happen because the keyboard is in some non-native mode.

I have keyboards which report the same scancode for both press and release of several keys (making the keys undistinguishable) unless switched to scancode set 3.

If switching to scancode set 3 solves the whole problem, that's great :)

-- Jamie

#8 lore raw
In reply to Vojtech Pavlik
Quoted 3 lines · [email protected] said:

be doing) PS/2 genre of keyboards. For USB for example you don't get an interrupt and a scancode per keypress. You get the current keyboard state.

Then how am I getting infinitely repeating keys with a USB keyboard? I recently switched to a kinesis ergo USB keyboard, and I had to disable autorepeat in X because I had problems with keys occasionally repeating infinitely until I hit something else to make it stop. I haven't tracked down whether that's a hardware problem or in software.

Are you aware of that happening with USB keyboards?

Jason

#9 lore raw
In reply to Andries Brouwer
Quoted 5 lines · Andries Brouwer

Yes, it would still be considered down. But that does not imply that pressing it doesnt do anything. It is up to the driver to discard key presses, and I think it shouldnt.
(Unless of course the user asks for that behaviour - it may be required on some broken laptops.)

It should discard multiple presses of the same key in very rapid succession, when that is immediately after the first press of that key. (After a time has passed, rapid successive presses are due to auto-repeat, which is ok).

Several laptops seem to send a key down event 3, 5 or very many times in response to a single press.

-- Jamie

#10 lore raw
Quoted 7 lines · Jamie Lokier
Quoted 5 lines · Andries Brouwer

Yes, it would still be considered down. But that does not imply that pressing it doesnt do anything. It is up to the driver to discard key presses, and I think it shouldnt.
(Unless of course the user asks for that behaviour - it may be required on some broken laptops.)

Quoted 7 lines

It should discard multiple presses of the same key in very rapid succession, when that is immediately after the first press of that key. (After a time has passed, rapid successive presses are due to auto-repeat, which is ok).

Several laptops seem to send a key down event 3, 5 or very many times in response to a single press.

One way this could be handled fairly nicely (although the method is maybe too clever to be good) would be to leave the autorepeat up to the sw, ignore any successive presses without a release and watch whether the keyboard will start autorepeating the key after 250 msec. If it does not, then force the key to be released even if we got no release scancode.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#11 lore raw
Quoted 9 lines · Vojtech Pavlik
Quoted 2 lines

Several laptops seem to send a key down event 3, 5 or very many times in response to a single press.

One way this could be handled fairly nicely (although the method is maybe too clever to be good) would be to leave the autorepeat up to the sw, ignore any successive presses without a release and watch whether the keyboard will start autorepeating the key after 250 msec. If it does not, then force the key to be released even if we got no release scancode.

Perhaps it's too clever, because some users configure the repeat delay in their BIOS to longer than 250ms.

It is fine if you are able to reliably program the keyboard to use the 250ms delay, though.

Aren't there some keys which report DOWN and UP but which don't repeat?

The PS/2 keyboard protocol is utterly absurd.

-- Jamie

#12 lore raw
Quoted 11 lines · Jamie Lokier
Quoted 9 lines · Vojtech Pavlik
Quoted 2 lines

Several laptops seem to send a key down event 3, 5 or very many times in response to a single press.

One way this could be handled fairly nicely (although the method is maybe too clever to be good) would be to leave the autorepeat up to the sw, ignore any successive presses without a release and watch whether the keyboard will start autorepeating the key after 250 msec. If it does not, then force the key to be released even if we got no release scancode.

Quoted 2 lines

Perhaps it's too clever, because some users configure the repeat delay in their BIOS to longer than 250ms.

The driver programs the delay. The BIOS setting is irrelevant.

Quoted 2 lines

It is fine if you are able to reliably program the keyboard to use the 250ms delay, though.

I am.

Quoted 1 line

Aren't there some keys which report DOWN and UP but which don't repeat?

No.

Quoted 1 line

The PS/2 keyboard protocol is utterly absurd.

Yep. It's a dozen or more years of hack upon a hack.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#13 lore raw
Quoted 3 lines · Vojtech Pavlik
Quoted 1 line

The PS/2 keyboard protocol is utterly absurd.

Yep. It's a dozen or more years of hack upon a hack.

Well, mode #3 with no translation in the i8042 looks quite sanely.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#14 lore raw
Quoted 4 lines · Maciej W. Rozycki
Quoted 2 lines · Vojtech Pavlik
Quoted 1 line

The PS/2 keyboard protocol is utterly absurd.

Yep. It's a dozen or more years of hack upon a hack.

Well, mode #3 with no translation in the i8042 looks quite sanely.

What are the known problems with mode #3, then?

That is, why doesn't everyone use it and why haven't they always used it?

For that matter, what does Windows use?

-- Jamie

#15 lore raw
Quoted 7 lines · Jamie Lokier
Quoted 4 lines · Maciej W. Rozycki
Quoted 2 lines · Vojtech Pavlik
Quoted 1 line

The PS/2 keyboard protocol is utterly absurd.

Yep. It's a dozen or more years of hack upon a hack.

Well, mode #3 with no translation in the i8042 looks quite sanely.

What are the known problems with mode #3, then?

It's broken on many keyboards (on some only slightly, like some keys not working properly). Other (special, either unix workstation or point of sale) keyboards need it to work properly.

Quoted 1 line

That is, why doesn't everyone use it and why haven't they always used it?

Because old AT keyboards didn't support it. Because the XT keyboard didn't support it. Because history sticks.

Quoted 1 line

For that matter, what does Windows use?

Translated Set 2. Actually an emulated XT keyboard.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#16 lore raw
Quoted 5 lines · Vojtech Pavlik
Quoted 1 line

What are the known problems with mode #3, then?

It's broken on many keyboards (on some only slightly, like some keys not working properly). Other (special, either unix workstation or point of sale) keyboards need it to work properly.

IIRC, OSF/1 running on later Alphas with a PS/2 keyboard interface
(earlier oned had an LK201 one) uses mode #3. I can't comment on the VMS.

Quoted 4 lines
Quoted 1 line

That is, why doesn't everyone use it and why haven't they always used it?

Because old AT keyboards didn't support it. Because the XT keyboard didn't support it. Because history sticks.

Since the 8042+keyboard combo supports a PC/XT compatibility mode there
was no incentive -- why bother modifying software if the hardware works with the old one? Even if that sucks.

Quoted 3 lines
Quoted 1 line

For that matter, what does Windows use?

Translated Set 2. Actually an emulated XT keyboard.

For mode #3 explicit handling for hot-plugging would be required -- I
guess the change would be much too intrusive. And untranslated mode #2 is nearly the same as an emulated PC/XT keyboard: codes are different and the release bit is replaced by the release code, but the multibyte mess for PS/2-specific keys remains -- no gain at all.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#17 lore raw
In reply to Maciej W. Rozycki
Quoted 1 line · Maciej W. Rozycki

Well, mode #3 with no translation in the i8042 looks quite sanely.

In theory perhaps. In practice it isnt sane at all.

(That is, the majority of the keyboards sold today do not do as one would wish. Since Microsoft does not require anything for Set 3, behaviour in Set 3 is essentially random, especially for these additional keys and buttons. A single keypress may give several scancodes, or none at all. Many laptops do not have any support for Set 3. USB compatibility only implements compatibility with translated Set 2.)

#18 lore raw
Quoted 3 lines · Andries Brouwer
Quoted 1 line

Well, mode #3 with no translation in the i8042 looks quite sanely.

In theory perhaps. In practice it isnt sane at all.

Yep, the design is clean. And we can handle it for good devices, for its
additional functionality (e.g. autorepeat of <Pause> ;-) ) and to have a clean reference design of code. I see no reason to "punish" good devices for the faults of bad ones.

Quoted 5 lines

(That is, the majority of the keyboards sold today do not do as one would wish. Since Microsoft does not require anything for Set 3, behaviour in Set 3 is essentially random, especially for these additional keys and buttons. A single keypress may give several scancodes, or none at all. Many laptops do not have any support

Well, we need not take care of non-standard keys -- as such they need to
be handled on a case-by-case basis (with customized key maps). The sort of standard Win keys seem to have a consistent definition across devices; at least it was the case with the ones I've encountered.

If standard keys are broken, then we can still revert to mode #2 with all
its limits as we do now. At least we can disable the translation in the i8042 to get full and unambiguous scan codes.

Quoted 2 lines

for Set 3. USB compatibility only implements compatibility with translated Set 2.)

That's actually irrelevant -- it's already an emulation. AFAIK, we can
handle USB keyboards natively just fine, so we don't need to make use of this translation layer.

Maciej

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#19 lore raw
Quoted 8 lines · Maciej W. Rozycki
Quoted 3 lines
Quoted 1 line

Well, mode #3 with no translation in the i8042 looks quite sanely.

In theory perhaps. In practice it isnt sane at all.

Yep, the design is clean. And we can handle it for good devices, for its
additional functionality (e.g. autorepeat of <Pause> ;-) ) and to have a clean reference design of code. I see no reason to "punish" good devices for the faults of bad ones.

Your reasoning is backwards.
For the user the only thing that matters is that the keyboard works. Which codes certain chips send to each other is completely irrelevant.

Everybody uses translated Set 2. It works.
Anything else gives obscure problems.

If we exchange ugly code that fails for one in a million users for nice code that fails for one in tenthousand users, that is no progress.

Quoted 8 lines
Quoted 5 lines

(That is, the majority of the keyboards sold today do not do as one would wish. Since Microsoft does not require anything for Set 3, behaviour in Set 3 is essentially random, especially for these additional keys and buttons. A single keypress may give several scancodes, or none at all. Many laptops do not have any support

Well, we need not take care of non-standard keys -- as such they need to
be handled on a case-by-case basis (with customized key maps).

If the keyboard is in Set 3, then these keys may not give any scancode at all. In order for the non-standard keys to work we need Set 2.

My laptop has function buttons that bring me to a setup menu where I can set various timeouts related to power saving. These built-in menus react to translated scancode Set 2 only. There is no way to get out if one first chooses Set 3.

Etc. Set 3 is a pain. Nobody wants it, except the people who have read the spec only and say - look, neat, a single code for a single keystroke. Reality is very different.

Quoted 3 lines

If standard keys are broken, then we can still revert to mode #2 with all
its limits as we do now. At least we can disable the translation in the i8042 to get full and unambiguous scan codes.

Also disabling translation causes all kinds of obscure troubles. It is extremely unwise to go for obscure modes that were supported by most keyboards ten years ago, and may or may not have any support today.

Andries

#20 lore raw
Quoted 8 lines · Andries Brouwer
Quoted 4 lines

Yep, the design is clean. And we can handle it for good devices, for its
additional functionality (e.g. autorepeat of <Pause> ;-) ) and to have a clean reference design of code. I see no reason to "punish" good devices for the faults of bad ones.

Your reasoning is backwards.
For the user the only thing that matters is that the keyboard works. Which codes certain chips send to each other is completely irrelevant.

The codes might not matter much to a user. But mode #3 gives additional
control over the keyboard which can be made user-visible.

Quoted 2 lines

Everybody uses translated Set 2. It works.
Anything else gives obscure problems.

It mostly works, indeed. With all its limitations.

Quoted 3 lines

If we exchange ugly code that fails for one in a million users for nice code that fails for one in tenthousand users, that is no progress.

I see no reason to force that 99 people per million to use anything
beyond they had so far. But why have the remaining 999900 people got to suffer?

Fortunately we already have an option to force one set or another.

Quoted 5 lines
Quoted 2 lines

Well, we need not take care of non-standard keys -- as such they need to
be handled on a case-by-case basis (with customized key maps).

If the keyboard is in Set 3, then these keys may not give any scancode at all. In order for the non-standard keys to work we need Set 2.

Interesting...

Quoted 4 lines

My laptop has function buttons that bring me to a setup menu where I can set various timeouts related to power saving. These built-in menus react to translated scancode Set 2 only. There is no way to get out if one first chooses Set 3.

Well, that's a design error. Can you do that when running Linux? I
suppose so. That means the SMM is involved with its all obscurities. The design error is it should be under the control of the OS.

Quoted 2 lines

Etc. Set 3 is a pain. Nobody wants it, except the people who have read the spec only and say - look, neat, a single code for a single keystroke.

Plus the symmetry of keys -- no more strange behaviour of "special" keys.
That's more important -- all keys behave the same way and they do not magically depend on modifiers.

Quoted 1 line

Reality is very different.

Actually the spec is a standard and standard hardware performs as
expected (e.g. hardware released by IBM). The rest is non-standard and if a manufacturer claims PS/2-compliance for any of these items, then he lies.

Quoted 7 lines
Quoted 3 lines

If standard keys are broken, then we can still revert to mode #2 with all
its limits as we do now. At least we can disable the translation in the i8042 to get full and unambiguous scan codes.

Also disabling translation causes all kinds of obscure troubles. It is extremely unwise to go for obscure modes that were supported by most keyboards ten years ago, and may or may not have any support today.

Note the translation is done outside the keyboard -- the onboard 8042
controller is responsible for it. And it's an obstacle for normal operation, most notably you cannot handle hot-plug events as they are undistinguishable from a <Shift> release.

To summarize -- I do not want anyone to suffer unnecessarily because of
having bad hardware (i.e. beyond what's directly caused by the limitations of such hardware). But those who have good hardware should be able to make good use of it. And I prefer the defaults to assume good hardware -- for bad hardware a command line option may override the defaults. This way bad hardware becomes visible -- right now a user cannot easily distinguish between a good keyboard and a broken one, so he has no obvious choice and also there is no incentive for manufacturers to fix broken devices for those who care (I wouldn't mind a statement on a keyboard box e.g.: "Windows-compliant" or "PS/2-compliant" or both, so that I know what to choose).

Maciej

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#21 lore raw
Quoted 4 lines · Maciej W. Rozycki
Quoted 2 lines

Etc. Set 3 is a pain. Nobody wants it, except the people who have read the spec only and say - look, neat, a single code for a single keystroke.

Plus the symmetry of keys -- no more strange behaviour of "special" keys.

On my BTC keyboard, the macro key produces e0 6f in Set 3, yes, two scancodes. On my Safeway keyboard, the multimedia keys do not produce any scancode at all in Set 3. The same holds for my Compaq Easy Access Keyboard. The correspondence between Set 2 codes and Set 3 codes varies from keyboard to keyboard.
Things are not pretty in reality.
Only on paper, and only if you disregard all "new" keys.

#22 lore raw
Quoted 8 lines · Andries Brouwer
Quoted 4 lines
Quoted 2 lines

Etc. Set 3 is a pain. Nobody wants it, except the people who have read the spec only and say - look, neat, a single code for a single keystroke.

Plus the symmetry of keys -- no more strange behaviour of "special" keys.

On my BTC keyboard, the macro key produces e0 6f in Set 3, yes, two scancodes. On my Safeway keyboard, the multimedia keys do not produce any scancode at all in Set 3. The same holds for my Compaq Easy Access Keyboard.

So if you need these keys, then just use what works for you. Thanks for
mentioning these -- I'll know what to avoid.

BTW, for completeness, have you tried set #1?

Quoted 4 lines

The correspondence between Set 2 codes and Set 3 codes varies from keyboard to keyboard.
Things are not pretty in reality.
Only on paper, and only if you disregard all "new" keys.

There are good devices out there (mine inclusive :-) ) that comply to
what papers require and I see no reason not to handle them fully.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#23 lore raw
Quoted 1 line · Maciej W. Rozycki

So if you need these keys, then just use what works for you.

I am not sure what you are discussing.
But I am talking about the Linux keyboard driver.

It must not touch Set 3, or lots of people will have problems.

Only when the user explicitly asks for Set 3 is it reasonable to switch to it.

#24 lore raw
Quoted 2 lines · Andries Brouwer

Only when the user explicitly asks for Set 3 is it reasonable to switch to it.

I have expressed my preference, but it's not strong enough for me not to
accept your one. As long as I can select untranslated mode #3 somehow, I can live with that.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#25 lore raw
In reply to Maciej W. Rozycki
Quoted 4 lines · Maciej W. Rozycki
Quoted 4 lines

My laptop has function buttons that bring me to a setup menu where I can set various timeouts related to power saving. These built-in menus react to translated scancode Set 2 only. There is no way to get out if one first chooses Set 3.

Perhaps the BIOS is listening for translated set 2 scancodes. Maybe some different keys would have the power saving functions in other modes?

Quoted 4 lines

Actually the spec is a standard and standard hardware performs as
expected (e.g. hardware released by IBM). The rest is non-standard and if a manufacturer claims PS/2-compliance for any of these items, then he lies.

The user doesn't care if it's PS/2 compliant or not. It must work, that is the only important thing. Even more so, given it is flawless

Quoted 4 lines

Note the translation is done outside the keyboard -- the onboard 8042
controller is responsible for it. And it's an obstacle for normal operation, most notably you cannot handle hot-plug events as they are undistinguishable from a <Shift> release.

Perhaps you can detect a keyboard being unplugged by periodically sending it Echo commands (EE), or any other command to which it responds.

-- Jamie

#26 lore raw
Quoted 2 lines · Jamie Lokier

The user doesn't care if it's PS/2 compliant or not. It must work, that is the only important thing. Even more so, given it is flawless

Yep, but "work" is ambiguous. What one considers working, someone else
may consider insufficient. That's why there are various quality goods out there -- someone might want to sacrifice quality to get a low price and someone else might want to get best quality he can afford.

Quoted 2 lines

Perhaps you can detect a keyboard being unplugged by periodically sending it Echo commands (EE), or any other command to which it responds.

Due to communication latencies and the system load it would be
unreasonable to send an echo request more often than once, perhaps twice per second. And it's quite easy to unplug and then plug a keyboard back in a shorter time.

Disabling the translation in the onboard 8042 solves the problem and I am
quite surprised there are problems with that. After all a pass-through mode is easier to implement than a cooked one -- it's essentially a no-op.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#27 lore raw
Quoted 3 lines · Maciej W. Rozycki

Disabling the translation in the onboard 8042 solves the problem and I am
quite surprised there are problems with that. After all a pass-through mode is easier to implement than a cooked one -- it's essentially a no-op.

Yes, but on a notebook, you often don't have a microcontroler in the keyboard itself, and there is no wire over which the untranslated set2 scancodes would be passed. The i8042 directly scans the keyboard matrix. Then it's easy to forget about the set3 scancode set ...

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#28 lore raw
Quoted 4 lines · Vojtech Pavlik

Yes, but on a notebook, you often don't have a microcontroler in the keyboard itself, and there is no wire over which the untranslated set2 scancodes would be passed. The i8042 directly scans the keyboard matrix. Then it's easy to forget about the set3 scancode set ...

Hmm, that would make some sense, but how does it work when an external
keyboard is attached?

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#29 lore raw
Quoted 2 lines · Maciej W. Rozycki

Hmm, that would make some sense, but how does it work when an external
keyboard is attached?

Usually the keyboard and mouse commands are sent to all attached keyboards resp. mice. Thus, with an internal keyboard that only knows about Set 2 and an external keyboard that also knows about Set 3 you can change the kbds to Set 3. Now the internal one is dead, but the external one functions.

#30 lore raw
Quoted 8 lines · Andries Brouwer
Quoted 2 lines

Hmm, that would make some sense, but how does it work when an external
keyboard is attached?

Usually the keyboard and mouse commands are sent to all attached keyboards resp. mice. Thus, with an internal keyboard that only knows about Set 2 and an external keyboard that also knows about Set 3 you can change the kbds to Set 3. Now the internal one is dead, but the external one functions.

I meant: how does the translation work if there is only a single onboard
controller that does scanning of the embedded keyboard and presents set #1 of codes directly? But after a bit of thinking I suppose it does support translation for an external keyboard (which presents set #2 by default and a lot of PC software expects set #1) and probably a pass-through mode for it as well.

What the big fault of all these limited implementations is, there is no
reliable way to query what is supported. If a device does not support mode switching or a particular mode, it should NAK a command that does it, or at least report the original mode if queried afterwards. Another possibility is to return a different device ID -- IBM chose a single value of 256 possible for its PS/2 keyboards -- why couldn't the incompatible others have chosen something different, sigh?...

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#31 lore raw
Quoted 11 lines · Maciej W. Rozycki

I meant: how does the translation work if there is only a single onboard
controller that does scanning of the embedded keyboard and presents set #1 of codes directly? But after a bit of thinking I suppose it does support translation for an external keyboard (which presents set #2 by default and a lot of PC software expects set #1) and probably a pass-through mode for it as well.

What the big fault of all these limited implementations is, there is no
reliable way to query what is supported. If a device does not support mode switching or a particular mode, it should NAK a command that does it, or at least report the original mode if queried afterwards.

Most do, most do ...

Quoted 4 lines

Another
possibility is to return a different device ID -- IBM chose a single value of 256 possible for its PS/2 keyboards -- why couldn't the incompatible others have chosen something different, sigh?...

Some do ...

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#32 lore raw
In reply to Jamie Lokier
Quoted 3 lines · Jamie Lokier

Aren't there some keys which report DOWN and UP but which don't repeat?

The PS/2 keyboard protocol is utterly absurd.

In mode #3 you can configure press/release/repeat characteristics of
every key separately, although the sane default might be to set all keys to report all three kinds of events. The exception might of course be buggy hardware.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
author
#33 lore raw
In reply to Vojtech Pavlik
Quoted 5 lines · On Friday August 15, [email protected] wrote:

My proposed solution is to do an input_report_key(pressed) immediately followed by input_report_key(released) for these keys straight in atkbd.c. Possibly based on some flag in the scancode->keycode table for that scancode.

Something like this?

I use bit 32 in the keycode setting to mean "don't expect an 'up' event".
It seems to work (though some of the keys actually generate 'down' events for both the down and up transitions, so it seems that the key is pressed twice. I'm happy that that is just a buggy keyboard and I can work around it).

NeilBrown

----------- Diffstat output ------------

 ./drivers/input/evdev.c          |   13 ++++++++++---
 ./drivers/input/keyboard/atkbd.c |    7 +++++++
 ./include/linux/input.h          |    1 +
 3 files changed, 18 insertions(+), 3 deletions(-)
drivers/input/evdev.c renamed from drivers/input/evdev.c~current~ +10 -3
diff ./drivers/input/evdev.c~current~ ./drivers/input/evdev.c
@@ -233,15 +233,22 @@ static int evdev_ioctl(struct inode *ino
 		case EVIOCGKEYCODE:
 			if (get_user(t, ((int *) arg) + 0)) return -EFAULT;
 			if (t < 0 || t > dev->keycodemax || !dev->keycodesize) return -EINVAL;
-			if (put_user(INPUT_KEYCODE(dev, t), ((int *) arg) + 1)) return -EFAULT;
+			u = (dev->keycode_noup && test_bit(t, dev->keycode_noup)) ? (1<<31) : 0;
+			if (put_user(u | INPUT_KEYCODE(dev, t), ((int *) arg) + 1)) return -EFAULT;
 			return 0;
 
 		case EVIOCSKEYCODE:
 			if (get_user(t, ((int *) arg) + 0)) return -EFAULT;
 			if (t < 0 || t > dev->keycodemax || !dev->keycodesize) return -EINVAL;
 			u = INPUT_KEYCODE(dev, t);
-			if (get_user(INPUT_KEYCODE(dev, t), ((int *) arg) + 1)) return -EFAULT;
-
+			if (get_user(i, ((int *) arg) + 1)) return -EFAULT;
+			INPUT_KEYCODE(dev, t) = i;
+			if (dev->keycode_noup) {
+				if (i & (1<<31))
+					set_bit(t, dev->keycode_noup);
+				else
+					clear_bit(t, dev->keycode_noup);
+			}
 			for (i = 0; i < dev->keycodemax; i++)
 				if(INPUT_KEYCODE(dev, t) == u) break;
 			if (i == dev->keycodemax) clear_bit(u, dev->keybit);
drivers/input/keyboard/atkbd.c renamed from drivers/input/keyboard/atkbd.c~current~ +7 -0
diff ./drivers/input/keyboard/atkbd.c~current~ ./drivers/input/keyboard/atkbd.c
@@ -112,6 +112,7 @@ static unsigned char atkbd_set3_keycode[
 
 struct atkbd {
 	unsigned char keycode[512];
+	unsigned long keycode_noup[NBITS(512)];
 	struct input_dev dev;
 	struct serio *serio;
 	char name[64];
@@ -198,6 +199,10 @@ static irqreturn_t atkbd_interrupt(struc
 			input_regs(&atkbd->dev, regs);
 			input_report_key(&atkbd->dev, atkbd->keycode[code], !atkbd->release);
 			input_sync(&atkbd->dev);
+			if (!atkbd->release && test_bit(code, atkbd->keycode_noup)) {
+				input_report_key(&atkbd->dev, atkbd->keycode[code], 0);
+				input_sync(&atkbd->dev);
+			}
 	}
 
 	atkbd->release = 0;
@@ -512,6 +517,7 @@ static void atkbd_connect(struct serio *
 	atkbd->dev.keycode = atkbd->keycode;
 	atkbd->dev.keycodesize = sizeof(unsigned char);
 	atkbd->dev.keycodemax = ARRAY_SIZE(atkbd_set2_keycode);
+	atkbd->dev.keycode_noup = atkbd->keycode_noup;
 	atkbd->dev.event = atkbd_event;
 	atkbd->dev.private = atkbd;
 
@@ -549,6 +555,7 @@ static void atkbd_connect(struct serio *
 		memcpy(atkbd->keycode, atkbd_set3_keycode, sizeof(atkbd->keycode));
 	else
 		memcpy(atkbd->keycode, atkbd_set2_keycode, sizeof(atkbd->keycode));
+	memset(atkbd->keycode_noup, 0, sizeof(atkbd->keycode_noup));
 
 	atkbd->dev.name = atkbd->name;
 	atkbd->dev.phys = atkbd->phys;
include/linux/input.h renamed from include/linux/input.h~current~ +1 -0
diff ./include/linux/input.h~current~ ./include/linux/input.h
@@ -778,6 +778,7 @@ struct input_dev {
 	unsigned int keycodemax;
 	unsigned int keycodesize;
 	void *keycode;
+	unsigned long *keycode_noup;
 
 	unsigned int repeat_key;
 	struct timer_list timer;
#34 lore raw
Quoted 7 lines · Neil Brown
Quoted 5 lines · On Friday August 15, [email protected] wrote:

My proposed solution is to do an input_report_key(pressed) immediately followed by input_report_key(released) for these keys straight in atkbd.c. Possibly based on some flag in the scancode->keycode table for that scancode.

Quoted 7 lines

Something like this?

I use bit 32 in the keycode setting to mean "don't expect an 'up' event".
It seems to work (though some of the keys actually generate 'down' events for both the down and up transitions, so it seems that the key is pressed twice.

Now that is suspicious. This smells of some scancode mangling happening. Can you try with i8042_direct=1? And with both i8042_direct=1 and atkbd_set=3?

Quoted 92 lines

I'm happy that that is just a buggy keyboard and I can work around it).

NeilBrown

----------- Diffstat output ------------

 ./drivers/input/evdev.c          |   13 ++++++++++---
 ./drivers/input/keyboard/atkbd.c |    7 +++++++
 ./include/linux/input.h          |    1 +
 3 files changed, 18 insertions(+), 3 deletions(-)

diff ./drivers/input/evdev.c~current~ ./drivers/input/evdev.c

drivers/input/evdev.c renamed from drivers/input/evdev.c~current~ +10 -3
@@ -233,15 +233,22 @@ static int evdev_ioctl(struct inode *ino
 		case EVIOCGKEYCODE:
 			if (get_user(t, ((int *) arg) + 0)) return -EFAULT;
 			if (t < 0 || t > dev->keycodemax || !dev->keycodesize) return -EINVAL;
-			if (put_user(INPUT_KEYCODE(dev, t), ((int *) arg) + 1)) return -EFAULT;
+			u = (dev->keycode_noup && test_bit(t, dev->keycode_noup)) ? (1<<31) : 0;
+			if (put_user(u | INPUT_KEYCODE(dev, t), ((int *) arg) + 1)) return -EFAULT;
 			return 0;
 
 		case EVIOCSKEYCODE:
 			if (get_user(t, ((int *) arg) + 0)) return -EFAULT;
 			if (t < 0 || t > dev->keycodemax || !dev->keycodesize) return -EINVAL;
 			u = INPUT_KEYCODE(dev, t);
-			if (get_user(INPUT_KEYCODE(dev, t), ((int *) arg) + 1)) return -EFAULT;
-
+			if (get_user(i, ((int *) arg) + 1)) return -EFAULT;
+			INPUT_KEYCODE(dev, t) = i;
+			if (dev->keycode_noup) {
+				if (i & (1<<31))
+					set_bit(t, dev->keycode_noup);
+				else
+					clear_bit(t, dev->keycode_noup);
+			}
 			for (i = 0; i < dev->keycodemax; i++)
 				if(INPUT_KEYCODE(dev, t) == u) break;
 			if (i == dev->keycodemax) clear_bit(u, dev->keybit);

diff ./drivers/input/keyboard/atkbd.c~current~ ./drivers/input/keyboard/atkbd.c

drivers/input/keyboard/atkbd.c renamed from drivers/input/keyboard/atkbd.c~current~ +7 -0
@@ -112,6 +112,7 @@ static unsigned char atkbd_set3_keycode[
 
 struct atkbd {
 	unsigned char keycode[512];
+	unsigned long keycode_noup[NBITS(512)];
 	struct input_dev dev;
 	struct serio *serio;
 	char name[64];
@@ -198,6 +199,10 @@ static irqreturn_t atkbd_interrupt(struc
 			input_regs(&atkbd->dev, regs);
 			input_report_key(&atkbd->dev, atkbd->keycode[code], !atkbd->release);
 			input_sync(&atkbd->dev);
+			if (!atkbd->release && test_bit(code, atkbd->keycode_noup)) {
+				input_report_key(&atkbd->dev, atkbd->keycode[code], 0);
+				input_sync(&atkbd->dev);
+			}
 	}
 
 	atkbd->release = 0;
@@ -512,6 +517,7 @@ static void atkbd_connect(struct serio *
 	atkbd->dev.keycode = atkbd->keycode;
 	atkbd->dev.keycodesize = sizeof(unsigned char);
 	atkbd->dev.keycodemax = ARRAY_SIZE(atkbd_set2_keycode);
+	atkbd->dev.keycode_noup = atkbd->keycode_noup;
 	atkbd->dev.event = atkbd_event;
 	atkbd->dev.private = atkbd;
 
@@ -549,6 +555,7 @@ static void atkbd_connect(struct serio *
 		memcpy(atkbd->keycode, atkbd_set3_keycode, sizeof(atkbd->keycode));
 	else
 		memcpy(atkbd->keycode, atkbd_set2_keycode, sizeof(atkbd->keycode));
+	memset(atkbd->keycode_noup, 0, sizeof(atkbd->keycode_noup));
 
 	atkbd->dev.name = atkbd->name;
 	atkbd->dev.phys = atkbd->phys;

diff ./include/linux/input.h~current~ ./include/linux/input.h

include/linux/input.h renamed from include/linux/input.h~current~ +1 -0
@@ -778,6 +778,7 @@ struct input_dev {
 	unsigned int keycodemax;
 	unsigned int keycodesize;
 	void *keycode;
+	unsigned long *keycode_noup;
 
 	unsigned int repeat_key;
 	struct timer_list timer;
Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#35 lore raw
In reply to Neil Brown
Quoted 3 lines · Neil Brown

It seems to work (though some of the keys actually generate 'down' events for both the down and up transitions, so it seems that the key is pressed twice.

Maybe it really is as you say. But your description sounds fishy. It would be nice to know what really happens.
(And it would be nice to know which scancodes are involved.)

#36 lore raw
Quoted 9 lines · Andries Brouwer
Quoted 3 lines · Neil Brown

It seems to work (though some of the keys actually generate 'down' events for both the down and up transitions, so it seems that the key is pressed twice.

Maybe it really is as you say. But your description sounds fishy. It would be nice to know what really happens.
(And it would be nice to know which scancodes are involved.)

Indeed. Neil, please enable DEBUG in i8042.c ... both with and without the i8042_direct=1 and atkbd_set=3 options from my previous e-mail.

And for Andries, if you can, do the showkey -s test on 2.4, too ...

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
author
#37 lore raw
Quoted 7 lines · On Friday August 15, [email protected] wrote:
Quoted 6 lines · Andries Brouwer
Quoted 3 lines · Neil Brown

It seems to work (though some of the keys actually generate 'down' events for both the down and up transitions, so it seems that the key is pressed twice.

Quoted 8 lines
Quoted 3 lines

Maybe it really is as you say. But your description sounds fishy. It would be nice to know what really happens.
(And it would be nice to know which scancodes are involved.)

Indeed. Neil, please enable DEBUG in i8042.c ... both with and without the i8042_direct=1 and atkbd_set=3 options from my previous e-mail.

And for Andries, if you can, do the showkey -s test on 2.4, too ...

Well...

There are 5 keys in question. Each one is fn + something else. Some of them (wireless, brighter, darker) cause the bios to do something, and only generate a keyboard event on a down transition. The others (battery, cdeject) don't appear to cause the bios to do anything, and generate a keyboard event on both the up and down transition, and it is always the same scancode.

Key      Meaning   2.6 scancode     2.4 (direct) scancode
fn-F2    wireless    0x13d               e0 08
fn-F3    battery     0x136               e0 07 
fn-F10   cdeject     0x13e               e0 09 
fn-down  darker      0x125               e0 05
fn-up    brighter    0x12e               e0 06

The "2.6 scancode" is the scancode reported in the

atkbd.c: Unknown key (set 2, scancode ...)

message, and it is always a "pressed" message. It is also the scancode I use in the EVIOCSKEYCODE ioctl to associate a keycode with the key.

The "2.4 (direct) scancode" is what I get back from "showkey -s".

When I set i8042_direct=1, the keyboard doesn't work sensibly at all. Many keys cause "Unknown key" messages, other cause unrelated characters to start autorepeating.
The 5 keys in question generate scancodes reported as 0x100 plus the second number in the "2.4 (direct) scancode" column.

Setting atkbd_set=3 doesn't appear to affect things at all. It is still reported as an "AT Set 2 keyboard".

When I enable debug in i8042.c, I get lots of messages about bytes to and from the i8042. There are no surprises in the bytes relating to keystrokes. They are exactly what is in the "2.4 (direct) scancode" column.
I can send you the i8042 initialisation conversations if they will help.

For my purposes, I need to use an "ioctl" to set a keycode for each scancode, so adding an ioctl to set the no-keyup status is no hassle for me. However the suggest approach of auto-detecting keys which have no up event would probably a good idea.

NeilBrown

#38 lore raw
Quoted 15 lines · Neil Brown
Quoted 14 lines · On Friday August 15, [email protected] wrote:
Quoted 9 lines · Andries Brouwer
Quoted 3 lines · Neil Brown

It seems to work (though some of the keys actually generate 'down' events for both the down and up transitions, so it seems that the key is pressed twice.

Maybe it really is as you say. But your description sounds fishy. It would be nice to know what really happens.
(And it would be nice to know which scancodes are involved.)

Indeed. Neil, please enable DEBUG in i8042.c ... both with and without the i8042_direct=1 and atkbd_set=3 options from my previous e-mail.

Quoted 8 lines
Quoted 1 line

And for Andries, if you can, do the showkey -s test on 2.4, too ...

Well...

For my purposes, I need to use an "ioctl" to set a keycode for each scancode, so adding an ioctl to set the no-keyup status is no hassle for me. However the suggest approach of auto-detecting keys which have no up event would probably a good idea.

How about this patch? It tries to be a bit clever, but hopefully not too much ...

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR

You can pull this changeset from:
bk://kernel.bkbits.net/vojtech/input

===================================================================

[email protected], 2003-08-18 18:00:19+02:00, [email protected]
input: atkbd.c - First take on keys which systematically or randomly don't generate release.

 atkbd.c |  156 ++++++++++++++++++++++++++++++++++++----------------------------
 1 files changed, 90 insertions(+), 66 deletions(-)

===================================================================

drivers/input/keyboard/atkbd.c +90 -66
diff -Nru a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
@@ -18,6 +18,7 @@
 #include <linux/input.h>
 #include <linux/serio.h>
 #include <linux/workqueue.h>
+#include <linux/timer.h>
 
 MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
 MODULE_DESCRIPTION("AT and PS/2 keyboard driver");
@@ -87,10 +88,10 @@
 #define ATKBD_CMD_GSCANSET	0x11f0
 #define ATKBD_CMD_SSCANSET	0x10f0
 #define ATKBD_CMD_GETID		0x02f2
+#define ATKBD_CMD_SETREP	0x10f3
 #define ATKBD_CMD_ENABLE	0x00f4
 #define ATKBD_CMD_RESET_DIS	0x00f5
 #define ATKBD_CMD_RESET_BAT	0x02ff
-#define ATKBD_CMD_SETALL_MB	0x00f8
 #define ATKBD_CMD_RESEND	0x00fe
 #define ATKBD_CMD_EX_ENABLE	0x10ea
 #define ATKBD_CMD_EX_SETLEDS	0x20eb
@@ -114,12 +115,14 @@
 	unsigned char keycode[512];
 	struct input_dev dev;
 	struct serio *serio;
+	struct timer_list timer;
 	char name[64];
 	char phys[32];
 	unsigned char cmdbuf[4];
 	unsigned char cmdcnt;
 	unsigned char set;
 	unsigned char release;
+	int lastkey;
 	volatile signed char ack;
 	unsigned char emul;
 	unsigned short id;
@@ -142,6 +145,7 @@
 	printk(KERN_DEBUG "atkbd.c: Received %02x flags %02x\n", data, flags);
 #endif
 
+#if !defined(__i386__) && !defined (__x86_64__)
 	if ((flags & (SERIO_FRAME | SERIO_PARITY)) && (~flags & SERIO_TIMEOUT) && !atkbd->resend && atkbd->write) {
 		printk("atkbd.c: frame/parity error: %02x\n", flags);
 		serio_write(serio, ATKBD_CMD_RESEND);
@@ -151,6 +155,7 @@
 	
 	if (!flags)
 		atkbd->resend = 0;
+#endif
 
 	switch (code) {
 		case ATKBD_RET_ACK:
@@ -195,6 +200,14 @@
 				atkbd->set, code, serio->phys, atkbd->release ? "released" : "pressed");
 			break;
 		default:
+
+			if (!atkbd->release) {
+				mod_timer(&atkbd->timer,
+					(test_bit(atkbd->keycode[code], &atkbd->dev.key)
+						? HZ/30 : HZ/4) + HZ/100);
+				atkbd->lastkey = atkbd->keycode[code];
+			}
+
 			input_regs(&atkbd->dev, regs);
 			input_report_key(&atkbd->dev, atkbd->keycode[code], !atkbd->release);
 			input_sync(&atkbd->dev);
@@ -205,6 +218,13 @@
 	return IRQ_HANDLED;
 }
 
+static void atkbd_force_key_up(unsigned long data)
+{
+	struct atkbd *atkbd = (void *) data;
+	input_report_key(&atkbd->dev, atkbd->lastkey, 0);
+	input_sync(&atkbd->dev);
+}
+
 /*
  * atkbd_sendbyte() sends a byte to the keyboard, and waits for
  * acknowledge. It doesn't handle resends according to the keyboard
@@ -214,7 +234,7 @@
 
 static int atkbd_sendbyte(struct atkbd *atkbd, unsigned char byte)
 {
-	int timeout = 10000; /* 100 msec */
+	int timeout = 20000; /* 200 msec */
 	atkbd->ack = 0;
 
 #ifdef ATKBD_DEBUG
@@ -322,6 +342,53 @@
 }
 
 /*
+ * atkbd_probe() probes for an AT keyboard on a serio port.
+ */
+
+static int atkbd_probe(struct atkbd *atkbd)
+{
+	unsigned char param[2];
+
+/*
+ * Some systems, where the bit-twiddling when testing the io-lines of the
+ * controller may confuse the keyboard need a full reset of the keyboard. On
+ * these systems the BIOS also usually doesn't do it for us.
+ */
+
+	if (atkbd_reset)
+		if (atkbd_command(atkbd, NULL, ATKBD_CMD_RESET_BAT)) 
+			printk(KERN_WARNING "atkbd.c: keyboard reset failed on %s\n", atkbd->serio->phys);
+
+/*
+ * Then we check the keyboard ID. We should get 0xab83 under normal conditions.
+ * Some keyboards report different values, but the first byte is always 0xab or
+ * 0xac. Some old AT keyboards don't report anything. If a mouse is connected, this
+ * should make sure we don't try to set the LEDs on it.
+ */
+
+	if (atkbd_command(atkbd, param, ATKBD_CMD_GETID)) {
+
+/*
+ * If the get ID command failed, we check if we can at least set the LEDs on
+ * the keyboard. This should work on every keyboard out there. It also turns
+ * the LEDs off, which we want anyway.
+ */
+		param[0] = 0;
+		if (atkbd_command(atkbd, param, ATKBD_CMD_SETLEDS))
+			return -1;
+		atkbd->id = 0xabba;
+		return 0;
+	}
+
+	if (param[0] != 0xab && param[0] != 0xac)
+		return -1;
+	atkbd->id = (param[0] << 8) | param[1];
+
+
+	return 0;
+}
+
+/*
  * atkbd_set_3 checks if a keyboard has a working Set 3 support, and
  * sets it into that. Unfortunately there are keyboards that can be switched
  * to Set 3, but don't work well in that (BTC Multimedia ...)
@@ -355,75 +422,26 @@
 			return 4;
 	}
 
-/*
- * Try to set the set we want.
- */
+	if (atkbd_set != 3) 
+		return 2;
 
-	param[0] = atkbd_set;
+	param[0] = 3;
 	if (atkbd_command(atkbd, param, ATKBD_CMD_SSCANSET))
 		return 2;
 
-/*
- * Read set number. Beware here. Some keyboards always send '2'
- * or some other number regardless into what mode they have been
- * attempted to be set. Other keyboards treat the '0' command as
- * 'set to set 0', and not 'report current set' as they should.
- * In that case we time out, and return 2.
- */
-
 	param[0] = 0;
 	if (atkbd_command(atkbd, param, ATKBD_CMD_GSCANSET))
 		return 2;
 
-/*
- * Here we return the set number the keyboard reports about
- * itself.
- */
+	if (param[0] != 3)
+		return 2;
 
-	return (param[0] == 3) ? 3 : 2;
+	return 3;
 }
 
-/*
- * atkbd_probe() probes for an AT keyboard on a serio port.
- */
-
-static int atkbd_probe(struct atkbd *atkbd)
+static int atkbd_enable(struct atkbd *atkbd)
 {
-	unsigned char param[2];
-
-/*
- * Some systems, where the bit-twiddling when testing the io-lines of the
- * controller may confuse the keyboard need a full reset of the keyboard. On
- * these systems the BIOS also usually doesn't do it for us.
- */
-
-	if (atkbd_reset)
-		if (atkbd_command(atkbd, NULL, ATKBD_CMD_RESET_BAT)) 
-			printk(KERN_WARNING "atkbd.c: keyboard reset failed on %s\n", atkbd->serio->phys);
-
-/*
- * Then we check the keyboard ID. We should get 0xab83 under normal conditions.
- * Some keyboards report different values, but the first byte is always 0xab or
- * 0xac. Some old AT keyboards don't report anything.
- */
-
-	if (atkbd_command(atkbd, param, ATKBD_CMD_GETID)) {
-
-/*
- * If the get ID command failed, we check if we can at least set the LEDs on
- * the keyboard. This should work on every keyboard out there. It also turns
- * the LEDs off, which we want anyway.
- */
-		param[0] = 0;
-		if (atkbd_command(atkbd, param, ATKBD_CMD_SETLEDS))
-			return -1;
-		atkbd->id = 0xabba;
-		return 0;
-	}
-
-	if (param[0] != 0xab && param[0] != 0xac)
-		return -1;
-	atkbd->id = (param[0] << 8) | param[1];
+	unsigned char param[1];
 
 /*
  * Set the LEDs to a defined state.
@@ -434,21 +452,22 @@
 		return -1;
 
 /*
- * Disable autorepeat. We don't need it, as we do it in software anyway,
- * because that way can get faster repeat, and have less system load (less
- * accesses to the slow ISA hardware). If this fails, we don't care, and will
- * just ignore the repeated keys.
+ * Set autorepeat to fastest possible.
  */
 
-	atkbd_command(atkbd, NULL, ATKBD_CMD_SETALL_MB);
+	param[0] = 0;
+	if (atkbd_command(atkbd, param, ATKBD_CMD_SETREP))
+		return -1;
 
 /*
- * Last, we enable the keyboard to make sure  that we get keypresses from it.
+ * Enable the keyboard to receive keystrokes.
  */
 
-	if (atkbd_command(atkbd, NULL, ATKBD_CMD_ENABLE))
+	if (atkbd_command(atkbd, NULL, ATKBD_CMD_ENABLE)) {
 		printk(KERN_ERR "atkbd.c: Failed to enable keyboard on %s\n",
 			atkbd->serio->phys);
+		return -1;
+	}
 
 	return 0;
 }
@@ -517,6 +536,10 @@
 
 	serio->private = atkbd;
 
+	init_timer(&atkbd->timer);
+	atkbd->timer.data = (long) atkbd;
+	atkbd->timer.function = atkbd_force_key_up;
+
 	if (serio_open(serio, dev)) {
 		kfree(atkbd);
 		return;
@@ -531,6 +554,7 @@
 		}
 		
 		atkbd->set = atkbd_set_3(atkbd);
+		atkbd_enable(atkbd);
 
 	} else {
 		atkbd->set = 2;
author
#39 lore raw
Quoted 4 lines · On Monday August 18, [email protected] wrote:

How about this patch? It tries to be a bit clever, but hopefully not too much ...

Uhmm.. mixed.

It behaved REALLY strangly until I fixed these typoes:

drivers/input/keyboard/atkbd.c line 207

Quoted 3 lines
drivers/input/keyboard/atkbd.c +3 -0
+				mod_timer(&atkbd->timer,
+					(test_bit(atkbd->keycode[code], &atkbd->dev.key)
+						? HZ/30 : HZ/4) + HZ/100);

should be

Review

Quoted 3 lines
(quoted diff) +3 -0
+				mod_timer(&atkbd->timer, jiffies + 
+					(test_bit(atkbd->keycode[code], atkbd->dev.key)
+						? HZ/30 : HZ/4) + HZ/100);

Then it sort-of worked - my problem keys gave nice up/down transitions.

However the hardware autorepeat and the software autorepeat seemed to interfere with each other and auto-repeat was rather erratic.

More of a problem was that control and shift would auto-repeat, and would often appear to be "up" when I was holding them "down", so control-X keys strokes were not reliable.

Thanks,
NeilBrown

#40 lore raw
Quoted 16 lines · Neil Brown
Quoted 4 lines · On Monday August 18, [email protected] wrote:

How about this patch? It tries to be a bit clever, but hopefully not too much ...

Uhmm.. mixed.

It behaved REALLY strangly until I fixed these typoes:

drivers/input/keyboard/atkbd.c line 207

Quoted 3 lines
drivers/input/keyboard/atkbd.c +3 -0
+				mod_timer(&atkbd->timer,
+					(test_bit(atkbd->keycode[code], &atkbd->dev.key)
+						? HZ/30 : HZ/4) + HZ/100);

should be

Quoted 3 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+				mod_timer(&atkbd->timer, jiffies + 
+					(test_bit(atkbd->keycode[code], atkbd->dev.key)
+						? HZ/30 : HZ/4) + HZ/100);

Thanks for spotting that! I originally had "!test_bit" there, and then removed the ! and forgot to swap the conditional values.

Quoted 2 lines

Then it sort-of worked - my problem keys gave nice up/down transitions.

Good to know. I'll test the rest on my keyboards here.

Quoted 2 lines

However the hardware autorepeat and the software autorepeat seemed to interfere with each other and auto-repeat was rather erratic.

Yep, you'll need to make the software autorepeat settings longer. They're HZ/4 and HZ/33 now, and need to be bigger than the in the above fixed statement.

Quoted 1 line

More of a problem was that control and shift would auto-repeat, and

This is normal.

Quoted 2 lines

would often appear to be "up" when I was holding them "down", so control-X keys strokes were not reliable.

Hmm, this is bad. I thought the code shouldn't be able to cause this (I tried to make it so), I'll try to fix it.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
author
#41 lore raw
Quoted 8 lines · On Tuesday August 19, [email protected] wrote:
Quoted 8 lines

It behaved REALLY strangly until I fixed these typoes:

drivers/input/keyboard/atkbd.c line 207

Quoted 3 lines
drivers/input/keyboard/atkbd.c +3 -0
+				mod_timer(&atkbd->timer,
+					(test_bit(atkbd->keycode[code], &atkbd->dev.key)
+						? HZ/30 : HZ/4) + HZ/100);

should be

Quoted 6 lines
Quoted 3 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+				mod_timer(&atkbd->timer, jiffies + 
+					(test_bit(atkbd->keycode[code], atkbd->dev.key)
+						? HZ/30 : HZ/4) + HZ/100);

Thanks for spotting that! I originally had "!test_bit" there, and then removed the ! and forgot to swap the conditional values.

I swapped the "30" and the "4", it is is better still. Auto-repeat of normal keys is ok (I think - didn't test extensively). control/shift is still a problem, though not quite as a bad

When I hold right-control down, evtest shows:

Event: time 1061335715.975639, type 1 (Key), code 97 (RightCtrl), value 1
Event: time 1061335715.975639, -------------- Config Sync ------------
Event: time 1061335716.014658, type 1 (Key), code 97 (RightCtrl), value 0
Event: time 1061335716.014659, -------------- Config Sync ------------
Event: time 1061335716.485899, type 1 (Key), code 97 (RightCtrl), value 1
Event: time 1061335716.485899, -------------- Config Sync ------------
Event: time 1061335716.734535, type 1 (Key), code 97 (RightCtrl), value 2
Event: time 1061335716.734536, -------------- Config Sync ------------
Event: time 1061335716.764555, type 1 (Key), code 97 (RightCtrl), value 2
Event: time 1061335716.764556, -------------- Config Sync ------------

so if I type another char between 30ms and 500ms after pressing control, the control isn't noticed, else it is.

NeilBrown

#42 lore raw
In reply to Neil Brown
Quoted 7 lines · Neil Brown

There are 5 keys in question. Each one is fn + something else. Some of them (wireless, brighter, darker) cause the bios to do something, and only generate a keyboard event on a down transition. The others (battery, cdeject) don't appear to cause the bios to do anything, and generate a keyboard event on both the up and down transition, and it is always the same scancode.

Quoted 6 lines
Key      Meaning   2.6 scancode     2.4 (direct) scancode
fn-F2    wireless    0x13d               e0 08
fn-F3    battery     0x136               e0 07 
fn-F10   cdeject     0x13e               e0 09 
fn-down  darker      0x125               e0 05
fn-up    brighter    0x12e               e0 06

Thanks - added to the data base.
http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html#ss1.12

Quoted 4 lines

For my purposes, I need to use an "ioctl" to set a keycode for each scancode, so adding an ioctl to set the no-keyup status is no hassle for me. However the suggest approach of auto-detecting keys which have no up event would probably a good idea.

I would be unhappy.
We need a solid keyboard driver that actually works. Not some fragile construction that has tricks built-in so as to make things work for every kernel developer. How many non-kernel-developers are there?
How many strange keyboards?

Andries

#43 lore raw
Quoted 9 lines · Andries Brouwer
Quoted 4 lines

For my purposes, I need to use an "ioctl" to set a keycode for each scancode, so adding an ioctl to set the no-keyup status is no hassle for me. However the suggest approach of auto-detecting keys which have no up event would probably a good idea.

I would be unhappy.
We need a solid keyboard driver that actually works. Not some fragile construction that has tricks built-in so as to make things work for every kernel developer.

Synthesising an UP event after receiving a DOWN from the keyboard, and nothing else for that key for > (repeat delay + a bit more) time looks like a good plan to me, UNLESS there are keys which do report UP when the key is released (as opposed to immediately after the DOWN), and also don't repeat.

Unrelated: I have some messages from my laptop, Toshiba Satellite 4070CDT:

atkbd.c: Unknown key (set 2, scancode 0x94, in isa0060/serio0) pressed. atkbd.c: Unknown key (set 2, scancode 0xbf, in isa0060/serio0) pressed. atkbd.c: Unknown key (set 2, scancode 0xa1, in isa0060/serio0) pressed.

Enjoy,
-- Jamie

#44 lore raw
Quoted 5 lines · Jamie Lokier

Synthesising an UP event after receiving a DOWN from the keyboard, and nothing else for that key for > (repeat delay + a bit more) time looks like a good plan to me, UNLESS there are keys which do report UP when the key is released (as opposed to immediately after the DOWN), and also don't repeat.

And there are keyboards with such keys.

Quoted 5 lines

Unrelated: I have some messages from my laptop, Toshiba Satellite 4070CDT:

atkbd.c: Unknown key (set 2, scancode 0x94, in isa0060/serio0) pressed. atkbd.c: Unknown key (set 2, scancode 0xbf, in isa0060/serio0) pressed. atkbd.c: Unknown key (set 2, scancode 0xa1, in isa0060/serio0) pressed.

Do you know what keystrokes cause this?

It looks like this cannot come from i8042_unxlate_table[]. Do you set i8042_direct?

Vojtech, this sounds like a bug in i8042.c:
We do

	if (data > 0x7f) {
		index = (data & 0x7f);
		if (test_and_clear_bit(index, i8042_unxlate_seen)) {
			data = i8042_unxlate_table[data & 0x7f];
		}
	} else {
		data = i8042_unxlate_table[data];
	}
	serio_interrupt(&i8042_kbd_port, data, dfl, regs);

In other words, the keyboard sends something in translated Set 2, but we fake that it is untranslated, unless it was
a key release and we didnt know that the key was down. Thus, atkbd.c gets a mixture of untranslated and translated codes.

Andries

#45 lore raw
Quoted 7 lines · Andries Brouwer
Quoted 5 lines

Synthesising an UP event after receiving a DOWN from the keyboard, and nothing else for that key for > (repeat delay + a bit more) time looks like a good plan to me, UNLESS there are keys which do report UP when the key is released (as opposed to immediately after the DOWN), and also don't repeat.

And there are keyboards with such keys.

Alas.

For programs which are only interested in key presses, there is no problem including a synthesised UP event.

But for programs which want to monitor a key and know its state continuously (this presently includes the software autorepeater, but it also includes games), none of the behaviours is right.

So the decision must be: shall we do the wrong thing for keyboards which report DOWN only (the key will appear stuck to some programs), or shall we do the wrong thing for keyboards which report DOWN, no repeat and then UP, by making it look like the key was released early?

-- Jamie

#46 lore raw
Quoted 4 lines · Jamie Lokier

So the decision must be: shall we do the wrong thing for keyboards which report DOWN only (the key will appear stuck to some programs), or shall we do the wrong thing for keyboards which report DOWN, no repeat and then UP, by making it look like the key was released early?

There are many more problems with your synthesized events. Look at your "repeat delay + a bit more". Can you specify how much "a bit more" is?

In times of heavy disk activity we lose interrupts. Indeed, if I copy a CD image or untar a kernel tree my keyboard and mouse are dead for several seconds.

There is no guaranteed "a bit more" within which we will see a keyboard event.

If the only events that are seen are actual events, and on rare occasions we miss an event, that is not so bad. We just hit that key again. But if we synthesize events, then a missed key up causes autorepeat.

In fact I see unwanted autorepeat - maybe once a day suddenly a single keystroke causes three to five identical characters to appear - but I am not sure what mechanism causes this.

Andries

#47 lore raw
Quoted 10 lines · Andries Brouwer

There are many more problems with your synthesized events. Look at your "repeat delay + a bit more". Can you specify how much "a bit more" is?

In times of heavy disk activity we lose interrupts. Indeed, if I copy a CD image or untar a kernel tree my keyboard and mouse are dead for several seconds.

There is no guaranteed "a bit more" within which we will see a keyboard event.

I think we can safely arrange that if the timer expires, we can be sure to check the 8042 for an event before synthesising one.

Quoted 4 lines

If the only events that are seen are actual events, and on rare occasions we miss an event, that is not so bad. We just hit that key again. But if we synthesize events, then a missed key up causes autorepeat.

You've mixed the question synthetic UP with software autorepeat. They are unrelated, and othogonal.

If you use software autorepeat, you have that problem of runaway events _anyway_, nothing to do with UP. And if you don't use software autorepeat, UP doesn't create a problem.

In fact, the synthetic UP is quite helpful if you miss real events. For programs which, say, grab the keyboard focus until the user lets go of a particular key, it is good that the program is eventually sent an UP. Otherwise it won't give up the focus at all. Similarly, in a game which does something as long as the player holds a key down, missing the real event results in the game assuming the key is perpetually held down.

Quoted 2 lines

In fact I see unwanted autorepeat - maybe once a day suddenly a single keystroke causes three to five identical

characters to appear - but I am not sure what mechanism causes this.

Faulty laptop keyboards. I get it too, with 2.4 and 2.5 kernels. It's not autorepeat, it's an instant burst of events. Possibly bad debouncing.

-- Jamie

#48 lore raw
In reply to Andries Brouwer
Quoted 5 lines · Andries Brouwer
Quoted 4 lines

So the decision must be: shall we do the wrong thing for keyboards which report DOWN only (the key will appear stuck to some programs), or shall we do the wrong thing for keyboards which report DOWN, no repeat and then UP, by making it look like the key was released early?

Quoted 7 lines

There are many more problems with your synthesized events. Look at your "repeat delay + a bit more". Can you specify how much "a bit more" is?

In times of heavy disk activity we lose interrupts. Indeed, if I copy a CD image or untar a kernel tree my keyboard and mouse are dead for several seconds.

This needs to be fixed. ;)

Quoted 2 lines

There is no guaranteed "a bit more" within which we will see a keyboard event.

Worst case we instead of autorepeat will generate a complete keypress and key release, not too bad, you won't even notice when your system has a second long response time.

Quoted 8 lines

If the only events that are seen are actual events, and on rare occasions we miss an event, that is not so bad. We just hit that key again. But if we synthesize events, then a missed key up causes autorepeat.

In fact I see unwanted autorepeat - maybe once a day suddenly a single keystroke causes three to five identical characters to appear - but I am not sure what mechanism causes this.

If you can find this, I'd be really grateful - some people see that, and I don't and I can't find any problem in the code.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#49 lore raw
In reply to Jamie Lokier
Quoted 14 lines · Jamie Lokier
Quoted 7 lines · Andries Brouwer
Quoted 5 lines

Synthesising an UP event after receiving a DOWN from the keyboard, and nothing else for that key for > (repeat delay + a bit more) time looks like a good plan to me, UNLESS there are keys which do report UP when the key is released (as opposed to immediately after the DOWN), and also don't repeat.

And there are keyboards with such keys.

Alas.

For programs which are only interested in key presses, there is no problem including a synthesised UP event.

Quoted 8 lines

But for programs which want to monitor a key and know its state continuously (this presently includes the software autorepeater, but it also includes games), none of the behaviours is right.

So the decision must be: shall we do the wrong thing for keyboards which report DOWN only (the key will appear stuck to some programs), or shall we do the wrong thing for keyboards which report DOWN, no repeat and then UP, by making it look like the key was released early?

I vote for the synthetised event and possibly making it disableable. It's a much bigger annoyance if your key stays stuck than if it goes up even when you're holding it. And remember that the keys affected will probably be special function keys only.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#50 lore raw
In reply to Jamie Lokier
Quoted 3 lines · Jamie Lokier

But for programs which want to monitor a key and know its state continuously (this presently includes the software autorepeater, but it also includes games), none of the behaviours is right.

X11 is another example of software that wants to know the state of keys
continuously. And that's not a piece of software to ignore easily.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#51 lore raw
Quoted 8 lines · Maciej W. Rozycki
Quoted 3 lines · Jamie Lokier

But for programs which want to monitor a key and know its state continuously (this presently includes the software autorepeater, but it also includes games), none of the behaviours is right.

X11 is another example of software that wants to know the state of keys
continuously. And that's not a piece of software to ignore easily.

You are both inventing the situation that games, or X11, ask the kernel for a bitmap of pressed keys. But they don't. The mechanism doesn't even exist.

#52 lore raw
Quoted 10 lines · Andries Brouwer
Quoted 6 lines
Quoted 3 lines

But for programs which want to monitor a key and know its state continuously (this presently includes the software autorepeater, but it also includes games), none of the behaviours is right.

X11 is another example of software that wants to know the state of keys
continuously. And that's not a piece of software to ignore easily.

You are both inventing the situation that games, or X11, ask the kernel for a bitmap of pressed keys. But they don't. The mechanism doesn't even exist.

I have no idea what X wants. What non-X "action" games want is simple (I have written a few): to know when the user is pushing particular keys.

Those games achieve this by observing a DOWN event when a key is pressed, an UP when it is released, to change their knowledge of a key state, and ignoring events which don't change their knowledge of the
state: auto-repeat DOWN events or spurious UP events.

-- Jamie

#53 lore raw
In reply to Andries Brouwer
Quoted 6 lines · Andries Brouwer
Quoted 2 lines

X11 is another example of software that wants to know the state of keys
continuously. And that's not a piece of software to ignore easily.

You are both inventing the situation that games, or X11, ask the kernel for a bitmap of pressed keys. But they don't. The mechanism doesn't even exist.

I don't know of any games, but X11 doesn't work that way. What I mean
X11 needs to know what keys are currently pressed and which are not. It handles that itself by tracking key presses and releases for all keys, so both kinds of events need to be reported properly. OTOH, the console doesn't really care about key releases except from modifier keys.

I'm sorry if my statement was ambiguous.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#54 lore raw
In reply to Andries Brouwer
Quoted 7 lines · Andries Brouwer
Quoted 5 lines

Synthesising an UP event after receiving a DOWN from the keyboard, and nothing else for that key for > (repeat delay + a bit more) time looks like a good plan to me, UNLESS there are keys which do report UP when the key is released (as opposed to immediately after the DOWN), and also don't repeat.

And there are keyboards with such keys.

Are there? Nevertheless the synthetic UP probably wouldn't hurt much, because it will only happen some 270 ms after the press at which time the user did probably already release the key, and if he did not, we just ignore the real release event.

I have that logic running on my computer and so far it doesn't cause any trouble.

Quoted 23 lines
Quoted 5 lines

Unrelated: I have some messages from my laptop, Toshiba Satellite 4070CDT:

atkbd.c: Unknown key (set 2, scancode 0x94, in isa0060/serio0) pressed. atkbd.c: Unknown key (set 2, scancode 0xbf, in isa0060/serio0) pressed. atkbd.c: Unknown key (set 2, scancode 0xa1, in isa0060/serio0) pressed.

Do you know what keystrokes cause this?

It looks like this cannot come from i8042_unxlate_table[]. Do you set i8042_direct?

Vojtech, this sounds like a bug in i8042.c:
We do

	if (data > 0x7f) {
		index = (data & 0x7f);
		if (test_and_clear_bit(index, i8042_unxlate_seen)) {
			data = i8042_unxlate_table[data & 0x7f];
		}
	} else {
		data = i8042_unxlate_table[data];
	}
	serio_interrupt(&i8042_kbd_port, data, dfl, regs);
Quoted 4 lines

In other words, the keyboard sends something in translated Set 2, but we fake that it is untranslated, unless it was
a key release and we didnt know that the key was down. Thus, atkbd.c gets a mixture of untranslated and translated codes.

It's not perfect, but it's the best what we can do if we don't want to move translated mode support to atkbd, which I definitely don't.

The problem is that only data below 0x7f is translated, by a mostly 1:1 table (there are two exceptions, 0x83 and 0x84). Data above 0x80 inclusive is not translated.

So, if you get a 0x9f code, you need to decide whether it really was 0x9f coming from the wire, or if it was actually 0xf0 0x27 coming from the wire.

The code has a slight problem with multiple key releases for a single key without a press event inbetween (which is what the toshiba does, and I've got another keyboard which does it, too). I already have a fix for that.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#55 lore raw
Quoted 7 lines · Vojtech Pavlik
Quoted 5 lines
Quoted 3 lines

UNLESS there are keys which do report UP when the key is released (as opposed to immediately after the DOWN), and also don't repeat.

And there are keyboards with such keys.

Are there?

I owe you an example. See, for example,

	http://www.win.tue.nl/~aeb/linux/kbd/scancodes-5.html#ss5.29

Abbreviated version:
Serge van den Boom reports that his LiteOn MediaTouch Keyboard has 18 additional keys: Suspend, Coffee, WWW, Calculator, Xfer, Switch window, Close, |<<, >|, [], >>|, Record, Rewind, Menu, Eject, Mute, Volume +, and Volume -. Of these, the keys |<<, >>|, Volume +, Volume - repeat. The others do not, except for the rather special Switch window key. Upon press it produces the LAlt-down, LShift-down, Tab-down, Tab-up sequence; it repeats Tab-down; and upon release it produces the sequence Tab-up, LAlt-up, LShift-up.
(Up events are as usual for the other 17 keys.)

#56 lore raw
Quoted 6 lines · Andries Brouwer
Quoted 4 lines · Vojtech Pavlik
Quoted 4 lines
Quoted 3 lines

UNLESS there are keys which do report UP when the key is released (as opposed to immediately after the DOWN), and also don't repeat.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

And there are keyboards with such keys.

Are there?

I owe you an example. See, for example,

	http://www.win.tue.nl/~aeb/linux/kbd/scancodes-5.html#ss5.29

Thanks.

Quoted 10 lines

Abbreviated version:
Serge van den Boom reports that his LiteOn MediaTouch Keyboard has 18 additional keys: Suspend, Coffee, WWW, Calculator, Xfer, Switch window, Close, |<<, >|, [], >>|, Record, Rewind, Menu, Eject, Mute, Volume +, and Volume -. Of these, the keys |<<, >>|, Volume +, Volume - repeat. The others do not, except for the rather special Switch window key. Upon press it produces the LAlt-down, LShift-down, Tab-down, Tab-up sequence; it repeats Tab-down; and upon release it produces the sequence Tab-up, LAlt-up, LShift-up.
(Up events are as usual for the other 17 keys.)

The code as is now (with the autorepeat and the forced up if the keyboard itself doesn't start repeating) won't have any problems with this keyboard.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#57 lore raw
Quoted 10 lines
Quoted 10 lines

Serge van den Boom reports that his LiteOn MediaTouch Keyboard has 18 additional keys: Suspend, Coffee, WWW, Calculator, Xfer, Switch window, Close, |<<, >|, [], >>|, Record, Rewind, Menu, Eject, Mute, Volume +, and Volume -. Of these, the keys |<<,

Quoted 1 line
Quoted 1 line

|, Volume +, Volume - repeat. The others do not, except for

the rather special Switch window key. Upon press it produces the LAlt-down, LShift-down, Tab-down, Tab-up sequence; it repeats Tab-down; and upon release it produces the sequence Tab-up, LAlt-up, LShift-up.
(Up events are as usual for the other 17 keys.)

Quoted 3 lines · Vojtech Pavlik

The code as is now (with the autorepeat and the forced up if the keyboard itself doesn't start repeating) won't have any problems with this keyboard.

That works well for typing, but if someone tries to use these keys in an action game, they will disappointed with the forced-up code - the game will see the key pressed and released, even when the user holds the key down for a long time.

Unfortunately, not doing the forced-up thing causes much worse problems, with the keys which started this thread.

There is only one solution which works well that I can see: do the forced-up thing by default, but as soon as you see a real UP event from a key, disabled forced-up _for that key_ in future.

That gives perfect results for typing, and after the first press of a key it is perfect for games too.

-- Jamie

Quoted 9 lines
Signature · 8 lines
-- 
Vojtech Pavlik
SuSE Labs, SuSE CR
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#58 lore raw
Quoted 12 lines · Jamie Lokier
Quoted 10 lines
Quoted 10 lines

Serge van den Boom reports that his LiteOn MediaTouch Keyboard has 18 additional keys: Suspend, Coffee, WWW, Calculator, Xfer, Switch window, Close, |<<, >|, [], >>|, Record, Rewind, Menu, Eject, Mute, Volume +, and Volume -. Of these, the keys |<<,

Quoted 1 line
Quoted 1 line

|, Volume +, Volume - repeat. The others do not, except for

the rather special Switch window key. Upon press it produces the LAlt-down, LShift-down, Tab-down, Tab-up sequence; it repeats Tab-down; and upon release it produces the sequence Tab-up, LAlt-up, LShift-up.
(Up events are as usual for the other 17 keys.)

Vojtech Pavlik wrote:

Quoted 8 lines
Quoted 3 lines

The code as is now (with the autorepeat and the forced up if the keyboard itself doesn't start repeating) won't have any problems with this keyboard.

That works well for typing, but if someone tries to use these keys in an action game, they will disappointed with the forced-up code - the game will see the key pressed and released, even when the user holds the key down for a long time.

Indeed. Are you expecting a game to be able to use the WWW or Calculator keys for anything useful?

Quoted 6 lines

Unfortunately, not doing the forced-up thing causes much worse problems, with the keys which started this thread.

There is only one solution which works well that I can see: do the forced-up thing by default, but as soon as you see a real UP event from a key, disabled forced-up _for that key_ in future.

Won't work. There are keyboards that forget to send a key up event sometimes. They usually send it, but from time to time they don't. We need to cover these keyboards, too. It's actually the main reason for the whole forced up thingy.

Quoted 2 lines

That gives perfect results for typing, and after the first press of a key it is perfect for games too.

I'll give you a kernel/module option to disable the forced up effect if you have a perfect keyboard. You can then also enable the untranslated mode and set 3. But the default will be translated set 2 with forced keyups if a key is not repeating.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#59 lore raw
Quoted 7 lines · Vojtech Pavlik
Quoted 4 lines

That works well for typing, but if someone tries to use these keys in an action game, they will disappointed with the forced-up code - the game will see the key pressed and released, even when the user holds the key down for a long time.

Indeed. Are you expecting a game to be able to use the WWW or Calculator keys for anything useful?

Of course. It's not unusual for a game to have a "define keys" option, where you press a key for each action, to set the key bindings. Sometimes you pick mnemonic keys; other times, you pick keys because of how their position feels, like making a custom joypad.

On my Microsoft multimedia keyboard there are about 20 keys that I could see being useful for that, especially as mnemonic keys.

Quoted 8 lines
Quoted 3 lines

There is only one solution which works well that I can see: do the forced-up thing by default, but as soon as you see a real UP event from a key, disabled forced-up _for that key_ in future.

Won't work. There are keyboards that forget to send a key up event sometimes. They usually send it, but from time to time they don't. We need to cover these keyboards, too. It's actually the main reason for the whole forced up thingy.

:( That's a shame, and a peculiar bug too. Then I agree that forced-up is needed all the time, if we do not know what triggers the keyboard to forget to send one or have any way to detect it.

It is not so bad, because even the multimedia keys will be fine on good quality keyboards.

Quoted 4 lines

I'll give you a kernel/module option to disable the forced up effect if you have a perfect keyboard. You can then also enable the untranslated mode and set 3. But the default will be translated set 2 with forced keyups if a key is not repeating.

Fair enough, I agree.

-- Jamie

#60 lore raw

Hi!

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

There is only one solution which works well that I can see: do the forced-up thing by default, but as soon as you see a real UP event from a key, disabled forced-up _for that key_ in future.

Quoted 8 lines
Quoted 4 lines

Won't work. There are keyboards that forget to send a key up event sometimes. They usually send it, but from time to time they don't. We need to cover these keyboards, too. It's actually the main reason for the whole forced up thingy.

:( That's a shame, and a peculiar bug too. Then I agree that forced-up is needed all the time, if we do not know what triggers the keyboard to forget to send one or have any way to detect it.

Can we at least report keyboard as broken to the syslog? Its usefull if we want manufacturers to eventually fix their hw (and its extremely usefull when someone gives you pre-production hw "see if you can break it")
Pavel

Signature · 2 lines
				Pavel
Written on sharp zaurus, because my Velo1 broke. If you have Velo you don't need...
#61 lore raw
In reply to Andries Brouwer
Quoted 4 lines · Andries Brouwer

The others do not, except for the rather special Switch window key. Upon press it produces the LAlt-down, LShift-down, Tab-down, Tab-up sequence; it repeats Tab-down; and upon release it produces the sequence Tab-up, LAlt-up, LShift-up.

What an interesting "design" of hardware trying to fit some version of
software. Do you know if the key behaves consitently if either or both <LAlt> and <LShift> are already depressed? And do cursor/editor keys work properly while <Switch_window> is depressed? Can I unambiguosly map the sequence the key generates e.g. to a "Multi_key" keysym? :->

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +