1ccae7af2SMauro Carvalho Chehab /* 2ccae7af2SMauro Carvalho Chehab tda18271-priv.h - private header for the NXP TDA18271 silicon tuner 3ccae7af2SMauro Carvalho Chehab 4ccae7af2SMauro Carvalho Chehab Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org> 5ccae7af2SMauro Carvalho Chehab 6ccae7af2SMauro Carvalho Chehab This program is free software; you can redistribute it and/or modify 7ccae7af2SMauro Carvalho Chehab it under the terms of the GNU General Public License as published by 8ccae7af2SMauro Carvalho Chehab the Free Software Foundation; either version 2 of the License, or 9ccae7af2SMauro Carvalho Chehab (at your option) any later version. 10ccae7af2SMauro Carvalho Chehab 11ccae7af2SMauro Carvalho Chehab This program is distributed in the hope that it will be useful, 12ccae7af2SMauro Carvalho Chehab but WITHOUT ANY WARRANTY; without even the implied warranty of 13ccae7af2SMauro Carvalho Chehab MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14ccae7af2SMauro Carvalho Chehab GNU General Public License for more details. 15ccae7af2SMauro Carvalho Chehab 16ccae7af2SMauro Carvalho Chehab You should have received a copy of the GNU General Public License 17ccae7af2SMauro Carvalho Chehab along with this program; if not, write to the Free Software 18ccae7af2SMauro Carvalho Chehab Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19ccae7af2SMauro Carvalho Chehab */ 20ccae7af2SMauro Carvalho Chehab 21ccae7af2SMauro Carvalho Chehab #ifndef __TDA18271_PRIV_H__ 22ccae7af2SMauro Carvalho Chehab #define __TDA18271_PRIV_H__ 23ccae7af2SMauro Carvalho Chehab 24*36dba13bSMauro Carvalho Chehab #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 25*36dba13bSMauro Carvalho Chehab 26ccae7af2SMauro Carvalho Chehab #include <linux/kernel.h> 27ccae7af2SMauro Carvalho Chehab #include <linux/types.h> 28ccae7af2SMauro Carvalho Chehab #include <linux/mutex.h> 29ccae7af2SMauro Carvalho Chehab #include "tuner-i2c.h" 30ccae7af2SMauro Carvalho Chehab #include "tda18271.h" 31ccae7af2SMauro Carvalho Chehab 32ccae7af2SMauro Carvalho Chehab #define R_ID 0x00 /* ID byte */ 33ccae7af2SMauro Carvalho Chehab #define R_TM 0x01 /* Thermo byte */ 34ccae7af2SMauro Carvalho Chehab #define R_PL 0x02 /* Power level byte */ 35ccae7af2SMauro Carvalho Chehab #define R_EP1 0x03 /* Easy Prog byte 1 */ 36ccae7af2SMauro Carvalho Chehab #define R_EP2 0x04 /* Easy Prog byte 2 */ 37ccae7af2SMauro Carvalho Chehab #define R_EP3 0x05 /* Easy Prog byte 3 */ 38ccae7af2SMauro Carvalho Chehab #define R_EP4 0x06 /* Easy Prog byte 4 */ 39ccae7af2SMauro Carvalho Chehab #define R_EP5 0x07 /* Easy Prog byte 5 */ 40ccae7af2SMauro Carvalho Chehab #define R_CPD 0x08 /* Cal Post-Divider byte */ 41ccae7af2SMauro Carvalho Chehab #define R_CD1 0x09 /* Cal Divider byte 1 */ 42ccae7af2SMauro Carvalho Chehab #define R_CD2 0x0a /* Cal Divider byte 2 */ 43ccae7af2SMauro Carvalho Chehab #define R_CD3 0x0b /* Cal Divider byte 3 */ 44ccae7af2SMauro Carvalho Chehab #define R_MPD 0x0c /* Main Post-Divider byte */ 45ccae7af2SMauro Carvalho Chehab #define R_MD1 0x0d /* Main Divider byte 1 */ 46ccae7af2SMauro Carvalho Chehab #define R_MD2 0x0e /* Main Divider byte 2 */ 47ccae7af2SMauro Carvalho Chehab #define R_MD3 0x0f /* Main Divider byte 3 */ 48ccae7af2SMauro Carvalho Chehab #define R_EB1 0x10 /* Extended byte 1 */ 49ccae7af2SMauro Carvalho Chehab #define R_EB2 0x11 /* Extended byte 2 */ 50ccae7af2SMauro Carvalho Chehab #define R_EB3 0x12 /* Extended byte 3 */ 51ccae7af2SMauro Carvalho Chehab #define R_EB4 0x13 /* Extended byte 4 */ 52ccae7af2SMauro Carvalho Chehab #define R_EB5 0x14 /* Extended byte 5 */ 53ccae7af2SMauro Carvalho Chehab #define R_EB6 0x15 /* Extended byte 6 */ 54ccae7af2SMauro Carvalho Chehab #define R_EB7 0x16 /* Extended byte 7 */ 55ccae7af2SMauro Carvalho Chehab #define R_EB8 0x17 /* Extended byte 8 */ 56ccae7af2SMauro Carvalho Chehab #define R_EB9 0x18 /* Extended byte 9 */ 57ccae7af2SMauro Carvalho Chehab #define R_EB10 0x19 /* Extended byte 10 */ 58ccae7af2SMauro Carvalho Chehab #define R_EB11 0x1a /* Extended byte 11 */ 59ccae7af2SMauro Carvalho Chehab #define R_EB12 0x1b /* Extended byte 12 */ 60ccae7af2SMauro Carvalho Chehab #define R_EB13 0x1c /* Extended byte 13 */ 61ccae7af2SMauro Carvalho Chehab #define R_EB14 0x1d /* Extended byte 14 */ 62ccae7af2SMauro Carvalho Chehab #define R_EB15 0x1e /* Extended byte 15 */ 63ccae7af2SMauro Carvalho Chehab #define R_EB16 0x1f /* Extended byte 16 */ 64ccae7af2SMauro Carvalho Chehab #define R_EB17 0x20 /* Extended byte 17 */ 65ccae7af2SMauro Carvalho Chehab #define R_EB18 0x21 /* Extended byte 18 */ 66ccae7af2SMauro Carvalho Chehab #define R_EB19 0x22 /* Extended byte 19 */ 67ccae7af2SMauro Carvalho Chehab #define R_EB20 0x23 /* Extended byte 20 */ 68ccae7af2SMauro Carvalho Chehab #define R_EB21 0x24 /* Extended byte 21 */ 69ccae7af2SMauro Carvalho Chehab #define R_EB22 0x25 /* Extended byte 22 */ 70ccae7af2SMauro Carvalho Chehab #define R_EB23 0x26 /* Extended byte 23 */ 71ccae7af2SMauro Carvalho Chehab 72ccae7af2SMauro Carvalho Chehab #define TDA18271_NUM_REGS 39 73ccae7af2SMauro Carvalho Chehab 74ccae7af2SMauro Carvalho Chehab /*---------------------------------------------------------------------*/ 75ccae7af2SMauro Carvalho Chehab 76ccae7af2SMauro Carvalho Chehab struct tda18271_rf_tracking_filter_cal { 77ccae7af2SMauro Carvalho Chehab u32 rfmax; 78ccae7af2SMauro Carvalho Chehab u8 rfband; 79ccae7af2SMauro Carvalho Chehab u32 rf1_def; 80ccae7af2SMauro Carvalho Chehab u32 rf2_def; 81ccae7af2SMauro Carvalho Chehab u32 rf3_def; 82ccae7af2SMauro Carvalho Chehab u32 rf1; 83ccae7af2SMauro Carvalho Chehab u32 rf2; 84ccae7af2SMauro Carvalho Chehab u32 rf3; 85ccae7af2SMauro Carvalho Chehab s32 rf_a1; 86ccae7af2SMauro Carvalho Chehab s32 rf_b1; 87ccae7af2SMauro Carvalho Chehab s32 rf_a2; 88ccae7af2SMauro Carvalho Chehab s32 rf_b2; 89ccae7af2SMauro Carvalho Chehab }; 90ccae7af2SMauro Carvalho Chehab 91ccae7af2SMauro Carvalho Chehab enum tda18271_pll { 92ccae7af2SMauro Carvalho Chehab TDA18271_MAIN_PLL, 93ccae7af2SMauro Carvalho Chehab TDA18271_CAL_PLL, 94ccae7af2SMauro Carvalho Chehab }; 95ccae7af2SMauro Carvalho Chehab 96ccae7af2SMauro Carvalho Chehab struct tda18271_map_layout; 97ccae7af2SMauro Carvalho Chehab 98ccae7af2SMauro Carvalho Chehab enum tda18271_ver { 99ccae7af2SMauro Carvalho Chehab TDA18271HDC1, 100ccae7af2SMauro Carvalho Chehab TDA18271HDC2, 101ccae7af2SMauro Carvalho Chehab }; 102ccae7af2SMauro Carvalho Chehab 103ccae7af2SMauro Carvalho Chehab struct tda18271_priv { 104ccae7af2SMauro Carvalho Chehab unsigned char tda18271_regs[TDA18271_NUM_REGS]; 105ccae7af2SMauro Carvalho Chehab 106ccae7af2SMauro Carvalho Chehab struct list_head hybrid_tuner_instance_list; 107ccae7af2SMauro Carvalho Chehab struct tuner_i2c_props i2c_props; 108ccae7af2SMauro Carvalho Chehab 109ccae7af2SMauro Carvalho Chehab enum tda18271_mode mode; 110ccae7af2SMauro Carvalho Chehab enum tda18271_role role; 111ccae7af2SMauro Carvalho Chehab enum tda18271_i2c_gate gate; 112ccae7af2SMauro Carvalho Chehab enum tda18271_ver id; 113ccae7af2SMauro Carvalho Chehab enum tda18271_output_options output_opt; 114ccae7af2SMauro Carvalho Chehab enum tda18271_small_i2c small_i2c; 115ccae7af2SMauro Carvalho Chehab 116ccae7af2SMauro Carvalho Chehab unsigned int config; /* interface to saa713x / tda829x */ 117ccae7af2SMauro Carvalho Chehab unsigned int cal_initialized:1; 118ccae7af2SMauro Carvalho Chehab 119ccae7af2SMauro Carvalho Chehab u8 tm_rfcal; 120ccae7af2SMauro Carvalho Chehab 121ccae7af2SMauro Carvalho Chehab struct tda18271_map_layout *maps; 122ccae7af2SMauro Carvalho Chehab struct tda18271_std_map std; 123ccae7af2SMauro Carvalho Chehab struct tda18271_rf_tracking_filter_cal rf_cal_state[8]; 124ccae7af2SMauro Carvalho Chehab 125ccae7af2SMauro Carvalho Chehab struct mutex lock; 126ccae7af2SMauro Carvalho Chehab 127ccae7af2SMauro Carvalho Chehab u16 if_freq; 128ccae7af2SMauro Carvalho Chehab 129ccae7af2SMauro Carvalho Chehab u32 frequency; 130ccae7af2SMauro Carvalho Chehab u32 bandwidth; 131ccae7af2SMauro Carvalho Chehab }; 132ccae7af2SMauro Carvalho Chehab 133ccae7af2SMauro Carvalho Chehab /*---------------------------------------------------------------------*/ 134ccae7af2SMauro Carvalho Chehab 135ccae7af2SMauro Carvalho Chehab extern int tda18271_debug; 136ccae7af2SMauro Carvalho Chehab 137ccae7af2SMauro Carvalho Chehab #define DBG_INFO 1 138ccae7af2SMauro Carvalho Chehab #define DBG_MAP 2 139ccae7af2SMauro Carvalho Chehab #define DBG_REG 4 140ccae7af2SMauro Carvalho Chehab #define DBG_ADV 8 141ccae7af2SMauro Carvalho Chehab #define DBG_CAL 16 142ccae7af2SMauro Carvalho Chehab 143ccae7af2SMauro Carvalho Chehab __attribute__((format(printf, 4, 5))) 1440f531e73SJoe Perches void _tda_printk(struct tda18271_priv *state, const char *level, 145ccae7af2SMauro Carvalho Chehab const char *func, const char *fmt, ...); 146ccae7af2SMauro Carvalho Chehab 147ccae7af2SMauro Carvalho Chehab #define tda_printk(st, lvl, fmt, arg...) \ 148ccae7af2SMauro Carvalho Chehab _tda_printk(st, lvl, __func__, fmt, ##arg) 149ccae7af2SMauro Carvalho Chehab 150ccae7af2SMauro Carvalho Chehab #define tda_dprintk(st, lvl, fmt, arg...) \ 151ccae7af2SMauro Carvalho Chehab do { \ 152ccae7af2SMauro Carvalho Chehab if (tda18271_debug & lvl) \ 153ccae7af2SMauro Carvalho Chehab tda_printk(st, KERN_DEBUG, fmt, ##arg); \ 154ccae7af2SMauro Carvalho Chehab } while (0) 155ccae7af2SMauro Carvalho Chehab 156ccae7af2SMauro Carvalho Chehab #define tda_info(fmt, arg...) pr_info(fmt, ##arg) 157ccae7af2SMauro Carvalho Chehab #define tda_warn(fmt, arg...) tda_printk(priv, KERN_WARNING, fmt, ##arg) 158ccae7af2SMauro Carvalho Chehab #define tda_err(fmt, arg...) tda_printk(priv, KERN_ERR, fmt, ##arg) 159ccae7af2SMauro Carvalho Chehab #define tda_dbg(fmt, arg...) tda_dprintk(priv, DBG_INFO, fmt, ##arg) 160ccae7af2SMauro Carvalho Chehab #define tda_map(fmt, arg...) tda_dprintk(priv, DBG_MAP, fmt, ##arg) 161ccae7af2SMauro Carvalho Chehab #define tda_reg(fmt, arg...) tda_dprintk(priv, DBG_REG, fmt, ##arg) 162ccae7af2SMauro Carvalho Chehab #define tda_cal(fmt, arg...) tda_dprintk(priv, DBG_CAL, fmt, ##arg) 163ccae7af2SMauro Carvalho Chehab 164ccae7af2SMauro Carvalho Chehab #define tda_fail(ret) \ 165ccae7af2SMauro Carvalho Chehab ({ \ 166ccae7af2SMauro Carvalho Chehab int __ret; \ 167ccae7af2SMauro Carvalho Chehab __ret = (ret < 0); \ 168ccae7af2SMauro Carvalho Chehab if (__ret) \ 169ccae7af2SMauro Carvalho Chehab tda_printk(priv, KERN_ERR, \ 170ccae7af2SMauro Carvalho Chehab "error %d on line %d\n", ret, __LINE__); \ 171ccae7af2SMauro Carvalho Chehab __ret; \ 172ccae7af2SMauro Carvalho Chehab }) 173ccae7af2SMauro Carvalho Chehab 174ccae7af2SMauro Carvalho Chehab /*---------------------------------------------------------------------*/ 175ccae7af2SMauro Carvalho Chehab 176ccae7af2SMauro Carvalho Chehab enum tda18271_map_type { 177ccae7af2SMauro Carvalho Chehab /* tda18271_pll_map */ 178ccae7af2SMauro Carvalho Chehab MAIN_PLL, 179ccae7af2SMauro Carvalho Chehab CAL_PLL, 180ccae7af2SMauro Carvalho Chehab /* tda18271_map */ 181ccae7af2SMauro Carvalho Chehab RF_CAL, 182ccae7af2SMauro Carvalho Chehab RF_CAL_KMCO, 183ccae7af2SMauro Carvalho Chehab RF_CAL_DC_OVER_DT, 184ccae7af2SMauro Carvalho Chehab BP_FILTER, 185ccae7af2SMauro Carvalho Chehab RF_BAND, 186ccae7af2SMauro Carvalho Chehab GAIN_TAPER, 187ccae7af2SMauro Carvalho Chehab IR_MEASURE, 188ccae7af2SMauro Carvalho Chehab }; 189ccae7af2SMauro Carvalho Chehab 190ccae7af2SMauro Carvalho Chehab extern int tda18271_lookup_pll_map(struct dvb_frontend *fe, 191ccae7af2SMauro Carvalho Chehab enum tda18271_map_type map_type, 192ccae7af2SMauro Carvalho Chehab u32 *freq, u8 *post_div, u8 *div); 193ccae7af2SMauro Carvalho Chehab extern int tda18271_lookup_map(struct dvb_frontend *fe, 194ccae7af2SMauro Carvalho Chehab enum tda18271_map_type map_type, 195ccae7af2SMauro Carvalho Chehab u32 *freq, u8 *val); 196ccae7af2SMauro Carvalho Chehab 197ccae7af2SMauro Carvalho Chehab extern int tda18271_lookup_thermometer(struct dvb_frontend *fe); 198ccae7af2SMauro Carvalho Chehab 199ccae7af2SMauro Carvalho Chehab extern int tda18271_lookup_rf_band(struct dvb_frontend *fe, 200ccae7af2SMauro Carvalho Chehab u32 *freq, u8 *rf_band); 201ccae7af2SMauro Carvalho Chehab 202ccae7af2SMauro Carvalho Chehab extern int tda18271_lookup_cid_target(struct dvb_frontend *fe, 203ccae7af2SMauro Carvalho Chehab u32 *freq, u8 *cid_target, 204ccae7af2SMauro Carvalho Chehab u16 *count_limit); 205ccae7af2SMauro Carvalho Chehab 206ccae7af2SMauro Carvalho Chehab extern int tda18271_assign_map_layout(struct dvb_frontend *fe); 207ccae7af2SMauro Carvalho Chehab 208ccae7af2SMauro Carvalho Chehab /*---------------------------------------------------------------------*/ 209ccae7af2SMauro Carvalho Chehab 210ccae7af2SMauro Carvalho Chehab extern int tda18271_read_regs(struct dvb_frontend *fe); 211ccae7af2SMauro Carvalho Chehab extern int tda18271_read_extended(struct dvb_frontend *fe); 212ccae7af2SMauro Carvalho Chehab extern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len); 213ccae7af2SMauro Carvalho Chehab extern int tda18271_init_regs(struct dvb_frontend *fe); 214ccae7af2SMauro Carvalho Chehab 215ccae7af2SMauro Carvalho Chehab extern int tda18271_charge_pump_source(struct dvb_frontend *fe, 216ccae7af2SMauro Carvalho Chehab enum tda18271_pll pll, int force); 217ccae7af2SMauro Carvalho Chehab extern int tda18271_set_standby_mode(struct dvb_frontend *fe, 218ccae7af2SMauro Carvalho Chehab int sm, int sm_lt, int sm_xt); 219ccae7af2SMauro Carvalho Chehab 220ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq); 221ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq); 222ccae7af2SMauro Carvalho Chehab 223ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq); 224ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq); 225ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq); 226ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq); 227ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq); 228ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq); 229ccae7af2SMauro Carvalho Chehab 230ccae7af2SMauro Carvalho Chehab #endif /* __TDA18271_PRIV_H__ */ 231