/* I2C */ static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num) { struct dvb_usb_device *d = i2c_get_adapdata(adap); int i; if (num > 2) return -EINVAL; if (mutex_lock_interruptible(&d->i2c_mutex) < 0) return -EAGAIN; for (i = 0; i < num; i++) { /* write/read request */ if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf, msg[i].len, msg[i+1].buf, msg[i+1].len) < 0) break; i++; } else if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf, msg[i].len, NULL, 0) < 0) break; } mutex_unlock(&d->i2c_mutex); return i; }
/* * Command sequence in this init function is a replay * of the captured USB commands from the Windows proprietary driver. */ static int friio_initialize(struct dvb_usb_device *d) { int ret; int i; int retry = 0; u8 rbuf[2]; u8 wbuf[3]; deb_info("%s called.\n", __func__); /* use gl861_i2c_msg instead of gl861_i2c_xfer(), */ /* because the i2c device is not set up yet. */ wbuf[0] = 0x11; wbuf[1] = 0x02; ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); if (ret < 0) goto error; msleep(2); wbuf[0] = 0x11; wbuf[1] = 0x00; ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); if (ret < 0) goto error; msleep(1); /* following msgs should be in the FE's init code? */ /* cmd sequence to identify the device type? (friio black/white) */ wbuf[0] = 0x03; wbuf[1] = 0x80; /* can't use gl861_i2c_cmd, as the register-addr is 16bit(0x0100) */ ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0), GL861_REQ_I2C_DATA_CTRL_WRITE, GL861_WRITE, 0x1200, 0x0100, wbuf, 2, 2000); if (ret < 0) goto error; msleep(2); wbuf[0] = 0x00; wbuf[2] = 0x01; /* reg.0x0100 */ wbuf[1] = 0x00; ret = gl861_i2c_msg(d, 0x12 >> 1, wbuf, 3, rbuf, 2); /* my Friio White returns 0xffff. */ if (ret < 0 || rbuf[0] != 0xff || rbuf[1] != 0xff) goto error; msleep(2); wbuf[0] = 0x03; wbuf[1] = 0x80; ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0), GL861_REQ_I2C_DATA_CTRL_WRITE, GL861_WRITE, 0x9000, 0x0100, wbuf, 2, 2000); if (ret < 0) goto error; msleep(2); wbuf[0] = 0x00; wbuf[2] = 0x01; /* reg.0x0100 */ wbuf[1] = 0x00; ret = gl861_i2c_msg(d, 0x90 >> 1, wbuf, 3, rbuf, 2); /* my Friio White returns 0xffff again. */ if (ret < 0 || rbuf[0] != 0xff || rbuf[1] != 0xff) goto error; msleep(1); restart: /* ============ start DEMOD init cmds ================== */ /* read PLL status to clear the POR bit */ wbuf[0] = JDVBT90502_2ND_I2C_REG; wbuf[1] = (FRIIO_PLL_ADDR << 1) + 1; /* +1 for reading */ ret = gl861_i2c_msg(d, FRIIO_DEMOD_ADDR, wbuf, 2, NULL, 0); if (ret < 0) goto error; msleep(5); /* note: DEMODULATOR has 16bit register-address. */ wbuf[0] = 0x00; wbuf[2] = 0x01; /* reg addr: 0x0100 */ wbuf[1] = 0x00; /* val: not used */ ret = gl861_i2c_msg(d, FRIIO_DEMOD_ADDR, wbuf, 3, rbuf, 1); if (ret < 0) goto error; /* msleep(1); wbuf[0] = 0x80; wbuf[1] = 0x00; ret = gl861_i2c_msg(d, FRIIO_DEMOD_ADDR, wbuf, 2, rbuf, 1); if (ret < 0) goto error; */ if (rbuf[0] & 0x80) { /* still in PowerOnReset state? */ if (++retry > 3) { deb_info("failed to get the correct" " FE demod status:0x%02x\n", rbuf[0]); goto error; } msleep(100); goto restart; } /* TODO: check return value in rbuf */ /* =========== end DEMOD init cmds ===================== */ msleep(1); wbuf[0] = 0x30; wbuf[1] = 0x04; ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); if (ret < 0) goto error; msleep(2); /* following 2 cmds unnecessary? */ wbuf[0] = 0x00; wbuf[1] = 0x01; ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); if (ret < 0) goto error; wbuf[0] = 0x06; wbuf[1] = 0x0F; ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); if (ret < 0) goto error; /* some streaming ctl cmds (maybe) */ msleep(10); for (i = 0; i < cmdlen; i++) { ret = gl861_i2c_msg(d, 0x00, streaming_init_cmds[i], 2, NULL, 0); if (ret < 0) goto error; msleep(1); } msleep(20); /* change the LED color etc. */ ret = friio_streaming_ctrl(&d->adapter[0], 0); if (ret < 0) goto error; return 0; error: deb_info("%s:ret == %d\n", __func__, ret); return -EIO; }
static int friio_initialize(struct dvb_usb_device *d) { int ret; int i; int retry = 0; u8 *rbuf, *wbuf; deb_info("%s called.\n", __func__); wbuf = kmalloc(3, GFP_KERNEL); if (!wbuf) return -ENOMEM; rbuf = kmalloc(2, GFP_KERNEL); if (!rbuf) { kfree(wbuf); return -ENOMEM; } /* */ /* */ wbuf[0] = 0x11; wbuf[1] = 0x02; ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); if (ret < 0) goto error; msleep(2); wbuf[0] = 0x11; wbuf[1] = 0x00; ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); if (ret < 0) goto error; msleep(1); /* */ /* */ wbuf[0] = 0x03; wbuf[1] = 0x80; /* */ ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0), GL861_REQ_I2C_DATA_CTRL_WRITE, GL861_WRITE, 0x1200, 0x0100, wbuf, 2, 2000); if (ret < 0) goto error; msleep(2); wbuf[0] = 0x00; wbuf[2] = 0x01; /* */ wbuf[1] = 0x00; ret = gl861_i2c_msg(d, 0x12 >> 1, wbuf, 3, rbuf, 2); /* */ if (ret < 0 || rbuf[0] != 0xff || rbuf[1] != 0xff) goto error; msleep(2); wbuf[0] = 0x03; wbuf[1] = 0x80; ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0), GL861_REQ_I2C_DATA_CTRL_WRITE, GL861_WRITE, 0x9000, 0x0100, wbuf, 2, 2000); if (ret < 0) goto error; msleep(2); wbuf[0] = 0x00; wbuf[2] = 0x01; /* */ wbuf[1] = 0x00; ret = gl861_i2c_msg(d, 0x90 >> 1, wbuf, 3, rbuf, 2); /* */ if (ret < 0 || rbuf[0] != 0xff || rbuf[1] != 0xff) goto error; msleep(1); restart: /* */ /* */ wbuf[0] = JDVBT90502_2ND_I2C_REG; wbuf[1] = (FRIIO_PLL_ADDR << 1) + 1; /* */ ret = gl861_i2c_msg(d, FRIIO_DEMOD_ADDR, wbuf, 2, NULL, 0); if (ret < 0) goto error; msleep(5); /* */ wbuf[0] = 0x00; wbuf[2] = 0x01; /* */ wbuf[1] = 0x00; /* */ ret = gl861_i2c_msg(d, FRIIO_DEMOD_ADDR, wbuf, 3, rbuf, 1); if (ret < 0) goto error; /* */ if (rbuf[0] & 0x80) { /* */ if (++retry > 3) { deb_info("failed to get the correct" " FE demod status:0x%02x\n", rbuf[0]); goto error; } msleep(100); goto restart; } /* */ /* */ msleep(1); wbuf[0] = 0x30; wbuf[1] = 0x04; ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); if (ret < 0) goto error; msleep(2); /* */ wbuf[0] = 0x00; wbuf[1] = 0x01; ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); if (ret < 0) goto error; wbuf[0] = 0x06; wbuf[1] = 0x0F; ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); if (ret < 0) goto error; /* */ msleep(10); for (i = 0; i < cmdlen; i++) { ret = gl861_i2c_msg(d, 0x00, streaming_init_cmds[i], 2, NULL, 0); if (ret < 0) goto error; msleep(1); } msleep(20); /* */ ret = friio_streaming_ctrl(&d->adapter[0], 0); if (ret < 0) goto error; return 0; error: kfree(wbuf); kfree(rbuf); deb_info("%s:ret == %d\n", __func__, ret); return -EIO; }