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/slab.h>
24 #include <linux/module.h>
25 #include <linux/dvb/frontend.h>
26 #include <asm/types.h>
31 #define dprintk(args...) \
34 printk(KERN_DEBUG "stb6000: " args); \
40 struct i2c_adapter
*i2c
;
44 static int stb6000_release(struct dvb_frontend
*fe
)
46 kfree(fe
->tuner_priv
);
47 fe
->tuner_priv
= NULL
;
51 static int stb6000_sleep(struct dvb_frontend
*fe
)
53 struct stb6000_priv
*priv
= fe
->tuner_priv
;
56 struct i2c_msg msg
= {
57 .addr
= priv
->i2c_address
,
63 dprintk("%s:\n", __func__
);
65 if (fe
->ops
.i2c_gate_ctrl
)
66 fe
->ops
.i2c_gate_ctrl(fe
, 1);
68 ret
= i2c_transfer(priv
->i2c
, &msg
, 1);
70 dprintk("%s: i2c error\n", __func__
);
72 if (fe
->ops
.i2c_gate_ctrl
)
73 fe
->ops
.i2c_gate_ctrl(fe
, 0);
75 return (ret
== 1) ? 0 : ret
;
78 static int stb6000_set_params(struct dvb_frontend
*fe
,
79 struct dvb_frontend_parameters
*params
)
81 struct stb6000_priv
*priv
= fe
->tuner_priv
;
87 struct i2c_msg msg
= {
88 .addr
= priv
->i2c_address
,
94 dprintk("%s:\n", __func__
);
96 freq_mhz
= params
->frequency
/ 1000;
97 bandwidth
= params
->u
.qpsk
.symbol_rate
/ 1000000;
102 if ((freq_mhz
> 949) && (freq_mhz
< 2151)) {
125 if (freq_mhz
< 1075) {
126 n
= freq_mhz
/ 8; /* vco=lo*4 */
129 n
= freq_mhz
/ 16; /* vco=lo*2 */
133 buf
[3] = (unsigned char)(((n
& 1) << 7) |
134 (m
* freq_mhz
- n
* 16) | 0x60);
138 buf
[6] = (unsigned char)(bandwidth
);
146 if (fe
->ops
.i2c_gate_ctrl
)
147 fe
->ops
.i2c_gate_ctrl(fe
, 1);
149 ret
= i2c_transfer(priv
->i2c
, &msg
, 1);
151 dprintk("%s: i2c error\n", __func__
);
154 if (fe
->ops
.i2c_gate_ctrl
)
155 fe
->ops
.i2c_gate_ctrl(fe
, 0);
164 if (fe
->ops
.i2c_gate_ctrl
)
165 fe
->ops
.i2c_gate_ctrl(fe
, 1);
167 ret
= i2c_transfer(priv
->i2c
, &msg
, 1);
169 dprintk("%s: i2c error\n", __func__
);
172 if (fe
->ops
.i2c_gate_ctrl
)
173 fe
->ops
.i2c_gate_ctrl(fe
, 0);
175 priv
->frequency
= freq_mhz
* 1000;
177 return (ret
== 1) ? 0 : ret
;
182 static int stb6000_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
184 struct stb6000_priv
*priv
= fe
->tuner_priv
;
185 *frequency
= priv
->frequency
;
189 static struct dvb_tuner_ops stb6000_tuner_ops
= {
191 .name
= "ST STB6000",
192 .frequency_min
= 950000,
193 .frequency_max
= 2150000
195 .release
= stb6000_release
,
196 .sleep
= stb6000_sleep
,
197 .set_params
= stb6000_set_params
,
198 .get_frequency
= stb6000_get_frequency
,
201 struct dvb_frontend
*stb6000_attach(struct dvb_frontend
*fe
, int addr
,
202 struct i2c_adapter
*i2c
)
204 struct stb6000_priv
*priv
= NULL
;
207 struct i2c_msg msg
[2] = {
222 dprintk("%s:\n", __func__
);
224 if (fe
->ops
.i2c_gate_ctrl
)
225 fe
->ops
.i2c_gate_ctrl(fe
, 1);
227 /* is some i2c device here ? */
228 ret
= i2c_transfer(i2c
, msg
, 2);
229 if (fe
->ops
.i2c_gate_ctrl
)
230 fe
->ops
.i2c_gate_ctrl(fe
, 0);
235 priv
= kzalloc(sizeof(struct stb6000_priv
), GFP_KERNEL
);
239 priv
->i2c_address
= addr
;
242 memcpy(&fe
->ops
.tuner_ops
, &stb6000_tuner_ops
,
243 sizeof(struct dvb_tuner_ops
));
245 fe
->tuner_priv
= priv
;
249 EXPORT_SYMBOL(stb6000_attach
);
251 module_param(debug
, int, 0644);
252 MODULE_PARM_DESC(debug
, "Turn on/off frontend debugging (default:off).");
254 MODULE_DESCRIPTION("DVB STB6000 driver");
255 MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
256 MODULE_LICENSE("GPL");