2 Driver for ST STB6000 DVBS Silicon tuner
4 Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/module.h>
24 #include <linux/dvb/frontend.h>
25 #include <asm/types.h>
30 #define dprintk(args...) \
33 printk(KERN_DEBUG "stb6000: " args); \
39 struct i2c_adapter
*i2c
;
43 static int stb6000_release(struct dvb_frontend
*fe
)
45 kfree(fe
->tuner_priv
);
46 fe
->tuner_priv
= NULL
;
50 static int stb6000_sleep(struct dvb_frontend
*fe
)
52 struct stb6000_priv
*priv
= fe
->tuner_priv
;
55 struct i2c_msg msg
= {
56 .addr
= priv
->i2c_address
,
62 dprintk("%s:\n", __func__
);
64 if (fe
->ops
.i2c_gate_ctrl
)
65 fe
->ops
.i2c_gate_ctrl(fe
, 1);
67 ret
= i2c_transfer(priv
->i2c
, &msg
, 1);
69 dprintk("%s: i2c error\n", __func__
);
71 if (fe
->ops
.i2c_gate_ctrl
)
72 fe
->ops
.i2c_gate_ctrl(fe
, 0);
74 return (ret
== 1) ? 0 : ret
;
77 static int stb6000_set_params(struct dvb_frontend
*fe
,
78 struct dvb_frontend_parameters
*params
)
80 struct stb6000_priv
*priv
= fe
->tuner_priv
;
86 struct i2c_msg msg
= {
87 .addr
= priv
->i2c_address
,
93 dprintk("%s:\n", __func__
);
95 freq_mhz
= params
->frequency
/ 1000;
96 bandwidth
= params
->u
.qpsk
.symbol_rate
/ 1000000;
101 if ((freq_mhz
> 949) && (freq_mhz
< 2151)) {
124 if (freq_mhz
< 1075) {
125 n
= freq_mhz
/ 8; /* vco=lo*4 */
128 n
= freq_mhz
/ 16; /* vco=lo*2 */
132 buf
[3] = (unsigned char)(((n
& 1) << 7) |
133 (m
* freq_mhz
- n
* 16) | 0x60);
137 buf
[6] = (unsigned char)(bandwidth
);
145 if (fe
->ops
.i2c_gate_ctrl
)
146 fe
->ops
.i2c_gate_ctrl(fe
, 1);
148 ret
= i2c_transfer(priv
->i2c
, &msg
, 1);
150 dprintk("%s: i2c error\n", __func__
);
153 if (fe
->ops
.i2c_gate_ctrl
)
154 fe
->ops
.i2c_gate_ctrl(fe
, 0);
163 if (fe
->ops
.i2c_gate_ctrl
)
164 fe
->ops
.i2c_gate_ctrl(fe
, 1);
166 ret
= i2c_transfer(priv
->i2c
, &msg
, 1);
168 dprintk("%s: i2c error\n", __func__
);
171 if (fe
->ops
.i2c_gate_ctrl
)
172 fe
->ops
.i2c_gate_ctrl(fe
, 0);
174 priv
->frequency
= freq_mhz
* 1000;
176 return (ret
== 1) ? 0 : ret
;
181 static int stb6000_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
183 struct stb6000_priv
*priv
= fe
->tuner_priv
;
184 *frequency
= priv
->frequency
;
188 static struct dvb_tuner_ops stb6000_tuner_ops
= {
190 .name
= "ST STB6000",
191 .frequency_min
= 950000,
192 .frequency_max
= 2150000
194 .release
= stb6000_release
,
195 .sleep
= stb6000_sleep
,
196 .set_params
= stb6000_set_params
,
197 .get_frequency
= stb6000_get_frequency
,
200 struct dvb_frontend
*stb6000_attach(struct dvb_frontend
*fe
, int addr
,
201 struct i2c_adapter
*i2c
)
203 struct stb6000_priv
*priv
= NULL
;
206 struct i2c_msg msg
[2] = {
221 dprintk("%s:\n", __func__
);
223 if (fe
->ops
.i2c_gate_ctrl
)
224 fe
->ops
.i2c_gate_ctrl(fe
, 1);
226 /* is some i2c device here ? */
227 ret
= i2c_transfer(i2c
, msg
, 2);
228 if (fe
->ops
.i2c_gate_ctrl
)
229 fe
->ops
.i2c_gate_ctrl(fe
, 0);
234 priv
= kzalloc(sizeof(struct stb6000_priv
), GFP_KERNEL
);
238 priv
->i2c_address
= addr
;
241 memcpy(&fe
->ops
.tuner_ops
, &stb6000_tuner_ops
,
242 sizeof(struct dvb_tuner_ops
));
244 fe
->tuner_priv
= priv
;
248 EXPORT_SYMBOL(stb6000_attach
);
250 module_param(debug
, int, 0644);
251 MODULE_PARM_DESC(debug
, "Turn on/off frontend debugging (default:off).");
253 MODULE_DESCRIPTION("DVB STB6000 driver");
254 MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
255 MODULE_LICENSE("GPL");