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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [armnommu/] [drivers/] [char/] [mouse.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1622 jcastillo
/*
2
 * linux/arch/arm/drivers/char/mouse.c
3
 *
4
 * Copyright (C) 1995, 1996 Russell King
5
 *
6
 * Medium-level interface for quadrature mouse.
7
 */
8
 
9
#include <linux/module.h>
10
#include <linux/config.h>
11
#include <linux/kernel.h>
12
#include <linux/sched.h>
13
#include <linux/signal.h>
14
#include <linux/errno.h>
15
#include <linux/mm.h>
16
#include <linux/miscdevice.h>
17
#include <linux/random.h>
18
 
19
#include <asm/system.h>
20
#include <asm/segment.h>
21
#include <asm/io.h>
22
 
23
#include "mouse.h"
24
 
25
#ifdef CONFIG_RPCMOUSE
26
extern void mouse_rpc_init (void);
27
#endif
28
 
29
static struct wait_queue *mouse_wait;
30
static struct fasync_struct *fasyncptr;
31
static char mouse_active;
32
static char mouse_buttons;
33
static char mouse_ready;
34
static int mouse_present;
35
static int mouse_dxpos;
36
static int mouse_dypos;
37
 
38
/*
39
 * a mouse driver just has to interface with these functions
40
 */
41
void add_mouse_movement(int dx, int dy)
42
{
43
        mouse_dxpos += dx;
44
        mouse_dypos += dy;
45
        mouse_ready = 1;
46
        wake_up(&mouse_wait);
47
 
48
}
49
 
50
int add_mouse_buttonchange(int set, int value)
51
{
52
        mouse_buttons = (mouse_buttons & ~set) ^ value;
53
        mouse_ready = 1;
54
        wake_up(&mouse_wait);
55
        return mouse_buttons;
56
}
57
 
58
static int fasync_mouse(struct inode *inode, struct file *filp, int on)
59
{
60
        int retval;
61
 
62
        retval = fasync_helper(inode, filp, on, &fasyncptr);
63
        if (retval < 0)
64
                return retval;
65
        return 0;
66
}
67
 
68
static void close_mouse(struct inode *inode, struct file *file)
69
{
70
        fasync_mouse (inode, file, 0);
71
        if (--mouse_active)
72
                return;
73
        mouse_ready = 0;
74
 
75
        MOD_DEC_USE_COUNT;
76
}
77
 
78
static int open_mouse(struct inode *inode,struct file *file)
79
{
80
        unsigned long flags;
81
 
82
        if (!mouse_present)
83
                return -EINVAL;
84
 
85
        if (mouse_active++)
86
                return 0;
87
 
88
        MOD_INC_USE_COUNT;
89
 
90
        save_flags_cli (flags);
91
        mouse_active  = 1;
92
        mouse_ready   = 0;
93
        mouse_dxpos   = 0;
94
        mouse_dypos   = 0;
95
        mouse_buttons = 7;
96
        restore_flags (flags);
97
 
98
        return 0;
99
}
100
 
101
static int write_mouse(struct inode *inode,struct file *file,const char *buffer,int count)
102
{
103
        return -EINVAL;
104
}
105
 
106
static int read_mouse(struct inode *inode,struct file *file,char *buffer,int count)
107
{
108
        unsigned long flags;
109
        int dxpos, dypos, i, buttons;
110
 
111
        if (count < 3)
112
                return -EINVAL;
113
        if ((i = verify_area(VERIFY_WRITE, buffer, count)))
114
                return i;
115
        if (!mouse_ready)
116
                return -EAGAIN;
117
 
118
        save_flags_cli (flags);
119
 
120
        dxpos = mouse_dxpos;
121
        dypos = mouse_dypos;
122
        buttons = mouse_buttons;
123
 
124
        if (dxpos < -127)
125
                dxpos =- 127;
126
        if (dxpos > 127)
127
                dxpos = 127;
128
        if (dypos < -127)
129
                dypos =- 127;
130
        if (dypos > 127)
131
                dypos = 127;
132
 
133
        mouse_dxpos -= dxpos;
134
        mouse_dypos -= dypos;
135
        mouse_ready = 0;
136
 
137
        restore_flags (flags);
138
 
139
        put_user ((char) buttons | 128, buffer);
140
        put_user ((char) dxpos, buffer + 1);
141
        put_user ((char) dypos, buffer + 2);
142
        for(i = 3; i < count; i++)
143
                put_user (0, buffer + i);
144
        return i;
145
}
146
 
147
static int select_mouse(struct inode *inode,struct file *file,int sel_type,select_table *wait)
148
{
149
        if (sel_type == SEL_IN) {
150
                if (mouse_ready)
151
                        return 1;
152
                select_wait (&mouse_wait,wait);
153
        }
154
        return 0;
155
}
156
 
157
struct file_operations kbd_mouse_fops=
158
{
159
        NULL,                   /* mouse_seek */
160
        read_mouse,
161
        write_mouse,
162
        NULL,                   /* mouse_readdir */
163
        select_mouse,
164
        NULL,                   /* mouse_ioctl */
165
        NULL,                   /* mouse_mmap */
166
        open_mouse,
167
        close_mouse,
168
        NULL,
169
        fasync_mouse,
170
};
171
 
172
static struct miscdevice mouse_misc = {
173
        6, "mouse", &kbd_mouse_fops, NULL, NULL
174
};
175
 
176
int misc_mouse_init(void)
177
{
178
        unsigned long flags;
179
 
180
        save_flags_cli (flags);
181
 
182
        mouse_buttons = 0;
183
        mouse_dxpos   = 0;
184
        mouse_dypos   = 0;
185
        mouse_present = 1;
186
        mouse_ready   = 0;
187
        mouse_active  = 0;
188
        mouse_wait    = NULL;
189
 
190
        restore_flags (flags);
191
        misc_register (&mouse_misc);
192
 
193
#ifdef CONFIG_RPCMOUSE
194
        mouse_rpc_init();
195
#endif
196
        return 0;
197
}
198
 
199
#ifdef MODULE
200
int init_module(void)
201
{
202
        return misc_mouse_init();
203
}
204
 
205
void cleanup_module(void)
206
{
207
        misc_deregister (&mouse_misc);
208
}
209
#endif

powered by: WebSVN 2.1.0

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