From cae6ee91fd215e49a02a32de468f136a8c454385 Mon Sep 17 00:00:00 2001 From: Henning Geinitz Date: Tue, 2 Mar 2004 21:00:46 +0000 Subject: [PATCH] Added workaround for toggle = data0 chipset bug. Fixes bug #300323. --- ChangeLog | 7 ++++++ backend/mustek_usb.c | 8 +++---- backend/mustek_usb_low.c | 40 ++++++++++++++++++++++++------- backend/mustek_usb_low.h | 3 +++ doc/mustek_usb/mustek_usb.CHANGES | 10 ++++++++ doc/mustek_usb/mustek_usb.TODO | 6 +++-- doc/sane-mustek_usb.man | 15 +++++------- 7 files changed, 65 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 382ba6807..4d5a0094c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-03-02 Henning Meier-Geinitz + + * backend/mustek_usb.c backend/mustek_usb_low.c + backend/mustek_usb_low.h doc/sane-mustek_usb.man: + Added workaround for toggle = data0 chipset bug. + Fixes bug #300323. + 2004-03-01 Frank Zago * doc/descriptions-external/genesys.desc: created list of scanners diff --git a/backend/mustek_usb.c b/backend/mustek_usb.c index 5344e6b93..cd690ddd7 100644 --- a/backend/mustek_usb.c +++ b/backend/mustek_usb.c @@ -3,7 +3,7 @@ Copyright (C) 2000 Mustek. Originally maintained by Tom Wang - Copyright (C) 2001, 2002 by Henning Meier-Geinitz. + Copyright (C) 2001 - 2004 by Henning Meier-Geinitz. This file is part of the SANE package. @@ -46,7 +46,7 @@ This file implements a SANE backend for Mustek 1200UB and similar USB flatbed scanners. */ -#define BUILD 17 +#define BUILD 18 #include "../include/sane/config.h" @@ -86,8 +86,8 @@ static Mustek_Usb_Device *first_dev; static Mustek_Usb_Scanner *first_handle; static const SANE_Device **devlist = 0; -/* Maximum amount of data read in one turn from USB */ -static SANE_Word max_block_size = 8 * 1024; +/* Maximum amount of data read in one turn from USB. */ +static SANE_Word max_block_size = (8 * 1024); /* Array of newly attached devices */ static Mustek_Usb_Device **new_dev; diff --git a/backend/mustek_usb_low.c b/backend/mustek_usb_low.c index 13a654783..e626b65dc 100644 --- a/backend/mustek_usb_low.c +++ b/backend/mustek_usb_low.c @@ -3,7 +3,7 @@ Copyright (C) 2000 Mustek. Originally maintained by Tom Wang - Copyright (C) 2001, 2002 by Henning Meier-Geinitz. + Copyright (C) 2001 - 2004 by Henning Meier-Geinitz. This file is part of the SANE package. @@ -153,6 +153,8 @@ usb_low_init (ma1017 ** chip_address) chip->sensor = ST_CANON600; chip->motor = MT_1200; + chip->total_read_urbs = 0; + chip->total_write_urbs = 0; DBG (7, "usb_low_init: exit\n"); return SANE_STATUS_GOOD; } @@ -163,17 +165,15 @@ usb_low_exit (ma1017 * chip) DBG (7, "usb_low_exit: chip = %p\n", (void *) chip); if (chip) { - if (chip->fd >= 0) - { - DBG (7, "usb_low_exit: closing fd %d\n", chip->fd); - sanei_usb_close (chip->fd); - chip->fd = -1; - } + if (chip->fd >= 0 && chip->is_opened) + usb_low_close (chip); DBG (7, "usb_low_exit: freeing chip\n"); free (chip); } - return SANE_STATUS_GOOD; + DBG (5, "usb_low_exit: read %d URBs, wrote %d URBs\n", + chip->total_read_urbs, chip->total_write_urbs); DBG (7, "usb_low_exit: exit\n"); + return SANE_STATUS_GOOD; } /* A0 ~ A1 */ @@ -294,6 +294,7 @@ usb_low_start_cmt_table (ma1017 * chip) "wrote %lu bytes\n", (unsigned long int) n); return SANE_STATUS_IO_ERROR; } + chip->total_write_urbs++; chip->is_rowing = SANE_TRUE; DBG (7, "usb_low_start_cmt_table: exit\n"); return SANE_STATUS_GOOD; @@ -331,7 +332,7 @@ usb_low_stop_cmt_table (ma1017 * chip) "%lu bytes\n", (unsigned long int) n); return SANE_STATUS_IO_ERROR; } - + chip->total_write_urbs++; n = 1; status = sanei_usb_read_bulk (chip->fd, &read_byte, &n); if (status != SANE_STATUS_GOOD || n != 1) @@ -340,6 +341,7 @@ usb_low_stop_cmt_table (ma1017 * chip) "bytes\n", (unsigned long int) n); return SANE_STATUS_IO_ERROR; } + chip->total_read_urbs++; chip->is_rowing = SANE_FALSE; DBG (7, "usb_low_stop_cmt_table: exit\n"); @@ -2601,6 +2603,7 @@ usb_low_wait_rowing (ma1017 * chip) sane_strstatus (status)); return SANE_STATUS_IO_ERROR; } + chip->total_read_urbs++; chip->is_rowing = SANE_FALSE; DBG (7, "usb_low_wait_rowing: exit\n"); return SANE_STATUS_GOOD; @@ -2638,6 +2641,9 @@ usb_low_read_rows (ma1017 * chip, SANE_Byte * data, SANE_Word byte_count) sane_strstatus (status)); return status; } + /* Count the number of URBs. This is a bit tricky, as we are reading + bigger chunks here but the scanner can only handle 64 bytes at once. */ + chip->total_read_urbs += ((n + 63) / 64); bytes_total += n; if ((SANE_Word) bytes_total != byte_count) { @@ -2688,6 +2694,7 @@ usb_low_write_reg (ma1017 * chip, SANE_Byte reg_no, SANE_Byte data) sane_strstatus (status)); return SANE_STATUS_IO_ERROR; } + chip->total_write_urbs++; DBG (7, "usb_low_write_reg: reg: 0x%02x, value: 0x%02x\n", reg_no, data); return SANE_STATUS_GOOD; } @@ -2719,6 +2726,8 @@ usb_low_read_reg (ma1017 * chip, SANE_Byte reg_no, SANE_Byte * data) return SANE_STATUS_INVAL; } n = 2; + DBG (5, "usb_low_read_reg: trying to write %lu bytes\n", (unsigned long int) n); + status = sanei_usb_write_bulk (chip->fd, data_field, &n); if (status != SANE_STATUS_GOOD || n != 2) { @@ -2727,7 +2736,9 @@ usb_low_read_reg (ma1017 * chip, SANE_Byte reg_no, SANE_Byte * data) sane_strstatus (status)); return SANE_STATUS_IO_ERROR; } + chip->total_write_urbs++; n = 1; + DBG (5, "usb_low_read_reg: trying to read %lu bytes\n", (unsigned long int) n); status = sanei_usb_read_bulk (chip->fd, (SANE_Byte *) & read_byte, &n); if (status != SANE_STATUS_GOOD || n != 1) { @@ -2736,6 +2747,7 @@ usb_low_read_reg (ma1017 * chip, SANE_Byte reg_no, SANE_Byte * data) (unsigned long int) n, sane_strstatus (status)); return SANE_STATUS_IO_ERROR; } + chip->total_read_urbs++; if (data) *data = read_byte; DBG (7, "usb_low_read_reg: Reg: 0x%02x, Value: 0x%02x\n", @@ -2879,8 +2891,18 @@ usb_low_close (ma1017 * chip) if (chip->fd >= 0) { + SANE_Byte dummy; + if (chip->is_rowing) usb_low_stop_rowing (chip); + /* Now make sure that both the number of written and + read URBs is even. Use some dummy writes/reads. That's to avoid + a nasty bug in the MA 1017 chipset that causes timeouts when + the number of URBs is odd (toggle bug). */ + if ((chip->total_read_urbs % 2) == 1) + usb_low_get_a4 (chip, &dummy); + if ((chip->total_write_urbs % 2) == 1) + usb_low_set_fix_pattern (chip, SANE_FALSE); sanei_usb_close (chip->fd); chip->fd = -1; } diff --git a/backend/mustek_usb_low.h b/backend/mustek_usb_low.h index 25ee6da74..e5605db56 100644 --- a/backend/mustek_usb_low.h +++ b/backend/mustek_usb_low.h @@ -188,6 +188,9 @@ typedef struct ma1017 Motor_Type motor; Mustek_Type scanner_type; SANE_Word max_block_size; + + SANE_Word total_read_urbs; + SANE_Word total_write_urbs; } ma1017; diff --git a/doc/mustek_usb/mustek_usb.CHANGES b/doc/mustek_usb/mustek_usb.CHANGES index 453c4c6cd..7b01c4af6 100644 --- a/doc/mustek_usb/mustek_usb.CHANGES +++ b/doc/mustek_usb/mustek_usb.CHANGES @@ -1,5 +1,15 @@ CHANGES for the SANE Mustek USB backend +2004-03-02 + * Release of version 1.0-18. + +2004-03-02 + * Added workaround for data0 toggle bug. I think this is a bug in the + chipset. The chipset doesn't set the toggle to data0 when the endpoints + are reset. As this is done whenever the device files/libusb is closed, + this backend worked ony once. Now we count the number of URBs and + just read/write some crap if the number is odd. + 2003-09-21 * Release of version 1.0-17. diff --git a/doc/mustek_usb/mustek_usb.TODO b/doc/mustek_usb/mustek_usb.TODO index 3851eb1ed..e52673f6c 100644 --- a/doc/mustek_usb/mustek_usb.TODO +++ b/doc/mustek_usb/mustek_usb.TODO @@ -1,8 +1,10 @@ -2002-11-21 +2004-03-02 * Support more scanners - - 1200 USB (work in progress) + - 1200 USB - 600 USB + These are both CCD scanners. Several people tried to add support until + now but I have never heard from the again ... * Remove/replace _word variables from usb_low * Check if low resolutions can be made faster. * Check fixmes. diff --git a/doc/sane-mustek_usb.man b/doc/sane-mustek_usb.man index 490f9dfbd..10c5b4d37 100644 --- a/doc/sane-mustek_usb.man +++ b/doc/sane-mustek_usb.man @@ -1,4 +1,4 @@ -.TH sane-mustek_usb 5 "21 Oct 2003" "@PACKAGEVERSION@" "SANE Scanner Access Now Easy" +.TH sane-mustek_usb 5 "3 Mar 2004" "@PACKAGEVERSION@" "SANE Scanner Access Now Easy" .IX sane-mustek_usb .SH NAME sane-mustek_usb \- SANE backend for Mustek USB flatbed scanners @@ -189,16 +189,13 @@ Tom Wang. .SH BUGS These devices have a hardware bug: Once data is written to them, they can't be -resetted (toggle = DATA0). That means, any operation that tries to reset the +reset (toggle = DATA0). That means, any operation that tries to reset the device will result in running into timeouts. -That means that this backend will fail when it is loaded the second time in -some configurations: E.g. using libusb, (Free|Open|Net)BSD or with Linux if -you unload and reload the scanner module. The only choice is to replug the -scanner in this case. The workaround for Linux is to use the scanner module -(modprobe scanner) instead of libusb. See -.BR sane-usb (5) -for details. +In earlier versions this backend failed when it is loaded the second time in +some configurations. The only choice was to replug the scanner in this case. The +backend uses a workaround for that bug now but it's only tested on +Linux. Reports for other operating systems are appriciated. .PP More detailed bug information is available at the Mustek backend homepage