2 * Driver for Infineon tua6100 pll.
4 * (c) 2006 Andrew de Quincey
6 * Based on code found in budget-av.c, which has the following:
7 * Compiled from various sources by Michael Hunold <michael@mihu.de>
9 * CI interface support (c) 2004 Olivier Gournet <ogournet@anevia.com> &
10 * Andrew de Quincey <adq_dvb@lidskialf.net>
12 * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
14 * Copyright (C) 1999-2002 Ralph Metzler
15 * & Marcus Metzler for convergence integrated media GmbH
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include <linux/slab.h>
32 #include <linux/module.h>
33 #include <linux/dvb/frontend.h>
34 #include <asm/types.h>
41 struct i2c_adapter
*i2c
;
45 static int tua6100_release(struct dvb_frontend
*fe
)
47 kfree(fe
->tuner_priv
);
48 fe
->tuner_priv
= NULL
;
52 static int tua6100_sleep(struct dvb_frontend
*fe
)
54 struct tua6100_priv
*priv
= fe
->tuner_priv
;
56 u8 reg0
[] = { 0x00, 0x00 };
57 struct i2c_msg msg
= { .addr
= priv
->i2c_address
, .flags
= 0, .buf
= reg0
, .len
= 2 };
59 if (fe
->ops
.i2c_gate_ctrl
)
60 fe
->ops
.i2c_gate_ctrl(fe
, 1);
61 if ((ret
= i2c_transfer (priv
->i2c
, &msg
, 1)) != 1) {
62 printk("%s: i2c error\n", __func__
);
64 if (fe
->ops
.i2c_gate_ctrl
)
65 fe
->ops
.i2c_gate_ctrl(fe
, 0);
67 return (ret
== 1) ? 0 : ret
;
70 static int tua6100_set_params(struct dvb_frontend
*fe
)
72 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
73 struct tua6100_priv
*priv
= fe
->tuner_priv
;
76 u8 reg0
[] = { 0x00, 0x00 };
77 u8 reg1
[] = { 0x01, 0x00, 0x00, 0x00 };
78 u8 reg2
[] = { 0x02, 0x00, 0x00 };
79 struct i2c_msg msg0
= { .addr
= priv
->i2c_address
, .flags
= 0, .buf
= reg0
, .len
= 2 };
80 struct i2c_msg msg1
= { .addr
= priv
->i2c_address
, .flags
= 0, .buf
= reg1
, .len
= 4 };
81 struct i2c_msg msg2
= { .addr
= priv
->i2c_address
, .flags
= 0, .buf
= reg2
, .len
= 3 };
88 if (c
->frequency
< 2000000)
94 if (c
->frequency
< 1630000)
101 if (c
->frequency
>= 1525000)
105 reg2
[1] = (_R
>> 8) & 0x03;
107 if (c
->frequency
< 1455000)
109 else if (c
->frequency
< 1630000)
115 * The N divisor ratio (note: c->frequency is in kHz, but we
118 prediv
= (c
->frequency
* _R
) / (_ri
/ 1000);
120 reg1
[1] |= (div
>> 9) & 0x03;
122 reg1
[3] = (div
<< 7);
123 priv
->frequency
= ((div
* _P
) * (_ri
/ 1000)) / _R
;
125 // Finally, calculate and store the value for A
126 reg1
[3] |= (prediv
- (div
*_P
)) & 0x7f;
132 if (fe
->ops
.i2c_gate_ctrl
)
133 fe
->ops
.i2c_gate_ctrl(fe
, 1);
134 if (i2c_transfer(priv
->i2c
, &msg0
, 1) != 1)
137 if (fe
->ops
.i2c_gate_ctrl
)
138 fe
->ops
.i2c_gate_ctrl(fe
, 1);
139 if (i2c_transfer(priv
->i2c
, &msg2
, 1) != 1)
142 if (fe
->ops
.i2c_gate_ctrl
)
143 fe
->ops
.i2c_gate_ctrl(fe
, 1);
144 if (i2c_transfer(priv
->i2c
, &msg1
, 1) != 1)
147 if (fe
->ops
.i2c_gate_ctrl
)
148 fe
->ops
.i2c_gate_ctrl(fe
, 0);
153 static int tua6100_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
155 struct tua6100_priv
*priv
= fe
->tuner_priv
;
156 *frequency
= priv
->frequency
;
160 static struct dvb_tuner_ops tua6100_tuner_ops
= {
162 .name
= "Infineon TUA6100",
163 .frequency_min
= 950000,
164 .frequency_max
= 2150000,
165 .frequency_step
= 1000,
167 .release
= tua6100_release
,
168 .sleep
= tua6100_sleep
,
169 .set_params
= tua6100_set_params
,
170 .get_frequency
= tua6100_get_frequency
,
173 struct dvb_frontend
*tua6100_attach(struct dvb_frontend
*fe
, int addr
, struct i2c_adapter
*i2c
)
175 struct tua6100_priv
*priv
= NULL
;
178 struct i2c_msg msg
[] = { { .addr
= addr
, .flags
= 0, .buf
= b1
, .len
= 1 },
179 { .addr
= addr
, .flags
= I2C_M_RD
, .buf
= b2
, .len
= 1 } };
182 if (fe
->ops
.i2c_gate_ctrl
)
183 fe
->ops
.i2c_gate_ctrl(fe
, 1);
184 ret
= i2c_transfer (i2c
, msg
, 2);
185 if (fe
->ops
.i2c_gate_ctrl
)
186 fe
->ops
.i2c_gate_ctrl(fe
, 0);
191 priv
= kzalloc(sizeof(struct tua6100_priv
), GFP_KERNEL
);
195 priv
->i2c_address
= addr
;
198 memcpy(&fe
->ops
.tuner_ops
, &tua6100_tuner_ops
, sizeof(struct dvb_tuner_ops
));
199 fe
->tuner_priv
= priv
;
202 EXPORT_SYMBOL(tua6100_attach
);
204 MODULE_DESCRIPTION("DVB tua6100 driver");
205 MODULE_AUTHOR("Andrew de Quincey");
206 MODULE_LICENSE("GPL");