diff options
author | Andrew de Quincey <adq_dvb@lidskialf.net> | 2006-09-05 16:53:06 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-09-26 11:30:35 -0400 |
commit | 00be2e7c64157c845afff56f25677da706b151b6 (patch) | |
tree | 763eecb4d93db9c2e407b6085e21655fd11cd23a /drivers | |
parent | c4e4aac88737879a562760ac07e51167847f193d (diff) |
V4L/DVB (4606): Add driver for TUA6100
This driver was originally in budget-av.c, however I have extracted it into
a seperate file to permit reuse.
I also reworked the code to make it maintainable. I then examined the KNC1
windows drivers and rewrote the code in order to configure the PLL as they
do. This solves a lot of reported tuning problems.
Signed-off-by: Andrew de Quincey <adq_dvb@lidskialf.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/dvb/frontends/Kconfig | 7 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/Makefile | 1 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/tua6100.c | 205 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/tua6100.h | 47 |
4 files changed, 260 insertions, 0 deletions
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig index 9e5ff0dbe2d4..080fa257a0bc 100644 --- a/drivers/media/dvb/frontends/Kconfig +++ b/drivers/media/dvb/frontends/Kconfig | |||
@@ -296,4 +296,11 @@ config DVB_ISL6421 | |||
296 | help | 296 | help |
297 | An SEC control chip. | 297 | An SEC control chip. |
298 | 298 | ||
299 | config DVB_TUA6100 | ||
300 | tristate "TUA6100 PLL" | ||
301 | depends on DVB_CORE && I2C | ||
302 | default m if DVB_FE_CUSTOMISE | ||
303 | help | ||
304 | A DVBS PLL chip. | ||
305 | |||
299 | endmenu | 306 | endmenu |
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile index 0b43942d8b54..dce9cf0c75c0 100644 --- a/drivers/media/dvb/frontends/Makefile +++ b/drivers/media/dvb/frontends/Makefile | |||
@@ -36,3 +36,4 @@ obj-$(CONFIG_DVB_ISL6421) += isl6421.o | |||
36 | obj-$(CONFIG_DVB_TDA10086) += tda10086.o | 36 | obj-$(CONFIG_DVB_TDA10086) += tda10086.o |
37 | obj-$(CONFIG_DVB_TDA826X) += tda826x.o | 37 | obj-$(CONFIG_DVB_TDA826X) += tda826x.o |
38 | obj-$(CONFIG_DVB_TUNER_MT2060) += mt2060.o | 38 | obj-$(CONFIG_DVB_TUNER_MT2060) += mt2060.o |
39 | obj-$(CONFIG_DVB_TUA6100) += tua6100.o | ||
diff --git a/drivers/media/dvb/frontends/tua6100.c b/drivers/media/dvb/frontends/tua6100.c new file mode 100644 index 000000000000..88554393a9bf --- /dev/null +++ b/drivers/media/dvb/frontends/tua6100.c | |||
@@ -0,0 +1,205 @@ | |||
1 | /** | ||
2 | * Driver for Infineon tua6100 pll. | ||
3 | * | ||
4 | * (c) 2006 Andrew de Quincey | ||
5 | * | ||
6 | * Based on code found in budget-av.c, which has the following: | ||
7 | * Compiled from various sources by Michael Hunold <michael@mihu.de> | ||
8 | * | ||
9 | * CI interface support (c) 2004 Olivier Gournet <ogournet@anevia.com> & | ||
10 | * Andrew de Quincey <adq_dvb@lidskialf.net> | ||
11 | * | ||
12 | * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de> | ||
13 | * | ||
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. | ||
20 | * | ||
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. | ||
25 | * | ||
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. | ||
29 | */ | ||
30 | |||
31 | #include <linux/module.h> | ||
32 | #include <linux/dvb/frontend.h> | ||
33 | #include <asm/types.h> | ||
34 | |||
35 | #include "tua6100.h" | ||
36 | |||
37 | struct tua6100_priv { | ||
38 | /* i2c details */ | ||
39 | int i2c_address; | ||
40 | struct i2c_adapter *i2c; | ||
41 | u32 frequency; | ||
42 | }; | ||
43 | |||
44 | static int tua6100_release(struct dvb_frontend *fe) | ||
45 | { | ||
46 | if (fe->tuner_priv) | ||
47 | kfree(fe->tuner_priv); | ||
48 | fe->tuner_priv = NULL; | ||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | static int tua6100_sleep(struct dvb_frontend *fe) | ||
53 | { | ||
54 | struct tua6100_priv *priv = fe->tuner_priv; | ||
55 | int ret; | ||
56 | u8 reg0[] = { 0x00, 0x00 }; | ||
57 | struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = reg0, .len = 2 }; | ||
58 | |||
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", __FUNCTION__); | ||
63 | } | ||
64 | if (fe->ops.i2c_gate_ctrl) | ||
65 | fe->ops.i2c_gate_ctrl(fe, 0); | ||
66 | |||
67 | return (ret == 1) ? 0 : ret; | ||
68 | } | ||
69 | |||
70 | static int tua6100_set_params(struct dvb_frontend *fe, | ||
71 | struct dvb_frontend_parameters *params) | ||
72 | { | ||
73 | struct tua6100_priv *priv = fe->tuner_priv; | ||
74 | u32 div; | ||
75 | u32 prediv; | ||
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 }; | ||
82 | |||
83 | #define _R 4 | ||
84 | #define _P 32 | ||
85 | #define _ri 4000000 | ||
86 | |||
87 | // setup register 0 | ||
88 | if (params->frequency < 2000000) { | ||
89 | reg0[1] = 0x03; | ||
90 | } else { | ||
91 | reg0[1] = 0x07; | ||
92 | } | ||
93 | |||
94 | // setup register 1 | ||
95 | if (params->frequency < 1630000) { | ||
96 | reg1[1] = 0x2c; | ||
97 | } else { | ||
98 | reg1[1] = 0x0c; | ||
99 | } | ||
100 | if (_P == 64) | ||
101 | reg1[1] |= 0x40; | ||
102 | if (params->frequency >= 1525000) | ||
103 | reg1[1] |= 0x80; | ||
104 | |||
105 | // register 2 | ||
106 | reg2[1] = (_R >> 8) & 0x03; | ||
107 | reg2[2] = _R; | ||
108 | if (params->frequency < 1455000) { | ||
109 | reg2[1] |= 0x1c; | ||
110 | } else if (params->frequency < 1630000) { | ||
111 | reg2[1] |= 0x0c; | ||
112 | } else { | ||
113 | reg2[1] |= 0x1c; | ||
114 | } | ||
115 | |||
116 | // The N divisor ratio (note: params->frequency is in kHz, but we need it in Hz) | ||
117 | prediv = (params->frequency * _R) / (_ri / 1000); | ||
118 | div = prediv / _P; | ||
119 | reg1[1] |= (div >> 9) & 0x03; | ||
120 | reg1[2] = div >> 1; | ||
121 | reg1[3] = (div << 7); | ||
122 | priv->frequency = ((div * _P) * (_ri / 1000)) / _R; | ||
123 | |||
124 | // Finally, calculate and store the value for A | ||
125 | reg1[3] |= (prediv - (div*_P)) & 0x7f; | ||
126 | |||
127 | #undef _R | ||
128 | #undef _P | ||
129 | #undef _ri | ||
130 | |||
131 | if (fe->ops.i2c_gate_ctrl) | ||
132 | fe->ops.i2c_gate_ctrl(fe, 1); | ||
133 | if (i2c_transfer(priv->i2c, &msg0, 1) != 1) | ||
134 | return -EIO; | ||
135 | |||
136 | if (fe->ops.i2c_gate_ctrl) | ||
137 | fe->ops.i2c_gate_ctrl(fe, 1); | ||
138 | if (i2c_transfer(priv->i2c, &msg2, 1) != 1) | ||
139 | return -EIO; | ||
140 | |||
141 | if (fe->ops.i2c_gate_ctrl) | ||
142 | fe->ops.i2c_gate_ctrl(fe, 1); | ||
143 | if (i2c_transfer(priv->i2c, &msg1, 1) != 1) | ||
144 | return -EIO; | ||
145 | |||
146 | if (fe->ops.i2c_gate_ctrl) | ||
147 | fe->ops.i2c_gate_ctrl(fe, 0); | ||
148 | |||
149 | return 0; | ||
150 | } | ||
151 | |||
152 | static int tua6100_get_frequency(struct dvb_frontend *fe, u32 *frequency) | ||
153 | { | ||
154 | struct tua6100_priv *priv = fe->tuner_priv; | ||
155 | *frequency = priv->frequency; | ||
156 | return 0; | ||
157 | } | ||
158 | |||
159 | static struct dvb_tuner_ops tua6100_tuner_ops = { | ||
160 | .info = { | ||
161 | .name = "Infineon TUA6100", | ||
162 | .frequency_min = 950000, | ||
163 | .frequency_max = 2150000, | ||
164 | .frequency_step = 1000, | ||
165 | }, | ||
166 | .release = tua6100_release, | ||
167 | .sleep = tua6100_sleep, | ||
168 | .set_params = tua6100_set_params, | ||
169 | .get_frequency = tua6100_get_frequency, | ||
170 | }; | ||
171 | |||
172 | struct dvb_frontend *tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c) | ||
173 | { | ||
174 | struct tua6100_priv *priv = NULL; | ||
175 | u8 b1 [] = { 0x80 }; | ||
176 | u8 b2 [] = { 0x00 }; | ||
177 | struct i2c_msg msg [] = { { .addr = addr, .flags = 0, .buf = b1, .len = 1 }, | ||
178 | { .addr = addr, .flags = I2C_M_RD, .buf = b2, .len = 1 } }; | ||
179 | int ret; | ||
180 | |||
181 | if (fe->ops.i2c_gate_ctrl) | ||
182 | fe->ops.i2c_gate_ctrl(fe, 1); | ||
183 | ret = i2c_transfer (i2c, msg, 2); | ||
184 | if (fe->ops.i2c_gate_ctrl) | ||
185 | fe->ops.i2c_gate_ctrl(fe, 0); | ||
186 | |||
187 | if (ret != 2) | ||
188 | return NULL; | ||
189 | |||
190 | priv = kzalloc(sizeof(struct tua6100_priv), GFP_KERNEL); | ||
191 | if (priv == NULL) | ||
192 | return NULL; | ||
193 | |||
194 | priv->i2c_address = addr; | ||
195 | priv->i2c = i2c; | ||
196 | |||
197 | memcpy(&fe->ops.tuner_ops, &tua6100_tuner_ops, sizeof(struct dvb_tuner_ops)); | ||
198 | fe->tuner_priv = priv; | ||
199 | return fe; | ||
200 | } | ||
201 | EXPORT_SYMBOL(tua6100_attach); | ||
202 | |||
203 | MODULE_DESCRIPTION("DVB tua6100 driver"); | ||
204 | MODULE_AUTHOR("Andrew de Quincey"); | ||
205 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/dvb/frontends/tua6100.h b/drivers/media/dvb/frontends/tua6100.h new file mode 100644 index 000000000000..2e5d8fb8d9ba --- /dev/null +++ b/drivers/media/dvb/frontends/tua6100.h | |||
@@ -0,0 +1,47 @@ | |||
1 | /** | ||
2 | * Driver for Infineon tua6100 PLL. | ||
3 | * | ||
4 | * (c) 2006 Andrew de Quincey | ||
5 | * | ||
6 | * Based on code found in budget-av.c, which has the following: | ||
7 | * Compiled from various sources by Michael Hunold <michael@mihu.de> | ||
8 | * | ||
9 | * CI interface support (c) 2004 Olivier Gournet <ogournet@anevia.com> & | ||
10 | * Andrew de Quincey <adq_dvb@lidskialf.net> | ||
11 | * | ||
12 | * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de> | ||
13 | * | ||
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. | ||
20 | * | ||
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. | ||
25 | * | ||
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. | ||
29 | */ | ||
30 | |||
31 | #ifndef __DVB_TUA6100_H__ | ||
32 | #define __DVB_TUA6100_H__ | ||
33 | |||
34 | #include <linux/i2c.h> | ||
35 | #include "dvb_frontend.h" | ||
36 | |||
37 | /** | ||
38 | * Attach a tua6100 pll to the supplied frontend structure. | ||
39 | * | ||
40 | * @param fe Frontend to attach to. | ||
41 | * @param addr i2c address of the pll. | ||
42 | * @param i2c i2c adapter to use. | ||
43 | * @return FE pointer on success, NULL on failure. | ||
44 | */ | ||
45 | extern struct dvb_frontend *tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c); | ||
46 | |||
47 | #endif | ||