aes4000.c 4.92 KB
Newer Older
1 2
/*
 * AuthenTec AES4000 driver for libfprint
3 4 5 6 7 8 9
 *
 * AES4000 is a press-typed sensor, which captures image in 96x96
 * pixels.
 *
 * This work is derived from Daniel Drake's AES4000 driver.
 *
 * Copyright (C) 2013 Juvenn Woo <machese@gmail.com>
10
 * Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#define FP_COMPONENT "aes4000"

29 30
#include "fp_internal.h"

31 32 33
#include <errno.h>

#include <glib.h>
34
#include <libusb.h>
35

36
#include <aeslib.h>
37

38
#include "aes3k.h"
39 40
#include "driver_ids.h"

41
#define DATA_BUFLEN	0x1259
42

43 44 45 46 47
/* image size = FRAME_WIDTH x FRAME_WIDTH */
#define FRAME_WIDTH 	96
#define FRAME_SIZE	(FRAME_WIDTH * AES3K_FRAME_HEIGHT / 2)
#define FRAME_NUMBER	(FRAME_WIDTH / AES3K_FRAME_HEIGHT)
#define ENLARGE_FACTOR 	3
48

49

50
static struct aes_regwrite init_reqs[] = {
51 52
	/* master reset */
	{ 0x80, 0x01 },
53
	{ 0, 0 },
54
	{ 0x80, 0x00 },
55
	{ 0, 0 },
56 57 58

	{ 0x81, 0x00 },
	{ 0x80, 0x00 },
59
	{ 0, 0 },
60 61 62

	/* scan reset */
	{ 0x80, 0x02 },
63
	{ 0, 0 },
64
	{ 0x80, 0x00 },
65
	{ 0, 0 },
66 67 68

	/* disable register buffering */
	{ 0x80, 0x04 },
69
	{ 0, 0 },
70
	{ 0x80, 0x00 },
71
	{ 0, 0 },
72 73

	{ 0x81, 0x00 },
74
	{ 0, 0 },
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
	/* windows driver reads registers now (81 02) */
	{ 0x80, 0x00 },
	{ 0x81, 0x00 },

	/* set excitation bias current: 2mhz drive ring frequency,
	 * 4V drive ring voltage, 16.5mA excitation bias */
	{ 0x82, 0x04 },

	/* continuously sample drive ring for finger detection,
	 * 62.50ms debounce delay */
	{ 0x83, 0x13 },

	{ 0x84, 0x07 }, /* set calibration resistance to 12 kiloohms */
	{ 0x85, 0x3d }, /* set calibration capacitance */
	{ 0x86, 0x03 }, /* detect drive voltage */
	{ 0x87, 0x01 }, /* set detection frequency to 125khz */
91 92 93
	{ 0x88, 0x02 }, /* set column scan period */
	{ 0x89, 0x02 }, /* set measure drive */
	{ 0x8a, 0x33 }, /* set measure frequency and sense amplifier bias */
94
	{ 0x8b, 0x33 }, /* set matrix pattern */
95
	{ 0x8c, 0x0f }, /* set demodulation phase 1 */
96
	{ 0x8d, 0x04 }, /* set demodulation phase 2 */
97 98 99 100 101
	{ 0x8e, 0x23 }, /* set sensor gain */
	{ 0x8f, 0x07 }, /* set image parameters */
	{ 0x90, 0x00 }, /* carrier offset null */
	{ 0x91, 0x1c }, /* set A/D reference high */
	{ 0x92, 0x08 }, /* set A/D reference low */
102 103 104 105 106 107 108 109 110 111 112 113 114
	{ 0x93, 0x00 }, /* set start row to 0 */
	{ 0x94, 0x05 }, /* set end row to 5 */
	{ 0x95, 0x00 }, /* set start column to 0 */
	{ 0x96, 0x18 }, /* set end column to 24*4=96 */
	{ 0x97, 0x04 }, /* data format and thresholds */
	{ 0x98, 0x28 }, /* image data control */
	{ 0x99, 0x00 }, /* disable general purpose outputs */
	{ 0x9a, 0x0b }, /* set initial scan state */
	{ 0x9b, 0x00 }, /* clear challenge word bits */
	{ 0x9c, 0x00 }, /* clear challenge word bits */
	{ 0x9d, 0x09 }, /* set some challenge word bits */
	{ 0x9e, 0x53 }, /* clear challenge word bits */
	{ 0x9f, 0x6b }, /* set some challenge word bits */
115
	{ 0, 0 },
116 117 118

	{ 0x80, 0x00 },
	{ 0x81, 0x00 },
119
	{ 0, 0 },
120
	{ 0x81, 0x04 },
121
	{ 0, 0 },
122 123 124 125 126 127
	{ 0x81, 0x00 },
};

static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
{
	int r;
128
	struct aes3k_dev *aesdev;
129

130
	r = libusb_claim_interface(dev->udev, 0);
131
	if (r < 0) {
132
		fp_err("could not claim interface 0: %s", libusb_error_name(r));
133 134
		return r;
	}
135

136 137 138 139
	aesdev = dev->priv = g_malloc0(sizeof(struct aes3k_dev));

	if (!aesdev)
		return -ENOMEM;
140

141 142 143 144 145 146 147 148
	aesdev->data_buflen = DATA_BUFLEN;
	aesdev->frame_width = FRAME_WIDTH;
	aesdev->frame_size = FRAME_SIZE;
	aesdev->frame_number = FRAME_NUMBER;
	aesdev->enlarge_factor = ENLARGE_FACTOR;
	aesdev->init_reqs = init_reqs;
	aesdev->init_reqs_len = G_N_ELEMENTS(init_reqs);
	fpi_imgdev_open_complete(dev, 0);
149 150

	return r;
151 152
}

153
static void dev_deinit(struct fp_img_dev *dev)
154
{
155 156
	struct aes3k_dev *aesdev = dev->priv;
	g_free(aesdev);
157
	libusb_release_interface(dev->udev, 0);
158
	fpi_imgdev_close_complete(dev);
159 160
}

161

162 163 164 165 166 167 168
static const struct usb_id id_table[] = {
	{ .vendor = 0x08ff, .product = 0x5501 },
	{ 0, 0, 0, },
};

struct fp_img_driver aes4000_driver = {
	.driver = {
169
		.id = AES4000_ID,
170 171 172
		.name = FP_COMPONENT,
		.full_name = "AuthenTec AES4000",
		.id_table = id_table,
173
		.scan_type = FP_SCAN_TYPE_PRESS,
174 175
	},
	.flags = 0,
176 177
	.img_height = FRAME_WIDTH * ENLARGE_FACTOR,
	.img_width = FRAME_WIDTH * ENLARGE_FACTOR,
178

179 180 181
	/* temporarily lowered until image quality improves */
	.bz3_threshold = 9,

182 183
	.open = dev_init,
	.close = dev_deinit,
184 185
	.activate = aes3k_dev_activate,
	.deactivate = aes3k_dev_deactivate,
186 187
};