18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci	STV6110(A) Silicon tuner driver
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci	Copyright (C) Manu Abraham <abraham.manu@gmail.com>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci	Copyright (C) ST Microelectronics
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci*/
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef __STV6110x_PRIV_H
128c2ecf20Sopenharmony_ci#define __STV6110x_PRIV_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define FE_ERROR				0
158c2ecf20Sopenharmony_ci#define FE_NOTICE				1
168c2ecf20Sopenharmony_ci#define FE_INFO					2
178c2ecf20Sopenharmony_ci#define FE_DEBUG				3
188c2ecf20Sopenharmony_ci#define FE_DEBUGREG				4
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define dprintk(__y, __z, format, arg...) do {						\
218c2ecf20Sopenharmony_ci	if (__z) {									\
228c2ecf20Sopenharmony_ci		if	((verbose > FE_ERROR) && (verbose > __y))			\
238c2ecf20Sopenharmony_ci			printk(KERN_ERR "%s: " format "\n", __func__ , ##arg);		\
248c2ecf20Sopenharmony_ci		else if	((verbose > FE_NOTICE) && (verbose > __y))			\
258c2ecf20Sopenharmony_ci			printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg);	\
268c2ecf20Sopenharmony_ci		else if ((verbose > FE_INFO) && (verbose > __y))			\
278c2ecf20Sopenharmony_ci			printk(KERN_INFO "%s: " format "\n", __func__ , ##arg);		\
288c2ecf20Sopenharmony_ci		else if ((verbose > FE_DEBUG) && (verbose > __y))			\
298c2ecf20Sopenharmony_ci			printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg);	\
308c2ecf20Sopenharmony_ci	} else {									\
318c2ecf20Sopenharmony_ci		if (verbose > __y)							\
328c2ecf20Sopenharmony_ci			printk(format, ##arg);						\
338c2ecf20Sopenharmony_ci	}										\
348c2ecf20Sopenharmony_ci} while (0)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define STV6110x_SETFIELD(mask, bitf, val)				\
388c2ecf20Sopenharmony_ci	(mask = (mask & (~(((1 << STV6110x_WIDTH_##bitf) - 1) <<	\
398c2ecf20Sopenharmony_ci				  STV6110x_OFFST_##bitf))) |		\
408c2ecf20Sopenharmony_ci			  (val << STV6110x_OFFST_##bitf))
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define STV6110x_GETFIELD(bitf, val)					\
438c2ecf20Sopenharmony_ci	((val >> STV6110x_OFFST_##bitf) &				\
448c2ecf20Sopenharmony_ci	((1 << STV6110x_WIDTH_##bitf) - 1))
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define MAKEWORD16(a, b)			(((a) << 8) | (b))
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define LSB(x)					((x & 0xff))
498c2ecf20Sopenharmony_ci#define MSB(y)					((y >> 8) & 0xff)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define TRIALS					10
528c2ecf20Sopenharmony_ci#define R_DIV(__div)				(1 << (__div + 1))
538c2ecf20Sopenharmony_ci#define REFCLOCK_kHz				(stv6110x->config->refclk /    1000)
548c2ecf20Sopenharmony_ci#define REFCLOCK_MHz				(stv6110x->config->refclk / 1000000)
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistruct stv6110x_state {
578c2ecf20Sopenharmony_ci	struct dvb_frontend		*frontend;
588c2ecf20Sopenharmony_ci	struct i2c_adapter		*i2c;
598c2ecf20Sopenharmony_ci	const struct stv6110x_config	*config;
608c2ecf20Sopenharmony_ci	u8				regs[8];
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	struct stv6110x_devctl	*devctl;
638c2ecf20Sopenharmony_ci};
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#endif /* __STV6110x_PRIV_H */
66