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 /* Max transfer size done by I2C transfer functions */
36 #define MAX_XFER_SIZE 64
38 static unsigned int verbose
= 0;//1;
39 module_param(verbose
, int, 0644);
41 /* C/N in dB/10, NIRM/NIRL */
42 static const struct stb0899_tab stb0899_cn_tab
[] = {
65 /* DVB-S AGCIQ_VALUE vs. signal level in dBm/10.
66 * As measured, connected to a modulator.
67 * -8.0 to -50.0 dBm directly connected,
68 * -52.0 to -74.8 with extra attenuation.
69 * Cut-off to AGCIQ_VALUE = 0x80 below -74.8dBm.
70 * Crude linear extrapolation below -84.8dBm and above -8.0dBm.
72 static const struct stb0899_tab stb0899_dvbsrf_tab
[] = {
106 /* DVB-S2 IF_AGC_GAIN vs. signal level in dBm/10.
107 * As measured, connected to a modulator.
108 * -8.0 to -50.1 dBm directly connected,
109 * -53.0 to -76.6 with extra attenuation.
110 * Cut-off to IF_AGC_GAIN = 0x3fff below -76.6dBm.
111 * Crude linear extrapolation below -76.6dBm and above -8.0dBm.
113 static const struct stb0899_tab stb0899_dvbs2rf_tab
[] = {
140 /* DVB-S2 Es/N0 quant in dB/100 vs read value * 100*/
141 static struct stb0899_tab stb0899_quant_tab
[] = {
183 /* DVB-S2 Es/N0 estimate in dB/100 vs read value */
184 static struct stb0899_tab stb0899_est_tab
[] = {
224 static int _stb0899_read_reg(struct stb0899_state
*state
, unsigned int reg
)
228 u8 b0
[] = { reg
>> 8, reg
& 0xff };
231 struct i2c_msg msg
[] = {
233 .addr
= state
->config
->demod_address
,
238 .addr
= state
->config
->demod_address
,
245 ret
= i2c_transfer(state
->i2c
, msg
, 2);
247 if (ret
!= -ERESTARTSYS
)
248 dprintk(state
->verbose
, FE_ERROR
, 1,
249 "Read error, Reg=[0x%02x], Status=%d",
252 return ret
< 0 ? ret
: -EREMOTEIO
;
254 if (unlikely(*state
->verbose
>= FE_DEBUGREG
))
255 dprintk(state
->verbose
, FE_ERROR
, 1, "Reg=[0x%02x], data=%02x",
258 return (unsigned int)buf
;
261 int stb0899_read_reg(struct stb0899_state
*state
, unsigned int reg
)
265 result
= _stb0899_read_reg(state
, reg
);
268 * access to 0xf2xx/0xf6xx
269 * must be followed by read from 0xf2ff/0xf6ff.
271 if ((reg
!= 0xf2ff) && (reg
!= 0xf6ff) &&
272 (((reg
& 0xff00) == 0xf200) || ((reg
& 0xff00) == 0xf600)))
273 _stb0899_read_reg(state
, (reg
| 0x00ff));
278 u32
_stb0899_read_s2reg(struct stb0899_state
*state
,
280 u32 stb0899_base_addr
,
281 u16 stb0899_reg_offset
)
289 GETBYTE(stb0899_i2cdev
, BYTE1
), /* 0xf3 S2 Base Address (MSB) */
290 GETBYTE(stb0899_i2cdev
, BYTE0
), /* 0xfc S2 Base Address (LSB) */
291 GETBYTE(stb0899_base_addr
, BYTE0
), /* 0x00 Base Address (LSB) */
292 GETBYTE(stb0899_base_addr
, BYTE1
), /* 0x04 Base Address (LSB) */
293 GETBYTE(stb0899_base_addr
, BYTE2
), /* 0x00 Base Address (MSB) */
294 GETBYTE(stb0899_base_addr
, BYTE3
), /* 0x00 Base Address (MSB) */
297 0x00, /* 0xf3 Reg Offset */
298 0x00, /* 0x44 Reg Offset */
301 struct i2c_msg msg_0
= {
302 .addr
= state
->config
->demod_address
,
308 struct i2c_msg msg_1
= {
309 .addr
= state
->config
->demod_address
,
315 struct i2c_msg msg_r
= {
316 .addr
= state
->config
->demod_address
,
322 tmpaddr
= stb0899_reg_offset
& 0xff00;
323 if (!(stb0899_reg_offset
& 0x8))
324 tmpaddr
= stb0899_reg_offset
| 0x20;
326 buf_1
[0] = GETBYTE(tmpaddr
, BYTE1
);
327 buf_1
[1] = GETBYTE(tmpaddr
, BYTE0
);
329 status
= i2c_transfer(state
->i2c
, &msg_0
, 1);
331 if (status
!= -ERESTARTSYS
)
332 printk(KERN_ERR
"%s ERR(1), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
333 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, status
);
339 status
= i2c_transfer(state
->i2c
, &msg_1
, 1);
343 status
= i2c_transfer(state
->i2c
, &msg_r
, 1);
347 buf_1
[0] = GETBYTE(stb0899_reg_offset
, BYTE1
);
348 buf_1
[1] = GETBYTE(stb0899_reg_offset
, BYTE0
);
351 status
= i2c_transfer(state
->i2c
, &msg_1
, 1);
353 if (status
!= -ERESTARTSYS
)
354 printk(KERN_ERR
"%s ERR(2), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
355 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, status
);
359 status
= i2c_transfer(state
->i2c
, &msg_r
, 1);
361 if (status
!= -ERESTARTSYS
)
362 printk(KERN_ERR
"%s ERR(3), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
363 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, status
);
364 return status
< 0 ? status
: -EREMOTEIO
;
367 data
= MAKEWORD32(buf
[3], buf
[2], buf
[1], buf
[0]);
368 if (unlikely(*state
->verbose
>= FE_DEBUGREG
))
369 printk(KERN_DEBUG
"%s Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Data=[0x%08x]\n",
370 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, data
);
375 return status
< 0 ? status
: -EREMOTEIO
;
378 int stb0899_write_s2reg(struct stb0899_state
*state
,
380 u32 stb0899_base_addr
,
381 u16 stb0899_reg_offset
,
386 /* Base Address Setup */
388 GETBYTE(stb0899_i2cdev
, BYTE1
), /* 0xf3 S2 Base Address (MSB) */
389 GETBYTE(stb0899_i2cdev
, BYTE0
), /* 0xfc S2 Base Address (LSB) */
390 GETBYTE(stb0899_base_addr
, BYTE0
), /* 0x00 Base Address (LSB) */
391 GETBYTE(stb0899_base_addr
, BYTE1
), /* 0x04 Base Address (LSB) */
392 GETBYTE(stb0899_base_addr
, BYTE2
), /* 0x00 Base Address (MSB) */
393 GETBYTE(stb0899_base_addr
, BYTE3
), /* 0x00 Base Address (MSB) */
396 0x00, /* 0xf3 Reg Offset */
397 0x00, /* 0x44 Reg Offset */
404 struct i2c_msg msg_0
= {
405 .addr
= state
->config
->demod_address
,
411 struct i2c_msg msg_1
= {
412 .addr
= state
->config
->demod_address
,
418 buf_1
[0] = GETBYTE(stb0899_reg_offset
, BYTE1
);
419 buf_1
[1] = GETBYTE(stb0899_reg_offset
, BYTE0
);
420 buf_1
[2] = GETBYTE(stb0899_data
, BYTE0
);
421 buf_1
[3] = GETBYTE(stb0899_data
, BYTE1
);
422 buf_1
[4] = GETBYTE(stb0899_data
, BYTE2
);
423 buf_1
[5] = GETBYTE(stb0899_data
, BYTE3
);
425 if (unlikely(*state
->verbose
>= FE_DEBUGREG
))
426 printk(KERN_DEBUG
"%s Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x]\n",
427 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, stb0899_data
);
429 status
= i2c_transfer(state
->i2c
, &msg_0
, 1);
430 if (unlikely(status
< 1)) {
431 if (status
!= -ERESTARTSYS
)
432 printk(KERN_ERR
"%s ERR (1), Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x], status=%d\n",
433 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, stb0899_data
, status
);
436 status
= i2c_transfer(state
->i2c
, &msg_1
, 1);
437 if (unlikely(status
< 1)) {
438 if (status
!= -ERESTARTSYS
)
439 printk(KERN_ERR
"%s ERR (2), Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x], status=%d\n",
440 __func__
, stb0899_i2cdev
, stb0899_base_addr
, stb0899_reg_offset
, stb0899_data
, status
);
442 return status
< 0 ? status
: -EREMOTEIO
;
448 return status
< 0 ? status
: -EREMOTEIO
;
451 int stb0899_read_regs(struct stb0899_state
*state
, unsigned int reg
, u8
*buf
, u32 count
)
455 u8 b0
[] = { reg
>> 8, reg
& 0xff };
457 struct i2c_msg msg
[] = {
459 .addr
= state
->config
->demod_address
,
464 .addr
= state
->config
->demod_address
,
471 status
= i2c_transfer(state
->i2c
, msg
, 2);
473 if (status
!= -ERESTARTSYS
)
474 printk(KERN_ERR
"%s Read error, Reg=[0x%04x], Count=%u, Status=%d\n",
475 __func__
, reg
, count
, status
);
480 * access to 0xf2xx/0xf6xx
481 * must be followed by read from 0xf2ff/0xf6ff.
483 if ((reg
!= 0xf2ff) && (reg
!= 0xf6ff) &&
484 (((reg
& 0xff00) == 0xf200) || ((reg
& 0xff00) == 0xf600)))
485 _stb0899_read_reg(state
, (reg
| 0x00ff));
487 if (unlikely(*state
->verbose
>= FE_DEBUGREG
)) {
490 printk(KERN_DEBUG
"%s [0x%04x]:", __func__
, reg
);
491 for (i
= 0; i
< count
; i
++) {
492 printk(" %02x", buf
[i
]);
499 return status
< 0 ? status
: -EREMOTEIO
;
502 int stb0899_write_regs(struct stb0899_state
*state
, unsigned int reg
, u8
*data
, u32 count
)
505 u8 buf
[MAX_XFER_SIZE
];
506 struct i2c_msg i2c_msg
= {
507 .addr
= state
->config
->demod_address
,
513 if (2 + count
> sizeof(buf
)) {
515 "%s: i2c wr reg=%04x: len=%d is too big!\n",
516 KBUILD_MODNAME
, reg
, count
);
522 memcpy(&buf
[2], data
, count
);
524 if (unlikely(*state
->verbose
>= FE_DEBUGREG
)) {
527 printk(KERN_DEBUG
"%s [0x%04x]:", __func__
, reg
);
528 for (i
= 0; i
< count
; i
++)
529 printk(" %02x", data
[i
]);
532 ret
= i2c_transfer(state
->i2c
, &i2c_msg
, 1);
536 * access to 0xf2xx/0xf6xx
537 * must be followed by read from 0xf2ff/0xf6ff.
539 if ((((reg
& 0xff00) == 0xf200) || ((reg
& 0xff00) == 0xf600)))
540 stb0899_read_reg(state
, (reg
| 0x00ff));
543 if (ret
!= -ERESTARTSYS
)
544 dprintk(state
->verbose
, FE_ERROR
, 1, "Reg=[0x%04x], Data=[0x%02x ...], Count=%u, Status=%d",
545 reg
, data
[0], count
, ret
);
546 return ret
< 0 ? ret
: -EREMOTEIO
;
552 int stb0899_write_reg(struct stb0899_state
*state
, unsigned int reg
, u8 data
)
554 return stb0899_write_regs(state
, reg
, &data
, 1);
559 * Get STB0899 master clock frequency
560 * ExtClk: external clock frequency (Hz)
562 static u32
stb0899_get_mclk(struct stb0899_state
*state
)
564 u32 mclk
= 0, div
= 0;
566 div
= stb0899_read_reg(state
, STB0899_NCOARSE
);
567 mclk
= (div
+ 1) * state
->config
->xtal_freq
/ 6;
568 dprintk(state
->verbose
, FE_DEBUG
, 1, "div=%d, mclk=%d", div
, mclk
);
575 * Set STB0899 master Clock frequency
576 * Mclk: demodulator master clock
577 * ExtClk: external clock frequency (Hz)
579 static void stb0899_set_mclk(struct stb0899_state
*state
, u32 Mclk
)
581 struct stb0899_internal
*internal
= &state
->internal
;
584 dprintk(state
->verbose
, FE_DEBUG
, 1, "state->config=%p", state
->config
);
585 mdiv
= ((6 * Mclk
) / state
->config
->xtal_freq
) - 1;
586 dprintk(state
->verbose
, FE_DEBUG
, 1, "mdiv=%d", mdiv
);
588 stb0899_write_reg(state
, STB0899_NCOARSE
, mdiv
);
589 internal
->master_clk
= stb0899_get_mclk(state
);
591 dprintk(state
->verbose
, FE_DEBUG
, 1, "MasterCLOCK=%d", internal
->master_clk
);
594 static int stb0899_postproc(struct stb0899_state
*state
, u8 ctl
, int enable
)
596 struct stb0899_config
*config
= state
->config
;
597 const struct stb0899_postproc
*postproc
= config
->postproc
;
599 /* post process event */
602 if (postproc
[ctl
].level
== STB0899_GPIOPULLUP
)
603 stb0899_write_reg(state
, postproc
[ctl
].gpio
, 0x02);
605 stb0899_write_reg(state
, postproc
[ctl
].gpio
, 0x82);
607 if (postproc
[ctl
].level
== STB0899_GPIOPULLUP
)
608 stb0899_write_reg(state
, postproc
[ctl
].gpio
, 0x82);
610 stb0899_write_reg(state
, postproc
[ctl
].gpio
, 0x02);
616 static void stb0899_release(struct dvb_frontend
*fe
)
618 struct stb0899_state
*state
= fe
->demodulator_priv
;
620 dprintk(state
->verbose
, FE_DEBUG
, 1, "Release Frontend");
621 /* post process event */
622 stb0899_postproc(state
, STB0899_POSTPROC_GPIO_POWER
, 0);
630 static int stb0899_get_alpha(struct stb0899_state
*state
)
634 mode_coeff
= stb0899_read_reg(state
, STB0899_DEMOD
);
636 if (STB0899_GETFIELD(MODECOEFF
, mode_coeff
) == 1)
645 static void stb0899_init_calc(struct stb0899_state
*state
)
647 struct stb0899_internal
*internal
= &state
->internal
;
652 /* Read registers (in burst mode) */
653 stb0899_read_regs(state
, STB0899_AGC1REF
, agc
, 2); /* AGC1R and AGC2O */
655 /* Initial calculations */
656 master_clk
= stb0899_get_mclk(state
);
657 internal
->t_agc1
= 0;
658 internal
->t_agc2
= 0;
659 internal
->master_clk
= master_clk
;
660 internal
->mclk
= master_clk
/ 65536L;
661 internal
->rolloff
= stb0899_get_alpha(state
);
663 /* DVBS2 Initial calculations */
664 /* Set AGC value to the middle */
665 internal
->agc_gain
= 8154;
666 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, IF_AGC_CNTRL
);
667 STB0899_SETFIELD_VAL(IF_GAIN_INIT
, reg
, internal
->agc_gain
);
668 stb0899_write_s2reg(state
, STB0899_S2DEMOD
, STB0899_BASE_IF_AGC_CNTRL
, STB0899_OFF0_IF_AGC_CNTRL
, reg
);
670 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, RRC_ALPHA
);
671 internal
->rrc_alpha
= STB0899_GETFIELD(RRC_ALPHA
, reg
);
673 internal
->center_freq
= 0;
674 internal
->av_frame_coarse
= 10;
675 internal
->av_frame_fine
= 20;
676 internal
->step_size
= 2;
678 if ((pParams->SpectralInv == FE_IQ_NORMAL) || (pParams->SpectralInv == FE_IQ_AUTO))
679 pParams->IQLocked = 0;
681 pParams->IQLocked = 1;
685 static int stb0899_wait_diseqc_fifo_empty(struct stb0899_state
*state
, int timeout
)
688 unsigned long start
= jiffies
;
691 reg
= stb0899_read_reg(state
, STB0899_DISSTATUS
);
692 if (!STB0899_GETFIELD(FIFOFULL
, reg
))
694 if ((jiffies
- start
) > timeout
) {
695 dprintk(state
->verbose
, FE_ERROR
, 1, "timed out !!");
703 static int stb0899_send_diseqc_msg(struct dvb_frontend
*fe
, struct dvb_diseqc_master_cmd
*cmd
)
705 struct stb0899_state
*state
= fe
->demodulator_priv
;
708 if (cmd
->msg_len
> 8)
711 /* enable FIFO precharge */
712 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
713 STB0899_SETFIELD_VAL(DISPRECHARGE
, reg
, 1);
714 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
715 for (i
= 0; i
< cmd
->msg_len
; i
++) {
716 /* wait for FIFO empty */
717 if (stb0899_wait_diseqc_fifo_empty(state
, 100) < 0)
720 stb0899_write_reg(state
, STB0899_DISFIFO
, cmd
->msg
[i
]);
722 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
723 STB0899_SETFIELD_VAL(DISPRECHARGE
, reg
, 0);
724 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
729 static int stb0899_wait_diseqc_rxidle(struct stb0899_state
*state
, int timeout
)
732 unsigned long start
= jiffies
;
734 while (!STB0899_GETFIELD(RXEND
, reg
)) {
735 reg
= stb0899_read_reg(state
, STB0899_DISRX_ST0
);
736 if (jiffies
- start
> timeout
) {
737 dprintk(state
->verbose
, FE_ERROR
, 1, "timed out!!");
746 static int stb0899_recv_slave_reply(struct dvb_frontend
*fe
, struct dvb_diseqc_slave_reply
*reply
)
748 struct stb0899_state
*state
= fe
->demodulator_priv
;
749 u8 reg
, length
= 0, i
;
752 if (stb0899_wait_diseqc_rxidle(state
, 100) < 0)
755 reg
= stb0899_read_reg(state
, STB0899_DISRX_ST0
);
756 if (STB0899_GETFIELD(RXEND
, reg
)) {
758 reg
= stb0899_read_reg(state
, STB0899_DISRX_ST1
);
759 length
= STB0899_GETFIELD(FIFOBYTENBR
, reg
);
761 if (length
> sizeof (reply
->msg
)) {
765 reply
->msg_len
= length
;
768 for (i
= 0; i
< length
; i
++)
769 reply
->msg
[i
] = stb0899_read_reg(state
, STB0899_DISFIFO
);
778 static int stb0899_wait_diseqc_txidle(struct stb0899_state
*state
, int timeout
)
781 unsigned long start
= jiffies
;
783 while (!STB0899_GETFIELD(TXIDLE
, reg
)) {
784 reg
= stb0899_read_reg(state
, STB0899_DISSTATUS
);
785 if (jiffies
- start
> timeout
) {
786 dprintk(state
->verbose
, FE_ERROR
, 1, "timed out!!");
794 static int stb0899_send_diseqc_burst(struct dvb_frontend
*fe
, fe_sec_mini_cmd_t burst
)
796 struct stb0899_state
*state
= fe
->demodulator_priv
;
799 /* wait for diseqc idle */
800 if (stb0899_wait_diseqc_txidle(state
, 100) < 0)
803 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
805 /* set to burst mode */
806 STB0899_SETFIELD_VAL(DISEQCMODE
, reg
, 0x03);
807 STB0899_SETFIELD_VAL(DISPRECHARGE
, reg
, 0x01);
808 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
812 stb0899_write_reg(state
, STB0899_DISFIFO
, 0x00);
816 stb0899_write_reg(state
, STB0899_DISFIFO
, 0xff);
819 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
820 STB0899_SETFIELD_VAL(DISPRECHARGE
, reg
, 0x00);
821 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
822 /* wait for diseqc idle */
823 if (stb0899_wait_diseqc_txidle(state
, 100) < 0)
827 stb0899_write_reg(state
, STB0899_DISCNTRL1
, old_state
);
832 static int stb0899_diseqc_init(struct stb0899_state
*state
)
835 struct dvb_diseqc_slave_reply rx_data;
839 u32 mclk
, tx_freq
= 22000;/* count = 0, i; */
840 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL2
);
841 STB0899_SETFIELD_VAL(ONECHIP_TRX
, reg
, 0);
842 stb0899_write_reg(state
, STB0899_DISCNTRL2
, reg
);
845 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
846 STB0899_SETFIELD_VAL(DISEQCRESET
, reg
, 1);
847 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
849 reg
= stb0899_read_reg(state
, STB0899_DISCNTRL1
);
850 STB0899_SETFIELD_VAL(DISEQCRESET
, reg
, 0);
851 stb0899_write_reg(state
, STB0899_DISCNTRL1
, reg
);
853 mclk
= stb0899_get_mclk(state
);
854 f22_tx
= mclk
/ (tx_freq
* 32);
855 stb0899_write_reg(state
, STB0899_DISF22
, f22_tx
); /* DiSEqC Tx freq */
856 state
->rx_freq
= 20000;
861 static int stb0899_sleep(struct dvb_frontend
*fe
)
863 struct stb0899_state
*state
= fe
->demodulator_priv
;
867 dprintk(state
->verbose
, FE_DEBUG
, 1, "Going to Sleep .. (Really tired .. :-))");
868 /* post process event */
869 stb0899_postproc(state
, STB0899_POSTPROC_GPIO_POWER
, 0);
874 static int stb0899_wakeup(struct dvb_frontend
*fe
)
877 struct stb0899_state
*state
= fe
->demodulator_priv
;
879 if ((rc
= stb0899_write_reg(state
, STB0899_SYNTCTRL
, STB0899_SELOSCI
)))
881 /* Activate all clocks; DVB-S2 registers are inaccessible otherwise. */
882 if ((rc
= stb0899_write_reg(state
, STB0899_STOPCLK1
, 0x00)))
884 if ((rc
= stb0899_write_reg(state
, STB0899_STOPCLK2
, 0x00)))
887 /* post process event */
888 stb0899_postproc(state
, STB0899_POSTPROC_GPIO_POWER
, 1);
893 static int stb0899_init(struct dvb_frontend
*fe
)
896 struct stb0899_state
*state
= fe
->demodulator_priv
;
897 struct stb0899_config
*config
= state
->config
;
899 dprintk(state
->verbose
, FE_DEBUG
, 1, "Initializing STB0899 ... ");
902 dprintk(state
->verbose
, FE_DEBUG
, 1, "init device");
903 for (i
= 0; config
->init_dev
[i
].address
!= 0xffff; i
++)
904 stb0899_write_reg(state
, config
->init_dev
[i
].address
, config
->init_dev
[i
].data
);
906 dprintk(state
->verbose
, FE_DEBUG
, 1, "init S2 demod");
908 for (i
= 0; config
->init_s2_demod
[i
].offset
!= 0xffff; i
++)
909 stb0899_write_s2reg(state
, STB0899_S2DEMOD
,
910 config
->init_s2_demod
[i
].base_address
,
911 config
->init_s2_demod
[i
].offset
,
912 config
->init_s2_demod
[i
].data
);
914 dprintk(state
->verbose
, FE_DEBUG
, 1, "init S1 demod");
916 for (i
= 0; config
->init_s1_demod
[i
].address
!= 0xffff; i
++)
917 stb0899_write_reg(state
, config
->init_s1_demod
[i
].address
, config
->init_s1_demod
[i
].data
);
919 dprintk(state
->verbose
, FE_DEBUG
, 1, "init S2 FEC");
921 for (i
= 0; config
->init_s2_fec
[i
].offset
!= 0xffff; i
++)
922 stb0899_write_s2reg(state
, STB0899_S2FEC
,
923 config
->init_s2_fec
[i
].base_address
,
924 config
->init_s2_fec
[i
].offset
,
925 config
->init_s2_fec
[i
].data
);
927 dprintk(state
->verbose
, FE_DEBUG
, 1, "init TST");
929 for (i
= 0; config
->init_tst
[i
].address
!= 0xffff; i
++)
930 stb0899_write_reg(state
, config
->init_tst
[i
].address
, config
->init_tst
[i
].data
);
932 stb0899_init_calc(state
);
933 stb0899_diseqc_init(state
);
938 static int stb0899_table_lookup(const struct stb0899_tab
*tab
, int max
, int val
)
943 if (val
< tab
[min
].read
)
945 else if (val
>= tab
[max
].read
)
948 while ((max
- min
) > 1) {
949 med
= (max
+ min
) / 2;
950 if (val
>= tab
[min
].read
&& val
< tab
[med
].read
)
955 res
= ((val
- tab
[min
].read
) *
956 (tab
[max
].real
- tab
[min
].real
) /
957 (tab
[max
].read
- tab
[min
].read
)) +
964 static int stb0899_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
966 struct stb0899_state
*state
= fe
->demodulator_priv
;
967 struct stb0899_internal
*internal
= &state
->internal
;
972 switch (state
->delsys
) {
975 if (internal
->lock
) {
976 reg
= stb0899_read_reg(state
, STB0899_VSTATUS
);
977 if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT
, reg
)) {
979 reg
= stb0899_read_reg(state
, STB0899_AGCIQIN
);
980 val
= (s32
)(s8
)STB0899_GETFIELD(AGCIQVALUE
, reg
);
982 *strength
= stb0899_table_lookup(stb0899_dvbsrf_tab
, ARRAY_SIZE(stb0899_dvbsrf_tab
) - 1, val
);
984 dprintk(state
->verbose
, FE_DEBUG
, 1, "AGCIQVALUE = 0x%02x, C = %d * 0.1 dBm",
985 val
& 0xff, *strength
);
990 if (internal
->lock
) {
991 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, IF_AGC_GAIN
);
992 val
= STB0899_GETFIELD(IF_AGC_GAIN
, reg
);
994 *strength
= stb0899_table_lookup(stb0899_dvbs2rf_tab
, ARRAY_SIZE(stb0899_dvbs2rf_tab
) - 1, val
);
996 dprintk(state
->verbose
, FE_DEBUG
, 1, "IF_AGC_GAIN = 0x%04x, C = %d * 0.1 dBm",
997 val
& 0x3fff, *strength
);
1001 dprintk(state
->verbose
, FE_DEBUG
, 1, "Unsupported delivery system");
1008 static int stb0899_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
1010 struct stb0899_state
*state
= fe
->demodulator_priv
;
1011 struct stb0899_internal
*internal
= &state
->internal
;
1013 unsigned int val
, quant
, quantn
= -1, est
, estn
= -1;
1018 reg
= stb0899_read_reg(state
, STB0899_VSTATUS
);
1019 switch (state
->delsys
) {
1022 if (internal
->lock
) {
1023 if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT
, reg
)) {
1025 stb0899_read_regs(state
, STB0899_NIRM
, buf
, 2);
1026 val
= MAKEWORD16(buf
[0], buf
[1]);
1028 *snr
= stb0899_table_lookup(stb0899_cn_tab
, ARRAY_SIZE(stb0899_cn_tab
) - 1, val
);
1029 dprintk(state
->verbose
, FE_DEBUG
, 1, "NIR = 0x%02x%02x = %u, C/N = %d * 0.1 dBm\n",
1030 buf
[0], buf
[1], val
, *snr
);
1035 if (internal
->lock
) {
1036 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, UWP_CNTRL1
);
1037 quant
= STB0899_GETFIELD(UWP_ESN0_QUANT
, reg
);
1038 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, UWP_STAT2
);
1039 est
= STB0899_GETFIELD(ESN0_EST
, reg
);
1041 val
= 301; /* C/N = 30.1 dB */
1043 val
= 270; /* C/N = 27.0 dB */
1045 /* quantn = 100 * log(quant^2) */
1046 quantn
= stb0899_table_lookup(stb0899_quant_tab
, ARRAY_SIZE(stb0899_quant_tab
) - 1, quant
* 100);
1047 /* estn = 100 * log(est) */
1048 estn
= stb0899_table_lookup(stb0899_est_tab
, ARRAY_SIZE(stb0899_est_tab
) - 1, est
);
1049 /* snr(dBm/10) = -10*(log(est)-log(quant^2)) => snr(dBm/10) = (100*log(quant^2)-100*log(est))/10 */
1050 val
= (quantn
- estn
) / 10;
1053 dprintk(state
->verbose
, FE_DEBUG
, 1, "Es/N0 quant = %d (%d) estimate = %u (%d), C/N = %d * 0.1 dBm",
1054 quant
, quantn
, est
, estn
, val
);
1058 dprintk(state
->verbose
, FE_DEBUG
, 1, "Unsupported delivery system");
1065 static int stb0899_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
1067 struct stb0899_state
*state
= fe
->demodulator_priv
;
1068 struct stb0899_internal
*internal
= &state
->internal
;
1072 switch (state
->delsys
) {
1075 dprintk(state
->verbose
, FE_DEBUG
, 1, "Delivery system DVB-S/DSS");
1076 if (internal
->lock
) {
1077 reg
= stb0899_read_reg(state
, STB0899_VSTATUS
);
1078 if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT
, reg
)) {
1079 dprintk(state
->verbose
, FE_DEBUG
, 1, "--------> FE_HAS_CARRIER | FE_HAS_LOCK");
1080 *status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
| FE_HAS_LOCK
;
1082 reg
= stb0899_read_reg(state
, STB0899_PLPARM
);
1083 if (STB0899_GETFIELD(VITCURPUN
, reg
)) {
1084 dprintk(state
->verbose
, FE_DEBUG
, 1, "--------> FE_HAS_VITERBI | FE_HAS_SYNC");
1085 *status
|= FE_HAS_VITERBI
| FE_HAS_SYNC
;
1086 /* post process event */
1087 stb0899_postproc(state
, STB0899_POSTPROC_GPIO_LOCK
, 1);
1093 dprintk(state
->verbose
, FE_DEBUG
, 1, "Delivery system DVB-S2");
1094 if (internal
->lock
) {
1095 reg
= STB0899_READ_S2REG(STB0899_S2DEMOD
, DMD_STAT2
);
1096 if (STB0899_GETFIELD(UWP_LOCK
, reg
) && STB0899_GETFIELD(CSM_LOCK
, reg
)) {
1097 *status
|= FE_HAS_CARRIER
;
1098 dprintk(state
->verbose
, FE_DEBUG
, 1,
1099 "UWP & CSM Lock ! ---> DVB-S2 FE_HAS_CARRIER");
1101 reg
= stb0899_read_reg(state
, STB0899_CFGPDELSTATUS1
);
1102 if (STB0899_GETFIELD(CFGPDELSTATUS_LOCK
, reg
)) {
1103 *status
|= FE_HAS_LOCK
;
1104 dprintk(state
->verbose
, FE_DEBUG
, 1,
1105 "Packet Delineator Locked ! -----> DVB-S2 FE_HAS_LOCK");
1108 if (STB0899_GETFIELD(CONTINUOUS_STREAM
, reg
)) {
1109 *status
|= FE_HAS_VITERBI
;
1110 dprintk(state
->verbose
, FE_DEBUG
, 1,
1111 "Packet Delineator found VITERBI ! -----> DVB-S2 FE_HAS_VITERBI");
1113 if (STB0899_GETFIELD(ACCEPTED_STREAM
, reg
)) {
1114 *status
|= FE_HAS_SYNC
;
1115 dprintk(state
->verbose
, FE_DEBUG
, 1,
1116 "Packet Delineator found SYNC ! -----> DVB-S2 FE_HAS_SYNC");
1117 /* post process event */
1118 stb0899_postproc(state
, STB0899_POSTPROC_GPIO_LOCK
, 1);
1124 dprintk(state
->verbose
, FE_DEBUG
, 1, "Unsupported delivery system");
1132 * viterbi error for DVB-S/DSS
1133 * packet error for DVB-S2
1134 * Bit Error Rate or Packet Error Rate * 10 ^ 7
1136 static int stb0899_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
1138 struct stb0899_state
*state
= fe
->demodulator_priv
;
1139 struct stb0899_internal
*internal
= &state
->internal
;
1145 switch (state
->delsys
) {
1148 if (internal
->lock
) {
1149 lsb
= stb0899_read_reg(state
, STB0899_ECNT1L
);
1150 msb
= stb0899_read_reg(state
, STB0899_ECNT1M
);
1151 *ber
= MAKEWORD16(msb
, lsb
);
1153 if (STB0899_GETFIELD(VSTATUS_PRFVIT
, internal
->v_status
)) {
1156 /* ber = ber * 10 ^ 7 */
1157 *ber
/= (-1 + (1 << (2 * STB0899_GETFIELD(NOE
, internal
->err_ctrl
))));
1163 if (internal
->lock
) {
1164 lsb
= stb0899_read_reg(state
, STB0899_ECNT1L
);
1165 msb
= stb0899_read_reg(state
, STB0899_ECNT1M
);
1166 *ber
= MAKEWORD16(msb
, lsb
);
1167 /* ber = ber * 10 ^ 7 */
1169 *ber
/= (-1 + (1 << (4 + 2 * STB0899_GETFIELD(NOE
, internal
->err_ctrl
))));
1173 dprintk(state
->verbose
, FE_DEBUG
, 1, "Unsupported delivery system");
1180 static int stb0899_set_voltage(struct dvb_frontend
*fe
, fe_sec_voltage_t voltage
)
1182 struct stb0899_state
*state
= fe
->demodulator_priv
;
1185 case SEC_VOLTAGE_13
:
1186 stb0899_write_reg(state
, STB0899_GPIO00CFG
, 0x82);
1187 stb0899_write_reg(state
, STB0899_GPIO01CFG
, 0x02);
1188 stb0899_write_reg(state
, STB0899_GPIO02CFG
, 0x00);
1190 case SEC_VOLTAGE_18
:
1191 stb0899_write_reg(state
, STB0899_GPIO00CFG
, 0x02);
1192 stb0899_write_reg(state
, STB0899_GPIO01CFG
, 0x02);
1193 stb0899_write_reg(state
, STB0899_GPIO02CFG
, 0x82);
1195 case SEC_VOLTAGE_OFF
:
1196 stb0899_write_reg(state
, STB0899_GPIO00CFG
, 0x82);
1197 stb0899_write_reg(state
, STB0899_GPIO01CFG
, 0x82);
1198 stb0899_write_reg(state
, STB0899_GPIO02CFG
, 0x82);
1207 static int stb0899_set_tone(struct dvb_frontend
*fe
, fe_sec_tone_mode_t tone
)
1209 struct stb0899_state
*state
= fe
->demodulator_priv
;
1210 struct stb0899_internal
*internal
= &state
->internal
;
1214 /* wait for diseqc idle */
1215 if (stb0899_wait_diseqc_txidle(state
, 100) < 0)
1220 div
= (internal
->master_clk
/ 100) / 5632;
1221 div
= (div
+ 5) / 10;
1222 stb0899_write_reg(state
, STB0899_DISEQCOCFG
, 0x66);
1223 reg
= stb0899_read_reg(state
, STB0899_ACRPRESC
);
1224 STB0899_SETFIELD_VAL(ACRPRESC
, reg
, 0x03);
1225 stb0899_write_reg(state
, STB0899_ACRPRESC
, reg
);
1226 stb0899_write_reg(state
, STB0899_ACRDIV1
, div
);
1229 stb0899_write_reg(state
, STB0899_DISEQCOCFG
, 0x20);
1237 int stb0899_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
1240 struct stb0899_state
*state
= fe
->demodulator_priv
;
1242 i2c_stat
= stb0899_read_reg(state
, STB0899_I2CRPT
);
1247 dprintk(state
->verbose
, FE_DEBUG
, 1, "Enabling I2C Repeater ...");
1248 i2c_stat
|= STB0899_I2CTON
;
1249 if (stb0899_write_reg(state
, STB0899_I2CRPT
, i2c_stat
) < 0)
1252 dprintk(state
->verbose
, FE_DEBUG
, 1, "Disabling I2C Repeater ...");
1253 i2c_stat
&= ~STB0899_I2CTON
;
1254 if (stb0899_write_reg(state
, STB0899_I2CRPT
, i2c_stat
) < 0)
1259 dprintk(state
->verbose
, FE_ERROR
, 1, "I2C Repeater control failed");
1264 static inline void CONVERT32(u32 x
, char *str
)
1266 *str
++ = (x
>> 24) & 0xff;
1267 *str
++ = (x
>> 16) & 0xff;
1268 *str
++ = (x
>> 8) & 0xff;
1269 *str
++ = (x
>> 0) & 0xff;
1273 static int stb0899_get_dev_id(struct stb0899_state
*state
)
1275 u8 chip_id
, release
;
1277 u32 demod_ver
= 0, fec_ver
= 0;
1278 char demod_str
[5] = { 0 };
1279 char fec_str
[5] = { 0 };
1281 id
= stb0899_read_reg(state
, STB0899_DEV_ID
);
1282 dprintk(state
->verbose
, FE_DEBUG
, 1, "ID reg=[0x%02x]", id
);
1283 chip_id
= STB0899_GETFIELD(CHIP_ID
, id
);
1284 release
= STB0899_GETFIELD(CHIP_REL
, id
);
1286 dprintk(state
->verbose
, FE_ERROR
, 1, "Device ID=[%d], Release=[%d]",
1289 CONVERT32(STB0899_READ_S2REG(STB0899_S2DEMOD
, DMD_CORE_ID
), (char *)&demod_str
);
1291 demod_ver
= STB0899_READ_S2REG(STB0899_S2DEMOD
, DMD_VERSION_ID
);
1292 dprintk(state
->verbose
, FE_ERROR
, 1, "Demodulator Core ID=[%s], Version=[%d]", (char *) &demod_str
, demod_ver
);
1293 CONVERT32(STB0899_READ_S2REG(STB0899_S2FEC
, FEC_CORE_ID_REG
), (char *)&fec_str
);
1294 fec_ver
= STB0899_READ_S2REG(STB0899_S2FEC
, FEC_VER_ID_REG
);
1295 if (! (chip_id
> 0)) {
1296 dprintk(state
->verbose
, FE_ERROR
, 1, "couldn't find a STB 0899");
1300 dprintk(state
->verbose
, FE_ERROR
, 1, "FEC Core ID=[%s], Version=[%d]", (char*) &fec_str
, fec_ver
);
1305 static void stb0899_set_delivery(struct stb0899_state
*state
)
1310 stop_clk
[0] = stb0899_read_reg(state
, STB0899_STOPCLK1
);
1311 stop_clk
[1] = stb0899_read_reg(state
, STB0899_STOPCLK2
);
1313 switch (state
->delsys
) {
1315 dprintk(state
->verbose
, FE_DEBUG
, 1, "Delivery System -- DVB-S");
1316 /* FECM/Viterbi ON */
1317 reg
= stb0899_read_reg(state
, STB0899_FECM
);
1318 STB0899_SETFIELD_VAL(FECM_RSVD0
, reg
, 0);
1319 STB0899_SETFIELD_VAL(FECM_VITERBI_ON
, reg
, 1);
1320 stb0899_write_reg(state
, STB0899_FECM
, reg
);
1322 stb0899_write_reg(state
, STB0899_RSULC
, 0xb1);
1323 stb0899_write_reg(state
, STB0899_TSULC
, 0x40);
1324 stb0899_write_reg(state
, STB0899_RSLLC
, 0x42);
1325 stb0899_write_reg(state
, STB0899_TSLPL
, 0x12);
1327 reg
= stb0899_read_reg(state
, STB0899_TSTRES
);
1328 STB0899_SETFIELD_VAL(FRESLDPC
, reg
, 1);
1329 stb0899_write_reg(state
, STB0899_TSTRES
, reg
);
1331 STB0899_SETFIELD_VAL(STOP_CHK8PSK
, stop_clk
[0], 1);
1332 STB0899_SETFIELD_VAL(STOP_CKFEC108
, stop_clk
[0], 1);
1333 STB0899_SETFIELD_VAL(STOP_CKFEC216
, stop_clk
[0], 1);
1335 STB0899_SETFIELD_VAL(STOP_CKPKDLIN108
, stop_clk
[1], 1);
1336 STB0899_SETFIELD_VAL(STOP_CKPKDLIN216
, stop_clk
[1], 1);
1338 STB0899_SETFIELD_VAL(STOP_CKINTBUF216
, stop_clk
[0], 1);
1339 STB0899_SETFIELD_VAL(STOP_CKCORE216
, stop_clk
[0], 0);
1341 STB0899_SETFIELD_VAL(STOP_CKS2DMD108
, stop_clk
[1], 1);
1344 /* FECM/Viterbi OFF */
1345 reg
= stb0899_read_reg(state
, STB0899_FECM
);
1346 STB0899_SETFIELD_VAL(FECM_RSVD0
, reg
, 0);
1347 STB0899_SETFIELD_VAL(FECM_VITERBI_ON
, reg
, 0);
1348 stb0899_write_reg(state
, STB0899_FECM
, reg
);
1350 stb0899_write_reg(state
, STB0899_RSULC
, 0xb1);
1351 stb0899_write_reg(state
, STB0899_TSULC
, 0x42);
1352 stb0899_write_reg(state
, STB0899_RSLLC
, 0x40);
1353 stb0899_write_reg(state
, STB0899_TSLPL
, 0x02);
1355 reg
= stb0899_read_reg(state
, STB0899_TSTRES
);
1356 STB0899_SETFIELD_VAL(FRESLDPC
, reg
, 0);
1357 stb0899_write_reg(state
, STB0899_TSTRES
, reg
);
1359 STB0899_SETFIELD_VAL(STOP_CHK8PSK
, stop_clk
[0], 1);
1360 STB0899_SETFIELD_VAL(STOP_CKFEC108
, stop_clk
[0], 0);
1361 STB0899_SETFIELD_VAL(STOP_CKFEC216
, stop_clk
[0], 0);
1363 STB0899_SETFIELD_VAL(STOP_CKPKDLIN108
, stop_clk
[1], 0);
1364 STB0899_SETFIELD_VAL(STOP_CKPKDLIN216
, stop_clk
[1], 0);
1366 STB0899_SETFIELD_VAL(STOP_CKINTBUF216
, stop_clk
[0], 0);
1367 STB0899_SETFIELD_VAL(STOP_CKCORE216
, stop_clk
[0], 0);
1369 STB0899_SETFIELD_VAL(STOP_CKS2DMD108
, stop_clk
[1], 0);
1372 /* FECM/Viterbi ON */
1373 reg
= stb0899_read_reg(state
, STB0899_FECM
);
1374 STB0899_SETFIELD_VAL(FECM_RSVD0
, reg
, 1);
1375 STB0899_SETFIELD_VAL(FECM_VITERBI_ON
, reg
, 1);
1376 stb0899_write_reg(state
, STB0899_FECM
, reg
);
1378 stb0899_write_reg(state
, STB0899_RSULC
, 0xa1);
1379 stb0899_write_reg(state
, STB0899_TSULC
, 0x61);
1380 stb0899_write_reg(state
, STB0899_RSLLC
, 0x42);
1382 reg
= stb0899_read_reg(state
, STB0899_TSTRES
);
1383 STB0899_SETFIELD_VAL(FRESLDPC
, reg
, 1);
1384 stb0899_write_reg(state
, STB0899_TSTRES
, reg
);
1386 STB0899_SETFIELD_VAL(STOP_CHK8PSK
, stop_clk
[0], 1);
1387 STB0899_SETFIELD_VAL(STOP_CKFEC108
, stop_clk
[0], 1);
1388 STB0899_SETFIELD_VAL(STOP_CKFEC216
, stop_clk
[0], 1);
1390 STB0899_SETFIELD_VAL(STOP_CKPKDLIN108
, stop_clk
[1], 1);
1391 STB0899_SETFIELD_VAL(STOP_CKPKDLIN216
, stop_clk
[1], 1);
1393 STB0899_SETFIELD_VAL(STOP_CKCORE216
, stop_clk
[0], 0);
1395 STB0899_SETFIELD_VAL(STOP_CKS2DMD108
, stop_clk
[1], 1);
1398 dprintk(state
->verbose
, FE_ERROR
, 1, "Unsupported delivery system");
1401 STB0899_SETFIELD_VAL(STOP_CKADCI108
, stop_clk
[0], 0);
1402 stb0899_write_regs(state
, STB0899_STOPCLK1
, stop_clk
, 2);
1406 * stb0899_set_iterations
1407 * set the LDPC iteration scale function
1409 static void stb0899_set_iterations(struct stb0899_state
*state
)
1411 struct stb0899_internal
*internal
= &state
->internal
;
1412 struct stb0899_config
*config
= state
->config
;
1417 iter_scale
= 17 * (internal
->master_clk
/ 1000);
1418 iter_scale
+= 410000;
1419 iter_scale
/= (internal
->srate
/ 1000000);
1422 if (iter_scale
> config
->ldpc_max_iter
)
1423 iter_scale
= config
->ldpc_max_iter
;
1425 reg
= STB0899_READ_S2REG(STB0899_S2FEC
, MAX_ITER
);
1426 STB0899_SETFIELD_VAL(MAX_ITERATIONS
, reg
, iter_scale
);
1427 stb0899_write_s2reg(state
, STB0899_S2FEC
, STB0899_BASE_MAX_ITER
, STB0899_OFF0_MAX_ITER
, reg
);
1430 static enum dvbfe_search
stb0899_search(struct dvb_frontend
*fe
)
1432 struct stb0899_state
*state
= fe
->demodulator_priv
;
1433 struct stb0899_params
*i_params
= &state
->params
;
1434 struct stb0899_internal
*internal
= &state
->internal
;
1435 struct stb0899_config
*config
= state
->config
;
1436 struct dtv_frontend_properties
*props
= &fe
->dtv_property_cache
;
1438 u32 SearchRange
, gain
;
1440 i_params
->freq
= props
->frequency
;
1441 i_params
->srate
= props
->symbol_rate
;
1442 state
->delsys
= props
->delivery_system
;
1443 dprintk(state
->verbose
, FE_DEBUG
, 1, "delivery system=%d", state
->delsys
);
1445 SearchRange
= 10000000;
1446 dprintk(state
->verbose
, FE_DEBUG
, 1, "Frequency=%d, Srate=%d", i_params
->freq
, i_params
->srate
);
1447 /* checking Search Range is meaningless for a fixed 3 Mhz */
1448 if (INRANGE(i_params
->srate
, 1000000, 45000000)) {
1449 dprintk(state
->verbose
, FE_DEBUG
, 1, "Parameters IN RANGE");
1450 stb0899_set_delivery(state
);
1452 if (state
->config
->tuner_set_rfsiggain
) {
1453 if (internal
->srate
> 15000000)
1454 gain
= 8; /* 15Mb < srate < 45Mb, gain = 8dB */
1455 else if (internal
->srate
> 5000000)
1456 gain
= 12; /* 5Mb < srate < 15Mb, gain = 12dB */
1458 gain
= 14; /* 1Mb < srate < 5Mb, gain = 14db */
1459 state
->config
->tuner_set_rfsiggain(fe
, gain
);
1462 if (i_params
->srate
<= 5000000)
1463 stb0899_set_mclk(state
, config
->lo_clk
);
1465 stb0899_set_mclk(state
, config
->hi_clk
);
1467 switch (state
->delsys
) {
1470 dprintk(state
->verbose
, FE_DEBUG
, 1, "DVB-S delivery system");
1471 internal
->freq
= i_params
->freq
;
1472 internal
->srate
= i_params
->srate
;
1474 * search = user search range +
1476 * 2 * Tuner_step_size +
1477 * 10% of the symbol rate
1479 internal
->srch_range
= SearchRange
+ 1500000 + (i_params
->srate
/ 5);
1480 internal
->derot_percent
= 30;
1482 /* What to do for tuners having no bandwidth setup ? */
1483 /* enable tuner I/O */
1484 stb0899_i2c_gate_ctrl(&state
->frontend
, 1);
1486 if (state
->config
->tuner_set_bandwidth
)
1487 state
->config
->tuner_set_bandwidth(fe
, (13 * (stb0899_carr_width(state
) + SearchRange
)) / 10);
1488 if (state
->config
->tuner_get_bandwidth
)
1489 state
->config
->tuner_get_bandwidth(fe
, &internal
->tuner_bw
);
1491 /* disable tuner I/O */
1492 stb0899_i2c_gate_ctrl(&state
->frontend
, 0);
1494 /* Set DVB-S1 AGC */
1495 stb0899_write_reg(state
, STB0899_AGCRFCFG
, 0x11);
1497 /* Run the search algorithm */
1498 dprintk(state
->verbose
, FE_DEBUG
, 1, "running DVB-S search algo ..");
1499 if (stb0899_dvbs_algo(state
) == RANGEOK
) {
1501 dprintk(state
->verbose
, FE_DEBUG
, 1,
1502 "-------------------------------------> DVB-S LOCK !");
1504 // stb0899_write_reg(state, STB0899_ERRCTRL1, 0x3d); /* Viterbi Errors */
1505 // internal->v_status = stb0899_read_reg(state, STB0899_VSTATUS);
1506 // internal->err_ctrl = stb0899_read_reg(state, STB0899_ERRCTRL1);
1507 // dprintk(state->verbose, FE_DEBUG, 1, "VSTATUS=0x%02x", internal->v_status);
1508 // dprintk(state->verbose, FE_DEBUG, 1, "ERR_CTRL=0x%02x", internal->err_ctrl);
1510 return DVBFE_ALGO_SEARCH_SUCCESS
;
1514 return DVBFE_ALGO_SEARCH_FAILED
;
1518 internal
->freq
= i_params
->freq
;
1519 internal
->srate
= i_params
->srate
;
1520 internal
->srch_range
= SearchRange
;
1522 /* enable tuner I/O */
1523 stb0899_i2c_gate_ctrl(&state
->frontend
, 1);
1525 if (state
->config
->tuner_set_bandwidth
)
1526 state
->config
->tuner_set_bandwidth(fe
, (stb0899_carr_width(state
) + SearchRange
));
1527 if (state
->config
->tuner_get_bandwidth
)
1528 state
->config
->tuner_get_bandwidth(fe
, &internal
->tuner_bw
);
1530 /* disable tuner I/O */
1531 stb0899_i2c_gate_ctrl(&state
->frontend
, 0);
1533 // pParams->SpectralInv = pSearch->IQ_Inversion;
1535 /* Set DVB-S2 AGC */
1536 stb0899_write_reg(state
, STB0899_AGCRFCFG
, 0x1c);
1538 /* Set IterScale =f(MCLK,SYMB) */
1539 stb0899_set_iterations(state
);
1541 /* Run the search algorithm */
1542 dprintk(state
->verbose
, FE_DEBUG
, 1, "running DVB-S2 search algo ..");
1543 if (stb0899_dvbs2_algo(state
) == DVBS2_FEC_LOCK
) {
1545 dprintk(state
->verbose
, FE_DEBUG
, 1,
1546 "-------------------------------------> DVB-S2 LOCK !");
1548 // stb0899_write_reg(state, STB0899_ERRCTRL1, 0xb6); /* Packet Errors */
1549 // internal->v_status = stb0899_read_reg(state, STB0899_VSTATUS);
1550 // internal->err_ctrl = stb0899_read_reg(state, STB0899_ERRCTRL1);
1552 return DVBFE_ALGO_SEARCH_SUCCESS
;
1556 return DVBFE_ALGO_SEARCH_FAILED
;
1560 dprintk(state
->verbose
, FE_ERROR
, 1, "Unsupported delivery system");
1561 return DVBFE_ALGO_SEARCH_INVALID
;
1565 return DVBFE_ALGO_SEARCH_ERROR
;
1568 static int stb0899_get_frontend(struct dvb_frontend
*fe
)
1570 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
1571 struct stb0899_state
*state
= fe
->demodulator_priv
;
1572 struct stb0899_internal
*internal
= &state
->internal
;
1574 dprintk(state
->verbose
, FE_DEBUG
, 1, "Get params");
1575 p
->symbol_rate
= internal
->srate
;
1576 p
->frequency
= internal
->freq
;
1581 static enum dvbfe_algo
stb0899_frontend_algo(struct dvb_frontend
*fe
)
1583 return DVBFE_ALGO_CUSTOM
;
1586 static struct dvb_frontend_ops stb0899_ops
= {
1587 .delsys
= { SYS_DVBS
, SYS_DVBS2
, SYS_DSS
},
1589 .name
= "STB0899 Multistandard",
1590 .frequency_min
= 950000,
1591 .frequency_max
= 2150000,
1592 .frequency_stepsize
= 0,
1593 .frequency_tolerance
= 0,
1594 .symbol_rate_min
= 5000000,
1595 .symbol_rate_max
= 45000000,
1597 .caps
= FE_CAN_INVERSION_AUTO
|
1599 FE_CAN_2G_MODULATION
|
1603 .release
= stb0899_release
,
1604 .init
= stb0899_init
,
1605 .sleep
= stb0899_sleep
,
1606 // .wakeup = stb0899_wakeup,
1608 .i2c_gate_ctrl
= stb0899_i2c_gate_ctrl
,
1610 .get_frontend_algo
= stb0899_frontend_algo
,
1611 .search
= stb0899_search
,
1612 .get_frontend
= stb0899_get_frontend
,
1615 .read_status
= stb0899_read_status
,
1616 .read_snr
= stb0899_read_snr
,
1617 .read_signal_strength
= stb0899_read_signal_strength
,
1618 .read_ber
= stb0899_read_ber
,
1620 .set_voltage
= stb0899_set_voltage
,
1621 .set_tone
= stb0899_set_tone
,
1623 .diseqc_send_master_cmd
= stb0899_send_diseqc_msg
,
1624 .diseqc_recv_slave_reply
= stb0899_recv_slave_reply
,
1625 .diseqc_send_burst
= stb0899_send_diseqc_burst
,
1628 struct dvb_frontend
*stb0899_attach(struct stb0899_config
*config
, struct i2c_adapter
*i2c
)
1630 struct stb0899_state
*state
= NULL
;
1632 state
= kzalloc(sizeof (struct stb0899_state
), GFP_KERNEL
);
1636 state
->verbose
= &verbose
;
1637 state
->config
= config
;
1639 state
->frontend
.ops
= stb0899_ops
;
1640 state
->frontend
.demodulator_priv
= state
;
1641 /* use configured inversion as default -- we'll later autodetect inversion */
1642 state
->internal
.inversion
= config
->inversion
;
1644 stb0899_wakeup(&state
->frontend
);
1645 if (stb0899_get_dev_id(state
) == -ENODEV
) {
1646 printk("%s: Exiting .. !\n", __func__
);
1650 printk("%s: Attaching STB0899 \n", __func__
);
1651 return &state
->frontend
;
1657 EXPORT_SYMBOL(stb0899_attach
);
1658 MODULE_PARM_DESC(verbose
, "Set Verbosity level");
1659 MODULE_AUTHOR("Manu Abraham");
1660 MODULE_DESCRIPTION("STB0899 Multi-Std frontend");
1661 MODULE_LICENSE("GPL");