2 STB0899 Multistandard Frontend driver
3 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
5 Copyright (C) ST Microelectronics
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.
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/string.h>
28 #include <linux/dvb/frontend.h>
29 #include "dvb_frontend.h"
31 #include "stb0899_drv.h"
32 #include "stb0899_priv.h"
33 #include "stb0899_reg.h"
35 static unsigned int verbose
= 0;//1;
36 module_param(verbose
, int, 0644);
38 /* C/N in dB/10, NIRM/NIRL */
39 static const struct stb0899_tab stb0899_cn_tab
[] = {
62 /* DVB-S AGCIQ_VALUE vs. signal level in dBm/10.
63 * As measured, connected to a modulator.
64 * -8.0 to -50.0 dBm directly connected,
65 * -52.0 to -74.8 with extra attenuation.
66 * Cut-off to AGCIQ_VALUE = 0x80 below -74.8dBm.
67 * Crude linear extrapolation below -84.8dBm and above -8.0dBm.
69 static const struct stb0899_tab stb0899_dvbsrf_tab
[] = {
103 /* DVB-S2 IF_AGC_GAIN vs. signal level in dBm/10.
104 * As measured, connected to a modulator.
105 * -8.0 to -50.1 dBm directly connected,
106 * -53.0 to -76.6 with extra attenuation.
107 * Cut-off to IF_AGC_GAIN = 0x3fff below -76.6dBm.
108 * Crude linear extrapolation below -76.6dBm and above -8.0dBm.
110 static const struct stb0899_tab stb0899_dvbs2rf_tab
[] = {
137 /* DVB-S2 Es/N0 quant in dB/100 vs read value * 100*/
138 static struct stb0899_tab stb0899_quant_tab
[] = {
180 /* DVB-S2 Es/N0 estimate in dB/100 vs read value */
181 static struct stb0899_tab stb0899_est_tab
[] = {
221 static int _stb0899_read_reg(struct stb0899_state
*state
, unsigned int reg
)
225 u8 b0
[] = { reg
>> 8, reg
& 0xff };
228 struct i2c_msg msg
[] = {
230 .addr
= state
->config
->demod_address
,
235 .addr
= state
->config
->demod_address
,
242 ret
= i2c_transfer(state
->i2c
, msg
, 2);
244 if (ret
!= -ERESTARTSYS
)
245 dprintk(state
->verbose
, FE_ERROR
, 1,
246 "Read error, Reg=[0x%02x], Status=%d",
249 return ret
< 0 ? ret
: -EREMOTEIO
;
251 if (unlikely(*state
->verbose
>= FE_DEBUGREG
))
252 dprintk(state
->verbose
, FE_ERROR
, 1, "Reg=[0x%02x], data=%02x",
255 return (unsigned int)buf
;
258 int stb0899_read_reg(struct stb0899_state
*state
, unsigned int reg
)
262 result
= _stb0899_read_reg(state
, reg
);
265 * access to 0xf2xx/0xf6xx
266 * must be followed by read from 0xf2ff/0xf6ff.
268 if ((reg
!= 0xf2ff) && (reg
!= 0xf6ff) &&
269 (((reg
& 0xff00) == 0xf200) || ((reg
& 0xff00) == 0xf600)))
270 _stb0899_read_reg(state
, (reg
| 0x00ff));
275 u32
_stb0899_read_s2reg(struct stb0899_state
*state
,
277 u32 stb0899_base_addr
,
278 u16 stb0899_reg_offset
)
286 GETBYTE(stb0899_i2cdev
, BYTE1
), /* 0xf3 S2 Base Address (MSB) */
287 GETBYTE(stb0899_i2cdev
, BYTE0
), /* 0xfc S2 Base Address (LSB) */
288 GETBYTE(stb0899_base_addr
, BYTE0
), /* 0x00 Base Address (LSB) */
289 GETBYTE(stb0899_base_addr
, BYTE1
), /* 0x04 Base Address (LSB) */
290 GETBYTE(stb0899_base_addr
, BYTE2
), /* 0x00 Base Address (MSB) */
291 GETBYTE(stb0899_base_addr
, BYTE3
), /* 0x00 Base Address (MSB) */
294 0x00, /* 0xf3 Reg Offset */
295 0x00, /* 0x44 Reg Offset */
298 struct i2c_msg msg_0
= {
299 .addr
= state
->config
->demod_address
,
305 struct i2c_msg msg_1
= {
306 .addr
= state
->config
->demod_address
,
312 struct i2c_msg msg_r
= {
313 .addr
= state
->config
->demod_address
,
319 tmpaddr
= stb0899_reg_offset
& 0xff00;
320 if (!(stb0899_reg_offset
& 0x8))
321 tmpaddr
= stb0899_reg_offset
| 0x20;
323 buf_1
[0] = GETBYTE(tmpaddr
, BYTE1
);
324 buf_1
[1] = GETBYTE(tmpaddr
, BYTE0
);
326 status
= i2c_transfer(state
->i2c
, &msg_0
, 1);
328 if (status
!= -ERESTARTSYS
)
329 printk(KERN_ERR
"%s ERR(1), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
330 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, status
);
336 status
= i2c_transfer(state
->i2c
, &msg_1
, 1);
340 status
= i2c_transfer(state
->i2c
, &msg_r
, 1);
344 buf_1
[0] = GETBYTE(stb0899_reg_offset
, BYTE1
);
345 buf_1
[1] = GETBYTE(stb0899_reg_offset
, BYTE0
);
348 status
= i2c_transfer(state
->i2c
, &msg_1
, 1);
350 if (status
!= -ERESTARTSYS
)
351 printk(KERN_ERR
"%s ERR(2), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
352 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, status
);
356 status
= i2c_transfer(state
->i2c
, &msg_r
, 1);
358 if (status
!= -ERESTARTSYS
)
359 printk(KERN_ERR
"%s ERR(3), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
360 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, status
);
361 return status
< 0 ? status
: -EREMOTEIO
;
364 data
= MAKEWORD32(buf
[3], buf
[2], buf
[1], buf
[0]);
365 if (unlikely(*state
->verbose
>= FE_DEBUGREG
))
366 printk(KERN_DEBUG
"%s Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Data=[0x%08x]\n",
367 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, data
);
372 return status
< 0 ? status
: -EREMOTEIO
;
375 int stb0899_write_s2reg(struct stb0899_state
*state
,
377 u32 stb0899_base_addr
,
378 u16 stb0899_reg_offset
,
383 /* Base Address Setup */
385 GETBYTE(stb0899_i2cdev
, BYTE1
), /* 0xf3 S2 Base Address (MSB) */
386 GETBYTE(stb0899_i2cdev
, BYTE0
), /* 0xfc S2 Base Address (LSB) */
387 GETBYTE(stb0899_base_addr
, BYTE0
), /* 0x00 Base Address (LSB) */
388 GETBYTE(stb0899_base_addr
, BYTE1
), /* 0x04 Base Address (LSB) */
389 GETBYTE(stb0899_base_addr
, BYTE2
), /* 0x00 Base Address (MSB) */
390 GETBYTE(stb0899_base_addr
, BYTE3
), /* 0x00 Base Address (MSB) */
393 0x00, /* 0xf3 Reg Offset */
394 0x00, /* 0x44 Reg Offset */
401 struct i2c_msg msg_0
= {
402 .addr
= state
->config
->demod_address
,
408 struct i2c_msg msg_1
= {
409 .addr
= state
->config
->demod_address
,
415 buf_1
[0] = GETBYTE(stb0899_reg_offset
, BYTE1
);
416 buf_1
[1] = GETBYTE(stb0899_reg_offset
, BYTE0
);
417 buf_1
[2] = GETBYTE(stb0899_data
, BYTE0
);
418 buf_1
[3] = GETBYTE(stb0899_data
, BYTE1
);
419 buf_1
[4] = GETBYTE(stb0899_data
, BYTE2
);
420 buf_1
[5] = GETBYTE(stb0899_data
, BYTE3
);
422 if (unlikely(*state
->verbose
>= FE_DEBUGREG
))
423 printk(KERN_DEBUG
"%s Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x]\n",
424 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, stb0899_data
);
426 status
= i2c_transfer(state
->i2c
, &msg_0
, 1);
427 if (unlikely(status
< 1)) {
428 if (status
!= -ERESTARTSYS
)
429 printk(KERN_ERR
"%s ERR (1), Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x], status=%d\n",
430 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, stb0899_data
, status
);
433 status
= i2c_transfer(state
->i2c
, &msg_1
, 1);
434 if (unlikely(status
< 1)) {
435 if (status
!= -ERESTARTSYS
)
436 printk(KERN_ERR
"%s ERR (2), Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x], status=%d\n",
437 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, stb0899_data
, status
);
439 return status
< 0 ? status
: -EREMOTEIO
;
445 return status
< 0 ? status
: -EREMOTEIO
;
448 int stb0899_read_regs(struct stb0899_state
*state
, unsigned int reg
, u8
*buf
, u32 count
)
452 u8 b0
[] = { reg
>> 8, reg
& 0xff };
454 struct i2c_msg msg
[] = {
456 .addr
= state
->config
->demod_address
,
461 .addr
= state
->config
->demod_address
,
468 status
= i2c_transfer(state
->i2c
, msg
, 2);
470 if (status
!= -ERESTARTSYS
)
471 printk(KERN_ERR
"%s Read error, Reg=[0x%04x], Count=%u, Status=%d\n",
472 __func__
, reg
, count
, status
);
477 * access to 0xf2xx/0xf6xx
478 * must be followed by read from 0xf2ff/0xf6ff.
480 if ((reg
!= 0xf2ff) && (reg
!= 0xf6ff) &&
481 (((reg
& 0xff00) == 0xf200) || ((reg
& 0xff00) == 0xf600)))
482 _stb0899_read_reg(state
, (reg
| 0x00ff));
484 if (unlikely(*state
->verbose
>= FE_DEBUGREG
)) {
487 printk(KERN_DEBUG
"%s [0x%04x]:", __func__
, reg
);
488 for (i
= 0; i
< count
; i
++) {
489 printk(" %02x", buf
[i
]);
496 return status
< 0 ? status
: -EREMOTEIO
;
499 int stb0899_write_regs(struct stb0899_state
*state
, unsigned int reg
, u8
*data
, u32 count
)
503 struct i2c_msg i2c_msg
= {
504 .addr
= state
->config
->demod_address
,
512 memcpy(&buf
[2], data
, count
);
514 if (unlikely(*state
->verbose
>= FE_DEBUGREG
)) {
517 printk(KERN_DEBUG
"%s [0x%04x]:", __func__
, reg
);
518 for (i
= 0; i
< count
; i
++)
519 printk(" %02x", data
[i
]);
522 ret
= i2c_transfer(state
->i2c
, &i2c_msg
, 1);
526 * access to 0xf2xx/0xf6xx
527 * must be followed by read from 0xf2ff/0xf6ff.
529 if ((((reg
& 0xff00) == 0xf200) || ((reg
& 0xff00) == 0xf600)))
530 stb0899_read_reg(state
, (reg
| 0x00ff));
533 if (ret
!= -ERESTARTSYS
)
534 dprintk(state
->verbose
, FE_ERROR
, 1, "Reg=[0x%04x], Data=[0x%02x ...], Count=%u, Status=%d",
535 reg
, data
[0], count
, ret
);
536 return ret
< 0 ? ret
: -EREMOTEIO
;
542 int stb0899_write_reg(struct stb0899_state
*state
, unsigned int reg
, u8 data
)
544 return stb0899_write_regs(state
, reg
, &data
, 1);
549 * Get STB0899 master clock frequency
550 * ExtClk: external clock frequency (Hz)
552 static u32
stb0899_get_mclk(struct stb0899_state
*state
)
554 u32 mclk
= 0, div
= 0;
556 div
= stb0899_read_reg(state
, STB0899_NCOARSE
);
557 mclk
= (div
+ 1) * state
->config
->xtal_freq
/ 6;
558 dprintk(state
->verbose
, FE_DEBUG
, 1, "div=%d, mclk=%d", div
, mclk
);
565 * Set STB0899 master Clock frequency
566 * Mclk: demodulator master clock
567 * ExtClk: external clock frequency (Hz)
569 static void stb0899_set_mclk(struct stb0899_state
*state
, u32 Mclk
)
571 struct stb0899_internal
*internal
= &state
->internal
;
574 dprintk(state
->verbose
, FE_DEBUG
, 1, "state->config=%p", state
->config
);
575 mdiv
= ((6 * Mclk
) / state
->config
->xtal_freq
) - 1;
576 dprintk(state
->verbose
, FE_DEBUG
, 1, "mdiv=%d", mdiv
);
578 stb0899_write_reg(state
, STB0899_NCOARSE
, mdiv
);
579 internal
->master_clk
= stb0899_get_mclk(state
);
581 dprintk(state
->verbose
, FE_DEBUG
, 1, "MasterCLOCK=%d", internal
->master_clk
);
584 static int stb0899_postproc(struct stb0899_state
*state
, u8 ctl
, int enable
)
586 struct stb0899_config
*config
= state
->config
;
587 const struct stb0899_postproc
*postproc
= config
->postproc
;
589 /* post process event */
592 if (postproc
[ctl
].level
== STB0899_GPIOPULLUP
)
593 stb0899_write_reg(state
, postproc
[ctl
].gpio
, 0x02);
595 stb0899_write_reg(state
, postproc
[ctl
].gpio
, 0x82);
597 if (postproc
[ctl
].level
== STB0899_GPIOPULLUP
)
598 stb0899_write_reg(state
, postproc
[ctl
].gpio
, 0x82);
600 stb0899_write_reg(state
, postproc
[ctl
].gpio
, 0x02);
606 static void stb0899_release(struct dvb_frontend
*fe
)
608 struct stb0899_state
*state
= fe
->demodulator_priv
;
610 dprintk(state
->verbose
, FE_DEBUG
, 1, "Release Frontend");
611 /* post process event */
612 stb0899_postproc(state
, STB0899_POSTPROC_GPIO_POWER
, 0);
620 static int stb0899_get_alpha(struct stb0899_state
*state
)
624 mode_coeff
= stb0899_read_reg(state
, STB0899_DEMOD
);
626 if (STB0899_GETFIELD(MODECOEFF
, mode_coeff
) == 1)
635 static void stb0899_init_calc(struct stb0899_state
*state
)
637 struct stb0899_internal
*internal
= &state
->internal
;
642 /* Read registers (in burst mode) */
643 stb0899_read_regs(state
, STB0899_AGC1REF
, agc
, 2); /* AGC1R and AGC2O */
645 /* Initial calculations */
646 master_clk
= stb0899_get_mclk(state
);
647 internal
->t_agc1
= 0;
648 internal
->t_agc2
= 0;
649 internal
->master_clk
= master_clk
;
650 internal
->mclk
= master_clk
/ 65536L;
651 internal
->rolloff
= stb0899_get_alpha(state
);
653 /* DVBS2 Initial calculations */
654 /* Set AGC value to the middle */
655 internal
->agc_gain
= 8154;
656 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, IF_AGC_CNTRL
);
657 STB0899_SETFIELD_VAL(IF_GAIN_INIT
, reg
, internal
->agc_gain
);
658 stb0899_write_s2reg(state
, STB0899_S2DEMOD
, STB0899_BASE_IF_AGC_CNTRL
, STB0899_OFF0_IF_AGC_CNTRL
, reg
);
660 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, RRC_ALPHA
);
661 internal
->rrc_alpha
= STB0899_GETFIELD(RRC_ALPHA
, reg
);
663 internal
->center_freq
= 0;
664 internal
->av_frame_coarse
= 10;
665 internal
->av_frame_fine
= 20;
666 internal
->step_size
= 2;
668 if ((pParams->SpectralInv == FE_IQ_NORMAL) || (pParams->SpectralInv == FE_IQ_AUTO))
669 pParams->IQLocked = 0;
671 pParams->IQLocked = 1;
675 static int stb0899_wait_diseqc_fifo_empty(struct stb0899_state
*state
, int timeout
)
678 unsigned long start
= jiffies
;
681 reg
= stb0899_read_reg(state
, STB0899_DISSTATUS
);
682 if (!STB0899_GETFIELD(FIFOFULL
, reg
))
684 if ((jiffies
- start
) > timeout
) {
685 dprintk(state
->verbose
, FE_ERROR
, 1, "timed out !!");
693 static int stb0899_send_diseqc_msg(struct dvb_frontend
*fe
, struct dvb_diseqc_master_cmd
*cmd
)
695 struct stb0899_state
*state
= fe
->demodulator_priv
;
698 if (cmd
->msg_len
> 8)
701 /* enable FIFO precharge */
702 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
703 STB0899_SETFIELD_VAL(DISPRECHARGE
, reg
, 1);
704 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
705 for (i
= 0; i
< cmd
->msg_len
; i
++) {
706 /* wait for FIFO empty */
707 if (stb0899_wait_diseqc_fifo_empty(state
, 100) < 0)
710 stb0899_write_reg(state
, STB0899_DISFIFO
, cmd
->msg
[i
]);
712 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
713 STB0899_SETFIELD_VAL(DISPRECHARGE
, reg
, 0);
714 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
719 static int stb0899_wait_diseqc_rxidle(struct stb0899_state
*state
, int timeout
)
722 unsigned long start
= jiffies
;
724 while (!STB0899_GETFIELD(RXEND
, reg
)) {
725 reg
= stb0899_read_reg(state
, STB0899_DISRX_ST0
);
726 if (jiffies
- start
> timeout
) {
727 dprintk(state
->verbose
, FE_ERROR
, 1, "timed out!!");
736 static int stb0899_recv_slave_reply(struct dvb_frontend
*fe
, struct dvb_diseqc_slave_reply
*reply
)
738 struct stb0899_state
*state
= fe
->demodulator_priv
;
739 u8 reg
, length
= 0, i
;
742 if (stb0899_wait_diseqc_rxidle(state
, 100) < 0)
745 reg
= stb0899_read_reg(state
, STB0899_DISRX_ST0
);
746 if (STB0899_GETFIELD(RXEND
, reg
)) {
748 reg
= stb0899_read_reg(state
, STB0899_DISRX_ST1
);
749 length
= STB0899_GETFIELD(FIFOBYTENBR
, reg
);
751 if (length
> sizeof (reply
->msg
)) {
755 reply
->msg_len
= length
;
758 for (i
= 0; i
< length
; i
++)
759 reply
->msg
[i
] = stb0899_read_reg(state
, STB0899_DISFIFO
);
768 static int stb0899_wait_diseqc_txidle(struct stb0899_state
*state
, int timeout
)
771 unsigned long start
= jiffies
;
773 while (!STB0899_GETFIELD(TXIDLE
, reg
)) {
774 reg
= stb0899_read_reg(state
, STB0899_DISSTATUS
);
775 if (jiffies
- start
> timeout
) {
776 dprintk(state
->verbose
, FE_ERROR
, 1, "timed out!!");
784 static int stb0899_send_diseqc_burst(struct dvb_frontend
*fe
, fe_sec_mini_cmd_t burst
)
786 struct stb0899_state
*state
= fe
->demodulator_priv
;
789 /* wait for diseqc idle */
790 if (stb0899_wait_diseqc_txidle(state
, 100) < 0)
793 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
795 /* set to burst mode */
796 STB0899_SETFIELD_VAL(DISEQCMODE
, reg
, 0x03);
797 STB0899_SETFIELD_VAL(DISPRECHARGE
, reg
, 0x01);
798 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
802 stb0899_write_reg(state
, STB0899_DISFIFO
, 0x00);
806 stb0899_write_reg(state
, STB0899_DISFIFO
, 0xff);
809 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
810 STB0899_SETFIELD_VAL(DISPRECHARGE
, reg
, 0x00);
811 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
812 /* wait for diseqc idle */
813 if (stb0899_wait_diseqc_txidle(state
, 100) < 0)
817 stb0899_write_reg(state
, STB0899_DISCNTRL1
, old_state
);
822 static int stb0899_diseqc_init(struct stb0899_state
*state
)
825 struct dvb_diseqc_slave_reply rx_data;
829 u32 mclk
, tx_freq
= 22000;/* count = 0, i; */
830 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL2
);
831 STB0899_SETFIELD_VAL(ONECHIP_TRX
, reg
, 0);
832 stb0899_write_reg(state
, STB0899_DISCNTRL2
, reg
);
835 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
836 STB0899_SETFIELD_VAL(DISEQCRESET
, reg
, 1);
837 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
839 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
840 STB0899_SETFIELD_VAL(DISEQCRESET
, reg
, 0);
841 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
843 mclk
= stb0899_get_mclk(state
);
844 f22_tx
= mclk
/ (tx_freq
* 32);
845 stb0899_write_reg(state
, STB0899_DISF22
, f22_tx
); /* DiSEqC Tx freq */
846 state
->rx_freq
= 20000;
851 static int stb0899_sleep(struct dvb_frontend
*fe
)
853 struct stb0899_state
*state
= fe
->demodulator_priv
;
857 dprintk(state
->verbose
, FE_DEBUG
, 1, "Going to Sleep .. (Really tired .. :-))");
858 /* post process event */
859 stb0899_postproc(state
, STB0899_POSTPROC_GPIO_POWER
, 0);
864 static int stb0899_wakeup(struct dvb_frontend
*fe
)
867 struct stb0899_state
*state
= fe
->demodulator_priv
;
869 if ((rc
= stb0899_write_reg(state
, STB0899_SYNTCTRL
, STB0899_SELOSCI
)))
871 /* Activate all clocks; DVB-S2 registers are inaccessible otherwise. */
872 if ((rc
= stb0899_write_reg(state
, STB0899_STOPCLK1
, 0x00)))
874 if ((rc
= stb0899_write_reg(state
, STB0899_STOPCLK2
, 0x00)))
877 /* post process event */
878 stb0899_postproc(state
, STB0899_POSTPROC_GPIO_POWER
, 1);
883 static int stb0899_init(struct dvb_frontend
*fe
)
886 struct stb0899_state
*state
= fe
->demodulator_priv
;
887 struct stb0899_config
*config
= state
->config
;
889 dprintk(state
->verbose
, FE_DEBUG
, 1, "Initializing STB0899 ... ");
892 dprintk(state
->verbose
, FE_DEBUG
, 1, "init device");
893 for (i
= 0; config
->init_dev
[i
].address
!= 0xffff; i
++)
894 stb0899_write_reg(state
, config
->init_dev
[i
].address
, config
->init_dev
[i
].data
);
896 dprintk(state
->verbose
, FE_DEBUG
, 1, "init S2 demod");
898 for (i
= 0; config
->init_s2_demod
[i
].offset
!= 0xffff; i
++)
899 stb0899_write_s2reg(state
, STB0899_S2DEMOD
,
900 config
->init_s2_demod
[i
].base_address
,
901 config
->init_s2_demod
[i
].offset
,
902 config
->init_s2_demod
[i
].data
);
904 dprintk(state
->verbose
, FE_DEBUG
, 1, "init S1 demod");
906 for (i
= 0; config
->init_s1_demod
[i
].address
!= 0xffff; i
++)
907 stb0899_write_reg(state
, config
->init_s1_demod
[i
].address
, config
->init_s1_demod
[i
].data
);
909 dprintk(state
->verbose
, FE_DEBUG
, 1, "init S2 FEC");
911 for (i
= 0; config
->init_s2_fec
[i
].offset
!= 0xffff; i
++)
912 stb0899_write_s2reg(state
, STB0899_S2FEC
,
913 config
->init_s2_fec
[i
].base_address
,
914 config
->init_s2_fec
[i
].offset
,
915 config
->init_s2_fec
[i
].data
);
917 dprintk(state
->verbose
, FE_DEBUG
, 1, "init TST");
919 for (i
= 0; config
->init_tst
[i
].address
!= 0xffff; i
++)
920 stb0899_write_reg(state
, config
->init_tst
[i
].address
, config
->init_tst
[i
].data
);
922 stb0899_init_calc(state
);
923 stb0899_diseqc_init(state
);
928 static int stb0899_table_lookup(const struct stb0899_tab
*tab
, int max
, int val
)
933 if (val
< tab
[min
].read
)
935 else if (val
>= tab
[max
].read
)
938 while ((max
- min
) > 1) {
939 med
= (max
+ min
) / 2;
940 if (val
>= tab
[min
].read
&& val
< tab
[med
].read
)
945 res
= ((val
- tab
[min
].read
) *
946 (tab
[max
].real
- tab
[min
].real
) /
947 (tab
[max
].read
- tab
[min
].read
)) +
954 static int stb0899_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
956 struct stb0899_state
*state
= fe
->demodulator_priv
;
957 struct stb0899_internal
*internal
= &state
->internal
;
962 switch (state
->delsys
) {
965 if (internal
->lock
) {
966 reg
= stb0899_read_reg(state
, STB0899_VSTATUS
);
967 if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT
, reg
)) {
969 reg
= stb0899_read_reg(state
, STB0899_AGCIQIN
);
970 val
= (s32
)(s8
)STB0899_GETFIELD(AGCIQVALUE
, reg
);
972 *strength
= stb0899_table_lookup(stb0899_dvbsrf_tab
, ARRAY_SIZE(stb0899_dvbsrf_tab
) - 1, val
);
974 dprintk(state
->verbose
, FE_DEBUG
, 1, "AGCIQVALUE = 0x%02x, C = %d * 0.1 dBm",
975 val
& 0xff, *strength
);
980 if (internal
->lock
) {
981 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, IF_AGC_GAIN
);
982 val
= STB0899_GETFIELD(IF_AGC_GAIN
, reg
);
984 *strength
= stb0899_table_lookup(stb0899_dvbs2rf_tab
, ARRAY_SIZE(stb0899_dvbs2rf_tab
) - 1, val
);
986 dprintk(state
->verbose
, FE_DEBUG
, 1, "IF_AGC_GAIN = 0x%04x, C = %d * 0.1 dBm",
987 val
& 0x3fff, *strength
);
991 dprintk(state
->verbose
, FE_DEBUG
, 1, "Unsupported delivery system");
998 static int stb0899_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
1000 struct stb0899_state
*state
= fe
->demodulator_priv
;
1001 struct stb0899_internal
*internal
= &state
->internal
;
1003 unsigned int val
, quant
, quantn
= -1, est
, estn
= -1;
1008 reg
= stb0899_read_reg(state
, STB0899_VSTATUS
);
1009 switch (state
->delsys
) {
1012 if (internal
->lock
) {
1013 if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT
, reg
)) {
1015 stb0899_read_regs(state
, STB0899_NIRM
, buf
, 2);
1016 val
= MAKEWORD16(buf
[0], buf
[1]);
1018 *snr
= stb0899_table_lookup(stb0899_cn_tab
, ARRAY_SIZE(stb0899_cn_tab
) - 1, val
);
1019 dprintk(state
->verbose
, FE_DEBUG
, 1, "NIR = 0x%02x%02x = %u, C/N = %d * 0.1 dBm\n",
1020 buf
[0], buf
[1], val
, *snr
);
1025 if (internal
->lock
) {
1026 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, UWP_CNTRL1
);
1027 quant
= STB0899_GETFIELD(UWP_ESN0_QUANT
, reg
);
1028 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, UWP_STAT2
);
1029 est
= STB0899_GETFIELD(ESN0_EST
, reg
);
1031 val
= 301; /* C/N = 30.1 dB */
1033 val
= 270; /* C/N = 27.0 dB */
1035 /* quantn = 100 * log(quant^2) */
1036 quantn
= stb0899_table_lookup(stb0899_quant_tab
, ARRAY_SIZE(stb0899_quant_tab
) - 1, quant
* 100);
1037 /* estn = 100 * log(est) */
1038 estn
= stb0899_table_lookup(stb0899_est_tab
, ARRAY_SIZE(stb0899_est_tab
) - 1, est
);
1039 /* snr(dBm/10) = -10*(log(est)-log(quant^2)) => snr(dBm/10) = (100*log(quant^2)-100*log(est))/10 */
1040 val
= (quantn
- estn
) / 10;
1043 dprintk(state
->verbose
, FE_DEBUG
, 1, "Es/N0 quant = %d (%d) estimate = %u (%d), C/N = %d * 0.1 dBm",
1044 quant
, quantn
, est
, estn
, val
);
1048 dprintk(state
->verbose
, FE_DEBUG
, 1, "Unsupported delivery system");
1055 static int stb0899_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
1057 struct stb0899_state
*state
= fe
->demodulator_priv
;
1058 struct stb0899_internal
*internal
= &state
->internal
;
1062 switch (state
->delsys
) {
1065 dprintk(state
->verbose
, FE_DEBUG
, 1, "Delivery system DVB-S/DSS");
1066 if (internal
->lock
) {
1067 reg
= stb0899_read_reg(state
, STB0899_VSTATUS
);
1068 if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT
, reg
)) {
1069 dprintk(state
->verbose
, FE_DEBUG
, 1, "--------> FE_HAS_CARRIER | FE_HAS_LOCK");
1070 *status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
| FE_HAS_LOCK
;
1072 reg
= stb0899_read_reg(state
, STB0899_PLPARM
);
1073 if (STB0899_GETFIELD(VITCURPUN
, reg
)) {
1074 dprintk(state
->verbose
, FE_DEBUG
, 1, "--------> FE_HAS_VITERBI | FE_HAS_SYNC");
1075 *status
|= FE_HAS_VITERBI
| FE_HAS_SYNC
;
1076 /* post process event */
1077 stb0899_postproc(state
, STB0899_POSTPROC_GPIO_LOCK
, 1);
1083 dprintk(state
->verbose
, FE_DEBUG
, 1, "Delivery system DVB-S2");
1084 if (internal
->lock
) {
1085 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, DMD_STAT2
);
1086 if (STB0899_GETFIELD(UWP_LOCK
, reg
) && STB0899_GETFIELD(CSM_LOCK
, reg
)) {
1087 *status
|= FE_HAS_CARRIER
;
1088 dprintk(state
->verbose
, FE_DEBUG
, 1,
1089 "UWP & CSM Lock ! ---> DVB-S2 FE_HAS_CARRIER");
1091 reg
= stb0899_read_reg(state
, STB0899_CFGPDELSTATUS1
);
1092 if (STB0899_GETFIELD(CFGPDELSTATUS_LOCK
, reg
)) {
1093 *status
|= FE_HAS_LOCK
;
1094 dprintk(state
->verbose
, FE_DEBUG
, 1,
1095 "Packet Delineator Locked ! -----> DVB-S2 FE_HAS_LOCK");
1098 if (STB0899_GETFIELD(CONTINUOUS_STREAM
, reg
)) {
1099 *status
|= FE_HAS_VITERBI
;
1100 dprintk(state
->verbose
, FE_DEBUG
, 1,
1101 "Packet Delineator found VITERBI ! -----> DVB-S2 FE_HAS_VITERBI");
1103 if (STB0899_GETFIELD(ACCEPTED_STREAM
, reg
)) {
1104 *status
|= FE_HAS_SYNC
;
1105 dprintk(state
->verbose
, FE_DEBUG
, 1,
1106 "Packet Delineator found SYNC ! -----> DVB-S2 FE_HAS_SYNC");
1107 /* post process event */
1108 stb0899_postproc(state
, STB0899_POSTPROC_GPIO_LOCK
, 1);
1114 dprintk(state
->verbose
, FE_DEBUG
, 1, "Unsupported delivery system");
1122 * viterbi error for DVB-S/DSS
1123 * packet error for DVB-S2
1124 * Bit Error Rate or Packet Error Rate * 10 ^ 7
1126 static int stb0899_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
1128 struct stb0899_state
*state
= fe
->demodulator_priv
;
1129 struct stb0899_internal
*internal
= &state
->internal
;
1135 switch (state
->delsys
) {
1138 if (internal
->lock
) {
1139 lsb
= stb0899_read_reg(state
, STB0899_ECNT1L
);
1140 msb
= stb0899_read_reg(state
, STB0899_ECNT1M
);
1141 *ber
= MAKEWORD16(msb
, lsb
);
1143 if (STB0899_GETFIELD(VSTATUS_PRFVIT
, internal
->v_status
)) {
1146 /* ber = ber * 10 ^ 7 */
1147 *ber
/= (-1 + (1 << (2 * STB0899_GETFIELD(NOE
, internal
->err_ctrl
))));
1153 if (internal
->lock
) {
1154 lsb
= stb0899_read_reg(state
, STB0899_ECNT1L
);
1155 msb
= stb0899_read_reg(state
, STB0899_ECNT1M
);
1156 *ber
= MAKEWORD16(msb
, lsb
);
1157 /* ber = ber * 10 ^ 7 */
1159 *ber
/= (-1 + (1 << (4 + 2 * STB0899_GETFIELD(NOE
, internal
->err_ctrl
))));
1163 dprintk(state
->verbose
, FE_DEBUG
, 1, "Unsupported delivery system");
1170 static int stb0899_set_voltage(struct dvb_frontend
*fe
, fe_sec_voltage_t voltage
)
1172 struct stb0899_state
*state
= fe
->demodulator_priv
;
1175 case SEC_VOLTAGE_13
:
1176 stb0899_write_reg(state
, STB0899_GPIO00CFG
, 0x82);
1177 stb0899_write_reg(state
, STB0899_GPIO01CFG
, 0x02);
1178 stb0899_write_reg(state
, STB0899_GPIO02CFG
, 0x00);
1180 case SEC_VOLTAGE_18
:
1181 stb0899_write_reg(state
, STB0899_GPIO00CFG
, 0x02);
1182 stb0899_write_reg(state
, STB0899_GPIO01CFG
, 0x02);
1183 stb0899_write_reg(state
, STB0899_GPIO02CFG
, 0x82);
1185 case SEC_VOLTAGE_OFF
:
1186 stb0899_write_reg(state
, STB0899_GPIO00CFG
, 0x82);
1187 stb0899_write_reg(state
, STB0899_GPIO01CFG
, 0x82);
1188 stb0899_write_reg(state
, STB0899_GPIO02CFG
, 0x82);
1197 static int stb0899_set_tone(struct dvb_frontend
*fe
, fe_sec_tone_mode_t tone
)
1199 struct stb0899_state
*state
= fe
->demodulator_priv
;
1200 struct stb0899_internal
*internal
= &state
->internal
;
1204 /* wait for diseqc idle */
1205 if (stb0899_wait_diseqc_txidle(state
, 100) < 0)
1210 div
= (internal
->master_clk
/ 100) / 5632;
1211 div
= (div
+ 5) / 10;
1212 stb0899_write_reg(state
, STB0899_DISEQCOCFG
, 0x66);
1213 reg
= stb0899_read_reg(state
, STB0899_ACRPRESC
);
1214 STB0899_SETFIELD_VAL(ACRPRESC
, reg
, 0x03);
1215 stb0899_write_reg(state
, STB0899_ACRPRESC
, reg
);
1216 stb0899_write_reg(state
, STB0899_ACRDIV1
, div
);
1219 stb0899_write_reg(state
, STB0899_DISEQCOCFG
, 0x20);
1227 int stb0899_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
1230 struct stb0899_state
*state
= fe
->demodulator_priv
;
1232 i2c_stat
= stb0899_read_reg(state
, STB0899_I2CRPT
);
1237 dprintk(state
->verbose
, FE_DEBUG
, 1, "Enabling I2C Repeater ...");
1238 i2c_stat
|= STB0899_I2CTON
;
1239 if (stb0899_write_reg(state
, STB0899_I2CRPT
, i2c_stat
) < 0)
1242 dprintk(state
->verbose
, FE_DEBUG
, 1, "Disabling I2C Repeater ...");
1243 i2c_stat
&= ~STB0899_I2CTON
;
1244 if (stb0899_write_reg(state
, STB0899_I2CRPT
, i2c_stat
) < 0)
1249 dprintk(state
->verbose
, FE_ERROR
, 1, "I2C Repeater control failed");
1254 static inline void CONVERT32(u32 x
, char *str
)
1256 *str
++ = (x
>> 24) & 0xff;
1257 *str
++ = (x
>> 16) & 0xff;
1258 *str
++ = (x
>> 8) & 0xff;
1259 *str
++ = (x
>> 0) & 0xff;
1263 int stb0899_get_dev_id(struct stb0899_state
*state
)
1265 u8 chip_id
, release
;
1267 u32 demod_ver
= 0, fec_ver
= 0;
1268 char demod_str
[5] = { 0 };
1269 char fec_str
[5] = { 0 };
1271 id
= stb0899_read_reg(state
, STB0899_DEV_ID
);
1272 dprintk(state
->verbose
, FE_DEBUG
, 1, "ID reg=[0x%02x]", id
);
1273 chip_id
= STB0899_GETFIELD(CHIP_ID
, id
);
1274 release
= STB0899_GETFIELD(CHIP_REL
, id
);
1276 dprintk(state
->verbose
, FE_ERROR
, 1, "Device ID=[%d], Release=[%d]",
1279 CONVERT32(STB0899_READ_S2REG(STB0899_S2DEMOD
, DMD_CORE_ID
), (char *)&demod_str
);
1281 demod_ver
= STB0899_READ_S2REG(STB0899_S2DEMOD
, DMD_VERSION_ID
);
1282 dprintk(state
->verbose
, FE_ERROR
, 1, "Demodulator Core ID=[%s], Version=[%d]", (char *) &demod_str
, demod_ver
);
1283 CONVERT32(STB0899_READ_S2REG(STB0899_S2FEC
, FEC_CORE_ID_REG
), (char *)&fec_str
);
1284 fec_ver
= STB0899_READ_S2REG(STB0899_S2FEC
, FEC_VER_ID_REG
);
1285 if (! (chip_id
> 0)) {
1286 dprintk(state
->verbose
, FE_ERROR
, 1, "couldn't find a STB 0899");
1290 dprintk(state
->verbose
, FE_ERROR
, 1, "FEC Core ID=[%s], Version=[%d]", (char*) &fec_str
, fec_ver
);
1295 static void stb0899_set_delivery(struct stb0899_state
*state
)
1300 stop_clk
[0] = stb0899_read_reg(state
, STB0899_STOPCLK1
);
1301 stop_clk
[1] = stb0899_read_reg(state
, STB0899_STOPCLK2
);
1303 switch (state
->delsys
) {
1305 dprintk(state
->verbose
, FE_DEBUG
, 1, "Delivery System -- DVB-S");
1306 /* FECM/Viterbi ON */
1307 reg
= stb0899_read_reg(state
, STB0899_FECM
);
1308 STB0899_SETFIELD_VAL(FECM_RSVD0
, reg
, 0);
1309 STB0899_SETFIELD_VAL(FECM_VITERBI_ON
, reg
, 1);
1310 stb0899_write_reg(state
, STB0899_FECM
, reg
);
1312 stb0899_write_reg(state
, STB0899_RSULC
, 0xb1);
1313 stb0899_write_reg(state
, STB0899_TSULC
, 0x40);
1314 stb0899_write_reg(state
, STB0899_RSLLC
, 0x42);
1315 stb0899_write_reg(state
, STB0899_TSLPL
, 0x12);
1317 reg
= stb0899_read_reg(state
, STB0899_TSTRES
);
1318 STB0899_SETFIELD_VAL(FRESLDPC
, reg
, 1);
1319 stb0899_write_reg(state
, STB0899_TSTRES
, reg
);
1321 STB0899_SETFIELD_VAL(STOP_CHK8PSK
, stop_clk
[0], 1);
1322 STB0899_SETFIELD_VAL(STOP_CKFEC108
, stop_clk
[0], 1);
1323 STB0899_SETFIELD_VAL(STOP_CKFEC216
, stop_clk
[0], 1);
1325 STB0899_SETFIELD_VAL(STOP_CKPKDLIN108
, stop_clk
[1], 1);
1326 STB0899_SETFIELD_VAL(STOP_CKPKDLIN216
, stop_clk
[1], 1);
1328 STB0899_SETFIELD_VAL(STOP_CKINTBUF216
, stop_clk
[0], 1);
1329 STB0899_SETFIELD_VAL(STOP_CKCORE216
, stop_clk
[0], 0);
1331 STB0899_SETFIELD_VAL(STOP_CKS2DMD108
, stop_clk
[1], 1);
1334 /* FECM/Viterbi OFF */
1335 reg
= stb0899_read_reg(state
, STB0899_FECM
);
1336 STB0899_SETFIELD_VAL(FECM_RSVD0
, reg
, 0);
1337 STB0899_SETFIELD_VAL(FECM_VITERBI_ON
, reg
, 0);
1338 stb0899_write_reg(state
, STB0899_FECM
, reg
);
1340 stb0899_write_reg(state
, STB0899_RSULC
, 0xb1);
1341 stb0899_write_reg(state
, STB0899_TSULC
, 0x42);
1342 stb0899_write_reg(state
, STB0899_RSLLC
, 0x40);
1343 stb0899_write_reg(state
, STB0899_TSLPL
, 0x02);
1345 reg
= stb0899_read_reg(state
, STB0899_TSTRES
);
1346 STB0899_SETFIELD_VAL(FRESLDPC
, reg
, 0);
1347 stb0899_write_reg(state
, STB0899_TSTRES
, reg
);
1349 STB0899_SETFIELD_VAL(STOP_CHK8PSK
, stop_clk
[0], 1);
1350 STB0899_SETFIELD_VAL(STOP_CKFEC108
, stop_clk
[0], 0);
1351 STB0899_SETFIELD_VAL(STOP_CKFEC216
, stop_clk
[0], 0);
1353 STB0899_SETFIELD_VAL(STOP_CKPKDLIN108
, stop_clk
[1], 0);
1354 STB0899_SETFIELD_VAL(STOP_CKPKDLIN216
, stop_clk
[1], 0);
1356 STB0899_SETFIELD_VAL(STOP_CKINTBUF216
, stop_clk
[0], 0);
1357 STB0899_SETFIELD_VAL(STOP_CKCORE216
, stop_clk
[0], 0);
1359 STB0899_SETFIELD_VAL(STOP_CKS2DMD108
, stop_clk
[1], 0);
1362 /* FECM/Viterbi ON */
1363 reg
= stb0899_read_reg(state
, STB0899_FECM
);
1364 STB0899_SETFIELD_VAL(FECM_RSVD0
, reg
, 1);
1365 STB0899_SETFIELD_VAL(FECM_VITERBI_ON
, reg
, 1);
1366 stb0899_write_reg(state
, STB0899_FECM
, reg
);
1368 stb0899_write_reg(state
, STB0899_RSULC
, 0xa1);
1369 stb0899_write_reg(state
, STB0899_TSULC
, 0x61);
1370 stb0899_write_reg(state
, STB0899_RSLLC
, 0x42);
1372 reg
= stb0899_read_reg(state
, STB0899_TSTRES
);
1373 STB0899_SETFIELD_VAL(FRESLDPC
, reg
, 1);
1374 stb0899_write_reg(state
, STB0899_TSTRES
, reg
);
1376 STB0899_SETFIELD_VAL(STOP_CHK8PSK
, stop_clk
[0], 1);
1377 STB0899_SETFIELD_VAL(STOP_CKFEC108
, stop_clk
[0], 1);
1378 STB0899_SETFIELD_VAL(STOP_CKFEC216
, stop_clk
[0], 1);
1380 STB0899_SETFIELD_VAL(STOP_CKPKDLIN108
, stop_clk
[1], 1);
1381 STB0899_SETFIELD_VAL(STOP_CKPKDLIN216
, stop_clk
[1], 1);
1383 STB0899_SETFIELD_VAL(STOP_CKCORE216
, stop_clk
[0], 0);
1385 STB0899_SETFIELD_VAL(STOP_CKS2DMD108
, stop_clk
[1], 1);
1388 dprintk(state
->verbose
, FE_ERROR
, 1, "Unsupported delivery system");
1391 STB0899_SETFIELD_VAL(STOP_CKADCI108
, stop_clk
[0], 0);
1392 stb0899_write_regs(state
, STB0899_STOPCLK1
, stop_clk
, 2);
1396 * stb0899_set_iterations
1397 * set the LDPC iteration scale function
1399 static void stb0899_set_iterations(struct stb0899_state
*state
)
1401 struct stb0899_internal
*internal
= &state
->internal
;
1402 struct stb0899_config
*config
= state
->config
;
1407 iter_scale
= 17 * (internal
->master_clk
/ 1000);
1408 iter_scale
+= 410000;
1409 iter_scale
/= (internal
->srate
/ 1000000);
1412 if (iter_scale
> config
->ldpc_max_iter
)
1413 iter_scale
= config
->ldpc_max_iter
;
1415 reg
= STB0899_READ_S2REG(STB0899_S2FEC
, MAX_ITER
);
1416 STB0899_SETFIELD_VAL(MAX_ITERATIONS
, reg
, iter_scale
);
1417 stb0899_write_s2reg(state
, STB0899_S2FEC
, STB0899_BASE_MAX_ITER
, STB0899_OFF0_MAX_ITER
, reg
);
1420 static enum dvbfe_search
stb0899_search(struct dvb_frontend
*fe
)
1422 struct stb0899_state
*state
= fe
->demodulator_priv
;
1423 struct stb0899_params
*i_params
= &state
->params
;
1424 struct stb0899_internal
*internal
= &state
->internal
;
1425 struct stb0899_config
*config
= state
->config
;
1426 struct dtv_frontend_properties
*props
= &fe
->dtv_property_cache
;
1428 u32 SearchRange
, gain
;
1430 i_params
->freq
= props
->frequency
;
1431 i_params
->srate
= props
->symbol_rate
;
1432 state
->delsys
= props
->delivery_system
;
1433 dprintk(state
->verbose
, FE_DEBUG
, 1, "delivery system=%d", state
->delsys
);
1435 SearchRange
= 10000000;
1436 dprintk(state
->verbose
, FE_DEBUG
, 1, "Frequency=%d, Srate=%d", i_params
->freq
, i_params
->srate
);
1437 /* checking Search Range is meaningless for a fixed 3 Mhz */
1438 if (INRANGE(i_params
->srate
, 1000000, 45000000)) {
1439 dprintk(state
->verbose
, FE_DEBUG
, 1, "Parameters IN RANGE");
1440 stb0899_set_delivery(state
);
1442 if (state
->config
->tuner_set_rfsiggain
) {
1443 if (internal
->srate
> 15000000)
1444 gain
= 8; /* 15Mb < srate < 45Mb, gain = 8dB */
1445 else if (internal
->srate
> 5000000)
1446 gain
= 12; /* 5Mb < srate < 15Mb, gain = 12dB */
1448 gain
= 14; /* 1Mb < srate < 5Mb, gain = 14db */
1449 state
->config
->tuner_set_rfsiggain(fe
, gain
);
1452 if (i_params
->srate
<= 5000000)
1453 stb0899_set_mclk(state
, config
->lo_clk
);
1455 stb0899_set_mclk(state
, config
->hi_clk
);
1457 switch (state
->delsys
) {
1460 dprintk(state
->verbose
, FE_DEBUG
, 1, "DVB-S delivery system");
1461 internal
->freq
= i_params
->freq
;
1462 internal
->srate
= i_params
->srate
;
1464 * search = user search range +
1466 * 2 * Tuner_step_size +
1467 * 10% of the symbol rate
1469 internal
->srch_range
= SearchRange
+ 1500000 + (i_params
->srate
/ 5);
1470 internal
->derot_percent
= 30;
1472 /* What to do for tuners having no bandwidth setup ? */
1473 /* enable tuner I/O */
1474 stb0899_i2c_gate_ctrl(&state
->frontend
, 1);
1476 if (state
->config
->tuner_set_bandwidth
)
1477 state
->config
->tuner_set_bandwidth(fe
, (13 * (stb0899_carr_width(state
) + SearchRange
)) / 10);
1478 if (state
->config
->tuner_get_bandwidth
)
1479 state
->config
->tuner_get_bandwidth(fe
, &internal
->tuner_bw
);
1481 /* disable tuner I/O */
1482 stb0899_i2c_gate_ctrl(&state
->frontend
, 0);
1484 /* Set DVB-S1 AGC */
1485 stb0899_write_reg(state
, STB0899_AGCRFCFG
, 0x11);
1487 /* Run the search algorithm */
1488 dprintk(state
->verbose
, FE_DEBUG
, 1, "running DVB-S search algo ..");
1489 if (stb0899_dvbs_algo(state
) == RANGEOK
) {
1491 dprintk(state
->verbose
, FE_DEBUG
, 1,
1492 "-------------------------------------> DVB-S LOCK !");
1494 // stb0899_write_reg(state, STB0899_ERRCTRL1, 0x3d); /* Viterbi Errors */
1495 // internal->v_status = stb0899_read_reg(state, STB0899_VSTATUS);
1496 // internal->err_ctrl = stb0899_read_reg(state, STB0899_ERRCTRL1);
1497 // dprintk(state->verbose, FE_DEBUG, 1, "VSTATUS=0x%02x", internal->v_status);
1498 // dprintk(state->verbose, FE_DEBUG, 1, "ERR_CTRL=0x%02x", internal->err_ctrl);
1500 return DVBFE_ALGO_SEARCH_SUCCESS
;
1504 return DVBFE_ALGO_SEARCH_FAILED
;
1508 internal
->freq
= i_params
->freq
;
1509 internal
->srate
= i_params
->srate
;
1510 internal
->srch_range
= SearchRange
;
1512 /* enable tuner I/O */
1513 stb0899_i2c_gate_ctrl(&state
->frontend
, 1);
1515 if (state
->config
->tuner_set_bandwidth
)
1516 state
->config
->tuner_set_bandwidth(fe
, (stb0899_carr_width(state
) + SearchRange
));
1517 if (state
->config
->tuner_get_bandwidth
)
1518 state
->config
->tuner_get_bandwidth(fe
, &internal
->tuner_bw
);
1520 /* disable tuner I/O */
1521 stb0899_i2c_gate_ctrl(&state
->frontend
, 0);
1523 // pParams->SpectralInv = pSearch->IQ_Inversion;
1525 /* Set DVB-S2 AGC */
1526 stb0899_write_reg(state
, STB0899_AGCRFCFG
, 0x1c);
1528 /* Set IterScale =f(MCLK,SYMB) */
1529 stb0899_set_iterations(state
);
1531 /* Run the search algorithm */
1532 dprintk(state
->verbose
, FE_DEBUG
, 1, "running DVB-S2 search algo ..");
1533 if (stb0899_dvbs2_algo(state
) == DVBS2_FEC_LOCK
) {
1535 dprintk(state
->verbose
, FE_DEBUG
, 1,
1536 "-------------------------------------> DVB-S2 LOCK !");
1538 // stb0899_write_reg(state, STB0899_ERRCTRL1, 0xb6); /* Packet Errors */
1539 // internal->v_status = stb0899_read_reg(state, STB0899_VSTATUS);
1540 // internal->err_ctrl = stb0899_read_reg(state, STB0899_ERRCTRL1);
1542 return DVBFE_ALGO_SEARCH_SUCCESS
;
1546 return DVBFE_ALGO_SEARCH_FAILED
;
1550 dprintk(state
->verbose
, FE_ERROR
, 1, "Unsupported delivery system");
1551 return DVBFE_ALGO_SEARCH_INVALID
;
1555 return DVBFE_ALGO_SEARCH_ERROR
;
1558 static int stb0899_get_frontend(struct dvb_frontend
*fe
)
1560 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
1561 struct stb0899_state
*state
= fe
->demodulator_priv
;
1562 struct stb0899_internal
*internal
= &state
->internal
;
1564 dprintk(state
->verbose
, FE_DEBUG
, 1, "Get params");
1565 p
->symbol_rate
= internal
->srate
;
1570 static enum dvbfe_algo
stb0899_frontend_algo(struct dvb_frontend
*fe
)
1572 return DVBFE_ALGO_CUSTOM
;
1575 static struct dvb_frontend_ops stb0899_ops
= {
1576 .delsys
= { SYS_DVBS
, SYS_DVBS2
, SYS_DSS
},
1578 .name
= "STB0899 Multistandard",
1579 .frequency_min
= 950000,
1580 .frequency_max
= 2150000,
1581 .frequency_stepsize
= 0,
1582 .frequency_tolerance
= 0,
1583 .symbol_rate_min
= 5000000,
1584 .symbol_rate_max
= 45000000,
1586 .caps
= FE_CAN_INVERSION_AUTO
|
1588 FE_CAN_2G_MODULATION
|
1592 .release
= stb0899_release
,
1593 .init
= stb0899_init
,
1594 .sleep
= stb0899_sleep
,
1595 // .wakeup = stb0899_wakeup,
1597 .i2c_gate_ctrl
= stb0899_i2c_gate_ctrl
,
1599 .get_frontend_algo
= stb0899_frontend_algo
,
1600 .search
= stb0899_search
,
1601 .get_frontend
= stb0899_get_frontend
,
1604 .read_status
= stb0899_read_status
,
1605 .read_snr
= stb0899_read_snr
,
1606 .read_signal_strength
= stb0899_read_signal_strength
,
1607 .read_ber
= stb0899_read_ber
,
1609 .set_voltage
= stb0899_set_voltage
,
1610 .set_tone
= stb0899_set_tone
,
1612 .diseqc_send_master_cmd
= stb0899_send_diseqc_msg
,
1613 .diseqc_recv_slave_reply
= stb0899_recv_slave_reply
,
1614 .diseqc_send_burst
= stb0899_send_diseqc_burst
,
1617 struct dvb_frontend
*stb0899_attach(struct stb0899_config
*config
, struct i2c_adapter
*i2c
)
1619 struct stb0899_state
*state
= NULL
;
1620 enum stb0899_inversion inversion
;
1622 state
= kzalloc(sizeof (struct stb0899_state
), GFP_KERNEL
);
1626 inversion
= config
->inversion
;
1627 state
->verbose
= &verbose
;
1628 state
->config
= config
;
1630 state
->frontend
.ops
= stb0899_ops
;
1631 state
->frontend
.demodulator_priv
= state
;
1632 state
->internal
.inversion
= inversion
;
1634 stb0899_wakeup(&state
->frontend
);
1635 if (stb0899_get_dev_id(state
) == -ENODEV
) {
1636 printk("%s: Exiting .. !\n", __func__
);
1640 printk("%s: Attaching STB0899 \n", __func__
);
1641 return &state
->frontend
;
1647 EXPORT_SYMBOL(stb0899_attach
);
1648 MODULE_PARM_DESC(verbose
, "Set Verbosity level");
1649 MODULE_AUTHOR("Manu Abraham");
1650 MODULE_DESCRIPTION("STB0899 Multi-Std frontend");
1651 MODULE_LICENSE("GPL");