21 #include <linux/kernel.h>
22 #include <linux/module.h>
24 #include <linux/string.h>
25 #include <linux/slab.h>
28 #include <asm/div64.h>
33 static unsigned int verbose = 1;
37 static unsigned int dst_addons;
41 static unsigned int dst_algo;
46 #define ATTEMPT_TUNE 2
54 #define dprintk(x, y, z, format, arg...) do { \
56 if ((x > DST_ERROR) && (x > y)) \
57 printk(KERN_ERR "dst(%d) %s: " format "\n", \
58 state->bt->nr, __func__ , ##arg); \
59 else if ((x > DST_NOTICE) && (x > y)) \
60 printk(KERN_NOTICE "dst(%d) %s: " format "\n", \
61 state->bt->nr, __func__ , ##arg); \
62 else if ((x > DST_INFO) && (x > y)) \
63 printk(KERN_INFO "dst(%d) %s: " format "\n", \
64 state->bt->nr, __func__ , ##arg); \
65 else if ((x > DST_DEBUG) && (x > y)) \
66 printk(KERN_DEBUG "dst(%d) %s: " format "\n", \
67 state->bt->nr, __func__ , ##arg); \
70 printk(format, ##arg); \
92 enb.enb.enable = enbb;
96 dprintk(
verbose,
DST_INFO, 1,
"dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)", err, mask, enbb);
105 bits.outp.mask = enbb;
106 bits.outp.highvals = outhigh;
108 dprintk(
verbose,
DST_INFO, 1,
"dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)", err, enbb, outhigh);
125 *result = (
u8) rd_packet.rd.value;
148 static int rdc_8820_reset(
struct dst_state *state)
164 static int dst_pio_enable(
struct dst_state *state)
193 for (i = 0; i < 200; i++) {
194 if (dst_gpio_inb(state, &reply) < 0) {
215 dst_pio_enable(state);
225 rdc_8820_reset(state);
236 if ((dst_pio_enable(state)) < 0) {
266 for (i = 0; i <
len; i++)
270 for (cnt = 0; cnt < 2; cnt++) {
272 dprintk(
verbose,
DST_INFO, 1,
"_write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, data[0]);
301 for (cnt = 0; cnt < 2; cnt++) {
303 dprintk(
verbose,
DST_INFO, 1,
"read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, ret[0]);
316 for (err = 1; err <
len; err++)
325 static int dst_set_polarization(
struct dst_state *state)
350 if (freq < 950 || freq > 2150)
352 state->
tx_tuna[2] = (freq >> 8);
362 if (freq < 137000 || freq > 858000)
364 state->
tx_tuna[2] = (freq >> 16) & 0xff;
365 state->
tx_tuna[3] = (freq >> 8) & 0xff;
369 state->
tx_tuna[2] = (freq >> 16) & 0xff;
370 state->
tx_tuna[3] = (freq >> 8) & 0xff;
374 if (freq < 51000 || freq > 858000)
376 state->
tx_tuna[2] = (freq >> 16) & 0xff;
377 state->
tx_tuna[3] = (freq >> 8) & 0xff;
456 static int dst_set_symbolrate(
struct dst_state *state,
u32 srate)
472 symcalc = (
u32) sval;
474 state->
tx_tuna[5] = (
u8) (symcalc >> 12);
478 state->
tx_tuna[5] = (
u8) (srate >> 16) & 0x7f;
508 switch (modulation) {
551 for (i = 0; i <
len; i++) {
558 static void dst_type_flags_print(
struct dst_state *state)
592 otype =
"terrestrial";
615 .tuner_name =
"L 64724",
616 .board_name =
"UNKNOWN",
622 .tuner_name =
"STV 0299",
623 .board_name =
"VP1020",
629 .tuner_name =
"STV 0299",
630 .board_name =
"VP1020",
636 .tuner_name =
"MB 86A15",
637 .board_name =
"VP1022",
643 .tuner_name =
"MB 86A15",
644 .board_name =
"VP1025",
650 .tuner_name =
"STV 0299",
651 .board_name =
"VP1030",
657 .tuner_name =
"STV 0299",
658 .board_name =
"VP1030",
664 .tuner_name =
"UNKNOWN",
665 .board_name =
"VP2021",
671 .tuner_name =
"UNKNOWN",
672 .board_name =
"VP2030",
678 .tuner_name =
"UNKNOWN",
679 .board_name =
"VP2031",
685 .tuner_name =
"UNKNOWN",
686 .board_name =
"VP2040",
692 .tuner_name =
"UNKNOWN",
693 .board_name =
"VP3020",
699 .tuner_name =
"UNKNOWN",
700 .board_name =
"VP3021",
706 .tuner_name =
"TDA10046",
707 .board_name =
"VP3040",
713 .tuner_name =
"UNKNOWN",
714 .board_name =
"VP3051",
720 .tuner_name =
"NXT200x",
721 .board_name =
"VP3220",
727 .tuner_name =
"NXT200x",
728 .board_name =
"VP3250",
770 .device_id =
"200103A",
779 .device_id =
"DST-020",
788 .device_id =
"DST-030",
797 .device_id =
"DST-03T",
807 .device_id =
"DST-MOT",
816 .device_id =
"DST-CI",
825 .device_id =
"DSTMCI",
835 .device_id =
"DSTFCI",
844 .device_id =
"DCT-CI",
853 .device_id =
"DCTNEW",
862 .device_id =
"DTT-CI",
871 .device_id =
"DTTDIG",
880 .device_id =
"DTTNXT",
889 .device_id =
"ATSCDI",
898 .device_id =
"ATSCAD",
910 static int dst_get_mac(
struct dst_state *state)
912 u8 get_mac[] = { 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
914 if (dst_command(state, get_mac, 8) < 0) {
925 static int dst_fw_ver(
struct dst_state *state)
927 u8 get_ver[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
929 if (dst_command(state, get_ver, 8) < 0) {
943 static int dst_card_type(
struct dst_state *state)
948 u8 get_type[] = { 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
950 if (dst_command(state, get_type, 8) < 0) {
958 for (j = 0, p_tuner_list = tuner_list; j <
ARRAY_SIZE(tuner_list); j++, p_tuner_list++) {
969 static int dst_get_vendor(
struct dst_state *state)
971 u8 get_vendor[] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
973 if (dst_command(state, get_vendor, 8) < 0) {
984 static void debug_dst_buffer(
struct dst_state *state)
989 printk(
"%s: [", __func__);
990 for (i = 0; i < 8; i++)
996 static int dst_check_stv0299(
struct dst_state *state)
998 u8 check_stv0299[] = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1001 if (dst_command(state, check_stv0299, 8) < 0) {
1005 debug_dst_buffer(state);
1016 static int dst_check_mb86a15(
struct dst_state *state)
1018 u8 check_mb86a15[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1021 if (dst_command(state, check_mb86a15, 8) < 0) {
1025 debug_dst_buffer(state);
1036 static int dst_get_tuner_info(
struct dst_state *state)
1038 u8 get_tuner_1[] = { 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1039 u8 get_tuner_2[] = { 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1045 if (dst_command(state, get_tuner_1, 8) < 0) {
1050 if (dst_command(state, get_tuner_2, 8) < 0) {
1081 static int dst_get_device_id(
struct dst_state *state)
1089 u8 use_dst_type = 0;
1090 u32 use_type_flags = 0;
1092 static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
1119 for (i = 0, p_dst_type = dst_tlist; i <
ARRAY_SIZE(dst_tlist); i++, p_dst_type++) {
1122 use_dst_type = p_dst_type->
dst_type;
1130 switch (use_dst_type) {
1133 if (dst_check_stv0299(state) < 0) {
1141 if (dst_check_mb86a15(state) < 0)
1147 for (j = 0, p_tuner_list = tuner_list; j <
ARRAY_SIZE(tuner_list); j++, p_tuner_list++) {
1164 dst_type_print(state, use_dst_type);
1167 dst_type_flags_print(state);
1172 static int dst_probe(
struct dst_state *state)
1176 if ((rdc_8820_reset(state)) < 0) {
1189 if (dst_get_device_id(state) < 0) {
1193 if (dst_get_mac(state) < 0) {
1197 if (dst_get_tuner_info(state) < 0)
1200 if (state->
type_flags & DST_TYPE_HAS_TS204) {
1201 dst_packsize(state, 204);
1204 if (dst_fw_ver(state) < 0) {
1208 if (dst_card_type(state) < 0) {
1212 if (dst_get_vendor(state) < 0) {
1256 if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
1285 static int dst_get_signal(
struct dst_state *state)
1288 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
1299 retval = dst_command(state, get_signal, 8);
1320 static int dst_tone_power_cmd(
struct dst_state *state)
1322 u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
1330 return dst_command(state, paket, 8);
1333 static int dst_get_tuna(
struct dst_state *state)
1342 if ((state->
type_flags & DST_TYPE_HAS_VLF) &&
1352 if ((state->
type_flags & DST_TYPE_HAS_VLF) &&
1401 if ((state->
type_flags & DST_TYPE_HAS_VLF) &&
1428 retval = dst_get_tuna(state);
1455 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
1466 return dst_command(state, paket, 8);
1471 int need_cmd, retval = 0;
1498 retval = dst_tone_power_cmd(state);
1525 return dst_tone_power_cmd(state);
1543 return dst_tone_power_cmd(state);
1551 static u8 sat_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x00, 0x73, 0x21, 0x00, 0x00 };
1552 static u8 sat_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x55, 0xbd, 0x50, 0x00, 0x00 };
1553 static u8 ter_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1554 static u8 ter_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1555 static u8 cab_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1556 static u8 cab_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1557 static u8 atsc_tuner[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1592 static int dst_read_signal_strength(
struct dvb_frontend *fe,
u16 *strength)
1596 int retval = dst_get_signal(state);
1606 int retval = dst_get_signal(state);
1619 retval = dst_set_freq(state, p->
frequency);
1629 dst_set_polarization(state);
1639 retval = dst_write_tuna(fe);
1647 unsigned int mode_flags,
1648 unsigned int *delay,
1663 dst_set_polarization(state);
1677 dst_read_status(fe, status);
1683 static int dst_get_tuning_algo(
struct dvb_frontend *fe)
1715 #ifdef CONFIG_MEDIA_ATTACH
1730 if (dst_probe(state) < 0) {
1764 .name =
"DST DVB-T",
1765 .frequency_min = 137000000,
1766 .frequency_max = 858000000,
1767 .frequency_stepsize = 166667,
1779 .release = dst_release,
1781 .tune = dst_tune_frontend,
1782 .set_frontend = dst_set_frontend,
1783 .get_frontend = dst_get_frontend,
1784 .get_frontend_algo = dst_get_tuning_algo,
1785 .read_status = dst_read_status,
1786 .read_signal_strength = dst_read_signal_strength,
1787 .read_snr = dst_read_snr,
1793 .name =
"DST DVB-S",
1794 .frequency_min = 950000,
1795 .frequency_max = 2150000,
1796 .frequency_stepsize = 1000,
1797 .frequency_tolerance = 29500,
1798 .symbol_rate_min = 1000000,
1799 .symbol_rate_max = 45000000,
1804 .release = dst_release,
1806 .tune = dst_tune_frontend,
1807 .set_frontend = dst_set_frontend,
1808 .get_frontend = dst_get_frontend,
1809 .get_frontend_algo = dst_get_tuning_algo,
1810 .read_status = dst_read_status,
1811 .read_signal_strength = dst_read_signal_strength,
1812 .read_snr = dst_read_snr,
1813 .diseqc_send_burst = dst_send_burst,
1814 .diseqc_send_master_cmd = dst_set_diseqc,
1815 .set_voltage = dst_set_voltage,
1816 .set_tone = dst_set_tone,
1822 .name =
"DST DVB-C",
1823 .frequency_stepsize = 62500,
1824 .frequency_min = 51000000,
1825 .frequency_max = 858000000,
1826 .symbol_rate_min = 1000000,
1827 .symbol_rate_max = 45000000,
1837 .release = dst_release,
1839 .tune = dst_tune_frontend,
1840 .set_frontend = dst_set_frontend,
1841 .get_frontend = dst_get_frontend,
1842 .get_frontend_algo = dst_get_tuning_algo,
1843 .read_status = dst_read_status,
1844 .read_signal_strength = dst_read_signal_strength,
1845 .read_snr = dst_read_snr,
1852 .frequency_stepsize = 62500,
1853 .frequency_min = 510000000,
1854 .frequency_max = 858000000,
1855 .symbol_rate_min = 1000000,
1856 .symbol_rate_max = 45000000,
1860 .release = dst_release,
1862 .tune = dst_tune_frontend,
1863 .set_frontend = dst_set_frontend,
1864 .get_frontend = dst_get_frontend,
1865 .get_frontend_algo = dst_get_tuning_algo,
1866 .read_status = dst_read_status,
1867 .read_signal_strength = dst_read_signal_strength,
1868 .read_snr = dst_read_snr,