X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=drivers%2Finput%2Ftsdev.c;h=d2f882e98e5e21c0c9c23b5d8c3e072883de052a;hb=489de30259e667d7bc47da9da44a0270b050cd97;hp=0300dca8591d9cdb076f0413eee62a6b56823fc8;hpb=4559b438225b01942e1661759db0df55883b1bc0;p=linux-2.6-omap-h63xx.git diff --git a/drivers/input/tsdev.c b/drivers/input/tsdev.c index 0300dca8591..d2f882e98e5 100644 --- a/drivers/input/tsdev.c +++ b/drivers/input/tsdev.c @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -110,14 +109,16 @@ struct tsdev { int open; int minor; char name[8]; - wait_queue_head_t wait; - struct list_head list; struct input_handle handle; + wait_queue_head_t wait; + struct list_head client_list; + struct device dev; + int x, y, pressure; struct ts_calibration cal; }; -struct tsdev_list { +struct tsdev_client { struct fasync_struct *fasync; struct list_head node; struct tsdev *tsdev; @@ -139,88 +140,110 @@ static struct tsdev *tsdev_table[TSDEV_MINORS/2]; static int tsdev_fasync(int fd, struct file *file, int on) { - struct tsdev_list *list = file->private_data; + struct tsdev_client *client = file->private_data; int retval; - retval = fasync_helper(fd, file, on, &list->fasync); + retval = fasync_helper(fd, file, on, &client->fasync); return retval < 0 ? retval : 0; } static int tsdev_open(struct inode *inode, struct file *file) { int i = iminor(inode) - TSDEV_MINOR_BASE; - struct tsdev_list *list; + struct tsdev_client *client; + struct tsdev *tsdev; + int error; printk(KERN_WARNING "tsdev (compaq touchscreen emulation) is scheduled " "for removal.\nSee Documentation/feature-removal-schedule.txt " "for details.\n"); - if (i >= TSDEV_MINORS || !tsdev_table[i & TSDEV_MINOR_MASK]) + if (i >= TSDEV_MINORS) return -ENODEV; - if (!(list = kzalloc(sizeof(struct tsdev_list), GFP_KERNEL))) - return -ENOMEM; + tsdev = tsdev_table[i & TSDEV_MINOR_MASK]; + if (!tsdev || !tsdev->exist) + return -ENODEV; - list->raw = (i >= TSDEV_MINORS/2) ? 1 : 0; + get_device(&tsdev->dev); - i &= TSDEV_MINOR_MASK; - list->tsdev = tsdev_table[i]; - list_add_tail(&list->node, &tsdev_table[i]->list); - file->private_data = list; + client = kzalloc(sizeof(struct tsdev_client), GFP_KERNEL); + if (!client) { + error = -ENOMEM; + goto err_put_tsdev; + } - if (!list->tsdev->open++) - if (list->tsdev->exist) - input_open_device(&list->tsdev->handle); + client->tsdev = tsdev; + client->raw = (i >= TSDEV_MINORS / 2) ? 1 : 0; + list_add_tail(&client->node, &tsdev->client_list); + + if (!tsdev->open++ && tsdev->exist) { + error = input_open_device(&tsdev->handle); + if (error) + goto err_free_client; + } + + file->private_data = client; return 0; + + err_free_client: + list_del(&client->node); + kfree(client); + err_put_tsdev: + put_device(&tsdev->dev); + return error; } -static void tsdev_free(struct tsdev *tsdev) +static void tsdev_free(struct device *dev) { + struct tsdev *tsdev = container_of(dev, struct tsdev, dev); + tsdev_table[tsdev->minor] = NULL; kfree(tsdev); } static int tsdev_release(struct inode *inode, struct file *file) { - struct tsdev_list *list = file->private_data; + struct tsdev_client *client = file->private_data; + struct tsdev *tsdev = client->tsdev; tsdev_fasync(-1, file, 0); - list_del(&list->node); - if (!--list->tsdev->open) { - if (list->tsdev->exist) - input_close_device(&list->tsdev->handle); - else - tsdev_free(list->tsdev); - } - kfree(list); + list_del(&client->node); + kfree(client); + + if (!--tsdev->open && tsdev->exist) + input_close_device(&tsdev->handle); + + put_device(&tsdev->dev); + return 0; } static ssize_t tsdev_read(struct file *file, char __user *buffer, size_t count, - loff_t * ppos) + loff_t *ppos) { - struct tsdev_list *list = file->private_data; + struct tsdev_client *client = file->private_data; + struct tsdev *tsdev = client->tsdev; int retval = 0; - if (list->head == list->tail && list->tsdev->exist && (file->f_flags & O_NONBLOCK)) + if (client->head == client->tail && tsdev->exist && (file->f_flags & O_NONBLOCK)) return -EAGAIN; - retval = wait_event_interruptible(list->tsdev->wait, - list->head != list->tail || !list->tsdev->exist); - + retval = wait_event_interruptible(tsdev->wait, + client->head != client->tail || !tsdev->exist); if (retval) return retval; - if (!list->tsdev->exist) + if (!tsdev->exist) return -ENODEV; - while (list->head != list->tail && + while (client->head != client->tail && retval + sizeof (struct ts_event) <= count) { - if (copy_to_user (buffer + retval, list->event + list->tail, + if (copy_to_user (buffer + retval, client->event + client->tail, sizeof (struct ts_event))) return -EFAULT; - list->tail = (list->tail + 1) & (TSDEV_BUFFER_SIZE - 1); + client->tail = (client->tail + 1) & (TSDEV_BUFFER_SIZE - 1); retval += sizeof (struct ts_event); } @@ -228,32 +251,33 @@ static ssize_t tsdev_read(struct file *file, char __user *buffer, size_t count, } /* No kernel lock - fine */ -static unsigned int tsdev_poll(struct file *file, poll_table * wait) +static unsigned int tsdev_poll(struct file *file, poll_table *wait) { - struct tsdev_list *list = file->private_data; + struct tsdev_client *client = file->private_data; + struct tsdev *tsdev = client->tsdev; - poll_wait(file, &list->tsdev->wait, wait); - return ((list->head == list->tail) ? 0 : (POLLIN | POLLRDNORM)) | - (list->tsdev->exist ? 0 : (POLLHUP | POLLERR)); + poll_wait(file, &tsdev->wait, wait); + return ((client->head == client->tail) ? 0 : (POLLIN | POLLRDNORM)) | + (tsdev->exist ? 0 : (POLLHUP | POLLERR)); } static int tsdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { - struct tsdev_list *list = file->private_data; - struct tsdev *tsdev = list->tsdev; + struct tsdev_client *client = file->private_data; + struct tsdev *tsdev = client->tsdev; int retval = 0; switch (cmd) { case TS_GET_CAL: - if (copy_to_user ((void __user *)arg, &tsdev->cal, - sizeof (struct ts_calibration))) + if (copy_to_user((void __user *)arg, &tsdev->cal, + sizeof (struct ts_calibration))) retval = -EFAULT; break; case TS_SET_CAL: - if (copy_from_user (&tsdev->cal, (void __user *)arg, - sizeof (struct ts_calibration))) + if (copy_from_user(&tsdev->cal, (void __user *)arg, + sizeof (struct ts_calibration))) retval = -EFAULT; break; @@ -279,7 +303,7 @@ 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; + struct tsdev_client *client; struct timeval time; switch (type) { @@ -343,18 +367,18 @@ static void tsdev_event(struct input_handle *handle, unsigned int type, if (type != EV_SYN || code != SYN_REPORT) return; - list_for_each_entry(list, &tsdev->list, node) { + list_for_each_entry(client, &tsdev->client_list, node) { int x, y, tmp; do_gettimeofday(&time); - list->event[list->head].millisecs = time.tv_usec / 100; - list->event[list->head].pressure = tsdev->pressure; + client->event[client->head].millisecs = time.tv_usec / 1000; + client->event[client->head].pressure = tsdev->pressure; x = tsdev->x; y = tsdev->y; /* Calibration */ - if (!list->raw) { + if (!client->raw) { x = ((x * tsdev->cal.xscale) >> 8) + tsdev->cal.xtrans; y = ((y * tsdev->cal.yscale) >> 8) + tsdev->cal.ytrans; if (tsdev->cal.xyswap) { @@ -362,43 +386,42 @@ static void tsdev_event(struct input_handle *handle, unsigned int type, } } - list->event[list->head].x = x; - list->event[list->head].y = y; - list->head = (list->head + 1) & (TSDEV_BUFFER_SIZE - 1); - kill_fasync(&list->fasync, SIGIO, POLL_IN); + client->event[client->head].x = x; + client->event[client->head].y = y; + client->head = (client->head + 1) & (TSDEV_BUFFER_SIZE - 1); + kill_fasync(&client->fasync, SIGIO, POLL_IN); } wake_up_interruptible(&tsdev->wait); } -static struct input_handle *tsdev_connect(struct input_handler *handler, - struct input_dev *dev, - const struct input_device_id *id) +static int tsdev_connect(struct input_handler *handler, struct input_dev *dev, + const struct input_device_id *id) { struct tsdev *tsdev; - struct class_device *cdev; int minor, delta; + int error; for (minor = 0; minor < TSDEV_MINORS / 2 && tsdev_table[minor]; minor++); if (minor >= TSDEV_MINORS / 2) { printk(KERN_ERR "tsdev: You have way too many touchscreens\n"); - return NULL; + return -ENFILE; } - if (!(tsdev = kzalloc(sizeof(struct tsdev), GFP_KERNEL))) - return NULL; + tsdev = kzalloc(sizeof(struct tsdev), GFP_KERNEL); + if (!tsdev) + return -ENOMEM; - INIT_LIST_HEAD(&tsdev->list); + INIT_LIST_HEAD(&tsdev->client_list); init_waitqueue_head(&tsdev->wait); - 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; + snprintf(tsdev->name, sizeof(tsdev->name), "ts%d", minor); /* Precompute the rough calibration matrix */ delta = dev->absmax [ABS_X] - dev->absmin [ABS_X] + 1; @@ -413,36 +436,51 @@ static struct input_handle *tsdev_connect(struct input_handler *handler, tsdev->cal.yscale = (yres << 8) / delta; tsdev->cal.ytrans = - ((dev->absmin [ABS_Y] * tsdev->cal.yscale) >> 8); + snprintf(tsdev->dev.bus_id, sizeof(tsdev->dev.bus_id), + "ts%d", minor); + tsdev->dev.class = &input_class; + tsdev->dev.parent = &dev->dev; + tsdev->dev.devt = MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor); + tsdev->dev.release = tsdev_free; + device_initialize(&tsdev->dev); + tsdev_table[minor] = tsdev; - cdev = class_device_create(&input_class, &dev->cdev, - MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor), - dev->cdev.dev, tsdev->name); + error = device_add(&tsdev->dev); + if (error) + goto err_free_tsdev; + + error = input_register_handle(&tsdev->handle); + if (error) + goto err_delete_tsdev; - /* temporary symlink to keep userspace happy */ - sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj, - tsdev->name); + return 0; - return &tsdev->handle; + err_delete_tsdev: + device_del(&tsdev->dev); + err_free_tsdev: + put_device(&tsdev->dev); + return error; } static void tsdev_disconnect(struct input_handle *handle) { struct tsdev *tsdev = handle->private; - struct tsdev_list *list; + struct tsdev_client *client; + + input_unregister_handle(handle); + device_del(&tsdev->dev); - sysfs_remove_link(&input_class.subsys.kset.kobj, tsdev->name); - class_device_destroy(&input_class, - MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + tsdev->minor)); tsdev->exist = 0; if (tsdev->open) { input_close_device(handle); + list_for_each_entry(client, &tsdev->client_list, node) + kill_fasync(&client->fasync, SIGIO, POLL_HUP); wake_up_interruptible(&tsdev->wait); - list_for_each_entry(list, &tsdev->list, node) - kill_fasync(&list->fasync, SIGIO, POLL_HUP); - } else - tsdev_free(tsdev); + } + + put_device(&tsdev->dev); } static const struct input_device_id tsdev_ids[] = {