16 static int nb_packet_buffer_size = 21;
19 "Set the dib0700 driver data buffer size. This parameter "
20 "corresponds to the number of TS packets. The actual size of "
21 "the data buffer corresponds to this parameter "
22 "multiplied by 188 (default: 21)");
34 err(
"could not acquire lock");
41 st->
buf, 16, USB_CTRL_GET_TIMEOUT);
42 if (hwversion !=
NULL)
43 *hwversion = (st->
buf[0] << 24) | (st->
buf[1] << 16) |
44 (st->
buf[2] << 8) | st->
buf[3];
46 *romversion = (st->
buf[4] << 24) | (st->
buf[5] << 16) |
47 (st->
buf[6] << 8) | st->
buf[7];
49 *ramversion = (st->
buf[8] << 24) | (st->
buf[9] << 16) |
50 (st->
buf[10] << 8) | st->
buf[11];
52 *fwtype = (st->
buf[12] << 24) | (st->
buf[13] << 16) |
53 (st->
buf[14] << 8) | st->
buf[15];
68 USB_CTRL_GET_TIMEOUT);
71 deb_data(
"ep 0 write error (status = %d, len: %d)\n",status,txlen);
73 return status < 0 ? status : 0;
83 err(
"tx buffer length is smaller than 2. Makes no sense.");
87 err(
"tx buffer length is larger than 4. Not supported.");
94 value = ((txlen - 2) << 8) | tx[1];
97 index |= (tx[2] << 8);
103 USB_CTRL_GET_TIMEOUT);
106 deb_info(
"ep 0 read error (status = %d)\n",status);
120 err(
"could not acquire lock");
126 st->
buf[2] = ((gpio_dir & 0x01) << 7) | ((gpio_val & 0x01) << 6);
128 ret = dib0700_ctrl_wr(d, st->
buf, 3);
141 err(
"could not acquire lock");
146 st->
buf[1] = (nb_ts_packets >> 8) & 0xff;
147 st->
buf[2] = nb_ts_packets & 0xff;
149 deb_info(
"set the USB xfer len to %i Ts packet\n", nb_ts_packets);
151 ret = dib0700_ctrl_wr(d, st->
buf, 3);
154 deb_info(
"this firmware does not allow to change the USB xfer len\n");
183 for (i = 0; i < num; i++) {
195 if (i == (num - 1)) {
205 i2c_dest = (msg[
i].
addr << 1);
206 value = ((en_start << 7) | (en_stop << 6) |
207 (msg[
i].
len & 0x3F)) << 8 | i2c_dest;
209 index = ((gen_mode << 6) & 0xC0) |
210 ((bus_mode << 4) & 0x30);
213 usb_rcvctrlpipe(d->
udev, 0),
216 value, index, msg[i].
buf,
218 USB_CTRL_GET_TIMEOUT);
220 deb_info(
"i2c read error (status = %d)\n", result);
230 err(
"could not acquire lock");
236 st->
buf[2] = (en_start << 7) | (en_stop << 6) |
239 st->
buf[3] = ((gen_mode << 6) & 0xC0) |
240 ((bus_mode << 4) & 0x30);
248 usb_sndctrlpipe(d->
udev, 0),
251 0, 0, st->
buf, msg[i].
len + 4,
252 USB_CTRL_GET_TIMEOUT);
255 deb_info(
"i2c write error (status = %d)\n", result);
267 static int dib0700_i2c_xfer_legacy(
struct i2c_adapter *adap,
277 err(
"could not acquire lock");
282 for (i = 0; i < num; i++) {
289 if (i+1 < num && (msg[i+1].
flags & I2C_M_RD)) {
295 msg[i+1].
buf, msg[i+1].
len);
297 deb_info(
"I2C read failed on address 0x%02x\n",
307 if (dib0700_ctrl_wr(d, st->
buf, msg[i].
len + 2) < 0)
325 return dib0700_i2c_xfer_new(adap, msg, num);
328 return dib0700_i2c_xfer_legacy(adap, msg, num);
338 .master_xfer = dib0700_i2c_xfer,
339 .functionality = dib0700_i2c_func,
356 deb_info(
"FW GET_VERSION length: %d\n",ret);
366 u8 pll_src,
u8 pll_range,
u8 clock_gpio3,
u16 pll_prediv,
367 u16 pll_loopdiv,
u16 free_div,
u16 dsuScaler)
373 err(
"could not acquire lock");
378 st->
buf[1] = (en_pll << 7) | (pll_src << 6) |
379 (pll_range << 5) | (clock_gpio3 << 4);
380 st->
buf[2] = (pll_prediv >> 8) & 0xff;
381 st->
buf[3] = pll_prediv & 0xff;
382 st->
buf[4] = (pll_loopdiv >> 8) & 0xff;
383 st->
buf[5] = pll_loopdiv & 0xff;
384 st->
buf[6] = (free_div >> 8) & 0xff;
385 st->
buf[7] = free_div & 0xff;
386 st->
buf[8] = (dsuScaler >> 8) & 0xff;
387 st->
buf[9] = dsuScaler & 0xff;
389 ret = dib0700_ctrl_wr(d, st->
buf, 10);
405 err(
"could not acquire lock");
410 divider = (
u16) (30000 / scl_kHz);
412 st->
buf[2] = (
u8) (divider >> 8);
413 st->
buf[3] = (
u8) (divider & 0xff);
414 divider = (
u16) (72000 / scl_kHz);
415 st->
buf[4] = (
u8) (divider >> 8);
416 st->
buf[5] = (
u8) (divider & 0xff);
417 divider = (
u16) (72000 / scl_kHz);
418 st->
buf[6] = (
u8) (divider >> 8);
419 st->
buf[7] = (
u8) (divider & 0xff);
421 deb_info(
"setting I2C speed: %04x %04x %04x (%d kHz).",
422 (st->
buf[2] << 8) | (st->
buf[3]), (st->
buf[4] << 8) |
423 st->
buf[5], (st->
buf[6] << 8) | st->
buf[7], scl_kHz);
425 ret = dib0700_ctrl_wr(d, st->
buf, 8);
435 case 72: dib0700_set_clock(d, 1, 0, 1, clock_out_gp3, 2, 24, 0, 0x4c);
break;
453 buf[4] = (address >> 24) & 0xff;
454 buf[5] = (address >> 16) & 0xff;
455 buf[6] = (address >> 8) & 0xff;
456 buf[7] = address & 0xff;
458 if ((ret =
usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x01),
buf,8,&actlen,1000)) < 0) {
459 deb_fw(
"jumpram to 0x%x failed\n",address);
463 deb_fw(
"jumpram to 0x%x failed\n",address);
475 int pos = 0,
ret, act_len,
i, adap_num;
484 deb_fwdata(
"writing to address 0x%08x (buffer: 0x%02x %02x)\n",
488 buf[1] = (hx.
addr >> 8) & 0xff;
489 buf[2] = hx.
addr & 0xff;
495 usb_sndbulkpipe(udev, 0x01),
502 err(
"firmware download failed at %d with %d",pos,ret);
509 if ((ret = dib0700_jumpram(udev, 0x70000000)) == 0) {
510 info(
"firmware started successfully.");
517 if (nb_packet_buffer_size < 1)
518 nb_packet_buffer_size = 1;
524 buf, 16, USB_CTRL_GET_TIMEOUT);
525 fw_version = (buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11];
532 if (fw_version >= 0x10201) {
533 dib0700_devices[
i].adapter[adap_num].fe[0].stream.u.bulk.buffersize = 188*nb_packet_buffer_size;
537 dib0700_devices[
i].adapter[adap_num].fe[0].stream.u.bulk.buffersize = ((188*nb_packet_buffer_size+188/2)/512)*512;
553 if ((onoff != 0) && (st->
fw_version >= 0x10201)) {
556 ret = dib0700_set_usb_xfer_len(adap->
dev,
559 deb_info(
"can not set the USB xfer len\n");
565 err(
"could not acquire lock");
572 st->
buf[1] = (onoff << 4) | 0x00;
577 st->
buf[2] = 0x01 << 4;
581 deb_info(
"modifying (%d) streaming state for %d\n", onoff, adap->
id);
584 if ((adap->
fe_adap[0].stream.props.endpoint != 2)
585 && (adap->
fe_adap[0].stream.props.endpoint != 3)) {
586 deb_info(
"the endpoint number (%i) is not correct, use the adapter id instead", adap->
fe_adap[0].stream.props.endpoint);
602 ret = dib0700_ctrl_wr(adap->
dev, st->
buf, 4);
615 err(
"could not acquire lock");
640 st->
buf[1] = new_proto;
642 ret = dib0700_ctrl_wr(d, st->
buf, 3);
644 err(
"ir protocol setup failed");
648 d->
props.rc.core.protocol = rc_type;
656 #define RC_REPEAT_DELAY_V1_20 10
672 #define RC_MSG_SIZE_V1_20 6
674 static void dib0700_rc_urb_completion(
struct urb *purb)
684 kfree(purb->transfer_buffer);
689 poll_reply = purb->transfer_buffer;
691 if (purb->status < 0) {
692 deb_info(
"discontinuing polling\n");
693 kfree(purb->transfer_buffer);
699 deb_info(
"malformed rc msg size=%d\n", purb->actual_length);
703 deb_data(
"IR ID = %02X state = %02X System = %02X %02X Cmd = %02X %02X (len %d)\n",
707 purb->actual_length);
709 switch (d->
props.rc.core.protocol) {
714 if ((poll_reply->
system == 0x00) && (poll_reply->
data == 0x00)
715 && (poll_reply->
not_data == 0xff)) {
721 deb_data(
"NEC extended protocol\n");
740 if ((poll_reply->
data + poll_reply->
not_data) != 0xff) {
742 err(
"key failed integrity check: %04x %02x %02x",
771 err(
"rc usb alloc urb failed");
776 if (purb->transfer_buffer ==
NULL) {
777 err(
"rc kzalloc failed");
783 usb_fill_bulk_urb(purb, d->
udev, usb_rcvbulkpipe(d->
udev, 1),
785 dib0700_rc_urb_completion, d);
789 err(
"rc submit urb failed");
790 kfree(purb->transfer_buffer);
805 &dev, adapter_nr) == 0) {
810 &fw_version, &fwtype);
812 deb_info(
"Firmware version: %x, %d, 0x%x, %d\n",
813 hwversion, romversion, fw_version, fwtype);
820 dev->
props.rc.core.bulk_mode =
true;
822 dev->
props.rc.core.bulk_mode =
false;
832 static struct usb_driver dib0700_driver = {
833 .name =
"dvb_usb_dib0700",
834 .probe = dib0700_probe,