1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun Driver for Philips tda1004xh OFDM Frontend
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun (c) 2004 Andrew de Quincey
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #ifndef TDA1004X_H
11*4882a593Smuzhiyun #define TDA1004X_H
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/dvb/frontend.h>
14*4882a593Smuzhiyun #include <linux/firmware.h>
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun enum tda10046_xtal {
17*4882a593Smuzhiyun TDA10046_XTAL_4M,
18*4882a593Smuzhiyun TDA10046_XTAL_16M,
19*4882a593Smuzhiyun };
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun enum tda10046_agc {
22*4882a593Smuzhiyun TDA10046_AGC_DEFAULT, /* original configuration */
23*4882a593Smuzhiyun TDA10046_AGC_IFO_AUTO_NEG, /* IF AGC only, automatic, negative */
24*4882a593Smuzhiyun TDA10046_AGC_IFO_AUTO_POS, /* IF AGC only, automatic, positive */
25*4882a593Smuzhiyun TDA10046_AGC_TDA827X, /* IF AGC only, special setup for tda827x */
26*4882a593Smuzhiyun };
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /* Many (hybrid) boards use GPIO 1 and 3
29*4882a593Smuzhiyun GPIO1 analog - dvb switch
30*4882a593Smuzhiyun GPIO3 firmware eeprom address switch
31*4882a593Smuzhiyun */
32*4882a593Smuzhiyun enum tda10046_gpio {
33*4882a593Smuzhiyun TDA10046_GPTRI = 0x00, /* All GPIOs tristate */
34*4882a593Smuzhiyun TDA10046_GP00 = 0x40, /* GPIO3=0, GPIO1=0 */
35*4882a593Smuzhiyun TDA10046_GP01 = 0x42, /* GPIO3=0, GPIO1=1 */
36*4882a593Smuzhiyun TDA10046_GP10 = 0x48, /* GPIO3=1, GPIO1=0 */
37*4882a593Smuzhiyun TDA10046_GP11 = 0x4a, /* GPIO3=1, GPIO1=1 */
38*4882a593Smuzhiyun TDA10046_GP00_I = 0x80, /* GPIO3=0, GPIO1=0, invert in sleep mode*/
39*4882a593Smuzhiyun TDA10046_GP01_I = 0x82, /* GPIO3=0, GPIO1=1, invert in sleep mode */
40*4882a593Smuzhiyun TDA10046_GP10_I = 0x88, /* GPIO3=1, GPIO1=0, invert in sleep mode */
41*4882a593Smuzhiyun TDA10046_GP11_I = 0x8a, /* GPIO3=1, GPIO1=1, invert in sleep mode */
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun enum tda10046_if {
45*4882a593Smuzhiyun TDA10046_FREQ_3617, /* original config, 36,166 MHZ */
46*4882a593Smuzhiyun TDA10046_FREQ_3613, /* 36,13 MHZ */
47*4882a593Smuzhiyun TDA10046_FREQ_045, /* low IF, 4.0, 4.5, or 5.0 MHZ */
48*4882a593Smuzhiyun TDA10046_FREQ_052, /* low IF, 5.1667 MHZ for tda9889 */
49*4882a593Smuzhiyun };
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun enum tda10046_tsout {
52*4882a593Smuzhiyun TDA10046_TS_PARALLEL = 0x00, /* parallel transport stream, default */
53*4882a593Smuzhiyun TDA10046_TS_SERIAL = 0x01, /* serial transport stream */
54*4882a593Smuzhiyun };
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun struct tda1004x_config
57*4882a593Smuzhiyun {
58*4882a593Smuzhiyun /* the demodulator's i2c address */
59*4882a593Smuzhiyun u8 demod_address;
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun /* does the "inversion" need inverted? */
62*4882a593Smuzhiyun u8 invert;
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun /* Does the OCLK signal need inverted? */
65*4882a593Smuzhiyun u8 invert_oclk;
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun /* parallel or serial transport stream */
68*4882a593Smuzhiyun enum tda10046_tsout ts_mode;
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun /* Xtal frequency, 4 or 16MHz*/
71*4882a593Smuzhiyun enum tda10046_xtal xtal_freq;
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun /* IF frequency */
74*4882a593Smuzhiyun enum tda10046_if if_freq;
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun /* AGC configuration */
77*4882a593Smuzhiyun enum tda10046_agc agc_config;
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun /* setting of GPIO1 and 3 */
80*4882a593Smuzhiyun enum tda10046_gpio gpio_config;
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun /* slave address and configuration of the tuner */
83*4882a593Smuzhiyun u8 tuner_address;
84*4882a593Smuzhiyun u8 antenna_switch;
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun /* if the board uses another I2c Bridge (tda8290), its address */
87*4882a593Smuzhiyun u8 i2c_gate;
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun /* request firmware for device */
90*4882a593Smuzhiyun int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name);
91*4882a593Smuzhiyun };
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun enum tda1004x_demod {
94*4882a593Smuzhiyun TDA1004X_DEMOD_TDA10045,
95*4882a593Smuzhiyun TDA1004X_DEMOD_TDA10046,
96*4882a593Smuzhiyun };
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun struct tda1004x_state {
99*4882a593Smuzhiyun struct i2c_adapter* i2c;
100*4882a593Smuzhiyun const struct tda1004x_config* config;
101*4882a593Smuzhiyun struct dvb_frontend frontend;
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /* private demod data */
104*4882a593Smuzhiyun enum tda1004x_demod demod_type;
105*4882a593Smuzhiyun };
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun #if IS_REACHABLE(CONFIG_DVB_TDA1004X)
108*4882a593Smuzhiyun extern struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
109*4882a593Smuzhiyun struct i2c_adapter* i2c);
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun extern struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
112*4882a593Smuzhiyun struct i2c_adapter* i2c);
113*4882a593Smuzhiyun #else
tda10045_attach(const struct tda1004x_config * config,struct i2c_adapter * i2c)114*4882a593Smuzhiyun static inline struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
115*4882a593Smuzhiyun struct i2c_adapter* i2c)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
118*4882a593Smuzhiyun return NULL;
119*4882a593Smuzhiyun }
tda10046_attach(const struct tda1004x_config * config,struct i2c_adapter * i2c)120*4882a593Smuzhiyun static inline struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
121*4882a593Smuzhiyun struct i2c_adapter* i2c)
122*4882a593Smuzhiyun {
123*4882a593Smuzhiyun printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
124*4882a593Smuzhiyun return NULL;
125*4882a593Smuzhiyun }
126*4882a593Smuzhiyun #endif // CONFIG_DVB_TDA1004X
127*4882a593Smuzhiyun
tda1004x_writereg(struct dvb_frontend * fe,u8 reg,u8 val)128*4882a593Smuzhiyun static inline int tda1004x_writereg(struct dvb_frontend *fe, u8 reg, u8 val) {
129*4882a593Smuzhiyun int r = 0;
130*4882a593Smuzhiyun u8 buf[] = {reg, val};
131*4882a593Smuzhiyun if (fe->ops.write)
132*4882a593Smuzhiyun r = fe->ops.write(fe, buf, 2);
133*4882a593Smuzhiyun return r;
134*4882a593Smuzhiyun }
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun #endif // TDA1004X_H
137