2 Frontend-driver for TwinHan DST Frontend
4 Copyright (C) 2003 Jamie Honan
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
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"
38 struct i2c_adapter
* i2c
;
42 struct dvb_frontend_ops ops
;
44 /* configuration settings */
45 const struct dst_config
* config
;
47 struct dvb_frontend frontend
;
49 /* private demodulator data */
56 u32 frequency
; /* intermediate frequency in kHz for QPSK */
57 fe_spectral_inversion_t inversion
;
58 u32 symbol_rate
; /* symbol rate in Symbols per second */
60 fe_sec_voltage_t voltage
;
61 fe_sec_tone_mode_t tone
;
66 unsigned long cur_jiff
;
68 fe_bandwidth_t bandwidth
;
71 static unsigned int dst_verbose
= 0;
72 module_param(dst_verbose
, int, 0644);
73 MODULE_PARM_DESC(dst_verbose
, "verbose startup messages, default is 1 (yes)");
74 static unsigned int dst_debug
= 0;
75 module_param(dst_debug
, int, 0644);
76 MODULE_PARM_DESC(dst_debug
, "debug messages, default is 0 (no)");
78 #define dprintk if (dst_debug) printk
80 #define DST_TYPE_IS_SAT 0
81 #define DST_TYPE_IS_TERR 1
82 #define DST_TYPE_IS_CABLE 2
84 #define DST_TYPE_HAS_NEWTUNE 1
85 #define DST_TYPE_HAS_TS204 2
86 #define DST_TYPE_HAS_SYMDIV 4
89 #define ATTEMPT_TUNE 2
92 static void dst_packsize(struct dst_state
* state
, int psize
)
94 union dst_gpio_packet bits
;
97 bt878_device_control(state
->bt
, DST_IG_TS
, &bits
);
100 static int dst_gpio_outb(struct dst_state
* state
, u32 mask
, u32 enbb
, u32 outhigh
)
102 union dst_gpio_packet enb
;
103 union dst_gpio_packet bits
;
107 enb
.enb
.enable
= enbb
;
108 if ((err
= bt878_device_control(state
->bt
, DST_IG_ENABLE
, &enb
)) < 0) {
109 dprintk("%s: dst_gpio_enb error (err == %i, mask == 0x%02x, enb == 0x%02x)\n", __FUNCTION__
, err
, mask
, enbb
);
113 /* because complete disabling means no output, no need to do output packet */
117 bits
.outp
.mask
= enbb
;
118 bits
.outp
.highvals
= outhigh
;
120 if ((err
= bt878_device_control(state
->bt
, DST_IG_WRITE
, &bits
)) < 0) {
121 dprintk("%s: dst_gpio_outb error (err == %i, enbb == 0x%02x, outhigh == 0x%02x)\n", __FUNCTION__
, err
, enbb
, outhigh
);
127 static int dst_gpio_inb(struct dst_state
*state
, u8
* result
)
129 union dst_gpio_packet rd_packet
;
134 if ((err
= bt878_device_control(state
->bt
, DST_IG_READ
, &rd_packet
)) < 0) {
135 dprintk("%s: dst_gpio_inb error (err == %i)\n", __FUNCTION__
, err
);
139 *result
= (u8
) rd_packet
.rd
.value
;
143 #define DST_I2C_ENABLE 1
146 static int dst_reset8820(struct dst_state
*state
)
149 /* pull 8820 gpio pin low, wait, high, wait, then low */
150 // dprintk ("%s: reset 8820\n", __FUNCTION__);
151 retval
= dst_gpio_outb(state
, DST_8820
, DST_8820
, 0);
155 retval
= dst_gpio_outb(state
, DST_8820
, DST_8820
, DST_8820
);
158 /* wait for more feedback on what works here *
160 retval = dst_gpio_outb(dst, DST_8820, DST_8820, 0);
167 static int dst_i2c_enable(struct dst_state
*state
)
170 /* pull I2C enable gpio pin low, wait */
171 // dprintk ("%s: i2c enable\n", __FUNCTION__);
172 retval
= dst_gpio_outb(state
, ~0, DST_I2C_ENABLE
, 0);
175 // dprintk ("%s: i2c enable delay\n", __FUNCTION__);
180 static int dst_i2c_disable(struct dst_state
*state
)
183 /* release I2C enable gpio pin, wait */
184 // dprintk ("%s: i2c disable\n", __FUNCTION__);
185 retval
= dst_gpio_outb(state
, ~0, 0, 0);
188 // dprintk ("%s: i2c disable delay\n", __FUNCTION__);
193 static int dst_wait_dst_ready(struct dst_state
*state
)
198 for (i
= 0; i
< 200; i
++) {
199 retval
= dst_gpio_inb(state
, &reply
);
202 if ((reply
& DST_I2C_ENABLE
) == 0) {
203 dprintk("%s: dst wait ready after %d\n", __FUNCTION__
, i
);
208 dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__
, i
);
212 static int write_dst(struct dst_state
*state
, u8
* data
, u8 len
)
214 struct i2c_msg msg
= {
215 .addr
= state
->config
->demod_address
,.flags
= 0,.buf
= data
,.len
= len
220 if (dst_debug
&& dst_verbose
) {
222 dprintk("%s writing", __FUNCTION__
);
223 for (i
= 0; i
< len
; i
++) {
224 dprintk(" 0x%02x", data
[i
]);
229 for (cnt
= 0; cnt
< 4; cnt
++) {
230 if ((err
= i2c_transfer(state
->i2c
, &msg
, 1)) < 0) {
231 dprintk("%s: write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__
, err
, len
, data
[0]);
232 dst_i2c_disable(state
);
234 dst_i2c_enable(state
);
245 static int read_dst(struct dst_state
*state
, u8
* ret
, u8 len
)
247 struct i2c_msg msg
= {.addr
= state
->config
->demod_address
,.flags
= I2C_M_RD
,.buf
= ret
,.len
= len
};
251 for (cnt
= 0; cnt
< 4; cnt
++) {
252 if ((err
= i2c_transfer(state
->i2c
, &msg
, 1)) < 0) {
253 dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__
, err
, len
, ret
[0]);
254 dst_i2c_disable(state
);
255 dst_i2c_enable(state
);
262 dprintk("%s reply is 0x%x\n", __FUNCTION__
, ret
[0]);
263 if (dst_debug
&& dst_verbose
) {
264 for (err
= 1; err
< len
; err
++)
265 dprintk(" 0x%x", ret
[err
]);
272 static int dst_set_freq(struct dst_state
*state
, u32 freq
)
276 state
->frequency
= freq
;
278 // dprintk("%s: set frequency %u\n", __FUNCTION__, freq);
279 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
281 if (freq
< 950 || freq
> 2150)
283 val
= &state
->tx_tuna
[0];
284 val
[2] = (freq
>> 8) & 0x7f;
290 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
292 if (freq
< 137000 || freq
> 858000)
294 val
= &state
->tx_tuna
[0];
295 val
[2] = (freq
>> 16) & 0xff;
296 val
[3] = (freq
>> 8) & 0xff;
299 switch (state
->bandwidth
) {
300 case BANDWIDTH_6_MHZ
:
304 case BANDWIDTH_7_MHZ
:
309 case BANDWIDTH_8_MHZ
:
316 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
317 /* guess till will get one */
319 val
= &state
->tx_tuna
[0];
320 val
[2] = (freq
>> 16) & 0xff;
321 val
[3] = (freq
>> 8) & 0xff;
328 static int dst_set_bandwidth(struct dst_state
* state
, fe_bandwidth_t bandwidth
)
332 state
->bandwidth
= bandwidth
;
334 if (state
->dst_type
!= DST_TYPE_IS_TERR
)
337 val
= &state
->tx_tuna
[0];
339 case BANDWIDTH_6_MHZ
:
343 case BANDWIDTH_7_MHZ
:
347 case BANDWIDTH_8_MHZ
:
357 static int dst_set_inversion(struct dst_state
* state
, fe_spectral_inversion_t inversion
)
361 state
->inversion
= inversion
;
363 val
= &state
->tx_tuna
[0];
379 static int dst_set_fec(struct dst_state
* state
, fe_code_rate_t fec
)
385 static fe_code_rate_t
dst_get_fec(struct dst_state
* state
)
390 static int dst_set_symbolrate(struct dst_state
* state
, u32 srate
)
396 state
->symbol_rate
= srate
;
398 if (state
->dst_type
== DST_TYPE_IS_TERR
) {
401 // dprintk("%s: set srate %u\n", __FUNCTION__, srate);
403 val
= &state
->tx_tuna
[0];
405 if (state
->type_flags
& DST_TYPE_HAS_SYMDIV
) {
409 symcalc
= (u32
) sval
;
410 // dprintk("%s: set symcalc %u\n", __FUNCTION__, symcalc);
411 val
[5] = (u8
) (symcalc
>> 12);
412 val
[6] = (u8
) (symcalc
>> 4);
413 val
[7] = (u8
) (symcalc
<< 4);
415 val
[5] = (u8
) (srate
>> 16) & 0x7f;
416 val
[6] = (u8
) (srate
>> 8);
425 static u8
dst_check_sum(u8
* buf
, u32 len
)
431 for (i
= 0; i
< len
; i
++) {
444 static struct dst_types dst_tlist
[] = {
445 {"DST-020", 0, DST_TYPE_IS_SAT
, DST_TYPE_HAS_SYMDIV
},
446 {"DST-030", 0, DST_TYPE_IS_SAT
, DST_TYPE_HAS_TS204
| DST_TYPE_HAS_NEWTUNE
},
447 {"DST-03T", 0, DST_TYPE_IS_SAT
, DST_TYPE_HAS_SYMDIV
| DST_TYPE_HAS_TS204
},
448 {"DST-MOT", 0, DST_TYPE_IS_SAT
, DST_TYPE_HAS_SYMDIV
},
449 {"DST-CI", 1, DST_TYPE_IS_SAT
, DST_TYPE_HAS_TS204
| DST_TYPE_HAS_NEWTUNE
},
450 {"DSTMCI", 1, DST_TYPE_IS_SAT
, DST_TYPE_HAS_NEWTUNE
},
451 {"DSTFCI", 1, DST_TYPE_IS_SAT
, DST_TYPE_HAS_NEWTUNE
},
452 {"DCTNEW", 1, DST_TYPE_IS_CABLE
, DST_TYPE_HAS_NEWTUNE
},
453 {"DCT-CI", 1, DST_TYPE_IS_CABLE
, DST_TYPE_HAS_NEWTUNE
| DST_TYPE_HAS_TS204
},
454 {"DTTDIG", 1, DST_TYPE_IS_TERR
, 0}
457 /* DCTNEW and DCT-CI are guesses */
459 static void dst_type_flags_print(u32 type_flags
)
461 printk("DST type flags :");
462 if (type_flags
& DST_TYPE_HAS_NEWTUNE
)
463 printk(" 0x%x newtuner", DST_TYPE_HAS_NEWTUNE
);
464 if (type_flags
& DST_TYPE_HAS_TS204
)
465 printk(" 0x%x ts204", DST_TYPE_HAS_TS204
);
466 if (type_flags
& DST_TYPE_HAS_SYMDIV
)
467 printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV
);
471 static int dst_type_print(u8 type
)
475 case DST_TYPE_IS_SAT
:
478 case DST_TYPE_IS_TERR
:
479 otype
= "terrestrial";
481 case DST_TYPE_IS_CABLE
:
485 printk("%s: invalid dst type %d\n", __FUNCTION__
, type
);
488 printk("DST type : %s\n", otype
);
492 static int dst_check_ci(struct dst_state
*state
)
498 struct dst_types
*dsp
;
502 memset(txbuf
, 0, sizeof(txbuf
));
504 txbuf
[7] = dst_check_sum(txbuf
, 7);
506 dst_i2c_enable(state
);
507 dst_reset8820(state
);
508 retval
= write_dst(state
, txbuf
, 8);
510 dst_i2c_disable(state
);
511 dprintk("%s: write not successful, maybe no card?\n", __FUNCTION__
);
515 retval
= read_dst(state
, rxbuf
, 1);
516 dst_i2c_disable(state
);
518 dprintk("%s: read not successful, maybe no card?\n", __FUNCTION__
);
521 if (rxbuf
[0] != 0xff) {
522 dprintk("%s: write reply not 0xff, not ci (%02x)\n", __FUNCTION__
, rxbuf
[0]);
525 if (!dst_wait_dst_ready(state
))
527 // dst_i2c_enable(i2c); Dimitri
528 retval
= read_dst(state
, rxbuf
, 8);
529 dst_i2c_disable(state
);
531 dprintk("%s: read not successful\n", __FUNCTION__
);
534 if (rxbuf
[7] != dst_check_sum(rxbuf
, 7)) {
535 dprintk("%s: checksum failure\n", __FUNCTION__
);
539 for (i
= 0, dsp
= &dst_tlist
[0]; i
< sizeof(dst_tlist
) / sizeof(dst_tlist
[0]); i
++, dsp
++) {
540 if (!strncmp(&rxbuf
[dsp
->offs
], dsp
->mstr
, strlen(dsp
->mstr
))) {
541 use_type_flags
= dsp
->type_flags
;
542 use_dst_type
= dsp
->dst_type
;
543 printk("%s: recognize %s\n", __FUNCTION__
, dsp
->mstr
);
547 if (i
>= sizeof(dst_tlist
) / sizeof(dst_tlist
[0])) {
548 printk("%s: unable to recognize %s or %s\n", __FUNCTION__
, &rxbuf
[0], &rxbuf
[1]);
549 printk("%s please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__
);
550 use_dst_type
= DST_TYPE_IS_SAT
;
551 use_type_flags
= DST_TYPE_HAS_SYMDIV
;
553 dst_type_print(use_dst_type
);
555 state
->type_flags
= use_type_flags
;
556 state
->dst_type
= use_dst_type
;
557 dst_type_flags_print(state
->type_flags
);
559 if (state
->type_flags
& DST_TYPE_HAS_TS204
) {
560 dst_packsize(state
, 204);
565 static int dst_command(struct dst_state
* state
, u8
* data
, u8 len
)
570 dst_i2c_enable(state
);
571 dst_reset8820(state
);
572 retval
= write_dst(state
, data
, len
);
574 dst_i2c_disable(state
);
575 dprintk("%s: write not successful\n", __FUNCTION__
);
579 retval
= read_dst(state
, &reply
, 1);
580 dst_i2c_disable(state
);
582 dprintk("%s: read verify not successful\n", __FUNCTION__
);
586 dprintk("%s: write reply not 0xff 0x%02x \n", __FUNCTION__
, reply
);
589 if (len
>= 2 && data
[0] == 0 && (data
[1] == 1 || data
[1] == 3))
591 if (!dst_wait_dst_ready(state
))
593 // dst_i2c_enable(i2c); Per dimitri
594 retval
= read_dst(state
, state
->rxbuffer
, 8);
595 dst_i2c_disable(state
);
597 dprintk("%s: read not successful\n", __FUNCTION__
);
600 if (state
->rxbuffer
[7] != dst_check_sum(state
->rxbuffer
, 7)) {
601 dprintk("%s: checksum failure\n", __FUNCTION__
);
607 static int dst_get_signal(struct dst_state
* state
)
610 u8 get_signal
[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
612 if ((state
->diseq_flags
& ATTEMPT_TUNE
) == 0) {
613 state
->decode_lock
= state
->decode_strength
= state
->decode_snr
= 0;
616 if (0 == (state
->diseq_flags
& HAS_LOCK
)) {
617 state
->decode_lock
= state
->decode_strength
= state
->decode_snr
= 0;
620 if (time_after_eq(jiffies
, state
->cur_jiff
+ (HZ
/ 5))) {
621 retval
= dst_command(state
, get_signal
, 8);
624 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
625 state
->decode_lock
= ((state
->rxbuffer
[6] & 0x10) == 0) ? 1 : 0;
626 state
->decode_strength
= state
->rxbuffer
[5] << 8;
627 state
->decode_snr
= state
->rxbuffer
[2] << 8 | state
->rxbuffer
[3];
628 } else if ((state
->dst_type
== DST_TYPE_IS_TERR
) || (state
->dst_type
== DST_TYPE_IS_CABLE
)) {
629 state
->decode_lock
= (state
->rxbuffer
[1]) ? 1 : 0;
630 state
->decode_strength
= state
->rxbuffer
[4] << 8;
631 state
->decode_snr
= state
->rxbuffer
[3] << 8;
633 state
->cur_jiff
= jiffies
;
638 static int dst_tone_power_cmd(struct dst_state
* state
)
640 u8 paket
[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
642 if (state
->dst_type
== DST_TYPE_IS_TERR
)
645 if (state
->voltage
== SEC_VOLTAGE_OFF
)
649 if (state
->tone
== SEC_TONE_ON
)
650 paket
[2] = state
->k22
;
653 paket
[7] = dst_check_sum(&paket
[0], 7);
654 dst_command(state
, paket
, 8);
658 static int dst_get_tuna(struct dst_state
* state
)
661 if ((state
->diseq_flags
& ATTEMPT_TUNE
) == 0)
663 state
->diseq_flags
&= ~(HAS_LOCK
);
664 if (!dst_wait_dst_ready(state
))
666 if (state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) {
667 /* how to get variable length reply ???? */
668 retval
= read_dst(state
, state
->rx_tuna
, 10);
670 retval
= read_dst(state
, &state
->rx_tuna
[2], 8);
673 dprintk("%s: read not successful\n", __FUNCTION__
);
676 if (state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) {
677 if (state
->rx_tuna
[9] != dst_check_sum(&state
->rx_tuna
[0], 9)) {
678 dprintk("%s: checksum failure?\n", __FUNCTION__
);
682 if (state
->rx_tuna
[9] != dst_check_sum(&state
->rx_tuna
[2], 7)) {
683 dprintk("%s: checksum failure?\n", __FUNCTION__
);
687 if (state
->rx_tuna
[2] == 0 && state
->rx_tuna
[3] == 0)
689 state
->decode_freq
= ((state
->rx_tuna
[2] & 0x7f) << 8) + state
->rx_tuna
[3];
691 state
->decode_lock
= 1;
693 dst->decode_n1 = (dst->rx_tuna[4] << 8) +
696 dst->decode_n2 = (dst->rx_tuna[8] << 8) +
699 state
->diseq_flags
|= HAS_LOCK
;
700 /* dst->cur_jiff = jiffies; */
704 static int dst_set_voltage(struct dvb_frontend
* fe
, fe_sec_voltage_t voltage
);
706 static int dst_write_tuna(struct dvb_frontend
* fe
)
708 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
712 dprintk("%s: type_flags 0x%x \n", __FUNCTION__
, state
->type_flags
);
713 state
->decode_freq
= 0;
714 state
->decode_lock
= state
->decode_strength
= state
->decode_snr
= 0;
715 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
716 if (!(state
->diseq_flags
& HAS_POWER
))
717 dst_set_voltage(fe
, SEC_VOLTAGE_13
);
719 state
->diseq_flags
&= ~(HAS_LOCK
| ATTEMPT_TUNE
);
720 dst_i2c_enable(state
);
721 if (state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) {
722 dst_reset8820(state
);
723 state
->tx_tuna
[9] = dst_check_sum(&state
->tx_tuna
[0], 9);
724 retval
= write_dst(state
, &state
->tx_tuna
[0], 10);
726 state
->tx_tuna
[9] = dst_check_sum(&state
->tx_tuna
[2], 7);
727 retval
= write_dst(state
, &state
->tx_tuna
[2], 8);
730 dst_i2c_disable(state
);
731 dprintk("%s: write not successful\n", __FUNCTION__
);
735 retval
= read_dst(state
, &reply
, 1);
736 dst_i2c_disable(state
);
738 dprintk("%s: read verify not successful\n", __FUNCTION__
);
742 dprintk("%s: write reply not 0xff 0x%02x \n", __FUNCTION__
, reply
);
745 state
->diseq_flags
|= ATTEMPT_TUNE
;
746 return dst_get_tuna(state
);
750 * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
751 * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
752 * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
753 * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
754 * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
755 * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
756 * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
757 * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
758 * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
759 * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
760 * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
763 static int dst_set_diseqc(struct dvb_frontend
* fe
, struct dvb_diseqc_master_cmd
* cmd
)
765 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
766 u8 paket
[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
768 if (state
->dst_type
== DST_TYPE_IS_TERR
)
771 if (cmd
->msg_len
== 0 || cmd
->msg_len
> 4)
773 memcpy(&paket
[3], cmd
->msg
, cmd
->msg_len
);
774 paket
[7] = dst_check_sum(&paket
[0], 7);
775 dst_command(state
, paket
, 8);
779 static int dst_set_voltage(struct dvb_frontend
* fe
, fe_sec_voltage_t voltage
)
783 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
785 state
->voltage
= voltage
;
787 if (state
->dst_type
== DST_TYPE_IS_TERR
)
791 val
= &state
->tx_tuna
[0];
795 if ((state
->diseq_flags
& HAS_POWER
) == 0)
797 state
->diseq_flags
|= HAS_POWER
;
800 if ((state
->diseq_flags
& HAS_POWER
) == 0)
802 state
->diseq_flags
|= HAS_POWER
;
805 case SEC_VOLTAGE_OFF
:
807 state
->diseq_flags
&= ~(HAS_POWER
| HAS_LOCK
| ATTEMPT_TUNE
);
813 dst_tone_power_cmd(state
);
818 static int dst_set_tone(struct dvb_frontend
* fe
, fe_sec_tone_mode_t tone
)
821 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
825 if (state
->dst_type
== DST_TYPE_IS_TERR
)
828 val
= &state
->tx_tuna
[0];
841 dst_tone_power_cmd(state
);
845 static int dst_init(struct dvb_frontend
* fe
)
847 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
848 static u8 ini_satci_tuna
[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 };
849 static u8 ini_satfta_tuna
[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 };
850 static u8 ini_tvfta_tuna
[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
851 static u8 ini_tvci_tuna
[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
852 static u8 ini_cabfta_tuna
[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
853 static u8 ini_cabci_tuna
[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
854 state
->inversion
= INVERSION_ON
;
855 state
->voltage
= SEC_VOLTAGE_13
;
856 state
->tone
= SEC_TONE_OFF
;
857 state
->symbol_rate
= 29473000;
858 state
->fec
= FEC_AUTO
;
859 state
->diseq_flags
= 0;
861 state
->bandwidth
= BANDWIDTH_7_MHZ
;
862 state
->cur_jiff
= jiffies
;
863 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
864 state
->frequency
= 950000;
865 memcpy(state
->tx_tuna
, ((state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) ? ini_satci_tuna
: ini_satfta_tuna
), sizeof(ini_satfta_tuna
));
866 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
867 state
->frequency
= 137000000;
868 memcpy(state
->tx_tuna
, ((state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) ? ini_tvci_tuna
: ini_tvfta_tuna
), sizeof(ini_tvfta_tuna
));
869 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
870 state
->frequency
= 51000000;
871 memcpy(state
->tx_tuna
, ((state
->type_flags
& DST_TYPE_HAS_NEWTUNE
) ? ini_cabci_tuna
: ini_cabfta_tuna
), sizeof(ini_cabfta_tuna
));
877 static int dst_read_status(struct dvb_frontend
* fe
, fe_status_t
* status
)
879 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
882 if (state
->diseq_flags
& HAS_LOCK
) {
883 dst_get_signal(state
);
884 if (state
->decode_lock
)
885 *status
|= FE_HAS_LOCK
| FE_HAS_SIGNAL
| FE_HAS_CARRIER
| FE_HAS_SYNC
| FE_HAS_VITERBI
;
891 static int dst_read_signal_strength(struct dvb_frontend
* fe
, u16
* strength
)
893 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
895 dst_get_signal(state
);
896 *strength
= state
->decode_strength
;
901 static int dst_read_snr(struct dvb_frontend
* fe
, u16
* snr
)
903 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
905 dst_get_signal(state
);
906 *snr
= state
->decode_snr
;
911 static int dst_set_frontend(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*p
)
913 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
915 dst_set_freq(state
, p
->frequency
);
916 dst_set_inversion(state
, p
->inversion
);
917 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
918 dst_set_fec(state
, p
->u
.qpsk
.fec_inner
);
919 dst_set_symbolrate(state
, p
->u
.qpsk
.symbol_rate
);
920 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
921 dst_set_bandwidth(state
, p
->u
.ofdm
.bandwidth
);
922 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
923 dst_set_fec(state
, p
->u
.qam
.fec_inner
);
924 dst_set_symbolrate(state
, p
->u
.qam
.symbol_rate
);
931 static int dst_get_frontend(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*p
)
933 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
935 p
->frequency
= state
->decode_freq
;
936 p
->inversion
= state
->inversion
;
937 if (state
->dst_type
== DST_TYPE_IS_SAT
) {
938 p
->u
.qpsk
.symbol_rate
= state
->symbol_rate
;
939 p
->u
.qpsk
.fec_inner
= dst_get_fec(state
);
940 } else if (state
->dst_type
== DST_TYPE_IS_TERR
) {
941 p
->u
.ofdm
.bandwidth
= state
->bandwidth
;
942 } else if (state
->dst_type
== DST_TYPE_IS_CABLE
) {
943 p
->u
.qam
.symbol_rate
= state
->symbol_rate
;
944 p
->u
.qam
.fec_inner
= dst_get_fec(state
);
945 p
->u
.qam
.modulation
= QAM_AUTO
;
951 static void dst_release(struct dvb_frontend
* fe
)
953 struct dst_state
* state
= (struct dst_state
*) fe
->demodulator_priv
;
957 static struct dvb_frontend_ops dst_dvbt_ops
;
958 static struct dvb_frontend_ops dst_dvbs_ops
;
959 static struct dvb_frontend_ops dst_dvbc_ops
;
961 struct dvb_frontend
* dst_attach(const struct dst_config
* config
,
962 struct i2c_adapter
* i2c
,
965 struct dst_state
* state
= NULL
;
967 /* allocate memory for the internal state */
968 state
= (struct dst_state
*) kmalloc(sizeof(struct dst_state
), GFP_KERNEL
);
969 if (state
== NULL
) goto error
;
971 /* setup the state */
972 state
->config
= config
;
976 /* check if the demod is there */
977 if (dst_check_ci(state
) < 0) goto error
;
979 /* determine settings based on type */
980 switch (state
->dst_type
) {
981 case DST_TYPE_IS_TERR
:
982 memcpy(&state
->ops
, &dst_dvbt_ops
, sizeof(struct dvb_frontend_ops
));
984 case DST_TYPE_IS_CABLE
:
985 memcpy(&state
->ops
, &dst_dvbc_ops
, sizeof(struct dvb_frontend_ops
));
987 case DST_TYPE_IS_SAT
:
988 memcpy(&state
->ops
, &dst_dvbs_ops
, sizeof(struct dvb_frontend_ops
));
991 printk("dst: unknown frontend type. please report to the LinuxTV.org DVB mailinglist.\n");
995 /* create dvb_frontend */
996 state
->frontend
.ops
= &state
->ops
;
997 state
->frontend
.demodulator_priv
= state
;
998 return &state
->frontend
;
1005 static struct dvb_frontend_ops dst_dvbt_ops
= {
1008 .name
= "DST DVB-T",
1010 .frequency_min
= 137000000,
1011 .frequency_max
= 858000000,
1012 .frequency_stepsize
= 166667,
1013 .caps
= FE_CAN_FEC_AUTO
| FE_CAN_QAM_AUTO
| FE_CAN_TRANSMISSION_MODE_AUTO
| FE_CAN_GUARD_INTERVAL_AUTO
1016 .release
= dst_release
,
1020 .set_frontend
= dst_set_frontend
,
1021 .get_frontend
= dst_get_frontend
,
1023 .read_status
= dst_read_status
,
1024 .read_signal_strength
= dst_read_signal_strength
,
1025 .read_snr
= dst_read_snr
,
1028 static struct dvb_frontend_ops dst_dvbs_ops
= {
1031 .name
= "DST DVB-S",
1033 .frequency_min
= 950000,
1034 .frequency_max
= 2150000,
1035 .frequency_stepsize
= 1000, /* kHz for QPSK frontends */
1036 .frequency_tolerance
= 29500,
1037 .symbol_rate_min
= 1000000,
1038 .symbol_rate_max
= 45000000,
1039 /* . symbol_rate_tolerance = ???,*/
1040 .caps
= FE_CAN_FEC_AUTO
| FE_CAN_QPSK
1043 .release
= dst_release
,
1047 .set_frontend
= dst_set_frontend
,
1048 .get_frontend
= dst_get_frontend
,
1050 .read_status
= dst_read_status
,
1051 .read_signal_strength
= dst_read_signal_strength
,
1052 .read_snr
= dst_read_snr
,
1054 .diseqc_send_master_cmd
= dst_set_diseqc
,
1055 .set_voltage
= dst_set_voltage
,
1056 .set_tone
= dst_set_tone
,
1059 static struct dvb_frontend_ops dst_dvbc_ops
= {
1062 .name
= "DST DVB-C",
1064 .frequency_stepsize
= 62500,
1065 .frequency_min
= 51000000,
1066 .frequency_max
= 858000000,
1067 .symbol_rate_min
= 1000000,
1068 .symbol_rate_max
= 45000000,
1069 /* . symbol_rate_tolerance = ???,*/
1070 .caps
= FE_CAN_FEC_AUTO
| FE_CAN_QAM_AUTO
1073 .release
= dst_release
,
1077 .set_frontend
= dst_set_frontend
,
1078 .get_frontend
= dst_get_frontend
,
1080 .read_status
= dst_read_status
,
1081 .read_signal_strength
= dst_read_signal_strength
,
1082 .read_snr
= dst_read_snr
,
1085 MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
1086 MODULE_AUTHOR("Jamie Honan");
1087 MODULE_LICENSE("GPL");
1089 EXPORT_SYMBOL(dst_attach
);