Original kernel 2.4.37.5
[tomato.git] / release / src / linux / linux / Documentation / usb / scanner.txt
blob2fa76311fe9a8594217544fc2be2c56897bdb58b
1 Copyright (C) 1999, 2000 David E. Nelson <dnelson@jump.net>
2 Updated 2003 by Henning Meier-Geinitz <henning@meier-geinitz.de>
5 OVERVIEW
7 This README addresses issues regarding how to configure the kernel to access a
8 USB scanner.  Although the driver was originally conceived for USB HP
9 scanners, it's general enough so that it can be used with most other USB
10 scanners.  Also, one can pass the USB Vendor and Product IDs using module
11 parameters for unknown scanners.
13 There are two drivers for SCSI-over-USB scanners: 
14 * The "hpusbscsi" module for Hewlett-Packard 53xx series, Hewlett-Packard 7400,
15   Minolta Scan Dual II, Minolta Elite II
16 * The "microtek" module for the Microtek Scanmaker X6
18 In addition to the kernel driver, user-space tools like SANE are necessary to
19 actually use the scanner.  SANE ("Scanner Access Now Easy") provides drivers
20 for a variety of USB scanners.  See the appropriate SANE man page for details,
21 e.g. man sane-usb and man sane-hp (for HP scanners).
23 NOTE: Just because a product is detected by this driver does not mean that
24 applications exist that support the product.  It's in the hopes that this will
25 allow developers a means to produce applications that will support the listed
26 USB products.
29 ADDITIONAL INFORMATION
31 http://www.linux-usb.org/           (General information, mailing lists, links)
32 http://www.mostang.com/sane/        (SANE user-space tools)
33 http://www.meier-geinitz.de/kernel/ (USB scanner driver information and patches)
36 REQUIREMENTS
38 A host with a USB port.  Ideally, either a UHCI (Intel), OHCI (Compaq and
39 others) or EHCI hardware should work.  
41 Using "make menuconfig" or your preferred method for configuring the kernel,
42 select "Support for USB", "OHCI/UHCI/EHCI" depending on your hardware, "USB
43 Scanner support", and "Preliminary USB device filesystem".  Compile and
44 install the modules (you may need to execute "depmod -a" to update the module
45 dependencies).  If any of the USB sections were compiled into the kernel, a
46 reboot is necessary.  NOTE: Updating the boot disk with "lilo" may also be
47 required.  Testing was performed only as modules, YMMV.
49 Up to 16 scanners can be connected/used simultaneously.  If devfs support is
50 enabled, see next section.  Otherwise, the device files must be created
51 manually if they don't exist yet, either by MAKEDEV or mknod.
53 MAKEDEV method:
54   cd /dev
55   MAKEDEV usb
56   Check that the device files "/dev/usb/scanner0" - "/dev/usb/scanner15" have
57   been created.
59 mknod method:
60   mknod /dev/usb/scanner0 c 180 48
61   mknod /dev/usb/scanner1 c 180 49
62                   . 
63                   .
64   mknod /dev/usb/scanner15 c 180 63
66 Set appropriate permissions for /dev/usb/scanner[0-15] (don't forget
67 about group and world permissions).  Both read and write permissions
68 are required for proper operation.  For example:
69   chmod 666 /dev/usb/scanner0
71 Load the appropriate modules (if compiled as modules):
73   modprobe usb-ohci (or uhci, usb-uhci, ehci)
74   modprobe scanner
77 DEVFS
79 The later versions of the Linux kernel (2.4.8'ish) included a dynamic
80 device filesystem call "devfs".  With devfs, there is no need to
81 create the device files as explained above; instead, they are
82 dynamically created for you.  For USB Scanner, the device is created
83 in /dev/usb/scannerX where X can range from 0 to 15 depending on the
84 number of scanners connected to the system.
86 To see if you have devfs, issue the command "cat /proc/filesytems".
87 If devfs is listed you should be ready to go.  You should also have a
88 process running called "devfsd".  In order to make sure, issue the
89 command "ps aux | grep '[d]evfsd'".
92 CONCLUSION
94 That's it.  SANE should now be able to access the device.  To make sure the
95 device was detected, use "cat /proc/bus/usb/devices".  Your scanner should be
96 listed and the line starting with "I:" should look similar to this example:
98   I:  If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=usbscanner
100 The important part is "Driver=usbscanner".  If it reads "Driver=(none)", the
101 USB scanner driver didn't recognize the scanner.  Have a look at the MODULE
102 PARAMETERS section for what to do in this case.
104 For more details on the format of "/proc/bus/usb/devices" see
105 Documentation/usb/proc_usb_info.txt.
108 MESSAGES
110 usb_control/bulk_msg: timeout -- On occasions this message will appear
111 in "/var/adm/messages", on the console, or both depending on how
112 your system is configured.  This is a side effect that scanners are
113 sometimes very slow at warming up and/or initializing.  In most cases,
114 however, only several of these messages should appear and is generally
115 considered to be normal.  
117 excessive NAK's received -- This message should be considered abnormal
118 and generally indicates that the USB system is unable to communicate
119 with the scanner for some particular reason.
121 probe_scanner: Undetected endpoint -- The USB Scanner driver is fairly
122 general when it comes to communicating to scanners.  Unfortunately,
123 some vendors have designed their scanners in one way or another that
124 this driver doesn't account for.
126 probe_scanner: Endpoint determination failed -- This means that the
127 driver is unable to detect a supported configuration for means to
128 communicate with the scanner.  See also "probe_scanner: Undetected
129 endpoint".
131 funky result -- Most of the time the data flow between the computer
132 and the scanner goes smoothly.  However, due to whatever reason,
133 whether it be solar flares or stray neutrons, sometimes the
134 communications don't work as expected.  The driver tries to handle
135 most types of errors but not all.  When this message is seen,
136 something weird happened.  Please contact the mailing list (see
137 CONTACT section for details).
140 MODULE PARAMETERS
142 If you have a device that you wish to experiment with or try using
143 this driver with, but the Vendor and Product IDs are not coded in,
144 don't despair.  If the driver was compiled as a module, you can pass
145 options to the driver.  Simply add 
147   options scanner vendor=0x#### product=0x****
149 to the /etc/modules.conf file replacing the #'s and the *'s with the
150 correct IDs.  The IDs can be retrieved from the messages file or
151 using "cat /proc/bus/usb/devices".
153 If the default timeout is too low, i.e. there are frequent "timeout" messages,
154 you may want to increase the timeout manually by using the parameter
155 "read_timeout".  The time is given in seconds.  This is an example for
156 modules.conf with a timeout of 60 seconds:
158   options scanner read_timeout=60
160 If the "scanner" module is already loaded into memory, it must be reloaded for
161 the module parameters to take effect.  In essence, "rmmod scanner; modprobe
162 scanner" must be performed.
165 BUGS
167 Just look at the list of fixes in the source files. 
170 CONTACT
172 For discussion and patches, use the linux-usb mailing list. Information
173 about the list can be found on http://www.linux-usb.org/.
176 CHANGES
178 - Added information about read_timeout
179 - Added more details about /proc/bus/usb/devices
180 - Added/updated links
181 - Added pointers two "special" scanner drivers
182 - Reordering, spell-checking, formatting
183 - Used /dev/usb/scanner[0-15] instead of /dev/usbscanner[0-15]
184 - Removed some basic USB configuration stuff
185 - Added EHCI
186 - Removed some more references to HP
187 - Amended for linux-2.4.12
188 - Updated devfs support
189 - Amended for linux-2.3.99-pre6-3
190 - Appended hp_scan.c to end of this README
191 - Removed most references to HP
192 - Updated uhci/ohci host controller info
193 - Updated support for multiple scanner support
194 - Updated supported scanners list
195 - Updated usbdevfs info
196 - Spellcheck
199 HP TEST PROGRAM
201 There is a small test program (hp_scan.c -- appended below) that can
202 be used to test the scanner device if it's an HP scanner that supports
203 SCL (Scanner Control Language).  Known HP scanner that support SCL are
204 the 4100, 5200, 6200, the 6300 -- note that the 4200 is *not*
205 supported since it does not understand SCL; it's also strongly
206 suspected that the 3300 and the PhotoSmart S20 are not SCL compliant.
207 Hp_scan.c's purpose is to test the driver without having to
208 retrieve/configure SANE.  Hp_scan.c will scan the entire bed and put
209 the output into a file called "out.dat" in the current directory.  The
210 data in the file is raw data so it's not very useful for imaging.
212 --------------- snip -- hp_scan.c -- snip ---------------
215 This is a really crude attempt at writing a short test program.  It's
216 mostly only to be used to test connectivity with USB HP scanners that
217 understand SCL.  Currently, the supported models are 4100C, 5200C,
218 6200C, and the 6300C.  Note that the 4200C is *NOT* acceptable.
220 Copyright (C) David E. Nelson <dnelson@jump.net>, 1999
222 This program is free software; you can redistribute it and/or modify
223 it under the terms of the GNU General Public License as published by
224 the Free Software Foundation; either version 2 of the License, or (at
225 your option) any later version.
229 #include <stdio.h>
230 #include <stdlib.h>
231 #include <error.h>
232 #include <unistd.h>
233 #include <fcntl.h>
236    Gray Output produces about a 8945400 byte file.
237    Color Output produces a 26836200 byte file. 
238    
239    To compile: gcc -o hp_scan hp_scan.c
242 // #define COLOR /* Undef to scan GrayScale */
244 int send_cmd(int, const char *, int);
245 int read_cmd(int, char *, int);
248 main(void) {
250         ssize_t cnt = 0, total_cnt = 0;
252         FILE *fpout;
254         int fp;
255         int data_size = 32768;
257         char *data;
259         static char reset_cmd[] = {'\x1b','E'};
261 #ifdef COLOR
262         static char data_type_cmd[] = {'\x1b','*','a','5','T'}; /* Color */
263         static char data_width_cmd[] = {'\x1b','*','a','2','4','G'}; /* 24 Bit Color */
264 #else
265         static char data_type_cmd[] = {'\x1b','*','a','4','T'}; /* Gray */
266         static char data_width_cmd[] = {'\x1b','*','a','8','G'}; /* 8 Bit Gray */
267 #endif
269         static char query_cmd[] = {'\x1b', '*', 's', '2', '5', '7', 'E'};
270         static char start_scan_cmd[] = {'\x1b','*','f','0','S'};
271         
272         if(!(data=malloc(data_size))) {
273                 perror("malloc failed");
274                 exit (1);
275         }
276         
277         if((fp=open("/dev/usb/scanner0", O_RDWR)) < 0) {
278                 perror("Unable to open scanner device");
279                 exit (1);
280         }
282         if((fpout=fopen("out.dat", "w+")) == NULL) {
283                 perror("Unable to open ouput file");
284                 exit(1);
285         }
287         send_cmd(fp, reset_cmd, sizeof(reset_cmd));
288         send_cmd(fp, data_type_cmd, sizeof(data_type_cmd));
289         send_cmd(fp, data_width_cmd, sizeof(data_width_cmd));
290         send_cmd(fp, start_scan_cmd, sizeof(start_scan_cmd));
292         while ((cnt = read(fp, data, data_size)) > 0) {
293                 printf("Read: %u\n", cnt); 
294                 if(fwrite(data, sizeof(char), cnt, fpout) < 0) {
295                         perror("Write to output file failed");
296                         exit (1);
297                 }
298                 total_cnt += cnt;
299         }
300         if (cnt < 0) {
301                 perror("Read from scanner failed");
302                 exit (1);
303         }
305         printf("\nRead %lu bytes.\n", total_cnt);
307         send_cmd(fp, reset_cmd, sizeof(reset_cmd));
309         close(fp);
310         fclose(fpout);
311         return (0);
315 send_cmd(int fp, const char * cmd, int length) {
317         int result;
318         int x;
320         if((result = write(fp, cmd, length)) != length) {
321                 printf ("Write warning: %d bytes requested, %d written\n");
322         } else if (result < 0) {
323                 perror ("send_cmd failure");
324                 exit (1);
325         }
326         return (result);
328         
330 read_cmd(int fp, char * response, int length) {
332         return read(fp, response, length);