[haiku-commits] haiku: hrev56204 - src/add-ons/kernel/bus_managers/ps2

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 21 Jun 2022 15:53:02 +0000 (UTC)

hrev56204 adds 1 changeset to branch 'master'
old head: b2059b9f151d2d6329f9fc4653f352678243f5eb
new head: e866d6e941e9412832f1a03e55a0363483371ad5
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=e866d6e941e9+%5Eb2059b9f151d

----------------------------------------------------------------------------

e866d6e941e9: 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
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/5387
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

                                   [ PulkoMandy <pulkomandy@xxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev56204
Commit:      e866d6e941e9412832f1a03e55a0363483371ad5
URL:         https://git.haiku-os.org/haiku/commit/?id=e866d6e941e9
Author:      PulkoMandy <pulkomandy@xxxxxxxxxxxxx>
Date:        Sat Jun 18 18:52:25 2022 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Tue Jun 21 15:52:53 2022 UTC

----------------------------------------------------------------------------

2 files changed, 21 insertions(+), 13 deletions(-)
.../kernel/bus_managers/ps2/ps2_common.cpp       | 29 ++++++++++++--------
src/add-ons/kernel/bus_managers/ps2/ps2_defs.h   |  5 ++--

----------------------------------------------------------------------------

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 2db0cc2b77..c2ab62213e 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 @@ ps2_setup_active_multiplexing(bool *enabled)
        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 @@ ps2_setup_active_multiplexing(bool *enabled)
                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 @@ ps2_setup_active_multiplexing(bool *enabled)
                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 @@ done:
        // 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 @@ ps2_command(uint8 cmd, const uint8 *out, int outCount, 
uint8 *in, int inCount)
        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 @@ ps2_command(uint8 cmd, const uint8 *out, int outCount, 
uint8 *in, int inCount)
                        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 @@ ps2_init(void)
        }
 
        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 4ca02ce706..b5aaacd370 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


Other related posts:

  • » [haiku-commits] haiku: hrev56204 - src/add-ons/kernel/bus_managers/ps2 - waddlesplash