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 version 2 as published by
* the Free Software Foundation.
/*
* 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
*/ */
#define EVDEV_MINOR_BASE 64 #define EVDEV_MINOR_BASE 64
...@@ -38,7 +20,7 @@ ...@@ -38,7 +20,7 @@
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/device.h> #include <linux/device.h>
struct evdev { struct evdev{
int exist; int exist;
int open; int open;
int minor; int minor;
...@@ -46,7 +28,7 @@ struct evdev { ...@@ -46,7 +28,7 @@ struct evdev {
struct input_handle handle; struct input_handle handle;
wait_queue_head_t wait; wait_queue_head_t wait;
devfs_handle_t devfs; devfs_handle_t devfs;
struct evdev_list *list; struct list_head list;
}; };
struct evdev_list { struct evdev_list {
...@@ -55,17 +37,17 @@ struct evdev_list { ...@@ -55,17 +37,17 @@ struct evdev_list {
int tail; int tail;
struct fasync_struct *fasync; struct fasync_struct *fasync;
struct evdev *evdev; 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) static void evdev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
{ {
struct evdev *evdev = handle->private; 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); do_gettimeofday(&list->buffer[list->head].time);
list->buffer[list->head].type = type; list->buffer[list->head].type = type;
...@@ -74,8 +56,6 @@ static void evdev_event(struct input_handle *handle, unsigned int type, unsigned ...@@ -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); list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1);
kill_fasync(&list->fasync, SIGIO, POLL_IN); kill_fasync(&list->fasync, SIGIO, POLL_IN);
list = list->next;
} }
wake_up_interruptible(&evdev->wait); wake_up_interruptible(&evdev->wait);
...@@ -91,7 +71,7 @@ static int evdev_fasync(int fd, struct file *file, int on) ...@@ -91,7 +71,7 @@ static int evdev_fasync(int fd, struct file *file, int on)
static int evdev_flush(struct file * file) 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; if (!list->evdev->exist) return -ENODEV;
return input_flush_device(&list->evdev->handle, file); return input_flush_device(&list->evdev->handle, file);
} }
...@@ -99,14 +79,9 @@ static int evdev_flush(struct file * file) ...@@ -99,14 +79,9 @@ static int evdev_flush(struct file * file)
static int evdev_release(struct inode * inode, struct file * file) static int evdev_release(struct inode * inode, struct file * file)
{ {
struct evdev_list *list = file->private_data; struct evdev_list *list = file->private_data;
struct evdev_list **listptr;
listptr = &list->evdev->list;
evdev_fasync(-1, file, 0); evdev_fasync(-1, file, 0);
list_del(&list->node);
while (*listptr && (*listptr != list))
listptr = &((*listptr)->next);
*listptr = (*listptr)->next;
if (!--list->evdev->open) { if (!--list->evdev->open) {
if (list->evdev->exist) { if (list->evdev->exist) {
...@@ -132,19 +107,15 @@ static int evdev_open(struct inode * inode, struct file * file) ...@@ -132,19 +107,15 @@ static int evdev_open(struct inode * inode, struct file * file)
if (i >= EVDEV_MINORS || !evdev_table[i]) if (i >= EVDEV_MINORS || !evdev_table[i])
return -ENODEV; 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; return accept_err;
}
if (!(list = kmalloc(sizeof(struct evdev_list), GFP_KERNEL))) if (!(list = kmalloc(sizeof(struct evdev_list), GFP_KERNEL)))
return -ENOMEM; return -ENOMEM;
memset(list, 0, sizeof(struct evdev_list)); memset(list, 0, sizeof(struct evdev_list));
list->evdev = evdev_table[i]; list->evdev = evdev_table[i];
list->next = evdev_table[i]->list; list_add_tail(&list->node, &evdev_table[i]->list);
evdev_table[i]->list = list;
file->private_data = list; file->private_data = list;
if (!list->evdev->open++) if (!list->evdev->open++)
...@@ -175,40 +146,21 @@ static ssize_t evdev_write(struct file * file, const char * buffer, size_t count ...@@ -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) 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; struct evdev_list *list = file->private_data;
int retval = 0; int retval;
if (list->head == list->tail) {
add_wait_queue(&list->evdev->wait, &wait);
set_current_state(TASK_INTERRUPTIBLE);
while (list->head == list->tail) {
if (!list->evdev->exist) { if (list->head == list->tail && list->evdev->exist && (file->f_flags & O_NONBLOCK))
retval = -ENODEV; return -EAGAIN;
break;
}
if (file->f_flags & O_NONBLOCK) {
retval = -EAGAIN;
break;
}
if (signal_pending(current)) {
retval = -ERESTARTSYS;
break;
}
schedule(); retval = wait_event_interruptible(list->evdev->wait,
} list->head != list->tail && list->evdev->exist);
set_current_state(TASK_RUNNING);
remove_wait_queue(&list->evdev->wait, &wait);
}
if (retval) if (retval)
return retval; return retval;
if (!list->evdev->exist)
return -ENODEV;
while (list->head != list->tail && retval + sizeof(struct input_event) <= count) { while (list->head != list->tail && retval + sizeof(struct input_event) <= count) {
if (copy_to_user(buffer + retval, list->buffer + list->tail, if (copy_to_user(buffer + retval, list->buffer + list->tail,
sizeof(struct input_event))) return -EFAULT; sizeof(struct input_event))) return -EFAULT;
...@@ -433,22 +385,20 @@ static struct input_handle *evdev_connect(struct input_handler *handler, struct ...@@ -433,22 +385,20 @@ static struct input_handle *evdev_connect(struct input_handler *handler, struct
return NULL; return NULL;
memset(evdev, 0, sizeof(struct evdev)); memset(evdev, 0, sizeof(struct evdev));
INIT_LIST_HEAD(&evdev->list);
init_waitqueue_head(&evdev->wait); init_waitqueue_head(&evdev->wait);
evdev->exist = 1;
evdev->minor = minor; evdev->minor = minor;
evdev_table[minor] = evdev;
sprintf(evdev->name, "event%d", minor);
evdev->handle.dev = dev; evdev->handle.dev = dev;
evdev->handle.name = evdev->name; evdev->handle.name = evdev->name;
evdev->handle.handler = handler; evdev->handle.handler = handler;
evdev->handle.private = evdev; 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->devfs = input_register_minor("event%d", minor, EVDEV_MINOR_BASE);
evdev->exist = 1;
return &evdev->handle; return &evdev->handle;
} }
......
...@@ -44,7 +44,6 @@ MODULE_LICENSE("GPL"); ...@@ -44,7 +44,6 @@ MODULE_LICENSE("GPL");
struct emu { struct emu {
struct pci_dev *dev; struct pci_dev *dev;
struct emu *next;
struct gameport gameport; struct gameport gameport;
int size; int size;
char phys[32]; char phys[32];
......
...@@ -53,13 +53,13 @@ struct ns558 { ...@@ -53,13 +53,13 @@ struct ns558 {
int type; int type;
int size; int size;
struct pci_dev *dev; struct pci_dev *dev;
struct ns558 *next; struct list_head node;
struct gameport gameport; struct gameport gameport;
char phys[32]; char phys[32];
char name[32]; char name[32];
}; };
static struct ns558 *ns558; static LIST_HEAD(ns558_list);
/* /*
* ns558_isa_probe() tries to find an isa gameport at the * ns558_isa_probe() tries to find an isa gameport at the
...@@ -67,7 +67,7 @@ static struct ns558 *ns558; ...@@ -67,7 +67,7 @@ static struct ns558 *ns558;
* A joystick must be attached for this to work. * 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; int i, j, b;
unsigned char c, u, v; unsigned char c, u, v;
...@@ -78,7 +78,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next) ...@@ -78,7 +78,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
*/ */
if (check_region(io, 1)) if (check_region(io, 1))
return next; return;
/* /*
* We must not be able to write arbitrary values to the port. * 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) ...@@ -89,7 +89,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
outb(~c & ~3, io); outb(~c & ~3, io);
if (~(u = v = inb(io)) & 3) { if (~(u = v = inb(io)) & 3) {
outb(c, io); outb(c, io);
return next; return;
} }
/* /*
* After a trigger, there must be at least some bits changing. * 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) ...@@ -99,7 +99,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
if (u == v) { if (u == v) {
outb(c, io); outb(c, io);
return next; return;
} }
wait_ms(3); wait_ms(3);
/* /*
...@@ -110,7 +110,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next) ...@@ -110,7 +110,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
for (i = 0; i < 1000; i++) for (i = 0; i < 1000; i++)
if ((u ^ inb(io)) & 0xf) { if ((u ^ inb(io)) & 0xf) {
outb(c, io); outb(c, io);
return next; return;
} }
/* /*
* And now find the number of mirrors of the port. * 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) ...@@ -134,11 +134,10 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
if (!(port = kmalloc(sizeof(struct ns558), GFP_KERNEL))) { if (!(port = kmalloc(sizeof(struct ns558), GFP_KERNEL))) {
printk(KERN_ERR "ns558: Memory allocation failed.\n"); printk(KERN_ERR "ns558: Memory allocation failed.\n");
return next; return;
} }
memset(port, 0, sizeof(struct ns558)); memset(port, 0, sizeof(struct ns558));
port->next = next;
port->type = NS558_ISA; port->type = NS558_ISA;
port->size = (1 << i); port->size = (1 << i);
port->gameport.io = io & (-1 << i); port->gameport.io = io & (-1 << i);
...@@ -157,7 +156,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next) ...@@ -157,7 +156,7 @@ static struct ns558* ns558_isa_probe(int io, struct ns558 *next)
if (port->size > 1) printk(" size %d", port->size); if (port->size > 1) printk(" size %d", port->size);
printk(" speed %d kHz\n", port->gameport.speed); printk(" speed %d kHz\n", port->gameport.speed);
return port; list_add(&port->node, &ns558_list);
} }
#ifdef __ISAPNP__ #ifdef __ISAPNP__
...@@ -194,22 +193,22 @@ static struct isapnp_device_id pnp_devids[] = { ...@@ -194,22 +193,22 @@ static struct isapnp_device_id pnp_devids[] = {
MODULE_DEVICE_TABLE(isapnp, 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; int ioport, iolen;
struct ns558 *port; struct ns558 *port;
if (dev->prepare && dev->prepare(dev) < 0) if (dev->prepare && dev->prepare(dev) < 0)
return next; return;
if (!(dev->resource[0].flags & IORESOURCE_IO)) { if (!(dev->resource[0].flags & IORESOURCE_IO)) {
printk(KERN_WARNING "ns558: No i/o ports on a gameport? Weird\n"); printk(KERN_WARNING "ns558: No i/o ports on a gameport? Weird\n");
return next; return;
} }
if (dev->activate && dev->activate(dev) < 0) { if (dev->activate && dev->activate(dev) < 0) {
printk(KERN_ERR "ns558: PnP resource allocation failed\n"); printk(KERN_ERR "ns558: PnP resource allocation failed\n");
return next; return;
} }
ioport = pci_resource_start(dev, 0); ioport = pci_resource_start(dev, 0);
...@@ -224,7 +223,6 @@ static struct ns558* ns558_pnp_probe(struct pci_dev *dev, struct ns558 *next) ...@@ -224,7 +223,6 @@ static struct ns558* ns558_pnp_probe(struct pci_dev *dev, struct ns558 *next)
} }
memset(port, 0, sizeof(struct ns558)); memset(port, 0, sizeof(struct ns558));
port->next = next;
port->type = NS558_PNP; port->type = NS558_PNP;
port->size = iolen; port->size = iolen;
port->dev = dev; port->dev = dev;
...@@ -247,12 +245,12 @@ static struct ns558* ns558_pnp_probe(struct pci_dev *dev, struct ns558 *next) ...@@ -247,12 +245,12 @@ static struct ns558* ns558_pnp_probe(struct pci_dev *dev, struct ns558 *next)
if (iolen > 1) printk(" size %d", iolen); if (iolen > 1) printk(" size %d", iolen);
printk(" speed %d kHz\n", port->gameport.speed); printk(" speed %d kHz\n", port->gameport.speed);
return port; list_add_tail(&port->node, &ns558_list);
return;
deactivate: deactivate:
if (dev->deactivate) if (dev->deactivate)
dev->deactivate(dev); dev->deactivate(dev);
return next;
} }
#endif #endif
...@@ -269,28 +267,26 @@ int __init ns558_init(void) ...@@ -269,28 +267,26 @@ int __init ns558_init(void)
*/ */
while (ns558_isa_portlist[i]) 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. * Probe for PnP ports.
*/ */
#ifdef __ISAPNP__ #ifdef __ISAPNP__
for (devid = pnp_devids; devid->vendor; devid++) { for (devid = pnp_devids; devid->vendor; devid++)
while ((dev = isapnp_find_dev(NULL, devid->vendor, devid->function, dev))) { while ((dev = isapnp_find_dev(NULL, devid->vendor, devid->function, dev)))
ns558 = ns558_pnp_probe(dev, ns558); ns558_pnp_probe(dev);
}
}
#endif #endif
return ns558 ? 0 : -ENODEV; return list_empty(&ns558_list) ? -ENODEV : 0;
} }
void __exit ns558_exit(void) 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); gameport_unregister_port(&port->gameport);
switch (port->type) { switch (port->type) {
...@@ -308,10 +304,6 @@ void __exit ns558_exit(void) ...@@ -308,10 +304,6 @@ void __exit ns558_exit(void)
default: default:
break; 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-2002 Vojtech Pavlik
* Copyright (c) 1999 Colin Van Dyke * 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 * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (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> #include <asm/io.h>
...@@ -63,8 +46,7 @@ struct joydev { ...@@ -63,8 +46,7 @@ struct joydev {
struct input_handle handle; struct input_handle handle;
wait_queue_head_t wait; wait_queue_head_t wait;
devfs_handle_t devfs; devfs_handle_t devfs;
struct joydev *next; struct list_head list;
struct joydev_list *list;
struct js_corr corr[ABS_MAX]; struct js_corr corr[ABS_MAX];
struct JS_DATA_SAVE_TYPE glue; struct JS_DATA_SAVE_TYPE glue;
int nabs; int nabs;
...@@ -83,7 +65,7 @@ struct joydev_list { ...@@ -83,7 +65,7 @@ struct joydev_list {
int startup; int startup;
struct fasync_struct *fasync; struct fasync_struct *fasync;
struct joydev *joydev; struct joydev *joydev;
struct joydev_list *next; struct list_head node;
}; };
static struct joydev *joydev_table[JOYDEV_MINORS]; static struct joydev *joydev_table[JOYDEV_MINORS];
...@@ -111,7 +93,7 @@ static int joydev_correct(int value, struct js_corr *corr) ...@@ -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) static void joydev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
{ {
struct joydev *joydev = handle->private; struct joydev *joydev = handle->private;
struct joydev_list *list = joydev->list; struct joydev_list *list;
struct js_event event; struct js_event event;
switch (type) { switch (type) {
...@@ -137,7 +119,7 @@ static void joydev_event(struct input_handle *handle, unsigned int type, unsigne ...@@ -137,7 +119,7 @@ static void joydev_event(struct input_handle *handle, unsigned int type, unsigne
event.time = MSECS(jiffies); event.time = MSECS(jiffies);
while (list) { list_for_each_entry(list, &joydev->list, node) {
memcpy(list->buffer + list->head, &event, sizeof(struct js_event)); 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 ...@@ -146,8 +128,6 @@ static void joydev_event(struct input_handle *handle, unsigned int type, unsigne
list->startup = 0; list->startup = 0;
kill_fasync(&list->fasync, SIGIO, POLL_IN); kill_fasync(&list->fasync, SIGIO, POLL_IN);
list = list->next;
} }
wake_up_interruptible(&joydev->wait); wake_up_interruptible(&joydev->wait);
...@@ -164,14 +144,10 @@ static int joydev_fasync(int fd, struct file *file, int on) ...@@ -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) static int joydev_release(struct inode * inode, struct file * file)
{ {
struct joydev_list *list = file->private_data; struct joydev_list *list = file->private_data;
struct joydev_list **listptr;
listptr = &list->joydev->list;
joydev_fasync(-1, file, 0); joydev_fasync(-1, file, 0);
while (*listptr && (*listptr != list)) list_del(&list->node);
listptr = &((*listptr)->next);
*listptr = (*listptr)->next;
if (!--list->joydev->open) { if (!--list->joydev->open) {
if (list->joydev->exist) { if (list->joydev->exist) {
...@@ -201,9 +177,7 @@ static int joydev_open(struct inode *inode, struct file *file) ...@@ -201,9 +177,7 @@ static int joydev_open(struct inode *inode, struct file *file)
memset(list, 0, sizeof(struct joydev_list)); memset(list, 0, sizeof(struct joydev_list));
list->joydev = joydev_table[i]; list->joydev = joydev_table[i];
list->next = joydev_table[i]->list; list_add_tail(&list->node, &joydev_table[i]->list);
joydev_table[i]->list = list;
file->private_data = list; file->private_data = list;
if (!list->joydev->open++) if (!list->joydev->open++)
...@@ -220,12 +194,14 @@ static ssize_t joydev_write(struct file * file, const char * buffer, size_t coun ...@@ -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) 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_list *list = file->private_data;
struct joydev *joydev = list->joydev; struct joydev *joydev = list->joydev;
struct input_dev *input = joydev->handle.dev; struct input_dev *input = joydev->handle.dev;
int retval = 0; int retval = 0;
if (!list->joydev->exist)
return -ENODEV;
if (count < sizeof(struct js_event)) if (count < sizeof(struct js_event))
return -EINVAL; return -EINVAL;
...@@ -248,36 +224,19 @@ static ssize_t joydev_read(struct file *file, char *buf, size_t count, loff_t *p ...@@ -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); return sizeof(struct JS_DATA_TYPE);
} }
if (list->head == list->tail && list->startup == joydev->nabs + joydev->nkey) { if (list->startup == joydev->nabs + joydev->nkey
&& list->head == list->tail && (file->f_flags & O_NONBLOCK))
add_wait_queue(&list->joydev->wait, &wait); return -EAGAIN;
set_current_state(TASK_INTERRUPTIBLE);
while (list->head == list->tail) { retval = wait_event_interruptible(list->joydev->wait, list->joydev->exist
&& (list->startup < joydev->nabs + joydev->nkey || 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);
}
if (retval) if (retval)
return retval; return retval;
if (!list->joydev->exist)
return -ENODEV;
while (list->startup < joydev->nabs + joydev->nkey && retval + sizeof(struct js_event) <= count) { while (list->startup < joydev->nabs + joydev->nkey && retval + sizeof(struct js_event) <= count) {
struct js_event event; struct js_event event;
...@@ -431,17 +390,16 @@ static struct input_handle *joydev_connect(struct input_handler *handler, struct ...@@ -431,17 +390,16 @@ static struct input_handle *joydev_connect(struct input_handler *handler, struct
return NULL; return NULL;
memset(joydev, 0, sizeof(struct joydev)); memset(joydev, 0, sizeof(struct joydev));
INIT_LIST_HEAD(&joydev->list);
init_waitqueue_head(&joydev->wait); init_waitqueue_head(&joydev->wait);
joydev->minor = minor; joydev->minor = minor;
joydev_table[minor] = joydev; joydev->exist = 1;
sprintf(joydev->name, "js%d", minor);
joydev->handle.dev = dev; joydev->handle.dev = dev;
joydev->handle.name = joydev->name; joydev->handle.name = joydev->name;
joydev->handle.handler = handler; joydev->handle.handler = handler;
joydev->handle.private = joydev; joydev->handle.private = joydev;
sprintf(joydev->name, "js%d", minor);
for (i = 0; i < ABS_MAX; i++) for (i = 0; i < ABS_MAX; i++)
if (test_bit(i, dev->absbit)) { if (test_bit(i, dev->absbit)) {
...@@ -482,10 +440,9 @@ static struct input_handle *joydev_connect(struct input_handler *handler, struct ...@@ -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->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->devfs = input_register_minor("js%d", minor, JOYDEV_MINOR_BASE);
joydev->exist = 1;
return &joydev->handle; 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 * 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 * it under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation.
* (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
*/ */
#define MOUSEDEV_MINOR_BASE 32 #define MOUSEDEV_MINOR_BASE 32
...@@ -61,7 +43,7 @@ struct mousedev { ...@@ -61,7 +43,7 @@ struct mousedev {
int minor; int minor;
char name[16]; char name[16];
wait_queue_head_t wait; wait_queue_head_t wait;
struct mousedev_list *list; struct list_head list;
struct input_handle handle; struct input_handle handle;
devfs_handle_t devfs; devfs_handle_t devfs;
}; };
...@@ -69,7 +51,7 @@ struct mousedev { ...@@ -69,7 +51,7 @@ struct mousedev {
struct mousedev_list { struct mousedev_list {
struct fasync_struct *fasync; struct fasync_struct *fasync;
struct mousedev *mousedev; struct mousedev *mousedev;
struct mousedev_list *next; struct list_head node;
int dx, dy, dz, oldx, oldy; int dx, dy, dz, oldx, oldy;
signed char ps2[6]; signed char ps2[6];
unsigned long buttons; unsigned long buttons;
...@@ -98,9 +80,10 @@ static void mousedev_event(struct input_handle *handle, unsigned int type, unsig ...@@ -98,9 +80,10 @@ static void mousedev_event(struct input_handle *handle, unsigned int type, unsig
int index, size, wake; int index, size, wake;
while (*mousedev) { while (*mousedev) {
wake = 0; wake = 0;
list = (*mousedev)->list;
while (list) { list_for_each_entry(list, &(*mousedev)->list, node)
switch (type) { switch (type) {
case EV_ABS: case EV_ABS:
if (test_bit(BTN_TRIGGER, handle->dev->keybit)) if (test_bit(BTN_TRIGGER, handle->dev->keybit))
...@@ -116,6 +99,7 @@ static void mousedev_event(struct input_handle *handle, unsigned int type, unsig ...@@ -116,6 +99,7 @@ static void mousedev_event(struct input_handle *handle, unsigned int type, unsig
list->oldx += list->dx; list->oldx += list->dx;
} }
break; break;
case ABS_Y: case ABS_Y:
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) { if (size != 0) {
...@@ -170,10 +154,10 @@ static void mousedev_event(struct input_handle *handle, unsigned int type, unsig ...@@ -170,10 +154,10 @@ static void mousedev_event(struct input_handle *handle, unsigned int type, unsig
break; break;
} }
} }
list = list->next;
}
if (wake) if (wake)
wake_up_interruptible(&((*mousedev)->wait)); wake_up_interruptible(&((*mousedev)->wait));
mousedev++; mousedev++;
} }
} }
...@@ -189,21 +173,17 @@ static int mousedev_fasync(int fd, struct file *file, int on) ...@@ -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) static int mousedev_release(struct inode * inode, struct file * file)
{ {
struct mousedev_list *list = file->private_data; 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); mousedev_fasync(-1, file, 0);
while (*listptr && (*listptr != list)) list_del(&list->node);
listptr = &((*listptr)->next);
*listptr = (*listptr)->next;
if (!--list->mousedev->open) { if (!--list->mousedev->open) {
if (list->mousedev->minor == MOUSEDEV_MIX) { if (list->mousedev->minor == MOUSEDEV_MIX) {
struct list_head * node; list_for_each_entry(handle, &mousedev_handler.h_list, h_node) {
list_for_each(node,&mousedev_handler.h_list) { mousedev = handle->private;
struct input_handle *handle = to_handle_h(node);
struct mousedev *mousedev = handle->private;
if (!mousedev->open) { if (!mousedev->open) {
if (mousedev->exist) { if (mousedev->exist) {
input_close_device(&mousedev->handle); input_close_device(&mousedev->handle);
...@@ -252,8 +232,7 @@ static int mousedev_open(struct inode * inode, struct file * file) ...@@ -252,8 +232,7 @@ static int mousedev_open(struct inode * inode, struct file * file)
memset(list, 0, sizeof(struct mousedev_list)); memset(list, 0, sizeof(struct mousedev_list));
list->mousedev = mousedev_table[i]; list->mousedev = mousedev_table[i];
list->next = mousedev_table[i]->list; list_add_tail(&list->node, &mousedev_table[i]->list);
mousedev_table[i]->list = list;
file->private_data = list; file->private_data = list;
if (!list->mousedev->open++) { if (!list->mousedev->open++) {
...@@ -373,35 +352,13 @@ static ssize_t mousedev_write(struct file * file, const char * buffer, size_t co ...@@ -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) 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; struct mousedev_list *list = file->private_data;
int retval = 0; 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); retval = wait_event_interruptible(list->mousedev->wait, list->ready || list->buffer);
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);
}
if (retval) if (retval)
return retval; return retval;
...@@ -454,23 +411,23 @@ static struct input_handle *mousedev_connect(struct input_handler *handler, stru ...@@ -454,23 +411,23 @@ static struct input_handle *mousedev_connect(struct input_handler *handler, stru
if (!(mousedev = kmalloc(sizeof(struct mousedev), GFP_KERNEL))) if (!(mousedev = kmalloc(sizeof(struct mousedev), GFP_KERNEL)))
return NULL; return NULL;
memset(mousedev, 0, sizeof(struct mousedev)); memset(mousedev, 0, sizeof(struct mousedev));
INIT_LIST_HEAD(&mousedev->list);
init_waitqueue_head(&mousedev->wait); init_waitqueue_head(&mousedev->wait);
mousedev->minor = minor; mousedev->minor = minor;
mousedev_table[minor] = mousedev; mousedev->exist = 1;
sprintf(mousedev->name, "mouse%d", minor);
mousedev->handle.dev = dev; mousedev->handle.dev = dev;
mousedev->handle.name = mousedev->name; mousedev->handle.name = mousedev->name;
mousedev->handle.handler = handler; mousedev->handle.handler = handler;
mousedev->handle.private = mousedev; mousedev->handle.private = mousedev;
sprintf(mousedev->name, "mouse%d", minor);
mousedev->devfs = input_register_minor("mouse%d", minor, MOUSEDEV_MINOR_BASE);
if (mousedev_mix.open) if (mousedev_mix.open)
input_open_device(&mousedev->handle); 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; return &mousedev->handle;
} }
......
...@@ -55,7 +55,7 @@ struct tsdev { ...@@ -55,7 +55,7 @@ struct tsdev {
int minor; int minor;
char name[16]; char name[16];
wait_queue_head_t wait; wait_queue_head_t wait;
struct tsdev_list *list; struct list_head list;
struct input_handle handle; struct input_handle handle;
devfs_handle_t devfs; devfs_handle_t devfs;
}; };
...@@ -70,7 +70,7 @@ typedef struct { ...@@ -70,7 +70,7 @@ typedef struct {
struct tsdev_list { struct tsdev_list {
struct fasync_struct *fasync; struct fasync_struct *fasync;
struct tsdev_list *next; struct list_head node;
struct tsdev *tsdev; struct tsdev *tsdev;
int head, tail; int head, tail;
int oldx, oldy, pendown; int oldx, oldy, pendown;
...@@ -106,8 +106,7 @@ static int tsdev_open(struct inode *inode, struct file *file) ...@@ -106,8 +106,7 @@ static int tsdev_open(struct inode *inode, struct file *file)
memset(list, 0, sizeof(struct tsdev_list)); memset(list, 0, sizeof(struct tsdev_list));
list->tsdev = tsdev_table[i]; list->tsdev = tsdev_table[i];
list->next = tsdev_table[i]->list; list_add_tail(&list->node, &tsdev_table[i]->list);
tsdev_table[i]->list = list;
file->private_data = list; file->private_data = list;
if (!list->tsdev->open++) if (!list->tsdev->open++)
...@@ -119,14 +118,9 @@ static int tsdev_open(struct inode *inode, struct file *file) ...@@ -119,14 +118,9 @@ static int tsdev_open(struct inode *inode, struct file *file)
static int tsdev_release(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 *list = file->private_data;
struct tsdev_list **listptr;
listptr = &list->tsdev->list;
tsdev_fasync(-1, file, 0); tsdev_fasync(-1, file, 0);
list_del(&list->node);
while (*listptr && (*listptr != list))
listptr = &((*listptr)->next);
*listptr = (*listptr)->next;
if (!--list->tsdev->open) { if (!--list->tsdev->open) {
if (list->tsdev->exist) { if (list->tsdev->exist) {
...@@ -144,45 +138,28 @@ static int tsdev_release(struct inode *inode, struct file *file) ...@@ -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, static ssize_t tsdev_read(struct file *file, char *buffer, size_t count,
loff_t * ppos) loff_t * ppos)
{ {
DECLARE_WAITQUEUE(wait, current);
struct tsdev_list *list = file->private_data; struct tsdev_list *list = file->private_data;
int retval = 0; int retval = 0;
if (list->head == list->tail) { if (list->head == list->tail && list->tsdev->exist && (file->f_flags & O_NONBLOCK))
add_wait_queue(&list->tsdev->wait, &wait); return -EAGAIN;
set_current_state(TASK_INTERRUPTIBLE);
while (list->head == list->tail) { retval = wait_event_interruptible(list->tsdev->wait,
if (!list->tsdev->exist) { (list->head != list->tail) && 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);
}
if (retval) if (retval)
return retval; return retval;
while (list->head != list->tail if (!list->tsdev->exist)
&& retval + sizeof(TS_EVENT) <= count) { return -ENODEV;
if (copy_to_user
(buffer + retval, list->event + list->tail, while (list->head != list->tail && retval + sizeof(TS_EVENT) <= count) {
sizeof(TS_EVENT))) if (copy_to_user (buffer + retval, list->event + list->tail, sizeof(TS_EVENT)))
return -EFAULT; return -EFAULT;
list->tail = (list->tail + 1) & (TSDEV_BUFFER_SIZE - 1); list->tail = (list->tail + 1) & (TSDEV_BUFFER_SIZE - 1);
retval += sizeof(TS_EVENT); retval += sizeof(TS_EVENT);
} }
return retval; return retval;
} }
...@@ -232,54 +209,35 @@ static void tsdev_event(struct input_handle *handle, unsigned int type, ...@@ -232,54 +209,35 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
unsigned int code, int value) unsigned int code, int value)
{ {
struct tsdev *tsdev = handle->private; struct tsdev *tsdev = handle->private;
struct tsdev_list *list = tsdev->list; struct tsdev_list *list;
struct timeval time; struct timeval time;
int size; int size;
while (list) { list_for_each_entry(list, &tsdev->list, node) {
switch (type) { switch (type) {
case EV_ABS: case EV_ABS:
switch (code) { switch (code) {
case ABS_X: case ABS_X:
if (!list->pendown) if (!list->pendown)
return; 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) if (size > 0)
list->oldx = list->oldx = ((value - handle->dev->absmin[ABS_X]) * xres / size);
((value -
handle->dev->absmin[ABS_X]) *
xres / size);
else else
list->oldx = list->oldx = ((value - handle->dev->absmin[ABS_X]));
((value -
handle->dev->absmin[ABS_X]));
break; break;
case ABS_Y: case ABS_Y:
if (!list->pendown) if (!list->pendown)
return; 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) if (size > 0)
list->oldy = list->oldy = ((value - handle->dev->absmin[ABS_Y]) * yres / size);
((value -
handle->dev->absmin[ABS_Y]) *
yres / size);
else else
list->oldy = list->oldy = ((value - handle->dev->absmin[ABS_Y]));
((value -
handle->dev->absmin[ABS_Y]));
break; break;
case ABS_PRESSURE: case ABS_PRESSURE:
list->pendown = list->pendown = ((value > handle->dev-> absmin[ABS_PRESSURE])) ?
((value > value - handle->dev->absmin[ABS_PRESSURE] : 0;
handle->dev->
absmin[ABS_PRESSURE])) ? value -
handle->dev->absmin[ABS_PRESSURE] : 0;
break; break;
} }
break; break;
...@@ -289,7 +247,6 @@ static void tsdev_event(struct input_handle *handle, unsigned int type, ...@@ -289,7 +247,6 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
case REL_X: case REL_X:
if (!list->pendown) if (!list->pendown)
return; return;
list->oldx += value; list->oldx += value;
if (list->oldx < 0) if (list->oldx < 0)
list->oldx = 0; list->oldx = 0;
...@@ -299,7 +256,6 @@ static void tsdev_event(struct input_handle *handle, unsigned int type, ...@@ -299,7 +256,6 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
case REL_Y: case REL_Y:
if (!list->pendown) if (!list->pendown)
return; return;
list->oldy += value; list->oldy += value;
if (list->oldy < 0) if (list->oldy < 0)
list->oldy = 0; list->oldy = 0;
...@@ -333,7 +289,6 @@ static void tsdev_event(struct input_handle *handle, unsigned int type, ...@@ -333,7 +289,6 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
list->event[list->head].y = list->oldy; list->event[list->head].y = list->oldy;
list->head = (list->head + 1) & (TSDEV_BUFFER_SIZE - 1); list->head = (list->head + 1) & (TSDEV_BUFFER_SIZE - 1);
kill_fasync(&list->fasync, SIGIO, POLL_IN); kill_fasync(&list->fasync, SIGIO, POLL_IN);
list = list->next;
} }
wake_up_interruptible(&tsdev->wait); wake_up_interruptible(&tsdev->wait);
} }
...@@ -356,21 +311,23 @@ static struct input_handle *tsdev_connect(struct input_handler *handler, ...@@ -356,21 +311,23 @@ static struct input_handle *tsdev_connect(struct input_handler *handler,
if (!(tsdev = kmalloc(sizeof(struct tsdev), GFP_KERNEL))) if (!(tsdev = kmalloc(sizeof(struct tsdev), GFP_KERNEL)))
return NULL; return NULL;
memset(tsdev, 0, sizeof(struct tsdev)); memset(tsdev, 0, sizeof(struct tsdev));
INIT_LIST_HEAD(&tsdev->list);
init_waitqueue_head(&tsdev->wait); init_waitqueue_head(&tsdev->wait);
tsdev->minor = minor;
tsdev_table[minor] = tsdev;
sprintf(tsdev->name, "ts%d", minor); sprintf(tsdev->name, "ts%d", minor);
tsdev->exist = 1;
tsdev->minor = minor;
tsdev->handle.dev = dev; tsdev->handle.dev = dev;
tsdev->handle.name = tsdev->name; tsdev->handle.name = tsdev->name;
tsdev->handle.handler = handler; tsdev->handle.handler = handler;
tsdev->handle.private = tsdev; tsdev->handle.private = tsdev;
tsdev_table[minor] = tsdev;
tsdev->devfs = tsdev->devfs =
input_register_minor("ts%d", minor, TSDEV_MINOR_BASE); input_register_minor("ts%d", minor, TSDEV_MINOR_BASE);
tsdev->exist = 1;
return &tsdev->handle; 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