Commit da81a523 authored by Povilas Kanapickas's avatar Povilas Kanapickas

genesys: Reuse sanei_genesys_bulk_write_register() on GL841

parent 2b1f13fd
This diff is collapsed.
......@@ -1248,7 +1248,9 @@ sanei_genesys_bulk_write_register (Genesys_Device * dev,
SANE_Status status = SANE_STATUS_GOOD;
size_t i;
if (dev->model->asic_type == GENESYS_GL646) {
if (dev->model->asic_type == GENESYS_GL646 ||
dev->model->asic_type == GENESYS_GL841)
{
uint8_t outdata[8];
uint8_t buffer[GENESYS_MAX_REGS * 2];
size_t size;
......@@ -1261,35 +1263,54 @@ sanei_genesys_bulk_write_register (Genesys_Device * dev,
elems = i;
size = i * 2;
DBG(DBG_io, "%s (elems= %lu, size = %lu)\n", __func__, (u_long) elems, (u_long) size);
outdata[0] = BULK_OUT;
outdata[1] = BULK_REGISTER;
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;
}
/* copy registers and values in data buffer */
for (i = 0; i < size; i += 2) {
buffer[i] = reg[i / 2].address;
buffer[i + 1] = reg[i / 2].value;
}
status = sanei_usb_write_bulk (dev->dn, buffer, &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_io, "%s (elems= %lu, size = %lu)\n", __func__, (u_long) elems, (u_long) size);
if (dev->model->asic_type == GENESYS_GL646) {
outdata[0] = BULK_OUT;
outdata[1] = BULK_REGISTER;
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, buffer, &size);
if (status != SANE_STATUS_GOOD) {
DBG(DBG_error, "%s: failed while writing bulk data: %s\n", __func__, sane_strstatus(status));
return status;
}
} else {
size_t c;
for (i = 0; i < elems;) {
c = elems - i;
if (c > 32) /*32 is max on GL841. checked that.*/
c = 32;
status = sanei_usb_control_msg(dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
VALUE_SET_REGISTER, INDEX, c * 2, buffer + i * 2);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed while writing command: %s\n", __func__,
sane_strstatus(status));
return status;
}
i += c;
}
}
} else {
for (i = 0; i < elems && status == SANE_STATUS_GOOD; i++) {
......
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