upektc: add support for Eikon Touch 300

https://bugs.freedesktop.org/show_bug.cgi?id=45197
This commit is contained in:
Vasily Khoruzhick 2012-11-24 16:05:58 +03:00 committed by Bastien Nocera
parent 59925d2027
commit 2084724115
2 changed files with 1262 additions and 21 deletions

View file

@ -28,13 +28,25 @@
#include "upektc.h"
#include "driver_ids.h"
#define EP_IN (2 | LIBUSB_ENDPOINT_IN)
#define EP_OUT (3 | LIBUSB_ENDPOINT_OUT)
#define UPEKTC_EP_IN (2 | LIBUSB_ENDPOINT_IN)
#define UPEKTC_EP_OUT (3 | LIBUSB_ENDPOINT_OUT)
#define UPEKET_EP_IN (1 | LIBUSB_ENDPOINT_IN)
#define UPEKET_EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
#define BULK_TIMEOUT 4000
struct upektc_dev {
gboolean deactivating;
const struct setup_cmd *setup_commands;
size_t setup_commands_len;
int ep_in;
int ep_out;
int init_idx;
int sum_threshold;
};
enum upektc_driver_data {
UPEKTC_2015,
UPEKTC_3001,
};
static void start_capture(struct fp_img_dev *dev);
@ -55,7 +67,7 @@ static void upektc_next_init_cmd(struct fpi_ssm *ssm)
struct upektc_dev *upekdev = dev->priv;
upekdev->init_idx += 1;
if (upekdev->init_idx == array_n_elements(setup_commands))
if (upekdev->init_idx == upekdev->setup_commands_len)
fpi_ssm_mark_completed(ssm);
else
fpi_ssm_jump_to_state(ssm, WRITE_INIT);
@ -69,7 +81,7 @@ static void write_init_cb(struct libusb_transfer *transfer)
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) &&
(transfer->length == transfer->actual_length)) {
if (setup_commands[upekdev->init_idx].response_len)
if (upekdev->setup_commands[upekdev->init_idx].response_len)
fpi_ssm_next_state(ssm);
else
upektc_next_init_cmd(ssm);
@ -105,8 +117,8 @@ static void activate_run_state(struct fpi_ssm *ssm)
fpi_ssm_mark_aborted(ssm, -ENOMEM);
return;
}
libusb_fill_bulk_transfer(transfer, dev->udev, EP_OUT,
(unsigned char*)setup_commands[upekdev->init_idx].cmd,
libusb_fill_bulk_transfer(transfer, dev->udev, upekdev->ep_out,
(unsigned char*)upekdev->setup_commands[upekdev->init_idx].cmd,
UPEKTC_CMD_LEN, write_init_cb, ssm, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
if (r < 0) {
@ -125,9 +137,9 @@ static void activate_run_state(struct fpi_ssm *ssm)
break;
}
data = g_malloc(setup_commands[upekdev->init_idx].response_len);
libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, data,
setup_commands[upekdev->init_idx].response_len,
data = g_malloc(upekdev->setup_commands[upekdev->init_idx].response_len);
libusb_fill_bulk_transfer(transfer, dev->udev, upekdev->ep_in, data,
upekdev->setup_commands[upekdev->init_idx].response_len,
read_init_data_cb, ssm, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
@ -155,7 +167,7 @@ static void activate_sm_complete(struct fpi_ssm *ssm)
/****** FINGER PRESENCE DETECTION ******/
static int finger_present(unsigned char *img, size_t len)
static int finger_present(unsigned char *img, size_t len, int sum_threshold)
{
int i, sum;
@ -168,12 +180,13 @@ static int finger_present(unsigned char *img, size_t len)
}
fp_dbg("finger_present: sum is %d\n", sum);
return sum < SUM_THRESHOLD ? 0 : 1;
return sum < sum_threshold ? 0 : 1;
}
static void finger_det_data_cb(struct libusb_transfer *transfer)
{
struct fp_img_dev *dev = transfer->user_data;
struct upektc_dev *upekdev = dev->priv;
unsigned char *data = transfer->buffer;
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
@ -186,7 +199,7 @@ static void finger_det_data_cb(struct libusb_transfer *transfer)
fpi_imgdev_session_error(dev, -EPROTO);
}
if (finger_present(data, IMAGE_SIZE)) {
if (finger_present(data, IMAGE_SIZE, upekdev->sum_threshold)) {
/* finger present, start capturing */
fpi_imgdev_report_finger_status(dev, TRUE);
start_capture(dev);
@ -206,6 +219,7 @@ static void finger_det_cmd_cb(struct libusb_transfer *t)
unsigned char *data;
int r;
struct fp_img_dev *dev = t->user_data;
struct upektc_dev *upekdev = dev->priv;
if (t->status != LIBUSB_TRANSFER_COMPLETED) {
fp_dbg("req transfer status %d\n", t->status);
@ -224,7 +238,7 @@ static void finger_det_cmd_cb(struct libusb_transfer *t)
}
data = g_malloc(IMAGE_SIZE);
libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, data, IMAGE_SIZE,
libusb_fill_bulk_transfer(transfer, dev->udev, upekdev->ep_in, data, IMAGE_SIZE,
finger_det_data_cb, dev, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
@ -254,7 +268,7 @@ static void start_finger_detection(struct fp_img_dev *dev)
fpi_imgdev_session_error(dev, -ENOMEM);
return;
}
libusb_fill_bulk_transfer(transfer, dev->udev, EP_OUT,
libusb_fill_bulk_transfer(transfer, dev->udev, upekdev->ep_out,
(unsigned char *)scan_cmd, UPEKTC_CMD_LEN,
finger_det_cmd_cb, dev, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
@ -315,6 +329,7 @@ out:
static void capture_run_state(struct fpi_ssm *ssm)
{
struct fp_img_dev *dev = ssm->priv;
struct upektc_dev *upekdev = dev->priv;
int r;
switch (ssm->cur_state) {
@ -325,7 +340,7 @@ static void capture_run_state(struct fpi_ssm *ssm)
fpi_ssm_mark_aborted(ssm, -ENOMEM);
return;
}
libusb_fill_bulk_transfer(transfer, dev->udev, EP_OUT,
libusb_fill_bulk_transfer(transfer, dev->udev, upekdev->ep_out,
(unsigned char *)scan_cmd, UPEKTC_CMD_LEN,
capture_cmd_cb, ssm, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
@ -346,7 +361,7 @@ static void capture_run_state(struct fpi_ssm *ssm)
}
data = g_malloc(IMAGE_SIZE);
libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, data, IMAGE_SIZE,
libusb_fill_bulk_transfer(transfer, dev->udev, upekdev->ep_in, data, IMAGE_SIZE,
capture_read_data_cb, ssm, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
@ -422,6 +437,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
{
/* TODO check that device has endpoints we're using */
int r;
struct upektc_dev *upekdev;
r = libusb_claim_interface(dev->udev, 0);
if (r < 0) {
@ -429,7 +445,29 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
return r;
}
dev->priv = g_malloc0(sizeof(struct upektc_dev));
dev->priv = upekdev = g_malloc0(sizeof(struct upektc_dev));
switch (driver_data) {
case UPEKTC_2015:
upekdev->ep_in = UPEKTC_EP_IN;
upekdev->ep_out = UPEKTC_EP_OUT;
upekdev->setup_commands = upektc_setup_commands;
upekdev->setup_commands_len = array_n_elements(upektc_setup_commands);
upekdev->sum_threshold = UPEKTC_SUM_THRESHOLD;
break;
case UPEKTC_3001:
upekdev->ep_in = UPEKET_EP_IN;
upekdev->ep_out = UPEKET_EP_OUT;
upekdev->setup_commands = upeket_setup_commands;
upekdev->setup_commands_len = array_n_elements(upeket_setup_commands);
upekdev->sum_threshold = UPEKET_SUM_THRESHOLD;
break;
default:
fp_err("Device variant %d is not known\n", driver_data);
g_free(upekdev);
dev->priv = NULL;
return -ENODEV;
break;
}
fpi_imgdev_open_complete(dev, 0);
return 0;
}
@ -442,7 +480,8 @@ static void dev_deinit(struct fp_img_dev *dev)
}
static const struct usb_id id_table[] = {
{ .vendor = 0x0483, .product = 0x2015 },
{ .vendor = 0x0483, .product = 0x2015, .driver_data = UPEKTC_2015 },
{ .vendor = 0x147e, .product = 0x3001, .driver_data = UPEKTC_3001 },
{ 0, 0, 0, },
};
@ -450,7 +489,7 @@ struct fp_img_driver upektc_driver = {
.driver = {
.id = UPEKTC_ID,
.name = FP_COMPONENT,
.full_name = "UPEK TouchChip",
.full_name = "UPEK TouchChip/Eikon Touch 300",
.id_table = id_table,
.scan_type = FP_SCAN_TYPE_PRESS,
},

File diff suppressed because it is too large Load diff