Commit 4244f724 authored by Florian Echtler's avatar Florian Echtler Committed by Greg Kroah-Hartman

[PATCH] USB: upgrade of the idmouse driver

Signed-off-by: default avatarFlorian Echtler  <echtler@fs.tum.de>
Signed-off-by: default avatarAndreas Deresch <aderesch@fs.tum.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 685eb93f
/* Siemens ID Mouse driver v0.5 /* Siemens ID Mouse driver v0.6
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as modify it under the terms of the GNU General Public License as
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
Derived from the USB Skeleton driver 1.1, Derived from the USB Skeleton driver 1.1,
Copyright (C) 2003 Greg Kroah-Hartman (greg@kroah.com) Copyright (C) 2003 Greg Kroah-Hartman (greg@kroah.com)
Additional information provided by Martin Reising
<Martin.Reising@natural-computing.de>
*/ */
#include <linux/config.h> #include <linux/config.h>
...@@ -25,29 +28,44 @@ ...@@ -25,29 +28,44 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/usb.h> #include <linux/usb.h>
/* image constants */
#define WIDTH 225 #define WIDTH 225
#define HEIGHT 288 #define HEIGHT 289
#define HEADER "P5 225 288 255 " #define HEADER "P5 225 289 255 "
#define IMGSIZE ((WIDTH * HEIGHT) + sizeof(HEADER)-1) #define IMGSIZE ((WIDTH * HEIGHT) + sizeof(HEADER)-1)
/* Version Information */ /* version information */
#define DRIVER_VERSION "0.5" #define DRIVER_VERSION "0.6"
#define DRIVER_SHORT "idmouse" #define DRIVER_SHORT "idmouse"
#define DRIVER_AUTHOR "Florian 'Floe' Echtler <echtler@fs.tum.de>" #define DRIVER_AUTHOR "Florian 'Floe' Echtler <echtler@fs.tum.de>"
#define DRIVER_DESC "Siemens ID Mouse FingerTIP Sensor Driver" #define DRIVER_DESC "Siemens ID Mouse FingerTIP Sensor Driver"
/* Siemens ID Mouse */ /* minor number for misc USB devices */
#define USB_IDMOUSE_VENDOR_ID 0x0681
#define USB_IDMOUSE_PRODUCT_ID 0x0005
/* we still need a minor number */
#define USB_IDMOUSE_MINOR_BASE 132 #define USB_IDMOUSE_MINOR_BASE 132
/* vendor and device IDs */
#define ID_SIEMENS 0x0681
#define ID_IDMOUSE 0x0005
#define ID_CHERRY 0x0010
/* device ID table */
static struct usb_device_id idmouse_table[] = { static struct usb_device_id idmouse_table[] = {
{USB_DEVICE(USB_IDMOUSE_VENDOR_ID, USB_IDMOUSE_PRODUCT_ID)}, {USB_DEVICE(ID_SIEMENS, ID_IDMOUSE)}, /* Siemens ID Mouse (Professional) */
{} /* null entry at the end */ {USB_DEVICE(ID_SIEMENS, ID_CHERRY )}, /* Cherry FingerTIP ID Board */
{} /* terminating null entry */
}; };
/* sensor commands */
#define FTIP_RESET 0x20
#define FTIP_ACQUIRE 0x21
#define FTIP_RELEASE 0x22
#define FTIP_BLINK 0x23 /* LSB of value = blink pulse width */
#define FTIP_SCROLL 0x24
#define ftip_command(dev, command, value, index) \
usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), command, \
USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, value, index, NULL, 0, 1000)
MODULE_DEVICE_TABLE(usb, idmouse_table); MODULE_DEVICE_TABLE(usb, idmouse_table);
/* structure to hold all of our device specific stuff */ /* structure to hold all of our device specific stuff */
...@@ -57,7 +75,8 @@ struct usb_idmouse { ...@@ -57,7 +75,8 @@ struct usb_idmouse {
struct usb_interface *interface; /* the interface for this device */ struct usb_interface *interface; /* the interface for this device */
unsigned char *bulk_in_buffer; /* the buffer to receive data */ unsigned char *bulk_in_buffer; /* the buffer to receive data */
size_t bulk_in_size; /* the size of the receive buffer */ size_t bulk_in_size; /* the maximum bulk packet size */
size_t orig_bi_size; /* same as above, but reported by the device */
__u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */
int open; /* if the port is open or not */ int open; /* if the port is open or not */
...@@ -103,7 +122,7 @@ static struct usb_driver idmouse_driver = { ...@@ -103,7 +122,7 @@ static struct usb_driver idmouse_driver = {
.id_table = idmouse_table, .id_table = idmouse_table,
}; };
// prevent races between open() and disconnect() /* prevent races between open() and disconnect() */
static DECLARE_MUTEX(disconnect_sem); static DECLARE_MUTEX(disconnect_sem);
static int idmouse_create_image(struct usb_idmouse *dev) static int idmouse_create_image(struct usb_idmouse *dev)
...@@ -112,42 +131,34 @@ static int idmouse_create_image(struct usb_idmouse *dev) ...@@ -112,42 +131,34 @@ static int idmouse_create_image(struct usb_idmouse *dev)
int bulk_read = 0; int bulk_read = 0;
int result = 0; int result = 0;
if (dev->bulk_in_size < sizeof(HEADER)) memcpy(dev->bulk_in_buffer, HEADER, sizeof(HEADER)-1);
return -ENOMEM;
memcpy(dev->bulk_in_buffer,HEADER,sizeof(HEADER)-1);
bytes_read += sizeof(HEADER)-1; bytes_read += sizeof(HEADER)-1;
/* Dump the setup packets. Yes, they are uncommented, simply /* reset the device and set a fast blink rate */
because they were sniffed under Windows using SnoopyPro. result = ftip_command(dev, FTIP_RELEASE, 0, 0);
I _guess_ that 0x22 is a kind of reset command and 0x21
means init..
*/
result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0),
0x21, 0x42, 0x0001, 0x0002, NULL, 0, 1000);
if (result < 0) if (result < 0)
return result; goto reset;
result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), result = ftip_command(dev, FTIP_BLINK, 1, 0);
0x20, 0x42, 0x0001, 0x0002, NULL, 0, 1000);
if (result < 0)
return result;
result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0),
0x22, 0x42, 0x0000, 0x0002, NULL, 0, 1000);
if (result < 0) if (result < 0)
return result; goto reset;
result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), /* initialize the sensor - sending this command twice */
0x21, 0x42, 0x0001, 0x0002, NULL, 0, 1000); /* significantly reduces the rate of failed reads */
result = ftip_command(dev, FTIP_ACQUIRE, 0, 0);
if (result < 0) if (result < 0)
return result; goto reset;
result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), result = ftip_command(dev, FTIP_ACQUIRE, 0, 0);
0x20, 0x42, 0x0001, 0x0002, NULL, 0, 1000);
if (result < 0) if (result < 0)
return result; goto reset;
result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0),
0x20, 0x42, 0x0000, 0x0002, NULL, 0, 1000); /* start the readout - sending this command twice */
/* presumably enables the high dynamic range mode */
result = ftip_command(dev, FTIP_RESET, 0, 0);
if (result < 0) if (result < 0)
return result; goto reset;
result = ftip_command(dev, FTIP_RESET, 0, 0);
if (result < 0)
goto reset;
/* loop over a blocking bulk read to get data from the device */ /* loop over a blocking bulk read to get data from the device */
while (bytes_read < IMGSIZE) { while (bytes_read < IMGSIZE) {
...@@ -155,22 +166,40 @@ static int idmouse_create_image(struct usb_idmouse *dev) ...@@ -155,22 +166,40 @@ static int idmouse_create_image(struct usb_idmouse *dev)
usb_rcvbulkpipe (dev->udev, dev->bulk_in_endpointAddr), usb_rcvbulkpipe (dev->udev, dev->bulk_in_endpointAddr),
dev->bulk_in_buffer + bytes_read, dev->bulk_in_buffer + bytes_read,
dev->bulk_in_size, &bulk_read, 5000); dev->bulk_in_size, &bulk_read, 5000);
if (result < 0) if (result < 0) {
return result; /* Maybe this error was caused by the increased packet size? */
if (signal_pending(current)) /* Reset to the original value and tell userspace to retry. */
return -EINTR; if (dev->bulk_in_size != dev->orig_bi_size) {
dev->bulk_in_size = dev->orig_bi_size;
result = -EAGAIN;
}
break;
}
if (signal_pending(current)) {
result = -EINTR;
break;
}
bytes_read += bulk_read; bytes_read += bulk_read;
} }
/* reset the device */ /* reset the device */
result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), reset:
0x22, 0x42, 0x0000, 0x0002, NULL, 0, 1000); ftip_command(dev, FTIP_RELEASE, 0, 0);
if (result < 0)
return result; /* check for valid image */
/* right border should be black (0x00) */
for (bytes_read = sizeof(HEADER)-1 + WIDTH-1; bytes_read < IMGSIZE; bytes_read += WIDTH)
if (dev->bulk_in_buffer[bytes_read] != 0x00)
return -EAGAIN;
/* should be IMGSIZE == 64815 */ /* lower border should be white (0xFF) */
for (bytes_read = IMGSIZE-WIDTH; bytes_read < IMGSIZE-1; bytes_read++)
if (dev->bulk_in_buffer[bytes_read] != 0xFF)
return -EAGAIN;
/* should be IMGSIZE == 65040 */
dbg("read %d bytes fingerprint data", bytes_read); dbg("read %d bytes fingerprint data", bytes_read);
return 0; return result;
} }
static inline void idmouse_delete(struct usb_idmouse *dev) static inline void idmouse_delete(struct usb_idmouse *dev)
...@@ -282,10 +311,10 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count ...@@ -282,10 +311,10 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
dev = (struct usb_idmouse *) file->private_data; dev = (struct usb_idmouse *) file->private_data;
// lock this object /* lock this object */
down (&dev->sem); down (&dev->sem);
// verify that the device wasn't unplugged /* verify that the device wasn't unplugged */
if (!dev->present) { if (!dev->present) {
up (&dev->sem); up (&dev->sem);
return -ENODEV; return -ENODEV;
...@@ -296,8 +325,7 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count ...@@ -296,8 +325,7 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
return 0; return 0;
} }
if (count > IMGSIZE - *ppos) count = min ((loff_t)count, IMGSIZE - (*ppos));
count = IMGSIZE - *ppos;
if (copy_to_user (buffer, dev->bulk_in_buffer + *ppos, count)) { if (copy_to_user (buffer, dev->bulk_in_buffer + *ppos, count)) {
result = -EFAULT; result = -EFAULT;
...@@ -306,7 +334,7 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count ...@@ -306,7 +334,7 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
*ppos += count; *ppos += count;
} }
// unlock the device /* unlock the device */
up(&dev->sem); up(&dev->sem);
return result; return result;
} }
...@@ -318,7 +346,6 @@ static int idmouse_probe(struct usb_interface *interface, ...@@ -318,7 +346,6 @@ static int idmouse_probe(struct usb_interface *interface,
struct usb_idmouse *dev = NULL; struct usb_idmouse *dev = NULL;
struct usb_host_interface *iface_desc; struct usb_host_interface *iface_desc;
struct usb_endpoint_descriptor *endpoint; struct usb_endpoint_descriptor *endpoint;
size_t buffer_size;
int result; int result;
/* check if we have gotten the data or the hid interface */ /* check if we have gotten the data or the hid interface */
...@@ -344,11 +371,11 @@ static int idmouse_probe(struct usb_interface *interface, ...@@ -344,11 +371,11 @@ static int idmouse_probe(struct usb_interface *interface,
USB_ENDPOINT_XFER_BULK)) { USB_ENDPOINT_XFER_BULK)) {
/* we found a bulk in endpoint */ /* we found a bulk in endpoint */
buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); dev->orig_bi_size = le16_to_cpu(endpoint->wMaxPacketSize);
dev->bulk_in_size = buffer_size; dev->bulk_in_size = 0x200; /* works _much_ faster */
dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
dev->bulk_in_buffer = dev->bulk_in_buffer =
kmalloc(IMGSIZE + buffer_size, GFP_KERNEL); kmalloc(IMGSIZE + dev->bulk_in_size, GFP_KERNEL);
if (!dev->bulk_in_buffer) { if (!dev->bulk_in_buffer) {
err("Unable to allocate input buffer."); err("Unable to allocate input buffer.");
......
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