1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Driver for ST STB6000 DVBS Silicon tuner
5 Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
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...) \
21 printk(KERN_DEBUG "stb6000: " args); \
27 struct i2c_adapter *i2c;
31 static void stb6000_release(struct dvb_frontend *fe)
33 kfree(fe->tuner_priv);
34 fe->tuner_priv = NULL;
37 static int stb6000_sleep(struct dvb_frontend *fe)
39 struct stb6000_priv *priv = fe->tuner_priv;
42 struct i2c_msg msg = {
43 .addr = priv->i2c_address,
49 dprintk("%s:\n", __func__);
51 if (fe->ops.i2c_gate_ctrl)
52 fe->ops.i2c_gate_ctrl(fe, 1);
54 ret = i2c_transfer(priv->i2c, &msg, 1);
56 dprintk("%s: i2c error\n", __func__);
58 if (fe->ops.i2c_gate_ctrl)
59 fe->ops.i2c_gate_ctrl(fe, 0);
61 return (ret == 1) ? 0 : ret;
64 static int stb6000_set_params(struct dvb_frontend *fe)
66 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
67 struct stb6000_priv *priv = fe->tuner_priv;
73 struct i2c_msg msg = {
74 .addr = priv->i2c_address,
80 dprintk("%s:\n", __func__);
82 freq_mhz = p->frequency / 1000;
83 bandwidth = p->symbol_rate / 1000000;
88 if ((freq_mhz > 949) && (freq_mhz < 2151)) {
111 if (freq_mhz < 1075) {
112 n = freq_mhz / 8; /* vco=lo*4 */
115 n = freq_mhz / 16; /* vco=lo*2 */
119 buf[3] = (unsigned char)(((n & 1) << 7) |
120 (m * freq_mhz - n * 16) | 0x60);
124 buf[6] = (unsigned char)(bandwidth);
132 if (fe->ops.i2c_gate_ctrl)
133 fe->ops.i2c_gate_ctrl(fe, 1);
135 ret = i2c_transfer(priv->i2c, &msg, 1);
137 dprintk("%s: i2c error\n", __func__);
140 if (fe->ops.i2c_gate_ctrl)
141 fe->ops.i2c_gate_ctrl(fe, 0);
150 if (fe->ops.i2c_gate_ctrl)
151 fe->ops.i2c_gate_ctrl(fe, 1);
153 ret = i2c_transfer(priv->i2c, &msg, 1);
155 dprintk("%s: i2c error\n", __func__);
158 if (fe->ops.i2c_gate_ctrl)
159 fe->ops.i2c_gate_ctrl(fe, 0);
161 priv->frequency = freq_mhz * 1000;
163 return (ret == 1) ? 0 : ret;
168 static int stb6000_get_frequency(struct dvb_frontend *fe, u32 *frequency)
170 struct stb6000_priv *priv = fe->tuner_priv;
171 *frequency = priv->frequency;
175 static const struct dvb_tuner_ops stb6000_tuner_ops = {
177 .name = "ST STB6000",
178 .frequency_min_hz = 950 * MHz,
179 .frequency_max_hz = 2150 * MHz
181 .release = stb6000_release,
182 .sleep = stb6000_sleep,
183 .set_params = stb6000_set_params,
184 .get_frequency = stb6000_get_frequency,
187 struct dvb_frontend *stb6000_attach(struct dvb_frontend *fe, int addr,
188 struct i2c_adapter *i2c)
190 struct stb6000_priv *priv = NULL;
193 struct i2c_msg msg[2] = {
208 dprintk("%s:\n", __func__);
210 if (fe->ops.i2c_gate_ctrl)
211 fe->ops.i2c_gate_ctrl(fe, 1);
213 /* is some i2c device here ? */
214 ret = i2c_transfer(i2c, msg, 2);
215 if (fe->ops.i2c_gate_ctrl)
216 fe->ops.i2c_gate_ctrl(fe, 0);
221 priv = kzalloc(sizeof(struct stb6000_priv), GFP_KERNEL);
225 priv->i2c_address = addr;
228 memcpy(&fe->ops.tuner_ops, &stb6000_tuner_ops,
229 sizeof(struct dvb_tuner_ops));
231 fe->tuner_priv = priv;
235 EXPORT_SYMBOL_GPL(stb6000_attach);
237 module_param(debug, int, 0644);
238 MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
240 MODULE_DESCRIPTION("DVB STB6000 driver");
241 MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
242 MODULE_LICENSE("GPL");