iwlwifi: introduce host commands callbacks
[linux/fpc-iii.git] / drivers / media / dvb / ttpci / budget.c
blob14b00f57b5de80ce18d57211dd5c6b9e8c6179da
1 /*
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/
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"
49 static int diseqc_method;
50 module_param(diseqc_method, int, 0444);
51 MODULE_PARM_DESC(diseqc_method, "Select DiSEqC method for subsystem id 13c2:1003, 0: default, 1: more reliable (for newer revisions only)");
53 static void Set22K (struct budget *budget, int state)
55 struct saa7146_dev *dev=budget->dev;
56 dprintk(2, "budget: %p\n", budget);
57 saa7146_setgpio(dev, 3, (state ? SAA7146_GPIO_OUTHI : SAA7146_GPIO_OUTLO));
60 /* Diseqc functions only for TT Budget card */
61 /* taken from the Skyvision DVB driver by
62 Ralph Metzler <rjkm@metzlerbros.de> */
64 static void DiseqcSendBit (struct budget *budget, int data)
66 struct saa7146_dev *dev=budget->dev;
67 dprintk(2, "budget: %p\n", budget);
69 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
70 udelay(data ? 500 : 1000);
71 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
72 udelay(data ? 1000 : 500);
75 static void DiseqcSendByte (struct budget *budget, int data)
77 int i, par=1, d;
79 dprintk(2, "budget: %p\n", budget);
81 for (i=7; i>=0; i--) {
82 d = (data>>i)&1;
83 par ^= d;
84 DiseqcSendBit(budget, d);
87 DiseqcSendBit(budget, par);
90 static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long burst)
92 struct saa7146_dev *dev=budget->dev;
93 int i;
95 dprintk(2, "budget: %p\n", budget);
97 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
98 mdelay(16);
100 for (i=0; i<len; i++)
101 DiseqcSendByte(budget, msg[i]);
103 mdelay(16);
105 if (burst!=-1) {
106 if (burst)
107 DiseqcSendByte(budget, 0xff);
108 else {
109 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
110 udelay(12500);
111 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
113 msleep(20);
116 return 0;
120 * Routines for the Fujitsu Siemens Activy budget card
121 * 22 kHz tone and DiSEqC are handled by the frontend.
122 * Voltage must be set here.
123 * GPIO 1: LNBP EN, GPIO 2: LNBP VSEL
125 static int SetVoltage_Activy (struct budget *budget, fe_sec_voltage_t voltage)
127 struct saa7146_dev *dev=budget->dev;
129 dprintk(2, "budget: %p\n", budget);
131 switch (voltage) {
132 case SEC_VOLTAGE_13:
133 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
134 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTLO);
135 break;
136 case SEC_VOLTAGE_18:
137 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
138 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI);
139 break;
140 case SEC_VOLTAGE_OFF:
141 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO);
142 break;
143 default:
144 return -EINVAL;
147 return 0;
150 static int siemens_budget_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
152 struct budget* budget = (struct budget*) fe->dvb->priv;
154 return SetVoltage_Activy (budget, voltage);
157 static int budget_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
159 struct budget* budget = (struct budget*) fe->dvb->priv;
161 switch (tone) {
162 case SEC_TONE_ON:
163 Set22K (budget, 1);
164 break;
166 case SEC_TONE_OFF:
167 Set22K (budget, 0);
168 break;
170 default:
171 return -EINVAL;
174 return 0;
177 static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
179 struct budget* budget = (struct budget*) fe->dvb->priv;
181 SendDiSEqCMsg (budget, cmd->msg_len, cmd->msg, 0);
183 return 0;
186 static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
188 struct budget* budget = (struct budget*) fe->dvb->priv;
190 SendDiSEqCMsg (budget, 0, NULL, minicmd);
192 return 0;
195 static int alps_bsrv2_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
197 struct budget* budget = (struct budget*) fe->dvb->priv;
198 u8 pwr = 0;
199 u8 buf[4];
200 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
201 u32 div = (params->frequency + 479500) / 125;
203 if (params->frequency > 2000000) pwr = 3;
204 else if (params->frequency > 1800000) pwr = 2;
205 else if (params->frequency > 1600000) pwr = 1;
206 else if (params->frequency > 1200000) pwr = 0;
207 else if (params->frequency >= 1100000) pwr = 1;
208 else pwr = 2;
210 buf[0] = (div >> 8) & 0x7f;
211 buf[1] = div & 0xff;
212 buf[2] = ((div & 0x18000) >> 10) | 0x95;
213 buf[3] = (pwr << 6) | 0x30;
215 // NOTE: since we're using a prescaler of 2, we set the
216 // divisor frequency to 62.5kHz and divide by 125 above
218 if (fe->ops.i2c_gate_ctrl)
219 fe->ops.i2c_gate_ctrl(fe, 1);
220 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
221 return 0;
224 static struct ves1x93_config alps_bsrv2_config =
226 .demod_address = 0x08,
227 .xin = 90100000UL,
228 .invert_pwm = 0,
231 static int alps_tdbe2_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
233 struct budget* budget = (struct budget*) fe->dvb->priv;
234 u32 div;
235 u8 data[4];
236 struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) };
238 div = (params->frequency + 35937500 + 31250) / 62500;
240 data[0] = (div >> 8) & 0x7f;
241 data[1] = div & 0xff;
242 data[2] = 0x85 | ((div >> 10) & 0x60);
243 data[3] = (params->frequency < 174000000 ? 0x88 : params->frequency < 470000000 ? 0x84 : 0x81);
245 if (fe->ops.i2c_gate_ctrl)
246 fe->ops.i2c_gate_ctrl(fe, 1);
247 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
248 return 0;
251 static struct ves1820_config alps_tdbe2_config = {
252 .demod_address = 0x09,
253 .xin = 57840000UL,
254 .invert = 1,
255 .selagc = VES1820_SELAGC_SIGNAMPERR,
258 static int grundig_29504_401_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
260 struct budget* budget = (struct budget*) fe->dvb->priv;
261 u32 div;
262 u8 cfg, cpump, band_select;
263 u8 data[4];
264 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
266 div = (36125000 + params->frequency) / 166666;
268 cfg = 0x88;
270 if (params->frequency < 175000000) cpump = 2;
271 else if (params->frequency < 390000000) cpump = 1;
272 else if (params->frequency < 470000000) cpump = 2;
273 else if (params->frequency < 750000000) cpump = 1;
274 else cpump = 3;
276 if (params->frequency < 175000000) band_select = 0x0e;
277 else if (params->frequency < 470000000) band_select = 0x05;
278 else band_select = 0x03;
280 data[0] = (div >> 8) & 0x7f;
281 data[1] = div & 0xff;
282 data[2] = ((div >> 10) & 0x60) | cfg;
283 data[3] = (cpump << 6) | band_select;
285 if (fe->ops.i2c_gate_ctrl)
286 fe->ops.i2c_gate_ctrl(fe, 1);
287 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
288 return 0;
291 static struct l64781_config grundig_29504_401_config = {
292 .demod_address = 0x55,
295 static int grundig_29504_451_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
297 struct budget* budget = (struct budget*) fe->dvb->priv;
298 u32 div;
299 u8 data[4];
300 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
302 div = params->frequency / 125;
303 data[0] = (div >> 8) & 0x7f;
304 data[1] = div & 0xff;
305 data[2] = 0x8e;
306 data[3] = 0x00;
308 if (fe->ops.i2c_gate_ctrl)
309 fe->ops.i2c_gate_ctrl(fe, 1);
310 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
311 return 0;
314 static struct tda8083_config grundig_29504_451_config = {
315 .demod_address = 0x68,
318 static int s5h1420_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
320 struct budget* budget = (struct budget*) fe->dvb->priv;
321 u32 div;
322 u8 data[4];
323 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
325 div = params->frequency / 1000;
326 data[0] = (div >> 8) & 0x7f;
327 data[1] = div & 0xff;
328 data[2] = 0xc2;
330 if (div < 1450)
331 data[3] = 0x00;
332 else if (div < 1850)
333 data[3] = 0x40;
334 else if (div < 2000)
335 data[3] = 0x80;
336 else
337 data[3] = 0xc0;
339 if (fe->ops.i2c_gate_ctrl)
340 fe->ops.i2c_gate_ctrl(fe, 1);
341 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
343 return 0;
346 static struct s5h1420_config s5h1420_config = {
347 .demod_address = 0x53,
348 .invert = 1,
351 static struct tda10086_config tda10086_config = {
352 .demod_address = 0x0e,
353 .invert = 0,
354 .diseqc_tone = 1,
357 static u8 read_pwm(struct budget* budget)
359 u8 b = 0xff;
360 u8 pwm;
361 struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },
362 { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };
364 if ((i2c_transfer(&budget->i2c_adap, msg, 2) != 2) || (pwm == 0xff))
365 pwm = 0x48;
367 return pwm;
370 static void frontend_init(struct budget *budget)
372 switch(budget->dev->pci->subsystem_device) {
373 case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659))
374 case 0x1013:
375 // try the ALPS BSRV2 first of all
376 budget->dvb_frontend = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &budget->i2c_adap);
377 if (budget->dvb_frontend) {
378 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
379 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
380 budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
381 budget->dvb_frontend->ops.set_tone = budget_set_tone;
382 break;
385 // try the ALPS BSRU6 now
386 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
387 if (budget->dvb_frontend) {
388 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
389 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
390 if (budget->dev->pci->subsystem_device == 0x1003 && diseqc_method == 0) {
391 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
392 budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
393 budget->dvb_frontend->ops.set_tone = budget_set_tone;
395 break;
397 break;
399 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
401 budget->dvb_frontend = dvb_attach(ves1820_attach, &alps_tdbe2_config, &budget->i2c_adap, read_pwm(budget));
402 if (budget->dvb_frontend) {
403 budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
404 break;
406 break;
408 case 0x1005: // Hauppauge/TT Nova-T budget (L64781/Grundig 29504-401(tsa5060))
410 budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config, &budget->i2c_adap);
411 if (budget->dvb_frontend) {
412 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
413 break;
415 break;
417 case 0x4f60: // Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/ALPS BSRU6(tsa5059))
418 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
419 if (budget->dvb_frontend) {
420 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
421 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
422 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
423 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
425 break;
427 case 0x4f61: // Fujitsu Siemens Activy Budget-S PCI rev GR (tda8083/Grundig 29504-451(tsa5522))
428 budget->dvb_frontend = dvb_attach(tda8083_attach, &grundig_29504_451_config, &budget->i2c_adap);
429 if (budget->dvb_frontend) {
430 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
431 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
432 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
434 break;
436 case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260))
437 budget->dvb_frontend = dvb_attach(s5h1420_attach, &s5h1420_config, &budget->i2c_adap);
438 if (budget->dvb_frontend) {
439 budget->dvb_frontend->ops.tuner_ops.set_params = s5h1420_tuner_set_params;
440 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
441 printk("%s: No LNBP21 found!\n", __FUNCTION__);
442 goto error_out;
444 break;
447 case 0x1018: // TT Budget-S-1401 (philips tda10086/philips tda8262)
448 // gpio2 is connected to CLB - reset it + leave it high
449 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTLO);
450 msleep(1);
451 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTHI);
452 msleep(1);
454 budget->dvb_frontend = dvb_attach(tda10086_attach, &tda10086_config, &budget->i2c_adap);
455 if (budget->dvb_frontend) {
456 if (dvb_attach(tda826x_attach, budget->dvb_frontend, 0x60, &budget->i2c_adap, 0) == NULL)
457 printk("%s: No tda826x found!\n", __FUNCTION__);
458 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
459 printk("%s: No LNBP21 found!\n", __FUNCTION__);
460 goto error_out;
462 break;
466 if (budget->dvb_frontend == NULL) {
467 printk("budget: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
468 budget->dev->pci->vendor,
469 budget->dev->pci->device,
470 budget->dev->pci->subsystem_vendor,
471 budget->dev->pci->subsystem_device);
472 } else {
473 if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend))
474 goto error_out;
476 return;
478 error_out:
479 printk("budget: Frontend registration failed!\n");
480 dvb_frontend_detach(budget->dvb_frontend);
481 budget->dvb_frontend = NULL;
482 return;
485 static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
487 struct budget *budget = NULL;
488 int err;
490 budget = kmalloc(sizeof(struct budget), GFP_KERNEL);
491 if( NULL == budget ) {
492 return -ENOMEM;
495 dprintk(2, "dev:%p, info:%p, budget:%p\n", dev, info, budget);
497 dev->ext_priv = budget;
499 if ((err = ttpci_budget_init (budget, dev, info, THIS_MODULE))) {
500 printk("==> failed\n");
501 kfree (budget);
502 return err;
505 budget->dvb_adapter.priv = budget;
506 frontend_init(budget);
508 ttpci_budget_init_hooks(budget);
510 return 0;
513 static int budget_detach (struct saa7146_dev* dev)
515 struct budget *budget = (struct budget*) dev->ext_priv;
516 int err;
518 if (budget->dvb_frontend) {
519 dvb_unregister_frontend(budget->dvb_frontend);
520 dvb_frontend_detach(budget->dvb_frontend);
523 err = ttpci_budget_deinit (budget);
525 kfree (budget);
526 dev->ext_priv = NULL;
528 return err;
531 static struct saa7146_extension budget_extension;
533 MAKE_BUDGET_INFO(ttbs, "TT-Budget/WinTV-NOVA-S PCI", BUDGET_TT);
534 MAKE_BUDGET_INFO(ttbc, "TT-Budget/WinTV-NOVA-C PCI", BUDGET_TT);
535 MAKE_BUDGET_INFO(ttbt, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
536 MAKE_BUDGET_INFO(satel, "SATELCO Multimedia PCI", BUDGET_TT_HW_DISEQC);
537 MAKE_BUDGET_INFO(ttbs1401, "TT-Budget-S-1401 PCI", BUDGET_TT);
538 MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY);
539 MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY);
541 static struct pci_device_id pci_tbl[] = {
542 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1003),
543 MAKE_EXTENSION_PCI(ttbc, 0x13c2, 0x1004),
544 MAKE_EXTENSION_PCI(ttbt, 0x13c2, 0x1005),
545 MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
546 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1016),
547 MAKE_EXTENSION_PCI(ttbs1401, 0x13c2, 0x1018),
548 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
549 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
551 .vendor = 0,
555 MODULE_DEVICE_TABLE(pci, pci_tbl);
557 static struct saa7146_extension budget_extension = {
558 .name = "budget dvb",
559 .flags = SAA7146_USE_I2C_IRQ,
561 .module = THIS_MODULE,
562 .pci_tbl = pci_tbl,
563 .attach = budget_attach,
564 .detach = budget_detach,
566 .irq_mask = MASK_10,
567 .irq_func = ttpci_budget_irq10_handler,
570 static int __init budget_init(void)
572 return saa7146_register_extension(&budget_extension);
575 static void __exit budget_exit(void)
577 saa7146_unregister_extension(&budget_extension);
580 module_init(budget_init);
581 module_exit(budget_exit);
583 MODULE_LICENSE("GPL");
584 MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others");
585 MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
586 "budget PCI DVB cards by Siemens, Technotrend, Hauppauge");