Lines Matching defs:ttusb

87  *  since we're casting (struct ttusb*) <-> (struct dvb_demux*) around
90 struct ttusb {
141 static int ttusb_cmd(struct ttusb *ttusb, u8 *data, int len, int len_result)
146 if (mutex_lock_interruptible(&ttusb->semusb) < 0)
152 memcpy(data, ttusb->send_buf, len);
154 err = usb_bulk_msg(ttusb->dev, ttusb->bulk_out_pipe,
155 ttusb->send_buf, len, &actual_len, 1000);
167 err = usb_bulk_msg(ttusb->dev, ttusb->bulk_in_pipe,
168 ttusb->last_result, MAX_RCV, &actual_len, 1000);
176 actual_len = ttusb->last_result[3] + 4;
177 dprintk("< %*ph\n", actual_len, ttusb->last_result);
181 memcpy(ttusb->send_buf, ttusb->last_result, len_result);
184 mutex_unlock(&ttusb->semusb);
188 static int ttusb_i2c_msg(struct ttusb *ttusb,
193 u8 id = ++ttusb->c;
210 err = ttusb_cmd(ttusb, b, snd_len + 7, MAX_RCV);
235 struct ttusb *ttusb = i2c_get_adapdata(adapter);
239 if (mutex_lock_interruptible(&ttusb->semi2c) < 0)
262 err = ttusb_i2c_msg(ttusb, addr,
273 mutex_unlock(&ttusb->semi2c);
277 static int ttusb_boot_dsp(struct ttusb *ttusb)
283 err = request_firmware(&fw, "ttusb-budget/dspbootcode.bin",
284 &ttusb->dev->dev);
300 b[1] = ++ttusb->c;
302 err = ttusb_cmd(ttusb, b, 32, 0);
308 b[1] = ++ttusb->c;
312 err = ttusb_cmd(ttusb, b, 4, 0);
317 b[1] = ++ttusb->c;
321 err = ttusb_cmd(ttusb, b, 4, 0);
332 static int ttusb_set_channel(struct ttusb *ttusb, int chan_id, int filter_type,
337 u8 b[] = { 0xaa, ++ttusb->c, 0x22, 4, chan_id, filter_type,
341 err = ttusb_cmd(ttusb, b, sizeof(b), 0);
345 static int ttusb_del_channel(struct ttusb *ttusb, int channel_id)
349 u8 b[] = { 0xaa, ++ttusb->c, 0x23, 1, channel_id };
351 err = ttusb_cmd(ttusb, b, sizeof(b), 0);
356 static int ttusb_set_filter(struct ttusb *ttusb, int filter_id,
370 err = ttusb_cmd(ttusb, b, sizeof(b), 0);
374 static int ttusb_del_filter(struct ttusb *ttusb, int filter_id)
378 u8 b[] = { 0xaa, ++ttusb->c, 0x25, 1, filter_id };
380 err = ttusb_cmd(ttusb, b, sizeof(b), 0);
385 static int ttusb_init_controller(struct ttusb *ttusb)
387 u8 b0[] = { 0xaa, ++ttusb->c, 0x15, 1, 0 };
388 u8 b1[] = { 0xaa, ++ttusb->c, 0x15, 1, 1 };
389 u8 b2[] = { 0xaa, ++ttusb->c, 0x32, 1, 0 };
392 { 0xaa, ++ttusb->c, 0x31, 5, 0x10, 0x02, 0x01, 0x00, 0x1e };
394 u8 get_version[] = { 0xaa, ++ttusb->c, 0x17, 5, 0, 0, 0, 0, 0 };
396 { 0xaa, ++ttusb->c, 0x26, 28, 0, 0, 0, 0, 0 };
400 if ((err = ttusb_cmd(ttusb, b0, sizeof(b0), 0)))
404 if ((err = ttusb_cmd(ttusb, b1, sizeof(b1), 0)))
407 ttusb_boot_dsp(ttusb);
410 if ((err = ttusb_cmd(ttusb, b2, sizeof(b2), 0)))
413 if ((err = ttusb_cmd(ttusb, b3, sizeof(b3), 0)))
416 if ((err = ttusb_cmd(ttusb, get_version,
432 ttusb->revision = ((get_version[6] - '0') << 4) |
436 ttusb_cmd(ttusb, get_dsp_version,
450 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
451 u8 b[12] = { 0xaa, ++ttusb->c, 0x18 };
462 if ((err = ttusb_cmd(ttusb, b, 4 + b[3], 0))) {
470 static int ttusb_update_lnb(struct ttusb *ttusb)
472 u8 b[] = { 0xaa, ++ttusb->c, 0x16, 5, /*power: */ 1,
473 ttusb->voltage == SEC_VOLTAGE_18 ? 0 : 1,
474 ttusb->tone == SEC_TONE_ON ? 1 : 0, 1, 1
479 if ((err = ttusb_cmd(ttusb, b, sizeof(b), 0))) {
489 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
491 ttusb->voltage = voltage;
492 return ttusb_update_lnb(ttusb);
498 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
500 ttusb->tone = tone;
501 return ttusb_update_lnb(ttusb);
507 static void ttusb_set_led_freq(struct ttusb *ttusb, u8 freq)
509 u8 b[] = { 0xaa, ++ttusb->c, 0x19, 1, freq };
512 err = ttusb_cmd(ttusb, b, sizeof(b), 0);
531 static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
553 if ((cc != ttusb->cc) && (ttusb->cc != -1))
555 (cc - ttusb->cc) & 0x7FFF);
556 ttusb->cc = (cc + 1) & 0x7FFF;
568 ttusb_handle_sec_data(ttusb->channel + channel, data,
572 if ((!!(ttusb->muxpack[0] & 0x20)) ^
573 !!(ttusb->muxpack[1] & 1))
585 if (ttusb->channel[channel].active
586 && (pid == ttusb->channel[channel].pid))
587 ttusb_handle_ts_data(ttusb->channel +
592 dvb_dmx_swfilter_packets(&ttusb->dvb_demux, muxpack, 1);
600 static void ttusb_process_frame(struct ttusb *ttusb, u8 * data, int len)
609 switch (ttusb->mux_state) {
615 ++ttusb->mux_state;
617 ttusb->mux_state = 0;
618 if (ttusb->insync) {
620 ttusb->insync = 0;
625 ttusb->insync = 1;
627 ttusb->mux_npacks = *data++;
628 ++ttusb->mux_state;
629 ttusb->muxpack_ptr = 0;
631 ttusb->muxpack_len = 2;
638 (ttusb->muxpack_len -
639 ttusb->muxpack_ptr))
641 ttusb->muxpack_len -
642 ttusb->muxpack_ptr;
643 memcpy(ttusb->muxpack + ttusb->muxpack_ptr,
645 ttusb->muxpack_ptr += avail;
646 BUG_ON(ttusb->muxpack_ptr > 264);
650 if (ttusb->muxpack_ptr == 2) {
651 if (ttusb->muxpack[0] & 0x80) {
652 ttusb->muxpack_len =
653 ttusb->muxpack[1] + 2;
654 if (ttusb->
656 ttusb->
659 (ttusb->
661 !!(ttusb->
663 ttusb->
665 ttusb->muxpack_len += 4;
666 } else if (ttusb->muxpack[0] ==
668 ttusb->muxpack_len =
670 else if (ttusb->muxpack[0] == 0x00)
671 ttusb->muxpack_len =
672 ttusb->muxpack[1] + 2 +
676 ttusb->muxpack[0]);
677 ttusb->mux_state = 0;
685 if ((ttusb->muxpack_ptr >= 2) &&
686 (ttusb->muxpack_ptr ==
687 ttusb->muxpack_len)) {
688 ttusb_process_muxpack(ttusb,
689 ttusb->
691 ttusb->
693 ttusb->muxpack_ptr = 0;
695 ttusb->muxpack_len = 2;
701 if (!ttusb->mux_npacks--) {
702 ttusb->mux_state = 0;
717 struct ttusb *ttusb = urb->context;
722 if (!ttusb->iso_streaming)
742 ttusb_process_frame(ttusb, data, len);
748 static void ttusb_free_iso_urbs(struct ttusb *ttusb)
753 usb_free_urb(ttusb->iso_urb[i]);
754 kfree(ttusb->iso_buffer);
757 static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
761 ttusb->iso_buffer = kcalloc(FRAMES_PER_ISO_BUF * ISO_BUF_COUNT,
763 if (!ttusb->iso_buffer)
772 ttusb_free_iso_urbs(ttusb);
776 ttusb->iso_urb[i] = urb;
782 static void ttusb_stop_iso_xfer(struct ttusb *ttusb)
787 usb_kill_urb(ttusb->iso_urb[i]);
789 ttusb->iso_streaming = 0;
792 static int ttusb_start_iso_xfer(struct ttusb *ttusb)
796 if (ttusb->iso_streaming) {
801 ttusb->cc = -1;
802 ttusb->insync = 0;
803 ttusb->mux_state = 0;
807 struct urb *urb = ttusb->iso_urb[i];
809 urb->dev = ttusb->dev;
810 urb->context = ttusb;
812 urb->pipe = ttusb->isoc_in_pipe;
818 urb->transfer_buffer = ttusb->iso_buffer + buffer_offset;
829 if ((err = usb_submit_urb(ttusb->iso_urb[i], GFP_ATOMIC))) {
830 ttusb_stop_iso_xfer(ttusb);
837 ttusb->iso_streaming = 1;
860 struct ttusb *ttusb = (struct ttusb *) dvbdmxfeed->demux;
896 ttusb_set_channel(ttusb, dvbdmxfeed->index, feed_type, dvbdmxfeed->pid);
898 if (0 == ttusb->running_feed_count++)
899 ttusb_start_iso_xfer(ttusb);
906 struct ttusb *ttusb = (struct ttusb *) dvbdmxfeed->demux;
908 ttusb_del_channel(ttusb, dvbdmxfeed->index);
910 if (--ttusb->running_feed_count == 0)
911 ttusb_stop_iso_xfer(ttusb);
916 static int ttusb_setup_interfaces(struct ttusb *ttusb)
918 usb_set_interface(ttusb->dev, 1, 1);
920 ttusb->bulk_out_pipe = usb_sndbulkpipe(ttusb->dev, 1);
921 ttusb->bulk_in_pipe = usb_rcvbulkpipe(ttusb->dev, 1);
922 ttusb->isoc_in_pipe = usb_rcvisocpipe(ttusb->dev, 2);
932 struct ttusb *ttusb = file->private_data;
937 ttusb_i2c_msg(ttusb, 0x50, snd_buf, 2, stc_firmware + addr,
973 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
987 if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1) return -EIO;
1001 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1009 if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) return -EIO;
1018 if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {
1019 i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1);
1028 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1092 if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1)
1101 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1103 return request_firmware(fw, name, &ttusb->dev->dev);
1235 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1253 if (ttusb->revision == TTUSB_REV_2_2)
1258 if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1)
1279 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1293 if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1)
1307 struct ttusb* ttusb = fe->dvb->priv;
1321 if (i2c_transfer (&ttusb->i2c_adap, &msg, 1) != 1)
1335 static u8 read_pwm(struct ttusb* ttusb)
1342 if ((i2c_transfer(&ttusb->i2c_adap, msg, 2) != 2) || (pwm == 0xff))
1352 struct ttusb *ttusb = (struct ttusb *) fe->dvb->priv;
1391 if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {
1400 if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {
1518 static void frontend_init(struct ttusb* ttusb)
1520 switch(le16_to_cpu(ttusb->dev->descriptor.idProduct)) {
1523 ttusb->fe = dvb_attach(stv0299_attach, &alps_stv0299_config, &ttusb->i2c_adap);
1524 if (ttusb->fe != NULL) {
1525 ttusb->fe->ops.tuner_ops.set_params = philips_tsa5059_tuner_set_params;
1527 if(ttusb->revision == TTUSB_REV_2_2) { // ALPS BSBE1
1529 dvb_attach(lnbp21_attach, ttusb->fe, &ttusb->i2c_adap, 0, 0);
1531 ttusb->fe->ops.set_voltage = ttusb_set_voltage;
1537 ttusb->fe = dvb_attach(tda8083_attach, &ttusb_novas_grundig_29504_491_config, &ttusb->i2c_adap);
1538 if (ttusb->fe != NULL) {
1539 ttusb->fe->ops.tuner_ops.set_params = ttusb_novas_grundig_29504_491_tuner_set_params;
1540 ttusb->fe->ops.set_voltage = ttusb_set_voltage;
1546 ttusb->fe = dvb_attach(ves1820_attach, &alps_tdbe2_config, &ttusb->i2c_adap, read_pwm(ttusb));
1547 if (ttusb->fe != NULL) {
1548 ttusb->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
1552 ttusb->fe = dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &ttusb->i2c_adap);
1553 if (ttusb->fe != NULL) {
1554 ttusb->fe->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
1561 ttusb->fe = dvb_attach(cx22700_attach, &alps_tdmb7_config, &ttusb->i2c_adap);
1562 if (ttusb->fe != NULL) {
1563 ttusb->fe->ops.tuner_ops.set_params = alps_tdmb7_tuner_set_params;
1568 ttusb->fe = dvb_attach(tda10046_attach, &philips_tdm1316l_config, &ttusb->i2c_adap);
1569 if (ttusb->fe != NULL) {
1570 ttusb->fe->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1571 ttusb->fe->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1577 if (ttusb->fe == NULL) {
1579 le16_to_cpu(ttusb->dev->descriptor.idVendor),
1580 le16_to_cpu(ttusb->dev->descriptor.idProduct));
1582 if (dvb_register_frontend(&ttusb->adapter, ttusb->fe)) {
1584 dvb_frontend_detach(ttusb->fe);
1585 ttusb->fe = NULL;
1600 struct ttusb *ttusb;
1609 if (!(ttusb = kzalloc(sizeof(struct ttusb), GFP_KERNEL)))
1612 ttusb->dev = udev;
1613 ttusb->c = 0;
1614 ttusb->mux_state = 0;
1615 mutex_init(&ttusb->semi2c);
1617 mutex_lock(&ttusb->semi2c);
1619 mutex_init(&ttusb->semusb);
1621 ttusb_setup_interfaces(ttusb);
1623 result = ttusb_alloc_iso_urbs(ttusb);
1626 mutex_unlock(&ttusb->semi2c);
1627 kfree(ttusb);
1631 if (ttusb_init_controller(ttusb))
1634 mutex_unlock(&ttusb->semi2c);
1636 result = dvb_register_adapter(&ttusb->adapter,
1640 ttusb_free_iso_urbs(ttusb);
1641 kfree(ttusb);
1644 ttusb->adapter.priv = ttusb;
1647 memset(&ttusb->i2c_adap, 0, sizeof(struct i2c_adapter));
1648 strscpy(ttusb->i2c_adap.name, "TTUSB DEC", sizeof(ttusb->i2c_adap.name));
1650 i2c_set_adapdata(&ttusb->i2c_adap, ttusb);
1652 ttusb->i2c_adap.algo = &ttusb_dec_algo;
1653 ttusb->i2c_adap.algo_data = NULL;
1654 ttusb->i2c_adap.dev.parent = &udev->dev;
1656 result = i2c_add_adapter(&ttusb->i2c_adap);
1660 memset(&ttusb->dvb_demux, 0, sizeof(ttusb->dvb_demux));
1662 ttusb->dvb_demux.dmx.capabilities =
1664 ttusb->dvb_demux.priv = NULL;
1666 ttusb->dvb_demux.filternum = TTUSB_MAXFILTER;
1668 ttusb->dvb_demux.filternum = 32;
1670 ttusb->dvb_demux.feednum = TTUSB_MAXCHANNEL;
1671 ttusb->dvb_demux.start_feed = ttusb_start_feed;
1672 ttusb->dvb_demux.stop_feed = ttusb_stop_feed;
1673 ttusb->dvb_demux.write_to_decoder = NULL;
1675 result = dvb_dmx_init(&ttusb->dvb_demux);
1682 ttusb->dmxdev.filternum = ttusb->dvb_demux.filternum;
1683 ttusb->dmxdev.demux = &ttusb->dvb_demux.dmx;
1684 ttusb->dmxdev.capabilities = 0;
1686 result = dvb_dmxdev_init(&ttusb->dmxdev, &ttusb->adapter);
1694 if (dvb_net_init(&ttusb->adapter, &ttusb->dvbnet, &ttusb->dvb_demux.dmx)) {
1700 usb_set_intfdata(intf, (void *) ttusb);
1702 frontend_init(ttusb);
1707 dvb_dmxdev_release(&ttusb->dmxdev);
1709 dvb_dmx_release(&ttusb->dvb_demux);
1711 i2c_del_adapter(&ttusb->i2c_adap);
1713 dvb_unregister_adapter (&ttusb->adapter);
1714 ttusb_free_iso_urbs(ttusb);
1715 kfree(ttusb);
1721 struct ttusb *ttusb = usb_get_intfdata(intf);
1725 ttusb->disconnecting = 1;
1727 ttusb_stop_iso_xfer(ttusb);
1729 ttusb->dvb_demux.dmx.close(&ttusb->dvb_demux.dmx);
1730 dvb_net_release(&ttusb->dvbnet);
1731 dvb_dmxdev_release(&ttusb->dmxdev);
1732 dvb_dmx_release(&ttusb->dvb_demux);
1733 if (ttusb->fe != NULL) {
1734 dvb_unregister_frontend(ttusb->fe);
1735 dvb_frontend_detach(ttusb->fe);
1737 i2c_del_adapter(&ttusb->i2c_adap);
1738 dvb_unregister_adapter(&ttusb->adapter);
1740 ttusb_free_iso_urbs(ttusb);
1742 kfree(ttusb);
1757 .name = "ttusb",
1768 MODULE_FIRMWARE("ttusb-budget/dspbootcode.bin");