int cx25840_loadfw(struct i2c_client *client) { struct cx25840_state *state = to_state(i2c_get_clientdata(client)); const struct firmware *fw = NULL; u8 buffer[FWSEND]; const u8 *ptr; const char *fwname = get_fw_name(client); int size, retval; int max_buf_size = FWSEND; u32 gpio_oe = 0, gpio_da = 0; if (is_cx2388x(state)) { /* Preserve the GPIO OE and output bits */ gpio_oe = cx25840_read(client, 0x160); gpio_da = cx25840_read(client, 0x164); } /* cx231xx cannot accept more than 16 bytes at a time */ if (is_cx231xx(state) && max_buf_size > 16) max_buf_size = 16; if (request_firmware(&fw, fwname, FWDEV(client)) != 0) return -EINVAL; start_fw_load(client); buffer[0] = 0x08; buffer[1] = 0x02; size = fw->size; ptr = fw->data; while (size > 0) { int len = min(max_buf_size - 2, size); memcpy(buffer + 2, ptr, len); retval = fw_write(client, buffer, len + 2); if (retval < 0) { release_firmware(fw); return retval; } size -= len; ptr += len; } end_fw_load(client); size = fw->size; release_firmware(fw); if (is_cx2388x(state)) { /* Restore GPIO configuration after f/w load */ cx25840_write(client, 0x160, gpio_oe); cx25840_write(client, 0x164, gpio_da); } return check_fw_load(client, size); }
int cx25840_loadfw(struct i2c_client *client) { struct cx25840_state *state = to_state(i2c_get_clientdata(client)); const struct firmware *fw = NULL; u8 buffer[FWSEND]; const u8 *ptr; int size, retval; int MAX_BUF_SIZE = FWSEND; if (state->is_cx23885) firmware = FWFILE_CX23885; else if (state->is_cx231xx) firmware = FWFILE_CX231XX; if ((state->is_cx231xx) && MAX_BUF_SIZE > 16) { v4l_err(client, " Firmware download size changed to 16 bytes max length\n"); MAX_BUF_SIZE = 16; /* cx231xx cannot accept more than 16 bytes at a time */ } if (request_firmware(&fw, firmware, FWDEV(client)) != 0) { v4l_err(client, "unable to open firmware %s\n", firmware); return -EINVAL; } start_fw_load(client); buffer[0] = 0x08; buffer[1] = 0x02; size = fw->size; ptr = fw->data; while (size > 0) { int len = min(MAX_BUF_SIZE - 2, size); memcpy(buffer + 2, ptr, len); retval = fw_write(client, buffer, len + 2); if (retval < 0) { release_firmware(fw); return retval; } size -= len; ptr += len; } end_fw_load(client); size = fw->size; release_firmware(fw); return check_fw_load(client, size); }