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