162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci tda18271-priv.h - private header for the NXP TDA18271 silicon tuner 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci*/ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#ifndef __TDA18271_PRIV_H__ 1062306a36Sopenharmony_ci#define __TDA18271_PRIV_H__ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <linux/kernel.h> 1562306a36Sopenharmony_ci#include <linux/types.h> 1662306a36Sopenharmony_ci#include <linux/mutex.h> 1762306a36Sopenharmony_ci#include "tuner-i2c.h" 1862306a36Sopenharmony_ci#include "tda18271.h" 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#define R_ID 0x00 /* ID byte */ 2162306a36Sopenharmony_ci#define R_TM 0x01 /* Thermo byte */ 2262306a36Sopenharmony_ci#define R_PL 0x02 /* Power level byte */ 2362306a36Sopenharmony_ci#define R_EP1 0x03 /* Easy Prog byte 1 */ 2462306a36Sopenharmony_ci#define R_EP2 0x04 /* Easy Prog byte 2 */ 2562306a36Sopenharmony_ci#define R_EP3 0x05 /* Easy Prog byte 3 */ 2662306a36Sopenharmony_ci#define R_EP4 0x06 /* Easy Prog byte 4 */ 2762306a36Sopenharmony_ci#define R_EP5 0x07 /* Easy Prog byte 5 */ 2862306a36Sopenharmony_ci#define R_CPD 0x08 /* Cal Post-Divider byte */ 2962306a36Sopenharmony_ci#define R_CD1 0x09 /* Cal Divider byte 1 */ 3062306a36Sopenharmony_ci#define R_CD2 0x0a /* Cal Divider byte 2 */ 3162306a36Sopenharmony_ci#define R_CD3 0x0b /* Cal Divider byte 3 */ 3262306a36Sopenharmony_ci#define R_MPD 0x0c /* Main Post-Divider byte */ 3362306a36Sopenharmony_ci#define R_MD1 0x0d /* Main Divider byte 1 */ 3462306a36Sopenharmony_ci#define R_MD2 0x0e /* Main Divider byte 2 */ 3562306a36Sopenharmony_ci#define R_MD3 0x0f /* Main Divider byte 3 */ 3662306a36Sopenharmony_ci#define R_EB1 0x10 /* Extended byte 1 */ 3762306a36Sopenharmony_ci#define R_EB2 0x11 /* Extended byte 2 */ 3862306a36Sopenharmony_ci#define R_EB3 0x12 /* Extended byte 3 */ 3962306a36Sopenharmony_ci#define R_EB4 0x13 /* Extended byte 4 */ 4062306a36Sopenharmony_ci#define R_EB5 0x14 /* Extended byte 5 */ 4162306a36Sopenharmony_ci#define R_EB6 0x15 /* Extended byte 6 */ 4262306a36Sopenharmony_ci#define R_EB7 0x16 /* Extended byte 7 */ 4362306a36Sopenharmony_ci#define R_EB8 0x17 /* Extended byte 8 */ 4462306a36Sopenharmony_ci#define R_EB9 0x18 /* Extended byte 9 */ 4562306a36Sopenharmony_ci#define R_EB10 0x19 /* Extended byte 10 */ 4662306a36Sopenharmony_ci#define R_EB11 0x1a /* Extended byte 11 */ 4762306a36Sopenharmony_ci#define R_EB12 0x1b /* Extended byte 12 */ 4862306a36Sopenharmony_ci#define R_EB13 0x1c /* Extended byte 13 */ 4962306a36Sopenharmony_ci#define R_EB14 0x1d /* Extended byte 14 */ 5062306a36Sopenharmony_ci#define R_EB15 0x1e /* Extended byte 15 */ 5162306a36Sopenharmony_ci#define R_EB16 0x1f /* Extended byte 16 */ 5262306a36Sopenharmony_ci#define R_EB17 0x20 /* Extended byte 17 */ 5362306a36Sopenharmony_ci#define R_EB18 0x21 /* Extended byte 18 */ 5462306a36Sopenharmony_ci#define R_EB19 0x22 /* Extended byte 19 */ 5562306a36Sopenharmony_ci#define R_EB20 0x23 /* Extended byte 20 */ 5662306a36Sopenharmony_ci#define R_EB21 0x24 /* Extended byte 21 */ 5762306a36Sopenharmony_ci#define R_EB22 0x25 /* Extended byte 22 */ 5862306a36Sopenharmony_ci#define R_EB23 0x26 /* Extended byte 23 */ 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#define TDA18271_NUM_REGS 39 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/*---------------------------------------------------------------------*/ 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_cistruct tda18271_rf_tracking_filter_cal { 6562306a36Sopenharmony_ci u32 rfmax; 6662306a36Sopenharmony_ci u8 rfband; 6762306a36Sopenharmony_ci u32 rf1_def; 6862306a36Sopenharmony_ci u32 rf2_def; 6962306a36Sopenharmony_ci u32 rf3_def; 7062306a36Sopenharmony_ci u32 rf1; 7162306a36Sopenharmony_ci u32 rf2; 7262306a36Sopenharmony_ci u32 rf3; 7362306a36Sopenharmony_ci s32 rf_a1; 7462306a36Sopenharmony_ci s32 rf_b1; 7562306a36Sopenharmony_ci s32 rf_a2; 7662306a36Sopenharmony_ci s32 rf_b2; 7762306a36Sopenharmony_ci}; 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_cienum tda18271_pll { 8062306a36Sopenharmony_ci TDA18271_MAIN_PLL, 8162306a36Sopenharmony_ci TDA18271_CAL_PLL, 8262306a36Sopenharmony_ci}; 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_cistruct tda18271_map_layout; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_cienum tda18271_ver { 8762306a36Sopenharmony_ci TDA18271HDC1, 8862306a36Sopenharmony_ci TDA18271HDC2, 8962306a36Sopenharmony_ci}; 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_cistruct tda18271_priv { 9262306a36Sopenharmony_ci unsigned char tda18271_regs[TDA18271_NUM_REGS]; 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci struct list_head hybrid_tuner_instance_list; 9562306a36Sopenharmony_ci struct tuner_i2c_props i2c_props; 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci enum tda18271_mode mode; 9862306a36Sopenharmony_ci enum tda18271_role role; 9962306a36Sopenharmony_ci enum tda18271_i2c_gate gate; 10062306a36Sopenharmony_ci enum tda18271_ver id; 10162306a36Sopenharmony_ci enum tda18271_output_options output_opt; 10262306a36Sopenharmony_ci enum tda18271_small_i2c small_i2c; 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci unsigned int config; /* interface to saa713x / tda829x */ 10562306a36Sopenharmony_ci unsigned int cal_initialized:1; 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci u8 tm_rfcal; 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci struct tda18271_map_layout *maps; 11062306a36Sopenharmony_ci struct tda18271_std_map std; 11162306a36Sopenharmony_ci struct tda18271_rf_tracking_filter_cal rf_cal_state[8]; 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci struct mutex lock; 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci u16 if_freq; 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci u32 frequency; 11862306a36Sopenharmony_ci u32 bandwidth; 11962306a36Sopenharmony_ci}; 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci/*---------------------------------------------------------------------*/ 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ciextern int tda18271_debug; 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci#define DBG_INFO 1 12662306a36Sopenharmony_ci#define DBG_MAP 2 12762306a36Sopenharmony_ci#define DBG_REG 4 12862306a36Sopenharmony_ci#define DBG_ADV 8 12962306a36Sopenharmony_ci#define DBG_CAL 16 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci__attribute__((format(printf, 4, 5))) 13262306a36Sopenharmony_civoid _tda_printk(struct tda18271_priv *state, const char *level, 13362306a36Sopenharmony_ci const char *func, const char *fmt, ...); 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci#define tda_printk(st, lvl, fmt, arg...) \ 13662306a36Sopenharmony_ci _tda_printk(st, lvl, __func__, fmt, ##arg) 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci#define tda_dprintk(st, lvl, fmt, arg...) \ 13962306a36Sopenharmony_cido { \ 14062306a36Sopenharmony_ci if (tda18271_debug & lvl) \ 14162306a36Sopenharmony_ci tda_printk(st, KERN_DEBUG, fmt, ##arg); \ 14262306a36Sopenharmony_ci} while (0) 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci#define tda_info(fmt, arg...) pr_info(fmt, ##arg) 14562306a36Sopenharmony_ci#define tda_warn(fmt, arg...) tda_printk(priv, KERN_WARNING, fmt, ##arg) 14662306a36Sopenharmony_ci#define tda_err(fmt, arg...) tda_printk(priv, KERN_ERR, fmt, ##arg) 14762306a36Sopenharmony_ci#define tda_dbg(fmt, arg...) tda_dprintk(priv, DBG_INFO, fmt, ##arg) 14862306a36Sopenharmony_ci#define tda_map(fmt, arg...) tda_dprintk(priv, DBG_MAP, fmt, ##arg) 14962306a36Sopenharmony_ci#define tda_reg(fmt, arg...) tda_dprintk(priv, DBG_REG, fmt, ##arg) 15062306a36Sopenharmony_ci#define tda_cal(fmt, arg...) tda_dprintk(priv, DBG_CAL, fmt, ##arg) 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci#define tda_fail(ret) \ 15362306a36Sopenharmony_ci({ \ 15462306a36Sopenharmony_ci int __ret; \ 15562306a36Sopenharmony_ci __ret = (ret < 0); \ 15662306a36Sopenharmony_ci if (__ret) \ 15762306a36Sopenharmony_ci tda_printk(priv, KERN_ERR, \ 15862306a36Sopenharmony_ci "error %d on line %d\n", ret, __LINE__); \ 15962306a36Sopenharmony_ci __ret; \ 16062306a36Sopenharmony_ci}) 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci/*---------------------------------------------------------------------*/ 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_cienum tda18271_map_type { 16562306a36Sopenharmony_ci /* tda18271_pll_map */ 16662306a36Sopenharmony_ci MAIN_PLL, 16762306a36Sopenharmony_ci CAL_PLL, 16862306a36Sopenharmony_ci /* tda18271_map */ 16962306a36Sopenharmony_ci RF_CAL, 17062306a36Sopenharmony_ci RF_CAL_KMCO, 17162306a36Sopenharmony_ci RF_CAL_DC_OVER_DT, 17262306a36Sopenharmony_ci BP_FILTER, 17362306a36Sopenharmony_ci RF_BAND, 17462306a36Sopenharmony_ci GAIN_TAPER, 17562306a36Sopenharmony_ci IR_MEASURE, 17662306a36Sopenharmony_ci}; 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ciextern int tda18271_lookup_pll_map(struct dvb_frontend *fe, 17962306a36Sopenharmony_ci enum tda18271_map_type map_type, 18062306a36Sopenharmony_ci u32 *freq, u8 *post_div, u8 *div); 18162306a36Sopenharmony_ciextern int tda18271_lookup_map(struct dvb_frontend *fe, 18262306a36Sopenharmony_ci enum tda18271_map_type map_type, 18362306a36Sopenharmony_ci u32 *freq, u8 *val); 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ciextern int tda18271_lookup_thermometer(struct dvb_frontend *fe); 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ciextern int tda18271_lookup_rf_band(struct dvb_frontend *fe, 18862306a36Sopenharmony_ci u32 *freq, u8 *rf_band); 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ciextern int tda18271_lookup_cid_target(struct dvb_frontend *fe, 19162306a36Sopenharmony_ci u32 *freq, u8 *cid_target, 19262306a36Sopenharmony_ci u16 *count_limit); 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ciextern int tda18271_assign_map_layout(struct dvb_frontend *fe); 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci/*---------------------------------------------------------------------*/ 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ciextern int tda18271_read_regs(struct dvb_frontend *fe); 19962306a36Sopenharmony_ciextern int tda18271_read_extended(struct dvb_frontend *fe); 20062306a36Sopenharmony_ciextern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len); 20162306a36Sopenharmony_ciextern int tda18271_init_regs(struct dvb_frontend *fe); 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ciextern int tda18271_charge_pump_source(struct dvb_frontend *fe, 20462306a36Sopenharmony_ci enum tda18271_pll pll, int force); 20562306a36Sopenharmony_ciextern int tda18271_set_standby_mode(struct dvb_frontend *fe, 20662306a36Sopenharmony_ci int sm, int sm_lt, int sm_xt); 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ciextern int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq); 20962306a36Sopenharmony_ciextern int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq); 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ciextern int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq); 21262306a36Sopenharmony_ciextern int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq); 21362306a36Sopenharmony_ciextern int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq); 21462306a36Sopenharmony_ciextern int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq); 21562306a36Sopenharmony_ciextern int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq); 21662306a36Sopenharmony_ciextern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq); 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ci#endif /* __TDA18271_PRIV_H__ */ 219