From 92b64711ecc88830d626be5214ce0fbc1a49dd2e Mon Sep 17 00:00:00 2001 From: Ralph Metzler Date: Sat, 16 Sep 2017 15:31:52 +0200 Subject: [PATCH] strict checkpatch style adjustments --- frontends/stv0910.c | 1334 +++++++++++++++++++++---------------------- 1 file changed, 656 insertions(+), 678 deletions(-) diff --git a/frontends/stv0910.c b/frontends/stv0910.c index 7e9fa26..10972b8 100644 --- a/frontends/stv0910.c +++ b/frontends/stv0910.c @@ -1,7 +1,7 @@ /* * Driver for the ST STV0910 DVB-S/S2 demodulator. * - * Copyright (C) 2014-2016 Ralph Metzler + * Copyright (C) 2014-2017 Ralph Metzler * Marcus Metzler * developed for Digital Devices GmbH * @@ -17,10 +17,8 @@ * * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - * Or, point your browser to http://www.gnu.org/copyleft/gpl.html + * along with this program; if not, point your browser to + * http://www.gnu.org/copyleft/gpl.html */ #include @@ -37,19 +35,18 @@ #include "stv0910.h" #include "stv0910_regs.h" - #define EXT_CLOCK 30000000 #define TUNING_DELAY 200 #define BER_SRC_S 0x20 #define BER_SRC_S2 0x20 -LIST_HEAD(stvlist); +static LIST_HEAD(stvlist); -enum ReceiveMode { Mode_None, Mode_DVBS, Mode_DVBS2, Mode_Auto }; +enum receive_mode { RCVMODE_NONE, RCVMODE_DVBS, RCVMODE_DVBS2, RCVMODE_AUTO }; -enum DVBS2_FECType { DVBS2_64K, DVBS2_16K }; +enum dvbs2_fec_type { DVBS2_64K, DVBS2_16K }; -enum DVBS2_ModCod { +enum dvbs2_modcod { DVBS2_DUMMY_PLF, DVBS2_QPSK_1_4, DVBS2_QPSK_1_3, DVBS2_QPSK_2_5, DVBS2_QPSK_1_2, DVBS2_QPSK_3_5, DVBS2_QPSK_2_3, DVBS2_QPSK_3_4, DVBS2_QPSK_4_5, DVBS2_QPSK_5_6, DVBS2_QPSK_8_9, DVBS2_QPSK_9_10, @@ -60,7 +57,7 @@ enum DVBS2_ModCod { DVBS2_32APSK_9_10 }; -enum FE_STV0910_ModCod { +enum fe_stv0190_modcod { FE_DUMMY_PLF, FE_QPSK_14, FE_QPSK_13, FE_QPSK_25, FE_QPSK_12, FE_QPSK_35, FE_QPSK_23, FE_QPSK_34, FE_QPSK_45, FE_QPSK_56, FE_QPSK_89, FE_QPSK_910, @@ -71,16 +68,16 @@ enum FE_STV0910_ModCod { FE_32APSK_910 }; -enum FE_STV0910_RollOff { FE_SAT_35, FE_SAT_25, FE_SAT_20, FE_SAT_15 }; +enum fe_stv0910_roll_off { FE_SAT_35, FE_SAT_25, FE_SAT_20, FE_SAT_15 }; -static inline u32 MulDiv32(u32 a, u32 b, u32 c) +static inline u32 muldiv32(u32 a, u32 b, u32 c) { u64 tmp64; tmp64 = (u64)a * (u64)b; do_div(tmp64, c); - return (u32) tmp64; + return (u32)tmp64; } struct stv_base { @@ -88,8 +85,8 @@ struct stv_base { u8 adr; struct i2c_adapter *i2c; - struct mutex i2c_lock; - struct mutex reg_lock; + struct mutex i2c_lock; /* i2c gate lock */ + struct mutex reg_lock; /* lock access to shared registers */ int count; u32 extclk; @@ -108,44 +105,38 @@ struct stv { u8 single; unsigned long tune_time; - s32 SearchRange; - u32 Started; - u32 DemodLockTime; - enum ReceiveMode ReceiveMode; - u32 DemodTimeout; - u32 FecTimeout; - u32 FirstTimeLock; - u8 DEMOD; - u32 SymbolRate; + s32 search_range; + u32 started; + u32 demod_lock_time; + enum receive_mode receive_mode; + u32 demod_timeout; + u32 fec_timeout; + u32 first_time_lock; + u8 demod; + u32 symbol_rate; - u8 LastViterbiRate; - enum fe_code_rate PunctureRate; - enum FE_STV0910_ModCod ModCod; - enum DVBS2_FECType FECType; - u32 Pilots; - enum FE_STV0910_RollOff FERollOff; + enum fe_code_rate puncture_rate; + enum fe_stv0190_modcod modcod; + enum dvbs2_fec_type fec_type; + u32 pilots; + enum fe_stv0910_roll_off fe_roll_off; - int isStandardBroadcast; - int isVCM; - - u32 CurScramblingCode; - u32 ScramblingCode; - - u32 LastBERNumerator; - u32 LastBERDenominator; - u8 BERScale; + int is_standard_broadcast; + int is_vcm; - u8 VTH[6]; + u32 cur_scrambling_code; + u32 scrambling_code; + + u32 last_ber_numerator; + u32 last_ber_denominator; + u8 ber_scale; + + u8 vth[6]; }; -struct SInitTable { - u16 Address; - u8 Data; -}; - -struct SLookup { - s16 Value; - u16 RegValue; +struct slookup { + s16 value; + u16 reg_value; }; static inline int i2c_write(struct i2c_adapter *adap, u8 adr, @@ -185,7 +176,6 @@ static int read_reg(struct stv *state, u16 reg, u8 *val) return i2c_read_reg16(state->base->i2c, state->base->adr, reg, val); } - static inline int i2c_read_regs16(struct i2c_adapter *adapter, u8 adr, u16 reg, u8 *val, int len) { @@ -216,132 +206,133 @@ static int write_shared_reg(struct stv *state, u16 reg, u8 mask, u8 val) return status; } -struct SLookup S1_SN_Lookup[] = { - { 0, 9242 }, /*C/N= 0dB*/ - { 05, 9105 }, /*C/N=0.5dB*/ - { 10, 8950 }, /*C/N=1.0dB*/ - { 15, 8780 }, /*C/N=1.5dB*/ - { 20, 8566 }, /*C/N=2.0dB*/ - { 25, 8366 }, /*C/N=2.5dB*/ - { 30, 8146 }, /*C/N=3.0dB*/ - { 35, 7908 }, /*C/N=3.5dB*/ - { 40, 7666 }, /*C/N=4.0dB*/ - { 45, 7405 }, /*C/N=4.5dB*/ - { 50, 7136 }, /*C/N=5.0dB*/ - { 55, 6861 }, /*C/N=5.5dB*/ - { 60, 6576 }, /*C/N=6.0dB*/ - { 65, 6330 }, /*C/N=6.5dB*/ - { 70, 6048 }, /*C/N=7.0dB*/ - { 75, 5768 }, /*C/N=7.5dB*/ - { 80, 5492 }, /*C/N=8.0dB*/ - { 85, 5224 }, /*C/N=8.5dB*/ - { 90, 4959 }, /*C/N=9.0dB*/ - { 95, 4709 }, /*C/N=9.5dB*/ - { 100, 4467 }, /*C/N=10.0dB*/ - { 105, 4236 }, /*C/N=10.5dB*/ - { 110, 4013 }, /*C/N=11.0dB*/ - { 115, 3800 }, /*C/N=11.5dB*/ - { 120, 3598 }, /*C/N=12.0dB*/ - { 125, 3406 }, /*C/N=12.5dB*/ - { 130, 3225 }, /*C/N=13.0dB*/ - { 135, 3052 }, /*C/N=13.5dB*/ - { 140, 2889 }, /*C/N=14.0dB*/ - { 145, 2733 }, /*C/N=14.5dB*/ - { 150, 2587 }, /*C/N=15.0dB*/ - { 160, 2318 }, /*C/N=16.0dB*/ - { 170, 2077 }, /*C/N=17.0dB*/ - { 180, 1862 }, /*C/N=18.0dB*/ - { 190, 1670 }, /*C/N=19.0dB*/ - { 200, 1499 }, /*C/N=20.0dB*/ - { 210, 1347 }, /*C/N=21.0dB*/ - { 220, 1213 }, /*C/N=22.0dB*/ - { 230, 1095 }, /*C/N=23.0dB*/ - { 240, 992 }, /*C/N=24.0dB*/ - { 250, 900 }, /*C/N=25.0dB*/ - { 260, 826 }, /*C/N=26.0dB*/ - { 270, 758 }, /*C/N=27.0dB*/ - { 280, 702 }, /*C/N=28.0dB*/ - { 290, 653 }, /*C/N=29.0dB*/ - { 300, 613 }, /*C/N=30.0dB*/ - { 310, 579 }, /*C/N=31.0dB*/ - { 320, 550 }, /*C/N=32.0dB*/ - { 330, 526 }, /*C/N=33.0dB*/ - { 350, 490 }, /*C/N=33.0dB*/ - { 400, 445 }, /*C/N=40.0dB*/ - { 450, 430 }, /*C/N=45.0dB*/ - { 500, 426 }, /*C/N=50.0dB*/ - { 510, 425 } /*C/N=51.0dB*/ +static const struct slookup s1_sn_lookup[] = { + { 0, 9242 }, /* C/N= 0dB */ + { 05, 9105 }, /* C/N=0.5dB */ + { 10, 8950 }, /* C/N=1.0dB */ + { 15, 8780 }, /* C/N=1.5dB */ + { 20, 8566 }, /* C/N=2.0dB */ + { 25, 8366 }, /* C/N=2.5dB */ + { 30, 8146 }, /* C/N=3.0dB */ + { 35, 7908 }, /* C/N=3.5dB */ + { 40, 7666 }, /* C/N=4.0dB */ + { 45, 7405 }, /* C/N=4.5dB */ + { 50, 7136 }, /* C/N=5.0dB */ + { 55, 6861 }, /* C/N=5.5dB */ + { 60, 6576 }, /* C/N=6.0dB */ + { 65, 6330 }, /* C/N=6.5dB */ + { 70, 6048 }, /* C/N=7.0dB */ + { 75, 5768 }, /* C/N=7.5dB */ + { 80, 5492 }, /* C/N=8.0dB */ + { 85, 5224 }, /* C/N=8.5dB */ + { 90, 4959 }, /* C/N=9.0dB */ + { 95, 4709 }, /* C/N=9.5dB */ + { 100, 4467 }, /* C/N=10.0dB */ + { 105, 4236 }, /* C/N=10.5dB */ + { 110, 4013 }, /* C/N=11.0dB */ + { 115, 3800 }, /* C/N=11.5dB */ + { 120, 3598 }, /* C/N=12.0dB */ + { 125, 3406 }, /* C/N=12.5dB */ + { 130, 3225 }, /* C/N=13.0dB */ + { 135, 3052 }, /* C/N=13.5dB */ + { 140, 2889 }, /* C/N=14.0dB */ + { 145, 2733 }, /* C/N=14.5dB */ + { 150, 2587 }, /* C/N=15.0dB */ + { 160, 2318 }, /* C/N=16.0dB */ + { 170, 2077 }, /* C/N=17.0dB */ + { 180, 1862 }, /* C/N=18.0dB */ + { 190, 1670 }, /* C/N=19.0dB */ + { 200, 1499 }, /* C/N=20.0dB */ + { 210, 1347 }, /* C/N=21.0dB */ + { 220, 1213 }, /* C/N=22.0dB */ + { 230, 1095 }, /* C/N=23.0dB */ + { 240, 992 }, /* C/N=24.0dB */ + { 250, 900 }, /* C/N=25.0dB */ + { 260, 826 }, /* C/N=26.0dB */ + { 270, 758 }, /* C/N=27.0dB */ + { 280, 702 }, /* C/N=28.0dB */ + { 290, 653 }, /* C/N=29.0dB */ + { 300, 613 }, /* C/N=30.0dB */ + { 310, 579 }, /* C/N=31.0dB */ + { 320, 550 }, /* C/N=32.0dB */ + { 330, 526 }, /* C/N=33.0dB */ + { 350, 490 }, /* C/N=33.0dB */ + { 400, 445 }, /* C/N=40.0dB */ + { 450, 430 }, /* C/N=45.0dB */ + { 500, 426 }, /* C/N=50.0dB */ + { 510, 425 }, /* C/N=51.0dB */ }; -struct SLookup S2_SN_Lookup[] = { - { -30, 13950 }, /*C/N=-2.5dB*/ - { -25, 13580 }, /*C/N=-2.5dB*/ - { -20, 13150 }, /*C/N=-2.0dB*/ - { -15, 12760 }, /*C/N=-1.5dB*/ - { -10, 12345 }, /*C/N=-1.0dB*/ - { -05, 11900 }, /*C/N=-0.5dB*/ - { 0, 11520 }, /*C/N= 0dB*/ - { 05, 11080 }, /*C/N= 0.5dB*/ - { 10, 10630 }, /*C/N= 1.0dB*/ - { 15, 10210 }, /*C/N= 1.5dB*/ - { 20, 9790 }, /*C/N= 2.0dB*/ - { 25, 9390 }, /*C/N= 2.5dB*/ - { 30, 8970 }, /*C/N= 3.0dB*/ - { 35, 8575 }, /*C/N= 3.5dB*/ - { 40, 8180 }, /*C/N= 4.0dB*/ - { 45, 7800 }, /*C/N= 4.5dB*/ - { 50, 7430 }, /*C/N= 5.0dB*/ - { 55, 7080 }, /*C/N= 5.5dB*/ - { 60, 6720 }, /*C/N= 6.0dB*/ - { 65, 6320 }, /*C/N= 6.5dB*/ - { 70, 6060 }, /*C/N= 7.0dB*/ - { 75, 5760 }, /*C/N= 7.5dB*/ - { 80, 5480 }, /*C/N= 8.0dB*/ - { 85, 5200 }, /*C/N= 8.5dB*/ - { 90, 4930 }, /*C/N= 9.0dB*/ - { 95, 4680 }, /*C/N= 9.5dB*/ - { 100, 4425 }, /*C/N=10.0dB*/ - { 105, 4210 }, /*C/N=10.5dB*/ - { 110, 3980 }, /*C/N=11.0dB*/ - { 115, 3765 }, /*C/N=11.5dB*/ - { 120, 3570 }, /*C/N=12.0dB*/ - { 125, 3315 }, /*C/N=12.5dB*/ - { 130, 3140 }, /*C/N=13.0dB*/ - { 135, 2980 }, /*C/N=13.5dB*/ - { 140, 2820 }, /*C/N=14.0dB*/ - { 145, 2670 }, /*C/N=14.5dB*/ - { 150, 2535 }, /*C/N=15.0dB*/ - { 160, 2270 }, /*C/N=16.0dB*/ - { 170, 2035 }, /*C/N=17.0dB*/ - { 180, 1825 }, /*C/N=18.0dB*/ - { 190, 1650 }, /*C/N=19.0dB*/ - { 200, 1485 }, /*C/N=20.0dB*/ - { 210, 1340 }, /*C/N=21.0dB*/ - { 220, 1212 }, /*C/N=22.0dB*/ - { 230, 1100 }, /*C/N=23.0dB*/ - { 240, 1000 }, /*C/N=24.0dB*/ - { 250, 910 }, /*C/N=25.0dB*/ - { 260, 836 }, /*C/N=26.0dB*/ - { 270, 772 }, /*C/N=27.0dB*/ - { 280, 718 }, /*C/N=28.0dB*/ - { 290, 671 }, /*C/N=29.0dB*/ - { 300, 635 }, /*C/N=30.0dB*/ - { 310, 602 }, /*C/N=31.0dB*/ - { 320, 575 }, /*C/N=32.0dB*/ - { 330, 550 }, /*C/N=33.0dB*/ - { 350, 517 }, /*C/N=35.0dB*/ - { 400, 480 }, /*C/N=40.0dB*/ - { 450, 466 }, /*C/N=45.0dB*/ - { 500, 464 }, /*C/N=50.0dB*/ - { 510, 463 }, /*C/N=51.0dB*/ +struct slookup s2_sn_lookup[] = { + { -30, 13950 }, /* C/N=-2.5dB */ + { -25, 13580 }, /* C/N=-2.5dB */ + { -20, 13150 }, /* C/N=-2.0dB */ + { -15, 12760 }, /* C/N=-1.5dB */ + { -10, 12345 }, /* C/N=-1.0dB */ + { -5, 11900 }, /* C/N=-0.5dB */ + { 0, 11520 }, /* C/N= 0dB */ + { 5, 11080 }, /* C/N= 0.5dB */ + { 10, 10630 }, /* C/N= 1.0dB */ + { 15, 10210 }, /* C/N= 1.5dB */ + { 20, 9790 }, /* C/N= 2.0dB */ + { 25, 9390 }, /* C/N= 2.5dB */ + { 30, 8970 }, /* C/N= 3.0dB */ + { 35, 8575 }, /* C/N= 3.5dB */ + { 40, 8180 }, /* C/N= 4.0dB */ + { 45, 7800 }, /* C/N= 4.5dB */ + { 50, 7430 }, /* C/N= 5.0dB */ + { 55, 7080 }, /* C/N= 5.5dB */ + { 60, 6720 }, /* C/N= 6.0dB */ + { 65, 6320 }, /* C/N= 6.5dB */ + { 70, 6060 }, /* C/N= 7.0dB */ + { 75, 5760 }, /* C/N= 7.5dB */ + { 80, 5480 }, /* C/N= 8.0dB */ + { 85, 5200 }, /* C/N= 8.5dB */ + { 90, 4930 }, /* C/N= 9.0dB */ + { 95, 4680 }, /* C/N= 9.5dB */ + { 100, 4425 }, /* C/N=10.0dB */ + { 105, 4210 }, /* C/N=10.5dB */ + { 110, 3980 }, /* C/N=11.0dB */ + { 115, 3765 }, /* C/N=11.5dB */ + { 120, 3570 }, /* C/N=12.0dB */ + { 125, 3315 }, /* C/N=12.5dB */ + { 130, 3140 }, /* C/N=13.0dB */ + { 135, 2980 }, /* C/N=13.5dB */ + { 140, 2820 }, /* C/N=14.0dB */ + { 145, 2670 }, /* C/N=14.5dB */ + { 150, 2535 }, /* C/N=15.0dB */ + { 160, 2270 }, /* C/N=16.0dB */ + { 170, 2035 }, /* C/N=17.0dB */ + { 180, 1825 }, /* C/N=18.0dB */ + { 190, 1650 }, /* C/N=19.0dB */ + { 200, 1485 }, /* C/N=20.0dB */ + { 210, 1340 }, /* C/N=21.0dB */ + { 220, 1212 }, /* C/N=22.0dB */ + { 230, 1100 }, /* C/N=23.0dB */ + { 240, 1000 }, /* C/N=24.0dB */ + { 250, 910 }, /* C/N=25.0dB */ + { 260, 836 }, /* C/N=26.0dB */ + { 270, 772 }, /* C/N=27.0dB */ + { 280, 718 }, /* C/N=28.0dB */ + { 290, 671 }, /* C/N=29.0dB */ + { 300, 635 }, /* C/N=30.0dB */ + { 310, 602 }, /* C/N=31.0dB */ + { 320, 575 }, /* C/N=32.0dB */ + { 330, 550 }, /* C/N=33.0dB */ + { 350, 517 }, /* C/N=35.0dB */ + { 400, 480 }, /* C/N=40.0dB */ + { 450, 466 }, /* C/N=45.0dB */ + { 500, 464 }, /* C/N=50.0dB */ + { 510, 463 }, /* C/N=51.0dB */ }; /********************************************************************* -Tracking carrier loop carrier QPSK 1/4 to 8PSK 9/10 long Frame -*********************************************************************/ -static u8 S2CarLoop[] = { + * Tracking carrier loop carrier QPSK 1/4 to 8PSK 9/10 long Frame + *********************************************************************/ +static const u8 s2car_loop[] = { /* Modcod 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff - 20MPon 20MPoff 30MPon 30MPoff*/ + * 20MPon 20MPoff 30MPon 30MPoff + */ /* FE_QPSK_14 */ 0x0C, 0x3C, 0x0B, 0x3C, 0x2A, 0x2C, 0x2A, 0x1C, 0x3A, 0x3B, /* FE_QPSK_13 */ @@ -378,10 +369,12 @@ static u8 S2CarLoop[] = { 0x0C, 0x1C, 0x0C, 0x3B, 0x2B, 0x1B, 0x3A, 0x0B, 0x2A, 0x2A, /********************************************************************** - Tracking carrier loop carrier 16APSK 2/3 to 32APSK 9/10 long Frame - **********************************************************************/ - /*Modcod 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon - 20MPoff 30MPon 30MPoff*/ + * Tracking carrier loop carrier 16APSK 2/3 to 32APSK 9/10 long Frame + **********************************************************************/ + /* + * Modcod 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon + * 20MPoff 30MPon 30MPoff + */ /* FE_16APSK_23 */ 0x0A, 0x0A, 0x0A, 0x0A, 0x1A, 0x0A, 0x39, 0x0A, 0x29, 0x0A, /* FE_16APSK_34 */ @@ -407,131 +400,131 @@ static u8 S2CarLoop[] = { }; static u8 get_optim_cloop(struct stv *state, - enum FE_STV0910_ModCod ModCod, u32 Pilots) + enum fe_stv0190_modcod modcod, u32 pilots) { int i = 0; - if (ModCod >= FE_32APSK_910) - i = ((int)FE_32APSK_910 - (int)FE_QPSK_14) * 10; - else if (ModCod >= FE_QPSK_14) - i = ((int)ModCod - (int)FE_QPSK_14) * 10; - if (state->SymbolRate <= 3000000) + if (modcod >= FE_32APSK_910) + i = ((int)FE_32APSK_910 - (int)FE_QPSK_14) * 10; + else if (modcod >= FE_QPSK_14) + i = ((int)modcod - (int)FE_QPSK_14) * 10; + + if (state->symbol_rate <= 3000000) i += 0; - else if (state->SymbolRate <= 7000000) + else if (state->symbol_rate <= 7000000) i += 2; - else if (state->SymbolRate <= 15000000) + else if (state->symbol_rate <= 15000000) i += 4; - else if (state->SymbolRate <= 25000000) + else if (state->symbol_rate <= 25000000) i += 6; else i += 8; - if (!Pilots) + if (!pilots) i += 1; - return S2CarLoop[i]; + return s2car_loop[i]; } -static int GetCurSymbolRate(struct stv *state, u32 *pSymbolRate) +static int get_cur_symbol_rate(struct stv *state, u32 *psymbol_rate) { int status = 0; - u8 SymbFreq0; - u8 SymbFreq1; - u8 SymbFreq2; - u8 SymbFreq3; - u8 TimOffs0; - u8 TimOffs1; - u8 TimOffs2; - u32 SymbolRate; - s32 TimingOffset; + u8 symb_freq0; + u8 symb_freq1; + u8 symb_freq2; + u8 symb_freq3; + u8 tim_offs0; + u8 tim_offs1; + u8 tim_offs2; + u32 symbol_rate; + s32 timing_offset; - *pSymbolRate = 0; - if (!state->Started) + *psymbol_rate = 0; + if (!state->started) return status; - read_reg(state, RSTV0910_P2_SFR3 + state->regoff, &SymbFreq3); - read_reg(state, RSTV0910_P2_SFR2 + state->regoff, &SymbFreq2); - read_reg(state, RSTV0910_P2_SFR1 + state->regoff, &SymbFreq1); - read_reg(state, RSTV0910_P2_SFR0 + state->regoff, &SymbFreq0); - read_reg(state, RSTV0910_P2_TMGREG2 + state->regoff, &TimOffs2); - read_reg(state, RSTV0910_P2_TMGREG1 + state->regoff, &TimOffs1); - read_reg(state, RSTV0910_P2_TMGREG0 + state->regoff, &TimOffs0); + read_reg(state, RSTV0910_P2_SFR3 + state->regoff, &symb_freq3); + read_reg(state, RSTV0910_P2_SFR2 + state->regoff, &symb_freq2); + read_reg(state, RSTV0910_P2_SFR1 + state->regoff, &symb_freq1); + read_reg(state, RSTV0910_P2_SFR0 + state->regoff, &symb_freq0); + read_reg(state, RSTV0910_P2_TMGREG2 + state->regoff, &tim_offs2); + read_reg(state, RSTV0910_P2_TMGREG1 + state->regoff, &tim_offs1); + read_reg(state, RSTV0910_P2_TMGREG0 + state->regoff, &tim_offs0); - SymbolRate = ((u32) SymbFreq3 << 24) | ((u32) SymbFreq2 << 16) | - ((u32) SymbFreq1 << 8) | (u32) SymbFreq0; - TimingOffset = ((u32) TimOffs2 << 16) | ((u32) TimOffs1 << 8) | - (u32) TimOffs0; + symbol_rate = ((u32)symb_freq3 << 24) | ((u32)symb_freq2 << 16) | + ((u32)symb_freq1 << 8) | (u32)symb_freq0; + timing_offset = ((u32)tim_offs2 << 16) | ((u32)tim_offs1 << 8) | + (u32)tim_offs0; - if ((TimingOffset & (1<<23)) != 0) - TimingOffset |= 0xFF000000; /* Sign extent */ + if ((timing_offset & (1 << 23)) != 0) + timing_offset |= 0xFF000000; /* Sign extent */ - SymbolRate = (u32) (((u64) SymbolRate * state->base->mclk) >> 32); - TimingOffset = (s32) (((s64) SymbolRate * (s64) TimingOffset) >> 29); + symbol_rate = (u32)(((u64)symbol_rate * state->base->mclk) >> 32); + timing_offset = (s32)(((s64)symbol_rate * (s64)timing_offset) >> 29); - *pSymbolRate = SymbolRate + TimingOffset; + *psymbol_rate = symbol_rate + timing_offset; return 0; } -static int GetSignalParameters(struct stv *state) +static int get_signal_parameters(struct stv *state) { u8 tmp; - - if (!state->Started) - return -1; - - if (state->ReceiveMode == Mode_DVBS2) { - read_reg(state, RSTV0910_P2_DMDMODCOD + state->regoff, &tmp); - state->ModCod = (enum FE_STV0910_ModCod) ((tmp & 0x7c) >> 2); - state->Pilots = (tmp & 0x01) != 0; - state->FECType = (enum DVBS2_FECType) ((tmp & 0x02) >> 1); + if (!state->started) + return -EINVAL; + + if (state->receive_mode == RCVMODE_DVBS2) { + read_reg(state, RSTV0910_P2_DMDMODCOD + state->regoff, &tmp); + state->modcod = (enum fe_stv0190_modcod)((tmp & 0x7c) >> 2); + state->pilots = (tmp & 0x01) != 0; + state->fec_type = (enum dvbs2_fec_type)((tmp & 0x02) >> 1); #if 0 read_reg(state, RSTV0910_P2_TMGOBS + state->regoff, &rolloff); rolloff = rolloff >> 6; - state->FERollOff = (enum FE_STV0910_RollOff) rolloff; + state->fe_roll_off = (enum fe_stv0910_roll_off)rolloff; #endif - } else if (state->ReceiveMode == Mode_DVBS) { + } else if (state->receive_mode == RCVMODE_DVBS) { read_reg(state, RSTV0910_P2_VITCURPUN + state->regoff, &tmp); - state->PunctureRate = FEC_NONE; + state->puncture_rate = FEC_NONE; switch (tmp & 0x1F) { case 0x0d: - state->PunctureRate = FEC_1_2; + state->puncture_rate = FEC_1_2; break; case 0x12: - state->PunctureRate = FEC_2_3; + state->puncture_rate = FEC_2_3; break; case 0x15: - state->PunctureRate = FEC_3_4; + state->puncture_rate = FEC_3_4; break; case 0x18: - state->PunctureRate = FEC_5_6; + state->puncture_rate = FEC_5_6; break; - case 0x1A: - state->PunctureRate = FEC_7_8; + case 0x1a: + state->puncture_rate = FEC_7_8; break; } - state->isVCM = 0; - state->isStandardBroadcast = 1; - state->FERollOff = FE_SAT_35; + state->is_vcm = 0; + state->is_standard_broadcast = 1; + state->fe_roll_off = FE_SAT_35; } return 0; } -static int TrackingOptimization(struct stv *state) +static int tracking_optimization(struct stv *state) { - u32 SymbolRate = 0; + u32 symbol_rate = 0; u8 tmp; - GetCurSymbolRate(state, &SymbolRate); + get_cur_symbol_rate(state, &symbol_rate); read_reg(state, RSTV0910_P2_DMDCFGMD + state->regoff, &tmp); tmp &= ~0xC0; - switch (state->ReceiveMode) { - case Mode_DVBS: + switch (state->receive_mode) { + case RCVMODE_DVBS: tmp |= 0x40; break; - case Mode_DVBS2: + case RCVMODE_DVBS2: tmp |= 0x80; break; default: @@ -540,28 +533,29 @@ static int TrackingOptimization(struct stv *state) } write_reg(state, RSTV0910_P2_DMDCFGMD + state->regoff, tmp); - if (state->ReceiveMode == Mode_DVBS2) { - /*Disable Reed-Solomon */ - write_shared_reg(state, RSTV0910_TSTTSRS, state->nr ? 0x02 : 0x01, 0x03); + if (state->receive_mode == RCVMODE_DVBS2) { + /* Disable Reed-Solomon */ + write_shared_reg(state, RSTV0910_TSTTSRS, + state->nr ? 0x02 : 0x01, 0x03); - if (state->FECType == DVBS2_64K) { - u8 aclc = get_optim_cloop(state, state->ModCod, - state->Pilots); + if (state->fec_type == DVBS2_64K) { + u8 aclc = get_optim_cloop(state, state->modcod, + state->pilots); - if (state->ModCod <= FE_QPSK_910) { + if (state->modcod <= FE_QPSK_910) { write_reg(state, RSTV0910_P2_ACLC2S2Q + state->regoff, aclc); - } else if (state->ModCod <= FE_8PSK_910) { + } else if (state->modcod <= FE_8PSK_910) { write_reg(state, RSTV0910_P2_ACLC2S2Q + state->regoff, 0x2a); write_reg(state, RSTV0910_P2_ACLC2S28 + state->regoff, aclc); - } else if (state->ModCod <= FE_16APSK_910) { + } else if (state->modcod <= FE_16APSK_910) { write_reg(state, RSTV0910_P2_ACLC2S2Q + state->regoff, 0x2a); write_reg(state, RSTV0910_P2_ACLC2S216A + state->regoff, aclc); - } else if (state->ModCod <= FE_32APSK_910) { + } else if (state->modcod <= FE_32APSK_910) { write_reg(state, RSTV0910_P2_ACLC2S2Q + state->regoff, 0x2a); write_reg(state, RSTV0910_P2_ACLC2S232A + @@ -572,107 +566,105 @@ static int TrackingOptimization(struct stv *state) return 0; } -static s32 TableLookup(struct SLookup *Table, - int TableSize, u16 RegValue) +static s32 table_lookup(const struct slookup *table, + int table_size, u16 reg_value) { - s32 Value; + s32 value; int imin = 0; - int imax = TableSize - 1; + int imax = table_size - 1; int i; - s32 RegDiff; - - /* Assumes Table[0].RegValue > Table[imax].RegValue */ - if( RegValue >= Table[0].RegValue ) - Value = Table[0].Value; - else if( RegValue <= Table[imax].RegValue ) - Value = Table[imax].Value; - else - { - while(imax-imin > 1) - { + s32 reg_diff; + + /* Assumes table[0].reg_value > table[imax].reg_value */ + if (reg_value >= table[0].reg_value) { + value = table[0].value; + } else if (reg_value <= table[imax].reg_value) { + value = table[imax].value; + } else { + while (imax - imin > 1) { i = (imax + imin) / 2; - if( (Table[imin].RegValue >= RegValue) && (RegValue >= Table[i].RegValue) ) + if ((table[imin].reg_value >= reg_value) && + (reg_value >= table[i].reg_value)) imax = i; else imin = i; } - - RegDiff = Table[imax].RegValue - Table[imin].RegValue; - Value = Table[imin].Value; - if( RegDiff != 0 ) - Value += ((s32)(RegValue - Table[imin].RegValue) * - (s32)(Table[imax].Value - Table[imin].Value))/(RegDiff); + reg_diff = table[imax].reg_value - table[imin].reg_value; + value = table[imin].value; + if (reg_diff != 0) + value += ((s32)(reg_value - table[imin].reg_value) * + (s32)(table[imax].value - + table[imin].value)) / reg_diff; } - - return Value; + return value; } -static int GetSignalToNoise(struct stv *state, s32 *SignalToNoise) +static int get_signal_to_noise(struct stv *state, s32 *snr) { - u8 Data0; - u8 Data1; - u16 Data; - int nLookup; - struct SLookup *Lookup; + u8 data0; + u8 data1; + u16 data; + int n_lookup; + const struct slookup *lookup; - *SignalToNoise = 0; + *snr = 0; - if (!state->Started) + if (!state->started) return 0; - if (state->ReceiveMode == Mode_DVBS2) { - read_reg(state, RSTV0910_P2_NNOSPLHT1 + state->regoff, &Data1); - read_reg(state, RSTV0910_P2_NNOSPLHT0 + state->regoff, &Data0); - nLookup = ARRAY_SIZE(S2_SN_Lookup); - Lookup = S2_SN_Lookup; + if (state->receive_mode == RCVMODE_DVBS2) { + read_reg(state, RSTV0910_P2_NNOSPLHT1 + state->regoff, &data1); + read_reg(state, RSTV0910_P2_NNOSPLHT0 + state->regoff, &data0); + n_lookup = ARRAY_SIZE(s2_sn_lookup); + lookup = s2_sn_lookup; } else { - read_reg(state, RSTV0910_P2_NNOSDATAT1 + state->regoff, &Data1); - read_reg(state, RSTV0910_P2_NNOSDATAT0 + state->regoff, &Data0); - nLookup = ARRAY_SIZE(S1_SN_Lookup); - Lookup = S1_SN_Lookup; + read_reg(state, RSTV0910_P2_NNOSDATAT1 + state->regoff, &data1); + read_reg(state, RSTV0910_P2_NNOSDATAT0 + state->regoff, &data0); + n_lookup = ARRAY_SIZE(s1_sn_lookup); + lookup = s1_sn_lookup; } - Data = (((u16)Data1) << 8) | (u16) Data0; - *SignalToNoise = TableLookup(Lookup, nLookup, Data); + data = (((u16)data1) << 8) | (u16)data0; + *snr = table_lookup(lookup, n_lookup, data); return 0; } -static int GetBitErrorRateS(struct stv *state, u32 *BERNumerator, - u32 *BERDenominator) +static int get_ber_s(struct stv *state, u32 *ber_numerator, + u32 *ber_denominator) { - u8 Regs[3]; + u8 regs[3]; int status = read_regs(state, RSTV0910_P2_ERRCNT12 + state->regoff, - Regs, 3); + regs, 3); if (status) return -1; - if ((Regs[0] & 0x80) == 0) { - state->LastBERDenominator = 1 << ((state->BERScale * 2) + + if ((regs[0] & 0x80) == 0) { + state->last_ber_denominator = 1 << ((state->ber_scale * 2) + 10 + 3); - state->LastBERNumerator = ((u32) (Regs[0] & 0x7F) << 16) | - ((u32) Regs[1] << 8) | Regs[2]; - if (state->LastBERNumerator < 256 && state->BERScale < 6) { - state->BERScale += 1; + state->last_ber_numerator = ((u32)(regs[0] & 0x7f) << 16) | + ((u32)regs[1] << 8) | regs[2]; + if (state->last_ber_numerator < 256 && state->ber_scale < 6) { + state->ber_scale += 1; status = write_reg(state, RSTV0910_P2_ERRCTRL1 + state->regoff, - 0x20 | state->BERScale); - } else if (state->LastBERNumerator > 1024 && - state->BERScale > 2) { - state->BERScale -= 1; + 0x20 | state->ber_scale); + } else if (state->last_ber_numerator > 1024 && + state->ber_scale > 2) { + state->ber_scale -= 1; status = write_reg(state, RSTV0910_P2_ERRCTRL1 + state->regoff, 0x20 | - state->BERScale); + state->ber_scale); } } - *BERNumerator = state->LastBERNumerator; - *BERDenominator = state->LastBERDenominator; + *ber_numerator = state->last_ber_numerator; + *ber_denominator = state->last_ber_denominator; return 0; } -static u32 DVBS2_nBCH(enum DVBS2_ModCod ModCod, enum DVBS2_FECType FECType) +static u32 dvbs_nbch(enum dvbs2_modcod modcod, enum dvbs2_fec_type fec_type) { - static u32 nBCH[][2] = { + static const u32 nbch[][2] = { { 0, 0}, /* dummy */ {16200, 3240}, /* QPSK_1_4, */ {21600, 5400}, /* QPSK_1_3, */ @@ -704,59 +696,57 @@ static u32 DVBS2_nBCH(enum DVBS2_ModCod ModCod, enum DVBS2_FECType FECType) {58320, 16000}, /* 32APSK_9_10 */ }; - if (ModCod >= DVBS2_QPSK_1_4 && - ModCod <= DVBS2_32APSK_9_10 && FECType <= DVBS2_16K) - return nBCH[ModCod][FECType]; + if (modcod >= DVBS2_QPSK_1_4 && + modcod <= DVBS2_32APSK_9_10 && fec_type <= DVBS2_16K) + return nbch[modcod][fec_type]; return 64800; } -static int GetBitErrorRateS2(struct stv *state, - u32 *BERNumerator, - u32 *BERDenominator) +static int get_ber_s2(struct stv *state, + u32 *ber_numerator, + u32 *ber_denominator) { - u8 Regs[3]; - + u8 regs[3]; + int status = read_regs(state, RSTV0910_P2_ERRCNT12 + state->regoff, - Regs, 3); + regs, 3); if (status) return -1; - if ((Regs[0] & 0x80) == 0) { - state->LastBERDenominator = - DVBS2_nBCH((enum DVBS2_ModCod) state->ModCod, - state->FECType) << - (state->BERScale * 2); - state->LastBERNumerator = (((u32) Regs[0] & 0x7F) << 16) | - ((u32) Regs[1] << 8) | Regs[2]; - if (state->LastBERNumerator < 256 && state->BERScale < 6) { - state->BERScale += 1; + if ((regs[0] & 0x80) == 0) { + state->last_ber_denominator = + dvbs_nbch((enum dvbs2_modcod)state->modcod, + state->fec_type) << + (state->ber_scale * 2); + state->last_ber_numerator = (((u32)regs[0] & 0x7f) << 16) | + ((u32)regs[1] << 8) | regs[2]; + if (state->last_ber_numerator < 256 && state->ber_scale < 6) { + state->ber_scale += 1; write_reg(state, RSTV0910_P2_ERRCTRL1 + state->regoff, - 0x20 | state->BERScale); - } else if (state->LastBERNumerator > 1024 && - state->BERScale > 2) { - state->BERScale -= 1; + 0x20 | state->ber_scale); + } else if (state->last_ber_numerator > 1024 && + state->ber_scale > 2) { + state->ber_scale -= 1; write_reg(state, RSTV0910_P2_ERRCTRL1 + state->regoff, - 0x20 | state->BERScale); + 0x20 | state->ber_scale); } } - *BERNumerator = state->LastBERNumerator; - *BERDenominator = state->LastBERDenominator; + *ber_numerator = state->last_ber_numerator; + *ber_denominator = state->last_ber_denominator; return status; } -static int GetBitErrorRate(struct stv *state, u32 *BERNumerator, - u32 *BERDenominator) +static int get_ber(struct stv *state, u32 *ber_numerator, u32 *ber_denominator) { - *BERNumerator = 0; - *BERDenominator = 1; + *ber_numerator = 0; + *ber_denominator = 1; - switch (state->ReceiveMode) { - case Mode_DVBS: - return GetBitErrorRateS(state, BERNumerator, BERDenominator); - break; - case Mode_DVBS2: - return GetBitErrorRateS2(state, BERNumerator, BERDenominator); + switch (state->receive_mode) { + case RCVMODE_DVBS: + return get_ber_s(state, ber_numerator, ber_denominator); + case RCVMODE_DVBS2: + return get_ber_s2(state, ber_numerator, ber_denominator); default: break; } @@ -768,13 +758,13 @@ static int init(struct dvb_frontend *fe) return 0; } -static int set_mclock(struct stv *state, u32 MasterClock) +static int set_mclock(struct stv *state, u32 master_clock) { u32 idf = 1; u32 odf = 4; u32 quartz = state->base->extclk / 1000000; - u32 Fphi = MasterClock / 1000000; - u32 ndiv = (Fphi * odf * idf) / quartz; + u32 fphi = master_clock / 1000000; + u32 ndiv = (fphi * odf * idf) / quartz; u32 cp = 7; u32 fvco; @@ -832,9 +822,9 @@ static int set_mclock(struct stv *state, u32 MasterClock) return 0; } -static int Stop(struct stv *state) +static int stop(struct stv *state) { - if (state->Started) { + if (state->started) { u8 tmp; write_reg(state, RSTV0910_P2_TSCFGH + state->regoff, @@ -846,205 +836,214 @@ static int Stop(struct stv *state) write_reg(state, RSTV0910_P2_AGC2O + state->regoff, 0x5B); /* Stop the demod */ write_reg(state, RSTV0910_P2_DMDISTATE + state->regoff, 0x5c); - state->Started = 0; + state->started = 0; } - state->ReceiveMode = Mode_None; + state->receive_mode = RCVMODE_NONE; return 0; } - static int init_search_param(struct stv *state) { u8 tmp; - + read_reg(state, RSTV0910_P2_PDELCTRL1 + state->regoff, &tmp); - tmp |= 0x20; // Filter_en (no effect if SIS=non-MIS + tmp |= 0x20; // Filter_en (no effect if SIS=non-MIS write_reg(state, RSTV0910_P2_PDELCTRL1 + state->regoff, tmp); - + read_reg(state, RSTV0910_P2_PDELCTRL2 + state->regoff, &tmp); - tmp &= ~0x02; // frame mode = 0 + tmp &= ~0x02; // frame mode = 0 write_reg(state, RSTV0910_P2_PDELCTRL2 + state->regoff, tmp); - + write_reg(state, RSTV0910_P2_UPLCCST0 + state->regoff, 0xe0); write_reg(state, RSTV0910_P2_ISIBITENA + state->regoff, 0x00); read_reg(state, RSTV0910_P2_TSSTATEM + state->regoff, &tmp); - tmp &= ~0x01; // nosync = 0, in case next signal is standard TS + tmp &= ~0x01; // nosync = 0, in case next signal is standard TS write_reg(state, RSTV0910_P2_TSSTATEM + state->regoff, tmp); - + read_reg(state, RSTV0910_P2_TSCFGL + state->regoff, &tmp); - tmp &= ~0x04; // embindvb = 0 + tmp &= ~0x04; // embindvb = 0 write_reg(state, RSTV0910_P2_TSCFGL + state->regoff, tmp); - + read_reg(state, RSTV0910_P2_TSINSDELH + state->regoff, &tmp); - tmp &= ~0x80; // syncbyte = 0 + tmp &= ~0x80; // syncbyte = 0 write_reg(state, RSTV0910_P2_TSINSDELH + state->regoff, tmp); - + read_reg(state, RSTV0910_P2_TSINSDELM + state->regoff, &tmp); - tmp &= ~0x08; // token = 0 + tmp &= ~0x08; // token = 0 write_reg(state, RSTV0910_P2_TSINSDELM + state->regoff, tmp); - + read_reg(state, RSTV0910_P2_TSDLYSET2 + state->regoff, &tmp); - tmp &= ~0x30; // hysteresis threshold = 0 + tmp &= ~0x30; // hysteresis threshold = 0 write_reg(state, RSTV0910_P2_TSDLYSET2 + state->regoff, tmp); - + read_reg(state, RSTV0910_P2_PDELCTRL0 + state->regoff, &tmp); - tmp = (tmp & ~0x30) | 0x10; // isi obs mode = 1, observe min ISI + tmp = (tmp & ~0x30) | 0x10; // isi obs mode = 1, observe min ISI write_reg(state, RSTV0910_P2_PDELCTRL0 + state->regoff, tmp); - + return 0; } -static int EnablePunctureRate(struct stv *state, enum fe_code_rate rate) +static int enable_puncture_rate(struct stv *state, enum fe_code_rate rate) { - switch(rate) { - case FEC_1_2: - return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, 0x01); - case FEC_2_3: - return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, 0x02); - case FEC_3_4: - return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, 0x04); - case FEC_5_6: - return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, 0x08); - case FEC_7_8: - return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, 0x20); - case FEC_NONE: - default: - return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, 0x2f); + switch (rate) { + case FEC_1_2: + return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, + 0x01); + case FEC_2_3: + return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, + 0x02); + case FEC_3_4: + return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, + 0x04); + case FEC_5_6: + return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, + 0x08); + case FEC_7_8: + return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, + 0x20); + case FEC_NONE: + default: + return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, + 0x2f); } + return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, 0x2f); } static int set_vth_default(struct stv *state) { - state->VTH[0] = 0xd7; - state->VTH[1] = 0x85; - state->VTH[2] = 0x58; - state->VTH[3] = 0x3a; - state->VTH[4] = 0x34; - state->VTH[5] = 0x28; - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 0, state->VTH[0]); - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 1, state->VTH[1]); - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 2, state->VTH[2]); - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 3, state->VTH[3]); - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 4, state->VTH[4]); - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 5, state->VTH[5]); + state->vth[0] = 0xd7; + state->vth[1] = 0x85; + state->vth[2] = 0x58; + state->vth[3] = 0x3a; + state->vth[4] = 0x34; + state->vth[5] = 0x28; + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 0, state->vth[0]); + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 1, state->vth[1]); + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 2, state->vth[2]); + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 3, state->vth[3]); + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 4, state->vth[4]); + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 5, state->vth[5]); return 0; } static int set_vth(struct stv *state) { - static struct SLookup VTHLookupTable[] = { - {250, 8780}, /*C/N=1.5dB*/ - {100, 7405}, /*C/N=4.5dB*/ - {40, 6330}, /*C/N=6.5dB*/ - {12, 5224}, /*C/N=8.5dB*/ - {5, 4236} /*C/N=10.5dB*/ + static struct slookup vth_lookup_table[] = { + {250, 8780}, /* C/N= 1.5dB */ + {100, 7405}, /* C/N= 4.5dB */ + {40, 6330}, /* C/N= 6.5dB */ + {12, 5224}, /* C/N= 8.5dB */ + {5, 4236}, /* C/N=10.5dB */ }; int i; u8 tmp[2]; - int status = read_regs(state, RSTV0910_P2_NNOSDATAT1 + state->regoff, tmp, 2); - u16 RegValue = (tmp[0] << 8) | tmp[1]; - s32 vth = TableLookup(VTHLookupTable, ARRAY_SIZE(VTHLookupTable), RegValue); + int status = read_regs(state, RSTV0910_P2_NNOSDATAT1 + state->regoff, + tmp, 2); + u16 value = (tmp[0] << 8) | tmp[1]; + s32 vth = table_lookup(vth_lookup_table, + ARRAY_SIZE(vth_lookup_table), value); - for (i = 0; i < 6; i += 1) - if (state->VTH[i] > vth) - state->VTH[i] = vth; - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 0, state->VTH[0]); - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 1, state->VTH[1]); - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 2, state->VTH[2]); - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 3, state->VTH[3]); - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 4, state->VTH[4]); - write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 5, state->VTH[5]); + for (i = 0; i < 6; i += 1) + if (state->vth[i] > vth) + state->vth[i] = vth; + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 0, state->vth[0]); + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 1, state->vth[1]); + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 2, state->vth[2]); + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 3, state->vth[3]); + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 4, state->vth[4]); + write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 5, state->vth[5]); return status; } -static int Start(struct stv *state, struct dtv_frontend_properties *p) +static int start(struct stv *state, struct dtv_frontend_properties *p) { - s32 Freq; - u8 regDMDCFGMD; + s32 freq; + u8 reg_dmdcfgmd; u16 symb; - u32 ScramblingCode = 1; - + u32 scrambling_code = 1; + if (p->symbol_rate < 100000 || p->symbol_rate > 70000000) return -EINVAL; - state->ReceiveMode = Mode_None; - state->DemodLockTime = 0; + state->receive_mode = RCVMODE_NONE; + state->demod_lock_time = 0; - /* Demod Stop*/ - if (state->Started) + /* Demod Stop */ + if (state->started) write_reg(state, RSTV0910_P2_DMDISTATE + state->regoff, 0x5C); init_search_param(state); - - if (p->stream_id != NO_STREAM_ID_FILTER) { + + if (p->stream_id != NO_STREAM_ID_FILTER) { /* Backwards compatibility to "crazy" API. - PRBS X root cannot be 0, so this should always work. - */ - if (p->stream_id & 0xffffff00) - ScramblingCode = p->stream_id >> 8; - write_reg(state, RSTV0910_P2_ISIENTRY + state->regoff, p->stream_id & 0xff); + * PRBS X root cannot be 0, so this should always work. + */ + if (p->stream_id & 0xffffff00) + scrambling_code = p->stream_id >> 8; + write_reg(state, RSTV0910_P2_ISIENTRY + state->regoff, + p->stream_id & 0xff); write_reg(state, RSTV0910_P2_ISIBITENA + state->regoff, 0xff); - //pr_info("ID=%08x\n", p->stream_id & 0xff); - } + } /* props->pls is always gold code ! */ - if (p->pls != NO_SCRAMBLING_CODE) - ScramblingCode = p->pls | 0x40000; + if (p->pls != NO_SCRAMBLING_CODE) + scrambling_code = p->pls | 0x40000; - if (ScramblingCode != state->CurScramblingCode) { + if (scrambling_code != state->cur_scrambling_code) { write_reg(state, RSTV0910_P2_PLROOT0 + state->regoff, - ScramblingCode & 0xff); + scrambling_code & 0xff); write_reg(state, RSTV0910_P2_PLROOT1 + state->regoff, - (ScramblingCode >> 8) & 0xff); + (scrambling_code >> 8) & 0xff); write_reg(state, RSTV0910_P2_PLROOT2 + state->regoff, - (ScramblingCode >> 16) & 0x0f); - state->CurScramblingCode = ScramblingCode; + (scrambling_code >> 16) & 0x0f); + state->cur_scrambling_code = scrambling_code; } if (p->symbol_rate <= 1000000) { /*SR <=1Msps*/ - state->DemodTimeout = 3000; - state->FecTimeout = 2000; + state->demod_timeout = 3000; + state->fec_timeout = 2000; } else if (p->symbol_rate <= 2000000) { /*1Msps < SR <=2Msps*/ - state->DemodTimeout = 2500; - state->FecTimeout = 1300; + state->demod_timeout = 2500; + state->fec_timeout = 1300; } else if (p->symbol_rate <= 5000000) { /*2Msps< SR <=5Msps*/ - state->DemodTimeout = 1000; - state->FecTimeout = 650; + state->demod_timeout = 1000; + state->fec_timeout = 650; } else if (p->symbol_rate <= 10000000) { /*5Msps< SR <=10Msps*/ - state->DemodTimeout = 700; - state->FecTimeout = 350; + state->demod_timeout = 700; + state->fec_timeout = 350; } else if (p->symbol_rate < 20000000) { /*10Msps< SR <=20Msps*/ - state->DemodTimeout = 400; - state->FecTimeout = 200; + state->demod_timeout = 400; + state->fec_timeout = 200; } else { /*SR >=20Msps*/ - state->DemodTimeout = 300; - state->FecTimeout = 200; + state->demod_timeout = 300; + state->fec_timeout = 200; } /* Set the Init Symbol rate*/ - symb = MulDiv32(p->symbol_rate, 65536, state->base->mclk); + symb = muldiv32(p->symbol_rate, 65536, state->base->mclk); write_reg(state, RSTV0910_P2_SFRINIT1 + state->regoff, ((symb >> 8) & 0x7F)); write_reg(state, RSTV0910_P2_SFRINIT0 + state->regoff, (symb & 0xFF)); /*pr_info("symb = %u\n", symb);*/ - state->DEMOD |= 0x80; - write_reg(state, RSTV0910_P2_DEMOD + state->regoff, state->DEMOD); + state->demod |= 0x80; + write_reg(state, RSTV0910_P2_DEMOD + state->regoff, state->demod); /* FE_STV0910_SetSearchStandard */ - read_reg(state, RSTV0910_P2_DMDCFGMD + state->regoff, ®DMDCFGMD); + read_reg(state, RSTV0910_P2_DMDCFGMD + state->regoff, ®_dmdcfgmd); write_reg(state, RSTV0910_P2_DMDCFGMD + state->regoff, - regDMDCFGMD |= 0xC0); - write_shared_reg(state, RSTV0910_TSTTSRS, state->nr ? 0x02 : 0x01, 0x00); - + reg_dmdcfgmd |= 0xC0); + write_shared_reg(state, RSTV0910_TSTTSRS, + state->nr ? 0x02 : 0x01, 0x00); + /* Disable DSS */ write_reg(state, RSTV0910_P2_FECM + state->regoff, 0x00); write_reg(state, RSTV0910_P2_PRVIT + state->regoff, 0x2F); - EnablePunctureRate(state, FEC_NONE); - + enable_puncture_rate(state, FEC_NONE); + /* 8PSK 3/5, 8PSK 2/3 Poff tracking optimization WA*/ write_reg(state, RSTV0910_P2_ACLC2S2Q + state->regoff, 0x0B); write_reg(state, RSTV0910_P2_ACLC2S28 + state->regoff, 0x0A); @@ -1052,38 +1051,36 @@ static int Start(struct stv *state, struct dtv_frontend_properties *p) write_reg(state, RSTV0910_P2_BCLC2S28 + state->regoff, 0x84); write_reg(state, RSTV0910_P2_CARHDR + state->regoff, 0x1C); write_reg(state, RSTV0910_P2_CARFREQ + state->regoff, 0x79); - + write_reg(state, RSTV0910_P2_ACLC2S216A + state->regoff, 0x29); write_reg(state, RSTV0910_P2_ACLC2S232A + state->regoff, 0x09); write_reg(state, RSTV0910_P2_BCLC2S216A + state->regoff, 0x84); write_reg(state, RSTV0910_P2_BCLC2S232A + state->regoff, 0x84); - /* Reset CAR3, bug DVBS2->DVBS1 lock*/ - /* Note: The bit is only pulsed -> no lock on shared register needed */ + /* Note: The bit is only pulsed -> no lock on shared register needed */ write_reg(state, RSTV0910_TSTRES0, state->nr ? 0x04 : 0x08); write_reg(state, RSTV0910_TSTRES0, 0); set_vth_default(state); - - /* Reset demod */ + /* Reset demod */ write_reg(state, RSTV0910_P2_DMDISTATE + state->regoff, 0x1F); write_reg(state, RSTV0910_P2_CARCFG + state->regoff, 0x46); if (p->symbol_rate <= 5000000) - Freq = (state->SearchRange / 2000) + 80; + freq = (state->search_range / 2000) + 80; else - Freq = (state->SearchRange / 2000) + 1600; - Freq = (Freq << 16) / (state->base->mclk / 1000); + freq = (state->search_range / 2000) + 1600; + freq = (freq << 16) / (state->base->mclk / 1000); write_reg(state, RSTV0910_P2_CFRUP1 + state->regoff, - (Freq >> 8) & 0xff); - write_reg(state, RSTV0910_P2_CFRUP0 + state->regoff, (Freq & 0xff)); + (freq >> 8) & 0xff); + write_reg(state, RSTV0910_P2_CFRUP0 + state->regoff, (freq & 0xff)); /*CFR Low Setting*/ - Freq = -Freq; + freq = -freq; write_reg(state, RSTV0910_P2_CFRLOW1 + state->regoff, - (Freq >> 8) & 0xff); - write_reg(state, RSTV0910_P2_CFRLOW0 + state->regoff, (Freq & 0xff)); + (freq >> 8) & 0xff); + write_reg(state, RSTV0910_P2_CFRLOW0 + state->regoff, (freq & 0xff)); /* init the demod frequency offset to 0 */ write_reg(state, RSTV0910_P2_CFRINIT1 + state->regoff, 0); @@ -1093,8 +1090,8 @@ static int Start(struct stv *state, struct dtv_frontend_properties *p) /* Trigger acq */ write_reg(state, RSTV0910_P2_DMDISTATE + state->regoff, 0x15); - state->DemodLockTime += TUNING_DELAY; - state->Started = 1; + state->demod_lock_time += TUNING_DELAY; + state->started = 1; return 0; } @@ -1102,13 +1099,13 @@ static int Start(struct stv *state, struct dtv_frontend_properties *p) static int init_diseqc(struct stv *state) { u16 offs = state->nr ? 0x40 : 0; /* Address offset */ - u8 Freq = ((state->base->mclk + 11000 * 32) / (22000 * 32)); + u8 freq = ((state->base->mclk + 11000 * 32) / (22000 * 32)); /* Disable receiver */ write_reg(state, RSTV0910_P1_DISRXCFG + offs, 0x00); write_reg(state, RSTV0910_P1_DISTXCFG + offs, 0xBA); /* Reset = 1 */ write_reg(state, RSTV0910_P1_DISTXCFG + offs, 0x3A); /* Reset = 0 */ - write_reg(state, RSTV0910_P1_DISTXF22 + offs, Freq); + write_reg(state, RSTV0910_P1_DISTXF22 + offs, freq); return 0; } @@ -1116,11 +1113,11 @@ static int probe(struct stv *state) { u8 id; - state->ReceiveMode = Mode_None; - state->Started = 0; + state->receive_mode = RCVMODE_NONE; + state->started = 0; if (read_reg(state, RSTV0910_MID, &id) < 0) - return -1; + return -EINVAL; if (id != 0x51) return -EINVAL; @@ -1139,9 +1136,9 @@ static int probe(struct stv *state) write_reg(state, RSTV0910_TSGENERAL, state->tsgeneral); /* TSGENERAL */ write_reg(state, RSTV0910_CFGEXT, 0x02); /* CFGEXT */ if (state->single) - write_reg(state, RSTV0910_GENCFG, 0x14); /* GENCFG */ + write_reg(state, RSTV0910_GENCFG, 0x14); /* GENCFG */ else - write_reg(state, RSTV0910_GENCFG, 0x15); /* GENCFG */ + write_reg(state, RSTV0910_GENCFG, 0x15); /* GENCFG */ write_reg(state, RSTV0910_P1_TNRCFG2, 0x02); /* IQSWAP = 0 */ write_reg(state, RSTV0910_P2_TNRCFG2, 0x82); /* IQSWAP = 1 */ @@ -1150,7 +1147,7 @@ static int probe(struct stv *state) write_reg(state, RSTV0910_P2_CAR3CFG, 0x02); write_reg(state, RSTV0910_P1_DMDCFG4, 0x04); write_reg(state, RSTV0910_P2_DMDCFG4, 0x04); - + write_reg(state, RSTV0910_TSTRES0, 0x80); /* LDPC Reset */ write_reg(state, RSTV0910_TSTRES0, 0x00); @@ -1163,27 +1160,27 @@ static int probe(struct stv *state) set_mclock(state, 135000000); /* TS output */ - write_reg(state, RSTV0910_P1_TSCFGH , state->tscfgh | 0x01); - write_reg(state, RSTV0910_P1_TSCFGH , state->tscfgh); - write_reg(state, RSTV0910_P1_TSCFGM , 0xC0); /* Manual speed */ - write_reg(state, RSTV0910_P1_TSCFGL , 0x20); + write_reg(state, RSTV0910_P1_TSCFGH, state->tscfgh | 0x01); + write_reg(state, RSTV0910_P1_TSCFGH, state->tscfgh); + write_reg(state, RSTV0910_P1_TSCFGM, 0xC0); /* Manual speed */ + write_reg(state, RSTV0910_P1_TSCFGL, 0x20); /* Speed = 67.5 MHz */ - write_reg(state, RSTV0910_P1_TSSPEED , state->tsspeed); + write_reg(state, RSTV0910_P1_TSSPEED, state->tsspeed); - write_reg(state, RSTV0910_P2_TSCFGH , state->tscfgh | 0x01); - write_reg(state, RSTV0910_P2_TSCFGH , state->tscfgh); - write_reg(state, RSTV0910_P2_TSCFGM , 0xC0); /* Manual speed */ - write_reg(state, RSTV0910_P2_TSCFGL , 0x20); + write_reg(state, RSTV0910_P2_TSCFGH, state->tscfgh | 0x01); + write_reg(state, RSTV0910_P2_TSCFGH, state->tscfgh); + write_reg(state, RSTV0910_P2_TSCFGM, 0xC0); /* Manual speed */ + write_reg(state, RSTV0910_P2_TSCFGL, 0x20); /* Speed = 67.5 MHz */ - write_reg(state, RSTV0910_P2_TSSPEED , state->tsspeed); + write_reg(state, RSTV0910_P2_TSSPEED, state->tsspeed); /* Reset stream merger */ - write_reg(state, RSTV0910_P1_TSCFGH , state->tscfgh | 0x01); - write_reg(state, RSTV0910_P2_TSCFGH , state->tscfgh | 0x01); - write_reg(state, RSTV0910_P1_TSCFGH , state->tscfgh); - write_reg(state, RSTV0910_P2_TSCFGH , state->tscfgh); + write_reg(state, RSTV0910_P1_TSCFGH, state->tscfgh | 0x01); + write_reg(state, RSTV0910_P2_TSCFGH, state->tscfgh | 0x01); + write_reg(state, RSTV0910_P1_TSCFGH, state->tscfgh); + write_reg(state, RSTV0910_P2_TSCFGH, state->tscfgh); write_reg(state, RSTV0910_P1_I2CRPT, state->i2crpt); write_reg(state, RSTV0910_P2_I2CRPT, state->i2crpt); @@ -1192,7 +1189,6 @@ static int probe(struct stv *state) return 0; } - static int gate_ctrl(struct dvb_frontend *fe, int enable) { struct stv *state = fe->demodulator_priv; @@ -1236,13 +1232,13 @@ static int set_parameters(struct dvb_frontend *fe) u32 IF; struct dtv_frontend_properties *p = &fe->dtv_property_cache; - Stop(state); + stop(state); if (fe->ops.tuner_ops.set_params) fe->ops.tuner_ops.set_params(fe); if (fe->ops.tuner_ops.get_if_frequency) fe->ops.tuner_ops.get_if_frequency(fe, &IF); - state->SymbolRate = p->symbol_rate; - stat = Start(state, p); + state->symbol_rate = p->symbol_rate; + stat = start(state, p); return stat; } @@ -1254,24 +1250,22 @@ static int get_frequency_offset(struct stv *state, s32 *off) read_reg(state, RSTV0910_P2_CFR2 + state->regoff, &cfr2); read_reg(state, RSTV0910_P2_CFR1 + state->regoff, &cfr1); read_reg(state, RSTV0910_P2_CFR0 + state->regoff, &cfr0); - - derot = ((u32) cfr2 << 16) | ((u32)cfr1 << 8) | cfr0; - if (derot & (1<<23)) + + derot = ((u32)cfr2 << 16) | ((u32)cfr1 << 8) | cfr0; + if (derot & (1 << 23)) derot |= 0xFF000000; - *off = (s32) (((s64) derot * (s64) state->base->mclk) >> 24); + *off = (s32)(((s64)derot * (s64)state->base->mclk) >> 24); //pr_info("foff = %d\n", *off); return 0; } - static int get_frontend(struct dvb_frontend *fe) { struct stv *state = fe->demodulator_priv; struct dtv_frontend_properties *p = &fe->dtv_property_cache; u8 tmp; - - if (state->ReceiveMode == Mode_DVBS2) { + if (state->receive_mode == RCVMODE_DVBS2) { u32 mc; enum fe_modulation modcod2mod[0x20] = { QPSK, QPSK, QPSK, QPSK, @@ -1281,7 +1275,7 @@ static int get_frontend(struct dvb_frontend *fe) PSK_8, PSK_8, APSK_16, APSK_16, APSK_16, APSK_16, APSK_16, APSK_16, APSK_32, APSK_32, APSK_32, APSK_32, - APSK_32, + APSK_32, }; enum fe_code_rate modcod2fec[0x20] = { FEC_NONE, FEC_1_4, FEC_1_3, FEC_2_5, @@ -1292,28 +1286,28 @@ static int get_frontend(struct dvb_frontend *fe) FEC_4_5, FEC_5_6, FEC_8_9, FEC_9_10, FEC_3_4, FEC_4_5, FEC_5_6, FEC_8_9, FEC_9_10 - }; + }; read_reg(state, RSTV0910_P2_DMDMODCOD + state->regoff, &tmp); mc = ((tmp & 0x7c) >> 2); p->pilot = (tmp & 0x01) ? PILOT_ON : PILOT_OFF; p->modulation = modcod2mod[mc]; - p->fec_inner = modcod2fec[mc]; - } else if (state->ReceiveMode == Mode_DVBS) { + p->fec_inner = modcod2fec[mc]; + } else if (state->receive_mode == RCVMODE_DVBS) { read_reg(state, RSTV0910_P2_VITCURPUN + state->regoff, &tmp); - switch( tmp & 0x1F ) { - case 0x0d: + switch (tmp & 0x1f) { + case 0x0d: p->fec_inner = FEC_1_2; break; - case 0x12: + case 0x12: p->fec_inner = FEC_2_3; break; - case 0x15: + case 0x15: p->fec_inner = FEC_3_4; break; - case 0x18: + case 0x18: p->fec_inner = FEC_5_6; break; - case 0x1a: + case 0x1a: p->fec_inner = FEC_7_8; break; default: @@ -1321,36 +1315,31 @@ static int get_frontend(struct dvb_frontend *fe) break; } p->rolloff = ROLLOFF_35; - } else { - } - return 0; } - -static int ManageMatypeInfo(struct stv *state) +static int manage_matype_info(struct stv *state) { - if (!state->Started) + if (!state->started) return -1; - if (state->ReceiveMode == Mode_DVBS2 ) { - u8 BBHeader[2]; - + if (state->receive_mode == RCVMODE_DVBS2) { + u8 bbheader[2]; + read_regs(state, RSTV0910_P2_MATSTR1 + state->regoff, - BBHeader, 2); - state->FERollOff = - (enum FE_STV0910_RollOff) (BBHeader[0] & 0x03); - state->isVCM = (BBHeader[0] & 0x10) == 0; - state->isStandardBroadcast = (BBHeader[0] & 0xFC) == 0xF0; - } else if (state->ReceiveMode == Mode_DVBS) { - state->isVCM = 0; - state->isStandardBroadcast = 1; - state->FERollOff = FE_SAT_35; - } + bbheader, 2); + state->fe_roll_off = + (enum fe_stv0910_roll_off)(bbheader[0] & 0x03); + state->is_vcm = (bbheader[0] & 0x10) == 0; + state->is_standard_broadcast = (bbheader[0] & 0xFC) == 0xF0; + } else if (state->receive_mode == RCVMODE_DVBS) { + state->is_vcm = 0; + state->is_standard_broadcast = 1; + state->fe_roll_off = FE_SAT_35; + } return 0; } - static int read_snr(struct dvb_frontend *fe, u16 *snr); static int read_signal_strength(struct dvb_frontend *fe, u16 *strength); static int read_ber(struct dvb_frontend *fe, u32 *ber); @@ -1358,59 +1347,54 @@ static int read_ber(struct dvb_frontend *fe, u32 *ber); static int read_status(struct dvb_frontend *fe, fe_status_t *status) { struct stv *state = fe->demodulator_priv; - u8 DmdState = 0; - u8 DStatus = 0; - enum ReceiveMode CurReceiveMode = Mode_None; - u32 FECLock = 0; + u8 dmdstate = 0; + u8 dstatus = 0; + enum receive_mode cur_receive_mode = RCVMODE_NONE; + u32 fec_lock = 0; u16 val; u32 ber; s32 foff; *status = 0; get_frequency_offset(state, &foff); - read_signal_strength(fe, &val); - read_snr(fe, &val); - read_ber(fe, &ber); - - read_reg(state, RSTV0910_P2_DMDSTATE + state->regoff, &DmdState); - if (DmdState & 0x40) { + read_reg(state, RSTV0910_P2_DMDSTATE + state->regoff, &dmdstate); + if (dmdstate & 0x40) { read_reg(state, RSTV0910_P2_DSTATUS + state->regoff, - &DStatus); - if (DStatus & 0x08) - CurReceiveMode = (DmdState & 0x20) ? - Mode_DVBS : Mode_DVBS2; + &dstatus); + if (dstatus & 0x08) + cur_receive_mode = (dmdstate & 0x20) ? + RCVMODE_DVBS : RCVMODE_DVBS2; } - if (CurReceiveMode == Mode_None) { + if (cur_receive_mode == RCVMODE_NONE) { set_vth(state); - //if( Time >= m_DemodTimeout ) *pLockStatus = NEVER_LOCK; + //if( Time >= state->demod_timeout ) *pLockStatus = NEVER_LOCK; return 0; } *status |= 0x0f; - if (state->ReceiveMode == Mode_None) { - state->ReceiveMode = CurReceiveMode; - state->DemodLockTime = jiffies; - state->FirstTimeLock = 1; + if (state->receive_mode == RCVMODE_NONE) { + state->receive_mode = cur_receive_mode; + state->demod_lock_time = jiffies; + state->first_time_lock = 1; - GetSignalParameters(state); - TrackingOptimization(state); - + get_signal_parameters(state); + tracking_optimization(state); #if 0 - if( CurReceiveMode == Mode_DVBS2 && m_bPilots - && ( m_ModCod == FE_8PSK_23 || m_ModCod == FE_8PSK_35) ) - { - LONG C_N; - CHK_ERROR(GetSignalToNoise(&C_N)); - if( C_N < 80 ) - { - CHK_ERROR(WriteReg(RSTV0910_P2_CARHDR + m_DemodOffset , 0x04)); - CHK_ERROR(WriteReg(RSTV0910_P2_BCLC2S28 + m_DemodOffset , 0x31)); - } - } + if (cur_receive_mode == RCVMODE_DVBS2 && m_bpilots && + (m_modcod == FE_8PSK_23 || m_modcod == FE_8PSK_35)) { + u32 C_N; + + get_signal_to_noise(&C_N); + if (C_N < 80) { + write_reg(RSTV0910_P2_CARHDR + state->regoff, + 0x04); + write_reg(RSTV0910_P2_BCLC2S28 + state->regoff, + 0x31); + } + } #endif - write_reg(state, RSTV0910_P2_TSCFGH + state->regoff, state->tscfgh); usleep_range(3000, 4000); @@ -1419,53 +1403,55 @@ static int read_status(struct dvb_frontend *fe, fe_status_t *status) write_reg(state, RSTV0910_P2_TSCFGH + state->regoff, state->tscfgh); } - if (DmdState & 0x40) { - if (state->ReceiveMode == Mode_DVBS2) { - u8 PDELStatus; + if (dmdstate & 0x40) { + if (state->receive_mode == RCVMODE_DVBS2) { + u8 pdel; + read_reg(state, RSTV0910_P2_PDELSTATUS1 + state->regoff, - &PDELStatus); - FECLock = (PDELStatus & 0x02) != 0; + &pdel); + fec_lock = (pdel & 0x02) != 0; } else { - u8 VStatus; + u8 vstatus; + read_reg(state, RSTV0910_P2_VSTATUSVIT + state->regoff, - &VStatus); - FECLock = (VStatus & 0x08) != 0; + &vstatus); + fec_lock = (vstatus & 0x08) != 0; } } - if (!FECLock) - //if( Time >= m_DemodLockTime + m_FecTimeout ) *pLockStatus = NEVER_LOCK; + if (!fec_lock) { + //if( Time >= m_demod_lock_time + state->fec_timeout ) *status = NEVER_LOCK; return 0; + } *status |= 0x10; - if (state->FirstTimeLock) { + if (state->first_time_lock) { u8 tmp; - state->FirstTimeLock = 0; + state->first_time_lock = 0; - ManageMatypeInfo(state); - + manage_matype_info(state); #if 0 - ULONG Bitrate; - CSTV0910::GetBitrate(&Bitrate); - BYTE newTSSPEED = (Bitrate > 67000000) ? 0x30 : 0x40; - if (newTSSPEED != m_TSSPEED) - { - KdPrintEx((MSG_INFO "_%d " __FUNCTION__ " TSSPEED = %02X\n", m_Instance, newTSSPEED)); - CHK_ERROR(WriteReg(RSTV0910_P2_TSSPEED + m_DemodOffset, newTSSPEED)); - m_TSSPEED = newTSSPEED; - } - + u32 bitrate = get_bitrate(&bitrate); + u8 new_tsspeed = (bitrate > 67000000) ? 0x30 : 0x40; + + if (new_tsspeed != state->tsspeed) { + write_reg(state, RSTV0910_P2_TSSPEED + state->regoff, + new_tsspeed); + state->tsspeed = new_tsspeed; + } #endif - if (state->ReceiveMode == Mode_DVBS2) { - /* FSTV0910_P2_MANUALSX_ROLLOFF, - FSTV0910_P2_MANUALS2_ROLLOFF = 0 */ - state->DEMOD &= ~0x84; + + if (state->receive_mode == RCVMODE_DVBS2) { + /* FSTV0910_P2_MANUALSX_ROLLOFF, + * FSTV0910_P2_MANUALS2_ROLLOFF = 0 + */ + state->demod &= ~0x84; write_reg(state, RSTV0910_P2_DEMOD + state->regoff, - state->DEMOD); + state->demod); read_reg(state, RSTV0910_P2_PDELCTRL2 + state->regoff, &tmp); /*reset DVBS2 packet delinator error counter */ @@ -1479,45 +1465,43 @@ static int read_status(struct dvb_frontend *fe, fe_status_t *status) state->regoff, tmp); - state->BERScale = 2; - state->LastBERNumerator = 0; - state->LastBERDenominator = 1; + state->ber_scale = 2; + state->last_ber_numerator = 0; + state->last_ber_denominator = 1; /* force to PRE BCH Rate */ write_reg(state, RSTV0910_P2_ERRCTRL1 + state->regoff, - BER_SRC_S2 | state->BERScale); + BER_SRC_S2 | state->ber_scale); } else { - state->BERScale = 2; - state->LastBERNumerator = 0; - state->LastBERDenominator = 1; + state->ber_scale = 2; + state->last_ber_numerator = 0; + state->last_ber_denominator = 1; /* force to PRE RS Rate */ write_reg(state, RSTV0910_P2_ERRCTRL1 + state->regoff, - BER_SRC_S | state->BERScale); + BER_SRC_S | state->ber_scale); } - /*Reset the Total packet counter */ + /* Reset the Total packet counter */ write_reg(state, RSTV0910_P2_FBERCPT4 + state->regoff, 0x00); - /*Reset the packet Error counter2 (and Set it to - infinit error count mode )*/ + /* Reset the packet Error counter2 (and Set it to + * infinit error count mode ) + */ write_reg(state, RSTV0910_P2_ERRCTRL2 + state->regoff, 0xc1); set_vth_default(state); - if (state->ReceiveMode == Mode_DVBS) - EnablePunctureRate(state, state->PunctureRate); + if (state->receive_mode == RCVMODE_DVBS) + enable_puncture_rate(state, state->puncture_rate); } -#if 0 - if( m_isVCM ) - { - // Use highest signaled ModCod for quality - BYTE tmp; - CHK_ERROR(ReadReg(RSTV0910_P2_DMDMODCOD + - m_DemodOffset,&tmp)); - FE_STV0910_ModCod ModCod = - FE_STV0910_ModCod((tmp & 0x7c) >> 2); + /* Use highest signaled ModCod for quality */ + if (state->is_vcm) { + u8 tmp; + enum fe_stv0190_modcod modcod; - if( ModCod > m_ModCod ) - m_ModCod = ModCod; - } -#endif + read_reg(state, RSTV0910_P2_DMDMODCOD + state->regoff, &tmp); + modcod = (enum fe_stv0190_modcod)((tmp & 0x7c) >> 2); + + if (modcod > state->modcod) + state->modcod = modcod; + } return 0; } @@ -1544,7 +1528,6 @@ static int tune(struct dvb_frontend *fe, bool re_tune, return 0; } - static int get_algo(struct dvb_frontend *fe) { return DVBFE_ALGO_HW; @@ -1576,7 +1559,7 @@ static int wait_dis(struct stv *state, u8 flag, u8 val) read_reg(state, RSTV0910_P1_DISTXSTATUS + offs, &stat); if ((stat & flag) == val) return 0; - msleep(10); + usleep_range(10000, 11000); } return -1; } @@ -1588,8 +1571,6 @@ static int send_master_cmd(struct dvb_frontend *fe, u16 offs = state->nr ? 0x40 : 0; int i; - /*pr_info("master_cmd %02x %02x %02x %02x\n", - cmd->msg[0], cmd->msg[1], cmd->msg[2], cmd->msg[3]);*/ write_reg(state, RSTV0910_P1_DISTXCFG + offs, 0x3E); for (i = 0; i < cmd->msg_len; i++) { wait_dis(state, 0x40, 0x00); @@ -1632,25 +1613,24 @@ static int sleep(struct dvb_frontend *fe) { struct stv *state = fe->demodulator_priv; - Stop(state); + stop(state); return 0; } - static int read_snr(struct dvb_frontend *fe, u16 *snr) { struct stv *state = fe->demodulator_priv; struct dtv_frontend_properties *p = &fe->dtv_property_cache; - s32 SNR; + s32 snr32; *snr = 0; - if (GetSignalToNoise(state, &SNR)) + if (get_signal_to_noise(state, &snr32)) return -EIO; - *snr = SNR; + *snr = snr32; p->cnr.len = 1; p->cnr.stat[0].scale = FE_SCALE_DECIBEL; - p->cnr.stat[0].uvalue = 100 * (s64) SNR; - + p->cnr.stat[0].uvalue = 100 * (s64)snr32; + return 0; } @@ -1660,8 +1640,8 @@ static int read_ber(struct dvb_frontend *fe, u32 *ber) struct dtv_frontend_properties *p = &fe->dtv_property_cache; u32 n, d; - GetBitErrorRate(state, &n, &d); - if (d) + get_ber(state, &n, &d); + if (d) *ber = n / d; else *ber = 0; @@ -1675,9 +1655,9 @@ static int read_ber(struct dvb_frontend *fe, u32 *ber) return 0; } -static s32 Log10x100(u32 x) +static s32 log10x100(u32 x) { - static u32 LookupTable[100] = { + static const u32 lookup_table[100] = { 101157945, 103514217, 105925373, 108392691, 110917482, 113501082, 116144861, 118850223, 121618600, 124451461, 127350308, 130316678, 133352143, 136458314, 139636836, @@ -1715,7 +1695,7 @@ static s32 Log10x100(u32 x) y -= 100; } i = 0; - while (i < 100 && x > LookupTable[i]) + while (i < 100 && x > lookup_table[i]) i += 1; y += i; return y; @@ -1725,37 +1705,37 @@ static int read_signal_strength(struct dvb_frontend *fe, u16 *strength) { struct stv *state = fe->demodulator_priv; struct dtv_frontend_properties *p = &fe->dtv_property_cache; - u8 Reg[2]; + u8 reg[2]; s32 bbgain; - s32 Power = 0; + s32 power = 0; int i; - read_regs(state, RSTV0910_P2_AGCIQIN1 + state->regoff, Reg, 2); - *strength = (((u32) Reg[0]) << 8) | Reg[1]; - + read_regs(state, RSTV0910_P2_AGCIQIN1 + state->regoff, reg, 2); + *strength = (((u32)reg[0]) << 8) | reg[1]; + for (i = 0; i < 5; i += 1) { - read_regs(state, RSTV0910_P2_POWERI + state->regoff, Reg, 2); - Power += (u32) Reg[0] * (u32) Reg[0] + - (u32) Reg[1] * (u32) Reg[1]; - msleep(3); + read_regs(state, RSTV0910_P2_POWERI + state->regoff, reg, 2); + power += (u32)reg[0] * (u32)reg[0] + + (u32)reg[1] * (u32)reg[1]; + usleep_range(3000, 4000); } - Power /= 5; - bbgain = (465 - Log10x100(Power)) * 10; - + power /= 5; + bbgain = (465 - log10x100(power)) * 10; + if (fe->ops.tuner_ops.get_rf_strength) fe->ops.tuner_ops.get_rf_strength(fe, strength); else *strength = 0; - if (bbgain < (s32) *strength) + if (bbgain < (s32)*strength) *strength -= bbgain; else *strength = 0; - + p->strength.len = 1; p->strength.stat[0].scale = FE_SCALE_DECIBEL; - p->strength.stat[0].uvalue = 10 * (s64) (s16) *strength - 108750; - + p->strength.stat[0].uvalue = 10 * (s64)(s16)*strength - 108750; + /* *strength is in hundredth dBuv, uvalue is in thousandth dBm */ return 0; } @@ -1763,8 +1743,6 @@ static int read_signal_strength(struct dvb_frontend *fe, u16 *strength) static int read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) { /* struct stv *state = fe->demodulator_priv; */ - - return 0; } @@ -1782,7 +1760,7 @@ static struct dvb_frontend_ops stv0910_ops = { FE_CAN_FEC_AUTO | FE_CAN_QPSK | FE_CAN_2G_MODULATION | - FE_CAN_MULTISTREAM, + FE_CAN_MULTISTREAM, }, .init = init, .sleep = sleep, @@ -1804,7 +1782,7 @@ static struct dvb_frontend_ops stv0910_ops = { .read_ucblocks = read_ucblocks, }; -static struct stv_base *match_base(struct i2c_adapter *i2c, u8 adr) +static struct stv_base *match_base(struct i2c_adapter *i2c, u8 adr) { struct stv_base *p; @@ -1821,7 +1799,7 @@ struct dvb_frontend *stv0910_attach(struct i2c_adapter *i2c, struct stv *state; struct stv_base *base; - state = kzalloc(sizeof(struct stv), GFP_KERNEL); + state = kzalloc(sizeof(*state), GFP_KERNEL); if (!state) return NULL; @@ -1831,18 +1809,18 @@ struct dvb_frontend *stv0910_attach(struct i2c_adapter *i2c, state->tsspeed = 0x28; state->nr = nr; state->regoff = state->nr ? 0 : 0x200; - state->SearchRange = 16000000; - state->DEMOD = 0x10; /* Inversion : Auto with reset to 0 */ - state->ReceiveMode = Mode_None; - state->CurScramblingCode = NO_SCRAMBLING_CODE; + state->search_range = 16000000; + state->demod = 0x10; /* Inversion : Auto with reset to 0 */ + state->receive_mode = RCVMODE_NONE; + state->cur_scrambling_code = NO_SCRAMBLING_CODE; state->single = cfg->single ? 1 : 0; - + base = match_base(i2c, cfg->adr); if (base) { base->count++; state->base = base; } else { - base = kzalloc(sizeof(struct stv_base), GFP_KERNEL); + base = kzalloc(sizeof(*base), GFP_KERNEL); if (!base) goto fail; base->i2c = i2c; @@ -1859,8 +1837,8 @@ struct dvb_frontend *stv0910_attach(struct i2c_adapter *i2c, } list_add(&base->stvlist, &stvlist); } - state->fe.ops = stv0910_ops; - state->fe.demodulator_priv = state; + state->fe.ops = stv0910_ops; + state->fe.demodulator_priv = state; state->nr = nr; return &state->fe; @@ -1871,6 +1849,6 @@ fail: } EXPORT_SYMBOL_GPL(stv0910_attach); -MODULE_DESCRIPTION("STV0910 driver"); +MODULE_DESCRIPTION("STV0910 DVB-S/S2 demodulator driver"); MODULE_AUTHOR("Ralph und Marcus Metzler, Manfred Voelkel"); MODULE_LICENSE("GPL");