home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / linux / 9217 < prev    next >
Encoding:
Text File  |  1992-08-27  |  10.0 KB  |  359 lines

  1. Path: sparky!uunet!gatech!prism!gt6698a
  2. From: gt6698a@prism.gatech.EDU (Andrew Hobson)
  3. Newsgroups: comp.os.linux
  4. Subject: Microsoft Bus mouse works, sorta
  5. Summary: microsoft bus mouse works, sorta
  6. Keywords: microsoft, bus
  7. Message-ID: <67043@hydra.gatech.EDU>
  8. Date: 27 Aug 92 18:41:44 GMT
  9. Organization: Georgia Institute of Technology
  10. Lines: 347
  11.  
  12.  
  13. Greets!
  14.  
  15. I have an ATI VGA Wonder XL and I have a microsoft mouse plugged in the 
  16. bus port. (It is on the VGA card)  Rik Faith (faith@cs.unc.edu) has
  17. written a X386 for ATI cards and it works great, I think. 
  18.  
  19. I received mail from Derrick C. Cole <cole@concert.net> when I posted
  20. previously about getting the microsoft bus mouse to work.  He mailed
  21. me a patch by Frank ten Wolde (franky@duteca.et.tudelft.nl). 
  22. I have modified this patch and the existing mouse.c by
  23. James Banks, David Giller, and Nathan Laredo (Thanks for the help,
  24. Nathan!!!)
  25.  
  26. I have made modifications to mouse.c so that a microsoft mouse will 
  27. work.  Essentially, these changes were only to the mouse_interrupt 
  28. function and should not have affected anything else.  If I run X, then 
  29. my mouse will not work, even though I am pretty sure that the mouse 
  30. driver works.  (I put printk's inside the driver, and I modified the 
  31. mouse test program that comes with X for use with a bus mouse and it
  32. works)  If I run a program that does an ioperm(port,1,1) for all 
  33. four of the port addresses, and then run X, I can use the mouse 
  34. until the xterm comes up.  Then, as long as I hold down a key 
  35. (on the keyboard), the mouse works.  If I do not hold down a key, 
  36. then move the mouse, and then press a key, the mouse will jump 
  37. to a new location, about where it should have moved.  (I have no 
  38. way of telling exactly where it should have moved.)  If I get 
  39. rid of the Xterm and Xclock, I still cannot use the mouse, 
  40. except by pressing down a key.  Pressing a mouse button does not 
  41. register, unless the mouse is moved.  Using the mouse program that came with X, if I press a button, then new information
  42. is printed on the screen, but is is the same information as before until
  43. I move the mouse. 
  44.  
  45. I guess I need some testers to see if the problem is with the ATI
  46. X or with my code.  
  47.  
  48. I have sent mail to Rik Faith about this, as well, so hopefully this 
  49. can be resolved.  I would really like to not have to press a key
  50. to use my mouse in X!!
  51.  
  52. Thanks alot for any help you can give me. I will include copies of my 
  53. /usr/src/linux/kernel/chr_drv/mouse.c and 
  54. /usr/src/linux/include/linux/mouse.h files.   I don't think that I have
  55. changed mouse.h. I can't post a patch because
  56. I am not sure I have the original I have done so many changes!!
  57.  
  58. Andrew Hobson
  59.  
  60. /*======================  MOUSE.C  =========================*/
  61.  
  62. /*
  63.  * Logitech Bus Mouse Driver for Linux
  64.  * by James Banks
  65.  * 
  66.  * Heavily modified by David Giller
  67.  *   changed from queue- to counter- driven
  68.  *   hacked out a (probably incorrect) mouse_select
  69.  *
  70.  * Modified again by Nathan Laredo to interface with
  71.  *   0.96c-pl1 IRQ handling changes (13JUL92)
  72.  *   didn't bother touching select code.
  73.  * 
  74.  * version 0.1
  75.  */
  76.  
  77. /* Modified to work with microsoft bus mice.  Might work, might not */
  78. /* Andrew Hobson gt6698a@prism.gatech.edu 27AUG92 */
  79.  
  80. #include    <linux/kernel.h>
  81. #include    <linux/sched.h>
  82. #include    <linux/tty.h>
  83. #include    <asm/io.h>
  84. #include    <asm/segment.h>
  85. #include    <asm/system.h>
  86. #include    <asm/irq.h>
  87. #include    <linux/errno.h>
  88. #include    <linux/signal.h>
  89. #include    <linux/mouse.h>
  90.  
  91. struct mouse_status mouse;
  92.  
  93. void release_mouse(struct inode * inode, struct file * file)
  94. {
  95.     MSE_INT_OFF();
  96.     mouse.active = 0;
  97.     mouse.ready = 0; 
  98.     mouse.inode = NULL;
  99.     
  100.     free_irq(MOUSE_IRQ);
  101. }
  102.  
  103. int open_mouse(struct inode * inode, struct file * file)
  104. {
  105.     if (mouse.active) return -EBUSY;
  106.     if (!mouse.present) return -EINVAL;
  107.     
  108.     mouse.active = 1;
  109.     mouse.ready = 0;
  110.     mouse.inode = inode;
  111.     mouse.dx = 0;
  112.     mouse.dy = 0;    
  113.     mouse.buttons = mouse.latch_buttons = 0x80;
  114.     
  115.     
  116.     MSE_INT_ON();
  117.     if (request_irq(MOUSE_IRQ, mouse_interrupt)) return -EBUSY;
  118.  
  119.     return 0;
  120. }
  121.  
  122. int write_mouse(struct inode * inode, struct file * file,
  123.         char * buffer, int count)
  124. {
  125.     return -EINVAL;
  126. }
  127.  
  128. int read_mouse(struct inode * inode, struct file * file, 
  129.         char * buffer, int count)
  130. {
  131.     int i;
  132.  
  133.     if (count < 3) return -EINVAL;
  134.     if (!mouse.ready) return -EAGAIN;
  135.     
  136.     MSE_INT_OFF();
  137.         
  138.     put_fs_byte(mouse.latch_buttons | 0x80, buffer); 
  139.     
  140.     if (mouse.dx < -127) mouse.dx = -127;
  141.     if (mouse.dx >  127) mouse.dx =  127;
  142.     
  143.     put_fs_byte((char)mouse.dx, buffer + 1);
  144.     
  145.     if (mouse.dy < -127) mouse.dy = -127;
  146.     if (mouse.dy >  127) mouse.dy =  127;
  147.     
  148.     put_fs_byte((char) -mouse.dy, buffer + 2);
  149.     
  150.     for (i = 3; i < count; i++)
  151.         put_fs_byte(0x00, buffer + i);
  152.  
  153.     mouse.dx = 0;
  154.     mouse.dy = 0;
  155.     mouse.latch_buttons = mouse.buttons;
  156.     mouse.ready = 0;
  157.     
  158.     MSE_INT_ON();
  159.     return i;    
  160. }
  161.  
  162. #define outp(a,b)    outb(b,a);
  163.  
  164. void mouse_interrupt(void)
  165. {
  166.     char dx, dy, buttons;
  167.     unsigned int i;
  168.      char tmp;
  169.  
  170.     MSE_INT_OFF();
  171.  
  172.         outp(MSE_DATA_PORT, 0x07);          /* from MSDOS device driver */
  173.         outp(MSE_SIGNATURE_PORT, tmp = (inb(MSE_SIGNATURE_PORT) | 0x20));
  174.  
  175.         /* FTW  version 0.2  920614:
  176.          * I have seen this in the MSDOS Microsoft Bus Mouse device driver.
  177.          * Don't know what its for. It does not seem required as it works
  178.          * well as it is!
  179.          */
  180.         if (0) {
  181.             /* I hope GCC is clever enough to just to remove this code :-) */
  182.         (void) inb(MSE_SIGNATURE_PORT);
  183.         (void) inb(MSE_SIGNATURE_PORT);
  184.         (void) inb(MSE_SIGNATURE_PORT);
  185.         outp(MSE_SIGNATURE_PORT, tmp);
  186.     }
  187.  
  188.         outp(MSE_DATA_PORT, 0x01);          /* from MSDOS device driver */
  189.         dx = inb(MSE_SIGNATURE_PORT);
  190.  
  191.         outp(MSE_DATA_PORT, 0x02);          /* from MSDOS device driver */
  192.         dy = inb(MSE_SIGNATURE_PORT);
  193.  
  194.         outp(MSE_DATA_PORT, 0x00);          /* from MSDOS device driver */
  195.         buttons = inb(MSE_SIGNATURE_PORT);
  196.  
  197.         outp(MSE_DATA_PORT, 0x07);          /* from MSDOS device driver */
  198.         outp(MSE_SIGNATURE_PORT, inb(MSE_SIGNATURE_PORT) & 0xDF);
  199.  
  200.         /* FTW  version 0.2  920614:
  201.          * Ah! The microsoft mouse has its buttons reversed with respect
  202.          * to the Logitech Mouse. You certainly get very strange mouse
  203.          * behaviour in X with the buttons reversed :-)
  204.          */
  205.         buttons = ~buttons;
  206.         buttons &= 0x07;        /* ignore button state change info      */
  207.  
  208.         /* FTW  version 0.2  920614
  209.          * Another thing: The original code for do_IRQ5 simply returned
  210.          * immediately if the event_queue was full. This does not work
  211.          * for Microsoft as the mouse requires to be 'flushed.' The behaviour
  212.          * in X was that after violent mouse movements it would simply freeze
  213.          * up and remained dead until after a system reboot. Hence the
  214.          * !queuefull test at this point in the code.
  215.          */
  216.  
  217.         /* FTW  version 0.2  920614
  218.          * The following outb() instruction probably does nothing for the
  219.          * Microsoft Mouse. It is a left over from the Logitech code.
  220.          */
  221.     MSE_INT_ON();
  222.  
  223.     mouse.buttons = buttons;
  224.     mouse.latch_buttons |= buttons;
  225.     mouse.dx += dx;
  226.     mouse.dy += dy;
  227.     mouse.ready = 1;
  228.     if (mouse.inode && mouse.inode->i_wait)
  229.              wake_up(&mouse.inode->i_wait);
  230.  
  231. }
  232.  
  233.     
  234. static struct file_operations mouse_fops = {
  235.         NULL,        /* mouse_seek */
  236.         read_mouse,
  237.         write_mouse,
  238.         NULL,         /* mouse_readdir */
  239.         mouse_select,     /* mouse_select */
  240.         NULL,         /* mouse_ioctl */
  241.         open_mouse,
  242.         release_mouse,
  243. };
  244.  
  245. int mouse_select(struct inode *inode, struct file *file, int which, 
  246.         select_table *seltable)
  247. {
  248.         if (mouse.ready) 
  249.        return 1;
  250.     else
  251.        return 0;
  252. }
  253.  
  254. long mouse_init(long kmem_start)
  255. {    
  256.     int i,j;
  257.     unsigned char tchar;
  258.     
  259.     outb(MSE_CONFIG_BYTE, MSE_CONFIG_PORT);
  260.     outb(0x09, MSE_SIGNATURE_PORT);
  261.  
  262.     for (i = 0; i < 100000; i++); /* busy loop */
  263.         tchar = inb(MSE_SIGNATURE_PORT);
  264.     if (tchar != (0x09)) {
  265.         printk("No bus mouse detected.\n");
  266.         mouse.present = 0;
  267.         return kmem_start;
  268.     }
  269.         chrdev_fops[10] = &mouse_fops;
  270.  
  271.     mouse.present = 1;
  272.     mouse.active = 0;
  273.     mouse.ready = 0;
  274.     mouse.buttons = mouse.latch_buttons = 0x80;
  275.     mouse.dx = 0;
  276.     mouse.dy = 0;
  277.     printk("Bus mouse detected and installed.\n");
  278.     return kmem_start;
  279. }
  280.  
  281.  
  282.  
  283. /* ============================== MOUSE.H ========================== */
  284.  
  285. /*
  286.  * linux/include/linux/mouse.h: header file for Logitech Bus Mouse driver
  287.  * by James Banks
  288.  *
  289.  * based on information gleamed from various mouse drivers on the net
  290.  *
  291.  * Heavily modified by David giller (rafetmad@oxy.edu)
  292.  *
  293.  * Minor modifications for Linux 0.96c-pl1 by Nathan Laredo
  294.  * gt7080a@prism.gatech.edu (13JUL92)
  295.  *
  296.  */
  297.  
  298. #ifndef _MOUSE_H
  299. #define _MOUSE_H
  300.  
  301. #define MOUSE_IRQ        5
  302.  
  303. #define    MSE_DATA_PORT        0x23c
  304. #define    MSE_SIGNATURE_PORT    0x23d
  305. #define    MSE_CONTROL_PORT    0x23e
  306. #define MSE_INTERRUPT_PORT    0x23e
  307. #define    MSE_CONFIG_PORT        0x23f
  308.  
  309. #define    MSE_ENABLE_INTERRUPTS    0x00
  310. #define    MSE_DISABLE_INTERRUPTS    0x10
  311.  
  312. #define    MSE_READ_X_LOW        0x80
  313. #define    MSE_READ_X_HIGH        0xa0
  314. #define    MSE_READ_Y_LOW        0xc0
  315. #define    MSE_READ_Y_HIGH        0xe0
  316.  
  317. /* Magic number used to check if the mouse exists */
  318. #define MSE_CONFIG_BYTE        0x91
  319. #define MSE_DEFAULT_MODE    0x90
  320. #define MSE_SIGNATURE_BYTE    0xa5
  321.  
  322. /* useful macros */
  323.  
  324. #define MSE_INT_OFF()    outb(MSE_DISABLE_INTERRUPTS, MSE_CONTROL_PORT)
  325. #define MSE_INT_ON()    outb(MSE_ENABLE_INTERRUPTS, MSE_CONTROL_PORT)
  326.  
  327. struct mouse_status
  328.     {
  329.     char        buttons;
  330.     char        latch_buttons;
  331.     int        dx;
  332.     int        dy;    
  333.  
  334.     int         present;
  335.     int        ready;
  336.     int        active;
  337.  
  338.     struct inode    *inode;
  339.     };
  340.  
  341. /* Function Prototypes */
  342. extern void mouse_interrupt(void);
  343. extern long mouse_init(long);
  344. extern int open_mouse(struct inode *, struct file *);
  345. extern void release_mouse(struct inode *, struct file *);
  346. extern int read_mouse(struct inode *, struct file *, char *, int);
  347. extern int write_mouse(struct inode *, struct file *, char *, int);
  348. extern int mouse_select(struct inode *inode, struct file *file, int which, 
  349.         select_table *seltable);
  350. #endif
  351.  
  352.  
  353.  
  354. -- 
  355. Andrew Hobson                         Internet: gt6698a@prism.gatech.edu
  356. "He who joyfully marches to music in rank and file has already
  357. earned my contempt.  He has been given a large brain by mistake,
  358. since for him the spinal cord would fully suffice."   -- Albert Einstein
  359.