Path: blob/master/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
15112 views
/*1* TTUSB DVB driver2*3* Copyright (c) 2002 Holger Waechtler <[email protected]>4* Copyright (c) 2003 Felix Domke <[email protected]>5*6* This program is free software; you can redistribute it and/or7* modify it under the terms of the GNU General Public License as8* published by the Free Software Foundation; either version 2 of9* the License, or (at your option) any later version.10*/11#include <linux/init.h>12#include <linux/slab.h>13#include <linux/wait.h>14#include <linux/fs.h>15#include <linux/module.h>16#include <linux/usb.h>17#include <linux/delay.h>18#include <linux/time.h>19#include <linux/errno.h>20#include <linux/jiffies.h>21#include <linux/mutex.h>22#include <linux/firmware.h>2324#include "dvb_frontend.h"25#include "dmxdev.h"26#include "dvb_demux.h"27#include "dvb_net.h"28#include "ves1820.h"29#include "cx22700.h"30#include "tda1004x.h"31#include "stv0299.h"32#include "tda8083.h"33#include "stv0297.h"34#include "lnbp21.h"3536#include <linux/dvb/frontend.h>37#include <linux/dvb/dmx.h>38#include <linux/pci.h>3940/*41TTUSB_HWSECTIONS:42the DSP supports filtering in hardware, however, since the "muxstream"43is a bit braindead (no matching channel masks or no matching filter mask),44we won't support this - yet. it doesn't event support negative filters,45so the best way is maybe to keep TTUSB_HWSECTIONS undef'd and just46parse TS data. USB bandwidth will be a problem when having large47datastreams, especially for dvb-net, but hey, that's not my problem.4849TTUSB_DISEQC, TTUSB_TONE:50let the STC do the diseqc/tone stuff. this isn't supported at least with51my TTUSB, so let it undef'd unless you want to implement another52frontend. never tested.5354debug:55define it to > 3 for really hardcore debugging. you probably don't want56this unless the device doesn't load at all. > 2 for bandwidth statistics.57*/5859static int debug;60module_param(debug, int, 0644);61MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");6263DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);6465#define dprintk(x...) do { if (debug) printk(KERN_DEBUG x); } while (0)6667#define ISO_BUF_COUNT 468#define FRAMES_PER_ISO_BUF 469#define ISO_FRAME_SIZE 91270#define TTUSB_MAXCHANNEL 3271#ifdef TTUSB_HWSECTIONS72#define TTUSB_MAXFILTER 16 /* ??? */73#endif7475#define TTUSB_REV_2_2 0x2276#define TTUSB_BUDGET_NAME "ttusb_stc_fw"7778/**79* since we're casting (struct ttusb*) <-> (struct dvb_demux*) around80* the dvb_demux field must be the first in struct!!81*/82struct ttusb {83struct dvb_demux dvb_demux;84struct dmxdev dmxdev;85struct dvb_net dvbnet;8687/* and one for USB access. */88struct mutex semi2c;89struct mutex semusb;9091struct dvb_adapter adapter;92struct usb_device *dev;9394struct i2c_adapter i2c_adap;9596int disconnecting;97int iso_streaming;9899unsigned int bulk_out_pipe;100unsigned int bulk_in_pipe;101unsigned int isoc_in_pipe;102103void *iso_buffer;104dma_addr_t iso_dma_handle;105106struct urb *iso_urb[ISO_BUF_COUNT];107108int running_feed_count;109int last_channel;110int last_filter;111112u8 c; /* transaction counter, wraps around... */113fe_sec_tone_mode_t tone;114fe_sec_voltage_t voltage;115116int mux_state; // 0..2 - MuxSyncWord, 3 - nMuxPacks, 4 - muxpack117u8 mux_npacks;118u8 muxpack[256 + 8];119int muxpack_ptr, muxpack_len;120121int insync;122123int cc; /* MuxCounter - will increment on EVERY MUX PACKET */124/* (including stuffing. yes. really.) */125126u8 last_result[32];127128int revision;129130struct dvb_frontend* fe;131};132133/* ugly workaround ... don't know why it's necessary to read */134/* all result codes. */135136static int ttusb_cmd(struct ttusb *ttusb,137const u8 * data, int len, int needresult)138{139int actual_len;140int err;141int i;142143if (debug >= 3) {144printk(KERN_DEBUG ">");145for (i = 0; i < len; ++i)146printk(KERN_CONT " %02x", data[i]);147printk(KERN_CONT "\n");148}149150if (mutex_lock_interruptible(&ttusb->semusb) < 0)151return -EAGAIN;152153err = usb_bulk_msg(ttusb->dev, ttusb->bulk_out_pipe,154(u8 *) data, len, &actual_len, 1000);155if (err != 0) {156dprintk("%s: usb_bulk_msg(send) failed, err == %i!\n",157__func__, err);158mutex_unlock(&ttusb->semusb);159return err;160}161if (actual_len != len) {162dprintk("%s: only wrote %d of %d bytes\n", __func__,163actual_len, len);164mutex_unlock(&ttusb->semusb);165return -1;166}167168err = usb_bulk_msg(ttusb->dev, ttusb->bulk_in_pipe,169ttusb->last_result, 32, &actual_len, 1000);170171if (err != 0) {172printk("%s: failed, receive error %d\n", __func__,173err);174mutex_unlock(&ttusb->semusb);175return err;176}177178if (debug >= 3) {179actual_len = ttusb->last_result[3] + 4;180printk(KERN_DEBUG "<");181for (i = 0; i < actual_len; ++i)182printk(KERN_CONT " %02x", ttusb->last_result[i]);183printk(KERN_CONT "\n");184}185186if (!needresult)187mutex_unlock(&ttusb->semusb);188return 0;189}190191static int ttusb_result(struct ttusb *ttusb, u8 * data, int len)192{193memcpy(data, ttusb->last_result, len);194mutex_unlock(&ttusb->semusb);195return 0;196}197198static int ttusb_i2c_msg(struct ttusb *ttusb,199u8 addr, u8 * snd_buf, u8 snd_len, u8 * rcv_buf,200u8 rcv_len)201{202u8 b[0x28];203u8 id = ++ttusb->c;204int i, err;205206if (snd_len > 0x28 - 7 || rcv_len > 0x20 - 7)207return -EINVAL;208209b[0] = 0xaa;210b[1] = id;211b[2] = 0x31;212b[3] = snd_len + 3;213b[4] = addr << 1;214b[5] = snd_len;215b[6] = rcv_len;216217for (i = 0; i < snd_len; i++)218b[7 + i] = snd_buf[i];219220err = ttusb_cmd(ttusb, b, snd_len + 7, 1);221222if (err)223return -EREMOTEIO;224225err = ttusb_result(ttusb, b, 0x20);226227/* check if the i2c transaction was successful */228if ((snd_len != b[5]) || (rcv_len != b[6])) return -EREMOTEIO;229230if (rcv_len > 0) {231232if (err || b[0] != 0x55 || b[1] != id) {233dprintk234("%s: usb_bulk_msg(recv) failed, err == %i, id == %02x, b == ",235__func__, err, id);236return -EREMOTEIO;237}238239for (i = 0; i < rcv_len; i++)240rcv_buf[i] = b[7 + i];241}242243return rcv_len;244}245246static int master_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num)247{248struct ttusb *ttusb = i2c_get_adapdata(adapter);249int i = 0;250int inc;251252if (mutex_lock_interruptible(&ttusb->semi2c) < 0)253return -EAGAIN;254255while (i < num) {256u8 addr, snd_len, rcv_len, *snd_buf, *rcv_buf;257int err;258259if (num > i + 1 && (msg[i + 1].flags & I2C_M_RD)) {260addr = msg[i].addr;261snd_buf = msg[i].buf;262snd_len = msg[i].len;263rcv_buf = msg[i + 1].buf;264rcv_len = msg[i + 1].len;265inc = 2;266} else {267addr = msg[i].addr;268snd_buf = msg[i].buf;269snd_len = msg[i].len;270rcv_buf = NULL;271rcv_len = 0;272inc = 1;273}274275err = ttusb_i2c_msg(ttusb, addr,276snd_buf, snd_len, rcv_buf, rcv_len);277278if (err < rcv_len) {279dprintk("%s: i == %i\n", __func__, i);280break;281}282283i += inc;284}285286mutex_unlock(&ttusb->semi2c);287return i;288}289290static int ttusb_boot_dsp(struct ttusb *ttusb)291{292const struct firmware *fw;293int i, err;294u8 b[40];295296err = request_firmware(&fw, "ttusb-budget/dspbootcode.bin",297&ttusb->dev->dev);298if (err) {299printk(KERN_ERR "ttusb-budget: failed to request firmware\n");300return err;301}302303/* BootBlock */304b[0] = 0xaa;305b[2] = 0x13;306b[3] = 28;307308/* upload dsp code in 32 byte steps (36 didn't work for me ...) */309/* 32 is max packet size, no messages should be splitted. */310for (i = 0; i < fw->size; i += 28) {311memcpy(&b[4], &fw->data[i], 28);312313b[1] = ++ttusb->c;314315err = ttusb_cmd(ttusb, b, 32, 0);316if (err)317goto done;318}319320/* last block ... */321b[1] = ++ttusb->c;322b[2] = 0x13;323b[3] = 0;324325err = ttusb_cmd(ttusb, b, 4, 0);326if (err)327goto done;328329/* BootEnd */330b[1] = ++ttusb->c;331b[2] = 0x14;332b[3] = 0;333334err = ttusb_cmd(ttusb, b, 4, 0);335336done:337release_firmware(fw);338if (err) {339dprintk("%s: usb_bulk_msg() failed, return value %i!\n",340__func__, err);341}342343return err;344}345346static int ttusb_set_channel(struct ttusb *ttusb, int chan_id, int filter_type,347int pid)348{349int err;350/* SetChannel */351u8 b[] = { 0xaa, ++ttusb->c, 0x22, 4, chan_id, filter_type,352(pid >> 8) & 0xff, pid & 0xff353};354355err = ttusb_cmd(ttusb, b, sizeof(b), 0);356return err;357}358359static int ttusb_del_channel(struct ttusb *ttusb, int channel_id)360{361int err;362/* DelChannel */363u8 b[] = { 0xaa, ++ttusb->c, 0x23, 1, channel_id };364365err = ttusb_cmd(ttusb, b, sizeof(b), 0);366return err;367}368369#ifdef TTUSB_HWSECTIONS370static int ttusb_set_filter(struct ttusb *ttusb, int filter_id,371int associated_chan, u8 filter[8], u8 mask[8])372{373int err;374/* SetFilter */375u8 b[] = { 0xaa, 0, 0x24, 0x1a, filter_id, associated_chan,376filter[0], filter[1], filter[2], filter[3],377filter[4], filter[5], filter[6], filter[7],378filter[8], filter[9], filter[10], filter[11],379mask[0], mask[1], mask[2], mask[3],380mask[4], mask[5], mask[6], mask[7],381mask[8], mask[9], mask[10], mask[11]382};383384err = ttusb_cmd(ttusb, b, sizeof(b), 0);385return err;386}387388static int ttusb_del_filter(struct ttusb *ttusb, int filter_id)389{390int err;391/* DelFilter */392u8 b[] = { 0xaa, ++ttusb->c, 0x25, 1, filter_id };393394err = ttusb_cmd(ttusb, b, sizeof(b), 0);395return err;396}397#endif398399static int ttusb_init_controller(struct ttusb *ttusb)400{401u8 b0[] = { 0xaa, ++ttusb->c, 0x15, 1, 0 };402u8 b1[] = { 0xaa, ++ttusb->c, 0x15, 1, 1 };403u8 b2[] = { 0xaa, ++ttusb->c, 0x32, 1, 0 };404/* i2c write read: 5 bytes, addr 0x10, 0x02 bytes write, 1 bytes read. */405u8 b3[] =406{ 0xaa, ++ttusb->c, 0x31, 5, 0x10, 0x02, 0x01, 0x00, 0x1e };407u8 b4[] =408{ 0x55, ttusb->c, 0x31, 4, 0x10, 0x02, 0x01, 0x00, 0x1e };409410u8 get_version[] = { 0xaa, ++ttusb->c, 0x17, 5, 0, 0, 0, 0, 0 };411u8 get_dsp_version[0x20] =412{ 0xaa, ++ttusb->c, 0x26, 28, 0, 0, 0, 0, 0 };413int err;414415/* reset board */416if ((err = ttusb_cmd(ttusb, b0, sizeof(b0), 0)))417return err;418419/* reset board (again?) */420if ((err = ttusb_cmd(ttusb, b1, sizeof(b1), 0)))421return err;422423ttusb_boot_dsp(ttusb);424425/* set i2c bit rate */426if ((err = ttusb_cmd(ttusb, b2, sizeof(b2), 0)))427return err;428429if ((err = ttusb_cmd(ttusb, b3, sizeof(b3), 1)))430return err;431432err = ttusb_result(ttusb, b4, sizeof(b4));433434if ((err = ttusb_cmd(ttusb, get_version, sizeof(get_version), 1)))435return err;436437if ((err = ttusb_result(ttusb, get_version, sizeof(get_version))))438return err;439440dprintk("%s: stc-version: %c%c%c%c%c\n", __func__,441get_version[4], get_version[5], get_version[6],442get_version[7], get_version[8]);443444if (memcmp(get_version + 4, "V 0.0", 5) &&445memcmp(get_version + 4, "V 1.1", 5) &&446memcmp(get_version + 4, "V 2.1", 5) &&447memcmp(get_version + 4, "V 2.2", 5)) {448printk449("%s: unknown STC version %c%c%c%c%c, please report!\n",450__func__, get_version[4], get_version[5],451get_version[6], get_version[7], get_version[8]);452}453454ttusb->revision = ((get_version[6] - '0') << 4) |455(get_version[8] - '0');456457err =458ttusb_cmd(ttusb, get_dsp_version, sizeof(get_dsp_version), 1);459if (err)460return err;461462err =463ttusb_result(ttusb, get_dsp_version, sizeof(get_dsp_version));464if (err)465return err;466printk("%s: dsp-version: %c%c%c\n", __func__,467get_dsp_version[4], get_dsp_version[5], get_dsp_version[6]);468return 0;469}470471#ifdef TTUSB_DISEQC472static int ttusb_send_diseqc(struct dvb_frontend* fe,473const struct dvb_diseqc_master_cmd *cmd)474{475struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;476u8 b[12] = { 0xaa, ++ttusb->c, 0x18 };477478int err;479480b[3] = 4 + 2 + cmd->msg_len;481b[4] = 0xFF; /* send diseqc master, not burst */482b[5] = cmd->msg_len;483484memcpy(b + 5, cmd->msg, cmd->msg_len);485486/* Diseqc */487if ((err = ttusb_cmd(ttusb, b, 4 + b[3], 0))) {488dprintk("%s: usb_bulk_msg() failed, return value %i!\n",489__func__, err);490}491492return err;493}494#endif495496static int ttusb_update_lnb(struct ttusb *ttusb)497{498u8 b[] = { 0xaa, ++ttusb->c, 0x16, 5, /*power: */ 1,499ttusb->voltage == SEC_VOLTAGE_18 ? 0 : 1,500ttusb->tone == SEC_TONE_ON ? 1 : 0, 1, 1501};502int err;503504/* SetLNB */505if ((err = ttusb_cmd(ttusb, b, sizeof(b), 0))) {506dprintk("%s: usb_bulk_msg() failed, return value %i!\n",507__func__, err);508}509510return err;511}512513static int ttusb_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)514{515struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;516517ttusb->voltage = voltage;518return ttusb_update_lnb(ttusb);519}520521#ifdef TTUSB_TONE522static int ttusb_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)523{524struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;525526ttusb->tone = tone;527return ttusb_update_lnb(ttusb);528}529#endif530531532#if 0533static void ttusb_set_led_freq(struct ttusb *ttusb, u8 freq)534{535u8 b[] = { 0xaa, ++ttusb->c, 0x19, 1, freq };536int err, actual_len;537538err = ttusb_cmd(ttusb, b, sizeof(b), 0);539if (err) {540dprintk("%s: usb_bulk_msg() failed, return value %i!\n",541__func__, err);542}543}544#endif545546/*****************************************************************************/547548#ifdef TTUSB_HWSECTIONS549static void ttusb_handle_ts_data(struct ttusb_channel *channel,550const u8 * data, int len);551static void ttusb_handle_sec_data(struct ttusb_channel *channel,552const u8 * data, int len);553#endif554555static int numpkt, numts, numstuff, numsec, numinvalid;556static unsigned long lastj;557558static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,559int len)560{561u16 csum = 0, cc;562int i;563for (i = 0; i < len; i += 2)564csum ^= le16_to_cpup((__le16 *) (muxpack + i));565if (csum) {566printk("%s: muxpack with incorrect checksum, ignoring\n",567__func__);568numinvalid++;569return;570}571572cc = (muxpack[len - 4] << 8) | muxpack[len - 3];573cc &= 0x7FFF;574if ((cc != ttusb->cc) && (ttusb->cc != -1))575printk("%s: cc discontinuity (%d frames missing)\n",576__func__, (cc - ttusb->cc) & 0x7FFF);577ttusb->cc = (cc + 1) & 0x7FFF;578if (muxpack[0] & 0x80) {579#ifdef TTUSB_HWSECTIONS580/* section data */581int pusi = muxpack[0] & 0x40;582int channel = muxpack[0] & 0x1F;583int payload = muxpack[1];584const u8 *data = muxpack + 2;585/* check offset flag */586if (muxpack[0] & 0x20)587data++;588589ttusb_handle_sec_data(ttusb->channel + channel, data,590payload);591data += payload;592593if ((!!(ttusb->muxpack[0] & 0x20)) ^594!!(ttusb->muxpack[1] & 1))595data++;596#warning TODO: pusi597printk("cc: %04x\n", (data[0] << 8) | data[1]);598#endif599numsec++;600} else if (muxpack[0] == 0x47) {601#ifdef TTUSB_HWSECTIONS602/* we have TS data here! */603int pid = ((muxpack[1] & 0x0F) << 8) | muxpack[2];604int channel;605for (channel = 0; channel < TTUSB_MAXCHANNEL; ++channel)606if (ttusb->channel[channel].active607&& (pid == ttusb->channel[channel].pid))608ttusb_handle_ts_data(ttusb->channel +609channel, muxpack,610188);611#endif612numts++;613dvb_dmx_swfilter_packets(&ttusb->dvb_demux, muxpack, 1);614} else if (muxpack[0] != 0) {615numinvalid++;616printk("illegal muxpack type %02x\n", muxpack[0]);617} else618numstuff++;619}620621static void ttusb_process_frame(struct ttusb *ttusb, u8 * data, int len)622{623int maxwork = 1024;624while (len) {625if (!(maxwork--)) {626printk("%s: too much work\n", __func__);627break;628}629630switch (ttusb->mux_state) {631case 0:632case 1:633case 2:634len--;635if (*data++ == 0xAA)636++ttusb->mux_state;637else {638ttusb->mux_state = 0;639if (ttusb->insync) {640dprintk("%s: %02x\n",641__func__, data[-1]);642printk(KERN_INFO "%s: lost sync.\n",643__func__);644ttusb->insync = 0;645}646}647break;648case 3:649ttusb->insync = 1;650len--;651ttusb->mux_npacks = *data++;652++ttusb->mux_state;653ttusb->muxpack_ptr = 0;654/* maximum bytes, until we know the length */655ttusb->muxpack_len = 2;656break;657case 4:658{659int avail;660avail = len;661if (avail >662(ttusb->muxpack_len -663ttusb->muxpack_ptr))664avail =665ttusb->muxpack_len -666ttusb->muxpack_ptr;667memcpy(ttusb->muxpack + ttusb->muxpack_ptr,668data, avail);669ttusb->muxpack_ptr += avail;670BUG_ON(ttusb->muxpack_ptr > 264);671data += avail;672len -= avail;673/* determine length */674if (ttusb->muxpack_ptr == 2) {675if (ttusb->muxpack[0] & 0x80) {676ttusb->muxpack_len =677ttusb->muxpack[1] + 2;678if (ttusb->679muxpack[0] & 0x20)680ttusb->681muxpack_len++;682if ((!!683(ttusb->684muxpack[0] & 0x20)) ^685!!(ttusb->686muxpack[1] & 1))687ttusb->688muxpack_len++;689ttusb->muxpack_len += 4;690} else if (ttusb->muxpack[0] ==6910x47)692ttusb->muxpack_len =693188 + 4;694else if (ttusb->muxpack[0] == 0x00)695ttusb->muxpack_len =696ttusb->muxpack[1] + 2 +6974;698else {699dprintk700("%s: invalid state: first byte is %x\n",701__func__,702ttusb->muxpack[0]);703ttusb->mux_state = 0;704}705}706707/**708* if length is valid and we reached the end:709* goto next muxpack710*/711if ((ttusb->muxpack_ptr >= 2) &&712(ttusb->muxpack_ptr ==713ttusb->muxpack_len)) {714ttusb_process_muxpack(ttusb,715ttusb->716muxpack,717ttusb->718muxpack_ptr);719ttusb->muxpack_ptr = 0;720/* maximum bytes, until we know the length */721ttusb->muxpack_len = 2;722723/**724* no muxpacks left?725* return to search-sync state726*/727if (!ttusb->mux_npacks--) {728ttusb->mux_state = 0;729break;730}731}732break;733}734default:735BUG();736break;737}738}739}740741static void ttusb_iso_irq(struct urb *urb)742{743struct ttusb *ttusb = urb->context;744struct usb_iso_packet_descriptor *d;745u8 *data;746int len, i;747748if (!ttusb->iso_streaming)749return;750751#if 0752printk("%s: status %d, errcount == %d, length == %i\n",753__func__,754urb->status, urb->error_count, urb->actual_length);755#endif756757if (!urb->status) {758for (i = 0; i < urb->number_of_packets; ++i) {759numpkt++;760if (time_after_eq(jiffies, lastj + HZ)) {761dprintk("frames/s: %lu (ts: %d, stuff %d, "762"sec: %d, invalid: %d, all: %d)\n",763numpkt * HZ / (jiffies - lastj),764numts, numstuff, numsec, numinvalid,765numts + numstuff + numsec + numinvalid);766numts = numstuff = numsec = numinvalid = 0;767lastj = jiffies;768numpkt = 0;769}770d = &urb->iso_frame_desc[i];771data = urb->transfer_buffer + d->offset;772len = d->actual_length;773d->actual_length = 0;774d->status = 0;775ttusb_process_frame(ttusb, data, len);776}777}778usb_submit_urb(urb, GFP_ATOMIC);779}780781static void ttusb_free_iso_urbs(struct ttusb *ttusb)782{783int i;784785for (i = 0; i < ISO_BUF_COUNT; i++)786if (ttusb->iso_urb[i])787usb_free_urb(ttusb->iso_urb[i]);788789pci_free_consistent(NULL,790ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF *791ISO_BUF_COUNT, ttusb->iso_buffer,792ttusb->iso_dma_handle);793}794795static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)796{797int i;798799ttusb->iso_buffer = pci_alloc_consistent(NULL,800ISO_FRAME_SIZE *801FRAMES_PER_ISO_BUF *802ISO_BUF_COUNT,803&ttusb->iso_dma_handle);804805if (!ttusb->iso_buffer) {806dprintk("%s: pci_alloc_consistent - not enough memory\n",807__func__);808return -ENOMEM;809}810811memset(ttusb->iso_buffer, 0,812ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT);813814for (i = 0; i < ISO_BUF_COUNT; i++) {815struct urb *urb;816817if (!818(urb =819usb_alloc_urb(FRAMES_PER_ISO_BUF, GFP_ATOMIC))) {820ttusb_free_iso_urbs(ttusb);821return -ENOMEM;822}823824ttusb->iso_urb[i] = urb;825}826827return 0;828}829830static void ttusb_stop_iso_xfer(struct ttusb *ttusb)831{832int i;833834for (i = 0; i < ISO_BUF_COUNT; i++)835usb_kill_urb(ttusb->iso_urb[i]);836837ttusb->iso_streaming = 0;838}839840static int ttusb_start_iso_xfer(struct ttusb *ttusb)841{842int i, j, err, buffer_offset = 0;843844if (ttusb->iso_streaming) {845printk("%s: iso xfer already running!\n", __func__);846return 0;847}848849ttusb->cc = -1;850ttusb->insync = 0;851ttusb->mux_state = 0;852853for (i = 0; i < ISO_BUF_COUNT; i++) {854int frame_offset = 0;855struct urb *urb = ttusb->iso_urb[i];856857urb->dev = ttusb->dev;858urb->context = ttusb;859urb->complete = ttusb_iso_irq;860urb->pipe = ttusb->isoc_in_pipe;861urb->transfer_flags = URB_ISO_ASAP;862urb->interval = 1;863urb->number_of_packets = FRAMES_PER_ISO_BUF;864urb->transfer_buffer_length =865ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF;866urb->transfer_buffer = ttusb->iso_buffer + buffer_offset;867buffer_offset += ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF;868869for (j = 0; j < FRAMES_PER_ISO_BUF; j++) {870urb->iso_frame_desc[j].offset = frame_offset;871urb->iso_frame_desc[j].length = ISO_FRAME_SIZE;872frame_offset += ISO_FRAME_SIZE;873}874}875876for (i = 0; i < ISO_BUF_COUNT; i++) {877if ((err = usb_submit_urb(ttusb->iso_urb[i], GFP_ATOMIC))) {878ttusb_stop_iso_xfer(ttusb);879printk880("%s: failed urb submission (%i: err = %i)!\n",881__func__, i, err);882return err;883}884}885886ttusb->iso_streaming = 1;887888return 0;889}890891#ifdef TTUSB_HWSECTIONS892static void ttusb_handle_ts_data(struct dvb_demux_feed *dvbdmxfeed, const u8 * data,893int len)894{895dvbdmxfeed->cb.ts(data, len, 0, 0, &dvbdmxfeed->feed.ts, 0);896}897898static void ttusb_handle_sec_data(struct dvb_demux_feed *dvbdmxfeed, const u8 * data,899int len)900{901// struct dvb_demux_feed *dvbdmxfeed = channel->dvbdmxfeed;902#error TODO: handle ugly stuff903// dvbdmxfeed->cb.sec(data, len, 0, 0, &dvbdmxfeed->feed.sec, 0);904}905#endif906907static int ttusb_start_feed(struct dvb_demux_feed *dvbdmxfeed)908{909struct ttusb *ttusb = (struct ttusb *) dvbdmxfeed->demux;910int feed_type = 1;911912dprintk("ttusb_start_feed\n");913914switch (dvbdmxfeed->type) {915case DMX_TYPE_TS:916break;917case DMX_TYPE_SEC:918break;919default:920return -EINVAL;921}922923if (dvbdmxfeed->type == DMX_TYPE_TS) {924switch (dvbdmxfeed->pes_type) {925case DMX_TS_PES_VIDEO:926case DMX_TS_PES_AUDIO:927case DMX_TS_PES_TELETEXT:928case DMX_TS_PES_PCR:929case DMX_TS_PES_OTHER:930break;931default:932return -EINVAL;933}934}935936#ifdef TTUSB_HWSECTIONS937#error TODO: allocate filters938if (dvbdmxfeed->type == DMX_TYPE_TS) {939feed_type = 1;940} else if (dvbdmxfeed->type == DMX_TYPE_SEC) {941feed_type = 2;942}943#endif944945ttusb_set_channel(ttusb, dvbdmxfeed->index, feed_type, dvbdmxfeed->pid);946947if (0 == ttusb->running_feed_count++)948ttusb_start_iso_xfer(ttusb);949950return 0;951}952953static int ttusb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)954{955struct ttusb *ttusb = (struct ttusb *) dvbdmxfeed->demux;956957ttusb_del_channel(ttusb, dvbdmxfeed->index);958959if (--ttusb->running_feed_count == 0)960ttusb_stop_iso_xfer(ttusb);961962return 0;963}964965static int ttusb_setup_interfaces(struct ttusb *ttusb)966{967usb_set_interface(ttusb->dev, 1, 1);968969ttusb->bulk_out_pipe = usb_sndbulkpipe(ttusb->dev, 1);970ttusb->bulk_in_pipe = usb_rcvbulkpipe(ttusb->dev, 1);971ttusb->isoc_in_pipe = usb_rcvisocpipe(ttusb->dev, 2);972973return 0;974}975976#if 0977static u8 stc_firmware[8192];978979static int stc_open(struct inode *inode, struct file *file)980{981struct ttusb *ttusb = file->private_data;982int addr;983984for (addr = 0; addr < 8192; addr += 16) {985u8 snd_buf[2] = { addr >> 8, addr & 0xFF };986ttusb_i2c_msg(ttusb, 0x50, snd_buf, 2, stc_firmware + addr,98716);988}989990return 0;991}992993static ssize_t stc_read(struct file *file, char *buf, size_t count,994loff_t *offset)995{996return simple_read_from_buffer(buf, count, offset, stc_firmware, 8192);997}998999static int stc_release(struct inode *inode, struct file *file)1000{1001return 0;1002}10031004static const struct file_operations stc_fops = {1005.owner = THIS_MODULE,1006.read = stc_read,1007.open = stc_open,1008.release = stc_release,1009};1010#endif10111012static u32 functionality(struct i2c_adapter *adapter)1013{1014return I2C_FUNC_I2C;1015}1016101710181019static int alps_tdmb7_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)1020{1021struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;1022u8 data[4];1023struct i2c_msg msg = {.addr=0x61, .flags=0, .buf=data, .len=sizeof(data) };1024u32 div;10251026div = (params->frequency + 36166667) / 166667;10271028data[0] = (div >> 8) & 0x7f;1029data[1] = div & 0xff;1030data[2] = ((div >> 10) & 0x60) | 0x85;1031data[3] = params->frequency < 592000000 ? 0x40 : 0x80;10321033if (fe->ops.i2c_gate_ctrl)1034fe->ops.i2c_gate_ctrl(fe, 1);1035if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1) return -EIO;1036return 0;1037}10381039static struct cx22700_config alps_tdmb7_config = {1040.demod_address = 0x43,1041};104210431044104510461047static int philips_tdm1316l_tuner_init(struct dvb_frontend* fe)1048{1049struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;1050static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };1051static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };1052struct i2c_msg tuner_msg = { .addr=0x60, .flags=0, .buf=td1316_init, .len=sizeof(td1316_init) };10531054// setup PLL configuration1055if (fe->ops.i2c_gate_ctrl)1056fe->ops.i2c_gate_ctrl(fe, 1);1057if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) return -EIO;1058msleep(1);10591060// disable the mc44BC374c (do not check for errors)1061tuner_msg.addr = 0x65;1062tuner_msg.buf = disable_mc44BC374c;1063tuner_msg.len = sizeof(disable_mc44BC374c);1064if (fe->ops.i2c_gate_ctrl)1065fe->ops.i2c_gate_ctrl(fe, 1);1066if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {1067i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1);1068}10691070return 0;1071}10721073static int philips_tdm1316l_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)1074{1075struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;1076u8 tuner_buf[4];1077struct i2c_msg tuner_msg = {.addr=0x60, .flags=0, .buf=tuner_buf, .len=sizeof(tuner_buf) };1078int tuner_frequency = 0;1079u8 band, cp, filter;10801081// determine charge pump1082tuner_frequency = params->frequency + 36130000;1083if (tuner_frequency < 87000000) return -EINVAL;1084else if (tuner_frequency < 130000000) cp = 3;1085else if (tuner_frequency < 160000000) cp = 5;1086else if (tuner_frequency < 200000000) cp = 6;1087else if (tuner_frequency < 290000000) cp = 3;1088else if (tuner_frequency < 420000000) cp = 5;1089else if (tuner_frequency < 480000000) cp = 6;1090else if (tuner_frequency < 620000000) cp = 3;1091else if (tuner_frequency < 830000000) cp = 5;1092else if (tuner_frequency < 895000000) cp = 7;1093else return -EINVAL;10941095// determine band1096if (params->frequency < 49000000) return -EINVAL;1097else if (params->frequency < 159000000) band = 1;1098else if (params->frequency < 444000000) band = 2;1099else if (params->frequency < 861000000) band = 4;1100else return -EINVAL;11011102// setup PLL filter1103switch (params->u.ofdm.bandwidth) {1104case BANDWIDTH_6_MHZ:1105tda1004x_writereg(fe, 0x0C, 0);1106filter = 0;1107break;11081109case BANDWIDTH_7_MHZ:1110tda1004x_writereg(fe, 0x0C, 0);1111filter = 0;1112break;11131114case BANDWIDTH_8_MHZ:1115tda1004x_writereg(fe, 0x0C, 0xFF);1116filter = 1;1117break;11181119default:1120return -EINVAL;1121}11221123// calculate divisor1124// ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)1125tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000;11261127// setup tuner buffer1128tuner_buf[0] = tuner_frequency >> 8;1129tuner_buf[1] = tuner_frequency & 0xff;1130tuner_buf[2] = 0xca;1131tuner_buf[3] = (cp << 5) | (filter << 3) | band;11321133if (fe->ops.i2c_gate_ctrl)1134fe->ops.i2c_gate_ctrl(fe, 1);1135if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1)1136return -EIO;11371138msleep(1);1139return 0;1140}11411142static int philips_tdm1316l_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)1143{1144struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;11451146return request_firmware(fw, name, &ttusb->dev->dev);1147}11481149static struct tda1004x_config philips_tdm1316l_config = {11501151.demod_address = 0x8,1152.invert = 1,1153.invert_oclk = 0,1154.request_firmware = philips_tdm1316l_request_firmware,1155};11561157static u8 alps_bsbe1_inittab[] = {11580x01, 0x15,11590x02, 0x30,11600x03, 0x00,11610x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */11620x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */11630x06, 0x40, /* DAC not used, set to high impendance mode */11640x07, 0x00, /* DAC LSB */11650x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */11660x09, 0x00, /* FIFO */11670x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */11680x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */11690x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */11700x10, 0x3f, // AGC2 0x3d11710x11, 0x84,11720x12, 0xb9,11730x15, 0xc9, // lock detector threshold11740x16, 0x00,11750x17, 0x00,11760x18, 0x00,11770x19, 0x00,11780x1a, 0x00,11790x1f, 0x50,11800x20, 0x00,11810x21, 0x00,11820x22, 0x00,11830x23, 0x00,11840x28, 0x00, // out imp: normal out type: parallel FEC mode:011850x29, 0x1e, // 1/2 threshold11860x2a, 0x14, // 2/3 threshold11870x2b, 0x0f, // 3/4 threshold11880x2c, 0x09, // 5/6 threshold11890x2d, 0x05, // 7/8 threshold11900x2e, 0x01,11910x31, 0x1f, // test all FECs11920x32, 0x19, // viterbi and synchro search11930x33, 0xfc, // rs control11940x34, 0x93, // error control11950x0f, 0x92,11960xff, 0xff1197};11981199static u8 alps_bsru6_inittab[] = {12000x01, 0x15,12010x02, 0x30,12020x03, 0x00,12030x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */12040x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */12050x06, 0x40, /* DAC not used, set to high impendance mode */12060x07, 0x00, /* DAC LSB */12070x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */12080x09, 0x00, /* FIFO */12090x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */12100x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */12110x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */12120x10, 0x3f, // AGC2 0x3d12130x11, 0x84,12140x12, 0xb9,12150x15, 0xc9, // lock detector threshold12160x16, 0x00,12170x17, 0x00,12180x18, 0x00,12190x19, 0x00,12200x1a, 0x00,12210x1f, 0x50,12220x20, 0x00,12230x21, 0x00,12240x22, 0x00,12250x23, 0x00,12260x28, 0x00, // out imp: normal out type: parallel FEC mode:012270x29, 0x1e, // 1/2 threshold12280x2a, 0x14, // 2/3 threshold12290x2b, 0x0f, // 3/4 threshold12300x2c, 0x09, // 5/6 threshold12310x2d, 0x05, // 7/8 threshold12320x2e, 0x01,12330x31, 0x1f, // test all FECs12340x32, 0x19, // viterbi and synchro search12350x33, 0xfc, // rs control12360x34, 0x93, // error control12370x0f, 0x52,12380xff, 0xff1239};12401241static int alps_stv0299_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)1242{1243u8 aclk = 0;1244u8 bclk = 0;12451246if (srate < 1500000) {1247aclk = 0xb7;1248bclk = 0x47;1249} else if (srate < 3000000) {1250aclk = 0xb7;1251bclk = 0x4b;1252} else if (srate < 7000000) {1253aclk = 0xb7;1254bclk = 0x4f;1255} else if (srate < 14000000) {1256aclk = 0xb7;1257bclk = 0x53;1258} else if (srate < 30000000) {1259aclk = 0xb6;1260bclk = 0x53;1261} else if (srate < 45000000) {1262aclk = 0xb4;1263bclk = 0x51;1264}12651266stv0299_writereg(fe, 0x13, aclk);1267stv0299_writereg(fe, 0x14, bclk);1268stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);1269stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);1270stv0299_writereg(fe, 0x21, (ratio) & 0xf0);12711272return 0;1273}12741275static int philips_tsa5059_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)1276{1277struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;1278u8 buf[4];1279u32 div;1280struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };12811282if ((params->frequency < 950000) || (params->frequency > 2150000))1283return -EINVAL;12841285div = (params->frequency + (125 - 1)) / 125; // round correctly1286buf[0] = (div >> 8) & 0x7f;1287buf[1] = div & 0xff;1288buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4;1289buf[3] = 0xC4;12901291if (params->frequency > 1530000)1292buf[3] = 0xC0;12931294/* BSBE1 wants XCE bit set */1295if (ttusb->revision == TTUSB_REV_2_2)1296buf[3] |= 0x20;12971298if (fe->ops.i2c_gate_ctrl)1299fe->ops.i2c_gate_ctrl(fe, 1);1300if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1)1301return -EIO;13021303return 0;1304}13051306static struct stv0299_config alps_stv0299_config = {1307.demod_address = 0x68,1308.inittab = alps_bsru6_inittab,1309.mclk = 88000000UL,1310.invert = 1,1311.skip_reinit = 0,1312.lock_output = STV0299_LOCKOUTPUT_1,1313.volt13_op0_op1 = STV0299_VOLT13_OP1,1314.min_delay_ms = 100,1315.set_symbol_rate = alps_stv0299_set_symbol_rate,1316};13171318static int ttusb_novas_grundig_29504_491_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)1319{1320struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;1321u8 buf[4];1322u32 div;1323struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };13241325div = params->frequency / 125;13261327buf[0] = (div >> 8) & 0x7f;1328buf[1] = div & 0xff;1329buf[2] = 0x8e;1330buf[3] = 0x00;13311332if (fe->ops.i2c_gate_ctrl)1333fe->ops.i2c_gate_ctrl(fe, 1);1334if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1)1335return -EIO;13361337return 0;1338}13391340static struct tda8083_config ttusb_novas_grundig_29504_491_config = {13411342.demod_address = 0x68,1343};13441345static int alps_tdbe2_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)1346{1347struct ttusb* ttusb = fe->dvb->priv;1348u32 div;1349u8 data[4];1350struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) };13511352div = (params->frequency + 35937500 + 31250) / 62500;13531354data[0] = (div >> 8) & 0x7f;1355data[1] = div & 0xff;1356data[2] = 0x85 | ((div >> 10) & 0x60);1357data[3] = (params->frequency < 174000000 ? 0x88 : params->frequency < 470000000 ? 0x84 : 0x81);13581359if (fe->ops.i2c_gate_ctrl)1360fe->ops.i2c_gate_ctrl(fe, 1);1361if (i2c_transfer (&ttusb->i2c_adap, &msg, 1) != 1)1362return -EIO;13631364return 0;1365}136613671368static struct ves1820_config alps_tdbe2_config = {1369.demod_address = 0x09,1370.xin = 57840000UL,1371.invert = 1,1372.selagc = VES1820_SELAGC_SIGNAMPERR,1373};13741375static u8 read_pwm(struct ttusb* ttusb)1376{1377u8 b = 0xff;1378u8 pwm;1379struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },1380{ .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };13811382if ((i2c_transfer(&ttusb->i2c_adap, msg, 2) != 2) || (pwm == 0xff))1383pwm = 0x48;13841385return pwm;1386}138713881389static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)1390{1391struct ttusb *ttusb = (struct ttusb *) fe->dvb->priv;1392u8 tuner_buf[5];1393struct i2c_msg tuner_msg = {.addr = 0x60,1394.flags = 0,1395.buf = tuner_buf,1396.len = sizeof(tuner_buf) };1397int tuner_frequency = 0;1398u8 band, cp, filter;13991400// determine charge pump1401tuner_frequency = params->frequency;1402if (tuner_frequency < 87000000) {return -EINVAL;}1403else if (tuner_frequency < 130000000) {cp = 3; band = 1;}1404else if (tuner_frequency < 160000000) {cp = 5; band = 1;}1405else if (tuner_frequency < 200000000) {cp = 6; band = 1;}1406else if (tuner_frequency < 290000000) {cp = 3; band = 2;}1407else if (tuner_frequency < 420000000) {cp = 5; band = 2;}1408else if (tuner_frequency < 480000000) {cp = 6; band = 2;}1409else if (tuner_frequency < 620000000) {cp = 3; band = 4;}1410else if (tuner_frequency < 830000000) {cp = 5; band = 4;}1411else if (tuner_frequency < 895000000) {cp = 7; band = 4;}1412else {return -EINVAL;}14131414// assume PLL filter should always be 8MHz for the moment.1415filter = 1;14161417// calculate divisor1418// (Finput + Fif)/Fref; Fif = 36125000 Hz, Fref = 62500 Hz1419tuner_frequency = ((params->frequency + 36125000) / 62500);14201421// setup tuner buffer1422tuner_buf[0] = tuner_frequency >> 8;1423tuner_buf[1] = tuner_frequency & 0xff;1424tuner_buf[2] = 0xc8;1425tuner_buf[3] = (cp << 5) | (filter << 3) | band;1426tuner_buf[4] = 0x80;14271428if (fe->ops.i2c_gate_ctrl)1429fe->ops.i2c_gate_ctrl(fe, 1);1430if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {1431printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 1\n");1432return -EIO;1433}14341435msleep(50);14361437if (fe->ops.i2c_gate_ctrl)1438fe->ops.i2c_gate_ctrl(fe, 1);1439if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {1440printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 2\n");1441return -EIO;1442}14431444msleep(1);14451446return 0;1447}14481449static u8 dvbc_philips_tdm1316l_inittab[] = {14500x80, 0x21,14510x80, 0x20,14520x81, 0x01,14530x81, 0x00,14540x00, 0x09,14550x01, 0x69,14560x03, 0x00,14570x04, 0x00,14580x07, 0x00,14590x08, 0x00,14600x20, 0x00,14610x21, 0x40,14620x22, 0x00,14630x23, 0x00,14640x24, 0x40,14650x25, 0x88,14660x30, 0xff,14670x31, 0x00,14680x32, 0xff,14690x33, 0x00,14700x34, 0x50,14710x35, 0x7f,14720x36, 0x00,14730x37, 0x20,14740x38, 0x00,14750x40, 0x1c,14760x41, 0xff,14770x42, 0x29,14780x43, 0x20,14790x44, 0xff,14800x45, 0x00,14810x46, 0x00,14820x49, 0x04,14830x4a, 0xff,14840x4b, 0x7f,14850x52, 0x30,14860x55, 0xae,14870x56, 0x47,14880x57, 0xe1,14890x58, 0x3a,14900x5a, 0x1e,14910x5b, 0x34,14920x60, 0x00,14930x63, 0x00,14940x64, 0x00,14950x65, 0x00,14960x66, 0x00,14970x67, 0x00,14980x68, 0x00,14990x69, 0x00,15000x6a, 0x02,15010x6b, 0x00,15020x70, 0xff,15030x71, 0x00,15040x72, 0x00,15050x73, 0x00,15060x74, 0x0c,15070x80, 0x00,15080x81, 0x00,15090x82, 0x00,15100x83, 0x00,15110x84, 0x04,15120x85, 0x80,15130x86, 0x24,15140x87, 0x78,15150x88, 0x00,15160x89, 0x00,15170x90, 0x01,15180x91, 0x01,15190xa0, 0x00,15200xa1, 0x00,15210xa2, 0x00,15220xb0, 0x91,15230xb1, 0x0b,15240xc0, 0x4b,15250xc1, 0x00,15260xc2, 0x00,15270xd0, 0x00,15280xd1, 0x00,15290xd2, 0x00,15300xd3, 0x00,15310xd4, 0x00,15320xd5, 0x00,15330xde, 0x00,15340xdf, 0x00,15350x61, 0x38,15360x62, 0x0a,15370x53, 0x13,15380x59, 0x08,15390x55, 0x00,15400x56, 0x40,15410x57, 0x08,15420x58, 0x3d,15430x88, 0x10,15440xa0, 0x00,15450xa0, 0x00,15460xa0, 0x00,15470xa0, 0x04,15480xff, 0xff,1549};15501551static struct stv0297_config dvbc_philips_tdm1316l_config = {1552.demod_address = 0x1c,1553.inittab = dvbc_philips_tdm1316l_inittab,1554.invert = 0,1555};15561557static void frontend_init(struct ttusb* ttusb)1558{1559switch(le16_to_cpu(ttusb->dev->descriptor.idProduct)) {1560case 0x1003: // Hauppauge/TT Nova-USB-S budget (stv0299/ALPS BSRU6|BSBE1(tsa5059))1561// try the stv0299 based first1562ttusb->fe = dvb_attach(stv0299_attach, &alps_stv0299_config, &ttusb->i2c_adap);1563if (ttusb->fe != NULL) {1564ttusb->fe->ops.tuner_ops.set_params = philips_tsa5059_tuner_set_params;15651566if(ttusb->revision == TTUSB_REV_2_2) { // ALPS BSBE11567alps_stv0299_config.inittab = alps_bsbe1_inittab;1568dvb_attach(lnbp21_attach, ttusb->fe, &ttusb->i2c_adap, 0, 0);1569} else { // ALPS BSRU61570ttusb->fe->ops.set_voltage = ttusb_set_voltage;1571}1572break;1573}15741575// Grundig 29504-4911576ttusb->fe = dvb_attach(tda8083_attach, &ttusb_novas_grundig_29504_491_config, &ttusb->i2c_adap);1577if (ttusb->fe != NULL) {1578ttusb->fe->ops.tuner_ops.set_params = ttusb_novas_grundig_29504_491_tuner_set_params;1579ttusb->fe->ops.set_voltage = ttusb_set_voltage;1580break;1581}1582break;15831584case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))1585ttusb->fe = dvb_attach(ves1820_attach, &alps_tdbe2_config, &ttusb->i2c_adap, read_pwm(ttusb));1586if (ttusb->fe != NULL) {1587ttusb->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;1588break;1589}15901591ttusb->fe = dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &ttusb->i2c_adap);1592if (ttusb->fe != NULL) {1593ttusb->fe->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;1594break;1595}1596break;15971598case 0x1005: // Hauppauge/TT Nova-USB-t budget (tda10046/Philips td1316(tda6651tt) OR cx22700/ALPS TDMB7(??))1599// try the ALPS TDMB7 first1600ttusb->fe = dvb_attach(cx22700_attach, &alps_tdmb7_config, &ttusb->i2c_adap);1601if (ttusb->fe != NULL) {1602ttusb->fe->ops.tuner_ops.set_params = alps_tdmb7_tuner_set_params;1603break;1604}16051606// Philips td13161607ttusb->fe = dvb_attach(tda10046_attach, &philips_tdm1316l_config, &ttusb->i2c_adap);1608if (ttusb->fe != NULL) {1609ttusb->fe->ops.tuner_ops.init = philips_tdm1316l_tuner_init;1610ttusb->fe->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;1611break;1612}1613break;1614}16151616if (ttusb->fe == NULL) {1617printk("dvb-ttusb-budget: A frontend driver was not found for device [%04x:%04x]\n",1618le16_to_cpu(ttusb->dev->descriptor.idVendor),1619le16_to_cpu(ttusb->dev->descriptor.idProduct));1620} else {1621if (dvb_register_frontend(&ttusb->adapter, ttusb->fe)) {1622printk("dvb-ttusb-budget: Frontend registration failed!\n");1623dvb_frontend_detach(ttusb->fe);1624ttusb->fe = NULL;1625}1626}1627}1628162916301631static struct i2c_algorithm ttusb_dec_algo = {1632.master_xfer = master_xfer,1633.functionality = functionality,1634};16351636static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *id)1637{1638struct usb_device *udev;1639struct ttusb *ttusb;1640int result;16411642dprintk("%s: TTUSB DVB connected\n", __func__);16431644udev = interface_to_usbdev(intf);16451646if (intf->altsetting->desc.bInterfaceNumber != 1) return -ENODEV;16471648if (!(ttusb = kzalloc(sizeof(struct ttusb), GFP_KERNEL)))1649return -ENOMEM;16501651ttusb->dev = udev;1652ttusb->c = 0;1653ttusb->mux_state = 0;1654mutex_init(&ttusb->semi2c);16551656mutex_lock(&ttusb->semi2c);16571658mutex_init(&ttusb->semusb);16591660ttusb_setup_interfaces(ttusb);16611662result = ttusb_alloc_iso_urbs(ttusb);1663if (result < 0) {1664dprintk("%s: ttusb_alloc_iso_urbs - failed\n", __func__);1665mutex_unlock(&ttusb->semi2c);1666kfree(ttusb);1667return result;1668}16691670if (ttusb_init_controller(ttusb))1671printk("ttusb_init_controller: error\n");16721673mutex_unlock(&ttusb->semi2c);16741675result = dvb_register_adapter(&ttusb->adapter,1676"Technotrend/Hauppauge Nova-USB",1677THIS_MODULE, &udev->dev, adapter_nr);1678if (result < 0) {1679ttusb_free_iso_urbs(ttusb);1680kfree(ttusb);1681return result;1682}1683ttusb->adapter.priv = ttusb;16841685/* i2c */1686memset(&ttusb->i2c_adap, 0, sizeof(struct i2c_adapter));1687strcpy(ttusb->i2c_adap.name, "TTUSB DEC");16881689i2c_set_adapdata(&ttusb->i2c_adap, ttusb);16901691ttusb->i2c_adap.algo = &ttusb_dec_algo;1692ttusb->i2c_adap.algo_data = NULL;1693ttusb->i2c_adap.dev.parent = &udev->dev;16941695result = i2c_add_adapter(&ttusb->i2c_adap);1696if (result) {1697dvb_unregister_adapter (&ttusb->adapter);1698return result;1699}17001701memset(&ttusb->dvb_demux, 0, sizeof(ttusb->dvb_demux));17021703ttusb->dvb_demux.dmx.capabilities =1704DMX_TS_FILTERING | DMX_SECTION_FILTERING;1705ttusb->dvb_demux.priv = NULL;1706#ifdef TTUSB_HWSECTIONS1707ttusb->dvb_demux.filternum = TTUSB_MAXFILTER;1708#else1709ttusb->dvb_demux.filternum = 32;1710#endif1711ttusb->dvb_demux.feednum = TTUSB_MAXCHANNEL;1712ttusb->dvb_demux.start_feed = ttusb_start_feed;1713ttusb->dvb_demux.stop_feed = ttusb_stop_feed;1714ttusb->dvb_demux.write_to_decoder = NULL;17151716if ((result = dvb_dmx_init(&ttusb->dvb_demux)) < 0) {1717printk("ttusb_dvb: dvb_dmx_init failed (errno = %d)\n", result);1718i2c_del_adapter(&ttusb->i2c_adap);1719dvb_unregister_adapter (&ttusb->adapter);1720return -ENODEV;1721}1722//FIXME dmxdev (nur WAS?)1723ttusb->dmxdev.filternum = ttusb->dvb_demux.filternum;1724ttusb->dmxdev.demux = &ttusb->dvb_demux.dmx;1725ttusb->dmxdev.capabilities = 0;17261727if ((result = dvb_dmxdev_init(&ttusb->dmxdev, &ttusb->adapter)) < 0) {1728printk("ttusb_dvb: dvb_dmxdev_init failed (errno = %d)\n",1729result);1730dvb_dmx_release(&ttusb->dvb_demux);1731i2c_del_adapter(&ttusb->i2c_adap);1732dvb_unregister_adapter (&ttusb->adapter);1733return -ENODEV;1734}17351736if (dvb_net_init(&ttusb->adapter, &ttusb->dvbnet, &ttusb->dvb_demux.dmx)) {1737printk("ttusb_dvb: dvb_net_init failed!\n");1738dvb_dmxdev_release(&ttusb->dmxdev);1739dvb_dmx_release(&ttusb->dvb_demux);1740i2c_del_adapter(&ttusb->i2c_adap);1741dvb_unregister_adapter (&ttusb->adapter);1742return -ENODEV;1743}17441745usb_set_intfdata(intf, (void *) ttusb);17461747frontend_init(ttusb);17481749return 0;1750}17511752static void ttusb_disconnect(struct usb_interface *intf)1753{1754struct ttusb *ttusb = usb_get_intfdata(intf);17551756usb_set_intfdata(intf, NULL);17571758ttusb->disconnecting = 1;17591760ttusb_stop_iso_xfer(ttusb);17611762ttusb->dvb_demux.dmx.close(&ttusb->dvb_demux.dmx);1763dvb_net_release(&ttusb->dvbnet);1764dvb_dmxdev_release(&ttusb->dmxdev);1765dvb_dmx_release(&ttusb->dvb_demux);1766if (ttusb->fe != NULL) {1767dvb_unregister_frontend(ttusb->fe);1768dvb_frontend_detach(ttusb->fe);1769}1770i2c_del_adapter(&ttusb->i2c_adap);1771dvb_unregister_adapter(&ttusb->adapter);17721773ttusb_free_iso_urbs(ttusb);17741775kfree(ttusb);17761777dprintk("%s: TTUSB DVB disconnected\n", __func__);1778}17791780static struct usb_device_id ttusb_table[] = {1781{USB_DEVICE(0xb48, 0x1003)},1782{USB_DEVICE(0xb48, 0x1004)},1783{USB_DEVICE(0xb48, 0x1005)},1784{}1785};17861787MODULE_DEVICE_TABLE(usb, ttusb_table);17881789static struct usb_driver ttusb_driver = {1790.name = "ttusb",1791.probe = ttusb_probe,1792.disconnect = ttusb_disconnect,1793.id_table = ttusb_table,1794};17951796static int __init ttusb_init(void)1797{1798int err;17991800if ((err = usb_register(&ttusb_driver)) < 0) {1801printk("%s: usb_register failed! Error number %d",1802__FILE__, err);1803return err;1804}18051806return 0;1807}18081809static void __exit ttusb_exit(void)1810{1811usb_deregister(&ttusb_driver);1812}18131814module_init(ttusb_init);1815module_exit(ttusb_exit);18161817MODULE_AUTHOR("Holger Waechtler <[email protected]>");1818MODULE_DESCRIPTION("TTUSB DVB Driver");1819MODULE_LICENSE("GPL");1820MODULE_FIRMWARE("ttusb-budget/dspbootcode.bin");182118221823