Merge with Linux 2.5.48.
[linux-2.6/linux-mips.git] / drivers / usb / image / scanner.h
blobdf0bd2dd420c8235beb284e864796bbabc69682c
1 /*
2 * Driver for USB Scanners (linux-2.4.18)
4 * Copyright (C) 1999, 2000, 2001, 2002 David E. Nelson
6 * Brian Beattie <beattie@beattie-home.net>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * 05/21/02 Currently maintained by Brian Beattie <beattie@beattie-home.net>
25 */
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/errno.h>
30 #include <asm/uaccess.h>
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/delay.h>
34 #include <linux/ioctl.h>
35 #include <linux/sched.h>
36 #include <linux/smp_lock.h>
37 #include <linux/devfs_fs_kernel.h>
39 // #define DEBUG
41 /* Enable this to support the older ioctl interfaces scanners that
42 * a PV8630 Scanner-On-Chip. The prefered method is the
43 * SCANNER_IOCTL_CTRLMSG ioctl.
45 // #define PV8630
47 #define DRIVER_VERSION "0.4.6"
48 #define DRIVER_DESC "USB Scanner Driver"
50 #include <linux/usb.h>
52 static __s32 vendor=-1, product=-1, read_timeout=0;
54 MODULE_AUTHOR("Brian Beattie, beattie@beattie-home.net");
55 MODULE_DESCRIPTION(DRIVER_DESC" "DRIVER_VERSION);
56 MODULE_LICENSE("GPL");
58 MODULE_PARM(vendor, "i");
59 MODULE_PARM_DESC(vendor, "User specified USB idVendor");
61 MODULE_PARM(product, "i");
62 MODULE_PARM_DESC(product, "User specified USB idProduct");
64 MODULE_PARM(read_timeout, "i");
65 MODULE_PARM_DESC(read_timeout, "User specified read timeout in seconds");
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. */
72 static struct usb_device_id scanner_device_ids [] = {
73 /* Acer */
74 { USB_DEVICE(0x04a5, 0x2060) }, /* Prisa Acerscan 620U & 640U (!)*/
75 { USB_DEVICE(0x04a5, 0x2040) }, /* Prisa AcerScan 620U (!) */
76 { USB_DEVICE(0x04a5, 0x20c0) }, /* Prisa AcerScan 1240UT */
77 { USB_DEVICE(0x04a5, 0x2022) }, /* Vuego Scan Brisa 340U */
78 { USB_DEVICE(0x04a5, 0x1a20) }, /* Unknown - Oliver Schwartz */
79 { USB_DEVICE(0x04a5, 0x1a2a) }, /* Unknown - Oliver Schwartz */
80 { USB_DEVICE(0x04a5, 0x207e) }, /* Prisa 640BU */
81 { USB_DEVICE(0x04a5, 0x20be) }, /* Unknown - Oliver Schwartz */
82 { USB_DEVICE(0x04a5, 0x20c0) }, /* Unknown - Oliver Schwartz */
83 { USB_DEVICE(0x04a5, 0x20de) }, /* S2W 3300U */
84 { USB_DEVICE(0x04a5, 0x20b0) }, /* Unknown - Oliver Schwartz */
85 { USB_DEVICE(0x04a5, 0x20fe) }, /* Unknown - Oliver Schwartz */
86 /* Agfa */
87 { USB_DEVICE(0x06bd, 0x0001) }, /* SnapScan 1212U */
88 { USB_DEVICE(0x06bd, 0x0002) }, /* SnapScan 1236U */
89 { USB_DEVICE(0x06bd, 0x2061) }, /* Another SnapScan 1212U (?)*/
90 { USB_DEVICE(0x06bd, 0x0100) }, /* SnapScan Touch */
91 { USB_DEVICE(0x06bd, 0x2091) }, /* SnapScan e20 */
92 { USB_DEVICE(0x06bd, 0x2095) }, /* SnapScan e25 */
93 { USB_DEVICE(0x06bd, 0x2097) }, /* SnapScan e26 */
94 { USB_DEVICE(0x06bd, 0x208d) }, /* Snapscan e40 */
95 /* Canon */
96 { USB_DEVICE(0x04a9, 0x2202) }, /* CanoScan FB620U */
97 { USB_DEVICE(0x04a9, 0x2204) }, /* CanoScan FB630U/FB636U */
98 { USB_DEVICE(0x04a9, 0x2206) }, /* CanoScan N650U/N656U */
99 { USB_DEVICE(0x04a9, 0x2207) }, /* CanoScan N1220U */
100 { USB_DEVICE(0x04a9, 0x2208) }, /* CanoScan D660U */
101 { USB_DEVICE(0x04a9, 0x220b) }, /* D646U */
102 /* Colorado -- See Primax/Colorado below */
103 /* Epson -- See Seiko/Epson below */
104 /* Genius */
105 { USB_DEVICE(0x0458, 0x2001) }, /* ColorPage-Vivid Pro */
106 { USB_DEVICE(0x0458, 0x2007) }, /* ColorPage HR6 V2 */
107 { USB_DEVICE(0x0458, 0x2008) }, /* Unknown */
108 { USB_DEVICE(0x0458, 0x2009) }, /* Unknown */
109 { USB_DEVICE(0x0458, 0x2013) }, /* Unknown */
110 { USB_DEVICE(0x0458, 0x2015) }, /* Unknown */
111 { USB_DEVICE(0x0458, 0x2016) }, /* Unknown */
112 /* Hewlett Packard */
113 { USB_DEVICE(0x03f0, 0x0205) }, /* 3300C */
114 { USB_DEVICE(0x03f0, 0x0405) }, /* 3400C */
115 { USB_DEVICE(0x03f0, 0x0101) }, /* 4100C */
116 { USB_DEVICE(0x03f0, 0x0105) }, /* 4200C */
117 { USB_DEVICE(0x03f0, 0x0305) }, /* 4300C */
118 { USB_DEVICE(0x03f0, 0x0705) }, /* 4400C */
119 { USB_DEVICE(0x03f0, 0x0102) }, /* PhotoSmart S20 */
120 { USB_DEVICE(0x03f0, 0x0401) }, /* 5200C */
121 // { USB_DEVICE(0x03f0, 0x0701) }, /* 5300C - NOT SUPPORTED - see http://www.neatech.nl/oss/HP5300C/ */
122 { USB_DEVICE(0x03f0, 0x0201) }, /* 6200C */
123 { USB_DEVICE(0x03f0, 0x0601) }, /* 6300C */
124 { USB_DEVICE(0x03f0, 0x605) }, /* 2200C */
125 /* iVina */
126 { USB_DEVICE(0x0638, 0x0268) }, /* 1200U */
127 /* Lifetec */
128 { USB_DEVICE(0x05d8, 0x4002) }, /* Lifetec LT9385 */
129 /* Memorex */
130 { USB_DEVICE(0x0461, 0x0346) }, /* 6136u - repackaged Primax ? */
131 /* Microtek -- No longer supported - Enable SCSI and USB Microtek in kernel config */
132 // { USB_DEVICE(0x05da, 0x0099) }, /* ScanMaker X6 - X6U */
133 // { USB_DEVICE(0x05da, 0x0094) }, /* Phantom 336CX - C3 */
134 // { USB_DEVICE(0x05da, 0x00a0) }, /* Phantom 336CX - C3 #2 */
135 // { USB_DEVICE(0x05da, 0x009a) }, /* Phantom C6 */
136 // { USB_DEVICE(0x05da, 0x00a3) }, /* ScanMaker V6USL */
137 // { USB_DEVICE(0x05da, 0x80a3) }, /* ScanMaker V6USL #2 */
138 // { USB_DEVICE(0x05da, 0x80ac) }, /* ScanMaker V6UL - SpicyU */
139 /* Minolta */
140 // { USB_DEVICE(0x0638,0x026a) }, /* Minolta Dimage Scan Dual II */
141 /* Mustek */
142 { USB_DEVICE(0x055f, 0x0001) }, /* 1200 CU */
143 { USB_DEVICE(0x0400, 0x1000) }, /* BearPaw 1200 */
144 { USB_DEVICE(0x055f, 0x0002) }, /* 600 CU */
145 { USB_DEVICE(0x055f, 0x0873) }, /* 600 USB */
146 { USB_DEVICE(0x055f, 0x0003) }, /* 1200 USB */
147 { USB_DEVICE(0x055f, 0x0006) }, /* 1200 UB */
148 { USB_DEVICE(0x0400, 0x1001) }, /* BearPaw 2400 */
149 { USB_DEVICE(0x055f, 0x0008) }, /* 1200 CU Plus */
150 { USB_DEVICE(0x0ff5, 0x0010) }, /* BearPaw 1200F */
151 { USB_DEVICE(0x055f, 0x0218) }, /* BearPaw 2400 TA */
152 { USB_DEVICE(0x05d8, 0x4002) }, /* 1200 CU and 1200 UB Plus */
153 /* Plustek */
154 { USB_DEVICE(0x07b3, 0x0017) }, /* OpticPro UT12 */
155 { USB_DEVICE(0x07b3, 0x0011) }, /* OpticPro UT24 */
156 { USB_DEVICE(0x07b3, 0x0005) }, /* Unknown */
157 { USB_DEVICE(0x07b3, 0x0007) }, /* Unknown */
158 { USB_DEVICE(0x07b3, 0x000F) }, /* Unknown */
159 { USB_DEVICE(0x07b3, 0x0010) }, /* Unknown */
160 { USB_DEVICE(0x07b3, 0x0012) }, /* Unknown */
161 { USB_DEVICE(0x07b3, 0x0013) }, /* Unknown */
162 { USB_DEVICE(0x07b3, 0x0014) }, /* Unknown */
163 { USB_DEVICE(0x07b3, 0x0015) }, /* Unknown */
164 { USB_DEVICE(0x07b3, 0x0016) }, /* Unknown */
165 { USB_DEVICE(0x07b3, 0x0012) }, /* Unknown */
166 /* Primax/Colorado */
167 { USB_DEVICE(0x0461, 0x0300) }, /* G2-300 #1 */
168 { USB_DEVICE(0x0461, 0x0380) }, /* G2-600 #1 */
169 { USB_DEVICE(0x0461, 0x0301) }, /* G2E-300 #1 */
170 { USB_DEVICE(0x0461, 0x0381) }, /* ReadyScan 636i */
171 { USB_DEVICE(0x0461, 0x0302) }, /* G2-300 #2 */
172 { USB_DEVICE(0x0461, 0x0382) }, /* G2-600 #2 */
173 { USB_DEVICE(0x0461, 0x0303) }, /* G2E-300 #2 */
174 { USB_DEVICE(0x0461, 0x0383) }, /* G2E-600 */
175 { USB_DEVICE(0x0461, 0x0340) }, /* Colorado USB 9600 */
176 // { USB_DEVICE(0x0461, 0x0360) }, /* Colorado USB 19200 - undetected endpoint */
177 { USB_DEVICE(0x0461, 0x0341) }, /* Colorado 600u */
178 { USB_DEVICE(0x0461, 0x0361) }, /* Colorado 1200u */
179 /* Relisis */
180 // { USB_DEVICE(0x0475, 0x0103) }, /* Episode - undetected endpoint */
181 /* Seiko/Epson Corp. */
182 { USB_DEVICE(0x04b8, 0x0101) }, /* Perfection 636U and 636Photo */
183 { USB_DEVICE(0x04b8, 0x0103) }, /* Perfection 610 */
184 { USB_DEVICE(0x04b8, 0x0104) }, /* Perfection 1200U and 1200Photo*/
185 { USB_DEVICE(0x04b8, 0x0106) }, /* Stylus Scan 2500 */
186 { USB_DEVICE(0x04b8, 0x0107) }, /* Expression 1600 */
187 { USB_DEVICE(0x04b8, 0x010a) }, /* Perfection 1640SU and 1640SU Photo */
188 { USB_DEVICE(0x04b8, 0x010b) }, /* Perfection 1240U */
189 { USB_DEVICE(0x04b8, 0x010c) }, /* Perfection 640U */
190 { USB_DEVICE(0x04b8, 0x010e) }, /* Expression 1680 */
191 { USB_DEVICE(0x04a9, 0x2204) }, /* FB630U */
192 { USB_DEVICE(0x04b8, 0x0110) }, /* Perfection 1650 */
193 { USB_DEVICE(0x04b8, 0x0112) }, /* Perfection 2450 - GT-9700 for the Japanese mkt */
194 { USB_DEVICE(0x04b8, 0x0114) }, /* Perfection 660 */
195 { USB_DEVICE(0x04b8, 0x011b) }, /* Perfection 2400 Photo */
196 { USB_DEVICE(0x04b8, 0x011e) }, /* Perfection 1660 Photo */
197 /* Umax */
198 { USB_DEVICE(0x1606, 0x0010) }, /* Astra 1220U */
199 { USB_DEVICE(0x1606, 0x0030) }, /* Astra 2000U */
200 { USB_DEVICE(0x1606, 0x0130) }, /* Astra 2100U */
201 { USB_DEVICE(0x1606, 0x0230) }, /* Astra 2200U */
202 /* Visioneer */
203 { USB_DEVICE(0x04a7, 0x0221) }, /* OneTouch 5300 USB */
204 { USB_DEVICE(0x04a7, 0x0211) }, /* OneTouch 7600 USB */
205 { USB_DEVICE(0x04a7, 0x0231) }, /* 6100 USB */
206 { USB_DEVICE(0x04a7, 0x0311) }, /* 6200 EPP/USB */
207 { USB_DEVICE(0x04a7, 0x0321) }, /* OneTouch 8100 EPP/USB */
208 { USB_DEVICE(0x04a7, 0x0331) }, /* OneTouch 8600 EPP/USB */
209 { } /* Terminating entry */
212 MODULE_DEVICE_TABLE (usb, scanner_device_ids);
214 #define IS_EP_BULK(ep) ((ep)->bmAttributes == USB_ENDPOINT_XFER_BULK ? 1 : 0)
215 #define IS_EP_BULK_IN(ep) (IS_EP_BULK(ep) && ((ep)->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)
216 #define IS_EP_BULK_OUT(ep) (IS_EP_BULK(ep) && ((ep)->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT)
217 #define IS_EP_INTR(ep) ((ep)->bmAttributes == USB_ENDPOINT_XFER_INT ? 1 : 0)
219 #define USB_SCN_MINOR(X) minor((X)->i_rdev) - SCN_BASE_MNR
221 #ifdef DEBUG
222 #define SCN_DEBUG(X) X
223 #else
224 #define SCN_DEBUG(X)
225 #endif
227 #define IBUF_SIZE 32768
228 #define OBUF_SIZE 4096
230 /* read_scanner timeouts -- RD_NAK_TIMEOUT * RD_EXPIRE = Number of seconds */
231 #define RD_NAK_TIMEOUT (10*HZ) /* Default number of X seconds to wait */
232 #define RD_EXPIRE 12 /* Number of attempts to wait X seconds */
235 /* FIXME: These are NOT registered ioctls()'s */
236 #ifdef PV8630
237 #define PV8630_IOCTL_INREQUEST 69
238 #define PV8630_IOCTL_OUTREQUEST 70
239 #endif /* PV8630 */
242 /* read vendor and product IDs from the scanner */
243 #define SCANNER_IOCTL_VENDOR _IOR('U', 0x20, int)
244 #define SCANNER_IOCTL_PRODUCT _IOR('U', 0x21, int)
245 /* send/recv a control message to the scanner */
246 #define SCANNER_IOCTL_CTRLMSG _IOWR('U', 0x22, struct usb_ctrlrequest)
249 #ifdef CONFIG_USB_DYNAMIC_MINORS
250 #define SCN_MAX_MNR 256
251 #define SCN_BASE_MNR 0
252 #else
253 #define SCN_MAX_MNR 16 /* We're allocated 16 minors */
254 #define SCN_BASE_MNR 48 /* USB Scanners start at minor 48 */
255 #endif
257 static DECLARE_MUTEX (scn_mutex); /* Initializes to unlocked */
259 struct scn_usb_data {
260 struct usb_device *scn_dev;
261 devfs_handle_t devfs; /* devfs device */
262 struct urb *scn_irq;
263 unsigned int ifnum; /* Interface number of the USB device */
264 int scn_minor; /* Scanner minor - used in disconnect() */
265 unsigned char button; /* Front panel buffer */
266 char isopen; /* Not zero if the device is open */
267 char present; /* Not zero if device is present */
268 char *obuf, *ibuf; /* transfer buffers */
269 char bulk_in_ep, bulk_out_ep, intr_ep; /* Endpoint assignments */
270 wait_queue_head_t rd_wait_q; /* read timeouts */
271 struct semaphore sem; /* lock to prevent concurrent reads or writes */
272 unsigned int rd_nak_timeout; /* Seconds to wait before read() timeout. */
275 extern devfs_handle_t usb_devfs_handle;
277 static struct scn_usb_data *p_scn_table[SCN_MAX_MNR] = { NULL, /* ... */};
279 static struct usb_driver scanner_driver;