Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003     STB0899 Multistandard Frontend driver
0004     Copyright (C) Manu Abraham (abraham.manu@gmail.com)
0005 
0006     Copyright (C) ST Microelectronics
0007 
0008 */
0009 
0010 #ifndef __STB0899_PRIV_H
0011 #define __STB0899_PRIV_H
0012 
0013 #include <media/dvb_frontend.h>
0014 #include "stb0899_drv.h"
0015 
0016 #define FE_ERROR                0
0017 #define FE_NOTICE               1
0018 #define FE_INFO                 2
0019 #define FE_DEBUG                3
0020 #define FE_DEBUGREG             4
0021 
0022 #define dprintk(x, y, z, format, arg...) do {                       \
0023     if (z) {                                    \
0024         if  ((*x > FE_ERROR) && (*x > y))                   \
0025             printk(KERN_ERR "%s: " format "\n", __func__ , ##arg);      \
0026         else if ((*x > FE_NOTICE) && (*x > y))                  \
0027             printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg);   \
0028         else if ((*x > FE_INFO) && (*x > y))                    \
0029             printk(KERN_INFO "%s: " format "\n", __func__ , ##arg);     \
0030         else if ((*x > FE_DEBUG) && (*x > y))                   \
0031             printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg);    \
0032     } else {                                    \
0033         if (*x > y)                             \
0034             printk(format, ##arg);                      \
0035     }                                       \
0036 } while(0)
0037 
0038 #define INRANGE(val, x, y)          (((x <= val) && (val <= y)) ||      \
0039                          ((y <= val) && (val <= x)) ? 1 : 0)
0040 
0041 #define BYTE0                   0
0042 #define BYTE1                   8
0043 #define BYTE2                   16
0044 #define BYTE3                   24
0045 
0046 #define GETBYTE(x, y)               (((x) >> (y)) & 0xff)
0047 #define MAKEWORD32(a, b, c, d)          (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
0048 #define MAKEWORD16(a, b)            (((a) << 8) | (b))
0049 
0050 #define LSB(x)                  ((x & 0xff))
0051 #define MSB(y)                  ((y >> 8) & 0xff)
0052 
0053 
0054 #define STB0899_GETFIELD(bitf, val)     ((val >> STB0899_OFFST_##bitf) & ((1 << STB0899_WIDTH_##bitf) - 1))
0055 
0056 
0057 #define STB0899_SETFIELD(mask, val, width, offset)      (mask & (~(((1 << width) - 1) <<    \
0058                              offset))) | ((val &            \
0059                              ((1 << width) - 1)) << offset)
0060 
0061 #define STB0899_SETFIELD_VAL(bitf, mask, val)   (mask = (mask & (~(((1 << STB0899_WIDTH_##bitf) - 1) <<\
0062                              STB0899_OFFST_##bitf))) | \
0063                              (val << STB0899_OFFST_##bitf))
0064 
0065 
0066 enum stb0899_status {
0067     NOAGC1  = 0,
0068     AGC1OK,
0069     NOTIMING,
0070     ANALOGCARRIER,
0071     TIMINGOK,
0072     NOAGC2,
0073     AGC2OK,
0074     NOCARRIER,
0075     CARRIEROK,
0076     NODATA,
0077     FALSELOCK,
0078     DATAOK,
0079     OUTOFRANGE,
0080     RANGEOK,
0081     DVBS2_DEMOD_LOCK,
0082     DVBS2_DEMOD_NOLOCK,
0083     DVBS2_FEC_LOCK,
0084     DVBS2_FEC_NOLOCK
0085 };
0086 
0087 enum stb0899_modcod {
0088     STB0899_DUMMY_PLF,
0089     STB0899_QPSK_14,
0090     STB0899_QPSK_13,
0091     STB0899_QPSK_25,
0092     STB0899_QPSK_12,
0093     STB0899_QPSK_35,
0094     STB0899_QPSK_23,
0095     STB0899_QPSK_34,
0096     STB0899_QPSK_45,
0097     STB0899_QPSK_56,
0098     STB0899_QPSK_89,
0099     STB0899_QPSK_910,
0100     STB0899_8PSK_35,
0101     STB0899_8PSK_23,
0102     STB0899_8PSK_34,
0103     STB0899_8PSK_56,
0104     STB0899_8PSK_89,
0105     STB0899_8PSK_910,
0106     STB0899_16APSK_23,
0107     STB0899_16APSK_34,
0108     STB0899_16APSK_45,
0109     STB0899_16APSK_56,
0110     STB0899_16APSK_89,
0111     STB0899_16APSK_910,
0112     STB0899_32APSK_34,
0113     STB0899_32APSK_45,
0114     STB0899_32APSK_56,
0115     STB0899_32APSK_89,
0116     STB0899_32APSK_910
0117 };
0118 
0119 enum stb0899_frame {
0120     STB0899_LONG_FRAME,
0121     STB0899_SHORT_FRAME
0122 };
0123 
0124 enum stb0899_alpha {
0125     RRC_20,
0126     RRC_25,
0127     RRC_35
0128 };
0129 
0130 struct stb0899_tab {
0131     s32 real;
0132     s32 read;
0133 };
0134 
0135 enum stb0899_fec {
0136     STB0899_FEC_1_2         = 13,
0137     STB0899_FEC_2_3         = 18,
0138     STB0899_FEC_3_4         = 21,
0139     STB0899_FEC_5_6         = 24,
0140     STB0899_FEC_6_7         = 25,
0141     STB0899_FEC_7_8         = 26
0142 };
0143 
0144 struct stb0899_params {
0145     u32 freq;                   /* Frequency    */
0146     u32 srate;                  /* Symbol rate  */
0147     enum fe_code_rate fecrate;
0148 };
0149 
0150 struct stb0899_internal {
0151     u32         master_clk;
0152     u32         freq;           /* Demod internal Frequency     */
0153     u32         srate;          /* Demod internal Symbol rate       */
0154     enum stb0899_fec    fecrate;        /* Demod internal FEC rate      */
0155     s32         srch_range;     /* Demod internal Search Range      */
0156     s32         sub_range;      /* Demod current sub range (Hz)     */
0157     s32         tuner_step;     /* Tuner step (Hz)          */
0158     s32         tuner_offst;        /* Relative offset to carrier (Hz)  */
0159     u32         tuner_bw;       /* Current bandwidth of the tuner (Hz)  */
0160 
0161     s32         mclk;           /* Masterclock Divider factor (binary)  */
0162     s32         rolloff;        /* Current RollOff of the filter (x100) */
0163 
0164     s16         derot_freq;     /* Current derotator frequency (Hz) */
0165     s16         derot_percent;
0166 
0167     s16         direction;      /* Current derotator search direction   */
0168     s16         derot_step;     /* Derotator step (binary value)    */
0169     s16         t_derot;        /* Derotator time constant (ms)     */
0170     s16         t_data;         /* Data recovery time constant (ms) */
0171     s16         sub_dir;        /* Direction of the next sub range  */
0172 
0173     s16         t_agc1;         /* Agc1 time constant (ms)      */
0174     s16         t_agc2;         /* Agc2 time constant (ms)      */
0175 
0176     u32         lock;           /* Demod internal lock state        */
0177     enum stb0899_status status;         /* Demod internal status        */
0178 
0179     /* DVB-S2 */
0180     s32         agc_gain;       /* RF AGC Gain              */
0181     s32         center_freq;        /* Nominal carrier frequency        */
0182     s32         av_frame_coarse;    /* Coarse carrier freq search frames    */
0183     s32         av_frame_fine;      /* Fine carrier freq search frames  */
0184 
0185     s16         step_size;      /* Carrier frequency search step size   */
0186 
0187     enum stb0899_alpha  rrc_alpha;
0188     enum stb0899_inversion  inversion;
0189     enum stb0899_modcod modcod;
0190     u8          pilots;         /* Pilots found             */
0191 
0192     enum stb0899_frame  frame_length;
0193     u8          v_status;       /* VSTATUS              */
0194     u8          err_ctrl;       /* ERRCTRLn             */
0195 };
0196 
0197 struct stb0899_state {
0198     struct i2c_adapter      *i2c;
0199     struct stb0899_config       *config;
0200     struct dvb_frontend     frontend;
0201 
0202     u32             *verbose;   /* Cached module verbosity level    */
0203 
0204     struct stb0899_internal     internal;   /* Device internal parameters       */
0205 
0206     /*  cached params from API  */
0207     enum fe_delivery_system     delsys;
0208     struct stb0899_params       params;
0209 
0210     u32             rx_freq;    /* DiSEqC 2.0 receiver freq     */
0211     struct mutex            search_lock;
0212 };
0213 /* stb0899.c        */
0214 extern int stb0899_read_reg(struct stb0899_state *state,
0215                 unsigned int reg);
0216 
0217 extern u32 _stb0899_read_s2reg(struct stb0899_state *state,
0218                    u32 stb0899_i2cdev,
0219                    u32 stb0899_base_addr,
0220                    u16 stb0899_reg_offset);
0221 
0222 extern int stb0899_read_regs(struct stb0899_state *state,
0223                  unsigned int reg, u8 *buf,
0224                  u32 count);
0225 
0226 extern int stb0899_write_regs(struct stb0899_state *state,
0227                   unsigned int reg, u8 *data,
0228                   u32 count);
0229 
0230 extern int stb0899_write_reg(struct stb0899_state *state,
0231                  unsigned int reg,
0232                  u8 data);
0233 
0234 extern int stb0899_write_s2reg(struct stb0899_state *state,
0235                    u32 stb0899_i2cdev,
0236                    u32 stb0899_base_addr,
0237                    u16 stb0899_reg_offset,
0238                    u32 stb0899_data);
0239 
0240 extern int stb0899_i2c_gate_ctrl(struct dvb_frontend *fe, int enable);
0241 
0242 
0243 #define STB0899_READ_S2REG(DEVICE, REG)     (_stb0899_read_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG))
0244 //#define STB0899_WRITE_S2REG(DEVICE, REG, DATA)    (_stb0899_write_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG, DATA))
0245 
0246 /* stb0899_algo.c   */
0247 extern enum stb0899_status stb0899_dvbs_algo(struct stb0899_state *state);
0248 extern enum stb0899_status stb0899_dvbs2_algo(struct stb0899_state *state);
0249 extern long stb0899_carr_width(struct stb0899_state *state);
0250 
0251 #endif //__STB0899_PRIV_H