linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh a PS/2 Trackpad
@ 2003-05-01 21:48 Hans-Georg Thien
  2003-05-01 22:13 ` Måns Rullgård
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Hans-Georg Thien @ 2003-05-01 21:48 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3564 bytes --]

Sorry for this long text and my bad english. And please be kind to me -
it is my very first posting to this mailing list ...

I have written a *very small* patch against the linux 2.4.20 kernel and
I want to submit it now.

The short story
---------------
The trackpad on the MacIntosh iBook Notebooks have a feature that
prevents unintended trackpad input while typing on the keyboard. There
are no mouse-moves or mouse-taps for a short period of time after each
keystroke.

I believe that many people with i386 notebooks would like this feature 
and I want to give it to the linux community.

First I had the idea of writing a loadable kernel module "trackpad" that
implements that feature and is loadable via

insmod keybd_irq=? mouse_irq=? delay=?

The long story
--------------
My first approach was - because I came from the bad old M$-DOS times -
write something like a "terminate and stay resident program"

      Procedure LoadModule
        Save the currentlly installed handlers for keyboard and mouse.
        Install your own interrupt handlers for keyboard and mouse.
      End

      Procedure UnloadModule
        Stop and remove "reset-timer" if necessary
        Restore the saved interrupt handlers for keyboard and mouse
      End

      Procedure KbdHandler
        Stop or modify "reset-timer" if necessary
        Set global variable block_mouse_events=1
        Start a timer that resets block_mouse_events=0 after ??? mSec
        Call the old keyboard interrupt handler
      End

      Proceure MouseHandler
        if block_mouse_events>0 then
          call ACK(mouse irq) if necessary
          do nothing
        else
          call old mouse interrupt handler
      End


So I bought the book "Linux Device Drivers" written by Alessandro Rubini
& Jonathan Corbert. It is an excellent book about LKM, but I couldn't
find a way  to "save and restore" irq-handlers as in the design
described above.

That's why I requested a little help in the newsgroup at
comp.os.linux.development.system. This ended up with some people who
said "don't mess around with irq-handlers in that way".

While trying to gain a deeper understanding of irq-handling - espically
for mouse and keyboard handlers - I found out that the keyboard and
mouse interrupts are handled *both* in
/usr/src/linux/drivers/char/pc_keyb.c.

Ok, that is only true for PS/2 mice, but the majority of notebooks on
the market have a PS/2 trackpad. On modifiying the pc_keyb.c file there
is no longer a need to save/restore Interrupt handlers or to call them
indirecty via a function pointer. Unfortunatly it has to be compiled in
the kernel and cannot be written as a LKM module.

But anyway - I sad down and got a working solution very quickly! I'm
very glad with it! I needed not more than 45 minutes to get this
working! Works in textmode (gpm) and under X11 as expected!


Testing
-------
I have tested my patch only on my own notebook (Compaq M300). It would
help a lot if there are some volunteers...


Future Plans
------------
[x] make the "disable trackpad time" configurable via the /proc
filesystem. Do you think that /proc/sys/kernel/trackpad is a good place
for it? There are other files under the /proc/sys/kernel directory that
fall in the category "keyboard handling", e.g. ctrl-alt-del or sysrq.

[x] make a /proc entry to allow "disable trackpad" and "enable
trackpad". That would allow to turn the builtin trackpad off when an
external mouse is pluged in, and to re-enable it when an external mouse
is unplugged again.


Here is the patch
-----------------



[-- Attachment #2: trackpad_patch.diff --]
[-- Type: text/plain, Size: 4183 bytes --]

diff -urN -X /tmp/dontdiff linux-2.4.20/Documentation/Configure.help /usr/src/linux/Documentation/Configure.help
--- linux-2.4.20/Documentation/Configure.help	Fri Nov 29 00:53:08 2002
+++ /usr/src/linux/Documentation/Configure.help	Thu May  1 02:12:04 2003
@@ -17752,6 +17752,16 @@
   <ftp://gnu.systemy.it/pub/gpm/>) solves this problem, or you can get
   the "mconv2" utility from <ftp://ibiblio.org/pub/Linux/system/mouse/>.
 
+Disable trackpad while typing
+CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+  For people with a notebook that have a build in trackpad.
+
+  It prevents unintended mouse moves and mouse taps while typing on
+  the notebook keyboard.
+
+  The majority of notebooks on the market have a PS/2 trackpad. 
+  So you will probably say "Y" if you have a notebook with a trackpad.
+
 C&T 82C710 mouse port support (as on TI Travelmate)
 CONFIG_82C710_MOUSE
   This is a certain kind of PS/2 mouse used on the TI Travelmate. If
diff -urN -X /tmp/dontdiff linux-2.4.20/drivers/char/Config.in /usr/src/linux/drivers/char/Config.in
--- linux-2.4.20/drivers/char/Config.in	Fri Nov 29 00:53:12 2002
+++ /usr/src/linux/drivers/char/Config.in	Thu May  1 02:30:45 2003
@@ -170,6 +170,13 @@
 tristate 'Mouse Support (not serial and bus mice)' CONFIG_MOUSE
 if [ "$CONFIG_MOUSE" != "n" ]; then
    bool '  PS/2 mouse (aka "auxiliary device") support' CONFIG_PSMOUSE
+
+   if [ "$CONFIG_PSMOUSE" = "y" ]
+   then
+     bool '    Disable Trackpad while typing on Notebooks' CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+   fi
+
+
    tristate '  C&T 82C710 mouse port support (as on TI Travelmate)' CONFIG_82C710_MOUSE
    tristate '  PC110 digitizer pad support' CONFIG_PC110_PAD
    tristate '  MK712 touch screen support' CONFIG_MK712_MOUSE
diff -urN -X /tmp/dontdiff linux-2.4.20/drivers/char/pc_keyb.c /usr/src/linux/drivers/char/pc_keyb.c
--- linux-2.4.20/drivers/char/pc_keyb.c	Fri Nov 29 00:53:12 2002
+++ /usr/src/linux/drivers/char/pc_keyb.c	Thu May  1 02:30:45 2003
@@ -13,6 +13,11 @@
  * Code fixes to handle mouse ACKs properly.
  * C. Scott Ananian <cananian@alumni.princeton.edu> 1999-01-29.
  *
+ * Implemented the "disable trackpad while typing" feature. This prevents
+ * unintended mouse moves and mouse taps while typing on the keyboard on
+ * notebooks with a PS/2 trackpad.
+ * Hans-Georg Thien <1682-600@onlinehome.de> 2003-04-30.
+ *
  */
 
 #include <linux/config.h>
@@ -85,6 +90,10 @@
 /*
  *	PS/2 Auxiliary Device
  */
+#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+static int disable_trackpad_while_typing=0;
+static int trackpad_delay=HZ;  /* delay trackpad for 1Sec after a key-event */
+#endif
 
 static int __init psaux_init(void);
 
@@ -449,6 +458,10 @@
 		return;
 	}
 
+#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+        if(disable_trackpad_while_typing > 0) return;
+#endif
+
 	prev_code = scancode;
 	add_mouse_randomness(scancode);
 	if (aux_count) {
@@ -467,8 +480,42 @@
 
 static unsigned char kbd_exists = 1;
 
+#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+
+void enable_trackpad(unsigned long ptr)
+{
+        disable_trackpad_while_typing=0; /* re-enable trackpad */
+}
+
+#endif
+
 static inline void handle_keyboard_event(unsigned char scancode)
 {
+
+#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+
+        /* setup a timer to re-enable the trackpad */
+        static struct timer_list enable_trackpad_timer;
+        static int enable_trackpad_timer_initialized=0;
+
+        disable_trackpad_while_typing=1; /* disable trackpad */
+
+        if(enable_trackpad_timer_initialized)
+        {
+                 /* trackpad timer already exists, - just restart it */
+                 mod_timer(&enable_trackpad_timer, jiffies+trackpad_delay);
+        }
+        else
+        {
+                 /* no trackpad timer yet. Initialize and start it */
+                 init_timer(&enable_trackpad_timer);
+                 enable_trackpad_timer.expires=jiffies+trackpad_delay;
+                 enable_trackpad_timer.function=enable_trackpad;
+                 add_timer(&enable_trackpad_timer);
+                 enable_trackpad_timer_initialized=1;
+        }
+#endif
+
 #ifdef CONFIG_VT
 	kbd_exists = 1;
 	if (do_acknowledge(scancode))



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh a PS/2 Trackpad
  2003-05-01 21:48 [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh a PS/2 Trackpad Hans-Georg Thien
@ 2003-05-01 22:13 ` Måns Rullgård
  2003-05-06  9:29 ` wwp
  2003-05-08 19:12 ` [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh aPS/2 Trackpad Khalid Aziz
  2 siblings, 0 replies; 24+ messages in thread
From: Måns Rullgård @ 2003-05-01 22:13 UTC (permalink / raw)
  To: linux-kernel

Hans-Georg Thien <1682-600@onlinehome.de> writes:

>  static inline void handle_keyboard_event(unsigned char scancode)
>  {
> +
> +#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
> +
> +        /* setup a timer to re-enable the trackpad */
> +        static struct timer_list enable_trackpad_timer;
> +        static int enable_trackpad_timer_initialized=0;
> +
> +        disable_trackpad_while_typing=1; /* disable trackpad */
> +
> +        if(enable_trackpad_timer_initialized)
> +        {
> +                 /* trackpad timer already exists, - just restart it */
> +                 mod_timer(&enable_trackpad_timer, jiffies+trackpad_delay);
> +        }
> +        else
> +        {
> +                 /* no trackpad timer yet. Initialize and start it */
> +                 init_timer(&enable_trackpad_timer);
> +                 enable_trackpad_timer.expires=jiffies+trackpad_delay;
> +                 enable_trackpad_timer.function=enable_trackpad;
> +                 add_timer(&enable_trackpad_timer);
> +                 enable_trackpad_timer_initialized=1;

The else block would probably be better off in some initialization
function.  Maybe the same place that sets up the interrupt handler is
appropriate.

-- 
Måns Rullgård
mru@users.sf.net


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh a PS/2 Trackpad
  2003-05-01 21:48 [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh a PS/2 Trackpad Hans-Georg Thien
  2003-05-01 22:13 ` Måns Rullgård
@ 2003-05-06  9:29 ` wwp
  2003-05-06 11:27   ` Hans-Georg Thien
  2003-05-08 19:12 ` [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh aPS/2 Trackpad Khalid Aziz
  2 siblings, 1 reply; 24+ messages in thread
From: wwp @ 2003-05-06  9:29 UTC (permalink / raw)
  To: Hans-Georg Thien, linux-kernel

Hi Hans-Georg Thien,


On Thu, 01 May 2003 23:48:21 +0200 Hans-Georg Thien <1682-600@onlinehome.de>
wrote:

> Sorry for this long text and my bad english. And please be kind to me -
> it is my very first posting to this mailing list ...
> 
> I have written a *very small* patch against the linux 2.4.20 kernel and
> I want to submit it now.

Would it be possible to enable/disable this feature from userspace using an
echo 1 > /proc/blabla, or only using insmod/modprobe -r?
Anyway, very good idea!


Regards,

-- 
wwp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh a PS/2 Trackpad
  2003-05-06  9:29 ` wwp
@ 2003-05-06 11:27   ` Hans-Georg Thien
  0 siblings, 0 replies; 24+ messages in thread
From: Hans-Georg Thien @ 2003-05-06 11:27 UTC (permalink / raw)
  To: wwp; +Cc: linux-kernel

wwp wrote:
> Hi Hans-Georg Thien,
> 
> 
> Would it be possible to enable/disable this feature from userspace using an
> echo 1 > /proc/blabla, or only using insmod/modprobe -r?
> Anyway, very good idea!
> 
> 
I'm working on an "echo ??? >/proc/something?" solution, where ??? is

delay=1200 # adjust trackpad to delay 1200 mSec after last keystroke
delay=0    # no delay, => disable that feature


-Hans



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh  aPS/2 Trackpad
  2003-05-01 21:48 [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh a PS/2 Trackpad Hans-Georg Thien
  2003-05-01 22:13 ` Måns Rullgård
  2003-05-06  9:29 ` wwp
@ 2003-05-08 19:12 ` Khalid Aziz
  2003-05-09 11:47   ` Hans-Georg Thien
  2003-05-27 20:47   ` Hans-Georg Thien
  2 siblings, 2 replies; 24+ messages in thread
From: Khalid Aziz @ 2003-05-08 19:12 UTC (permalink / raw)
  To: Hans-Georg Thien; +Cc: LKML

This patch makes it impossible to perform any operation that requires
pressing a key on the keyboard while clicking a mouse button - for
example bringing up X-terminal menu with CTRL-<middle button>. I am sure
there are other similar combination used by other software. You would
think 1 second after the CTRL key is pressed (which is when a keyboard
event is generated), mouse will be re-enabled and you should be able to
click mouse buttons as long as you do not let go of the key. Does not
seem to work that way. Mouse stays disabled as long as the key is
pressed.

--
Khalid

Hans-Georg Thien wrote:
> 
> Sorry for this long text and my bad english. And please be kind to me -
> it is my very first posting to this mailing list ...
> 
> I have written a *very small* patch against the linux 2.4.20 kernel and
> I want to submit it now.
> 
> The short story
> ---------------
> The trackpad on the MacIntosh iBook Notebooks have a feature that
> prevents unintended trackpad input while typing on the keyboard. There
> are no mouse-moves or mouse-taps for a short period of time after each
> keystroke.
> 
> I believe that many people with i386 notebooks would like this feature
> and I want to give it to the linux community.
> 
> First I had the idea of writing a loadable kernel module "trackpad" that
> implements that feature and is loadable via
> 
> insmod keybd_irq=? mouse_irq=? delay=?
> 
> The long story
> --------------
> My first approach was - because I came from the bad old M$-DOS times -
> write something like a "terminate and stay resident program"
> 
>       Procedure LoadModule
>         Save the currentlly installed handlers for keyboard and mouse.
>         Install your own interrupt handlers for keyboard and mouse.
>       End
> 
>       Procedure UnloadModule
>         Stop and remove "reset-timer" if necessary
>         Restore the saved interrupt handlers for keyboard and mouse
>       End
> 
>       Procedure KbdHandler
>         Stop or modify "reset-timer" if necessary
>         Set global variable block_mouse_events=1
>         Start a timer that resets block_mouse_events=0 after ??? mSec
>         Call the old keyboard interrupt handler
>       End
> 
>       Proceure MouseHandler
>         if block_mouse_events>0 then
>           call ACK(mouse irq) if necessary
>           do nothing
>         else
>           call old mouse interrupt handler
>       End
> 
> So I bought the book "Linux Device Drivers" written by Alessandro Rubini
> & Jonathan Corbert. It is an excellent book about LKM, but I couldn't
> find a way  to "save and restore" irq-handlers as in the design
> described above.
> 
> That's why I requested a little help in the newsgroup at
> comp.os.linux.development.system. This ended up with some people who
> said "don't mess around with irq-handlers in that way".
> 
> While trying to gain a deeper understanding of irq-handling - espically
> for mouse and keyboard handlers - I found out that the keyboard and
> mouse interrupts are handled *both* in
> /usr/src/linux/drivers/char/pc_keyb.c.
> 
> Ok, that is only true for PS/2 mice, but the majority of notebooks on
> the market have a PS/2 trackpad. On modifiying the pc_keyb.c file there
> is no longer a need to save/restore Interrupt handlers or to call them
> indirecty via a function pointer. Unfortunatly it has to be compiled in
> the kernel and cannot be written as a LKM module.
> 
> But anyway - I sad down and got a working solution very quickly! I'm
> very glad with it! I needed not more than 45 minutes to get this
> working! Works in textmode (gpm) and under X11 as expected!
> 
> Testing
> -------
> I have tested my patch only on my own notebook (Compaq M300). It would
> help a lot if there are some volunteers...
> 
> Future Plans
> ------------
> [x] make the "disable trackpad time" configurable via the /proc
> filesystem. Do you think that /proc/sys/kernel/trackpad is a good place
> for it? There are other files under the /proc/sys/kernel directory that
> fall in the category "keyboard handling", e.g. ctrl-alt-del or sysrq.
> 
> [x] make a /proc entry to allow "disable trackpad" and "enable
> trackpad". That would allow to turn the builtin trackpad off when an
> external mouse is pluged in, and to re-enable it when an external mouse
> is unplugged again.
> 
-- 

====================================================================
Khalid Aziz                                Linux and Open Source Lab
(970)898-9214                                        Hewlett-Packard
khalid@hp.com                                       Fort Collins, CO

"The Linux kernel is subject to relentless development" 
				- Alessandro Rubini

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh aPS/2 Trackpad
  2003-05-08 19:12 ` [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh aPS/2 Trackpad Khalid Aziz
@ 2003-05-09 11:47   ` Hans-Georg Thien
  2003-05-27 20:47   ` Hans-Georg Thien
  1 sibling, 0 replies; 24+ messages in thread
From: Hans-Georg Thien @ 2003-05-09 11:47 UTC (permalink / raw)
  To: Kernel Mailing List; +Cc: Khalid Aziz

[-- Attachment #1: Type: text/plain, Size: 811 bytes --]

Khalid Aziz wrote:
> [...] impossible to perform any operation that requires
> pressing a key on the keyboard while clicking a mouse button - for
> example bringing up X-terminal menu with CTRL-<middle button>. I am sure
> there are other similar combination used by other software. You would
> think 1 second after the CTRL key is pressed (which is when a keyboard
> event is generated), mouse will be re-enabled and you should be able to
> click mouse buttons as long as you do not let go of the key. Does not
> seem to work that way. Mouse stays disabled as long as the key is
> pressed.
> 
Thanks a lot Khalid! I have fixed that now.

Now, when you first press a key the trackpad is disabled. But the
"timer" is not restarted now when you hold the key pressed down
(prev_scancode == actual_scancode).







[-- Attachment #2: trackpad-2.4.20.diff --]
[-- Type: text/plain, Size: 3118 bytes --]

--- /usr/src/linux-2.4.20/Documentation/Configure.help	Fri Nov 29 00:53:08 2002
+++ /usr/src/linux/Documentation/Configure.help	Thu May  1 02:12:04 2003
@@ -17752,6 +17752,16 @@
   <ftp://gnu.systemy.it/pub/gpm/>) solves this problem, or you can get
   the "mconv2" utility from <ftp://ibiblio.org/pub/Linux/system/mouse/>.
 
+Disable trackpad while typing
+CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+  For people with a notebook that have a build in trackpad.
+
+  It prevents unintended mouse moves and mouse taps while typing on
+  the notebook keyboard.
+
+  The majority of notebooks on the market have a PS/2 trackpad. 
+  So you will probably say "Y" if you have a notebook with a trackpad.
+
 C&T 82C710 mouse port support (as on TI Travelmate)
 CONFIG_82C710_MOUSE
   This is a certain kind of PS/2 mouse used on the TI Travelmate. If
--- /usr/src/linux-2.4.20/drivers/char/Config.in	Fri Nov 29 00:53:12 2002
+++ /usr/src/linux/drivers/char/Config.in	Thu May  1 02:30:45 2003
@@ -170,6 +170,13 @@
 tristate 'Mouse Support (not serial and bus mice)' CONFIG_MOUSE
 if [ "$CONFIG_MOUSE" != "n" ]; then
    bool '  PS/2 mouse (aka "auxiliary device") support' CONFIG_PSMOUSE
+
+   if [ "$CONFIG_PSMOUSE" = "y" ]
+   then
+     bool '    Disable Trackpad while typing on Notebooks' CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+   fi
+
+
    tristate '  C&T 82C710 mouse port support (as on TI Travelmate)' CONFIG_82C710_MOUSE
    tristate '  PC110 digitizer pad support' CONFIG_PC110_PAD
    tristate '  MK712 touch screen support' CONFIG_MK712_MOUSE
--- /usr/src/linux-2.4.20/drivers/char/pc_keyb.c	Fri Nov 29 00:53:12 2002
+++ /usr/src/linux/drivers/char/pc_keyb.c	Fri May  9 15:17:45 2003
@@ -13,6 +13,11 @@
  * Code fixes to handle mouse ACKs properly.
  * C. Scott Ananian <cananian@alumni.princeton.edu> 1999-01-29.
  *
+ * Implemented the "disable trackpad while typing" feature. This prevents
+ * unintended mouse moves and mouse taps while typing on the keyboard on
+ * notebooks with a PS/2 trackpad.
+ * Hans-Georg Thien <1682-600@onlinehome.de> 2003-04-30.
+ *
  */
 
 #include <linux/config.h>
@@ -67,6 +72,11 @@
 static void aux_write_ack(int val);
 static void __aux_write_ack(int val);
 static int aux_reconnect = 0;
+
+#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+static int last_kbd_event = 0; /* used to hold timestamp of last kbd event */
+#endif
+
 #endif
 
 #ifndef kbd_controller_present
@@ -449,6 +459,11 @@
 		return;
 	}
 
+#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+        /* do nothing if time since last kbd event is less then 1Sec */
+        if ( abs(jiffies - last_kbd_event) < HZ ) return;
+#endif
+
 	prev_code = scancode;
 	add_mouse_randomness(scancode);
 	if (aux_count) {
@@ -469,6 +484,17 @@
 
 static inline void handle_keyboard_event(unsigned char scancode)
 {
+
+#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+        static unsigned char prev_scancode=0;
+
+        if (scancode != prev_scancode)
+        {
+                last_kbd_event = jiffies;
+                prev_scancode=scancode;
+        }
+#endif
+
 #ifdef CONFIG_VT
 	kbd_exists = 1;
 	if (do_acknowledge(scancode))


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh aPS/2 Trackpad
  2003-05-08 19:12 ` [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh aPS/2 Trackpad Khalid Aziz
  2003-05-09 11:47   ` Hans-Georg Thien
@ 2003-05-27 20:47   ` Hans-Georg Thien
  2003-05-27 21:10     ` wwp
  1 sibling, 1 reply; 24+ messages in thread
From: Hans-Georg Thien @ 2003-05-27 20:47 UTC (permalink / raw)
  To: Kernel Mailing List; +Cc: Khalid Aziz, subscript

[-- Attachment #1: Type: text/plain, Size: 1297 bytes --]

Hans-Georg Thien wrote:
    > The short story
    > ---------------
    > Apple MacIntosh iBook Notebooks computers have a nice feature that
    > prevents unintended trackpad input while typing on the keyboard. There
    > are no mouse-moves or mouse-taps for a short period of time after each
    > keystroke. I wanted to have this feature on my i386 notebook ...

It it is now possible to adjust some settings via

       echo ???? > /proc/tty/ps2-trackpad

(1) Set the delay time to 2 Secs (default is 10 ==> 1 Sec)

         echo "delay 20" > /proc/tty/ps2-trackpad


(2)  Completely disable the trackpad (default 0). Useful if you plug in 
an external mouse.

         echo "disable 1" > /proc/tty/ps2-trackpad

(3)  Escape the keyboard scancode for a key. These scancodes are
passed without a delay. (defaults are the scancodes for CTRL and SHIFT
keys).

This is useful for some applications ( like xterm ) which are using 
keydown events in combination with mouseclick events.

You can use showkey -s to find out the scancodes of your own keys.
To unescape a scancode you must apply that scancode twice! For keys with 
multiple scancodes you must use the *last* generated scancode.

     Example: define an escape for HOME-KeyDown

         echo "escape 0x047" > /proc/tty/ps2-trackpad




[-- Attachment #2: trackpad-2.4.20.diff --]
[-- Type: text/plain, Size: 8244 bytes --]

--- /usr/src/linux-2.4.20/Documentation/Configure.help	Fri Nov 29 00:53:08 2002
+++ /usr/src/linux/Documentation/Configure.help	Wed May 28 00:04:44 2003
@@ -17752,6 +17752,44 @@
   <ftp://gnu.systemy.it/pub/gpm/>) solves this problem, or you can get
   the "mconv2" utility from <ftp://ibiblio.org/pub/Linux/system/mouse/>.
 
+Disable trackpad while typing
+CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+  For people with a notebook that have a build in trackpad.
+
+  It prevents unintended mouse moves and mouse taps while typing on
+  the notebook keyboard.
+
+  The majority of notebooks on the market have a PS/2 trackpad. 
+  So you will probably say "Y" if you have a notebook with a trackpad.
+
+  Also note that you can control the behaviour of the trackpad via the 
+  /proc/tty/ps2-trackpad file, e.g.
+
+  Set the delay time to 2 Secs (default is 10 ==> 1 Sec)
+
+  	echo "delay 20" > /proc/tty/ps2-trackpad
+  
+
+  Completely disable the trackpad (default 0). Useful if you plug in an
+  external mouse.
+
+  	echo "disable 1" > /proc/tty/ps2-trackpad
+
+
+  Escape the keyboard scancode for the key. These scancodes are passed
+  without a delay. (defaults are the scancodes for CTRL and SHIFT keys). 
+
+  This is useful for some applications ( like xterm ) which are using
+  keydown-click events.
+
+  You can use showkey -s to find out the scancodes of your own keys. 
+  Apply "escape 0x0??" twice to unescape a scancode. For keys with
+  multiple scancodes you must use the *last* generated scancode.
+
+  Example: define an escape for HOME-KeyDown 
+
+  	echo "escape 0x047" > /proc/tty/ps2-trackpad
+
 C&T 82C710 mouse port support (as on TI Travelmate)
 CONFIG_82C710_MOUSE
   This is a certain kind of PS/2 mouse used on the TI Travelmate. If
--- /usr/src/linux-2.4.20/drivers/char/Config.in	Fri Nov 29 00:53:12 2002
+++ /usr/src/linux/drivers/char/Config.in	Thu May  1 02:30:45 2003
@@ -170,6 +170,13 @@
 tristate 'Mouse Support (not serial and bus mice)' CONFIG_MOUSE
 if [ "$CONFIG_MOUSE" != "n" ]; then
    bool '  PS/2 mouse (aka "auxiliary device") support' CONFIG_PSMOUSE
+
+   if [ "$CONFIG_PSMOUSE" = "y" ]
+   then
+     bool '    Disable Trackpad while typing on Notebooks' CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+   fi
+
+
    tristate '  C&T 82C710 mouse port support (as on TI Travelmate)' CONFIG_82C710_MOUSE
    tristate '  PC110 digitizer pad support' CONFIG_PC110_PAD
    tristate '  MK712 touch screen support' CONFIG_MK712_MOUSE
--- /usr/src/linux-2.4.20/drivers/char/pc_keyb.c	Fri Nov 29 00:53:12 2002
+++ /usr/src/linux/drivers/char/pc_keyb.c	Tue May 27 23:08:46 2003
@@ -13,6 +13,11 @@
  * Code fixes to handle mouse ACKs properly.
  * C. Scott Ananian <cananian@alumni.princeton.edu> 1999-01-29.
  *
+ * Implemented the "disable trackpad while typing" feature. This prevents
+ * unintended mouse moves and mouse taps while typing on the keyboard on
+ * notebooks with a PS/2 trackpad.
+ * Hans-Georg Thien <1682-600@onlinehome.de> 2003-04-30.
+ *
  */
 
 #include <linux/config.h>
@@ -35,7 +40,7 @@
 #include <linux/smp_lock.h>
 #include <linux/kd.h>
 #include <linux/pm.h>
-
+#include <linux/proc_fs.h>
 #include <asm/keyboard.h>
 #include <asm/bitops.h>
 #include <asm/uaccess.h>
@@ -102,6 +107,125 @@
 #define MAX_RETRIES	60		/* some aux operations take long time*/
 #endif /* CONFIG_PSMOUSE */
 
+#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+
+static int last_kbd_event = 0;     /* timestamp of last kbd event */
+static int last_kbd_scancode = 0; 
+static int trackpad_disable = 0;
+static int trackpad_delay = HZ;    /* default delay is 1Sec */
+
+static unsigned char trackpad_escape[256/8]; /* 256-Bit vector of keyboard scancodes to ignore */
+
+
+static int trackpad_write_proc(struct file *file,
+                               const char *buf,
+                               unsigned long len,
+                               void *data)
+{
+
+/*
+ * handle write requests to /proc/tty/ps2-trackpad
+ */
+        char lbuf[32];
+        int tmp;
+        int success = 0;
+ 
+        if (len > sizeof(lbuf)-1) return -EINVAL;
+
+        if (copy_from_user(lbuf, buf, len)) return -EFAULT;
+
+        lbuf[len] = '\0';
+
+        if (sscanf(lbuf, "delay %d", &tmp)) {
+                trackpad_delay = (tmp * HZ) / 10; /* convert 1/10Sec to jiffies */
+                success=1; 
+        }
+
+        if (sscanf(lbuf, "disable %d", &tmp)) {
+                trackpad_disable = tmp ? 1 : 0;
+                success=1; 
+        }
+
+        if (sscanf(lbuf, "escape 0x%x", &tmp)) {
+                if ((tmp < 0) || (tmp > 255)) return -EINVAL;
+                change_bit(tmp, trackpad_escape);
+                success=1; 
+        }
+
+        if (!success) return -EINVAL;
+
+        return len;
+}
+
+static int trackpad_read_proc(char *buf, char **start, off_t ofs,
+                              int count, int *eof, void *data)
+{  
+
+/* 
+ * handle read requests to /proc/tty/ps2-trackpad 
+ */
+
+        int len  = 0;
+        int i;
+
+        len += sprintf(buf+len, "delay %d\n", 
+                                (trackpad_delay * 10) / HZ); /* convert jiffies to 1/10Sec */
+        len += sprintf(buf+len, "disable %d\n", trackpad_disable);
+
+        for (i = 0; i < sizeof(trackpad_escape) * 8; i++) {
+                if (test_bit(i, trackpad_escape)) {
+                        len += sprintf(buf+len, "escape 0x0%x\n", i);
+                }
+        }
+
+        *eof = 1;
+        buf[len+1] = '\0';
+        return len;
+}
+
+static int trackpad_config_setup(void)
+{  
+
+/* 
+ * create read-write entries in /proc/tty/ps2-trackpad and setup some 
+ * defaults for the trackpad handling
+ */
+
+        struct proc_dir_entry *trackpad_proc_entry;
+
+        trackpad_proc_entry=create_proc_entry("tty/ps2-trackpad", 0, NULL);
+
+        if (trackpad_proc_entry == NULL) return -1;
+
+        trackpad_proc_entry->mode |=  S_IWUGO;
+        trackpad_proc_entry->read_proc = trackpad_read_proc;
+        trackpad_proc_entry->write_proc = trackpad_write_proc;
+
+        
+        /* set keyboard scancodes to ignore */
+        memset(trackpad_escape, 0, sizeof(trackpad_escape));
+        set_bit(0x1d, trackpad_escape);  /* CTRL-L/CTRL-R keydown */
+        set_bit(0x2a, trackpad_escape);  /* SHIFT-L keydown */
+        set_bit(0x36, trackpad_escape);  /* SHIFT-R keydown */
+#if 0
+        set_bit(0x38, trackpad_escape);  /* ALT-L/ALT-R keydown */
+        set_bit(0x01, trackpad_escape);  /* ESC keydown */
+        set_bit(0x47, trackpad_escape);  /* HOME keydown */
+        set_bit(0x48, trackpad_escape);  /* CURSORUP keydown */
+        set_bit(0x49, trackpad_escape);  /* PAGEUP keydown */
+        set_bit(0x4b, trackpad_escape);  /* CURSOR-L keydown */
+        set_bit(0x4d, trackpad_escape);  /* CURSOR-R keydown */
+        set_bit(0x4f, trackpad_escape);  /* END keydown */
+        set_bit(0x50, trackpad_escape);  /* CURSORDOWN keydown */
+        set_bit(0x51, trackpad_escape);  /* PAGEDOWN keydown */
+        set_bit(0x5d, trackpad_escape);  /* MENU keydown */
+#endif
+
+        return 0;
+}
+
+#endif /* CONFIG_DISABLE_TRACKPAD_WHILE_TYPING */
+
 /*
  * Wait for keyboard controller input buffer to drain.
  *
@@ -449,6 +573,15 @@
 		return;
 	}
 
+#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+        if (trackpad_disable) return;
+
+        if (!test_bit(last_kbd_scancode, trackpad_escape)) {
+                  /* do nothing if time since last kbd event is less then trackpad_delay */
+                  if (abs(jiffies - last_kbd_event) < trackpad_delay) return;
+        }
+#endif
+
 	prev_code = scancode;
 	add_mouse_randomness(scancode);
 	if (aux_count) {
@@ -469,6 +602,12 @@
 
 static inline void handle_keyboard_event(unsigned char scancode)
 {
+
+#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+                last_kbd_event = jiffies;
+                last_kbd_scancode = scancode;
+#endif
+
 #ifdef CONFIG_VT
 	kbd_exists = 1;
 	if (do_acknowledge(scancode))
@@ -1219,6 +1358,10 @@
 	kbd_write_command(KBD_CCMD_MOUSE_DISABLE); /* Disable aux device. */
 	kbd_write_cmd(AUX_INTS_OFF); /* Disable controller ints. */
 
+#ifdef CONFIG_DISABLE_TRACKPAD_WHILE_TYPING
+        trackpad_config_setup();
+#endif
+
 	return 0;
 }
 



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh aPS/2 Trackpad
  2003-05-27 20:47   ` Hans-Georg Thien
@ 2003-05-27 21:10     ` wwp
  2003-05-29 12:07       ` Hans-Georg Thien
                         ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: wwp @ 2003-05-27 21:10 UTC (permalink / raw)
  To: Hans-Georg Thien, linux-kernel

Hi Hans-Georg Thien,


On Tue, 27 May 2003 22:47:06 +0200 Hans-Georg Thien <1682-600@onlinehome.de>
wrote:

> Hans-Georg Thien wrote:
[snip]
> It it is now possible to adjust some settings via
> 
>        echo ???? > /proc/tty/ps2-trackpad
> 
> (1) Set the delay time to 2 Secs (default is 10 ==> 1 Sec)
> 
>          echo "delay 20" > /proc/tty/ps2-trackpad
> 
> 
> (2)  Completely disable the trackpad (default 0). Useful if you plug in 
> an external mouse.
> 
>          echo "disable 1" > /proc/tty/ps2-trackpad
> 
> (3)  Escape the keyboard scancode for a key. These scancodes are
[snip]

Sounds good, thanx for your work, guy :-).
Do you think/know if this patch will be merged to the official tree?


Regards,

-- 
wwp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh aPS/2 Trackpad
  2003-05-27 21:10     ` wwp
@ 2003-05-29 12:07       ` Hans-Georg Thien
  2003-09-30 20:51       ` [PORT to 2.6.x] "Disable Trackpad while typing" on Notebooks with a PS/2 Trackpad Hans-Georg Thien
  2003-10-02 17:40       ` getting timestamp of last interrupt? Hans-Georg Thien
  2 siblings, 0 replies; 24+ messages in thread
From: Hans-Georg Thien @ 2003-05-29 12:07 UTC (permalink / raw)
  To: wwp; +Cc: Kernel Mailing List

wwp wrote:
> Hi Hans-Georg Thien,
> 
> 
> On Tue, 27 May 2003 22:47:06 +0200 Hans-Georg Thien <1682-600@onlinehome.de>
> wrote:
> 
> 
>>Hans-Georg Thien wrote:
> 
> [snip]
> 
>>It it is now possible to adjust some settings via
>>
>>       echo ???? > /proc/tty/ps2-trackpad
>>
>>(1) Set the delay time to 2 Secs (default is 10 ==> 1 Sec)
>>
>>         echo "delay 20" > /proc/tty/ps2-trackpad
>>
>>
>>(2)  Completely disable the trackpad (default 0). Useful if you plug in 
>>an external mouse.
>>
>>         echo "disable 1" > /proc/tty/ps2-trackpad
>>
>>(3)  Escape the keyboard scancode for a key. These scancodes are
> 
> [snip]
> 
> Sounds good, thanx for your work, guy :-).
> Do you think/know if this patch will be merged to the official tree?
> 
I hope, of course ... If you know a way to enforce it - let me know!


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PORT to 2.6.x] "Disable Trackpad while typing" on Notebooks with a PS/2 Trackpad
  2003-05-27 21:10     ` wwp
  2003-05-29 12:07       ` Hans-Georg Thien
@ 2003-09-30 20:51       ` Hans-Georg Thien
  2003-10-02 17:40       ` getting timestamp of last interrupt? Hans-Georg Thien
  2 siblings, 0 replies; 24+ messages in thread
From: Hans-Georg Thien @ 2003-09-30 20:51 UTC (permalink / raw)
  To: linux-kernel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have written a patch against the linux 2.4.x kernel and I want to port 
it to the 2.6.x Kernel now.

What it is
- ----------
The trackpad on the MacIntosh iBook notebooks have a feature that 
prevents unintended trackpad input while typing on the keyboard. There 
are no mouse-moves or mouse-taps for a short period of time after each 
keystroke.

I thougt that was a nice-to-have for my i386 notebook and have 
implemented it ( with some very important help of other people, namely 
Torsten Foertsch ).

This feature is fully configurable via a proc entry.

How it currently works
- ----------------------

In the 2.4.x kernel the handling of keyboard and PS/2 mouse where both 
done in linux/drivers/char/pc_keyb.c. So it was easy to apply a patch 
without touching other files.

It simply stores a timestamp whenever a key event occurs. If a mouse 
event occurs it compares the timestamp of the mouse event with stored 
timestamp of the key event. If the delta of these timestamps is less 
than a treshold value, than this mouse event is simply discarded. There 
where some things more to consider about, but I think you have the idea.

Where I need help now
- ---------------------
Since I do not want to touch the keyboard driver, I wonder if there is 
better way to get the timestamp when the last keyboard event occured?

Maybe a function call, a callback function where I can register to the 
be notified when a event occurs, a global accessible variable, a proc 
entry or something like that.

Any ideas ?

- - Hans

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)

iD8DBQE/eezq2xSpXPjN/jsRAgyAAJ9djvaiYsgiR4pOf4GRJ2xNKCUa5QCdFreB
4/iOjaoS+3XX0dL8DFGEaJk=
=zh+9
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 24+ messages in thread

* getting timestamp of last interrupt?
  2003-05-27 21:10     ` wwp
  2003-05-29 12:07       ` Hans-Georg Thien
  2003-09-30 20:51       ` [PORT to 2.6.x] "Disable Trackpad while typing" on Notebooks with a PS/2 Trackpad Hans-Georg Thien
@ 2003-10-02 17:40       ` Hans-Georg Thien
  2003-10-02 18:54         ` Karim Yaghmour
                           ` (2 more replies)
  2 siblings, 3 replies; 24+ messages in thread
From: Hans-Georg Thien @ 2003-10-02 17:40 UTC (permalink / raw)
  To: linux-kernel

I am looking for a possibility to read out the last timestamp when an 
interrupt has occured.

e.g.: the user presses a key on the keyboard. Where can I read out the 
timestamp of this event?

To be more precise, I 'm looking for

( )a function call
( ) a callback where I can register to be notified when an event occurs
( ) a global accessible variable
( ) a /proc entry

or something like that.

Any ideas ?

- Hans



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
  2003-10-02 17:40       ` getting timestamp of last interrupt? Hans-Georg Thien
@ 2003-10-02 18:54         ` Karim Yaghmour
  2003-10-02 18:59         ` Richard B. Johnson
  2003-10-02 22:46         ` Peter Chubb
  2 siblings, 0 replies; 24+ messages in thread
From: Karim Yaghmour @ 2003-10-02 18:54 UTC (permalink / raw)
  To: Hans-Georg Thien; +Cc: linux-kernel


Hans-Georg Thien wrote:
> I am looking for a possibility to read out the last timestamp when an 
> interrupt has occured.
> 
> e.g.: the user presses a key on the keyboard. Where can I read out the 
> timestamp of this event?
> 
> To be more precise, I 'm looking for
> 
> ( )a function call
> ( ) a callback where I can register to be notified when an event occurs
> ( ) a global accessible variable
> ( ) a /proc entry
> 
> or something like that.
> 
> Any ideas ?

Have a look at the Linux Trace Toolkit:
http://www.opersys.com/LTT/
It records micro-second time-stamps for quite a few events, including
interrupts.

HTH,

Karim
-- 
Author, Speaker, Developer, Consultant
Pushing Embedded and Real-Time Linux Systems Beyond the Limits
http://www.opersys.com || karim@opersys.com || 514-812-4145


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
  2003-10-02 17:40       ` getting timestamp of last interrupt? Hans-Georg Thien
  2003-10-02 18:54         ` Karim Yaghmour
@ 2003-10-02 18:59         ` Richard B. Johnson
  2003-10-02 22:46         ` Peter Chubb
  2 siblings, 0 replies; 24+ messages in thread
From: Richard B. Johnson @ 2003-10-02 18:59 UTC (permalink / raw)
  To: Hans-Georg Thien; +Cc: linux-kernel

On Thu, 2 Oct 2003, Hans-Georg Thien wrote:

> I am looking for a possibility to read out the last timestamp when an
> interrupt has occured.
>
> e.g.: the user presses a key on the keyboard. Where can I read out the
> timestamp of this event?

You can get A SIGIO signal for every keyboard, (or other input) event.
What you do with it is entirely up to you. Linux/Unix doesn't have
"callbacks", instead it has signals. It also has select() and poll(),
all useful for handling such events. If you want a time-stamp, you
call gettimeofday() in your signal handler.


Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
            Note 96.31% of all statistics are fiction.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* getting timestamp of last interrupt?
  2003-10-02 17:40       ` getting timestamp of last interrupt? Hans-Georg Thien
  2003-10-02 18:54         ` Karim Yaghmour
  2003-10-02 18:59         ` Richard B. Johnson
@ 2003-10-02 22:46         ` Peter Chubb
  2 siblings, 0 replies; 24+ messages in thread
From: Peter Chubb @ 2003-10-02 22:46 UTC (permalink / raw)
  To: Hans-Georg Thien; +Cc: linux-kernel

>>>>> "Hans-Georg" == Hans-Georg Thien <1682-600@onlinehome.de> writes:

Hans-Georg> I am looking for a possibility to read out the last
Hans-Georg> timestamp when an interrupt has occured.

Hans-Georg> e.g.: the user presses a key on the keyboard. Where can I
Hans-Georg> read out the timestamp of this event?

Hans-Georg> To be more precise, I 'm looking for

Hans-Georg> ( )a function call ( ) a callback where I can register to
Hans-Georg> be notified when an event occurs ( ) a global accessible
Hans-Georg> variable ( ) a /proc entry

Hans-Georg> or something like that.

Hans-Georg> Any ideas ?

If you have the microstate accoounting patch applied, then the
timestamp of each  last IRQ is in the array msa_irq_entered[cpu][irq],
measured as an architecture-specific number.  Convert it to
nanoseconds since boot with MSA_TO_NSEC


Peter C

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
  2003-10-06 19:33             ` Richard B. Johnson
@ 2003-10-06 21:59               ` Hans-Georg Thien
  0 siblings, 0 replies; 24+ messages in thread
From: Hans-Georg Thien @ 2003-10-06 21:59 UTC (permalink / raw)
  To: root; +Cc: Kernel Mailing List

Richard B. Johnson wrote:

> On Mon, 6 Oct 2003, Hans-Georg Thien wrote:
> 
> 
>>Richard B. Johnson wrote:
>>
>>
>>>On Mon, 6 Oct 2003, Hans-Georg Thien wrote:
>>>
>>>
>>>>[...]
>>>>I'm writing a kernel mode device driver (mouse).
>>>>
>>>>In that device driver I need the timestamp of the last event for another
>>>>kernel mode device (keyboard).
>>>>
>>>>I do not care if that timestamp is in jiffies or in gettimeofday()
>>>>format or whatever format does exist in the world. I am absolutely sure
>>>>I can convert it somehow to fit my needs.
>>>>
>>>>But since it is a kernel mode driver it can not -AFAIK- use the signal()
>>>>syscall.
>>>>
>>>>-Hans
>>>
>>>
>>>Then it gets real simple. Just use jiffies, if you can stand the [...]
>>
>>I fear that there is still some miss-understanding. Jiffies are totally
>>OK for me. I can use them without any conversion.
>>
>>I'll try to formulate the problem with some other words:
>>
>>I hope that there is is something like a "jiffie-counter" for the
>>keyboard driver, that stores the actual jiffies value whenever a
>>keyboard interrupt occurs.
>>
> 
> 
> Well the keyboard driver and the mouse driver are entirely
> different devices.
> 
yes, - I know

> The keyboard has a built-int CPU that generates scan-codes for
> every key-press/key-release. It also performs auto-repeat. The
> mouse generates mouse data at each interrupting event. This data
> represents direction and three key events. Wheel mouse have may
> have additional data, I haven't looked at them. They are not
> related in any way.
> 
yes, - I know

> 
> 
>>I hope too, that there is a way to query that "jiffie-counter" from
>>another kernel driver, so that I can write something like
>>
>>
>>mymouse_module.c
>>
>>...
>>void mouse_event(){
>>
>>    // get the current time in jiffies
>>    int now=jiffies;
>>
>>    // get the jiffie value of the last kbd event
>>    int last_kbd_event= ????;  // ... but how to do that ...
>>
>>    if ((now - last_kbd_event) > delay) {
>>	do_some_very_smart_things();
>>    }
>>   }
>>...
>>
> 
> 
> Now this pseudo-code shows a "last_kbd_event", not a mouse-
> event as shown in:
> 
yes, - I know =8))

It is because I want do some things with the mouse in relation to 
keyboard events.

> 
> [... a quite detailed explanation on mouse interrupts, mouse data ...]
yes, I know. But my question was: how can I get the timestamp of the 
last keyboard interrupt.

> When your module is un-installed, it needs to restore the
> previous (saved) value of that pointer.
> 
yes, - I know

> Whatever code you make that pointer point-to, must be
> interrupt-safe. It can get the jiffie-count and put it
> into a buffer, then return.
>
yes, - I know

Hey Richard, - what is so difficult to understand ?

Anyway, - have you read the email reply from Gabriel Paubert regarding 
this topic? Sounds very good for a 2.6.x kernel. It seems that I can use 
the /dev/input/event? device files. I have just modprobed the "evdev" 
module. It seems that I can get my timestamps by reading one of this 
files. Have to investigate still which one of them I have to use.

-Hans



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
  2003-10-06 19:05           ` Hans-Georg Thien
@ 2003-10-06 19:33             ` Richard B. Johnson
  2003-10-06 21:59               ` Hans-Georg Thien
  0 siblings, 1 reply; 24+ messages in thread
From: Richard B. Johnson @ 2003-10-06 19:33 UTC (permalink / raw)
  To: Hans-Georg Thien; +Cc: Kernel Mailing List

On Mon, 6 Oct 2003, Hans-Georg Thien wrote:

> Richard B. Johnson wrote:
>
> > On Mon, 6 Oct 2003, Hans-Georg Thien wrote:
> >
> >>
> >>[...]
> >>I'm writing a kernel mode device driver (mouse).
> >>
> >>In that device driver I need the timestamp of the last event for another
> >>kernel mode device (keyboard).
> >>
> >>I do not care if that timestamp is in jiffies or in gettimeofday()
> >>format or whatever format does exist in the world. I am absolutely sure
> >>I can convert it somehow to fit my needs.
> >>
> >>But since it is a kernel mode driver it can not -AFAIK- use the signal()
> >>syscall.
> >>
> >>-Hans
> >
> >
> > Then it gets real simple. Just use jiffies, if you can stand the [...]
> I fear that there is still some miss-understanding. Jiffies are totally
> OK for me. I can use them without any conversion.
>
> I'll try to formulate the problem with some other words:
>
> I hope that there is is something like a "jiffie-counter" for the
> keyboard driver, that stores the actual jiffies value whenever a
> keyboard interrupt occurs.
>

Well the keyboard driver and the mouse driver are entirely
different devices.

The keyboard has a built-int CPU that generates scan-codes for
every key-press/key-release. It also performs auto-repeat. The
mouse generates mouse data at each interrupting event. This data
represents direction and three key events. Wheel mouse have may
have additional data, I haven't looked at them. They are not
related in any way.


> I hope too, that there is a way to query that "jiffie-counter" from
> another kernel driver, so that I can write something like
>
>
> mymouse_module.c
>
> ...
> void mouse_event(){
>
>     // get the current time in jiffies
>     int now=jiffies;
>
>     // get the jiffie value of the last kbd event
>     int last_kbd_event= ????;  // ... but how to do that ...
>
>     if ((now - last_kbd_event) > delay) {
> 	do_some_very_smart_things();
>     }
>    }
> ...
>

Now this pseudo-code shows a "last_kbd_event", not a mouse-
event as shown in:

> >>I'm writing a kernel mode device driver (mouse).

... your words, not mine.

I presume that you are replacing the existing mouse-driver.
If so, your mouse-buffer, i.e., the place you put the
mouse-event movement-codes can be something like:

struct mouse_event {
    unsigned long time;
    int mouse_code;
    }

You allocate a buffer of this type and, during each interrupt,
you put both the jiffie-time and the mouse code into your buffer.

If you are not replacing the existing mouse driver, then you
need to share its interrupt with your new module. The new
module records the time-stamp of each of the interrupts, only.

Every bit of mouse-data was obtained as a result of an interrupt.
Using that knowledge, you should be able to correlate a time-stamp
to mouse-data (clear your time-stamp buffer when no mouse data
are available).

If you are using the keyboard, not the mouse, then the same
things apply.

If you just want to patch the existing keyboard or mouse
ISR to save a time-stamp in your module code, you need to
make the built-in keyboard or mouse ISR code call a function
by pointer. This pointer must be initialized to point to a
stub that simply returns. You need to export this symbol
so it can be found by your module.

When your module is installed, it saves the value in that
pointer. It then changes the pointer value to the address of
your routine. It needs to do this under a spin-lock.

When your module is un-installed, it needs to restore the
previous (saved) value of that pointer.

Whatever code you make that pointer point-to, must be
interrupt-safe. It can get the jiffie-count and put it
into a buffer, then return.


Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
            Note 96.31% of all statistics are fiction.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
  2003-10-06 18:34         ` Richard B. Johnson
@ 2003-10-06 19:05           ` Hans-Georg Thien
  2003-10-06 19:33             ` Richard B. Johnson
  0 siblings, 1 reply; 24+ messages in thread
From: Hans-Georg Thien @ 2003-10-06 19:05 UTC (permalink / raw)
  To: root; +Cc: Kernel Mailing List

Richard B. Johnson wrote:

> On Mon, 6 Oct 2003, Hans-Georg Thien wrote:
> 
>>
>>[...]
>>I'm writing a kernel mode device driver (mouse).
>>
>>In that device driver I need the timestamp of the last event for another
>>kernel mode device (keyboard).
>>
>>I do not care if that timestamp is in jiffies or in gettimeofday()
>>format or whatever format does exist in the world. I am absolutely sure
>>I can convert it somehow to fit my needs.
>>
>>But since it is a kernel mode driver it can not -AFAIK- use the signal()
>>syscall.
>>
>>-Hans
> 
> 
> Then it gets real simple. Just use jiffies, if you can stand the [...]
I fear that there is still some miss-understanding. Jiffies are totally 
OK for me. I can use them without any conversion.

I'll try to formulate the problem with some other words:

I hope that there is is something like a "jiffie-counter" for the 
keyboard driver, that stores the actual jiffies value whenever a 
keyboard interrupt occurs.

I hope too, that there is a way to query that "jiffie-counter" from 
another kernel driver, so that I can write something like


mymouse_module.c

...
void mouse_event(){

    // get the current time in jiffies
    int now=jiffies;

    // get the jiffie value of the last kbd event
    int last_kbd_event= ????;  // ... but how to do that ...

    if ((now - last_kbd_event) > delay) {
	do_some_very_smart_things();
    }
   }
...

-Hans



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
  2003-10-06 15:26     ` Gabriel Paubert
@ 2003-10-06 18:37       ` Hans-Georg Thien
  0 siblings, 0 replies; 24+ messages in thread
From: Hans-Georg Thien @ 2003-10-06 18:37 UTC (permalink / raw)
  To: Gabriel Paubert; +Cc: Kernel Mailing List

Gabriel Paubert wrote:

>>> [...]
>>>>I am looking for a possibility to read out the last timestamp when an 
>>>>interrupt has occured.
>>>>[...]
> 
> 
> Doesn't the input layer add a timestamp to every event? 
> 
> At least that's the impression I have from xxd /dev/input/eventN: the
> first eight bytes of each 16 bytes packet look so furiously close to
> a struct timeval that they can't be anything else :-)
> 
> Just that I don't know how the devices and N are associated, it seems to be
> order of discovery/registering at boot.
Hello Gabriel,

Oh yes, - that looks quite good to me. I'm investigating on that now. I 
found out, that you need at least to compile the "evdev" module.

-Hans



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
  2003-10-06 18:21       ` Hans-Georg Thien
@ 2003-10-06 18:34         ` Richard B. Johnson
  2003-10-06 19:05           ` Hans-Georg Thien
  0 siblings, 1 reply; 24+ messages in thread
From: Richard B. Johnson @ 2003-10-06 18:34 UTC (permalink / raw)
  To: Hans-Georg Thien; +Cc: Kernel Mailing List

On Mon, 6 Oct 2003, Hans-Georg Thien wrote:

> Richard B. Johnson wrote:
> > On Sat, 4 Oct 2003, Hans-Georg Thien wrote:
> >
> >
> >>> [...]
> >>>>I am looking for a possibility to read out the last timestamp when an
> >>>>interrupt has occured.
> >>>>
> >>>>e.g.: the user presses a key on the keyboard. Where can I read out the
> >>>>timestamp of this event?
> >>>
> >>>
> >>>You can get A SIGIO signal for every keyboard, (or other input) event.
> >>>What you do with it is entirely up to you. Linux/Unix doesn't have
> >>>"callbacks", instead it has signals. It also has select() and poll(),
> >>>all useful for handling such events. If you want a time-stamp, you
> >>>call gettimeofday() in your signal handler.
> >>>
> >>
> >>Thanks a lot Richard,
> >>
> >>... but ... can I use signals in kernel mode?
> >
> >
> > Well you talked about the user pressing a key and getting
> > a time-stamp as a result. If you need time-stamps
> > inside the kernel, i.e, a module, then you can call
> > the kernel's do_gettimeofday() function.
> >
> Hello Richard, - It seems, that I should be more precise about what I
> exactly mean...
>
>
> I'm writing a kernel mode device driver (mouse).
>
> In that device driver I need the timestamp of the last event for another
> kernel mode device (keyboard).
>
> I do not care if that timestamp is in jiffies or in gettimeofday()
> format or whatever format does exist in the world. I am absolutely sure
> I can convert it somehow to fit my needs.
>
> But since it is a kernel mode driver it can not -AFAIK- use the signal()
> syscall.
>
> -Hans

Then it gets real simple. Just use jiffies, if you can stand the
wrap that will occur every (2^32 -1)/HZ seconds ~= 497 days with
HZ = 100. If not, call sys_gettimeofday(). Also, if your events
are closer in time than a HZ, then you must get time from
sys_gettimeofday().

Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
            Note 96.31% of all statistics are fiction.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
  2003-10-06 12:52     ` Richard B. Johnson
@ 2003-10-06 18:21       ` Hans-Georg Thien
  2003-10-06 18:34         ` Richard B. Johnson
  0 siblings, 1 reply; 24+ messages in thread
From: Hans-Georg Thien @ 2003-10-06 18:21 UTC (permalink / raw)
  To: root; +Cc: Kernel Mailing List

Richard B. Johnson wrote:
> On Sat, 4 Oct 2003, Hans-Georg Thien wrote:
> 
> 
>>> [...]
>>>>I am looking for a possibility to read out the last timestamp when an
>>>>interrupt has occured.
>>>>
>>>>e.g.: the user presses a key on the keyboard. Where can I read out the
>>>>timestamp of this event?
>>>
>>>
>>>You can get A SIGIO signal for every keyboard, (or other input) event.
>>>What you do with it is entirely up to you. Linux/Unix doesn't have
>>>"callbacks", instead it has signals. It also has select() and poll(),
>>>all useful for handling such events. If you want a time-stamp, you
>>>call gettimeofday() in your signal handler.
>>>
>>
>>Thanks a lot Richard,
>>
>>... but ... can I use signals in kernel mode?
> 
> 
> Well you talked about the user pressing a key and getting
> a time-stamp as a result. If you need time-stamps
> inside the kernel, i.e, a module, then you can call
> the kernel's do_gettimeofday() function.
> 
Hello Richard, - It seems, that I should be more precise about what I 
exactly mean...


I'm writing a kernel mode device driver (mouse).

In that device driver I need the timestamp of the last event for another 
kernel mode device (keyboard).

I do not care if that timestamp is in jiffies or in gettimeofday() 
format or whatever format does exist in the world. I am absolutely sure 
I can convert it somehow to fit my needs.

But since it is a kernel mode driver it can not -AFAIK- use the signal() 
syscall.

-Hans




^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
  2003-10-04  4:05   ` Hans-Georg Thien
@ 2003-10-06 15:26     ` Gabriel Paubert
  2003-10-06 18:37       ` Hans-Georg Thien
  0 siblings, 1 reply; 24+ messages in thread
From: Gabriel Paubert @ 2003-10-06 15:26 UTC (permalink / raw)
  To: Hans-Georg Thien; +Cc: linux-kernel

On Sat, Oct 04, 2003 at 06:05:02AM +0200, Hans-Georg Thien wrote:
> Karim Yaghmour wrote:
> 
> >
> >Hans-Georg Thien wrote:
> >
> >>I am looking for a possibility to read out the last timestamp when an 
> >>interrupt has occured.
> >>
> >>e.g.: the user presses a key on the keyboard. Where can I read out the 
> >>timestamp of this event?
> >>
> >>To be more precise, I 'm looking for
> >>
> >>( )a function call
> >>( ) a callback where I can register to be notified when an event occurs
> >>( ) a global accessible variable
> >>( ) a /proc entry
> >>
> >>or something like that.
> >>
> >>Any ideas ?
> >
> >
> >Have a look at the Linux Trace Toolkit:
> >http://www.opersys.com/LTT/
> >It records micro-second time-stamps for quite a few events, including
> >interrupts.
> >
> thanke a lot for reply Karim,
> 
> but I think that LTT does not fit to my needs. It needs to modify the
> kernel - and that is what I want to avoid.
> 
> I'm looking for a already existing built-in capability.
> 
> Maybe signal SIGIO is a solution, if it  does not
> 
> (x) give me *every* IO event
> (x) has to much overhead - I have to respond to keyboard/mouse events, *not*

Doesn't the input layer add a timestamp to every event? 

At least that's the impression I have from xxd /dev/input/eventN: the
first eight bytes of each 16 bytes packet look so furiously close to
a struct timeval that they can't be anything else :-)

Just that I don't know how the devices and N are associated, it seems to be
order of discovery/registering at boot.

	Regards,
	Gabriel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
  2003-10-04  4:03   ` Hans-Georg Thien
@ 2003-10-06 12:52     ` Richard B. Johnson
  2003-10-06 18:21       ` Hans-Georg Thien
  0 siblings, 1 reply; 24+ messages in thread
From: Richard B. Johnson @ 2003-10-06 12:52 UTC (permalink / raw)
  To: Hans-Georg Thien; +Cc: linux-kernel

On Sat, 4 Oct 2003, Hans-Georg Thien wrote:

> Richard B. Johnson wrote:
> > On Thu, 2 Oct 2003, Hans-Georg Thien wrote:
> >
> >
> >>I am looking for a possibility to read out the last timestamp when an
> >>interrupt has occured.
> >>
> >>e.g.: the user presses a key on the keyboard. Where can I read out the
> >>timestamp of this event?
> >
> >
> > You can get A SIGIO signal for every keyboard, (or other input) event.
> > What you do with it is entirely up to you. Linux/Unix doesn't have
> > "callbacks", instead it has signals. It also has select() and poll(),
> > all useful for handling such events. If you want a time-stamp, you
> > call gettimeofday() in your signal handler.
> >
> Thanks a lot Richard,
>
> ... but ... can I use signals in kernel mode?

Well you talked about the user pressing a key and getting
a time-stamp as a result. If you need time-stamps
inside the kernel, i.e, a module, then you can call
the kernel's do_gettimeofday() function.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
            Note 96.31% of all statistics are fiction.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
       [not found] ` <fa.ch95hks.10kepak@ifi.uio.no>
@ 2003-10-04  4:05   ` Hans-Georg Thien
  2003-10-06 15:26     ` Gabriel Paubert
  0 siblings, 1 reply; 24+ messages in thread
From: Hans-Georg Thien @ 2003-10-04  4:05 UTC (permalink / raw)
  To: linux-kernel

Karim Yaghmour wrote:

> 
> Hans-Georg Thien wrote:
> 
>> I am looking for a possibility to read out the last timestamp when an 
>> interrupt has occured.
>>
>> e.g.: the user presses a key on the keyboard. Where can I read out the 
>> timestamp of this event?
>>
>> To be more precise, I 'm looking for
>>
>> ( )a function call
>> ( ) a callback where I can register to be notified when an event occurs
>> ( ) a global accessible variable
>> ( ) a /proc entry
>>
>> or something like that.
>>
>> Any ideas ?
> 
> 
> Have a look at the Linux Trace Toolkit:
> http://www.opersys.com/LTT/
> It records micro-second time-stamps for quite a few events, including
> interrupts.
> 
thanke a lot for reply Karim,

but I think that LTT does not fit to my needs. It needs to modify the
kernel - and that is what I want to avoid.

I'm looking for a already existing built-in capability.

Maybe signal SIGIO is a solution, if it  does not

(x) give me *every* IO event
(x) has to much overhead - I have to respond to keyboard/mouse events, *not*
     disk events
     grafic card events
     eth event
     etc. ...


- Hans





^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: getting timestamp of last interrupt?
       [not found] ` <fa.fvjdidn.13ni70f@ifi.uio.no>
@ 2003-10-04  4:03   ` Hans-Georg Thien
  2003-10-06 12:52     ` Richard B. Johnson
  0 siblings, 1 reply; 24+ messages in thread
From: Hans-Georg Thien @ 2003-10-04  4:03 UTC (permalink / raw)
  To: linux-kernel

Richard B. Johnson wrote:
> On Thu, 2 Oct 2003, Hans-Georg Thien wrote:
> 
> 
>>I am looking for a possibility to read out the last timestamp when an
>>interrupt has occured.
>>
>>e.g.: the user presses a key on the keyboard. Where can I read out the
>>timestamp of this event?
> 
> 
> You can get A SIGIO signal for every keyboard, (or other input) event.
> What you do with it is entirely up to you. Linux/Unix doesn't have
> "callbacks", instead it has signals. It also has select() and poll(),
> all useful for handling such events. If you want a time-stamp, you
> call gettimeofday() in your signal handler.
> 
Thanks a lot Richard,

... but ... can I use signals in kernel mode?



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2003-10-06 21:59 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-01 21:48 [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh a PS/2 Trackpad Hans-Georg Thien
2003-05-01 22:13 ` Måns Rullgård
2003-05-06  9:29 ` wwp
2003-05-06 11:27   ` Hans-Georg Thien
2003-05-08 19:12 ` [RFC][PATCH] "Disable Trackpad while typing" on Notebooks withh aPS/2 Trackpad Khalid Aziz
2003-05-09 11:47   ` Hans-Georg Thien
2003-05-27 20:47   ` Hans-Georg Thien
2003-05-27 21:10     ` wwp
2003-05-29 12:07       ` Hans-Georg Thien
2003-09-30 20:51       ` [PORT to 2.6.x] "Disable Trackpad while typing" on Notebooks with a PS/2 Trackpad Hans-Georg Thien
2003-10-02 17:40       ` getting timestamp of last interrupt? Hans-Georg Thien
2003-10-02 18:54         ` Karim Yaghmour
2003-10-02 18:59         ` Richard B. Johnson
2003-10-02 22:46         ` Peter Chubb
     [not found] <fa.fj0euih.s2sbop@ifi.uio.no>
     [not found] ` <fa.fvjdidn.13ni70f@ifi.uio.no>
2003-10-04  4:03   ` Hans-Georg Thien
2003-10-06 12:52     ` Richard B. Johnson
2003-10-06 18:21       ` Hans-Georg Thien
2003-10-06 18:34         ` Richard B. Johnson
2003-10-06 19:05           ` Hans-Georg Thien
2003-10-06 19:33             ` Richard B. Johnson
2003-10-06 21:59               ` Hans-Georg Thien
     [not found] ` <fa.ch95hks.10kepak@ifi.uio.no>
2003-10-04  4:05   ` Hans-Georg Thien
2003-10-06 15:26     ` Gabriel Paubert
2003-10-06 18:37       ` Hans-Georg Thien

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).