GSC(4)

NAME
gsc - a device driver for a handy scanner

SYNOPSIS
#include <machine/gsc.h>

Minor number bits: uu d g p ...
uu  unit gsc0 .. gsc3
d   selects logging of debug messages
g   selects bitmap vs. graymap output
p   selects raw vs. portable pnm output

DESCRIPTION
The gsc character device driver currently handles only the Genius GS-4500 handy scanner. It operates in pure dma modus, although the hardware could be set up to work with irq. I had neither enough documentation nor experience in writing interrupt driven device drivers.

The device can operate at four different resolutions: 100, 200, 300 and 400dpi. It produces a simple bitmap with the most significant bit at the left side. The driver can optionally output the famous and likely simple portable bitmap file format pbm(5) by Jef Poskanzer. Thus the scans can easily processed by any graphic package around ( xpaint(1), xv(1), xli(1) only to name some of them ...). In raw mode a bit which is set means a black pixel because the scanner detects black points on white paper. On the other hand, because pnm format describes intensities of electron beams in video screens a set bit in pbm mode means a white pixel.

The width of the output bitmap is fixed as given by the resolution value. However, the height of the bitmap must be supplied in pnm mode since the driver must know at what time the directly copy the scanner output into a pbm file with cat. Of course you can obtain a similar effect by using dd(1) with the driver in raw mode.

The graymap output mode is not yet implemented into the driver. It is even questionable if external programs would not do this job better thereby not counting to the size of the kernel. Even though, I do not know of tools which produce a graymap from a halftone bitmap.

The ioctl requests that are served by gsc are listed below. There is a utility, called sgsc(1), that provides access to these requests from within shell.

GSC_SRES int
    Set the resolution value. If this call is made after the first read access to the device there will be no effect unless the device is closed and opened again.

GSC_GRES int
    Get current resolution in dots per inch (dpi).

GSC_SRESSSW void
    Set resolution value from selector switch. The driver must be in an open though untouched state otherwise the request will fail and errno(2) is set to EBUSY.

GSC_SWIDTH int
    Set the width of the bitmap. Actually, this is an alternative way of setting the resolution, since any allowed resolution matches exactly one width. Allowed are listed in the table below.
    resolution
        width
    100 dpi
        424 pixels
    200 dpi
        840 pixels
    300 dpi
        1264 pixels
    400 dpi
        1648 pixels
    ?   1696 pixels
    ?   2544 pixels
    ?   3648 pixels

    Values which are not reported in the above table will cause the ioctl call to fail with errno(2) set to EINVAL.

    As you can see, there are width values > 1696. This does, however, not mean that you can obtain scanned lines longer than the width of your scanner or by higher resolutions. Actually, the resolution is selected by only by the hardware switch. Any line that is longer than what is defined for the actual resolution will be undefined (usually white) on the right part that is exceeding the standard line.

GSC_GWIDTH int
    Get current width of the bitmap in pixels.

GSC_SHEIGHT int
    Set the height of the bitmap in pnm mode. This is actually a limit on the amount of lines scannable after the first read operation. When the limit is reached read will return 0. However, the device is turned off only when a close is performed (either explicitly or implicitly on exit of the calling process).

GSC_GHEIGHT int
    Get the current height of the bitmap.

GSC_SBLEN int
    Set the length of the buffer used internally to do the DMA transfer. The buffer length is supplied in lines of the bitmap. Since the buffer size limit is (currently) 0x3000 bytes the maximum number of lines allowed will vary with the width of each line. This upper limit is checked before it overwrites the current value and pases an ENOMEM in the errno(2) variable. However, since the bitmap width can change after a buffer length was selected a read request may fail with ENOMEM if the buffer length turns out too high. It is generally wise to choose long buffers rather than go save in order to obtain better output.

GSC_GBLEN int
    Get the current buffer length in lines.

GSC_SBTIME int
    Set the timeout for the completion of reading one buffer. Since a handy scanner is a human/computer interface timeout values are usually higher than those of a flat scanner. Default is 15 seconds. After timeout is reached the read operation will fail with EBUSY. Note that the timeout timer starts anew for each buffer to be read and thus does not cause you to scan faster for longer images. BLEN/BTIME is similar as MIN/TIME in termios(4).

GSC_GBTIME int
    Get the current buffer timeout.

All ioctl requests that modify a parameter except GSC_SBTIME do not have an effect on an ongoing scan process, i.e. after the first read request that follows open. You must close the device and open it again for the new selections to take effect. Consequently, the selections are not reset when you close or open the device.

Similarly, requests that read a value do not report the value that is used for the ongoing scan process. The values needed during the scan process are saved when it starts and thus are not accessed by ioctl requests.

The BTIME value does, however, have an immediate effect on the ongoing scan. Thus the timeout can for example be set to long until the user starts scanning. It can then be set to a short amount to react (nearly) immediately when the user stops. Note that the user should be left time to at least fill one buffer without having to haste.

Note that the pbm versus raw mode selection is done by the minor number not by ioctl requests. In raw mode the selected height of the bitmap will have no effect.

FILES

/dev/gsc0
    device node for raw output, has minor number 0.

/dev/gsc0d
    device node for raw output emitting debug messages if the GSCDEBUG option was given at compile time, has minor number 32.

/dev/gsc0p
    device node for output in pbm file format, has minor number 8.

/dev/gsc0pd
    device node for pbm and debug mode, has minor number 40.

EXAMPLES

    dd if=/dev/gsc0 of=rawfile bs=(width/8) count=(height)
    cat /dev/gsc0p > pbmfile

DIAGNOSTICS

GSCDEBUG
    When you define this name as an `option' in the kernel configuration you can get debug output if you access the driver with a minor number whose debug bit (i.e. bit 5 out of 7) is set.

SEE ALSO
cat(1), dd(1), pbmtopgm(1), pnm(1), sgsc(1), close(2), intro(2), ioctl(2), open(2), read(2), termios(4), pbm(5)

AUTHORS
Gunther Schadow <gusw@fub46.zedat.fu-berlin.de>

BUGS
Even though the scanner device has a little switch by which you should be able to select one of the four resolution modes, I could not yet determine how to read its status. Unless this is not fixed the driver depends on the value passed by means of ioctl(2) which need not match what is selected by the hardware.