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"
49 #define DEBIADDR_IR 0x1234
50 #define DEBIADDR_CICONTROL 0x0000
51 #define DEBIADDR_CIVERSION 0x4000
52 #define DEBIADDR_IO 0x1000
53 #define DEBIADDR_ATTR 0x3000
55 #define CICONTROL_RESET 0x01
56 #define CICONTROL_ENABLETS 0x02
57 #define CICONTROL_CAMDETECT 0x08
59 #define DEBICICTL 0x00420000
60 #define DEBICICAM 0x02420000
62 #define SLOTSTATUS_NONE 1
63 #define SLOTSTATUS_PRESENT 2
64 #define SLOTSTATUS_RESET 4
65 #define SLOTSTATUS_READY 8
66 #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
70 struct input_dev *input_dev;
71 struct tasklet_struct msp430_irq_tasklet;
72 struct tasklet_struct ciintf_irq_tasklet;
75 struct dvb_ca_en50221 ca;
77 u8 tuner_pll_address; /* used for philips_tdm1316l configs */
80 /* from reading the following remotes:
81 Zenith Universal 7 / TV Mode 807 / VCR Mode 837
82 Hauppauge (from NOVA-CI-s box product)
83 i've taken a "middle of the road" approach and note the differences
85 static u16 key_map[64] = {
87 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8,
91 KEY_POWER, /* RADIO on Hauppauge */
94 KEY_A, /* TV on Hauppauge */
96 KEY_VOLUMEUP, KEY_VOLUMEDOWN,
101 KEY_OPTION, /* RESERVED on Hauppauge */
104 KEY_CHANNELUP, KEY_CHANNELDOWN,
105 KEY_PREVIOUS, /* Prev. Ch on Zenith, SOURCE on Hauppauge */
106 0, KEY_RESTART, KEY_OK,
107 KEY_CYCLEWINDOWS, /* MINIMIZE on Hauppauge */
109 KEY_ENTER, /* VCR mode on Zenith */
114 KEY_MENU, /* FULL SCREEN on Hauppauge */
118 KEY_PREVIOUS, /* VCR mode on Zenith */
124 KEY_TUNER, /* TV/VCR on Zenith */
130 KEY_TUNER, /* VCR mode on Zenith */
134 static void msp430_ir_debounce(unsigned long data)
136 struct input_dev *dev = (struct input_dev *) data;
138 if (dev->rep[0] == 0 || dev->rep[0] == ~0) {
139 input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0);
144 dev->timer.expires = jiffies + HZ * 350 / 1000;
145 add_timer(&dev->timer);
146 input_event(dev, EV_KEY, key_map[dev->repeat_key], 2); /* REPEAT */
149 static void msp430_ir_interrupt(unsigned long data)
151 struct budget_ci *budget_ci = (struct budget_ci *) data;
152 struct input_dev *dev = budget_ci->input_dev;
154 ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
159 if (timer_pending(&dev->timer)) {
160 if (code == dev->repeat_key) {
164 del_timer(&dev->timer);
165 input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0);
168 if (!key_map[code]) {
169 printk("DVB (%s): no key for %02x!\n", __FUNCTION__, code);
173 /* initialize debounce and repeat */
174 dev->repeat_key = code;
175 /* Zenith remote _always_ sends 2 sequences */
177 /* 350 milliseconds */
178 dev->timer.expires = jiffies + HZ * 350 / 1000;
180 input_event(dev, EV_KEY, key_map[code], !0);
181 add_timer(&dev->timer);
185 static int msp430_ir_init(struct budget_ci *budget_ci)
187 struct saa7146_dev *saa = budget_ci->budget.dev;
188 struct input_dev *input_dev;
191 budget_ci->input_dev = input_dev = input_allocate_device();
195 sprintf(budget_ci->ir_dev_name, "Budget-CI dvb ir receiver %s", saa->name);
197 input_dev->name = budget_ci->ir_dev_name;
199 set_bit(EV_KEY, input_dev->evbit);
200 for (i = 0; i < ARRAY_SIZE(key_map); i++)
202 set_bit(key_map[i], input_dev->keybit);
204 input_register_device(budget_ci->input_dev);
206 input_dev->timer.function = msp430_ir_debounce;
208 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_06);
209 saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
214 static void msp430_ir_deinit(struct budget_ci *budget_ci)
216 struct saa7146_dev *saa = budget_ci->budget.dev;
217 struct input_dev *dev = budget_ci->input_dev;
219 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_06);
220 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
222 if (del_timer(&dev->timer))
223 input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0);
225 input_unregister_device(dev);
228 static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
230 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
235 return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
236 DEBIADDR_ATTR | (address & 0xfff), 1, 1, 0);
239 static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
241 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
246 return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
247 DEBIADDR_ATTR | (address & 0xfff), 1, value, 1, 0);
250 static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
252 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
257 return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
258 DEBIADDR_IO | (address & 3), 1, 1, 0);
261 static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
263 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
268 return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
269 DEBIADDR_IO | (address & 3), 1, value, 1, 0);
272 static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
274 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
275 struct saa7146_dev *saa = budget_ci->budget.dev;
280 if (budget_ci->ci_irq) {
281 // trigger on RISING edge during reset so we know when READY is re-asserted
282 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
284 budget_ci->slot_status = SLOTSTATUS_RESET;
285 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
287 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
288 CICONTROL_RESET, 1, 0);
290 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
291 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
295 static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
297 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
298 struct saa7146_dev *saa = budget_ci->budget.dev;
303 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
304 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
308 static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
310 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
311 struct saa7146_dev *saa = budget_ci->budget.dev;
317 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
319 tmp = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
320 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
321 tmp | CICONTROL_ENABLETS, 1, 0);
323 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);
327 static void ciintf_interrupt(unsigned long data)
329 struct budget_ci *budget_ci = (struct budget_ci *) data;
330 struct saa7146_dev *saa = budget_ci->budget.dev;
333 // ensure we don't get spurious IRQs during initialisation
334 if (!budget_ci->budget.ci_present)
337 // read the CAM status
338 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
339 if (flags & CICONTROL_CAMDETECT) {
341 // GPIO should be set to trigger on falling edge if a CAM is present
342 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
344 if (budget_ci->slot_status & SLOTSTATUS_NONE) {
346 budget_ci->slot_status = SLOTSTATUS_PRESENT;
347 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
348 DVB_CA_EN50221_CAMCHANGE_INSERTED);
350 } else if (budget_ci->slot_status & SLOTSTATUS_RESET) {
351 // CAM ready (reset completed)
352 budget_ci->slot_status = SLOTSTATUS_READY;
353 dvb_ca_en50221_camready_irq(&budget_ci->ca, 0);
355 } else if (budget_ci->slot_status & SLOTSTATUS_READY) {
357 dvb_ca_en50221_frda_irq(&budget_ci->ca, 0);
361 // trigger on rising edge if a CAM is not present - when a CAM is inserted, we
362 // only want to get the IRQ when it sets READY. If we trigger on the falling edge,
363 // the CAM might not actually be ready yet.
364 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
366 // generate a CAM removal IRQ if we haven't already
367 if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) {
369 budget_ci->slot_status = SLOTSTATUS_NONE;
370 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
371 DVB_CA_EN50221_CAMCHANGE_REMOVED);
376 static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
378 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
381 // ensure we don't get spurious IRQs during initialisation
382 if (!budget_ci->budget.ci_present)
385 // read the CAM status
386 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
387 if (flags & CICONTROL_CAMDETECT) {
388 // mark it as present if it wasn't before
389 if (budget_ci->slot_status & SLOTSTATUS_NONE) {
390 budget_ci->slot_status = SLOTSTATUS_PRESENT;
393 // during a RESET, we check if we can read from IO memory to see when CAM is ready
394 if (budget_ci->slot_status & SLOTSTATUS_RESET) {
395 if (ciintf_read_attribute_mem(ca, slot, 0) == 0x1d) {
396 budget_ci->slot_status = SLOTSTATUS_READY;
400 budget_ci->slot_status = SLOTSTATUS_NONE;
403 if (budget_ci->slot_status != SLOTSTATUS_NONE) {
404 if (budget_ci->slot_status & SLOTSTATUS_READY) {
405 return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
407 return DVB_CA_EN50221_POLL_CAM_PRESENT;
413 static int ciintf_init(struct budget_ci *budget_ci)
415 struct saa7146_dev *saa = budget_ci->budget.dev;
421 memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221));
424 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16) | 0x800);
426 // test if it is there
427 ci_version = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0);
428 if ((ci_version & 0xa0) != 0xa0) {
433 // determine whether a CAM is present or not
434 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
435 budget_ci->slot_status = SLOTSTATUS_NONE;
436 if (flags & CICONTROL_CAMDETECT)
437 budget_ci->slot_status = SLOTSTATUS_PRESENT;
439 // version 0xa2 of the CI firmware doesn't generate interrupts
440 if (ci_version == 0xa2) {
442 budget_ci->ci_irq = 0;
444 ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE |
445 DVB_CA_EN50221_FLAG_IRQ_FR |
446 DVB_CA_EN50221_FLAG_IRQ_DA;
447 budget_ci->ci_irq = 1;
450 // register CI interface
451 budget_ci->ca.owner = THIS_MODULE;
452 budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem;
453 budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem;
454 budget_ci->ca.read_cam_control = ciintf_read_cam_control;
455 budget_ci->ca.write_cam_control = ciintf_write_cam_control;
456 budget_ci->ca.slot_reset = ciintf_slot_reset;
457 budget_ci->ca.slot_shutdown = ciintf_slot_shutdown;
458 budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable;
459 budget_ci->ca.poll_slot_status = ciintf_poll_slot_status;
460 budget_ci->ca.data = budget_ci;
461 if ((result = dvb_ca_en50221_init(&budget_ci->budget.dvb_adapter,
463 ca_flags, 1)) != 0) {
464 printk("budget_ci: CI interface detected, but initialisation failed.\n");
469 if (budget_ci->ci_irq) {
470 tasklet_init(&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, (unsigned long) budget_ci);
471 if (budget_ci->slot_status != SLOTSTATUS_NONE) {
472 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
474 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
476 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_03);
480 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
481 CICONTROL_RESET, 1, 0);
484 printk("budget_ci: CI interface initialised\n");
485 budget_ci->budget.ci_present = 1;
487 // forge a fake CI IRQ so the CAM state is setup correctly
488 if (budget_ci->ci_irq) {
489 flags = DVB_CA_EN50221_CAMCHANGE_REMOVED;
490 if (budget_ci->slot_status != SLOTSTATUS_NONE)
491 flags = DVB_CA_EN50221_CAMCHANGE_INSERTED;
492 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, flags);
498 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16));
502 static void ciintf_deinit(struct budget_ci *budget_ci)
504 struct saa7146_dev *saa = budget_ci->budget.dev;
506 // disable CI interrupts
507 if (budget_ci->ci_irq) {
508 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_03);
509 saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
510 tasklet_kill(&budget_ci->ciintf_irq_tasklet);
514 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
516 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
517 CICONTROL_RESET, 1, 0);
519 // disable TS data stream to CI interface
520 saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT);
522 // release the CA device
523 dvb_ca_en50221_release(&budget_ci->ca);
526 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16));
529 static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
531 struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
533 dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci);
536 tasklet_schedule(&budget_ci->msp430_irq_tasklet);
539 ttpci_budget_irq10_handler(dev, isr);
541 if ((*isr & MASK_03) && (budget_ci->budget.ci_present) && (budget_ci->ci_irq))
542 tasklet_schedule(&budget_ci->ciintf_irq_tasklet);
545 static u8 philips_su1278_tt_inittab[] = {
591 static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
593 stv0299_writereg(fe, 0x0e, 0x44);
594 if (srate >= 10000000) {
595 stv0299_writereg(fe, 0x13, 0x97);
596 stv0299_writereg(fe, 0x14, 0x95);
597 stv0299_writereg(fe, 0x15, 0xc9);
598 stv0299_writereg(fe, 0x17, 0x8c);
599 stv0299_writereg(fe, 0x1a, 0xfe);
600 stv0299_writereg(fe, 0x1c, 0x7f);
601 stv0299_writereg(fe, 0x2d, 0x09);
603 stv0299_writereg(fe, 0x13, 0x99);
604 stv0299_writereg(fe, 0x14, 0x8d);
605 stv0299_writereg(fe, 0x15, 0xce);
606 stv0299_writereg(fe, 0x17, 0x43);
607 stv0299_writereg(fe, 0x1a, 0x1d);
608 stv0299_writereg(fe, 0x1c, 0x12);
609 stv0299_writereg(fe, 0x2d, 0x05);
611 stv0299_writereg(fe, 0x0e, 0x23);
612 stv0299_writereg(fe, 0x0f, 0x94);
613 stv0299_writereg(fe, 0x10, 0x39);
614 stv0299_writereg(fe, 0x15, 0xc9);
616 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
617 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
618 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
623 static int philips_su1278_tt_tuner_set_params(struct dvb_frontend *fe,
624 struct dvb_frontend_parameters *params)
626 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
629 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
631 if ((params->frequency < 950000) || (params->frequency > 2150000))
634 div = (params->frequency + (500 - 1)) / 500; // round correctly
635 buf[0] = (div >> 8) & 0x7f;
637 buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2;
640 if (params->u.qpsk.symbol_rate < 4000000)
643 if (params->frequency < 1250000)
645 else if (params->frequency < 1550000)
647 else if (params->frequency < 2050000)
649 else if (params->frequency < 2150000)
652 if (fe->ops.i2c_gate_ctrl)
653 fe->ops.i2c_gate_ctrl(fe, 1);
654 if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1)
659 static struct stv0299_config philips_su1278_tt_config = {
661 .demod_address = 0x68,
662 .inittab = philips_su1278_tt_inittab,
666 .lock_output = STV0229_LOCKOUTPUT_1,
667 .volt13_op0_op1 = STV0299_VOLT13_OP1,
669 .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
674 static int philips_tdm1316l_tuner_init(struct dvb_frontend *fe)
676 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
677 static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
678 static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
679 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = td1316_init,.len =
680 sizeof(td1316_init) };
682 // setup PLL configuration
683 if (fe->ops.i2c_gate_ctrl)
684 fe->ops.i2c_gate_ctrl(fe, 1);
685 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
689 // disable the mc44BC374c (do not check for errors)
690 tuner_msg.addr = 0x65;
691 tuner_msg.buf = disable_mc44BC374c;
692 tuner_msg.len = sizeof(disable_mc44BC374c);
693 if (fe->ops.i2c_gate_ctrl)
694 fe->ops.i2c_gate_ctrl(fe, 1);
695 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) {
696 if (fe->ops.i2c_gate_ctrl)
697 fe->ops.i2c_gate_ctrl(fe, 1);
698 i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1);
704 static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
706 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
708 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) };
709 int tuner_frequency = 0;
712 // determine charge pump
713 tuner_frequency = params->frequency + 36130000;
714 if (tuner_frequency < 87000000)
716 else if (tuner_frequency < 130000000)
718 else if (tuner_frequency < 160000000)
720 else if (tuner_frequency < 200000000)
722 else if (tuner_frequency < 290000000)
724 else if (tuner_frequency < 420000000)
726 else if (tuner_frequency < 480000000)
728 else if (tuner_frequency < 620000000)
730 else if (tuner_frequency < 830000000)
732 else if (tuner_frequency < 895000000)
738 if (params->frequency < 49000000)
740 else if (params->frequency < 159000000)
742 else if (params->frequency < 444000000)
744 else if (params->frequency < 861000000)
749 // setup PLL filter and TDA9889
750 switch (params->u.ofdm.bandwidth) {
751 case BANDWIDTH_6_MHZ:
752 tda1004x_write_byte(fe, 0x0C, 0x14);
756 case BANDWIDTH_7_MHZ:
757 tda1004x_write_byte(fe, 0x0C, 0x80);
761 case BANDWIDTH_8_MHZ:
762 tda1004x_write_byte(fe, 0x0C, 0x14);
771 // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
772 tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000;
774 // setup tuner buffer
775 tuner_buf[0] = tuner_frequency >> 8;
776 tuner_buf[1] = tuner_frequency & 0xff;
778 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
780 if (fe->ops.i2c_gate_ctrl)
781 fe->ops.i2c_gate_ctrl(fe, 1);
782 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
789 static int philips_tdm1316l_request_firmware(struct dvb_frontend *fe,
790 const struct firmware **fw, char *name)
792 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
794 return request_firmware(fw, name, &budget_ci->budget.dev->pci->dev);
797 static struct tda1004x_config philips_tdm1316l_config = {
799 .demod_address = 0x8,
802 .xtal_freq = TDA10046_XTAL_4M,
803 .agc_config = TDA10046_AGC_DEFAULT,
804 .if_freq = TDA10046_FREQ_3617,
805 .request_firmware = philips_tdm1316l_request_firmware,
808 static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
810 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
812 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,
815 .len = sizeof(tuner_buf) };
816 int tuner_frequency = 0;
819 // determine charge pump
820 tuner_frequency = params->frequency + 36125000;
821 if (tuner_frequency < 87000000)
823 else if (tuner_frequency < 130000000) {
826 } else if (tuner_frequency < 160000000) {
829 } else if (tuner_frequency < 200000000) {
832 } else if (tuner_frequency < 290000000) {
835 } else if (tuner_frequency < 420000000) {
838 } else if (tuner_frequency < 480000000) {
841 } else if (tuner_frequency < 620000000) {
844 } else if (tuner_frequency < 830000000) {
847 } else if (tuner_frequency < 895000000) {
853 // assume PLL filter should always be 8MHz for the moment.
857 tuner_frequency = (params->frequency + 36125000 + (62500/2)) / 62500;
859 // setup tuner buffer
860 tuner_buf[0] = tuner_frequency >> 8;
861 tuner_buf[1] = tuner_frequency & 0xff;
863 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
866 if (fe->ops.i2c_gate_ctrl)
867 fe->ops.i2c_gate_ctrl(fe, 1);
868 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
873 if (fe->ops.i2c_gate_ctrl)
874 fe->ops.i2c_gate_ctrl(fe, 1);
875 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
883 static u8 dvbc_philips_tdm1316l_inittab[] = {
976 static struct stv0297_config dvbc_philips_tdm1316l_config = {
977 .demod_address = 0x1c,
978 .inittab = dvbc_philips_tdm1316l_inittab,
980 .stop_during_read = 1,
986 static void frontend_init(struct budget_ci *budget_ci)
988 switch (budget_ci->budget.dev->pci->subsystem_device) {
989 case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059))
990 budget_ci->budget.dvb_frontend =
991 stv0299_attach(&alps_bsru6_config, &budget_ci->budget.i2c_adap);
992 if (budget_ci->budget.dvb_frontend) {
993 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
994 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
999 case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059))
1000 budget_ci->budget.dvb_frontend =
1001 stv0299_attach(&philips_su1278_tt_config, &budget_ci->budget.i2c_adap);
1002 if (budget_ci->budget.dvb_frontend) {
1003 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params;
1008 case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt))
1009 budget_ci->tuner_pll_address = 0x61;
1010 budget_ci->budget.dvb_frontend =
1011 stv0297_attach(&dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1012 if (budget_ci->budget.dvb_frontend) {
1013 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
1018 case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
1019 budget_ci->tuner_pll_address = 0x63;
1020 budget_ci->budget.dvb_frontend =
1021 tda10045_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1022 if (budget_ci->budget.dvb_frontend) {
1023 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1024 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1029 case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
1030 budget_ci->tuner_pll_address = 0x60;
1031 budget_ci->budget.dvb_frontend =
1032 tda10046_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1033 if (budget_ci->budget.dvb_frontend) {
1034 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1035 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1040 case 0x1017: // TT S-1500 PCI
1041 budget_ci->budget.dvb_frontend = stv0299_attach(&alps_bsbe1_config, &budget_ci->budget.i2c_adap);
1042 if (budget_ci->budget.dvb_frontend) {
1043 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
1044 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
1046 budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
1047 if (lnbp21_attach(budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0)) {
1048 printk("%s: No LNBP21 found!\n", __FUNCTION__);
1049 if (budget_ci->budget.dvb_frontend->ops.release)
1050 budget_ci->budget.dvb_frontend->ops.release(budget_ci->budget.dvb_frontend);
1051 budget_ci->budget.dvb_frontend = NULL;
1058 if (budget_ci->budget.dvb_frontend == NULL) {
1059 printk("budget-ci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
1060 budget_ci->budget.dev->pci->vendor,
1061 budget_ci->budget.dev->pci->device,
1062 budget_ci->budget.dev->pci->subsystem_vendor,
1063 budget_ci->budget.dev->pci->subsystem_device);
1065 if (dvb_register_frontend
1066 (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
1067 printk("budget-ci: Frontend registration failed!\n");
1068 if (budget_ci->budget.dvb_frontend->ops.release)
1069 budget_ci->budget.dvb_frontend->ops.release(budget_ci->budget.dvb_frontend);
1070 budget_ci->budget.dvb_frontend = NULL;
1075 static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
1077 struct budget_ci *budget_ci;
1080 if (!(budget_ci = kmalloc(sizeof(struct budget_ci), GFP_KERNEL)))
1083 dprintk(2, "budget_ci: %p\n", budget_ci);
1085 budget_ci->budget.ci_present = 0;
1087 dev->ext_priv = budget_ci;
1089 if ((err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE))) {
1094 tasklet_init(&budget_ci->msp430_irq_tasklet, msp430_ir_interrupt,
1095 (unsigned long) budget_ci);
1097 msp430_ir_init(budget_ci);
1099 ciintf_init(budget_ci);
1101 budget_ci->budget.dvb_adapter.priv = budget_ci;
1102 frontend_init(budget_ci);
1104 ttpci_budget_init_hooks(&budget_ci->budget);
1109 static int budget_ci_detach(struct saa7146_dev *dev)
1111 struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
1112 struct saa7146_dev *saa = budget_ci->budget.dev;
1115 if (budget_ci->budget.ci_present)
1116 ciintf_deinit(budget_ci);
1117 if (budget_ci->budget.dvb_frontend)
1118 dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
1119 err = ttpci_budget_deinit(&budget_ci->budget);
1121 tasklet_kill(&budget_ci->msp430_irq_tasklet);
1123 msp430_ir_deinit(budget_ci);
1125 // disable frontend and CI interface
1126 saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
1133 static struct saa7146_extension budget_extension;
1135 MAKE_BUDGET_INFO(ttbs2, "TT-Budget/S-1500 PCI", BUDGET_TT);
1136 MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
1137 MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
1138 MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
1139 MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT);
1141 static struct pci_device_id pci_tbl[] = {
1142 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
1143 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
1144 MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
1145 MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
1146 MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
1147 MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
1153 MODULE_DEVICE_TABLE(pci, pci_tbl);
1155 static struct saa7146_extension budget_extension = {
1156 .name = "budget_ci dvb\0",
1157 .flags = SAA7146_I2C_SHORT_DELAY,
1159 .module = THIS_MODULE,
1160 .pci_tbl = &pci_tbl[0],
1161 .attach = budget_ci_attach,
1162 .detach = budget_ci_detach,
1164 .irq_mask = MASK_03 | MASK_06 | MASK_10,
1165 .irq_func = budget_ci_irq,
1168 static int __init budget_ci_init(void)
1170 return saa7146_register_extension(&budget_extension);
1173 static void __exit budget_ci_exit(void)
1175 saa7146_unregister_extension(&budget_extension);
1178 module_init(budget_ci_init);
1179 module_exit(budget_ci_exit);
1181 MODULE_LICENSE("GPL");
1182 MODULE_AUTHOR("Michael Hunold, Jack Thomasson, Andrew de Quincey, others");
1183 MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
1184 "budget PCI DVB cards w/ CI-module produced by "
1185 "Siemens, Technotrend, Hauppauge");