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.
27 #include <linux/slab.h>
28 #include <linux/module.h>
29 #include <linux/dvb/frontend.h>
30 #include <asm/types.h>
37 struct i2c_adapter
*i2c
;
41 static void tua6100_release(struct dvb_frontend
*fe
)
43 kfree(fe
->tuner_priv
);
44 fe
->tuner_priv
= NULL
;
47 static int tua6100_sleep(struct dvb_frontend
*fe
)
49 struct tua6100_priv
*priv
= fe
->tuner_priv
;
51 u8 reg0
[] = { 0x00, 0x00 };
52 struct i2c_msg msg
= { .addr
= priv
->i2c_address
, .flags
= 0, .buf
= reg0
, .len
= 2 };
54 if (fe
->ops
.i2c_gate_ctrl
)
55 fe
->ops
.i2c_gate_ctrl(fe
, 1);
56 if ((ret
= i2c_transfer (priv
->i2c
, &msg
, 1)) != 1) {
57 printk("%s: i2c error\n", __func__
);
59 if (fe
->ops
.i2c_gate_ctrl
)
60 fe
->ops
.i2c_gate_ctrl(fe
, 0);
62 return (ret
== 1) ? 0 : ret
;
65 static int tua6100_set_params(struct dvb_frontend
*fe
)
67 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
68 struct tua6100_priv
*priv
= fe
->tuner_priv
;
71 u8 reg0
[] = { 0x00, 0x00 };
72 u8 reg1
[] = { 0x01, 0x00, 0x00, 0x00 };
73 u8 reg2
[] = { 0x02, 0x00, 0x00 };
74 struct i2c_msg msg0
= { .addr
= priv
->i2c_address
, .flags
= 0, .buf
= reg0
, .len
= 2 };
75 struct i2c_msg msg1
= { .addr
= priv
->i2c_address
, .flags
= 0, .buf
= reg1
, .len
= 4 };
76 struct i2c_msg msg2
= { .addr
= priv
->i2c_address
, .flags
= 0, .buf
= reg2
, .len
= 3 };
83 if (c
->frequency
< 2000000)
89 if (c
->frequency
< 1630000)
96 if (c
->frequency
>= 1525000)
100 reg2
[1] = (_R
>> 8) & 0x03;
102 if (c
->frequency
< 1455000)
104 else if (c
->frequency
< 1630000)
110 * The N divisor ratio (note: c->frequency is in kHz, but we
113 prediv
= (c
->frequency
* _R
) / (_ri
/ 1000);
115 reg1
[1] |= (div
>> 9) & 0x03;
117 reg1
[3] = (div
<< 7);
118 priv
->frequency
= ((div
* _P
) * (_ri
/ 1000)) / _R
;
120 // Finally, calculate and store the value for A
121 reg1
[3] |= (prediv
- (div
*_P
)) & 0x7f;
127 if (fe
->ops
.i2c_gate_ctrl
)
128 fe
->ops
.i2c_gate_ctrl(fe
, 1);
129 if (i2c_transfer(priv
->i2c
, &msg0
, 1) != 1)
132 if (fe
->ops
.i2c_gate_ctrl
)
133 fe
->ops
.i2c_gate_ctrl(fe
, 1);
134 if (i2c_transfer(priv
->i2c
, &msg2
, 1) != 1)
137 if (fe
->ops
.i2c_gate_ctrl
)
138 fe
->ops
.i2c_gate_ctrl(fe
, 1);
139 if (i2c_transfer(priv
->i2c
, &msg1
, 1) != 1)
142 if (fe
->ops
.i2c_gate_ctrl
)
143 fe
->ops
.i2c_gate_ctrl(fe
, 0);
148 static int tua6100_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
150 struct tua6100_priv
*priv
= fe
->tuner_priv
;
151 *frequency
= priv
->frequency
;
155 static const struct dvb_tuner_ops tua6100_tuner_ops
= {
157 .name
= "Infineon TUA6100",
158 .frequency_min
= 950000,
159 .frequency_max
= 2150000,
160 .frequency_step
= 1000,
162 .release
= tua6100_release
,
163 .sleep
= tua6100_sleep
,
164 .set_params
= tua6100_set_params
,
165 .get_frequency
= tua6100_get_frequency
,
168 struct dvb_frontend
*tua6100_attach(struct dvb_frontend
*fe
, int addr
, struct i2c_adapter
*i2c
)
170 struct tua6100_priv
*priv
= NULL
;
173 struct i2c_msg msg
[] = { { .addr
= addr
, .flags
= 0, .buf
= b1
, .len
= 1 },
174 { .addr
= addr
, .flags
= I2C_M_RD
, .buf
= b2
, .len
= 1 } };
177 if (fe
->ops
.i2c_gate_ctrl
)
178 fe
->ops
.i2c_gate_ctrl(fe
, 1);
179 ret
= i2c_transfer (i2c
, msg
, 2);
180 if (fe
->ops
.i2c_gate_ctrl
)
181 fe
->ops
.i2c_gate_ctrl(fe
, 0);
186 priv
= kzalloc(sizeof(struct tua6100_priv
), GFP_KERNEL
);
190 priv
->i2c_address
= addr
;
193 memcpy(&fe
->ops
.tuner_ops
, &tua6100_tuner_ops
, sizeof(struct dvb_tuner_ops
));
194 fe
->tuner_priv
= priv
;
197 EXPORT_SYMBOL(tua6100_attach
);
199 MODULE_DESCRIPTION("DVB tua6100 driver");
200 MODULE_AUTHOR("Andrew de Quincey");
201 MODULE_LICENSE("GPL");