firedtv: use length_field() of PMT as length
[linux-2.6] / drivers / media / dvb / ttpci / budget.c
1 /*
2  * budget.c: driver for the SAA7146 based Budget DVB cards
3  *
4  * Compiled from various sources by Michael Hunold <michael@mihu.de>
5  *
6  * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
7  *
8  * Copyright (C) 1999-2002 Ralph  Metzler
9  *                       & Marcus Metzler for convergence integrated media GmbH
10  *
11  * 26feb2004 Support for FS Activy Card (Grundig tuner) by
12  *           Michael Dreher <michael@5dot1.de>,
13  *           Oliver Endriss <o.endriss@gmx.de> and
14  *           Andreas 'randy' Weinberger
15  *
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
32  *
33  *
34  * the project's page is at http://www.linuxtv.org/dvb/
35  */
36
37 #include "budget.h"
38 #include "stv0299.h"
39 #include "ves1x93.h"
40 #include "ves1820.h"
41 #include "l64781.h"
42 #include "tda8083.h"
43 #include "s5h1420.h"
44 #include "tda10086.h"
45 #include "tda826x.h"
46 #include "lnbp21.h"
47 #include "bsru6.h"
48 #include "bsbe1.h"
49 #include "tdhd1.h"
50
51 static int diseqc_method;
52 module_param(diseqc_method, int, 0444);
53 MODULE_PARM_DESC(diseqc_method, "Select DiSEqC method for subsystem id 13c2:1003, 0: default, 1: more reliable (for newer revisions only)");
54
55 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
56
57 static void Set22K (struct budget *budget, int state)
58 {
59         struct saa7146_dev *dev=budget->dev;
60         dprintk(2, "budget: %p\n", budget);
61         saa7146_setgpio(dev, 3, (state ? SAA7146_GPIO_OUTHI : SAA7146_GPIO_OUTLO));
62 }
63
64 /* Diseqc functions only for TT Budget card */
65 /* taken from the Skyvision DVB driver by
66    Ralph Metzler <rjkm@metzlerbros.de> */
67
68 static void DiseqcSendBit (struct budget *budget, int data)
69 {
70         struct saa7146_dev *dev=budget->dev;
71         dprintk(2, "budget: %p\n", budget);
72
73         saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
74         udelay(data ? 500 : 1000);
75         saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
76         udelay(data ? 1000 : 500);
77 }
78
79 static void DiseqcSendByte (struct budget *budget, int data)
80 {
81         int i, par=1, d;
82
83         dprintk(2, "budget: %p\n", budget);
84
85         for (i=7; i>=0; i--) {
86                 d = (data>>i)&1;
87                 par ^= d;
88                 DiseqcSendBit(budget, d);
89         }
90
91         DiseqcSendBit(budget, par);
92 }
93
94 static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long burst)
95 {
96         struct saa7146_dev *dev=budget->dev;
97         int i;
98
99         dprintk(2, "budget: %p\n", budget);
100
101         saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
102         mdelay(16);
103
104         for (i=0; i<len; i++)
105                 DiseqcSendByte(budget, msg[i]);
106
107         mdelay(16);
108
109         if (burst!=-1) {
110                 if (burst)
111                         DiseqcSendByte(budget, 0xff);
112                 else {
113                         saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
114                         mdelay(12);
115                         udelay(500);
116                         saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
117                 }
118                 msleep(20);
119         }
120
121         return 0;
122 }
123
124 /*
125  *   Routines for the Fujitsu Siemens Activy budget card
126  *   22 kHz tone and DiSEqC are handled by the frontend.
127  *   Voltage must be set here.
128  *   GPIO 1: LNBP EN, GPIO 2: LNBP VSEL
129  */
130 static int SetVoltage_Activy (struct budget *budget, fe_sec_voltage_t voltage)
131 {
132         struct saa7146_dev *dev=budget->dev;
133
134         dprintk(2, "budget: %p\n", budget);
135
136         switch (voltage) {
137                 case SEC_VOLTAGE_13:
138                         saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
139                         saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTLO);
140                         break;
141                 case SEC_VOLTAGE_18:
142                         saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
143                         saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI);
144                         break;
145                 case SEC_VOLTAGE_OFF:
146                         saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO);
147                         break;
148                 default:
149                         return -EINVAL;
150         }
151
152         return 0;
153 }
154
155 static int siemens_budget_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
156 {
157         struct budget* budget = (struct budget*) fe->dvb->priv;
158
159         return SetVoltage_Activy (budget, voltage);
160 }
161
162 static int budget_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
163 {
164         struct budget* budget = (struct budget*) fe->dvb->priv;
165
166         switch (tone) {
167         case SEC_TONE_ON:
168                 Set22K (budget, 1);
169                 break;
170
171         case SEC_TONE_OFF:
172                 Set22K (budget, 0);
173                 break;
174
175         default:
176                 return -EINVAL;
177         }
178
179         return 0;
180 }
181
182 static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
183 {
184         struct budget* budget = (struct budget*) fe->dvb->priv;
185
186         SendDiSEqCMsg (budget, cmd->msg_len, cmd->msg, 0);
187
188         return 0;
189 }
190
191 static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
192 {
193         struct budget* budget = (struct budget*) fe->dvb->priv;
194
195         SendDiSEqCMsg (budget, 0, NULL, minicmd);
196
197         return 0;
198 }
199
200 static int alps_bsrv2_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
201 {
202         struct budget* budget = (struct budget*) fe->dvb->priv;
203         u8 pwr = 0;
204         u8 buf[4];
205         struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
206         u32 div = (params->frequency + 479500) / 125;
207
208         if (params->frequency > 2000000) pwr = 3;
209         else if (params->frequency > 1800000) pwr = 2;
210         else if (params->frequency > 1600000) pwr = 1;
211         else if (params->frequency > 1200000) pwr = 0;
212         else if (params->frequency >= 1100000) pwr = 1;
213         else pwr = 2;
214
215         buf[0] = (div >> 8) & 0x7f;
216         buf[1] = div & 0xff;
217         buf[2] = ((div & 0x18000) >> 10) | 0x95;
218         buf[3] = (pwr << 6) | 0x30;
219
220         // NOTE: since we're using a prescaler of 2, we set the
221         // divisor frequency to 62.5kHz and divide by 125 above
222
223         if (fe->ops.i2c_gate_ctrl)
224                 fe->ops.i2c_gate_ctrl(fe, 1);
225         if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
226         return 0;
227 }
228
229 static struct ves1x93_config alps_bsrv2_config =
230 {
231         .demod_address = 0x08,
232         .xin = 90100000UL,
233         .invert_pwm = 0,
234 };
235
236 static int alps_tdbe2_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
237 {
238         struct budget* budget = (struct budget*) fe->dvb->priv;
239         u32 div;
240         u8 data[4];
241         struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) };
242
243         div = (params->frequency + 35937500 + 31250) / 62500;
244
245         data[0] = (div >> 8) & 0x7f;
246         data[1] = div & 0xff;
247         data[2] = 0x85 | ((div >> 10) & 0x60);
248         data[3] = (params->frequency < 174000000 ? 0x88 : params->frequency < 470000000 ? 0x84 : 0x81);
249
250         if (fe->ops.i2c_gate_ctrl)
251                 fe->ops.i2c_gate_ctrl(fe, 1);
252         if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
253         return 0;
254 }
255
256 static struct ves1820_config alps_tdbe2_config = {
257         .demod_address = 0x09,
258         .xin = 57840000UL,
259         .invert = 1,
260         .selagc = VES1820_SELAGC_SIGNAMPERR,
261 };
262
263 static int grundig_29504_401_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
264 {
265         struct budget *budget = fe->dvb->priv;
266         u8 *tuner_addr = fe->tuner_priv;
267         u32 div;
268         u8 cfg, cpump, band_select;
269         u8 data[4];
270         struct i2c_msg msg = { .flags = 0, .buf = data, .len = sizeof(data) };
271
272         if (tuner_addr)
273                 msg.addr = *tuner_addr;
274         else
275                 msg.addr = 0x61;
276
277         div = (36125000 + params->frequency) / 166666;
278
279         cfg = 0x88;
280
281         if (params->frequency < 175000000) cpump = 2;
282         else if (params->frequency < 390000000) cpump = 1;
283         else if (params->frequency < 470000000) cpump = 2;
284         else if (params->frequency < 750000000) cpump = 1;
285         else cpump = 3;
286
287         if (params->frequency < 175000000) band_select = 0x0e;
288         else if (params->frequency < 470000000) band_select = 0x05;
289         else band_select = 0x03;
290
291         data[0] = (div >> 8) & 0x7f;
292         data[1] = div & 0xff;
293         data[2] = ((div >> 10) & 0x60) | cfg;
294         data[3] = (cpump << 6) | band_select;
295
296         if (fe->ops.i2c_gate_ctrl)
297                 fe->ops.i2c_gate_ctrl(fe, 1);
298         if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
299         return 0;
300 }
301
302 static struct l64781_config grundig_29504_401_config = {
303         .demod_address = 0x55,
304 };
305
306 static struct l64781_config grundig_29504_401_config_activy = {
307         .demod_address = 0x54,
308 };
309
310 static u8 tuner_address_grundig_29504_401_activy = 0x60;
311
312 static int grundig_29504_451_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
313 {
314         struct budget* budget = (struct budget*) fe->dvb->priv;
315         u32 div;
316         u8 data[4];
317         struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
318
319         div = params->frequency / 125;
320         data[0] = (div >> 8) & 0x7f;
321         data[1] = div & 0xff;
322         data[2] = 0x8e;
323         data[3] = 0x00;
324
325         if (fe->ops.i2c_gate_ctrl)
326                 fe->ops.i2c_gate_ctrl(fe, 1);
327         if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
328         return 0;
329 }
330
331 static struct tda8083_config grundig_29504_451_config = {
332         .demod_address = 0x68,
333 };
334
335 static int s5h1420_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
336 {
337         struct budget* budget = (struct budget*) fe->dvb->priv;
338         u32 div;
339         u8 data[4];
340         struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
341
342         div = params->frequency / 1000;
343         data[0] = (div >> 8) & 0x7f;
344         data[1] = div & 0xff;
345         data[2] = 0xc2;
346
347         if (div < 1450)
348                 data[3] = 0x00;
349         else if (div < 1850)
350                 data[3] = 0x40;
351         else if (div < 2000)
352                 data[3] = 0x80;
353         else
354                 data[3] = 0xc0;
355
356         if (fe->ops.i2c_gate_ctrl)
357                 fe->ops.i2c_gate_ctrl(fe, 1);
358         if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
359
360         return 0;
361 }
362
363 static struct s5h1420_config s5h1420_config = {
364         .demod_address = 0x53,
365         .invert = 1,
366         .cdclk_polarity = 1,
367 };
368
369 static struct tda10086_config tda10086_config = {
370         .demod_address = 0x0e,
371         .invert = 0,
372         .diseqc_tone = 1,
373         .xtal_freq = TDA10086_XTAL_16M,
374 };
375
376 static struct stv0299_config alps_bsru6_config_activy = {
377         .demod_address = 0x68,
378         .inittab = alps_bsru6_inittab,
379         .mclk = 88000000UL,
380         .invert = 1,
381         .op0_off = 1,
382         .min_delay_ms = 100,
383         .set_symbol_rate = alps_bsru6_set_symbol_rate,
384 };
385
386 static struct stv0299_config alps_bsbe1_config_activy = {
387         .demod_address = 0x68,
388         .inittab = alps_bsbe1_inittab,
389         .mclk = 88000000UL,
390         .invert = 1,
391         .op0_off = 1,
392         .min_delay_ms = 100,
393         .set_symbol_rate = alps_bsbe1_set_symbol_rate,
394 };
395
396 static int alps_tdhd1_204_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name)
397 {
398         struct budget *budget = (struct budget *)fe->dvb->priv;
399
400         return request_firmware(fw, name, &budget->dev->pci->dev);
401 }
402
403
404 static int i2c_readreg(struct i2c_adapter *i2c, u8 adr, u8 reg)
405 {
406         u8 val;
407         struct i2c_msg msg[] = {
408                 { .addr = adr, .flags = 0, .buf = &reg, .len = 1 },
409                 { .addr = adr, .flags = I2C_M_RD, .buf = &val, .len = 1 }
410         };
411
412         return (i2c_transfer(i2c, msg, 2) != 2) ? -EIO : val;
413 }
414
415 static u8 read_pwm(struct budget* budget)
416 {
417         u8 b = 0xff;
418         u8 pwm;
419         struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },
420                                  { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };
421
422         if ((i2c_transfer(&budget->i2c_adap, msg, 2) != 2) || (pwm == 0xff))
423                 pwm = 0x48;
424
425         return pwm;
426 }
427
428 static void frontend_init(struct budget *budget)
429 {
430         (void)alps_bsbe1_config; /* avoid warning */
431
432         switch(budget->dev->pci->subsystem_device) {
433         case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659))
434         case 0x1013:
435                 // try the ALPS BSRV2 first of all
436                 budget->dvb_frontend = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &budget->i2c_adap);
437                 if (budget->dvb_frontend) {
438                         budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
439                         budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
440                         budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
441                         budget->dvb_frontend->ops.set_tone = budget_set_tone;
442                         break;
443                 }
444
445                 // try the ALPS BSRU6 now
446                 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
447                 if (budget->dvb_frontend) {
448                         budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
449                         budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
450                         if (budget->dev->pci->subsystem_device == 0x1003 && diseqc_method == 0) {
451                                 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
452                                 budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
453                                 budget->dvb_frontend->ops.set_tone = budget_set_tone;
454                         }
455                         break;
456                 }
457                 break;
458
459         case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
460
461                 budget->dvb_frontend = dvb_attach(ves1820_attach, &alps_tdbe2_config, &budget->i2c_adap, read_pwm(budget));
462                 if (budget->dvb_frontend) {
463                         budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
464                         break;
465                 }
466                 break;
467
468         case 0x1005: // Hauppauge/TT Nova-T budget (L64781/Grundig 29504-401(tsa5060))
469
470                 budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config, &budget->i2c_adap);
471                 if (budget->dvb_frontend) {
472                         budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
473                         budget->dvb_frontend->tuner_priv = NULL;
474                         break;
475                 }
476                 break;
477
478         case 0x4f60: /* Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/tsa5059) */
479         {
480                 int subtype = i2c_readreg(&budget->i2c_adap, 0x50, 0x67);
481
482                 if (subtype < 0)
483                         break;
484                 /* fixme: find a better way to identify the card */
485                 if (subtype < 0x36) {
486                         /* assume ALPS BSRU6 */
487                         budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config_activy, &budget->i2c_adap);
488                         if (budget->dvb_frontend) {
489                                 printk(KERN_INFO "budget: tuner ALPS BSRU6 detected\n");
490                                 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
491                                 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
492                                 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
493                                 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
494                                 break;
495                         }
496                 } else {
497                         /* assume ALPS BSBE1 */
498                         /* reset tuner */
499                         saa7146_setgpio(budget->dev, 3, SAA7146_GPIO_OUTLO);
500                         msleep(50);
501                         saa7146_setgpio(budget->dev, 3, SAA7146_GPIO_OUTHI);
502                         msleep(250);
503                         budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config_activy, &budget->i2c_adap);
504                         if (budget->dvb_frontend) {
505                                 printk(KERN_INFO "budget: tuner ALPS BSBE1 detected\n");
506                                 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
507                                 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
508                                 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
509                                 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
510                                 break;
511                         }
512                 }
513                 break;
514         }
515
516         case 0x4f61: // Fujitsu Siemens Activy Budget-S PCI rev GR (tda8083/Grundig 29504-451(tsa5522))
517                 budget->dvb_frontend = dvb_attach(tda8083_attach, &grundig_29504_451_config, &budget->i2c_adap);
518                 if (budget->dvb_frontend) {
519                         budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
520                         budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
521                         budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
522                 }
523                 break;
524
525         case 0x5f60: /* Fujitsu Siemens Activy Budget-T PCI rev AL (tda10046/ALPS TDHD1-204A) */
526                 budget->dvb_frontend = dvb_attach(tda10046_attach, &alps_tdhd1_204a_config, &budget->i2c_adap);
527                 if (budget->dvb_frontend) {
528                         budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdhd1_204a_tuner_set_params;
529                         budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
530                 }
531                 break;
532
533         case 0x5f61: /* Fujitsu Siemens Activy Budget-T PCI rev GR (L64781/Grundig 29504-401(tsa5060)) */
534                 budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config_activy, &budget->i2c_adap);
535                 if (budget->dvb_frontend) {
536                         budget->dvb_frontend->tuner_priv = &tuner_address_grundig_29504_401_activy;
537                         budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
538                 }
539                 break;
540
541         case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260))
542                 budget->dvb_frontend = dvb_attach(s5h1420_attach, &s5h1420_config, &budget->i2c_adap);
543                 if (budget->dvb_frontend) {
544                         budget->dvb_frontend->ops.tuner_ops.set_params = s5h1420_tuner_set_params;
545                         if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
546                                 printk("%s: No LNBP21 found!\n", __func__);
547                                 goto error_out;
548                         }
549                         break;
550                 }
551
552         case 0x1018: // TT Budget-S-1401 (philips tda10086/philips tda8262)
553                 // gpio2 is connected to CLB - reset it + leave it high
554                 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTLO);
555                 msleep(1);
556                 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTHI);
557                 msleep(1);
558
559                 budget->dvb_frontend = dvb_attach(tda10086_attach, &tda10086_config, &budget->i2c_adap);
560                 if (budget->dvb_frontend) {
561                         if (dvb_attach(tda826x_attach, budget->dvb_frontend, 0x60, &budget->i2c_adap, 0) == NULL)
562                                 printk("%s: No tda826x found!\n", __func__);
563                         if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
564                                 printk("%s: No LNBP21 found!\n", __func__);
565                                 goto error_out;
566                         }
567                         break;
568                 }
569         }
570
571         if (budget->dvb_frontend == NULL) {
572                 printk("budget: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
573                        budget->dev->pci->vendor,
574                        budget->dev->pci->device,
575                        budget->dev->pci->subsystem_vendor,
576                        budget->dev->pci->subsystem_device);
577         } else {
578                 if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend))
579                         goto error_out;
580         }
581         return;
582
583 error_out:
584         printk("budget: Frontend registration failed!\n");
585         dvb_frontend_detach(budget->dvb_frontend);
586         budget->dvb_frontend = NULL;
587         return;
588 }
589
590 static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
591 {
592         struct budget *budget = NULL;
593         int err;
594
595         budget = kmalloc(sizeof(struct budget), GFP_KERNEL);
596         if( NULL == budget ) {
597                 return -ENOMEM;
598         }
599
600         dprintk(2, "dev:%p, info:%p, budget:%p\n", dev, info, budget);
601
602         dev->ext_priv = budget;
603
604         err = ttpci_budget_init(budget, dev, info, THIS_MODULE, adapter_nr);
605         if (err) {
606                 printk("==> failed\n");
607                 kfree (budget);
608                 return err;
609         }
610
611         budget->dvb_adapter.priv = budget;
612         frontend_init(budget);
613
614         ttpci_budget_init_hooks(budget);
615
616         return 0;
617 }
618
619 static int budget_detach (struct saa7146_dev* dev)
620 {
621         struct budget *budget = (struct budget*) dev->ext_priv;
622         int err;
623
624         if (budget->dvb_frontend) {
625                 dvb_unregister_frontend(budget->dvb_frontend);
626                 dvb_frontend_detach(budget->dvb_frontend);
627         }
628
629         err = ttpci_budget_deinit (budget);
630
631         kfree (budget);
632         dev->ext_priv = NULL;
633
634         return err;
635 }
636
637 static struct saa7146_extension budget_extension;
638
639 MAKE_BUDGET_INFO(ttbs,  "TT-Budget/WinTV-NOVA-S  PCI",  BUDGET_TT);
640 MAKE_BUDGET_INFO(ttbc,  "TT-Budget/WinTV-NOVA-C  PCI",  BUDGET_TT);
641 MAKE_BUDGET_INFO(ttbt,  "TT-Budget/WinTV-NOVA-T  PCI",  BUDGET_TT);
642 MAKE_BUDGET_INFO(satel, "SATELCO Multimedia PCI",       BUDGET_TT_HW_DISEQC);
643 MAKE_BUDGET_INFO(ttbs1401, "TT-Budget-S-1401 PCI", BUDGET_TT);
644 MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY);
645 MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY);
646 MAKE_BUDGET_INFO(fsact,  "Fujitsu Siemens Activy Budget-T PCI (rev GR/Grundig frontend)", BUDGET_FS_ACTIVY);
647 MAKE_BUDGET_INFO(fsact1, "Fujitsu Siemens Activy Budget-T PCI (rev AL/ALPS TDHD1-204A)", BUDGET_FS_ACTIVY);
648
649 static struct pci_device_id pci_tbl[] = {
650         MAKE_EXTENSION_PCI(ttbs,  0x13c2, 0x1003),
651         MAKE_EXTENSION_PCI(ttbc,  0x13c2, 0x1004),
652         MAKE_EXTENSION_PCI(ttbt,  0x13c2, 0x1005),
653         MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
654         MAKE_EXTENSION_PCI(ttbs,  0x13c2, 0x1016),
655         MAKE_EXTENSION_PCI(ttbs1401, 0x13c2, 0x1018),
656         MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
657         MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
658         MAKE_EXTENSION_PCI(fsact1, 0x1131, 0x5f60),
659         MAKE_EXTENSION_PCI(fsact, 0x1131, 0x5f61),
660         {
661                 .vendor    = 0,
662         }
663 };
664
665 MODULE_DEVICE_TABLE(pci, pci_tbl);
666
667 static struct saa7146_extension budget_extension = {
668         .name           = "budget dvb",
669         .flags          = SAA7146_USE_I2C_IRQ,
670
671         .module         = THIS_MODULE,
672         .pci_tbl        = pci_tbl,
673         .attach         = budget_attach,
674         .detach         = budget_detach,
675
676         .irq_mask       = MASK_10,
677         .irq_func       = ttpci_budget_irq10_handler,
678 };
679
680 static int __init budget_init(void)
681 {
682         return saa7146_register_extension(&budget_extension);
683 }
684
685 static void __exit budget_exit(void)
686 {
687         saa7146_unregister_extension(&budget_extension);
688 }
689
690 module_init(budget_init);
691 module_exit(budget_exit);
692
693 MODULE_LICENSE("GPL");
694 MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others");
695 MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
696                    "budget PCI DVB cards by Siemens, Technotrend, Hauppauge");