From 902610132b04d1adc279f11cc2cb7541a28b0ba7 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Tue, 23 Apr 2019 00:14:46 +0300 Subject: [PATCH 1/4] genesys: Include genesys_low.h --- backend/genesys_devices.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/genesys_devices.c b/backend/genesys_devices.c index 15b0b198c..eee88ffdd 100644 --- a/backend/genesys_devices.c +++ b/backend/genesys_devices.c @@ -55,6 +55,8 @@ /* Some setup DAC and CCD tables */ /* ------------------------------------------------------------------------ */ +#include "genesys_low.h" + /** Setup table for various scanners using a Wolfson DAC */ static Genesys_Frontend Wolfson[] = { From f04119b12626d0bb7c71e46a8a82837501da7ee9 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Tue, 23 Apr 2019 00:14:47 +0300 Subject: [PATCH 2/4] genesys: Remove support for fake USB mode WIP implement support for 8600F --- backend/genesys_gl124.c | 15 ++------------ backend/genesys_gl846.c | 10 ++------- backend/genesys_gl847.c | 4 ++-- backend/genesys_low.c | 46 ++++++++++++++++------------------------- backend/genesys_low.h | 11 +++++++--- 5 files changed, 32 insertions(+), 54 deletions(-) diff --git a/backend/genesys_gl124.c b/backend/genesys_gl124.c index 668663f60..8fd51c8d4 100644 --- a/backend/genesys_gl124.c +++ b/backend/genesys_gl124.c @@ -687,7 +687,7 @@ gl124_send_slope_table (Genesys_Device * dev, int table_nr, /* slope table addresses are fixed */ status = - sanei_genesys_write_ahb (dev->dn, dev->usb_mode, 0x10000000 + 0x4000 * table_nr, steps * 2, table); + sanei_genesys_write_ahb(dev->dn, 0x10000000 + 0x4000 * table_nr, steps * 2, table); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, @@ -805,11 +805,6 @@ gl124_set_fe (Genesys_Device * dev, uint8_t set) RIE (sanei_genesys_read_register (dev, REG0A, &val)); - if(dev->usb_mode<0) - { - val=3<>REG0AS_SIFSEL) { @@ -2198,12 +2193,6 @@ gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) DBG(DBG_proc, "%s (wait_until_home = %d)\n", __func__, wait_until_home); - if(dev->usb_mode<0) - { - DBGCOMPLETED; - return SANE_STATUS_GOOD; - } - /* post scan gpio : without that HOMSNR is unreliable */ gl124_homsnr_gpio(dev); @@ -2938,7 +2927,7 @@ gl124_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) } RIE (sanei_genesys_read_register (dev, 0xd0+i, &val)); addr = val * 8192 + 0x10000000; - status = sanei_genesys_write_ahb (dev->dn, dev->usb_mode, addr, pixels*dev->segnb, buffer); + status = sanei_genesys_write_ahb(dev->dn, addr, pixels*dev->segnb, buffer); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s; write to AHB failed (%s)\n", __func__, sane_strstatus(status)); diff --git a/backend/genesys_gl846.c b/backend/genesys_gl846.c index 909bc9a47..4d2dc840b 100644 --- a/backend/genesys_gl846.c +++ b/backend/genesys_gl846.c @@ -599,7 +599,7 @@ gl846_send_slope_table (Genesys_Device * dev, int table_nr, } /* slope table addresses are fixed */ - status = sanei_genesys_write_ahb (dev->dn, dev->usb_mode, 0x10000000 + 0x4000 * table_nr, steps * 2, table); + status = sanei_genesys_write_ahb(dev->dn, 0x10000000 + 0x4000 * table_nr, steps * 2, table); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: write to AHB failed writing slope table %d (%s)\n", __func__, table_nr, @@ -1875,12 +1875,6 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) DBG(DBG_proc, "%s (wait_until_home = %d)\n", __func__, wait_until_home); - if(dev->usb_mode<0) - { - DBGCOMPLETED; - return SANE_STATUS_GOOD; - } - /* post scan gpio : without that HOMSNR is unreliable */ gl846_homsnr_gpio(dev); @@ -2523,7 +2517,7 @@ gl846_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) RIEF (sanei_genesys_read_register (dev, 0xd0+i, &val), buffer); addr = val * 8192 + 0x10000000; - status = sanei_genesys_write_ahb (dev->dn, dev->usb_mode, addr, pixels, buffer); + status = sanei_genesys_write_ahb(dev->dn, addr, pixels, buffer); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s; write to AHB failed (%s)\n", __func__, sane_strstatus(status)); diff --git a/backend/genesys_gl847.c b/backend/genesys_gl847.c index b5059713c..bba714680 100644 --- a/backend/genesys_gl847.c +++ b/backend/genesys_gl847.c @@ -622,7 +622,7 @@ gl847_send_slope_table (Genesys_Device * dev, int table_nr, /* slope table addresses are fixed */ status = - sanei_genesys_write_ahb (dev->dn, dev->usb_mode, 0x10000000 + 0x4000 * table_nr, steps * 2, table); + sanei_genesys_write_ahb(dev->dn, 0x10000000 + 0x4000 * table_nr, steps * 2, table); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: write to AHB failed writing slope table %d (%s)\n", __func__, table_nr, @@ -2582,7 +2582,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) RIE (sanei_genesys_read_register (dev, 0xd0+i, &val)); addr = val * 8192 + 0x10000000; - status = sanei_genesys_write_ahb (dev->dn, dev->usb_mode, addr, pixels, buffer); + status = sanei_genesys_write_ahb(dev->dn, addr, pixels, buffer); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s; write to AHB failed (%s)\n", __func__, sane_strstatus(status)); diff --git a/backend/genesys_low.c b/backend/genesys_low.c index a15103680..0631fc3d3 100644 --- a/backend/genesys_low.c +++ b/backend/genesys_low.c @@ -1049,13 +1049,13 @@ sanei_genesys_bulk_write_register (Genesys_Device * dev, /** * writes a block of data to AHB * @param dn USB device index - * @param usb_mode usb mode : -1, fake usb, 1 usb 1.1, 2 usb 2.0 + * @param usb_mode usb mode : 1 usb 1.1, 2 usb 2.0 * @param addr AHB address to write to * @param size size of the chunk of data * @param data pointer to the data to write */ SANE_Status -sanei_genesys_write_ahb (SANE_Int dn, int usb_mode, uint32_t addr, uint32_t size, uint8_t * data) +sanei_genesys_write_ahb (SANE_Int dn, uint32_t addr, uint32_t size, uint8_t * data) { uint8_t outdata[8]; size_t written,blksize; @@ -1082,13 +1082,6 @@ sanei_genesys_write_ahb (SANE_Int dn, int usb_mode, uint32_t addr, uint32_t size DBG (DBG_io, "%s: %s\n", __func__, msg); } - /* no effective write if fake USB */ - if(usb_mode<0) - { - DBGCOMPLETED; - return status; - } - /* write addr and size for AHB */ status = sanei_usb_control_msg (dn, REQUEST_TYPE_OUT, REQUEST_BUFFER, VALUE_BUFFER, @@ -1252,7 +1245,7 @@ sanei_genesys_send_gamma_table (Genesys_Device * dev) RIEF (sanei_genesys_write_register (dev, 0xc5+2*i, gamma[size*2*i+1]), gamma); RIEF (sanei_genesys_write_register (dev, 0xc6+2*i, gamma[size*2*i]), gamma); - status = sanei_genesys_write_ahb (dev->dn, dev->usb_mode, 0x01000000 + 0x200 * i, (size-1) * 2, gamma + i * size * 2+2); + status = sanei_genesys_write_ahb(dev->dn, 0x01000000 + 0x200 * i, (size-1) * 2, gamma + i * size * 2+2); if (status != SANE_STATUS_GOOD) { free (gamma); @@ -1289,25 +1282,22 @@ sanei_genesys_asic_init (Genesys_Device * dev, int max_regs) DBGSTART; /* URB 16 control 0xc0 0x0c 0x8e 0x0b len 1 read 0x00 */ - if(dev->usb_mode>=0) + status = sanei_usb_control_msg (dev->dn, REQUEST_TYPE_IN, REQUEST_REGISTER, VALUE_GET_REGISTER, 0x00, 1, &val); + if (status != SANE_STATUS_GOOD) { - status = sanei_usb_control_msg (dev->dn, REQUEST_TYPE_IN, REQUEST_REGISTER, VALUE_GET_REGISTER, 0x00, 1, &val); - if (status != SANE_STATUS_GOOD) - { - DBG (DBG_error, "%s: request register failed %s\n", __func__, - sane_strstatus (status)); - return status; - } - DBG (DBG_io2, "%s: value=0x%02x\n", __func__, val); - DBG (DBG_info, "%s: device is %s\n", __func__, (val & 0x08) ? "USB 1.0" : "USB2.0"); - if (val & 0x08) - { - dev->usb_mode = 1; - } - else - { - dev->usb_mode = 2; - } + DBG (DBG_error, "%s: request register failed %s\n", __func__, + sane_strstatus (status)); + return status; + } + DBG (DBG_io2, "%s: value=0x%02x\n", __func__, val); + DBG (DBG_info, "%s: device is %s\n", __func__, (val & 0x08) ? "USB 1.0" : "USB2.0"); + if (val & 0x08) + { + dev->usb_mode = 1; + } + else + { + dev->usb_mode = 2; } /* setup gamma tables */ diff --git a/backend/genesys_low.h b/backend/genesys_low.h index 349f785f7..e59c35c4e 100644 --- a/backend/genesys_low.h +++ b/backend/genesys_low.h @@ -771,8 +771,13 @@ struct Genesys_Device SANE_Int dn; SANE_Word vendorId; /**< USB vendor identifier */ SANE_Word productId; /**< USB product identifier */ - SANE_Int usb_mode; /**< USB mode: 1 for USB 1.1, 2 for USB 2.0, - 0 unset and -1 for fake USB device */ + + // USB mode: + // 0: not set + // 1: USB 1.1 + // 2: USB 2.0 + SANE_Int usb_mode; + SANE_String file_name; SANE_String calib_file; Genesys_Model *model; @@ -948,7 +953,7 @@ extern SANE_Status sanei_genesys_get_status (Genesys_Device * dev, uint8_t * sta extern void sanei_genesys_print_status (uint8_t val); extern SANE_Status -sanei_genesys_write_ahb (SANE_Int dn, int usb_mode, uint32_t addr, uint32_t size, uint8_t * data); +sanei_genesys_write_ahb(SANE_Int dn, uint32_t addr, uint32_t size, uint8_t * data); extern void sanei_genesys_init_fe (Genesys_Device * dev); From d7c17f75403aa5619c711b7d19e81932fa9a47b1 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Tue, 23 Apr 2019 00:14:48 +0300 Subject: [PATCH 3/4] genesys: Limit maximum bulk transfer size to allow data capture --- backend/genesys_low.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/genesys_low.h b/backend/genesys_low.h index e59c35c4e..cf069c156 100644 --- a/backend/genesys_low.h +++ b/backend/genesys_low.h @@ -203,8 +203,14 @@ #define BULK_RAM 0x00 #define BULK_REGISTER 0x11 -#define BULKIN_MAXSIZE 0xFE00 -#define GL646_BULKIN_MAXSIZE 0xFFC0 +/* Genesys supports 0xFE00 maximum size in general, wheraus GL646 supports + 0xFFC0. We use 0xF000 because that's the packet limit in the Linux usbmon + USB capture stack. By default it limits packet size to b_size / 5 where + b_size is the size of the ring buffer. By default it's 300*1024, so the + packet is limited 61440 without any visibility to acquiring software. +*/ +#define BULKIN_MAXSIZE 0xF000 +#define GL646_BULKIN_MAXSIZE 0xF000 #define GL646_BULKIN_MINSIZE 0x0800 #define BULKOUT_MAXSIZE 0xF000 From 3cd8a4cd015769d275816252b256cc0e97b9a847 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Tue, 23 Apr 2019 00:14:49 +0300 Subject: [PATCH 4/4] genesys: Use hex to print USB vendor and product IDs to debug log --- backend/genesys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/genesys.c b/backend/genesys.c index 06102f55e..20cba2b86 100644 --- a/backend/genesys.c +++ b/backend/genesys.c @@ -6009,8 +6009,8 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait) if (!dev) { - DBG(DBG_error, "%s: vendor %d product %d is not supported by this backend\n", __func__, - vendor, product); + DBG(DBG_error, "%s: vendor 0x%xd product 0x%xd is not supported by this backend\n", __func__, + vendor, product); return SANE_STATUS_INVAL; }