2ffc2c5
From 2fea21f28ecbcd83ec4c4cf6d1578cdd552b0df4 Mon Sep 17 00:00:00 2001
2ffc2c5
From: Nils Philippsen <nils@redhat.com>
2ffc2c5
Date: Tue, 14 Mar 2017 17:38:49 +0100
2ffc2c5
Subject: [PATCH] patch: avision-skip-adf
2ffc2c5
2ffc2c5
Squashed commit of the following:
2ffc2c5
2ffc2c5
commit 1177ca9c2673e5264741dff60010ddebaf43737c
2ffc2c5
Author: Dave Platt <dplatt@radagast.org>
2ffc2c5
Date:   Thu Dec 15 22:29:16 2016 -0800
2ffc2c5
2ffc2c5
    avision.c: Add "skip-adf" option
2ffc2c5
2ffc2c5
    The code which tries aggressively to reset/initialize HP 82xx/83xx
2ffc2c5
    Automatic Document Feeders doesn't work well if there's no ADF attached,
2ffc2c5
    because the scanner reports a non-zero ADF model type in this case.
2ffc2c5
    The retry code makes several attempts to initialize the ADF, and then
2ffc2c5
    bails out with an "Operation not supported" error.
2ffc2c5
2ffc2c5
    Add a new "option skip-adf" which will cause the backend to believe
2ffc2c5
    the "ADF not present" status if that's what the scanner reports.
2ffc2c5
2ffc2c5
    Fixes #313751
2ffc2c5
2ffc2c5
    (cherry picked from commit 6585b6f60d07a196e42c99b935e2754bbc80b3c8)
2ffc2c5
---
2ffc2c5
 backend/avision.c    | 14 ++++++++++++--
2ffc2c5
 doc/sane-avision.man | 10 ++++++++++
2ffc2c5
 2 files changed, 22 insertions(+), 2 deletions(-)
2ffc2c5
2ffc2c5
diff --git a/backend/avision.c b/backend/avision.c
2ffc2c5
index 146125c..b02b547 100644
2ffc2c5
--- a/backend/avision.c
2ffc2c5
+++ b/backend/avision.c
2ffc2c5
@@ -1277,6 +1277,9 @@ static SANE_Bool force_calibration = SANE_FALSE;
2ffc2c5
 static SANE_Bool force_a4 = SANE_FALSE;
2ffc2c5
 static SANE_Bool force_a3 = SANE_FALSE;
2ffc2c5
 
2ffc2c5
+/* trust ADF-presence flag, even if ADF model is nonzero */
2ffc2c5
+static SANE_Bool skip_adf = SANE_FALSE;
2ffc2c5
+
2ffc2c5
 /* hardware resolutions to interpolate from */
2ffc2c5
 static const int  hw_res_list_c5[] =
2ffc2c5
   {
2ffc2c5
@@ -3218,11 +3221,13 @@ get_accessories_info (Avision_Scanner* s)
2ffc2c5
     {
2ffc2c5
       dev->inquiry_duplex = 1;
2ffc2c5
       dev->inquiry_duplex_interlaced = 0;
2ffc2c5
-    } else if (result[0] == 0 && result[2] != 0) {
2ffc2c5
+    } else if (result[0] == 0 && result[2] != 0 && !skip_adf) {
2ffc2c5
       /* Sometimes the scanner will report that there is no ADF attached, yet
2ffc2c5
        * an ADF model number will still be reported.  This happens on the
2ffc2c5
        * HP8200 series and possibly others.  In this case we need to reset the
2ffc2c5
-       * the adf and try reading it again.
2ffc2c5
+       * the adf and try reading it again.  Skip this if the configuration says
2ffc2c5
+       * to do so, so that we don't fail out the scanner as being broken and
2ffc2c5
+       * unsupported if there isn't actually an ADF present.
2ffc2c5
        */
2ffc2c5
       DBG (3, "get_accessories_info: Found ADF model number but the ADF-present flag is not set. Trying to recover...\n");
2ffc2c5
       status = adf_reset (s);
2ffc2c5
@@ -7630,6 +7635,11 @@ sane_reload_devices (void)
2ffc2c5
 		     linenumber);
2ffc2c5
 		force_a3 = SANE_TRUE;
2ffc2c5
 	      }
2ffc2c5
+	      else if (strcmp (word, "skip-adf") == 0) {
2ffc2c5
+		DBG (3, "sane_reload_devices: config file line %d: enabling skip-adf\n",
2ffc2c5
+		     linenumber);
2ffc2c5
+		skip_adf = SANE_TRUE;
2ffc2c5
+	      }
2ffc2c5
 	      else if (strcmp (word, "static-red-calib") == 0) {
2ffc2c5
 		DBG (3, "sane_reload_devices: config file line %d: static red calibration\n",
2ffc2c5
 		     linenumber);
2ffc2c5
diff --git a/doc/sane-avision.man b/doc/sane-avision.man
2ffc2c5
index 299bb72..6a991b6 100644
2ffc2c5
--- a/doc/sane-avision.man
2ffc2c5
+++ b/doc/sane-avision.man
2ffc2c5
@@ -36,6 +36,7 @@ a hash mark (#) are ignored. A sample configuration file is shown below:
2ffc2c5
 \ 
2ffc2c5
  option force\-a4
2ffc2c5
  option force\-a3
2ffc2c5
+ option skip\-adf
2ffc2c5
  option disable\-gamma\-table
2ffc2c5
  option disable\-calibration
2ffc2c5
 \ 
2ffc2c5
@@ -61,6 +62,15 @@ known to return bogus data are marked in the backend
2ffc2c5
 so if you need this option please report this to the
2ffc2c5
 backend maintainer. USE WITH CARE!
2ffc2c5
 .TP
2ffc2c5
+skip\-adf:
2ffc2c5
+Forces the backend to ignore an inconsistent ADF
2ffc2c5
+status returned by the scanner (ADF not present, but
2ffc2c5
+ADF model number non-zero).  Without this option, the
2ffc2c5
+backend will make several attempts to reset the ADF
2ffc2c5
+and retry the query in this situation, and will fail
2ffc2c5
+with a "not supported" error if the ADF still doesn't
2ffc2c5
+respond.
2ffc2c5
+.TP
2ffc2c5
 disable\-gamma\-table:
2ffc2c5
 Disables the usage of the scanner's gamma-table. You
2ffc2c5
 might try this if your scans hang or only produces
2ffc2c5
-- 
2ffc2c5
2.9.3
2ffc2c5