2 * ATI XL Bus Mouse Driver for Linux
3 * by Bob Harris (rth@sparta.com)
5 * Uses VFS interface for linux 0.98 (01OCT92)
7 * Modified by Chris Colohan (colohan@eecg.toronto.edu)
8 * Modularised 8-Sep-95 Philip Blundell <pjb27@cam.ac.uk>
10 * Converted to use new generic busmouse code. 5 Apr 1998
11 * Russell King <rmk@arm.uk.linux.org>
16 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/signal.h>
21 #include <linux/errno.h>
22 #include <linux/miscdevice.h>
23 #include <linux/random.h>
24 #include <linux/poll.h>
25 #include <linux/init.h>
26 #include <linux/ioport.h>
29 #include <asm/uaccess.h>
30 #include <asm/system.h>
35 #define ATIXL_MOUSE_IRQ 5 /* H/W interrupt # set up on ATIXL board */
36 #define ATIXL_BUSMOUSE 3 /* Minor device # (mknod c 10 3 /dev/bm) */
38 /* ATI XL Inport Busmouse Definitions */
40 #define ATIXL_MSE_DATA_PORT 0x23d
41 #define ATIXL_MSE_SIGNATURE_PORT 0x23e
42 #define ATIXL_MSE_CONTROL_PORT 0x23c
44 #define ATIXL_MSE_READ_BUTTONS 0x00
45 #define ATIXL_MSE_READ_X 0x01
46 #define ATIXL_MSE_READ_Y 0x02
48 /* Some nice ATI XL macros */
50 /* Select IR7, HOLD UPDATES (INT ENABLED), save X,Y */
51 #define ATIXL_MSE_DISABLE_UPDATE() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \
52 outb( (0x20 | inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); }
54 /* Select IR7, Enable updates (INT ENABLED) */
55 #define ATIXL_MSE_ENABLE_UPDATE() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \
56 outb( (0xdf & inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); }
58 /* Select IR7 - Mode Register, NO INTERRUPTS */
59 #define ATIXL_MSE_INT_OFF() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \
60 outb( (0xe7 & inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); }
62 /* Select IR7 - Mode Register, DATA INTERRUPTS ENABLED */
63 #define ATIXL_MSE_INT_ON() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \
64 outb( (0x08 | inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); }
66 /* Same general mouse structure */
70 static void mouse_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
74 ATIXL_MSE_DISABLE_UPDATE(); /* Note that interrupts are still enabled */
75 outb(ATIXL_MSE_READ_X
, ATIXL_MSE_CONTROL_PORT
); /* Select IR1 - X movement */
76 dx
= inb( ATIXL_MSE_DATA_PORT
);
77 outb(ATIXL_MSE_READ_Y
, ATIXL_MSE_CONTROL_PORT
); /* Select IR2 - Y movement */
78 dy
= inb( ATIXL_MSE_DATA_PORT
);
79 outb(ATIXL_MSE_READ_BUTTONS
, ATIXL_MSE_CONTROL_PORT
); /* Select IR0 - Button Status */
80 buttons
= inb( ATIXL_MSE_DATA_PORT
);
81 busmouse_add_movementbuttons(msedev
, dx
, -dy
, buttons
);
82 ATIXL_MSE_ENABLE_UPDATE();
85 static int release_mouse(struct inode
* inode
, struct file
* file
)
87 ATIXL_MSE_INT_OFF(); /* Interrupts are really shut down here */
88 free_irq(ATIXL_MOUSE_IRQ
, NULL
);
92 static int open_mouse(struct inode
* inode
, struct file
* file
)
94 if (request_irq(ATIXL_MOUSE_IRQ
, mouse_interrupt
, 0, "ATIXL mouse", NULL
))
96 ATIXL_MSE_INT_ON(); /* Interrupts are really enabled here */
100 static struct busmouse atixlmouse
= {
101 ATIXL_BUSMOUSE
, "atixl", THIS_MODULE
, open_mouse
, release_mouse
, 0
104 static int __init
atixl_busmouse_init(void)
109 * We must request the resource and claim it atomically
110 * nowdays. We can throw it away on error. Otherwise we
111 * may race another module load of the same I/O
114 if (!request_region(ATIXL_MSE_DATA_PORT
, 3, "atixlmouse"))
117 a
= inb( ATIXL_MSE_SIGNATURE_PORT
); /* Get signature */
118 b
= inb( ATIXL_MSE_SIGNATURE_PORT
);
119 c
= inb( ATIXL_MSE_SIGNATURE_PORT
);
120 if (( a
!= b
) && ( a
== c
))
121 printk(KERN_INFO
"\nATI Inport ");
124 release_region(ATIXL_MSE_DATA_PORT
,3);
127 outb(0x80, ATIXL_MSE_CONTROL_PORT
); /* Reset the Inport device */
128 outb(0x07, ATIXL_MSE_CONTROL_PORT
); /* Select Internal Register 7 */
129 outb(0x0a, ATIXL_MSE_DATA_PORT
); /* Data Interrupts 8+, 1=30hz, 2=50hz, 3=100hz, 4=200hz rate */
131 msedev
= register_busmouse(&atixlmouse
);
134 printk("Bus mouse initialisation error.\n");
135 release_region(ATIXL_MSE_DATA_PORT
,3); /* Was missing */
138 printk("Bus mouse detected and installed.\n");
139 return msedev
< 0 ? msedev
: 0;
142 static void __exit
atixl_cleanup (void)
144 release_region(ATIXL_MSE_DATA_PORT
, 3);
145 unregister_busmouse(msedev
);
148 module_init(atixl_busmouse_init
);
149 module_exit(atixl_cleanup
);