32 #include <linux/module.h>
33 #include <linux/errno.h>
34 #include <linux/slab.h>
57 #define MODULE_NAME "budget_ci"
66 #define DEBIADDR_IR 0x4000
67 #define DEBIADDR_CICONTROL 0x0000
68 #define DEBIADDR_CIVERSION 0x4000
69 #define DEBIADDR_IO 0x1000
70 #define DEBIADDR_ATTR 0x3000
72 #define CICONTROL_RESET 0x01
73 #define CICONTROL_ENABLETS 0x02
74 #define CICONTROL_CAMDETECT 0x08
76 #define DEBICICTL 0x00420000
77 #define DEBICICAM 0x02420000
79 #define SLOTSTATUS_NONE 1
80 #define SLOTSTATUS_PRESENT 2
81 #define SLOTSTATUS_RESET 4
82 #define SLOTSTATUS_READY 8
83 #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
86 #define IR_DEVICE_ANY 255
88 static int rc5_device = -1;
90 MODULE_PARM_DESC(rc5_device,
"only IR commands to given RC5 device (device = 0 - 31, any device = 255, default: autodetect)");
119 static void msp430_ir_interrupt(
unsigned long data)
142 printk(
"budget_ci: received byte 0x%02x\n", command);
145 command = command & 0x7f;
148 if (command & 0x40) {
149 budget_ci->
ir.have_command =
true;
150 budget_ci->
ir.ir_key = command & 0x3f;
155 if (!budget_ci->
ir.have_command)
157 budget_ci->
ir.have_command =
false;
160 budget_ci->
ir.rc5_device != (command & 0x1f))
163 if (budget_ci->
ir.full_rc5) {
165 budget_ci->
ir.rc5_device <<8 | budget_ci->
ir.ir_key,
166 (command & 0x20) ? 1 : 0);
171 rc_keydown(dev, budget_ci->
ir.ir_key, (command & 0x20) ? 1 : 0);
174 static int msp430_ir_init(
struct budget_ci *budget_ci)
182 printk(
KERN_ERR "budget_ci: IR interface initialisation failed\n");
186 snprintf(budget_ci->
ir.name,
sizeof(budget_ci->
ir.name),
187 "Budget-CI dvb ir receiver %s", saa->
name);
188 snprintf(budget_ci->
ir.phys,
sizeof(budget_ci->
ir.phys),
189 "pci-%s/ir0", pci_name(saa->
pci));
196 if (saa->
pci->subsystem_vendor) {
198 dev->
input_id.product = saa->
pci->subsystem_device;
203 dev->
dev.parent = &saa->
pci->dev;
208 budget_ci->
ir.rc5_device = rc5_device;
211 switch (budget_ci->
budget.dev->pci->subsystem_device) {
218 budget_ci->
ir.full_rc5 =
true;
221 budget_ci->
ir.rc5_device = 0x1f;
236 if (!budget_ci->
ir.full_rc5)
241 printk(
KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
246 budget_ci->
ir.dev =
dev;
248 tasklet_init(&budget_ci->
ir.msp430_irq_tasklet, msp430_ir_interrupt,
249 (
unsigned long) budget_ci);
251 SAA7146_IER_ENABLE(saa,
MASK_06);
257 static void msp430_ir_deinit(
struct budget_ci *budget_ci)
261 SAA7146_IER_DISABLE(saa,
MASK_06);
270 struct budget_ci *budget_ci = (
struct budget_ci *) ca->
data;
281 struct budget_ci *budget_ci = (
struct budget_ci *) ca->
data;
290 static int ciintf_read_cam_control(
struct dvb_ca_en50221 *ca,
int slot,
u8 address)
292 struct budget_ci *budget_ci = (
struct budget_ci *) ca->
data;
301 static int ciintf_write_cam_control(
struct dvb_ca_en50221 *ca,
int slot,
u8 address,
u8 value)
303 struct budget_ci *budget_ci = (
struct budget_ci *) ca->
data;
314 struct budget_ci *budget_ci = (
struct budget_ci *) ca->
data;
335 static int ciintf_slot_shutdown(
struct dvb_ca_en50221 *ca,
int slot)
337 struct budget_ci *budget_ci = (
struct budget_ci *) ca->
data;
348 static int ciintf_slot_ts_enable(
struct dvb_ca_en50221 *ca,
int slot)
350 struct budget_ci *budget_ci = (
struct budget_ci *) ca->
data;
367 static void ciintf_interrupt(
unsigned long data)
369 struct budget_ci *budget_ci = (
struct budget_ci *) data;
374 if (!budget_ci->
budget.ci_present)
418 struct budget_ci *budget_ci = (
struct budget_ci *) ca->
data;
427 if (flags & CICONTROL_CAMDETECT) {
435 if (ciintf_read_attribute_mem(ca, slot, 0) == 0x1d) {
453 static int ciintf_init(
struct budget_ci *budget_ci)
468 if ((ci_version & 0xa0) != 0xa0) {
476 if (flags & CICONTROL_CAMDETECT)
480 if (ci_version == 0xa2) {
492 budget_ci->
ca.read_attribute_mem = ciintf_read_attribute_mem;
493 budget_ci->
ca.write_attribute_mem = ciintf_write_attribute_mem;
494 budget_ci->
ca.read_cam_control = ciintf_read_cam_control;
495 budget_ci->
ca.write_cam_control = ciintf_write_cam_control;
496 budget_ci->
ca.slot_reset = ciintf_slot_reset;
497 budget_ci->
ca.slot_shutdown = ciintf_slot_shutdown;
498 budget_ci->
ca.slot_ts_enable = ciintf_slot_ts_enable;
499 budget_ci->
ca.poll_slot_status = ciintf_poll_slot_status;
500 budget_ci->
ca.data = budget_ci;
503 ca_flags, 1)) != 0) {
504 printk(
"budget_ci: CI interface detected, but initialisation failed.\n");
516 SAA7146_IER_ENABLE(saa,
MASK_03);
524 printk(
"budget_ci: CI interface initialised\n");
525 budget_ci->
budget.ci_present = 1;
542 static void ciintf_deinit(
struct budget_ci *budget_ci)
548 SAA7146_IER_DISABLE(saa,
MASK_03);
571 struct budget_ci *budget_ci = (
struct budget_ci *) dev->
ext_priv;
573 dprintk(8,
"dev: %p, budget_ci: %p\n", dev, budget_ci);
576 tasklet_schedule(&budget_ci->
ir.msp430_irq_tasklet);
585 static u8 philips_su1278_tt_inittab[] = {
633 stv0299_writereg(fe, 0x0e, 0x44);
634 if (srate >= 10000000) {
635 stv0299_writereg(fe, 0x13, 0x97);
636 stv0299_writereg(fe, 0x14, 0x95);
637 stv0299_writereg(fe, 0x15, 0xc9);
638 stv0299_writereg(fe, 0x17, 0x8c);
639 stv0299_writereg(fe, 0x1a, 0xfe);
640 stv0299_writereg(fe, 0x1c, 0x7f);
641 stv0299_writereg(fe, 0x2d, 0x09);
643 stv0299_writereg(fe, 0x13, 0x99);
644 stv0299_writereg(fe, 0x14, 0x8d);
645 stv0299_writereg(fe, 0x15, 0xce);
646 stv0299_writereg(fe, 0x17, 0x43);
647 stv0299_writereg(fe, 0x1a, 0x1d);
648 stv0299_writereg(fe, 0x1c, 0x12);
649 stv0299_writereg(fe, 0x2d, 0x05);
651 stv0299_writereg(fe, 0x0e, 0x23);
652 stv0299_writereg(fe, 0x0f, 0x94);
653 stv0299_writereg(fe, 0x10, 0x39);
654 stv0299_writereg(fe, 0x15, 0xc9);
656 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
657 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
658 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
663 static int philips_su1278_tt_tuner_set_params(
struct dvb_frontend *fe)
666 struct budget_ci *budget_ci = (
struct budget_ci *) fe->
dvb->priv;
669 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf =
buf,.len =
sizeof(
buf) };
671 if ((
p->frequency < 950000) || (
p->frequency > 2150000))
674 div = (
p->frequency + (500 - 1)) / 500;
675 buf[0] = (
div >> 8) & 0x7f;
677 buf[2] = 0x80 | ((
div & 0x18000) >> 10) | 2;
680 if (
p->symbol_rate < 4000000)
683 if (
p->frequency < 1250000)
685 else if (
p->frequency < 1550000)
687 else if (
p->frequency < 2050000)
689 else if (
p->frequency < 2150000)
692 if (fe->
ops.i2c_gate_ctrl)
693 fe->
ops.i2c_gate_ctrl(fe, 1);
701 .demod_address = 0x68,
702 .inittab = philips_su1278_tt_inittab,
709 .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
714 static int philips_tdm1316l_tuner_init(
struct dvb_frontend *fe)
716 struct budget_ci *budget_ci = (
struct budget_ci *) fe->
dvb->priv;
717 static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
718 static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
720 sizeof(td1316_init) };
723 if (fe->
ops.i2c_gate_ctrl)
724 fe->
ops.i2c_gate_ctrl(fe, 1);
730 tuner_msg.
addr = 0x65;
731 tuner_msg.
buf = disable_mc44BC374c;
732 tuner_msg.
len =
sizeof(disable_mc44BC374c);
733 if (fe->
ops.i2c_gate_ctrl)
734 fe->
ops.i2c_gate_ctrl(fe, 1);
736 if (fe->
ops.i2c_gate_ctrl)
737 fe->
ops.i2c_gate_ctrl(fe, 1);
744 static int philips_tdm1316l_tuner_set_params(
struct dvb_frontend *fe)
747 struct budget_ci *budget_ci = (
struct budget_ci *) fe->
dvb->priv;
750 int tuner_frequency = 0;
754 tuner_frequency =
p->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 (
p->frequency < 49000000)
781 else if (
p->frequency < 159000000)
783 else if (
p->frequency < 444000000)
785 else if (
p->frequency < 861000000)
791 switch (
p->bandwidth_hz) {
793 tda1004x_writereg(fe, 0x0C, 0x14);
798 tda1004x_writereg(fe, 0x0C, 0x80);
803 tda1004x_writereg(fe, 0x0C, 0x14);
813 tuner_frequency = (((
p->frequency / 1000) * 6) + 217280) / 1000;
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 (fe->
ops.i2c_gate_ctrl)
822 fe->
ops.i2c_gate_ctrl(fe, 1);
830 static int philips_tdm1316l_request_firmware(
struct dvb_frontend *fe,
833 struct budget_ci *budget_ci = (
struct budget_ci *) fe->
dvb->priv;
840 .demod_address = 0x8,
846 .request_firmware = philips_tdm1316l_request_firmware,
851 .demod_address = 0x8,
857 .request_firmware = philips_tdm1316l_request_firmware,
860 static int dvbc_philips_tdm1316l_tuner_set_params(
struct dvb_frontend *fe)
863 struct budget_ci *budget_ci = (
struct budget_ci *) fe->
dvb->priv;
868 .len =
sizeof(tuner_buf) };
869 int tuner_frequency = 0;
873 tuner_frequency =
p->frequency + 36125000;
874 if (tuner_frequency < 87000000)
876 else if (tuner_frequency < 130000000) {
879 }
else if (tuner_frequency < 160000000) {
882 }
else if (tuner_frequency < 200000000) {
885 }
else if (tuner_frequency < 290000000) {
888 }
else if (tuner_frequency < 420000000) {
891 }
else if (tuner_frequency < 480000000) {
894 }
else if (tuner_frequency < 620000000) {
897 }
else if (tuner_frequency < 830000000) {
900 }
else if (tuner_frequency < 895000000) {
910 tuner_frequency = (
p->frequency + 36125000 + (62500/2)) / 62500;
913 tuner_buf[0] = tuner_frequency >> 8;
914 tuner_buf[1] = tuner_frequency & 0xff;
916 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
919 if (fe->
ops.i2c_gate_ctrl)
920 fe->
ops.i2c_gate_ctrl(fe, 1);
926 if (fe->
ops.i2c_gate_ctrl)
927 fe->
ops.i2c_gate_ctrl(fe, 1);
936 static u8 dvbc_philips_tdm1316l_inittab[] = {
1030 .demod_address = 0x1c,
1031 .inittab = dvbc_philips_tdm1316l_inittab,
1033 .stop_during_read = 1,
1051 static const struct stb0899_s1_reg tt3200_stb0899_s1_init_1[] = {
1138 static const struct stb0899_s1_reg tt3200_stb0899_s1_init_3[] = {
1272 .init_dev = tt3200_stb0899_s1_init_1,
1273 .init_s2_demod = stb0899_s2_init_2,
1274 .init_s1_demod = tt3200_stb0899_s1_init_3,
1275 .init_s2_fec = stb0899_s2_init_4,
1276 .init_tst = stb0899_s1_init_5,
1280 .demod_address = 0x68,
1282 .xtal_freq = 27000000,
1303 .tuner_get_frequency = stb6100_get_frequency,
1304 .tuner_set_frequency = stb6100_set_frequency,
1305 .tuner_set_bandwidth = stb6100_set_bandwidth,
1306 .tuner_get_bandwidth = stb6100_get_bandwidth,
1307 .tuner_set_rfsiggain =
NULL
1311 .tuner_address = 0x60,
1312 .refclock = 27000000,
1315 static void frontend_init(
struct budget_ci *budget_ci)
1317 switch (budget_ci->
budget.dev->pci->subsystem_device) {
1319 budget_ci->
budget.dvb_frontend =
1321 if (budget_ci->
budget.dvb_frontend) {
1322 budget_ci->
budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
1323 budget_ci->
budget.dvb_frontend->tuner_priv = &budget_ci->
budget.i2c_adap;
1329 budget_ci->
budget.dvb_frontend =
1331 if (budget_ci->
budget.dvb_frontend) {
1332 budget_ci->
budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params;
1339 budget_ci->
budget.dvb_frontend =
1341 if (budget_ci->
budget.dvb_frontend) {
1342 budget_ci->
budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
1349 budget_ci->
budget.dvb_frontend =
1351 if (budget_ci->
budget.dvb_frontend) {
1352 budget_ci->
budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1353 budget_ci->
budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1360 budget_ci->
budget.dvb_frontend =
1362 if (budget_ci->
budget.dvb_frontend) {
1363 budget_ci->
budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1364 budget_ci->
budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1371 if (budget_ci->
budget.dvb_frontend) {
1372 budget_ci->
budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
1373 budget_ci->
budget.dvb_frontend->tuner_priv = &budget_ci->
budget.i2c_adap;
1375 budget_ci->
budget.dvb_frontend->ops.dishnetwork_send_legacy_command =
NULL;
1377 printk(
"%s: No LNBP21 found!\n", __func__);
1386 if (budget_ci->
budget.dvb_frontend) {
1397 if (budget_ci->
budget.dvb_frontend) {
1437 if (budget_ci->
budget.dvb_frontend) {
1440 printk(
"%s: No LNBP21 found!\n", __func__);
1453 if (budget_ci->
budget.dvb_frontend ==
NULL) {
1454 printk(
"budget-ci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
1455 budget_ci->
budget.dev->pci->vendor,
1456 budget_ci->
budget.dev->pci->device,
1457 budget_ci->
budget.dev->pci->subsystem_vendor,
1458 budget_ci->
budget.dev->pci->subsystem_device);
1461 (&budget_ci->
budget.dvb_adapter, budget_ci->
budget.dvb_frontend)) {
1462 printk(
"budget-ci: Frontend registration failed!\n");
1471 struct budget_ci *budget_ci;
1474 budget_ci = kzalloc(
sizeof(
struct budget_ci),
GFP_KERNEL);
1480 dprintk(2,
"budget_ci: %p\n", budget_ci);
1489 err = msp430_ir_init(budget_ci);
1493 ciintf_init(budget_ci);
1495 budget_ci->
budget.dvb_adapter.priv = budget_ci;
1496 frontend_init(budget_ci);
1510 static int budget_ci_detach(
struct saa7146_dev *dev)
1512 struct budget_ci *budget_ci = (
struct budget_ci *) dev->
ext_priv;
1517 ciintf_deinit(budget_ci);
1518 msp430_ir_deinit(budget_ci);
1519 if (budget_ci->
budget.dvb_frontend) {
1562 .name =
"budget_ci dvb",
1566 .pci_tbl = &pci_tbl[0],
1567 .attach = budget_ci_attach,
1568 .detach = budget_ci_detach,
1570 .irq_mask = MASK_03 | MASK_06 |
MASK_10,
1571 .irq_func = budget_ci_irq,
1574 static int __init budget_ci_init(
void)
1579 static void __exit budget_ci_exit(
void)
1588 MODULE_AUTHOR(
"Michael Hunold, Jack Thomasson, Andrew de Quincey, others");
1590 "budget PCI DVB cards w/ CI-module produced by "
1591 "Siemens, Technotrend, Hauppauge");