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 addons)");
49 #define dprintk if (debug) printk
52 #define ATTEMPT_TUNE 2
55 static void dst_packsize(struct dst_state
* state
, int psize
)
57 union dst_gpio_packet bits
;
60 bt878_device_control(state
->bt
, DST_IG_TS
, &bits
);
63 int dst_gpio_outb(struct dst_state
* state
, u32 mask
, u32 enbb
, u32 outhigh
, int delay
)
65 union dst_gpio_packet enb
;
66 union dst_gpio_packet bits
;
70 enb
.enb
.enable
= enbb
;
72 dprintk("%s: mask=[%04x], enbb=[%04x], outhigh=[%04x]\n", __FUNCTION__
, mask
, enbb
, outhigh
);
74 if ((err
= bt878_device_control(state
->bt
, DST_IG_ENABLE
, &enb
)) < 0) {
75 dprintk("%s: dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)\n", __FUNCTION__
, err
, mask
, enbb
);
79 /* because complete disabling means no output, no need to do output packet */
86 bits
.outp
.mask
= enbb
;
87 bits
.outp
.highvals
= outhigh
;
89 if ((err
= bt878_device_control(state
->bt
, DST_IG_WRITE
, &bits
)) < 0) {
90 dprintk("%s: dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)\n", __FUNCTION__
, err
, enbb
, outhigh
);
95 EXPORT_SYMBOL(dst_gpio_outb
);
97 int dst_gpio_inb(struct dst_state
*state
, u8
* result
)
99 union dst_gpio_packet rd_packet
;
104 if ((err
= bt878_device_control(state
->bt
, DST_IG_READ
, &rd_packet
)) < 0) {
105 dprintk("%s: dst_gpio_inb error (err == %i)\n", __FUNCTION__
, err
);
109 *result
= (u8
) rd_packet
.rd
.value
;
112 EXPORT_SYMBOL(dst_gpio_inb
);
114 int rdc_reset_state(struct dst_state
*state
)
117 dprintk("%s: Resetting state machine\n", __FUNCTION__
);
119 if (dst_gpio_outb(state
, RDC_8820_INT
, RDC_8820_INT
, 0, NO_DELAY
) < 0) {
120 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
126 if (dst_gpio_outb(state
, RDC_8820_INT
, RDC_8820_INT
, RDC_8820_INT
, NO_DELAY
) < 0) {
127 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
134 EXPORT_SYMBOL(rdc_reset_state
);
136 int rdc_8820_reset(struct dst_state
*state
)
139 dprintk("%s: Resetting DST\n", __FUNCTION__
);
141 if (dst_gpio_outb(state
, RDC_8820_RESET
, RDC_8820_RESET
, 0, NO_DELAY
) < 0) {
142 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
146 if (dst_gpio_outb(state
, RDC_8820_RESET
, RDC_8820_RESET
, RDC_8820_RESET
, DELAY
) < 0) {
147 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
153 EXPORT_SYMBOL(rdc_8820_reset
);
155 int dst_pio_enable(struct dst_state
*state
)
157 if (dst_gpio_outb(state
, ~0, RDC_8820_PIO_0_ENABLE
, 0, NO_DELAY
) < 0) {
158 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
164 EXPORT_SYMBOL(dst_pio_enable
);
166 int dst_pio_disable(struct dst_state
*state
)
168 if (dst_gpio_outb(state
, ~0, RDC_8820_PIO_0_DISABLE
, RDC_8820_PIO_0_DISABLE
, NO_DELAY
) < 0) {
169 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__
);
172 if (state
->type_flags
& DST_TYPE_HAS_FW_1
)
177 EXPORT_SYMBOL(dst_pio_disable
);
179 int dst_wait_dst_ready(struct dst_state
*state
, u8 delay_mode
)
184 for (i
= 0; i
< 200; i
++) {
185 if (dst_gpio_inb(state
, &reply
) < 0) {
186 dprintk("%s: dst_gpio_inb ERROR !\n", __FUNCTION__
);
190 if ((reply
& RDC_8820_PIO_0_ENABLE
) == 0) {
192 dprintk("%s: dst wait ready after %d\n", __FUNCTION__
, i
);
198 dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__
, i
);
202 EXPORT_SYMBOL(dst_wait_dst_ready
);
204 int dst_error_recovery(struct dst_state
*state
)
206 dprintk("%s: Trying to return from previous errors...\n", __FUNCTION__
);
207 dst_pio_disable(state
);
209 dst_pio_enable(state
);
214 EXPORT_SYMBOL(dst_error_recovery
);
216 int dst_error_bailout(struct dst_state
*state
)
218 dprintk("%s: Trying to bailout from previous error...\n", __FUNCTION__
);
219 rdc_8820_reset(state
);
220 dst_pio_disable(state
);
225 EXPORT_SYMBOL(dst_error_bailout
);
228 int dst_comm_init(struct dst_state
* state
)
231 dprintk ("%s: Initializing DST..\n", __FUNCTION__
);
232 if ((dst_pio_enable(state
)) < 0) {
233 dprintk("%s: PIO Enable Failed.\n", __FUNCTION__
);
236 if ((rdc_reset_state(state
)) < 0) {
237 dprintk("%s: RDC 8820 State RESET Failed.\n", __FUNCTION__
);
240 if (state
->type_flags
& DST_TYPE_HAS_FW_1
)
247 EXPORT_SYMBOL(dst_comm_init
);
250 int write_dst(struct dst_state
*state
, u8
*data
, u8 len
)
252 struct i2c_msg msg
= {
253 .addr
= state
->config
->demod_address
,.flags
= 0,.buf
= data
,.len
= len
258 if (debug
&& (verbose
> 4)) {
261 dprintk("%s writing [ ", __FUNCTION__
);
262 for (i
= 0; i
< len
; i
++)
263 dprintk("%02x ", data
[i
]);
267 for (cnt
= 0; cnt
< 2; cnt
++) {
268 if ((err
= i2c_transfer(state
->i2c
, &msg
, 1)) < 0) {
269 dprintk("%s: _write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__
, err
, len
, data
[0]);
270 dst_error_recovery(state
);
278 printk("%s: RDC 8820 RESET...\n", __FUNCTION__
);
279 dst_error_bailout(state
);
286 EXPORT_SYMBOL(write_dst
);
288 int read_dst(struct dst_state
*state
, u8
* ret
, u8 len
)
290 struct i2c_msg msg
= {.addr
= state
->config
->demod_address
,.flags
= I2C_M_RD
,.buf
= ret
,.len
= len
};
294 for (cnt
= 0; cnt
< 2; cnt
++) {
295 if ((err
= i2c_transfer(state
->i2c
, &msg
, 1)) < 0) {
297 dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__
, err
, len
, ret
[0]);
298 dst_error_recovery(state
);
306 printk("%s: RDC 8820 RESET...\n", __FUNCTION__
);
307 dst_error_bailout(state
);
311 if (debug
&& (verbose
> 4)) {
312 dprintk("%s reply is 0x%x\n", __FUNCTION__
, ret
[0]);
313 for (err
= 1; err
< len
; err
++)
314 dprintk(" 0x%x", ret
[err
]);
321 EXPORT_SYMBOL(read_dst
);
323 static int dst_set_polarization(struct dst_state
*state
)
325 switch (state
->voltage
) {
326 case SEC_VOLTAGE_13
: // vertical
327 printk("%s: Polarization=[Vertical]\n", __FUNCTION__
);
328 state
->tx_tuna
[8] &= ~0x40; //1
331 case SEC_VOLTAGE_18
: // horizontal
332 printk("%s: Polarization=[Horizontal]\n", __FUNCTION__
);
333 state
->tx_tuna
[8] |= 0x40; // 0
336 case SEC_VOLTAGE_OFF
:
344 static int dst_set_freq(struct dst_state
*state
, u32 freq
)
346 state
->frequency
= freq
;
348 dprintk("%s: set Frequency %u\n", __FUNCTION__
, freq
);
350 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
352 if (freq
< 950 || freq
> 2150)
355 state
->tx_tuna
[2] = (freq
>> 8);
356 state
->tx_tuna
[3] = (u8
) freq
;
357 state
->tx_tuna
[4] = 0x01;
358 state
->tx_tuna
[8] &= ~0x04;
359 if (state
->type_flags
& DST_TYPE_HAS_OBS_REGS
) {
361 state
->tx_tuna
[8] |= 0x04;
364 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
366 if (freq
< 137000 || freq
> 858000)
369 state
->tx_tuna
[2] = (freq
>> 16) & 0xff;
370 state
->tx_tuna
[3] = (freq
>> 8) & 0xff;
371 state
->tx_tuna
[4] = (u8
) freq
;
373 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
374 state
->tx_tuna
[2] = (freq
>> 16) & 0xff;
375 state
->tx_tuna
[3] = (freq
>> 8) & 0xff;
376 state
->tx_tuna
[4] = (u8
) freq
;
383 static int dst_set_bandwidth(struct dst_state
* state
, fe_bandwidth_t bandwidth
)
385 state
->bandwidth
= bandwidth
;
387 if (state
->dst_type
!= DST_TYPE_IS_TERR
)
391 case BANDWIDTH_6_MHZ
:
392 if (state
->dst_hw_cap
& DST_TYPE_HAS_CA
)
393 state
->tx_tuna
[7] = 0x06;
395 state
->tx_tuna
[6] = 0x06;
396 state
->tx_tuna
[7] = 0x00;
400 case BANDWIDTH_7_MHZ
:
401 if (state
->dst_hw_cap
& DST_TYPE_HAS_CA
)
402 state
->tx_tuna
[7] = 0x07;
404 state
->tx_tuna
[6] = 0x07;
405 state
->tx_tuna
[7] = 0x00;
409 case BANDWIDTH_8_MHZ
:
410 if (state
->dst_hw_cap
& DST_TYPE_HAS_CA
)
411 state
->tx_tuna
[7] = 0x08;
413 state
->tx_tuna
[6] = 0x08;
414 state
->tx_tuna
[7] = 0x00;
424 static int dst_set_inversion(struct dst_state
* state
, fe_spectral_inversion_t inversion
)
426 state
->inversion
= inversion
;
428 case INVERSION_OFF
: // Inversion = Normal
429 state
->tx_tuna
[8] &= ~0x80;
433 state
->tx_tuna
[8] |= 0x80;
441 static int dst_set_fec(struct dst_state
* state
, fe_code_rate_t fec
)
447 static fe_code_rate_t
dst_get_fec(struct dst_state
* state
)
452 static int dst_set_symbolrate(struct dst_state
* state
, u32 srate
)
458 state
->symbol_rate
= srate
;
460 if (state
->dst_type
== DST_TYPE_IS_TERR
) {
464 dprintk("%s: set symrate %u\n", __FUNCTION__
, srate
);
466 val
= &state
->tx_tuna
[0];
468 if (state
->type_flags
& DST_TYPE_HAS_SYMDIV
) {
472 symcalc
= (u32
) sval
;
475 dprintk("%s: set symcalc %u\n", __FUNCTION__
, symcalc
);
477 val
[5] = (u8
) (symcalc
>> 12);
478 val
[6] = (u8
) (symcalc
>> 4);
479 val
[7] = (u8
) (symcalc
<< 4);
481 val
[5] = (u8
) (srate
>> 16) & 0x7f;
482 val
[6] = (u8
) (srate
>> 8);
492 static int dst_set_modulation(struct dst_state
*state
, fe_modulation_t modulation
)
494 if (state
->dst_type
!= DST_TYPE_IS_CABLE
)
497 state
->modulation
= modulation
;
498 switch (modulation
) {
500 state
->tx_tuna
[8] = 0x10;
504 state
->tx_tuna
[8] = 0x20;
508 state
->tx_tuna
[8] = 0x40;
512 state
->tx_tuna
[8] = 0x80;
516 state
->tx_tuna
[8] = 0x00;
531 static fe_modulation_t
dst_get_modulation(struct dst_state
*state
)
533 return state
->modulation
;
537 u8
dst_check_sum(u8
* buf
, u32 len
)
543 for (i
= 0; i
< len
; i
++) {
548 EXPORT_SYMBOL(dst_check_sum
);
550 static void dst_type_flags_print(u32 type_flags
)
552 printk("DST type flags :");
553 if (type_flags
& DST_TYPE_HAS_NEWTUNE
)
554 printk(" 0x%x newtuner", DST_TYPE_HAS_NEWTUNE
);
555 if (type_flags
& DST_TYPE_HAS_TS204
)
556 printk(" 0x%x ts204", DST_TYPE_HAS_TS204
);
557 if (type_flags
& DST_TYPE_HAS_SYMDIV
)
558 printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV
);
559 if (type_flags
& DST_TYPE_HAS_FW_1
)
560 printk(" 0x%x firmware version = 1", DST_TYPE_HAS_FW_1
);
561 if (type_flags
& DST_TYPE_HAS_FW_2
)
562 printk(" 0x%x firmware version = 2", DST_TYPE_HAS_FW_2
);
563 if (type_flags
& DST_TYPE_HAS_FW_3
)
564 printk(" 0x%x firmware version = 3", DST_TYPE_HAS_FW_3
);
565 // if ((type_flags & DST_TYPE_HAS_FW_BUILD) && new_fw)
571 static int dst_type_print (u8 type
)
575 case DST_TYPE_IS_SAT
:
579 case DST_TYPE_IS_TERR
:
580 otype
= "terrestrial";
583 case DST_TYPE_IS_CABLE
:
588 printk("%s: invalid dst type %d\n", __FUNCTION__
, type
);
591 printk("DST type : %s\n", otype
);
601 VP-1020 DST-MOT LG(old), TS=188
603 VP-1020 DST-03T LG(new), TS=204
604 VP-1022 DST-03T LG(new), TS=204
605 VP-1025 DST-03T LG(new), TS=204
607 VP-1030 DSTMCI, LG(new), TS=188
608 VP-1032 DSTMCI, LG(new), TS=188
612 VP-2030 DCT-CI, Samsung, TS=204
613 VP-2021 DCT-CI, Unknown, TS=204
614 VP-2031 DCT-CI, Philips, TS=188
615 VP-2040 DCT-CI, Philips, TS=188, with CA daughter board
616 VP-2040 DCT-CI, Philips, TS=204, without CA daughter board
620 VP-3050 DTTNXT TS=188
621 VP-3040 DTT-CI, Philips, TS=188
622 VP-3040 DTT-CI, Philips, TS=204
626 VP-3220 ATSCDI, TS=188
627 VP-3250 ATSCAD, TS=188
631 struct dst_types dst_tlist
[] = {
633 .device_id
= "200103A",
635 .dst_type
= DST_TYPE_IS_SAT
,
636 .type_flags
= DST_TYPE_HAS_SYMDIV
| DST_TYPE_HAS_FW_1
| DST_TYPE_HAS_OBS_REGS
,
641 .device_id
= "DST-020",
643 .dst_type
= DST_TYPE_IS_SAT
,
644 .type_flags
= DST_TYPE_HAS_SYMDIV
| DST_TYPE_HAS_FW_1
,
649 .device_id
= "DST-030",
651 .dst_type
= DST_TYPE_IS_SAT
,
652 .type_flags
= DST_TYPE_HAS_TS204
| DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_1
,
657 .device_id
= "DST-03T",
659 .dst_type
= DST_TYPE_IS_SAT
,
660 .type_flags
= DST_TYPE_HAS_SYMDIV
| DST_TYPE_HAS_TS204
| DST_TYPE_HAS_FW_2
,
661 .dst_feature
= DST_TYPE_HAS_DISEQC3
| DST_TYPE_HAS_DISEQC4
| DST_TYPE_HAS_DISEQC5
662 | DST_TYPE_HAS_MAC
| DST_TYPE_HAS_MOTO
666 .device_id
= "DST-MOT",
668 .dst_type
= DST_TYPE_IS_SAT
,
669 .type_flags
= DST_TYPE_HAS_SYMDIV
| DST_TYPE_HAS_FW_1
,
674 .device_id
= "DST-CI",
676 .dst_type
= DST_TYPE_IS_SAT
,
677 .type_flags
= DST_TYPE_HAS_TS204
| DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_1
,
678 .dst_feature
= DST_TYPE_HAS_CA
679 }, /* An OEM board */
682 .device_id
= "DSTMCI",
684 .dst_type
= DST_TYPE_IS_SAT
,
685 .type_flags
= DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_2
| DST_TYPE_HAS_FW_BUILD
| DST_TYPE_HAS_INC_COUNT
,
686 .dst_feature
= DST_TYPE_HAS_CA
| DST_TYPE_HAS_DISEQC3
| DST_TYPE_HAS_DISEQC4
687 | DST_TYPE_HAS_MOTO
| DST_TYPE_HAS_MAC
691 .device_id
= "DSTFCI",
693 .dst_type
= DST_TYPE_IS_SAT
,
694 .type_flags
= DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_1
,
696 }, /* unknown to vendor */
699 .device_id
= "DCT-CI",
701 .dst_type
= DST_TYPE_IS_CABLE
,
702 .type_flags
= DST_TYPE_HAS_TS204
| DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_1
703 | DST_TYPE_HAS_FW_2
| DST_TYPE_HAS_FW_BUILD
,
704 .dst_feature
= DST_TYPE_HAS_CA
708 .device_id
= "DCTNEW",
710 .dst_type
= DST_TYPE_IS_CABLE
,
711 .type_flags
= DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_FW_3
,
716 .device_id
= "DTT-CI",
718 .dst_type
= DST_TYPE_IS_TERR
,
719 .type_flags
= DST_TYPE_HAS_TS204
| DST_TYPE_HAS_FW_2
| DST_TYPE_HAS_FW_BUILD
,
724 .device_id
= "DTTDIG",
726 .dst_type
= DST_TYPE_IS_TERR
,
727 .type_flags
= DST_TYPE_HAS_FW_2
,
732 .device_id
= "DTTNXT",
734 .dst_type
= DST_TYPE_IS_TERR
,
735 .type_flags
= DST_TYPE_HAS_FW_2
,
736 .dst_feature
= DST_TYPE_HAS_ANALOG
740 .device_id
= "ATSCDI",
742 .dst_type
= DST_TYPE_IS_ATSC
,
743 .type_flags
= DST_TYPE_HAS_FW_2
,
748 .device_id
= "ATSCAD",
750 .dst_type
= DST_TYPE_IS_ATSC
,
751 .type_flags
= DST_TYPE_HAS_FW_2
,
760 static int dst_get_device_id(struct dst_state
*state
)
765 struct dst_types
*p_dst_type
;
767 u32 use_type_flags
= 0;
769 static u8 device_type
[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
771 device_type
[7] = dst_check_sum(device_type
, 7);
773 if (write_dst(state
, device_type
, FIXED_COMM
))
774 return -1; /* Write failed */
776 if ((dst_pio_disable(state
)) < 0)
779 if (read_dst(state
, &reply
, GET_ACK
))
780 return -1; /* Read failure */
783 dprintk("%s: Write not Acknowledged! [Reply=0x%02x]\n", __FUNCTION__
, reply
);
784 return -1; /* Unack'd write */
787 if (!dst_wait_dst_ready(state
, DEVICE_INIT
))
788 return -1; /* DST not ready yet */
790 if (read_dst(state
, state
->rxbuffer
, FIXED_COMM
))
793 dst_pio_disable(state
);
795 if (state
->rxbuffer
[7] != dst_check_sum(state
->rxbuffer
, 7)) {
796 dprintk("%s: Checksum failure! \n", __FUNCTION__
);
797 return -1; /* Checksum failure */
800 state
->rxbuffer
[7] = '\0';
802 for (i
= 0, p_dst_type
= dst_tlist
; i
< ARRAY_SIZE (dst_tlist
); i
++, p_dst_type
++) {
803 if (!strncmp (&state
->rxbuffer
[p_dst_type
->offset
], p_dst_type
->device_id
, strlen (p_dst_type
->device_id
))) {
804 use_type_flags
= p_dst_type
->type_flags
;
805 use_dst_type
= p_dst_type
->dst_type
;
807 /* Card capabilities */
808 state
->dst_hw_cap
= p_dst_type
->dst_feature
;
809 printk ("%s: Recognise [%s]\n", __FUNCTION__
, p_dst_type
->device_id
);
815 if (i
>= sizeof (dst_tlist
) / sizeof (dst_tlist
[0])) {
816 printk("%s: Unable to recognize %s or %s\n", __FUNCTION__
, &state
->rxbuffer
[0], &state
->rxbuffer
[1]);
817 printk("%s: please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__
);
818 use_dst_type
= DST_TYPE_IS_SAT
;
819 use_type_flags
= DST_TYPE_HAS_SYMDIV
;
822 dst_type_print(use_dst_type
);
823 state
->type_flags
= use_type_flags
;
824 state
->dst_type
= use_dst_type
;
825 dst_type_flags_print(state
->type_flags
);
827 if (state
->type_flags
& DST_TYPE_HAS_TS204
) {
828 dst_packsize(state
, 204);
834 static int dst_probe(struct dst_state
*state
)
836 if ((rdc_8820_reset(state
)) < 0) {
837 dprintk("%s: RDC 8820 RESET Failed.\n", __FUNCTION__
);
840 if (dst_addons
& DST_TYPE_HAS_CA
)
845 if ((dst_comm_init(state
)) < 0) {
846 dprintk("%s: DST Initialization Failed.\n", __FUNCTION__
);
850 if (dst_get_device_id(state
) < 0) {
851 dprintk("%s: unknown device.\n", __FUNCTION__
);
858 int dst_command(struct dst_state
* state
, u8
* data
, u8 len
)
861 if ((dst_comm_init(state
)) < 0) {
862 dprintk("%s: DST Communication Initialization Failed.\n", __FUNCTION__
);
866 if (write_dst(state
, data
, len
)) {
868 dprintk("%s: Tring to recover.. \n", __FUNCTION__
);
869 if ((dst_error_recovery(state
)) < 0) {
870 dprintk("%s: Recovery Failed.\n", __FUNCTION__
);
875 if ((dst_pio_disable(state
)) < 0) {
876 dprintk("%s: PIO Disable Failed.\n", __FUNCTION__
);
879 if (state
->type_flags
& DST_TYPE_HAS_FW_1
)
882 if (read_dst(state
, &reply
, GET_ACK
)) {
884 dprintk("%s: Trying to recover.. \n", __FUNCTION__
);
885 if ((dst_error_recovery(state
)) < 0) {
886 dprintk("%s: Recovery Failed.\n", __FUNCTION__
);
893 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__
, reply
);
896 if (len
>= 2 && data
[0] == 0 && (data
[1] == 1 || data
[1] == 3))
900 if (state
->type_flags
& DST_TYPE_HAS_FW_1
)
905 if (!dst_wait_dst_ready(state
, NO_DELAY
))
908 if (read_dst(state
, state
->rxbuffer
, FIXED_COMM
)) {
910 dprintk("%s: Trying to recover.. \n", __FUNCTION__
);
911 if ((dst_error_recovery(state
)) < 0) {
912 dprintk("%s: Recovery failed.\n", __FUNCTION__
);
918 if (state
->rxbuffer
[7] != dst_check_sum(state
->rxbuffer
, 7)) {
919 dprintk("%s: checksum failure\n", __FUNCTION__
);
925 EXPORT_SYMBOL(dst_command
);
927 static int dst_get_signal(struct dst_state
* state
)
930 u8 get_signal
[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
931 dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__
);
932 if ((state
->diseq_flags
& ATTEMPT_TUNE
) == 0) {
933 state
->decode_lock
= state
->decode_strength
= state
->decode_snr
= 0;
936 if (0 == (state
->diseq_flags
& HAS_LOCK
)) {
937 state
->decode_lock
= state
->decode_strength
= state
->decode_snr
= 0;
940 if (time_after_eq(jiffies
, state
->cur_jiff
+ (HZ
/ 5))) {
941 retval
= dst_command(state
, get_signal
, 8);
944 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
945 state
->decode_lock
= ((state
->rxbuffer
[6] & 0x10) == 0) ? 1 : 0;
946 state
->decode_strength
= state
->rxbuffer
[5] << 8;
947 state
->decode_snr
= state
->rxbuffer
[2] << 8 | state
->rxbuffer
[3];
948 } else if ((state
->dst_type
== DST_TYPE_IS_TERR
) || (state
->dst_type
== DST_TYPE_IS_CABLE
)) {
949 state
->decode_lock
= (state
->rxbuffer
[1]) ? 1 : 0;
950 state
->decode_strength
= state
->rxbuffer
[4] << 8;
951 state
->decode_snr
= state
->rxbuffer
[3] << 8;
953 state
->cur_jiff
= jiffies
;
958 static int dst_tone_power_cmd(struct dst_state
* state
)
960 u8 paket
[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
962 if (state
->dst_type
== DST_TYPE_IS_TERR
)
965 paket
[4] = state
->tx_tuna
[4];
966 paket
[2] = state
->tx_tuna
[2];
967 paket
[3] = state
->tx_tuna
[3];
968 paket
[7] = dst_check_sum (paket
, 7);
969 dst_command(state
, paket
, 8);
974 static int dst_get_tuna(struct dst_state
* state
)
978 if ((state
->diseq_flags
& ATTEMPT_TUNE
) == 0)
981 state
->diseq_flags
&= ~(HAS_LOCK
);
982 if (!dst_wait_dst_ready(state
, NO_DELAY
))
985 if (state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) {
986 /* how to get variable length reply ???? */
987 retval
= read_dst(state
, state
->rx_tuna
, 10);
989 retval
= read_dst(state
, &state
->rx_tuna
[2], FIXED_COMM
);
993 dprintk("%s: read not successful\n", __FUNCTION__
);
997 if (state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) {
998 if (state
->rx_tuna
[9] != dst_check_sum(&state
->rx_tuna
[0], 9)) {
999 dprintk("%s: checksum failure?\n", __FUNCTION__
);
1003 if (state
->rx_tuna
[9] != dst_check_sum(&state
->rx_tuna
[2], 7)) {
1004 dprintk("%s: checksum failure?\n", __FUNCTION__
);
1008 if (state
->rx_tuna
[2] == 0 && state
->rx_tuna
[3] == 0)
1010 state
->decode_freq
= ((state
->rx_tuna
[2] & 0x7f) << 8) + state
->rx_tuna
[3];
1012 state
->decode_lock
= 1;
1013 state
->diseq_flags
|= HAS_LOCK
;
1018 static int dst_set_voltage(struct dvb_frontend
* fe
, fe_sec_voltage_t voltage
);
1020 static int dst_write_tuna(struct dvb_frontend
* fe
)
1022 struct dst_state
* state
= fe
->demodulator_priv
;
1027 dprintk("%s: type_flags 0x%x \n", __FUNCTION__
, state
->type_flags
);
1029 state
->decode_freq
= 0;
1030 state
->decode_lock
= state
->decode_strength
= state
->decode_snr
= 0;
1031 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
1032 if (!(state
->diseq_flags
& HAS_POWER
))
1033 dst_set_voltage(fe
, SEC_VOLTAGE_13
);
1035 state
->diseq_flags
&= ~(HAS_LOCK
| ATTEMPT_TUNE
);
1037 if ((dst_comm_init(state
)) < 0) {
1038 dprintk("%s: DST Communication initialization failed.\n", __FUNCTION__
);
1042 if (state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) {
1043 state
->tx_tuna
[9] = dst_check_sum(&state
->tx_tuna
[0], 9);
1044 retval
= write_dst(state
, &state
->tx_tuna
[0], 10);
1047 state
->tx_tuna
[9] = dst_check_sum(&state
->tx_tuna
[2], 7);
1048 retval
= write_dst(state
, &state
->tx_tuna
[2], FIXED_COMM
);
1051 dst_pio_disable(state
);
1052 dprintk("%s: write not successful\n", __FUNCTION__
);
1056 if ((dst_pio_disable(state
)) < 0) {
1057 dprintk("%s: DST PIO disable failed !\n", __FUNCTION__
);
1061 if ((read_dst(state
, &reply
, GET_ACK
) < 0)) {
1062 dprintk("%s: read verify not successful.\n", __FUNCTION__
);
1066 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__
, reply
);
1069 state
->diseq_flags
|= ATTEMPT_TUNE
;
1071 return dst_get_tuna(state
);
1075 * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
1076 * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
1077 * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
1078 * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
1079 * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
1080 * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
1081 * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
1082 * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
1083 * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
1084 * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
1085 * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
1088 static int dst_set_diseqc(struct dvb_frontend
* fe
, struct dvb_diseqc_master_cmd
* cmd
)
1090 struct dst_state
* state
= fe
->demodulator_priv
;
1091 u8 paket
[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
1093 if (state
->dst_type
!= DST_TYPE_IS_SAT
)
1096 if (cmd
->msg_len
== 0 || cmd
->msg_len
> 4)
1098 memcpy(&paket
[3], cmd
->msg
, cmd
->msg_len
);
1099 paket
[7] = dst_check_sum(&paket
[0], 7);
1100 dst_command(state
, paket
, 8);
1104 static int dst_set_voltage(struct dvb_frontend
* fe
, fe_sec_voltage_t voltage
)
1107 struct dst_state
* state
= fe
->demodulator_priv
;
1109 state
->voltage
= voltage
;
1111 if (state
->dst_type
!= DST_TYPE_IS_SAT
)
1116 case SEC_VOLTAGE_13
:
1117 case SEC_VOLTAGE_18
:
1118 if ((state
->diseq_flags
& HAS_POWER
) == 0)
1120 state
->diseq_flags
|= HAS_POWER
;
1121 state
->tx_tuna
[4] = 0x01;
1124 case SEC_VOLTAGE_OFF
:
1126 state
->diseq_flags
&= ~(HAS_POWER
| HAS_LOCK
| ATTEMPT_TUNE
);
1127 state
->tx_tuna
[4] = 0x00;
1134 dst_tone_power_cmd(state
);
1139 static int dst_set_tone(struct dvb_frontend
* fe
, fe_sec_tone_mode_t tone
)
1141 struct dst_state
* state
= fe
->demodulator_priv
;
1145 if (state
->dst_type
!= DST_TYPE_IS_SAT
)
1150 if (state
->type_flags
& DST_TYPE_HAS_OBS_REGS
)
1151 state
->tx_tuna
[2] = 0x00;
1153 state
->tx_tuna
[2] = 0xff;
1158 state
->tx_tuna
[2] = 0x02;
1164 dst_tone_power_cmd(state
);
1169 static int dst_send_burst(struct dvb_frontend
*fe
, fe_sec_mini_cmd_t minicmd
)
1171 struct dst_state
*state
= fe
->demodulator_priv
;
1173 if (state
->dst_type
!= DST_TYPE_IS_SAT
)
1176 state
->minicmd
= minicmd
;
1180 state
->tx_tuna
[3] = 0x02;
1183 state
->tx_tuna
[3] = 0xff;
1186 dst_tone_power_cmd(state
);
1192 static int dst_init(struct dvb_frontend
* fe
)
1194 struct dst_state
* state
= fe
->demodulator_priv
;
1195 static u8 ini_satci_tuna
[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 };
1196 static u8 ini_satfta_tuna
[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 };
1197 static u8 ini_tvfta_tuna
[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1198 static u8 ini_tvci_tuna
[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1199 static u8 ini_cabfta_tuna
[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1200 static u8 ini_cabci_tuna
[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1201 // state->inversion = INVERSION_ON;
1202 state
->inversion
= INVERSION_OFF
;
1203 state
->voltage
= SEC_VOLTAGE_13
;
1204 state
->tone
= SEC_TONE_OFF
;
1205 state
->symbol_rate
= 29473000;
1206 state
->fec
= FEC_AUTO
;
1207 state
->diseq_flags
= 0;
1209 state
->bandwidth
= BANDWIDTH_7_MHZ
;
1210 state
->cur_jiff
= jiffies
;
1211 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
1212 state
->frequency
= 950000;
1213 memcpy(state
->tx_tuna
, ((state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) ? ini_satci_tuna
: ini_satfta_tuna
), sizeof(ini_satfta_tuna
));
1214 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
1215 state
->frequency
= 137000000;
1216 memcpy(state
->tx_tuna
, ((state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) ? ini_tvci_tuna
: ini_tvfta_tuna
), sizeof(ini_tvfta_tuna
));
1217 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
1218 state
->frequency
= 51000000;
1219 memcpy(state
->tx_tuna
, ((state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) ? ini_cabci_tuna
: ini_cabfta_tuna
), sizeof(ini_cabfta_tuna
));
1225 static int dst_read_status(struct dvb_frontend
* fe
, fe_status_t
* status
)
1227 struct dst_state
* state
= fe
->demodulator_priv
;
1230 if (state
->diseq_flags
& HAS_LOCK
) {
1231 // dst_get_signal(state); // don't require(?) to ask MCU
1232 if (state
->decode_lock
)
1233 *status
|= FE_HAS_LOCK
| FE_HAS_SIGNAL
| FE_HAS_CARRIER
| FE_HAS_SYNC
| FE_HAS_VITERBI
;
1239 static int dst_read_signal_strength(struct dvb_frontend
* fe
, u16
* strength
)
1241 struct dst_state
* state
= fe
->demodulator_priv
;
1243 dst_get_signal(state
);
1244 *strength
= state
->decode_strength
;
1249 static int dst_read_snr(struct dvb_frontend
* fe
, u16
* snr
)
1251 struct dst_state
* state
= fe
->demodulator_priv
;
1253 dst_get_signal(state
);
1254 *snr
= state
->decode_snr
;
1259 static int dst_set_frontend(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*p
)
1261 struct dst_state
* state
= fe
->demodulator_priv
;
1263 dst_set_freq(state
, p
->frequency
);
1265 dprintk("Set Frequency=[%d]\n", p
->frequency
);
1267 // dst_set_inversion(state, p->inversion);
1268 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
1269 if (state
->type_flags
& DST_TYPE_HAS_OBS_REGS
)
1270 dst_set_inversion(state
, p
->inversion
);
1272 dst_set_fec(state
, p
->u
.qpsk
.fec_inner
);
1273 dst_set_symbolrate(state
, p
->u
.qpsk
.symbol_rate
);
1274 dst_set_polarization(state
);
1276 dprintk("Set Symbolrate=[%d]\n", p
->u
.qpsk
.symbol_rate
);
1278 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
1279 dst_set_bandwidth(state
, p
->u
.ofdm
.bandwidth
);
1280 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
1281 dst_set_fec(state
, p
->u
.qam
.fec_inner
);
1282 dst_set_symbolrate(state
, p
->u
.qam
.symbol_rate
);
1283 dst_set_modulation(state
, p
->u
.qam
.modulation
);
1290 static int dst_get_frontend(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*p
)
1292 struct dst_state
* state
= fe
->demodulator_priv
;
1294 p
->frequency
= state
->decode_freq
;
1295 // p->inversion = state->inversion;
1296 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
1297 if (state
->type_flags
& DST_TYPE_HAS_OBS_REGS
)
1298 p
->inversion
= state
->inversion
;
1300 p
->u
.qpsk
.symbol_rate
= state
->symbol_rate
;
1301 p
->u
.qpsk
.fec_inner
= dst_get_fec(state
);
1302 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
1303 p
->u
.ofdm
.bandwidth
= state
->bandwidth
;
1304 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
1305 p
->u
.qam
.symbol_rate
= state
->symbol_rate
;
1306 p
->u
.qam
.fec_inner
= dst_get_fec(state
);
1307 // p->u.qam.modulation = QAM_AUTO;
1308 p
->u
.qam
.modulation
= dst_get_modulation(state
);
1314 static void dst_release(struct dvb_frontend
* fe
)
1316 struct dst_state
* state
= fe
->demodulator_priv
;
1320 static struct dvb_frontend_ops dst_dvbt_ops
;
1321 static struct dvb_frontend_ops dst_dvbs_ops
;
1322 static struct dvb_frontend_ops dst_dvbc_ops
;
1324 struct dst_state
* dst_attach(struct dst_state
*state
, struct dvb_adapter
*dvb_adapter
)
1327 /* check if the ASIC is there */
1328 if (dst_probe(state
) < 0) {
1334 /* determine settings based on type */
1335 switch (state
->dst_type
) {
1336 case DST_TYPE_IS_TERR
:
1337 memcpy(&state
->ops
, &dst_dvbt_ops
, sizeof(struct dvb_frontend_ops
));
1340 case DST_TYPE_IS_CABLE
:
1341 memcpy(&state
->ops
, &dst_dvbc_ops
, sizeof(struct dvb_frontend_ops
));
1344 case DST_TYPE_IS_SAT
:
1345 memcpy(&state
->ops
, &dst_dvbs_ops
, sizeof(struct dvb_frontend_ops
));
1349 printk("%s: unknown DST type. please report to the LinuxTV.org DVB mailinglist.\n", __FUNCTION__
);
1356 /* create dvb_frontend */
1357 state
->frontend
.ops
= &state
->ops
;
1358 state
->frontend
.demodulator_priv
= state
;
1360 return state
; /* Manu (DST is a card not a frontend) */
1363 EXPORT_SYMBOL(dst_attach
);
1365 static struct dvb_frontend_ops dst_dvbt_ops
= {
1368 .name
= "DST DVB-T",
1370 .frequency_min
= 137000000,
1371 .frequency_max
= 858000000,
1372 .frequency_stepsize
= 166667,
1373 .caps
= FE_CAN_FEC_AUTO
| FE_CAN_QAM_AUTO
| FE_CAN_TRANSMISSION_MODE_AUTO
| FE_CAN_GUARD_INTERVAL_AUTO
1376 .release
= dst_release
,
1380 .set_frontend
= dst_set_frontend
,
1381 .get_frontend
= dst_get_frontend
,
1383 .read_status
= dst_read_status
,
1384 .read_signal_strength
= dst_read_signal_strength
,
1385 .read_snr
= dst_read_snr
,
1388 static struct dvb_frontend_ops dst_dvbs_ops
= {
1391 .name
= "DST DVB-S",
1393 .frequency_min
= 950000,
1394 .frequency_max
= 2150000,
1395 .frequency_stepsize
= 1000, /* kHz for QPSK frontends */
1396 .frequency_tolerance
= 29500,
1397 .symbol_rate_min
= 1000000,
1398 .symbol_rate_max
= 45000000,
1399 /* . symbol_rate_tolerance = ???,*/
1400 .caps
= FE_CAN_FEC_AUTO
| FE_CAN_QPSK
1403 .release
= dst_release
,
1407 .set_frontend
= dst_set_frontend
,
1408 .get_frontend
= dst_get_frontend
,
1410 .read_status
= dst_read_status
,
1411 .read_signal_strength
= dst_read_signal_strength
,
1412 .read_snr
= dst_read_snr
,
1414 .diseqc_send_burst
= dst_send_burst
,
1415 .diseqc_send_master_cmd
= dst_set_diseqc
,
1416 .set_voltage
= dst_set_voltage
,
1417 .set_tone
= dst_set_tone
,
1420 static struct dvb_frontend_ops dst_dvbc_ops
= {
1423 .name
= "DST DVB-C",
1425 .frequency_stepsize
= 62500,
1426 .frequency_min
= 51000000,
1427 .frequency_max
= 858000000,
1428 .symbol_rate_min
= 1000000,
1429 .symbol_rate_max
= 45000000,
1430 /* . symbol_rate_tolerance = ???,*/
1431 .caps
= FE_CAN_FEC_AUTO
| FE_CAN_QAM_AUTO
1434 .release
= dst_release
,
1438 .set_frontend
= dst_set_frontend
,
1439 .get_frontend
= dst_get_frontend
,
1441 .read_status
= dst_read_status
,
1442 .read_signal_strength
= dst_read_signal_strength
,
1443 .read_snr
= dst_read_snr
,
1447 MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
1448 MODULE_AUTHOR("Jamie Honan, Manu Abraham");
1449 MODULE_LICENSE("GPL");