18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci    tda18271-priv.h - private header for the NXP TDA18271 silicon tuner
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci    Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci*/
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef __TDA18271_PRIV_H__
108c2ecf20Sopenharmony_ci#define __TDA18271_PRIV_H__
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/kernel.h>
158c2ecf20Sopenharmony_ci#include <linux/types.h>
168c2ecf20Sopenharmony_ci#include <linux/mutex.h>
178c2ecf20Sopenharmony_ci#include "tuner-i2c.h"
188c2ecf20Sopenharmony_ci#include "tda18271.h"
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define R_ID     0x00	/* ID byte                */
218c2ecf20Sopenharmony_ci#define R_TM     0x01	/* Thermo byte            */
228c2ecf20Sopenharmony_ci#define R_PL     0x02	/* Power level byte       */
238c2ecf20Sopenharmony_ci#define R_EP1    0x03	/* Easy Prog byte 1       */
248c2ecf20Sopenharmony_ci#define R_EP2    0x04	/* Easy Prog byte 2       */
258c2ecf20Sopenharmony_ci#define R_EP3    0x05	/* Easy Prog byte 3       */
268c2ecf20Sopenharmony_ci#define R_EP4    0x06	/* Easy Prog byte 4       */
278c2ecf20Sopenharmony_ci#define R_EP5    0x07	/* Easy Prog byte 5       */
288c2ecf20Sopenharmony_ci#define R_CPD    0x08	/* Cal Post-Divider byte  */
298c2ecf20Sopenharmony_ci#define R_CD1    0x09	/* Cal Divider byte 1     */
308c2ecf20Sopenharmony_ci#define R_CD2    0x0a	/* Cal Divider byte 2     */
318c2ecf20Sopenharmony_ci#define R_CD3    0x0b	/* Cal Divider byte 3     */
328c2ecf20Sopenharmony_ci#define R_MPD    0x0c	/* Main Post-Divider byte */
338c2ecf20Sopenharmony_ci#define R_MD1    0x0d	/* Main Divider byte 1    */
348c2ecf20Sopenharmony_ci#define R_MD2    0x0e	/* Main Divider byte 2    */
358c2ecf20Sopenharmony_ci#define R_MD3    0x0f	/* Main Divider byte 3    */
368c2ecf20Sopenharmony_ci#define R_EB1    0x10	/* Extended byte 1        */
378c2ecf20Sopenharmony_ci#define R_EB2    0x11	/* Extended byte 2        */
388c2ecf20Sopenharmony_ci#define R_EB3    0x12	/* Extended byte 3        */
398c2ecf20Sopenharmony_ci#define R_EB4    0x13	/* Extended byte 4        */
408c2ecf20Sopenharmony_ci#define R_EB5    0x14	/* Extended byte 5        */
418c2ecf20Sopenharmony_ci#define R_EB6    0x15	/* Extended byte 6        */
428c2ecf20Sopenharmony_ci#define R_EB7    0x16	/* Extended byte 7        */
438c2ecf20Sopenharmony_ci#define R_EB8    0x17	/* Extended byte 8        */
448c2ecf20Sopenharmony_ci#define R_EB9    0x18	/* Extended byte 9        */
458c2ecf20Sopenharmony_ci#define R_EB10   0x19	/* Extended byte 10       */
468c2ecf20Sopenharmony_ci#define R_EB11   0x1a	/* Extended byte 11       */
478c2ecf20Sopenharmony_ci#define R_EB12   0x1b	/* Extended byte 12       */
488c2ecf20Sopenharmony_ci#define R_EB13   0x1c	/* Extended byte 13       */
498c2ecf20Sopenharmony_ci#define R_EB14   0x1d	/* Extended byte 14       */
508c2ecf20Sopenharmony_ci#define R_EB15   0x1e	/* Extended byte 15       */
518c2ecf20Sopenharmony_ci#define R_EB16   0x1f	/* Extended byte 16       */
528c2ecf20Sopenharmony_ci#define R_EB17   0x20	/* Extended byte 17       */
538c2ecf20Sopenharmony_ci#define R_EB18   0x21	/* Extended byte 18       */
548c2ecf20Sopenharmony_ci#define R_EB19   0x22	/* Extended byte 19       */
558c2ecf20Sopenharmony_ci#define R_EB20   0x23	/* Extended byte 20       */
568c2ecf20Sopenharmony_ci#define R_EB21   0x24	/* Extended byte 21       */
578c2ecf20Sopenharmony_ci#define R_EB22   0x25	/* Extended byte 22       */
588c2ecf20Sopenharmony_ci#define R_EB23   0x26	/* Extended byte 23       */
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define TDA18271_NUM_REGS 39
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci/*---------------------------------------------------------------------*/
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistruct tda18271_rf_tracking_filter_cal {
658c2ecf20Sopenharmony_ci	u32 rfmax;
668c2ecf20Sopenharmony_ci	u8  rfband;
678c2ecf20Sopenharmony_ci	u32 rf1_def;
688c2ecf20Sopenharmony_ci	u32 rf2_def;
698c2ecf20Sopenharmony_ci	u32 rf3_def;
708c2ecf20Sopenharmony_ci	u32 rf1;
718c2ecf20Sopenharmony_ci	u32 rf2;
728c2ecf20Sopenharmony_ci	u32 rf3;
738c2ecf20Sopenharmony_ci	s32 rf_a1;
748c2ecf20Sopenharmony_ci	s32 rf_b1;
758c2ecf20Sopenharmony_ci	s32 rf_a2;
768c2ecf20Sopenharmony_ci	s32 rf_b2;
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cienum tda18271_pll {
808c2ecf20Sopenharmony_ci	TDA18271_MAIN_PLL,
818c2ecf20Sopenharmony_ci	TDA18271_CAL_PLL,
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cistruct tda18271_map_layout;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cienum tda18271_ver {
878c2ecf20Sopenharmony_ci	TDA18271HDC1,
888c2ecf20Sopenharmony_ci	TDA18271HDC2,
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cistruct tda18271_priv {
928c2ecf20Sopenharmony_ci	unsigned char tda18271_regs[TDA18271_NUM_REGS];
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	struct list_head	hybrid_tuner_instance_list;
958c2ecf20Sopenharmony_ci	struct tuner_i2c_props	i2c_props;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	enum tda18271_mode mode;
988c2ecf20Sopenharmony_ci	enum tda18271_role role;
998c2ecf20Sopenharmony_ci	enum tda18271_i2c_gate gate;
1008c2ecf20Sopenharmony_ci	enum tda18271_ver id;
1018c2ecf20Sopenharmony_ci	enum tda18271_output_options output_opt;
1028c2ecf20Sopenharmony_ci	enum tda18271_small_i2c small_i2c;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	unsigned int config; /* interface to saa713x / tda829x */
1058c2ecf20Sopenharmony_ci	unsigned int cal_initialized:1;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	u8 tm_rfcal;
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	struct tda18271_map_layout *maps;
1108c2ecf20Sopenharmony_ci	struct tda18271_std_map std;
1118c2ecf20Sopenharmony_ci	struct tda18271_rf_tracking_filter_cal rf_cal_state[8];
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	struct mutex lock;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	u16 if_freq;
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	u32 frequency;
1188c2ecf20Sopenharmony_ci	u32 bandwidth;
1198c2ecf20Sopenharmony_ci};
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/*---------------------------------------------------------------------*/
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ciextern int tda18271_debug;
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#define DBG_INFO 1
1268c2ecf20Sopenharmony_ci#define DBG_MAP  2
1278c2ecf20Sopenharmony_ci#define DBG_REG  4
1288c2ecf20Sopenharmony_ci#define DBG_ADV  8
1298c2ecf20Sopenharmony_ci#define DBG_CAL  16
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci__attribute__((format(printf, 4, 5)))
1328c2ecf20Sopenharmony_civoid _tda_printk(struct tda18271_priv *state, const char *level,
1338c2ecf20Sopenharmony_ci		 const char *func, const char *fmt, ...);
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#define tda_printk(st, lvl, fmt, arg...)			\
1368c2ecf20Sopenharmony_ci	_tda_printk(st, lvl, __func__, fmt, ##arg)
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#define tda_dprintk(st, lvl, fmt, arg...)			\
1398c2ecf20Sopenharmony_cido {								\
1408c2ecf20Sopenharmony_ci	if (tda18271_debug & lvl)				\
1418c2ecf20Sopenharmony_ci		tda_printk(st, KERN_DEBUG, fmt, ##arg);		\
1428c2ecf20Sopenharmony_ci} while (0)
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#define tda_info(fmt, arg...)	pr_info(fmt, ##arg)
1458c2ecf20Sopenharmony_ci#define tda_warn(fmt, arg...)	tda_printk(priv, KERN_WARNING, fmt, ##arg)
1468c2ecf20Sopenharmony_ci#define tda_err(fmt, arg...)	tda_printk(priv, KERN_ERR,     fmt, ##arg)
1478c2ecf20Sopenharmony_ci#define tda_dbg(fmt, arg...)	tda_dprintk(priv, DBG_INFO,    fmt, ##arg)
1488c2ecf20Sopenharmony_ci#define tda_map(fmt, arg...)	tda_dprintk(priv, DBG_MAP,     fmt, ##arg)
1498c2ecf20Sopenharmony_ci#define tda_reg(fmt, arg...)	tda_dprintk(priv, DBG_REG,     fmt, ##arg)
1508c2ecf20Sopenharmony_ci#define tda_cal(fmt, arg...)	tda_dprintk(priv, DBG_CAL,     fmt, ##arg)
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#define tda_fail(ret)							     \
1538c2ecf20Sopenharmony_ci({									     \
1548c2ecf20Sopenharmony_ci	int __ret;							     \
1558c2ecf20Sopenharmony_ci	__ret = (ret < 0);						     \
1568c2ecf20Sopenharmony_ci	if (__ret)							     \
1578c2ecf20Sopenharmony_ci		tda_printk(priv, KERN_ERR,				     \
1588c2ecf20Sopenharmony_ci			   "error %d on line %d\n", ret, __LINE__);	     \
1598c2ecf20Sopenharmony_ci	__ret;								     \
1608c2ecf20Sopenharmony_ci})
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci/*---------------------------------------------------------------------*/
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cienum tda18271_map_type {
1658c2ecf20Sopenharmony_ci	/* tda18271_pll_map */
1668c2ecf20Sopenharmony_ci	MAIN_PLL,
1678c2ecf20Sopenharmony_ci	CAL_PLL,
1688c2ecf20Sopenharmony_ci	/* tda18271_map */
1698c2ecf20Sopenharmony_ci	RF_CAL,
1708c2ecf20Sopenharmony_ci	RF_CAL_KMCO,
1718c2ecf20Sopenharmony_ci	RF_CAL_DC_OVER_DT,
1728c2ecf20Sopenharmony_ci	BP_FILTER,
1738c2ecf20Sopenharmony_ci	RF_BAND,
1748c2ecf20Sopenharmony_ci	GAIN_TAPER,
1758c2ecf20Sopenharmony_ci	IR_MEASURE,
1768c2ecf20Sopenharmony_ci};
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ciextern int tda18271_lookup_pll_map(struct dvb_frontend *fe,
1798c2ecf20Sopenharmony_ci				   enum tda18271_map_type map_type,
1808c2ecf20Sopenharmony_ci				   u32 *freq, u8 *post_div, u8 *div);
1818c2ecf20Sopenharmony_ciextern int tda18271_lookup_map(struct dvb_frontend *fe,
1828c2ecf20Sopenharmony_ci			       enum tda18271_map_type map_type,
1838c2ecf20Sopenharmony_ci			       u32 *freq, u8 *val);
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ciextern int tda18271_lookup_thermometer(struct dvb_frontend *fe);
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ciextern int tda18271_lookup_rf_band(struct dvb_frontend *fe,
1888c2ecf20Sopenharmony_ci				   u32 *freq, u8 *rf_band);
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ciextern int tda18271_lookup_cid_target(struct dvb_frontend *fe,
1918c2ecf20Sopenharmony_ci				      u32 *freq, u8 *cid_target,
1928c2ecf20Sopenharmony_ci				      u16 *count_limit);
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ciextern int tda18271_assign_map_layout(struct dvb_frontend *fe);
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci/*---------------------------------------------------------------------*/
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ciextern int tda18271_read_regs(struct dvb_frontend *fe);
1998c2ecf20Sopenharmony_ciextern int tda18271_read_extended(struct dvb_frontend *fe);
2008c2ecf20Sopenharmony_ciextern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len);
2018c2ecf20Sopenharmony_ciextern int tda18271_init_regs(struct dvb_frontend *fe);
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ciextern int tda18271_charge_pump_source(struct dvb_frontend *fe,
2048c2ecf20Sopenharmony_ci				       enum tda18271_pll pll, int force);
2058c2ecf20Sopenharmony_ciextern int tda18271_set_standby_mode(struct dvb_frontend *fe,
2068c2ecf20Sopenharmony_ci				     int sm, int sm_lt, int sm_xt);
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ciextern int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq);
2098c2ecf20Sopenharmony_ciextern int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ciextern int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq);
2128c2ecf20Sopenharmony_ciextern int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq);
2138c2ecf20Sopenharmony_ciextern int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq);
2148c2ecf20Sopenharmony_ciextern int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq);
2158c2ecf20Sopenharmony_ciextern int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq);
2168c2ecf20Sopenharmony_ciextern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq);
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci#endif /* __TDA18271_PRIV_H__ */
219