2 * budget.c: driver for the SAA7146 based Budget DVB cards
4 * Compiled from various sources by Michael Hunold <michael@mihu.de>
6 * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
8 * Copyright (C) 1999-2002 Ralph Metzler
9 * & Marcus Metzler for convergence integrated media GmbH
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
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.
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.
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
34 * the project's page is at http://www.linuxtv.org/dvb/
47 static void Set22K (struct budget *budget, int state)
49 struct saa7146_dev *dev=budget->dev;
50 dprintk(2, "budget: %p\n", budget);
51 saa7146_setgpio(dev, 3, (state ? SAA7146_GPIO_OUTHI : SAA7146_GPIO_OUTLO));
54 /* Diseqc functions only for TT Budget card */
55 /* taken from the Skyvision DVB driver by
56 Ralph Metzler <rjkm@metzlerbros.de> */
58 static void DiseqcSendBit (struct budget *budget, int data)
60 struct saa7146_dev *dev=budget->dev;
61 dprintk(2, "budget: %p\n", budget);
63 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
64 udelay(data ? 500 : 1000);
65 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
66 udelay(data ? 1000 : 500);
69 static void DiseqcSendByte (struct budget *budget, int data)
73 dprintk(2, "budget: %p\n", budget);
75 for (i=7; i>=0; i--) {
78 DiseqcSendBit(budget, d);
81 DiseqcSendBit(budget, par);
84 static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long burst)
86 struct saa7146_dev *dev=budget->dev;
89 dprintk(2, "budget: %p\n", budget);
91 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
95 DiseqcSendByte(budget, msg[i]);
101 DiseqcSendByte(budget, 0xff);
103 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
105 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
114 * Routines for the Fujitsu Siemens Activy budget card
115 * 22 kHz tone and DiSEqC are handled by the frontend.
116 * Voltage must be set here.
117 * GPIO 1: LNBP EN, GPIO 2: LNBP VSEL
119 static int SetVoltage_Activy (struct budget *budget, fe_sec_voltage_t voltage)
121 struct saa7146_dev *dev=budget->dev;
123 dprintk(2, "budget: %p\n", budget);
127 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
128 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTLO);
131 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
132 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI);
134 case SEC_VOLTAGE_OFF:
135 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO);
144 static int siemens_budget_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
146 struct budget* budget = (struct budget*) fe->dvb->priv;
148 return SetVoltage_Activy (budget, voltage);
151 static int budget_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
153 struct budget* budget = (struct budget*) fe->dvb->priv;
171 static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
173 struct budget* budget = (struct budget*) fe->dvb->priv;
175 SendDiSEqCMsg (budget, cmd->msg_len, cmd->msg, 0);
180 static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
182 struct budget* budget = (struct budget*) fe->dvb->priv;
184 SendDiSEqCMsg (budget, 0, NULL, minicmd);
189 static int alps_bsrv2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
191 struct budget* budget = (struct budget*) fe->dvb->priv;
194 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
195 u32 div = (params->frequency + 479500) / 125;
197 if (params->frequency > 2000000) pwr = 3;
198 else if (params->frequency > 1800000) pwr = 2;
199 else if (params->frequency > 1600000) pwr = 1;
200 else if (params->frequency > 1200000) pwr = 0;
201 else if (params->frequency >= 1100000) pwr = 1;
204 buf[0] = (div >> 8) & 0x7f;
206 buf[2] = ((div & 0x18000) >> 10) | 0x95;
207 buf[3] = (pwr << 6) | 0x30;
209 // NOTE: since we're using a prescaler of 2, we set the
210 // divisor frequency to 62.5kHz and divide by 125 above
212 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
216 static struct ves1x93_config alps_bsrv2_config =
218 .demod_address = 0x08,
221 .pll_set = alps_bsrv2_pll_set,
224 static int alps_tdbe2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
226 struct budget* budget = (struct budget*) fe->dvb->priv;
229 struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) };
231 div = (params->frequency + 35937500 + 31250) / 62500;
233 data[0] = (div >> 8) & 0x7f;
234 data[1] = div & 0xff;
235 data[2] = 0x85 | ((div >> 10) & 0x60);
236 data[3] = (params->frequency < 174000000 ? 0x88 : params->frequency < 470000000 ? 0x84 : 0x81);
238 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
242 static struct ves1820_config alps_tdbe2_config = {
243 .demod_address = 0x09,
246 .selagc = VES1820_SELAGC_SIGNAMPERR,
247 .pll_set = alps_tdbe2_pll_set,
250 static int grundig_29504_401_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
252 struct budget* budget = (struct budget*) fe->dvb->priv;
254 u8 cfg, cpump, band_select;
256 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
258 div = (36125000 + params->frequency) / 166666;
262 if (params->frequency < 175000000) cpump = 2;
263 else if (params->frequency < 390000000) cpump = 1;
264 else if (params->frequency < 470000000) cpump = 2;
265 else if (params->frequency < 750000000) cpump = 1;
268 if (params->frequency < 175000000) band_select = 0x0e;
269 else if (params->frequency < 470000000) band_select = 0x05;
270 else band_select = 0x03;
272 data[0] = (div >> 8) & 0x7f;
273 data[1] = div & 0xff;
274 data[2] = ((div >> 10) & 0x60) | cfg;
275 data[3] = (cpump << 6) | band_select;
277 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
281 static struct l64781_config grundig_29504_401_config = {
282 .demod_address = 0x55,
283 .pll_set = grundig_29504_401_pll_set,
286 static int grundig_29504_451_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
288 struct budget* budget = (struct budget*) fe->dvb->priv;
291 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
293 div = params->frequency / 125;
294 data[0] = (div >> 8) & 0x7f;
295 data[1] = div & 0xff;
299 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
303 static struct tda8083_config grundig_29504_451_config = {
304 .demod_address = 0x68,
305 .pll_set = grundig_29504_451_pll_set,
308 static int s5h1420_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u32* freqout)
310 struct budget* budget = (struct budget*) fe->dvb->priv;
313 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
315 div = params->frequency / 1000;
316 data[0] = (div >> 8) & 0x7f;
317 data[1] = div & 0xff;
329 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
331 *freqout = div * 1000;
335 static struct s5h1420_config s5h1420_config = {
336 .demod_address = 0x53,
338 .pll_set = s5h1420_pll_set,
341 static u8 read_pwm(struct budget* budget)
345 struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },
346 { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };
348 if ((i2c_transfer(&budget->i2c_adap, msg, 2) != 2) || (pwm == 0xff))
354 static void frontend_init(struct budget *budget)
356 switch(budget->dev->pci->subsystem_device) {
357 case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659))
359 // try the ALPS BSRV2 first of all
360 budget->dvb_frontend = ves1x93_attach(&alps_bsrv2_config, &budget->i2c_adap);
361 if (budget->dvb_frontend) {
362 budget->dvb_frontend->ops->diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
363 budget->dvb_frontend->ops->diseqc_send_burst = budget_diseqc_send_burst;
364 budget->dvb_frontend->ops->set_tone = budget_set_tone;
368 // try the ALPS BSRU6 now
369 budget->dvb_frontend = stv0299_attach(&alps_bsru6_config, &budget->i2c_adap);
370 if (budget->dvb_frontend) {
371 budget->dvb_frontend->ops->diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
372 budget->dvb_frontend->ops->diseqc_send_burst = budget_diseqc_send_burst;
373 budget->dvb_frontend->ops->set_tone = budget_set_tone;
378 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
380 budget->dvb_frontend = ves1820_attach(&alps_tdbe2_config, &budget->i2c_adap, read_pwm(budget));
381 if (budget->dvb_frontend) break;
384 case 0x1005: // Hauppauge/TT Nova-T budget (L64781/Grundig 29504-401(tsa5060))
386 budget->dvb_frontend = l64781_attach(&grundig_29504_401_config, &budget->i2c_adap);
387 if (budget->dvb_frontend) break;
390 case 0x4f60: // Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/ALPS BSRU6(tsa5059))
391 budget->dvb_frontend = stv0299_attach(&alps_bsru6_config, &budget->i2c_adap);
392 if (budget->dvb_frontend) {
393 budget->dvb_frontend->ops->set_voltage = siemens_budget_set_voltage;
394 budget->dvb_frontend->ops->dishnetwork_send_legacy_command = NULL;
398 case 0x4f61: // Fujitsu Siemens Activy Budget-S PCI rev GR (tda8083/Grundig 29504-451(tsa5522))
399 budget->dvb_frontend = tda8083_attach(&grundig_29504_451_config, &budget->i2c_adap);
400 if (budget->dvb_frontend) {
401 budget->dvb_frontend->ops->set_voltage = siemens_budget_set_voltage;
402 budget->dvb_frontend->ops->dishnetwork_send_legacy_command = NULL;
406 case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260))
407 budget->dvb_frontend = s5h1420_attach(&s5h1420_config, &budget->i2c_adap);
408 if (budget->dvb_frontend) {
409 if (lnbp21_init(budget->dvb_frontend, &budget->i2c_adap, 0, 0)) {
410 printk("%s: No LNBP21 found!\n", __FUNCTION__);
417 if (budget->dvb_frontend == NULL) {
418 printk("budget: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
419 budget->dev->pci->vendor,
420 budget->dev->pci->device,
421 budget->dev->pci->subsystem_vendor,
422 budget->dev->pci->subsystem_device);
424 if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend))
430 printk("budget: Frontend registration failed!\n");
431 if (budget->dvb_frontend->ops->release)
432 budget->dvb_frontend->ops->release(budget->dvb_frontend);
433 budget->dvb_frontend = NULL;
437 static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
439 struct budget *budget = NULL;
442 budget = kmalloc(sizeof(struct budget), GFP_KERNEL);
443 if( NULL == budget ) {
447 dprintk(2, "dev:%p, info:%p, budget:%p\n", dev, info, budget);
449 dev->ext_priv = budget;
451 if ((err = ttpci_budget_init (budget, dev, info, THIS_MODULE))) {
452 printk("==> failed\n");
457 budget->dvb_adapter.priv = budget;
458 frontend_init(budget);
463 static int budget_detach (struct saa7146_dev* dev)
465 struct budget *budget = (struct budget*) dev->ext_priv;
468 if (budget->dvb_frontend) dvb_unregister_frontend(budget->dvb_frontend);
470 err = ttpci_budget_deinit (budget);
473 dev->ext_priv = NULL;
478 static struct saa7146_extension budget_extension;
480 MAKE_BUDGET_INFO(ttbs, "TT-Budget/WinTV-NOVA-S PCI", BUDGET_TT);
481 MAKE_BUDGET_INFO(ttbc, "TT-Budget/WinTV-NOVA-C PCI", BUDGET_TT);
482 MAKE_BUDGET_INFO(ttbt, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
483 MAKE_BUDGET_INFO(satel, "SATELCO Multimedia PCI", BUDGET_TT_HW_DISEQC);
484 MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY);
485 MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY);
487 static struct pci_device_id pci_tbl[] = {
488 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1003),
489 MAKE_EXTENSION_PCI(ttbc, 0x13c2, 0x1004),
490 MAKE_EXTENSION_PCI(ttbt, 0x13c2, 0x1005),
491 MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
492 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1016),
493 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
494 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
500 MODULE_DEVICE_TABLE(pci, pci_tbl);
502 static struct saa7146_extension budget_extension = {
503 .name = "budget dvb\0",
504 .flags = SAA7146_I2C_SHORT_DELAY,
506 .module = THIS_MODULE,
508 .attach = budget_attach,
509 .detach = budget_detach,
512 .irq_func = ttpci_budget_irq10_handler,
515 static int __init budget_init(void)
517 return saa7146_register_extension(&budget_extension);
520 static void __exit budget_exit(void)
522 saa7146_unregister_extension(&budget_extension);
525 module_init(budget_init);
526 module_exit(budget_exit);
528 MODULE_LICENSE("GPL");
529 MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others");
530 MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
531 "budget PCI DVB cards by Siemens, Technotrend, Hauppauge");