OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [char/] [atarimouse.c] - Blame information for rev 1626

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 * Atari Mouse Driver for Linux
3
 * by Robert de Vries (robert@and.nl) 19Jul93
4
 *
5
 * 16 Nov 1994 Andreas Schwab
6
 * Compatibility with busmouse
7
 * Support for three button mouse (shamelessly stolen from MiNT)
8
 * third button wired to one of the joystick directions on joystick 1
9
 *
10
 * 1996/02/11 Andreas Schwab
11
 * Module support
12
 * Allow multiple open's
13
 */
14
 
15
#include <linux/module.h>
16
 
17
#include <linux/sched.h>
18
#include <linux/errno.h>
19
#include <linux/miscdevice.h>
20
#include <linux/mm.h>
21
#include <linux/random.h>
22
 
23
#include <asm/atarikb.h>
24
#include <asm/atari_mouse.h>
25
#include <asm/segment.h>
26
#include <asm/bootinfo.h>
27
 
28
static struct mouse_status mouse;
29
static int atari_mouse_x_threshold = 2, atari_mouse_y_threshold = 2;
30
extern int atari_mouse_buttons;
31
 
32
static void atari_mouse_interrupt(char *buf)
33
{
34
    int buttons;
35
 
36
/*    ikbd_mouse_disable(); */
37
 
38
    buttons = ((buf[0] & 1 ? 1 : 0)
39
               | (buf[0] & 2 ? 4 : 0)
40
               | (atari_mouse_buttons & 2));
41
    atari_mouse_buttons = buttons;
42
    add_mouse_randomness((buttons << 16) + (buf[2] << 8) + buf[1]);
43
    mouse.buttons = ~buttons & 7;
44
    mouse.dx += buf[1];
45
    mouse.dy -= buf[2];
46
    mouse.ready = 1;
47
    wake_up_interruptible(&mouse.wait);
48
    if (mouse.fasyncptr)
49
        kill_fasync(mouse.fasyncptr, SIGIO);
50
 
51
/*    ikbd_mouse_rel_pos(); */
52
}
53
 
54
static int fasync_mouse(struct inode *inode, struct file *filp, int on)
55
{
56
        int retval;
57
 
58
        retval = fasync_helper(inode, filp, on, &mouse.fasyncptr);
59
        if (retval < 0)
60
                return retval;
61
        return 0;
62
}
63
 
64
static void release_mouse(struct inode *inode, struct file *file)
65
{
66
    fasync_mouse(inode, file, 0);
67
    if (--mouse.active)
68
      return;
69
    ikbd_mouse_disable();
70
 
71
    atari_mouse_interrupt_hook = NULL;
72
    MOD_DEC_USE_COUNT;
73
}
74
 
75
static int open_mouse(struct inode *inode, struct file *file)
76
{
77
    if (mouse.active++)
78
        return 0;
79
    mouse.ready = 0;
80
    mouse.dx = mouse.dy = 0;
81
    atari_mouse_buttons = 0;
82
    ikbd_mouse_y0_top ();
83
    ikbd_mouse_thresh (atari_mouse_x_threshold, atari_mouse_y_threshold);
84
    ikbd_mouse_rel_pos();
85
    MOD_INC_USE_COUNT;
86
    atari_mouse_interrupt_hook = atari_mouse_interrupt;
87
    return 0;
88
}
89
 
90
static int write_mouse(struct inode *inode, struct file *file, const char *buffer, int count)
91
{
92
    return -EINVAL;
93
}
94
 
95
static int read_mouse(struct inode *inode, struct file *file, char *buffer, int count)
96
{
97
    int dx, dy, buttons;
98
    int r;
99
 
100
    if (count < 3)
101
        return -EINVAL;
102
    if ((r = verify_area(VERIFY_WRITE, buffer, count)))
103
        return r;
104
    if (!mouse.ready)
105
        return -EAGAIN;
106
    /* ikbd_mouse_disable */
107
    dx = mouse.dx;
108
    dy = mouse.dy;
109
    buttons = mouse.buttons;
110
    if (dx > 127)
111
      dx = 127;
112
    else if (dx < -128)
113
      dx = -128;
114
    if (dy > 127)
115
      dy = 127;
116
    else if (dy < -128)
117
      dy = -128;
118
    mouse.dx -= dx;
119
    mouse.dy -= dy;
120
    if (mouse.dx == 0 && mouse.dy == 0)
121
      mouse.ready = 0;
122
    /* ikbd_mouse_rel_pos(); */
123
    put_user(buttons | 0x80, buffer);
124
    put_user((char) dx, buffer + 1);
125
    put_user((char) dy, buffer + 2);
126
    for (r = 3; r < count; r++)
127
      put_user (0, buffer + r);
128
    return r;
129
}
130
 
131
static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table *wait)
132
{
133
        if (sel_type == SEL_IN) {
134
                if (mouse.ready)
135
                        return 1;
136
                select_wait(&mouse.wait, wait);
137
        }
138
        return 0;
139
}
140
 
141
struct file_operations atari_mouse_fops = {
142
    NULL,               /* mouse_seek */
143
    read_mouse,
144
    write_mouse,
145
    NULL,               /* mouse_readdir */
146
    mouse_select,
147
    NULL,               /* mouse_ioctl */
148
    NULL,               /* mouse_mmap */
149
    open_mouse,
150
    release_mouse,
151
    NULL,
152
    fasync_mouse,
153
};
154
 
155
static struct miscdevice atari_mouse = {
156
    ATARIMOUSE_MINOR, "atarimouse", &atari_mouse_fops
157
};
158
 
159
int atari_mouse_init(void)
160
{
161
    mouse.active = 0;
162
    mouse.ready = 0;
163
    mouse.wait = NULL;
164
 
165
    if (!MACH_IS_ATARI)
166
        return -ENODEV;
167
    printk(KERN_INFO "Atari mouse installed.\n");
168
    misc_register(&atari_mouse);
169
    return 0;
170
}
171
 
172
 
173
#define MIN_THRESHOLD 1
174
#define MAX_THRESHOLD 20        /* more seems not reasonable... */
175
 
176
void atari_mouse_setup( char *str, int *ints )
177
{
178
    if (ints[0] < 1) {
179
        printk( "atari_mouse_setup: no arguments!\n" );
180
        return;
181
    }
182
    else if (ints[0] > 2) {
183
        printk( "atari_mouse_setup: too many arguments\n" );
184
    }
185
 
186
    if (ints[1] < MIN_THRESHOLD || ints[1] > MAX_THRESHOLD)
187
        printk( "atari_mouse_setup: bad threshold value (ignored)\n" );
188
    else {
189
        atari_mouse_x_threshold = ints[1];
190
        atari_mouse_y_threshold = ints[1];
191
        if (ints[0] > 1) {
192
            if (ints[2] < MIN_THRESHOLD || ints[2] > MAX_THRESHOLD)
193
                printk("atari_mouse_setup: bad threshold value (ignored)\n" );
194
            else
195
                atari_mouse_y_threshold = ints[2];
196
        }
197
    }
198
 
199
}
200
 
201
#ifdef MODULE
202
#include <asm/bootinfo.h>
203
 
204
int init_module(void)
205
{
206
        return atari_mouse_init();
207
}
208
 
209
void cleanup_module(void)
210
{
211
  misc_deregister(&atari_mouse);
212
}
213
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.