36 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
50 #include <linux/module.h>
51 #include <linux/errno.h>
52 #include <linux/slab.h>
54 #include <linux/input.h>
59 #define DEBICICAM 0x02420000
61 #define SLOTSTATUS_NONE 1
62 #define SLOTSTATUS_PRESENT 2
63 #define SLOTSTATUS_RESET 4
64 #define SLOTSTATUS_READY 8
65 #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
102 msgs[0].addr = msgs[1].addr =
id / 2;
118 {.
addr =
id / 2,.flags = 0,.buf = mm1,.len = 1},
119 {.addr =
id / 2,.flags =
I2C_M_RD,.buf =
buf,.len = len}
153 ciintf_slot_shutdown(ca, slot);
161 struct budget_av *budget_av = (
struct budget_av *) ca->
data;
172 ciintf_slot_shutdown(ca, slot);
178 static int ciintf_read_cam_control(
struct dvb_ca_en50221 *ca,
int slot,
u8 address)
180 struct budget_av *budget_av = (
struct budget_av *) ca->
data;
191 ciintf_slot_shutdown(ca, slot);
198 static int ciintf_write_cam_control(
struct dvb_ca_en50221 *ca,
int slot,
u8 address,
u8 value)
200 struct budget_av *budget_av = (
struct budget_av *) ca->
data;
211 ciintf_slot_shutdown(ca, slot);
219 struct budget_av *budget_av = (
struct budget_av *) ca->
data;
225 dprintk(1,
"ciintf_slot_reset\n");
246 static int ciintf_slot_shutdown(
struct dvb_ca_en50221 *ca,
int slot)
248 struct budget_av *budget_av = (
struct budget_av *) ca->
data;
254 dprintk(1,
"ciintf_slot_shutdown\n");
262 static int ciintf_slot_ts_enable(
struct dvb_ca_en50221 *ca,
int slot)
264 struct budget_av *budget_av = (
struct budget_av *) ca->
data;
279 struct budget_av *budget_av = (
struct budget_av *) ca->
data;
314 ciintf_slot_shutdown(ca, slot);
323 result = ciintf_read_attribute_mem(ca, slot, 0);
339 static int ciintf_init(
struct budget_av *budget_av)
356 budget_av->
ca.read_attribute_mem = ciintf_read_attribute_mem;
357 budget_av->
ca.write_attribute_mem = ciintf_write_attribute_mem;
358 budget_av->
ca.read_cam_control = ciintf_read_cam_control;
359 budget_av->
ca.write_cam_control = ciintf_write_cam_control;
360 budget_av->
ca.slot_reset = ciintf_slot_reset;
361 budget_av->
ca.slot_shutdown = ciintf_slot_shutdown;
362 budget_av->
ca.slot_ts_enable = ciintf_slot_ts_enable;
363 budget_av->
ca.poll_slot_status = ciintf_poll_slot_status;
364 budget_av->
ca.data = budget_av;
365 budget_av->
budget.ci_present = 1;
369 &budget_av->
ca, 0, 1)) != 0) {
370 pr_err(
"ci initialisation failed\n");
374 pr_info(
"ci interface initialised\n");
382 static void ciintf_deinit(
struct budget_av *budget_av)
399 static const u8 saa7113_tab[] = {
420 0x15, 0x00, 0x16, 0x00, 0x17, 0x00,
423 0x40, 0x82, 0x58, 0x00, 0x59, 0x54, 0x5a, 0x07,
424 0x5b, 0x83, 0x5e, 0x00,
428 static int saa7113_init(
struct budget_av *budget_av)
432 const u8 *
data = saa7113_tab;
438 dprintk(1,
"saa7113 not found on KNC card\n");
442 dprintk(1,
"saa7113 detected and initializing\n");
444 while (*data != 0xff) {
454 static int saa7113_setinput(
struct budget_av *budget_av,
int input)
456 struct budget *budget = &budget_av->
budget;
464 }
else if (input == 0) {
484 else if (srate < 5000000)
486 else if (srate < 15000000)
488 else if (srate < 45000000)
495 stv0299_writereg(fe, 0x13, aclk);
496 stv0299_writereg(fe, 0x14, bclk);
497 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
498 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
499 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
500 stv0299_writereg(fe, 0x0f, 0x80 | m1);
505 static int philips_su1278_ty_ci_tuner_set_params(
struct dvb_frontend *fe)
510 struct budget *budget = (
struct budget *) fe->
dvb->priv;
511 struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len =
sizeof(buf) };
513 if ((
c->frequency < 950000) || (
c->frequency > 2150000))
516 div = (
c->frequency + (125 - 1)) / 125;
517 buf[0] = (
div >> 8) & 0x7f;
519 buf[2] = 0x80 | ((
div & 0x18000) >> 10) | 4;
522 if (
c->symbol_rate < 4000000)
525 if (
c->frequency < 1250000)
527 else if (
c->frequency < 1550000)
529 else if (
c->frequency < 2050000)
531 else if (
c->frequency < 2150000)
534 if (fe->
ops.i2c_gate_ctrl)
535 fe->
ops.i2c_gate_ctrl(fe, 1);
541 static u8 typhoon_cinergy1200s_inittab[] = {
584 .demod_address = 0x68,
585 .inittab = typhoon_cinergy1200s_inittab,
592 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate,
597 .demod_address = 0x68,
598 .inittab = typhoon_cinergy1200s_inittab,
605 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate,
609 .demod_address = 0x68,
610 .inittab = typhoon_cinergy1200s_inittab,
617 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate,
620 static int philips_cu1216_tuner_set_params(
struct dvb_frontend *fe)
623 struct budget *budget = (
struct budget *) fe->
dvb->priv;
625 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len =
sizeof(buf) };
628 #define CU1216_IF 36125000
629 #define TUNER_MUL 62500
633 buf[0] = (div >> 8) & 0x7f;
636 buf[3] = (
c->frequency < 150000000 ? 0x01 :
637 c->frequency < 445000000 ? 0x02 : 0x04);
641 if (fe->
ops.i2c_gate_ctrl)
642 fe->
ops.i2c_gate_ctrl(fe, 1);
649 for (i = 0; i < 20; i++) {
650 if (fe->
ops.i2c_gate_ctrl)
651 fe->
ops.i2c_gate_ctrl(fe, 1);
662 if (fe->
ops.i2c_gate_ctrl)
663 fe->
ops.i2c_gate_ctrl(fe, 1);
671 .demod_address = 0x0c,
676 .demod_address = 0x0d,
681 .demod_address = 0x0c,
685 static int philips_tu1216_tuner_init(
struct dvb_frontend *fe)
687 struct budget *budget = (
struct budget *) fe->
dvb->priv;
688 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
689 struct i2c_msg tuner_msg = {.
addr = 0x60,.flags = 0,.buf = tu1216_init,.len =
sizeof(tu1216_init) };
692 if (fe->
ops.i2c_gate_ctrl)
693 fe->
ops.i2c_gate_ctrl(fe, 1);
701 static int philips_tu1216_tuner_set_params(
struct dvb_frontend *fe)
704 struct budget *budget = (
struct budget *) fe->
dvb->priv;
706 struct i2c_msg tuner_msg = {.
addr = 0x60,.flags = 0,.buf = tuner_buf,.len =
708 int tuner_frequency = 0;
712 tuner_frequency =
c->frequency + 36166000;
713 if (tuner_frequency < 87000000)
715 else if (tuner_frequency < 130000000)
717 else if (tuner_frequency < 160000000)
719 else if (tuner_frequency < 200000000)
721 else if (tuner_frequency < 290000000)
723 else if (tuner_frequency < 420000000)
725 else if (tuner_frequency < 480000000)
727 else if (tuner_frequency < 620000000)
729 else if (tuner_frequency < 830000000)
731 else if (tuner_frequency < 895000000)
737 if (
c->frequency < 49000000)
739 else if (
c->frequency < 161000000)
741 else if (
c->frequency < 444000000)
743 else if (
c->frequency < 861000000)
749 switch (
c->bandwidth_hz) {
768 tuner_frequency = (((
c->frequency / 1000) * 6) + 217496) / 1000;
771 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
772 tuner_buf[1] = tuner_frequency & 0xff;
774 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
776 if (fe->
ops.i2c_gate_ctrl)
777 fe->
ops.i2c_gate_ctrl(fe, 1);
785 static int philips_tu1216_request_firmware(
struct dvb_frontend *fe,
788 struct budget *budget = (
struct budget *) fe->
dvb->priv;
795 .demod_address = 0x8,
801 .request_firmware = philips_tu1216_request_firmware,
804 static u8 philips_sd1878_inittab[] = {
847 static int philips_sd1878_ci_set_symbol_rate(
struct dvb_frontend *fe,
857 else if (srate < 5000000)
859 else if (srate < 15000000)
861 else if (srate < 45000000)
868 stv0299_writereg(fe, 0x0e, 0x23);
869 stv0299_writereg(fe, 0x0f, 0x94);
870 stv0299_writereg(fe, 0x10, 0x39);
871 stv0299_writereg(fe, 0x13, aclk);
872 stv0299_writereg(fe, 0x14, bclk);
873 stv0299_writereg(fe, 0x15, 0xc9);
874 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
875 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
876 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
877 stv0299_writereg(fe, 0x0f, 0x80 | m1);
883 .demod_address = 0x68,
884 .inittab = philips_sd1878_inittab,
891 .set_symbol_rate = philips_sd1878_ci_set_symbol_rate,
1117 .init_dev = knc1_stb0899_s1_init_1,
1118 .init_s2_demod = stb0899_s2_init_2,
1119 .init_s1_demod = knc1_stb0899_s1_init_3,
1120 .init_s2_fec = stb0899_s2_init_4,
1121 .init_tst = stb0899_s1_init_5,
1125 .demod_address = 0x68,
1130 .xtal_freq = 27000000,
1151 .tuner_get_frequency = tda8261_get_frequency,
1152 .tuner_set_frequency = tda8261_set_frequency,
1153 .tuner_set_bandwidth =
NULL,
1154 .tuner_get_bandwidth = tda8261_get_bandwidth,
1155 .tuner_set_rfsiggain =
NULL
1168 static u8 read_pwm(
struct budget_av *budget_av)
1172 struct i2c_msg msg[] = { {.addr = 0x50,.flags = 0,.buf = &
b,.len = 1},
1173 {.addr = 0x50,.flags =
I2C_M_RD,.buf = &
pwm,.len = 1}
1183 #define SUBID_DVBS_KNC1 0x0010
1184 #define SUBID_DVBS_KNC1_PLUS 0x0011
1185 #define SUBID_DVBS_TYPHOON 0x4f56
1186 #define SUBID_DVBS_CINERGY1200 0x1154
1187 #define SUBID_DVBS_CYNERGY1200N 0x1155
1188 #define SUBID_DVBS_TV_STAR 0x0014
1189 #define SUBID_DVBS_TV_STAR_PLUS_X4 0x0015
1190 #define SUBID_DVBS_TV_STAR_CI 0x0016
1191 #define SUBID_DVBS2_KNC1 0x0018
1192 #define SUBID_DVBS2_KNC1_OEM 0x0019
1193 #define SUBID_DVBS_EASYWATCH_1 0x001a
1194 #define SUBID_DVBS_EASYWATCH_2 0x001b
1195 #define SUBID_DVBS2_EASYWATCH 0x001d
1196 #define SUBID_DVBS_EASYWATCH 0x001e
1198 #define SUBID_DVBC_EASYWATCH 0x002a
1199 #define SUBID_DVBC_EASYWATCH_MK3 0x002c
1200 #define SUBID_DVBC_KNC1 0x0020
1201 #define SUBID_DVBC_KNC1_PLUS 0x0021
1202 #define SUBID_DVBC_KNC1_MK3 0x0022
1203 #define SUBID_DVBC_KNC1_TDA10024 0x0028
1204 #define SUBID_DVBC_KNC1_PLUS_MK3 0x0023
1205 #define SUBID_DVBC_CINERGY1200 0x1156
1206 #define SUBID_DVBC_CINERGY1200_MK3 0x1176
1208 #define SUBID_DVBT_EASYWATCH 0x003a
1209 #define SUBID_DVBT_KNC1_PLUS 0x0031
1210 #define SUBID_DVBT_KNC1 0x0030
1211 #define SUBID_DVBT_CINERGY1200 0x1157
1213 static void frontend_init(
struct budget_av *budget_av)
1225 switch (saa->
pci->subsystem_device) {
1238 switch (saa->
pci->subsystem_device) {
1249 if (saa->
pci->subsystem_vendor == 0x1894) {
1251 &budget_av->
budget.i2c_adap);
1257 &budget_av->
budget.i2c_adap);
1259 fe->
ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params;
1271 &budget_av->
budget.i2c_adap);
1274 &budget_av->
budget.i2c_adap,
1281 &budget_av->
budget.i2c_adap);
1283 fe->
ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params;
1296 &budget_av->
budget.i2c_adap);
1298 fe->
ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params;
1309 &budget_av->
budget.i2c_adap,
1310 read_pwm(budget_av));
1313 &budget_av->
budget.i2c_adap,
1314 read_pwm(budget_av));
1316 fe->
ops.tuner_ops.set_params = philips_cu1216_tuner_set_params;
1328 &philips_cu1216_tda10023_config,
1329 &budget_av->
budget.i2c_adap,
1330 read_pwm(budget_av));
1332 fe->
ops.tuner_ops.set_params = philips_cu1216_tuner_set_params;
1342 &budget_av->
budget.i2c_adap);
1344 fe->
ops.tuner_ops.init = philips_tu1216_tuner_init;
1345 fe->
ops.tuner_ops.set_params = philips_tu1216_tuner_set_params;
1351 pr_err(
"A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
1354 saa->
pci->subsystem_vendor,
1355 saa->
pci->subsystem_device);
1359 budget_av->
budget.dvb_frontend = fe;
1362 budget_av->
budget.dvb_frontend)) {
1363 pr_err(
"Frontend registration failed!\n");
1372 struct budget_av *budget_av = (
struct budget_av *) dev->
ext_priv;
1374 dprintk(8,
"dev: %p, budget_av: %p\n", dev, budget_av);
1380 static int budget_av_detach(
struct saa7146_dev *dev)
1382 struct budget_av *budget_av = (
struct budget_av *) dev->
ext_priv;
1397 if (budget_av->
budget.ci_present)
1398 ciintf_deinit(budget_av);
1400 if (budget_av->
budget.dvb_frontend !=
NULL) {
1411 #define KNC1_INPUTS 2
1428 static int vidioc_g_input(
struct file *file,
void *fh,
unsigned int *i)
1431 struct budget_av *budget_av = (
struct budget_av *)dev->
ext_priv;
1435 dprintk(1,
"VIDIOC_G_INPUT %d\n", *i);
1439 static int vidioc_s_input(
struct file *file,
void *fh,
unsigned int input)
1442 struct budget_av *budget_av = (
struct budget_av *)dev->
ext_priv;
1444 dprintk(1,
"VIDIOC_S_INPUT %d\n", input);
1445 return saa7113_setinput(budget_av, input);
1452 struct budget_av *budget_av;
1458 if (!(budget_av = kzalloc(
sizeof(
struct budget_av),
GFP_KERNEL)))
1462 budget_av->
budget.ci_present = 0;
1478 if (saa7113_init(budget_av) == 0) {
1483 ERR(
"cannot init vv subsystem\n");
1486 vv_data.vid_ops.vidioc_enum_input = vidioc_enum_input;
1487 vv_data.vid_ops.vidioc_g_input = vidioc_g_input;
1488 vv_data.vid_ops.vidioc_s_input = vidioc_s_input;
1492 ERR(
"cannot register capture v4l2 device\n");
1501 saa7113_setinput(budget_av, 0);
1507 mac = budget_av->
budget.dvb_adapter.proposed_mac;
1508 if (i2c_readregs(&budget_av->
budget.i2c_adap, 0xa0, 0x30, mac, 6)) {
1509 pr_err(
"KNC1-%d: Could not read MAC from KNC1 card\n",
1510 budget_av->
budget.dvb_adapter.num);
1513 pr_info(
"KNC1-%d: MAC addr = %pM\n",
1514 budget_av->
budget.dvb_adapter.num, mac);
1517 budget_av->
budget.dvb_adapter.priv = budget_av;
1518 frontend_init(budget_av);
1519 ciintf_init(budget_av);
1528 .v_offset = 0x17,.v_field = 288,
1529 .h_offset = 0x14,.h_pixels = 680,
1530 .v_max_out = 576,.h_max_out = 768 },
1533 .v_offset = 0x16,.v_field = 240,
1534 .h_offset = 0x06,.h_pixels = 708,
1535 .v_max_out = 480,.h_max_out = 640, },
1542 .stds = &standard[0],
1611 .name =
"budget_av",
1617 .attach = budget_av_attach,
1618 .detach = budget_av_detach,
1621 .irq_func = budget_av_irq,
1624 static int __init budget_av_init(
void)
1629 static void __exit budget_av_exit(
void)
1638 MODULE_AUTHOR(
"Ralph Metzler, Marcus Metzler, Michael Hunold, others");
1640 "budget PCI DVB w/ analog input and CI-module (e.g. the KNC cards)");