1/*
2 * Driver for USB Scanners (linux-2.4)
3 *
4 * Copyright (C) 1999, 2000, 2001, 2002 David E. Nelson
5 * Previously maintained by Brian Beattie
6 *
7 * Current maintainer: Henning Meier-Geinitz <henning@meier-geinitz.de>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25/*
26 * For documentation, see Documentation/usb/scanner.txt.
27 * Website: http://www.meier-geinitz.de/kernel/
28 * Please contact the maintainer if your scanner is not detected by this
29 * driver automatically.
30 */
31
32#include <linux/module.h>
33#include <linux/kernel.h>
34#include <linux/errno.h>
35#include <asm/uaccess.h>
36#include <linux/init.h>
37#include <linux/slab.h>
38#include <linux/delay.h>
39#include <linux/ioctl.h>
40#include <linux/sched.h>
41#include <linux/smp_lock.h>
42#include <linux/devfs_fs_kernel.h>
43#include <linux/usb_scanner_ioctl.h>
44
45// #define DEBUG
46
47#define DRIVER_VERSION "0.4.16"
48#define DRIVER_DESC "USB Scanner Driver"
49
50#include <linux/usb.h>
51
52static __s32 vendor=-1, product=-1, read_timeout=0;
53
54MODULE_AUTHOR("Henning Meier-Geinitz, henning@meier-geinitz.de");
55MODULE_DESCRIPTION(DRIVER_DESC" "DRIVER_VERSION);
56MODULE_LICENSE("GPL");
57
58MODULE_PARM(vendor, "i");
59MODULE_PARM_DESC(vendor, "User specified USB idVendor");
60
61MODULE_PARM(product, "i");
62MODULE_PARM_DESC(product, "User specified USB idProduct");
63
64MODULE_PARM(read_timeout, "i");
65MODULE_PARM_DESC(read_timeout, "User specified read timeout in seconds");
66
67
68/* WARNING: These DATA_DUMP's can produce a lot of data. Caveat Emptor. */
69// #define RD_DATA_DUMP /* Enable to dump data - limited to 24 bytes */
70// #define WR_DATA_DUMP /* DEBUG does not have to be defined. */
71
72static struct usb_device_id scanner_device_ids [] = {
73	/* Acer (now Benq) */
74	{ USB_DEVICE(0x04a5, 0x1a20) },	/* Prisa 310U */
75	{ USB_DEVICE(0x04a5, 0x1a2a) },	/* Another 620U */
76	{ USB_DEVICE(0x04a5, 0x2022) },	/* 340U */
77	{ USB_DEVICE(0x04a5, 0x2040) },	/* 620U (!) */
78	{ USB_DEVICE(0x04a5, 0x2060) },	/* 620U & 640U (!)*/
79	{ USB_DEVICE(0x04a5, 0x207e) },	/* 640BU */
80	{ USB_DEVICE(0x04a5, 0x20b0) },	/* Benq 4300 */
81	{ USB_DEVICE(0x04a5, 0x20be) },	/* Unknown - Oliver Schwartz */
82	{ USB_DEVICE(0x04a5, 0x20c0) }, /* 1240UT, 1240U */
83	{ USB_DEVICE(0x04a5, 0x20de) },	/* S2W 3300U */
84	{ USB_DEVICE(0x04a5, 0x20fc) }, /* Benq 5000 */
85	{ USB_DEVICE(0x04a5, 0x20fe) },	/* Benq 5300 */
86	/* Agfa */
87	{ USB_DEVICE(0x06bd, 0x0001) },	/* SnapScan 1212U */
88	{ USB_DEVICE(0x06bd, 0x0002) },	/* SnapScan 1236U */
89	{ USB_DEVICE(0x06bd, 0x0100) },	/* SnapScan Touch */
90	{ USB_DEVICE(0x06bd, 0x2061) },	/* Another SnapScan 1212U (?)*/
91	{ USB_DEVICE(0x06bd, 0x208d) }, /* Snapscan e40 */
92	{ USB_DEVICE(0x06bd, 0x208f) }, /* SnapScan e50*/
93	{ USB_DEVICE(0x06bd, 0x2091) }, /* SnapScan e20 */
94	{ USB_DEVICE(0x06bd, 0x2093) }, /* SnapScan e10*/
95	{ USB_DEVICE(0x06bd, 0x2095) }, /* SnapScan e25 */
96	{ USB_DEVICE(0x06bd, 0x2097) }, /* SnapScan e26 */
97	{ USB_DEVICE(0x06bd, 0x20fd) }, /* SnapScan e52*/
98	{ USB_DEVICE(0x06bd, 0x20ff) }, /* SnapScan e42*/
99	/* Artec */
100	{ USB_DEVICE(0x05d8, 0x4001) },	/* Ultima 2000 */
101	{ USB_DEVICE(0x05d8, 0x4002) }, /* Ultima 2000 (GT6801 based) */
102	{ USB_DEVICE(0x05d8, 0x4003) }, /* E+ 48U */
103	{ USB_DEVICE(0x05d8, 0x4004) }, /* E+ Pro */
104	/* Avision */
105	{ USB_DEVICE(0x0638, 0x0268) }, /* iVina 1200U */
106	{ USB_DEVICE(0x0638, 0x0a10) },	/* iVina FB1600 (=Umax Astra 4500) */
107	{ USB_DEVICE(0x0638, 0x0a20) }, /* iVina FB1800 (=Umax Astra 4700) */
108	/* Benq: see Acer */
109	/* Brother */
110	{ USB_DEVICE(0x04f9, 0x010f) },	/* MFC 5100C */
111	{ USB_DEVICE(0x04f9, 0x0111) },	/* MFC 6800 */
112	/* Canon */
113	{ USB_DEVICE(0x04a9, 0x2201) }, /* CanoScan FB320U */
114	{ USB_DEVICE(0x04a9, 0x2202) }, /* CanoScan FB620U */
115	{ USB_DEVICE(0x04a9, 0x2204) }, /* CanoScan FB630U/FB636U */
116	{ USB_DEVICE(0x04a9, 0x2205) }, /* CanoScan FB1210U */
117	{ USB_DEVICE(0x04a9, 0x2206) }, /* CanoScan N650U/N656U */
118	{ USB_DEVICE(0x04a9, 0x2207) }, /* CanoScan N1220U */
119	{ USB_DEVICE(0x04a9, 0x2208) }, /* CanoScan D660U */
120	{ USB_DEVICE(0x04a9, 0x220a) },	/* CanoScan D2400UF */
121	{ USB_DEVICE(0x04a9, 0x220b) }, /* CanoScan D646U */
122	{ USB_DEVICE(0x04a9, 0x220c) },	/* CanoScan D1250U2 */
123	{ USB_DEVICE(0x04a9, 0x220d) }, /* CanoScan N670U/N676U/LIDE 20 */
124	{ USB_DEVICE(0x04a9, 0x220e) }, /* CanoScan N1240U/LIDE 30 */
125	{ USB_DEVICE(0x04a9, 0x220f) },	/* CanoScan 8000F */
126	{ USB_DEVICE(0x04a9, 0x2210) },	/* CanoScan 9900F */
127	{ USB_DEVICE(0x04a9, 0x2212) },	/* CanoScan 5000F */
128	{ USB_DEVICE(0x04a9, 0x2213) },	/* LIDE 50 */
129	{ USB_DEVICE(0x04a9, 0x2215) },	/* CanoScan 3000 */
130	{ USB_DEVICE(0x04a9, 0x3042) }, /* FS4000US */
131	/* Colorado -- See Primax/Colorado below */
132	/* Compaq */
133	{ USB_DEVICE(0x049f, 0x001a) },	/* S4 100 */
134	{ USB_DEVICE(0x049f, 0x0021) },	/* S200 */
135	/* Epson -- See Seiko/Epson below */
136	/* Fujitsu */
137	{ USB_DEVICE(0x04c5, 0x1041) }, /* fi-4220c USB/SCSI info:mza@mu-tec.de */
138	{ USB_DEVICE(0x04c5, 0x1042) }, /* fi-4120c USB/SCSI info:mza@mu-tec.de */
139	{ USB_DEVICE(0x04c5, 0x1029) }, /* fi-4010c USB AVision info:mza@mu-tec.de */
140	/* Genius */
141	{ USB_DEVICE(0x0458, 0x2001) },	/* ColorPage Vivid Pro */
142	{ USB_DEVICE(0x0458, 0x2007) },	/* ColorPage HR6 V2 */
143	{ USB_DEVICE(0x0458, 0x2008) }, /* ColorPage HR6 V2 */
144	{ USB_DEVICE(0x0458, 0x2009) }, /* ColorPage HR6A */
145	{ USB_DEVICE(0x0458, 0x2011) }, /* ColorPage Vivid3x */
146	{ USB_DEVICE(0x0458, 0x2013) }, /* ColorPage HR7 */
147	{ USB_DEVICE(0x0458, 0x2015) }, /* ColorPage HR7LE */
148	{ USB_DEVICE(0x0458, 0x2016) }, /* ColorPage HR6X */
149	{ USB_DEVICE(0x0458, 0x2018) },	/* ColorPage HR7X */
150	{ USB_DEVICE(0x0458, 0x201b) },	/* Colorpage Vivid 4x */
151	/* Hewlett Packard */
152	/* IMPORTANT: Hewlett-Packard multi-function peripherals (OfficeJet,
153	   Printer/Scanner/Copier (PSC), LaserJet, or PhotoSmart printer)
154	   should not be added to this table because they are accessed by a
155	   userspace driver (hpoj) */
156	{ USB_DEVICE(0x03f0, 0x0101) },	/* ScanJet 4100C */
157	{ USB_DEVICE(0x03f0, 0x0102) },	/* PhotoSmart S20 */
158	{ USB_DEVICE(0x03f0, 0x0105) },	/* ScanJet 4200C */
159	{ USB_DEVICE(0x03f0, 0x0201) },	/* ScanJet 6200C */
160	{ USB_DEVICE(0x03f0, 0x0205) },	/* ScanJet 3300C */
161	{ USB_DEVICE(0x03f0, 0x0305) }, /* ScanJet 4300C */
162	{ USB_DEVICE(0x03f0, 0x0401) },	/* ScanJet 5200C */
163	{ USB_DEVICE(0x03f0, 0x0405) }, /* ScanJet 3400C */
164	{ USB_DEVICE(0x03f0, 0x0505) }, /* ScanJet 2100C */
165	{ USB_DEVICE(0x03f0, 0x0601) },	/* ScanJet 6300C */
166	{ USB_DEVICE(0x03f0, 0x0605) },	/* ScanJet 2200C */
167	//	{ USB_DEVICE(0x03f0, 0x0701) },	/* ScanJet 5300C - NOT SUPPORTED - use hpusbscsi driver */
168	{ USB_DEVICE(0x03f0, 0x0705) }, /* ScanJet 4400C */
169	//	{ USB_DEVICE(0x03f0, 0x0801) },	/* ScanJet 7400C - NOT SUPPORTED - use hpusbscsi driver */
170	{ USB_DEVICE(0x03f0, 0x0805) },	/* ScanJet 4470c */
171	{ USB_DEVICE(0x03f0, 0x0901) }, /* ScanJet 2300C */
172	{ USB_DEVICE(0x03f0, 0x0a01) },	/* ScanJet 2400c */
173	{ USB_DEVICE(0x03F0, 0x1005) },	/* ScanJet 5400C */
174	{ USB_DEVICE(0x03F0, 0x1105) },	/* ScanJet 5470C */
175	{ USB_DEVICE(0x03f0, 0x1205) }, /* ScanJet 5550C */
176	{ USB_DEVICE(0x03f0, 0x1305) },	/* Scanjet 4570c */
177	//	{ USB_DEVICE(0x03f0, 0x1411) }, /* PSC 750 - NOT SUPPORTED - use hpoj userspace driver */
178	{ USB_DEVICE(0x03f0, 0x2005) },	/* ScanJet 3570c */
179	{ USB_DEVICE(0x03f0, 0x2205) },	/* ScanJet 3500c */
180	//	{ USB_DEVICE(0x03f0, 0x2f11) }, /* PSC 1210 - NOT SUPPORTED - use hpoj userspace driver */
181	/* Lexmark */
182	{ USB_DEVICE(0x043d, 0x002d) }, /* X70/X73 */
183	{ USB_DEVICE(0x043d, 0x003d) }, /* X83 */
184	/* LG Electronics */
185	{ USB_DEVICE(0x0461, 0x0364) },	/* Scanworks 600U (repackaged Primax?) */
186	/* Medion */
187	{ USB_DEVICE(0x0461, 0x0377) },	/* MD 5345 - repackaged Primax? */
188	/* Memorex */
189	{ USB_DEVICE(0x0461, 0x0346) }, /* 6136u - repackaged Primax ? */
190	/* Microtek */
191	{ USB_DEVICE(0x05da, 0x20a7) },	/* ScanMaker 5600 */
192	{ USB_DEVICE(0x05da, 0x20c9) }, /* ScanMaker 6700 */
193	{ USB_DEVICE(0x05da, 0x30ce) },	/* ScanMaker 3800 */
194	{ USB_DEVICE(0x05da, 0x30cf) },	/* ScanMaker 4800 */
195	{ USB_DEVICE(0x05da, 0x30d4) },	/* ScanMaker 3830 + 3840 */
196	{ USB_DEVICE(0x05da, 0x30d8) },	/* ScanMaker 5900 */
197	{ USB_DEVICE(0x04a7, 0x0224) },	/* Scanport 3000 (actually Visioneer?)*/
198	/* The following SCSI-over-USB Microtek devices are supported by the
199	   microtek driver: Enable SCSI and USB Microtek in kernel config */
200	//	{ USB_DEVICE(0x05da, 0x0099) },	/* ScanMaker X6 - X6U */
201	//	{ USB_DEVICE(0x05da, 0x0094) },	/* Phantom 336CX - C3 */
202	//	{ USB_DEVICE(0x05da, 0x00a0) },	/* Phantom 336CX - C3 #2 */
203	//	{ USB_DEVICE(0x05da, 0x009a) },	/* Phantom C6 */
204	//	{ USB_DEVICE(0x05da, 0x00a3) },	/* ScanMaker V6USL */
205	//	{ USB_DEVICE(0x05da, 0x80a3) },	/* ScanMaker V6USL #2 */
206	//	{ USB_DEVICE(0x05da, 0x80ac) },	/* ScanMaker V6UL - SpicyU */
207	/* Minolta */
208	{ USB_DEVICE(0x0686, 0x400d) }, /* Scan Dual III */
209	/* The following SCSI-over-USB Minolta devices are supported by the
210	   hpusbscsi driver: Enable SCSI and USB hpusbscsi in kernel config */
211	//	{ USB_DEVICE(0x0638, 0x026a) }, /* Minolta Dimage Scan Dual II */
212	//	{ USB_DEVICE(0x0686, 0x4004) }, /* Scan Elite II (need interrupt ep) */
213	/* Mustek */
214	{ USB_DEVICE(0x0400, 0x1000) },	/* BearPaw 1200 (National Semiconductor LM9831) */
215	{ USB_DEVICE(0x0400, 0x1001) }, /* BearPaw 2400 (National Semiconductor LM9832) */
216	{ USB_DEVICE(0x055f, 0x0001) },	/* ScanExpress 1200 CU */
217	{ USB_DEVICE(0x055f, 0x0002) },	/* ScanExpress 600 CU */
218	{ USB_DEVICE(0x055f, 0x0003) },	/* ScanExpress 1200 USB */
219	{ USB_DEVICE(0x055f, 0x0006) },	/* ScanExpress 1200 UB */
220	{ USB_DEVICE(0x055f, 0x0007) },	/* ScanExpress 1200 USB Plus */
221	{ USB_DEVICE(0x055f, 0x0008) }, /* ScanExpress 1200 CU Plus */
222	{ USB_DEVICE(0x055f, 0x0010) }, /* BearPaw 1200F */
223	{ USB_DEVICE(0x055f, 0x0210) },	/* ScanExpress A3 USB */
224	{ USB_DEVICE(0x055f, 0x0218) }, /* BearPaw 2400 TA */
225	{ USB_DEVICE(0x055f, 0x0219) }, /* BearPaw 2400 TA Plus */
226	{ USB_DEVICE(0x055f, 0x021c) }, /* BearPaw 1200 CU Plus */
227	{ USB_DEVICE(0x055f, 0x021d) }, /* Bearpaw 2400 CU Plus */
228	{ USB_DEVICE(0x055f, 0x021e) }, /* BearPaw 1200 TA/CS */
229	{ USB_DEVICE(0x055f, 0x0400) }, /* BearPaw 2400 TA PRO */
230	{ USB_DEVICE(0x055f, 0x0401) },	/* P 3600 A3 Pro */
231	{ USB_DEVICE(0x055f, 0x0409) },	/* BearPaw 2448TA Pro */
232	{ USB_DEVICE(0x055f, 0x0873) }, /* ScanExpress 600 USB */
233	{ USB_DEVICE(0x055f, 0x1000) }, /* BearPaw 4800 TA PRO */
234	//	{ USB_DEVICE(0x05d8, 0x4002) }, /* BearPaw 1200 CU and ScanExpress 1200 UB Plus (see Artec) */
235	/* Nikon */
236	{ USB_DEVICE(0x04b0, 0x4000) }, /* Coolscan LS 40 ED */
237	/* Pacific Image Electronics */
238	{ USB_DEVICE(0x05e3, 0x0120) },	/* PrimeFilm 1800u */
239	/* Plustek */
240	{ USB_DEVICE(0x07b3, 0x0001) },	/* 1212U */
241	{ USB_DEVICE(0x07b3, 0x0005) }, /* Unknown */
242	{ USB_DEVICE(0x07b3, 0x0007) }, /* Unknown */
243	{ USB_DEVICE(0x07b3, 0x000F) }, /* Unknown */
244	{ USB_DEVICE(0x07b3, 0x0010) }, /* OpticPro U12 */
245	{ USB_DEVICE(0x07b3, 0x0011) }, /* OpticPro U24 */
246	{ USB_DEVICE(0x07b3, 0x0012) }, /* Unknown */
247	{ USB_DEVICE(0x07b3, 0x0013) }, /* UT12 */
248	{ USB_DEVICE(0x07b3, 0x0014) }, /* Unknown */
249	{ USB_DEVICE(0x07b3, 0x0015) }, /* OpticPro U24 */
250	{ USB_DEVICE(0x07b3, 0x0016) }, /* Unknown */
251	{ USB_DEVICE(0x07b3, 0x0017) }, /* OpticPro UT12/UT16/UT24 */
252	{ USB_DEVICE(0x07b3, 0x0400) }, /* OpticPro 1248U */
253	{ USB_DEVICE(0x07b3, 0x0401) }, /* OpticPro 1248U (another one) */
254	{ USB_DEVICE(0x07b3, 0x0403) },	/* U16B */
255	{ USB_DEVICE(0x07b3, 0x0413) },	/* OpticSlim 1200 */
256	/* Primax/Colorado */
257	{ USB_DEVICE(0x0461, 0x0300) },	/* G2-300 #1 */
258	{ USB_DEVICE(0x0461, 0x0301) },	/* G2E-300 #1 */
259	{ USB_DEVICE(0x0461, 0x0302) },	/* G2-300 #2 */
260	{ USB_DEVICE(0x0461, 0x0303) },	/* G2E-300 #2 */
261	{ USB_DEVICE(0x0461, 0x0340) },	/* Colorado USB 9600 */
262	{ USB_DEVICE(0x0461, 0x0341) },	/* Colorado 600u */
263	{ USB_DEVICE(0x0461, 0x0347) },	/* Primascan Colorado 2600u */
264	{ USB_DEVICE(0x0461, 0x0360) },	/* Colorado USB 19200 */
265	{ USB_DEVICE(0x0461, 0x0361) },	/* Colorado 1200u */
266	{ USB_DEVICE(0x0461, 0x0380) },	/* G2-600 #1 */
267	{ USB_DEVICE(0x0461, 0x0381) },	/* ReadyScan 636i */
268	{ USB_DEVICE(0x0461, 0x0382) },	/* G2-600 #2 */
269	{ USB_DEVICE(0x0461, 0x0383) },	/* G2E-600 */
270	/* Prolink */
271	{ USB_DEVICE(0x06dc, 0x0014) }, /* Winscan Pro 2448U */
272	/* Reflecta  */
273	{ USB_DEVICE(0x05e3, 0x0120) },	/* iScan 1800 */
274	/* Relisis */
275	// { USB_DEVICE(0x0475, 0x0103) },	/* Episode - undetected endpoint */
276	{ USB_DEVICE(0x0475, 0x0210) }, /* Scorpio Ultra 3 */
277	/* Seiko/Epson Corp. */
278	{ USB_DEVICE(0x04b8, 0x0101) },	/* Perfection 636U and 636Photo */
279	{ USB_DEVICE(0x04b8, 0x0102) }, /* GT-2200 */
280	{ USB_DEVICE(0x04b8, 0x0103) },	/* Perfection 610 */
281	{ USB_DEVICE(0x04b8, 0x0104) },	/* Perfection 1200U and 1200Photo*/
282	{ USB_DEVICE(0x04b8, 0x0105) }, /* StylusScan 2000 */
283	{ USB_DEVICE(0x04b8, 0x0106) },	/* Stylus Scan 2500 */
284	{ USB_DEVICE(0x04b8, 0x0107) },	/* Expression 1600 */
285	{ USB_DEVICE(0x04b8, 0x0109) }, /* Expression 1640XL */
286	{ USB_DEVICE(0x04b8, 0x010a) }, /* Perfection 1640SU and 1640SU Photo */
287	{ USB_DEVICE(0x04b8, 0x010b) }, /* Perfection 1240U */
288	{ USB_DEVICE(0x04b8, 0x010c) }, /* Perfection 640U */
289	{ USB_DEVICE(0x04b8, 0x010e) }, /* Expression 1680 */
290	{ USB_DEVICE(0x04b8, 0x010f) }, /* Perfection 1250U */
291	{ USB_DEVICE(0x04b8, 0x0110) }, /* Perfection 1650 */
292	{ USB_DEVICE(0x04b8, 0x0112) }, /* Perfection 2450 - GT-9700 for the Japanese mkt */
293	{ USB_DEVICE(0x04b8, 0x0114) }, /* Perfection 660 */
294	{ USB_DEVICE(0x04b8, 0x011b) }, /* Perfection 2400 Photo */
295	{ USB_DEVICE(0x04b8, 0x011c) }, /* Perfection 3200 */
296	{ USB_DEVICE(0x04b8, 0x011d) }, /* Perfection 1260 */
297	{ USB_DEVICE(0x04b8, 0x011e) }, /* Perfection 1660 Photo */
298	{ USB_DEVICE(0x04b8, 0x011f) },	/* Perfection 1670 */
299	{ USB_DEVICE(0x04b8, 0x0801) }, /* Stylus CX5200 */
300	{ USB_DEVICE(0x04b8, 0x0802) }, /* Stylus CX3200 */
301	/* Siemens */
302	{ USB_DEVICE(0x0681, 0x0005) },	/* ID Mouse Professional */
303	{ USB_DEVICE(0x0681, 0x0010) },	/* Cherry FingerTIP ID Board - Sensor */
304	/* SYSCAN */
305	{ USB_DEVICE(0x0a82, 0x4600) }, /* TravelScan 460/464 */
306	/* Trust */
307	{ USB_DEVICE(0x05cb, 0x1483) }, /* CombiScan 19200 */
308	{ USB_DEVICE(0x05d8, 0x4006) }, /* Easy Webscan 19200 (repackaged Artec?) */
309	/* Umax */
310	{ USB_DEVICE(0x05d8, 0x4009) },	/* Astraslim (actually Artec?) */
311	{ USB_DEVICE(0x1606, 0x0010) },	/* Astra 1220U */
312	{ USB_DEVICE(0x1606, 0x0030) },	/* Astra 2000U */
313	{ USB_DEVICE(0x1606, 0x0060) }, /* Astra 3400U/3450U */
314	{ USB_DEVICE(0x1606, 0x0070) },	/* Astra 4400 */
315	{ USB_DEVICE(0x1606, 0x0130) }, /* Astra 2100U */
316	{ USB_DEVICE(0x1606, 0x0160) }, /* Astra 5400U */
317	{ USB_DEVICE(0x1606, 0x0230) },	/* Astra 2200U */
318	/* Visioneer */
319	{ USB_DEVICE(0x04a7, 0x0211) },	/* OneTouch 7600 USB */
320	{ USB_DEVICE(0x04a7, 0x0221) },	/* OneTouch 5300 USB */
321	{ USB_DEVICE(0x04a7, 0x0224) },	/* OneTouch 4800 USB */
322	{ USB_DEVICE(0x04a7, 0x0226) },	/* OneTouch 5800 USB */
323	{ USB_DEVICE(0x04a7, 0x0229) }, /* OneTouch 7100 USB */
324	{ USB_DEVICE(0x04a7, 0x022c) },	/* OneTouch 9020 USB */
325	{ USB_DEVICE(0x04a7, 0x0231) },	/* 6100 USB */
326	{ USB_DEVICE(0x04a7, 0x0311) },	/* 6200 EPP/USB */
327	{ USB_DEVICE(0x04a7, 0x0321) },	/* OneTouch 8100 EPP/USB */
328	{ USB_DEVICE(0x04a7, 0x0331) }, /* OneTouch 8600 EPP/USB */
329	{ USB_DEVICE(0x0461, 0x0345) }, /* 6200 (actually Primax?) */
330	{ USB_DEVICE(0x0461, 0x0371) }, /* Onetouch 8920 USB (actually Primax?) */
331	{ }				/* Terminating entry */
332};
333
334MODULE_DEVICE_TABLE (usb, scanner_device_ids);
335
336#define IS_EP_BULK(ep)  ((ep).bmAttributes == USB_ENDPOINT_XFER_BULK ? 1 : 0)
337#define IS_EP_BULK_IN(ep) (IS_EP_BULK(ep) && ((ep).bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)
338#define IS_EP_BULK_OUT(ep) (IS_EP_BULK(ep) && ((ep).bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT)
339#define IS_EP_INTR(ep) ((ep).bmAttributes == USB_ENDPOINT_XFER_INT ? 1 : 0)
340
341#define USB_SCN_MINOR(X) MINOR((X)->i_rdev) - SCN_BASE_MNR
342
343#ifdef DEBUG
344#define SCN_DEBUG(X) X
345#else
346#define SCN_DEBUG(X)
347#endif
348
349#define IBUF_SIZE 32768
350#define OBUF_SIZE 4096
351
352/* read_scanner timeouts -- RD_NAK_TIMEOUT * RD_EXPIRE = Number of seconds */
353#define RD_NAK_TIMEOUT (10*HZ)	/* Default number of X seconds to wait */
354#define RD_EXPIRE 12		/* Number of attempts to wait X seconds */
355
356
357/* USB bInterfaceClass used by Hewlett-Packard ScanJet 3300c and Genius HR6
358   USB - Vivid III */
359#define SCN_CLASS_SCANJET 16
360
361#define SCN_MAX_MNR 16		/* We're allocated 16 minors */
362#define SCN_BASE_MNR 48		/* USB Scanners start at minor 48 */
363
364static DECLARE_MUTEX (scn_mutex); /* Initializes to unlocked */
365
366struct scn_usb_data {
367	struct usb_device *scn_dev;
368	devfs_handle_t devfs;	/* devfs device */
369	struct urb scn_irq;
370	unsigned int ifnum;	/* Interface number of the USB device */
371	kdev_t scn_minor;	/* Scanner minor - used in disconnect() */
372	unsigned char button;	/* Front panel buffer */
373	char isopen;		/* Not zero if the device is open */
374	char present;		/* Not zero if device is present */
375	char *obuf, *ibuf;	/* transfer buffers */
376	char bulk_in_ep, bulk_out_ep, intr_ep; /* Endpoint assignments */
377	wait_queue_head_t rd_wait_q; /* read timeouts */
378	struct semaphore sem; /* lock to prevent concurrent reads or writes */
379	unsigned int rd_nak_timeout; /* Seconds to wait before read() timeout. */
380};
381
382extern devfs_handle_t usb_devfs_handle;
383
384static struct scn_usb_data *p_scn_table[SCN_MAX_MNR] = { NULL, /* ... */};
385
386static struct usb_driver scanner_driver;
387