blob: 659fd1b43c2544111ff2a4b71fbe96916ca34d33 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
4 *
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -07005 * Extended 3 / 2005 by Hartmut Hackmann to support various
6 * cards with the tda10046 DVB-T channel decoder
7 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/init.h>
24#include <linux/list.h>
25#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/slab.h>
28#include <linux/delay.h>
29#include <linux/kthread.h>
30#include <linux/suspend.h>
31
32#include "saa7134-reg.h"
33#include "saa7134.h"
Michael Krufky5e453dc2006-01-09 15:32:31 -020034#include <media/v4l2-common.h>
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -020035#include "dvb-pll.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Andrew de Quincey1f10c7a2006-08-08 09:10:09 -030037#include "mt352.h"
38#include "mt352_priv.h" /* FIXME */
39#include "tda1004x.h"
40#include "nxt200x.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -030042#include "tda10086.h"
43#include "tda826x.h"
Michael Krufky8ce47da2007-04-27 12:31:14 -030044#include "tda827x.h"
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -030045#include "isl6421.h"
Michael Krufky8ce47da2007-04-27 12:31:14 -030046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
48MODULE_LICENSE("GPL");
49
50static unsigned int antenna_pwr = 0;
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052module_param(antenna_pwr, int, 0444);
53MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
54
Stephan Berberigb331daa2006-12-20 09:37:05 -030055static int use_frontend = 0;
56module_param(use_frontend, int, 0644);
57MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
Nico Sabbi1f683cd2006-11-15 22:06:56 -030058
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -030059static int debug = 0;
60module_param(debug, int, 0644);
61MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
62
63#define dprintk(fmt, arg...) if (debug) \
64 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg)
65
66/* ------------------------------------------------------------------
67 * mt352 based DVB-T cards
68 */
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
71{
72 u32 ok;
73
74 if (!on) {
75 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
76 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
77 return 0;
78 }
79
80 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
81 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
82 udelay(10);
83
84 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
85 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
86 udelay(10);
87 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
88 udelay(10);
89 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
90 printk("%s: %s %s\n", dev->name, __FUNCTION__,
91 ok ? "on" : "off");
92
93 if (!ok)
94 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
95 return ok;
96}
97
98static int mt352_pinnacle_init(struct dvb_frontend* fe)
99{
100 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
101 static u8 reset [] = { RESET, 0x80 };
102 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
103 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
104 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
105 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
106 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
107 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
108 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
109 struct saa7134_dev *dev= fe->dvb->priv;
110
111 printk("%s: %s called\n",dev->name,__FUNCTION__);
112
113 mt352_write(fe, clock_config, sizeof(clock_config));
114 udelay(200);
115 mt352_write(fe, reset, sizeof(reset));
116 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
117 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
118 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
119 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
120
121 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
122 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
123 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
Hartmut Hackmanndf8cf702006-03-03 12:09:26 -0300124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 return 0;
126}
127
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200128static int mt352_aver777_init(struct dvb_frontend* fe)
129{
130 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
131 static u8 reset [] = { RESET, 0x80 };
132 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
133 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
134 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
135
136 mt352_write(fe, clock_config, sizeof(clock_config));
137 udelay(200);
138 mt352_write(fe, reset, sizeof(reset));
139 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
140 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
141 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
142
143 return 0;
144}
145
Andrew de Quincey0463f122006-05-16 17:22:02 -0300146static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
147 struct dvb_frontend_parameters* params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Hartmut Hackmanndf8cf702006-03-03 12:09:26 -0300149 u8 off[] = { 0x00, 0xf1};
150 u8 on[] = { 0x00, 0x71};
151 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 struct saa7134_dev *dev = fe->dvb->priv;
154 struct v4l2_frequency f;
155
156 /* set frequency (mt2050) */
157 f.tuner = 0;
158 f.type = V4L2_TUNER_DIGITAL_TV;
159 f.frequency = params->frequency / 1000 * 16 / 1000;
Patrick Boettcherdea74862006-05-14 05:01:31 -0300160 if (fe->ops.i2c_gate_ctrl)
161 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmanndf8cf702006-03-03 12:09:26 -0300162 i2c_transfer(&dev->i2c_adap, &msg, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
Hartmut Hackmanndf8cf702006-03-03 12:09:26 -0300164 msg.buf = on;
Patrick Boettcherdea74862006-05-14 05:01:31 -0300165 if (fe->ops.i2c_gate_ctrl)
166 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmanndf8cf702006-03-03 12:09:26 -0300167 i2c_transfer(&dev->i2c_adap, &msg, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 pinnacle_antenna_pwr(dev, antenna_pwr);
170
171 /* mt352 setup */
Andrew de Quincey0463f122006-05-16 17:22:02 -0300172 return mt352_pinnacle_init(fe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173}
174
Andrew de Quinceybd4956b2006-04-18 21:38:49 -0300175static int mt352_aver777_tuner_calc_regs(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8* pllbuf, int buf_len)
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200176{
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300177 if (buf_len < 5)
178 return -EINVAL;
179
180 pllbuf[0] = 0x61;
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200181 dvb_pll_configure(&dvb_pll_philips_td1316, pllbuf+1,
182 params->frequency,
183 params->u.ofdm.bandwidth);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300184 return 5;
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200185}
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187static struct mt352_config pinnacle_300i = {
188 .demod_address = 0x3c >> 1,
189 .adc_clock = 20333,
190 .if2 = 36150,
191 .no_tuner = 1,
192 .demod_init = mt352_pinnacle_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193};
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200194
195static struct mt352_config avermedia_777 = {
196 .demod_address = 0xf,
197 .demod_init = mt352_aver777_init,
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200198};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300200/* ==================================================================
201 * tda1004x based DVB-T cards, helper functions
202 */
203
204static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
205 const struct firmware **fw, char *name)
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700206{
207 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300208 return request_firmware(fw, name, &dev->pci->dev);
209}
210
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300211/* ------------------------------------------------------------------
212 * these tuners are tu1216, td1316(a)
213 */
214
215static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
216{
217 struct saa7134_dev *dev = fe->dvb->priv;
218 struct tda1004x_state *state = fe->demodulator_priv;
219 u8 addr = state->config->tuner_address;
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700220 u8 tuner_buf[4];
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800221 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700222 sizeof(tuner_buf) };
223 int tuner_frequency = 0;
224 u8 band, cp, filter;
225
226 /* determine charge pump */
227 tuner_frequency = params->frequency + 36166000;
228 if (tuner_frequency < 87000000)
229 return -EINVAL;
230 else if (tuner_frequency < 130000000)
231 cp = 3;
232 else if (tuner_frequency < 160000000)
233 cp = 5;
234 else if (tuner_frequency < 200000000)
235 cp = 6;
236 else if (tuner_frequency < 290000000)
237 cp = 3;
238 else if (tuner_frequency < 420000000)
239 cp = 5;
240 else if (tuner_frequency < 480000000)
241 cp = 6;
242 else if (tuner_frequency < 620000000)
243 cp = 3;
244 else if (tuner_frequency < 830000000)
245 cp = 5;
246 else if (tuner_frequency < 895000000)
247 cp = 7;
248 else
249 return -EINVAL;
250
251 /* determine band */
252 if (params->frequency < 49000000)
253 return -EINVAL;
254 else if (params->frequency < 161000000)
255 band = 1;
256 else if (params->frequency < 444000000)
257 band = 2;
258 else if (params->frequency < 861000000)
259 band = 4;
260 else
261 return -EINVAL;
262
263 /* setup PLL filter */
264 switch (params->u.ofdm.bandwidth) {
265 case BANDWIDTH_6_MHZ:
266 filter = 0;
267 break;
268
269 case BANDWIDTH_7_MHZ:
270 filter = 0;
271 break;
272
273 case BANDWIDTH_8_MHZ:
274 filter = 1;
275 break;
276
277 default:
278 return -EINVAL;
279 }
280
281 /* calculate divisor
282 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
283 */
284 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
285
286 /* setup tuner buffer */
287 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
288 tuner_buf[1] = tuner_frequency & 0xff;
289 tuner_buf[2] = 0xca;
290 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
291
Patrick Boettcherdea74862006-05-14 05:01:31 -0300292 if (fe->ops.i2c_gate_ctrl)
293 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300294 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
295 printk("%s/dvb: could not write to tuner at addr: 0x%02x\n",dev->name, addr << 1);
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700296 return -EIO;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300297 }
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700298 msleep(1);
299 return 0;
300}
301
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300302static int philips_tu1216_init(struct dvb_frontend *fe)
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800303{
304 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300305 struct tda1004x_state *state = fe->demodulator_priv;
306 u8 addr = state->config->tuner_address;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800307 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
308 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
309
310 /* setup PLL configuration */
Patrick Boettcherdea74862006-05-14 05:01:31 -0300311 if (fe->ops.i2c_gate_ctrl)
312 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800313 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
314 return -EIO;
315 msleep(1);
316
317 return 0;
318}
319
320/* ------------------------------------------------------------------ */
321
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800322static struct tda1004x_config philips_tu1216_60_config = {
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700323 .demod_address = 0x8,
324 .invert = 1,
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800325 .invert_oclk = 0,
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700326 .xtal_freq = TDA10046_XTAL_4M,
327 .agc_config = TDA10046_AGC_DEFAULT,
328 .if_freq = TDA10046_FREQ_3617,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300329 .tuner_address = 0x60,
330 .request_firmware = philips_tda1004x_request_firmware
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331};
332
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800333static struct tda1004x_config philips_tu1216_61_config = {
334
335 .demod_address = 0x8,
336 .invert = 1,
337 .invert_oclk = 0,
338 .xtal_freq = TDA10046_XTAL_4M,
339 .agc_config = TDA10046_AGC_DEFAULT,
340 .if_freq = TDA10046_FREQ_3617,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300341 .tuner_address = 0x61,
342 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800343};
344
345/* ------------------------------------------------------------------ */
346
Hartmut Hackmanncbb94522006-10-30 20:00:16 -0300347static int philips_td1316_tuner_init(struct dvb_frontend *fe)
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800348{
349 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300350 struct tda1004x_state *state = fe->demodulator_priv;
351 u8 addr = state->config->tuner_address;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800352 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300353 struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800354
355 /* setup PLL configuration */
Patrick Boettcherdea74862006-05-14 05:01:31 -0300356 if (fe->ops.i2c_gate_ctrl)
357 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800358 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
359 return -EIO;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800360 return 0;
361}
362
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300363static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800364{
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300365 return philips_tda6651_pll_set(fe, params);
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800366}
367
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300368static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
369{
370 struct saa7134_dev *dev = fe->dvb->priv;
371 struct tda1004x_state *state = fe->demodulator_priv;
372 u8 addr = state->config->tuner_address;
373 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
374 struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
375
376 /* switch the tuner to analog mode */
377 if (fe->ops.i2c_gate_ctrl)
378 fe->ops.i2c_gate_ctrl(fe, 1);
379 if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
380 return -EIO;
381 return 0;
382}
383
384/* ------------------------------------------------------------------ */
385
Hartmut Hackmanncbb94522006-10-30 20:00:16 -0300386static int philips_europa_tuner_init(struct dvb_frontend *fe)
387{
388 struct saa7134_dev *dev = fe->dvb->priv;
389 static u8 msg[] = { 0x00, 0x40};
390 struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
391
392
393 if (philips_td1316_tuner_init(fe))
394 return -EIO;
395 msleep(1);
396 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
397 return -EIO;
398
399 return 0;
400}
401
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300402static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800403{
404 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800405
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300406 static u8 msg[] = { 0x00, 0x14 };
407 struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
408
409 if (philips_td1316_tuner_sleep(fe))
410 return -EIO;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800411
412 /* switch the board to analog mode */
Patrick Boettcherdea74862006-05-14 05:01:31 -0300413 if (fe->ops.i2c_gate_ctrl)
414 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800415 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300416 return 0;
417}
418
419static int philips_europa_demod_sleep(struct dvb_frontend *fe)
420{
421 struct saa7134_dev *dev = fe->dvb->priv;
422
423 if (dev->original_demod_sleep)
424 dev->original_demod_sleep(fe);
Patrick Boettcherdea74862006-05-14 05:01:31 -0300425 fe->ops.i2c_gate_ctrl(fe, 1);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300426 return 0;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800427}
428
429static struct tda1004x_config philips_europa_config = {
430
431 .demod_address = 0x8,
432 .invert = 0,
433 .invert_oclk = 0,
434 .xtal_freq = TDA10046_XTAL_4M,
435 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
436 .if_freq = TDA10046_FREQ_052,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300437 .tuner_address = 0x61,
438 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800439};
440
441/* ------------------------------------------------------------------ */
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700442
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300443static int philips_fmd1216_tuner_init(struct dvb_frontend *fe)
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700444{
445 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300446 struct tda1004x_state *state = fe->demodulator_priv;
447 u8 addr = state->config->tuner_address;
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700448 /* this message is to set up ATC and ALC */
449 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300450 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700451
Patrick Boettcherdea74862006-05-14 05:01:31 -0300452 if (fe->ops.i2c_gate_ctrl)
453 fe->ops.i2c_gate_ctrl(fe, 1);
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700454 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
455 return -EIO;
456 msleep(1);
457
458 return 0;
459}
460
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300461static int philips_fmd1216_tuner_sleep(struct dvb_frontend *fe)
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700462{
463 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300464 struct tda1004x_state *state = fe->demodulator_priv;
465 u8 addr = state->config->tuner_address;
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700466 /* this message actually turns the tuner back to analog mode */
467 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300468 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700469
Patrick Boettcherdea74862006-05-14 05:01:31 -0300470 if (fe->ops.i2c_gate_ctrl)
471 fe->ops.i2c_gate_ctrl(fe, 1);
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700472 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
473 msleep(1);
474 fmd1216_init[2] = 0x86;
475 fmd1216_init[3] = 0x54;
Patrick Boettcherdea74862006-05-14 05:01:31 -0300476 if (fe->ops.i2c_gate_ctrl)
477 fe->ops.i2c_gate_ctrl(fe, 1);
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700478 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
479 msleep(1);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300480 return 0;
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700481}
482
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300483static int philips_fmd1216_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700484{
485 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300486 struct tda1004x_state *state = fe->demodulator_priv;
487 u8 addr = state->config->tuner_address;
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700488 u8 tuner_buf[4];
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300489 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700490 sizeof(tuner_buf) };
491 int tuner_frequency = 0;
492 int divider = 0;
493 u8 band, mode, cp;
494
495 /* determine charge pump */
496 tuner_frequency = params->frequency + 36130000;
497 if (tuner_frequency < 87000000)
498 return -EINVAL;
499 /* low band */
500 else if (tuner_frequency < 180000000) {
501 band = 1;
502 mode = 7;
503 cp = 0;
504 } else if (tuner_frequency < 195000000) {
505 band = 1;
506 mode = 6;
507 cp = 1;
508 /* mid band */
509 } else if (tuner_frequency < 366000000) {
510 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
511 band = 10;
512 } else {
513 band = 2;
514 }
515 mode = 7;
516 cp = 0;
517 } else if (tuner_frequency < 478000000) {
518 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
519 band = 10;
520 } else {
521 band = 2;
522 }
523 mode = 6;
524 cp = 1;
525 /* high band */
526 } else if (tuner_frequency < 662000000) {
527 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
528 band = 12;
529 } else {
530 band = 4;
531 }
532 mode = 7;
533 cp = 0;
534 } else if (tuner_frequency < 840000000) {
535 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
536 band = 12;
537 } else {
538 band = 4;
539 }
540 mode = 6;
541 cp = 1;
542 } else {
543 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
544 band = 12;
545 } else {
546 band = 4;
547 }
548 mode = 7;
549 cp = 1;
550
551 }
552 /* calculate divisor */
553 /* ((36166000 + Finput) / 166666) rounded! */
554 divider = (tuner_frequency + 83333) / 166667;
555
556 /* setup tuner buffer */
557 tuner_buf[0] = (divider >> 8) & 0x7f;
558 tuner_buf[1] = divider & 0xff;
559 tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
560 tuner_buf[3] = 0x40 | band;
561
Patrick Boettcherdea74862006-05-14 05:01:31 -0300562 if (fe->ops.i2c_gate_ctrl)
563 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300564 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
565 printk("%s/dvb: could not write to tuner at addr: 0x%02x\n",dev->name, addr << 1);
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700566 return -EIO;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300567 }
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700568 return 0;
569}
570
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700571static struct tda1004x_config medion_cardbus = {
572 .demod_address = 0x08,
573 .invert = 1,
574 .invert_oclk = 0,
575 .xtal_freq = TDA10046_XTAL_16M,
576 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
577 .if_freq = TDA10046_FREQ_3613,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300578 .tuner_address = 0x61,
579 .request_firmware = philips_tda1004x_request_firmware
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700580};
581
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300582/* ------------------------------------------------------------------
583 * tda 1004x based cards with philips silicon tuner
584 */
585
586static void philips_tda827x_lna_gain(struct dvb_frontend *fe, int high)
587{
588 struct saa7134_dev *dev = fe->dvb->priv;
589 struct tda1004x_state *state = fe->demodulator_priv;
590 u8 addr = state->config->i2c_gate;
591 u8 config = state->config->tuner_config;
592 u8 GP00_CF[] = {0x20, 0x01};
593 u8 GP00_LEV[] = {0x22, 0x00};
594
595 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = GP00_CF, .len = 2};
596 if (config) {
597 if (high) {
598 dprintk("setting LNA to high gain\n");
599 } else {
600 dprintk("setting LNA to low gain\n");
601 }
602 }
603 switch (config) {
604 case 0: /* no LNA */
605 break;
606 case 1: /* switch is GPIO 0 of tda8290 */
607 case 2:
608 /* turn Vsync off */
609 saa7134_set_gpio(dev, 22, 0);
610 GP00_LEV[1] = high ? 0 : 1;
611 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
612 printk("%s/dvb: could not access tda8290 at addr: 0x%02x\n",dev->name, addr << 1);
613 return;
614 }
615 msg.buf = GP00_LEV;
616 if (config == 2)
617 GP00_LEV[1] = high ? 1 : 0;
618 i2c_transfer(&dev->i2c_adap, &msg, 1);
619 break;
620 case 3: /* switch with GPIO of saa713x */
621 saa7134_set_gpio(dev, 22, high);
622 break;
623 }
624}
625
626static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
627{
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300628 struct tda1004x_state *state = fe->demodulator_priv;
629
630 u8 addr = state->config->i2c_gate;
631 static u8 tda8290_close[] = { 0x21, 0xc0};
632 static u8 tda8290_open[] = { 0x21, 0x80};
633 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
634 if (enable) {
635 tda8290_msg.buf = tda8290_close;
636 } else {
637 tda8290_msg.buf = tda8290_open;
638 }
Hartmut Hackmann06be3032007-04-27 12:31:15 -0300639 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
640 printk("saa7134/dvb: could not access tda8290 I2C gate\n");
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300641 return -EIO;
642 }
643 msleep(20);
644 return 0;
645}
646
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700647/* ------------------------------------------------------------------ */
648
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300649static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
Hartmut Hackmann587d2fd2006-10-06 19:13:50 -0300650{
651 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300652 struct tda1004x_state *state = fe->demodulator_priv;
Michael Krufky8ce47da2007-04-27 12:31:14 -0300653
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300654 switch (state->config->antenna_switch) {
655 case 0: break;
656 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
657 saa7134_set_gpio(dev, 21, 0);
658 break;
659 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
660 saa7134_set_gpio(dev, 21, 1);
661 break;
662 }
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300663 return 0;
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800664}
665
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300666static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
667{
668 struct saa7134_dev *dev = fe->dvb->priv;
669 struct tda1004x_state *state = fe->demodulator_priv;
Michael Krufky8ce47da2007-04-27 12:31:14 -0300670
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300671 switch (state->config->antenna_switch) {
672 case 0: break;
673 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
674 saa7134_set_gpio(dev, 21, 1);
675 break;
676 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
677 saa7134_set_gpio(dev, 21, 0);
678 break;
679 }
680 return 0;
681}
682
Michael Krufky8ce47da2007-04-27 12:31:14 -0300683static struct tda827x_config tda827x_cfg = {
684 .lna_gain = philips_tda827x_lna_gain,
685 .init = philips_tda827x_tuner_init,
686 .sleep = philips_tda827x_tuner_sleep
687};
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300688
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -0300689static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf)
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300690{
691 dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap);
692 if (dev->dvb.frontend) {
693 if (tda_conf->i2c_gate)
694 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
Michael Krufky8ce47da2007-04-27 12:31:14 -0300695 dvb_attach(tda827x_attach,dev->dvb.frontend,
696 tda_conf->tuner_address,&dev->i2c_adap,&tda827x_cfg);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300697 }
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300698}
699
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800700/* ------------------------------------------------------------------ */
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300701static struct tda1004x_config tda827x_lifeview_config = {
702 .demod_address = 0x08,
703 .invert = 1,
704 .invert_oclk = 0,
705 .xtal_freq = TDA10046_XTAL_16M,
706 .agc_config = TDA10046_AGC_TDA827X,
707 .gpio_config = TDA10046_GP11_I,
708 .if_freq = TDA10046_FREQ_045,
709 .tuner_address = 0x60,
710 .request_firmware = philips_tda1004x_request_firmware
711};
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800712
713static struct tda1004x_config philips_tiger_config = {
714 .demod_address = 0x08,
715 .invert = 1,
716 .invert_oclk = 0,
717 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300718 .agc_config = TDA10046_AGC_TDA827X,
719 .gpio_config = TDA10046_GP11_I,
Hartmut Hackmann550a9a52006-11-15 21:31:54 -0300720 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300721 .i2c_gate = 0x4b,
722 .tuner_address = 0x61,
723 .tuner_config = 0,
724 .antenna_switch= 1,
725 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann550a9a52006-11-15 21:31:54 -0300726};
Hartmut Hackmann550a9a52006-11-15 21:31:54 -0300727
728static struct tda1004x_config cinergy_ht_config = {
729 .demod_address = 0x08,
730 .invert = 1,
731 .invert_oclk = 0,
732 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300733 .agc_config = TDA10046_AGC_TDA827X,
734 .gpio_config = TDA10046_GP01_I,
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800735 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300736 .i2c_gate = 0x4b,
737 .tuner_address = 0x61,
738 .tuner_config = 0,
739 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800740};
741
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300742static struct tda1004x_config cinergy_ht_pci_config = {
743 .demod_address = 0x08,
744 .invert = 1,
745 .invert_oclk = 0,
746 .xtal_freq = TDA10046_XTAL_16M,
747 .agc_config = TDA10046_AGC_TDA827X,
748 .gpio_config = TDA10046_GP01_I,
749 .if_freq = TDA10046_FREQ_045,
750 .i2c_gate = 0x4b,
751 .tuner_address = 0x60,
752 .tuner_config = 0,
753 .request_firmware = philips_tda1004x_request_firmware
754};
755
756static struct tda1004x_config philips_tiger_s_config = {
757 .demod_address = 0x08,
758 .invert = 1,
759 .invert_oclk = 0,
760 .xtal_freq = TDA10046_XTAL_16M,
761 .agc_config = TDA10046_AGC_TDA827X,
762 .gpio_config = TDA10046_GP01_I,
763 .if_freq = TDA10046_FREQ_045,
764 .i2c_gate = 0x4b,
765 .tuner_address = 0x61,
766 .tuner_config = 2,
767 .antenna_switch= 1,
768 .request_firmware = philips_tda1004x_request_firmware
769};
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200770
Hartmut Hackmann587d2fd2006-10-06 19:13:50 -0300771static struct tda1004x_config pinnacle_pctv_310i_config = {
772 .demod_address = 0x08,
773 .invert = 1,
774 .invert_oclk = 0,
775 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300776 .agc_config = TDA10046_AGC_TDA827X,
777 .gpio_config = TDA10046_GP11_I,
Hartmut Hackmann587d2fd2006-10-06 19:13:50 -0300778 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300779 .i2c_gate = 0x4b,
780 .tuner_address = 0x61,
781 .tuner_config = 1,
782 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann587d2fd2006-10-06 19:13:50 -0300783};
784
Thomas Gentyc6e53da2006-11-05 14:17:30 -0300785static struct tda1004x_config hauppauge_hvr_1110_config = {
786 .demod_address = 0x08,
787 .invert = 1,
788 .invert_oclk = 0,
789 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300790 .agc_config = TDA10046_AGC_TDA827X,
791 .gpio_config = TDA10046_GP11_I,
Thomas Gentyc6e53da2006-11-05 14:17:30 -0300792 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300793 .i2c_gate = 0x4b,
794 .tuner_address = 0x61,
795 .request_firmware = philips_tda1004x_request_firmware
Thomas Gentyc6e53da2006-11-05 14:17:30 -0300796};
797
Hartmut Hackmann83646812006-10-12 20:38:51 -0300798static struct tda1004x_config asus_p7131_dual_config = {
799 .demod_address = 0x08,
800 .invert = 1,
801 .invert_oclk = 0,
802 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300803 .agc_config = TDA10046_AGC_TDA827X,
804 .gpio_config = TDA10046_GP11_I,
Hartmut Hackmann83646812006-10-12 20:38:51 -0300805 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300806 .i2c_gate = 0x4b,
807 .tuner_address = 0x61,
808 .tuner_config = 0,
809 .antenna_switch= 2,
810 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann83646812006-10-12 20:38:51 -0300811};
812
Nico Sabbi420f32f2006-03-03 12:11:28 -0300813static struct tda1004x_config lifeview_trio_config = {
814 .demod_address = 0x09,
815 .invert = 1,
816 .invert_oclk = 0,
817 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300818 .agc_config = TDA10046_AGC_TDA827X,
819 .gpio_config = TDA10046_GP00_I,
Nico Sabbi420f32f2006-03-03 12:11:28 -0300820 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300821 .tuner_address = 0x60,
822 .request_firmware = philips_tda1004x_request_firmware
Nico Sabbi420f32f2006-03-03 12:11:28 -0300823};
824
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300825static struct tda1004x_config tevion_dvbt220rf_config = {
826 .demod_address = 0x08,
827 .invert = 1,
828 .invert_oclk = 0,
829 .xtal_freq = TDA10046_XTAL_16M,
830 .agc_config = TDA10046_AGC_TDA827X,
831 .gpio_config = TDA10046_GP11_I,
832 .if_freq = TDA10046_FREQ_045,
833 .tuner_address = 0x60,
834 .request_firmware = philips_tda1004x_request_firmware
835};
Nico Sabbi420f32f2006-03-03 12:11:28 -0300836
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300837static struct tda1004x_config md8800_dvbt_config = {
838 .demod_address = 0x08,
839 .invert = 1,
840 .invert_oclk = 0,
841 .xtal_freq = TDA10046_XTAL_16M,
842 .agc_config = TDA10046_AGC_TDA827X,
843 .gpio_config = TDA10046_GP01_I,
844 .if_freq = TDA10046_FREQ_045,
845 .i2c_gate = 0x4b,
846 .tuner_address = 0x60,
847 .tuner_config = 0,
848 .request_firmware = philips_tda1004x_request_firmware
849};
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200850
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300851/* ------------------------------------------------------------------
852 * special case: this card uses saa713x GPIO22 for the mode switch
853 */
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200854
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300855static int ads_duo_tuner_init(struct dvb_frontend *fe)
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200856{
857 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300858 philips_tda827x_tuner_init(fe);
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200859 /* route TDA8275a AGC input to the channel decoder */
Hartmut Hackmann06be3032007-04-27 12:31:15 -0300860 saa7134_set_gpio(dev, 22, 1);
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200861 return 0;
862}
863
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300864static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200865{
866 struct saa7134_dev *dev = fe->dvb->priv;
867 /* route TDA8275a AGC input to the analog IF chip*/
Hartmut Hackmann06be3032007-04-27 12:31:15 -0300868 saa7134_set_gpio(dev, 22, 0);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300869 philips_tda827x_tuner_sleep(fe);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300870 return 0;
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200871}
872
Michael Krufky8ce47da2007-04-27 12:31:14 -0300873static struct tda827x_config ads_duo_cfg = {
874 .lna_gain = philips_tda827x_lna_gain,
875 .init = ads_duo_tuner_init,
876 .sleep = ads_duo_tuner_sleep
877};
878
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200879static struct tda1004x_config ads_tech_duo_config = {
880 .demod_address = 0x08,
881 .invert = 1,
882 .invert_oclk = 0,
883 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300884 .agc_config = TDA10046_AGC_TDA827X,
885 .gpio_config = TDA10046_GP00_I,
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200886 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300887 .tuner_address = 0x61,
888 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200889};
890
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300891/* ==================================================================
892 * tda10086 based DVB-S cards, helper functions
893 */
Hartmut Hackmann5eda2272006-08-07 14:03:32 -0300894
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -0300895static struct tda10086_config flydvbs = {
896 .demod_address = 0x0e,
897 .invert = 0,
898};
899
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300900/* ==================================================================
901 * nxt200x based ATSC cards, helper functions
902 */
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800903
Michael Krufky3b64e8e2005-11-08 21:38:20 -0800904static struct nxt200x_config avertvhda180 = {
905 .demod_address = 0x0a,
Michael Krufky3b64e8e2005-11-08 21:38:20 -0800906};
Andrew Burri3e1410a2006-02-27 00:08:23 -0300907
Curt Meyersfbc81c02006-02-27 00:08:27 -0300908static int nxt200x_set_pll_input(u8 *buf, int input)
909{
910 if (input)
911 buf[3] |= 0x08;
912 else
913 buf[3] &= ~0x08;
914 return 0;
915}
916
Andrew Burri3e1410a2006-02-27 00:08:23 -0300917static struct nxt200x_config kworldatsc110 = {
918 .demod_address = 0x0a,
Curt Meyersfbc81c02006-02-27 00:08:27 -0300919 .set_pll_input = nxt200x_set_pll_input,
Andrew Burri3e1410a2006-02-27 00:08:23 -0300920};
Michael Krufky3b64e8e2005-11-08 21:38:20 -0800921
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300922/* ==================================================================
923 * Core code
924 */
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926static int dvb_init(struct saa7134_dev *dev)
927{
Hartmut Hackmann1c4f76a2007-04-27 12:31:16 -0300928 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 /* init struct videobuf_dvb */
930 dev->ts.nr_bufs = 32;
931 dev->ts.nr_packets = 32*4;
932 dev->dvb.name = dev->name;
933 videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
934 dev->pci, &dev->slock,
935 V4L2_BUF_TYPE_VIDEO_CAPTURE,
936 V4L2_FIELD_ALTERNATE,
937 sizeof(struct saa7134_buf),
938 dev);
939
940 switch (dev->board) {
941 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
942 printk("%s: pinnacle 300i dvb setup\n",dev->name);
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300943 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
Michael Krufkyf7b54b12006-08-08 15:48:08 -0300944 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300945 if (dev->dvb.frontend) {
Patrick Boettcherdea74862006-05-14 05:01:31 -0300946 dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 break;
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200949 case SAA7134_BOARD_AVERMEDIA_777:
Petr Baudis515c2082006-09-26 16:53:53 -0300950 case SAA7134_BOARD_AVERMEDIA_A16AR:
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200951 printk("%s: avertv 777 dvb setup\n",dev->name);
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300952 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
Michael Krufkyf7b54b12006-08-08 15:48:08 -0300953 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300954 if (dev->dvb.frontend) {
Patrick Boettcherdea74862006-05-14 05:01:31 -0300955 dev->dvb.frontend->ops.tuner_ops.calc_regs = mt352_aver777_tuner_calc_regs;
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300956 }
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200957 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 case SAA7134_BOARD_MD7134:
Michael Krufkyf7b54b12006-08-08 15:48:08 -0300959 dev->dvb.frontend = dvb_attach(tda10046_attach,
960 &medion_cardbus,
961 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300962 if (dev->dvb.frontend) {
Patrick Boettcherdea74862006-05-14 05:01:31 -0300963 dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
964 dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
965 dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300966 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 break;
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700968 case SAA7134_BOARD_PHILIPS_TOUGH:
Michael Krufkyf7b54b12006-08-08 15:48:08 -0300969 dev->dvb.frontend = dvb_attach(tda10046_attach,
970 &philips_tu1216_60_config,
971 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300972 if (dev->dvb.frontend) {
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300973 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
974 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300975 }
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700976 break;
977 case SAA7134_BOARD_FLYDVBTDUO:
Peter Missel10b7a902006-01-23 17:11:06 -0200978 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -0300979 configure_tda827x_fe(dev, &tda827x_lifeview_config);
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700980 break;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800981 case SAA7134_BOARD_PHILIPS_EUROPA:
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800982 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
Michael Krufkyf7b54b12006-08-08 15:48:08 -0300983 dev->dvb.frontend = dvb_attach(tda10046_attach,
984 &philips_europa_config,
985 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300986 if (dev->dvb.frontend) {
Hartmut Hackmann588f9832006-10-18 17:30:42 -0300987 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
988 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
Patrick Boettcherdea74862006-05-14 05:01:31 -0300989 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
990 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
991 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300992 }
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800993 break;
994 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
Michael Krufkyf7b54b12006-08-08 15:48:08 -0300995 dev->dvb.frontend = dvb_attach(tda10046_attach,
996 &philips_tu1216_61_config,
997 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300998 if (dev->dvb.frontend) {
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300999 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1000 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001001 }
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -08001002 break;
Hartmut Hackmann90e9df72005-11-08 21:38:42 -08001003 case SAA7134_BOARD_PHILIPS_TIGER:
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -03001004 configure_tda827x_fe(dev, &philips_tiger_config);
Hartmut Hackmann587d2fd2006-10-06 19:13:50 -03001005 break;
1006 case SAA7134_BOARD_PINNACLE_PCTV_310i:
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -03001007 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config);
Hartmut Hackmann90e9df72005-11-08 21:38:42 -08001008 break;
Thomas Gentyc6e53da2006-11-05 14:17:30 -03001009 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -03001010 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config);
Thomas Gentyc6e53da2006-11-05 14:17:30 -03001011 break;
Hartmut Hackmannd4b0aba2005-11-08 21:38:44 -08001012 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -03001013 configure_tda827x_fe(dev, &asus_p7131_dual_config);
Hartmut Hackmannd4b0aba2005-11-08 21:38:44 -08001014 break;
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -02001015 case SAA7134_BOARD_FLYDVBT_LR301:
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -03001016 configure_tda827x_fe(dev, &tda827x_lifeview_config);
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -02001017 break;
Nico Sabbi420f32f2006-03-03 12:11:28 -03001018 case SAA7134_BOARD_FLYDVB_TRIO:
Stephan Berberigb331daa2006-12-20 09:37:05 -03001019 if(! use_frontend) { //terrestrial
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -03001020 configure_tda827x_fe(dev, &lifeview_trio_config);
Nico Sabbi1f683cd2006-11-15 22:06:56 -03001021 } else { //satellite
1022 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1023 if (dev->dvb.frontend) {
1024 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1025 &dev->i2c_adap, 0) == NULL) {
1026 printk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__);
1027 }
1028 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1029 0x08, 0, 0) == NULL) {
1030 printk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__);
1031 }
1032 }
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001033 }
Nico Sabbi420f32f2006-03-03 12:11:28 -03001034 break;
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -02001035 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
Hartmut Hackmannd95b8942006-03-27 19:39:30 -03001036 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001037 dev->dvb.frontend = dvb_attach(tda10046_attach,
1038 &ads_tech_duo_config,
1039 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001040 if (dev->dvb.frontend) {
Michael Krufky8ce47da2007-04-27 12:31:14 -03001041 dvb_attach(tda827x_attach,dev->dvb.frontend,
1042 ads_tech_duo_config.tuner_address,
1043 &dev->i2c_adap,&ads_duo_cfg);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001044 }
Hartmut Hackmannd95b8942006-03-27 19:39:30 -03001045 break;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -03001046 case SAA7134_BOARD_TEVION_DVBT_220RF:
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -03001047 configure_tda827x_fe(dev, &tevion_dvbt220rf_config);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -03001048 break;
Hartmut Hackmann5eda2272006-08-07 14:03:32 -03001049 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -03001050 configure_tda827x_fe(dev, &md8800_dvbt_config);
Hartmut Hackmann5eda2272006-08-07 14:03:32 -03001051 break;
Michael Krufky3b64e8e2005-11-08 21:38:20 -08001052 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001053 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1054 &dev->i2c_adap);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -03001055 if (dev->dvb.frontend) {
Michael Krufky4ad8eee52006-08-08 15:48:08 -03001056 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1057 NULL, &dvb_pll_tdhu2);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -03001058 }
Michael Krufky3b64e8e2005-11-08 21:38:20 -08001059 break;
Andrew Burri3e1410a2006-02-27 00:08:23 -03001060 case SAA7134_BOARD_KWORLD_ATSC110:
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001061 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1062 &dev->i2c_adap);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -03001063 if (dev->dvb.frontend) {
Michael Krufky4ad8eee52006-08-08 15:48:08 -03001064 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1065 NULL, &dvb_pll_tuv1236d);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -03001066 }
Andrew Burri3e1410a2006-02-27 00:08:23 -03001067 break;
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -03001068 case SAA7134_BOARD_FLYDVBS_LR300:
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001069 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1070 &dev->i2c_adap);
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -03001071 if (dev->dvb.frontend) {
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001072 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1073 &dev->i2c_adap, 0) == NULL) {
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -03001074 printk("%s: No tda826x found!\n", __FUNCTION__);
1075 }
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001076 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1077 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -03001078 printk("%s: No ISL6421 found!\n", __FUNCTION__);
1079 }
1080 }
1081 break;
Hartmut Hackmanncf146ca2006-10-02 20:49:24 -03001082 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
1083 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
1084 &dev->i2c_adap);
1085 if (dev->dvb.frontend) {
1086 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1087 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1088 dev->dvb.frontend->ops.tuner_ops.init = philips_fmd1216_tuner_init;
1089 dev->dvb.frontend->ops.tuner_ops.sleep = philips_fmd1216_tuner_sleep;
1090 dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
1091 }
1092 break;
Hartmut Hackmanncbb94522006-10-30 20:00:16 -03001093 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1094 dev->dvb.frontend = dvb_attach(tda10046_attach,
1095 &philips_europa_config,
1096 &dev->i2c_adap);
1097 if (dev->dvb.frontend) {
1098 dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1099 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1100 }
1101 break;
Hartmut Hackmann550a9a52006-11-15 21:31:54 -03001102 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -03001103 configure_tda827x_fe(dev, &cinergy_ht_config);
Hartmut Hackmann550a9a52006-11-15 21:31:54 -03001104 break;
Michael Krufky9de271e2007-01-16 18:36:40 -03001105 case SAA7134_BOARD_CINERGY_HT_PCI:
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -03001106 configure_tda827x_fe(dev, &cinergy_ht_pci_config);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -03001107 break;
1108 case SAA7134_BOARD_PHILIPS_TIGER_S:
Hartmut Hackmannb8bc76d2007-04-27 12:31:16 -03001109 configure_tda827x_fe(dev, &philips_tiger_s_config);
Michael Krufky9de271e2007-01-16 18:36:40 -03001110 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 default:
1112 printk("%s: Huh? unknown DVB card?\n",dev->name);
1113 break;
1114 }
1115
1116 if (NULL == dev->dvb.frontend) {
1117 printk("%s: frontend initialization failed\n",dev->name);
1118 return -1;
1119 }
1120
1121 /* register everything else */
Hartmut Hackmann1c4f76a2007-04-27 12:31:16 -03001122 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
1123
1124 /* this sequence is necessary to make the tda1004x load its firmware
1125 * and to enter analog mode of hybrid boards
1126 */
1127 if (!ret) {
1128 if (dev->dvb.frontend->ops.init)
1129 dev->dvb.frontend->ops.init(dev->dvb.frontend);
1130 if (dev->dvb.frontend->ops.sleep)
1131 dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
1132 }
1133 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134}
1135
1136static int dvb_fini(struct saa7134_dev *dev)
1137{
1138 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1139
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 switch (dev->board) {
1141 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1142 /* otherwise we don't detect the tuner on next insmod */
1143 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
1144 break;
1145 };
1146 videobuf_dvb_unregister(&dev->dvb);
1147 return 0;
1148}
1149
1150static struct saa7134_mpeg_ops dvb_ops = {
1151 .type = SAA7134_MPEG_DVB,
1152 .init = dvb_init,
1153 .fini = dvb_fini,
1154};
1155
1156static int __init dvb_register(void)
1157{
1158 return saa7134_ts_register(&dvb_ops);
1159}
1160
1161static void __exit dvb_unregister(void)
1162{
1163 saa7134_ts_unregister(&dvb_ops);
1164}
1165
1166module_init(dvb_register);
1167module_exit(dvb_unregister);
1168
1169/* ------------------------------------------------------------------ */
1170/*
1171 * Local variables:
1172 * c-basic-offset: 8
1173 * End:
1174 */