Commit 80efacab authored by Povilas Kanapickas's avatar Povilas Kanapickas

genesys: Reuse sanei_genesys_bulk_write_data() on GL841

parent d62d4f0d
......@@ -112,72 +112,6 @@ gl841_bulk_write_register (Genesys_Device * dev,
return status;
}
/* Write bulk data (e.g. shading, gamma) */
static SANE_Status
gl841_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];
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 > BULKOUT_MAXSIZE)
size = BULKOUT_MAXSIZE;
else
size = len;
outdata[0] = BULK_OUT;
outdata[1] = BULK_RAM;
outdata[2] = VALUE_BUFFER & 0xff;
outdata[3] = (VALUE_BUFFER >> 8) & 0xff;
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;
}
DBG(DBG_io, "%s: completed\n", __func__);
return status;
}
/* for debugging transfer rate*/
/*
#include <sys/time.h>
......@@ -227,73 +161,6 @@ gl841_set_buffer_address_gamma (Genesys_Device * dev, uint32_t addr)
return status;
}
/* Write bulk data (e.g. gamma) */
GENESYS_STATIC SANE_Status
gl841_bulk_write_data_gamma (Genesys_Device * dev, uint8_t addr,
uint8_t * data, size_t len)
{
SANE_Status status;
size_t size;
uint8_t outdata[8];
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 > BULKOUT_MAXSIZE)
size = BULKOUT_MAXSIZE;
else
size = len;
outdata[0] = BULK_OUT;
outdata[1] = BULK_RAM;
outdata[2] = 0x00;/* 0x82 works, too */
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:gamma wrote %lu bytes, %lu remaining\n", __func__, (u_long) size,
(u_long) (len - size));
len -= size;
data += size;
}
DBG(DBG_io, "%s: completed\n", __func__);
return status;
}
/****************************************************************************
Mid level functions
****************************************************************************/
......@@ -595,7 +462,7 @@ sanei_gl841_asic_test (Genesys_Device * dev)
return status;
}
/* status = gl841_bulk_write_data (dev, 0x3c, data, size);
/* status = sanei_genesys_bulk_write_data(dev, 0x3c, data, size);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to bulk write data: %s\n", __func__, sane_strstatus(status));
......@@ -1046,9 +913,7 @@ gl841_send_slope_table (Genesys_Device * dev, int table_nr,
return status;
}
status =
gl841_bulk_write_data (dev, 0x3c, (uint8_t *) table,
steps * 2);
status = sanei_genesys_bulk_write_data(dev, 0x3c, (uint8_t *) table, steps * 2);
if (status != SANE_STATUS_GOOD)
{
/*#ifdef WORDS_BIGENDIAN*/
......@@ -1515,7 +1380,7 @@ uint8_t *table;
RIE(sanei_genesys_write_register(dev, 0x66, 0x00));
RIE(sanei_genesys_write_register(dev, 0x5b, 0x0c));
RIE(sanei_genesys_write_register(dev, 0x5c, 0x00));
RIE(gl841_bulk_write_data_gamma (dev, 0x28, table, 128));
RIE(sanei_genesys_bulk_write_data(dev, 0x28, table, 128));
RIE(sanei_genesys_write_register(dev, 0x5b, 0x00));
RIE(sanei_genesys_write_register(dev, 0x5c, 0x00));
}
......@@ -4298,7 +4163,7 @@ gl841_send_gamma_table (Genesys_Device * dev)
}
/* send data */
status = gl841_bulk_write_data_gamma (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);
......@@ -6036,7 +5901,7 @@ static Genesys_Command_Set gl841_cmd_set = {
NULL,
gl841_bulk_write_register,
gl841_bulk_write_data,
sanei_genesys_bulk_write_data,
sanei_genesys_bulk_read_data,
gl841_update_hardware_sensors,
......
......@@ -344,6 +344,7 @@ SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uin
SANE_Status sanei_genesys_bulk_write_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
size_t len)
{
// supported: GL841, GL843
SANE_Status status;
size_t size;
uint8_t outdata[8];
......@@ -366,10 +367,18 @@ SANE_Status sanei_genesys_bulk_write_data(Genesys_Device * dev, uint8_t addr, ui
else
size = len;
outdata[0] = BULK_OUT;
outdata[1] = BULK_RAM;
outdata[2] = 0x00;
outdata[3] = 0x00;
if (dev->model->asic_type == GENESYS_GL841) {
outdata[0] = BULK_OUT;
outdata[1] = BULK_RAM;
outdata[2] = VALUE_BUFFER & 0xff;
outdata[3] = (VALUE_BUFFER >> 8) & 0xff;
} else {
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);
......
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