Module Name: src Committed By: riz Date: Fri Mar 2 16:34:47 UTC 2012
Modified Files: src/sys/dev/scsipi [netbsd-6]: ss.c ss_mustek.c ss_scanjet.c ssvar.h Log Message: Pull up following revision(s) (requested by mbalmer in ticket #65): sys/dev/scsipi/ss_scanjet.c: revision 1.52 sys/dev/scsipi/ss.c: revision 1.81 sys/dev/scsipi/ssvar.h: revision 1.19 sys/dev/scsipi/ss_mustek.c: revision 1.41 Convert to device_t, aka softc/device_t split, and clean up a bit the code. To generate a diff of this commit: cvs rdiff -u -r1.80 -r1.80.18.1 src/sys/dev/scsipi/ss.c cvs rdiff -u -r1.40 -r1.40.18.1 src/sys/dev/scsipi/ss_mustek.c cvs rdiff -u -r1.51 -r1.51.18.1 src/sys/dev/scsipi/ss_scanjet.c cvs rdiff -u -r1.18 -r1.18.8.1 src/sys/dev/scsipi/ssvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/scsipi/ss.c diff -u src/sys/dev/scsipi/ss.c:1.80 src/sys/dev/scsipi/ss.c:1.80.18.1 --- src/sys/dev/scsipi/ss.c:1.80 Sun Dec 6 22:48:17 2009 +++ src/sys/dev/scsipi/ss.c Fri Mar 2 16:34:47 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ss.c,v 1.80 2009/12/06 22:48:17 dyoung Exp $ */ +/* $NetBSD: ss.c,v 1.80.18.1 2012/03/02 16:34:47 riz Exp $ */ /* * Copyright (c) 1995 Kenneth Stailey. All rights reserved. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ss.c,v 1.80 2009/12/06 22:48:17 dyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ss.c,v 1.80.18.1 2012/03/02 16:34:47 riz Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -72,8 +72,14 @@ static int ssmatch(device_t, cfdata_t, v static void ssattach(device_t, device_t, void *); static int ssdetach(device_t self, int flags); -CFATTACH_DECL(ss, sizeof(struct ss_softc), - ssmatch, ssattach, ssdetach, NULL); +CFATTACH_DECL_NEW( + ss, + sizeof(struct ss_softc), + ssmatch, + ssattach, + ssdetach, + NULL +); extern struct cfdriver ss_cd; @@ -121,8 +127,7 @@ static const struct scsipi_inquiry_patte }; static int -ssmatch(device_t parent, cfdata_t match, - void *aux) +ssmatch(device_t parent, cfdata_t match, void *aux) { struct scsipibus_attach_args *sa = aux; int priority; @@ -130,7 +135,7 @@ ssmatch(device_t parent, cfdata_t match, (void)scsipi_inqmatch(&sa->sa_inqbuf, ss_patterns, sizeof(ss_patterns) / sizeof(ss_patterns[0]), sizeof(ss_patterns[0]), &priority); - return (priority); + return priority; } /* @@ -147,21 +152,18 @@ ssattach(device_t parent, device_t self, struct scsipi_periph *periph = sa->sa_periph; SC_DEBUG(periph, SCSIPI_DB2, ("ssattach: ")); + ss->sc_dev = self; ss->flags |= SSF_AUTOCONF; - /* - * Store information needed to contact our base driver - */ + /* Store information needed to contact our base driver */ ss->sc_periph = periph; - periph->periph_dev = &ss->sc_dev; + periph->periph_dev = ss->sc_dev; periph->periph_switch = &ss_switch; printf("\n"); - /* - * Set up the buf queue for this device - */ + /* Set up the buf queue for this device */ bufq_alloc(&ss->buf_queue, "fcfs", 0); callout_init(&ss->sc_callout, 0); @@ -176,10 +178,11 @@ ssattach(device_t parent, device_t self, if (memcmp(sa->sa_inqbuf.vendor, "HP ", 8) == 0 && memcmp(sa->sa_inqbuf.product, "ScanJet 5300C", 13) != 0) scanjet_attach(ss, sa); +#if 0 if (ss->special == NULL) { /* XXX add code to restart a SCSI2 scanner, if any */ } - +#endif ss->flags &= ~SSF_AUTOCONF; } @@ -211,7 +214,7 @@ ssdetach(device_t self, int flags) mn = SSUNIT(device_unit(self)); vdevgone(cmaj, mn, mn+SSNMINOR-1, VCHR); - return (0); + return 0; } /* @@ -230,26 +233,27 @@ ssopen(dev_t dev, int flag, int mode, st unit = SSUNIT(dev); ss = device_lookup_private(&ss_cd, unit); if (ss == NULL) - return (ENXIO); + return ENXIO; - if (!device_is_active(&ss->sc_dev)) - return (ENODEV); + if (!device_is_active(ss->sc_dev)) + return ENODEV; ssmode = SSMODE(dev); periph = ss->sc_periph; adapt = periph->periph_channel->chan_adapter; - SC_DEBUG(periph, SCSIPI_DB1, ("open: dev=0x%"PRIx64" (unit %d (of %d))\n", dev, - unit, ss_cd.cd_ndevs)); + SC_DEBUG(periph, SCSIPI_DB1, + ("open: dev=0x%"PRIx64" (unit %d (of %d))\n", dev, unit, + ss_cd.cd_ndevs)); if (periph->periph_flags & PERIPH_OPEN) { - aprint_error_dev(&ss->sc_dev, "already open\n"); - return (EBUSY); + aprint_error_dev(ss->sc_dev, "already open\n"); + return EBUSY; } if ((error = scsipi_adapter_addref(adapt)) != 0) - return (error); + return error; /* * Catch any unit attention errors. @@ -272,15 +276,15 @@ ssopen(dev_t dev, int flag, int mode, st * This mode does NOT ALLOW I/O, only ioctls */ if (ssmode == MODE_CONTROL) - return (0); + return 0; SC_DEBUG(periph, SCSIPI_DB2, ("open complete\n")); - return (0); + return 0; bad: scsipi_adapter_delref(adapt); periph->periph_flags &= ~PERIPH_OPEN; - return (error); + return error; } /* @@ -302,10 +306,13 @@ ssclose(dev_t dev, int flag, int mode, s /* call special handler to rewind/abort scan */ error = (ss->special->rewind_scanner)(ss); if (error) - return (error); - } else { + return error; + } +#if 0 + else { /* XXX add code to restart a SCSI2 scanner, if any */ } +#endif ss->sio.scan_window_size = 0; ss->flags &= ~SSF_TRIGGERED; } @@ -315,7 +322,7 @@ ssclose(dev_t dev, int flag, int mode, s scsipi_adapter_delref(adapt); periph->periph_flags &= ~PERIPH_OPEN; - return (0); + return 0; } /* @@ -353,8 +360,8 @@ ssread(dev_t dev, struct uio *uio, int f struct ss_softc *ss = device_lookup_private(&ss_cd, SSUNIT(dev)); int error; - if (!device_is_active(&ss->sc_dev)) - return (ENODEV); + if (!device_is_active(ss->sc_dev)) + return ENODEV; /* if the scanner has not yet been started, do it now */ if (!(ss->flags & SSF_TRIGGERED)) { @@ -366,7 +373,7 @@ ssread(dev_t dev, struct uio *uio, int f ss->flags |= SSF_TRIGGERED; } - return (physio(ssstrategy, NULL, dev, B_READ, ssminphys, uio)); + return physio(ssstrategy, NULL, dev, B_READ, ssminphys, uio); } /* @@ -382,12 +389,11 @@ ssstrategy(struct buf *bp) int s; SC_DEBUG(ss->sc_periph, SCSIPI_DB1, - ("ssstrategy %d bytes @ blk %" PRId64 "\n", bp->b_bcount, bp->b_blkno)); + ("ssstrategy %d bytes @ blk %" PRId64 "\n", bp->b_bcount, + bp->b_blkno)); - /* - * If the device has been made invalid, error out - */ - if (!device_is_active(&ss->sc_dev)) { + /* If the device has been made invalid, error out */ + if (!device_is_active(ss->sc_dev)) { if (periph->periph_flags & PERIPH_OPEN) bp->b_error = EIO; else @@ -404,9 +410,7 @@ ssstrategy(struct buf *bp) 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 it's a null transfer, return immediatly */ if (bp->b_bcount == 0) goto done; @@ -429,9 +433,7 @@ ssstrategy(struct buf *bp) splx(s); return; done: - /* - * Correctly set the buf to indicate a completed xfer - */ + /* Correctly set the buf to indicate a completed xfer */ bp->b_resid = bp->b_bcount; biodone(bp); } @@ -453,7 +455,7 @@ done: static void ssstart(struct scsipi_periph *periph) { - struct ss_softc *ss = (void *)periph->periph_dev; + struct ss_softc *ss = device_private(periph->periph_dev); struct buf *bp; SC_DEBUG(periph, SCSIPI_DB2, ("ssstart ")); @@ -475,12 +477,14 @@ ssstart(struct scsipi_periph *periph) if ((bp = bufq_peek(ss->buf_queue)) == NULL) return; - if (ss->special && ss->special->read) { + if (ss->special && ss->special->read) (ss->special->read)(ss, bp); +#if 0 } else { /* generic scsi2 scanner read */ /* XXX add code for SCSI2 scanner read */ } +#endif } } @@ -516,8 +520,8 @@ ssioctl(dev_t dev, u_long cmd, void *add int error = 0; struct scan_io *sio; - if (!device_is_active(&ss->sc_dev)) - return (ENODEV); + if (!device_is_active(ss->sc_dev)) + return ENODEV; switch (cmd) { case SCIOCGET: @@ -525,11 +529,10 @@ ssioctl(dev_t dev, u_long cmd, void *add /* call special handler */ error = (ss->special->get_params)(ss); if (error) - return (error); - } else { + return error; + } else /* XXX add code for SCSI2 scanner, if any */ - return (EOPNOTSUPP); - } + return EOPNOTSUPP; memcpy(addr, &ss->sio, sizeof(struct scan_io)); break; case SCIOCSET: @@ -539,21 +542,20 @@ ssioctl(dev_t dev, u_long cmd, void *add /* call special handler */ error = (ss->special->set_params)(ss, sio); if (error) - return (error); - } else { + return error; + } else /* XXX add code for SCSI2 scanner, if any */ - return (EOPNOTSUPP); - } + return EOPNOTSUPP; break; case SCIOCRESTART: if (ss->special && ss->special->rewind_scanner ) { /* call special handler */ error = (ss->special->rewind_scanner)(ss); if (error) - return (error); + return error; } else /* XXX add code for SCSI2 scanner, if any */ - return (EOPNOTSUPP); + return EOPNOTSUPP; ss->flags &= ~SSF_TRIGGERED; break; #ifdef NOTYET @@ -561,8 +563,7 @@ ssioctl(dev_t dev, u_long cmd, void *add break; #endif default: - return (scsipi_do_ioctl(ss->sc_periph, dev, cmd, addr, - flag, l)); + return scsipi_do_ioctl(ss->sc_periph, dev, cmd, addr, flag, l); } - return (error); + return error; } Index: src/sys/dev/scsipi/ss_mustek.c diff -u src/sys/dev/scsipi/ss_mustek.c:1.40 src/sys/dev/scsipi/ss_mustek.c:1.40.18.1 --- src/sys/dev/scsipi/ss_mustek.c:1.40 Mon Nov 23 02:13:47 2009 +++ src/sys/dev/scsipi/ss_mustek.c Fri Mar 2 16:34:47 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ss_mustek.c,v 1.40 2009/11/23 02:13:47 rmind Exp $ */ +/* $NetBSD: ss_mustek.c,v 1.40.18.1 2012/03/02 16:34:47 riz Exp $ */ /* * Copyright (c) 1995 Joachim Koenig-Baltes. All rights reserved. @@ -46,7 +46,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ss_mustek.c,v 1.40 2009/11/23 02:13:47 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ss_mustek.c,v 1.40.18.1 2012/03/02 16:34:47 riz Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -83,9 +83,7 @@ static int mustek_rewind_scanner(struct static int mustek_get_status(struct ss_softc *, int, int); static void mustek_compute_sizes(struct ss_softc *); -/* - * structure for the special handlers - */ +/* structure for the special handlers */ static struct ss_special mustek_special = { mustek_set_params, mustek_trigger_scanner, @@ -97,9 +95,7 @@ static struct ss_special mustek_special NULL /* no adf support right now */ }; -/* - * mustek_attach: attach special functions to ss - */ +/* mustek_attach: attach special functions to ss */ void mustek_attach(struct ss_softc *ss, struct scsipibus_attach_args *sa) { @@ -110,16 +106,18 @@ mustek_attach(struct ss_softc *ss, struc SC_DEBUG(periph, SCSIPI_DB1, ("mustek_attach: start\n")); ss->sio.scan_scanner_type = 0; - printf("\n%s: ", device_xname(&ss->sc_dev)); + printf("\n%s: ", device_xname(ss->sc_dev)); /* first, check the model which determines resolutions */ if (!memcmp(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"); + printf("Mustek 6000CX Flatbed 3-pass color scanner, " + "3 - 600 dpi\n"); } if (!memcmp(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"); + printf("Mustek 12000CX Flatbed 3-pass color scanner, " + "6 - 1200 dpi\n"); } SC_DEBUG(periph, SCSIPI_DB1, ("mustek_attach: scanner_type = %d\n", @@ -149,8 +147,7 @@ mustek_attach(struct ss_softc *ss, struc static int mustek_get_params (struct ss_softc *ss) { - - return (0); + return 0; } /* @@ -163,13 +160,11 @@ mustek_set_params(struct ss_softc *ss, s { int error; - /* - * if the scanner is triggered, then rewind it - */ + /* if the scanner is triggered, then rewind it */ if (ss->flags & SSF_TRIGGERED) { error = mustek_rewind_scanner(ss); if (error) - return (error); + return error; } /* size constraints: 8.5" horizontally and 14" vertically */ @@ -184,7 +179,7 @@ mustek_set_params(struct ss_softc *ss, s sio->scan_x_origin + sio->scan_width > 10200 || sio->scan_height == 0 || sio->scan_y_origin + sio->scan_height > 16800) - return (EINVAL); + return EINVAL; /* * for now, only realize the values for the MUSTEK_06000CX @@ -201,17 +196,17 @@ mustek_set_params(struct ss_softc *ss, s 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); + 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); + 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); + return EINVAL; /* * velocity: between 0 (fast) and 4 (slow) which will be mapped @@ -220,7 +215,7 @@ mustek_set_params(struct ss_softc *ss, s */ sio->scan_quality -= sio->scan_quality % 20; if (sio->scan_quality < 20 || sio->scan_quality > 100) - return (EINVAL); + return EINVAL; switch (sio->scan_image_mode) { case SIM_BINARY_MONOCHROME: @@ -231,7 +226,7 @@ mustek_set_params(struct ss_softc *ss, s case SIM_BLUE: break; default: - return (EINVAL); + return EINVAL; } /* change ss_softc to the new values, but save ro-variables */ @@ -240,7 +235,7 @@ mustek_set_params(struct ss_softc *ss, s mustek_compute_sizes(ss); - return (0); + return 0; } /* @@ -286,9 +281,7 @@ mustek_trigger_scanner(struct ss_softc * SC_DEBUG(periph, SCSIPI_DB1, ("mustek_trigger_scanner\n")); - /* - * set the window params and send the scsi command - */ + /* set the window params and send the scsi command */ memset(&window_cmd, 0, sizeof(window_cmd)); window_cmd.opcode = MUSTEK_SET_WINDOW; window_cmd.length = sizeof(window_data); @@ -325,7 +318,7 @@ mustek_trigger_scanner(struct ss_softc * (void *)&window_data, sizeof(window_data), MUSTEK_RETRIES, 5000, NULL, XS_CTL_DATA_OUT); if (error) - return (error); + return error; /* * do what it takes to actualize the mode @@ -337,16 +330,16 @@ mustek_trigger_scanner(struct ss_softc * memset(&mode_data, 0, sizeof(mode_data)); mode_data.mode = MUSTEK_MODE_MASK | MUSTEK_HT_PATTERN_BUILTIN | MUSTEK_UNIT_SPEC; - if (ss->sio.scan_x_resolution <= 300) { + if (ss->sio.scan_x_resolution <= 300) mode_data.resolution = ss->sio.scan_x_resolution / 3; - } else { + 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; @@ -364,7 +357,7 @@ mustek_trigger_scanner(struct ss_softc * (void *)&mode_data, sizeof(mode_data), MUSTEK_RETRIES, 5000, NULL, XS_CTL_DATA_OUT); if (error) - return (error); + return error; /* * now construct and send the start command @@ -398,11 +391,10 @@ mustek_trigger_scanner(struct ss_softc * /* send the command to the scanner */ SC_DEBUG(periph, SCSIPI_DB1, ("mustek_trigger_scanner: start_scan\n")); error = scsipi_command(periph, - (void *)&start_scan_cmd, sizeof(start_scan_cmd), - NULL, 0, + (void *)&start_scan_cmd, sizeof(start_scan_cmd), NULL, 0, MUSTEK_RETRIES, 5000, NULL, 0); if (error) - return (error); + return error; /* * now check if scanner ready this time with update of size info @@ -413,14 +405,12 @@ mustek_trigger_scanner(struct ss_softc * SC_DEBUG(periph, SCSIPI_DB1, ("mustek_trigger_scanner: get_status\n")); error = mustek_get_status(ss, 60, 1); if (error) - return (error); + return error; - return (0); + return 0; } -/* - * stop a scan operation in progress - */ +/* stop a scan operation in progress */ static int mustek_rewind_scanner(struct ss_softc *ss) { @@ -445,17 +435,15 @@ mustek_rewind_scanner(struct ss_softc *s NULL, 0, MUSTEK_RETRIES, 5000, NULL, 0); if (error) - return (error); + return error; } SC_DEBUG(periph, SCSIPI_DB1, ("mustek_rewind_scanner: end\n")); - return (0); + return 0; } -/* - * read the requested number of bytes/lines from the scanner - */ +/* read the requested number of bytes/lines from the scanner */ static int mustek_read(struct ss_softc *ss, struct buf *bp) { @@ -477,9 +465,7 @@ mustek_read(struct ss_softc *ss, struct lines_to_read)); _lto3b(lines_to_read, cmd.length); - /* - * go ask the adapter to do all this for us - */ + /* go ask the adapter to do all this for us */ xs = scsipi_make_xs(periph, (struct scsipi_generic *) &cmd, sizeof(cmd), (u_char *) bp->b_data, bp->b_bcount, @@ -492,7 +478,7 @@ mustek_read(struct ss_softc *ss, struct */ callout_reset(&ss->sc_callout, hz / 2, ssrestart, periph); - return(0); + return 0; } #ifdef DIAGNOSTIC if (bufq_get(ss->buf_queue) != bp) @@ -513,7 +499,7 @@ mustek_read(struct ss_softc *ss, struct if (ss->sio.scan_window_size < 0) ss->sio.scan_window_size = 0; #endif - return (0); + return 0; } /* @@ -541,7 +527,7 @@ mustek_get_status(struct ss_softc *ss, i (void *)&data, sizeof(data), MUSTEK_RETRIES, 5000, NULL, XS_CTL_DATA_IN); if (error) - return (error); + return error; if ((data.ready_busy == MUSTEK_READY) || (timeout-- <= 0)) break; @@ -555,27 +541,27 @@ mustek_get_status(struct ss_softc *ss, i if (lines != ss->sio.scan_lines) { printf("mustek: lines actual(%d) != computed(%ld)\n", lines, ss->sio.scan_lines); - return (EIO); + return EIO; } if (bytes_per_line * lines != ss->sio.scan_window_size) { printf("mustek: win-size actual(%d) != computed(%ld)\n", bytes_per_line * lines, ss->sio.scan_window_size); - return (EIO); + return EIO; } SC_DEBUG(periph, SCSIPI_DB1, ("mustek_get_size: bpl=%ld, lines=%ld\n", - (ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8, - ss->sio.scan_lines)); + (ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) + / 8, ss->sio.scan_lines)); SC_DEBUG(periph, SCSIPI_DB1, ("window size = %ld\n", ss->sio.scan_window_size)); } SC_DEBUG(periph, SCSIPI_DB1, ("mustek_get_status: end\n")); if (data.ready_busy == MUSTEK_READY) - return (0); + return 0; else - return (EBUSY); + return EBUSY; } /* Index: src/sys/dev/scsipi/ss_scanjet.c diff -u src/sys/dev/scsipi/ss_scanjet.c:1.51 src/sys/dev/scsipi/ss_scanjet.c:1.51.18.1 --- src/sys/dev/scsipi/ss_scanjet.c:1.51 Mon Nov 23 02:13:47 2009 +++ src/sys/dev/scsipi/ss_scanjet.c Fri Mar 2 16:34:47 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ss_scanjet.c,v 1.51 2009/11/23 02:13:47 rmind Exp $ */ +/* $NetBSD: ss_scanjet.c,v 1.51.18.1 2012/03/02 16:34:47 riz Exp $ */ /* * Copyright (c) 1995 Kenneth Stailey. All rights reserved. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ss_scanjet.c,v 1.51 2009/11/23 02:13:47 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ss_scanjet.c,v 1.51.18.1 2012/03/02 16:34:47 riz Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -70,9 +70,7 @@ static int scanjet_ctl_read(struct ss_so static int scanjet_set_window(struct ss_softc *); static int scanjet_compute_sizes(struct ss_softc *); -/* - * structure for the special handlers - */ +/* structure for the special handlers */ static struct ss_special scanjet_special = { scanjet_set_params, scanjet_trigger_scanner, @@ -84,9 +82,7 @@ static struct ss_special scanjet_special NULL /* no adf support right now */ }; -/* - * scanjet_attach: attach special functions to ss - */ +/* scanjet_attach: attach special functions to ss */ void scanjet_attach(struct ss_softc *ss, struct scsipibus_attach_args *sa) { @@ -95,10 +91,9 @@ scanjet_attach(struct ss_softc *ss, stru SC_DEBUG(ss->sc_periph, SCSIPI_DB1, ("scanjet_attach: start\n")); ss->sio.scan_scanner_type = 0; - printf("%s: ", device_xname(&ss->sc_dev)); + printf("%s: ", device_xname(ss->sc_dev)); /* first, check the model (which determines nothing yet) */ - if (!memcmp(sa->sa_inqbuf.product, "C1750A", 6)) { ss->sio.scan_scanner_type = HP_SCANJET_IIC; printf("HP ScanJet IIc"); @@ -126,9 +121,7 @@ scanjet_attach(struct ss_softc *ss, stru /* now install special handlers */ ss->special = &scanjet_special; - /* - * populate the scanio struct with legal values - */ + /* populate the scanio struct with legal values */ ss->sio.scan_width = 1200; ss->sio.scan_height = 1200; ss->sio.scan_x_resolution = 100; @@ -150,15 +143,13 @@ scanjet_attach(struct ss_softc *ss, stru printf(" compute_sizes failed\n"); return; } - printf("\n"); } static int scanjet_get_params(struct ss_softc *ss) { - - return (0); + return 0; } /* @@ -178,7 +169,7 @@ scanjet_set_params(struct ss_softc *ss, if (ss->flags & SSF_TRIGGERED) { error = scanjet_rewind_scanner(ss); if (error) - return (error); + return error; } #endif @@ -187,14 +178,14 @@ scanjet_set_params(struct ss_softc *ss, 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); + 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); + return EINVAL; switch (sio->scan_image_mode) { case SIM_BINARY_MONOCHROME: @@ -203,7 +194,7 @@ scanjet_set_params(struct ss_softc *ss, case SIM_COLOR: break; default: - return (EINVAL); + return EINVAL; } /* change ss_softc to the new values, but save ro-variables */ @@ -212,16 +203,15 @@ scanjet_set_params(struct ss_softc *ss, error = scanjet_set_window(ss); if (error) { - uprintf("%s: set_window failed\n", device_xname(&ss->sc_dev)); - return (error); + uprintf("%s: set_window failed\n", device_xname(ss->sc_dev)); + return error; } error = scanjet_compute_sizes(ss); if (error) { - uprintf("%s: compute_sizes failed\n", device_xname(&ss->sc_dev)); - return (error); + uprintf("%s: compute_sizes failed\n", device_xname(ss->sc_dev)); + return error; } - - return (0); + return 0; } /* @@ -237,24 +227,24 @@ scanjet_trigger_scanner(struct ss_softc error = scanjet_set_window(ss); if (error) { - uprintf("%s: set_window failed\n", device_xname(&ss->sc_dev)); - return (error); + uprintf("%s: set_window failed\n", device_xname(ss->sc_dev)); + return error; } error = scanjet_compute_sizes(ss); if (error) { - uprintf("%s: compute_sizes failed\n", device_xname(&ss->sc_dev)); - return (error); + uprintf("%s: compute_sizes failed\n", device_xname(ss->sc_dev)); + return error; } /* send "trigger" operation */ strlcpy(escape_codes, "\033*f0S", sizeof(escape_codes)); error = scanjet_ctl_write(ss, escape_codes, strlen(escape_codes)); if (error) { - uprintf("%s: trigger_scanner failed\n", device_xname(&ss->sc_dev)); - return (error); + uprintf("%s: trigger_scanner failed\n", + device_xname(ss->sc_dev)); + return error; } - - return (0); + return 0; } static int @@ -265,9 +255,7 @@ scanjet_read(struct ss_softc *ss, struct struct scsipi_periph *periph = ss->sc_periph; int error; - /* - * Fill out the scsi command - */ + /* Fill out the scsi command */ memset(&cmd, 0, sizeof(cmd)); cmd.opcode = READ; @@ -277,12 +265,10 @@ scanjet_read(struct ss_softc *ss, struct */ _lto3b(bp->b_bcount, cmd.len); - /* - * go ask the adapter to do all this for us - */ + /* go ask the adapter to do all this for us */ xs = scsipi_make_xs(periph, - (struct scsipi_generic *) &cmd, sizeof(cmd), - (u_char *) bp->b_data, bp->b_bcount, + (struct scsipi_generic *)&cmd, sizeof(cmd), + (u_char *)bp->b_data, bp->b_bcount, SCANJET_RETRIES, 100000, bp, XS_CTL_NOSLEEP | XS_CTL_ASYNC | XS_CTL_DATA_IN); if (xs == NULL) { @@ -290,9 +276,8 @@ scanjet_read(struct ss_softc *ss, struct * out of memory. Keep this buffer in the queue, and * retry later. */ - callout_reset(&ss->sc_callout, hz / 2, ssrestart, - periph); - return(0); + callout_reset(&ss->sc_callout, hz / 2, ssrestart, periph); + return 0; } #ifdef DIAGNOSTIC if (bufq_get(ss->buf_queue) != bp) @@ -308,13 +293,11 @@ scanjet_read(struct ss_softc *ss, struct if (ss->sio.scan_window_size < 0) ss->sio.scan_window_size = 0; #endif - return (0); + return 0; } -/* - * Do a synchronous write. Used to send control messages. - */ +/* Do a synchronous write. Used to send control messages. */ static int scanjet_ctl_write(struct ss_softc *ss, char *tbuf, u_int size) { @@ -329,15 +312,13 @@ scanjet_ctl_write(struct ss_softc *ss, c cmd.opcode = WRITE; _lto3b(size, cmd.len); - return (scsipi_command(ss->sc_periph, + return scsipi_command(ss->sc_periph, (void *)&cmd, sizeof(cmd), (void *)tbuf, size, 0, 100000, NULL, - flags | XS_CTL_DATA_OUT)); + flags | XS_CTL_DATA_OUT); } -/* - * Do a synchronous read. Used to read responses to control messages. - */ +/* Do a synchronous read. Used to read responses to control messages. */ static int scanjet_ctl_read(struct ss_softc *ss, char *tbuf, u_int size) { @@ -352,9 +333,9 @@ scanjet_ctl_read(struct ss_softc *ss, ch cmd.opcode = READ; _lto3b(size, cmd.len); - return (scsipi_command(ss->sc_periph, + return scsipi_command(ss->sc_periph, (void *)&cmd, sizeof(cmd), (void *)tbuf, size, 0, 100000, NULL, - flags | XS_CTL_DATA_IN)); + flags | XS_CTL_DATA_IN); } @@ -363,6 +344,7 @@ static void show_es(char *es) { char *p = es; + while (*p) { if (*p == '\033') printf("[Esc]"); @@ -435,10 +417,12 @@ scanjet_set_window(struct ss_softc *ss) } 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); + 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); - return (scanjet_ctl_write(ss, escape_codes, p - escape_codes)); + return scanjet_ctl_write(ss, escape_codes, p - escape_codes); } static int @@ -474,18 +458,18 @@ scanjet_compute_sizes(struct ss_softc *s } error = scanjet_ctl_write(ss, escape_codes, strlen(escape_codes)); if (error) { - uprintf(wfail, device_xname(&ss->sc_dev)); - return (error); + uprintf(wfail, device_xname(ss->sc_dev)); + return error; } error = scanjet_ctl_read(ss, response, 20); if (error) { - uprintf(rfail, device_xname(&ss->sc_dev)); - return (error); + uprintf(rfail, device_xname(ss->sc_dev)); + return error; } p = strchr(response, 'd'); if (p == 0) { - uprintf(dfail, device_xname(&ss->sc_dev)); - return (EIO); + uprintf(dfail, device_xname(ss->sc_dev)); + return EIO; } ss->sio.scan_pixels_per_line = strtoul(p + 1, NULL, 10); if (ss->sio.scan_image_mode < SIM_GRAYSCALE) @@ -495,23 +479,23 @@ scanjet_compute_sizes(struct ss_softc *s strlcpy(escape_codes, "\033*s1026E", sizeof(escape_codes)); error = scanjet_ctl_write(ss, escape_codes, strlen(escape_codes)); if (error) { - uprintf(wfail, device_xname(&ss->sc_dev)); - return (error); + uprintf(wfail, device_xname(ss->sc_dev)); + return error; } error = scanjet_ctl_read(ss, response, 20); if (error) { - uprintf(rfail, device_xname(&ss->sc_dev)); - return (error); + uprintf(rfail, device_xname(ss->sc_dev)); + return error; } p = strchr(response, 'd'); if (p == 0) { - uprintf(dfail, device_xname(&ss->sc_dev)); - return (EIO); + uprintf(dfail, device_xname(ss->sc_dev)); + return EIO; } ss->sio.scan_lines = strtoul(p + 1, NULL, 10); ss->sio.scan_window_size = ss->sio.scan_lines * ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8); - return (0); + return 0; } Index: src/sys/dev/scsipi/ssvar.h diff -u src/sys/dev/scsipi/ssvar.h:1.18 src/sys/dev/scsipi/ssvar.h:1.18.8.1 --- src/sys/dev/scsipi/ssvar.h:1.18 Thu Jun 30 20:09:40 2011 +++ src/sys/dev/scsipi/ssvar.h Fri Mar 2 16:34:47 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ssvar.h,v 1.18 2011/06/30 20:09:40 wiz Exp $ */ +/* $NetBSD: ssvar.h,v 1.18.8.1 2012/03/02 16:34:47 riz Exp $ */ /* * Copyright (c) 1995 Kenneth Stailey. All rights reserved. @@ -59,7 +59,7 @@ struct ss_special { * modules include it */ struct ss_softc { - struct device sc_dev; + device_t sc_dev; int flags; #define SSF_TRIGGERED 0x01 /* read operation has been primed */ @@ -70,7 +70,7 @@ struct ss_softc { struct bufq_state *buf_queue; /* the queue of pending IO operations */ struct callout sc_callout; /* to restart the buf queue */ u_int quirks; /* scanner is only mildly twisted */ -#define SS_Q_GET_BUFFER_SIZE 0x0001 /* poll for available data in ssread() */ +#define SS_Q_GET_BUFFER_SIZE 0x0001 /* poll for available data in ssread()*/ /* truncate to byte boundary 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 */