1*74ba9207SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 29a0bf528SMauro Carvalho Chehab /* 39a0bf528SMauro Carvalho Chehab STB0899 Multistandard Frontend driver 49a0bf528SMauro Carvalho Chehab Copyright (C) Manu Abraham (abraham.manu@gmail.com) 59a0bf528SMauro Carvalho Chehab 69a0bf528SMauro Carvalho Chehab Copyright (C) ST Microelectronics 79a0bf528SMauro Carvalho Chehab 89a0bf528SMauro Carvalho Chehab */ 99a0bf528SMauro Carvalho Chehab 109a0bf528SMauro Carvalho Chehab #ifndef __STB0899_PRIV_H 119a0bf528SMauro Carvalho Chehab #define __STB0899_PRIV_H 129a0bf528SMauro Carvalho Chehab 13fada1935SMauro Carvalho Chehab #include <media/dvb_frontend.h> 149a0bf528SMauro Carvalho Chehab #include "stb0899_drv.h" 159a0bf528SMauro Carvalho Chehab 169a0bf528SMauro Carvalho Chehab #define FE_ERROR 0 179a0bf528SMauro Carvalho Chehab #define FE_NOTICE 1 189a0bf528SMauro Carvalho Chehab #define FE_INFO 2 199a0bf528SMauro Carvalho Chehab #define FE_DEBUG 3 209a0bf528SMauro Carvalho Chehab #define FE_DEBUGREG 4 219a0bf528SMauro Carvalho Chehab 229a0bf528SMauro Carvalho Chehab #define dprintk(x, y, z, format, arg...) do { \ 239a0bf528SMauro Carvalho Chehab if (z) { \ 249a0bf528SMauro Carvalho Chehab if ((*x > FE_ERROR) && (*x > y)) \ 259a0bf528SMauro Carvalho Chehab printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \ 269a0bf528SMauro Carvalho Chehab else if ((*x > FE_NOTICE) && (*x > y)) \ 279a0bf528SMauro Carvalho Chehab printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \ 289a0bf528SMauro Carvalho Chehab else if ((*x > FE_INFO) && (*x > y)) \ 299a0bf528SMauro Carvalho Chehab printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \ 309a0bf528SMauro Carvalho Chehab else if ((*x > FE_DEBUG) && (*x > y)) \ 319a0bf528SMauro Carvalho Chehab printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \ 329a0bf528SMauro Carvalho Chehab } else { \ 339a0bf528SMauro Carvalho Chehab if (*x > y) \ 349a0bf528SMauro Carvalho Chehab printk(format, ##arg); \ 359a0bf528SMauro Carvalho Chehab } \ 369a0bf528SMauro Carvalho Chehab } while(0) 379a0bf528SMauro Carvalho Chehab 389a0bf528SMauro Carvalho Chehab #define INRANGE(val, x, y) (((x <= val) && (val <= y)) || \ 399a0bf528SMauro Carvalho Chehab ((y <= val) && (val <= x)) ? 1 : 0) 409a0bf528SMauro Carvalho Chehab 419a0bf528SMauro Carvalho Chehab #define BYTE0 0 429a0bf528SMauro Carvalho Chehab #define BYTE1 8 439a0bf528SMauro Carvalho Chehab #define BYTE2 16 449a0bf528SMauro Carvalho Chehab #define BYTE3 24 459a0bf528SMauro Carvalho Chehab 469a0bf528SMauro Carvalho Chehab #define GETBYTE(x, y) (((x) >> (y)) & 0xff) 479a0bf528SMauro Carvalho Chehab #define MAKEWORD32(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) 489a0bf528SMauro Carvalho Chehab #define MAKEWORD16(a, b) (((a) << 8) | (b)) 499a0bf528SMauro Carvalho Chehab 509a0bf528SMauro Carvalho Chehab #define LSB(x) ((x & 0xff)) 519a0bf528SMauro Carvalho Chehab #define MSB(y) ((y >> 8) & 0xff) 529a0bf528SMauro Carvalho Chehab 539a0bf528SMauro Carvalho Chehab 549a0bf528SMauro Carvalho Chehab #define STB0899_GETFIELD(bitf, val) ((val >> STB0899_OFFST_##bitf) & ((1 << STB0899_WIDTH_##bitf) - 1)) 559a0bf528SMauro Carvalho Chehab 569a0bf528SMauro Carvalho Chehab 579a0bf528SMauro Carvalho Chehab #define STB0899_SETFIELD(mask, val, width, offset) (mask & (~(((1 << width) - 1) << \ 589a0bf528SMauro Carvalho Chehab offset))) | ((val & \ 599a0bf528SMauro Carvalho Chehab ((1 << width) - 1)) << offset) 609a0bf528SMauro Carvalho Chehab 619a0bf528SMauro Carvalho Chehab #define STB0899_SETFIELD_VAL(bitf, mask, val) (mask = (mask & (~(((1 << STB0899_WIDTH_##bitf) - 1) <<\ 629a0bf528SMauro Carvalho Chehab STB0899_OFFST_##bitf))) | \ 639a0bf528SMauro Carvalho Chehab (val << STB0899_OFFST_##bitf)) 649a0bf528SMauro Carvalho Chehab 659a0bf528SMauro Carvalho Chehab 669a0bf528SMauro Carvalho Chehab enum stb0899_status { 679a0bf528SMauro Carvalho Chehab NOAGC1 = 0, 689a0bf528SMauro Carvalho Chehab AGC1OK, 699a0bf528SMauro Carvalho Chehab NOTIMING, 709a0bf528SMauro Carvalho Chehab ANALOGCARRIER, 719a0bf528SMauro Carvalho Chehab TIMINGOK, 729a0bf528SMauro Carvalho Chehab NOAGC2, 739a0bf528SMauro Carvalho Chehab AGC2OK, 749a0bf528SMauro Carvalho Chehab NOCARRIER, 759a0bf528SMauro Carvalho Chehab CARRIEROK, 769a0bf528SMauro Carvalho Chehab NODATA, 779a0bf528SMauro Carvalho Chehab FALSELOCK, 789a0bf528SMauro Carvalho Chehab DATAOK, 799a0bf528SMauro Carvalho Chehab OUTOFRANGE, 809a0bf528SMauro Carvalho Chehab RANGEOK, 819a0bf528SMauro Carvalho Chehab DVBS2_DEMOD_LOCK, 829a0bf528SMauro Carvalho Chehab DVBS2_DEMOD_NOLOCK, 839a0bf528SMauro Carvalho Chehab DVBS2_FEC_LOCK, 849a0bf528SMauro Carvalho Chehab DVBS2_FEC_NOLOCK 859a0bf528SMauro Carvalho Chehab }; 869a0bf528SMauro Carvalho Chehab 879a0bf528SMauro Carvalho Chehab enum stb0899_modcod { 889a0bf528SMauro Carvalho Chehab STB0899_DUMMY_PLF, 899a0bf528SMauro Carvalho Chehab STB0899_QPSK_14, 909a0bf528SMauro Carvalho Chehab STB0899_QPSK_13, 919a0bf528SMauro Carvalho Chehab STB0899_QPSK_25, 929a0bf528SMauro Carvalho Chehab STB0899_QPSK_12, 939a0bf528SMauro Carvalho Chehab STB0899_QPSK_35, 949a0bf528SMauro Carvalho Chehab STB0899_QPSK_23, 959a0bf528SMauro Carvalho Chehab STB0899_QPSK_34, 969a0bf528SMauro Carvalho Chehab STB0899_QPSK_45, 979a0bf528SMauro Carvalho Chehab STB0899_QPSK_56, 989a0bf528SMauro Carvalho Chehab STB0899_QPSK_89, 999a0bf528SMauro Carvalho Chehab STB0899_QPSK_910, 1009a0bf528SMauro Carvalho Chehab STB0899_8PSK_35, 1019a0bf528SMauro Carvalho Chehab STB0899_8PSK_23, 1029a0bf528SMauro Carvalho Chehab STB0899_8PSK_34, 1039a0bf528SMauro Carvalho Chehab STB0899_8PSK_56, 1049a0bf528SMauro Carvalho Chehab STB0899_8PSK_89, 1059a0bf528SMauro Carvalho Chehab STB0899_8PSK_910, 1069a0bf528SMauro Carvalho Chehab STB0899_16APSK_23, 1079a0bf528SMauro Carvalho Chehab STB0899_16APSK_34, 1089a0bf528SMauro Carvalho Chehab STB0899_16APSK_45, 1099a0bf528SMauro Carvalho Chehab STB0899_16APSK_56, 1109a0bf528SMauro Carvalho Chehab STB0899_16APSK_89, 1119a0bf528SMauro Carvalho Chehab STB0899_16APSK_910, 1129a0bf528SMauro Carvalho Chehab STB0899_32APSK_34, 1139a0bf528SMauro Carvalho Chehab STB0899_32APSK_45, 1149a0bf528SMauro Carvalho Chehab STB0899_32APSK_56, 1159a0bf528SMauro Carvalho Chehab STB0899_32APSK_89, 1169a0bf528SMauro Carvalho Chehab STB0899_32APSK_910 1179a0bf528SMauro Carvalho Chehab }; 1189a0bf528SMauro Carvalho Chehab 1199a0bf528SMauro Carvalho Chehab enum stb0899_frame { 1209a0bf528SMauro Carvalho Chehab STB0899_LONG_FRAME, 1219a0bf528SMauro Carvalho Chehab STB0899_SHORT_FRAME 1229a0bf528SMauro Carvalho Chehab }; 1239a0bf528SMauro Carvalho Chehab 1249a0bf528SMauro Carvalho Chehab enum stb0899_alpha { 1259a0bf528SMauro Carvalho Chehab RRC_20, 1269a0bf528SMauro Carvalho Chehab RRC_25, 1279a0bf528SMauro Carvalho Chehab RRC_35 1289a0bf528SMauro Carvalho Chehab }; 1299a0bf528SMauro Carvalho Chehab 1309a0bf528SMauro Carvalho Chehab struct stb0899_tab { 1319a0bf528SMauro Carvalho Chehab s32 real; 1329a0bf528SMauro Carvalho Chehab s32 read; 1339a0bf528SMauro Carvalho Chehab }; 1349a0bf528SMauro Carvalho Chehab 1359a0bf528SMauro Carvalho Chehab enum stb0899_fec { 1369a0bf528SMauro Carvalho Chehab STB0899_FEC_1_2 = 13, 1379a0bf528SMauro Carvalho Chehab STB0899_FEC_2_3 = 18, 1389a0bf528SMauro Carvalho Chehab STB0899_FEC_3_4 = 21, 1399a0bf528SMauro Carvalho Chehab STB0899_FEC_5_6 = 24, 1409a0bf528SMauro Carvalho Chehab STB0899_FEC_6_7 = 25, 1419a0bf528SMauro Carvalho Chehab STB0899_FEC_7_8 = 26 1429a0bf528SMauro Carvalho Chehab }; 1439a0bf528SMauro Carvalho Chehab 1449a0bf528SMauro Carvalho Chehab struct stb0899_params { 1459a0bf528SMauro Carvalho Chehab u32 freq; /* Frequency */ 1469a0bf528SMauro Carvalho Chehab u32 srate; /* Symbol rate */ 1479a0bf528SMauro Carvalho Chehab enum fe_code_rate fecrate; 1489a0bf528SMauro Carvalho Chehab }; 1499a0bf528SMauro Carvalho Chehab 1509a0bf528SMauro Carvalho Chehab struct stb0899_internal { 1519a0bf528SMauro Carvalho Chehab u32 master_clk; 1529a0bf528SMauro Carvalho Chehab u32 freq; /* Demod internal Frequency */ 1539a0bf528SMauro Carvalho Chehab u32 srate; /* Demod internal Symbol rate */ 1549a0bf528SMauro Carvalho Chehab enum stb0899_fec fecrate; /* Demod internal FEC rate */ 1559a0bf528SMauro Carvalho Chehab s32 srch_range; /* Demod internal Search Range */ 1569a0bf528SMauro Carvalho Chehab s32 sub_range; /* Demod current sub range (Hz) */ 1579a0bf528SMauro Carvalho Chehab s32 tuner_step; /* Tuner step (Hz) */ 1589a0bf528SMauro Carvalho Chehab s32 tuner_offst; /* Relative offset to carrier (Hz) */ 1599a0bf528SMauro Carvalho Chehab u32 tuner_bw; /* Current bandwidth of the tuner (Hz) */ 1609a0bf528SMauro Carvalho Chehab 1619a0bf528SMauro Carvalho Chehab s32 mclk; /* Masterclock Divider factor (binary) */ 1629a0bf528SMauro Carvalho Chehab s32 rolloff; /* Current RollOff of the filter (x100) */ 1639a0bf528SMauro Carvalho Chehab 1649a0bf528SMauro Carvalho Chehab s16 derot_freq; /* Current derotator frequency (Hz) */ 1659a0bf528SMauro Carvalho Chehab s16 derot_percent; 1669a0bf528SMauro Carvalho Chehab 1679a0bf528SMauro Carvalho Chehab s16 direction; /* Current derotator search direction */ 1689a0bf528SMauro Carvalho Chehab s16 derot_step; /* Derotator step (binary value) */ 1699a0bf528SMauro Carvalho Chehab s16 t_derot; /* Derotator time constant (ms) */ 1709a0bf528SMauro Carvalho Chehab s16 t_data; /* Data recovery time constant (ms) */ 1719a0bf528SMauro Carvalho Chehab s16 sub_dir; /* Direction of the next sub range */ 1729a0bf528SMauro Carvalho Chehab 1739a0bf528SMauro Carvalho Chehab s16 t_agc1; /* Agc1 time constant (ms) */ 1749a0bf528SMauro Carvalho Chehab s16 t_agc2; /* Agc2 time constant (ms) */ 1759a0bf528SMauro Carvalho Chehab 1769a0bf528SMauro Carvalho Chehab u32 lock; /* Demod internal lock state */ 1779a0bf528SMauro Carvalho Chehab enum stb0899_status status; /* Demod internal status */ 1789a0bf528SMauro Carvalho Chehab 1799a0bf528SMauro Carvalho Chehab /* DVB-S2 */ 1809a0bf528SMauro Carvalho Chehab s32 agc_gain; /* RF AGC Gain */ 1819a0bf528SMauro Carvalho Chehab s32 center_freq; /* Nominal carrier frequency */ 1829a0bf528SMauro Carvalho Chehab s32 av_frame_coarse; /* Coarse carrier freq search frames */ 1839a0bf528SMauro Carvalho Chehab s32 av_frame_fine; /* Fine carrier freq search frames */ 1849a0bf528SMauro Carvalho Chehab 1859a0bf528SMauro Carvalho Chehab s16 step_size; /* Carrier frequency search step size */ 1869a0bf528SMauro Carvalho Chehab 1879a0bf528SMauro Carvalho Chehab enum stb0899_alpha rrc_alpha; 1889a0bf528SMauro Carvalho Chehab enum stb0899_inversion inversion; 1899a0bf528SMauro Carvalho Chehab enum stb0899_modcod modcod; 1909a0bf528SMauro Carvalho Chehab u8 pilots; /* Pilots found */ 1919a0bf528SMauro Carvalho Chehab 1929a0bf528SMauro Carvalho Chehab enum stb0899_frame frame_length; 1939a0bf528SMauro Carvalho Chehab u8 v_status; /* VSTATUS */ 1949a0bf528SMauro Carvalho Chehab u8 err_ctrl; /* ERRCTRLn */ 1959a0bf528SMauro Carvalho Chehab }; 1969a0bf528SMauro Carvalho Chehab 1979a0bf528SMauro Carvalho Chehab struct stb0899_state { 1989a0bf528SMauro Carvalho Chehab struct i2c_adapter *i2c; 1999a0bf528SMauro Carvalho Chehab struct stb0899_config *config; 2009a0bf528SMauro Carvalho Chehab struct dvb_frontend frontend; 2019a0bf528SMauro Carvalho Chehab 2029a0bf528SMauro Carvalho Chehab u32 *verbose; /* Cached module verbosity level */ 2039a0bf528SMauro Carvalho Chehab 2049a0bf528SMauro Carvalho Chehab struct stb0899_internal internal; /* Device internal parameters */ 2059a0bf528SMauro Carvalho Chehab 2069a0bf528SMauro Carvalho Chehab /* cached params from API */ 2079a0bf528SMauro Carvalho Chehab enum fe_delivery_system delsys; 2089a0bf528SMauro Carvalho Chehab struct stb0899_params params; 2099a0bf528SMauro Carvalho Chehab 2109a0bf528SMauro Carvalho Chehab u32 rx_freq; /* DiSEqC 2.0 receiver freq */ 2119a0bf528SMauro Carvalho Chehab struct mutex search_lock; 2129a0bf528SMauro Carvalho Chehab }; 2139a0bf528SMauro Carvalho Chehab /* stb0899.c */ 2149a0bf528SMauro Carvalho Chehab extern int stb0899_read_reg(struct stb0899_state *state, 2159a0bf528SMauro Carvalho Chehab unsigned int reg); 2169a0bf528SMauro Carvalho Chehab 2179a0bf528SMauro Carvalho Chehab extern u32 _stb0899_read_s2reg(struct stb0899_state *state, 2189a0bf528SMauro Carvalho Chehab u32 stb0899_i2cdev, 2199a0bf528SMauro Carvalho Chehab u32 stb0899_base_addr, 2209a0bf528SMauro Carvalho Chehab u16 stb0899_reg_offset); 2219a0bf528SMauro Carvalho Chehab 2229a0bf528SMauro Carvalho Chehab extern int stb0899_read_regs(struct stb0899_state *state, 2239a0bf528SMauro Carvalho Chehab unsigned int reg, u8 *buf, 2249a0bf528SMauro Carvalho Chehab u32 count); 2259a0bf528SMauro Carvalho Chehab 2269a0bf528SMauro Carvalho Chehab extern int stb0899_write_regs(struct stb0899_state *state, 2279a0bf528SMauro Carvalho Chehab unsigned int reg, u8 *data, 2289a0bf528SMauro Carvalho Chehab u32 count); 2299a0bf528SMauro Carvalho Chehab 2309a0bf528SMauro Carvalho Chehab extern int stb0899_write_reg(struct stb0899_state *state, 2319a0bf528SMauro Carvalho Chehab unsigned int reg, 2329a0bf528SMauro Carvalho Chehab u8 data); 2339a0bf528SMauro Carvalho Chehab 2349a0bf528SMauro Carvalho Chehab extern int stb0899_write_s2reg(struct stb0899_state *state, 2359a0bf528SMauro Carvalho Chehab u32 stb0899_i2cdev, 2369a0bf528SMauro Carvalho Chehab u32 stb0899_base_addr, 2379a0bf528SMauro Carvalho Chehab u16 stb0899_reg_offset, 2389a0bf528SMauro Carvalho Chehab u32 stb0899_data); 2399a0bf528SMauro Carvalho Chehab 2409a0bf528SMauro Carvalho Chehab extern int stb0899_i2c_gate_ctrl(struct dvb_frontend *fe, int enable); 2419a0bf528SMauro Carvalho Chehab 2429a0bf528SMauro Carvalho Chehab 2439a0bf528SMauro Carvalho Chehab #define STB0899_READ_S2REG(DEVICE, REG) (_stb0899_read_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG)) 2449a0bf528SMauro Carvalho Chehab //#define STB0899_WRITE_S2REG(DEVICE, REG, DATA) (_stb0899_write_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG, DATA)) 2459a0bf528SMauro Carvalho Chehab 2469a0bf528SMauro Carvalho Chehab /* stb0899_algo.c */ 2479a0bf528SMauro Carvalho Chehab extern enum stb0899_status stb0899_dvbs_algo(struct stb0899_state *state); 2489a0bf528SMauro Carvalho Chehab extern enum stb0899_status stb0899_dvbs2_algo(struct stb0899_state *state); 2499a0bf528SMauro Carvalho Chehab extern long stb0899_carr_width(struct stb0899_state *state); 2509a0bf528SMauro Carvalho Chehab 2519a0bf528SMauro Carvalho Chehab #endif //__STB0899_PRIV_H 252