2 Frontend/Card driver for TwinHan DST Frontend
3 Copyright (C) 2003 Jamie Honan
4 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/string.h>
27 #include <linux/slab.h>
28 #include <linux/vmalloc.h>
29 #include <linux/delay.h>
30 #include <asm/div64.h>
31 #include "dvb_frontend.h"
33 #include "dst_common.h"
35 static unsigned int verbose;
36 module_param(verbose, int, 0644);
37 MODULE_PARM_DESC(verbose, "verbosity level (0 to 3)");
39 static unsigned int dst_addons;
40 module_param(dst_addons, int, 0644);
41 MODULE_PARM_DESC(dst_addons, "CA daughterboard, default is 0 (No addons)");
43 static unsigned int dst_algo;
44 module_param(dst_algo, int, 0644);
45 MODULE_PARM_DESC(dst_algo, "tuning algo: default is 0=(SW), 1=(HW)");
48 #define ATTEMPT_TUNE 2
51 #define dprintk(level, fmt, arg...) do { \
52 if (level >= verbose) \
53 printk(KERN_DEBUG pr_fmt("%s: " fmt), \
57 static int dst_command(struct dst_state *state, u8 *data, u8 len);
59 static void dst_packsize(struct dst_state *state, int psize)
61 union dst_gpio_packet bits;
64 bt878_device_control(state->bt, DST_IG_TS, &bits);
67 static int dst_gpio_outb(struct dst_state *state, u32 mask, u32 enbb,
68 u32 outhigh, int delay)
70 union dst_gpio_packet enb;
71 union dst_gpio_packet bits;
75 enb.enb.enable = enbb;
77 dprintk(2, "mask=[%04x], enbb=[%04x], outhigh=[%04x]\n",
79 if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) {
80 dprintk(2, "dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)\n",
85 /* because complete disabling means no output, no need to do output packet */
90 bits.outp.mask = enbb;
91 bits.outp.highvals = outhigh;
92 if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) {
93 dprintk(2, "dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)\n",
101 static int dst_gpio_inb(struct dst_state *state, u8 *result)
103 union dst_gpio_packet rd_packet;
107 if ((err = bt878_device_control(state->bt, DST_IG_READ, &rd_packet)) < 0) {
108 pr_err("dst_gpio_inb error (err == %i)\n", err);
111 *result = (u8) rd_packet.rd.value;
116 int rdc_reset_state(struct dst_state *state)
118 dprintk(2, "Resetting state machine\n");
119 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, 0, NO_DELAY) < 0) {
120 pr_err("dst_gpio_outb ERROR !\n");
124 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, RDC_8820_INT, NO_DELAY) < 0) {
125 pr_err("dst_gpio_outb ERROR !\n");
132 EXPORT_SYMBOL(rdc_reset_state);
134 static int rdc_8820_reset(struct dst_state *state)
136 dprintk(3, "Resetting DST\n");
137 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
138 pr_err("dst_gpio_outb ERROR !\n");
142 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, RDC_8820_RESET, DELAY) < 0) {
143 pr_err("dst_gpio_outb ERROR !\n");
150 static int dst_pio_enable(struct dst_state *state)
152 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) {
153 pr_err("dst_gpio_outb ERROR !\n");
161 int dst_pio_disable(struct dst_state *state)
163 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_DISABLE, RDC_8820_PIO_0_DISABLE, NO_DELAY) < 0) {
164 pr_err("dst_gpio_outb ERROR !\n");
167 if (state->type_flags & DST_TYPE_HAS_FW_1)
172 EXPORT_SYMBOL(dst_pio_disable);
174 int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode)
179 for (i = 0; i < 200; i++) {
180 if (dst_gpio_inb(state, &reply) < 0) {
181 pr_err("dst_gpio_inb ERROR !\n");
184 if ((reply & RDC_8820_PIO_0_ENABLE) == 0) {
185 dprintk(2, "dst wait ready after %d\n", i);
190 dprintk(1, "dst wait NOT ready after %d\n", i);
194 EXPORT_SYMBOL(dst_wait_dst_ready);
196 int dst_error_recovery(struct dst_state *state)
198 dprintk(1, "Trying to return from previous errors.\n");
199 dst_pio_disable(state);
201 dst_pio_enable(state);
206 EXPORT_SYMBOL(dst_error_recovery);
208 int dst_error_bailout(struct dst_state *state)
210 dprintk(2, "Trying to bailout from previous error.\n");
211 rdc_8820_reset(state);
212 dst_pio_disable(state);
217 EXPORT_SYMBOL(dst_error_bailout);
219 int dst_comm_init(struct dst_state *state)
221 dprintk(2, "Initializing DST.\n");
222 if ((dst_pio_enable(state)) < 0) {
223 pr_err("PIO Enable Failed\n");
226 if ((rdc_reset_state(state)) < 0) {
227 pr_err("RDC 8820 State RESET Failed.\n");
230 if (state->type_flags & DST_TYPE_HAS_FW_1)
237 EXPORT_SYMBOL(dst_comm_init);
239 int write_dst(struct dst_state *state, u8 *data, u8 len)
241 struct i2c_msg msg = {
242 .addr = state->config->demod_address,
251 dprintk(1, "writing [ %*ph ]\n", len, data);
253 for (cnt = 0; cnt < 2; cnt++) {
254 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
255 dprintk(2, "_write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n",
257 dst_error_recovery(state);
263 dprintk(2, "RDC 8820 RESET\n");
264 dst_error_bailout(state);
271 EXPORT_SYMBOL(write_dst);
273 int read_dst(struct dst_state *state, u8 *ret, u8 len)
275 struct i2c_msg msg = {
276 .addr = state->config->demod_address,
285 for (cnt = 0; cnt < 2; cnt++) {
286 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
287 dprintk(2, "read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n",
289 dst_error_recovery(state);
295 dprintk(2, "RDC 8820 RESET\n");
296 dst_error_bailout(state);
300 dprintk(3, "reply is %*ph\n", len, ret);
304 EXPORT_SYMBOL(read_dst);
306 static int dst_set_polarization(struct dst_state *state)
308 switch (state->voltage) {
309 case SEC_VOLTAGE_13: /* Vertical */
310 dprintk(2, "Polarization=[Vertical]\n");
311 state->tx_tuna[8] &= ~0x40;
313 case SEC_VOLTAGE_18: /* Horizontal */
314 dprintk(2, "Polarization=[Horizontal]\n");
315 state->tx_tuna[8] |= 0x40;
317 case SEC_VOLTAGE_OFF:
324 static int dst_set_freq(struct dst_state *state, u32 freq)
326 state->frequency = freq;
327 dprintk(2, "set Frequency %u\n", freq);
329 if (state->dst_type == DST_TYPE_IS_SAT) {
331 if (freq < 950 || freq > 2150)
333 state->tx_tuna[2] = (freq >> 8);
334 state->tx_tuna[3] = (u8) freq;
335 state->tx_tuna[4] = 0x01;
336 state->tx_tuna[8] &= ~0x04;
337 if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
339 state->tx_tuna[8] |= 0x04;
341 } else if (state->dst_type == DST_TYPE_IS_TERR) {
343 if (freq < 137000 || freq > 858000)
345 state->tx_tuna[2] = (freq >> 16) & 0xff;
346 state->tx_tuna[3] = (freq >> 8) & 0xff;
347 state->tx_tuna[4] = (u8) freq;
348 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
350 state->tx_tuna[2] = (freq >> 16) & 0xff;
351 state->tx_tuna[3] = (freq >> 8) & 0xff;
352 state->tx_tuna[4] = (u8) freq;
353 } else if (state->dst_type == DST_TYPE_IS_ATSC) {
355 if (freq < 51000 || freq > 858000)
357 state->tx_tuna[2] = (freq >> 16) & 0xff;
358 state->tx_tuna[3] = (freq >> 8) & 0xff;
359 state->tx_tuna[4] = (u8) freq;
360 state->tx_tuna[5] = 0x00; /* ATSC */
361 state->tx_tuna[6] = 0x00;
362 if (state->dst_hw_cap & DST_TYPE_HAS_ANALOG)
363 state->tx_tuna[7] = 0x00; /* Digital */
370 static int dst_set_bandwidth(struct dst_state *state, u32 bandwidth)
372 state->bandwidth = bandwidth;
374 if (state->dst_type != DST_TYPE_IS_TERR)
379 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
380 state->tx_tuna[7] = 0x06;
382 state->tx_tuna[6] = 0x06;
383 state->tx_tuna[7] = 0x00;
387 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
388 state->tx_tuna[7] = 0x07;
390 state->tx_tuna[6] = 0x07;
391 state->tx_tuna[7] = 0x00;
395 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
396 state->tx_tuna[7] = 0x08;
398 state->tx_tuna[6] = 0x08;
399 state->tx_tuna[7] = 0x00;
409 static int dst_set_inversion(struct dst_state *state,
410 enum fe_spectral_inversion inversion)
412 state->inversion = inversion;
414 case INVERSION_OFF: /* Inversion = Normal */
415 state->tx_tuna[8] &= ~0x80;
418 state->tx_tuna[8] |= 0x80;
427 static int dst_set_fec(struct dst_state *state, enum fe_code_rate fec)
433 static enum fe_code_rate dst_get_fec(struct dst_state *state)
438 static int dst_set_symbolrate(struct dst_state *state, u32 srate)
443 state->symbol_rate = srate;
444 if (state->dst_type == DST_TYPE_IS_TERR) {
447 dprintk(2, "set symrate %u\n", srate);
449 if (state->dst_type == DST_TYPE_IS_SAT) {
450 if (state->type_flags & DST_TYPE_HAS_SYMDIV) {
454 symcalc = (u32) sval;
455 dprintk(2, "set symcalc %u\n", symcalc);
456 state->tx_tuna[5] = (u8) (symcalc >> 12);
457 state->tx_tuna[6] = (u8) (symcalc >> 4);
458 state->tx_tuna[7] = (u8) (symcalc << 4);
460 state->tx_tuna[5] = (u8) (srate >> 16) & 0x7f;
461 state->tx_tuna[6] = (u8) (srate >> 8);
462 state->tx_tuna[7] = (u8) srate;
464 state->tx_tuna[8] &= ~0x20;
465 if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
467 state->tx_tuna[8] |= 0x20;
469 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
470 dprintk(3, "%s\n", state->fw_name);
471 if (!strncmp(state->fw_name, "DCTNEW", 6)) {
472 state->tx_tuna[5] = (u8) (srate >> 8);
473 state->tx_tuna[6] = (u8) srate;
474 state->tx_tuna[7] = 0x00;
475 } else if (!strncmp(state->fw_name, "DCT-CI", 6)) {
476 state->tx_tuna[5] = 0x00;
477 state->tx_tuna[6] = (u8) (srate >> 8);
478 state->tx_tuna[7] = (u8) srate;
484 static int dst_set_modulation(struct dst_state *state,
485 enum fe_modulation modulation)
487 if (state->dst_type != DST_TYPE_IS_CABLE)
490 state->modulation = modulation;
491 switch (modulation) {
493 state->tx_tuna[8] = 0x10;
496 state->tx_tuna[8] = 0x20;
499 state->tx_tuna[8] = 0x40;
502 state->tx_tuna[8] = 0x80;
505 if (!strncmp(state->fw_name, "DCTNEW", 6))
506 state->tx_tuna[8] = 0xff;
507 else if (!strncmp(state->fw_name, "DCT-CI", 6))
508 state->tx_tuna[8] = 0x00;
522 static enum fe_modulation dst_get_modulation(struct dst_state *state)
524 return state->modulation;
528 u8 dst_check_sum(u8 *buf, u32 len)
534 for (i = 0; i < len; i++) {
539 EXPORT_SYMBOL(dst_check_sum);
541 static void dst_type_flags_print(struct dst_state *state)
543 u32 type_flags = state->type_flags;
545 pr_err("DST type flags :\n");
546 if (type_flags & DST_TYPE_HAS_TS188)
547 pr_err(" 0x%x newtuner\n", DST_TYPE_HAS_TS188);
548 if (type_flags & DST_TYPE_HAS_NEWTUNE_2)
549 pr_err(" 0x%x newtuner 2\n", DST_TYPE_HAS_NEWTUNE_2);
550 if (type_flags & DST_TYPE_HAS_TS204)
551 pr_err(" 0x%x ts204\n", DST_TYPE_HAS_TS204);
552 if (type_flags & DST_TYPE_HAS_VLF)
553 pr_err(" 0x%x VLF\n", DST_TYPE_HAS_VLF);
554 if (type_flags & DST_TYPE_HAS_SYMDIV)
555 pr_err(" 0x%x symdiv\n", DST_TYPE_HAS_SYMDIV);
556 if (type_flags & DST_TYPE_HAS_FW_1)
557 pr_err(" 0x%x firmware version = 1\n", DST_TYPE_HAS_FW_1);
558 if (type_flags & DST_TYPE_HAS_FW_2)
559 pr_err(" 0x%x firmware version = 2\n", DST_TYPE_HAS_FW_2);
560 if (type_flags & DST_TYPE_HAS_FW_3)
561 pr_err(" 0x%x firmware version = 3\n", DST_TYPE_HAS_FW_3);
566 static int dst_type_print(struct dst_state *state, u8 type)
570 case DST_TYPE_IS_SAT:
574 case DST_TYPE_IS_TERR:
575 otype = "terrestrial";
578 case DST_TYPE_IS_CABLE:
582 case DST_TYPE_IS_ATSC:
587 dprintk(2, "invalid dst type %d\n", type);
590 dprintk(2, "DST type: %s\n", otype);
595 static struct tuner_types tuner_list[] = {
597 .tuner_type = TUNER_TYPE_L64724,
598 .tuner_name = "L 64724",
599 .board_name = "UNKNOWN",
604 .tuner_type = TUNER_TYPE_STV0299,
605 .tuner_name = "STV 0299",
606 .board_name = "VP1020",
611 .tuner_type = TUNER_TYPE_STV0299,
612 .tuner_name = "STV 0299",
613 .board_name = "VP1020",
618 .tuner_type = TUNER_TYPE_MB86A15,
619 .tuner_name = "MB 86A15",
620 .board_name = "VP1022",
625 .tuner_type = TUNER_TYPE_MB86A15,
626 .tuner_name = "MB 86A15",
627 .board_name = "VP1025",
632 .tuner_type = TUNER_TYPE_STV0299,
633 .tuner_name = "STV 0299",
634 .board_name = "VP1030",
639 .tuner_type = TUNER_TYPE_STV0299,
640 .tuner_name = "STV 0299",
641 .board_name = "VP1030",
646 .tuner_type = TUNER_TYPE_UNKNOWN,
647 .tuner_name = "UNKNOWN",
648 .board_name = "VP2021",
653 .tuner_type = TUNER_TYPE_UNKNOWN,
654 .tuner_name = "UNKNOWN",
655 .board_name = "VP2030",
660 .tuner_type = TUNER_TYPE_UNKNOWN,
661 .tuner_name = "UNKNOWN",
662 .board_name = "VP2031",
667 .tuner_type = TUNER_TYPE_UNKNOWN,
668 .tuner_name = "UNKNOWN",
669 .board_name = "VP2040",
674 .tuner_type = TUNER_TYPE_UNKNOWN,
675 .tuner_name = "UNKNOWN",
676 .board_name = "VP3020",
681 .tuner_type = TUNER_TYPE_UNKNOWN,
682 .tuner_name = "UNKNOWN",
683 .board_name = "VP3021",
688 .tuner_type = TUNER_TYPE_TDA10046,
689 .tuner_name = "TDA10046",
690 .board_name = "VP3040",
695 .tuner_type = TUNER_TYPE_UNKNOWN,
696 .tuner_name = "UNKNOWN",
697 .board_name = "VP3051",
702 .tuner_type = TUNER_TYPE_NXT200x,
703 .tuner_name = "NXT200x",
704 .board_name = "VP3220",
709 .tuner_type = TUNER_TYPE_NXT200x,
710 .tuner_name = "NXT200x",
711 .board_name = "VP3250",
721 VP-1020 DST-MOT LG(old), TS=188
723 VP-1020 DST-03T LG(new), TS=204
724 VP-1022 DST-03T LG(new), TS=204
725 VP-1025 DST-03T LG(new), TS=204
727 VP-1030 DSTMCI, LG(new), TS=188
728 VP-1032 DSTMCI, LG(new), TS=188
732 VP-2030 DCT-CI, Samsung, TS=204
733 VP-2021 DCT-CI, Unknown, TS=204
734 VP-2031 DCT-CI, Philips, TS=188
735 VP-2040 DCT-CI, Philips, TS=188, with CA daughter board
736 VP-2040 DCT-CI, Philips, TS=204, without CA daughter board
740 VP-3050 DTTNXT TS=188
741 VP-3040 DTT-CI, Philips, TS=188
742 VP-3040 DTT-CI, Philips, TS=204
746 VP-3220 ATSCDI, TS=188
747 VP-3250 ATSCAD, TS=188
751 static struct dst_types dst_tlist[] = {
753 .device_id = "200103A",
755 .dst_type = DST_TYPE_IS_SAT,
756 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_OBS_REGS,
762 .device_id = "DST-020",
764 .dst_type = DST_TYPE_IS_SAT,
765 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
771 .device_id = "DST-030",
773 .dst_type = DST_TYPE_IS_SAT,
774 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_TS188 | DST_TYPE_HAS_FW_1,
780 .device_id = "DST-03T",
782 .dst_type = DST_TYPE_IS_SAT,
783 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
784 .dst_feature = DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 | DST_TYPE_HAS_DISEQC5
785 | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO,
786 .tuner_type = TUNER_TYPE_MULTI
790 .device_id = "DST-MOT",
792 .dst_type = DST_TYPE_IS_SAT,
793 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
799 .device_id = "DST-CI",
801 .dst_type = DST_TYPE_IS_SAT,
802 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_1,
803 .dst_feature = DST_TYPE_HAS_CA,
805 }, /* An OEM board */
808 .device_id = "DSTMCI",
810 .dst_type = DST_TYPE_IS_SAT,
811 .type_flags = DST_TYPE_HAS_TS188 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_INC_COUNT | DST_TYPE_HAS_VLF,
812 .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
813 | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC,
814 .tuner_type = TUNER_TYPE_MULTI
818 .device_id = "DSTFCI",
820 .dst_type = DST_TYPE_IS_SAT,
821 .type_flags = DST_TYPE_HAS_TS188 | DST_TYPE_HAS_FW_1,
824 }, /* unknown to vendor */
827 .device_id = "DCT-CI",
829 .dst_type = DST_TYPE_IS_CABLE,
830 .type_flags = DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_VLF,
831 .dst_feature = DST_TYPE_HAS_CA,
836 .device_id = "DCTNEW",
838 .dst_type = DST_TYPE_IS_CABLE,
839 .type_flags = DST_TYPE_HAS_TS188 | DST_TYPE_HAS_FW_3 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_MULTI_FE,
845 .device_id = "DTT-CI",
847 .dst_type = DST_TYPE_IS_TERR,
848 .type_flags = DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_VLF,
849 .dst_feature = DST_TYPE_HAS_CA,
854 .device_id = "DTTDIG",
856 .dst_type = DST_TYPE_IS_TERR,
857 .type_flags = DST_TYPE_HAS_FW_2,
863 .device_id = "DTTNXT",
865 .dst_type = DST_TYPE_IS_TERR,
866 .type_flags = DST_TYPE_HAS_FW_2,
867 .dst_feature = DST_TYPE_HAS_ANALOG,
872 .device_id = "ATSCDI",
874 .dst_type = DST_TYPE_IS_ATSC,
875 .type_flags = DST_TYPE_HAS_FW_2,
881 .device_id = "ATSCAD",
883 .dst_type = DST_TYPE_IS_ATSC,
884 .type_flags = DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
885 .dst_feature = DST_TYPE_HAS_MAC | DST_TYPE_HAS_ANALOG,
893 static int dst_get_mac(struct dst_state *state)
895 u8 get_mac[] = { 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
896 get_mac[7] = dst_check_sum(get_mac, 7);
897 if (dst_command(state, get_mac, 8) < 0) {
898 dprintk(2, "Unsupported Command\n");
901 memset(&state->mac_address, '\0', 8);
902 memcpy(&state->mac_address, &state->rxbuffer, 6);
903 pr_err("MAC Address=[%pM]\n", state->mac_address);
908 static int dst_fw_ver(struct dst_state *state)
910 u8 get_ver[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
911 get_ver[7] = dst_check_sum(get_ver, 7);
912 if (dst_command(state, get_ver, 8) < 0) {
913 dprintk(2, "Unsupported Command\n");
916 memcpy(&state->fw_version, &state->rxbuffer, 8);
917 pr_err("Firmware Ver = %x.%x Build = %02x, on %x:%x, %x-%x-20%02x\n",
918 state->fw_version[0] >> 4, state->fw_version[0] & 0x0f,
919 state->fw_version[1],
920 state->fw_version[5], state->fw_version[6],
921 state->fw_version[4], state->fw_version[3], state->fw_version[2]);
926 static int dst_card_type(struct dst_state *state)
929 struct tuner_types *p_tuner_list = NULL;
931 u8 get_type[] = { 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
932 get_type[7] = dst_check_sum(get_type, 7);
933 if (dst_command(state, get_type, 8) < 0) {
934 dprintk(2, "Unsupported Command\n");
937 memset(&state->card_info, '\0', 8);
938 memcpy(&state->card_info, &state->rxbuffer, 7);
939 pr_err("Device Model=[%s]\n", &state->card_info[0]);
941 for (j = 0, p_tuner_list = tuner_list; j < ARRAY_SIZE(tuner_list); j++, p_tuner_list++) {
942 if (!strcmp(&state->card_info[0], p_tuner_list->board_name)) {
943 state->tuner_type = p_tuner_list->tuner_type;
944 pr_err("DST has [%s] tuner, tuner type=[%d]\n",
945 p_tuner_list->tuner_name, p_tuner_list->tuner_type);
952 static int dst_get_vendor(struct dst_state *state)
954 u8 get_vendor[] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
955 get_vendor[7] = dst_check_sum(get_vendor, 7);
956 if (dst_command(state, get_vendor, 8) < 0) {
957 dprintk(2, "Unsupported Command\n");
960 memset(&state->vendor, '\0', 8);
961 memcpy(&state->vendor, &state->rxbuffer, 7);
962 pr_err("Vendor=[%s]\n", &state->vendor[0]);
967 static void debug_dst_buffer(struct dst_state *state)
969 dprintk(3, "%s: [ %*ph ]\n", __func__, 8, state->rxbuffer);
972 static int dst_check_stv0299(struct dst_state *state)
974 u8 check_stv0299[] = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
976 check_stv0299[7] = dst_check_sum(check_stv0299, 7);
977 if (dst_command(state, check_stv0299, 8) < 0) {
978 pr_err("Cmd=[0x04] failed\n");
981 debug_dst_buffer(state);
983 if (memcmp(&check_stv0299, &state->rxbuffer, 8)) {
984 pr_err("Found a STV0299 NIM\n");
985 state->tuner_type = TUNER_TYPE_STV0299;
992 static int dst_check_mb86a15(struct dst_state *state)
994 u8 check_mb86a15[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
996 check_mb86a15[7] = dst_check_sum(check_mb86a15, 7);
997 if (dst_command(state, check_mb86a15, 8) < 0) {
998 pr_err("Cmd=[0x10], failed\n");
1001 debug_dst_buffer(state);
1003 if (memcmp(&check_mb86a15, &state->rxbuffer, 8) < 0) {
1004 pr_err("Found a MB86A15 NIM\n");
1005 state->tuner_type = TUNER_TYPE_MB86A15;
1012 static int dst_get_tuner_info(struct dst_state *state)
1014 u8 get_tuner_1[] = { 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1015 u8 get_tuner_2[] = { 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1017 get_tuner_1[7] = dst_check_sum(get_tuner_1, 7);
1018 get_tuner_2[7] = dst_check_sum(get_tuner_2, 7);
1019 pr_err("DST TYpe = MULTI FE\n");
1020 if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
1021 if (dst_command(state, get_tuner_1, 8) < 0) {
1022 dprintk(2, "Cmd=[0x13], Unsupported\n");
1026 if (dst_command(state, get_tuner_2, 8) < 0) {
1027 dprintk(2, "Cmd=[0xb], Unsupported\n");
1031 memcpy(&state->board_info, &state->rxbuffer, 8);
1032 if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
1033 pr_err("DST type has TS=188\n");
1035 if (state->board_info[0] == 0xbc) {
1036 if (state->dst_type != DST_TYPE_IS_ATSC)
1037 state->type_flags |= DST_TYPE_HAS_TS188;
1039 state->type_flags |= DST_TYPE_HAS_NEWTUNE_2;
1041 if (state->board_info[1] == 0x01) {
1042 state->dst_hw_cap |= DST_TYPE_HAS_DBOARD;
1043 pr_err("DST has Daughterboard\n");
1049 if (!strncmp(state->fw_name, "DCT-CI", 6)) {
1050 state->type_flags |= DST_TYPE_HAS_TS204;
1051 pr_err("Forcing [%s] to TS188\n", state->fw_name);
1057 static int dst_get_device_id(struct dst_state *state)
1062 struct dst_types *p_dst_type = NULL;
1063 struct tuner_types *p_tuner_list = NULL;
1065 u8 use_dst_type = 0;
1066 u32 use_type_flags = 0;
1068 static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
1070 state->tuner_type = 0;
1071 device_type[7] = dst_check_sum(device_type, 7);
1073 if (write_dst(state, device_type, FIXED_COMM))
1074 return -1; /* Write failed */
1075 if ((dst_pio_disable(state)) < 0)
1077 if (read_dst(state, &reply, GET_ACK))
1078 return -1; /* Read failure */
1080 dprintk(2, "Write not Acknowledged! [Reply=0x%02x]\n", reply);
1081 return -1; /* Unack'd write */
1083 if (!dst_wait_dst_ready(state, DEVICE_INIT))
1084 return -1; /* DST not ready yet */
1085 if (read_dst(state, state->rxbuffer, FIXED_COMM))
1088 dst_pio_disable(state);
1089 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
1090 dprintk(2, "Checksum failure!\n");
1091 return -1; /* Checksum failure */
1093 state->rxbuffer[7] = '\0';
1095 for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE(dst_tlist); i++, p_dst_type++) {
1096 if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
1097 use_type_flags = p_dst_type->type_flags;
1098 use_dst_type = p_dst_type->dst_type;
1100 /* Card capabilities */
1101 state->dst_hw_cap = p_dst_type->dst_feature;
1102 pr_err("Recognise [%s]\n", p_dst_type->device_id);
1103 strncpy(&state->fw_name[0], p_dst_type->device_id, 6);
1104 /* Multiple tuners */
1105 if (p_dst_type->tuner_type & TUNER_TYPE_MULTI) {
1106 switch (use_dst_type) {
1107 case DST_TYPE_IS_SAT:
1109 if (dst_check_stv0299(state) < 0) {
1110 pr_err("Unsupported\n");
1111 state->tuner_type = TUNER_TYPE_MB86A15;
1117 if (dst_check_mb86a15(state) < 0)
1118 pr_err("Unsupported\n");
1121 state->tuner_type = p_dst_type->tuner_type;
1123 for (j = 0, p_tuner_list = tuner_list; j < ARRAY_SIZE(tuner_list); j++, p_tuner_list++) {
1124 if (!(strncmp(p_dst_type->device_id, p_tuner_list->fw_name, 7)) &&
1125 p_tuner_list->tuner_type == state->tuner_type) {
1126 pr_err("[%s] has a [%s]\n",
1127 p_dst_type->device_id, p_tuner_list->tuner_name);
1134 if (i >= ARRAY_SIZE(dst_tlist)) {
1135 pr_err("Unable to recognize %s or %s\n", &state->rxbuffer[0], &state->rxbuffer[1]);
1136 pr_err("please email linux-dvb@linuxtv.org with this type in");
1137 use_dst_type = DST_TYPE_IS_SAT;
1138 use_type_flags = DST_TYPE_HAS_SYMDIV;
1140 dst_type_print(state, use_dst_type);
1141 state->type_flags = use_type_flags;
1142 state->dst_type = use_dst_type;
1143 dst_type_flags_print(state);
1148 static int dst_probe(struct dst_state *state)
1150 mutex_init(&state->dst_mutex);
1151 if (dst_addons & DST_TYPE_HAS_CA) {
1152 if ((rdc_8820_reset(state)) < 0) {
1153 pr_err("RDC 8820 RESET Failed.\n");
1160 if ((dst_comm_init(state)) < 0) {
1161 pr_err("DST Initialization Failed.\n");
1165 if (dst_get_device_id(state) < 0) {
1166 pr_err("unknown device.\n");
1169 if (dst_get_mac(state) < 0) {
1170 dprintk(2, "MAC: Unsupported command\n");
1172 if ((state->type_flags & DST_TYPE_HAS_MULTI_FE) || (state->type_flags & DST_TYPE_HAS_FW_BUILD)) {
1173 if (dst_get_tuner_info(state) < 0)
1174 dprintk(2, "Tuner: Unsupported command\n");
1176 if (state->type_flags & DST_TYPE_HAS_TS204) {
1177 dst_packsize(state, 204);
1179 if (state->type_flags & DST_TYPE_HAS_FW_BUILD) {
1180 if (dst_fw_ver(state) < 0) {
1181 dprintk(2, "FW: Unsupported command\n");
1184 if (dst_card_type(state) < 0) {
1185 dprintk(2, "Card: Unsupported command\n");
1188 if (dst_get_vendor(state) < 0) {
1189 dprintk(2, "Vendor: Unsupported command\n");
1197 static int dst_command(struct dst_state *state, u8 *data, u8 len)
1201 mutex_lock(&state->dst_mutex);
1202 if ((dst_comm_init(state)) < 0) {
1203 dprintk(1, "DST Communication Initialization Failed.\n");
1206 if (write_dst(state, data, len)) {
1207 dprintk(2, "Trying to recover..\n");
1208 if ((dst_error_recovery(state)) < 0) {
1209 pr_err("Recovery Failed.\n");
1214 if ((dst_pio_disable(state)) < 0) {
1215 pr_err("PIO Disable Failed.\n");
1218 if (state->type_flags & DST_TYPE_HAS_FW_1)
1220 if (read_dst(state, &reply, GET_ACK)) {
1221 dprintk(3, "Trying to recover..\n");
1222 if ((dst_error_recovery(state)) < 0) {
1223 dprintk(2, "Recovery Failed.\n");
1229 dprintk(2, "write not acknowledged 0x%02x\n", reply);
1232 if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
1234 if (state->type_flags & DST_TYPE_HAS_FW_1)
1238 if (!dst_wait_dst_ready(state, NO_DELAY))
1240 if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
1241 dprintk(3, "Trying to recover..\n");
1242 if ((dst_error_recovery(state)) < 0) {
1243 dprintk(2, "Recovery failed.\n");
1248 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
1249 dprintk(2, "checksum failure\n");
1252 mutex_unlock(&state->dst_mutex);
1256 mutex_unlock(&state->dst_mutex);
1261 static int dst_get_signal(struct dst_state *state)
1264 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
1265 //dprintk("%s: Getting Signal strength and other parameters\n", __func__);
1266 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
1267 state->decode_lock = state->decode_strength = state->decode_snr = 0;
1270 if (0 == (state->diseq_flags & HAS_LOCK)) {
1271 state->decode_lock = state->decode_strength = state->decode_snr = 0;
1274 if (time_after_eq(jiffies, state->cur_jiff + (HZ / 5))) {
1275 retval = dst_command(state, get_signal, 8);
1278 if (state->dst_type == DST_TYPE_IS_SAT) {
1279 state->decode_lock = ((state->rxbuffer[6] & 0x10) == 0) ? 1 : 0;
1280 state->decode_strength = state->rxbuffer[5] << 8;
1281 state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
1282 } else if ((state->dst_type == DST_TYPE_IS_TERR) || (state->dst_type == DST_TYPE_IS_CABLE)) {
1283 state->decode_lock = (state->rxbuffer[1]) ? 1 : 0;
1284 state->decode_strength = state->rxbuffer[4] << 8;
1285 state->decode_snr = state->rxbuffer[3] << 8;
1286 } else if (state->dst_type == DST_TYPE_IS_ATSC) {
1287 state->decode_lock = (state->rxbuffer[6] == 0x00) ? 1 : 0;
1288 state->decode_strength = state->rxbuffer[4] << 8;
1289 state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
1291 state->cur_jiff = jiffies;
1296 static int dst_tone_power_cmd(struct dst_state *state)
1298 u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
1300 if (state->dst_type != DST_TYPE_IS_SAT)
1302 paket[4] = state->tx_tuna[4];
1303 paket[2] = state->tx_tuna[2];
1304 paket[3] = state->tx_tuna[3];
1305 paket[7] = dst_check_sum (paket, 7);
1306 return dst_command(state, paket, 8);
1309 static int dst_get_tuna(struct dst_state *state)
1313 if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
1315 state->diseq_flags &= ~(HAS_LOCK);
1316 if (!dst_wait_dst_ready(state, NO_DELAY))
1318 if ((state->type_flags & DST_TYPE_HAS_VLF) &&
1319 !(state->dst_type == DST_TYPE_IS_ATSC))
1321 retval = read_dst(state, state->rx_tuna, 10);
1323 retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
1325 dprintk(3, "read not successful\n");
1328 if ((state->type_flags & DST_TYPE_HAS_VLF) &&
1329 !(state->dst_type == DST_TYPE_IS_ATSC)) {
1331 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
1332 dprintk(2, "checksum failure ?\n");
1336 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) {
1337 dprintk(2, "checksum failure?\n");
1341 if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0)
1343 if (state->dst_type == DST_TYPE_IS_SAT) {
1344 state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
1346 state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 16) + (state->rx_tuna[3] << 8) + state->rx_tuna[4];
1348 state->decode_freq = state->decode_freq * 1000;
1349 state->decode_lock = 1;
1350 state->diseq_flags |= HAS_LOCK;
1355 static int dst_set_voltage(struct dvb_frontend *fe,
1356 enum fe_sec_voltage voltage);
1358 static int dst_write_tuna(struct dvb_frontend *fe)
1360 struct dst_state *state = fe->demodulator_priv;
1364 dprintk(2, "type_flags 0x%x\n", state->type_flags);
1365 state->decode_freq = 0;
1366 state->decode_lock = state->decode_strength = state->decode_snr = 0;
1367 if (state->dst_type == DST_TYPE_IS_SAT) {
1368 if (!(state->diseq_flags & HAS_POWER))
1369 dst_set_voltage(fe, SEC_VOLTAGE_13);
1371 state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
1372 mutex_lock(&state->dst_mutex);
1373 if ((dst_comm_init(state)) < 0) {
1374 dprintk(3, "DST Communication initialization failed.\n");
1377 // if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
1378 if ((state->type_flags & DST_TYPE_HAS_VLF) &&
1379 (!(state->dst_type == DST_TYPE_IS_ATSC))) {
1381 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
1382 retval = write_dst(state, &state->tx_tuna[0], 10);
1384 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
1385 retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
1388 dst_pio_disable(state);
1389 dprintk(3, "write not successful\n");
1392 if ((dst_pio_disable(state)) < 0) {
1393 dprintk(3, "DST PIO disable failed !\n");
1396 if ((read_dst(state, &reply, GET_ACK) < 0)) {
1397 dprintk(3, "read verify not successful.\n");
1401 dprintk(3, "write not acknowledged 0x%02x\n", reply);
1404 state->diseq_flags |= ATTEMPT_TUNE;
1405 retval = dst_get_tuna(state);
1407 mutex_unlock(&state->dst_mutex);
1411 mutex_unlock(&state->dst_mutex);
1416 * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
1417 * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
1418 * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
1419 * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
1420 * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
1421 * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
1422 * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
1423 * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
1424 * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
1425 * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
1426 * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
1429 static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd *cmd)
1431 struct dst_state *state = fe->demodulator_priv;
1432 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
1434 if (state->dst_type != DST_TYPE_IS_SAT)
1436 if (cmd->msg_len > 0 && cmd->msg_len < 5)
1437 memcpy(&paket[3], cmd->msg, cmd->msg_len);
1438 else if (cmd->msg_len == 5 && state->dst_hw_cap & DST_TYPE_HAS_DISEQC5)
1439 memcpy(&paket[2], cmd->msg, cmd->msg_len);
1442 paket[7] = dst_check_sum(&paket[0], 7);
1443 return dst_command(state, paket, 8);
1446 static int dst_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage voltage)
1448 int need_cmd, retval = 0;
1449 struct dst_state *state = fe->demodulator_priv;
1451 state->voltage = voltage;
1452 if (state->dst_type != DST_TYPE_IS_SAT)
1458 case SEC_VOLTAGE_13:
1459 case SEC_VOLTAGE_18:
1460 if ((state->diseq_flags & HAS_POWER) == 0)
1462 state->diseq_flags |= HAS_POWER;
1463 state->tx_tuna[4] = 0x01;
1465 case SEC_VOLTAGE_OFF:
1467 state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
1468 state->tx_tuna[4] = 0x00;
1475 retval = dst_tone_power_cmd(state);
1480 static int dst_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
1482 struct dst_state *state = fe->demodulator_priv;
1485 if (state->dst_type != DST_TYPE_IS_SAT)
1490 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1491 state->tx_tuna[2] = 0x00;
1493 state->tx_tuna[2] = 0xff;
1497 state->tx_tuna[2] = 0x02;
1502 return dst_tone_power_cmd(state);
1505 static int dst_send_burst(struct dvb_frontend *fe, enum fe_sec_mini_cmd minicmd)
1507 struct dst_state *state = fe->demodulator_priv;
1509 if (state->dst_type != DST_TYPE_IS_SAT)
1511 state->minicmd = minicmd;
1514 state->tx_tuna[3] = 0x02;
1517 state->tx_tuna[3] = 0xff;
1520 return dst_tone_power_cmd(state);
1524 static int bt8xx_dst_init(struct dvb_frontend *fe)
1526 struct dst_state *state = fe->demodulator_priv;
1528 static u8 sat_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x00, 0x73, 0x21, 0x00, 0x00 };
1529 static u8 sat_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x55, 0xbd, 0x50, 0x00, 0x00 };
1530 static u8 ter_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1531 static u8 ter_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1532 static u8 cab_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1533 static u8 cab_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1534 static u8 atsc_tuner[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1536 state->inversion = INVERSION_OFF;
1537 state->voltage = SEC_VOLTAGE_13;
1538 state->tone = SEC_TONE_OFF;
1539 state->diseq_flags = 0;
1541 state->bandwidth = 7000000;
1542 state->cur_jiff = jiffies;
1543 if (state->dst_type == DST_TYPE_IS_SAT)
1544 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_VLF) ? sat_tuna_188 : sat_tuna_204), sizeof (sat_tuna_204));
1545 else if (state->dst_type == DST_TYPE_IS_TERR)
1546 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_VLF) ? ter_tuna_188 : ter_tuna_204), sizeof (ter_tuna_204));
1547 else if (state->dst_type == DST_TYPE_IS_CABLE)
1548 memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_VLF) ? cab_tuna_188 : cab_tuna_204), sizeof (cab_tuna_204));
1549 else if (state->dst_type == DST_TYPE_IS_ATSC)
1550 memcpy(state->tx_tuna, atsc_tuner, sizeof (atsc_tuner));
1555 static int dst_read_status(struct dvb_frontend *fe, enum fe_status *status)
1557 struct dst_state *state = fe->demodulator_priv;
1560 if (state->diseq_flags & HAS_LOCK) {
1561 // dst_get_signal(state); // don't require(?) to ask MCU
1562 if (state->decode_lock)
1563 *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
1569 static int dst_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
1571 struct dst_state *state = fe->demodulator_priv;
1573 int retval = dst_get_signal(state);
1574 *strength = state->decode_strength;
1579 static int dst_read_snr(struct dvb_frontend *fe, u16 *snr)
1581 struct dst_state *state = fe->demodulator_priv;
1583 int retval = dst_get_signal(state);
1584 *snr = state->decode_snr;
1589 static int dst_set_frontend(struct dvb_frontend *fe)
1591 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1592 int retval = -EINVAL;
1593 struct dst_state *state = fe->demodulator_priv;
1596 retval = dst_set_freq(state, p->frequency);
1599 dprintk(3, "Set Frequency=[%d]\n", p->frequency);
1601 if (state->dst_type == DST_TYPE_IS_SAT) {
1602 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1603 dst_set_inversion(state, p->inversion);
1604 dst_set_fec(state, p->fec_inner);
1605 dst_set_symbolrate(state, p->symbol_rate);
1606 dst_set_polarization(state);
1607 dprintk(3, "Set Symbolrate=[%d]\n", p->symbol_rate);
1609 } else if (state->dst_type == DST_TYPE_IS_TERR)
1610 dst_set_bandwidth(state, p->bandwidth_hz);
1611 else if (state->dst_type == DST_TYPE_IS_CABLE) {
1612 dst_set_fec(state, p->fec_inner);
1613 dst_set_symbolrate(state, p->symbol_rate);
1614 dst_set_modulation(state, p->modulation);
1616 retval = dst_write_tuna(fe);
1622 static int dst_tune_frontend(struct dvb_frontend* fe,
1624 unsigned int mode_flags,
1625 unsigned int *delay,
1626 enum fe_status *status)
1628 struct dst_state *state = fe->demodulator_priv;
1629 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1632 dst_set_freq(state, p->frequency);
1633 dprintk(3, "Set Frequency=[%d]\n", p->frequency);
1635 if (state->dst_type == DST_TYPE_IS_SAT) {
1636 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1637 dst_set_inversion(state, p->inversion);
1638 dst_set_fec(state, p->fec_inner);
1639 dst_set_symbolrate(state, p->symbol_rate);
1640 dst_set_polarization(state);
1641 dprintk(3, "Set Symbolrate=[%d]\n", p->symbol_rate);
1643 } else if (state->dst_type == DST_TYPE_IS_TERR)
1644 dst_set_bandwidth(state, p->bandwidth_hz);
1645 else if (state->dst_type == DST_TYPE_IS_CABLE) {
1646 dst_set_fec(state, p->fec_inner);
1647 dst_set_symbolrate(state, p->symbol_rate);
1648 dst_set_modulation(state, p->modulation);
1653 if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
1654 dst_read_status(fe, status);
1660 static int dst_get_tuning_algo(struct dvb_frontend *fe)
1662 return dst_algo ? DVBFE_ALGO_HW : DVBFE_ALGO_SW;
1665 static int dst_get_frontend(struct dvb_frontend *fe,
1666 struct dtv_frontend_properties *p)
1668 struct dst_state *state = fe->demodulator_priv;
1670 p->frequency = state->decode_freq;
1671 if (state->dst_type == DST_TYPE_IS_SAT) {
1672 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1673 p->inversion = state->inversion;
1674 p->symbol_rate = state->symbol_rate;
1675 p->fec_inner = dst_get_fec(state);
1676 } else if (state->dst_type == DST_TYPE_IS_TERR) {
1677 p->bandwidth_hz = state->bandwidth;
1678 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
1679 p->symbol_rate = state->symbol_rate;
1680 p->fec_inner = dst_get_fec(state);
1681 p->modulation = dst_get_modulation(state);
1687 static void bt8xx_dst_release(struct dvb_frontend *fe)
1689 struct dst_state *state = fe->demodulator_priv;
1690 if (state->dst_ca) {
1691 dvb_unregister_device(state->dst_ca);
1692 #ifdef CONFIG_MEDIA_ATTACH
1693 symbol_put(dst_ca_attach);
1699 static const struct dvb_frontend_ops dst_dvbt_ops;
1700 static const struct dvb_frontend_ops dst_dvbs_ops;
1701 static const struct dvb_frontend_ops dst_dvbc_ops;
1702 static const struct dvb_frontend_ops dst_atsc_ops;
1704 struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
1706 /* check if the ASIC is there */
1707 if (dst_probe(state) < 0) {
1711 /* determine settings based on type */
1712 /* create dvb_frontend */
1713 switch (state->dst_type) {
1714 case DST_TYPE_IS_TERR:
1715 memcpy(&state->frontend.ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
1717 case DST_TYPE_IS_CABLE:
1718 memcpy(&state->frontend.ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
1720 case DST_TYPE_IS_SAT:
1721 memcpy(&state->frontend.ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
1723 case DST_TYPE_IS_ATSC:
1724 memcpy(&state->frontend.ops, &dst_atsc_ops, sizeof(struct dvb_frontend_ops));
1727 pr_err("unknown DST type. please report to the LinuxTV.org DVB mailinglist.\n");
1731 state->frontend.demodulator_priv = state;
1733 return state; /* Manu (DST is a card not a frontend) */
1736 EXPORT_SYMBOL_GPL(dst_attach);
1738 static const struct dvb_frontend_ops dst_dvbt_ops = {
1739 .delsys = { SYS_DVBT },
1741 .name = "DST DVB-T",
1742 .frequency_min = 137000000,
1743 .frequency_max = 858000000,
1744 .frequency_stepsize = 166667,
1745 .caps = FE_CAN_FEC_AUTO |
1752 FE_CAN_TRANSMISSION_MODE_AUTO |
1753 FE_CAN_GUARD_INTERVAL_AUTO
1756 .release = bt8xx_dst_release,
1757 .init = bt8xx_dst_init,
1758 .tune = dst_tune_frontend,
1759 .set_frontend = dst_set_frontend,
1760 .get_frontend = dst_get_frontend,
1761 .get_frontend_algo = dst_get_tuning_algo,
1762 .read_status = dst_read_status,
1763 .read_signal_strength = dst_read_signal_strength,
1764 .read_snr = dst_read_snr,
1767 static const struct dvb_frontend_ops dst_dvbs_ops = {
1768 .delsys = { SYS_DVBS },
1770 .name = "DST DVB-S",
1771 .frequency_min = 950000,
1772 .frequency_max = 2150000,
1773 .frequency_stepsize = 1000, /* kHz for QPSK frontends */
1774 .frequency_tolerance = 29500,
1775 .symbol_rate_min = 1000000,
1776 .symbol_rate_max = 45000000,
1777 /* . symbol_rate_tolerance = ???,*/
1778 .caps = FE_CAN_FEC_AUTO | FE_CAN_QPSK
1781 .release = bt8xx_dst_release,
1782 .init = bt8xx_dst_init,
1783 .tune = dst_tune_frontend,
1784 .set_frontend = dst_set_frontend,
1785 .get_frontend = dst_get_frontend,
1786 .get_frontend_algo = dst_get_tuning_algo,
1787 .read_status = dst_read_status,
1788 .read_signal_strength = dst_read_signal_strength,
1789 .read_snr = dst_read_snr,
1790 .diseqc_send_burst = dst_send_burst,
1791 .diseqc_send_master_cmd = dst_set_diseqc,
1792 .set_voltage = dst_set_voltage,
1793 .set_tone = dst_set_tone,
1796 static const struct dvb_frontend_ops dst_dvbc_ops = {
1797 .delsys = { SYS_DVBC_ANNEX_A },
1799 .name = "DST DVB-C",
1800 .frequency_stepsize = 62500,
1801 .frequency_min = 51000000,
1802 .frequency_max = 858000000,
1803 .symbol_rate_min = 1000000,
1804 .symbol_rate_max = 45000000,
1805 .caps = FE_CAN_FEC_AUTO |
1814 .release = bt8xx_dst_release,
1815 .init = bt8xx_dst_init,
1816 .tune = dst_tune_frontend,
1817 .set_frontend = dst_set_frontend,
1818 .get_frontend = dst_get_frontend,
1819 .get_frontend_algo = dst_get_tuning_algo,
1820 .read_status = dst_read_status,
1821 .read_signal_strength = dst_read_signal_strength,
1822 .read_snr = dst_read_snr,
1825 static const struct dvb_frontend_ops dst_atsc_ops = {
1826 .delsys = { SYS_ATSC },
1829 .frequency_stepsize = 62500,
1830 .frequency_min = 510000000,
1831 .frequency_max = 858000000,
1832 .symbol_rate_min = 1000000,
1833 .symbol_rate_max = 45000000,
1834 .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
1837 .release = bt8xx_dst_release,
1838 .init = bt8xx_dst_init,
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,
1848 MODULE_DESCRIPTION("DST DVB-S/T/C/ATSC Combo Frontend driver");
1849 MODULE_AUTHOR("Jamie Honan, Manu Abraham");
1850 MODULE_LICENSE("GPL");