History log of /openbsd-current/sys/dev/pckbc/pckbd.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.51 13-Aug-2023 miod

The 8042 emulation found on Chromebooks does not support the RESET command,
for no good reason, and causes pckbc not to attach. However, sending a `get
keyboard id' works, so this can be used as a second check to give those
fawlty pieces of hardware a chance to work.

Based on a diff submitted by, and tested by, Vladimir 'phcoder' Serbinenko.


# 1.50 25-Jul-2023 miod

Extend the PCKBC_CANT_TRANSLATE feature, specific to Tadpole/RDI hardware,
to also support scan code set #3 in addition to the existing scan code set #2.

This makes the built-in keyboard on the Tadpole UltraBook IIe work.


# 1.49 24-Jul-2023 miod

Use RAWKEY constants for scan code tables, rather than magic numbers.
No functional change intended.


Revision tags: OPENBSD_7_3_BASE
# 1.48 08-Mar-2023 guenther

Delete obsolete /* ARGSUSED */ lint comments.

ok miod@ millert@


Revision tags: OPENBSD_7_2_BASE
# 1.47 06-Apr-2022 naddy

constify struct cfattach


Revision tags: OPENBSD_7_1_BASE
# 1.46 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.45 22-May-2018 mpi

Do not overwrite `table' in the non-translating case.

This ensures the keyboard is using the expected scancode.

From miod@, problem also noticed by Markus Hennecke, ok otto@


Revision tags: OPENBSD_6_3_BASE
# 1.44 06-Jan-2018 jcs

pckbd: don't change translation mode if controller is in table 2

This was changed a decade ago to forcibly try table 3 first in order
to make some now-long-gone hardware work.

Newer Lenovo machines seem to have trouble being asked to change
modes which manifests as a long boot delay as it waits for each
request to timeout, or by causing the keyboard to generate junk when
typing.

Assume table 2 by default and just leave it alone if it's already
there. This is how Linux has operated for quite a while and seems
to help on these Lenovo machines.

Tested by a few with these machines and has been in snaps for a bit.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.43 14-Apr-2016 mlarkin

Re-enable pckbd on resume (similar to what we do on boot). Fixes problems
on (at least) various HP laptops that previously had no working keyboard
after resuming from 'zzz'.

Reported by Aleksandar Lakic, who also verified several versions of the
diff during development, thanks.

discussed with miod and kettenis, tested by many others on tech@ - thanks.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.42 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.41 16-Mar-2015 jcs

Revert 1.39. Resetting after specifically putting the keyboard in a
different table will most likely just revert the keyboard to its
default table anyway.

Instead, just flush the kbd slot before choosing a table and then
still forcefully enable the slot, which is enough to fix UKC on the
3rd gen X1 carbon while having a much smaller chance of breaking
anything else.

ok deraadt


# 1.40 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.39 12-Mar-2015 deraadt

On first cnpoll, reset the keyboard and pms hard. This is required
to make "boot -c" support work on a variety of newer machines.
Do not anticipate this harming older machines, but we'll have to wait
and see with this change in the tree.
with jcs


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.38 24-Jul-2014 mpi

Speed up the boot sequence by deferring the scan of xt keyboard code set.

If you were wondering why there's a pause of 5 seconds after loading the
kernel and before seeing the copyright in blue when booting some of your
machines, well this is for you!

mlarkin@ found that this delay is caused by some code probing for xt scan
code tables when pckbd(4) initialize the console keyboard. So this diff
implements an idea from deraadt@ to only do the scan once, either during
*attach() or if we enter ddb> or ukc> before that!

ok miod@, mlarkin@, deraadt@, shadchin@


# 1.37 23-Mar-2014 ratchov

my bad, last commit was not ok deraadt, revert it.


# 1.36 13-Mar-2014 ratchov

Don't use volume keys when in raw-mode (this doesn't work), and let
Xorg driver do the translation and handle them as regular keys. Fixes
confusion caused by the volume being changed twice in contradictory
ways: once by X programs and once by the pckbd(4) driver.

ok deraadt, kettenis


Revision tags: OPENBSD_5_5_BASE
# 1.35 26-Jan-2014 miod

Attempt to make user changes of keyboard layout a bit more `sticky' on wsmux
kernels:
- keyboard drivers will now tell wskbd if the keyboard layout they ask
for is a default value, or a value they are 100% sure of (either
because your kernel has a XXXKBD_LAYOUT option, or because the
driver can tell the keyboard layout, e.g. by the country code on USB
keyboards which provide it, such as Sun's)
- when attaching a keyboard with a non-default layout, the layout will
become the default layout of the mux for new keyboard attachments if
the mux doesn't have a layout set already.
- when changing the keyboard layout of a particular keyboard with an
ioctl (i.e. using kbd(8) or wsconsctl(8)), the layout will become the
default layout of the mux for new keyboard attachments.

ok mpi@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 15-Feb-2013 ratchov

backout latest: audio keys can autorepeat. Autorepeated keys are not
decoded by the wskbd layer, thus autorepeted audio keys end-up passed
to userland in raw mode (ie to X), resulting in keyboard input
corruption. Noticed (and debugged) by halex@, thanks.


# 1.33 06-Jan-2013 ratchov

don't propagate XF86XK_Audio{Lower,Raise}Volume keys to userspace,
otherwise volume may be adjusted twice: once by X apps and once in
the kernel.

feedback from many, ok shadchin@


# 1.32 10-Aug-2012 shadchin

simplify pckbc_xt_translation()
* call only for set translation on (once in /sys/dev/pckbd.c)
therefore we can delete unused code.
* change behavior (more standard) - return zero on success

ok miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.31 17-Mar-2011 shadchin

Ansify non-ansified function definitions. No functional change.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.30 16-Dec-2010 shadchin

small cleanup ioctl WSKBDIO_GETLEDS

ok miod@


# 1.29 03-Dec-2010 shadchin

removed slot argument of function pckbd_cnattach
because it is always PCKBC_KBD_SLOT

ok miod@, krw@


# 1.28 28-Aug-2010 miod

In pckbd_scancode_translate(), correctly translate the break sequence
between scan code sets 1 and 2.


Revision tags: OPENBSD_4_8_BASE
# 1.27 22-Jul-2010 deraadt

Don't do anything on suspend/resume for now (there is a diff brewing,
but it has some problems still..)


# 1.26 21-Jul-2010 miod

Disable the heuristics for legacy free systems if pckbc flags are set to 1
in UKC; found the hard way by jakemsr@ on an old Tecra laptop.


# 1.25 08-Jul-2010 deraadt

For DVACT_SUSPEND and DVACT_RESUME we should always return success.


Revision tags: OPENBSD_4_7_BASE
# 1.24 23-Nov-2009 deraadt

pckbd_activate() should return failure if it knows; ok pirofti


# 1.23 23-Nov-2009 deraadt

better style is DVACT_SUSPEND before DVACT_RESUME


# 1.22 23-Nov-2009 pirofti

Fix pckbd and acpihpet suspend/resume cases to fit with the future framework
that's going to get in really soon.

Okay mlarkin@, deraadt@.


# 1.21 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


# 1.20 25-Aug-2009 miod

Legacy-free PC hardware do not have a real PS/2 keyboard controller, but
rather have the USB HCI emulate it during boot, while legacy mode is enabled.

This causes pckbd0 to attach as the console device, but is lost as soon as
the USB HCI driver attaches.

The disappearance of the emulated PS/2 controller can however be detected
in pckbc(4) - which is supposed to attach after [eou]hci(4), with the controller
refusing to ack commands and replying ``please resend'' instead.

In that case, the kernel will now no longer attach pckbd, and will perform a
new console input device selection, allowing the (real) usb keyboard to
become the console.

Thanks to krw@ for countless tests on legacy-free hardware; also tested on
more conventional hardware by naddy@ and I.

Only amd64 and i386 platforms are affected by this change.


# 1.19 13-Aug-2009 pirofti

Forgot to add break to the switch cases. Silly.
Okay deraadt@.


# 1.18 13-Aug-2009 pirofti

Add wake/suspend support for pckbd(4).

Patch initially from mlarkin@. KNF and refactoring by me.
Suggestions and okay deraadt@.


Revision tags: OPENBSD_4_6_BASE
# 1.17 03-May-2009 miod

Make sure pckbd_scancode_translate() returns a scancode with the break/release
bit set if needed, in all cases. This fixes rawkbd operation on controllers
which require the kernel to perform scancode translation.

Found by and ok kettenis@


Revision tags: OPENBSD_4_5_BASE
# 1.16 21-Nov-2008 robert

Move #include <dev/pckbc/wskbdmap_mfii.h> after including
dev/wscons/wsksymvar.h where struct wskbd_mapdata gets
declared.

ok miod@


Revision tags: OPENBSD_4_4_BASE
# 1.15 16-Jul-2008 miod

If pckbc_xt_translation() fails, do not try to force the keyboard in table
1; instead, try table 2 first, then 1: some older keyboards, connected to
a castrated 8042, do not know how to talk in table 1 (or worse, will report
they do while they don't).

If automatic translation is not possible, remember which table the keyboard
ended configured in, and convert the scancodes from table 2 to table 1 if
necessary.

ok kettenis@


# 1.14 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.13 31-Dec-2007 miod

Keep running the scancode translation state machine even when the keyboard
is set to raw mode, but only feed decoded events to wscons if non-raw mode.

Then, as an exception to this, pass the audio control keys events to
wscons even if in raw mode, so that the in-kernel mixer control code can
perform its work. The event is also seen by the raw event consumer (i.e.
the X server).

Requested and tested by many...


# 1.12 17-Oct-2007 deraadt

miod says noone needs isa/isavar.h anymore, and i believe him


# 1.11 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


# 1.10 17-Oct-2007 fgsch

- Remove a shadow declaration.
- Correct resp size.

deraadt@ ok.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.9 30-Jan-2007 jcs

default to have pckbd_set_xtscancode() instruct the 8042 to use
table 3, still falling back on table 2 or 1 after carefully checking
that the table set request took

fixes the keyboard on the oqo model 01/01+

in snaps for a while, tested by many

ok miod@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.8 29-Dec-2005 martin

go via pckbc_enqeue_cmd() in pckbd_enable() if on; fixes PR 4615

ok miod@, mickey@


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.7 22-Feb-2005 mickey

send enable cmd after a reset; form netbsd


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.6 22-Oct-2003 jmc

typos from Tom Cosgrove;


Revision tags: OPENBSD_3_4_BASE
# 1.5 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


# 1.3 18-Feb-2002 jason

Don't include isavar.h on sparc64


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE UBC_BASE
# 1.2 02-Feb-2001 aaron

branches: 1.2.4; 1.2.8;
Remove dead code.


# 1.1 13-Nov-2000 aaron

Machine-independent PC-like keyboard driver; from NetBSD. XXX - Not used
anywhere quite yet, but useful to have these files in the tree while we work
towards wscons for i386 and alpha.


# 1.50 25-Jul-2023 miod

Extend the PCKBC_CANT_TRANSLATE feature, specific to Tadpole/RDI hardware,
to also support scan code set #3 in addition to the existing scan code set #2.

This makes the built-in keyboard on the Tadpole UltraBook IIe work.


# 1.49 24-Jul-2023 miod

Use RAWKEY constants for scan code tables, rather than magic numbers.
No functional change intended.


Revision tags: OPENBSD_7_3_BASE
# 1.48 08-Mar-2023 guenther

Delete obsolete /* ARGSUSED */ lint comments.

ok miod@ millert@


Revision tags: OPENBSD_7_2_BASE
# 1.47 06-Apr-2022 naddy

constify struct cfattach


Revision tags: OPENBSD_7_1_BASE
# 1.46 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.45 22-May-2018 mpi

Do not overwrite `table' in the non-translating case.

This ensures the keyboard is using the expected scancode.

From miod@, problem also noticed by Markus Hennecke, ok otto@


Revision tags: OPENBSD_6_3_BASE
# 1.44 06-Jan-2018 jcs

pckbd: don't change translation mode if controller is in table 2

This was changed a decade ago to forcibly try table 3 first in order
to make some now-long-gone hardware work.

Newer Lenovo machines seem to have trouble being asked to change
modes which manifests as a long boot delay as it waits for each
request to timeout, or by causing the keyboard to generate junk when
typing.

Assume table 2 by default and just leave it alone if it's already
there. This is how Linux has operated for quite a while and seems
to help on these Lenovo machines.

Tested by a few with these machines and has been in snaps for a bit.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.43 14-Apr-2016 mlarkin

Re-enable pckbd on resume (similar to what we do on boot). Fixes problems
on (at least) various HP laptops that previously had no working keyboard
after resuming from 'zzz'.

Reported by Aleksandar Lakic, who also verified several versions of the
diff during development, thanks.

discussed with miod and kettenis, tested by many others on tech@ - thanks.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.42 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.41 16-Mar-2015 jcs

Revert 1.39. Resetting after specifically putting the keyboard in a
different table will most likely just revert the keyboard to its
default table anyway.

Instead, just flush the kbd slot before choosing a table and then
still forcefully enable the slot, which is enough to fix UKC on the
3rd gen X1 carbon while having a much smaller chance of breaking
anything else.

ok deraadt


# 1.40 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.39 12-Mar-2015 deraadt

On first cnpoll, reset the keyboard and pms hard. This is required
to make "boot -c" support work on a variety of newer machines.
Do not anticipate this harming older machines, but we'll have to wait
and see with this change in the tree.
with jcs


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.38 24-Jul-2014 mpi

Speed up the boot sequence by deferring the scan of xt keyboard code set.

If you were wondering why there's a pause of 5 seconds after loading the
kernel and before seeing the copyright in blue when booting some of your
machines, well this is for you!

mlarkin@ found that this delay is caused by some code probing for xt scan
code tables when pckbd(4) initialize the console keyboard. So this diff
implements an idea from deraadt@ to only do the scan once, either during
*attach() or if we enter ddb> or ukc> before that!

ok miod@, mlarkin@, deraadt@, shadchin@


# 1.37 23-Mar-2014 ratchov

my bad, last commit was not ok deraadt, revert it.


# 1.36 13-Mar-2014 ratchov

Don't use volume keys when in raw-mode (this doesn't work), and let
Xorg driver do the translation and handle them as regular keys. Fixes
confusion caused by the volume being changed twice in contradictory
ways: once by X programs and once by the pckbd(4) driver.

ok deraadt, kettenis


Revision tags: OPENBSD_5_5_BASE
# 1.35 26-Jan-2014 miod

Attempt to make user changes of keyboard layout a bit more `sticky' on wsmux
kernels:
- keyboard drivers will now tell wskbd if the keyboard layout they ask
for is a default value, or a value they are 100% sure of (either
because your kernel has a XXXKBD_LAYOUT option, or because the
driver can tell the keyboard layout, e.g. by the country code on USB
keyboards which provide it, such as Sun's)
- when attaching a keyboard with a non-default layout, the layout will
become the default layout of the mux for new keyboard attachments if
the mux doesn't have a layout set already.
- when changing the keyboard layout of a particular keyboard with an
ioctl (i.e. using kbd(8) or wsconsctl(8)), the layout will become the
default layout of the mux for new keyboard attachments.

ok mpi@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 15-Feb-2013 ratchov

backout latest: audio keys can autorepeat. Autorepeated keys are not
decoded by the wskbd layer, thus autorepeted audio keys end-up passed
to userland in raw mode (ie to X), resulting in keyboard input
corruption. Noticed (and debugged) by halex@, thanks.


# 1.33 06-Jan-2013 ratchov

don't propagate XF86XK_Audio{Lower,Raise}Volume keys to userspace,
otherwise volume may be adjusted twice: once by X apps and once in
the kernel.

feedback from many, ok shadchin@


# 1.32 10-Aug-2012 shadchin

simplify pckbc_xt_translation()
* call only for set translation on (once in /sys/dev/pckbd.c)
therefore we can delete unused code.
* change behavior (more standard) - return zero on success

ok miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.31 17-Mar-2011 shadchin

Ansify non-ansified function definitions. No functional change.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.30 16-Dec-2010 shadchin

small cleanup ioctl WSKBDIO_GETLEDS

ok miod@


# 1.29 03-Dec-2010 shadchin

removed slot argument of function pckbd_cnattach
because it is always PCKBC_KBD_SLOT

ok miod@, krw@


# 1.28 28-Aug-2010 miod

In pckbd_scancode_translate(), correctly translate the break sequence
between scan code sets 1 and 2.


Revision tags: OPENBSD_4_8_BASE
# 1.27 22-Jul-2010 deraadt

Don't do anything on suspend/resume for now (there is a diff brewing,
but it has some problems still..)


# 1.26 21-Jul-2010 miod

Disable the heuristics for legacy free systems if pckbc flags are set to 1
in UKC; found the hard way by jakemsr@ on an old Tecra laptop.


# 1.25 08-Jul-2010 deraadt

For DVACT_SUSPEND and DVACT_RESUME we should always return success.


Revision tags: OPENBSD_4_7_BASE
# 1.24 23-Nov-2009 deraadt

pckbd_activate() should return failure if it knows; ok pirofti


# 1.23 23-Nov-2009 deraadt

better style is DVACT_SUSPEND before DVACT_RESUME


# 1.22 23-Nov-2009 pirofti

Fix pckbd and acpihpet suspend/resume cases to fit with the future framework
that's going to get in really soon.

Okay mlarkin@, deraadt@.


# 1.21 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


# 1.20 25-Aug-2009 miod

Legacy-free PC hardware do not have a real PS/2 keyboard controller, but
rather have the USB HCI emulate it during boot, while legacy mode is enabled.

This causes pckbd0 to attach as the console device, but is lost as soon as
the USB HCI driver attaches.

The disappearance of the emulated PS/2 controller can however be detected
in pckbc(4) - which is supposed to attach after [eou]hci(4), with the controller
refusing to ack commands and replying ``please resend'' instead.

In that case, the kernel will now no longer attach pckbd, and will perform a
new console input device selection, allowing the (real) usb keyboard to
become the console.

Thanks to krw@ for countless tests on legacy-free hardware; also tested on
more conventional hardware by naddy@ and I.

Only amd64 and i386 platforms are affected by this change.


# 1.19 13-Aug-2009 pirofti

Forgot to add break to the switch cases. Silly.
Okay deraadt@.


# 1.18 13-Aug-2009 pirofti

Add wake/suspend support for pckbd(4).

Patch initially from mlarkin@. KNF and refactoring by me.
Suggestions and okay deraadt@.


Revision tags: OPENBSD_4_6_BASE
# 1.17 03-May-2009 miod

Make sure pckbd_scancode_translate() returns a scancode with the break/release
bit set if needed, in all cases. This fixes rawkbd operation on controllers
which require the kernel to perform scancode translation.

Found by and ok kettenis@


Revision tags: OPENBSD_4_5_BASE
# 1.16 21-Nov-2008 robert

Move #include <dev/pckbc/wskbdmap_mfii.h> after including
dev/wscons/wsksymvar.h where struct wskbd_mapdata gets
declared.

ok miod@


Revision tags: OPENBSD_4_4_BASE
# 1.15 16-Jul-2008 miod

If pckbc_xt_translation() fails, do not try to force the keyboard in table
1; instead, try table 2 first, then 1: some older keyboards, connected to
a castrated 8042, do not know how to talk in table 1 (or worse, will report
they do while they don't).

If automatic translation is not possible, remember which table the keyboard
ended configured in, and convert the scancodes from table 2 to table 1 if
necessary.

ok kettenis@


# 1.14 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.13 31-Dec-2007 miod

Keep running the scancode translation state machine even when the keyboard
is set to raw mode, but only feed decoded events to wscons if non-raw mode.

Then, as an exception to this, pass the audio control keys events to
wscons even if in raw mode, so that the in-kernel mixer control code can
perform its work. The event is also seen by the raw event consumer (i.e.
the X server).

Requested and tested by many...


# 1.12 17-Oct-2007 deraadt

miod says noone needs isa/isavar.h anymore, and i believe him


# 1.11 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


# 1.10 17-Oct-2007 fgsch

- Remove a shadow declaration.
- Correct resp size.

deraadt@ ok.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.9 30-Jan-2007 jcs

default to have pckbd_set_xtscancode() instruct the 8042 to use
table 3, still falling back on table 2 or 1 after carefully checking
that the table set request took

fixes the keyboard on the oqo model 01/01+

in snaps for a while, tested by many

ok miod@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.8 29-Dec-2005 martin

go via pckbc_enqeue_cmd() in pckbd_enable() if on; fixes PR 4615

ok miod@, mickey@


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.7 22-Feb-2005 mickey

send enable cmd after a reset; form netbsd


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.6 22-Oct-2003 jmc

typos from Tom Cosgrove;


Revision tags: OPENBSD_3_4_BASE
# 1.5 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


# 1.3 18-Feb-2002 jason

Don't include isavar.h on sparc64


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE UBC_BASE
# 1.2 02-Feb-2001 aaron

branches: 1.2.4; 1.2.8;
Remove dead code.


# 1.1 13-Nov-2000 aaron

Machine-independent PC-like keyboard driver; from NetBSD. XXX - Not used
anywhere quite yet, but useful to have these files in the tree while we work
towards wscons for i386 and alpha.


# 1.48 08-Mar-2023 guenther

Delete obsolete /* ARGSUSED */ lint comments.

ok miod@ millert@


Revision tags: OPENBSD_7_2_BASE
# 1.47 06-Apr-2022 naddy

constify struct cfattach


Revision tags: OPENBSD_7_1_BASE
# 1.46 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.45 22-May-2018 mpi

Do not overwrite `table' in the non-translating case.

This ensures the keyboard is using the expected scancode.

From miod@, problem also noticed by Markus Hennecke, ok otto@


Revision tags: OPENBSD_6_3_BASE
# 1.44 06-Jan-2018 jcs

pckbd: don't change translation mode if controller is in table 2

This was changed a decade ago to forcibly try table 3 first in order
to make some now-long-gone hardware work.

Newer Lenovo machines seem to have trouble being asked to change
modes which manifests as a long boot delay as it waits for each
request to timeout, or by causing the keyboard to generate junk when
typing.

Assume table 2 by default and just leave it alone if it's already
there. This is how Linux has operated for quite a while and seems
to help on these Lenovo machines.

Tested by a few with these machines and has been in snaps for a bit.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.43 14-Apr-2016 mlarkin

Re-enable pckbd on resume (similar to what we do on boot). Fixes problems
on (at least) various HP laptops that previously had no working keyboard
after resuming from 'zzz'.

Reported by Aleksandar Lakic, who also verified several versions of the
diff during development, thanks.

discussed with miod and kettenis, tested by many others on tech@ - thanks.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.42 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.41 16-Mar-2015 jcs

Revert 1.39. Resetting after specifically putting the keyboard in a
different table will most likely just revert the keyboard to its
default table anyway.

Instead, just flush the kbd slot before choosing a table and then
still forcefully enable the slot, which is enough to fix UKC on the
3rd gen X1 carbon while having a much smaller chance of breaking
anything else.

ok deraadt


# 1.40 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.39 12-Mar-2015 deraadt

On first cnpoll, reset the keyboard and pms hard. This is required
to make "boot -c" support work on a variety of newer machines.
Do not anticipate this harming older machines, but we'll have to wait
and see with this change in the tree.
with jcs


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.38 24-Jul-2014 mpi

Speed up the boot sequence by deferring the scan of xt keyboard code set.

If you were wondering why there's a pause of 5 seconds after loading the
kernel and before seeing the copyright in blue when booting some of your
machines, well this is for you!

mlarkin@ found that this delay is caused by some code probing for xt scan
code tables when pckbd(4) initialize the console keyboard. So this diff
implements an idea from deraadt@ to only do the scan once, either during
*attach() or if we enter ddb> or ukc> before that!

ok miod@, mlarkin@, deraadt@, shadchin@


# 1.37 23-Mar-2014 ratchov

my bad, last commit was not ok deraadt, revert it.


# 1.36 13-Mar-2014 ratchov

Don't use volume keys when in raw-mode (this doesn't work), and let
Xorg driver do the translation and handle them as regular keys. Fixes
confusion caused by the volume being changed twice in contradictory
ways: once by X programs and once by the pckbd(4) driver.

ok deraadt, kettenis


Revision tags: OPENBSD_5_5_BASE
# 1.35 26-Jan-2014 miod

Attempt to make user changes of keyboard layout a bit more `sticky' on wsmux
kernels:
- keyboard drivers will now tell wskbd if the keyboard layout they ask
for is a default value, or a value they are 100% sure of (either
because your kernel has a XXXKBD_LAYOUT option, or because the
driver can tell the keyboard layout, e.g. by the country code on USB
keyboards which provide it, such as Sun's)
- when attaching a keyboard with a non-default layout, the layout will
become the default layout of the mux for new keyboard attachments if
the mux doesn't have a layout set already.
- when changing the keyboard layout of a particular keyboard with an
ioctl (i.e. using kbd(8) or wsconsctl(8)), the layout will become the
default layout of the mux for new keyboard attachments.

ok mpi@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 15-Feb-2013 ratchov

backout latest: audio keys can autorepeat. Autorepeated keys are not
decoded by the wskbd layer, thus autorepeted audio keys end-up passed
to userland in raw mode (ie to X), resulting in keyboard input
corruption. Noticed (and debugged) by halex@, thanks.


# 1.33 06-Jan-2013 ratchov

don't propagate XF86XK_Audio{Lower,Raise}Volume keys to userspace,
otherwise volume may be adjusted twice: once by X apps and once in
the kernel.

feedback from many, ok shadchin@


# 1.32 10-Aug-2012 shadchin

simplify pckbc_xt_translation()
* call only for set translation on (once in /sys/dev/pckbd.c)
therefore we can delete unused code.
* change behavior (more standard) - return zero on success

ok miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.31 17-Mar-2011 shadchin

Ansify non-ansified function definitions. No functional change.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.30 16-Dec-2010 shadchin

small cleanup ioctl WSKBDIO_GETLEDS

ok miod@


# 1.29 03-Dec-2010 shadchin

removed slot argument of function pckbd_cnattach
because it is always PCKBC_KBD_SLOT

ok miod@, krw@


# 1.28 28-Aug-2010 miod

In pckbd_scancode_translate(), correctly translate the break sequence
between scan code sets 1 and 2.


Revision tags: OPENBSD_4_8_BASE
# 1.27 22-Jul-2010 deraadt

Don't do anything on suspend/resume for now (there is a diff brewing,
but it has some problems still..)


# 1.26 21-Jul-2010 miod

Disable the heuristics for legacy free systems if pckbc flags are set to 1
in UKC; found the hard way by jakemsr@ on an old Tecra laptop.


# 1.25 08-Jul-2010 deraadt

For DVACT_SUSPEND and DVACT_RESUME we should always return success.


Revision tags: OPENBSD_4_7_BASE
# 1.24 23-Nov-2009 deraadt

pckbd_activate() should return failure if it knows; ok pirofti


# 1.23 23-Nov-2009 deraadt

better style is DVACT_SUSPEND before DVACT_RESUME


# 1.22 23-Nov-2009 pirofti

Fix pckbd and acpihpet suspend/resume cases to fit with the future framework
that's going to get in really soon.

Okay mlarkin@, deraadt@.


# 1.21 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


# 1.20 25-Aug-2009 miod

Legacy-free PC hardware do not have a real PS/2 keyboard controller, but
rather have the USB HCI emulate it during boot, while legacy mode is enabled.

This causes pckbd0 to attach as the console device, but is lost as soon as
the USB HCI driver attaches.

The disappearance of the emulated PS/2 controller can however be detected
in pckbc(4) - which is supposed to attach after [eou]hci(4), with the controller
refusing to ack commands and replying ``please resend'' instead.

In that case, the kernel will now no longer attach pckbd, and will perform a
new console input device selection, allowing the (real) usb keyboard to
become the console.

Thanks to krw@ for countless tests on legacy-free hardware; also tested on
more conventional hardware by naddy@ and I.

Only amd64 and i386 platforms are affected by this change.


# 1.19 13-Aug-2009 pirofti

Forgot to add break to the switch cases. Silly.
Okay deraadt@.


# 1.18 13-Aug-2009 pirofti

Add wake/suspend support for pckbd(4).

Patch initially from mlarkin@. KNF and refactoring by me.
Suggestions and okay deraadt@.


Revision tags: OPENBSD_4_6_BASE
# 1.17 03-May-2009 miod

Make sure pckbd_scancode_translate() returns a scancode with the break/release
bit set if needed, in all cases. This fixes rawkbd operation on controllers
which require the kernel to perform scancode translation.

Found by and ok kettenis@


Revision tags: OPENBSD_4_5_BASE
# 1.16 21-Nov-2008 robert

Move #include <dev/pckbc/wskbdmap_mfii.h> after including
dev/wscons/wsksymvar.h where struct wskbd_mapdata gets
declared.

ok miod@


Revision tags: OPENBSD_4_4_BASE
# 1.15 16-Jul-2008 miod

If pckbc_xt_translation() fails, do not try to force the keyboard in table
1; instead, try table 2 first, then 1: some older keyboards, connected to
a castrated 8042, do not know how to talk in table 1 (or worse, will report
they do while they don't).

If automatic translation is not possible, remember which table the keyboard
ended configured in, and convert the scancodes from table 2 to table 1 if
necessary.

ok kettenis@


# 1.14 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.13 31-Dec-2007 miod

Keep running the scancode translation state machine even when the keyboard
is set to raw mode, but only feed decoded events to wscons if non-raw mode.

Then, as an exception to this, pass the audio control keys events to
wscons even if in raw mode, so that the in-kernel mixer control code can
perform its work. The event is also seen by the raw event consumer (i.e.
the X server).

Requested and tested by many...


# 1.12 17-Oct-2007 deraadt

miod says noone needs isa/isavar.h anymore, and i believe him


# 1.11 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


# 1.10 17-Oct-2007 fgsch

- Remove a shadow declaration.
- Correct resp size.

deraadt@ ok.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.9 30-Jan-2007 jcs

default to have pckbd_set_xtscancode() instruct the 8042 to use
table 3, still falling back on table 2 or 1 after carefully checking
that the table set request took

fixes the keyboard on the oqo model 01/01+

in snaps for a while, tested by many

ok miod@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.8 29-Dec-2005 martin

go via pckbc_enqeue_cmd() in pckbd_enable() if on; fixes PR 4615

ok miod@, mickey@


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.7 22-Feb-2005 mickey

send enable cmd after a reset; form netbsd


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.6 22-Oct-2003 jmc

typos from Tom Cosgrove;


Revision tags: OPENBSD_3_4_BASE
# 1.5 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


# 1.3 18-Feb-2002 jason

Don't include isavar.h on sparc64


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE UBC_BASE
# 1.2 02-Feb-2001 aaron

branches: 1.2.4; 1.2.8;
Remove dead code.


# 1.1 13-Nov-2000 aaron

Machine-independent PC-like keyboard driver; from NetBSD. XXX - Not used
anywhere quite yet, but useful to have these files in the tree while we work
towards wscons for i386 and alpha.


# 1.47 06-Apr-2022 naddy

constify struct cfattach


Revision tags: OPENBSD_7_1_BASE
# 1.46 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.45 22-May-2018 mpi

Do not overwrite `table' in the non-translating case.

This ensures the keyboard is using the expected scancode.

From miod@, problem also noticed by Markus Hennecke, ok otto@


Revision tags: OPENBSD_6_3_BASE
# 1.44 06-Jan-2018 jcs

pckbd: don't change translation mode if controller is in table 2

This was changed a decade ago to forcibly try table 3 first in order
to make some now-long-gone hardware work.

Newer Lenovo machines seem to have trouble being asked to change
modes which manifests as a long boot delay as it waits for each
request to timeout, or by causing the keyboard to generate junk when
typing.

Assume table 2 by default and just leave it alone if it's already
there. This is how Linux has operated for quite a while and seems
to help on these Lenovo machines.

Tested by a few with these machines and has been in snaps for a bit.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.43 14-Apr-2016 mlarkin

Re-enable pckbd on resume (similar to what we do on boot). Fixes problems
on (at least) various HP laptops that previously had no working keyboard
after resuming from 'zzz'.

Reported by Aleksandar Lakic, who also verified several versions of the
diff during development, thanks.

discussed with miod and kettenis, tested by many others on tech@ - thanks.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.42 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.41 16-Mar-2015 jcs

Revert 1.39. Resetting after specifically putting the keyboard in a
different table will most likely just revert the keyboard to its
default table anyway.

Instead, just flush the kbd slot before choosing a table and then
still forcefully enable the slot, which is enough to fix UKC on the
3rd gen X1 carbon while having a much smaller chance of breaking
anything else.

ok deraadt


# 1.40 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.39 12-Mar-2015 deraadt

On first cnpoll, reset the keyboard and pms hard. This is required
to make "boot -c" support work on a variety of newer machines.
Do not anticipate this harming older machines, but we'll have to wait
and see with this change in the tree.
with jcs


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.38 24-Jul-2014 mpi

Speed up the boot sequence by deferring the scan of xt keyboard code set.

If you were wondering why there's a pause of 5 seconds after loading the
kernel and before seeing the copyright in blue when booting some of your
machines, well this is for you!

mlarkin@ found that this delay is caused by some code probing for xt scan
code tables when pckbd(4) initialize the console keyboard. So this diff
implements an idea from deraadt@ to only do the scan once, either during
*attach() or if we enter ddb> or ukc> before that!

ok miod@, mlarkin@, deraadt@, shadchin@


# 1.37 23-Mar-2014 ratchov

my bad, last commit was not ok deraadt, revert it.


# 1.36 13-Mar-2014 ratchov

Don't use volume keys when in raw-mode (this doesn't work), and let
Xorg driver do the translation and handle them as regular keys. Fixes
confusion caused by the volume being changed twice in contradictory
ways: once by X programs and once by the pckbd(4) driver.

ok deraadt, kettenis


Revision tags: OPENBSD_5_5_BASE
# 1.35 26-Jan-2014 miod

Attempt to make user changes of keyboard layout a bit more `sticky' on wsmux
kernels:
- keyboard drivers will now tell wskbd if the keyboard layout they ask
for is a default value, or a value they are 100% sure of (either
because your kernel has a XXXKBD_LAYOUT option, or because the
driver can tell the keyboard layout, e.g. by the country code on USB
keyboards which provide it, such as Sun's)
- when attaching a keyboard with a non-default layout, the layout will
become the default layout of the mux for new keyboard attachments if
the mux doesn't have a layout set already.
- when changing the keyboard layout of a particular keyboard with an
ioctl (i.e. using kbd(8) or wsconsctl(8)), the layout will become the
default layout of the mux for new keyboard attachments.

ok mpi@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 15-Feb-2013 ratchov

backout latest: audio keys can autorepeat. Autorepeated keys are not
decoded by the wskbd layer, thus autorepeted audio keys end-up passed
to userland in raw mode (ie to X), resulting in keyboard input
corruption. Noticed (and debugged) by halex@, thanks.


# 1.33 06-Jan-2013 ratchov

don't propagate XF86XK_Audio{Lower,Raise}Volume keys to userspace,
otherwise volume may be adjusted twice: once by X apps and once in
the kernel.

feedback from many, ok shadchin@


# 1.32 10-Aug-2012 shadchin

simplify pckbc_xt_translation()
* call only for set translation on (once in /sys/dev/pckbd.c)
therefore we can delete unused code.
* change behavior (more standard) - return zero on success

ok miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.31 17-Mar-2011 shadchin

Ansify non-ansified function definitions. No functional change.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.30 16-Dec-2010 shadchin

small cleanup ioctl WSKBDIO_GETLEDS

ok miod@


# 1.29 03-Dec-2010 shadchin

removed slot argument of function pckbd_cnattach
because it is always PCKBC_KBD_SLOT

ok miod@, krw@


# 1.28 28-Aug-2010 miod

In pckbd_scancode_translate(), correctly translate the break sequence
between scan code sets 1 and 2.


Revision tags: OPENBSD_4_8_BASE
# 1.27 22-Jul-2010 deraadt

Don't do anything on suspend/resume for now (there is a diff brewing,
but it has some problems still..)


# 1.26 21-Jul-2010 miod

Disable the heuristics for legacy free systems if pckbc flags are set to 1
in UKC; found the hard way by jakemsr@ on an old Tecra laptop.


# 1.25 08-Jul-2010 deraadt

For DVACT_SUSPEND and DVACT_RESUME we should always return success.


Revision tags: OPENBSD_4_7_BASE
# 1.24 23-Nov-2009 deraadt

pckbd_activate() should return failure if it knows; ok pirofti


# 1.23 23-Nov-2009 deraadt

better style is DVACT_SUSPEND before DVACT_RESUME


# 1.22 23-Nov-2009 pirofti

Fix pckbd and acpihpet suspend/resume cases to fit with the future framework
that's going to get in really soon.

Okay mlarkin@, deraadt@.


# 1.21 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


# 1.20 25-Aug-2009 miod

Legacy-free PC hardware do not have a real PS/2 keyboard controller, but
rather have the USB HCI emulate it during boot, while legacy mode is enabled.

This causes pckbd0 to attach as the console device, but is lost as soon as
the USB HCI driver attaches.

The disappearance of the emulated PS/2 controller can however be detected
in pckbc(4) - which is supposed to attach after [eou]hci(4), with the controller
refusing to ack commands and replying ``please resend'' instead.

In that case, the kernel will now no longer attach pckbd, and will perform a
new console input device selection, allowing the (real) usb keyboard to
become the console.

Thanks to krw@ for countless tests on legacy-free hardware; also tested on
more conventional hardware by naddy@ and I.

Only amd64 and i386 platforms are affected by this change.


# 1.19 13-Aug-2009 pirofti

Forgot to add break to the switch cases. Silly.
Okay deraadt@.


# 1.18 13-Aug-2009 pirofti

Add wake/suspend support for pckbd(4).

Patch initially from mlarkin@. KNF and refactoring by me.
Suggestions and okay deraadt@.


Revision tags: OPENBSD_4_6_BASE
# 1.17 03-May-2009 miod

Make sure pckbd_scancode_translate() returns a scancode with the break/release
bit set if needed, in all cases. This fixes rawkbd operation on controllers
which require the kernel to perform scancode translation.

Found by and ok kettenis@


Revision tags: OPENBSD_4_5_BASE
# 1.16 21-Nov-2008 robert

Move #include <dev/pckbc/wskbdmap_mfii.h> after including
dev/wscons/wsksymvar.h where struct wskbd_mapdata gets
declared.

ok miod@


Revision tags: OPENBSD_4_4_BASE
# 1.15 16-Jul-2008 miod

If pckbc_xt_translation() fails, do not try to force the keyboard in table
1; instead, try table 2 first, then 1: some older keyboards, connected to
a castrated 8042, do not know how to talk in table 1 (or worse, will report
they do while they don't).

If automatic translation is not possible, remember which table the keyboard
ended configured in, and convert the scancodes from table 2 to table 1 if
necessary.

ok kettenis@


# 1.14 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.13 31-Dec-2007 miod

Keep running the scancode translation state machine even when the keyboard
is set to raw mode, but only feed decoded events to wscons if non-raw mode.

Then, as an exception to this, pass the audio control keys events to
wscons even if in raw mode, so that the in-kernel mixer control code can
perform its work. The event is also seen by the raw event consumer (i.e.
the X server).

Requested and tested by many...


# 1.12 17-Oct-2007 deraadt

miod says noone needs isa/isavar.h anymore, and i believe him


# 1.11 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


# 1.10 17-Oct-2007 fgsch

- Remove a shadow declaration.
- Correct resp size.

deraadt@ ok.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.9 30-Jan-2007 jcs

default to have pckbd_set_xtscancode() instruct the 8042 to use
table 3, still falling back on table 2 or 1 after carefully checking
that the table set request took

fixes the keyboard on the oqo model 01/01+

in snaps for a while, tested by many

ok miod@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.8 29-Dec-2005 martin

go via pckbc_enqeue_cmd() in pckbd_enable() if on; fixes PR 4615

ok miod@, mickey@


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.7 22-Feb-2005 mickey

send enable cmd after a reset; form netbsd


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.6 22-Oct-2003 jmc

typos from Tom Cosgrove;


Revision tags: OPENBSD_3_4_BASE
# 1.5 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


# 1.3 18-Feb-2002 jason

Don't include isavar.h on sparc64


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE UBC_BASE
# 1.2 02-Feb-2001 aaron

branches: 1.2.4; 1.2.8;
Remove dead code.


# 1.1 13-Nov-2000 aaron

Machine-independent PC-like keyboard driver; from NetBSD. XXX - Not used
anywhere quite yet, but useful to have these files in the tree while we work
towards wscons for i386 and alpha.


# 1.46 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.45 22-May-2018 mpi

Do not overwrite `table' in the non-translating case.

This ensures the keyboard is using the expected scancode.

From miod@, problem also noticed by Markus Hennecke, ok otto@


Revision tags: OPENBSD_6_3_BASE
# 1.44 06-Jan-2018 jcs

pckbd: don't change translation mode if controller is in table 2

This was changed a decade ago to forcibly try table 3 first in order
to make some now-long-gone hardware work.

Newer Lenovo machines seem to have trouble being asked to change
modes which manifests as a long boot delay as it waits for each
request to timeout, or by causing the keyboard to generate junk when
typing.

Assume table 2 by default and just leave it alone if it's already
there. This is how Linux has operated for quite a while and seems
to help on these Lenovo machines.

Tested by a few with these machines and has been in snaps for a bit.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.43 14-Apr-2016 mlarkin

Re-enable pckbd on resume (similar to what we do on boot). Fixes problems
on (at least) various HP laptops that previously had no working keyboard
after resuming from 'zzz'.

Reported by Aleksandar Lakic, who also verified several versions of the
diff during development, thanks.

discussed with miod and kettenis, tested by many others on tech@ - thanks.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.42 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.41 16-Mar-2015 jcs

Revert 1.39. Resetting after specifically putting the keyboard in a
different table will most likely just revert the keyboard to its
default table anyway.

Instead, just flush the kbd slot before choosing a table and then
still forcefully enable the slot, which is enough to fix UKC on the
3rd gen X1 carbon while having a much smaller chance of breaking
anything else.

ok deraadt


# 1.40 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.39 12-Mar-2015 deraadt

On first cnpoll, reset the keyboard and pms hard. This is required
to make "boot -c" support work on a variety of newer machines.
Do not anticipate this harming older machines, but we'll have to wait
and see with this change in the tree.
with jcs


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.38 24-Jul-2014 mpi

Speed up the boot sequence by deferring the scan of xt keyboard code set.

If you were wondering why there's a pause of 5 seconds after loading the
kernel and before seeing the copyright in blue when booting some of your
machines, well this is for you!

mlarkin@ found that this delay is caused by some code probing for xt scan
code tables when pckbd(4) initialize the console keyboard. So this diff
implements an idea from deraadt@ to only do the scan once, either during
*attach() or if we enter ddb> or ukc> before that!

ok miod@, mlarkin@, deraadt@, shadchin@


# 1.37 23-Mar-2014 ratchov

my bad, last commit was not ok deraadt, revert it.


# 1.36 13-Mar-2014 ratchov

Don't use volume keys when in raw-mode (this doesn't work), and let
Xorg driver do the translation and handle them as regular keys. Fixes
confusion caused by the volume being changed twice in contradictory
ways: once by X programs and once by the pckbd(4) driver.

ok deraadt, kettenis


Revision tags: OPENBSD_5_5_BASE
# 1.35 26-Jan-2014 miod

Attempt to make user changes of keyboard layout a bit more `sticky' on wsmux
kernels:
- keyboard drivers will now tell wskbd if the keyboard layout they ask
for is a default value, or a value they are 100% sure of (either
because your kernel has a XXXKBD_LAYOUT option, or because the
driver can tell the keyboard layout, e.g. by the country code on USB
keyboards which provide it, such as Sun's)
- when attaching a keyboard with a non-default layout, the layout will
become the default layout of the mux for new keyboard attachments if
the mux doesn't have a layout set already.
- when changing the keyboard layout of a particular keyboard with an
ioctl (i.e. using kbd(8) or wsconsctl(8)), the layout will become the
default layout of the mux for new keyboard attachments.

ok mpi@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 15-Feb-2013 ratchov

backout latest: audio keys can autorepeat. Autorepeated keys are not
decoded by the wskbd layer, thus autorepeted audio keys end-up passed
to userland in raw mode (ie to X), resulting in keyboard input
corruption. Noticed (and debugged) by halex@, thanks.


# 1.33 06-Jan-2013 ratchov

don't propagate XF86XK_Audio{Lower,Raise}Volume keys to userspace,
otherwise volume may be adjusted twice: once by X apps and once in
the kernel.

feedback from many, ok shadchin@


# 1.32 10-Aug-2012 shadchin

simplify pckbc_xt_translation()
* call only for set translation on (once in /sys/dev/pckbd.c)
therefore we can delete unused code.
* change behavior (more standard) - return zero on success

ok miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.31 17-Mar-2011 shadchin

Ansify non-ansified function definitions. No functional change.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.30 16-Dec-2010 shadchin

small cleanup ioctl WSKBDIO_GETLEDS

ok miod@


# 1.29 03-Dec-2010 shadchin

removed slot argument of function pckbd_cnattach
because it is always PCKBC_KBD_SLOT

ok miod@, krw@


# 1.28 28-Aug-2010 miod

In pckbd_scancode_translate(), correctly translate the break sequence
between scan code sets 1 and 2.


Revision tags: OPENBSD_4_8_BASE
# 1.27 22-Jul-2010 deraadt

Don't do anything on suspend/resume for now (there is a diff brewing,
but it has some problems still..)


# 1.26 21-Jul-2010 miod

Disable the heuristics for legacy free systems if pckbc flags are set to 1
in UKC; found the hard way by jakemsr@ on an old Tecra laptop.


# 1.25 08-Jul-2010 deraadt

For DVACT_SUSPEND and DVACT_RESUME we should always return success.


Revision tags: OPENBSD_4_7_BASE
# 1.24 23-Nov-2009 deraadt

pckbd_activate() should return failure if it knows; ok pirofti


# 1.23 23-Nov-2009 deraadt

better style is DVACT_SUSPEND before DVACT_RESUME


# 1.22 23-Nov-2009 pirofti

Fix pckbd and acpihpet suspend/resume cases to fit with the future framework
that's going to get in really soon.

Okay mlarkin@, deraadt@.


# 1.21 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


# 1.20 25-Aug-2009 miod

Legacy-free PC hardware do not have a real PS/2 keyboard controller, but
rather have the USB HCI emulate it during boot, while legacy mode is enabled.

This causes pckbd0 to attach as the console device, but is lost as soon as
the USB HCI driver attaches.

The disappearance of the emulated PS/2 controller can however be detected
in pckbc(4) - which is supposed to attach after [eou]hci(4), with the controller
refusing to ack commands and replying ``please resend'' instead.

In that case, the kernel will now no longer attach pckbd, and will perform a
new console input device selection, allowing the (real) usb keyboard to
become the console.

Thanks to krw@ for countless tests on legacy-free hardware; also tested on
more conventional hardware by naddy@ and I.

Only amd64 and i386 platforms are affected by this change.


# 1.19 13-Aug-2009 pirofti

Forgot to add break to the switch cases. Silly.
Okay deraadt@.


# 1.18 13-Aug-2009 pirofti

Add wake/suspend support for pckbd(4).

Patch initially from mlarkin@. KNF and refactoring by me.
Suggestions and okay deraadt@.


Revision tags: OPENBSD_4_6_BASE
# 1.17 03-May-2009 miod

Make sure pckbd_scancode_translate() returns a scancode with the break/release
bit set if needed, in all cases. This fixes rawkbd operation on controllers
which require the kernel to perform scancode translation.

Found by and ok kettenis@


Revision tags: OPENBSD_4_5_BASE
# 1.16 21-Nov-2008 robert

Move #include <dev/pckbc/wskbdmap_mfii.h> after including
dev/wscons/wsksymvar.h where struct wskbd_mapdata gets
declared.

ok miod@


Revision tags: OPENBSD_4_4_BASE
# 1.15 16-Jul-2008 miod

If pckbc_xt_translation() fails, do not try to force the keyboard in table
1; instead, try table 2 first, then 1: some older keyboards, connected to
a castrated 8042, do not know how to talk in table 1 (or worse, will report
they do while they don't).

If automatic translation is not possible, remember which table the keyboard
ended configured in, and convert the scancodes from table 2 to table 1 if
necessary.

ok kettenis@


# 1.14 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.13 31-Dec-2007 miod

Keep running the scancode translation state machine even when the keyboard
is set to raw mode, but only feed decoded events to wscons if non-raw mode.

Then, as an exception to this, pass the audio control keys events to
wscons even if in raw mode, so that the in-kernel mixer control code can
perform its work. The event is also seen by the raw event consumer (i.e.
the X server).

Requested and tested by many...


# 1.12 17-Oct-2007 deraadt

miod says noone needs isa/isavar.h anymore, and i believe him


# 1.11 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


# 1.10 17-Oct-2007 fgsch

- Remove a shadow declaration.
- Correct resp size.

deraadt@ ok.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.9 30-Jan-2007 jcs

default to have pckbd_set_xtscancode() instruct the 8042 to use
table 3, still falling back on table 2 or 1 after carefully checking
that the table set request took

fixes the keyboard on the oqo model 01/01+

in snaps for a while, tested by many

ok miod@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.8 29-Dec-2005 martin

go via pckbc_enqeue_cmd() in pckbd_enable() if on; fixes PR 4615

ok miod@, mickey@


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.7 22-Feb-2005 mickey

send enable cmd after a reset; form netbsd


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.6 22-Oct-2003 jmc

typos from Tom Cosgrove;


Revision tags: OPENBSD_3_4_BASE
# 1.5 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


# 1.3 18-Feb-2002 jason

Don't include isavar.h on sparc64


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE UBC_BASE
# 1.2 02-Feb-2001 aaron

branches: 1.2.4; 1.2.8;
Remove dead code.


# 1.1 13-Nov-2000 aaron

Machine-independent PC-like keyboard driver; from NetBSD. XXX - Not used
anywhere quite yet, but useful to have these files in the tree while we work
towards wscons for i386 and alpha.


# 1.45 22-May-2018 mpi

Do not overwrite `table' in the non-translating case.

This ensures the keyboard is using the expected scancode.

From miod@, problem also noticed by Markus Hennecke, ok otto@


Revision tags: OPENBSD_6_3_BASE
# 1.44 06-Jan-2018 jcs

pckbd: don't change translation mode if controller is in table 2

This was changed a decade ago to forcibly try table 3 first in order
to make some now-long-gone hardware work.

Newer Lenovo machines seem to have trouble being asked to change
modes which manifests as a long boot delay as it waits for each
request to timeout, or by causing the keyboard to generate junk when
typing.

Assume table 2 by default and just leave it alone if it's already
there. This is how Linux has operated for quite a while and seems
to help on these Lenovo machines.

Tested by a few with these machines and has been in snaps for a bit.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.43 14-Apr-2016 mlarkin

Re-enable pckbd on resume (similar to what we do on boot). Fixes problems
on (at least) various HP laptops that previously had no working keyboard
after resuming from 'zzz'.

Reported by Aleksandar Lakic, who also verified several versions of the
diff during development, thanks.

discussed with miod and kettenis, tested by many others on tech@ - thanks.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.42 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.41 16-Mar-2015 jcs

Revert 1.39. Resetting after specifically putting the keyboard in a
different table will most likely just revert the keyboard to its
default table anyway.

Instead, just flush the kbd slot before choosing a table and then
still forcefully enable the slot, which is enough to fix UKC on the
3rd gen X1 carbon while having a much smaller chance of breaking
anything else.

ok deraadt


# 1.40 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.39 12-Mar-2015 deraadt

On first cnpoll, reset the keyboard and pms hard. This is required
to make "boot -c" support work on a variety of newer machines.
Do not anticipate this harming older machines, but we'll have to wait
and see with this change in the tree.
with jcs


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.38 24-Jul-2014 mpi

Speed up the boot sequence by deferring the scan of xt keyboard code set.

If you were wondering why there's a pause of 5 seconds after loading the
kernel and before seeing the copyright in blue when booting some of your
machines, well this is for you!

mlarkin@ found that this delay is caused by some code probing for xt scan
code tables when pckbd(4) initialize the console keyboard. So this diff
implements an idea from deraadt@ to only do the scan once, either during
*attach() or if we enter ddb> or ukc> before that!

ok miod@, mlarkin@, deraadt@, shadchin@


# 1.37 23-Mar-2014 ratchov

my bad, last commit was not ok deraadt, revert it.


# 1.36 13-Mar-2014 ratchov

Don't use volume keys when in raw-mode (this doesn't work), and let
Xorg driver do the translation and handle them as regular keys. Fixes
confusion caused by the volume being changed twice in contradictory
ways: once by X programs and once by the pckbd(4) driver.

ok deraadt, kettenis


Revision tags: OPENBSD_5_5_BASE
# 1.35 26-Jan-2014 miod

Attempt to make user changes of keyboard layout a bit more `sticky' on wsmux
kernels:
- keyboard drivers will now tell wskbd if the keyboard layout they ask
for is a default value, or a value they are 100% sure of (either
because your kernel has a XXXKBD_LAYOUT option, or because the
driver can tell the keyboard layout, e.g. by the country code on USB
keyboards which provide it, such as Sun's)
- when attaching a keyboard with a non-default layout, the layout will
become the default layout of the mux for new keyboard attachments if
the mux doesn't have a layout set already.
- when changing the keyboard layout of a particular keyboard with an
ioctl (i.e. using kbd(8) or wsconsctl(8)), the layout will become the
default layout of the mux for new keyboard attachments.

ok mpi@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 15-Feb-2013 ratchov

backout latest: audio keys can autorepeat. Autorepeated keys are not
decoded by the wskbd layer, thus autorepeted audio keys end-up passed
to userland in raw mode (ie to X), resulting in keyboard input
corruption. Noticed (and debugged) by halex@, thanks.


# 1.33 06-Jan-2013 ratchov

don't propagate XF86XK_Audio{Lower,Raise}Volume keys to userspace,
otherwise volume may be adjusted twice: once by X apps and once in
the kernel.

feedback from many, ok shadchin@


# 1.32 10-Aug-2012 shadchin

simplify pckbc_xt_translation()
* call only for set translation on (once in /sys/dev/pckbd.c)
therefore we can delete unused code.
* change behavior (more standard) - return zero on success

ok miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.31 17-Mar-2011 shadchin

Ansify non-ansified function definitions. No functional change.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.30 16-Dec-2010 shadchin

small cleanup ioctl WSKBDIO_GETLEDS

ok miod@


# 1.29 03-Dec-2010 shadchin

removed slot argument of function pckbd_cnattach
because it is always PCKBC_KBD_SLOT

ok miod@, krw@


# 1.28 28-Aug-2010 miod

In pckbd_scancode_translate(), correctly translate the break sequence
between scan code sets 1 and 2.


Revision tags: OPENBSD_4_8_BASE
# 1.27 22-Jul-2010 deraadt

Don't do anything on suspend/resume for now (there is a diff brewing,
but it has some problems still..)


# 1.26 21-Jul-2010 miod

Disable the heuristics for legacy free systems if pckbc flags are set to 1
in UKC; found the hard way by jakemsr@ on an old Tecra laptop.


# 1.25 08-Jul-2010 deraadt

For DVACT_SUSPEND and DVACT_RESUME we should always return success.


Revision tags: OPENBSD_4_7_BASE
# 1.24 23-Nov-2009 deraadt

pckbd_activate() should return failure if it knows; ok pirofti


# 1.23 23-Nov-2009 deraadt

better style is DVACT_SUSPEND before DVACT_RESUME


# 1.22 23-Nov-2009 pirofti

Fix pckbd and acpihpet suspend/resume cases to fit with the future framework
that's going to get in really soon.

Okay mlarkin@, deraadt@.


# 1.21 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


# 1.20 25-Aug-2009 miod

Legacy-free PC hardware do not have a real PS/2 keyboard controller, but
rather have the USB HCI emulate it during boot, while legacy mode is enabled.

This causes pckbd0 to attach as the console device, but is lost as soon as
the USB HCI driver attaches.

The disappearance of the emulated PS/2 controller can however be detected
in pckbc(4) - which is supposed to attach after [eou]hci(4), with the controller
refusing to ack commands and replying ``please resend'' instead.

In that case, the kernel will now no longer attach pckbd, and will perform a
new console input device selection, allowing the (real) usb keyboard to
become the console.

Thanks to krw@ for countless tests on legacy-free hardware; also tested on
more conventional hardware by naddy@ and I.

Only amd64 and i386 platforms are affected by this change.


# 1.19 13-Aug-2009 pirofti

Forgot to add break to the switch cases. Silly.
Okay deraadt@.


# 1.18 13-Aug-2009 pirofti

Add wake/suspend support for pckbd(4).

Patch initially from mlarkin@. KNF and refactoring by me.
Suggestions and okay deraadt@.


Revision tags: OPENBSD_4_6_BASE
# 1.17 03-May-2009 miod

Make sure pckbd_scancode_translate() returns a scancode with the break/release
bit set if needed, in all cases. This fixes rawkbd operation on controllers
which require the kernel to perform scancode translation.

Found by and ok kettenis@


Revision tags: OPENBSD_4_5_BASE
# 1.16 21-Nov-2008 robert

Move #include <dev/pckbc/wskbdmap_mfii.h> after including
dev/wscons/wsksymvar.h where struct wskbd_mapdata gets
declared.

ok miod@


Revision tags: OPENBSD_4_4_BASE
# 1.15 16-Jul-2008 miod

If pckbc_xt_translation() fails, do not try to force the keyboard in table
1; instead, try table 2 first, then 1: some older keyboards, connected to
a castrated 8042, do not know how to talk in table 1 (or worse, will report
they do while they don't).

If automatic translation is not possible, remember which table the keyboard
ended configured in, and convert the scancodes from table 2 to table 1 if
necessary.

ok kettenis@


# 1.14 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.13 31-Dec-2007 miod

Keep running the scancode translation state machine even when the keyboard
is set to raw mode, but only feed decoded events to wscons if non-raw mode.

Then, as an exception to this, pass the audio control keys events to
wscons even if in raw mode, so that the in-kernel mixer control code can
perform its work. The event is also seen by the raw event consumer (i.e.
the X server).

Requested and tested by many...


# 1.12 17-Oct-2007 deraadt

miod says noone needs isa/isavar.h anymore, and i believe him


# 1.11 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


# 1.10 17-Oct-2007 fgsch

- Remove a shadow declaration.
- Correct resp size.

deraadt@ ok.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.9 30-Jan-2007 jcs

default to have pckbd_set_xtscancode() instruct the 8042 to use
table 3, still falling back on table 2 or 1 after carefully checking
that the table set request took

fixes the keyboard on the oqo model 01/01+

in snaps for a while, tested by many

ok miod@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.8 29-Dec-2005 martin

go via pckbc_enqeue_cmd() in pckbd_enable() if on; fixes PR 4615

ok miod@, mickey@


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.7 22-Feb-2005 mickey

send enable cmd after a reset; form netbsd


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.6 22-Oct-2003 jmc

typos from Tom Cosgrove;


Revision tags: OPENBSD_3_4_BASE
# 1.5 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


# 1.3 18-Feb-2002 jason

Don't include isavar.h on sparc64


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE UBC_BASE
# 1.2 02-Feb-2001 aaron

branches: 1.2.4; 1.2.8;
Remove dead code.


# 1.1 13-Nov-2000 aaron

Machine-independent PC-like keyboard driver; from NetBSD. XXX - Not used
anywhere quite yet, but useful to have these files in the tree while we work
towards wscons for i386 and alpha.


# 1.44 06-Jan-2018 jcs

pckbd: don't change translation mode if controller is in table 2

This was changed a decade ago to forcibly try table 3 first in order
to make some now-long-gone hardware work.

Newer Lenovo machines seem to have trouble being asked to change
modes which manifests as a long boot delay as it waits for each
request to timeout, or by causing the keyboard to generate junk when
typing.

Assume table 2 by default and just leave it alone if it's already
there. This is how Linux has operated for quite a while and seems
to help on these Lenovo machines.

Tested by a few with these machines and has been in snaps for a bit.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.43 14-Apr-2016 mlarkin

Re-enable pckbd on resume (similar to what we do on boot). Fixes problems
on (at least) various HP laptops that previously had no working keyboard
after resuming from 'zzz'.

Reported by Aleksandar Lakic, who also verified several versions of the
diff during development, thanks.

discussed with miod and kettenis, tested by many others on tech@ - thanks.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.42 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.41 16-Mar-2015 jcs

Revert 1.39. Resetting after specifically putting the keyboard in a
different table will most likely just revert the keyboard to its
default table anyway.

Instead, just flush the kbd slot before choosing a table and then
still forcefully enable the slot, which is enough to fix UKC on the
3rd gen X1 carbon while having a much smaller chance of breaking
anything else.

ok deraadt


# 1.40 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.39 12-Mar-2015 deraadt

On first cnpoll, reset the keyboard and pms hard. This is required
to make "boot -c" support work on a variety of newer machines.
Do not anticipate this harming older machines, but we'll have to wait
and see with this change in the tree.
with jcs


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.38 24-Jul-2014 mpi

Speed up the boot sequence by deferring the scan of xt keyboard code set.

If you were wondering why there's a pause of 5 seconds after loading the
kernel and before seeing the copyright in blue when booting some of your
machines, well this is for you!

mlarkin@ found that this delay is caused by some code probing for xt scan
code tables when pckbd(4) initialize the console keyboard. So this diff
implements an idea from deraadt@ to only do the scan once, either during
*attach() or if we enter ddb> or ukc> before that!

ok miod@, mlarkin@, deraadt@, shadchin@


# 1.37 23-Mar-2014 ratchov

my bad, last commit was not ok deraadt, revert it.


# 1.36 13-Mar-2014 ratchov

Don't use volume keys when in raw-mode (this doesn't work), and let
Xorg driver do the translation and handle them as regular keys. Fixes
confusion caused by the volume being changed twice in contradictory
ways: once by X programs and once by the pckbd(4) driver.

ok deraadt, kettenis


Revision tags: OPENBSD_5_5_BASE
# 1.35 26-Jan-2014 miod

Attempt to make user changes of keyboard layout a bit more `sticky' on wsmux
kernels:
- keyboard drivers will now tell wskbd if the keyboard layout they ask
for is a default value, or a value they are 100% sure of (either
because your kernel has a XXXKBD_LAYOUT option, or because the
driver can tell the keyboard layout, e.g. by the country code on USB
keyboards which provide it, such as Sun's)
- when attaching a keyboard with a non-default layout, the layout will
become the default layout of the mux for new keyboard attachments if
the mux doesn't have a layout set already.
- when changing the keyboard layout of a particular keyboard with an
ioctl (i.e. using kbd(8) or wsconsctl(8)), the layout will become the
default layout of the mux for new keyboard attachments.

ok mpi@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 15-Feb-2013 ratchov

backout latest: audio keys can autorepeat. Autorepeated keys are not
decoded by the wskbd layer, thus autorepeted audio keys end-up passed
to userland in raw mode (ie to X), resulting in keyboard input
corruption. Noticed (and debugged) by halex@, thanks.


# 1.33 06-Jan-2013 ratchov

don't propagate XF86XK_Audio{Lower,Raise}Volume keys to userspace,
otherwise volume may be adjusted twice: once by X apps and once in
the kernel.

feedback from many, ok shadchin@


# 1.32 10-Aug-2012 shadchin

simplify pckbc_xt_translation()
* call only for set translation on (once in /sys/dev/pckbd.c)
therefore we can delete unused code.
* change behavior (more standard) - return zero on success

ok miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.31 17-Mar-2011 shadchin

Ansify non-ansified function definitions. No functional change.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.30 16-Dec-2010 shadchin

small cleanup ioctl WSKBDIO_GETLEDS

ok miod@


# 1.29 03-Dec-2010 shadchin

removed slot argument of function pckbd_cnattach
because it is always PCKBC_KBD_SLOT

ok miod@, krw@


# 1.28 28-Aug-2010 miod

In pckbd_scancode_translate(), correctly translate the break sequence
between scan code sets 1 and 2.


Revision tags: OPENBSD_4_8_BASE
# 1.27 22-Jul-2010 deraadt

Don't do anything on suspend/resume for now (there is a diff brewing,
but it has some problems still..)


# 1.26 21-Jul-2010 miod

Disable the heuristics for legacy free systems if pckbc flags are set to 1
in UKC; found the hard way by jakemsr@ on an old Tecra laptop.


# 1.25 08-Jul-2010 deraadt

For DVACT_SUSPEND and DVACT_RESUME we should always return success.


Revision tags: OPENBSD_4_7_BASE
# 1.24 23-Nov-2009 deraadt

pckbd_activate() should return failure if it knows; ok pirofti


# 1.23 23-Nov-2009 deraadt

better style is DVACT_SUSPEND before DVACT_RESUME


# 1.22 23-Nov-2009 pirofti

Fix pckbd and acpihpet suspend/resume cases to fit with the future framework
that's going to get in really soon.

Okay mlarkin@, deraadt@.


# 1.21 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


# 1.20 25-Aug-2009 miod

Legacy-free PC hardware do not have a real PS/2 keyboard controller, but
rather have the USB HCI emulate it during boot, while legacy mode is enabled.

This causes pckbd0 to attach as the console device, but is lost as soon as
the USB HCI driver attaches.

The disappearance of the emulated PS/2 controller can however be detected
in pckbc(4) - which is supposed to attach after [eou]hci(4), with the controller
refusing to ack commands and replying ``please resend'' instead.

In that case, the kernel will now no longer attach pckbd, and will perform a
new console input device selection, allowing the (real) usb keyboard to
become the console.

Thanks to krw@ for countless tests on legacy-free hardware; also tested on
more conventional hardware by naddy@ and I.

Only amd64 and i386 platforms are affected by this change.


# 1.19 13-Aug-2009 pirofti

Forgot to add break to the switch cases. Silly.
Okay deraadt@.


# 1.18 13-Aug-2009 pirofti

Add wake/suspend support for pckbd(4).

Patch initially from mlarkin@. KNF and refactoring by me.
Suggestions and okay deraadt@.


Revision tags: OPENBSD_4_6_BASE
# 1.17 03-May-2009 miod

Make sure pckbd_scancode_translate() returns a scancode with the break/release
bit set if needed, in all cases. This fixes rawkbd operation on controllers
which require the kernel to perform scancode translation.

Found by and ok kettenis@


Revision tags: OPENBSD_4_5_BASE
# 1.16 21-Nov-2008 robert

Move #include <dev/pckbc/wskbdmap_mfii.h> after including
dev/wscons/wsksymvar.h where struct wskbd_mapdata gets
declared.

ok miod@


Revision tags: OPENBSD_4_4_BASE
# 1.15 16-Jul-2008 miod

If pckbc_xt_translation() fails, do not try to force the keyboard in table
1; instead, try table 2 first, then 1: some older keyboards, connected to
a castrated 8042, do not know how to talk in table 1 (or worse, will report
they do while they don't).

If automatic translation is not possible, remember which table the keyboard
ended configured in, and convert the scancodes from table 2 to table 1 if
necessary.

ok kettenis@


# 1.14 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.13 31-Dec-2007 miod

Keep running the scancode translation state machine even when the keyboard
is set to raw mode, but only feed decoded events to wscons if non-raw mode.

Then, as an exception to this, pass the audio control keys events to
wscons even if in raw mode, so that the in-kernel mixer control code can
perform its work. The event is also seen by the raw event consumer (i.e.
the X server).

Requested and tested by many...


# 1.12 17-Oct-2007 deraadt

miod says noone needs isa/isavar.h anymore, and i believe him


# 1.11 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


# 1.10 17-Oct-2007 fgsch

- Remove a shadow declaration.
- Correct resp size.

deraadt@ ok.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.9 30-Jan-2007 jcs

default to have pckbd_set_xtscancode() instruct the 8042 to use
table 3, still falling back on table 2 or 1 after carefully checking
that the table set request took

fixes the keyboard on the oqo model 01/01+

in snaps for a while, tested by many

ok miod@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.8 29-Dec-2005 martin

go via pckbc_enqeue_cmd() in pckbd_enable() if on; fixes PR 4615

ok miod@, mickey@


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.7 22-Feb-2005 mickey

send enable cmd after a reset; form netbsd


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.6 22-Oct-2003 jmc

typos from Tom Cosgrove;


Revision tags: OPENBSD_3_4_BASE
# 1.5 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


# 1.3 18-Feb-2002 jason

Don't include isavar.h on sparc64


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE UBC_BASE
# 1.2 02-Feb-2001 aaron

branches: 1.2.4; 1.2.8;
Remove dead code.


# 1.1 13-Nov-2000 aaron

Machine-independent PC-like keyboard driver; from NetBSD. XXX - Not used
anywhere quite yet, but useful to have these files in the tree while we work
towards wscons for i386 and alpha.