Commit 9acb0b42 authored by Vojtech Pavlik's avatar Vojtech Pavlik

Convert more of input to list.h usage.

parent d3aadf21
/*
* $Id: evdev.c,v 1.48 2002/05/26 14:28:26 jdeneux Exp $
* Event char devices, giving access to raw input device events.
*
* Copyright (c) 1999-2001 Vojtech Pavlik
* Copyright (c) 1999-2002 Vojtech Pavlik
*
* Event char devices, giving access to raw input device events.
*/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Should you need to contact me, the author, you can do so either by
* e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#define EVDEV_MINOR_BASE 64
......@@ -38,7 +20,7 @@
#include <linux/smp_lock.h>
#include <linux/device.h>
struct evdev {
struct evdev{
int exist;
int open;
int minor;
......@@ -46,7 +28,7 @@ struct evdev {
struct input_handle handle;
wait_queue_head_t wait;
devfs_handle_t devfs;
struct evdev_list *list;
struct list_head list;
};
struct evdev_list {
......@@ -55,17 +37,17 @@ struct evdev_list {
int tail;
struct fasync_struct *fasync;
struct evdev *evdev;
struct evdev_list *next;
struct list_head node;
};
static struct evdev *evdev_table[EVDEV_MINORS] = { NULL, /* ... */ };
static struct evdev *evdev_table[EVDEV_MINORS];
static void evdev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
{
struct evdev *evdev = handle->private;
struct evdev_list *list = evdev->list;
struct evdev_list *list;
while (list) {
list_for_each_entry(list, &evdev->list, node) {
do_gettimeofday(&list->buffer[list->head].time);
list->buffer[list->head].type = type;
......@@ -74,8 +56,6 @@ static void evdev_event(struct input_handle *handle, unsigned int type, unsigned
list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1);
kill_fasync(&list->fasync, SIGIO, POLL_IN);
list = list->next;
}
wake_up_interruptible(&evdev->wait);
......@@ -91,7 +71,7 @@ static int evdev_fasync(int fd, struct file *file, int on)
static int evdev_flush(struct file * file)
{
struct evdev_list *list = (struct evdev_list*)file->private_data;
struct evdev_list *list = file->private_data;
if (!list->evdev->exist) return -ENODEV;
return input_flush_device(&list->evdev->handle, file);
}
......@@ -99,14 +79,9 @@ static int evdev_flush(struct file * file)
static int evdev_release(struct inode * inode, struct file * file)
{
struct evdev_list *list = file->private_data;
struct evdev_list **listptr;
listptr = &list->evdev->list;
evdev_fasync(-1, file, 0);
while (*listptr && (*listptr != list))
listptr = &((*listptr)->next);
*listptr = (*listptr)->next;
list_del(&list->node);
if (!--list->evdev->open) {
if (list->evdev->exist) {
......@@ -132,19 +107,15 @@ static int evdev_open(struct inode * inode, struct file * file)
if (i >= EVDEV_MINORS || !evdev_table[i])
return -ENODEV;
/* Ask the driver if he wishes to accept the open() */
if ((accept_err = input_accept_process(&(evdev_table[i]->handle), file))) {
if ((accept_err = input_accept_process(&(evdev_table[i]->handle), file)))
return accept_err;
}
if (!(list = kmalloc(sizeof(struct evdev_list), GFP_KERNEL)))
return -ENOMEM;
memset(list, 0, sizeof(struct evdev_list));
list->evdev = evdev_table[i];
list->next = evdev_table[i]->list;
evdev_table[i]->list = list;
list_add_tail(&list->node, &evdev_table[i]->list);
file->private_data = list;
if (!list->evdev->open++)
......@@ -175,40 +146,21 @@ static ssize_t evdev_write(struct file * file, const char * buffer, size_t count
static ssize_t evdev_read(struct file * file, char * buffer, size_t count, loff_t *ppos)
{
DECLARE_WAITQUEUE(wait, current);
struct evdev_list *list = file->private_data;
int retval = 0;
if (list->head == list->tail) {
add_wait_queue(&list->evdev->wait, &wait);
set_current_state(TASK_INTERRUPTIBLE);
while (list->head == list->tail) {
int retval;
if (!list->evdev->exist) {
retval = -ENODEV;
break;
}
if (file->f_flags & O_NONBLOCK) {
retval = -EAGAIN;
break;
}
if (signal_pending(current)) {
retval = -ERESTARTSYS;
break;
}
if (list->head == list->tail && list->evdev->exist && (file->f_flags & O_NONBLOCK))
return -EAGAIN;
schedule();
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&list->evdev->wait, &wait);
}
retval = wait_event_interruptible(list->evdev->wait,
list->head != list->tail && list->evdev->exist);
if (retval)
return retval;
if (!list->evdev->exist)
return -ENODEV;
while (list->head != list->tail && retval + sizeof(struct input_event) <= count) {
if (copy_to_user(buffer + retval, list->buffer + list->tail,
sizeof(struct input_event))) return -EFAULT;
......@@ -433,22 +385,20 @@ static struct input_handle *evdev_connect(struct input_handler *handler, struct
return NULL;
memset(evdev, 0, sizeof(struct evdev));
INIT_LIST_HEAD(&evdev->list);
init_waitqueue_head(&evdev->wait);
evdev->exist = 1;
evdev->minor = minor;
evdev_table[minor] = evdev;
sprintf(evdev->name, "event%d", minor);
evdev->handle.dev = dev;
evdev->handle.name = evdev->name;
evdev->handle.handler = handler;
evdev->handle.private = evdev;
sprintf(evdev->name, "event%d", minor);
evdev_table[minor] = evdev;
evdev->devfs = input_register_minor("event%d", minor, EVDEV_MINOR_BASE);
evdev->exist = 1;
return &evdev->handle;
}
......
......@@ -44,7 +44,6 @@ MODULE_LICENSE("GPL");
struct emu {
struct pci_dev *dev;
struct emu *next;
struct gameport gameport;
int size;
char phys[32];
......
......@@ -53,13 +53,13 @@ struct ns558 {
int type;
int size;
struct pci_dev *dev;
struct ns558 *next;
struct list_head node;
struct gameport gameport;
char phys[32];
char name[32];
};
static struct ns558 *ns558;
static LIST_HEAD(ns558_list);
/*
* ns558_isa_probe() tries to find an isa gameport at the
......@@ -67,7 +67,7 @@ static struct ns558 *ns558;
* A joystick must be attached for this to work.
*/
static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
static void ns558_isa_probe(int io)
{
int i, j, b;
unsigned char c, u, v;
......@@ -78,7 +78,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
*/
if (check_region(io, 1))
return next;
return;
/*
* We must not be able to write arbitrary values to the port.
......@@ -89,7 +89,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
outb(~c & ~3, io);
if (~(u = v = inb(io)) & 3) {
outb(c, io);
return next;
return;
}
/*
* After a trigger, there must be at least some bits changing.
......@@ -99,7 +99,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
if (u == v) {
outb(c, io);
return next;
return;
}
wait_ms(3);
/*
......@@ -110,7 +110,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
for (i = 0; i < 1000; i++)
if ((u ^ inb(io)) & 0xf) {
outb(c, io);
return next;
return;
}
/*
* And now find the number of mirrors of the port.
......@@ -134,11 +134,10 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
if (!(port = kmalloc(sizeof(struct ns558), GFP_KERNEL))) {
printk(KERN_ERR "ns558: Memory allocation failed.\n");
return next;
return;
}
memset(port, 0, sizeof(struct ns558));
port->next = next;
port->type = NS558_ISA;
port->size = (1 << i);
port->gameport.io = io & (-1 << i);
......@@ -157,7 +156,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
if (port->size > 1) printk(" size %d", port->size);
printk(" speed %d kHz\n", port->gameport.speed);
return port;
list_add(&port->node, &ns558_list);
}
#ifdef __ISAPNP__
......@@ -194,22 +193,22 @@ static struct isapnp_device_id pnp_devids[] = {
MODULE_DEVICE_TABLE(isapnp, pnp_devids);
static struct ns558* ns558_pnp_probe(struct pci_dev *dev, struct ns558 *next)
static void ns558_pnp_probe(struct pci_dev *dev)
{
int ioport, iolen;
struct ns558 *port;
if (dev->prepare && dev->prepare(dev) < 0)
return next;
return;
if (!(dev->resource[0].flags & IORESOURCE_IO)) {
printk(KERN_WARNING "ns558: No i/o ports on a gameport? Weird\n");
return next;
return;
}
if (dev->activate && dev->activate(dev) < 0) {
printk(KERN_ERR "ns558: PnP resource allocation failed\n");
return next;
return;
}
ioport = pci_resource_start(dev, 0);
......@@ -224,7 +223,6 @@ static struct ns558* ns558_pnp_probe(struct pci_dev *dev, struct ns558 *next)
}
memset(port, 0, sizeof(struct ns558));
port->next = next;
port->type = NS558_PNP;
port->size = iolen;
port->dev = dev;
......@@ -247,12 +245,12 @@ static struct ns558* ns558_pnp_probe(struct pci_dev *dev, struct ns558 *next)
if (iolen > 1) printk(" size %d", iolen);
printk(" speed %d kHz\n", port->gameport.speed);
return port;
list_add_tail(&port->node, &ns558_list);
return;
deactivate:
if (dev->deactivate)
dev->deactivate(dev);
return next;
}
#endif
......@@ -269,28 +267,26 @@ int __init ns558_init(void)
*/
while (ns558_isa_portlist[i])
ns558 = ns558_isa_probe(ns558_isa_portlist[i++], ns558);
ns558_isa_probe(ns558_isa_portlist[i++]);
/*
* Probe for PnP ports.
*/
#ifdef __ISAPNP__
for (devid = pnp_devids; devid->vendor; devid++) {
while ((dev = isapnp_find_dev(NULL, devid->vendor, devid->function, dev))) {
ns558 = ns558_pnp_probe(dev, ns558);
}
}
for (devid = pnp_devids; devid->vendor; devid++)
while ((dev = isapnp_find_dev(NULL, devid->vendor, devid->function, dev)))
ns558_pnp_probe(dev);
#endif
return ns558 ? 0 : -ENODEV;
return list_empty(&ns558_list) ? -ENODEV : 0;
}
void __exit ns558_exit(void)
{
struct ns558 *next, *port = ns558;
struct ns558 *port;
while (port) {
list_for_each_entry(port, &ns558_list, node) {
gameport_unregister_port(&port->gameport);
switch (port->type) {
......@@ -308,10 +304,6 @@ void __exit ns558_exit(void)
default:
break;
}
next = port->next;
kfree(port);
port = next;
}
}
......
/*
* $Id: joydev.c,v 1.43 2002/04/09 23:59:01 jsimmons Exp $
* Joystick device driver for the input driver suite.
*
* Copyright (c) 1999-2001 Vojtech Pavlik
* Copyright (c) 1999 Colin Van Dyke
* Copyright (c) 1999-2002 Vojtech Pavlik
* Copyright (c) 1999 Colin Van Dyke
*
* Joystick device driver for the input driver suite.
*/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Should you need to contact me, the author, you can do so either by
* e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
*/
#include <asm/io.h>
......@@ -63,8 +46,7 @@ struct joydev {
struct input_handle handle;
wait_queue_head_t wait;
devfs_handle_t devfs;
struct joydev *next;
struct joydev_list *list;
struct list_head list;
struct js_corr corr[ABS_MAX];
struct JS_DATA_SAVE_TYPE glue;
int nabs;
......@@ -83,7 +65,7 @@ struct joydev_list {
int startup;
struct fasync_struct *fasync;
struct joydev *joydev;
struct joydev_list *next;
struct list_head node;
};
static struct joydev *joydev_table[JOYDEV_MINORS];
......@@ -111,7 +93,7 @@ static int joydev_correct(int value, struct js_corr *corr)
static void joydev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
{
struct joydev *joydev = handle->private;
struct joydev_list *list = joydev->list;
struct joydev_list *list;
struct js_event event;
switch (type) {
......@@ -137,7 +119,7 @@ static void joydev_event(struct input_handle *handle, unsigned int type, unsigne
event.time = MSECS(jiffies);
while (list) {
list_for_each_entry(list, &joydev->list, node) {
memcpy(list->buffer + list->head, &event, sizeof(struct js_event));
......@@ -146,8 +128,6 @@ static void joydev_event(struct input_handle *handle, unsigned int type, unsigne
list->startup = 0;
kill_fasync(&list->fasync, SIGIO, POLL_IN);
list = list->next;
}
wake_up_interruptible(&joydev->wait);
......@@ -164,14 +144,10 @@ static int joydev_fasync(int fd, struct file *file, int on)
static int joydev_release(struct inode * inode, struct file * file)
{
struct joydev_list *list = file->private_data;
struct joydev_list **listptr;
listptr = &list->joydev->list;
joydev_fasync(-1, file, 0);
while (*listptr && (*listptr != list))
listptr = &((*listptr)->next);
*listptr = (*listptr)->next;
list_del(&list->node);
if (!--list->joydev->open) {
if (list->joydev->exist) {
......@@ -201,9 +177,7 @@ static int joydev_open(struct inode *inode, struct file *file)
memset(list, 0, sizeof(struct joydev_list));
list->joydev = joydev_table[i];
list->next = joydev_table[i]->list;
joydev_table[i]->list = list;
list_add_tail(&list->node, &joydev_table[i]->list);
file->private_data = list;
if (!list->joydev->open++)
......@@ -220,12 +194,14 @@ static ssize_t joydev_write(struct file * file, const char * buffer, size_t coun
static ssize_t joydev_read(struct file *file, char *buf, size_t count, loff_t *ppos)
{
DECLARE_WAITQUEUE(wait, current);
struct joydev_list *list = file->private_data;
struct joydev *joydev = list->joydev;
struct input_dev *input = joydev->handle.dev;
int retval = 0;
if (!list->joydev->exist)
return -ENODEV;
if (count < sizeof(struct js_event))
return -EINVAL;
......@@ -248,36 +224,19 @@ static ssize_t joydev_read(struct file *file, char *buf, size_t count, loff_t *p
return sizeof(struct JS_DATA_TYPE);
}
if (list->head == list->tail && list->startup == joydev->nabs + joydev->nkey) {
add_wait_queue(&list->joydev->wait, &wait);
set_current_state(TASK_INTERRUPTIBLE);
if (list->startup == joydev->nabs + joydev->nkey
&& list->head == list->tail && (file->f_flags & O_NONBLOCK))
return -EAGAIN;
while (list->head == list->tail) {
if (!joydev->exist) {
retval = -ENODEV;
break;
}
if (file->f_flags & O_NONBLOCK) {
retval = -EAGAIN;
break;
}
if (signal_pending(current)) {
retval = -ERESTARTSYS;
break;
}
schedule();
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&list->joydev->wait, &wait);
}
retval = wait_event_interruptible(list->joydev->wait, list->joydev->exist
&& (list->startup < joydev->nabs + joydev->nkey || list->head != list->tail));
if (retval)
return retval;
if (!list->joydev->exist)
return -ENODEV;
while (list->startup < joydev->nabs + joydev->nkey && retval + sizeof(struct js_event) <= count) {
struct js_event event;
......@@ -431,17 +390,16 @@ static struct input_handle *joydev_connect(struct input_handler *handler, struct
return NULL;
memset(joydev, 0, sizeof(struct joydev));
INIT_LIST_HEAD(&joydev->list);
init_waitqueue_head(&joydev->wait);
joydev->minor = minor;
joydev_table[minor] = joydev;
sprintf(joydev->name, "js%d", minor);
joydev->exist = 1;
joydev->handle.dev = dev;
joydev->handle.name = joydev->name;
joydev->handle.handler = handler;
joydev->handle.private = joydev;
sprintf(joydev->name, "js%d", minor);
for (i = 0; i < ABS_MAX; i++)
if (test_bit(i, dev->absbit)) {
......@@ -482,10 +440,9 @@ static struct input_handle *joydev_connect(struct input_handler *handler, struct
joydev->abs[i] = joydev_correct(dev->abs[j], joydev->corr + i);
}
joydev_table[minor] = joydev;
joydev->devfs = input_register_minor("js%d", minor, JOYDEV_MINOR_BASE);
joydev->exist = 1;
return &joydev->handle;
}
......
/*
* $Id: mousedev.c,v 1.42 2002/04/09 20:51:26 jdeneux Exp $
* Input driver to ExplorerPS/2 device driver module.
*
* Copyright (c) 1999-2001 Vojtech Pavlik
* Copyright (c) 1999-2002 Vojtech Pavlik
*
* Input driver to ExplorerPS/2 device driver module.
*/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Should you need to contact me, the author, you can do so either by
* e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
* it under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#define MOUSEDEV_MINOR_BASE 32
......@@ -61,7 +43,7 @@ struct mousedev {
int minor;
char name[16];
wait_queue_head_t wait;
struct mousedev_list *list;
struct list_head list;
struct input_handle handle;
devfs_handle_t devfs;
};
......@@ -69,7 +51,7 @@ struct mousedev {
struct mousedev_list {
struct fasync_struct *fasync;
struct mousedev *mousedev;
struct mousedev_list *next;
struct list_head node;
int dx, dy, dz, oldx, oldy;
signed char ps2[6];
unsigned long buttons;
......@@ -98,9 +80,10 @@ static void mousedev_event(struct input_handle *handle, unsigned int type, unsig
int index, size, wake;
while (*mousedev) {
wake = 0;
list = (*mousedev)->list;
while (list) {
list_for_each_entry(list, &(*mousedev)->list, node)
switch (type) {
case EV_ABS:
if (test_bit(BTN_TRIGGER, handle->dev->keybit))
......@@ -116,6 +99,7 @@ static void mousedev_event(struct input_handle *handle, unsigned int type, unsig
list->oldx += list->dx;
}
break;
case ABS_Y:
size = handle->dev->absmax[ABS_Y] - handle->dev->absmin[ABS_Y];
if (size != 0) {
......@@ -170,10 +154,10 @@ static void mousedev_event(struct input_handle *handle, unsigned int type, unsig
break;
}
}
list = list->next;
}
if (wake)
wake_up_interruptible(&((*mousedev)->wait));
mousedev++;
}
}
......@@ -189,21 +173,17 @@ static int mousedev_fasync(int fd, struct file *file, int on)
static int mousedev_release(struct inode * inode, struct file * file)
{
struct mousedev_list *list = file->private_data;
struct mousedev_list **listptr;
struct input_handle *handle;
struct mousedev *mousedev;
listptr = &list->mousedev->list;
mousedev_fasync(-1, file, 0);
while (*listptr && (*listptr != list))
listptr = &((*listptr)->next);
*listptr = (*listptr)->next;
list_del(&list->node);
if (!--list->mousedev->open) {
if (list->mousedev->minor == MOUSEDEV_MIX) {
struct list_head * node;
list_for_each(node,&mousedev_handler.h_list) {
struct input_handle *handle = to_handle_h(node);
struct mousedev *mousedev = handle->private;
list_for_each_entry(handle, &mousedev_handler.h_list, h_node) {
mousedev = handle->private;
if (!mousedev->open) {
if (mousedev->exist) {
input_close_device(&mousedev->handle);
......@@ -252,8 +232,7 @@ static int mousedev_open(struct inode * inode, struct file * file)
memset(list, 0, sizeof(struct mousedev_list));
list->mousedev = mousedev_table[i];
list->next = mousedev_table[i]->list;
mousedev_table[i]->list = list;
list_add_tail(&list->node, &mousedev_table[i]->list);
file->private_data = list;
if (!list->mousedev->open++) {
......@@ -373,35 +352,13 @@ static ssize_t mousedev_write(struct file * file, const char * buffer, size_t co
static ssize_t mousedev_read(struct file * file, char * buffer, size_t count, loff_t *ppos)
{
DECLARE_WAITQUEUE(wait, current);
struct mousedev_list *list = file->private_data;
int retval = 0;
if (!list->ready && !list->buffer) {
if (!list->ready && !list->buffer && (file->f_flags & O_NONBLOCK))
return -EAGAIN;
add_wait_queue(&list->mousedev->wait, &wait);
for (;;) {
set_current_state(TASK_INTERRUPTIBLE);
retval = 0;
if (list->ready || list->buffer)
break;
retval = -EAGAIN;
if (file->f_flags & O_NONBLOCK)
break;
retval = -ERESTARTSYS;
if (signal_pending(current))
break;
schedule();
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&list->mousedev->wait, &wait);
}
retval = wait_event_interruptible(list->mousedev->wait, list->ready || list->buffer);
if (retval)
return retval;
......@@ -454,23 +411,23 @@ static struct input_handle *mousedev_connect(struct input_handler *handler, stru
if (!(mousedev = kmalloc(sizeof(struct mousedev), GFP_KERNEL)))
return NULL;
memset(mousedev, 0, sizeof(struct mousedev));
INIT_LIST_HEAD(&mousedev->list);
init_waitqueue_head(&mousedev->wait);
mousedev->minor = minor;
mousedev_table[minor] = mousedev;
sprintf(mousedev->name, "mouse%d", minor);
mousedev->exist = 1;
mousedev->handle.dev = dev;
mousedev->handle.name = mousedev->name;
mousedev->handle.handler = handler;
mousedev->handle.private = mousedev;
mousedev->devfs = input_register_minor("mouse%d", minor, MOUSEDEV_MINOR_BASE);
sprintf(mousedev->name, "mouse%d", minor);
if (mousedev_mix.open)
input_open_device(&mousedev->handle);
mousedev->exist = 1;
mousedev_table[minor] = mousedev;
mousedev->devfs = input_register_minor("mouse%d", minor, MOUSEDEV_MINOR_BASE);
return &mousedev->handle;
}
......
......@@ -55,7 +55,7 @@ struct tsdev {
int minor;
char name[16];
wait_queue_head_t wait;
struct tsdev_list *list;
struct list_head list;
struct input_handle handle;
devfs_handle_t devfs;
};
......@@ -70,7 +70,7 @@ typedef struct {
struct tsdev_list {
struct fasync_struct *fasync;
struct tsdev_list *next;
struct list_head node;
struct tsdev *tsdev;
int head, tail;
int oldx, oldy, pendown;
......@@ -106,8 +106,7 @@ static int tsdev_open(struct inode *inode, struct file *file)
memset(list, 0, sizeof(struct tsdev_list));
list->tsdev = tsdev_table[i];
list->next = tsdev_table[i]->list;
tsdev_table[i]->list = list;
list_add_tail(&list->node, &tsdev_table[i]->list);
file->private_data = list;
if (!list->tsdev->open++)
......@@ -119,14 +118,9 @@ static int tsdev_open(struct inode *inode, struct file *file)
static int tsdev_release(struct inode *inode, struct file *file)
{
struct tsdev_list *list = file->private_data;
struct tsdev_list **listptr;
listptr = &list->tsdev->list;
tsdev_fasync(-1, file, 0);
while (*listptr && (*listptr != list))
listptr = &((*listptr)->next);
*listptr = (*listptr)->next;
list_del(&list->node);
if (!--list->tsdev->open) {
if (list->tsdev->exist) {
......@@ -144,45 +138,28 @@ static int tsdev_release(struct inode *inode, struct file *file)
static ssize_t tsdev_read(struct file *file, char *buffer, size_t count,
loff_t * ppos)
{
DECLARE_WAITQUEUE(wait, current);
struct tsdev_list *list = file->private_data;
int retval = 0;
if (list->head == list->tail) {
add_wait_queue(&list->tsdev->wait, &wait);
set_current_state(TASK_INTERRUPTIBLE);
if (list->head == list->tail && list->tsdev->exist && (file->f_flags & O_NONBLOCK))
return -EAGAIN;
while (list->head == list->tail) {
if (!list->tsdev->exist) {
retval = -ENODEV;
break;
}
if (file->f_flags & O_NONBLOCK) {
retval = -EAGAIN;
break;
}
if (signal_pending(current)) {
retval = -ERESTARTSYS;
break;
}
schedule();
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&list->tsdev->wait, &wait);
}
retval = wait_event_interruptible(list->tsdev->wait,
(list->head != list->tail) && list->tsdev->exist);
if (retval)
return retval;
while (list->head != list->tail
&& retval + sizeof(TS_EVENT) <= count) {
if (copy_to_user
(buffer + retval, list->event + list->tail,
sizeof(TS_EVENT)))
if (!list->tsdev->exist)
return -ENODEV;
while (list->head != list->tail && retval + sizeof(TS_EVENT) <= count) {
if (copy_to_user (buffer + retval, list->event + list->tail, sizeof(TS_EVENT)))
return -EFAULT;
list->tail = (list->tail + 1) & (TSDEV_BUFFER_SIZE - 1);
retval += sizeof(TS_EVENT);
}
return retval;
}
......@@ -232,54 +209,35 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
unsigned int code, int value)
{
struct tsdev *tsdev = handle->private;
struct tsdev_list *list = tsdev->list;
struct tsdev_list *list;
struct timeval time;
int size;
while (list) {
list_for_each_entry(list, &tsdev->list, node) {
switch (type) {
case EV_ABS:
switch (code) {
case ABS_X:
if (!list->pendown)
return;
size =
handle->dev->absmax[ABS_X] -
handle->dev->absmin[ABS_X];
size = handle->dev->absmax[ABS_X] - handle->dev->absmin[ABS_X];
if (size > 0)
list->oldx =
((value -
handle->dev->absmin[ABS_X]) *
xres / size);
list->oldx = ((value - handle->dev->absmin[ABS_X]) * xres / size);
else
list->oldx =
((value -
handle->dev->absmin[ABS_X]));
list->oldx = ((value - handle->dev->absmin[ABS_X]));
break;
case ABS_Y:
if (!list->pendown)
return;
size =
handle->dev->absmax[ABS_Y] -
handle->dev->absmin[ABS_Y];
size = handle->dev->absmax[ABS_Y] - handle->dev->absmin[ABS_Y];
if (size > 0)
list->oldy =
((value -
handle->dev->absmin[ABS_Y]) *
yres / size);
list->oldy = ((value - handle->dev->absmin[ABS_Y]) * yres / size);
else
list->oldy =
((value -
handle->dev->absmin[ABS_Y]));
list->oldy = ((value - handle->dev->absmin[ABS_Y]));
break;
case ABS_PRESSURE:
list->pendown =
((value >
handle->dev->
absmin[ABS_PRESSURE])) ? value -
handle->dev->absmin[ABS_PRESSURE] : 0;
list->pendown = ((value > handle->dev-> absmin[ABS_PRESSURE])) ?
value - handle->dev->absmin[ABS_PRESSURE] : 0;
break;
}
break;
......@@ -289,7 +247,6 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
case REL_X:
if (!list->pendown)
return;
list->oldx += value;
if (list->oldx < 0)
list->oldx = 0;
......@@ -299,7 +256,6 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
case REL_Y:
if (!list->pendown)
return;
list->oldy += value;
if (list->oldy < 0)
list->oldy = 0;
......@@ -333,7 +289,6 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
list->event[list->head].y = list->oldy;
list->head = (list->head + 1) & (TSDEV_BUFFER_SIZE - 1);
kill_fasync(&list->fasync, SIGIO, POLL_IN);
list = list->next;
}
wake_up_interruptible(&tsdev->wait);
}
......@@ -356,21 +311,23 @@ static struct input_handle *tsdev_connect(struct input_handler *handler,
if (!(tsdev = kmalloc(sizeof(struct tsdev), GFP_KERNEL)))
return NULL;
memset(tsdev, 0, sizeof(struct tsdev));
INIT_LIST_HEAD(&tsdev->list);
init_waitqueue_head(&tsdev->wait);
tsdev->minor = minor;
tsdev_table[minor] = tsdev;
sprintf(tsdev->name, "ts%d", minor);
tsdev->exist = 1;
tsdev->minor = minor;
tsdev->handle.dev = dev;
tsdev->handle.name = tsdev->name;
tsdev->handle.handler = handler;
tsdev->handle.private = tsdev;
tsdev_table[minor] = tsdev;
tsdev->devfs =
input_register_minor("ts%d", minor, TSDEV_MINOR_BASE);
tsdev->exist = 1;
return &tsdev->handle;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment