bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNU Mach] [patch] ImPS/2 support


From: Kilobug
Subject: [GNU Mach] [patch] ImPS/2 support
Date: Mon, 20 May 2002 11:30:21 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0+) Gecko/20020510

Hello,
        I've hacked this small patch to support ImPS/2 mouses in GNU
Mach. I know we will soon use the driver code in OSKit, so this hack
isn't really useful in the long-term, but I was needing it, so I've made
it, and I send it to this list because it could help some people too.

There are too patches, one for GNU Mach (CVS version of yesterday), the other for the mouse translator.

Regards
--
** Gael Le Mignot "Kilobug", Ing3 EPITA - http://kilobug.free.fr **
Home Mail   : kilobug@freesurf.fr          Work Mail : le-mig_g@epita.fr
GSM         : 06.71.47.18.22 (in France)   ICQ UIN   : 7299959
Fingerprint : 1F2C 9804 7505 79DF 95E6 7323 B66B F67B 7103 C5DA

"Software is like sex it's better when it's free.", Linus Torvalds
diff -u -r -N gnumach/i386/i386at/kd_mouse.c 
gnumach-imps2/i386/i386at/kd_mouse.c
--- gnumach/i386/i386at/kd_mouse.c      Thu Apr  5 08:39:21 2001
+++ gnumach-imps2/i386/i386at/kd_mouse.c        Sun May 19 18:12:13 2002
@@ -64,6 +64,10 @@
  * described in i386at/kd.h.
  */
 
+/*
+ * Hacked up from ImPS/2 support, by Gaël Le Mignot "Kilobug", 2002
+ */
+
 #include <mach/boolean.h>
 #include <sys/types.h>
 #ifdef MACH_KERNEL
@@ -85,6 +89,8 @@
 #include <i386at/kd_queue.h>
 #include <i386at/i8250.h>
 
+#include "mouse_defines.h"
+
 static int (*oldvect)();               /* old interrupt vector */
 static int oldunit;
 static spl_t oldspl;
@@ -157,6 +163,8 @@
 #define NO_MOUSE               3
 #define LOGITECH_TRACKMAN      4
 #define        MICROSOFT_MOUSE7        5
+#define IMPS2_MOUSE            6
+
 static int mouse_type;
 static int mousebufsize;
 static int mousebufindex = 0;
@@ -213,6 +221,11 @@
                kd_mouse_open(dev, 12);
                ibm_ps2_mouse_open(dev);
                break;
+       case IMPS2_MOUSE:
+               mousebufsize = 4;
+               kd_mouse_open(dev, 12);
+               imps2_mouse_open(dev);
+               break;
        case NO_MOUSE:
                break;
        }
@@ -264,6 +277,7 @@
        case LOGITECH_TRACKMAN:
                serial_mouse_close(dev);
                break;
+       case IMPS2_MOUSE:
        case IBM_MOUSE:
                ibm_ps2_mouse_close(dev);
                kd_mouse_close(dev, 12);
@@ -637,6 +651,7 @@
                        fourthgitech = 1;
                }
                break;
+       case IMPS2_MOUSE:
        case IBM_MOUSE:
                mouse_packet_ibm_ps2_mouse(mousebuf);
                break;
@@ -763,42 +778,99 @@
        return ch;
 }
 
-ibm_ps2_mouse_open(dev)
+static int 
+kd_mouse_write_ack(unsigned char c, spl_t s)
 {
-       spl_t   s = spltty();
-
-       lastbuttons = 0;
-       mouse_char_cmd = TRUE;  /* responses are to commands */
-
-       kd_sendcmd(0xa8);       /* enable mouse in kbd */
-
-       kd_cmdreg_write(0x47);  /* allow mouse interrupts */
+  kd_mouse_write(c);   /* reset mouse */
+  if (kd_mouse_read() != GPM_AUX_ACK) 
+    {
+      splx(s);
+      return 0;                /* need ACK */
+    }
+  return 1;
+}
+
+static int 
+kd_mouse_write_str_ack(unsigned char *c, int nb, spl_t s)
+{
+  int i = 0;
+  
+  for (i = 0; i < nb; i++)
+    if (kd_mouse_write_ack(c[i], s) < 0)
+      return 0;
+  return 1;
+}
+
+imps2_mouse_open(dev)
+{
+  int id;
+  static unsigned char basic_init[] = { GPM_AUX_ENABLE_DEV, 
GPM_AUX_SET_SAMPLE, 100 };
+  static unsigned char imps2_init[] = { GPM_AUX_SET_SAMPLE, 200, 
GPM_AUX_SET_SAMPLE, 100, GPM_AUX_SET_SAMPLE, 80, };
+  static unsigned char ps2_init[] = { GPM_AUX_SET_SCALE11, GPM_AUX_ENABLE_DEV, 
GPM_AUX_SET_SAMPLE, 100, GPM_AUX_SET_RES, 3, };
+
+  spl_t        s = spltty();
+  
+  lastbuttons = 0;
+  mouse_char_cmd = TRUE;       /* responses are to commands */
+  
+  kd_sendcmd(0xa8);    /* enable mouse in kbd */
+  
+  kd_cmdreg_write(0x47);       /* allow mouse interrupts */
                                /* magic number for ibm? */
+  
+  if (!kd_mouse_write_ack(GPM_AUX_RESET, s))   /* reset mouse */
+    return;
+  
+  (void) kd_mouse_read();      /* discard 2-character mouse ID */
+  (void) kd_mouse_read();
+  
+  if (!kd_mouse_write_ack(GPM_AUX_SET_STREAM, s)) /* set stream mode */
+    return;
+
+  /* Do a basic init in case the mouse is confused */
+  if (!kd_mouse_write_str_ack(basic_init, sizeof(basic_init), s))
+    return;
+  
+  /* Try to switch to 3 button mode */
+  if (!kd_mouse_write_str_ack(imps2_init, sizeof(imps2_init), s))
+    return;
+
+  /* And do the real initialisation */
+  if (!kd_mouse_write_str_ack(ps2_init, sizeof (ps2_init), s))
+    return;
+
+  mouse_char_cmd = FALSE;      /* now we get mouse packets */
+  
+  splx(s);
+}
 
-       kd_mouse_write(0xff);   /* reset mouse */
-       if (kd_mouse_read() != 0xfa) {
-           splx(s);
-           return;             /* need ACK */
-       }
-
-       (void) kd_mouse_read(); /* discard 2-character mouse ID */
-       (void) kd_mouse_read();
-
-       kd_mouse_write(0xea);   /* set stream mode */
-       if (kd_mouse_read() != 0xfa) {
-           splx(s);
-           return;             /* need ACK */
-       }
-
-       kd_mouse_write(0xf4);   /* enable */
-       if (kd_mouse_read() != 0xfa) {
-           splx(s);
-           return;             /* need ACK */
-       }
-
-       mouse_char_cmd = FALSE; /* now we get mouse packets */
-
-       splx(s);
+ibm_ps2_mouse_open(dev)
+{
+  spl_t        s = spltty();
+  
+  lastbuttons = 0;
+  mouse_char_cmd = TRUE;       /* responses are to commands */
+  
+  kd_sendcmd(0xa8);    /* enable mouse in kbd */
+  
+  kd_cmdreg_write(0x47);       /* allow mouse interrupts */
+                               /* magic number for ibm? */
+  
+  if (!kd_mouse_write_ack(GPM_AUX_RESET, s))   /* reset mouse */
+    return;
+  
+  (void) kd_mouse_read();      /* discard 2-character mouse ID */
+  (void) kd_mouse_read();
+  
+  if (!kd_mouse_write_ack(GPM_AUX_SET_STREAM, s)) /* set stream mode */
+    return;
+
+  if (!kd_mouse_write_ack(GPM_AUX_ENABLE_DEV, s)) /* enable */
+    return;
+
+  mouse_char_cmd = FALSE;      /* now we get mouse packets */
+  
+  splx(s);
 }
 
 ibm_ps2_mouse_close(dev)
diff -u -r -N gnumach/i386/i386at/mouse_defines.h 
gnumach-imps2/i386/i386at/mouse_defines.h
--- gnumach/i386/i386at/mouse_defines.h Thu Jan  1 01:00:00 1970
+++ gnumach-imps2/i386/i386at/mouse_defines.h   Sun May 19 18:12:13 2002
@@ -0,0 +1,36 @@
+/*
+ *   General defines for GNU Mach mouse driver - coming from GPM
+ *   (c) Gaël Le Mignot "Kilobug", 2002
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _MACH_MOUSE_DEFINES_
+#define _MACH_MOUSE_DEFINES_
+
+/* these are shameless stolen from /usr/src/linux/include/linux/pc_keyb.h    */
+#define GPM_AUX_SET_RES        0xE8  /* Set resolution */
+#define GPM_AUX_SET_SCALE11    0xE6  /* Set 1:1 scaling */ 
+#define GPM_AUX_SET_SCALE21    0xE7  /* Set 2:1 scaling */
+#define GPM_AUX_GET_SCALE      0xE9  /* Get scaling factor */
+#define GPM_AUX_SET_STREAM     0xEA  /* Set stream mode */
+#define GPM_AUX_SET_SAMPLE     0xF3  /* Set sample rate */ 
+#define GPM_AUX_ENABLE_DEV     0xF4  /* Enable aux device */
+#define GPM_AUX_DISABLE_DEV    0xF5  /* Disable aux device */
+#define GPM_AUX_RESET          0xFF  /* Reset aux device */
+#define GPM_AUX_ACK            0xFA  /* Command byte ACK. */ 
+
+#endif
+
diff -r -u hurd-20020418/trans/kd.h hurd-kb/trans/kd.h
--- hurd-20020418/trans/kd.h    Sun May 19 18:26:17 2002
+++ hurd-kb/trans/kd.h  Sun May 19 18:19:51 2002
@@ -68,5 +68,6 @@
 #define NO_MOUSE               3
 #define LOGITECH_TRACKMAN      4
 #define        MICROSOFT_MOUSE7        5
+#define IMPS2_MOUSE            6
 
 
diff -r -u hurd-20020418/trans/mouse.c hurd-kb/trans/mouse.c
--- hurd-20020418/trans/mouse.c Sun May 19 18:26:17 2002
+++ hurd-kb/trans/mouse.c       Sun May 19 18:19:51 2002
@@ -85,6 +85,7 @@
     { MOUSE_SYSTEM_MOUSE, "mousesystem"},
     { MICROSOFT_MOUSE, "microsoft" },
     { IBM_MOUSE, "ps/2" },
+    { IMPS2_MOUSE, "imps/2" },
     { NO_MOUSE, "nomouse" },
     { LOGITECH_TRACKMAN, "logitech" },
     { MICROSOFT_MOUSE7, "mouse7" },

reply via email to

[Prev in Thread] Current Thread [Next in Thread]