Exemplo n.º 1
0
static int af9015_copy_firmware(struct dvb_usb_device *d)
{
	int ret;
	u8 fw_params[4];
	u8 val, i;
	struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params),
		fw_params };
	deb_info("%s:\n", __func__);

	fw_params[0] = af9015_config.firmware_size >> 8;
	fw_params[1] = af9015_config.firmware_size & 0xff;
	fw_params[2] = af9015_config.firmware_checksum >> 8;
	fw_params[3] = af9015_config.firmware_checksum & 0xff;

	/* wait 2nd demodulator ready */
	msleep(100);

	ret = af9015_read_reg_i2c(d,
		af9015_af9013_config[1].demod_address, 0x98be, &val);
	if (ret)
		goto error;
	else
		deb_info("%s: firmware status:%02x\n", __func__, val);

	if (val == 0x0c) /* fw is running, no need for download */
		goto exit;

	/* set I2C master clock to fast (to speed up firmware copy) */
	ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */
	if (ret)
		goto error;

	msleep(50);

	/* copy firmware */
	ret = af9015_ctrl_msg(d, &req);
	if (ret)
		err("firmware copy cmd failed:%d", ret);
	deb_info("%s: firmware copy done\n", __func__);

	/* set I2C master clock back to normal */
	ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */
	if (ret)
		goto error;

	/* request boot firmware */
	ret = af9015_write_reg_i2c(d, af9015_af9013_config[1].demod_address,
		0xe205, 1);
	deb_info("%s: firmware boot cmd status:%d\n", __func__, ret);
	if (ret)
		goto error;

	for (i = 0; i < 15; i++) {
		msleep(100);

		/* check firmware status */
		ret = af9015_read_reg_i2c(d,
			af9015_af9013_config[1].demod_address, 0x98be, &val);
		deb_info("%s: firmware status cmd status:%d fw status:%02x\n",
			__func__, ret, val);
		if (ret)
			goto error;

		if (val == 0x0c || val == 0x04) /* success or fail */
			break;
	}

	if (val == 0x04) {
		err("firmware did not run");
		ret = -1;
	} else if (val != 0x0c) {
		err("firmware boot timeout");
		ret = -1;
	}

error:
exit:
	return ret;
}
Exemplo n.º 2
0
static int af9015_copy_firmware(struct dvb_usb_device *d)
{
    struct af9015_state *state = d_to_priv(d);
    int ret;
    u8 fw_params[4];
    u8 val, i;
    struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params),
               fw_params
    };
    dev_dbg(&d->udev->dev, "%s:\n", __func__);

    fw_params[0] = state->firmware_size >> 8;
    fw_params[1] = state->firmware_size & 0xff;
    fw_params[2] = state->firmware_checksum >> 8;
    fw_params[3] = state->firmware_checksum & 0xff;

    /* wait 2nd demodulator ready */
    msleep(100);

    ret = af9015_read_reg_i2c(d, state->af9013_config[1].i2c_addr,
                              0x98be, &val);
    if (ret)
        goto error;
    else
        dev_dbg(&d->udev->dev, "%s: firmware status=%02x\n",
                __func__, val);

    if (val == 0x0c) /* fw is running, no need for download */
        goto exit;

    /* set I2C master clock to fast (to speed up firmware copy) */
    ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */
    if (ret)
        goto error;

    msleep(50);

    /* copy firmware */
    ret = af9015_ctrl_msg(d, &req);
    if (ret)
        dev_err(&d->udev->dev, "%s: firmware copy cmd failed=%d\n",
                KBUILD_MODNAME, ret);

    dev_dbg(&d->udev->dev, "%s: firmware copy done\n", __func__);

    /* set I2C master clock back to normal */
    ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */
    if (ret)
        goto error;

    /* request boot firmware */
    ret = af9015_write_reg_i2c(d, state->af9013_config[1].i2c_addr,
                               0xe205, 1);
    dev_dbg(&d->udev->dev, "%s: firmware boot cmd status=%d\n",
            __func__, ret);
    if (ret)
        goto error;

    for (i = 0; i < 15; i++) {
        msleep(100);

        /* check firmware status */
        ret = af9015_read_reg_i2c(d, state->af9013_config[1].i2c_addr,
                                  0x98be, &val);
        dev_dbg(&d->udev->dev, "%s: firmware status cmd status=%d " \
                "firmware status=%02x\n", __func__, ret, val);
        if (ret)
            goto error;

        if (val == 0x0c || val == 0x04) /* success or fail */
            break;
    }

    if (val == 0x04) {
        dev_err(&d->udev->dev, "%s: firmware did not run\n",
                KBUILD_MODNAME);
        ret = -ETIMEDOUT;
    } else if (val != 0x0c) {
        dev_err(&d->udev->dev, "%s: firmware boot timeout\n",
                KBUILD_MODNAME);
        ret = -ETIMEDOUT;
    }

error:
exit:
    return ret;
}