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)
76 struct input_dev *dev;
77 struct tasklet_struct msp430_irq_tasklet;
78 char name[72]; /* 40 + 32 for (struct saa7146_dev).name */
83 struct tasklet_struct ciintf_irq_tasklet;
86 struct dvb_ca_en50221 ca;
87 struct budget_ci_ir ir;
88 u8 tuner_pll_address; /* used for philips_tdm1316l configs */
91 /* from reading the following remotes:
92 Zenith Universal 7 / TV Mode 807 / VCR Mode 837
93 Hauppauge (from NOVA-CI-s box product)
94 i've taken a "middle of the road" approach and note the differences
96 static u16 key_map[64] = {
98 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8,
102 KEY_POWER, /* RADIO on Hauppauge */
105 KEY_A, /* TV on Hauppauge */
107 KEY_VOLUMEUP, KEY_VOLUMEDOWN,
112 KEY_OPTION, /* RESERVED on Hauppauge */
115 KEY_CHANNELUP, KEY_CHANNELDOWN,
116 KEY_PREVIOUS, /* Prev. Ch on Zenith, SOURCE on Hauppauge */
117 0, KEY_RESTART, KEY_OK,
118 KEY_CYCLEWINDOWS, /* MINIMIZE on Hauppauge */
120 KEY_ENTER, /* VCR mode on Zenith */
125 KEY_MENU, /* FULL SCREEN on Hauppauge */
129 KEY_PREVIOUS, /* VCR mode on Zenith */
135 KEY_TUNER, /* TV/VCR on Zenith */
141 KEY_TUNER, /* VCR mode on Zenith */
145 static void msp430_ir_debounce(unsigned long data)
147 struct input_dev *dev = (struct input_dev *) data;
149 if (dev->rep[0] == 0 || dev->rep[0] == ~0) {
150 input_event(dev, EV_KEY, key_map[dev->repeat_key], 0);
153 dev->timer.expires = jiffies + HZ * 350 / 1000;
154 add_timer(&dev->timer);
155 input_event(dev, EV_KEY, key_map[dev->repeat_key], 2); /* REPEAT */
160 static void msp430_ir_interrupt(unsigned long data)
162 struct budget_ci *budget_ci = (struct budget_ci *) data;
163 struct input_dev *dev = budget_ci->ir.dev;
165 ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
170 if (timer_pending(&dev->timer)) {
171 if (code == dev->repeat_key) {
175 del_timer(&dev->timer);
176 input_event(dev, EV_KEY, key_map[dev->repeat_key], 0);
179 if (!key_map[code]) {
180 printk("DVB (%s): no key for %02x!\n", __FUNCTION__, code);
184 input_event(dev, EV_KEY, key_map[code], 1);
187 /* initialize debounce and repeat */
188 dev->repeat_key = code;
189 /* Zenith remote _always_ sends 2 sequences */
191 mod_timer(&dev->timer, jiffies + msecs_to_jiffies(350));
195 static int msp430_ir_init(struct budget_ci *budget_ci)
197 struct saa7146_dev *saa = budget_ci->budget.dev;
198 struct input_dev *input_dev = budget_ci->ir.dev;
202 budget_ci->ir.dev = input_dev = input_allocate_device();
206 snprintf(budget_ci->ir.name, sizeof(budget_ci->ir.name),
207 "Budget-CI dvb ir receiver %s", saa->name);
208 input_dev->name = budget_ci->ir.name;
210 set_bit(EV_KEY, input_dev->evbit);
211 for (i = 0; i < ARRAY_SIZE(key_map); i++)
213 set_bit(key_map[i], input_dev->keybit);
215 err = input_register_device(input_dev);
217 input_free_device(input_dev);
221 input_register_device(budget_ci->ir.dev);
223 input_dev->timer.function = msp430_ir_debounce;
225 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_06);
226 saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
231 static void msp430_ir_deinit(struct budget_ci *budget_ci)
233 struct saa7146_dev *saa = budget_ci->budget.dev;
234 struct input_dev *dev = budget_ci->ir.dev;
236 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_06);
237 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
239 if (del_timer(&dev->timer)) {
240 input_event(dev, EV_KEY, key_map[dev->repeat_key], 0);
244 input_unregister_device(dev);
247 static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
249 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
254 return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
255 DEBIADDR_ATTR | (address & 0xfff), 1, 1, 0);
258 static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
260 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
265 return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
266 DEBIADDR_ATTR | (address & 0xfff), 1, value, 1, 0);
269 static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
271 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
276 return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
277 DEBIADDR_IO | (address & 3), 1, 1, 0);
280 static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
282 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
287 return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
288 DEBIADDR_IO | (address & 3), 1, value, 1, 0);
291 static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
293 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
294 struct saa7146_dev *saa = budget_ci->budget.dev;
299 if (budget_ci->ci_irq) {
300 // trigger on RISING edge during reset so we know when READY is re-asserted
301 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
303 budget_ci->slot_status = SLOTSTATUS_RESET;
304 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
306 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
307 CICONTROL_RESET, 1, 0);
309 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
310 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
314 static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
316 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
317 struct saa7146_dev *saa = budget_ci->budget.dev;
322 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
323 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
327 static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
329 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
330 struct saa7146_dev *saa = budget_ci->budget.dev;
336 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
338 tmp = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
339 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
340 tmp | CICONTROL_ENABLETS, 1, 0);
342 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);
346 static void ciintf_interrupt(unsigned long data)
348 struct budget_ci *budget_ci = (struct budget_ci *) data;
349 struct saa7146_dev *saa = budget_ci->budget.dev;
352 // ensure we don't get spurious IRQs during initialisation
353 if (!budget_ci->budget.ci_present)
356 // read the CAM status
357 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
358 if (flags & CICONTROL_CAMDETECT) {
360 // GPIO should be set to trigger on falling edge if a CAM is present
361 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
363 if (budget_ci->slot_status & SLOTSTATUS_NONE) {
365 budget_ci->slot_status = SLOTSTATUS_PRESENT;
366 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
367 DVB_CA_EN50221_CAMCHANGE_INSERTED);
369 } else if (budget_ci->slot_status & SLOTSTATUS_RESET) {
370 // CAM ready (reset completed)
371 budget_ci->slot_status = SLOTSTATUS_READY;
372 dvb_ca_en50221_camready_irq(&budget_ci->ca, 0);
374 } else if (budget_ci->slot_status & SLOTSTATUS_READY) {
376 dvb_ca_en50221_frda_irq(&budget_ci->ca, 0);
380 // trigger on rising edge if a CAM is not present - when a CAM is inserted, we
381 // only want to get the IRQ when it sets READY. If we trigger on the falling edge,
382 // the CAM might not actually be ready yet.
383 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
385 // generate a CAM removal IRQ if we haven't already
386 if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) {
388 budget_ci->slot_status = SLOTSTATUS_NONE;
389 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
390 DVB_CA_EN50221_CAMCHANGE_REMOVED);
395 static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
397 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
400 // ensure we don't get spurious IRQs during initialisation
401 if (!budget_ci->budget.ci_present)
404 // read the CAM status
405 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
406 if (flags & CICONTROL_CAMDETECT) {
407 // mark it as present if it wasn't before
408 if (budget_ci->slot_status & SLOTSTATUS_NONE) {
409 budget_ci->slot_status = SLOTSTATUS_PRESENT;
412 // during a RESET, we check if we can read from IO memory to see when CAM is ready
413 if (budget_ci->slot_status & SLOTSTATUS_RESET) {
414 if (ciintf_read_attribute_mem(ca, slot, 0) == 0x1d) {
415 budget_ci->slot_status = SLOTSTATUS_READY;
419 budget_ci->slot_status = SLOTSTATUS_NONE;
422 if (budget_ci->slot_status != SLOTSTATUS_NONE) {
423 if (budget_ci->slot_status & SLOTSTATUS_READY) {
424 return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
426 return DVB_CA_EN50221_POLL_CAM_PRESENT;
432 static int ciintf_init(struct budget_ci *budget_ci)
434 struct saa7146_dev *saa = budget_ci->budget.dev;
440 memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221));
443 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16) | 0x800);
445 // test if it is there
446 ci_version = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0);
447 if ((ci_version & 0xa0) != 0xa0) {
452 // determine whether a CAM is present or not
453 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
454 budget_ci->slot_status = SLOTSTATUS_NONE;
455 if (flags & CICONTROL_CAMDETECT)
456 budget_ci->slot_status = SLOTSTATUS_PRESENT;
458 // version 0xa2 of the CI firmware doesn't generate interrupts
459 if (ci_version == 0xa2) {
461 budget_ci->ci_irq = 0;
463 ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE |
464 DVB_CA_EN50221_FLAG_IRQ_FR |
465 DVB_CA_EN50221_FLAG_IRQ_DA;
466 budget_ci->ci_irq = 1;
469 // register CI interface
470 budget_ci->ca.owner = THIS_MODULE;
471 budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem;
472 budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem;
473 budget_ci->ca.read_cam_control = ciintf_read_cam_control;
474 budget_ci->ca.write_cam_control = ciintf_write_cam_control;
475 budget_ci->ca.slot_reset = ciintf_slot_reset;
476 budget_ci->ca.slot_shutdown = ciintf_slot_shutdown;
477 budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable;
478 budget_ci->ca.poll_slot_status = ciintf_poll_slot_status;
479 budget_ci->ca.data = budget_ci;
480 if ((result = dvb_ca_en50221_init(&budget_ci->budget.dvb_adapter,
482 ca_flags, 1)) != 0) {
483 printk("budget_ci: CI interface detected, but initialisation failed.\n");
488 if (budget_ci->ci_irq) {
489 tasklet_init(&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, (unsigned long) budget_ci);
490 if (budget_ci->slot_status != SLOTSTATUS_NONE) {
491 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
493 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
495 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_03);
499 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
500 CICONTROL_RESET, 1, 0);
503 printk("budget_ci: CI interface initialised\n");
504 budget_ci->budget.ci_present = 1;
506 // forge a fake CI IRQ so the CAM state is setup correctly
507 if (budget_ci->ci_irq) {
508 flags = DVB_CA_EN50221_CAMCHANGE_REMOVED;
509 if (budget_ci->slot_status != SLOTSTATUS_NONE)
510 flags = DVB_CA_EN50221_CAMCHANGE_INSERTED;
511 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, flags);
517 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16));
521 static void ciintf_deinit(struct budget_ci *budget_ci)
523 struct saa7146_dev *saa = budget_ci->budget.dev;
525 // disable CI interrupts
526 if (budget_ci->ci_irq) {
527 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_03);
528 saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
529 tasklet_kill(&budget_ci->ciintf_irq_tasklet);
533 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
535 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
536 CICONTROL_RESET, 1, 0);
538 // disable TS data stream to CI interface
539 saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT);
541 // release the CA device
542 dvb_ca_en50221_release(&budget_ci->ca);
545 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16));
548 static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
550 struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
552 dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci);
555 tasklet_schedule(&budget_ci->ir.msp430_irq_tasklet);
558 ttpci_budget_irq10_handler(dev, isr);
560 if ((*isr & MASK_03) && (budget_ci->budget.ci_present) && (budget_ci->ci_irq))
561 tasklet_schedule(&budget_ci->ciintf_irq_tasklet);
564 static u8 philips_su1278_tt_inittab[] = {
610 static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
612 stv0299_writereg(fe, 0x0e, 0x44);
613 if (srate >= 10000000) {
614 stv0299_writereg(fe, 0x13, 0x97);
615 stv0299_writereg(fe, 0x14, 0x95);
616 stv0299_writereg(fe, 0x15, 0xc9);
617 stv0299_writereg(fe, 0x17, 0x8c);
618 stv0299_writereg(fe, 0x1a, 0xfe);
619 stv0299_writereg(fe, 0x1c, 0x7f);
620 stv0299_writereg(fe, 0x2d, 0x09);
622 stv0299_writereg(fe, 0x13, 0x99);
623 stv0299_writereg(fe, 0x14, 0x8d);
624 stv0299_writereg(fe, 0x15, 0xce);
625 stv0299_writereg(fe, 0x17, 0x43);
626 stv0299_writereg(fe, 0x1a, 0x1d);
627 stv0299_writereg(fe, 0x1c, 0x12);
628 stv0299_writereg(fe, 0x2d, 0x05);
630 stv0299_writereg(fe, 0x0e, 0x23);
631 stv0299_writereg(fe, 0x0f, 0x94);
632 stv0299_writereg(fe, 0x10, 0x39);
633 stv0299_writereg(fe, 0x15, 0xc9);
635 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
636 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
637 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
642 static int philips_su1278_tt_tuner_set_params(struct dvb_frontend *fe,
643 struct dvb_frontend_parameters *params)
645 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
648 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
650 if ((params->frequency < 950000) || (params->frequency > 2150000))
653 div = (params->frequency + (500 - 1)) / 500; // round correctly
654 buf[0] = (div >> 8) & 0x7f;
656 buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2;
659 if (params->u.qpsk.symbol_rate < 4000000)
662 if (params->frequency < 1250000)
664 else if (params->frequency < 1550000)
666 else if (params->frequency < 2050000)
668 else if (params->frequency < 2150000)
671 if (fe->ops.i2c_gate_ctrl)
672 fe->ops.i2c_gate_ctrl(fe, 1);
673 if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1)
678 static struct stv0299_config philips_su1278_tt_config = {
680 .demod_address = 0x68,
681 .inittab = philips_su1278_tt_inittab,
685 .lock_output = STV0229_LOCKOUTPUT_1,
686 .volt13_op0_op1 = STV0299_VOLT13_OP1,
688 .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
693 static int philips_tdm1316l_tuner_init(struct dvb_frontend *fe)
695 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
696 static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
697 static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
698 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = td1316_init,.len =
699 sizeof(td1316_init) };
701 // setup PLL configuration
702 if (fe->ops.i2c_gate_ctrl)
703 fe->ops.i2c_gate_ctrl(fe, 1);
704 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
708 // disable the mc44BC374c (do not check for errors)
709 tuner_msg.addr = 0x65;
710 tuner_msg.buf = disable_mc44BC374c;
711 tuner_msg.len = sizeof(disable_mc44BC374c);
712 if (fe->ops.i2c_gate_ctrl)
713 fe->ops.i2c_gate_ctrl(fe, 1);
714 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) {
715 if (fe->ops.i2c_gate_ctrl)
716 fe->ops.i2c_gate_ctrl(fe, 1);
717 i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1);
723 static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
725 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
727 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) };
728 int tuner_frequency = 0;
731 // determine charge pump
732 tuner_frequency = params->frequency + 36130000;
733 if (tuner_frequency < 87000000)
735 else if (tuner_frequency < 130000000)
737 else if (tuner_frequency < 160000000)
739 else if (tuner_frequency < 200000000)
741 else if (tuner_frequency < 290000000)
743 else if (tuner_frequency < 420000000)
745 else if (tuner_frequency < 480000000)
747 else if (tuner_frequency < 620000000)
749 else if (tuner_frequency < 830000000)
751 else if (tuner_frequency < 895000000)
757 if (params->frequency < 49000000)
759 else if (params->frequency < 159000000)
761 else if (params->frequency < 444000000)
763 else if (params->frequency < 861000000)
768 // setup PLL filter and TDA9889
769 switch (params->u.ofdm.bandwidth) {
770 case BANDWIDTH_6_MHZ:
771 tda1004x_writereg(fe, 0x0C, 0x14);
775 case BANDWIDTH_7_MHZ:
776 tda1004x_writereg(fe, 0x0C, 0x80);
780 case BANDWIDTH_8_MHZ:
781 tda1004x_writereg(fe, 0x0C, 0x14);
790 // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
791 tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000;
793 // setup tuner buffer
794 tuner_buf[0] = tuner_frequency >> 8;
795 tuner_buf[1] = tuner_frequency & 0xff;
797 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
799 if (fe->ops.i2c_gate_ctrl)
800 fe->ops.i2c_gate_ctrl(fe, 1);
801 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
808 static int philips_tdm1316l_request_firmware(struct dvb_frontend *fe,
809 const struct firmware **fw, char *name)
811 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
813 return request_firmware(fw, name, &budget_ci->budget.dev->pci->dev);
816 static struct tda1004x_config philips_tdm1316l_config = {
818 .demod_address = 0x8,
821 .xtal_freq = TDA10046_XTAL_4M,
822 .agc_config = TDA10046_AGC_DEFAULT,
823 .if_freq = TDA10046_FREQ_3617,
824 .request_firmware = philips_tdm1316l_request_firmware,
827 static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
829 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
831 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,
834 .len = sizeof(tuner_buf) };
835 int tuner_frequency = 0;
838 // determine charge pump
839 tuner_frequency = params->frequency + 36125000;
840 if (tuner_frequency < 87000000)
842 else if (tuner_frequency < 130000000) {
845 } else if (tuner_frequency < 160000000) {
848 } else if (tuner_frequency < 200000000) {
851 } else if (tuner_frequency < 290000000) {
854 } else if (tuner_frequency < 420000000) {
857 } else if (tuner_frequency < 480000000) {
860 } else if (tuner_frequency < 620000000) {
863 } else if (tuner_frequency < 830000000) {
866 } else if (tuner_frequency < 895000000) {
872 // assume PLL filter should always be 8MHz for the moment.
876 tuner_frequency = (params->frequency + 36125000 + (62500/2)) / 62500;
878 // setup tuner buffer
879 tuner_buf[0] = tuner_frequency >> 8;
880 tuner_buf[1] = tuner_frequency & 0xff;
882 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
885 if (fe->ops.i2c_gate_ctrl)
886 fe->ops.i2c_gate_ctrl(fe, 1);
887 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
892 if (fe->ops.i2c_gate_ctrl)
893 fe->ops.i2c_gate_ctrl(fe, 1);
894 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
902 static u8 dvbc_philips_tdm1316l_inittab[] = {
995 static struct stv0297_config dvbc_philips_tdm1316l_config = {
996 .demod_address = 0x1c,
997 .inittab = dvbc_philips_tdm1316l_inittab,
999 .stop_during_read = 1,
1005 static void frontend_init(struct budget_ci *budget_ci)
1007 switch (budget_ci->budget.dev->pci->subsystem_device) {
1008 case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059))
1009 budget_ci->budget.dvb_frontend =
1010 dvb_attach(stv0299_attach, &alps_bsru6_config, &budget_ci->budget.i2c_adap);
1011 if (budget_ci->budget.dvb_frontend) {
1012 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
1013 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
1018 case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059))
1019 budget_ci->budget.dvb_frontend =
1020 dvb_attach(stv0299_attach, &philips_su1278_tt_config, &budget_ci->budget.i2c_adap);
1021 if (budget_ci->budget.dvb_frontend) {
1022 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params;
1027 case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt))
1028 budget_ci->tuner_pll_address = 0x61;
1029 budget_ci->budget.dvb_frontend =
1030 dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1031 if (budget_ci->budget.dvb_frontend) {
1032 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
1037 case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
1038 budget_ci->tuner_pll_address = 0x63;
1039 budget_ci->budget.dvb_frontend =
1040 dvb_attach(tda10045_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1041 if (budget_ci->budget.dvb_frontend) {
1042 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1043 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1048 case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
1049 budget_ci->tuner_pll_address = 0x60;
1050 philips_tdm1316l_config.invert = 1;
1051 budget_ci->budget.dvb_frontend =
1052 dvb_attach(tda10046_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1053 if (budget_ci->budget.dvb_frontend) {
1054 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1055 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1060 case 0x1017: // TT S-1500 PCI
1061 budget_ci->budget.dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config, &budget_ci->budget.i2c_adap);
1062 if (budget_ci->budget.dvb_frontend) {
1063 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
1064 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
1066 budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
1067 if (dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0) == NULL) {
1068 printk("%s: No LNBP21 found!\n", __FUNCTION__);
1069 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1070 budget_ci->budget.dvb_frontend = NULL;
1077 if (budget_ci->budget.dvb_frontend == NULL) {
1078 printk("budget-ci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
1079 budget_ci->budget.dev->pci->vendor,
1080 budget_ci->budget.dev->pci->device,
1081 budget_ci->budget.dev->pci->subsystem_vendor,
1082 budget_ci->budget.dev->pci->subsystem_device);
1084 if (dvb_register_frontend
1085 (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
1086 printk("budget-ci: Frontend registration failed!\n");
1087 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1088 budget_ci->budget.dvb_frontend = NULL;
1093 static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
1095 struct budget_ci *budget_ci;
1098 if (!(budget_ci = kmalloc(sizeof(struct budget_ci), GFP_KERNEL)))
1101 dprintk(2, "budget_ci: %p\n", budget_ci);
1103 budget_ci->budget.ci_present = 0;
1105 dev->ext_priv = budget_ci;
1107 if ((err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE))) {
1112 tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,
1113 (unsigned long) budget_ci);
1115 msp430_ir_init(budget_ci);
1117 ciintf_init(budget_ci);
1119 budget_ci->budget.dvb_adapter.priv = budget_ci;
1120 frontend_init(budget_ci);
1122 ttpci_budget_init_hooks(&budget_ci->budget);
1127 static int budget_ci_detach(struct saa7146_dev *dev)
1129 struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
1130 struct saa7146_dev *saa = budget_ci->budget.dev;
1133 if (budget_ci->budget.ci_present)
1134 ciintf_deinit(budget_ci);
1135 if (budget_ci->budget.dvb_frontend) {
1136 dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
1137 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1139 err = ttpci_budget_deinit(&budget_ci->budget);
1141 tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
1143 msp430_ir_deinit(budget_ci);
1145 // disable frontend and CI interface
1146 saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
1153 static struct saa7146_extension budget_extension;
1155 MAKE_BUDGET_INFO(ttbs2, "TT-Budget/S-1500 PCI", BUDGET_TT);
1156 MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
1157 MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
1158 MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
1159 MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT);
1161 static struct pci_device_id pci_tbl[] = {
1162 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
1163 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
1164 MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
1165 MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
1166 MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
1167 MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
1173 MODULE_DEVICE_TABLE(pci, pci_tbl);
1175 static struct saa7146_extension budget_extension = {
1176 .name = "budget_ci dvb",
1177 .flags = SAA7146_I2C_SHORT_DELAY,
1179 .module = THIS_MODULE,
1180 .pci_tbl = &pci_tbl[0],
1181 .attach = budget_ci_attach,
1182 .detach = budget_ci_detach,
1184 .irq_mask = MASK_03 | MASK_06 | MASK_10,
1185 .irq_func = budget_ci_irq,
1188 static int __init budget_ci_init(void)
1190 return saa7146_register_extension(&budget_extension);
1193 static void __exit budget_ci_exit(void)
1195 saa7146_unregister_extension(&budget_extension);
1198 module_init(budget_ci_init);
1199 module_exit(budget_ci_exit);
1201 MODULE_LICENSE("GPL");
1202 MODULE_AUTHOR("Michael Hunold, Jack Thomasson, Andrew de Quincey, others");
1203 MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
1204 "budget PCI DVB cards w/ CI-module produced by "
1205 "Siemens, Technotrend, Hauppauge");