1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Driver for Philips tda8262/tda8263 DVBS Silicon tuners
5 (c) 2006 Andrew de Quincey
10 #include <linux/slab.h>
11 #include <linux/module.h>
12 #include <linux/dvb/frontend.h>
13 #include <asm/types.h>
18 #define dprintk(args...) \
20 if (debug) printk(KERN_DEBUG "tda826x: " args); \
26 struct i2c_adapter
*i2c
;
31 static void tda826x_release(struct dvb_frontend
*fe
)
33 kfree(fe
->tuner_priv
);
34 fe
->tuner_priv
= NULL
;
37 static int tda826x_sleep(struct dvb_frontend
*fe
)
39 struct tda826x_priv
*priv
= fe
->tuner_priv
;
41 u8 buf
[] = { 0x00, 0x8d };
42 struct i2c_msg msg
= { .addr
= priv
->i2c_address
, .flags
= 0, .buf
= buf
, .len
= 2 };
44 dprintk("%s:\n", __func__
);
46 if (!priv
->has_loopthrough
)
49 if (fe
->ops
.i2c_gate_ctrl
)
50 fe
->ops
.i2c_gate_ctrl(fe
, 1);
51 if ((ret
= i2c_transfer (priv
->i2c
, &msg
, 1)) != 1) {
52 dprintk("%s: i2c error\n", __func__
);
54 if (fe
->ops
.i2c_gate_ctrl
)
55 fe
->ops
.i2c_gate_ctrl(fe
, 0);
57 return (ret
== 1) ? 0 : ret
;
60 static int tda826x_set_params(struct dvb_frontend
*fe
)
62 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
63 struct tda826x_priv
*priv
= fe
->tuner_priv
;
69 struct i2c_msg msg
= { .addr
= priv
->i2c_address
, .flags
= 0, .buf
= buf
, .len
= 11 };
71 dprintk("%s:\n", __func__
);
73 div
= (p
->frequency
+ (1000-1)) / 1000;
75 /* BW = ((1 + RO) * SR/2 + 5) * 1.3 [SR in MSPS, BW in MHz] */
76 /* with R0 = 0.35 and some transformations: */
77 ksyms
= p
->symbol_rate
/ 1000;
78 bandwidth
= (878 * ksyms
+ 6500000) / 1000000 + 1;
81 else if (bandwidth
> 36)
84 buf
[0] = 0x00; // subaddress
85 buf
[1] = 0x09; // powerdown RSSI + the magic value 1
86 if (!priv
->has_loopthrough
)
87 buf
[1] |= 0x20; // power down loopthrough if not needed
88 buf
[2] = (1<<5) | 0x0b; // 1Mhz + 0.45 VCO
91 buf
[5] = ((bandwidth
- 5) << 3) | 7; /* baseband cut-off */
92 buf
[6] = 0xfe; // baseband gain 9 db + no RF attenuation
93 buf
[7] = 0x83; // charge pumps at high, tests off
94 buf
[8] = 0x80; // recommended value 4 for AMPVCO + disable ports.
95 buf
[9] = 0x1a; // normal caltime + recommended values for SELTH + SELVTL
96 buf
[10] = 0xd4; // recommended value 13 for BBIAS + unknown bit set on
98 if (fe
->ops
.i2c_gate_ctrl
)
99 fe
->ops
.i2c_gate_ctrl(fe
, 1);
100 if ((ret
= i2c_transfer (priv
->i2c
, &msg
, 1)) != 1) {
101 dprintk("%s: i2c error\n", __func__
);
103 if (fe
->ops
.i2c_gate_ctrl
)
104 fe
->ops
.i2c_gate_ctrl(fe
, 0);
106 priv
->frequency
= div
* 1000;
108 return (ret
== 1) ? 0 : ret
;
111 static int tda826x_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
113 struct tda826x_priv
*priv
= fe
->tuner_priv
;
114 *frequency
= priv
->frequency
;
118 static const struct dvb_tuner_ops tda826x_tuner_ops
= {
120 .name
= "Philips TDA826X",
121 .frequency_min_hz
= 950 * MHz
,
122 .frequency_max_hz
= 2175 * MHz
124 .release
= tda826x_release
,
125 .sleep
= tda826x_sleep
,
126 .set_params
= tda826x_set_params
,
127 .get_frequency
= tda826x_get_frequency
,
130 struct dvb_frontend
*tda826x_attach(struct dvb_frontend
*fe
, int addr
, struct i2c_adapter
*i2c
, int has_loopthrough
)
132 struct tda826x_priv
*priv
= NULL
;
134 struct i2c_msg msg
[2] = {
135 { .addr
= addr
, .flags
= 0, .buf
= NULL
, .len
= 0 },
136 { .addr
= addr
, .flags
= I2C_M_RD
, .buf
= b1
, .len
= 2 }
140 dprintk("%s:\n", __func__
);
142 if (fe
->ops
.i2c_gate_ctrl
)
143 fe
->ops
.i2c_gate_ctrl(fe
, 1);
144 ret
= i2c_transfer (i2c
, msg
, 2);
145 if (fe
->ops
.i2c_gate_ctrl
)
146 fe
->ops
.i2c_gate_ctrl(fe
, 0);
153 priv
= kzalloc(sizeof(struct tda826x_priv
), GFP_KERNEL
);
157 priv
->i2c_address
= addr
;
159 priv
->has_loopthrough
= has_loopthrough
;
161 memcpy(&fe
->ops
.tuner_ops
, &tda826x_tuner_ops
, sizeof(struct dvb_tuner_ops
));
163 fe
->tuner_priv
= priv
;
167 EXPORT_SYMBOL(tda826x_attach
);
169 module_param(debug
, int, 0644);
170 MODULE_PARM_DESC(debug
, "Turn on/off frontend debugging (default:off).");
172 MODULE_DESCRIPTION("DVB TDA826x driver");
173 MODULE_AUTHOR("Andrew de Quincey");
174 MODULE_LICENSE("GPL");