1Copyright (C) 1999, 2000 David E. Nelson <dnelson@jump.net>
2
3April 26, 2000
4
5CHANGES
6
7- Amended for linux-2.4.12
8- Updated devfs support
9- Amended for linux-2.3.99-pre6-3
10- Appended hp_scan.c to end of this README
11- Removed most references to HP
12- Updated uhci/ohci host controller info
13- Updated support for multiple scanner support
14- Updated supported scanners list
15- Updated usbdevfs info
16- Spellcheck
17
18OVERVIEW
19
20This README addresses issues regarding how to configure the kernel
21to access a USB scanner.  Although the driver was originally conceived
22for USB HP scanners, it's general enough so that it can be used with
23other scanners.  Also, one can now pass the USB Vendor and Product
24ID's using module parameters for unknown scanners.  Refer to the
25document scanner-hp-sane.txt for guidance on how to configure SANE to
26use a USB HP Scanner.
27
28
29ADDITIONAL INFORMATION
30
31http://www.linux-usb.org/
32
33
34REQUIREMENTS
35
36A host with a USB port.  Ideally, either a UHCI (Intel) or OHCI
37(Compaq and others) hardware port should work.  At the time of this
38writing, there are two UHCI drivers and one OHCI.
39
40A Linux kernel with USB support enabled or a backported version to
41linux-2.2.x.  See http://www.linux-usb.org for more information on
42accomplishing this.
43
44'lspci' which is only needed to determine the type of USB hardware
45available/installed in your machine.
46
47CONFIGURATION
48
49Using `lspci -v`, determine the type of USB hardware available/installed.
50
51  If you see something like:
52
53    USB Controller: ......
54    Flags: .....
55    I/O ports at ....
56
57  Then you have a UHCI based controller.
58
59  If you see something like:
60
61     USB Controller: .....
62     Flags: ....
63     Memory at .....
64
65  Then you have a OHCI based controller.
66
67Using `make menuconfig` or your preferred method for configuring the
68kernel, select 'Support for USB', 'OHCI/UHCI' depending on your
69hardware (determined from the steps above), 'USB Scanner support', and
70'Preliminary USB device filesystem'.  Compile and install the modules
71(you may need to execute `depmod -a` to update the module
72dependencies). If any of the USB sections were compiled into the
73kernel, a reboot is necessary. NOTE: Updating the boot disk with
74'lilo' may also be required. Testing was performed only as modules,
75YMMV.
76
77Beginning with version 0.4 of the driver, up to 16 scanners can be
78connected/used simultaneously.  For devfs support, see next section.
79If you intend to use more than one scanner at a time w/o devfs support:
80
81   Add a device for the USB scanner:
82	`mknod /dev/usbscanner0 c 180 48`
83	`mknod /dev/usbscanner1 c 180 49`
84                      . 
85                      .
86	`mknod /dev/usbscanner15 c 180 63`
87
88
89If you foresee using only one scanner it is best to:
90	`mknod /dev/usbscanner0 c 180 48`
91	`ln -s /dev/usbscanner0 /dev/usbscanner`
92
93
94Set appropriate permissions for /dev/usbscanner[0-15] (don't forget
95about group and world permissions).  Both read and write permissions
96are required for proper operation. For example:
97	`chmod 666 /dev/usbscanner0`
98
99Load the appropriate modules (if compiled as modules):
100
101  OHCI:
102    modprobe usb-ohci
103    modprobe scanner
104
105  UHCI:
106    modprobe usb-uhci
107    modprobe scanner
108
109DEVFS
110
111The later versions of the Linux kernel (2.4.8'ish) included a dynamic
112device filesystem call 'devfs'.  With devfs, there is no need to
113create the device files as explained above; instead, they are
114dynamically created for you.  For USB Scanner, the device is created
115in /dev/usb/scannerX where X can range from 0 to 15 depending on the
116number of scanners connected to the system.
117
118To see if you have devfs, issue the command `cat /proc/filesytems`.
119If devfs is listed you should be ready to go.  You sould also have a
120process running called 'devfsd'.  In order to make sure, issue the
121command `ps aux | grep '[d]evfsd'`.
122
123If you would like to maintain /dev/usbscanner0 in order to maintain
124compatibility with applications, then add the following to
125/etc/devfsd.conf:
126
127REGISTER ^usb/scanner0$ CFUNCTION GLOBAL symlink usb/scanner0 usbscanner0
128UNREGISTER ^usb/scanner0$ CFUNCTION GLOBAL unlink usbscanner0
129
130Then reset the scanner (reseat the USB connector or power cycle). This
131will create the necessary symlinks in /dev to /dev/usb.
132
133CONCLUSION
134
135That's it.  SANE should now be able to access the device.  
136
137There is a small test program (hp_scan.c -- appended below) that can
138be used to test the scanner device if it's an HP scanner that supports
139SCL (Scanner Control Language).  Known HP scanner that support SCL are
140the 4100, 5200, 6200, the 6300 -- note that the 4200 is *not*
141supported since it does not understand SCL; it's also strongly
142suspected that the 3300 and the PhotoSmart S20 are not SCL compliant.
143Hp_scan.c's purpose is to test the driver without having to
144retrieve/configure SANE.  Hp_scan.c will scan the entire bed and put
145the output into a file called 'out.dat' in the current directory.  The
146data in the file is raw data so it's not very useful for imaging.
147
148MESSAGES
149
150usb_control/bulk_msg: timeout -- On occasions this message will appear
151in '/var/adm/messages', on the console, or both depending on how
152your system is configured.  This is a side effect that scanners are
153sometimes very slow at warming up and/or initializing.  In most cases,
154however, only several of these messages should appear and is generally
155considered to be normal.  
156
157excessive NAK's received -- This message should be considered abnormal
158and generally indicates that the USB system is unable to communicate
159with the scanner for some particular reason.
160
161probe_scanner: Undetected endpoint -- The USB Scanner driver is fairly
162general when it comes to communicating to scanners.  Unfortunately,
163some vendors have designed their scanners in one way or another that
164this driver doesn't account for.
165
166probe_scanner: Endpoint determination failed -- This means that the
167driver is unable to detect a supported configuration for means to
168communicate with the scanner.  See also 'probe_scanner: Undetected
169endpoint'.
170
171funky result -- Most of the time the data flow between the computer
172and the scanner goes smoothly.  However, due to whatever reason,
173whether it be solar flares or stray neutrons, sometimes the
174communications don't work as expected.  The driver tries to handle
175most types of errors but not all.  When this message is seen,
176something weird happened.  Please contact the maintaner listed at the
177top of this file.
178
179SUPPORTED SCANNERS
180
181NOTE: Just because a product is listed here does not mean that
182applications exist that support the product.  It's in the hopes that
183this will allow developers a means to produce applications that will
184support the listed USB products.
185
186At the time of this writing, the following scanners were supported by
187scanner.c:
188
189 Acer
190	 Prisa Acerscan 620U & 640U (!)
191	 Prisa AcerScan 620U (!)
192 Agfa
193	 SnapScan 1212U
194	 Another SnapScan 1212U (?)
195	 SnapScan Touch
196 Colorado -- See Primax/Colorado below
197 Epson -- See Seiko/Epson below
198 Genius
199         ColorPage-Vivid Pro
200 Hewlett Packard
201	 3300C
202	 4100C
203	 4200C
204	 PhotoSmart S20
205	 5200C
206	 6200C
207	 6300C
208 Microtek
209	 ScanMaker X6 - X6U
210	 Phantom 336CX - C3
211	 Phantom 336CX - C3 #2
212	 Phantom C6
213	 ScanMaker V6USL
214	 ScanMaker V6USL #2
215	 ScanMaker V6UL - SpicyU
216 Mustek
217	 1200 CU
218 Primax/Colorado
219	 G2-300 #1
220	 G2-600 #1
221	 G2E-300 #1
222	 ReadyScan 636i
223	 G2-300 #2
224	 G2-600 #2
225	 G2E-300 #2
226	 G2E-600
227	 Colorado USB 9600
228	 Colorado USB 19200
229	 Colorado 600u
230	 Colorado 1200u
231 Seiko/Epson Corp.
232	 Perfection 636U and 636Photo
233	 Perfection 610
234	 Perfection 1200U and 1200Photo
235 Umax
236	 Astra 1220U
237	 Astra 1236U
238	 Astra 2000U
239	 Astra 2200U
240 Visioneer
241	 OneTouch 5300
242	 OneTouch 7600 duplicate ID (!)
243	 6100
244
245
246MODULE PARAMETERS
247
248If you have a device that you wish to experiment with or try using
249this driver with, but the Vendor and Product ID's are not coded in,
250don't despair.  If the driver was compiled as a module, you can pass
251options to the driver.  Simply add 
252
253  options scanner vendor=0x#### product=0x****
254
255to the /etc/modules.conf file replacing the #'s and the *'s with the
256correct ID's.  The ID's can be retrieved from the messages file or
257using `cat /proc/bus/usb/devices`. Note that USB /proc support must be
258enabled during kernel configuration.  If the 'scanner' module is
259already loaded into memory, it must be reloaded for the module
260parameters to take effect.  In essence, `rmmod scanner; modprobe
261scanner` must be performed.
262
263**NOTE**: In later kernels (2.3.38+), a new filesystem was introduced,
264usbdevfs.  To mount the filesystem, issue the command (as root):
265
266  mount -t usbdevfs /proc/bus/usb /proc/bus/usb
267
268An alternative and more permanent method would be to add
269
270  none  /proc/bus/usb  usbdevfs  defaults  0  0
271
272to /etc/fstab.  This will mount usbdevfs at each reboot.  You can then
273issue `cat /proc/bus/usb/devices` to extract USB device information.
274
275
276BUGS
277
278Just look at the list of fixes in the source files.  So, if you
279encounter any problems feel free to drop me an email.
280
281David /\/elson
282dnelson@jump.net
283http://www.jump.net/~dnelson
284
285--------------- snip -- hp_scan.c -- snip ---------------
286/*
287
288This is a really crude attempt at writing a short test program.  It's
289mostly only to be used to test connectivity with USB HP scanners that
290understand SCL.  Currently, the supported models are 4100C, 5200C,
2916200C, and the 6300C.  Note that the 4200C is *NOT* acceptable.
292
293Copyright (C) David E. Nelson <dnelson@jump.net>, 1999
294
295This program is free software; you can redistribute it and/or modify
296it under the terms of the GNU General Public License as published by
297the Free Software Foundation; either version 2 of the License, or (at
298your option) any later version.
299
300*/
301
302#include <stdio.h>
303#include <stdlib.h>
304#include <error.h>
305#include <unistd.h>
306#include <fcntl.h>
307
308/*
309   Gray Output produces about a 8945400 byte file.
310   Color Output produces a 26836200 byte file. 
311   
312   To compile: gcc -o hp_scan hp_scan.c
313*/
314
315// #define COLOR /* Undef to scan GrayScale */
316
317int send_cmd(int, const char *, int);
318int read_cmd(int, char *, int);
319
320int
321main(void) {
322
323	ssize_t cnt = 0, total_cnt = 0;
324
325	FILE *fpout;
326
327	int fp;
328	int data_size = 32768;
329
330	char *data;
331
332	static char reset_cmd[] = {'\x1b','E'};
333
334#ifdef COLOR
335	static char data_type_cmd[] = {'\x1b','*','a','5','T'}; /* Color */
336	static char data_width_cmd[] = {'\x1b','*','a','2','4','G'}; /* 24 Bit Color */
337#else
338	static char data_type_cmd[] = {'\x1b','*','a','4','T'}; /* Gray */
339	static char data_width_cmd[] = {'\x1b','*','a','8','G'}; /* 8 Bit Gray */
340#endif
341
342	static char query_cmd[] = {'\x1b', '*', 's', '2', '5', '7', 'E'};
343	static char start_scan_cmd[] = {'\x1b','*','f','0','S'};
344	
345	if(!(data=malloc(data_size))) {
346		perror("malloc failed");
347		exit (1);
348	}
349	
350	if((fp=open("/dev/usbscanner", O_RDWR)) < 0) {
351		perror("Unable to open scanner device");
352		exit (1);
353	}
354
355	if((fpout=fopen("out.dat", "w+")) == NULL) {
356		perror("Unable to open ouput file");
357		exit(1);
358	}
359
360	send_cmd(fp, reset_cmd, sizeof(reset_cmd));
361	send_cmd(fp, data_type_cmd, sizeof(data_type_cmd));
362	send_cmd(fp, data_width_cmd, sizeof(data_width_cmd));
363	send_cmd(fp, start_scan_cmd, sizeof(start_scan_cmd));
364
365	while ((cnt = read(fp, data, data_size)) > 0) {
366		printf("Read: %u\n", cnt); 
367		if(fwrite(data, sizeof(char), cnt, fpout) < 0) {
368			perror("Write to output file failed");
369			exit (1);
370		}
371		total_cnt += cnt;
372	}
373	if (cnt < 0) {
374		perror("Read from scanner failed");
375		exit (1);
376	}
377
378	printf("\nRead %lu bytes.\n", total_cnt);
379
380	send_cmd(fp, reset_cmd, sizeof(reset_cmd));
381
382	close(fp);
383	fclose(fpout);
384	return (0);
385}
386
387int
388send_cmd(int fp, const char * cmd, int length) {
389
390	int result;
391	int x;
392
393	if((result = write(fp, cmd, length)) != length) {
394		printf ("Write warning: %d bytes requested, %d written\n");
395	} else if (result < 0) {
396		perror ("send_cmd failure");
397		exit (1);
398	}
399	return (result);
400}
401	
402int
403read_cmd(int fp, char * response, int length) {
404
405	return read(fp, response, length);
406
407}
408