summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2010-07-08 00:42:40 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2010-07-08 00:42:40 +0000
commit226cd7e8b90dcd34d2f7d56d26618e8c873eeff5 (patch)
tree86784c157c3b692a684ce331ce162fccb19055ee /sys
parenta384facfffa31bed8d82f23fc76bb15aa3ee896e (diff)
Move ss and friends to the attic.
Enthusiastic huzzahs from many. "A great day" dlg@
Diffstat (limited to 'sys')
-rw-r--r--sys/scsi/ss.c1084
-rw-r--r--sys/scsi/ss_mustek.c646
-rw-r--r--sys/scsi/ss_mustek.h180
-rw-r--r--sys/scsi/ss_scanjet.c605
4 files changed, 0 insertions, 2515 deletions
diff --git a/sys/scsi/ss.c b/sys/scsi/ss.c
deleted file mode 100644
index 9e3c26af616..00000000000
--- a/sys/scsi/ss.c
+++ /dev/null
@@ -1,1084 +0,0 @@
-/* $OpenBSD: ss.c,v 1.79 2010/07/01 05:11:18 krw Exp $ */
-/* $NetBSD: ss.c,v 1.10 1996/05/05 19:52:55 christos Exp $ */
-
-/*
- * Copyright (c) 1995, 1997 Kenneth Stailey. All rights reserved.
- * modified for configurable scanner support by Joachim Koenig
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Kenneth Stailey.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/fcntl.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/buf.h>
-#include <sys/proc.h>
-#include <sys/device.h>
-#include <sys/conf.h>
-#include <sys/scanio.h>
-
-#include <scsi/scsi_all.h>
-#include <scsi/scsi_scanner.h>
-#include <scsi/scsiconf.h>
-#include <scsi/ssvar.h>
-
-#include <scsi/ss_mustek.h>
-
-#define SSMODE(z) ( minor(z) & 0x03)
-#define SSUNIT(z) ((minor(z) >> 4) )
-
-/*
- * If the mode is 3 (e.g. minor = 3,7,11,15)
- * then the device has been openned to set defaults
- * This mode does NOT ALLOW I/O, only ioctls
- */
-#define MODE_REWIND 0
-#define MODE_NONREWIND 1
-#define MODE_CONTROL 3
-
-struct quirkdata {
- char *name;
- u_int quirks;
-#define SS_Q_WINDOW_DESC_LEN 0x0001 /* needs special WDL */
-#define SS_Q_BRIGHTNESS 0x0002 /* needs special value for brightness */
-#define SS_Q_REV_BRIGHTNESS 0x0004 /* reverse brightness control in s/w */
-#define SS_Q_THRESHOLD 0x0008 /* needs special value for threshold */
-#define SS_Q_MONO_THRESHOLD 0x0010 /* same as SS_Q_THRESHOLD but only
- * for monochrome image data */
-#define SS_Q_CONTRAST 0x0020 /* needs special value for contrast */
-#define SS_Q_REV_CONTRAST 0x0040 /* reverse contrast control in s/w */
-#define SS_Q_HALFTONE 0x0080 /* uses non-zero halftone */
-#define SS_Q_SET_RIF 0x0100 /* set RIF bit */
-#define SS_Q_PADDING_TYPE 0x0200 /* does not truncate to byte boundary */
-#define SS_Q_BIT_ORDERING 0x0400 /* needs non-zero bit ordering */
- long window_descriptor_length;
- u_int8_t brightness;
- u_int8_t threshold;
- u_int8_t contrast;
- u_int8_t halftone_pattern[2];
- int pad_type;
- long bit_ordering;
- u_int8_t scanner_type;
- /*
- * To enable additional scanner options, point vendor_unique_sw
- * at a function that adds more stuff to the SET_WINDOW parameters.
- */
- int (*vendor_unique_sw)(struct ss_softc *, struct scan_io *,
- struct scsi_set_window *, void *);
- /*
- * If the scanner requires use of GET_BUFFER_STATUS before READ
- * it can be called from ss_minphys().
- */
- void (*special_minphys)(struct ss_softc *, struct buf *);
-
- int (*compute_sizes)(void);
-};
-
-struct ss_quirk_inquiry_pattern {
- struct scsi_inquiry_pattern pattern;
- struct quirkdata quirkdata;
-};
-
-struct quirkdata ss_gen_quirks = {
- "generic", 0, 0, 0, 0, 0,
- {0, 0}, 0, 0, GENERIC_SCSI2,
- NULL, NULL, NULL
-};
-
-void ssstrategy(struct buf *);
-void ssstart(struct scsi_xfer *);
-void ssdone(struct scsi_xfer *);
-void ssminphys(struct buf *);
-
-void ss_identify_scanner(struct ss_softc *, struct scsi_inquiry_data*);
-int ss_set_window(struct ss_softc *, struct scan_io *);
-
-int ricoh_is410_sw(struct ss_softc *, struct scan_io *,
- struct scsi_set_window *, void *);
-int umax_uc630_sw(struct ss_softc *, struct scan_io *,
- struct scsi_set_window *, void *);
-#ifdef NOTYET /* for ADF support */
-int fujitsu_m3096g_sw(struct ss_softc *, struct scan_io *,
- struct scsi_set_window *, void *);
-#endif
-
-void get_buffer_status(struct ss_softc *, struct buf *);
-
-/*
- * WDL:
- *
- * Ricoh IS-50 & IS-410 insist on 320 (even it transfer len is less.)
- * Ricoh FS-1 accepts 256 (I haven't tested other values.)
- * UMAX UC-630 accepts 46 (I haven't tested other values.)
- * Fujitsu M3096G wants 40 <= x <= 248 (tested OK at 40 & 64.)
- */
-
-const struct ss_quirk_inquiry_pattern ss_quirk_patterns[] = {
- {{T_SCANNER, T_FIXED,
- "ULTIMA ", "AT3 1.60 ", " "}, {
- "Ultima AT3",
- SS_Q_HALFTONE |
- SS_Q_PADDING_TYPE,
- 0, 0, 0, 0, { 3, 0 }, 0, 0,
- ULTIMA_AT3,
- NULL, NULL, NULL
- }},
- {{T_SCANNER, T_FIXED,
- "ULTIMA ", "A6000C PLUS ", " "}, {
- "Ultima A6000C",
- SS_Q_HALFTONE |
- SS_Q_PADDING_TYPE,
- 0, 0, 0, 0, { 3, 0 }, 0, 0,
- ULTIMA_AC6000C,
- NULL, NULL, NULL
- }},
- {{T_SCANNER, T_FIXED,
- "RICOH ", "IS50 ", " "}, {
- "Ricoh IS-50",
- SS_Q_WINDOW_DESC_LEN |
- SS_Q_REV_BRIGHTNESS |
- SS_Q_THRESHOLD |
- SS_Q_REV_CONTRAST |
- SS_Q_HALFTONE |
- SS_Q_BIT_ORDERING,
- 320, 0, 0, 0, { 2, 0x0a }, 0, 7,
- RICOH_IS50,
- ricoh_is410_sw, get_buffer_status, NULL
- }},
- {{T_SCANNER, T_FIXED,
- "RICOH ", "IS410 ", " "}, {
- "Ricoh IS-410",
- SS_Q_WINDOW_DESC_LEN |
- SS_Q_THRESHOLD |
- SS_Q_HALFTONE |
- SS_Q_BIT_ORDERING,
- 320, 0, 0, 0, { 2, 0x0a }, 0, 7,
- RICOH_IS410,
- ricoh_is410_sw, get_buffer_status, NULL
- }},
- {{T_SCANNER, T_FIXED, /* Ricoh IS-410 OEMed by IBM */
- "IBM ", "2456-001 ", " "}, {
- "IBM 2456",
- SS_Q_WINDOW_DESC_LEN |
- SS_Q_THRESHOLD |
- SS_Q_HALFTONE |
- SS_Q_BIT_ORDERING,
- 320, 0, 0, 0, { 2, 0x0a }, 0, 7,
- RICOH_IS410,
- ricoh_is410_sw, get_buffer_status, NULL
- }},
- {{T_SCANNER, T_FIXED,
- "UMAX ", "UC630 ", " "}, {
- "UMAX UC-630",
- SS_Q_WINDOW_DESC_LEN |
- SS_Q_HALFTONE,
- 0x2e, 0, 0, 0, { 0, 1 }, 0, 0,
- UMAX_UC630,
- umax_uc630_sw, NULL, NULL
- }},
- {{T_SCANNER, T_FIXED,
- "UMAX ", "UG630 ", " "}, {
- "UMAX UG-630",
- SS_Q_WINDOW_DESC_LEN |
- SS_Q_HALFTONE,
- 0x2e, 0, 0, 0, { 0, 1 }, 0, 0,
- UMAX_UG630,
- umax_uc630_sw, NULL, NULL
- }},
-#ifdef NOTYET /* ADF version */
- {{T_SCANNER, T_FIXED,
- "FUJITSU ", "M3096Gm ", " "}, {
- "Fujitsu M3096G",
- SS_Q_WINDOW_DESC_LEN |
- SS_Q_BRIGHTNESS |
- SS_Q_MONO_THRESHOLD |
- SS_Q_HALFTONE |
- SS_Q_SET_RIF |
- SS_Q_PADDING_TYPE,
- 64, 0, 0, 0, { 0, 1 }, 0, 0,
- FUJITSU_M3096G,
- fujistsu_m3096g_sw, NULL, NULL
- }},
-#else /* flatbed-only version */
- {{T_SCANNER, T_FIXED,
- "FUJITSU ", "M3096Gm ", " "}, {
- "Fujitsu M3096G",
- SS_Q_BRIGHTNESS |
- SS_Q_MONO_THRESHOLD |
- SS_Q_CONTRAST |
- SS_Q_HALFTONE |
- SS_Q_PADDING_TYPE,
- 0, 0, 0, 0, { 0, 1 }, 0, 0,
- FUJITSU_M3096G,
- NULL, NULL, NULL
- }},
-#endif
-};
-
-
-int ssmatch(struct device *, void *, void *);
-void ssattach(struct device *, struct device *, void *);
-
-struct cfattach ss_ca = {
- sizeof(struct ss_softc), ssmatch, ssattach
-};
-
-struct cfdriver ss_cd = {
- NULL, "ss", DV_DULL
-};
-
-const struct scsi_inquiry_pattern ss_patterns[] = {
- {T_SCANNER, T_FIXED,
- "", "", ""},
- {T_SCANNER, T_REMOV,
- "", "", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C1750A ", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C1790A ", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C2500A ", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C2570A ", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C2520A ", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C1130A ", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C5110A ", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C6290A ", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C5190A ", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C7190A ", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C6270A ", ""},
- {T_PROCESSOR, T_FIXED,
- "HP ", "C7670A ", ""},
-};
-
-int
-ssmatch(parent, match, aux)
- struct device *parent;
- void *match, *aux;
-{
- struct scsi_attach_args *sa = aux;
- int priority;
-
- (void)scsi_inqmatch(sa->sa_inqbuf,
- ss_patterns, sizeof(ss_patterns)/sizeof(ss_patterns[0]),
- sizeof(ss_patterns[0]), &priority);
- return (priority);
-}
-
-/*
- * The routine called by the low level scsi routine when it discovers
- * A device suitable for this driver
- * If it is a know special, call special attach routine to install
- * special handlers into the ss_softc structure
- */
-void
-ssattach(parent, self, aux)
- struct device *parent, *self;
- void *aux;
-{
- struct ss_softc *ss = (void *)self;
- struct scsi_attach_args *sa = aux;
- struct scsi_link *sc_link = sa->sa_sc_link;
-
- SC_DEBUG(sc_link, SDEV_DB2, ("ssattach:\n"));
-
- /*
- * Store information needed to contact our base driver
- */
- ss->sc_link = sc_link;
- sc_link->device_softc = ss;
- sc_link->openings = 1;
-
- if (!bcmp(sa->sa_inqbuf->vendor, "MUSTEK", 6))
- mustek_attach(ss, sa);
- else if (!bcmp(sa->sa_inqbuf->vendor, "HP ", 8))
- scanjet_attach(ss, sa);
- else
- ss_identify_scanner(ss, sa->sa_inqbuf);
-
- /*
- * populate the scanio struct with legal values
- */
- ss->sio.scan_width = 1200;
- ss->sio.scan_height = 1200;
- ss->sio.scan_x_resolution = 100;
- ss->sio.scan_y_resolution = 100;
- ss->sio.scan_x_origin = 0;
- ss->sio.scan_y_origin = 0;
- ss->sio.scan_brightness = 128;
- ss->sio.scan_contrast = 128;
- ss->sio.scan_quality = 100;
- ss->sio.scan_image_mode = SIM_GRAYSCALE;
-
- /* XXX fill in the rest of the scan_io struct by calling the
- compute_sizes routine */
-
- scsi_xsh_set(&ss->xsh, sc_link, ssstart);
- timeout_set(&ss->timeout, (void (*)(void *))scsi_xsh_add, &ss->xsh);
-
- /* Set up the buf queue for this device. */
- ss->sc_bufq = bufq_init(BUFQ_DEFAULT);
-}
-
-void
-ss_identify_scanner(ss, inqbuf)
- struct ss_softc *ss;
- struct scsi_inquiry_data *inqbuf;
-{
- const struct ss_quirk_inquiry_pattern *finger;
- int priority;
- /*
- * look for non-standard scanners with help of the quirk table
- * and install functions for special handling
- */
- finger = (const struct ss_quirk_inquiry_pattern *)scsi_inqmatch(inqbuf,
- ss_quirk_patterns,
- sizeof(ss_quirk_patterns)/sizeof(ss_quirk_patterns[0]),
- sizeof(ss_quirk_patterns[0]), &priority);
- if (priority != 0) {
- ss->quirkdata = &finger->quirkdata;
- if (ss->quirkdata->special_minphys != NULL) {
- ss->special.minphys = ss->quirkdata->special_minphys;
- }
- ss->sio.scan_scanner_type = ss->quirkdata->scanner_type;
- printf("\n%s: %s\n", ss->sc_dev.dv_xname, ss->quirkdata->name);
- } else {
- printf("\n%s: generic scanner\n", ss->sc_dev.dv_xname);
- bzero(&ss_gen_quirks, sizeof(ss_gen_quirks));
- ss->quirkdata = &ss_gen_quirks;
- ss->sio.scan_scanner_type = GENERIC_SCSI2;
- }
-}
-
-/*
- * open the device.
- */
-int
-ssopen(dev, flag, mode, p)
- dev_t dev;
- int flag;
- int mode;
- struct proc *p;
-{
- int unit;
- u_int ssmode;
- int error = 0;
- struct ss_softc *ss;
- struct scsi_link *sc_link;
-
- unit = SSUNIT(dev);
- if (unit >= ss_cd.cd_ndevs)
- return (ENXIO);
- ss = ss_cd.cd_devs[unit];
- if (!ss)
- return (ENXIO);
-
- ssmode = SSMODE(dev);
- sc_link = ss->sc_link;
-
- SC_DEBUG(sc_link, SDEV_DB1, ("open: dev=0x%x (unit %d (of %d))\n", dev,
- unit, ss_cd.cd_ndevs));
-
- if (sc_link->flags & SDEV_OPEN) {
- printf("%s: already open\n", ss->sc_dev.dv_xname);
- return (EBUSY);
- }
-
- /*
- * Catch any unit attention errors.
- *
- * SCSI_IGNORE_MEDIA_CHANGE: when you have an ADF, some scanners
- * consider paper to be a changeable media
- *
- */
- error = scsi_test_unit_ready(sc_link, TEST_READY_RETRIES,
- SCSI_IGNORE_MEDIA_CHANGE | SCSI_IGNORE_ILLEGAL_REQUEST |
- (ssmode == MODE_CONTROL ? SCSI_IGNORE_NOT_READY : 0));
- if (error)
- goto bad;
-
- sc_link->flags |= SDEV_OPEN; /* unit attn are now errors */
-
- /*
- * If the mode is 3 (e.g. minor = 3,7,11,15)
- * then the device has been opened to set defaults
- * This mode does NOT ALLOW I/O, only ioctls
- */
- if (ssmode == MODE_CONTROL)
- return (0);
-
- SC_DEBUG(sc_link, SDEV_DB2, ("open complete\n"));
- return (0);
-
-bad:
- sc_link->flags &= ~SDEV_OPEN;
- return (error);
-}
-
-/*
- * close the device.. only called if we are the LAST
- * occurrence of an open device
- */
-int
-ssclose(dev, flag, mode, p)
- dev_t dev;
- int flag;
- int mode;
- struct proc *p;
-{
- struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(dev)];
- int error;
-
- SC_DEBUG(ss->sc_link, SDEV_DB1, ("closing\n"));
-
- if (SSMODE(dev) == MODE_REWIND) {
- if (ss->special.rewind_scanner) {
- /* call special handler to rewind/abort scan */
- error = (ss->special.rewind_scanner)(ss);
- if (error)
- return (error);
- } else {
- /* XXX add code to restart a SCSI2 scanner, if any */
- }
- ss->sio.scan_window_size = 0;
- ss->flags &= ~SSF_TRIGGERED;
- }
- ss->sc_link->flags &= ~SDEV_OPEN;
-
- return (0);
-}
-
-/*
- * trim the size of the transfer if needed,
- * called by physio
- * basically the smaller of our min and the scsi driver's
- * minphys
- */
-void
-ssminphys(bp)
- struct buf *bp;
-{
- struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(bp->b_dev)];
-
- (ss->sc_link->adapter->scsi_minphys)(bp, ss->sc_link);
-
- /*
- * trim the transfer further for special devices this is
- * because some scanners only read multiples of a line at a
- * time, also some cannot disconnect, so the read must be
- * short enough to happen quickly
- */
- if (ss->special.minphys)
- (ss->special.minphys)(ss, bp);
-}
-
-/*
- * Do a read on a device for a user process.
- * Prime scanner at start of read, check uio values, call ssstrategy
- * via physio for the actual transfer.
- */
-int
-ssread(dev, uio, flag)
- dev_t dev;
- struct uio *uio;
- int flag;
-{
- struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(dev)];
- int error;
-
- /* if the scanner has not yet been started, do it now */
- if (!(ss->flags & SSF_TRIGGERED)) {
- if (ss->special.trigger_scanner) {
- error = (ss->special.trigger_scanner)(ss);
- if (error)
- return (error);
- } else {
- struct scsi_start_stop trigger_cmd;
- bzero(&trigger_cmd, sizeof(trigger_cmd));
- trigger_cmd.opcode = START_STOP;
- trigger_cmd.how = SSS_START;
- scsi_scsi_cmd(ss->sc_link,
- (struct scsi_generic *)&trigger_cmd,
- sizeof(trigger_cmd), 0, 0, SCSI_RETRIES, 5000,
- NULL, 0);
- }
- ss->flags |= SSF_TRIGGERED;
- }
-
- return (physio(ssstrategy, NULL, dev, B_READ, ssminphys, uio));
-}
-
-/*
- * Actually translate the requested transfer into one the physical
- * driver can understand The transfer is described by a buf and will
- * include only one physical transfer.
- */
-void
-ssstrategy(bp)
- struct buf *bp;
-{
- struct ss_softc *ss;
- int s;
-
- ss = ss_cd.cd_devs[SSUNIT(bp->b_dev)];
- if (ss == NULL) {
- bp->b_error = ENXIO;
- goto bad;
- }
-
- SC_DEBUG(ss->sc_link, SDEV_DB2, ("ssstrategy: %ld bytes @ blk %d\n",
- bp->b_bcount, bp->b_blkno));
-
- if (bp->b_bcount > ss->sio.scan_window_size)
- bp->b_bcount = ss->sio.scan_window_size;
-
- /*
- * If it's a null transfer, return immediately
- */
- if (bp->b_bcount == 0)
- goto done;
-
- /*
- * Place it in the queue of activities for this scanner
- * at the end (a bit silly because we only have on user..)
- * (but it could fork() or dup())
- */
- BUFQ_QUEUE(ss->sc_bufq, bp);
-
- /*
- * Tell the device to get going on the transfer if it's
- * not doing anything, otherwise just wait for completion
- * (All a bit silly if we're only allowing 1 open but..)
- */
- scsi_xsh_add(&ss->xsh);
-
- device_unref(&ss->sc_dev);
- return;
-
-bad:
- bp->b_flags |= B_ERROR;
-done:
- /*
- * Set the buf to indicate no xfer was done.
- */
- bp->b_resid = bp->b_bcount;
- s = splbio();
- biodone(bp);
- splx(s);
- if (ss != NULL)
- device_unref(&ss->sc_dev);
-}
-
-/*
- * ssstart looks to see if there is a buf waiting for the device
- * and that the device is not already busy. If both are true,
- * It dequeues the buf and creates a scsi command to perform the
- * transfer required. The transfer request will call scsi_done
- * on completion, which will in turn call this routine again
- * so that the next queued transfer is performed.
- * The bufs are queued by the strategy routine (ssstrategy)
- *
- * This routine is also called after other non-queued requests
- * have been made of the scsi driver, to ensure that the queue
- * continues to be drained.
- * ssstart() is called at splbio
- */
-void
-ssstart(struct scsi_xfer *xs)
-{
- struct scsi_link *sc_link = xs->sc_link;
- struct ss_softc *ss = sc_link->device_softc;
- struct buf *bp;
- struct scsi_r_scanner *cdb;
-
- SC_DEBUG(sc_link, SDEV_DB2, ("ssstart\n"));
-
- bp = BUFQ_DEQUEUE(ss->sc_bufq);
- if (bp == NULL) {
- scsi_xs_put(xs);
- return;
- }
-
- if (ss->special.read) {
- (ss->special.read)(ss, xs, bp);
- } else {
- cdb = (struct scsi_r_scanner *)xs->cmd;
- xs->cmdlen = sizeof(*cdb);
-
- cdb->opcode = READ_BIG;
- _lto3b(bp->b_bcount, cdb->len);
-
- xs->data = bp->b_data;
- xs->datalen = bp->b_bcount;
- xs->flags |= SCSI_DATA_IN;
- xs->retries = 0;
- xs->timeout = 100000;
- xs->done = ssdone;
- xs->cookie = bp;
- xs->bp = bp;
-
- scsi_xs_exec(xs);
- }
-
- if (ISSET(ss->flags, SSF_WAITING))
- CLR(ss->flags, SSF_WAITING);
- else if (BUFQ_PEEK(ss->sc_bufq))
- scsi_xsh_add(&ss->xsh);
-}
-
-void
-ssdone(struct scsi_xfer *xs)
-{
- struct ss_softc *ss = xs->sc_link->device_softc;
- struct buf *bp = xs->cookie;
- int error, s;
-
- switch (xs->error) {
- case XS_NOERROR:
- bp->b_error = 0;
- bp->b_resid = xs->resid;
- break;
-
- case XS_NO_CCB:
- /* The adapter is busy, requeue the buf and try it later. */
- BUFQ_REQUEUE(ss->sc_bufq, bp);
- scsi_xs_put(xs);
- SET(ss->flags, SSF_WAITING);
- timeout_add(&ss->timeout, 1);
- return;
-
- case XS_SENSE:
- case XS_SHORTSENSE:
-#ifdef SCSIDEBUG
- scsi_sense_print_debug(xs);
-#endif
- error = scsi_interpret_sense(xs);
- if (error == 0) {
- bp->b_error = 0;
- bp->b_resid = xs->resid;
- break;
- }
- if (error != ERESTART)
- xs->retries = 0;
- goto retry;
-
- case XS_BUSY:
- if (xs->retries) {
- if (scsi_delay(xs, 1) != ERESTART)
- xs->retries = 0;
- }
- goto retry;
-
- case XS_TIMEOUT:
-retry:
- if (xs->retries--) {
- scsi_xs_exec(xs);
- return;
- }
- /* FALLTHROUGH */
-
- default:
- bp->b_error = EIO;
- bp->b_flags |= B_ERROR;
- bp->b_resid = bp->b_bcount;
- break;
- }
-
- s = splbio();
- biodone(bp);
- splx(s);
- scsi_xs_put(xs);
-}
-
-/*
- * Perform special action on behalf of the user;
- * knows about the internals of this device
- */
-int
-ssioctl(dev, cmd, addr, flag, p)
- dev_t dev;
- u_long cmd;
- caddr_t addr;
- int flag;
- struct proc *p;
-{
- struct ss_softc *ss = ss_cd.cd_devs[SSUNIT(dev)];
- int error = 0;
- struct scan_io *sio;
-
- switch (cmd) {
- case SCIOCGET:
- /* call special handler, if any */
- if (ss->special.get_params) {
- error = (ss->special.get_params)(ss);
- if (error)
- return (error);
- }
- bcopy(&ss->sio, addr, sizeof(struct scan_io));
- break;
- case SCIOCSET:
- sio = (struct scan_io *)addr;
-
- /* call special handler, if any */
- if (ss->special.set_params) {
- error = (ss->special.set_params)(ss, sio);
- if (error)
- return (error);
- } else {
- /* XXX add routine to validate parameters */
- ss_set_window(ss, sio);
- }
- break;
- case SCIOCRESTART:
- /* call special handler, if any */
- if (ss->special.rewind_scanner ) {
- error = (ss->special.rewind_scanner)(ss);
- if (error)
- return (error);
- } else
- /* XXX add code for SCSI2 scanner, if any */
- return (EOPNOTSUPP);
- ss->flags &= ~SSF_TRIGGERED;
- break;
- case SCIOC_USE_ADF:
- /* XXX add Automatic Document Feeder Support */
- return (EOPNOTSUPP);
- default:
- if (SSMODE(dev) != MODE_CONTROL)
- return (ENOTTY);
- return (scsi_do_ioctl(ss->sc_link, cmd, addr, flag));
- }
- return (error);
-}
-
-int
-ss_set_window(ss, sio)
- struct ss_softc *ss;
- struct scan_io *sio;
-{
- struct scsi_set_window window_cmd;
- struct {
- struct scsi_window_data window_data;
- /* vendor_unique must provide enough space for worst case
- * (currently Ricoh IS-410.) 40 + 280 = 320 which is the size
- * of its window descriptor length
- */
- u_int8_t vendor_unique[280];
- } wd;
-#define window_data wd.window_data
-#define vendor_unique wd.vendor_unique
- struct scsi_link *sc_link = ss->sc_link;
-
- /*
- * The CDB for SET WINDOW goes in here.
- * The two structures that follow are sent via data out.
- */
- bzero(&window_cmd, sizeof(window_cmd));
- window_cmd.opcode = SET_WINDOW;
- _lto3l(sizeof(window_data), window_cmd.len);
-
- bzero(&window_data, sizeof(window_data));
- if (ss->quirkdata->quirks & SS_Q_WINDOW_DESC_LEN)
- _lto2l(ss->quirkdata->window_descriptor_length,
- window_data.window_desc_len);
- else
- _lto2l(40L, window_data.window_desc_len);
-
- /* start of SET_WINDOW parameter block */
-
- /* leave window id at zero */
- /* leave auto bit at zero */
- _lto2l(sio->scan_x_resolution, window_data.x_res);
- _lto2l(sio->scan_y_resolution, window_data.y_res);
- _lto4l(sio->scan_x_origin, window_data.x_org);
- _lto4l(sio->scan_y_origin, window_data.y_org);
- _lto4l(sio->scan_width, window_data.width);
- _lto4l(sio->scan_height, window_data.length);
-
- if (ss->quirkdata->quirks & SS_Q_REV_BRIGHTNESS)
- window_data.brightness = 256 - sio->scan_brightness;
- else if (ss->quirkdata->quirks & SS_Q_BRIGHTNESS)
- window_data.brightness = ss->quirkdata->brightness;
- else
- window_data.brightness = sio->scan_brightness;
-
- /*
- * threshold: Default is to follow brightness.
- * If SS_Q_MONO_THRESHOLD is set then the quirkdata contains a special
- * value to be used instead of default when image data is monochrome.
- * Otherwise if SS_Q_THRESHOLD is set then the quirkdata contains
- * the threshold to always use.
- * Both SS_Q_MONO_THRESHOLD and SS_Q_THRESHOLD should not be set at
- * the same time.
- */
- if (ss->quirkdata->quirks & SS_Q_MONO_THRESHOLD) {
- if (sio->scan_image_mode == SIM_BINARY_MONOCHROME ||
- sio->scan_image_mode == SIM_DITHERED_MONOCHROME)
- window_data.threshold = ss->quirkdata->threshold;
- else
- window_data.threshold = sio->scan_brightness;
- } else if (ss->quirkdata->quirks & SS_Q_THRESHOLD)
- window_data.threshold = ss->quirkdata->threshold;
- else
- window_data.threshold = sio->scan_brightness;
-
- if (ss->quirkdata->quirks & SS_Q_REV_CONTRAST)
- window_data.contrast = 256 - sio->scan_contrast;
- else if (ss->quirkdata->quirks & SS_Q_CONTRAST)
- window_data.contrast = ss->quirkdata->contrast;
- else
- window_data.contrast = sio->scan_contrast;
-
- switch (sio->scan_image_mode) {
- case SIM_RED:
- case SIM_GREEN:
- case SIM_BLUE:
- window_data.image_comp = SIM_GRAYSCALE;
- break;
- default:
- window_data.image_comp = sio->scan_image_mode;
- }
-
- window_data.bits_per_pixel = sio->scan_bits_per_pixel;
-
- if (ss->quirkdata->quirks & SS_Q_HALFTONE) {
- window_data.halftone_pattern[0] =
- ss->quirkdata->halftone_pattern[0];
- window_data.halftone_pattern[1] =
- ss->quirkdata->halftone_pattern[1];
- } /* else leave halftone set to zero. */
-
- if (ss->quirkdata->quirks & SS_Q_SET_RIF)
- window_data.rif = 1;
-
- if (ss->quirkdata->quirks & SS_Q_PADDING_TYPE)
- window_data.pad_type = ss->quirkdata->pad_type;
- else
- window_data.pad_type = 3; /* 3 = truncate to byte boundary */
-
- if (ss->quirkdata->quirks & SS_Q_BIT_ORDERING)
- _lto2l(ss->quirkdata->bit_ordering, window_data.bit_ordering);
- /* else leave bit_ordering set to zero. */
-
- /* leave compression type & argument set to zero. */
-
-#undef window_data
-
- if (ss->quirkdata->vendor_unique_sw != NULL)
- return ((*ss->quirkdata->vendor_unique_sw)(ss, sio,
- &window_cmd, (void *)&wd));
- else
- /* send the command to the scanner */
- return (scsi_scsi_cmd(sc_link,
- (struct scsi_generic *)&window_cmd,
- sizeof(window_cmd), (u_char *) &wd.window_data,
- (ss->quirkdata->quirks & SS_Q_WINDOW_DESC_LEN) ?
- ss->quirkdata->window_descriptor_length : 40,
- SCSI_RETRIES, 5000, NULL, SCSI_DATA_OUT));
-}
-
-int
-ricoh_is410_sw(ss, sio, wcmd, vwd)
- struct ss_softc *ss;
- struct scan_io *sio;
- struct scsi_set_window *wcmd;
- void *vwd;
-{
- struct ricoh_is410_window_data {
- struct scsi_window_data window_data;
- u_int8_t res1;
- u_int8_t res2;
- u_int mrif:1; /* reverse image format (grayscale negative) */
- u_int filtering:3;
- u_int gamma_id:4;
- } *rwd = (struct ricoh_is410_window_data*)vwd;
- struct scsi_link *sc_link = ss->sc_link;
-
- rwd->mrif = 1; /* force grayscale to match PGM */
-
- /* send the command to the scanner */
- return (scsi_scsi_cmd(sc_link, (struct scsi_generic *)wcmd,
- sizeof(struct scsi_set_window), (u_char *)rwd,
- sizeof(struct ricoh_is410_window_data), SCSI_RETRIES, 5000, NULL,
- SCSI_DATA_OUT));
-}
-
-int
-umax_uc630_sw(ss, sio, wcmd, vwd)
- struct ss_softc *ss;
- struct scan_io *sio;
- struct scsi_set_window *wcmd;
- void *vwd;
-{
- struct umax_uc630_window_data {
- struct scsi_window_data window_data;
- u_int8_t speed;
- u_int8_t select_color;
- u_int8_t highlight;
- u_int8_t shadow;
- u_int8_t paper_length[2];
- } *uwd = (struct umax_uc630_window_data*)vwd;
- struct scsi_link *sc_link = ss->sc_link;
-
- uwd->speed = 1; /* speed: fastest speed that doesn't smear */
- switch (sio->scan_image_mode) { /* UMAX has three-pass color. */
- case SIM_RED: /* This selects which filter to use. */
- uwd->select_color = 0x80;
- break;
- case SIM_GREEN:
- uwd->select_color = 0x40;
- break;
- case SIM_BLUE:
- uwd->select_color = 0x20;
- break;
- }
- uwd->highlight = 50; /* 50 = highest; 0 = lowest */
- /* leave shadow set to zero. */
- /* XXX paper length is for ADF */
-
- /* send the command to the scanner */
- return (scsi_scsi_cmd(sc_link, (struct scsi_generic *)wcmd,
- sizeof(struct scsi_set_window), (u_char *)uwd,
- sizeof(struct umax_uc630_window_data), SCSI_RETRIES, 5000, NULL,
- SCSI_DATA_OUT));
-}
-
-#ifdef NOTYET /* for ADF support */
-int
-fujitsu_m3096g_sw(ss, sio, wcmd, vwd)
- struct ss_softc *ss;
- struct scan_io *sio;
- struct scsi_set_window *wcmd;
- void *vwd;
-{
- struct fujitsu_m3096g_window_data {
- struct scsi_window_data window_data;
- u_int8_t id;
- u_int8_t res1;
- u_int8_t outline;
- u_int8_t emphasis;
- u_int8_t mixed;
- u_int8_t mirroring;
- u_int8_t res2[5];
- u_int8_t subwindow_list[2];
- u_int paper_size_std:2;
- u_int res3:1;
- u_int paper_orientaton:1;
- u_int paper_size_type:4;
-/* defines for Paper Size Type: */
-#define FUJITSU_PST_A3 0x03
-#define FUJITSU_PST_A4 0x04
-#define FUJITSU_PST_A5 0x05
-#define FUJITSU_PST_DOUBLE_LETTER 0x06
-#define FUJITSU_PST_LETTER 0x07
-#define FUJITSU_PST_B4 0x0C
-#define FUJITSU_PST_B5 0x0D
-#define FUJITSU_PST_LEGAL 0x0F
- u_int8_t paper_width_x[4];
- u_int8_t paper_width_y[4];
- u_int8_t res4[2];
- } *fwd = (struct fujitsu_m3096g_window_data*)vwd;
- struct scsi_link *sc_link = ss->sc_link;
-
- /* send the command to the scanner */
- return (scsi_scsi_cmd(sc_link, (struct scsi_generic *)wcmd,
- sizeof(struct scsi_set_window), (u_char *)fwd,
- sizeof(struct fujitsu_m3096g_window_data), SCSI_RETRIES, 5000, NULL,
- SCSI_DATA_OUT));
-}
-#endif
-
-void
-get_buffer_status(ss, bp)
- struct ss_softc *ss;
- struct buf *bp;
-{
- struct scsi_get_buffer_status gbs_cmd;
- struct scsi_link *sc_link = ss->sc_link;
- struct {
- u_int8_t stat_len[3];
- u_int8_t res1;
- u_int8_t window_id;
- u_int8_t res2;
- u_int8_t tgt_accept_buf_len[3];
- u_int8_t tgt_send_buf_len[3];
- } buf_sz_retn;
- int flags;
-
- bzero(&gbs_cmd, sizeof(gbs_cmd));
- gbs_cmd.opcode = GET_BUFFER_STATUS;
- _lto2b(12, gbs_cmd.len);
- flags = SCSI_DATA_IN;
-
- if (scsi_scsi_cmd(sc_link, (struct scsi_generic *) &gbs_cmd,
- sizeof(gbs_cmd), (u_char *) &buf_sz_retn, sizeof(buf_sz_retn),
- 0, 100000, bp, flags | SCSI_NOSLEEP)) {
- printf("%s: not queued\n", ss->sc_dev.dv_xname);
- }
- bp->b_bcount = MIN(_3btol(buf_sz_retn.tgt_send_buf_len), bp->b_bcount);
-}
-
-#ifdef NOTYET
-int
-umax_compute_sizes(ss)
- struct ss_softc *ss;
-{
- ss->sio.scan_lines = ;
- ss->sio.scan_window_size = ;
-}
-
-int
-calc_umax_row_len(dpi, ww)
- int dpi;
- int ww;
-{
- int st[301];
- int i;
- int rowB = 0;
-
- for (i = 1; i <= 300; i++)
- st[i] = 1;
-
- for (i = 1; i <= 300 - dpi; i++)
- st[i * 300 / (300 - dpi)] = 0;
-
- for (i = 1; i <= (ww % 1200) / 4; i++) {
- if (st[i])
- rowB++;
- }
-
- return ((ww / 1200) * dpi + rowB);
-}
-#endif
diff --git a/sys/scsi/ss_mustek.c b/sys/scsi/ss_mustek.c
deleted file mode 100644
index 4b0aab182b2..00000000000
--- a/sys/scsi/ss_mustek.c
+++ /dev/null
@@ -1,646 +0,0 @@
-/* $OpenBSD: ss_mustek.c,v 1.27 2010/07/01 05:11:18 krw Exp $ */
-/* $NetBSD: ss_mustek.c,v 1.4 1996/05/05 19:52:57 christos Exp $ */
-
-/*
- * Copyright (c) 1995 Joachim Koenig-Baltes. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Joachim Koenig-Baltes.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * special driver for MUSTEK flatbed scanners MFS 06000CX and MFS 12000CX
- * these scanners come with their own scsi card, containing an NCR53C400
- * SCSI controller chip. I'm in the progress of writing a driver for this
- * card to work under NetBSD-current. I've hooked it up to a Seagate ST01
- * hostadapter in the meantime, giving 350KB/sec for higher resolutions!
- *
- * I tried to connect it to my Adaptec 1542B, but with no success. It seems,
- * it does not like synchronous negotiation between Hostadapter and other
- * targets, but I could not turn this off for the 1542B.
- *
- * There is also an other reason why you would not like to connect it to your
- * favourite SCSI host adapter: The Mustek DOES NOT DISCONNECT. It will block
- * other traffic from the bus while a transfer is active.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/fcntl.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/buf.h>
-#include <sys/proc.h>
-#include <sys/device.h>
-#include <sys/conf.h> /* for cdevsw */
-#include <sys/scanio.h>
-
-#include <scsi/scsi_all.h>
-#include <scsi/scsi_scanner.h>
-#include <scsi/scsiconf.h>
-#include <scsi/ssvar.h>
-#include <scsi/ss_mustek.h>
-
-int mustek_set_params(struct ss_softc *, struct scan_io *);
-int mustek_trigger_scanner(struct ss_softc *);
-void mustek_minphys(struct ss_softc *, struct buf *);
-int mustek_read(struct ss_softc *, struct scsi_xfer *xs, struct buf *);
-void mustek_read_done(struct scsi_xfer *);
-int mustek_rewind_scanner(struct ss_softc *);
-
-/* only used internally */
-int mustek_get_status(struct ss_softc *, int, int);
-void mustek_compute_sizes(struct ss_softc *);
-
-/*
- * structure for the special handlers
- */
-struct ss_special mustek_special = {
- mustek_set_params,
- mustek_trigger_scanner,
- NULL,
- mustek_minphys,
- mustek_read,
- mustek_rewind_scanner,
- NULL, /* no adf support right now */
- NULL /* no adf support right now */
-};
-
-/*
- * mustek_attach: attach special functions to ss
- */
-void
-mustek_attach(ss, sa)
- struct ss_softc *ss;
- struct scsi_attach_args *sa;
-{
-#ifdef SCSIDEBUG
- struct scsi_link *sc_link = sa->sa_sc_link;
-#endif
-
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_attach: start\n"));
- ss->sio.scan_scanner_type = 0;
-
- printf("\n%s: ", ss->sc_dev.dv_xname);
-
- /* first, check the model which determines resolutions */
- if (!bcmp(sa->sa_inqbuf->product, "MFS-06000CX", 11)) {
- ss->sio.scan_scanner_type = MUSTEK_06000CX;
- printf("Mustek 6000CX Flatbed 3-pass color scanner, 3 - 600 dpi\n");
- }
- if (!bcmp(sa->sa_inqbuf->product, "MFS-12000CX", 11)) {
- ss->sio.scan_scanner_type = MUSTEK_12000CX;
- printf("Mustek 12000CX Flatbed 3-pass color scanner, 6 - 1200 dpi\n");
- }
-
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_attach: scanner_type = %d\n",
- ss->sio.scan_scanner_type));
-
- /* install special handlers */
- ss->special = mustek_special;
-
- mustek_compute_sizes(ss);
-}
-
-/*
- * check the parameters if the mustek is capable of fulfilling it
- * but don't send the command to the scanner in case the user wants
- * to change parameters by more than one call
- */
-int
-mustek_set_params(ss, sio)
- struct ss_softc *ss;
- struct scan_io *sio;
-{
- int error;
-
- /*
- * if the scanner is triggered, then rewind it
- */
- if (ss->flags & SSF_TRIGGERED) {
- error = mustek_rewind_scanner(ss);
- if (error)
- return (error);
- }
-
- /* size constraints: 8.5" horizontally and 14" vertically */
-#ifdef MUSTEK_INCH_SPEC
- /* sizes must be a multiple of 1/8" */
- sio->scan_x_origin -= sio->scan_x_origin % 150;
- sio->scan_y_origin -= sio->scan_y_origin % 150;
- sio->scan_width -= sio->scan_width % 150;
- sio->scan_height -= sio->scan_height % 150;
-#endif
- if (sio->scan_width == 0 ||
- sio->scan_x_origin + sio->scan_width > 10200 ||
- sio->scan_height == 0 ||
- sio->scan_y_origin + sio->scan_height > 16800)
- return (EINVAL);
-
- /*
- * for now, only realize the values for the MUSTEK_06000CX
- * in the future, values for the MUSTEK_12000CX will be implemented
- */
-
- /*
- * resolution (dpi) must be <= 300 and a multiple of 3 or
- * between 300 and 600 and a multiple of 30
- */
- sio->scan_x_resolution -= sio->scan_x_resolution <= 300 ?
- sio->scan_x_resolution % 3 : sio->scan_x_resolution % 30;
- sio->scan_y_resolution -= sio->scan_y_resolution <= 300 ?
- sio->scan_y_resolution % 3 : sio->scan_y_resolution % 30;
- if (sio->scan_x_resolution < 3 || sio->scan_x_resolution > 600 ||
- sio->scan_x_resolution != sio->scan_y_resolution)
- return (EINVAL);
-
- /* assume brightness values are between 64 and 136 in steps of 3 */
- sio->scan_brightness -= (sio->scan_brightness - 64) % 3;
- if (sio->scan_brightness < 64 || sio->scan_brightness > 136)
- return (EINVAL);
-
- /* contrast values must be between 16 and 184 in steps of 7 */
- sio->scan_contrast -= (sio->scan_contrast - 16) % 7;
- if (sio->scan_contrast < 16 || sio->scan_contrast > 184)
- return (EINVAL);
-
- /*
- * velocity: between 0 (fast) and 4 (slow) which will be mapped
- * to 100% = 4, 80% = 3, 60% = 2, 40% = 1, 20% = 0
- * must be a multiple of 20
- */
- sio->scan_quality -= sio->scan_quality % 20;
- if (sio->scan_quality < 20 || sio->scan_quality > 100)
- return (EINVAL);
-
- switch (sio->scan_image_mode) {
- case SIM_BINARY_MONOCHROME:
- case SIM_DITHERED_MONOCHROME:
- case SIM_GRAYSCALE:
- case SIM_RED:
- case SIM_GREEN:
- case SIM_BLUE:
- break;
- default:
- return (EINVAL);
- }
-
- /* change ss_softc to the new values, but save ro-variables */
- sio->scan_scanner_type = ss->sio.scan_scanner_type;
- bcopy(sio, &ss->sio, sizeof(struct scan_io));
-
- mustek_compute_sizes(ss);
-
- return (0);
-}
-
-/*
- * trim the requested transfer to a multiple of the line size
- * this is called only from ssread() which guarantees, scanner is triggered
- * In the future, it will trim the transfer to not read to much at a time
- * because the mustek cannot disconnect. It will be calculated by the
- * resolution, the velocity and the number of bytes per line.
- */
-void
-mustek_minphys(ss, bp)
- struct ss_softc *ss;
- struct buf *bp;
-{
-#ifdef SCSIDEBUG
- struct scsi_link *sc_link = ss->sc_link;
-#endif
-
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_minphys: before: %ld\n",
- bp->b_bcount));
- bp->b_bcount -= bp->b_bcount %
- ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_minphys: after: %ld\n",
- bp->b_bcount));
-}
-
-/*
- * trigger the scanner to start a scan operation
- * this includes sending the mode- and window-data, starting the scanner
- * and getting the image size info
- */
-int
-mustek_trigger_scanner(ss)
- struct ss_softc *ss;
-{
- struct mustek_mode_select_cmd mode_cmd;
- struct mustek_mode_select_data mode_data;
- struct mustek_set_window_cmd window_cmd;
- struct mustek_set_window_data window_data;
- struct mustek_start_scan_cmd start_scan_cmd;
- struct scsi_link *sc_link = ss->sc_link;
- int pixel_tlx, pixel_tly, pixel_brx, pixel_bry, paperlength;
- int error;
-
- mustek_compute_sizes(ss);
-
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_trigger_scanner\n"));
-
- /*
- * set the window params and send the scsi command
- */
- bzero(&window_cmd, sizeof(window_cmd));
- window_cmd.opcode = MUSTEK_SET_WINDOW;
- window_cmd.length = sizeof(window_data);
-
- bzero(&window_data, sizeof(window_data));
- window_data.frame.header = MUSTEK_LINEART_BACKGROUND | MUSTEK_UNIT_SPEC;
-#ifdef MUSTEK_INCH_SPEC
- /* the positional values are all 1 byte because 256 / 8 = 32" */
- pixel_tlx = ss->sio.scan_x_origin / 150;
- pixel_tly = ss->sio.scan_y_origin / 150;
- pixel_brx = pixel_tlx + ss->sio.scan_width / 150;
- pixel_bry = pixel_tly + ss->sio.scan_height / 150;
-#else
- pixel_tlx = (ss->sio.scan_x_origin * ss->sio.scan_x_resolution) / 1200;
- pixel_tly = (ss->sio.scan_y_origin * ss->sio.scan_y_resolution) / 1200;
- pixel_brx = pixel_tlx +
- (ss->sio.scan_width * ss->sio.scan_x_resolution) / 1200;
- pixel_bry = pixel_tly +
- (ss->sio.scan_height * ss->sio.scan_y_resolution) / 1200;
-#endif
- _lto2l(pixel_tlx, window_data.frame.tl_x);
- _lto2l(pixel_tly, window_data.frame.tl_y);
- _lto2l(pixel_brx, window_data.frame.br_x);
- _lto2l(pixel_bry, window_data.frame.br_y);
-
-#if MUSTEK_WINDOWS >= 1
- window_data.window1 = window_data.frame;
- window_data.window1.header = MUSTEK_WINDOW_MASK | MUSTEK_UNIT_SPEC;
-#endif
-
- /* send the set window command to the scanner */
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_set_parms: set_window\n"));
- error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &window_cmd,
- sizeof(window_cmd), (u_char *) &window_data, sizeof(window_data),
- SCSI_RETRIES, 5000, NULL, SCSI_DATA_OUT);
- if (error)
- return (error);
-
- /*
- * do what it takes to actualize the mode
- */
- bzero(&mode_cmd, sizeof(mode_cmd));
- mode_cmd.opcode = MUSTEK_MODE_SELECT;
- _lto2b(sizeof(mode_data), mode_cmd.length);
-
- bzero(&mode_data, sizeof(mode_data));
- mode_data.mode =
- MUSTEK_MODE_MASK | MUSTEK_HT_PATTERN_BUILTIN | MUSTEK_UNIT_SPEC;
- if (ss->sio.scan_x_resolution <= 300) {
- mode_data.resolution = ss->sio.scan_x_resolution / 3;
- } else {
- /*
- * the resolution values is computed by modulo 100, but not
- * for 600dpi, where the value is 100 (a bit tricky, but ...)
- */
- mode_data.resolution =
- ((ss->sio.scan_x_resolution - 1) % 100) + 1;
- }
- mode_data.brightness = (ss->sio.scan_brightness - 64) / 3;
- mode_data.contrast = (ss->sio.scan_contrast - 16) / 7;
- mode_data.grain = 0;
- mode_data.velocity = ss->sio.scan_quality / 20 - 1;
-#ifdef MUSTEK_INCH_SPEC
- paperlength = 14 * 8; /* 14" */
-#else
- paperlength = 14 * ss->sio.scan_y_resolution; /* 14" */
-#endif
- _lto2l(paperlength, mode_data.paperlength);
-
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_trigger_scanner: mode_select\n"));
- /* send the command to the scanner */
- error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &mode_cmd,
- sizeof(mode_cmd), (u_char *) &mode_data, sizeof(mode_data),
- SCSI_RETRIES, 5000, NULL, SCSI_DATA_OUT);
- if (error)
- return (error);
-
- /*
- * now construct and send the start command
- */
- bzero(&start_scan_cmd,sizeof(start_scan_cmd));
- start_scan_cmd.opcode = MUSTEK_START_STOP;
- start_scan_cmd.mode = MUSTEK_SCAN_START;
- if (ss->sio.scan_x_resolution <= 300)
- start_scan_cmd.mode |= MUSTEK_RES_STEP_1;
- else
- start_scan_cmd.mode |= MUSTEK_RES_STEP_10;
- switch (ss->sio.scan_image_mode) {
- case SIM_BINARY_MONOCHROME:
- case SIM_DITHERED_MONOCHROME:
- start_scan_cmd.mode |= MUSTEK_BIT_MODE | MUSTEK_GRAY_FILTER;
- break;
- case SIM_GRAYSCALE:
- start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_GRAY_FILTER;
- break;
- case SIM_RED:
- start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_RED_FILTER;
- break;
- case SIM_GREEN:
- start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_GREEN_FILTER;
- break;
- case SIM_BLUE:
- start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_BLUE_FILTER;
- break;
- }
-
- /* send the command to the scanner */
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_trigger_scanner: start_scan\n"));
- error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &start_scan_cmd,
- sizeof(start_scan_cmd), NULL, 0,
- SCSI_RETRIES, 5000, NULL, 0);
- if (error)
- return (error);
-
- /*
- * now check if scanner ready this time with update of size info
- * we wait here so that if the user issues a read directly afterwards,
- * the scanner will respond directly (otherwise we had to sleep with
- * a buffer locked in memory)
- */
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_trigger_scanner: get_status\n"));
- error = mustek_get_status(ss, 60, 1);
- if (error)
- return (error);
-
- return (0);
-}
-
-/*
- * stop a scan operation in progress
- */
-int
-mustek_rewind_scanner(ss)
- struct ss_softc *ss;
-{
- struct mustek_start_scan_cmd cmd;
- struct scsi_link *sc_link = ss->sc_link;
- int error;
-
- if (ss->sio.scan_window_size != 0) {
- /*
- * only if not all data has been read, the scanner has to be
- * stopped
- */
- bzero(&cmd, sizeof(cmd));
- cmd.opcode = MUSTEK_START_STOP;
- cmd.mode = MUSTEK_SCAN_STOP;
-
- /* send the command to the scanner */
- SC_DEBUG(sc_link, SDEV_DB1,
- ("mustek_rewind_scanner: stop_scan\n"));
- error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd,
- sizeof(cmd), NULL, 0, SCSI_RETRIES, 5000, NULL, 0);
- if (error)
- return (error);
- }
-
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_rewind_scanner: end\n"));
-
- return (0);
-}
-
-/*
- * read the requested number of bytes/lines from the scanner
- */
-int
-mustek_read(ss, xs, bp)
- struct ss_softc *ss;
- struct scsi_xfer *xs;
- struct buf *bp;
-{
- struct mustek_read_cmd *cdb;
- u_long lines_to_read;
-
- SC_DEBUG(ss->sc_link, SDEV_DB1, ("mustek_read: start\n"));
-
- cdb = (struct mustek_read_cmd *)xs->cmd;
- xs->cmdlen = sizeof(*cdb);
-
- cdb->opcode = MUSTEK_READ;
-
- /* instead of the bytes, the mustek wants the number of lines */
- lines_to_read = bp->b_bcount /
- ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
- SC_DEBUG(ss->sc_link, SDEV_DB1, ("mustek_read: read %ld lines\n",
- lines_to_read));
- _lto3b(lines_to_read, cdb->length);
-
- xs->data = bp->b_data;
- xs->datalen = bp->b_bcount;
- xs->flags |= SCSI_DATA_IN;
- xs->done = mustek_read_done;
- xs->cookie = bp;
- xs->bp = bp;
-
- scsi_xs_exec(xs);
-
- return (0);
-}
-
-void
-mustek_read_done(struct scsi_xfer *xs)
-{
- struct ss_softc *ss = xs->sc_link->device_softc;
- struct buf *bp = xs->cookie;
- int error, s;
-
- switch (xs->error) {
- case XS_NOERROR:
- ss->sio.scan_lines -= bp->b_bcount /
- ((ss->sio.scan_pixels_per_line *
- ss->sio.scan_bits_per_pixel) / 8);
- ss->sio.scan_window_size -= bp->b_bcount;
- bp->b_error = 0;
- bp->b_resid = xs->resid;
- break;
-
- case XS_NO_CCB:
- /* The adapter is busy, requeue the buf and try it later. */
- BUFQ_REQUEUE(ss->sc_bufq, bp);
- scsi_xs_put(xs);
- SET(ss->flags, SSF_WAITING);
- timeout_add(&ss->timeout, 1);
- return;
-
- case XS_SENSE:
- case XS_SHORTSENSE:
-#ifdef SCSIDEBUG
- scsi_sense_print_debug(xs);
-#endif
- error = scsi_interpret_sense(xs);
- if (error == 0) {
- ss->sio.scan_lines -= bp->b_bcount /
- ((ss->sio.scan_pixels_per_line *
- ss->sio.scan_bits_per_pixel) / 8);
- ss->sio.scan_window_size -= bp->b_bcount;
- bp->b_error = 0;
- bp->b_resid = xs->resid;
- break;
- }
- if (error != ERESTART)
- xs->retries = 0;
- goto retry;
-
- case XS_BUSY:
- if (xs->retries) {
- if (scsi_delay(xs, 1) != ERESTART)
- xs->retries = 0;
- }
- goto retry;
-
- case XS_TIMEOUT:
-retry:
- if (xs->retries--) {
- scsi_xs_exec(xs);
- return;
- }
- /* FALLTHROUGH */
-
- default:
- bp->b_error = EIO;
- bp->b_flags |= B_ERROR;
- bp->b_resid = bp->b_bcount;
- break;
- }
-
- s = splbio();
- biodone(bp);
- splx(s);
- scsi_xs_put(xs);
-}
-
-/*
- * check if the scanner is ready to take commands
- * wait timeout seconds and try only every second
- * if update, then update picture size info
- *
- * returns EBUSY if scanner not ready
- */
-int
-mustek_get_status(ss, timeout, update)
- struct ss_softc *ss;
- int timeout, update;
-{
- struct mustek_get_status_cmd cmd;
- struct mustek_get_status_data data;
- struct scsi_link *sc_link = ss->sc_link;
- int error, lines, bytes_per_line;
-
- bzero(&cmd, sizeof(cmd));
- cmd.opcode = MUSTEK_GET_STATUS;
- cmd.length = sizeof(data);
-
- while (1) {
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_get_status: stat_cmd\n"));
- error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd,
- sizeof(cmd), (u_char *) &data, sizeof(data), SCSI_RETRIES,
- 5000, NULL, SCSI_DATA_IN);
- if (error)
- return (error);
- if ((data.ready_busy == MUSTEK_READY) ||
- (timeout-- <= 0))
- break;
- /* please wait a second */
- tsleep((caddr_t)mustek_get_status, PRIBIO + 1, "mtkrdy", hz);
- }
-
- if (update) {
- bytes_per_line = _2ltol(data.bytes_per_line);
- lines = _3ltol(data.lines);
- if (lines != ss->sio.scan_lines) {
- printf("mustek: lines actual(%d) != computed(%ld)\n",
- lines, ss->sio.scan_lines);
- return (EIO);
- }
- if (bytes_per_line * lines != ss->sio.scan_window_size) {
- printf("mustek: win-size actual(%d) != computed(%ld)\n",
- bytes_per_line * lines, ss->sio.scan_window_size);
- return (EIO);
- }
-
- SC_DEBUG(sc_link, SDEV_DB1,
- ("mustek_get_size: bpl=%ld, lines=%ld\n",
- (ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8,
- ss->sio.scan_lines));
- SC_DEBUG(sc_link, SDEV_DB1, ("window size = %ld\n",
- ss->sio.scan_window_size));
- }
-
- SC_DEBUG(sc_link, SDEV_DB1, ("mustek_get_status: end\n"));
- if (data.ready_busy == MUSTEK_READY)
- return (0);
- else
- return (EBUSY);
-}
-
-/*
- * mustek_compute_sizes: compute window_size and lines for the picture
- * this function is called from different places in the code
- */
-void
-mustek_compute_sizes(ss)
- struct ss_softc *ss;
-{
-
- switch (ss->sio.scan_image_mode) {
- case SIM_BINARY_MONOCHROME:
- case SIM_DITHERED_MONOCHROME:
- ss->sio.scan_bits_per_pixel = 1;
- break;
- case SIM_GRAYSCALE:
- case SIM_RED:
- case SIM_GREEN:
- case SIM_BLUE:
- ss->sio.scan_bits_per_pixel = 8;
- break;
- }
-
- /*
- * horizontal number of bytes is always a multiple of 2,
- * in 8-bit mode at least
- */
- ss->sio.scan_pixels_per_line =
- (ss->sio.scan_width * ss->sio.scan_x_resolution) / 1200;
- if (ss->sio.scan_bits_per_pixel == 1)
- /* make it a multiple of 16, and thus of 2 bytes */
- ss->sio.scan_pixels_per_line =
- (ss->sio.scan_pixels_per_line + 15) & 0xfffffff0;
- else
- ss->sio.scan_pixels_per_line =
- (ss->sio.scan_pixels_per_line + 1) & 0xfffffffe;
-
- ss->sio.scan_lines =
- (ss->sio.scan_height * ss->sio.scan_y_resolution) / 1200;
- ss->sio.scan_window_size = ss->sio.scan_lines *
- ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
-}
diff --git a/sys/scsi/ss_mustek.h b/sys/scsi/ss_mustek.h
deleted file mode 100644
index b692aa2c56a..00000000000
--- a/sys/scsi/ss_mustek.h
+++ /dev/null
@@ -1,180 +0,0 @@
-/* $OpenBSD: ss_mustek.h,v 1.7 2006/05/11 00:45:59 krw Exp $ */
-/* $NetBSD: ss_mustek.h,v 1.2 1996/03/19 03:08:37 mycroft Exp $ */
-
-/*
- * Copyright (c) 1995 Joachim Koenig-Baltes. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Joachim Koenig-Baltes.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _SS_MUSTEK_H_
-#define _SS_MUSTEK_H_ 1
-
-/*
- * support for MUSTEK flatbed SCSI scanners MFS-06000CX and MFS-12000CX
- * (600 and 1200 dpi horizontally resp), not conforming to the SCSI2 spec.
- */
-
-/*
- * Configuration section: describes the mode in which scanner is driven
- * MUSTEK_INCH_SPEC: frame/window sizes are given in inches instead of
- * pixels, note: unit is 1/8th of an inch
- * MUSTEK_WINDOWS: number of windows in a frame, up to 4 allowed,
- * not used yet, so set to 0
- */
-#define MUSTEK_INCH_SPEC /* use inches to specify sizes */
-#define MUSTEK_WINDOWS 0 /* no window support yet */
-
-/* mustek scsi commands */
-#define MUSTEK_SET_WINDOW 0x04 /* set image area and windows */
-#define MUSTEK_READ 0x08 /* read command */
-#define MUSTEK_GET_STATUS 0x0f /* image status */
-#define MUSTEK_MODE_SELECT 0x15 /* set resolution, paper length, .. */
-#define MUSTEK_ADF 0x10 /* ADF and backtracking selection */
-#define MUSTEK_START_STOP 0x1b /* start/stop scan */
-#define MUSTEK_LUT 0x55 /* look up table download */
-
-/* the size spec is at the same bit position in different commands */
-#define MUSTEK_UNIT_INCHES 0x00
-#define MUSTEK_UNIT_PIXELS 0x08
-#ifdef MUSTEK_INCH_SPEC
-#define MUSTEK_UNIT_SPEC MUSTEK_UNIT_INCHES
-#else
-#define MUSTEK_UNIT_SPEC MUSTEK_UNIT_PIXELS
-#endif
-
-/*
- * SCSI command formats
- */
-
-struct mustek_set_window_cmd {
- u_int8_t opcode; /* 0x04 */
- u_int8_t reserved[3];
- u_int8_t length; /* in bytes */
- u_int8_t control;
-};
-
-struct mustek_window {
- u_int8_t header; /* unit-defines also apply */
- u_int8_t tl_x[2]; /* LSB */
- u_int8_t tl_y[2];
- u_int8_t br_x[2];
- u_int8_t br_y[2];
-};
-
-struct mustek_set_window_data {
-#define MUSTEK_LINEART_BACKGROUND 0x00
-#define MUSTEK_HALFTONE_BACKGROUND 0x01
- struct mustek_window frame;
-#if MUSTEK_WINDOWS >= 1
-#define MUSTEK_WINDOW_MASK 0x80
- struct mustek_window window1;
-#endif
-#if MUSTEK_WINDOWS >= 2
- struct mustek_window window2;
-#endif
-#if MUSTEK_WINDOWS >= 3
- struct mustek_window window3;
-#endif
-#if MUSTEK_WINDOWS >= 4
- struct mustek_window window4;
-#endif
-};
-
-struct mustek_read_cmd {
- u_int8_t opcode; /* 0x08 */
- u_int8_t reserved;
- u_int8_t length[3];
- u_int8_t control;
-};
-
-struct mustek_get_status_cmd {
- u_int8_t opcode; /* 0x0f */
- u_int8_t reserved[3];
- u_int8_t length; /* 0x06 */
- u_int8_t control;
-};
-
-struct mustek_get_status_data {
-#define MUSTEK_READY 0
-#define MUSTEK_BUSY -1
- u_int8_t ready_busy; /* 0 = ready */
- u_int8_t bytes_per_line[2]; /* LSB */
- u_int8_t lines[3]; /* LSB */
-};
-
-struct mustek_mode_select_cmd {
- u_int8_t opcode; /* 0x15 */
- u_int8_t reserved[2];
- u_int8_t length[2];
- u_int8_t control;
-};
-
-/*
- * resolution settings:
- * MFS06000CX:
- * 1% : 0x01 0x02 ... 0x64
- * 3 6 ... 300 dpi
- * 10%: 0x1e 0x3c 0x5a 0x14 0x32 0x50 0x0a 0x28 0x46 0x64
- * 330 360 390 420 450 480 510 540 570 600 dpi
- * MFS12000CX:
- * 1% : 0x01 0x02 ... 0x64
- * 6 12 ... 600 dpi
- * 10%: 0x1e 0x3c 0x5a 0x14 0x32 0x50 0x0a 0x28 0x46 0x64
- * 660 720 780 840 900 960 1020 1080 1140 1200 dpi
- */
-struct mustek_mode_select_data {
-#define MUSTEK_MODE_MASK 0x83
-#define MUSTEK_HT_PATTERN_BUILTIN 0x00
-#define MUSTEK_HT_PATTERN_DOWNLOADED 0x10
- u_int8_t mode;
- u_int8_t resolution;
- u_int8_t brightness;
- u_int8_t contrast;
- u_int8_t grain; /* 0 = 8x8, ..... 5 = 2x2 */
- u_int8_t velocity; /* 0 = fast, ...., 4 = slow */
- u_int8_t reserved[2];
- u_int8_t paperlength[2]; /* LSB */
-};
-
-struct mustek_start_scan_cmd {
- u_int8_t opcode; /* 0x1b */
- u_int8_t reserved[3];
-#define MUSTEK_SCAN_STOP 0x00
-#define MUSTEK_SCAN_START 0x01
-#define MUSTEK_GRAY_FILTER 0x00
-#define MUSTEK_RED_FILTER 0x08
-#define MUSTEK_GREEN_FILTER 0x10
-#define MUSTEK_BLUE_FILTER 0x18
-#define MUSTEK_GRAY_MODE 0x40
-#define MUSTEK_BIT_MODE 0x00
-#define MUSTEK_RES_STEP_1 0x00
-#define MUSTEK_RES_STEP_10 0x80
- u_int8_t mode;
- u_int8_t control;
-};
-
-#endif /* _SS_MUSTEK_H_ */
diff --git a/sys/scsi/ss_scanjet.c b/sys/scsi/ss_scanjet.c
deleted file mode 100644
index 277555cdd0a..00000000000
--- a/sys/scsi/ss_scanjet.c
+++ /dev/null
@@ -1,605 +0,0 @@
-/* $OpenBSD: ss_scanjet.c,v 1.44 2010/07/01 05:11:18 krw Exp $ */
-/* $NetBSD: ss_scanjet.c,v 1.6 1996/05/18 22:58:01 christos Exp $ */
-
-/*
- * Copyright (c) 1995 Kenneth Stailey. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Kenneth Stailey.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * special functions for the HP ScanJet IIc and IIcx
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/fcntl.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/buf.h>
-#include <sys/proc.h>
-#include <sys/device.h>
-#include <sys/conf.h> /* for cdevsw */
-#include <sys/scanio.h>
-
-#include <scsi/scsi_all.h>
-#include <scsi/scsi_scanner.h>
-#include <scsi/scsiconf.h>
-#include <scsi/ssvar.h>
-
-int scanjet_set_params(struct ss_softc *, struct scan_io *);
-int scanjet_trigger_scanner(struct ss_softc *);
-int scanjet_read(struct ss_softc *, struct scsi_xfer *, struct buf *);
-void scanjet_read_done(struct scsi_xfer *);
-
-/* only used internally */
-int scanjet_ctl_write(struct ss_softc *, char *, u_int, int);
-int scanjet_ctl_read(struct ss_softc *, char *, u_int, int);
-int scanjet_set_window(struct ss_softc *, int);
-int scanjet_compute_sizes(struct ss_softc *, int);
-/* Maybe move to libkern? */
-#define atoi local_atoi
-__inline static int atoi(const char *);
-
-
-/*
- * structure for the special handlers
- */
-struct ss_special scanjet_special = {
- scanjet_set_params,
- scanjet_trigger_scanner,
- NULL,
- NULL, /* no special minphys */
- scanjet_read, /* scsi 6-byte read */
- NULL, /* no "rewind" code (yet?) */
- NULL, /* no adf support right now */
- NULL /* no adf support right now */
-};
-
-/*
- * scanjet_attach: attach special functions to ss
- */
-void
-scanjet_attach(ss, sa)
- struct ss_softc *ss;
- struct scsi_attach_args *sa;
-{
-#ifdef SCSIDEBUG
- struct scsi_link *sc_link = sa->sa_sc_link;
-#endif
- int error;
-
- SC_DEBUG(sc_link, SDEV_DB1, ("scanjet_attach: start\n"));
- ss->sio.scan_scanner_type = 0;
-
- printf("\n%s: ", ss->sc_dev.dv_xname);
-
- /* first, check the model (which determines nothing yet) */
-
- if (!bcmp(sa->sa_inqbuf->product, "C1750A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet IIc");
- }
- /* The IIp is a grayscale-only HP SCL scanner */
- if (!bcmp(sa->sa_inqbuf->product, "C1790A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet IIp");
- }
- if (!bcmp(sa->sa_inqbuf->product, "C2500A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet IIcx");
- }
- /* The 3p is a grayscale-only HP SCL scanner */
- if (!bcmp(sa->sa_inqbuf->product, "C2570A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet 3p");
- }
- /* The 3c/4c/6100C report as the same? */
- if (!bcmp(sa->sa_inqbuf->product, "C2520A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet 3c/4c/6100C");
- }
- if (!bcmp(sa->sa_inqbuf->product, "C1130A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet 4p");
- }
- if (!bcmp(sa->sa_inqbuf->product, "C5110A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet 5p");
- }
- if (!bcmp(sa->sa_inqbuf->product, "C6290A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet 4100C");
- }
- if (!bcmp(sa->sa_inqbuf->product, "C5190A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet 5100C");
- }
- if (!bcmp(sa->sa_inqbuf->product, "C7190A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet 5200C");
- }
- if (!bcmp(sa->sa_inqbuf->product, "C6270A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet 6200C");
- }
- if (!bcmp(sa->sa_inqbuf->product, "C7670A", 6)) {
- ss->sio.scan_scanner_type = HP_SCANJET_IIC;
- printf("HP ScanJet 6300C");
- }
-
- SC_DEBUG(sc_link, SDEV_DB1, ("scanjet_attach: scanner_type = %d\n",
- ss->sio.scan_scanner_type));
-
- /* now install special handlers */
- ss->special = scanjet_special;
-
- /*
- * fill in the rest of the scan_io struct by calling
- * set_window and compute_sizes routines
- */
- error = scanjet_set_window(ss, SCSI_POLL);
- if (error) {
- printf(" set_window failed\n");
- return;
- }
-
- error = scanjet_compute_sizes(ss, SCSI_POLL);
- if (error) {
- printf(" compute_sizes failed\n");
- return;
- }
-
- printf("\n");
-}
-
-/*
- * check the parameters if the scanjet is capable of fulfilling it
- * but don't send the command to the scanner in case the user wants
- * to change parameters by more than one call
- */
-int
-scanjet_set_params(ss, sio)
- struct ss_softc *ss;
- struct scan_io *sio;
-{
- int error;
-
-#if 0
- /*
- * if the scanner is triggered, then rewind it
- */
- if (ss->flags & SSF_TRIGGERED) {
- error = scanjet_rewind_scanner(ss);
- if (error)
- return (error);
- }
-#endif
-
- /* size constraints... */
- if (sio->scan_width == 0 ||
- sio->scan_x_origin + sio->scan_width > 10200 || /* 8.5" */
- sio->scan_height == 0 ||
- sio->scan_y_origin + sio->scan_height > 16800) /* 14" */
- return (EINVAL);
-
- /* resolution (dpi)... */
- if (sio->scan_x_resolution < 100 ||
- sio->scan_x_resolution > 400 ||
- sio->scan_y_resolution < 100 ||
- sio->scan_y_resolution > 400)
- return (EINVAL);
-
- switch (sio->scan_image_mode) {
- case SIM_BINARY_MONOCHROME:
- case SIM_DITHERED_MONOCHROME:
- case SIM_GRAYSCALE:
- case SIM_COLOR:
- break;
- default:
- return (EINVAL);
- }
-
- /* change ss_softc to the new values, but save ro-variables */
- sio->scan_scanner_type = ss->sio.scan_scanner_type;
- bcopy(sio, &ss->sio, sizeof(struct scan_io));
-
- error = scanjet_set_window(ss, 0);
- if (error) {
- uprintf("%s: set_window failed\n", ss->sc_dev.dv_xname);
- return (error);
- }
- error = scanjet_compute_sizes(ss, 0);
- if (error) {
- uprintf("%s: compute_sizes failed\n", ss->sc_dev.dv_xname);
- return (error);
- }
-
- return (0);
-}
-
-/*
- * trigger the scanner to start a scan operation
- * this includes sending the mode- and window-data,
- * and starting the scanner
- */
-int
-scanjet_trigger_scanner(ss)
- struct ss_softc *ss;
-{
- static char *escape_codes = "\033*f0S";
- int error;
-
- error = scanjet_set_window(ss, 0);
- if (error) {
- uprintf("%s: set_window failed\n", ss->sc_dev.dv_xname);
- return (error);
- }
- error = scanjet_compute_sizes(ss, 0);
- if (error) {
- uprintf("%s: compute_sizes failed\n", ss->sc_dev.dv_xname);
- return (error);
- }
-
- /* send "trigger" operation */
- error = scanjet_ctl_write(ss, escape_codes, strlen(escape_codes), 0);
- if (error) {
- uprintf("%s: trigger_scanner failed\n", ss->sc_dev.dv_xname);
- return (error);
- }
-
- return (0);
-}
-
-int
-scanjet_read(ss, xs, bp)
- struct ss_softc *ss;
- struct scsi_xfer *xs;
- struct buf *bp;
-{
- struct scsi_rw_scanner *cdb;
-
- SC_DEBUG(ss->sc_link, SDEV_DB1, ("scanjet_read: start\n"));
-
- cdb = (struct scsi_rw_scanner *)xs->cmd;
- xs->cmdlen = sizeof(*cdb);
-
- cdb->opcode = READ;
- _lto3b(bp->b_bcount, cdb->len);
-
- xs->data = bp->b_data;
- xs->datalen = bp->b_bcount;
- xs->flags |= SCSI_DATA_IN;
- xs->timeout = 100000;
- xs->done = scanjet_read_done;
- xs->cookie = bp;
- xs->bp = bp;
-
- scsi_xs_exec(xs);
-
- return (0);
-}
-
-void
-scanjet_read_done(struct scsi_xfer *xs)
-{
- struct ss_softc *ss = xs->sc_link->device_softc;
- struct buf *bp = xs->cookie;
- int error, s;
-
- switch (xs->error) {
- case XS_NOERROR:
- if (bp->b_bcount >= ss->sio.scan_window_size)
- ss->sio.scan_window_size = 0;
- else
- ss->sio.scan_window_size -= bp->b_bcount;
-
- bp->b_error = 0;
- bp->b_resid = xs->resid;
- break;
-
- case XS_NO_CCB:
- /* The adapter is busy, requeue the buf and try it later. */
- BUFQ_REQUEUE(ss->sc_bufq, bp);
- scsi_xs_put(xs);
- SET(ss->flags, SSF_WAITING);
- timeout_add(&ss->timeout, 1);
- return;
-
- case XS_SENSE:
- case XS_SHORTSENSE:
-#ifdef SCSIDEBUG
- scsi_sense_print_debug(xs);
-#endif
- error = scsi_interpret_sense(xs);
- if (error == 0) {
- if (bp->b_bcount >= ss->sio.scan_window_size)
- ss->sio.scan_window_size = 0;
- else
- ss->sio.scan_window_size -= bp->b_bcount;
- bp->b_error = 0;
- bp->b_resid = xs->resid;
- break;
- }
- if (error != ERESTART)
- xs->retries = 0;
- goto retry;
-
- case XS_BUSY:
- if (xs->retries) {
- if (scsi_delay(xs, 1) != ERESTART)
- xs->retries = 0;
- }
- goto retry;
-
- case XS_TIMEOUT:
-retry:
- if (xs->retries--) {
- scsi_xs_exec(xs);
- return;
- }
- /* FALLTHROUGH */
-
- default:
- bp->b_error = EIO;
- bp->b_flags |= B_ERROR;
- bp->b_resid = bp->b_bcount;
- break;
- }
-
- s = splbio();
- biodone(bp);
- splx(s);
- scsi_xs_put(xs);
-}
-
-/*
- * Do a synchronous write. Used to send control messages.
- */
-int
-scanjet_ctl_write(ss, buf, size, flags)
- struct ss_softc *ss;
- char *buf;
- u_int size;
- int flags;
-{
- struct scsi_rw_scanner cmd;
-
- bzero(&cmd, sizeof(cmd));
- cmd.opcode = WRITE;
- _lto3b(size, cmd.len);
- return (scsi_scsi_cmd(ss->sc_link, (struct scsi_generic *) &cmd,
- sizeof(cmd), (u_char *) buf, size, 0, 100000, NULL,
- flags | SCSI_DATA_OUT));
-}
-
-
-/*
- * Do a synchronous read. Used to read responses to control messages.
- */
-int
-scanjet_ctl_read(ss, buf, size, flags)
- struct ss_softc *ss;
- char *buf;
- u_int size;
- int flags;
-{
- struct scsi_rw_scanner cmd;
-
- bzero(&cmd, sizeof(cmd));
- cmd.opcode = READ;
- _lto3b(size, cmd.len);
- return (scsi_scsi_cmd(ss->sc_link, (struct scsi_generic *) &cmd,
- sizeof(cmd), (u_char *) buf, size, 0, 100000, NULL,
- flags | SCSI_DATA_IN));
-}
-
-
-#ifdef SCANJETDEBUG
-static void show_es(char *es)
-{
- char *p = es;
-
- while (*p) {
- if (*p == '\033')
- printf("[Esc]");
- else
- printf("%c", *p);
- ++p;
- }
- printf("\n");
-}
-#endif
-
-/*
- * simulate SCSI_SET_WINDOW for ScanJets
- */
-int
-scanjet_set_window(ss, flags)
- struct ss_softc *ss;
- int flags;
-{
- char escape_codes[128];
- size_t len;
- int n;
-
- snprintf(escape_codes, sizeof escape_codes,
- "\033*f%ldP\033*f%ldQ\033*f%ldX\033*f%ldY\033*a%dR\033*a%dS",
- ss->sio.scan_width / 4,
- ss->sio.scan_height / 4,
- ss->sio.scan_x_origin / 4,
- ss->sio.scan_y_origin / 4,
- ss->sio.scan_x_resolution,
- ss->sio.scan_y_resolution);
-
- switch (ss->sio.scan_image_mode) {
- case SIM_BINARY_MONOCHROME:
- ss->sio.scan_bits_per_pixel = 1;
- /*
- * Use line art mode (\033*aoT) and make image data be
- * min-is-white ala PBM (\033*a0I).
- */
- strlcat(escape_codes, "\033*a0T\033*a0I", sizeof escape_codes);
- break;
- case SIM_DITHERED_MONOCHROME:
- ss->sio.scan_bits_per_pixel = 1;
- /*
- * Use dithered mode (\033*a3T) and make image data be
- * min-is-white ala PBM (\033*a0I).
- */
- strlcat(escape_codes, "\033*a3T\033*a0I", sizeof escape_codes);
- break;
- case SIM_GRAYSCALE:
- ss->sio.scan_bits_per_pixel = 8;
- /*
- * Use grayscale mode (\033*a4T) and make image data be
- * min-is-black ala PGM (\033*a1I)
- */
- strlcat(escape_codes, "\033*a4T\033*a1I", sizeof escape_codes);
- break;
- case SIM_COLOR:
- ss->sio.scan_bits_per_pixel = 24;
- /*
- * Use RGB color mode (\033*a5T), make image data be
- * min-is-black ala PPM (\033*a1I) and use pass-through matrix,
- * i.e. disable NTSC (\033*u2T).
- */
- strlcat(escape_codes, "\033*a5T\033*a1I\033*u2T",
- sizeof escape_codes);
- break;
- }
-
- /*
- * If the escape sequence has been truncated at this point, appending
- * the next sequence will also cause truncation, and this time we pay
- * attention.
- */
- len = strlen(escape_codes);
- n = snprintf(escape_codes + len, sizeof escape_codes - len,
- "\033*a%dG\033*a%dL\033*a%dK",
- ss->sio.scan_bits_per_pixel,
- (int)(ss->sio.scan_brightness) - 128,
- (int)(ss->sio.scan_contrast) - 128);
-
- if (n >= sizeof escape_codes - len)
- return (ENOMEM);
- len += n;
-
- return (scanjet_ctl_write(ss, escape_codes, len, flags));
-}
-
-/* atoi() is from /sys/arch/amiga/dev/ite.c
- and is only used in scanjet_compute_sizes */
-
-__inline static int
-atoi(cp)
- const char *cp;
-{
- int n;
-
- for (n = 0; *cp && *cp >= '0' && *cp <= '9'; cp++)
- n = n * 10 + *cp - '0';
-
- return (n);
-}
-
-int
-scanjet_compute_sizes(ss, flags)
- struct ss_softc *ss;
- int flags;
-{
- int error;
- static char *wfail = "%s: interrogate write failed\n";
- static char *rfail = "%s: interrogate read failed\n";
- static char *dfail = "%s: bad data returned\n";
- static char *mono = "\033*s1025E"; /* bytes wide */
- static char *color = "\033*s1024E"; /* pixels wide */
- static char *high = "\033*s1026E"; /* pixels high */
- char response[20];
- char *p;
-
- /*
- * Deal with the fact that the HP ScanJet IIc uses 1/300" not 1/1200"
- * as its base unit of measurement. PINT uses 1/1200" (yes I know
- * ScanJet II's use decipoints as well but 1200 % 720 != 0)
- */
- ss->sio.scan_width = (ss->sio.scan_width + 3) & 0xfffffffc;
- ss->sio.scan_height = (ss->sio.scan_height + 3) & 0xfffffffc;
-
- switch (ss->sio.scan_image_mode) {
- case SIM_BINARY_MONOCHROME:
- case SIM_DITHERED_MONOCHROME:
- error = scanjet_ctl_write(ss, mono, strlen(mono), flags);
- break;
- case SIM_GRAYSCALE:
- case SIM_COLOR:
- error = scanjet_ctl_write(ss, color, strlen(color), flags);
- break;
- default:
- error = EIO;
- break;
- }
- if (error) {
- uprintf(wfail, ss->sc_dev.dv_xname);
- return (error);
- }
- error = scanjet_ctl_read(ss, response, 20, flags);
- if (error) {
- uprintf(rfail, ss->sc_dev.dv_xname);
- return (error);
- }
- p = strchr(response, 'd');
- if (p == NULL) {
- uprintf(dfail, ss->sc_dev.dv_xname);
- return (EIO);
- }
- ss->sio.scan_pixels_per_line = atoi(p + 1);
- if (ss->sio.scan_image_mode < SIM_GRAYSCALE)
- ss->sio.scan_pixels_per_line *= 8;
-
- error = scanjet_ctl_write(ss, high, strlen(high), flags);
- if (error) {
- uprintf(wfail, ss->sc_dev.dv_xname);
- return (error);
- }
- error = scanjet_ctl_read(ss, response, 20, flags);
- if (error) {
- uprintf(rfail, ss->sc_dev.dv_xname);
- return (error);
- }
- p = strchr(response, 'd');
- if (p == NULL) {
- uprintf(dfail, ss->sc_dev.dv_xname);
- return (EIO);
- }
- ss->sio.scan_lines = atoi(p + 1);
-
- ss->sio.scan_window_size = ss->sio.scan_lines *
- ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
-
- return (0);
-}