1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Montage Technology DS3000 - DVBS/S2 Demodulator driver
4 Copyright (C) 2009-2012 Konstantin Dimitrov <kosio.dimitrov@gmail.com>
6 Copyright (C) 2009-2012 TurboSight.com
10 #include <linux/slab.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/init.h>
15 #include <linux/firmware.h>
17 #include <media/dvb_frontend.h>
23 #define dprintk(args...) \
29 /* as of March 2009 current DS3000 firmware version is 1.78 */
30 /* DS3000 FW v1.78 MD5: a32d17910c4f370073f9346e71d34b80 */
31 #define DS3000_DEFAULT_FIRMWARE "dvb-fe-ds3000.fw"
33 #define DS3000_SAMPLE_RATE 96000 /* in kHz */
35 /* Register values to initialise the demod in DVB-S mode */
36 static u8 ds3000_dvbs_init_tab
[] = {
120 /* Register values to initialise the demod in DVB-S2 mode */
121 static u8 ds3000_dvbs2_init_tab
[] = {
220 struct ds3000_state
{
221 struct i2c_adapter
*i2c
;
222 const struct ds3000_config
*config
;
223 struct dvb_frontend frontend
;
224 /* previous uncorrected block counter for DVB-S2 */
228 static int ds3000_writereg(struct ds3000_state
*state
, int reg
, int data
)
230 u8 buf
[] = { reg
, data
};
231 struct i2c_msg msg
= { .addr
= state
->config
->demod_address
,
232 .flags
= 0, .buf
= buf
, .len
= 2 };
235 dprintk("%s: write reg 0x%02x, value 0x%02x\n", __func__
, reg
, data
);
237 err
= i2c_transfer(state
->i2c
, &msg
, 1);
239 printk(KERN_ERR
"%s: writereg error(err == %i, reg == 0x%02x, value == 0x%02x)\n",
240 __func__
, err
, reg
, data
);
247 static int ds3000_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
249 struct ds3000_state
*state
= fe
->demodulator_priv
;
252 ds3000_writereg(state
, 0x03, 0x12);
254 ds3000_writereg(state
, 0x03, 0x02);
259 /* I2C write for 8k firmware load */
260 static int ds3000_writeFW(struct ds3000_state
*state
, int reg
,
261 const u8
*data
, u16 len
)
267 buf
= kmalloc(33, GFP_KERNEL
);
273 msg
.addr
= state
->config
->demod_address
;
278 for (i
= 0; i
< len
; i
+= 32) {
279 memcpy(buf
+ 1, data
+ i
, 32);
281 dprintk("%s: write reg 0x%02x, len = %d\n", __func__
, reg
, len
);
283 ret
= i2c_transfer(state
->i2c
, &msg
, 1);
285 printk(KERN_ERR
"%s: write error(err == %i, reg == 0x%02x\n",
299 static int ds3000_readreg(struct ds3000_state
*state
, u8 reg
)
304 struct i2c_msg msg
[] = {
306 .addr
= state
->config
->demod_address
,
311 .addr
= state
->config
->demod_address
,
318 ret
= i2c_transfer(state
->i2c
, msg
, 2);
321 printk(KERN_ERR
"%s: reg=0x%x(error=%d)\n", __func__
, reg
, ret
);
325 dprintk("%s: read reg 0x%02x, value 0x%02x\n", __func__
, reg
, b1
[0]);
330 static int ds3000_load_firmware(struct dvb_frontend
*fe
,
331 const struct firmware
*fw
);
333 static int ds3000_firmware_ondemand(struct dvb_frontend
*fe
)
335 struct ds3000_state
*state
= fe
->demodulator_priv
;
336 const struct firmware
*fw
;
339 dprintk("%s()\n", __func__
);
341 ret
= ds3000_readreg(state
, 0xb2);
346 /* request the firmware, this will block until someone uploads it */
347 printk(KERN_INFO
"%s: Waiting for firmware upload (%s)...\n", __func__
,
348 DS3000_DEFAULT_FIRMWARE
);
349 ret
= request_firmware(&fw
, DS3000_DEFAULT_FIRMWARE
,
350 state
->i2c
->dev
.parent
);
351 printk(KERN_INFO
"%s: Waiting for firmware upload(2)...\n", __func__
);
353 printk(KERN_ERR
"%s: No firmware uploaded (timeout or file not found?)\n",
358 ret
= ds3000_load_firmware(fe
, fw
);
360 printk("%s: Writing firmware to device failed\n", __func__
);
362 release_firmware(fw
);
364 dprintk("%s: Firmware upload %s\n", __func__
,
365 ret
== 0 ? "complete" : "failed");
370 static int ds3000_load_firmware(struct dvb_frontend
*fe
,
371 const struct firmware
*fw
)
373 struct ds3000_state
*state
= fe
->demodulator_priv
;
376 dprintk("%s\n", __func__
);
377 dprintk("Firmware is %zu bytes (%02x %02x .. %02x %02x)\n",
381 fw
->data
[fw
->size
- 2],
382 fw
->data
[fw
->size
- 1]);
384 /* Begin the firmware load process */
385 ds3000_writereg(state
, 0xb2, 0x01);
386 /* write the entire firmware */
387 ret
= ds3000_writeFW(state
, 0xb0, fw
->data
, fw
->size
);
388 ds3000_writereg(state
, 0xb2, 0x00);
393 static int ds3000_set_voltage(struct dvb_frontend
*fe
,
394 enum fe_sec_voltage voltage
)
396 struct ds3000_state
*state
= fe
->demodulator_priv
;
399 dprintk("%s(%d)\n", __func__
, voltage
);
401 data
= ds3000_readreg(state
, 0xa2);
402 data
|= 0x03; /* bit0 V/H, bit1 off/on */
412 case SEC_VOLTAGE_OFF
:
416 ds3000_writereg(state
, 0xa2, data
);
421 static int ds3000_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
423 struct ds3000_state
*state
= fe
->demodulator_priv
;
424 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
429 switch (c
->delivery_system
) {
431 lock
= ds3000_readreg(state
, 0xd1);
432 if ((lock
& 0x07) == 0x07)
433 *status
= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
434 FE_HAS_VITERBI
| FE_HAS_SYNC
|
439 lock
= ds3000_readreg(state
, 0x0d);
440 if ((lock
& 0x8f) == 0x8f)
441 *status
= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
442 FE_HAS_VITERBI
| FE_HAS_SYNC
|
450 if (state
->config
->set_lock_led
)
451 state
->config
->set_lock_led(fe
, *status
== 0 ? 0 : 1);
453 dprintk("%s: status = 0x%02x\n", __func__
, lock
);
458 /* read DS3000 BER value */
459 static int ds3000_read_ber(struct dvb_frontend
*fe
, u32
* ber
)
461 struct ds3000_state
*state
= fe
->demodulator_priv
;
462 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
464 u32 ber_reading
, lpdc_frames
;
466 dprintk("%s()\n", __func__
);
468 switch (c
->delivery_system
) {
470 /* set the number of bytes checked during
472 ds3000_writereg(state
, 0xf9, 0x04);
473 /* read BER estimation status */
474 data
= ds3000_readreg(state
, 0xf8);
475 /* check if BER estimation is ready */
476 if ((data
& 0x10) == 0) {
477 /* this is the number of error bits,
478 to calculate the bit error rate
480 *ber
= (ds3000_readreg(state
, 0xf7) << 8) |
481 ds3000_readreg(state
, 0xf6);
482 /* start counting error bits */
483 /* need to be set twice
484 otherwise it fails sometimes */
486 ds3000_writereg(state
, 0xf8, data
);
487 ds3000_writereg(state
, 0xf8, data
);
489 /* used to indicate that BER estimation
490 is not ready, i.e. BER is unknown */
494 /* read the number of LPDC decoded frames */
495 lpdc_frames
= (ds3000_readreg(state
, 0xd7) << 16) |
496 (ds3000_readreg(state
, 0xd6) << 8) |
497 ds3000_readreg(state
, 0xd5);
498 /* read the number of packets with bad CRC */
499 ber_reading
= (ds3000_readreg(state
, 0xf8) << 8) |
500 ds3000_readreg(state
, 0xf7);
501 if (lpdc_frames
> 750) {
502 /* clear LPDC frame counters */
503 ds3000_writereg(state
, 0xd1, 0x01);
504 /* clear bad packets counter */
505 ds3000_writereg(state
, 0xf9, 0x01);
506 /* enable bad packets counter */
507 ds3000_writereg(state
, 0xf9, 0x00);
508 /* enable LPDC frame counters */
509 ds3000_writereg(state
, 0xd1, 0x00);
512 /* used to indicate that BER estimation is not ready,
513 i.e. BER is unknown */
523 static int ds3000_read_signal_strength(struct dvb_frontend
*fe
,
524 u16
*signal_strength
)
526 if (fe
->ops
.tuner_ops
.get_rf_strength
)
527 fe
->ops
.tuner_ops
.get_rf_strength(fe
, signal_strength
);
532 /* calculate DS3000 snr value in dB */
533 static int ds3000_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
535 struct ds3000_state
*state
= fe
->demodulator_priv
;
536 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
537 u8 snr_reading
, snr_value
;
538 u32 dvbs2_signal_reading
, dvbs2_noise_reading
, tmp
;
539 static const u16 dvbs_snr_tab
[] = { /* 20 x Table (rounded up) */
540 0x0000, 0x1b13, 0x2aea, 0x3627, 0x3ede, 0x45fe, 0x4c03,
541 0x513a, 0x55d4, 0x59f2, 0x5dab, 0x6111, 0x6431, 0x6717,
542 0x69c9, 0x6c4e, 0x6eac, 0x70e8, 0x7304, 0x7505
544 static const u16 dvbs2_snr_tab
[] = { /* 80 x Table (rounded up) */
545 0x0000, 0x0bc2, 0x12a3, 0x1785, 0x1b4e, 0x1e65, 0x2103,
546 0x2347, 0x2546, 0x2710, 0x28ae, 0x2a28, 0x2b83, 0x2cc5,
547 0x2df1, 0x2f09, 0x3010, 0x3109, 0x31f4, 0x32d2, 0x33a6,
548 0x3470, 0x3531, 0x35ea, 0x369b, 0x3746, 0x37ea, 0x3888,
549 0x3920, 0x39b3, 0x3a42, 0x3acc, 0x3b51, 0x3bd3, 0x3c51,
550 0x3ccb, 0x3d42, 0x3db6, 0x3e27, 0x3e95, 0x3f00, 0x3f68,
551 0x3fcf, 0x4033, 0x4094, 0x40f4, 0x4151, 0x41ac, 0x4206,
552 0x425e, 0x42b4, 0x4308, 0x435b, 0x43ac, 0x43fc, 0x444a,
553 0x4497, 0x44e2, 0x452d, 0x4576, 0x45bd, 0x4604, 0x4649,
554 0x468e, 0x46d1, 0x4713, 0x4755, 0x4795, 0x47d4, 0x4813,
555 0x4851, 0x488d, 0x48c9, 0x4904, 0x493f, 0x4978, 0x49b1,
556 0x49e9, 0x4a20, 0x4a57
559 dprintk("%s()\n", __func__
);
561 switch (c
->delivery_system
) {
563 snr_reading
= ds3000_readreg(state
, 0xff);
565 if (snr_reading
== 0)
568 if (snr_reading
> 20)
570 snr_value
= dvbs_snr_tab
[snr_reading
- 1] * 10 / 23026;
571 /* cook the value to be suitable for szap-s2
572 human readable output */
573 *snr
= snr_value
* 8 * 655;
575 dprintk("%s: raw / cooked = 0x%02x / 0x%04x\n", __func__
,
579 dvbs2_noise_reading
= (ds3000_readreg(state
, 0x8c) & 0x3f) +
580 (ds3000_readreg(state
, 0x8d) << 4);
581 dvbs2_signal_reading
= ds3000_readreg(state
, 0x8e);
582 tmp
= dvbs2_signal_reading
* dvbs2_signal_reading
>> 1;
587 if (dvbs2_noise_reading
== 0) {
589 /* cook the value to be suitable for szap-s2
590 human readable output */
594 if (tmp
> dvbs2_noise_reading
) {
595 snr_reading
= tmp
/ dvbs2_noise_reading
;
596 if (snr_reading
> 80)
598 snr_value
= dvbs2_snr_tab
[snr_reading
- 1] / 1000;
599 /* cook the value to be suitable for szap-s2
600 human readable output */
601 *snr
= snr_value
* 5 * 655;
603 snr_reading
= dvbs2_noise_reading
/ tmp
;
604 if (snr_reading
> 80)
606 *snr
= -(dvbs2_snr_tab
[snr_reading
- 1] / 1000);
608 dprintk("%s: raw / cooked = 0x%02x / 0x%04x\n", __func__
,
618 /* read DS3000 uncorrected blocks */
619 static int ds3000_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
621 struct ds3000_state
*state
= fe
->demodulator_priv
;
622 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
626 dprintk("%s()\n", __func__
);
628 switch (c
->delivery_system
) {
630 *ucblocks
= (ds3000_readreg(state
, 0xf5) << 8) |
631 ds3000_readreg(state
, 0xf4);
632 data
= ds3000_readreg(state
, 0xf8);
633 /* clear packet counters */
635 ds3000_writereg(state
, 0xf8, data
);
636 /* enable packet counters */
638 ds3000_writereg(state
, 0xf8, data
);
641 _ucblocks
= (ds3000_readreg(state
, 0xe2) << 8) |
642 ds3000_readreg(state
, 0xe1);
643 if (_ucblocks
> state
->prevUCBS2
)
644 *ucblocks
= _ucblocks
- state
->prevUCBS2
;
646 *ucblocks
= state
->prevUCBS2
- _ucblocks
;
647 state
->prevUCBS2
= _ucblocks
;
656 static int ds3000_set_tone(struct dvb_frontend
*fe
, enum fe_sec_tone_mode tone
)
658 struct ds3000_state
*state
= fe
->demodulator_priv
;
661 dprintk("%s(%d)\n", __func__
, tone
);
662 if ((tone
!= SEC_TONE_ON
) && (tone
!= SEC_TONE_OFF
)) {
663 printk(KERN_ERR
"%s: Invalid, tone=%d\n", __func__
, tone
);
667 data
= ds3000_readreg(state
, 0xa2);
669 ds3000_writereg(state
, 0xa2, data
);
673 dprintk("%s: setting tone on\n", __func__
);
674 data
= ds3000_readreg(state
, 0xa1);
677 ds3000_writereg(state
, 0xa1, data
);
680 dprintk("%s: setting tone off\n", __func__
);
681 data
= ds3000_readreg(state
, 0xa2);
683 ds3000_writereg(state
, 0xa2, data
);
690 static int ds3000_send_diseqc_msg(struct dvb_frontend
*fe
,
691 struct dvb_diseqc_master_cmd
*d
)
693 struct ds3000_state
*state
= fe
->demodulator_priv
;
697 /* Dump DiSEqC message */
698 dprintk("%s(", __func__
);
699 for (i
= 0 ; i
< d
->msg_len
;) {
700 dprintk("0x%02x", d
->msg
[i
]);
701 if (++i
< d
->msg_len
)
705 /* enable DiSEqC message send pin */
706 data
= ds3000_readreg(state
, 0xa2);
708 ds3000_writereg(state
, 0xa2, data
);
711 for (i
= 0; i
< d
->msg_len
; i
++)
712 ds3000_writereg(state
, 0xa3 + i
, d
->msg
[i
]);
714 data
= ds3000_readreg(state
, 0xa1);
715 /* clear DiSEqC message length and status,
716 enable DiSEqC message send */
718 /* set DiSEqC mode, modulation active during 33 pulses,
719 set DiSEqC message length */
720 data
|= ((d
->msg_len
- 1) << 3) | 0x07;
721 ds3000_writereg(state
, 0xa1, data
);
723 /* wait up to 150ms for DiSEqC transmission to complete */
724 for (i
= 0; i
< 15; i
++) {
725 data
= ds3000_readreg(state
, 0xa1);
726 if ((data
& 0x40) == 0)
731 /* DiSEqC timeout after 150ms */
733 data
= ds3000_readreg(state
, 0xa1);
736 ds3000_writereg(state
, 0xa1, data
);
738 data
= ds3000_readreg(state
, 0xa2);
741 ds3000_writereg(state
, 0xa2, data
);
746 data
= ds3000_readreg(state
, 0xa2);
749 ds3000_writereg(state
, 0xa2, data
);
754 /* Send DiSEqC burst */
755 static int ds3000_diseqc_send_burst(struct dvb_frontend
*fe
,
756 enum fe_sec_mini_cmd burst
)
758 struct ds3000_state
*state
= fe
->demodulator_priv
;
762 dprintk("%s()\n", __func__
);
764 data
= ds3000_readreg(state
, 0xa2);
766 ds3000_writereg(state
, 0xa2, data
);
769 if (burst
== SEC_MINI_A
)
770 /* Unmodulated tone burst */
771 ds3000_writereg(state
, 0xa1, 0x02);
772 else if (burst
== SEC_MINI_B
)
773 /* Modulated tone burst */
774 ds3000_writereg(state
, 0xa1, 0x01);
779 for (i
= 0; i
< 5; i
++) {
780 data
= ds3000_readreg(state
, 0xa1);
781 if ((data
& 0x40) == 0)
787 data
= ds3000_readreg(state
, 0xa1);
790 ds3000_writereg(state
, 0xa1, data
);
792 data
= ds3000_readreg(state
, 0xa2);
795 ds3000_writereg(state
, 0xa2, data
);
800 data
= ds3000_readreg(state
, 0xa2);
803 ds3000_writereg(state
, 0xa2, data
);
808 static void ds3000_release(struct dvb_frontend
*fe
)
810 struct ds3000_state
*state
= fe
->demodulator_priv
;
812 if (state
->config
->set_lock_led
)
813 state
->config
->set_lock_led(fe
, 0);
815 dprintk("%s\n", __func__
);
819 static const struct dvb_frontend_ops ds3000_ops
;
821 struct dvb_frontend
*ds3000_attach(const struct ds3000_config
*config
,
822 struct i2c_adapter
*i2c
)
824 struct ds3000_state
*state
;
827 dprintk("%s\n", __func__
);
829 /* allocate memory for the internal state */
830 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
834 state
->config
= config
;
836 state
->prevUCBS2
= 0;
838 /* check if the demod is present */
839 ret
= ds3000_readreg(state
, 0x00) & 0xfe;
842 printk(KERN_ERR
"Invalid probe, probably not a DS3000\n");
846 printk(KERN_INFO
"DS3000 chip version: %d.%d attached.\n",
847 ds3000_readreg(state
, 0x02),
848 ds3000_readreg(state
, 0x01));
850 memcpy(&state
->frontend
.ops
, &ds3000_ops
,
851 sizeof(struct dvb_frontend_ops
));
852 state
->frontend
.demodulator_priv
= state
;
855 * Some devices like T480 starts with voltage on. Be sure
856 * to turn voltage off during init, as this can otherwise
857 * interfere with Unicable SCR systems.
859 ds3000_set_voltage(&state
->frontend
, SEC_VOLTAGE_OFF
);
860 return &state
->frontend
;
862 EXPORT_SYMBOL(ds3000_attach
);
864 static int ds3000_set_carrier_offset(struct dvb_frontend
*fe
,
865 s32 carrier_offset_khz
)
867 struct ds3000_state
*state
= fe
->demodulator_priv
;
870 tmp
= carrier_offset_khz
;
872 tmp
= (2 * tmp
+ DS3000_SAMPLE_RATE
) / (2 * DS3000_SAMPLE_RATE
);
877 ds3000_writereg(state
, 0x5f, tmp
>> 8);
878 ds3000_writereg(state
, 0x5e, tmp
& 0xff);
883 static int ds3000_set_frontend(struct dvb_frontend
*fe
)
885 struct ds3000_state
*state
= fe
->demodulator_priv
;
886 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
889 enum fe_status status
;
894 dprintk("%s() ", __func__
);
896 if (state
->config
->set_ts_params
)
897 state
->config
->set_ts_params(fe
, 0);
899 if (fe
->ops
.tuner_ops
.set_params
)
900 fe
->ops
.tuner_ops
.set_params(fe
);
902 /* ds3000 global reset */
903 ds3000_writereg(state
, 0x07, 0x80);
904 ds3000_writereg(state
, 0x07, 0x00);
905 /* ds3000 built-in uC reset */
906 ds3000_writereg(state
, 0xb2, 0x01);
907 /* ds3000 software reset */
908 ds3000_writereg(state
, 0x00, 0x01);
910 switch (c
->delivery_system
) {
912 /* initialise the demod in DVB-S mode */
913 for (i
= 0; i
< sizeof(ds3000_dvbs_init_tab
); i
+= 2)
914 ds3000_writereg(state
,
915 ds3000_dvbs_init_tab
[i
],
916 ds3000_dvbs_init_tab
[i
+ 1]);
917 value
= ds3000_readreg(state
, 0xfe);
920 ds3000_writereg(state
, 0xfe, value
);
923 /* initialise the demod in DVB-S2 mode */
924 for (i
= 0; i
< sizeof(ds3000_dvbs2_init_tab
); i
+= 2)
925 ds3000_writereg(state
,
926 ds3000_dvbs2_init_tab
[i
],
927 ds3000_dvbs2_init_tab
[i
+ 1]);
928 if (c
->symbol_rate
>= 30000000)
929 ds3000_writereg(state
, 0xfe, 0x54);
931 ds3000_writereg(state
, 0xfe, 0x98);
937 /* enable 27MHz clock output */
938 ds3000_writereg(state
, 0x29, 0x80);
939 /* enable ac coupling */
940 ds3000_writereg(state
, 0x25, 0x8a);
942 if ((c
->symbol_rate
< ds3000_ops
.info
.symbol_rate_min
) ||
943 (c
->symbol_rate
> ds3000_ops
.info
.symbol_rate_max
)) {
944 dprintk("%s() symbol_rate %u out of range (%u ... %u)\n",
945 __func__
, c
->symbol_rate
,
946 ds3000_ops
.info
.symbol_rate_min
,
947 ds3000_ops
.info
.symbol_rate_max
);
951 /* enhance symbol rate performance */
952 if ((c
->symbol_rate
/ 1000) <= 5000) {
953 value
= 29777 / (c
->symbol_rate
/ 1000) + 1;
956 ds3000_writereg(state
, 0xc3, 0x0d);
957 ds3000_writereg(state
, 0xc8, value
);
958 ds3000_writereg(state
, 0xc4, 0x10);
959 ds3000_writereg(state
, 0xc7, 0x0e);
960 } else if ((c
->symbol_rate
/ 1000) <= 10000) {
961 value
= 92166 / (c
->symbol_rate
/ 1000) + 1;
964 ds3000_writereg(state
, 0xc3, 0x07);
965 ds3000_writereg(state
, 0xc8, value
);
966 ds3000_writereg(state
, 0xc4, 0x09);
967 ds3000_writereg(state
, 0xc7, 0x12);
968 } else if ((c
->symbol_rate
/ 1000) <= 20000) {
969 value
= 64516 / (c
->symbol_rate
/ 1000) + 1;
970 ds3000_writereg(state
, 0xc3, value
);
971 ds3000_writereg(state
, 0xc8, 0x0e);
972 ds3000_writereg(state
, 0xc4, 0x07);
973 ds3000_writereg(state
, 0xc7, 0x18);
975 value
= 129032 / (c
->symbol_rate
/ 1000) + 1;
976 ds3000_writereg(state
, 0xc3, value
);
977 ds3000_writereg(state
, 0xc8, 0x0a);
978 ds3000_writereg(state
, 0xc4, 0x05);
979 ds3000_writereg(state
, 0xc7, 0x24);
982 /* normalized symbol rate rounded to the closest integer */
983 value
= (((c
->symbol_rate
/ 1000) << 16) +
984 (DS3000_SAMPLE_RATE
/ 2)) / DS3000_SAMPLE_RATE
;
985 ds3000_writereg(state
, 0x61, value
& 0x00ff);
986 ds3000_writereg(state
, 0x62, (value
& 0xff00) >> 8);
988 /* co-channel interference cancellation disabled */
989 ds3000_writereg(state
, 0x56, 0x00);
991 /* equalizer disabled */
992 ds3000_writereg(state
, 0x76, 0x00);
994 /*ds3000_writereg(state, 0x08, 0x03);
995 ds3000_writereg(state, 0xfd, 0x22);
996 ds3000_writereg(state, 0x08, 0x07);
997 ds3000_writereg(state, 0xfd, 0x42);
998 ds3000_writereg(state, 0x08, 0x07);*/
1000 if (state
->config
->ci_mode
) {
1001 switch (c
->delivery_system
) {
1004 ds3000_writereg(state
, 0xfd, 0x80);
1007 ds3000_writereg(state
, 0xfd, 0x01);
1012 /* ds3000 out of software reset */
1013 ds3000_writereg(state
, 0x00, 0x00);
1014 /* start ds3000 built-in uC */
1015 ds3000_writereg(state
, 0xb2, 0x00);
1017 if (fe
->ops
.tuner_ops
.get_frequency
) {
1018 fe
->ops
.tuner_ops
.get_frequency(fe
, &frequency
);
1019 offset_khz
= frequency
- c
->frequency
;
1020 ds3000_set_carrier_offset(fe
, offset_khz
);
1023 for (i
= 0; i
< 30 ; i
++) {
1024 ds3000_read_status(fe
, &status
);
1025 if (status
& FE_HAS_LOCK
)
1034 static int ds3000_tune(struct dvb_frontend
*fe
,
1036 unsigned int mode_flags
,
1037 unsigned int *delay
,
1038 enum fe_status
*status
)
1041 int ret
= ds3000_set_frontend(fe
);
1048 return ds3000_read_status(fe
, status
);
1051 static enum dvbfe_algo
ds3000_get_algo(struct dvb_frontend
*fe
)
1053 struct ds3000_state
*state
= fe
->demodulator_priv
;
1055 if (state
->config
->set_lock_led
)
1056 state
->config
->set_lock_led(fe
, 0);
1058 dprintk("%s()\n", __func__
);
1059 return DVBFE_ALGO_HW
;
1063 * Initialise or wake up device
1065 * Power config will reset and load initial firmware if required
1067 static int ds3000_initfe(struct dvb_frontend
*fe
)
1069 struct ds3000_state
*state
= fe
->demodulator_priv
;
1072 dprintk("%s()\n", __func__
);
1074 ds3000_writereg(state
, 0x08, 0x01 | ds3000_readreg(state
, 0x08));
1077 /* Load the firmware if required */
1078 ret
= ds3000_firmware_ondemand(fe
);
1080 printk(KERN_ERR
"%s: Unable initialize firmware\n", __func__
);
1087 static const struct dvb_frontend_ops ds3000_ops
= {
1088 .delsys
= { SYS_DVBS
, SYS_DVBS2
},
1090 .name
= "Montage Technology DS3000",
1091 .frequency_min_hz
= 950 * MHz
,
1092 .frequency_max_hz
= 2150 * MHz
,
1093 .frequency_stepsize_hz
= 1011 * kHz
,
1094 .frequency_tolerance_hz
= 5 * MHz
,
1095 .symbol_rate_min
= 1000000,
1096 .symbol_rate_max
= 45000000,
1097 .caps
= FE_CAN_INVERSION_AUTO
|
1098 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
1099 FE_CAN_FEC_4_5
| FE_CAN_FEC_5_6
| FE_CAN_FEC_6_7
|
1100 FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
1101 FE_CAN_2G_MODULATION
|
1102 FE_CAN_QPSK
| FE_CAN_RECOVER
1105 .release
= ds3000_release
,
1107 .init
= ds3000_initfe
,
1108 .i2c_gate_ctrl
= ds3000_i2c_gate_ctrl
,
1109 .read_status
= ds3000_read_status
,
1110 .read_ber
= ds3000_read_ber
,
1111 .read_signal_strength
= ds3000_read_signal_strength
,
1112 .read_snr
= ds3000_read_snr
,
1113 .read_ucblocks
= ds3000_read_ucblocks
,
1114 .set_voltage
= ds3000_set_voltage
,
1115 .set_tone
= ds3000_set_tone
,
1116 .diseqc_send_master_cmd
= ds3000_send_diseqc_msg
,
1117 .diseqc_send_burst
= ds3000_diseqc_send_burst
,
1118 .get_frontend_algo
= ds3000_get_algo
,
1120 .set_frontend
= ds3000_set_frontend
,
1121 .tune
= ds3000_tune
,
1124 module_param(debug
, int, 0644);
1125 MODULE_PARM_DESC(debug
, "Activates frontend debugging (default:0)");
1127 MODULE_DESCRIPTION("DVB Frontend module for Montage Technology DS3000 hardware");
1128 MODULE_AUTHOR("Konstantin Dimitrov <kosio.dimitrov@gmail.com>");
1129 MODULE_LICENSE("GPL");
1130 MODULE_FIRMWARE(DS3000_DEFAULT_FIRMWARE
);