blob: 874a10a9d493cc594afc29ae15c011376656fefa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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"
Andrew de Quincey96bf2f22005-07-07 17:57:53 -070043#include "s5h1420.h"
Andrew de Quinceyadc619a2006-08-08 09:10:10 -030044#include "tda10086.h"
45#include "tda826x.h"
Oliver Endriss2f27bdc2006-02-28 09:31:16 -030046#include "lnbp21.h"
Perceval Anichini265366e2006-03-16 11:22:47 -030047#include "bsru6.h"
Oliver Endriss87dd9652008-04-20 22:34:57 -030048#include "bsbe1.h"
Oliver Endriss81ae9532008-09-03 18:16:09 -030049#include "tdhd1.h"
Andreas Regel62ad7c12009-04-23 14:59:36 -030050#include "stv6110x.h"
51#include "stv090x.h"
52#include "isl6423.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Oliver Endrissbc495b62006-11-19 02:15:37 -030054static int diseqc_method;
55module_param(diseqc_method, int, 0444);
56MODULE_PARM_DESC(diseqc_method, "Select DiSEqC method for subsystem id 13c2:1003, 0: default, 1: more reliable (for newer revisions only)");
57
Janne Grunau26dc4d02008-09-21 20:50:11 -030058DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060static void Set22K (struct budget *budget, int state)
61{
62 struct saa7146_dev *dev=budget->dev;
63 dprintk(2, "budget: %p\n", budget);
64 saa7146_setgpio(dev, 3, (state ? SAA7146_GPIO_OUTHI : SAA7146_GPIO_OUTLO));
65}
66
67/* Diseqc functions only for TT Budget card */
68/* taken from the Skyvision DVB driver by
69 Ralph Metzler <rjkm@metzlerbros.de> */
70
71static void DiseqcSendBit (struct budget *budget, int data)
72{
73 struct saa7146_dev *dev=budget->dev;
74 dprintk(2, "budget: %p\n", budget);
75
76 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
77 udelay(data ? 500 : 1000);
78 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
79 udelay(data ? 1000 : 500);
80}
81
82static void DiseqcSendByte (struct budget *budget, int data)
83{
84 int i, par=1, d;
85
86 dprintk(2, "budget: %p\n", budget);
87
88 for (i=7; i>=0; i--) {
89 d = (data>>i)&1;
90 par ^= d;
91 DiseqcSendBit(budget, d);
92 }
93
94 DiseqcSendBit(budget, par);
95}
96
97static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long burst)
98{
99 struct saa7146_dev *dev=budget->dev;
100 int i;
101
102 dprintk(2, "budget: %p\n", budget);
103
104 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
105 mdelay(16);
106
107 for (i=0; i<len; i++)
108 DiseqcSendByte(budget, msg[i]);
109
110 mdelay(16);
111
112 if (burst!=-1) {
113 if (burst)
114 DiseqcSendByte(budget, 0xff);
115 else {
116 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
Thierry MERLEdb210422008-09-01 17:28:57 -0300117 mdelay(12);
118 udelay(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
120 }
121 msleep(20);
122 }
123
124 return 0;
125}
126
127/*
128 * Routines for the Fujitsu Siemens Activy budget card
129 * 22 kHz tone and DiSEqC are handled by the frontend.
130 * Voltage must be set here.
Oliver Endrissf49cc152006-01-09 15:25:06 -0200131 * GPIO 1: LNBP EN, GPIO 2: LNBP VSEL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 */
133static int SetVoltage_Activy (struct budget *budget, fe_sec_voltage_t voltage)
134{
135 struct saa7146_dev *dev=budget->dev;
136
137 dprintk(2, "budget: %p\n", budget);
138
139 switch (voltage) {
140 case SEC_VOLTAGE_13:
Oliver Endrissf49cc152006-01-09 15:25:06 -0200141 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTLO);
143 break;
144 case SEC_VOLTAGE_18:
Oliver Endrissf49cc152006-01-09 15:25:06 -0200145 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI);
147 break;
Oliver Endrissf49cc152006-01-09 15:25:06 -0200148 case SEC_VOLTAGE_OFF:
149 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO);
150 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 default:
152 return -EINVAL;
153 }
154
155 return 0;
156}
157
158static int siemens_budget_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
159{
160 struct budget* budget = (struct budget*) fe->dvb->priv;
161
162 return SetVoltage_Activy (budget, voltage);
163}
164
165static int budget_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
166{
167 struct budget* budget = (struct budget*) fe->dvb->priv;
168
169 switch (tone) {
170 case SEC_TONE_ON:
171 Set22K (budget, 1);
172 break;
173
174 case SEC_TONE_OFF:
175 Set22K (budget, 0);
176 break;
177
178 default:
179 return -EINVAL;
180 }
181
182 return 0;
183}
184
185static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
186{
187 struct budget* budget = (struct budget*) fe->dvb->priv;
188
189 SendDiSEqCMsg (budget, cmd->msg_len, cmd->msg, 0);
190
191 return 0;
192}
193
194static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
195{
196 struct budget* budget = (struct budget*) fe->dvb->priv;
197
198 SendDiSEqCMsg (budget, 0, NULL, minicmd);
199
200 return 0;
201}
202
Andrew de Quincey067145b2006-04-18 17:47:11 -0300203static int alps_bsrv2_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
205 struct budget* budget = (struct budget*) fe->dvb->priv;
206 u8 pwr = 0;
207 u8 buf[4];
208 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
209 u32 div = (params->frequency + 479500) / 125;
210
211 if (params->frequency > 2000000) pwr = 3;
212 else if (params->frequency > 1800000) pwr = 2;
213 else if (params->frequency > 1600000) pwr = 1;
214 else if (params->frequency > 1200000) pwr = 0;
215 else if (params->frequency >= 1100000) pwr = 1;
216 else pwr = 2;
217
218 buf[0] = (div >> 8) & 0x7f;
219 buf[1] = div & 0xff;
220 buf[2] = ((div & 0x18000) >> 10) | 0x95;
221 buf[3] = (pwr << 6) | 0x30;
222
Mauro Carvalho Chehab9101e622005-12-12 00:37:24 -0800223 // NOTE: since we're using a prescaler of 2, we set the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 // divisor frequency to 62.5kHz and divide by 125 above
225
Patrick Boettcherdea74862006-05-14 05:01:31 -0300226 if (fe->ops.i2c_gate_ctrl)
227 fe->ops.i2c_gate_ctrl(fe, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
229 return 0;
230}
231
232static struct ves1x93_config alps_bsrv2_config =
233{
234 .demod_address = 0x08,
235 .xin = 90100000UL,
236 .invert_pwm = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237};
238
Andrew de Quincey067145b2006-04-18 17:47:11 -0300239static int alps_tdbe2_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 struct budget* budget = (struct budget*) fe->dvb->priv;
242 u32 div;
243 u8 data[4];
244 struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) };
245
246 div = (params->frequency + 35937500 + 31250) / 62500;
247
248 data[0] = (div >> 8) & 0x7f;
249 data[1] = div & 0xff;
250 data[2] = 0x85 | ((div >> 10) & 0x60);
251 data[3] = (params->frequency < 174000000 ? 0x88 : params->frequency < 470000000 ? 0x84 : 0x81);
252
Patrick Boettcherdea74862006-05-14 05:01:31 -0300253 if (fe->ops.i2c_gate_ctrl)
254 fe->ops.i2c_gate_ctrl(fe, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
256 return 0;
257}
258
259static struct ves1820_config alps_tdbe2_config = {
260 .demod_address = 0x09,
261 .xin = 57840000UL,
262 .invert = 1,
263 .selagc = VES1820_SELAGC_SIGNAMPERR,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264};
265
Andrew de Quincey067145b2006-04-18 17:47:11 -0300266static int grundig_29504_401_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
Oliver Endrissfaea4d22008-04-09 17:49:55 -0300268 struct budget *budget = fe->dvb->priv;
269 u8 *tuner_addr = fe->tuner_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 u32 div;
271 u8 cfg, cpump, band_select;
272 u8 data[4];
Oliver Endrissfaea4d22008-04-09 17:49:55 -0300273 struct i2c_msg msg = { .flags = 0, .buf = data, .len = sizeof(data) };
274
275 if (tuner_addr)
276 msg.addr = *tuner_addr;
277 else
278 msg.addr = 0x61;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 div = (36125000 + params->frequency) / 166666;
281
282 cfg = 0x88;
283
284 if (params->frequency < 175000000) cpump = 2;
285 else if (params->frequency < 390000000) cpump = 1;
286 else if (params->frequency < 470000000) cpump = 2;
287 else if (params->frequency < 750000000) cpump = 1;
288 else cpump = 3;
289
290 if (params->frequency < 175000000) band_select = 0x0e;
291 else if (params->frequency < 470000000) band_select = 0x05;
292 else band_select = 0x03;
293
294 data[0] = (div >> 8) & 0x7f;
295 data[1] = div & 0xff;
296 data[2] = ((div >> 10) & 0x60) | cfg;
297 data[3] = (cpump << 6) | band_select;
298
Patrick Boettcherdea74862006-05-14 05:01:31 -0300299 if (fe->ops.i2c_gate_ctrl)
300 fe->ops.i2c_gate_ctrl(fe, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
302 return 0;
303}
304
305static struct l64781_config grundig_29504_401_config = {
306 .demod_address = 0x55,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307};
308
Oliver Endrissfaea4d22008-04-09 17:49:55 -0300309static struct l64781_config grundig_29504_401_config_activy = {
310 .demod_address = 0x54,
311};
312
313static u8 tuner_address_grundig_29504_401_activy = 0x60;
314
Andrew de Quincey067145b2006-04-18 17:47:11 -0300315static int grundig_29504_451_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
317 struct budget* budget = (struct budget*) fe->dvb->priv;
318 u32 div;
319 u8 data[4];
320 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
321
322 div = params->frequency / 125;
323 data[0] = (div >> 8) & 0x7f;
324 data[1] = div & 0xff;
325 data[2] = 0x8e;
326 data[3] = 0x00;
327
Patrick Boettcherdea74862006-05-14 05:01:31 -0300328 if (fe->ops.i2c_gate_ctrl)
329 fe->ops.i2c_gate_ctrl(fe, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
331 return 0;
332}
333
334static struct tda8083_config grundig_29504_451_config = {
335 .demod_address = 0x68,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336};
337
Andrew de Quincey067145b2006-04-18 17:47:11 -0300338static int s5h1420_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
Andrew de Quincey96bf2f22005-07-07 17:57:53 -0700339{
340 struct budget* budget = (struct budget*) fe->dvb->priv;
341 u32 div;
342 u8 data[4];
343 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
344
345 div = params->frequency / 1000;
346 data[0] = (div >> 8) & 0x7f;
347 data[1] = div & 0xff;
348 data[2] = 0xc2;
349
350 if (div < 1450)
351 data[3] = 0x00;
352 else if (div < 1850)
353 data[3] = 0x40;
354 else if (div < 2000)
355 data[3] = 0x80;
356 else
357 data[3] = 0xc0;
358
Patrick Boettcherdea74862006-05-14 05:01:31 -0300359 if (fe->ops.i2c_gate_ctrl)
360 fe->ops.i2c_gate_ctrl(fe, 1);
Andrew de Quincey96bf2f22005-07-07 17:57:53 -0700361 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
362
Andrew de Quincey96bf2f22005-07-07 17:57:53 -0700363 return 0;
364}
365
366static struct s5h1420_config s5h1420_config = {
367 .demod_address = 0x53,
Andrew de Quinceya9d6a802005-09-09 13:02:31 -0700368 .invert = 1,
Patrick Boettcherdbad1082008-04-13 15:47:53 -0300369 .cdclk_polarity = 1,
Andrew de Quincey96bf2f22005-07-07 17:57:53 -0700370};
371
Andrew de Quinceyadc619a2006-08-08 09:10:10 -0300372static struct tda10086_config tda10086_config = {
373 .demod_address = 0x0e,
374 .invert = 0,
Hartmut Hackmannea75baf2008-02-09 23:54:24 -0300375 .diseqc_tone = 1,
Hartmut Hackmann9a1b04e2008-04-09 23:07:11 -0300376 .xtal_freq = TDA10086_XTAL_16M,
Andrew de Quinceyadc619a2006-08-08 09:10:10 -0300377};
378
Oliver Endriss87dd9652008-04-20 22:34:57 -0300379static struct stv0299_config alps_bsru6_config_activy = {
380 .demod_address = 0x68,
381 .inittab = alps_bsru6_inittab,
382 .mclk = 88000000UL,
383 .invert = 1,
384 .op0_off = 1,
385 .min_delay_ms = 100,
386 .set_symbol_rate = alps_bsru6_set_symbol_rate,
387};
388
389static struct stv0299_config alps_bsbe1_config_activy = {
390 .demod_address = 0x68,
391 .inittab = alps_bsbe1_inittab,
392 .mclk = 88000000UL,
393 .invert = 1,
394 .op0_off = 1,
395 .min_delay_ms = 100,
396 .set_symbol_rate = alps_bsbe1_set_symbol_rate,
397};
398
Oliver Endriss83512e22008-09-04 20:35:19 -0300399static int alps_tdhd1_204_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name)
400{
401 struct budget *budget = (struct budget *)fe->dvb->priv;
402
403 return request_firmware(fw, name, &budget->dev->pci->dev);
404}
405
Oliver Endriss87dd9652008-04-20 22:34:57 -0300406
407static int i2c_readreg(struct i2c_adapter *i2c, u8 adr, u8 reg)
408{
409 u8 val;
410 struct i2c_msg msg[] = {
411 { .addr = adr, .flags = 0, .buf = &reg, .len = 1 },
412 { .addr = adr, .flags = I2C_M_RD, .buf = &val, .len = 1 }
413 };
414
415 return (i2c_transfer(i2c, msg, 2) != 2) ? -EIO : val;
416}
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418static u8 read_pwm(struct budget* budget)
419{
420 u8 b = 0xff;
421 u8 pwm;
422 struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },
423 { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };
424
Mauro Carvalho Chehab9101e622005-12-12 00:37:24 -0800425 if ((i2c_transfer(&budget->i2c_adap, msg, 2) != 2) || (pwm == 0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 pwm = 0x48;
427
428 return pwm;
429}
430
Andreas Regel62ad7c12009-04-23 14:59:36 -0300431static struct stv090x_config tt1600_stv090x_config = {
432 .device = STV0903,
433 .demod_mode = STV090x_SINGLE,
434 .clk_mode = STV090x_CLK_EXT,
435
Andreas Regel93e32cd2010-01-05 19:24:32 -0300436 .xtal = 13500000,
Andreas Regel62ad7c12009-04-23 14:59:36 -0300437 .address = 0x68,
Andreas Regel62ad7c12009-04-23 14:59:36 -0300438
Andreas Regel560db4a2009-04-23 15:00:04 -0300439 .ts1_mode = STV090x_TSMODE_DVBCI,
440 .ts2_mode = STV090x_TSMODE_SERIAL_CONTINUOUS,
Andreas Regel62ad7c12009-04-23 14:59:36 -0300441
442 .repeater_level = STV090x_RPTLEVEL_16,
443
444 .tuner_init = NULL,
Manu Abrahamc5b74b02010-01-23 05:49:08 -0300445 .tuner_sleep = NULL,
Andreas Regel62ad7c12009-04-23 14:59:36 -0300446 .tuner_set_mode = NULL,
447 .tuner_set_frequency = NULL,
448 .tuner_get_frequency = NULL,
449 .tuner_set_bandwidth = NULL,
450 .tuner_get_bandwidth = NULL,
451 .tuner_set_bbgain = NULL,
452 .tuner_get_bbgain = NULL,
453 .tuner_set_refclk = NULL,
454 .tuner_get_status = NULL,
455};
456
457static struct stv6110x_config tt1600_stv6110x_config = {
458 .addr = 0x60,
459 .refclk = 27000000,
Andreas Regel93e32cd2010-01-05 19:24:32 -0300460 .clk_div = 2,
Andreas Regel62ad7c12009-04-23 14:59:36 -0300461};
462
463static struct isl6423_config tt1600_isl6423_config = {
464 .current_max = SEC_CURRENT_515m,
465 .curlim = SEC_CURRENT_LIM_ON,
466 .mod_extern = 1,
467 .addr = 0x08,
468};
469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470static void frontend_init(struct budget *budget)
471{
Oliver Endriss87dd9652008-04-20 22:34:57 -0300472 (void)alps_bsbe1_config; /* avoid warning */
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 switch(budget->dev->pci->subsystem_device) {
475 case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659))
476 case 0x1013:
477 // try the ALPS BSRV2 first of all
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300478 budget->dvb_frontend = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &budget->i2c_adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 if (budget->dvb_frontend) {
Patrick Boettcherdea74862006-05-14 05:01:31 -0300480 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
481 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
482 budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
483 budget->dvb_frontend->ops.set_tone = budget_set_tone;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 break;
485 }
486
487 // try the ALPS BSRU6 now
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300488 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 if (budget->dvb_frontend) {
Patrick Boettcherdea74862006-05-14 05:01:31 -0300490 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
Andrew de Quincey067145b2006-04-18 17:47:11 -0300491 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
Oliver Endrissbc495b62006-11-19 02:15:37 -0300492 if (budget->dev->pci->subsystem_device == 0x1003 && diseqc_method == 0) {
493 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
494 budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
495 budget->dvb_frontend->ops.set_tone = budget_set_tone;
496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 break;
498 }
499 break;
500
501 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
502
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300503 budget->dvb_frontend = dvb_attach(ves1820_attach, &alps_tdbe2_config, &budget->i2c_adap, read_pwm(budget));
Andrew de Quincey067145b2006-04-18 17:47:11 -0300504 if (budget->dvb_frontend) {
Patrick Boettcherdea74862006-05-14 05:01:31 -0300505 budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
Andrew de Quincey067145b2006-04-18 17:47:11 -0300506 break;
507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 break;
509
510 case 0x1005: // Hauppauge/TT Nova-T budget (L64781/Grundig 29504-401(tsa5060))
511
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300512 budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config, &budget->i2c_adap);
Andrew de Quincey067145b2006-04-18 17:47:11 -0300513 if (budget->dvb_frontend) {
Patrick Boettcherdea74862006-05-14 05:01:31 -0300514 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
Tony Broad6dbe7af2009-01-18 07:55:38 -0300515 budget->dvb_frontend->tuner_priv = NULL;
Andrew de Quincey067145b2006-04-18 17:47:11 -0300516 break;
517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 break;
519
Oliver Endriss87dd9652008-04-20 22:34:57 -0300520 case 0x4f60: /* Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/tsa5059) */
521 {
522 int subtype = i2c_readreg(&budget->i2c_adap, 0x50, 0x67);
523
524 if (subtype < 0)
525 break;
526 /* fixme: find a better way to identify the card */
527 if (subtype < 0x36) {
528 /* assume ALPS BSRU6 */
529 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config_activy, &budget->i2c_adap);
530 if (budget->dvb_frontend) {
531 printk(KERN_INFO "budget: tuner ALPS BSRU6 detected\n");
532 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
533 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
534 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
535 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
536 break;
537 }
538 } else {
539 /* assume ALPS BSBE1 */
540 /* reset tuner */
541 saa7146_setgpio(budget->dev, 3, SAA7146_GPIO_OUTLO);
542 msleep(50);
543 saa7146_setgpio(budget->dev, 3, SAA7146_GPIO_OUTHI);
544 msleep(250);
545 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config_activy, &budget->i2c_adap);
546 if (budget->dvb_frontend) {
547 printk(KERN_INFO "budget: tuner ALPS BSBE1 detected\n");
548 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
549 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
550 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
551 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
552 break;
553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 }
555 break;
Oliver Endriss87dd9652008-04-20 22:34:57 -0300556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 case 0x4f61: // Fujitsu Siemens Activy Budget-S PCI rev GR (tda8083/Grundig 29504-451(tsa5522))
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300559 budget->dvb_frontend = dvb_attach(tda8083_attach, &grundig_29504_451_config, &budget->i2c_adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 if (budget->dvb_frontend) {
Patrick Boettcherdea74862006-05-14 05:01:31 -0300561 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
562 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
563 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
565 break;
Andrew de Quincey96bf2f22005-07-07 17:57:53 -0700566
Oliver Endriss81ae9532008-09-03 18:16:09 -0300567 case 0x5f60: /* Fujitsu Siemens Activy Budget-T PCI rev AL (tda10046/ALPS TDHD1-204A) */
568 budget->dvb_frontend = dvb_attach(tda10046_attach, &alps_tdhd1_204a_config, &budget->i2c_adap);
569 if (budget->dvb_frontend) {
570 budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdhd1_204a_tuner_set_params;
571 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
572 }
573 break;
574
Oliver Endrissfaea4d22008-04-09 17:49:55 -0300575 case 0x5f61: /* Fujitsu Siemens Activy Budget-T PCI rev GR (L64781/Grundig 29504-401(tsa5060)) */
576 budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config_activy, &budget->i2c_adap);
577 if (budget->dvb_frontend) {
578 budget->dvb_frontend->tuner_priv = &tuner_address_grundig_29504_401_activy;
579 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
580 }
581 break;
582
Andrew de Quincey96bf2f22005-07-07 17:57:53 -0700583 case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260))
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300584 budget->dvb_frontend = dvb_attach(s5h1420_attach, &s5h1420_config, &budget->i2c_adap);
Andrew de Quincey96bf2f22005-07-07 17:57:53 -0700585 if (budget->dvb_frontend) {
Patrick Boettcherdea74862006-05-14 05:01:31 -0300586 budget->dvb_frontend->ops.tuner_ops.set_params = s5h1420_tuner_set_params;
Andrew de Quinceyadc619a2006-08-08 09:10:10 -0300587 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
Harvey Harrison3ca7fc82008-04-08 23:20:00 -0300588 printk("%s: No LNBP21 found!\n", __func__);
Andrew de Quinceyadc619a2006-08-08 09:10:10 -0300589 goto error_out;
590 }
591 break;
592 }
593
594 case 0x1018: // TT Budget-S-1401 (philips tda10086/philips tda8262)
595 // gpio2 is connected to CLB - reset it + leave it high
596 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTLO);
597 msleep(1);
598 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTHI);
599 msleep(1);
600
601 budget->dvb_frontend = dvb_attach(tda10086_attach, &tda10086_config, &budget->i2c_adap);
602 if (budget->dvb_frontend) {
603 if (dvb_attach(tda826x_attach, budget->dvb_frontend, 0x60, &budget->i2c_adap, 0) == NULL)
Harvey Harrison3ca7fc82008-04-08 23:20:00 -0300604 printk("%s: No tda826x found!\n", __func__);
Andrew de Quinceyadc619a2006-08-08 09:10:10 -0300605 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
Harvey Harrison3ca7fc82008-04-08 23:20:00 -0300606 printk("%s: No LNBP21 found!\n", __func__);
Martin Zwickel9691bb12005-11-08 21:35:10 -0800607 goto error_out;
608 }
Andrew de Quincey96bf2f22005-07-07 17:57:53 -0700609 break;
610 }
Andreas Regel62ad7c12009-04-23 14:59:36 -0300611
612 case 0x101c: { /* TT S2-1600 */
613 struct stv6110x_devctl *ctl;
614 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTLO);
615 msleep(50);
616 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTHI);
617 msleep(250);
618
619 budget->dvb_frontend = dvb_attach(stv090x_attach,
620 &tt1600_stv090x_config,
621 &budget->i2c_adap,
622 STV090x_DEMODULATOR_0);
623
624 if (budget->dvb_frontend) {
625
626 ctl = dvb_attach(stv6110x_attach,
627 budget->dvb_frontend,
628 &tt1600_stv6110x_config,
629 &budget->i2c_adap);
630
Bjørn Morkdd0bbcc2010-03-24 10:30:15 -0300631 if (ctl) {
632 tt1600_stv090x_config.tuner_init = ctl->tuner_init;
633 tt1600_stv090x_config.tuner_sleep = ctl->tuner_sleep;
634 tt1600_stv090x_config.tuner_set_mode = ctl->tuner_set_mode;
635 tt1600_stv090x_config.tuner_set_frequency = ctl->tuner_set_frequency;
636 tt1600_stv090x_config.tuner_get_frequency = ctl->tuner_get_frequency;
637 tt1600_stv090x_config.tuner_set_bandwidth = ctl->tuner_set_bandwidth;
638 tt1600_stv090x_config.tuner_get_bandwidth = ctl->tuner_get_bandwidth;
639 tt1600_stv090x_config.tuner_set_bbgain = ctl->tuner_set_bbgain;
640 tt1600_stv090x_config.tuner_get_bbgain = ctl->tuner_get_bbgain;
641 tt1600_stv090x_config.tuner_set_refclk = ctl->tuner_set_refclk;
642 tt1600_stv090x_config.tuner_get_status = ctl->tuner_get_status;
Andreas Regel62ad7c12009-04-23 14:59:36 -0300643
Bjørn Morkdd0bbcc2010-03-24 10:30:15 -0300644 /* call the init function once to initialize
645 tuner's clock output divider and demod's
646 master clock */
647 if (budget->dvb_frontend->ops.init)
648 budget->dvb_frontend->ops.init(budget->dvb_frontend);
Andreas Regel5817ea02010-02-13 16:48:07 -0300649
Bjørn Morkdd0bbcc2010-03-24 10:30:15 -0300650 if (dvb_attach(isl6423_attach,
651 budget->dvb_frontend,
652 &budget->i2c_adap,
653 &tt1600_isl6423_config) == NULL) {
654 printk(KERN_ERR "%s: No Intersil ISL6423 found!\n", __func__);
655 goto error_out;
656 }
657 } else {
658 printk(KERN_ERR "%s: No STV6110(A) Silicon Tuner found!\n", __func__);
659 goto error_out;
660 }
Andreas Regel62ad7c12009-04-23 14:59:36 -0300661 }
662 }
663 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 }
665
666 if (budget->dvb_frontend == NULL) {
Bjorn Helgaas29e66a62008-09-04 17:24:51 -0300667 printk("budget: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 budget->dev->pci->vendor,
669 budget->dev->pci->device,
670 budget->dev->pci->subsystem_vendor,
671 budget->dev->pci->subsystem_device);
672 } else {
Martin Zwickel9691bb12005-11-08 21:35:10 -0800673 if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend))
674 goto error_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 }
Martin Zwickel9691bb12005-11-08 21:35:10 -0800676 return;
677
678error_out:
679 printk("budget: Frontend registration failed!\n");
Andrew de Quinceyf52a8382006-08-08 09:10:09 -0300680 dvb_frontend_detach(budget->dvb_frontend);
Martin Zwickel9691bb12005-11-08 21:35:10 -0800681 budget->dvb_frontend = NULL;
682 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
685static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
686{
687 struct budget *budget = NULL;
688 int err;
689
690 budget = kmalloc(sizeof(struct budget), GFP_KERNEL);
691 if( NULL == budget ) {
692 return -ENOMEM;
693 }
694
695 dprintk(2, "dev:%p, info:%p, budget:%p\n", dev, info, budget);
696
697 dev->ext_priv = budget;
698
Janne Grunau26dc4d02008-09-21 20:50:11 -0300699 err = ttpci_budget_init(budget, dev, info, THIS_MODULE, adapter_nr);
700 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 printk("==> failed\n");
702 kfree (budget);
703 return err;
704 }
705
Johannes Stezenbachfdc53a62005-05-16 21:54:39 -0700706 budget->dvb_adapter.priv = budget;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 frontend_init(budget);
708
Oliver Endriss32e4c3a2006-07-18 22:55:23 -0300709 ttpci_budget_init_hooks(budget);
710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 return 0;
712}
713
714static int budget_detach (struct saa7146_dev* dev)
715{
716 struct budget *budget = (struct budget*) dev->ext_priv;
717 int err;
718
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300719 if (budget->dvb_frontend) {
720 dvb_unregister_frontend(budget->dvb_frontend);
Andrew de Quinceyf52a8382006-08-08 09:10:09 -0300721 dvb_frontend_detach(budget->dvb_frontend);
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300722 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 err = ttpci_budget_deinit (budget);
725
726 kfree (budget);
727 dev->ext_priv = NULL;
728
729 return err;
730}
731
732static struct saa7146_extension budget_extension;
733
734MAKE_BUDGET_INFO(ttbs, "TT-Budget/WinTV-NOVA-S PCI", BUDGET_TT);
735MAKE_BUDGET_INFO(ttbc, "TT-Budget/WinTV-NOVA-C PCI", BUDGET_TT);
736MAKE_BUDGET_INFO(ttbt, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
737MAKE_BUDGET_INFO(satel, "SATELCO Multimedia PCI", BUDGET_TT_HW_DISEQC);
Andrew de Quinceyadc619a2006-08-08 09:10:10 -0300738MAKE_BUDGET_INFO(ttbs1401, "TT-Budget-S-1401 PCI", BUDGET_TT);
Andreas Regel62ad7c12009-04-23 14:59:36 -0300739MAKE_BUDGET_INFO(tt1600, "TT-Budget S2-1600 PCI", BUDGET_TT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY);
741MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY);
Oliver Endrissfaea4d22008-04-09 17:49:55 -0300742MAKE_BUDGET_INFO(fsact, "Fujitsu Siemens Activy Budget-T PCI (rev GR/Grundig frontend)", BUDGET_FS_ACTIVY);
Oliver Endriss81ae9532008-09-03 18:16:09 -0300743MAKE_BUDGET_INFO(fsact1, "Fujitsu Siemens Activy Budget-T PCI (rev AL/ALPS TDHD1-204A)", BUDGET_FS_ACTIVY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745static struct pci_device_id pci_tbl[] = {
746 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1003),
747 MAKE_EXTENSION_PCI(ttbc, 0x13c2, 0x1004),
748 MAKE_EXTENSION_PCI(ttbt, 0x13c2, 0x1005),
749 MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
Andrew de Quincey96bf2f22005-07-07 17:57:53 -0700750 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1016),
Andrew de Quinceyadc619a2006-08-08 09:10:10 -0300751 MAKE_EXTENSION_PCI(ttbs1401, 0x13c2, 0x1018),
Andreas Regel62ad7c12009-04-23 14:59:36 -0300752 MAKE_EXTENSION_PCI(tt1600, 0x13c2, 0x101c),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
754 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
Oliver Endriss81ae9532008-09-03 18:16:09 -0300755 MAKE_EXTENSION_PCI(fsact1, 0x1131, 0x5f60),
Oliver Endrissfaea4d22008-04-09 17:49:55 -0300756 MAKE_EXTENSION_PCI(fsact, 0x1131, 0x5f61),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 {
758 .vendor = 0,
759 }
760};
761
762MODULE_DEVICE_TABLE(pci, pci_tbl);
763
764static struct saa7146_extension budget_extension = {
Dave Jones0e367a12006-08-07 13:18:56 -0300765 .name = "budget dvb",
Oliver Endriss00c4cc62006-11-01 13:09:51 -0300766 .flags = SAA7146_USE_I2C_IRQ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 .module = THIS_MODULE,
769 .pci_tbl = pci_tbl,
770 .attach = budget_attach,
771 .detach = budget_detach,
772
773 .irq_mask = MASK_10,
774 .irq_func = ttpci_budget_irq10_handler,
775};
776
777static int __init budget_init(void)
778{
779 return saa7146_register_extension(&budget_extension);
780}
781
782static void __exit budget_exit(void)
783{
784 saa7146_unregister_extension(&budget_extension);
785}
786
787module_init(budget_init);
788module_exit(budget_exit);
789
790MODULE_LICENSE("GPL");
791MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others");
792MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
793 "budget PCI DVB cards by Siemens, Technotrend, Hauppauge");