2005-12-11 15:16:03 +03:00
|
|
|
/* $NetBSD: ss_scanjet.c,v 1.44 2005/12/11 12:23:51 christos Exp $ */
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2001-11-13 09:54:32 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-12-11 15:16:03 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ss_scanjet.c,v 1.44 2005/12/11 12:23:51 christos Exp $");
|
2001-11-13 09:54:32 +03:00
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
2004-10-28 11:07:35 +04:00
|
|
|
#include <sys/bufq.h>
|
1996-02-18 23:32:40 +03:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/conf.h> /* for cdevsw */
|
|
|
|
#include <sys/scanio.h>
|
Improve handling of memory shortage, to fix problems like:
sd3(mpt0:0:1:0): unable to allocate scsipi_xfer
sd3: not queued, error 12
Havard Eidnes's analysis of this problem is that the scsipi_xfer pool is
competing for resources with other pools, including the the inode and vnode
pools which can grow quite large.
*_scsipi_cmd(): don't biodone the buffer if scsipi_make_xs() fails, let the
caller deal with the problem
start function of block devices drivers: dequeue the buffer after the
scsipi_command() call. If scsipi_command() fails with ENOMEM don't dequeue
the buffer, and schedule a callout to call the start function after
some delay.
scsipi_init(): prime the scsipi_xfer_pool with one page. This ensure that
there is always some scsipi_xfer to play with. If scsipi_command() fails
because of pool_get(), we're sure there will be resources available later,
when the pending commands have completed.
Reviewed by Jason Thorpe and Havard Eidnes.
Todo: remove the "unable to allocate scsipi_xfer" and "not queued, error %d"
printfs, but I choose to keep them for now, to help make sure the code does
what it should.
2004-08-28 00:37:28 +04:00
|
|
|
#include <sys/kernel.h>
|
1996-02-18 23:32:40 +03:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
2004-09-18 04:21:03 +04:00
|
|
|
#include <dev/scsipi/scsi_all.h>
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/scsi_scanner.h>
|
2004-09-18 04:21:03 +04:00
|
|
|
#include <dev/scsipi/scsipiconf.h>
|
2004-09-09 23:35:30 +04:00
|
|
|
#include <dev/scsipi/scsipi_base.h>
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/ssvar.h>
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
#define SCANJET_RETRIES 4
|
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static int scanjet_get_params(struct ss_softc *);
|
|
|
|
static int scanjet_set_params(struct ss_softc *, struct scan_io *);
|
|
|
|
static int scanjet_trigger_scanner(struct ss_softc *);
|
|
|
|
static int scanjet_read(struct ss_softc *, struct buf *);
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
/* only used internally */
|
2005-02-01 03:19:34 +03:00
|
|
|
static int scanjet_ctl_write(struct ss_softc *, char *, u_int);
|
|
|
|
static int scanjet_ctl_read(struct ss_softc *, char *, u_int);
|
2004-08-22 02:02:31 +04:00
|
|
|
static int scanjet_set_window(struct ss_softc *);
|
|
|
|
static int scanjet_compute_sizes(struct ss_softc *);
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* structure for the special handlers
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static struct ss_special scanjet_special = {
|
1996-02-18 23:32:40 +03:00
|
|
|
scanjet_set_params,
|
|
|
|
scanjet_trigger_scanner,
|
|
|
|
scanjet_get_params,
|
|
|
|
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
|
2004-08-22 02:02:31 +04:00
|
|
|
scanjet_attach(struct ss_softc *ss, struct scsipibus_attach_args *sa)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
1996-05-12 02:21:51 +04:00
|
|
|
int error;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(ss->sc_periph, SCSIPI_DB1, ("scanjet_attach: start\n"));
|
1996-02-18 23:32:40 +03:00
|
|
|
ss->sio.scan_scanner_type = 0;
|
|
|
|
|
2000-03-12 22:16:48 +03:00
|
|
|
printf("%s: ", ss->sc_dev.dv_xname);
|
1996-03-31 00:47:00 +03:00
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
/* first, check the model (which determines nothing yet) */
|
|
|
|
|
2001-07-18 22:27:08 +04:00
|
|
|
if (!memcmp(sa->sa_inqbuf.product, "C1750A", 6)) {
|
1996-02-18 23:32:40 +03:00
|
|
|
ss->sio.scan_scanner_type = HP_SCANJET_IIC;
|
1996-10-13 03:23:13 +04:00
|
|
|
printf("HP ScanJet IIc");
|
2002-09-15 01:41:24 +04:00
|
|
|
} else if (!memcmp(sa->sa_inqbuf.product, "C2500A", 6)) {
|
1996-02-18 23:32:40 +03:00
|
|
|
ss->sio.scan_scanner_type = HP_SCANJET_IIC;
|
1996-10-13 03:23:13 +04:00
|
|
|
printf("HP ScanJet IIcx");
|
2002-09-15 01:41:24 +04:00
|
|
|
} else if (!memcmp(sa->sa_inqbuf.product, "C2520A", 6)) {
|
|
|
|
ss->sio.scan_scanner_type = HP_SCANJET_IIC;
|
|
|
|
printf("HP ScanJet 4c");
|
|
|
|
} else if (!memcmp(sa->sa_inqbuf.product, "C1130A", 6)) {
|
1996-12-03 04:25:53 +03:00
|
|
|
ss->sio.scan_scanner_type = HP_SCANJET_IIC;
|
|
|
|
printf("HP ScanJet 4p");
|
2002-09-15 01:41:24 +04:00
|
|
|
} else if (!memcmp(sa->sa_inqbuf.product, "C5110A", 6)) {
|
1997-11-19 06:03:15 +03:00
|
|
|
ss->sio.scan_scanner_type = HP_SCANJET_IIC;
|
|
|
|
printf("HP ScanJet 5p");
|
2002-09-15 01:41:24 +04:00
|
|
|
} else {
|
|
|
|
ss->sio.scan_scanner_type = HP_SCANJET_IIC;
|
|
|
|
printf("HP ScanJet (unknown model)");
|
1997-11-19 06:03:15 +03:00
|
|
|
}
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
SC_DEBUG(ss->sc_periph, SCSIPI_DB1,
|
|
|
|
("scanjet_attach: scanner_type = %d\n",
|
1996-02-18 23:32:40 +03:00
|
|
|
ss->sio.scan_scanner_type));
|
|
|
|
|
|
|
|
/* now install special handlers */
|
|
|
|
ss->special = &scanjet_special;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
1996-03-31 00:47:00 +03:00
|
|
|
ss->sio.scan_brightness = 128;
|
|
|
|
ss->sio.scan_contrast = 128;
|
1996-02-18 23:32:40 +03:00
|
|
|
ss->sio.scan_quality = 100;
|
|
|
|
ss->sio.scan_image_mode = SIM_GRAYSCALE;
|
|
|
|
|
1996-05-12 02:21:51 +04:00
|
|
|
error = scanjet_set_window(ss);
|
|
|
|
if (error) {
|
1996-10-13 03:23:13 +04:00
|
|
|
printf(" set_window failed\n");
|
1996-05-12 02:21:51 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
error = scanjet_compute_sizes(ss);
|
|
|
|
if (error) {
|
1996-10-13 03:23:13 +04:00
|
|
|
printf(" compute_sizes failed\n");
|
1996-05-12 02:21:51 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1996-10-13 03:23:13 +04:00
|
|
|
printf("\n");
|
1996-02-18 23:32:40 +03:00
|
|
|
}
|
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
|
|
|
scanjet_get_params(struct ss_softc *ss)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
|
|
|
scanjet_set_params(struct ss_softc *ss, struct scan_io *sio)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
1996-05-12 02:21:51 +04:00
|
|
|
#if 0
|
1996-02-18 23:32:40 +03:00
|
|
|
/*
|
|
|
|
* 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;
|
2001-07-18 22:25:41 +04:00
|
|
|
memcpy(&ss->sio, sio, sizeof(struct scan_io));
|
1996-02-18 23:32:40 +03:00
|
|
|
|
1996-05-12 02:21:51 +04:00
|
|
|
error = scanjet_set_window(ss);
|
|
|
|
if (error) {
|
|
|
|
uprintf("%s: set_window failed\n", ss->sc_dev.dv_xname);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
error = scanjet_compute_sizes(ss);
|
|
|
|
if (error) {
|
|
|
|
uprintf("%s: compute_sizes failed\n", ss->sc_dev.dv_xname);
|
|
|
|
return (error);
|
|
|
|
}
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* trigger the scanner to start a scan operation
|
|
|
|
* this includes sending the mode- and window-data,
|
|
|
|
* and starting the scanner
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
|
|
|
scanjet_trigger_scanner(struct ss_softc *ss)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
|
|
|
char escape_codes[20];
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = scanjet_set_window(ss);
|
|
|
|
if (error) {
|
1996-05-12 02:21:51 +04:00
|
|
|
uprintf("%s: set_window failed\n", ss->sc_dev.dv_xname);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
error = scanjet_compute_sizes(ss);
|
|
|
|
if (error) {
|
|
|
|
uprintf("%s: compute_sizes failed\n", ss->sc_dev.dv_xname);
|
1996-02-18 23:32:40 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send "trigger" operation */
|
2004-04-22 04:17:10 +04:00
|
|
|
strlcpy(escape_codes, "\033*f0S", sizeof(escape_codes));
|
1999-04-05 23:19:34 +04:00
|
|
|
error = scanjet_ctl_write(ss, escape_codes, strlen(escape_codes));
|
1996-02-18 23:32:40 +03:00
|
|
|
if (error) {
|
1996-05-12 02:21:51 +04:00
|
|
|
uprintf("%s: trigger_scanner failed\n", ss->sc_dev.dv_xname);
|
1996-02-18 23:32:40 +03:00
|
|
|
return (error);
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
|
|
|
scanjet_read(struct ss_softc *ss, struct buf *bp)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
|
|
|
struct scsi_rw_scanner cmd;
|
2004-09-09 23:35:30 +04:00
|
|
|
struct scsipi_xfer *xs;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_periph *periph = ss->sc_periph;
|
1999-04-05 23:19:34 +04:00
|
|
|
int error;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill out the scsi command
|
|
|
|
*/
|
2001-07-18 22:21:04 +04:00
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
1996-02-18 23:32:40 +03:00
|
|
|
cmd.opcode = READ;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle "fixed-block-mode" tape drives by using the
|
|
|
|
* block count instead of the length.
|
|
|
|
*/
|
1996-03-19 06:05:15 +03:00
|
|
|
_lto3b(bp->b_bcount, cmd.len);
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* go ask the adapter to do all this for us
|
|
|
|
*/
|
2004-09-09 23:35:30 +04:00
|
|
|
xs = scsipi_make_xs(periph,
|
1997-10-01 05:18:38 +04:00
|
|
|
(struct scsipi_generic *) &cmd, sizeof(cmd),
|
2005-02-01 03:19:34 +03:00
|
|
|
(u_char *) bp->b_data, bp->b_bcount,
|
2004-09-09 23:35:30 +04:00
|
|
|
SCANJET_RETRIES, 100000, bp,
|
1999-10-01 02:57:52 +04:00
|
|
|
XS_CTL_NOSLEEP | XS_CTL_ASYNC | XS_CTL_DATA_IN);
|
2004-09-09 23:35:30 +04:00
|
|
|
if (xs == NULL) {
|
|
|
|
/*
|
|
|
|
* out of memory. Keep this buffer in the queue, and
|
|
|
|
* retry later.
|
|
|
|
*/
|
|
|
|
callout_reset(&ss->sc_callout, hz / 2, ssrestart,
|
|
|
|
periph);
|
|
|
|
return(0);
|
1996-02-18 23:32:40 +03:00
|
|
|
}
|
Improve handling of memory shortage, to fix problems like:
sd3(mpt0:0:1:0): unable to allocate scsipi_xfer
sd3: not queued, error 12
Havard Eidnes's analysis of this problem is that the scsipi_xfer pool is
competing for resources with other pools, including the the inode and vnode
pools which can grow quite large.
*_scsipi_cmd(): don't biodone the buffer if scsipi_make_xs() fails, let the
caller deal with the problem
start function of block devices drivers: dequeue the buffer after the
scsipi_command() call. If scsipi_command() fails with ENOMEM don't dequeue
the buffer, and schedule a callout to call the start function after
some delay.
scsipi_init(): prime the scsipi_xfer_pool with one page. This ensure that
there is always some scsipi_xfer to play with. If scsipi_command() fails
because of pool_get(), we're sure there will be resources available later,
when the pending commands have completed.
Reviewed by Jason Thorpe and Havard Eidnes.
Todo: remove the "unable to allocate scsipi_xfer" and "not queued, error %d"
printfs, but I choose to keep them for now, to help make sure the code does
what it should.
2004-08-28 00:37:28 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2005-10-15 21:29:10 +04:00
|
|
|
if (BUFQ_GET(ss->buf_queue) != bp)
|
Improve handling of memory shortage, to fix problems like:
sd3(mpt0:0:1:0): unable to allocate scsipi_xfer
sd3: not queued, error 12
Havard Eidnes's analysis of this problem is that the scsipi_xfer pool is
competing for resources with other pools, including the the inode and vnode
pools which can grow quite large.
*_scsipi_cmd(): don't biodone the buffer if scsipi_make_xs() fails, let the
caller deal with the problem
start function of block devices drivers: dequeue the buffer after the
scsipi_command() call. If scsipi_command() fails with ENOMEM don't dequeue
the buffer, and schedule a callout to call the start function after
some delay.
scsipi_init(): prime the scsipi_xfer_pool with one page. This ensure that
there is always some scsipi_xfer to play with. If scsipi_command() fails
because of pool_get(), we're sure there will be resources available later,
when the pending commands have completed.
Reviewed by Jason Thorpe and Havard Eidnes.
Todo: remove the "unable to allocate scsipi_xfer" and "not queued, error %d"
printfs, but I choose to keep them for now, to help make sure the code does
what it should.
2004-08-28 00:37:28 +04:00
|
|
|
panic("ssstart(): dequeued wrong buf");
|
|
|
|
#else
|
2005-10-15 21:29:10 +04:00
|
|
|
BUFQ_GET(ss->buf_queue);
|
Improve handling of memory shortage, to fix problems like:
sd3(mpt0:0:1:0): unable to allocate scsipi_xfer
sd3: not queued, error 12
Havard Eidnes's analysis of this problem is that the scsipi_xfer pool is
competing for resources with other pools, including the the inode and vnode
pools which can grow quite large.
*_scsipi_cmd(): don't biodone the buffer if scsipi_make_xs() fails, let the
caller deal with the problem
start function of block devices drivers: dequeue the buffer after the
scsipi_command() call. If scsipi_command() fails with ENOMEM don't dequeue
the buffer, and schedule a callout to call the start function after
some delay.
scsipi_init(): prime the scsipi_xfer_pool with one page. This ensure that
there is always some scsipi_xfer to play with. If scsipi_command() fails
because of pool_get(), we're sure there will be resources available later,
when the pending commands have completed.
Reviewed by Jason Thorpe and Havard Eidnes.
Todo: remove the "unable to allocate scsipi_xfer" and "not queued, error %d"
printfs, but I choose to keep them for now, to help make sure the code does
what it should.
2004-08-28 00:37:28 +04:00
|
|
|
#endif
|
2004-09-18 03:35:13 +04:00
|
|
|
error = scsipi_execute_xs(xs);
|
2004-09-09 23:35:30 +04:00
|
|
|
/* with a scsipi_xfer preallocated, scsipi_command can't fail */
|
|
|
|
KASSERT(error == 0);
|
|
|
|
ss->sio.scan_window_size -= bp->b_bcount;
|
|
|
|
if (ss->sio.scan_window_size < 0)
|
|
|
|
ss->sio.scan_window_size = 0;
|
1996-02-18 23:32:40 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do a synchronous write. Used to send control messages.
|
|
|
|
*/
|
2005-02-27 03:26:58 +03:00
|
|
|
static int
|
2005-05-30 08:25:32 +04:00
|
|
|
scanjet_ctl_write(struct ss_softc *ss, char *tbuf, u_int size)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
|
|
|
struct scsi_rw_scanner cmd;
|
1999-04-05 23:19:34 +04:00
|
|
|
int flags;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
1999-04-05 23:19:34 +04:00
|
|
|
flags = 0;
|
1998-04-22 23:44:18 +04:00
|
|
|
if ((ss->flags & SSF_AUTOCONF) != 0)
|
1999-10-01 02:57:52 +04:00
|
|
|
flags |= XS_CTL_DISCOVERY;
|
1998-04-22 23:44:18 +04:00
|
|
|
|
2001-07-18 22:21:04 +04:00
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
1996-02-18 23:32:40 +03:00
|
|
|
cmd.opcode = WRITE;
|
1996-03-19 06:05:15 +03:00
|
|
|
_lto3b(size, cmd.len);
|
2004-09-18 04:08:16 +04:00
|
|
|
|
2004-09-18 03:43:17 +04:00
|
|
|
return (scsipi_command(ss->sc_periph,
|
2005-05-30 08:25:32 +04:00
|
|
|
(void *)&cmd, sizeof(cmd), (void *)tbuf, size, 0, 100000, NULL,
|
2000-06-09 12:54:19 +04:00
|
|
|
flags | XS_CTL_DATA_OUT | XS_CTL_DATA_ONSTACK));
|
1996-02-18 23:32:40 +03:00
|
|
|
}
|
|
|
|
|
1996-05-12 02:21:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do a synchronous read. Used to read responses to control messages.
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
2005-05-30 08:25:32 +04:00
|
|
|
scanjet_ctl_read(struct ss_softc *ss, char *tbuf, u_int size)
|
1996-05-12 02:21:51 +04:00
|
|
|
{
|
|
|
|
struct scsi_rw_scanner cmd;
|
1999-04-05 23:19:34 +04:00
|
|
|
int flags;
|
1996-05-12 02:21:51 +04:00
|
|
|
|
1999-04-05 23:19:34 +04:00
|
|
|
flags = 0;
|
1998-04-22 23:44:18 +04:00
|
|
|
if ((ss->flags & SSF_AUTOCONF) != 0)
|
1999-10-01 02:57:52 +04:00
|
|
|
flags |= XS_CTL_DISCOVERY;
|
1998-04-22 23:44:18 +04:00
|
|
|
|
2001-07-18 22:21:04 +04:00
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
1996-05-12 02:21:51 +04:00
|
|
|
cmd.opcode = READ;
|
|
|
|
_lto3b(size, cmd.len);
|
2004-09-18 04:08:16 +04:00
|
|
|
|
2004-09-18 03:43:17 +04:00
|
|
|
return (scsipi_command(ss->sc_periph,
|
2005-05-30 08:25:32 +04:00
|
|
|
(void *)&cmd, sizeof(cmd), (void *)tbuf, size, 0, 100000, NULL,
|
2000-06-09 12:54:19 +04:00
|
|
|
flags | XS_CTL_DATA_IN | XS_CTL_DATA_ONSTACK));
|
1996-05-12 02:21:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
#ifdef SCANJETDEBUG
|
2004-08-22 02:02:31 +04:00
|
|
|
static void
|
|
|
|
show_es(char *es)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
1997-10-01 05:18:38 +04:00
|
|
|
char *p = es;
|
|
|
|
while (*p) {
|
|
|
|
if (*p == '\033')
|
|
|
|
printf("[Esc]");
|
|
|
|
else
|
|
|
|
printf("%c", *p);
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
printf("\n");
|
1996-02-18 23:32:40 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
/*
|
1996-02-18 23:32:40 +03:00
|
|
|
* simulate SCSI_SET_WINDOW for ScanJets
|
|
|
|
*/
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
|
|
|
scanjet_set_window(struct ss_softc *ss)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
2004-04-22 04:17:10 +04:00
|
|
|
char escape_codes[128], *p, *ep;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
p = escape_codes;
|
2004-04-22 04:17:10 +04:00
|
|
|
ep = &escape_codes[128];
|
|
|
|
|
|
|
|
p += snprintf(p, ep - p, "\033*f%ldP", ss->sio.scan_width / 4);
|
|
|
|
p += snprintf(p, ep - p, "\033*f%ldQ", ss->sio.scan_height / 4);
|
|
|
|
p += snprintf(p, ep - p, "\033*f%ldX", ss->sio.scan_x_origin / 4);
|
|
|
|
p += snprintf(p, ep - p, "\033*f%ldY", ss->sio.scan_y_origin / 4);
|
|
|
|
p += snprintf(p, ep - p, "\033*a%dR", ss->sio.scan_x_resolution);
|
|
|
|
p += snprintf(p, ep - p, "\033*a%dS", ss->sio.scan_y_resolution);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1996-02-18 23:32:40 +03:00
|
|
|
switch (ss->sio.scan_image_mode) {
|
|
|
|
case SIM_BINARY_MONOCHROME:
|
1996-05-12 02:21:51 +04:00
|
|
|
ss->sio.scan_bits_per_pixel = 1;
|
1996-02-18 23:32:40 +03:00
|
|
|
/* use "line art" mode */
|
2004-04-22 04:17:10 +04:00
|
|
|
strlcpy(p, "\033*a0T", ep - p);
|
1996-02-18 23:32:40 +03:00
|
|
|
p += strlen(p);
|
|
|
|
/* make image data be "min-is-white ala PBM */
|
2004-04-22 04:17:10 +04:00
|
|
|
strlcpy(p, "\033*a0I", ep - p);
|
1996-02-18 23:32:40 +03:00
|
|
|
p += strlen(p);
|
|
|
|
break;
|
|
|
|
case SIM_DITHERED_MONOCHROME:
|
1996-05-12 02:21:51 +04:00
|
|
|
ss->sio.scan_bits_per_pixel = 1;
|
1996-02-18 23:32:40 +03:00
|
|
|
/* use dithered mode */
|
2004-04-22 04:17:10 +04:00
|
|
|
strlcpy(p, "\033*a3T", ep - p);
|
1996-02-18 23:32:40 +03:00
|
|
|
p += strlen(p);
|
|
|
|
/* make image data be "min-is-white ala PBM */
|
2004-04-22 04:17:10 +04:00
|
|
|
strlcpy(p, "\033*a0I", ep - p);
|
1996-02-18 23:32:40 +03:00
|
|
|
p += strlen(p);
|
|
|
|
break;
|
|
|
|
case SIM_GRAYSCALE:
|
1996-05-12 02:21:51 +04:00
|
|
|
ss->sio.scan_bits_per_pixel = 8;
|
1996-02-18 23:32:40 +03:00
|
|
|
/* use grayscale mode */
|
2004-04-22 04:17:10 +04:00
|
|
|
strlcpy(p, "\033*a4T", ep - p);
|
1996-02-18 23:32:40 +03:00
|
|
|
p += strlen(p);
|
|
|
|
/* make image data be "min-is-black ala PGM */
|
2004-04-22 04:17:10 +04:00
|
|
|
strlcpy(p, "\033*a1I", ep - p);
|
1996-02-18 23:32:40 +03:00
|
|
|
p += strlen(p);
|
|
|
|
break;
|
|
|
|
case SIM_COLOR:
|
1996-05-12 02:21:51 +04:00
|
|
|
ss->sio.scan_bits_per_pixel = 24;
|
1996-02-18 23:32:40 +03:00
|
|
|
/* use RGB color mode */
|
2004-04-22 04:17:10 +04:00
|
|
|
strlcpy(p, "\033*a5T", ep - p);
|
1996-02-18 23:32:40 +03:00
|
|
|
p += strlen(p);
|
|
|
|
/* make image data be "min-is-black ala PPM */
|
2004-04-22 04:17:10 +04:00
|
|
|
strlcpy(p, "\033*a1I", ep - p);
|
1996-02-18 23:32:40 +03:00
|
|
|
p += strlen(p);
|
|
|
|
/* use pass-through matrix (disable NTSC) */
|
2004-04-22 04:17:10 +04:00
|
|
|
strlcpy(p, "\033*u2T", ep - p);
|
1996-02-18 23:32:40 +03:00
|
|
|
p += strlen(p);
|
1996-05-12 02:21:51 +04:00
|
|
|
break;
|
1996-02-18 23:32:40 +03:00
|
|
|
}
|
|
|
|
|
2004-04-22 04:17:10 +04:00
|
|
|
p += snprintf(p, ep - p, "\033*a%dG", ss->sio.scan_bits_per_pixel);
|
|
|
|
p += snprintf(p, ep - p, "\033*a%dL", (int)(ss->sio.scan_brightness) - 128);
|
|
|
|
p += snprintf(p, ep - p, "\033*a%dK", (int)(ss->sio.scan_contrast) - 128);
|
1996-02-18 23:32:40 +03:00
|
|
|
|
1999-04-05 23:19:34 +04:00
|
|
|
return (scanjet_ctl_write(ss, escape_codes, p - escape_codes));
|
1996-02-18 23:32:40 +03:00
|
|
|
}
|
|
|
|
|
2004-08-22 02:02:31 +04:00
|
|
|
static int
|
|
|
|
scanjet_compute_sizes(struct ss_softc *ss)
|
1996-02-18 23:32:40 +03:00
|
|
|
{
|
1996-05-12 02:21:51 +04:00
|
|
|
int error;
|
2001-04-25 21:53:04 +04:00
|
|
|
static const char *wfail = "%s: interrogate write failed\n";
|
|
|
|
static const char *rfail = "%s: interrogate read failed\n";
|
|
|
|
static const char *dfail = "%s: bad data returned\n";
|
1996-05-12 02:21:51 +04:00
|
|
|
char escape_codes[20];
|
|
|
|
char response[20];
|
|
|
|
char *p;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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:
|
2004-04-22 04:17:10 +04:00
|
|
|
/* bytes wide */
|
|
|
|
strlcpy(escape_codes, "\033*s1025E", sizeof(escape_codes));
|
1996-02-18 23:32:40 +03:00
|
|
|
break;
|
|
|
|
case SIM_GRAYSCALE:
|
|
|
|
case SIM_COLOR:
|
2004-04-22 04:17:10 +04:00
|
|
|
/* pixels wide */
|
|
|
|
strlcpy(escape_codes, "\033*s1024E", sizeof(escape_codes));
|
1996-02-18 23:32:40 +03:00
|
|
|
break;
|
|
|
|
}
|
1999-04-05 23:19:34 +04:00
|
|
|
error = scanjet_ctl_write(ss, escape_codes, strlen(escape_codes));
|
1996-05-12 02:21:51 +04:00
|
|
|
if (error) {
|
|
|
|
uprintf(wfail, ss->sc_dev.dv_xname);
|
|
|
|
return (error);
|
|
|
|
}
|
1999-04-05 23:19:34 +04:00
|
|
|
error = scanjet_ctl_read(ss, response, 20);
|
1996-05-12 02:21:51 +04:00
|
|
|
if (error) {
|
|
|
|
uprintf(rfail, ss->sc_dev.dv_xname);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
p = strchr(response, 'd');
|
|
|
|
if (p == 0) {
|
|
|
|
uprintf(dfail, ss->sc_dev.dv_xname);
|
|
|
|
return (EIO);
|
|
|
|
}
|
2002-09-15 01:41:24 +04:00
|
|
|
ss->sio.scan_pixels_per_line = strtoul(p + 1, NULL, 10);
|
1996-05-12 02:21:51 +04:00
|
|
|
if (ss->sio.scan_image_mode < SIM_GRAYSCALE)
|
|
|
|
ss->sio.scan_pixels_per_line *= 8;
|
1996-02-18 23:32:40 +03:00
|
|
|
|
2004-04-22 04:17:10 +04:00
|
|
|
/* pixels high */
|
|
|
|
strlcpy(escape_codes, "\033*s1026E", sizeof(escape_codes));
|
1999-04-05 23:19:34 +04:00
|
|
|
error = scanjet_ctl_write(ss, escape_codes, strlen(escape_codes));
|
1996-05-12 02:21:51 +04:00
|
|
|
if (error) {
|
|
|
|
uprintf(wfail, ss->sc_dev.dv_xname);
|
|
|
|
return (error);
|
|
|
|
}
|
1999-04-05 23:19:34 +04:00
|
|
|
error = scanjet_ctl_read(ss, response, 20);
|
1996-05-12 02:21:51 +04:00
|
|
|
if (error) {
|
|
|
|
uprintf(rfail, ss->sc_dev.dv_xname);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
p = strchr(response, 'd');
|
|
|
|
if (p == 0) {
|
|
|
|
uprintf(dfail, ss->sc_dev.dv_xname);
|
|
|
|
return (EIO);
|
|
|
|
}
|
2002-09-15 01:41:24 +04:00
|
|
|
ss->sio.scan_lines = strtoul(p + 1, NULL, 10);
|
1996-02-18 23:32:40 +03:00
|
|
|
|
|
|
|
ss->sio.scan_window_size = ss->sio.scan_lines *
|
|
|
|
((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
|
1996-05-12 02:21:51 +04:00
|
|
|
|
|
|
|
return (0);
|
1996-02-18 23:32:40 +03:00
|
|
|
}
|