2 * budget-ci.c: driver for the SAA7146 based Budget DVB cards
4 * Compiled from various sources by Michael Hunold <michael@mihu.de>
6 * msp430 IR support contributed by Jack Thomasson <jkt@Helius.COM>
7 * partially based on the Siemens DVB driver by Ralph+Marcus Metzler
9 * CI interface support (c) 2004 Andrew de Quincey <adq_dvb@lidskialf.net>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
29 * the project's page is at http://www.linuxtv.org/dvb/
34 #include <linux/module.h>
35 #include <linux/errno.h>
36 #include <linux/slab.h>
37 #include <linux/interrupt.h>
38 #include <linux/input.h>
39 #include <linux/spinlock.h>
41 #include "dvb_ca_en50221.h"
45 #define DEBIADDR_IR 0x1234
46 #define DEBIADDR_CICONTROL 0x0000
47 #define DEBIADDR_CIVERSION 0x4000
48 #define DEBIADDR_IO 0x1000
49 #define DEBIADDR_ATTR 0x3000
51 #define CICONTROL_RESET 0x01
52 #define CICONTROL_ENABLETS 0x02
53 #define CICONTROL_CAMDETECT 0x08
55 #define DEBICICTL 0x00420000
56 #define DEBICICAM 0x02420000
58 #define SLOTSTATUS_NONE 1
59 #define SLOTSTATUS_PRESENT 2
60 #define SLOTSTATUS_RESET 4
61 #define SLOTSTATUS_READY 8
62 #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
66 struct input_dev input_dev;
67 struct tasklet_struct msp430_irq_tasklet;
68 struct tasklet_struct ciintf_irq_tasklet;
70 struct dvb_ca_en50221 ca;
74 /* from reading the following remotes:
75 Zenith Universal 7 / TV Mode 807 / VCR Mode 837
76 Hauppauge (from NOVA-CI-s box product)
77 i've taken a "middle of the road" approach and note the differences
79 static u16 key_map[64] = {
81 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8,
85 KEY_POWER, /* RADIO on Hauppauge */
88 KEY_A, /* TV on Hauppauge */
90 KEY_VOLUMEUP, KEY_VOLUMEDOWN,
95 KEY_OPTION, /* RESERVED on Hauppauge */
98 KEY_CHANNELUP, KEY_CHANNELDOWN,
99 KEY_PREVIOUS, /* Prev. Ch on Zenith, SOURCE on Hauppauge */
100 0, KEY_RESTART, KEY_OK,
101 KEY_CYCLEWINDOWS, /* MINIMIZE on Hauppauge */
103 KEY_ENTER, /* VCR mode on Zenith */
108 KEY_MENU, /* FULL SCREEN on Hauppauge */
112 KEY_PREVIOUS, /* VCR mode on Zenith */
118 KEY_TUNER, /* TV/VCR on Zenith */
124 KEY_TUNER, /* VCR mode on Zenith */
128 static void msp430_ir_debounce(unsigned long data)
130 struct input_dev *dev = (struct input_dev *) data;
132 if (dev->rep[0] == 0 || dev->rep[0] == ~0) {
133 input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0);
138 dev->timer.expires = jiffies + HZ * 350 / 1000;
139 add_timer(&dev->timer);
140 input_event(dev, EV_KEY, key_map[dev->repeat_key], 2); /* REPEAT */
143 static void msp430_ir_interrupt(unsigned long data)
145 struct budget_ci *budget_ci = (struct budget_ci *) data;
146 struct input_dev *dev = &budget_ci->input_dev;
148 ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
153 if (timer_pending(&dev->timer)) {
154 if (code == dev->repeat_key) {
158 del_timer(&dev->timer);
159 input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0);
162 if (!key_map[code]) {
163 printk("DVB (%s): no key for %02x!\n", __FUNCTION__, code);
167 /* initialize debounce and repeat */
168 dev->repeat_key = code;
169 /* Zenith remote _always_ sends 2 sequences */
171 /* 350 milliseconds */
172 dev->timer.expires = jiffies + HZ * 350 / 1000;
174 input_event(dev, EV_KEY, key_map[code], !0);
175 add_timer(&dev->timer);
179 static int msp430_ir_init(struct budget_ci *budget_ci)
181 struct saa7146_dev *saa = budget_ci->budget.dev;
184 memset(&budget_ci->input_dev, 0, sizeof(struct input_dev));
186 sprintf(budget_ci->ir_dev_name, "Budget-CI dvb ir receiver %s", saa->name);
187 budget_ci->input_dev.name = budget_ci->ir_dev_name;
189 set_bit(EV_KEY, budget_ci->input_dev.evbit);
191 for (i = 0; i < sizeof(key_map) / sizeof(*key_map); i++)
193 set_bit(key_map[i], budget_ci->input_dev.keybit);
195 input_register_device(&budget_ci->input_dev);
197 budget_ci->input_dev.timer.function = msp430_ir_debounce;
199 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_06);
201 saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
206 static void msp430_ir_deinit(struct budget_ci *budget_ci)
208 struct saa7146_dev *saa = budget_ci->budget.dev;
209 struct input_dev *dev = &budget_ci->input_dev;
211 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_06);
212 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
214 if (del_timer(&dev->timer))
215 input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0);
217 input_unregister_device(dev);
220 static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
222 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
227 return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
228 DEBIADDR_ATTR | (address & 0xfff), 1, 1, 0);
231 static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
233 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
238 return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
239 DEBIADDR_ATTR | (address & 0xfff), 1, value, 1, 0);
242 static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
244 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
249 return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
250 DEBIADDR_IO | (address & 3), 1, 1, 0);
253 static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
255 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
260 return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
261 DEBIADDR_IO | (address & 3), 1, value, 1, 0);
264 static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
266 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
267 struct saa7146_dev *saa = budget_ci->budget.dev;
272 // trigger on RISING edge during reset so we know when READY is re-asserted
273 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
274 budget_ci->slot_status = SLOTSTATUS_RESET;
275 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
277 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
278 CICONTROL_RESET, 1, 0);
280 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
281 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
285 static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
287 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
288 struct saa7146_dev *saa = budget_ci->budget.dev;
293 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
294 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
298 static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
300 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
301 struct saa7146_dev *saa = budget_ci->budget.dev;
307 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
309 tmp = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
310 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
311 tmp | CICONTROL_ENABLETS, 1, 0);
313 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);
317 static void ciintf_interrupt(unsigned long data)
319 struct budget_ci *budget_ci = (struct budget_ci *) data;
320 struct saa7146_dev *saa = budget_ci->budget.dev;
323 // ensure we don't get spurious IRQs during initialisation
324 if (!budget_ci->budget.ci_present)
327 // read the CAM status
328 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
329 if (flags & CICONTROL_CAMDETECT) {
331 // GPIO should be set to trigger on falling edge if a CAM is present
332 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
334 if (budget_ci->slot_status & SLOTSTATUS_NONE) {
336 budget_ci->slot_status = SLOTSTATUS_PRESENT;
337 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
338 DVB_CA_EN50221_CAMCHANGE_INSERTED);
340 } else if (budget_ci->slot_status & SLOTSTATUS_RESET) {
341 // CAM ready (reset completed)
342 budget_ci->slot_status = SLOTSTATUS_READY;
343 dvb_ca_en50221_camready_irq(&budget_ci->ca, 0);
345 } else if (budget_ci->slot_status & SLOTSTATUS_READY) {
347 dvb_ca_en50221_frda_irq(&budget_ci->ca, 0);
351 // trigger on rising edge if a CAM is not present - when a CAM is inserted, we
352 // only want to get the IRQ when it sets READY. If we trigger on the falling edge,
353 // the CAM might not actually be ready yet.
354 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
356 // generate a CAM removal IRQ if we haven't already
357 if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) {
359 budget_ci->slot_status = SLOTSTATUS_NONE;
360 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
361 DVB_CA_EN50221_CAMCHANGE_REMOVED);
366 static int ciintf_init(struct budget_ci *budget_ci)
368 struct saa7146_dev *saa = budget_ci->budget.dev;
372 memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221));
375 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16) | 0x800);
377 // test if it is there
378 if ((ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0) & 0xa0) != 0xa0) {
382 // determine whether a CAM is present or not
383 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
384 budget_ci->slot_status = SLOTSTATUS_NONE;
385 if (flags & CICONTROL_CAMDETECT)
386 budget_ci->slot_status = SLOTSTATUS_PRESENT;
388 // register CI interface
389 budget_ci->ca.owner = THIS_MODULE;
390 budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem;
391 budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem;
392 budget_ci->ca.read_cam_control = ciintf_read_cam_control;
393 budget_ci->ca.write_cam_control = ciintf_write_cam_control;
394 budget_ci->ca.slot_reset = ciintf_slot_reset;
395 budget_ci->ca.slot_shutdown = ciintf_slot_shutdown;
396 budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable;
397 budget_ci->ca.data = budget_ci;
398 if ((result = dvb_ca_en50221_init(&budget_ci->budget.dvb_adapter,
400 DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE |
401 DVB_CA_EN50221_FLAG_IRQ_FR |
402 DVB_CA_EN50221_FLAG_IRQ_DA, 1)) != 0) {
403 printk("budget_ci: CI interface detected, but initialisation failed.\n");
407 tasklet_init(&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, (unsigned long) budget_ci);
408 if (budget_ci->slot_status != SLOTSTATUS_NONE) {
409 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
411 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
413 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_03);
414 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
415 CICONTROL_RESET, 1, 0);
418 printk("budget_ci: CI interface initialised\n");
419 budget_ci->budget.ci_present = 1;
421 // forge a fake CI IRQ so the CAM state is setup correctly
422 flags = DVB_CA_EN50221_CAMCHANGE_REMOVED;
423 if (budget_ci->slot_status != SLOTSTATUS_NONE)
424 flags = DVB_CA_EN50221_CAMCHANGE_INSERTED;
425 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, flags);
430 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16));
434 static void ciintf_deinit(struct budget_ci *budget_ci)
436 struct saa7146_dev *saa = budget_ci->budget.dev;
438 // disable CI interrupts
439 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_03);
440 saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
441 tasklet_kill(&budget_ci->ciintf_irq_tasklet);
442 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
444 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
445 CICONTROL_RESET, 1, 0);
447 // disable TS data stream to CI interface
448 saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT);
450 // release the CA device
451 dvb_ca_en50221_release(&budget_ci->ca);
454 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16));
457 static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
459 struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
461 dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci);
464 tasklet_schedule(&budget_ci->msp430_irq_tasklet);
467 ttpci_budget_irq10_handler(dev, isr);
469 if ((*isr & MASK_03) && (budget_ci->budget.ci_present))
470 tasklet_schedule(&budget_ci->ciintf_irq_tasklet);
474 static u8 alps_bsru6_inittab[] = {
478 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
479 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
480 0x06, 0x40, /* DAC not used, set to high impendance mode */
481 0x07, 0x00, /* DAC LSB */
482 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
483 0x09, 0x00, /* FIFO */
484 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
485 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
486 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
487 0x10, 0x3f, // AGC2 0x3d
489 0x12, 0xb5, // Lock detect: -64 Carrier freq detect:on
490 0x15, 0xc9, // lock detector threshold
501 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
502 0x29, 0x1e, // 1/2 threshold
503 0x2a, 0x14, // 2/3 threshold
504 0x2b, 0x0f, // 3/4 threshold
505 0x2c, 0x09, // 5/6 threshold
506 0x2d, 0x05, // 7/8 threshold
508 0x31, 0x1f, // test all FECs
509 0x32, 0x19, // viterbi and synchro search
510 0x33, 0xfc, // rs control
511 0x34, 0x93, // error control
516 static int alps_bsru6_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
521 if (srate < 1500000) {
524 } else if (srate < 3000000) {
527 } else if (srate < 7000000) {
530 } else if (srate < 14000000) {
533 } else if (srate < 30000000) {
536 } else if (srate < 45000000) {
541 stv0299_writereg(fe, 0x13, aclk);
542 stv0299_writereg(fe, 0x14, bclk);
543 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
544 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
545 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
550 static int alps_bsru6_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
552 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
555 struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };
557 if ((params->frequency < 950000) || (params->frequency > 2150000))
560 div = (params->frequency + (125 - 1)) / 125; // round correctly
561 buf[0] = (div >> 8) & 0x7f;
563 buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
566 if (params->frequency > 1530000)
569 if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1)
574 static struct stv0299_config alps_bsru6_config = {
576 .demod_address = 0x68,
577 .inittab = alps_bsru6_inittab,
580 .enhanced_tuning = 0,
582 .lock_output = STV0229_LOCKOUTPUT_1,
583 .volt13_op0_op1 = STV0299_VOLT13_OP1,
585 .set_symbol_rate = alps_bsru6_set_symbol_rate,
586 .pll_set = alps_bsru6_pll_set,
592 static u8 philips_su1278_tt_inittab[] = {
638 static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
640 stv0299_writereg(fe, 0x0e, 0x44);
641 if (srate >= 10000000) {
642 stv0299_writereg(fe, 0x13, 0x97);
643 stv0299_writereg(fe, 0x14, 0x95);
644 stv0299_writereg(fe, 0x15, 0xc9);
645 stv0299_writereg(fe, 0x17, 0x8c);
646 stv0299_writereg(fe, 0x1a, 0xfe);
647 stv0299_writereg(fe, 0x1c, 0x7f);
648 stv0299_writereg(fe, 0x2d, 0x09);
650 stv0299_writereg(fe, 0x13, 0x99);
651 stv0299_writereg(fe, 0x14, 0x8d);
652 stv0299_writereg(fe, 0x15, 0xce);
653 stv0299_writereg(fe, 0x17, 0x43);
654 stv0299_writereg(fe, 0x1a, 0x1d);
655 stv0299_writereg(fe, 0x1c, 0x12);
656 stv0299_writereg(fe, 0x2d, 0x05);
658 stv0299_writereg(fe, 0x0e, 0x23);
659 stv0299_writereg(fe, 0x0f, 0x94);
660 stv0299_writereg(fe, 0x10, 0x39);
661 stv0299_writereg(fe, 0x15, 0xc9);
663 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
664 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
665 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
670 static int philips_su1278_tt_pll_set(struct dvb_frontend *fe,
671 struct dvb_frontend_parameters *params)
673 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
676 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
678 if ((params->frequency < 950000) || (params->frequency > 2150000))
681 div = (params->frequency + (500 - 1)) / 500; // round correctly
682 buf[0] = (div >> 8) & 0x7f;
684 buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2;
687 if (params->u.qpsk.symbol_rate < 4000000)
690 if (params->frequency < 1250000)
692 else if (params->frequency < 1550000)
694 else if (params->frequency < 2050000)
696 else if (params->frequency < 2150000)
699 if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1)
704 static struct stv0299_config philips_su1278_tt_config = {
706 .demod_address = 0x68,
707 .inittab = philips_su1278_tt_inittab,
710 .enhanced_tuning = 1,
712 .lock_output = STV0229_LOCKOUTPUT_1,
713 .volt13_op0_op1 = STV0299_VOLT13_OP1,
715 .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
716 .pll_set = philips_su1278_tt_pll_set,
721 static int philips_tdm1316l_pll_init(struct dvb_frontend *fe)
723 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
724 static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
725 static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
726 struct i2c_msg tuner_msg = {.addr = 0x63,.flags = 0,.buf = td1316_init,.len =
727 sizeof(td1316_init) };
729 // setup PLL configuration
730 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
734 // disable the mc44BC374c (do not check for errors)
735 tuner_msg.addr = 0x65;
736 tuner_msg.buf = disable_mc44BC374c;
737 tuner_msg.len = sizeof(disable_mc44BC374c);
738 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) {
739 i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1);
745 static int philips_tdm1316l_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
747 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
749 struct i2c_msg tuner_msg = {.addr = 0x63,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) };
750 int tuner_frequency = 0;
753 // determine charge pump
754 tuner_frequency = params->frequency + 36130000;
755 if (tuner_frequency < 87000000)
757 else if (tuner_frequency < 130000000)
759 else if (tuner_frequency < 160000000)
761 else if (tuner_frequency < 200000000)
763 else if (tuner_frequency < 290000000)
765 else if (tuner_frequency < 420000000)
767 else if (tuner_frequency < 480000000)
769 else if (tuner_frequency < 620000000)
771 else if (tuner_frequency < 830000000)
773 else if (tuner_frequency < 895000000)
779 if (params->frequency < 49000000)
781 else if (params->frequency < 159000000)
783 else if (params->frequency < 444000000)
785 else if (params->frequency < 861000000)
790 // setup PLL filter and TDA9889
791 switch (params->u.ofdm.bandwidth) {
792 case BANDWIDTH_6_MHZ:
793 tda1004x_write_byte(fe, 0x0C, 0x14);
797 case BANDWIDTH_7_MHZ:
798 tda1004x_write_byte(fe, 0x0C, 0x80);
802 case BANDWIDTH_8_MHZ:
803 tda1004x_write_byte(fe, 0x0C, 0x14);
812 // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
813 tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000;
815 // setup tuner buffer
816 tuner_buf[0] = tuner_frequency >> 8;
817 tuner_buf[1] = tuner_frequency & 0xff;
819 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
821 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
828 static int philips_tdm1316l_request_firmware(struct dvb_frontend *fe,
829 const struct firmware **fw, char *name)
831 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
833 return request_firmware(fw, name, &budget_ci->budget.dev->pci->dev);
836 static struct tda1004x_config philips_tdm1316l_config = {
838 .demod_address = 0x8,
841 .pll_init = philips_tdm1316l_pll_init,
842 .pll_set = philips_tdm1316l_pll_set,
843 .request_firmware = philips_tdm1316l_request_firmware,
848 static void frontend_init(struct budget_ci *budget_ci)
850 switch (budget_ci->budget.dev->pci->subsystem_device) {
851 case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059))
852 budget_ci->budget.dvb_frontend =
853 stv0299_attach(&alps_bsru6_config, &budget_ci->budget.i2c_adap);
854 if (budget_ci->budget.dvb_frontend) {
859 case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059))
860 budget_ci->budget.dvb_frontend =
861 stv0299_attach(&philips_su1278_tt_config, &budget_ci->budget.i2c_adap);
862 if (budget_ci->budget.dvb_frontend) {
867 case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
868 budget_ci->budget.dvb_frontend =
869 tda10045_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
870 if (budget_ci->budget.dvb_frontend) {
876 if (budget_ci->budget.dvb_frontend == NULL) {
877 printk("budget-ci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
878 budget_ci->budget.dev->pci->vendor,
879 budget_ci->budget.dev->pci->device,
880 budget_ci->budget.dev->pci->subsystem_vendor,
881 budget_ci->budget.dev->pci->subsystem_device);
883 if (dvb_register_frontend
884 (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
885 printk("budget-ci: Frontend registration failed!\n");
886 if (budget_ci->budget.dvb_frontend->ops->release)
887 budget_ci->budget.dvb_frontend->ops->release(budget_ci->budget.dvb_frontend);
888 budget_ci->budget.dvb_frontend = NULL;
893 static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
895 struct budget_ci *budget_ci;
898 if (!(budget_ci = kmalloc(sizeof(struct budget_ci), GFP_KERNEL)))
901 dprintk(2, "budget_ci: %p\n", budget_ci);
903 budget_ci->budget.ci_present = 0;
905 dev->ext_priv = budget_ci;
907 if ((err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE))) {
912 tasklet_init(&budget_ci->msp430_irq_tasklet, msp430_ir_interrupt,
913 (unsigned long) budget_ci);
915 msp430_ir_init(budget_ci);
917 ciintf_init(budget_ci);
919 budget_ci->budget.dvb_adapter.priv = budget_ci;
920 frontend_init(budget_ci);
925 static int budget_ci_detach(struct saa7146_dev *dev)
927 struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
928 struct saa7146_dev *saa = budget_ci->budget.dev;
931 if (budget_ci->budget.ci_present)
932 ciintf_deinit(budget_ci);
933 if (budget_ci->budget.dvb_frontend)
934 dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
935 err = ttpci_budget_deinit(&budget_ci->budget);
937 tasklet_kill(&budget_ci->msp430_irq_tasklet);
939 msp430_ir_deinit(budget_ci);
941 // disable frontend and CI interface
942 saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
949 static struct saa7146_extension budget_extension;
951 MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
952 MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
954 static struct pci_device_id pci_tbl[] = {
955 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
956 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
957 MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
963 MODULE_DEVICE_TABLE(pci, pci_tbl);
965 static struct saa7146_extension budget_extension = {
966 .name = "budget_ci dvb\0",
969 .module = THIS_MODULE,
970 .pci_tbl = &pci_tbl[0],
971 .attach = budget_ci_attach,
972 .detach = budget_ci_detach,
974 .irq_mask = MASK_03 | MASK_06 | MASK_10,
975 .irq_func = budget_ci_irq,
978 static int __init budget_ci_init(void)
980 return saa7146_register_extension(&budget_extension);
983 static void __exit budget_ci_exit(void)
985 saa7146_unregister_extension(&budget_extension);
988 module_init(budget_ci_init);
989 module_exit(budget_ci_exit);
991 MODULE_LICENSE("GPL");
992 MODULE_AUTHOR("Michael Hunold, Jack Thomasson, Andrew de Quincey, others");
993 MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
994 "budget PCI DVB cards w/ CI-module produced by "
995 "Siemens, Technotrend, Hauppauge");