ss_mustek.c revision 1.20 1 /* $NetBSD: ss_mustek.c,v 1.20 2004/08/27 20:37:29 bouyer Exp $ */
2
3 /*
4 * Copyright (c) 1995 Joachim Koenig-Baltes. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Joachim Koenig-Baltes.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * special driver for MUSTEK flatbed scanners MFS 06000CX and MFS 12000CX
34 * these scanners come with their own scsi card, containing an NCR53C400
35 * SCSI controller chip. I'm in the progress of writing a driver for this
36 * card to work under NetBSD-current. I've hooked it up to a Seagate ST01
37 * hostadapter in the meantime, giving 350KB/sec for higher resolutions!
38 *
39 * I tried to connect it to my Adaptec 1542B, but with no success. It seems,
40 * it does not like synchronous negotiation between Hostadapter and other
41 * targets, but I could not turn this off for the 1542B.
42 *
43 * There is also an other reason why you would not like to connect it to your
44 * favourite SCSI host adapter: The Mustek DOES NOT DISCONNECT. It will block
45 * other traffic from the bus while a transfer is active.
46 */
47
48 #include <sys/cdefs.h>
49 __KERNEL_RCSID(0, "$NetBSD: ss_mustek.c,v 1.20 2004/08/27 20:37:29 bouyer Exp $");
50
51 #include <sys/param.h>
52 #include <sys/kernel.h>
53 #include <sys/systm.h>
54 #include <sys/fcntl.h>
55 #include <sys/errno.h>
56 #include <sys/ioctl.h>
57 #include <sys/malloc.h>
58 #include <sys/buf.h>
59 #include <sys/proc.h>
60 #include <sys/user.h>
61 #include <sys/device.h>
62 #include <sys/conf.h> /* for cdevsw */
63 #include <sys/scanio.h>
64
65 #include <dev/scsipi/scsi_all.h>
66 #include <dev/scsipi/scsipi_all.h>
67 #include <dev/scsipi/scsi_scanner.h>
68 #include <dev/scsipi/scsiconf.h>
69 #include <dev/scsipi/ssvar.h>
70 #include <dev/scsipi/ss_mustek.h>
71
72 #define MUSTEK_RETRIES 4
73
74 static int mustek_get_params(struct ss_softc *);
75 static int mustek_set_params(struct ss_softc *, struct scan_io *);
76 static int mustek_trigger_scanner(struct ss_softc *);
77 static void mustek_minphys(struct ss_softc *, struct buf *);
78 static int mustek_read(struct ss_softc *, struct buf *);
79 static int mustek_rewind_scanner(struct ss_softc *);
80
81 /* only used internally */
82 static int mustek_get_status(struct ss_softc *, int, int);
83 static void mustek_compute_sizes(struct ss_softc *);
84
85 /*
86 * structure for the special handlers
87 */
88 static struct ss_special mustek_special = {
89 mustek_set_params,
90 mustek_trigger_scanner,
91 mustek_get_params,
92 mustek_minphys,
93 mustek_read,
94 mustek_rewind_scanner,
95 NULL, /* no adf support right now */
96 NULL /* no adf support right now */
97 };
98
99 /*
100 * mustek_attach: attach special functions to ss
101 */
102 void
103 mustek_attach(struct ss_softc *ss, struct scsipibus_attach_args *sa)
104 {
105 #ifdef SCSIPI_DEBUG
106 struct scsipi_periph *periph = sa->sa_periph;
107 #endif
108
109 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_attach: start\n"));
110 ss->sio.scan_scanner_type = 0;
111
112 printf("\n%s: ", ss->sc_dev.dv_xname);
113
114 /* first, check the model which determines resolutions */
115 if (!memcmp(sa->sa_inqbuf.product, "MFS-06000CX", 11)) {
116 ss->sio.scan_scanner_type = MUSTEK_06000CX;
117 printf("Mustek 6000CX Flatbed 3-pass color scanner, 3 - 600 dpi\n");
118 }
119 if (!memcmp(sa->sa_inqbuf.product, "MFS-12000CX", 11)) {
120 ss->sio.scan_scanner_type = MUSTEK_12000CX;
121 printf("Mustek 12000CX Flatbed 3-pass color scanner, 6 - 1200 dpi\n");
122 }
123
124 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_attach: scanner_type = %d\n",
125 ss->sio.scan_scanner_type));
126
127 /* install special handlers */
128 ss->special = &mustek_special;
129
130 /*
131 * populate the scanio struct with legal values
132 * the default should come from user space
133 */
134 ss->sio.scan_width = 1200;
135 ss->sio.scan_height = 1200;
136 ss->sio.scan_x_resolution = 99;
137 ss->sio.scan_y_resolution = 99;
138 ss->sio.scan_x_origin = 0;
139 ss->sio.scan_y_origin = 0;
140 ss->sio.scan_brightness = 100;
141 ss->sio.scan_contrast = 100;
142 ss->sio.scan_quality = 100;
143 ss->sio.scan_image_mode = SIM_GRAYSCALE;
144
145 mustek_compute_sizes(ss);
146 }
147
148 static int
149 mustek_get_params (struct ss_softc *ss)
150 {
151
152 return (0);
153 }
154
155 /*
156 * check the parameters if the mustek is capable of fulfilling it
157 * but don't send the command to the scanner in case the user wants
158 * to change parameters by more than one call
159 */
160 static int
161 mustek_set_params(struct ss_softc *ss, struct scan_io *sio)
162 {
163 int error;
164
165 /*
166 * if the scanner is triggered, then rewind it
167 */
168 if (ss->flags & SSF_TRIGGERED) {
169 error = mustek_rewind_scanner(ss);
170 if (error)
171 return (error);
172 }
173
174 /* size constraints: 8.5" horizontally and 14" vertically */
175 #ifdef MUSTEK_INCH_SPEC
176 /* sizes must be a multiple of 1/8" */
177 sio->scan_x_origin -= sio->scan_x_origin % 150;
178 sio->scan_y_origin -= sio->scan_y_origin % 150;
179 sio->scan_width -= sio->scan_width % 150;
180 sio->scan_height -= sio->scan_height % 150;
181 #endif
182 if (sio->scan_width == 0 ||
183 sio->scan_x_origin + sio->scan_width > 10200 ||
184 sio->scan_height == 0 ||
185 sio->scan_y_origin + sio->scan_height > 16800)
186 return (EINVAL);
187
188 /*
189 * for now, only realize the values for the MUSTEK_06000CX
190 * in the future, values for the MUSTEK_12000CX will be implemented
191 */
192
193 /*
194 * resolution (dpi) must be <= 300 and a multiple of 3 or
195 * between 300 and 600 and a multiple of 30
196 */
197 sio->scan_x_resolution -= sio->scan_x_resolution <= 300 ?
198 sio->scan_x_resolution % 3 : sio->scan_x_resolution % 30;
199 sio->scan_y_resolution -= sio->scan_y_resolution <= 300 ?
200 sio->scan_y_resolution % 3 : sio->scan_y_resolution % 30;
201 if (sio->scan_x_resolution < 3 || sio->scan_x_resolution > 600 ||
202 sio->scan_x_resolution != sio->scan_y_resolution)
203 return (EINVAL);
204
205 /* assume brightness values are between 64 and 136 in steps of 3 */
206 sio->scan_brightness -= (sio->scan_brightness - 64) % 3;
207 if (sio->scan_brightness < 64 || sio->scan_brightness > 136)
208 return (EINVAL);
209
210 /* contrast values must be between 16 and 184 in steps of 7 */
211 sio->scan_contrast -= (sio->scan_contrast - 16) % 7;
212 if (sio->scan_contrast < 16 || sio->scan_contrast > 184)
213 return (EINVAL);
214
215 /*
216 * velocity: between 0 (fast) and 4 (slow) which will be mapped
217 * to 100% = 4, 80% = 3, 60% = 2, 40% = 1, 20% = 0
218 * must be a multiple of 20
219 */
220 sio->scan_quality -= sio->scan_quality % 20;
221 if (sio->scan_quality < 20 || sio->scan_quality > 100)
222 return (EINVAL);
223
224 switch (sio->scan_image_mode) {
225 case SIM_BINARY_MONOCHROME:
226 case SIM_DITHERED_MONOCHROME:
227 case SIM_GRAYSCALE:
228 case SIM_RED:
229 case SIM_GREEN:
230 case SIM_BLUE:
231 break;
232 default:
233 return (EINVAL);
234 }
235
236 /* change ss_softc to the new values, but save ro-variables */
237 sio->scan_scanner_type = ss->sio.scan_scanner_type;
238 memcpy(&ss->sio, sio, sizeof(struct scan_io));
239
240 mustek_compute_sizes(ss);
241
242 return (0);
243 }
244
245 /*
246 * trim the requested transfer to a multiple of the line size
247 * this is called only from ssread() which guarantees, scanner is triggered
248 * In the future, it will trim the transfer to not read to much at a time
249 * because the mustek cannot disconnect. It will be calculated by the
250 * resolution, the velocity and the number of bytes per line.
251 */
252 static void
253 mustek_minphys(struct ss_softc *ss, struct buf *bp)
254 {
255 #ifdef SCSIPI_DEBUG
256 struct scsipi_periph *periph = ss->sc_periph;
257 #endif
258
259 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_minphys: before: %ld\n",
260 bp->b_bcount));
261 bp->b_bcount -= bp->b_bcount %
262 ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
263 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_minphys: after: %ld\n",
264 bp->b_bcount));
265 }
266
267 /*
268 * trigger the scanner to start a scan operation
269 * this includes sending the mode- and window-data, starting the scanner
270 * and getting the image size info
271 */
272 static int
273 mustek_trigger_scanner(struct ss_softc *ss)
274 {
275 struct mustek_mode_select_cmd mode_cmd;
276 struct mustek_mode_select_data mode_data;
277 struct mustek_set_window_cmd window_cmd;
278 struct mustek_set_window_data window_data;
279 struct mustek_start_scan_cmd start_scan_cmd;
280 struct scsipi_periph *periph = ss->sc_periph;
281 int pixel_tlx, pixel_tly, pixel_brx, pixel_bry, paperlength;
282 int error;
283
284 mustek_compute_sizes(ss);
285
286 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_trigger_scanner\n"));
287
288 /*
289 * set the window params and send the scsi command
290 */
291 memset(&window_cmd, 0, sizeof(window_cmd));
292 window_cmd.opcode = MUSTEK_SET_WINDOW;
293 window_cmd.length = sizeof(window_data);
294
295 memset(&window_data, 0, sizeof(window_data));
296 window_data.frame.header = MUSTEK_LINEART_BACKGROUND | MUSTEK_UNIT_SPEC;
297 #ifdef MUSTEK_INCH_SPEC
298 /* the positional values are all 1 byte because 256 / 8 = 32" */
299 pixel_tlx = ss->sio.scan_x_origin / 150;
300 pixel_tly = ss->sio.scan_y_origin / 150;
301 pixel_brx = pixel_tlx + ss->sio.scan_width / 150;
302 pixel_bry = pixel_tly + ss->sio.scan_height / 150;
303 #else
304 pixel_tlx = (ss->sio.scan_x_origin * ss->sio.scan_x_resolution) / 1200;
305 pixel_tly = (ss->sio.scan_y_origin * ss->sio.scan_y_resolution) / 1200;
306 pixel_brx = pixel_tlx +
307 (ss->sio.scan_width * ss->sio.scan_x_resolution) / 1200;
308 pixel_bry = pixel_tly +
309 (ss->sio.scan_height * ss->sio.scan_y_resolution) / 1200;
310 #endif
311 _lto2l(pixel_tlx, window_data.frame.tl_x);
312 _lto2l(pixel_tly, window_data.frame.tl_y);
313 _lto2l(pixel_brx, window_data.frame.br_x);
314 _lto2l(pixel_bry, window_data.frame.br_y);
315
316 #if MUSTEK_WINDOWS >= 1
317 window_data.window1 = window_data.frame;
318 window_data.window1.header = MUSTEK_WINDOW_MASK | MUSTEK_UNIT_SPEC;
319 #endif
320
321 /* send the set window command to the scanner */
322 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_set_parms: set_window\n"));
323 error = scsipi_command(periph,
324 (struct scsipi_generic *) &window_cmd,
325 sizeof(window_cmd), (u_char *) &window_data, sizeof(window_data),
326 MUSTEK_RETRIES, 5000, NULL, XS_CTL_DATA_OUT | XS_CTL_DATA_ONSTACK);
327 if (error)
328 return (error);
329
330 /*
331 * do what it takes to actualize the mode
332 */
333 memset(&mode_cmd, 0, sizeof(mode_cmd));
334 mode_cmd.opcode = MUSTEK_MODE_SELECT;
335 _lto2b(sizeof(mode_data), mode_cmd.length);
336
337 memset(&mode_data, 0, sizeof(mode_data));
338 mode_data.mode =
339 MUSTEK_MODE_MASK | MUSTEK_HT_PATTERN_BUILTIN | MUSTEK_UNIT_SPEC;
340 if (ss->sio.scan_x_resolution <= 300) {
341 mode_data.resolution = ss->sio.scan_x_resolution / 3;
342 } else {
343 /*
344 * the resolution values is computed by modulo 100, but not
345 * for 600dpi, where the value is 100 (a bit tricky, but ...)
346 */
347 mode_data.resolution =
348 ((ss->sio.scan_x_resolution - 1) % 100) + 1;
349 }
350 mode_data.brightness = (ss->sio.scan_brightness - 64) / 3;
351 mode_data.contrast = (ss->sio.scan_contrast - 16) / 7;
352 mode_data.grain = 0;
353 mode_data.velocity = ss->sio.scan_quality / 20 - 1;
354 #ifdef MUSTEK_INCH_SPEC
355 paperlength = 14 * 8; /* 14" */
356 #else
357 paperlength = 14 * ss->sio.scan_y_resolution; /* 14" */
358 #endif
359 _lto2l(paperlength, mode_data.paperlength);
360
361 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_trigger_scanner: mode_select\n"));
362 /* send the command to the scanner */
363 error = scsipi_command(periph,
364 (struct scsipi_generic *) &mode_cmd,
365 sizeof(mode_cmd), (u_char *) &mode_data, sizeof(mode_data),
366 MUSTEK_RETRIES, 5000, NULL, XS_CTL_DATA_OUT | XS_CTL_DATA_ONSTACK);
367 if (error)
368 return (error);
369
370 /*
371 * now construct and send the start command
372 */
373 memset(&start_scan_cmd, 0, sizeof(start_scan_cmd));
374 start_scan_cmd.opcode = MUSTEK_START_STOP;
375 start_scan_cmd.mode = MUSTEK_SCAN_START;
376 if (ss->sio.scan_x_resolution <= 300)
377 start_scan_cmd.mode |= MUSTEK_RES_STEP_1;
378 else
379 start_scan_cmd.mode |= MUSTEK_RES_STEP_10;
380 switch (ss->sio.scan_image_mode) {
381 case SIM_BINARY_MONOCHROME:
382 case SIM_DITHERED_MONOCHROME:
383 start_scan_cmd.mode |= MUSTEK_BIT_MODE | MUSTEK_GRAY_FILTER;
384 break;
385 case SIM_GRAYSCALE:
386 start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_GRAY_FILTER;
387 break;
388 case SIM_RED:
389 start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_RED_FILTER;
390 break;
391 case SIM_GREEN:
392 start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_GREEN_FILTER;
393 break;
394 case SIM_BLUE:
395 start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_BLUE_FILTER;
396 break;
397 }
398
399 /* send the command to the scanner */
400 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_trigger_scanner: start_scan\n"));
401 error = scsipi_command(periph,
402 (struct scsipi_generic *) &start_scan_cmd,
403 sizeof(start_scan_cmd), NULL, 0,
404 MUSTEK_RETRIES, 5000, NULL, 0);
405 if (error)
406 return (error);
407
408 /*
409 * now check if scanner ready this time with update of size info
410 * we wait here so that if the user issues a read directly afterwards,
411 * the scanner will respond directly (otherwise we had to sleep with
412 * a buffer locked in memory)
413 */
414 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_trigger_scanner: get_status\n"));
415 error = mustek_get_status(ss, 60, 1);
416 if (error)
417 return (error);
418
419 return (0);
420 }
421
422 /*
423 * stop a scan operation in progress
424 */
425 static int
426 mustek_rewind_scanner(struct ss_softc *ss)
427 {
428 struct mustek_start_scan_cmd cmd;
429 struct scsipi_periph *periph = ss->sc_periph;
430 int error;
431
432 if (ss->sio.scan_window_size != 0) {
433 /*
434 * only if not all data has been read, the scanner has to be
435 * stopped
436 */
437 memset(&cmd, 0, sizeof(cmd));
438 cmd.opcode = MUSTEK_START_STOP;
439 cmd.mode = MUSTEK_SCAN_STOP;
440
441 /* send the command to the scanner */
442 SC_DEBUG(periph, SCSIPI_DB1,
443 ("mustek_rewind_scanner: stop_scan\n"));
444 error = scsipi_command(periph,
445 (struct scsipi_generic *) &cmd,
446 sizeof(cmd), NULL, 0, MUSTEK_RETRIES, 5000, NULL, 0);
447 if (error)
448 return (error);
449 }
450
451 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_rewind_scanner: end\n"));
452
453 return (0);
454 }
455
456 /*
457 * read the requested number of bytes/lines from the scanner
458 */
459 static int
460 mustek_read(struct ss_softc *ss, struct buf *bp)
461 {
462 struct mustek_read_cmd cmd;
463 struct scsipi_periph *periph = ss->sc_periph;
464 u_long lines_to_read;
465 int error;
466
467 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_read: start\n"));
468
469 memset(&cmd, 0, sizeof(cmd));
470 cmd.opcode = MUSTEK_READ;
471
472 /* instead of the bytes, the mustek wants the number of lines */
473 lines_to_read = bp->b_bcount /
474 ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
475 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_read: read %ld lines\n",
476 lines_to_read));
477 _lto3b(lines_to_read, cmd.length);
478
479 /*
480 * go ask the adapter to do all this for us
481 */
482 error = scsipi_command(periph,
483 (struct scsipi_generic *) &cmd, sizeof(cmd),
484 (u_char *) bp->b_data, bp->b_bcount, MUSTEK_RETRIES, 10000, bp,
485 XS_CTL_NOSLEEP | XS_CTL_ASYNC | XS_CTL_DATA_IN);
486 if (error) {
487 printf("%s: not queued, error %d\n", ss->sc_dev.dv_xname,
488 error);
489 if (error == ENOMEM) {
490 /*
491 * out of memory. Keep this buffer in the queue, and
492 * retry later.
493 */
494 callout_reset(&ss->sc_callout, hz / 2, ssrestart,
495 periph);
496 return(0);
497 }
498 } else {
499 ss->sio.scan_lines -= lines_to_read;
500 if (ss->sio.scan_lines < 0)
501 ss->sio.scan_lines = 0;
502 ss->sio.scan_window_size -= bp->b_bcount;
503 if (ss->sio.scan_window_size < 0)
504 ss->sio.scan_window_size = 0;
505 }
506 #ifdef DIAGNOSTIC
507 if (BUFQ_GET(&ss->buf_queue) != bp)
508 panic("ssstart(): dequeued wrong buf");
509 #else
510 BUFQ_GET(&ss->buf_queue);
511 #endif
512
513 return (0);
514 }
515
516 /*
517 * check if the scanner is ready to take commands
518 * wait timeout seconds and try only every second
519 * if update, then update picture size info
520 *
521 * returns EBUSY if scanner not ready
522 */
523 static int
524 mustek_get_status(struct ss_softc *ss, int timeout, int update)
525 {
526 struct mustek_get_status_cmd cmd;
527 struct mustek_get_status_data data;
528 struct scsipi_periph *periph = ss->sc_periph;
529 int error, lines, bytes_per_line;
530
531 memset(&cmd, 0, sizeof(cmd));
532 cmd.opcode = MUSTEK_GET_STATUS;
533 cmd.length = sizeof(data);
534
535 while (1) {
536 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_get_status: stat_cmd\n"));
537 error = scsipi_command(periph,
538 (struct scsipi_generic *) &cmd, sizeof(cmd),
539 (u_char *) &data, sizeof(data), MUSTEK_RETRIES,
540 5000, NULL, XS_CTL_DATA_IN | XS_CTL_DATA_ONSTACK);
541 if (error)
542 return (error);
543 if ((data.ready_busy == MUSTEK_READY) ||
544 (timeout-- <= 0))
545 break;
546 /* please wait a second */
547 tsleep((caddr_t)mustek_get_status, PRIBIO + 1, "mtkrdy", hz);
548 }
549
550 if (update) {
551 bytes_per_line = _2ltol(data.bytes_per_line);
552 lines = _3ltol(data.lines);
553 if (lines != ss->sio.scan_lines) {
554 printf("mustek: lines actual(%d) != computed(%ld)\n",
555 lines, ss->sio.scan_lines);
556 return (EIO);
557 }
558 if (bytes_per_line * lines != ss->sio.scan_window_size) {
559 printf("mustek: win-size actual(%d) != computed(%ld)\n",
560 bytes_per_line * lines, ss->sio.scan_window_size);
561 return (EIO);
562 }
563
564 SC_DEBUG(periph, SCSIPI_DB1,
565 ("mustek_get_size: bpl=%ld, lines=%ld\n",
566 (ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8,
567 ss->sio.scan_lines));
568 SC_DEBUG(periph, SCSIPI_DB1, ("window size = %ld\n",
569 ss->sio.scan_window_size));
570 }
571
572 SC_DEBUG(periph, SCSIPI_DB1, ("mustek_get_status: end\n"));
573 if (data.ready_busy == MUSTEK_READY)
574 return (0);
575 else
576 return (EBUSY);
577 }
578
579 /*
580 * mustek_compute_sizes: compute window_size and lines for the picture
581 * this function is called from different places in the code
582 */
583 static void
584 mustek_compute_sizes(struct ss_softc *ss)
585 {
586
587 switch (ss->sio.scan_image_mode) {
588 case SIM_BINARY_MONOCHROME:
589 case SIM_DITHERED_MONOCHROME:
590 ss->sio.scan_bits_per_pixel = 1;
591 break;
592 case SIM_GRAYSCALE:
593 case SIM_RED:
594 case SIM_GREEN:
595 case SIM_BLUE:
596 ss->sio.scan_bits_per_pixel = 8;
597 break;
598 }
599
600 /*
601 * horizontal number of bytes is always a multiple of 2,
602 * in 8-bit mode at least
603 */
604 ss->sio.scan_pixels_per_line =
605 (ss->sio.scan_width * ss->sio.scan_x_resolution) / 1200;
606 if (ss->sio.scan_bits_per_pixel == 1)
607 /* make it a multiple of 16, and thus of 2 bytes */
608 ss->sio.scan_pixels_per_line =
609 (ss->sio.scan_pixels_per_line + 15) & 0xfffffff0;
610 else
611 ss->sio.scan_pixels_per_line =
612 (ss->sio.scan_pixels_per_line + 1) & 0xfffffffe;
613
614 ss->sio.scan_lines =
615 (ss->sio.scan_height * ss->sio.scan_y_resolution) / 1200;
616 ss->sio.scan_window_size = ss->sio.scan_lines *
617 ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
618 }
619