Commit 3c8b9b91 authored by Povilas Kanapickas's avatar Povilas Kanapickas

Merge branch 'genesys-reduce-duplication' into 'master'

genesys: Reduce duplication in low level functions

See merge request !63
parents 74fffa64 8de5a1fd
Pipeline #60815811 passed with stages
in 7 minutes and 30 seconds
......@@ -47,124 +47,6 @@
#include "genesys_gl124.h"
/****************************************************************************
Low level function
****************************************************************************/
/* ------------------------------------------------------------------------ */
/* Read and write RAM, registers and AFE */
/* ------------------------------------------------------------------------ */
/** @brief read scanned data
* Read in 0xeff0 maximum sized blocks. This read is done in 2
* parts if not multple of 512. First read is rounded to a multiple of 512 bytes, last read fetches the
* remainder. Read addr is always 0x10000000 with the memory layout setup.
* @param dev device to read data from
* @param addr address within ASIC emory space
* @param data pointer where to store the read data
* @param len size to read
*/
static SANE_Status
gl124_bulk_read_data (Genesys_Device * dev, uint8_t addr,
uint8_t * data, size_t len)
{
SANE_Status status;
size_t size, target, read, done;
uint8_t outdata[8], *buffer;
DBG(DBG_io, "%s: requesting %lu bytes (unused addr=0x%02x)\n", __func__, (u_long) len,addr);
if (len == 0)
return SANE_STATUS_GOOD;
target = len;
buffer = data;
/* loop until computed data size is read */
while (target)
{
if (target > 0xeff0)
{
size = 0xeff0;
}
else
{
size = target;
}
/* hard coded 0x10000000 addr */
outdata[0] = 0;
outdata[1] = 0;
outdata[2] = 0;
outdata[3] = 0x10;
/* data size to transfer */
outdata[4] = (size & 0xff);
outdata[5] = ((size >> 8) & 0xff);
outdata[6] = ((size >> 16) & 0xff);
outdata[7] = ((size >> 24) & 0xff);
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
VALUE_BUFFER, 0x00, sizeof (outdata),
outdata);
if (status != SANE_STATUS_GOOD)
{
DBG (DBG_error, "%s failed while writing command: %s\n",
__func__, sane_strstatus (status));
return status;
}
/* blocks must be multiple of 512 but not last block */
read = size;
read /= 512;
read *= 512;
if(read>0)
{
DBG(DBG_io2, "%s: trying to read %lu bytes of data\n", __func__, (u_long) read);
status = sanei_usb_read_bulk (dev->dn, data, &read);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while reading bulk data: %s\n", __func__,
sane_strstatus(status));
return status;
}
}
/* read less than 512 bytes remainder */
if (read < size)
{
done = read;
read = size - read;
DBG(DBG_io2, "%s: trying to read remaining %lu bytes of data\n", __func__, (u_long) read);
status = sanei_usb_read_bulk (dev->dn, data+done, &read);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while reading bulk data: %s\n", __func__,
sane_strstatus(status));
return status;
}
}
DBG (DBG_io2, "%s: read %lu bytes, %lu remaining\n", __func__,
(u_long) size, (u_long) (target - size));
target -= size;
data += size;
}
if (DBG_LEVEL >= DBG_data && dev->binary!=NULL)
{
fwrite(buffer, len, 1, dev->binary);
}
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
/****************************************************************************
Mid level functions
****************************************************************************/
......@@ -686,8 +568,7 @@ gl124_send_slope_table (Genesys_Device * dev, int table_nr,
}
/* slope table addresses are fixed */
status =
sanei_genesys_write_ahb(dev->dn, 0x10000000 + 0x4000 * table_nr, steps * 2, table);
status = sanei_genesys_write_ahb(dev, 0x10000000 + 0x4000 * table_nr, steps * 2, table);
if (status != SANE_STATUS_GOOD)
{
DBG (DBG_error,
......@@ -2927,7 +2808,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, addr, pixels*dev->segnb, buffer);
status = sanei_genesys_write_ahb(dev, addr, pixels*dev->segnb, buffer);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s; write to AHB failed (%s)\n", __func__, sane_strstatus(status));
......@@ -3876,7 +3757,7 @@ static Genesys_Command_Set gl124_cmd_set = {
sanei_genesys_bulk_write_register,
NULL,
gl124_bulk_read_data,
sanei_genesys_bulk_read_data,
gl124_update_hardware_sensors,
......
This diff is collapsed.
This diff is collapsed.
......@@ -55,74 +55,6 @@
/* Read and write RAM, registers and AFE */
/* ------------------------------------------------------------------------ */
/**
* Write bulk data (e.g. gamma or shading data) */
static SANE_Status
gl843_bulk_write_data (Genesys_Device * dev, uint8_t addr,
uint8_t * data, size_t len)
{
SANE_Status status;
size_t size;
uint8_t outdata[8];
DBGSTART;
DBG(DBG_io, "%s writing %lu bytes\n", __func__, (u_long) len);
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_REGISTER,
VALUE_SET_REGISTER, INDEX, 1, &addr);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while setting register: %s\n", __func__, sane_strstatus(status));
return status;
}
while (len)
{
if(len>65472)
size=65472;
else
size = len;
outdata[0] = BULK_OUT;
outdata[1] = BULK_RAM;
outdata[2] = 0x00;
outdata[3] = 0x00;
outdata[4] = (size & 0xff);
outdata[5] = ((size >> 8) & 0xff);
outdata[6] = ((size >> 16) & 0xff);
outdata[7] = ((size >> 24) & 0xff);
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
VALUE_BUFFER, INDEX, sizeof (outdata),
outdata);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while writing command: %s\n", __func__, sane_strstatus(status));
return status;
}
status = sanei_usb_write_bulk (dev->dn, data, &size);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while writing bulk data: %s\n", __func__,
sane_strstatus(status));
return status;
}
DBG(DBG_io2, "%s: wrote %lu bytes, %lu remaining\n", __func__, (u_long) size,
(u_long) (len - size));
len -= size;
data += size;
}
DBGCOMPLETED;
return status;
}
/* Set address for writing data */
static SANE_Status
gl843_set_buffer_address (Genesys_Device * dev, uint32_t addr)
......@@ -174,7 +106,7 @@ write_data (Genesys_Device * dev, uint32_t addr, uint32_t size,
}
/* write actual data */
status = gl843_bulk_write_data (dev, 0x28, data, size);
status = sanei_genesys_bulk_write_data(dev, 0x28, data, size);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed while writing bulk write data: %s\n", __func__,
......@@ -194,81 +126,6 @@ write_data (Genesys_Device * dev, uint32_t addr, uint32_t size,
return status;
}
static SANE_Status
gl843_bulk_read_data (Genesys_Device * dev, uint8_t addr,
uint8_t * data, size_t len)
{
SANE_Status status;
size_t size;
uint8_t outdata[8];
DBGSTART;
DBG(DBG_io, "%s: requesting %lu bytes from 0x%02x addr\n", __func__, (u_long) len, addr);
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_REGISTER,
VALUE_SET_REGISTER, 0, 1, &addr);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to set register address %s\n", __func__, sane_strstatus(status));
return status;
}
if (len == 0)
return SANE_STATUS_GOOD;
outdata[0] = BULK_IN;
outdata[1] = BULK_RAM;
outdata[2] = VALUE_BUFFER;
outdata[3] = 0;
outdata[4] = (len & 0xff);
outdata[5] = ((len >> 8) & 0xff);
outdata[6] = ((len >> 16) & 0xff);
outdata[7] = ((len >> 24) & 0xff);
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
VALUE_BUFFER, INDEX, sizeof (outdata), outdata);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while writing command: %s\n", __func__, sane_strstatus(status));
return status;
}
while (len)
{
if (len > 0xF000)
size = 0xF000;
else
size = len;
if (size >= 512)
{
size /= 512;
size *= 512;
}
DBG(DBG_io2, "%s: trying to read %lu bytes of data\n", __func__, (u_long) size);
status = sanei_usb_read_bulk (dev->dn, data, &size);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while reading bulk data: %s\n", __func__,
sane_strstatus(status));
return status;
}
DBG(DBG_io2, "%s read %lu bytes, %lu remaining\n", __func__, (u_long) size,
(u_long) (len - size));
len -= size;
data += size;
}
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
/****************************************************************************
Mid level functions
****************************************************************************/
......@@ -3008,7 +2865,7 @@ gl843_send_gamma_table (Genesys_Device * dev)
}
/* send data */
status = gl843_bulk_write_data (dev, 0x28, (uint8_t *) gamma, size * 2 * 3);
status = sanei_genesys_bulk_write_data(dev, 0x28, (uint8_t *) gamma, size * 2 * 3);
if (status != SANE_STATUS_GOOD)
{
free (gamma);
......@@ -4272,8 +4129,8 @@ static Genesys_Command_Set gl843_cmd_set = {
NULL,
sanei_genesys_bulk_write_register,
gl843_bulk_write_data,
gl843_bulk_read_data,
sanei_genesys_bulk_write_data,
sanei_genesys_bulk_read_data,
gl843_update_hardware_sensors,
......
......@@ -51,128 +51,6 @@
#include "genesys_gl846.h"
/****************************************************************************
Low level function
****************************************************************************/
/* ------------------------------------------------------------------------ */
/* Read and write RAM, registers and AFE */
/* ------------------------------------------------------------------------ */
/** @brief read scanned data
* Read in 0xeff0 maximum sized blocks. This read is done in 2
* parts if not multple of 512. First read is rounded to a multiple of 512 bytes, last read fetches the
* remainder. Read addr is always 0x10000000 with the memory layout setup.
* @param dev device to read data from
* @param addr address within ASIC memory space, unused but kept for API
* @param data pointer where to store the read data
* @param len size to read
*/
static SANE_Status
gl846_bulk_read_data (Genesys_Device * dev, uint8_t addr,
uint8_t * data, size_t len)
{
SANE_Status status;
size_t size, target, read, done;
uint8_t outdata[8];
uint8_t *buffer;
DBG(DBG_io, "%s: requesting %lu bytes at addr=0x%02x\n", __func__, (u_long) len, addr);
if (len == 0)
return SANE_STATUS_GOOD;
target = len;
buffer = data;
/* loop until computed data size is read */
while (target)
{
if (target > 0xeff0)
{
size = 0xeff0;
}
else
{
size = target;
}
/* hard coded 0x10000000 addr */
outdata[0] = 0;
outdata[1] = 0;
outdata[2] = 0;
outdata[3] = 0x10;
/* data size to transfer */
outdata[4] = (size & 0xff);
outdata[5] = ((size >> 8) & 0xff);
outdata[6] = ((size >> 16) & 0xff);
outdata[7] = ((size >> 24) & 0xff);
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
VALUE_BUFFER, 0x00, sizeof (outdata),
outdata);
if (status != SANE_STATUS_GOOD)
{
DBG (DBG_error, "%s failed while writing command: %s\n",
__func__, sane_strstatus (status));
return status;
}
/* blocks must be multiple of 512 but not last block */
read = size;
if (read >= 512)
{
read /= 512;
read *= 512;
}
DBG(DBG_io2, "%s: trying to read %lu bytes of data\n", __func__, (u_long) read);
status = sanei_usb_read_bulk (dev->dn, buffer, &read);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while reading bulk data: %s\n", __func__,
sane_strstatus(status));
return status;
}
done=read;
DBG(DBG_io2, "%s: %lu bytes of data read\n", __func__, (u_long) done);
/* read less than 512 bytes remainder */
if (read < size)
{
read = size - read;
DBG(DBG_io2, "%s: trying to read %lu bytes of data\n", __func__, (u_long) read);
status = sanei_usb_read_bulk (dev->dn, buffer+done, &read);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while reading bulk data: %s\n", __func__,
sane_strstatus(status));
return status;
}
done=read;
DBG(DBG_io2, "%s: %lu bytes of data read\n", __func__, (u_long) done);
}
DBG(DBG_io2, "%s: read %lu bytes, %lu remaining\n", __func__,
(u_long) size, (u_long) (target - size));
target -= size;
buffer += size;
}
if (DBG_LEVEL >= DBG_data && dev->binary!=NULL)
{
fwrite(data, len, 1, dev->binary);
}
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
/****************************************************************************
Mid level functions
****************************************************************************/
......@@ -599,7 +477,7 @@ gl846_send_slope_table (Genesys_Device * dev, int table_nr,
}
/* slope table addresses are fixed */
status = sanei_genesys_write_ahb(dev->dn, 0x10000000 + 0x4000 * table_nr, steps * 2, table);
status = sanei_genesys_write_ahb(dev, 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,
......@@ -1434,12 +1312,6 @@ gl846_init_scan_regs (Genesys_Device * dev,
bytes_per_line = (bytes_per_line * channels * depth) / 8;
requested_buffer_size = 8 * bytes_per_line;
/* we must use a round number of bytes_per_line */
/* XXX STEF XXX
if (requested_buffer_size > BULKIN_MAXSIZE)
requested_buffer_size =
(BULKIN_MAXSIZE / bytes_per_line) * bytes_per_line;
*/
read_buffer_size =
2 * requested_buffer_size +
......@@ -2517,7 +2389,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, addr, pixels, buffer);
status = sanei_genesys_write_ahb(dev, addr, pixels, buffer);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s; write to AHB failed (%s)\n", __func__, sane_strstatus(status));
......@@ -3564,7 +3436,7 @@ static Genesys_Command_Set gl846_cmd_set = {
sanei_genesys_bulk_write_register,
NULL,
gl846_bulk_read_data,
sanei_genesys_bulk_read_data,
gl846_update_hardware_sensors,
......
......@@ -47,127 +47,6 @@
#include "genesys_gl847.h"
/****************************************************************************
Low level function
****************************************************************************/
/* ------------------------------------------------------------------------ */
/* Read and write RAM, registers and AFE */
/* ------------------------------------------------------------------------ */
/** @brief read scanned data
* Read in 0xeff0 maximum sized blocks. This read is done in 2
* parts if not multple of 512. First read is rounded to a multiple of 512 bytes, last read fetches the
* remainder. Read addr is always 0x10000000 with the memory layout setup.
* @param dev device to read data from
* @param addr address within ASIC memory space, unused but kept for API
* @param data pointer where to store the read data
* @param len size to read
*/
static SANE_Status
gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr,
uint8_t * data, size_t len)
{
SANE_Status status;
size_t size, target, read, done;
uint8_t outdata[8];
uint8_t *buffer;
DBG(DBG_io, "%s: requesting %lu bytes at addr=0x%02x\n", __func__, (u_long) len, addr);
if (len == 0)
return SANE_STATUS_GOOD;
target = len;
buffer = data;
/* loop until computed data size is read */
while (target)
{
if (target > 0xeff0)
{
size = 0xeff0;
}
else
{
size = target;
}
/* hard coded 0x10000000 addr */
outdata[0] = 0;
outdata[1] = 0;
outdata[2] = 0;
outdata[3] = 0x10;
/* data size to transfer */
outdata[4] = (size & 0xff);
outdata[5] = ((size >> 8) & 0xff);
outdata[6] = ((size >> 16) & 0xff);
outdata[7] = ((size >> 24) & 0xff);
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
VALUE_BUFFER, 0x00, sizeof (outdata),
outdata);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while writing command: %s\n", __func__, sane_strstatus(status));
return status;
}
/* blocks must be multiple of 512 but not last block */
read = size;
if (read >= 512)
{
read /= 512;
read *= 512;
}
DBG(DBG_io2, "%s: trying to read %lu bytes of data\n", __func__, (u_long) read);
status = sanei_usb_read_bulk (dev->dn, buffer, &read);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while reading bulk data: %s\n", __func__,
sane_strstatus(status));
return status;
}
done=read;
DBG(DBG_io2, "%s: %lu bytes of data read\n", __func__, (u_long) done);
/* read less than 512 bytes remainder */
if (read < size)
{
read = size - read;
DBG(DBG_io2, "%s: trying to read %lu bytes of data\n", __func__, (u_long) read);
status = sanei_usb_read_bulk (dev->dn, buffer+done, &read);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s failed while reading bulk data: %s\n", __func__,
sane_strstatus(status));
return status;
}
done=read;
DBG(DBG_io2, "%s: %lu bytes of data read\n", __func__, (u_long) done);
}
DBG(DBG_io2, "%s: read %lu bytes, %lu remaining\n", __func__, (u_long) size,
(u_long) (target - size));
target -= size;
buffer += size;
}
if (DBG_LEVEL >= DBG_data && dev->binary!=NULL)
{
fwrite(data, len, 1, dev->binary);
}
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
/****************************************************************************
Mid level functions
****************************************************************************/
......@@ -621,8 +500,7 @@ gl847_send_slope_table (Genesys_Device * dev, int table_nr,
}
/* slope table addresses are fixed */
status =
sanei_genesys_write_ahb(dev->dn, 0x10000000 + 0x4000 * table_nr, steps * 2, table);
status = sanei_genesys_write_ahb(dev, 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,
......@@ -1450,12 +1328,6 @@ gl847_init_scan_regs (Genesys_Device * dev,
bytes_per_line = (bytes_per_line * channels * depth) / 8;
requested_buffer_size = 8 * bytes_per_line;
/* we must use a round number of bytes_per_line */
/* XXX STEF XXX
if (requested_buffer_size > BULKIN_MAXSIZE)
requested_buffer_size =
(BULKIN_MAXSIZE / bytes_per_line) * bytes_per_line;
*/
read_buffer_size =
2 * requested_buffer_size +
......@@ -2582,7 +2454,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, addr, pixels, buffer);
status = sanei_genesys_write_ahb(dev, addr, pixels, buffer);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s; write to AHB failed (%s)\n", __func__, sane_strstatus(status));
......@@ -3685,7 +3557,7 @@ static Genesys_Command_Set gl847_cmd_set = {
sanei_genesys_bulk_write_register,
NULL,
gl847_bulk_read_data,
sanei_genesys_bulk_read_data,
gl847_update_hardware_sensors,
......
This diff is collapsed.
......@@ -203,15 +203,6 @@
#define BULK_RAM 0x00
#define BULK_REGISTER 0x11
/* 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
/* AFE values */
......@@ -1003,12 +994,20 @@ sanei_genesys_bulk_write_register (Genesys_Device * dev,
extern SANE_Status sanei_genesys_write_0x8c (Genesys_Device * dev, uint8_t index, uint8_t val);
extern unsigned sanei_genesys_get_bulk_max_size(Genesys_Device * dev);
extern SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
size_t len);
extern SANE_Status sanei_genesys_bulk_write_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
size_t len);
extern SANE_Status sanei_genesys_get_status (Genesys_Device * dev, uint8_t * status);
extern void sanei_genesys_print_status (uint8_t val);
extern SANE_Status
sanei_genesys_write_ahb(SANE_Int dn, uint32_t addr, uint32_t size, uint8_t * data);
sanei_genesys_write_ahb(Genesys_Device* dev, uint32_t addr, uint32_t size, uint8_t * data);
extern void sanei_genesys_init_fe (Genesys_Device * dev);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment