[haiku-commits] Change in haiku[master]: ps2: disable keyboard during multiplexing probing

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 19 Jun 2022 14:22:49 +0000

From Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>:

Adrien Destugues has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/5387 ;)


Change subject: ps2: disable keyboard during multiplexing probing
......................................................................

ps2: disable keyboard during multiplexing probing

My machine does not have an AUX/Mouse port at all. As a result, the
commands all get sent to the keyboard, which confuses the keyboard and
it eventually resets. This is generally harmless, but it ends up
resetting the keyboard, which cancels the effect of the commands to set
the repeat rate and delay during boot.

By disabling the keyboard during this step, we can avoid interference
with it.

Change-Id: Ic0513972a31e030a15577477c3d3fe32d4ce9bd3
---
M src/add-ons/kernel/bus_managers/ps2/ps2_common.cpp
M src/add-ons/kernel/bus_managers/ps2/ps2_defs.h
2 files changed, 21 insertions(+), 13 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/87/5387/1

diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_common.cpp 
b/src/add-ons/kernel/bus_managers/ps2/ps2_common.cpp
index 2db0cc2..5b7e6f8 100644
--- a/src/add-ons/kernel/bus_managers/ps2/ps2_common.cpp
+++ b/src/add-ons/kernel/bus_managers/ps2/ps2_common.cpp
@@ -167,8 +167,11 @@
        status_t res;
        uint8 in, out;

+       // Disable the keyboard port to avoid any interference with the keyboard
+       ps2_command(PS2_CTRL_KEYBOARD_DISABLE, NULL, 0, NULL, 0);
+
        out = 0xf0;
-       res = ps2_command(0xd3, &out, 1, &in, 1);
+       res = ps2_command(PS2_CTRL_AUX_LOOPBACK, &out, 1, &in, 1);
        if (res)
                goto fail;
        // Step 1, if controller is good, in does match out.
@@ -177,7 +180,7 @@
                goto no_support;

        out = 0x56;
-       res = ps2_command(0xd3, &out, 1, &in, 1);
+       res = ps2_command(PS2_CTRL_AUX_LOOPBACK, &out, 1, &in, 1);
        if (res)
                goto fail;
        // Step 2, if controller is good, in does match out.
@@ -185,7 +188,7 @@
                goto no_support;

        out = 0xa4;
-       res = ps2_command(0xd3, &out, 1, &in, 1);
+       res = ps2_command(PS2_CTRL_AUX_LOOPBACK, &out, 1, &in, 1);
        if (res)
                goto fail;
        // Step 3, if the controller doesn't support active multiplexing,
@@ -214,7 +217,7 @@
        // loopback, thus we need to send a harmless command (enable keyboard
        // interface) next.
        // This fixes bug report #1175
-       res = ps2_command(0xae, NULL, 0, NULL, 0);
+       res = ps2_command(PS2_CTRL_KEYBOARD_ENABLE, NULL, 0, NULL, 0);
        if (res != B_OK) {
                INFO("ps2: active multiplexing d3 workaround failed, status 
0x%08"
                        B_PRIx32 "\n", res);
@@ -239,7 +242,7 @@
        acquire_sem(gControllerSem);
        atomic_add(&sIgnoreInterrupts, 1);

-#ifdef TRACE_PS2
+#ifdef TRACE_PS2_COMMON
        TRACE("ps2: ps2_command cmd 0x%02x, out %d, in %d\n", cmd, outCount, 
inCount);
        for (i = 0; i < outCount; i++)
                TRACE("ps2: ps2_command out 0x%02x\n", out[i]);
@@ -265,7 +268,7 @@
                        TRACE("ps2: ps2_command in byte %d failed\n", i);
        }

-#ifdef TRACE_PS2
+#ifdef TRACE_PS2_COMMON
        for (i = 0; i < inCount; i++)
                TRACE("ps2: ps2_command in 0x%02x\n", in[i]);
        TRACE("ps2: ps2_command result 0x%08" B_PRIx32 "\n", res);
@@ -399,16 +402,20 @@
        }

        if (gActiveMultiplexingEnabled) {
+               // The multiplexing spec recommends to leave device 0 
unconnected because it saves some
+               // confusion with the use of the D3 command which appears as if 
the replied data was
+               // coming from device 0. So we enable it only if it really 
looks like there is a device
+               // connected there.
                if (ps2_dev_command_timeout(&ps2_device[PS2_DEVICE_MOUSE],
-                               PS2_CMD_MOUSE_SET_SCALE11, NULL, 0, NULL, 0, 
100000)
-                       == B_TIMED_OUT) {
+                               PS2_CMD_MOUSE_SET_SCALE11, NULL, 0, NULL, 0, 
100000) == B_TIMED_OUT) {
                        INFO("ps2: accessing multiplexed mouse port 0 timed 
out, ignoring it!\n");
                } else {
                        
ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE]);
                }
-               ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE + 
1]);
-               ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE + 
2]);
-               ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE + 
3]);
+
+               for (int idx = 1; idx < 3; idx++) {
+                       
ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE + idx]);
+               }
                ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_KEYB]);
        } else {
                ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE]);
diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_defs.h 
b/src/add-ons/kernel/bus_managers/ps2/ps2_defs.h
index 4ca02ce..b5aaacd 100644
--- a/src/add-ons/kernel/bus_managers/ps2/ps2_defs.h
+++ b/src/add-ons/kernel/bus_managers/ps2/ps2_defs.h
@@ -28,14 +28,15 @@
 // control words
 #define PS2_CTRL_READ_CMD                              0x20
 #define PS2_CTRL_WRITE_CMD                             0x60
+#define PS2_CTRL_AUX_LOOPBACK                  0xd3
 #define PS2_CTRL_WRITE_AUX                             0xd4
 #define PS2_CTRL_MOUSE_DISABLE                 0xa7
 #define PS2_CTRL_MOUSE_ENABLE                  0xa8
 #define PS2_CTRL_MOUSE_TEST                            0xa9
 #define PS2_CTRL_SELF_TEST                             0xaa
 #define PS2_CTRL_KEYBOARD_TEST                 0xab
-#define PS2_CTRL_KEYBOARD_ACTIVATE             0xae
-#define PS2_CTRL_KEYBOARD_DEACTIVATE   0xad
+#define PS2_CTRL_KEYBOARD_DISABLE              0xad
+#define PS2_CTRL_KEYBOARD_ENABLE               0xae

 // command bytes
 #define PS2_CMD_DEV_INIT                               0x43

--
To view, visit https://review.haiku-os.org/c/haiku/+/5387
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: Ic0513972a31e030a15577477c3d3fe32d4ce9bd3
Gerrit-Change-Number: 5387
Gerrit-PatchSet: 1
Gerrit-Owner: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: ps2: disable keyboard during multiplexing probing - Gerrit