Commit 0092293e authored by Antti Palosaari's avatar Antti Palosaari Committed by Mauro Carvalho Chehab

media: af9015: refactor copy firmware to slave demod

Small improvements.
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 2ffb2fa3
...@@ -720,79 +720,79 @@ static int af9015_copy_firmware(struct dvb_usb_device *d) ...@@ -720,79 +720,79 @@ static int af9015_copy_firmware(struct dvb_usb_device *d)
struct af9015_state *state = d_to_priv(d); struct af9015_state *state = d_to_priv(d);
struct usb_interface *intf = d->intf; struct usb_interface *intf = d->intf;
int ret; int ret;
u8 fw_params[4]; unsigned long timeout;
u8 val, i; u8 val, firmware_info[4];
struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params), struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, 4, firmware_info};
fw_params };
dev_dbg(&intf->dev, "\n"); dev_dbg(&intf->dev, "\n");
fw_params[0] = state->firmware_size >> 8; firmware_info[0] = (state->firmware_size >> 8) & 0xff;
fw_params[1] = state->firmware_size & 0xff; firmware_info[1] = (state->firmware_size >> 0) & 0xff;
fw_params[2] = state->firmware_checksum >> 8; firmware_info[2] = (state->firmware_checksum >> 8) & 0xff;
fw_params[3] = state->firmware_checksum & 0xff; firmware_info[3] = (state->firmware_checksum >> 0) & 0xff;
ret = af9015_read_reg_i2c(d, state->af9013_i2c_addr[1], /* Check whether firmware is already running */
0x98be, &val); ret = af9015_read_reg_i2c(d, state->af9013_i2c_addr[1], 0x98be, &val);
if (ret) if (ret)
goto error; goto err;
else
dev_dbg(&intf->dev, "firmware status %02x\n", val);
if (val == 0x0c) /* fw is running, no need for download */ dev_dbg(&intf->dev, "firmware status %02x\n", val);
goto exit;
/* set I2C master clock to fast (to speed up firmware copy) */ if (val == 0x0c)
ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */ return 0;
if (ret)
goto error;
msleep(50); /* Set i2c clock to 625kHz to speed up firmware copy */
ret = af9015_write_reg(d, 0xd416, 0x04);
if (ret)
goto err;
/* copy firmware */ /* Copy firmware from master demod to slave demod */
ret = af9015_ctrl_msg(d, &req); ret = af9015_ctrl_msg(d, &req);
if (ret) if (ret) {
dev_err(&intf->dev, "firmware copy cmd failed %d\n", ret); dev_err(&intf->dev, "firmware copy cmd failed %d\n", ret);
goto err;
}
dev_dbg(&intf->dev, "firmware copy done\n"); /* Set i2c clock to 125kHz */
ret = af9015_write_reg(d, 0xd416, 0x14);
/* set I2C master clock back to normal */
ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */
if (ret) if (ret)
goto error; goto err;
/* request boot firmware */ /* Boot firmware */
ret = af9015_write_reg_i2c(d, state->af9013_i2c_addr[1], ret = af9015_write_reg_i2c(d, state->af9013_i2c_addr[1], 0xe205, 0x01);
0xe205, 1);
dev_dbg(&intf->dev, "firmware boot cmd status %d\n", ret);
if (ret) if (ret)
goto error; goto err;
for (i = 0; i < 15; i++) { /* Poll firmware ready */
msleep(100); for (val = 0x00, timeout = jiffies + msecs_to_jiffies(1000);
!time_after(jiffies, timeout) && val != 0x0c && val != 0x04;) {
msleep(20);
/* check firmware status */ /* Check firmware status. 0c=OK, 04=fail */
ret = af9015_read_reg_i2c(d, state->af9013_i2c_addr[1], ret = af9015_read_reg_i2c(d, state->af9013_i2c_addr[1],
0x98be, &val); 0x98be, &val);
dev_dbg(&intf->dev, "firmware status cmd status %d, firmware status %02x\n",
ret, val);
if (ret) if (ret)
goto error; goto err;
if (val == 0x0c || val == 0x04) /* success or fail */ dev_dbg(&intf->dev, "firmware status %02x\n", val);
break;
} }
dev_dbg(&intf->dev, "firmware boot took %u ms\n",
jiffies_to_msecs(jiffies) - (jiffies_to_msecs(timeout) - 1000));
if (val == 0x04) { if (val == 0x04) {
ret = -ETIMEDOUT; ret = -ENODEV;
dev_err(&intf->dev, "firmware did not run\n"); dev_err(&intf->dev, "firmware did not run\n");
goto err;
} else if (val != 0x0c) { } else if (val != 0x0c) {
ret = -ETIMEDOUT; ret = -ETIMEDOUT;
dev_err(&intf->dev, "firmware boot timeout\n"); dev_err(&intf->dev, "firmware boot timeout\n");
goto err;
} }
error: return 0;
exit: err:
dev_dbg(&intf->dev, "failed %d\n", ret);
return ret; return ret;
} }
......
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