3 Frontend/Card driver for TwinHan DST Frontend
4 Copyright (C) 2003 Jamie Honan
5 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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>
32 #include "dvb_frontend.h"
34 #include "dst_common.h"
37 static unsigned int verbose
= 1;
38 module_param(verbose
, int, 0644);
39 MODULE_PARM_DESC(verbose
, "verbose startup messages, default is 1 (yes)");
41 static unsigned int debug
= 1;
42 module_param(debug
, int, 0644);
43 MODULE_PARM_DESC(debug
, "debug messages, default is 0 (yes)");
45 static unsigned int dst_addons
;
46 module_param(dst_addons
, int, 0644);
47 MODULE_PARM_DESC(dst_addons
, "CA daughterboard, default is 0 (no)");
49 static unsigned int new_fw
;
50 module_param(new_fw
, int, 0644);
51 MODULE_PARM_DESC(new_fw
, "Support for the new interface firmware, default 0");
55 #define dprintk if (debug) printk
58 #define ATTEMPT_TUNE 2
61 static void dst_packsize(struct dst_state
* state
, int psize
)
63 union dst_gpio_packet bits
;
66 bt878_device_control(state
->bt
, DST_IG_TS
, &bits
);
69 int dst_gpio_outb(struct dst_state
* state
, u32 mask
, u32 enbb
, u32 outhigh
, int delay
)
71 union dst_gpio_packet enb
;
72 union dst_gpio_packet bits
;
76 enb
.enb
.enable
= enbb
;
78 dprintk("%s: mask=[%04x], enbb=[%04x], outhigh=[%04x]\n", __FUNCTION__
, mask
, enbb
, outhigh
);
80 if ((err
= bt878_device_control(state
->bt
, DST_IG_ENABLE
, &enb
)) < 0) {
81 dprintk("%s: dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)\n", __FUNCTION__
, err
, mask
, enbb
);
87 /* because complete disabling means no output, no need to do output packet */
94 bits
.outp
.mask
= enbb
;
95 bits
.outp
.highvals
= outhigh
;
97 if ((err
= bt878_device_control(state
->bt
, DST_IG_WRITE
, &bits
)) < 0) {
98 dprintk("%s: dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)\n", __FUNCTION__
, err
, enbb
, outhigh
);
103 EXPORT_SYMBOL(dst_gpio_outb
);
105 int dst_gpio_inb(struct dst_state
*state
, u8
* result
)
107 union dst_gpio_packet rd_packet
;
112 if ((err
= bt878_device_control(state
->bt
, DST_IG_READ
, &rd_packet
)) < 0) {
113 dprintk("%s: dst_gpio_inb error (err == %i)\n", __FUNCTION__
, err
);
117 *result
= (u8
) rd_packet
.rd
.value
;
120 EXPORT_SYMBOL(dst_gpio_inb
);
122 int rdc_reset_state(struct dst_state
*state
)
125 dprintk("%s: Resetting state machine\n", __FUNCTION__
);
127 if (dst_gpio_outb(state
, RDC_8820_INT
, RDC_8820_INT
, 0, NO_DELAY
) < 0) {
128 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
134 if (dst_gpio_outb(state
, RDC_8820_INT
, RDC_8820_INT
, RDC_8820_INT
, NO_DELAY
) < 0) {
135 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
142 EXPORT_SYMBOL(rdc_reset_state
);
144 int rdc_8820_reset(struct dst_state
*state
)
147 dprintk("%s: Resetting DST\n", __FUNCTION__
);
149 if (dst_gpio_outb(state
, RDC_8820_RESET
, RDC_8820_RESET
, 0, NO_DELAY
) < 0) {
150 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
155 if (dst_gpio_outb(state
, RDC_8820_RESET
, RDC_8820_RESET
, RDC_8820_RESET
, DELAY
) < 0) {
156 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
162 EXPORT_SYMBOL(rdc_8820_reset
);
164 int dst_pio_enable(struct dst_state
*state
)
166 if (dst_gpio_outb(state
, ~0, RDC_8820_PIO_0_ENABLE
, 0, NO_DELAY
) < 0) {
167 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
174 EXPORT_SYMBOL(dst_pio_enable
);
176 int dst_pio_disable(struct dst_state
*state
)
178 if (dst_gpio_outb(state
, ~0, RDC_8820_PIO_0_DISABLE
, RDC_8820_PIO_0_DISABLE
, NO_DELAY
) < 0) {
179 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
185 EXPORT_SYMBOL(dst_pio_disable
);
187 int dst_wait_dst_ready(struct dst_state
*state
, u8 delay_mode
)
192 for (i
= 0; i
< 200; i
++) {
193 if (dst_gpio_inb(state
, &reply
) < 0) {
194 dprintk("%s: dst_gpio_inb ERROR !\n", __FUNCTION__
);
198 if ((reply
& RDC_8820_PIO_0_ENABLE
) == 0) {
200 dprintk("%s: dst wait ready after %d\n", __FUNCTION__
, i
);
206 dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__
, i
);
210 EXPORT_SYMBOL(dst_wait_dst_ready
);
212 int dst_error_recovery(struct dst_state
*state
)
214 dprintk("%s: Trying to return from previous errors...\n", __FUNCTION__
);
215 dst_pio_disable(state
);
217 dst_pio_enable(state
);
222 EXPORT_SYMBOL(dst_error_recovery
);
224 int dst_error_bailout(struct dst_state
*state
)
226 dprintk("%s: Trying to bailout from previous error...\n", __FUNCTION__
);
227 rdc_8820_reset(state
);
228 dst_pio_disable(state
);
233 EXPORT_SYMBOL(dst_error_bailout
);
236 int dst_comm_init(struct dst_state
* state
)
239 dprintk ("%s: Initializing DST..\n", __FUNCTION__
);
240 if ((dst_pio_enable(state
)) < 0) {
241 dprintk("%s: PIO Enable Failed.\n", __FUNCTION__
);
244 if ((rdc_reset_state(state
)) < 0) {
245 dprintk("%s: RDC 8820 State RESET Failed.\n", __FUNCTION__
);
250 EXPORT_SYMBOL(dst_comm_init
);
253 int write_dst(struct dst_state
*state
, u8
*data
, u8 len
)
255 struct i2c_msg msg
= {
256 .addr
= state
->config
->demod_address
,.flags
= 0,.buf
= data
,.len
= len
261 if (debug
&& (verbose
> 4)) {
264 dprintk("%s writing", __FUNCTION__
);
265 for (i
= 0; i
< len
; i
++)
266 dprintk(" %02x", data
[i
]);
270 for (cnt
= 0; cnt
< 2; cnt
++) {
271 if ((err
= i2c_transfer(state
->i2c
, &msg
, 1)) < 0) {
272 dprintk("%s: _write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__
, err
, len
, data
[0]);
273 dst_error_recovery(state
);
281 printk("%s: RDC 8820 RESET...\n", __FUNCTION__
);
282 dst_error_bailout(state
);
289 EXPORT_SYMBOL(write_dst
);
291 int read_dst(struct dst_state
*state
, u8
* ret
, u8 len
)
293 struct i2c_msg msg
= {.addr
= state
->config
->demod_address
,.flags
= I2C_M_RD
,.buf
= ret
,.len
= len
};
297 for (cnt
= 0; cnt
< 2; cnt
++) {
298 if ((err
= i2c_transfer(state
->i2c
, &msg
, 1)) < 0) {
300 dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__
, err
, len
, ret
[0]);
301 dst_error_recovery(state
);
309 printk("%s: RDC 8820 RESET...\n", __FUNCTION__
);
310 dst_error_bailout(state
);
314 if (debug
&& (verbose
> 4)) {
315 dprintk("%s reply is 0x%x\n", __FUNCTION__
, ret
[0]);
316 for (err
= 1; err
< len
; err
++)
317 dprintk(" 0x%x", ret
[err
]);
324 EXPORT_SYMBOL(read_dst
);
326 static int dst_set_freq(struct dst_state
*state
, u32 freq
)
330 state
->frequency
= freq
;
332 // dprintk("%s: set frequency %u\n", __FUNCTION__, freq);
333 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
335 if (freq
< 950 || freq
> 2150)
337 val
= &state
->tx_tuna
[0];
338 val
[2] = (freq
>> 8) & 0x7f;
344 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
346 if (freq
< 137000 || freq
> 858000)
348 val
= &state
->tx_tuna
[0];
349 val
[2] = (freq
>> 16) & 0xff;
350 val
[3] = (freq
>> 8) & 0xff;
353 switch (state
->bandwidth
) {
354 case BANDWIDTH_6_MHZ
:
358 case BANDWIDTH_7_MHZ
:
363 case BANDWIDTH_8_MHZ
:
370 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
371 /* guess till will get one */
373 val
= &state
->tx_tuna
[0];
374 val
[2] = (freq
>> 16) & 0xff;
375 val
[3] = (freq
>> 8) & 0xff;
382 static int dst_set_bandwidth(struct dst_state
* state
, fe_bandwidth_t bandwidth
)
386 state
->bandwidth
= bandwidth
;
388 if (state
->dst_type
!= DST_TYPE_IS_TERR
)
391 val
= &state
->tx_tuna
[0];
393 case BANDWIDTH_6_MHZ
:
397 case BANDWIDTH_7_MHZ
:
401 case BANDWIDTH_8_MHZ
:
411 static int dst_set_inversion(struct dst_state
* state
, fe_spectral_inversion_t inversion
)
415 state
->inversion
= inversion
;
417 val
= &state
->tx_tuna
[0];
433 static int dst_set_fec(struct dst_state
* state
, fe_code_rate_t fec
)
439 static fe_code_rate_t
dst_get_fec(struct dst_state
* state
)
444 static int dst_set_symbolrate(struct dst_state
* state
, u32 srate
)
450 state
->symbol_rate
= srate
;
452 if (state
->dst_type
== DST_TYPE_IS_TERR
) {
455 // dprintk("%s: set srate %u\n", __FUNCTION__, srate);
457 val
= &state
->tx_tuna
[0];
459 if (state
->type_flags
& DST_TYPE_HAS_SYMDIV
) {
463 symcalc
= (u32
) sval
;
464 // dprintk("%s: set symcalc %u\n", __FUNCTION__, symcalc);
465 val
[5] = (u8
) (symcalc
>> 12);
466 val
[6] = (u8
) (symcalc
>> 4);
467 val
[7] = (u8
) (symcalc
<< 4);
469 val
[5] = (u8
) (srate
>> 16) & 0x7f;
470 val
[6] = (u8
) (srate
>> 8);
479 u8
dst_check_sum(u8
* buf
, u32 len
)
485 for (i
= 0; i
< len
; i
++) {
490 EXPORT_SYMBOL(dst_check_sum
);
492 static void dst_type_flags_print(u32 type_flags
)
494 printk("DST type flags :");
495 if (type_flags
& DST_TYPE_HAS_NEWTUNE
)
496 printk(" 0x%x newtuner", DST_TYPE_HAS_NEWTUNE
);
497 if (type_flags
& DST_TYPE_HAS_TS204
)
498 printk(" 0x%x ts204", DST_TYPE_HAS_TS204
);
499 if (type_flags
& DST_TYPE_HAS_SYMDIV
)
500 printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV
);
501 if (type_flags
& DST_TYPE_HAS_FW_1
)
502 printk(" 0x%x firmware version = 1", DST_TYPE_HAS_FW_1
);
503 if (type_flags
& DST_TYPE_HAS_FW_2
)
504 printk(" 0x%x firmware version = 2", DST_TYPE_HAS_FW_2
);
505 if (type_flags
& DST_TYPE_HAS_FW_3
)
506 printk(" 0x%x firmware version = 3", DST_TYPE_HAS_FW_3
);
512 static int dst_type_print (u8 type
)
516 case DST_TYPE_IS_SAT
:
520 case DST_TYPE_IS_TERR
:
521 otype
= "terrestrial";
524 case DST_TYPE_IS_CABLE
:
529 printk("%s: invalid dst type %d\n", __FUNCTION__
, type
);
532 printk("DST type : %s\n", otype
);
542 VP-1020 DST-MOT LG(old), TS=188
544 VP-1020 DST-03T LG(new), TS=204
545 VP-1022 DST-03T LG(new), TS=204
546 VP-1025 DST-03T LG(new), TS=204
548 VP-1030 DSTMCI, LG(new), TS=188
549 VP-1032 DSTMCI, LG(new), TS=188
553 VP-2030 DCT-CI, Samsung, TS=204
554 VP-2021 DCT-CI, Unknown, TS=204
555 VP-2031 DCT-CI, Philips, TS=188
556 VP-2040 DCT-CI, Philips, TS=188, with CA daughter board
557 VP-2040 DCT-CI, Philips, TS=204, without CA daughter board
561 VP-3050 DTTNXT TS=188
562 VP-3040 DTT-CI, Philips, TS=188
563 VP-3040 DTT-CI, Philips, TS=204
567 VP-3220 ATSCDI, TS=188
568 VP-3250 ATSCAD, TS=188
572 struct dst_types dst_tlist
[] = {
574 .device_id
= "200103A",
576 .dst_type
= DST_TYPE_IS_SAT
,
577 .type_flags
= DST_TYPE_HAS_SYMDIV
| DST_TYPE_HAS_FW_1
,
582 .device_id
= "DST-020",
584 .dst_type
= DST_TYPE_IS_SAT
,
585 .type_flags
= DST_TYPE_HAS_SYMDIV
| DST_TYPE_HAS_FW_1
,
590 .device_id
= "DST-030",
592 .dst_type
= DST_TYPE_IS_SAT
,
593 .type_flags
= DST_TYPE_HAS_TS204
| DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_1
,
598 .device_id
= "DST-03T",
600 .dst_type
= DST_TYPE_IS_SAT
,
601 .type_flags
= DST_TYPE_HAS_SYMDIV
| DST_TYPE_HAS_TS204
| DST_TYPE_HAS_FW_2
,
602 .dst_feature
= DST_TYPE_HAS_DISEQC3
| DST_TYPE_HAS_DISEQC4
| DST_TYPE_HAS_DISEQC5
603 | DST_TYPE_HAS_MAC
| DST_TYPE_HAS_MOTO
607 .device_id
= "DST-MOT",
609 .dst_type
= DST_TYPE_IS_SAT
,
610 .type_flags
= DST_TYPE_HAS_SYMDIV
| DST_TYPE_HAS_FW_1
,
615 .device_id
= "DST-CI",
617 .dst_type
= DST_TYPE_IS_SAT
,
618 .type_flags
= DST_TYPE_HAS_TS204
| DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_1
,
619 .dst_feature
= DST_TYPE_HAS_CA
620 }, /* unknown to vendor */
623 .device_id
= "DSTMCI",
625 .dst_type
= DST_TYPE_IS_SAT
,
626 .type_flags
= DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_2
,
627 .dst_feature
= DST_TYPE_HAS_CA
| DST_TYPE_HAS_DISEQC3
| DST_TYPE_HAS_DISEQC4
628 | DST_TYPE_HAS_MOTO
| DST_TYPE_HAS_MAC
632 .device_id
= "DSTFCI",
634 .dst_type
= DST_TYPE_IS_SAT
,
635 .type_flags
= DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_1
,
637 }, /* unknown to vendor */
640 .device_id
= "DCT-CI",
642 .dst_type
= DST_TYPE_IS_CABLE
,
643 .type_flags
= DST_TYPE_HAS_TS204
| DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_1
| DST_TYPE_HAS_FW_2
,
644 .dst_feature
= DST_TYPE_HAS_CA
648 .device_id
= "DCTNEW",
650 .dst_type
= DST_TYPE_IS_CABLE
,
651 .type_flags
= DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_3
,
656 .device_id
= "DTT-CI",
658 .dst_type
= DST_TYPE_IS_TERR
,
659 .type_flags
= DST_TYPE_HAS_TS204
| DST_TYPE_HAS_FW_2
,
664 .device_id
= "DTTDIG",
666 .dst_type
= DST_TYPE_IS_TERR
,
667 .type_flags
= DST_TYPE_HAS_FW_2
,
672 .device_id
= "DTTNXT",
674 .dst_type
= DST_TYPE_IS_TERR
,
675 .type_flags
= DST_TYPE_HAS_FW_2
,
676 .dst_feature
= DST_TYPE_HAS_ANALOG
680 .device_id
= "ATSCDI",
682 .dst_type
= DST_TYPE_IS_ATSC
,
683 .type_flags
= DST_TYPE_HAS_FW_2
,
688 .device_id
= "ATSCAD",
690 .dst_type
= DST_TYPE_IS_ATSC
,
691 .type_flags
= DST_TYPE_HAS_FW_2
,
700 static int dst_get_device_id(struct dst_state
*state
)
705 struct dst_types
*p_dst_type
;
707 u32 use_type_flags
= 0;
709 static u8 device_type
[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
711 device_type
[7] = dst_check_sum(device_type
, 7);
713 if (write_dst(state
, device_type
, FIXED_COMM
))
714 return -1; /* Write failed */
716 if ((dst_pio_disable(state
)) < 0)
719 if (read_dst(state
, &reply
, GET_ACK
))
720 return -1; /* Read failure */
723 dprintk("%s: Write not Acknowledged! [Reply=0x%02x]\n", __FUNCTION__
, reply
);
724 return -1; /* Unack'd write */
727 if (!dst_wait_dst_ready(state
, DEVICE_INIT
))
728 return -1; /* DST not ready yet */
730 if (read_dst(state
, state
->rxbuffer
, FIXED_COMM
))
733 dst_pio_disable(state
);
735 if (state
->rxbuffer
[7] != dst_check_sum(state
->rxbuffer
, 7)) {
736 dprintk("%s: Checksum failure! \n", __FUNCTION__
);
737 return -1; /* Checksum failure */
740 state
->rxbuffer
[7] = '\0';
742 for (i
= 0, p_dst_type
= dst_tlist
; i
< ARRAY_SIZE (dst_tlist
); i
++, p_dst_type
++) {
743 if (!strncmp (&state
->rxbuffer
[p_dst_type
->offset
], p_dst_type
->device_id
, strlen (p_dst_type
->device_id
))) {
744 use_type_flags
= p_dst_type
->type_flags
;
745 use_dst_type
= p_dst_type
->dst_type
;
747 /* Card capabilities */
748 state
->dst_hw_cap
= p_dst_type
->dst_feature
;
749 printk ("%s: Recognise [%s]\n", __FUNCTION__
, p_dst_type
->device_id
);
755 if (i
>= sizeof (dst_tlist
) / sizeof (dst_tlist
[0])) {
756 printk("%s: Unable to recognize %s or %s\n", __FUNCTION__
, &state
->rxbuffer
[0], &state
->rxbuffer
[1]);
757 printk("%s: please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__
);
758 use_dst_type
= DST_TYPE_IS_SAT
;
759 use_type_flags
= DST_TYPE_HAS_SYMDIV
;
762 dst_type_print(use_dst_type
);
763 state
->type_flags
= use_type_flags
;
764 state
->dst_type
= use_dst_type
;
765 dst_type_flags_print(state
->type_flags
);
767 if (state
->type_flags
& DST_TYPE_HAS_TS204
) {
768 dst_packsize(state
, 204);
774 static int dst_probe(struct dst_state
*state
)
776 if ((rdc_8820_reset(state
)) < 0) {
777 dprintk("%s: RDC 8820 RESET Failed.\n", __FUNCTION__
);
781 if ((dst_comm_init(state
)) < 0) {
782 dprintk("%s: DST Initialization Failed.\n", __FUNCTION__
);
786 if (dst_get_device_id(state
) < 0) {
787 dprintk("%s: unknown device.\n", __FUNCTION__
);
794 int dst_command(struct dst_state
* state
, u8
* data
, u8 len
)
797 if ((dst_comm_init(state
)) < 0) {
798 dprintk("%s: DST Communication Initialization Failed.\n", __FUNCTION__
);
802 if (write_dst(state
, data
, len
)) {
804 dprintk("%s: Tring to recover.. \n", __FUNCTION__
);
805 if ((dst_error_recovery(state
)) < 0) {
806 dprintk("%s: Recovery Failed.\n", __FUNCTION__
);
811 if ((dst_pio_disable(state
)) < 0) {
812 dprintk("%s: PIO Disable Failed.\n", __FUNCTION__
);
816 if (read_dst(state
, &reply
, GET_ACK
)) {
818 dprintk("%s: Trying to recover.. \n", __FUNCTION__
);
819 if ((dst_error_recovery(state
)) < 0) {
820 dprintk("%s: Recovery Failed.\n", __FUNCTION__
);
827 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__
, reply
);
830 if (len
>= 2 && data
[0] == 0 && (data
[1] == 1 || data
[1] == 3))
832 if (!dst_wait_dst_ready(state
, NO_DELAY
))
835 if (read_dst(state
, state
->rxbuffer
, FIXED_COMM
)) {
837 dprintk("%s: Trying to recover.. \n", __FUNCTION__
);
838 if ((dst_error_recovery(state
)) < 0) {
839 dprintk("%s: Recovery failed.\n", __FUNCTION__
);
845 if (state
->rxbuffer
[7] != dst_check_sum(state
->rxbuffer
, 7)) {
846 dprintk("%s: checksum failure\n", __FUNCTION__
);
852 EXPORT_SYMBOL(dst_command
);
854 static int dst_get_signal(struct dst_state
* state
)
857 u8 get_signal
[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
859 if ((state
->diseq_flags
& ATTEMPT_TUNE
) == 0) {
860 state
->decode_lock
= state
->decode_strength
= state
->decode_snr
= 0;
863 if (0 == (state
->diseq_flags
& HAS_LOCK
)) {
864 state
->decode_lock
= state
->decode_strength
= state
->decode_snr
= 0;
867 if (time_after_eq(jiffies
, state
->cur_jiff
+ (HZ
/ 5))) {
868 retval
= dst_command(state
, get_signal
, 8);
871 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
872 state
->decode_lock
= ((state
->rxbuffer
[6] & 0x10) == 0) ? 1 : 0;
873 state
->decode_strength
= state
->rxbuffer
[5] << 8;
874 state
->decode_snr
= state
->rxbuffer
[2] << 8 | state
->rxbuffer
[3];
875 } else if ((state
->dst_type
== DST_TYPE_IS_TERR
) || (state
->dst_type
== DST_TYPE_IS_CABLE
)) {
876 state
->decode_lock
= (state
->rxbuffer
[1]) ? 1 : 0;
877 state
->decode_strength
= state
->rxbuffer
[4] << 8;
878 state
->decode_snr
= state
->rxbuffer
[3] << 8;
880 state
->cur_jiff
= jiffies
;
885 static int dst_tone_power_cmd(struct dst_state
* state
)
887 u8 paket
[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
889 if (state
->dst_type
== DST_TYPE_IS_TERR
)
892 if (state
->voltage
== SEC_VOLTAGE_OFF
)
897 if (state
->tone
== SEC_TONE_ON
)
901 if (state
->minicmd
== SEC_MINI_A
)
906 paket
[7] = dst_check_sum (paket
, 7);
907 dst_command(state
, paket
, 8);
911 static int dst_get_tuna(struct dst_state
* state
)
915 if ((state
->diseq_flags
& ATTEMPT_TUNE
) == 0)
918 state
->diseq_flags
&= ~(HAS_LOCK
);
919 if (!dst_wait_dst_ready(state
, NO_DELAY
))
924 if (state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) {
925 /* how to get variable length reply ???? */
926 retval
= read_dst(state
, state
->rx_tuna
, 10);
928 retval
= read_dst(state
, &state
->rx_tuna
[2], FIXED_COMM
);
932 dprintk("%s: read not successful\n", __FUNCTION__
);
936 if (state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) {
937 if (state
->rx_tuna
[9] != dst_check_sum(&state
->rx_tuna
[0], 9)) {
938 dprintk("%s: checksum failure?\n", __FUNCTION__
);
942 if (state
->rx_tuna
[9] != dst_check_sum(&state
->rx_tuna
[2], 7)) {
943 dprintk("%s: checksum failure?\n", __FUNCTION__
);
947 if (state
->rx_tuna
[2] == 0 && state
->rx_tuna
[3] == 0)
949 state
->decode_freq
= ((state
->rx_tuna
[2] & 0x7f) << 8) + state
->rx_tuna
[3];
951 state
->decode_lock
= 1;
953 dst->decode_n1 = (dst->rx_tuna[4] << 8) +
956 dst->decode_n2 = (dst->rx_tuna[8] << 8) +
959 state
->diseq_flags
|= HAS_LOCK
;
960 /* dst->cur_jiff = jiffies; */
964 static int dst_set_voltage(struct dvb_frontend
* fe
, fe_sec_voltage_t voltage
);
966 static int dst_write_tuna(struct dvb_frontend
* fe
)
968 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
972 dprintk("%s: type_flags 0x%x \n", __FUNCTION__
, state
->type_flags
);
973 state
->decode_freq
= 0;
974 state
->decode_lock
= state
->decode_strength
= state
->decode_snr
= 0;
975 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
976 if (!(state
->diseq_flags
& HAS_POWER
))
977 dst_set_voltage(fe
, SEC_VOLTAGE_13
);
979 state
->diseq_flags
&= ~(HAS_LOCK
| ATTEMPT_TUNE
);
981 if ((dst_comm_init(state
)) < 0) {
982 dprintk("%s: DST Communication initialization failed.\n", __FUNCTION__
);
986 if (state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) {
987 state
->tx_tuna
[9] = dst_check_sum(&state
->tx_tuna
[0], 9);
988 retval
= write_dst(state
, &state
->tx_tuna
[0], 10);
991 state
->tx_tuna
[9] = dst_check_sum(&state
->tx_tuna
[2], 7);
992 retval
= write_dst(state
, &state
->tx_tuna
[2], FIXED_COMM
);
995 dst_pio_disable(state
);
996 dprintk("%s: write not successful\n", __FUNCTION__
);
1000 if ((dst_pio_disable(state
)) < 0) {
1001 dprintk("%s: DST PIO disable failed !\n", __FUNCTION__
);
1005 if ((read_dst(state
, &reply
, GET_ACK
) < 0)) {
1006 dprintk("%s: read verify not successful.\n", __FUNCTION__
);
1010 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__
, reply
);
1013 state
->diseq_flags
|= ATTEMPT_TUNE
;
1015 return dst_get_tuna(state
);
1019 * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
1020 * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
1021 * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
1022 * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
1023 * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
1024 * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
1025 * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
1026 * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
1027 * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
1028 * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
1029 * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
1032 static int dst_set_diseqc(struct dvb_frontend
* fe
, struct dvb_diseqc_master_cmd
* cmd
)
1034 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
1035 u8 paket
[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
1037 if (state
->dst_type
== DST_TYPE_IS_TERR
)
1040 if (cmd
->msg_len
== 0 || cmd
->msg_len
> 4)
1042 memcpy(&paket
[3], cmd
->msg
, cmd
->msg_len
);
1043 paket
[7] = dst_check_sum(&paket
[0], 7);
1044 dst_command(state
, paket
, 8);
1048 static int dst_set_voltage(struct dvb_frontend
* fe
, fe_sec_voltage_t voltage
)
1052 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
1054 state
->voltage
= voltage
;
1056 if (state
->dst_type
== DST_TYPE_IS_TERR
)
1060 val
= &state
->tx_tuna
[0];
1063 case SEC_VOLTAGE_13
:
1064 if ((state
->diseq_flags
& HAS_POWER
) == 0)
1066 state
->diseq_flags
|= HAS_POWER
;
1069 case SEC_VOLTAGE_18
:
1070 if ((state
->diseq_flags
& HAS_POWER
) == 0)
1072 state
->diseq_flags
|= HAS_POWER
;
1076 case SEC_VOLTAGE_OFF
:
1078 state
->diseq_flags
&= ~(HAS_POWER
| HAS_LOCK
| ATTEMPT_TUNE
);
1085 dst_tone_power_cmd(state
);
1090 static int dst_set_tone(struct dvb_frontend
* fe
, fe_sec_tone_mode_t tone
)
1093 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
1097 if (state
->dst_type
== DST_TYPE_IS_TERR
)
1100 val
= &state
->tx_tuna
[0];
1115 dst_tone_power_cmd(state
);
1120 static int dst_init(struct dvb_frontend
* fe
)
1122 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
1123 static u8 ini_satci_tuna
[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 };
1124 static u8 ini_satfta_tuna
[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 };
1125 static u8 ini_tvfta_tuna
[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1126 static u8 ini_tvci_tuna
[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1127 static u8 ini_cabfta_tuna
[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1128 static u8 ini_cabci_tuna
[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1129 state
->inversion
= INVERSION_ON
;
1130 state
->voltage
= SEC_VOLTAGE_13
;
1131 state
->tone
= SEC_TONE_OFF
;
1132 state
->symbol_rate
= 29473000;
1133 state
->fec
= FEC_AUTO
;
1134 state
->diseq_flags
= 0;
1136 state
->bandwidth
= BANDWIDTH_7_MHZ
;
1137 state
->cur_jiff
= jiffies
;
1138 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
1139 state
->frequency
= 950000;
1140 memcpy(state
->tx_tuna
, ((state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) ? ini_satci_tuna
: ini_satfta_tuna
), sizeof(ini_satfta_tuna
));
1141 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
1142 state
->frequency
= 137000000;
1143 memcpy(state
->tx_tuna
, ((state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) ? ini_tvci_tuna
: ini_tvfta_tuna
), sizeof(ini_tvfta_tuna
));
1144 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
1145 state
->frequency
= 51000000;
1146 memcpy(state
->tx_tuna
, ((state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) ? ini_cabci_tuna
: ini_cabfta_tuna
), sizeof(ini_cabfta_tuna
));
1152 static int dst_read_status(struct dvb_frontend
* fe
, fe_status_t
* status
)
1154 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
1157 if (state
->diseq_flags
& HAS_LOCK
) {
1158 dst_get_signal(state
);
1159 if (state
->decode_lock
)
1160 *status
|= FE_HAS_LOCK
| FE_HAS_SIGNAL
| FE_HAS_CARRIER
| FE_HAS_SYNC
| FE_HAS_VITERBI
;
1166 static int dst_read_signal_strength(struct dvb_frontend
* fe
, u16
* strength
)
1168 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
1170 dst_get_signal(state
);
1171 *strength
= state
->decode_strength
;
1176 static int dst_read_snr(struct dvb_frontend
* fe
, u16
* snr
)
1178 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
1180 dst_get_signal(state
);
1181 *snr
= state
->decode_snr
;
1186 static int dst_set_frontend(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*p
)
1188 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
1190 dst_set_freq(state
, p
->frequency
);
1192 dprintk("Set Frequency = [%d]\n", p
->frequency
);
1194 dst_set_inversion(state
, p
->inversion
);
1195 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
1196 dst_set_fec(state
, p
->u
.qpsk
.fec_inner
);
1197 dst_set_symbolrate(state
, p
->u
.qpsk
.symbol_rate
);
1199 dprintk("Set Symbolrate = [%d]\n", p
->u
.qpsk
.symbol_rate
);
1201 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
1202 dst_set_bandwidth(state
, p
->u
.ofdm
.bandwidth
);
1203 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
1204 dst_set_fec(state
, p
->u
.qam
.fec_inner
);
1205 dst_set_symbolrate(state
, p
->u
.qam
.symbol_rate
);
1212 static int dst_get_frontend(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*p
)
1214 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
1216 p
->frequency
= state
->decode_freq
;
1217 p
->inversion
= state
->inversion
;
1218 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
1219 p
->u
.qpsk
.symbol_rate
= state
->symbol_rate
;
1220 p
->u
.qpsk
.fec_inner
= dst_get_fec(state
);
1221 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
1222 p
->u
.ofdm
.bandwidth
= state
->bandwidth
;
1223 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
1224 p
->u
.qam
.symbol_rate
= state
->symbol_rate
;
1225 p
->u
.qam
.fec_inner
= dst_get_fec(state
);
1226 p
->u
.qam
.modulation
= QAM_AUTO
;
1232 static void dst_release(struct dvb_frontend
* fe
)
1234 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
1238 static struct dvb_frontend_ops dst_dvbt_ops
;
1239 static struct dvb_frontend_ops dst_dvbs_ops
;
1240 static struct dvb_frontend_ops dst_dvbc_ops
;
1242 struct dst_state
* dst_attach(struct dst_state
*state
, struct dvb_adapter
*dvb_adapter
)
1245 /* check if the ASIC is there */
1246 if (dst_probe(state
) < 0) {
1252 /* determine settings based on type */
1253 switch (state
->dst_type
) {
1254 case DST_TYPE_IS_TERR
:
1255 memcpy(&state
->ops
, &dst_dvbt_ops
, sizeof(struct dvb_frontend_ops
));
1258 case DST_TYPE_IS_CABLE
:
1259 memcpy(&state
->ops
, &dst_dvbc_ops
, sizeof(struct dvb_frontend_ops
));
1262 case DST_TYPE_IS_SAT
:
1263 memcpy(&state
->ops
, &dst_dvbs_ops
, sizeof(struct dvb_frontend_ops
));
1267 printk("%s: unknown DST type. please report to the LinuxTV.org DVB mailinglist.\n", __FUNCTION__
);
1274 /* create dvb_frontend */
1275 state
->frontend
.ops
= &state
->ops
;
1276 state
->frontend
.demodulator_priv
= state
;
1278 return state
; /* Manu (DST is a card not a frontend) */
1281 EXPORT_SYMBOL(dst_attach
);
1283 static struct dvb_frontend_ops dst_dvbt_ops
= {
1286 .name
= "DST DVB-T",
1288 .frequency_min
= 137000000,
1289 .frequency_max
= 858000000,
1290 .frequency_stepsize
= 166667,
1291 .caps
= FE_CAN_FEC_AUTO
| FE_CAN_QAM_AUTO
| FE_CAN_TRANSMISSION_MODE_AUTO
| FE_CAN_GUARD_INTERVAL_AUTO
1294 .release
= dst_release
,
1298 .set_frontend
= dst_set_frontend
,
1299 .get_frontend
= dst_get_frontend
,
1301 .read_status
= dst_read_status
,
1302 .read_signal_strength
= dst_read_signal_strength
,
1303 .read_snr
= dst_read_snr
,
1306 static struct dvb_frontend_ops dst_dvbs_ops
= {
1309 .name
= "DST DVB-S",
1311 .frequency_min
= 950000,
1312 .frequency_max
= 2150000,
1313 .frequency_stepsize
= 1000, /* kHz for QPSK frontends */
1314 .frequency_tolerance
= 29500,
1315 .symbol_rate_min
= 1000000,
1316 .symbol_rate_max
= 45000000,
1317 /* . symbol_rate_tolerance = ???,*/
1318 .caps
= FE_CAN_FEC_AUTO
| FE_CAN_QPSK
1321 .release
= dst_release
,
1325 .set_frontend
= dst_set_frontend
,
1326 .get_frontend
= dst_get_frontend
,
1328 .read_status
= dst_read_status
,
1329 .read_signal_strength
= dst_read_signal_strength
,
1330 .read_snr
= dst_read_snr
,
1332 .diseqc_send_burst
= dst_set_tone
,
1333 .diseqc_send_master_cmd
= dst_set_diseqc
,
1334 .set_voltage
= dst_set_voltage
,
1335 .set_tone
= dst_set_tone
,
1338 static struct dvb_frontend_ops dst_dvbc_ops
= {
1341 .name
= "DST DVB-C",
1343 .frequency_stepsize
= 62500,
1344 .frequency_min
= 51000000,
1345 .frequency_max
= 858000000,
1346 .symbol_rate_min
= 1000000,
1347 .symbol_rate_max
= 45000000,
1348 /* . symbol_rate_tolerance = ???,*/
1349 .caps
= FE_CAN_FEC_AUTO
| FE_CAN_QAM_AUTO
1352 .release
= dst_release
,
1356 .set_frontend
= dst_set_frontend
,
1357 .get_frontend
= dst_get_frontend
,
1359 .read_status
= dst_read_status
,
1360 .read_signal_strength
= dst_read_signal_strength
,
1361 .read_snr
= dst_read_snr
,
1365 MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
1366 MODULE_AUTHOR("Jamie Honan, Manu Abraham");
1367 MODULE_LICENSE("GPL");