diff options
-rw-r--r-- | sys/scsi/files.scsi | 6 | ||||
-rw-r--r-- | sys/scsi/scsi_conf.h | 50 | ||||
-rw-r--r-- | sys/scsi/scsi_scanner.h | 114 | ||||
-rw-r--r-- | sys/scsi/scsiconf.c | 198 | ||||
-rw-r--r-- | sys/scsi/scsiconf.h | 24 | ||||
-rw-r--r-- | sys/scsi/ss.c | 477 | ||||
-rw-r--r-- | sys/scsi/ss_mustek.c | 623 | ||||
-rw-r--r-- | sys/scsi/ss_mustek.h | 218 | ||||
-rw-r--r-- | sys/scsi/ss_scanjet.c | 410 | ||||
-rw-r--r-- | sys/scsi/ssvar.h | 79 |
10 files changed, 2092 insertions, 107 deletions
diff --git a/sys/scsi/files.scsi b/sys/scsi/files.scsi index c1060f0c18a..554ac2ac95c 100644 --- a/sys/scsi/files.scsi +++ b/sys/scsi/files.scsi @@ -1,4 +1,4 @@ -# $NetBSD: files.scsi,v 1.1 1995/04/17 07:15:40 cgd Exp $ +# $NetBSD: files.scsi,v 1.2 1996/02/18 20:32:40 mycroft Exp $ # # Config.new file and device description for machine-independent SCSI code. # Included by ports that need it. Ports that usee it must provide @@ -19,6 +19,10 @@ device sd at scsibus: disk file scsi/sd.c sd needs-flag device st at scsibus: tape file scsi/st.c st needs-flag +device ss at scsibus: tape +file scsi/ss.c ss needs-flag +file scsi/ss_mustek.c ss +file scsi/ss_scanjet.c ss device su at scsibus: disk file scsi/su.c su needs-flag device uk at scsibus: disk diff --git a/sys/scsi/scsi_conf.h b/sys/scsi/scsi_conf.h new file mode 100644 index 00000000000..65a67f410d1 --- /dev/null +++ b/sys/scsi/scsi_conf.h @@ -0,0 +1,50 @@ +/* $NetBSD: scsi_conf.h,v 1.2 1996/02/18 20:32:41 mycroft Exp $ */ + +/* + * Copyright (c) 1995 Christos Zoulas. 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 Christos Zoulas. + * 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/conf.h> + +#include "ch.h" +cdev_decl(ch); + +#include "ss.h" +cdev_decl(ss); + +#include "sd.h" +bdev_decl(sd); +cdev_decl(sd); + +#include "st.h" +bdev_decl(st); +cdev_decl(st); + +#include "cd.h" +bdev_decl(cd); +cdev_decl(cd); diff --git a/sys/scsi/scsi_scanner.h b/sys/scsi/scsi_scanner.h new file mode 100644 index 00000000000..0db8028c2f6 --- /dev/null +++ b/sys/scsi/scsi_scanner.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) 1995 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. + */ + +/* + * SCSI scanner interface description + */ + +#ifndef _SCSI_SCANNER_H_ +#define _SCSI_SCANNER_H_ + +/* SCSI scanner commands */ +#define GET_IMAGE_STATUS 0x0f +#define READ_BIG 0x28 +#define WRITE_BIG 0x2a +#define OBJECT_POSITION 0x31 +#define GET_BUFFER_STATUS 0x34 + +/* generic scanner command formats */ + +struct scsi_rw_scanner { +#define READ 0x08 +#define WRITE 0x0a + u_char opcode; + u_char byte2; +#define SRW_FIXED 0x01 + u_char len[3]; + u_char control; +}; + +struct scsi_start_stop { + u_char opcode; + u_char byte2; + u_char unused[2]; + u_char how; +#define SSS_STOP 0x00 +#define SSS_START 0x01 +#define SSS_LOEJ 0x02 + u_char control; +}; + +struct scsi_set_window { +#define SET_WINDOW 0x24 /* set params of image area and windows */ +#define GET_WINDOW 0x25 + u_char opcode; + u_char byte2; + u_char reserved[4]; + u_char len[3]; + u_char control; +}; + +struct scsi_window_header { + u_char reserved[6]; + u_char len[2]; /* MSB-LSB */ +}; + +struct scsi_window_data { + u_char window_id; /* must be zero */ + u_char res1:7; + u_char auto_bit:1; + u_char x_res[2]; + u_char y_res[2]; + u_char x_org[4]; + u_char y_org[4]; + u_char width[4]; + u_char length[4]; + u_char brightness; + u_char threshold; + u_char contrast; + u_char image_comp; /* image composition (data type) */ + u_char bits_per_pixel; + u_char halftone_pattern[2]; + u_char rif:1; /* reverse image format (mono negative) */ + u_char res2:4; + u_char pad_type:3; + u_char bit_ordering[2]; + u_char compression_type; + u_char compression_arg; + u_char res3[6]; +}; + +/* mustek scsi commands */ + +#define MUSTEK_SET_WINDOW 0x04 /* set image area and windows */ +#define MUSTEK_ADF 0x10 /* ADF and backtracking selection */ +#define MUSTEK_LUT 0x55 /* look up table download */ + +#endif /* _SCSI_SCANNER_H_ */ diff --git a/sys/scsi/scsiconf.c b/sys/scsi/scsiconf.c index f208f56e700..697a98966d1 100644 --- a/sys/scsi/scsiconf.c +++ b/sys/scsi/scsiconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: scsiconf.c,v 1.47 1996/01/12 11:32:37 pk Exp $ */ +/* $NetBSD: scsiconf.c,v 1.49 1996/02/18 20:32:43 mycroft Exp $ */ /* * Copyright (c) 1994 Charles Hannum. All rights reserved. @@ -51,6 +51,7 @@ #include <sys/systm.h> #include <sys/malloc.h> #include <sys/device.h> +#include <sys/cpu.h> #include <scsi/scsi_all.h> #include <scsi/scsiconf.h> @@ -85,6 +86,7 @@ struct scsi_device probe_switch = { int scsibusmatch __P((struct device *, void *, void *)); void scsibusattach __P((struct device *, struct device *, void *)); +int scsibussubmatch __P((struct device *, void *, void *)); struct cfdriver scsibuscd = { NULL, "scsibus", scsibusmatch, scsibusattach, DV_DULL, @@ -257,106 +259,106 @@ struct scsi_quirk_inquiry_pattern { }; struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = { - {T_CDROM, T_REMOV, - "CHINON ", "CD-ROM CDS-431 ", "", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "Chinon ", "CD-ROM CDS-525 ", "", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "CHINON ", "CD-ROM CDS-535 ", "", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "DENON ", "DRD-25X ", "V", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "IMS ", "CDD521/10 ", "2.06", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "MEDIAVIS", "CDR-H93MV ", "1.31", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "NEC ", "CD-ROM DRIVE:55 ", "", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "NEC ", "CD-ROM DRIVE:83 ", "", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "NEC ", "CD-ROM DRIVE:84 ", "", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "NEC ", "CD-ROM DRIVE:841", "", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "SONY ", "CD-ROM CDU-541 ", "", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "SONY ", "CD-ROM CDU-55S ", "", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "SONY ", "CD-ROM CDU-8003A", "", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "SONY ", "CD-ROM CDU-8012 ", "", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "TEAC ", "CD-ROM ", "1.06", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "TEXEL ", "CD-ROM ", "1.06", SDEV_NOLUNS}, - {T_CDROM, T_REMOV, - "TEXEL ", "CD-ROM DM-XX24 K", "1.10", SDEV_NOLUNS}, - - {T_DIRECT, T_FIXED, - "EMULEX ", "MD21/S2 ESDI", "A00", SDEV_FORCELUNS}, - {T_DIRECT, T_FIXED, - "MAXTOR ", "XT-3280 ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "MAXTOR ", "XT-4380S ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "MAXTOR ", "MXT-1240S ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "MAXTOR ", "XT-4170S ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "MAXTOR ", "XT-8760S ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "MAXTOR ", "LXT-213S ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "MAXTOR ", "LXT-213S SUN0207", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "MST ", "SnapLink ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "QUANTUM ", "LPS525S ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "QUANTUM ", "P105S 910-10-94x", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "QUANTUM ", "PD1225S ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "QUANTUM ", "PD210S SUN0207", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "RODIME ", "RO3000S ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "SEAGATE ", "ST157N ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "SEAGATE ", "ST296 ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "SEAGATE ", "ST296N ", "", SDEV_NOLUNS}, - {T_DIRECT, T_FIXED, - "TOSHIBA ", "MK538FB ", "6027", SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "CHINON ", "CD-ROM CDS-431 ", ""}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "Chinon ", "CD-ROM CDS-525 ", ""}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "CHINON ", "CD-ROM CDS-535 ", ""}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "DENON ", "DRD-25X ", "V"}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "IMS ", "CDD521/10 ", "2.06"}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "MEDIAVIS", "CDR-H93MV ", "1.31"}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "NEC ", "CD-ROM DRIVE:55 ", ""}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "NEC ", "CD-ROM DRIVE:83 ", ""}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "NEC ", "CD-ROM DRIVE:84 ", ""}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "NEC ", "CD-ROM DRIVE:841", ""}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "SONY ", "CD-ROM CDU-541 ", ""}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "SONY ", "CD-ROM CDU-55S ", ""}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "SONY ", "CD-ROM CDU-8003A", ""}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "SONY ", "CD-ROM CDU-8012 ", ""}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "TEAC ", "CD-ROM ", "1.06"}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "TEXEL ", "CD-ROM ", "1.06"}, SDEV_NOLUNS}, + {{T_CDROM, T_REMOV, + "TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS}, + + {{T_DIRECT, T_FIXED, + "EMULEX ", "MD21/S2 ESDI", "A00"}, SDEV_FORCELUNS}, + {{T_DIRECT, T_FIXED, + "MAXTOR ", "XT-3280 ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "MAXTOR ", "XT-4380S ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "MAXTOR ", "MXT-1240S ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "MAXTOR ", "XT-4170S ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "MAXTOR ", "XT-8760S ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "MAXTOR ", "LXT-213S ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "MAXTOR ", "LXT-213S SUN0207", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "MST ", "SnapLink ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "QUANTUM ", "LPS525S ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "QUANTUM ", "P105S 910-10-94x", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "QUANTUM ", "PD1225S ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "QUANTUM ", "PD210S SUN0207", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "RODIME ", "RO3000S ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "SEAGATE ", "ST157N ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "SEAGATE ", "ST296 ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "SEAGATE ", "ST296N ", ""}, SDEV_NOLUNS}, + {{T_DIRECT, T_FIXED, + "TOSHIBA ", "MK538FB ", "6027"}, SDEV_NOLUNS}, /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */ - {T_SEQUENTIAL, T_REMOV, - " ", " ", " ", SDEV_NOLUNS}, - {T_SEQUENTIAL, T_REMOV, - "CALIPER ", "CP150 ", "", SDEV_NOLUNS}, - {T_SEQUENTIAL, T_REMOV, - "EXABYTE ", "EXB-8200 ", "", SDEV_NOLUNS}, - {T_SEQUENTIAL, T_REMOV, - "SONY ", "SDT-2000 ", "2.09", SDEV_NOLUNS}, - {T_SEQUENTIAL, T_REMOV, - "SONY ", "SDT-5000 ", "3.", SDEV_NOSYNCWIDE}, - {T_SEQUENTIAL, T_REMOV, - "SONY ", "SDT-5200 ", "3.", SDEV_NOLUNS}, - {T_SEQUENTIAL, T_REMOV, - "TANDBERG", " TDC 3600 ", "", SDEV_NOLUNS}, + {{T_SEQUENTIAL, T_REMOV, + " ", " ", " "}, SDEV_NOLUNS}, + {{T_SEQUENTIAL, T_REMOV, + "CALIPER ", "CP150 ", ""}, SDEV_NOLUNS}, + {{T_SEQUENTIAL, T_REMOV, + "EXABYTE ", "EXB-8200 ", ""}, SDEV_NOLUNS}, + {{T_SEQUENTIAL, T_REMOV, + "SONY ", "SDT-2000 ", "2.09"}, SDEV_NOLUNS}, + {{T_SEQUENTIAL, T_REMOV, + "SONY ", "SDT-5000 ", "3."}, SDEV_NOSYNCWIDE}, + {{T_SEQUENTIAL, T_REMOV, + "SONY ", "SDT-5200 ", "3."}, SDEV_NOLUNS}, + {{T_SEQUENTIAL, T_REMOV, + "TANDBERG", " TDC 3600 ", ""}, SDEV_NOLUNS}, /* Following entry reported as a Tandberg 3600; ref. PR1933 */ - {T_SEQUENTIAL, T_REMOV, - "ARCHIVE ", "VIPER 150 21247", "", SDEV_NOLUNS}, - {T_SEQUENTIAL, T_REMOV, - "WANGTEK ", "5099ES SCSI", "", SDEV_NOLUNS}, - {T_SEQUENTIAL, T_REMOV, - "WANGTEK ", "5150ES SCSI", "", SDEV_NOLUNS}, - {T_SEQUENTIAL, T_REMOV, - "WangDAT ", "Model 1300 ", "02.4", SDEV_NOSYNCWIDE}, - {T_SEQUENTIAL, T_REMOV, - "WangDAT ", "Model 2600 ", "01.7", SDEV_NOSYNCWIDE}, - {T_SEQUENTIAL, T_REMOV, - "WangDAT ", "Model 3200 ", "02.2", SDEV_NOSYNCWIDE}, + {{T_SEQUENTIAL, T_REMOV, + "ARCHIVE ", "VIPER 150 21247", ""}, SDEV_NOLUNS}, + {{T_SEQUENTIAL, T_REMOV, + "WANGTEK ", "5099ES SCSI", ""}, SDEV_NOLUNS}, + {{T_SEQUENTIAL, T_REMOV, + "WANGTEK ", "5150ES SCSI", ""}, SDEV_NOLUNS}, + {{T_SEQUENTIAL, T_REMOV, + "WangDAT ", "Model 1300 ", "02.4"}, SDEV_NOSYNCWIDE}, + {{T_SEQUENTIAL, T_REMOV, + "WangDAT ", "Model 2600 ", "01.7"}, SDEV_NOSYNCWIDE}, + {{T_SEQUENTIAL, T_REMOV, + "WangDAT ", "Model 3200 ", "02.2"}, SDEV_NOSYNCWIDE}, }; /* diff --git a/sys/scsi/scsiconf.h b/sys/scsi/scsiconf.h index ef5e32aaa5a..9df8aee05e4 100644 --- a/sys/scsi/scsiconf.h +++ b/sys/scsi/scsiconf.h @@ -1,4 +1,4 @@ -/* $NetBSD: scsiconf.h,v 1.26 1996/01/12 22:43:31 thorpej Exp $ */ +/* $NetBSD: scsiconf.h,v 1.28 1996/02/18 20:32:45 mycroft Exp $ */ /* * Copyright (c) 1993, 1994, 1995 Charles Hannum. All rights reserved. @@ -84,6 +84,8 @@ typedef int boolean; * scsi system to find the associated other parts. */ +struct buf; +struct scsi_xfer; /* * These entrypoints are called by the high-end drivers to get services from @@ -91,10 +93,10 @@ typedef int boolean; * these statically allocated. */ struct scsi_adapter { - int (*scsi_cmd)(); + int (*scsi_cmd) __P((struct scsi_xfer *)); void (*scsi_minphys) __P((struct buf *)); - int (*open_target_lu)(); - int (*close_target_lu)(); + int (*open_target_lu) __P((void)); + int (*close_target_lu) __P((void)); }; /* @@ -111,16 +113,18 @@ struct scsi_adapter { * of these statically allocated. */ struct scsi_device { - int (*err_handler)(); /* returns -1 to say err processing done */ - void (*start)(); - int (*async)(); + int (*err_handler) __P((struct scsi_xfer *)); + /* returns -1 to say err processing done */ + void (*start) __P((void *)); + + int (*async) __P((void)); /* * When called with `0' as the second argument, we expect status * back from the upper-level driver. When called with a `1', * we're simply notifying the upper-level driver that the command * is complete and expect no status back. */ - int (*done)( /* struct scsi_xfer *, int */ ); + int (*done) __P((struct scsi_xfer *, int)); }; /* @@ -270,6 +274,7 @@ int scsi_inquire __P((struct scsi_link *, struct scsi_inquiry_data *, int)); int scsi_prevent __P((struct scsi_link *, int, int)); int scsi_start __P((struct scsi_link *, int, int)); void scsi_done __P((struct scsi_xfer *)); +void scsi_user_done __P((struct scsi_xfer *)); int scsi_scsi_cmd __P((struct scsi_link *, struct scsi_generic *, int cmdlen, u_char *data_addr, int datalen, int retries, @@ -281,6 +286,9 @@ void sc_print_addr __P((struct scsi_link *)); void show_scsi_xs __P((struct scsi_xfer *)); void show_scsi_cmd __P((struct scsi_xfer *)); void show_mem __P((u_char *, int)); +int scsi_probe_busses __P((int, int, int)); +void scsi_strvis __P((u_char *, u_char *, int)); + void lto3b __P((u_int32_t val, u_int8_t *bytes)); u_int32_t _3btol __P((u_int8_t *bytes)); diff --git a/sys/scsi/ss.c b/sys/scsi/ss.c new file mode 100644 index 00000000000..46769cbaea3 --- /dev/null +++ b/sys/scsi/ss.c @@ -0,0 +1,477 @@ +/* $NetBSD: ss.c,v 1.6 1996/02/19 00:06:07 mycroft Exp $ */ + +/* + * Copyright (c) 1995 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/types.h> +#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> +#include <sys/proc.h> +#include <sys/user.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> + +#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 + +int ssmatch __P((struct device *, void *, void *)); +void ssattach __P((struct device *, struct device *, void *)); + +struct cfdriver sscd = { + NULL, "ss", ssmatch, ssattach, DV_DULL, sizeof(struct ss_softc) +}; + +void ssstrategy __P((struct buf *)); +void ssstart __P((void *)); + +struct scsi_device ss_switch = { + NULL, + ssstart, + NULL, + NULL, +}; + +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 ", "C2500A ", ""}, +}; + +int +ssmatch(parent, match, aux) + struct device *parent; + void *match, *aux; +{ + struct scsibus_attach_args *sa = aux; + int priority; + + (void)scsi_inqmatch(sa->sa_inqbuf, + (caddr_t)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 scsibus_attach_args *sa = aux; + struct scsi_link *sc_link = sa->sa_sc_link; + + SC_DEBUG(sc_link, SDEV_DB2, ("ssattach: ")); + + /* + * Store information needed to contact our base driver + */ + ss->sc_link = sc_link; + sc_link->device = &ss_switch; + sc_link->device_softc = ss; + sc_link->openings = 1; + + /* + * look for non-standard scanners with help of the quirk table + * and install functions for special handling + */ + SC_DEBUG(sc_link, SDEV_DB2, ("ssattach:\n")); + if (!bcmp(sa->sa_inqbuf->vendor, "MUSTEK ", 8)) + mustek_attach(ss, sa); + if (!bcmp(sa->sa_inqbuf->vendor, "HP ", 8)) + scanjet_attach(ss, sa); + if (ss->special == NULL) { + /* XXX add code to restart a SCSI2 scanner, if any */ + } + + /* + * Set up the buf queue for this device + */ + ss->buf_queue.b_active = 0; + ss->buf_queue.b_actf = 0; + ss->buf_queue.b_actb = &ss->buf_queue.b_actf; +} + +/* + * 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 >= sscd.cd_ndevs) + return (ENXIO); + ss = sscd.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, sscd.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, + 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 + * occurence of an open device + */ +int +ssclose(dev) + dev_t dev; +{ + struct ss_softc *ss = sscd.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; +{ + register struct ss_softc *ss = sscd.cd_devs[SSUNIT(bp->b_dev)]; + + (ss->sc_link->adapter->scsi_minphys)(bp); + + /* + * 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 = sscd.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); + } + 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 = sscd.cd_devs[SSUNIT(bp->b_dev)]; + struct buf *dp; + int s; + + SC_DEBUG(ss->sc_link, SDEV_DB1, + ("ssstrategy %d 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 immediatly + */ + if (bp->b_bcount == 0) + goto done; + + s = splbio(); + + /* + * 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())) + */ + dp = &ss->buf_queue; + bp->b_actf = NULL; + bp->b_actb = dp->b_actb; + *dp->b_actb = bp; + dp->b_actb = &bp->b_actf; + + /* + * 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..) + */ + ssstart(ss); + + splx(s); + return; +bad: + bp->b_flags |= B_ERROR; +done: + /* + * Correctly set the buf to indicate a completed xfer + */ + bp->b_resid = bp->b_bcount; + biodone(bp); +} + +/* + * 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(v) + void *v; +{ + struct ss_softc *ss = v; + struct scsi_link *sc_link = ss->sc_link; + register struct buf *bp, *dp; + + SC_DEBUG(sc_link, SDEV_DB2, ("ssstart ")); + /* + * See if there is a buf to do and we are not already + * doing one + */ + while (sc_link->openings > 0) { + /* if a special awaits, let it proceed first */ + if (sc_link->flags & SDEV_WAITING) { + sc_link->flags &= ~SDEV_WAITING; + wakeup((caddr_t)sc_link); + return; + } + + /* + * See if there is a buf with work for us to do.. + */ + dp = &ss->buf_queue; + if ((bp = dp->b_actf) == NULL) + return; + if ((dp = bp->b_actf) != NULL) + dp->b_actb = bp->b_actb; + else + ss->buf_queue.b_actb = bp->b_actb; + *bp->b_actb = dp; + + if (ss->special->read) { + (ss->special->read)(ss, bp); + } else { + /* generic scsi2 scanner read */ + /* XXX add code for SCSI2 scanner read */ + } + } +} + +/* + * 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 = sscd.cd_devs[SSUNIT(dev)]; + int error = 0; + int unit; + struct scan_io *sio; + + switch (cmd) { + case SCIOCGET: + if (ss->special->get_params) { + /* call special handler */ + error = (ss->special->get_params)(ss); + if (error) + return (error); + } else { + /* XXX add code for SCSI2 scanner, if any */ + return (EOPNOTSUPP); + } + bcopy(&ss->sio, addr, sizeof(struct scan_io)); + break; + case SCIOCSET: + sio = (struct scan_io *)addr; + + if (ss->special->set_params) { + /* call special handler */ + error = (ss->special->set_params)(ss, sio); + if (error) + return (error); + } else { + /* XXX add code for SCSI2 scanner, if any */ + return (EOPNOTSUPP); + } + break; + case SCIOCRESTART: + if (ss->special->rewind_scanner ) { + /* call special handler */ + 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; +#ifdef NOTYET + case SCAN_USE_ADF: + break; +#endif + default: + if (SSMODE(dev) != MODE_CONTROL) + return (ENOTTY); + return (scsi_do_ioctl(ss->sc_link, dev, cmd, addr, flag, p)); + } + return (error); +} diff --git a/sys/scsi/ss_mustek.c b/sys/scsi/ss_mustek.c new file mode 100644 index 00000000000..7be6628fe01 --- /dev/null +++ b/sys/scsi/ss_mustek.c @@ -0,0 +1,623 @@ +/* $NetBSD: ss_mustek.c,v 1.1 1996/02/18 20:32:47 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. + */ + +/* + * 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/malloc.h> +#include <sys/buf.h> +#include <sys/proc.h> +#include <sys/user.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> + +#define MUSTEK_RETRIES 4 + +int mustek_get_params __P((struct ss_softc *)); +int mustek_set_params __P((struct ss_softc *, struct scan_io *)); +int mustek_trigger_scanner __P((struct ss_softc *)); +void mustek_minphys __P((struct ss_softc *, struct buf *)); +int mustek_read __P((struct ss_softc *, struct buf *)); +int mustek_rewind_scanner __P((struct ss_softc *)); + +/* only used internally */ +int mustek_get_status __P((struct ss_softc *, int, int)); +void mustek_compute_sizes __P((struct ss_softc *)); + +/* + * structure for the special handlers + */ +struct ss_special mustek_special = { + mustek_set_params, + mustek_trigger_scanner, + mustek_get_params, + 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 scsibus_attach_args *sa; +{ + struct scsi_link *sc_link = sa->sa_sc_link; + + SC_DEBUG(sc_link, SDEV_DB1, ("mustek_attach: start\n")); + ss->sio.scan_scanner_type = 0; + + /* 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; + + /* + * populate the scanio struct with legal values + * the default should come from user space + */ + ss->sio.scan_width = 1200; + ss->sio.scan_height = 1200; + ss->sio.scan_x_resolution = 99; + ss->sio.scan_y_resolution = 99; + ss->sio.scan_x_origin = 0; + ss->sio.scan_y_origin = 0; + ss->sio.scan_brightness = 100; + ss->sio.scan_contrast = 100; + ss->sio.scan_quality = 100; + ss->sio.scan_image_mode = SIM_GRAYSCALE; + + mustek_compute_sizes(ss); +} + +int +mustek_get_params (ss) + struct ss_softc *ss; +{ + + return (0); +} + +/* + * 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; +{ + struct scsi_link *sc_link = ss->sc_link; + + SC_DEBUG(sc_link, SDEV_DB1, ("mustek_minphys: before: %d\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: %d\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; +#ifndef MUSTEK_INCH_SPEC + int pixel_tlx, pixel_tly, pixel_brx, pixel_bry, paperlength; +#endif + 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" */ + window_data.frame_tl_x_0 = ss->sio.scan_x_origin / 150; + window_data.frame_tl_x_1 = 0; + window_data.frame_tl_y_0 = ss->sio.scan_y_origin / 150; + window_data.frame_tl_y_1 = 0; + window_data.frame_br_x_0 = (ss->sio.scan_x_origin + + ss->sio.scan_width) / 150; + window_data.frame_br_x_1 = 0; + window_data.frame_br_y_0 = (ss->sio.scan_y_origin + + ss->sio.scan_height) / 150; + window_data.frame_br_y_1 = 0; +#else + pixel_tlx = (ss->sio.scan_x_origin * ss->sio.scan_x_resolution) / 1200; + window_data.frame_tl_x_0 = pixel_tlx & 0xff; + window_data.frame_tl_x_1 = (pixel_tlx >> 8) & 0xff; + pixel_tly = (ss->sio.scan_y_origin * ss->sio.scan_y_resolution) / 1200; + window_data.frame_tl_y_0 = pixel_tly & 0xff; + window_data.frame_tl_y_1 = (pixel_tly >> 8) & 0xff; + pixel_brx = pixel_tlx + + (ss->sio.scan_width * ss->sio.scan_x_resolution) / 1200; + window_data.frame_br_x_0 = pixel_brx & 0xff; + window_data.frame_br_x_1 = (pixel_brx >> 8) & 0xff; + pixel_bry = pixel_tly + + (ss->sio.scan_height * ss->sio.scan_y_resolution) / 1200; + window_data.frame_br_y_0 = pixel_bry & 0xff; + window_data.frame_br_y_1 = (pixel_bry >> 8) & 0xff; +#endif + +#if MUSTEK_WINDOWS >= 1 + window_data.window1_header = MUSTEK_WINDOW_MASK | MUSTEK_UNIT_SPEC; + window_data.window1_tl_x_0 = window_data.frame_tl_x_0; + window_data.window1_tl_x_1 = window_data.frame_tl_x_1; + window_data.window1_tl_y_0 = window_data.frame_tl_y_0; + window_data.window1_tl_y_1 = window_data.frame_tl_y_1; + window_data.window1_br_x_0 = window_data.frame_br_x_0; + window_data.window1_br_x_1 = window_data.frame_br_x_1; + window_data.window1_br_y_0 = window_data.frame_br_y_0; + window_data.window1_br_y_1 = window_data.frame_br_y_1; +#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), + MUSTEK_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; + mode_cmd.length_0 = sizeof(mode_data); + + 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 + mode_data.paperlength_0 = 14 * 8; /* 14" */ + mode_data.paperlength_1 = 0; +#else + paperlength = 14 * ss->sio.scan_y_resolution; /* 14" */ + mode_data.paperlength_0 = paperlength & 0xff; + mode_data.paperlength_1 = (paperlength >> 8) & 0xff; +#endif + + 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), + MUSTEK_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, + MUSTEK_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, MUSTEK_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, bp) + struct ss_softc *ss; + struct buf *bp; +{ + struct mustek_read_cmd cmd; + struct scsi_link *sc_link = ss->sc_link; + u_long lines_to_read; + + SC_DEBUG(sc_link, SDEV_DB1, ("mustek_read: start\n")); + + bzero(&cmd, sizeof(cmd)); + cmd.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(sc_link, SDEV_DB1, ("mustek_read: read %d lines\n", + lines_to_read)); + cmd.length_0 = lines_to_read & 0xff; + cmd.length_1 = (lines_to_read >> 8) & 0xff; + cmd.length_2 = (lines_to_read >> 16) & 0xff; + + /* + * go ask the adapter to do all this for us + */ + if (scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd, sizeof(cmd), + (u_char *) bp->b_data, bp->b_bcount, MUSTEK_RETRIES, 10000, bp, + SCSI_NOSLEEP | SCSI_DATA_IN) != SUCCESSFULLY_QUEUED) + printf("%s: not queued\n", ss->sc_dev.dv_xname); + else { + ss->sio.scan_lines -= lines_to_read; + ss->sio.scan_window_size -= bp->b_bcount; + } + + return (0); +} + +/* + * 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), MUSTEK_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 = + (data.bytes_per_line_1 << 8) | + data.bytes_per_line_0; + lines = + (data.lines_2 << 16) | + (data.lines_1 << 8) | + data.lines_0; + if (lines != ss->sio.scan_lines) { + printf("mustek: lines actual(%d) != computed(%d)\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(%d)\n", + bytes_per_line * lines, ss->sio.scan_window_size); + return (EIO); + } + + SC_DEBUG(sc_link, SDEV_DB1, + ("mustek_get_size: bpl=%d, lines=%d\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 = %d\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 new file mode 100644 index 00000000000..c045675077b --- /dev/null +++ b/sys/scsi/ss_mustek.h @@ -0,0 +1,218 @@ +/* $NetBSD: ss_mustek.h,v 1.1 1996/02/18 20:32:48 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_char opcode; /* 0x04 */ + u_char reserved[3]; + u_char length; /* in bytes */ + u_char control; +}; + +struct mustek_set_window_data { +#define MUSTEK_LINEART_BACKGROUND 0x00 +#define MUSTEK_HALFTONE_BACKGROUND 0x01 + u_char frame_header; /* unit-defines also apply */ + u_char frame_tl_x_0; + u_char frame_tl_x_1; + u_char frame_tl_y_0; + u_char frame_tl_y_1; + u_char frame_br_x_0; + u_char frame_br_x_1; + u_char frame_br_y_0; + u_char frame_br_y_1; +#if MUSTEK_WINDOWS >= 1 +#define MUSTEK_WINDOW_MASK 0x80 + u_char window1_header; /* unit-defines also apply */ + u_char window1_tl_x_0; + u_char window1_tl_x_1; + u_char window1_tl_y_0; + u_char window1_tl_y_1; + u_char window1_br_x_0; + u_char window1_br_x_1; + u_char window1_br_y_0; + u_char window1_br_y_1; +#endif +#if MUSTEK_WINDOWS >= 2 + u_char window2_header; + u_char window2_tl_x_0; + u_char window2_tl_x_1; + u_char window2_tl_y_0; + u_char window2_tl_y_1; + u_char window2_br_x_0; + u_char window2_br_x_1; + u_char window2_br_y_0; + u_char window2_br_y_1; +#endif +#if MUSTEK_WINDOWS >= 3 + u_char window3_header; + u_char window3_tl_x_0; + u_char window3_tl_x_1; + u_char window3_tl_y_0; + u_char window3_tl_y_1; + u_char window3_br_x_0; + u_char window3_br_x_1; + u_char window3_br_y_0; + u_char window3_br_y_1; +#endif +#if MUSTEK_WINDOWS == 4 + u_char window4_header; + u_char window4_tl_x_0; + u_char window4_tl_x_1; + u_char window4_tl_y_0; + u_char window4_tl_y_1; + u_char window4_br_x_0; + u_char window4_br_x_1; + u_char window4_br_y_0; + u_char window4_br_y_1; +#endif +}; + +struct mustek_read_cmd { + u_char opcode; /* 0x08 */ + u_char reserved; + u_char length_2; /* number of LINES to be read (MSB) */ + u_char length_1; /* number of LINES to be read */ + u_char length_0; /* number of LINES to be read (LSB) */ + u_char control; +}; + +struct mustek_get_status_cmd { + u_char opcode; /* 0x0f */ + u_char reserved[3]; + u_char length; /* 0x06 */ + u_char control; +}; + +struct mustek_get_status_data { +#define MUSTEK_READY 0 +#define MUSTEK_BUSY -1 + u_char ready_busy; /* 0 = ready */ + u_char bytes_per_line_0; /* LSB */ + u_char bytes_per_line_1; /* MSB */ + u_char lines_0; /* LSB */ + u_char lines_1; + u_char lines_2; /* MSB */ +}; + +struct mustek_mode_select_cmd { + u_char opcode; /* 0x15 */ + u_char reserved[2]; + u_char length_1; /* MSB */ + u_char length_0; /* LSB */ + u_char 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_char mode; + u_char resolution; + u_char brightness; + u_char contrast; + u_char grain; /* 0 = 8x8, ..... 5 = 2x2 */ + u_char velocity; /* 0 = fast, ...., 4 = slow */ + u_char reserved[2]; + u_char paperlength_0; /* LSB */ + u_char paperlength_1; /* MSB */ +}; + +struct mustek_start_scan_cmd { + u_char opcode; /* 0x1b */ + u_char 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_char mode; + u_char control; +}; + +#endif /* _SS_MUSTEK_H_ */ diff --git a/sys/scsi/ss_scanjet.c b/sys/scsi/ss_scanjet.c new file mode 100644 index 00000000000..4faebc78a75 --- /dev/null +++ b/sys/scsi/ss_scanjet.c @@ -0,0 +1,410 @@ +/* $NetBSD: ss_scanjet.c,v 1.1 1996/02/18 20:32:49 mycroft 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/malloc.h> +#include <sys/buf.h> +#include <sys/proc.h> +#include <sys/user.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> + +#define SCANJET_RETRIES 4 + +int scanjet_get_params __P((struct ss_softc *)); +int scanjet_set_params __P((struct ss_softc *, struct scan_io *)); +int scanjet_trigger_scanner __P((struct ss_softc *)); +int scanjet_read __P((struct ss_softc *, struct buf *)); + +/* only used internally */ +int scanjet_write __P((struct ss_softc *ss, char *buf, u_int size, int flags)); +int scanjet_set_window __P((struct ss_softc *ss)); +void scanjet_compute_sizes __P((struct ss_softc *)); + +/* + * structure for the special handlers + */ +struct ss_special scanjet_special = { + 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 +scanjet_attach(ss, sa) + struct ss_softc *ss; + struct scsibus_attach_args *sa; +{ + struct scsi_link *sc_link = sa->sa_sc_link; + + SC_DEBUG(sc_link, SDEV_DB1, ("scanjet_attach: start\n")); + ss->sio.scan_scanner_type = 0; + + /* 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\n"); + } + if (!bcmp(sa->sa_inqbuf->product, "C2500A", 6)) { + ss->sio.scan_scanner_type = HP_SCANJET_IIC; + printf(": HP ScanJet IIcx\n"); + } + + SC_DEBUG(sc_link, SDEV_DB1, ("mustek_attach: scanner_type = %d\n", + 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; + ss->sio.scan_brightness = 100; + ss->sio.scan_contrast = 100; + ss->sio.scan_quality = 100; + ss->sio.scan_image_mode = SIM_GRAYSCALE; + + scanjet_compute_sizes(ss); +} + +int +scanjet_get_params(ss) + struct ss_softc *ss; +{ + + 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 + */ +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)); + + scanjet_compute_sizes(ss); + + 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; +{ + char escape_codes[20]; + struct scsi_link *sc_link = ss->sc_link; + int error; + + scanjet_compute_sizes(ss); + + /* send parameters */ + error = scanjet_set_window(ss); + if (error) { + uprintf("set window failed\n"); + return (error); + } + + /* send "trigger" operation */ + strcpy(escape_codes, "\033*f0S"); + error = scanjet_write(ss, escape_codes, strlen(escape_codes), 0); + if (error) { + uprintf("trigger failed\n"); + return (error); + } + + return (0); +} + +int +scanjet_read(ss, bp) + struct ss_softc *ss; + struct buf *bp; +{ + struct scsi_rw_scanner cmd; + struct scsi_link *sc_link = ss->sc_link; + + /* + * Fill out the scsi command + */ + bzero(&cmd, sizeof(cmd)); + cmd.opcode = READ; + + /* + * Handle "fixed-block-mode" tape drives by using the + * block count instead of the length. + */ + lto3b(bp->b_bcount, cmd.len); + + /* + * go ask the adapter to do all this for us + */ + if (scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd, sizeof(cmd), + (u_char *) bp->b_data, bp->b_bcount, SCANJET_RETRIES, 100000, bp, + SCSI_NOSLEEP | SCSI_DATA_IN) != SUCCESSFULLY_QUEUED) + printf("%s: not queued\n", ss->sc_dev.dv_xname); + else { + ss->sio.scan_window_size -= bp->b_bcount; + if (ss->sio.scan_window_size < 0) + ss->sio.scan_window_size = 0; + } + + return (0); +} + + +/* + * Do a synchronous write. Used to send control messages. + */ +int +scanjet_write(ss, buf, size, flags) + struct ss_softc *ss; + char *buf; + u_int size; + int flags; +{ + struct scsi_rw_scanner cmd; + + /* + * If it's a null transfer, return immediatly + */ + if (size == 0) + return (0); + 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)); +} + +#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) + struct ss_softc *ss; +{ + char escape_codes[128], *p; + + p = escape_codes; + + sprintf(p, "\033*f%dP", ss->sio.scan_width / 4); + p += strlen(p); + sprintf(p, "\033*f%dQ", ss->sio.scan_height / 4); + p += strlen(p); + sprintf(p, "\033*f%dX", ss->sio.scan_x_origin / 4); + p += strlen(p); + sprintf(p, "\033*f%dY", ss->sio.scan_y_origin / 4); + p += strlen(p); + sprintf(p, "\033*a%dR", ss->sio.scan_x_resolution); + p += strlen(p); + sprintf(p, "\033*a%dS", ss->sio.scan_y_resolution); + p += strlen(p); + + switch (ss->sio.scan_image_mode) { + case SIM_BINARY_MONOCHROME: + /* use "line art" mode */ + strcpy(p, "\033*a0T"); + p += strlen(p); + /* make image data be "min-is-white ala PBM */ + strcpy(p, "\033*a0I"); + p += strlen(p); + break; + case SIM_DITHERED_MONOCHROME: + /* use dithered mode */ + strcpy(p, "\033*a3T"); + p += strlen(p); + /* make image data be "min-is-white ala PBM */ + strcpy(p, "\033*a0I"); + p += strlen(p); + break; + case SIM_GRAYSCALE: + /* use grayscale mode */ + strcpy(p, "\033*a4T"); + p += strlen(p); + /* make image data be "min-is-black ala PGM */ + strcpy(p, "\033*a1I"); + p += strlen(p); + break; + case SIM_COLOR: + /* use RGB color mode */ + strcpy(p, "\033*a5T"); + p += strlen(p); + /* make image data be "min-is-black ala PPM */ + strcpy(p, "\033*a1I"); + p += strlen(p); + /* use pass-through matrix (disable NTSC) */ + strcpy(p, "\033*u2T"); + p += strlen(p); + } + + sprintf(p, "\033*a%dG", ss->sio.scan_bits_per_pixel); + p += strlen(p); + sprintf(p, "\033*a%dL", (int)(ss->sio.scan_brightness) - 128); + p += strlen(p); + sprintf(p, "\033*a%dK", (int)(ss->sio.scan_contrast) - 128); + p += strlen(p); + + return (scanjet_write(ss, escape_codes, p - escape_codes, 0)); +} + +void +scanjet_compute_sizes(ss) + struct ss_softc *ss; +{ + + /* + * 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: + ss->sio.scan_bits_per_pixel = 1; + break; + case SIM_GRAYSCALE: + ss->sio.scan_bits_per_pixel = 8; + break; + case SIM_COLOR: + ss->sio.scan_bits_per_pixel = 24; + break; + } + + ss->sio.scan_pixels_per_line = + (ss->sio.scan_width * ss->sio.scan_x_resolution) / 1200; + if (ss->sio.scan_bits_per_pixel == 1) + /* pad to byte boundary: */ + ss->sio.scan_pixels_per_line = + (ss->sio.scan_pixels_per_line + 7) & 0xfffffff8; + + 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/ssvar.h b/sys/scsi/ssvar.h new file mode 100644 index 00000000000..3aea359392d --- /dev/null +++ b/sys/scsi/ssvar.h @@ -0,0 +1,79 @@ +/* $NetBSD: ssvar.h,v 1.1 1996/02/18 20:32:50 mycroft Exp $ */ + +/* + * Copyright (c) 1995 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. + */ + +/* + * SCSI scanner interface description + */ + +/* + * Special handlers for impractically different scanner types. + * Register NULL for a function if you want to try the real SCSI code + * (with quirks table) + */ +struct ss_special { + int (*set_params)(); + int (*trigger_scanner)(); + int (*get_params)(); + void (*minphys)(); /* some scanners only send line-multiples */ + int (*read)(); + int (*rewind_scanner)(); + int (*load_adf)(); + int (*unload_adf)(); +}; + +/* + * ss_softc has to be declared here, because the device dependant + * modules include it + */ +struct ss_softc { + struct device sc_dev; + + int flags; +#define SSF_TRIGGERED 0x01 /* read operation has been primed */ +#define SSF_LOADED 0x02 /* parameters loaded */ + struct scsi_link *sc_link; /* contains our targ, lun, etc. */ + struct scan_io sio; + struct buf buf_queue; /* the queue of pending IO operations */ + u_int quirks; /* scanner is only mildly twisted */ +#define SS_Q_GET_BUFFER_SIZE 0x0001 /* poll for available data in ssread() */ +/* truncate to byte boundry is assumed by default unless one of these is set */ +#define SS_Q_PAD_TO_BYTE 0x0002 /* pad monochrome data to byte boundary */ +#define SS_Q_PAD_TO_WORD 0x0004 /* pad monochrome data to word boundary */ +#define SS_Q_THRESHOLD_FOLLOWS_BRIGHTNESS 0x0008 + struct ss_special *special; /* special handlers for spec. devices */ +}; + +/* + * define the special attach routines if configured + */ +void mustek_attach __P((struct ss_softc *, struct scsibus_attach_args *)); +void scanjet_attach __P((struct ss_softc *, struct scsibus_attach_args *)); |