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"
50 * Regarding DEBIADDR_IR:
51 * Some CI modules hang if random addresses are read.
52 * Using address 0x4000 for the IR read means that we
53 * use the same address as for CI version, which should
56 #define DEBIADDR_IR 0x4000
57 #define DEBIADDR_CICONTROL 0x0000
58 #define DEBIADDR_CIVERSION 0x4000
59 #define DEBIADDR_IO 0x1000
60 #define DEBIADDR_ATTR 0x3000
62 #define CICONTROL_RESET 0x01
63 #define CICONTROL_ENABLETS 0x02
64 #define CICONTROL_CAMDETECT 0x08
66 #define DEBICICTL 0x00420000
67 #define DEBICICAM 0x02420000
69 #define SLOTSTATUS_NONE 1
70 #define SLOTSTATUS_PRESENT 2
71 #define SLOTSTATUS_RESET 4
72 #define SLOTSTATUS_READY 8
73 #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
77 struct input_dev *input_dev;
78 struct tasklet_struct msp430_irq_tasklet;
79 struct tasklet_struct ciintf_irq_tasklet;
82 struct dvb_ca_en50221 ca;
84 u8 tuner_pll_address; /* used for philips_tdm1316l configs */
87 /* from reading the following remotes:
88 Zenith Universal 7 / TV Mode 807 / VCR Mode 837
89 Hauppauge (from NOVA-CI-s box product)
90 i've taken a "middle of the road" approach and note the differences
92 static u16 key_map[64] = {
94 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8,
98 KEY_POWER, /* RADIO on Hauppauge */
101 KEY_A, /* TV on Hauppauge */
103 KEY_VOLUMEUP, KEY_VOLUMEDOWN,
108 KEY_OPTION, /* RESERVED on Hauppauge */
111 KEY_CHANNELUP, KEY_CHANNELDOWN,
112 KEY_PREVIOUS, /* Prev. Ch on Zenith, SOURCE on Hauppauge */
113 0, KEY_RESTART, KEY_OK,
114 KEY_CYCLEWINDOWS, /* MINIMIZE on Hauppauge */
116 KEY_ENTER, /* VCR mode on Zenith */
121 KEY_MENU, /* FULL SCREEN on Hauppauge */
125 KEY_PREVIOUS, /* VCR mode on Zenith */
131 KEY_TUNER, /* TV/VCR on Zenith */
137 KEY_TUNER, /* VCR mode on Zenith */
141 static void msp430_ir_debounce(unsigned long data)
143 struct input_dev *dev = (struct input_dev *) data;
145 if (dev->rep[0] == 0 || dev->rep[0] == ~0) {
146 input_event(dev, EV_KEY, key_map[dev->repeat_key], 0);
149 dev->timer.expires = jiffies + HZ * 350 / 1000;
150 add_timer(&dev->timer);
151 input_event(dev, EV_KEY, key_map[dev->repeat_key], 2); /* REPEAT */
156 static void msp430_ir_interrupt(unsigned long data)
158 struct budget_ci *budget_ci = (struct budget_ci *) data;
159 struct input_dev *dev = budget_ci->input_dev;
161 ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
166 if (timer_pending(&dev->timer)) {
167 if (code == dev->repeat_key) {
171 del_timer(&dev->timer);
172 input_event(dev, EV_KEY, key_map[dev->repeat_key], 0);
175 if (!key_map[code]) {
176 printk("DVB (%s): no key for %02x!\n", __FUNCTION__, code);
180 input_event(dev, EV_KEY, key_map[code], 1);
183 /* initialize debounce and repeat */
184 dev->repeat_key = code;
185 /* Zenith remote _always_ sends 2 sequences */
187 mod_timer(&dev->timer, jiffies + msecs_to_jiffies(350));
191 static int msp430_ir_init(struct budget_ci *budget_ci)
193 struct saa7146_dev *saa = budget_ci->budget.dev;
194 struct input_dev *input_dev;
198 input_dev = input_allocate_device();
202 sprintf(budget_ci->ir_dev_name, "Budget-CI dvb ir receiver %s", saa->name);
204 input_dev->name = budget_ci->ir_dev_name;
206 set_bit(EV_KEY, input_dev->evbit);
207 for (i = 0; i < ARRAY_SIZE(key_map); i++)
209 set_bit(key_map[i], input_dev->keybit);
211 err = input_register_device(input_dev);
213 input_free_device(input_dev);
217 input_dev->timer.function = msp430_ir_debounce;
219 budget_ci->input_dev = input_dev;
221 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_06);
222 saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
227 static void msp430_ir_deinit(struct budget_ci *budget_ci)
229 struct saa7146_dev *saa = budget_ci->budget.dev;
230 struct input_dev *dev = budget_ci->input_dev;
232 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_06);
233 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
235 if (del_timer(&dev->timer)) {
236 input_event(dev, EV_KEY, key_map[dev->repeat_key], 0);
240 input_unregister_device(dev);
243 static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
245 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
250 return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
251 DEBIADDR_ATTR | (address & 0xfff), 1, 1, 0);
254 static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
256 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
261 return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
262 DEBIADDR_ATTR | (address & 0xfff), 1, value, 1, 0);
265 static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
267 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
272 return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
273 DEBIADDR_IO | (address & 3), 1, 1, 0);
276 static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
278 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
283 return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
284 DEBIADDR_IO | (address & 3), 1, value, 1, 0);
287 static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
289 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
290 struct saa7146_dev *saa = budget_ci->budget.dev;
295 if (budget_ci->ci_irq) {
296 // trigger on RISING edge during reset so we know when READY is re-asserted
297 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
299 budget_ci->slot_status = SLOTSTATUS_RESET;
300 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
302 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
303 CICONTROL_RESET, 1, 0);
305 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
306 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
310 static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
312 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
313 struct saa7146_dev *saa = budget_ci->budget.dev;
318 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
319 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
323 static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
325 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
326 struct saa7146_dev *saa = budget_ci->budget.dev;
332 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
334 tmp = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
335 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
336 tmp | CICONTROL_ENABLETS, 1, 0);
338 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);
342 static void ciintf_interrupt(unsigned long data)
344 struct budget_ci *budget_ci = (struct budget_ci *) data;
345 struct saa7146_dev *saa = budget_ci->budget.dev;
348 // ensure we don't get spurious IRQs during initialisation
349 if (!budget_ci->budget.ci_present)
352 // read the CAM status
353 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
354 if (flags & CICONTROL_CAMDETECT) {
356 // GPIO should be set to trigger on falling edge if a CAM is present
357 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
359 if (budget_ci->slot_status & SLOTSTATUS_NONE) {
361 budget_ci->slot_status = SLOTSTATUS_PRESENT;
362 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
363 DVB_CA_EN50221_CAMCHANGE_INSERTED);
365 } else if (budget_ci->slot_status & SLOTSTATUS_RESET) {
366 // CAM ready (reset completed)
367 budget_ci->slot_status = SLOTSTATUS_READY;
368 dvb_ca_en50221_camready_irq(&budget_ci->ca, 0);
370 } else if (budget_ci->slot_status & SLOTSTATUS_READY) {
372 dvb_ca_en50221_frda_irq(&budget_ci->ca, 0);
376 // trigger on rising edge if a CAM is not present - when a CAM is inserted, we
377 // only want to get the IRQ when it sets READY. If we trigger on the falling edge,
378 // the CAM might not actually be ready yet.
379 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
381 // generate a CAM removal IRQ if we haven't already
382 if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) {
384 budget_ci->slot_status = SLOTSTATUS_NONE;
385 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
386 DVB_CA_EN50221_CAMCHANGE_REMOVED);
391 static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
393 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
396 // ensure we don't get spurious IRQs during initialisation
397 if (!budget_ci->budget.ci_present)
400 // read the CAM status
401 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
402 if (flags & CICONTROL_CAMDETECT) {
403 // mark it as present if it wasn't before
404 if (budget_ci->slot_status & SLOTSTATUS_NONE) {
405 budget_ci->slot_status = SLOTSTATUS_PRESENT;
408 // during a RESET, we check if we can read from IO memory to see when CAM is ready
409 if (budget_ci->slot_status & SLOTSTATUS_RESET) {
410 if (ciintf_read_attribute_mem(ca, slot, 0) == 0x1d) {
411 budget_ci->slot_status = SLOTSTATUS_READY;
415 budget_ci->slot_status = SLOTSTATUS_NONE;
418 if (budget_ci->slot_status != SLOTSTATUS_NONE) {
419 if (budget_ci->slot_status & SLOTSTATUS_READY) {
420 return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
422 return DVB_CA_EN50221_POLL_CAM_PRESENT;
428 static int ciintf_init(struct budget_ci *budget_ci)
430 struct saa7146_dev *saa = budget_ci->budget.dev;
436 memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221));
439 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16) | 0x800);
441 // test if it is there
442 ci_version = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0);
443 if ((ci_version & 0xa0) != 0xa0) {
448 // determine whether a CAM is present or not
449 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
450 budget_ci->slot_status = SLOTSTATUS_NONE;
451 if (flags & CICONTROL_CAMDETECT)
452 budget_ci->slot_status = SLOTSTATUS_PRESENT;
454 // version 0xa2 of the CI firmware doesn't generate interrupts
455 if (ci_version == 0xa2) {
457 budget_ci->ci_irq = 0;
459 ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE |
460 DVB_CA_EN50221_FLAG_IRQ_FR |
461 DVB_CA_EN50221_FLAG_IRQ_DA;
462 budget_ci->ci_irq = 1;
465 // register CI interface
466 budget_ci->ca.owner = THIS_MODULE;
467 budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem;
468 budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem;
469 budget_ci->ca.read_cam_control = ciintf_read_cam_control;
470 budget_ci->ca.write_cam_control = ciintf_write_cam_control;
471 budget_ci->ca.slot_reset = ciintf_slot_reset;
472 budget_ci->ca.slot_shutdown = ciintf_slot_shutdown;
473 budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable;
474 budget_ci->ca.poll_slot_status = ciintf_poll_slot_status;
475 budget_ci->ca.data = budget_ci;
476 if ((result = dvb_ca_en50221_init(&budget_ci->budget.dvb_adapter,
478 ca_flags, 1)) != 0) {
479 printk("budget_ci: CI interface detected, but initialisation failed.\n");
484 if (budget_ci->ci_irq) {
485 tasklet_init(&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, (unsigned long) budget_ci);
486 if (budget_ci->slot_status != SLOTSTATUS_NONE) {
487 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
489 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
491 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_03);
495 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
496 CICONTROL_RESET, 1, 0);
499 printk("budget_ci: CI interface initialised\n");
500 budget_ci->budget.ci_present = 1;
502 // forge a fake CI IRQ so the CAM state is setup correctly
503 if (budget_ci->ci_irq) {
504 flags = DVB_CA_EN50221_CAMCHANGE_REMOVED;
505 if (budget_ci->slot_status != SLOTSTATUS_NONE)
506 flags = DVB_CA_EN50221_CAMCHANGE_INSERTED;
507 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, flags);
513 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16));
517 static void ciintf_deinit(struct budget_ci *budget_ci)
519 struct saa7146_dev *saa = budget_ci->budget.dev;
521 // disable CI interrupts
522 if (budget_ci->ci_irq) {
523 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_03);
524 saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
525 tasklet_kill(&budget_ci->ciintf_irq_tasklet);
529 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
531 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
532 CICONTROL_RESET, 1, 0);
534 // disable TS data stream to CI interface
535 saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT);
537 // release the CA device
538 dvb_ca_en50221_release(&budget_ci->ca);
541 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16));
544 static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
546 struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
548 dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci);
551 tasklet_schedule(&budget_ci->msp430_irq_tasklet);
554 ttpci_budget_irq10_handler(dev, isr);
556 if ((*isr & MASK_03) && (budget_ci->budget.ci_present) && (budget_ci->ci_irq))
557 tasklet_schedule(&budget_ci->ciintf_irq_tasklet);
560 static u8 philips_su1278_tt_inittab[] = {
606 static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
608 stv0299_writereg(fe, 0x0e, 0x44);
609 if (srate >= 10000000) {
610 stv0299_writereg(fe, 0x13, 0x97);
611 stv0299_writereg(fe, 0x14, 0x95);
612 stv0299_writereg(fe, 0x15, 0xc9);
613 stv0299_writereg(fe, 0x17, 0x8c);
614 stv0299_writereg(fe, 0x1a, 0xfe);
615 stv0299_writereg(fe, 0x1c, 0x7f);
616 stv0299_writereg(fe, 0x2d, 0x09);
618 stv0299_writereg(fe, 0x13, 0x99);
619 stv0299_writereg(fe, 0x14, 0x8d);
620 stv0299_writereg(fe, 0x15, 0xce);
621 stv0299_writereg(fe, 0x17, 0x43);
622 stv0299_writereg(fe, 0x1a, 0x1d);
623 stv0299_writereg(fe, 0x1c, 0x12);
624 stv0299_writereg(fe, 0x2d, 0x05);
626 stv0299_writereg(fe, 0x0e, 0x23);
627 stv0299_writereg(fe, 0x0f, 0x94);
628 stv0299_writereg(fe, 0x10, 0x39);
629 stv0299_writereg(fe, 0x15, 0xc9);
631 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
632 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
633 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
638 static int philips_su1278_tt_tuner_set_params(struct dvb_frontend *fe,
639 struct dvb_frontend_parameters *params)
641 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
644 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
646 if ((params->frequency < 950000) || (params->frequency > 2150000))
649 div = (params->frequency + (500 - 1)) / 500; // round correctly
650 buf[0] = (div >> 8) & 0x7f;
652 buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2;
655 if (params->u.qpsk.symbol_rate < 4000000)
658 if (params->frequency < 1250000)
660 else if (params->frequency < 1550000)
662 else if (params->frequency < 2050000)
664 else if (params->frequency < 2150000)
667 if (fe->ops.i2c_gate_ctrl)
668 fe->ops.i2c_gate_ctrl(fe, 1);
669 if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1)
674 static struct stv0299_config philips_su1278_tt_config = {
676 .demod_address = 0x68,
677 .inittab = philips_su1278_tt_inittab,
681 .lock_output = STV0229_LOCKOUTPUT_1,
682 .volt13_op0_op1 = STV0299_VOLT13_OP1,
684 .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
689 static int philips_tdm1316l_tuner_init(struct dvb_frontend *fe)
691 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
692 static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
693 static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
694 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = td1316_init,.len =
695 sizeof(td1316_init) };
697 // setup PLL configuration
698 if (fe->ops.i2c_gate_ctrl)
699 fe->ops.i2c_gate_ctrl(fe, 1);
700 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
704 // disable the mc44BC374c (do not check for errors)
705 tuner_msg.addr = 0x65;
706 tuner_msg.buf = disable_mc44BC374c;
707 tuner_msg.len = sizeof(disable_mc44BC374c);
708 if (fe->ops.i2c_gate_ctrl)
709 fe->ops.i2c_gate_ctrl(fe, 1);
710 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) {
711 if (fe->ops.i2c_gate_ctrl)
712 fe->ops.i2c_gate_ctrl(fe, 1);
713 i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1);
719 static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
721 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
723 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) };
724 int tuner_frequency = 0;
727 // determine charge pump
728 tuner_frequency = params->frequency + 36130000;
729 if (tuner_frequency < 87000000)
731 else if (tuner_frequency < 130000000)
733 else if (tuner_frequency < 160000000)
735 else if (tuner_frequency < 200000000)
737 else if (tuner_frequency < 290000000)
739 else if (tuner_frequency < 420000000)
741 else if (tuner_frequency < 480000000)
743 else if (tuner_frequency < 620000000)
745 else if (tuner_frequency < 830000000)
747 else if (tuner_frequency < 895000000)
753 if (params->frequency < 49000000)
755 else if (params->frequency < 159000000)
757 else if (params->frequency < 444000000)
759 else if (params->frequency < 861000000)
764 // setup PLL filter and TDA9889
765 switch (params->u.ofdm.bandwidth) {
766 case BANDWIDTH_6_MHZ:
767 tda1004x_writereg(fe, 0x0C, 0x14);
771 case BANDWIDTH_7_MHZ:
772 tda1004x_writereg(fe, 0x0C, 0x80);
776 case BANDWIDTH_8_MHZ:
777 tda1004x_writereg(fe, 0x0C, 0x14);
786 // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
787 tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000;
789 // setup tuner buffer
790 tuner_buf[0] = tuner_frequency >> 8;
791 tuner_buf[1] = tuner_frequency & 0xff;
793 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
795 if (fe->ops.i2c_gate_ctrl)
796 fe->ops.i2c_gate_ctrl(fe, 1);
797 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
804 static int philips_tdm1316l_request_firmware(struct dvb_frontend *fe,
805 const struct firmware **fw, char *name)
807 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
809 return request_firmware(fw, name, &budget_ci->budget.dev->pci->dev);
812 static struct tda1004x_config philips_tdm1316l_config = {
814 .demod_address = 0x8,
817 .xtal_freq = TDA10046_XTAL_4M,
818 .agc_config = TDA10046_AGC_DEFAULT,
819 .if_freq = TDA10046_FREQ_3617,
820 .request_firmware = philips_tdm1316l_request_firmware,
823 static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
825 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
827 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,
830 .len = sizeof(tuner_buf) };
831 int tuner_frequency = 0;
834 // determine charge pump
835 tuner_frequency = params->frequency + 36125000;
836 if (tuner_frequency < 87000000)
838 else if (tuner_frequency < 130000000) {
841 } else if (tuner_frequency < 160000000) {
844 } else if (tuner_frequency < 200000000) {
847 } else if (tuner_frequency < 290000000) {
850 } else if (tuner_frequency < 420000000) {
853 } else if (tuner_frequency < 480000000) {
856 } else if (tuner_frequency < 620000000) {
859 } else if (tuner_frequency < 830000000) {
862 } else if (tuner_frequency < 895000000) {
868 // assume PLL filter should always be 8MHz for the moment.
872 tuner_frequency = (params->frequency + 36125000 + (62500/2)) / 62500;
874 // setup tuner buffer
875 tuner_buf[0] = tuner_frequency >> 8;
876 tuner_buf[1] = tuner_frequency & 0xff;
878 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
881 if (fe->ops.i2c_gate_ctrl)
882 fe->ops.i2c_gate_ctrl(fe, 1);
883 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
888 if (fe->ops.i2c_gate_ctrl)
889 fe->ops.i2c_gate_ctrl(fe, 1);
890 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
898 static u8 dvbc_philips_tdm1316l_inittab[] = {
991 static struct stv0297_config dvbc_philips_tdm1316l_config = {
992 .demod_address = 0x1c,
993 .inittab = dvbc_philips_tdm1316l_inittab,
995 .stop_during_read = 1,
1001 static void frontend_init(struct budget_ci *budget_ci)
1003 switch (budget_ci->budget.dev->pci->subsystem_device) {
1004 case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059))
1005 budget_ci->budget.dvb_frontend =
1006 dvb_attach(stv0299_attach, &alps_bsru6_config, &budget_ci->budget.i2c_adap);
1007 if (budget_ci->budget.dvb_frontend) {
1008 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
1009 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
1014 case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059))
1015 budget_ci->budget.dvb_frontend =
1016 dvb_attach(stv0299_attach, &philips_su1278_tt_config, &budget_ci->budget.i2c_adap);
1017 if (budget_ci->budget.dvb_frontend) {
1018 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params;
1023 case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt))
1024 budget_ci->tuner_pll_address = 0x61;
1025 budget_ci->budget.dvb_frontend =
1026 dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1027 if (budget_ci->budget.dvb_frontend) {
1028 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
1033 case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
1034 budget_ci->tuner_pll_address = 0x63;
1035 budget_ci->budget.dvb_frontend =
1036 dvb_attach(tda10045_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1037 if (budget_ci->budget.dvb_frontend) {
1038 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1039 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1044 case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
1045 budget_ci->tuner_pll_address = 0x60;
1046 philips_tdm1316l_config.invert = 1;
1047 budget_ci->budget.dvb_frontend =
1048 dvb_attach(tda10046_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1049 if (budget_ci->budget.dvb_frontend) {
1050 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1051 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1056 case 0x1017: // TT S-1500 PCI
1057 budget_ci->budget.dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config, &budget_ci->budget.i2c_adap);
1058 if (budget_ci->budget.dvb_frontend) {
1059 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
1060 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
1062 budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
1063 if (dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0) == NULL) {
1064 printk("%s: No LNBP21 found!\n", __FUNCTION__);
1065 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1066 budget_ci->budget.dvb_frontend = NULL;
1073 if (budget_ci->budget.dvb_frontend == NULL) {
1074 printk("budget-ci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
1075 budget_ci->budget.dev->pci->vendor,
1076 budget_ci->budget.dev->pci->device,
1077 budget_ci->budget.dev->pci->subsystem_vendor,
1078 budget_ci->budget.dev->pci->subsystem_device);
1080 if (dvb_register_frontend
1081 (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
1082 printk("budget-ci: Frontend registration failed!\n");
1083 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1084 budget_ci->budget.dvb_frontend = NULL;
1089 static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
1091 struct budget_ci *budget_ci;
1094 if (!(budget_ci = kmalloc(sizeof(struct budget_ci), GFP_KERNEL)))
1097 dprintk(2, "budget_ci: %p\n", budget_ci);
1099 budget_ci->budget.ci_present = 0;
1101 dev->ext_priv = budget_ci;
1103 if ((err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE))) {
1108 tasklet_init(&budget_ci->msp430_irq_tasklet, msp430_ir_interrupt,
1109 (unsigned long) budget_ci);
1111 msp430_ir_init(budget_ci);
1113 ciintf_init(budget_ci);
1115 budget_ci->budget.dvb_adapter.priv = budget_ci;
1116 frontend_init(budget_ci);
1118 ttpci_budget_init_hooks(&budget_ci->budget);
1123 static int budget_ci_detach(struct saa7146_dev *dev)
1125 struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
1126 struct saa7146_dev *saa = budget_ci->budget.dev;
1129 if (budget_ci->budget.ci_present)
1130 ciintf_deinit(budget_ci);
1131 if (budget_ci->budget.dvb_frontend) {
1132 dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
1133 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1135 err = ttpci_budget_deinit(&budget_ci->budget);
1137 tasklet_kill(&budget_ci->msp430_irq_tasklet);
1139 msp430_ir_deinit(budget_ci);
1141 // disable frontend and CI interface
1142 saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
1149 static struct saa7146_extension budget_extension;
1151 MAKE_BUDGET_INFO(ttbs2, "TT-Budget/S-1500 PCI", BUDGET_TT);
1152 MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
1153 MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
1154 MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
1155 MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT);
1157 static struct pci_device_id pci_tbl[] = {
1158 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
1159 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
1160 MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
1161 MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
1162 MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
1163 MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
1169 MODULE_DEVICE_TABLE(pci, pci_tbl);
1171 static struct saa7146_extension budget_extension = {
1172 .name = "budget_ci dvb",
1173 .flags = SAA7146_I2C_SHORT_DELAY,
1175 .module = THIS_MODULE,
1176 .pci_tbl = &pci_tbl[0],
1177 .attach = budget_ci_attach,
1178 .detach = budget_ci_detach,
1180 .irq_mask = MASK_03 | MASK_06 | MASK_10,
1181 .irq_func = budget_ci_irq,
1184 static int __init budget_ci_init(void)
1186 return saa7146_register_extension(&budget_extension);
1189 static void __exit budget_ci_exit(void)
1191 saa7146_unregister_extension(&budget_extension);
1194 module_init(budget_ci_init);
1195 module_exit(budget_ci_exit);
1197 MODULE_LICENSE("GPL");
1198 MODULE_AUTHOR("Michael Hunold, Jack Thomasson, Andrew de Quincey, others");
1199 MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
1200 "budget PCI DVB cards w/ CI-module produced by "
1201 "Siemens, Technotrend, Hauppauge");